Added buttons to menu bar, settings grabs size for use, Files grabs URI for use
This commit is contained in:
parent
28dc11863c
commit
51dd15484e
@ -7,6 +7,7 @@
|
|||||||
<option name="testRunner" value="GRADLE" />
|
<option name="testRunner" value="GRADLE" />
|
||||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="gradleJvm" value="Embedded JDK" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
package com.example.myapplication
|
package com.example.myapplication
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
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 com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
@ -35,4 +41,35 @@ class MainActivity : AppCompatActivity() {
|
|||||||
menuInflater.inflate(R.menu.action_bar_menu, menu)
|
menuInflater.inflate(R.menu.action_bar_menu, menu)
|
||||||
return super.onCreateOptionsMenu(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()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,9 +1,15 @@
|
|||||||
package com.example.myapplication.ui.settings
|
package com.example.myapplication.ui.settings
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.text.Editable
|
||||||
|
import android.text.TextWatcher
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
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.fragment.app.Fragment
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import com.example.myapplication.databinding.FragmentSettingsBinding
|
import com.example.myapplication.databinding.FragmentSettingsBinding
|
||||||
@ -28,6 +34,64 @@ class SettingsFragment : Fragment() {
|
|||||||
_binding = FragmentSettingsBinding.inflate(inflater, container, false)
|
_binding = FragmentSettingsBinding.inflate(inflater, container, false)
|
||||||
val root: View = binding.root
|
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
|
// val textView: TextView = binding.textSettings
|
||||||
// homeViewModel.text.observe(viewLifecycleOwner) {
|
// homeViewModel.text.observe(viewLifecycleOwner) {
|
||||||
// textView.text = it
|
// textView.text = it
|
||||||
|
@ -10,4 +10,10 @@ class SettingsViewModel : ViewModel() {
|
|||||||
value = "This is settings Fragment"
|
value = "This is settings Fragment"
|
||||||
}
|
}
|
||||||
val text: LiveData<String> = _text
|
val text: LiveData<String> = _text
|
||||||
|
|
||||||
|
//size of the file, grab this for use
|
||||||
|
private val _size = MutableLiveData<Double>().apply {
|
||||||
|
value = 8.0
|
||||||
|
}
|
||||||
|
val size: MutableLiveData<Double> = _size
|
||||||
}
|
}
|
@ -10,6 +10,7 @@
|
|||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
|
android:id="@+id/setting_radio_group"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
@ -23,6 +24,7 @@
|
|||||||
android:id="@+id/setting_default_size_video"
|
android:id="@+id/setting_default_size_video"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:checked="true"
|
||||||
android:text="@string/settings_default_size" />
|
android:text="@string/settings_default_size" />
|
||||||
|
|
||||||
<RadioButton
|
<RadioButton
|
||||||
|
@ -6,5 +6,15 @@
|
|||||||
android:id="@+id/add"
|
android:id="@+id/add"
|
||||||
android:title="Add"
|
android:title="Add"
|
||||||
android:icon="@drawable/ic_add"
|
android:icon="@drawable/ic_add"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="ifRoom" >
|
||||||
|
<menu>
|
||||||
|
<item
|
||||||
|
android:id="@+id/addFile"
|
||||||
|
android:title="@string/files" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/addYoutube"
|
||||||
|
android:title="@string/youtube" />
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
@ -10,4 +10,6 @@
|
|||||||
<string name="settings_huge_size">500mb</string>
|
<string name="settings_huge_size">500mb</string>
|
||||||
<string name="settings_custom_size">Custom</string>
|
<string name="settings_custom_size">Custom</string>
|
||||||
<string name="settings_custom_size_hint">Enter Size in MB</string>
|
<string name="settings_custom_size_hint">Enter Size in MB</string>
|
||||||
|
<string name="files">Files</string>
|
||||||
|
<string name="youtube">Youtube</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user