0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-27 05:23:00 +00:00

Back Button Fix and dupe bug fix

This commit is contained in:
ostajic 2020-09-19 10:21:48 +02:00
parent 229952435c
commit 6e2d2c1df7
14 changed files with 11 additions and 131 deletions

View file

@ -7,17 +7,13 @@ import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import androidx.preference.PreferenceManager
import com.vanced.manager.R
import com.vanced.manager.databinding.FragmentAboutBinding
import com.vanced.manager.ui.viewmodels.AboutViewModel
import kotlinx.android.synthetic.main.fragment_main.*
class AboutFragment : Fragment() {
@ -42,12 +38,6 @@ class AboutFragment : Fragment() {
val viewModel: AboutViewModel by viewModels()
binding.viewModel = viewModel
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
view.setOnTouchListener { _, event: MotionEvent ->

View file

@ -7,11 +7,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.core.content.edit
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.DialogFragment
import androidx.navigation.fragment.findNavController
import com.vanced.manager.R
import com.vanced.manager.databinding.FragmentChosenPreferencesBinding
import java.util.*
@ -43,12 +41,7 @@ class ChosenPreferenceDialogFragment : DialogFragment() {
}
}
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(this, callback)
binding.chosenTheme.text = requireActivity().getString(R.string.chosen_theme, prefs.getString("theme", "dark")?.capitalize(Locale.ROOT))
binding.chosenLang.text = requireActivity().getString(R.string.chosen_lang, newPrefs.joinToString())

View file

@ -6,10 +6,8 @@ import android.os.Build
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AlertDialog
import androidx.core.content.FileProvider
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
@ -26,12 +24,7 @@ class DevSettingsFragment: PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.dev_settings, rootKey)
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
val ftSwitch: Preference? = findPreference("firststart_switch")

View file

@ -5,14 +5,12 @@ import android.os.Bundle
import android.view.*
import android.view.animation.AccelerateDecelerateInterpolator
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.vanced.manager.R
@ -32,20 +30,16 @@ open class HomeFragment : Fragment(), View.OnClickListener {
private val viewModel: HomeViewModel by viewModels()
private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(requireActivity()) }
override fun onStart() {
super.onStart()
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
variant = if (requireActivity().findViewById<TabLayout>(R.id.main_tablayout).selectedTabPosition == 1) "root" else "nonroot"
viewModel.variant = variant
requireActivity().title = getString(R.string.title_home)
setHasOptionsMenu(true)
variant = if (requireActivity().findViewById<TabLayout>(R.id.main_tablayout).selectedTabPosition == 1) "root" else "nonroot"
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false)
binding.viewModel = viewModel
viewModel.variant = variant
return binding.root
}
@ -59,13 +53,6 @@ open class HomeFragment : Fragment(), View.OnClickListener {
}
})
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
requireActivity().finish()
}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
with(binding) {
includeChangelogsLayout.changelogButton.setOnClickListener(this@HomeFragment)

View file

@ -22,6 +22,7 @@ import com.google.android.material.tabs.TabLayout
import com.vanced.manager.R
import com.vanced.manager.databinding.FragmentMainBinding
import com.vanced.manager.ui.MainActivity
import kotlin.system.exitProcess
class MainFragment : Fragment() {
@ -44,7 +45,10 @@ class MainFragment : Fragment() {
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
requireActivity().finish()
if(!navHost.popBackStack())
{
exitProcess(0)
}
}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)

View file

@ -4,11 +4,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.vanced.manager.R
import com.vanced.manager.databinding.FragmentManagerChangelogBinding
import com.vanced.manager.ui.viewmodels.HomeViewModel
@ -27,14 +25,4 @@ class ManagerChangelogFragment : Fragment() {
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
}
}

View file

@ -4,11 +4,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.vanced.manager.R
import com.vanced.manager.databinding.FragmentMicrogChangelogBinding
import com.vanced.manager.ui.viewmodels.HomeViewModel
@ -27,14 +25,4 @@ class MicrogChangelogFragment : Fragment() {
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
}
}

View file

@ -4,11 +4,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.vanced.manager.R
import com.vanced.manager.databinding.FragmentMusicChangelogBinding
import com.vanced.manager.ui.viewmodels.HomeViewModel
@ -29,12 +27,6 @@ class MusicChangelogFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.viewModel = viewModel
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
}
}

View file

@ -4,13 +4,9 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import androidx.preference.*
import com.google.firebase.messaging.FirebaseMessaging
import com.vanced.manager.R
import kotlinx.android.synthetic.main.fragment_main.*
import java.io.File
class SettingsFragment : PreferenceFragmentCompat() {
@ -21,13 +17,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
activity?.title = getString(R.string.title_settings)
setHasOptionsMenu(true)
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(this, callback)
findPreference<Preference>("update_check")?.setOnPreferenceClickListener {
UpdateCheckFragment().show(childFragmentManager.beginTransaction(), "Update Center")
true
@ -112,6 +101,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
true
}
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {

View file

@ -8,9 +8,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.DialogFragment
import androidx.navigation.fragment.findNavController
import androidx.preference.PreferenceManager
import com.google.android.material.button.MaterialButton
import com.vanced.manager.R
@ -44,14 +42,6 @@ class URLChangeFragment : DialogFragment() {
prefs.edit().putString("install_url", finalUrl).apply()
dismiss()
}
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
view.findViewById<MaterialButton>(R.id.url_reset).setOnClickListener {
prefs.edit().putString("install_url", baseUrl).apply()
dismiss()

View file

@ -14,10 +14,8 @@ import android.widget.Button
import android.widget.ProgressBar
import android.widget.TextView
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.core.content.FileProvider
import androidx.fragment.app.DialogFragment
import androidx.navigation.fragment.findNavController
import com.downloader.OnDownloadListener
import com.downloader.PRDownloader
import com.google.android.material.button.MaterialButton
@ -48,13 +46,6 @@ class UpdateCheckFragment : DialogFragment() {
view.findViewById<Button>(R.id.update_center_dismiss).setOnClickListener { dismiss() }
view.findViewById<MaterialButton>(R.id.update_center_recheck).setOnClickListener{ checkUpdates() }
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
downLoadingState(false)
}

View file

@ -4,11 +4,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.vanced.manager.R
import com.vanced.manager.databinding.FragmentVancedChangelogBinding
import com.vanced.manager.ui.viewmodels.HomeViewModel
@ -27,13 +25,4 @@ class VancedChangelogFragment : Fragment() {
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
}
}

View file

@ -8,11 +8,9 @@ import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.LinearLayout
import androidx.activity.OnBackPressedCallback
import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.Fragment
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import com.google.android.material.button.MaterialButton
import com.google.android.material.checkbox.MaterialCheckBox
import com.vanced.manager.R
@ -38,12 +36,6 @@ class VancedLanguageSelectionFragment : Fragment() {
@ExperimentalStdlibApi
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
val app = activity?.application as App
langs = app.vanced?.array<String>("langs")?.value ?: mutableListOf("null")
loadBoxes(view.findViewById(R.id.lang_button_ll))

View file

@ -7,10 +7,8 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.RadioGroup
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.Fragment
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import com.google.android.material.radiobutton.MaterialRadioButton
import com.vanced.manager.R
@ -26,12 +24,7 @@ class VancedThemeSelectionFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
val nextButton = view.findViewById<Button>(R.id.vanced_next_to_variant)
val themeGroup = view.findViewById<RadioGroup>(R.id.theme_radiogroup)
val prefs = activity?.getSharedPreferences("installPrefs", Context.MODE_PRIVATE)