diff --git a/.idea/gradle.xml b/.idea/gradle.xml index a2d7c21..a0de2a1 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -7,6 +7,7 @@ + diff --git a/app/src/main/java/com/example/myapplication/MainActivity.kt b/app/src/main/java/com/example/myapplication/MainActivity.kt index 3394e95..b3feec5 100644 --- a/app/src/main/java/com/example/myapplication/MainActivity.kt +++ b/app/src/main/java/com/example/myapplication/MainActivity.kt @@ -1,7 +1,13 @@ package com.example.myapplication +import android.app.Activity +import android.content.Intent +import android.net.Uri import android.os.Bundle import android.view.Menu +import android.view.MenuItem +import android.widget.Toast +import androidx.activity.result.contract.ActivityResultContracts import com.google.android.material.bottomnavigation.BottomNavigationView import androidx.appcompat.app.AppCompatActivity import androidx.navigation.findNavController @@ -35,4 +41,35 @@ class MainActivity : AppCompatActivity() { menuInflater.inflate(R.menu.action_bar_menu, menu) return super.onCreateOptionsMenu(menu) } + + //adds actions for when you press buttons + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return when (item.itemId) { + //runs when pressing "Files" + R.id.addFile -> { + val intent = Intent() + .setType("*/*") + .setAction(Intent.ACTION_GET_CONTENT) + + resultLauncher.launch(intent) + + Toast.makeText(applicationContext, "Files", Toast.LENGTH_LONG).show() + return true + } + R.id.addYoutube ->{ + Toast.makeText(applicationContext, "Youtube downloading is currently not available", Toast.LENGTH_LONG).show() + return true + } + else -> super.onOptionsItemSelected(item) + } + } + + //grabs output from pressing files, used for grabbing URI + var resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == Activity.RESULT_OK) { + // There are no request codes + val data: Uri? = result.data?.data + Toast.makeText(applicationContext, data.toString(), Toast.LENGTH_LONG).show() + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/ui/settings/SettingsFragment.kt b/app/src/main/java/com/example/myapplication/ui/settings/SettingsFragment.kt index 92669d7..531b6d0 100644 --- a/app/src/main/java/com/example/myapplication/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/example/myapplication/ui/settings/SettingsFragment.kt @@ -1,9 +1,15 @@ package com.example.myapplication.ui.settings import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.RadioButton +import android.widget.Toast +import androidx.core.view.isVisible +import androidx.core.widget.addTextChangedListener import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider import com.example.myapplication.databinding.FragmentSettingsBinding @@ -28,6 +34,64 @@ class SettingsFragment : Fragment() { _binding = FragmentSettingsBinding.inflate(inflater, container, false) val root: View = binding.root + + + + //sets the textbox visibility on startup + binding.settingCustomSizeVideoText.visibility = View.INVISIBLE + + + //updates size when size selection changes + binding.settingRadioGroup.setOnCheckedChangeListener{ group,checkedID -> + + if(checkedID == binding.settingDefaultSizeVideo.id){ + homeViewModel.size.value = 8.0 + }else if(checkedID == binding.settingBigSizeVideo.id){ + homeViewModel.size.value = 50.0 + }else if(checkedID == binding.settingHugeSize.id){ + homeViewModel.size.value = 500.0 + }else{ + try{ + homeViewModel.size.value = binding.settingCustomSizeVideoText.text.toString().toDouble() + }catch (e: NumberFormatException){ + homeViewModel.size.value = 0.0 + } + } + + Toast.makeText(root.context,"" + homeViewModel.size.value,Toast.LENGTH_SHORT).show() + + } + + //updates size when the custom value changes + binding.settingCustomSizeVideoText.addTextChangedListener ( object: TextWatcher { + + override fun afterTextChanged(s: Editable) {} + + override fun beforeTextChanged(s: CharSequence, start: Int, + count: Int, after: Int) { + } + + override fun onTextChanged(s: CharSequence, start: Int, + before: Int, count: Int) { + try{ + homeViewModel.size.value = s.toString().toDouble() + }catch (e: NumberFormatException){ + homeViewModel.size.value = 0.0 + } + Toast.makeText(root.context,"" + homeViewModel.size.value,Toast.LENGTH_SHORT).show() + } + } + ) + + //listens for changes in the custom radiobutton and hides or shows the textbox + binding.settingCustomSizeVideo.setOnCheckedChangeListener{ _, isChecked -> + if (isChecked){ + binding.settingCustomSizeVideoText.visibility = View.VISIBLE + }else{ + binding.settingCustomSizeVideoText.visibility = View.INVISIBLE + } + } + // val textView: TextView = binding.textSettings // homeViewModel.text.observe(viewLifecycleOwner) { // textView.text = it diff --git a/app/src/main/java/com/example/myapplication/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/example/myapplication/ui/settings/SettingsViewModel.kt index a41f14e..f681f6c 100644 --- a/app/src/main/java/com/example/myapplication/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/example/myapplication/ui/settings/SettingsViewModel.kt @@ -10,4 +10,10 @@ class SettingsViewModel : ViewModel() { value = "This is settings Fragment" } val text: LiveData = _text + + //size of the file, grab this for use + private val _size = MutableLiveData().apply { + value = 8.0 + } + val size: MutableLiveData = _size } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index 75bfcd5..6930a24 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -10,6 +10,7 @@ android:layout_height="match_parent"> @@ -23,6 +24,7 @@ android:id="@+id/setting_default_size_video" android:layout_width="match_parent" android:layout_height="wrap_content" + android:checked="true" android:text="@string/settings_default_size" /> + app:showAsAction="ifRoom" > + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 00aae77..98c3fb5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,4 +10,6 @@ 500mb Custom Enter Size in MB + Files + Youtube \ No newline at end of file