0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-12-18 06:20:07 +00:00

Merge pull request #159 from ostajic/dev

Back Button Fix and dupe bug fix
This commit is contained in:
Tornike Khintibidze 2020-09-19 12:24:41 +04:00 committed by GitHub
commit 9b98b3239b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.databinding.FragmentAboutBinding import com.vanced.manager.databinding.FragmentAboutBinding
import com.vanced.manager.ui.viewmodels.AboutViewModel import com.vanced.manager.ui.viewmodels.AboutViewModel
import kotlinx.android.synthetic.main.fragment_main.*
class AboutFragment : Fragment() { class AboutFragment : Fragment() {
@ -42,12 +38,6 @@ class AboutFragment : Fragment() {
val viewModel: AboutViewModel by viewModels() val viewModel: AboutViewModel by viewModels()
binding.viewModel = viewModel binding.viewModel = viewModel
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
view.setOnTouchListener { _, event: MotionEvent -> view.setOnTouchListener { _, event: MotionEvent ->

View file

@ -7,11 +7,9 @@ import android.os.Bundle
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 androidx.activity.OnBackPressedCallback
import androidx.core.content.edit import androidx.core.content.edit
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.navigation.fragment.findNavController
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.databinding.FragmentChosenPreferencesBinding import com.vanced.manager.databinding.FragmentChosenPreferencesBinding
import java.util.* 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.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()) 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.os.Bundle
import android.util.Log import android.util.Log
import android.widget.Toast import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
@ -26,12 +24,7 @@ class DevSettingsFragment: PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.dev_settings, rootKey) 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") val ftSwitch: Preference? = findPreference("firststart_switch")

View file

@ -5,14 +5,12 @@ import android.os.Bundle
import android.view.* import android.view.*
import android.view.animation.AccelerateDecelerateInterpolator import android.view.animation.AccelerateDecelerateInterpolator
import android.widget.Toast import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.navigation.findNavController import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
import com.vanced.manager.R import com.vanced.manager.R
@ -32,20 +30,16 @@ open class HomeFragment : Fragment(), View.OnClickListener {
private val viewModel: HomeViewModel by viewModels() private val viewModel: HomeViewModel by viewModels()
private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(requireActivity()) } private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(requireActivity()) }
override fun onStart() {
super.onStart()
}
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): 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) requireActivity().title = getString(R.string.title_home)
setHasOptionsMenu(true) 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 = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false)
binding.viewModel = viewModel binding.viewModel = viewModel
viewModel.variant = variant
return binding.root 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) { with(binding) {
includeChangelogsLayout.changelogButton.setOnClickListener(this@HomeFragment) 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.R
import com.vanced.manager.databinding.FragmentMainBinding import com.vanced.manager.databinding.FragmentMainBinding
import com.vanced.manager.ui.MainActivity import com.vanced.manager.ui.MainActivity
import kotlin.system.exitProcess
class MainFragment : Fragment() { class MainFragment : Fragment() {
@ -44,7 +45,10 @@ class MainFragment : Fragment() {
val callback = object : OnBackPressedCallback(true) { val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() { override fun handleOnBackPressed() {
requireActivity().finish() if(!navHost.popBackStack())
{
exitProcess(0)
}
} }
} }
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback) requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)

View file

@ -4,11 +4,9 @@ import android.os.Bundle
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 androidx.activity.OnBackPressedCallback
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.databinding.FragmentManagerChangelogBinding import com.vanced.manager.databinding.FragmentManagerChangelogBinding
import com.vanced.manager.ui.viewmodels.HomeViewModel import com.vanced.manager.ui.viewmodels.HomeViewModel
@ -27,14 +25,4 @@ class ManagerChangelogFragment : Fragment() {
return binding.root 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.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.databinding.FragmentMicrogChangelogBinding import com.vanced.manager.databinding.FragmentMicrogChangelogBinding
import com.vanced.manager.ui.viewmodels.HomeViewModel import com.vanced.manager.ui.viewmodels.HomeViewModel
@ -27,14 +25,4 @@ class MicrogChangelogFragment : Fragment() {
return binding.root 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.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.databinding.FragmentMusicChangelogBinding import com.vanced.manager.databinding.FragmentMusicChangelogBinding
import com.vanced.manager.ui.viewmodels.HomeViewModel import com.vanced.manager.ui.viewmodels.HomeViewModel
@ -29,12 +27,6 @@ class MusicChangelogFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding.viewModel = viewModel 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.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.widget.Toast import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import androidx.preference.* import androidx.preference.*
import com.google.firebase.messaging.FirebaseMessaging import com.google.firebase.messaging.FirebaseMessaging
import com.vanced.manager.R import com.vanced.manager.R
import kotlinx.android.synthetic.main.fragment_main.*
import java.io.File import java.io.File
class SettingsFragment : PreferenceFragmentCompat() { class SettingsFragment : PreferenceFragmentCompat() {
@ -21,13 +17,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
activity?.title = getString(R.string.title_settings) activity?.title = getString(R.string.title_settings)
setHasOptionsMenu(true) setHasOptionsMenu(true)
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
findNavController().popBackStack()
}
}
requireActivity().onBackPressedDispatcher.addCallback(this, callback)
findPreference<Preference>("update_check")?.setOnPreferenceClickListener { findPreference<Preference>("update_check")?.setOnPreferenceClickListener {
UpdateCheckFragment().show(childFragmentManager.beginTransaction(), "Update Center") UpdateCheckFragment().show(childFragmentManager.beginTransaction(), "Update Center")
true true
@ -112,6 +101,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
} }
true true
} }
} }
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {

View file

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

View file

@ -14,10 +14,8 @@ import android.widget.Button
import android.widget.ProgressBar import android.widget.ProgressBar
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.navigation.fragment.findNavController
import com.downloader.OnDownloadListener import com.downloader.OnDownloadListener
import com.downloader.PRDownloader import com.downloader.PRDownloader
import com.google.android.material.button.MaterialButton 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<Button>(R.id.update_center_dismiss).setOnClickListener { dismiss() }
view.findViewById<MaterialButton>(R.id.update_center_recheck).setOnClickListener{ checkUpdates() } 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) downLoadingState(false)
} }

View file

@ -4,11 +4,9 @@ import android.os.Bundle
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 androidx.activity.OnBackPressedCallback
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.databinding.FragmentVancedChangelogBinding import com.vanced.manager.databinding.FragmentVancedChangelogBinding
import com.vanced.manager.ui.viewmodels.HomeViewModel import com.vanced.manager.ui.viewmodels.HomeViewModel
@ -27,13 +25,4 @@ class VancedChangelogFragment : Fragment() {
return binding.root 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.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.activity.OnBackPressedCallback
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.navigation.findNavController import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import com.google.android.material.checkbox.MaterialCheckBox import com.google.android.material.checkbox.MaterialCheckBox
import com.vanced.manager.R import com.vanced.manager.R
@ -38,12 +36,6 @@ class VancedLanguageSelectionFragment : Fragment() {
@ExperimentalStdlibApi @ExperimentalStdlibApi
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) 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 val app = activity?.application as App
langs = app.vanced?.array<String>("langs")?.value ?: mutableListOf("null") langs = app.vanced?.array<String>("langs")?.value ?: mutableListOf("null")
loadBoxes(view.findViewById(R.id.lang_button_ll)) loadBoxes(view.findViewById(R.id.lang_button_ll))

View file

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