mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
refactor: replace deprecated onBackPressed with onBackPressedCallback
This commit is contained in:
parent
d0b6ce5c52
commit
c07a6acd0b
1 changed files with 21 additions and 15 deletions
|
|
@ -14,6 +14,7 @@ import android.os.Bundle
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.CheckBox
|
import android.widget.CheckBox
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
|
|
@ -166,6 +167,8 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
|
||||||
private var _binding: ActivityUploadBinding? = null
|
private var _binding: ActivityUploadBinding? = null
|
||||||
private val binding: ActivityUploadBinding get() = _binding!!
|
private val binding: ActivityUploadBinding get() = _binding!!
|
||||||
|
|
||||||
|
private lateinit var onBackPressedCallback: OnBackPressedCallback
|
||||||
|
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
@ -173,6 +176,23 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
|
||||||
_binding = ActivityUploadBinding.inflate(layoutInflater)
|
_binding = ActivityUploadBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
|
// Overrides the back button to make sure the user is prepared to lose their progress
|
||||||
|
onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||||
|
override fun handleOnBackPressed() {
|
||||||
|
showAlertDialog(
|
||||||
|
this@UploadActivity,
|
||||||
|
getString(R.string.back_button_warning),
|
||||||
|
getString(R.string.back_button_warning_desc),
|
||||||
|
getString(R.string.back_button_continue),
|
||||||
|
getString(R.string.back_button_warning),
|
||||||
|
null
|
||||||
|
) {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
If Configuration of device is changed then get the new fragments
|
If Configuration of device is changed then get the new fragments
|
||||||
created by the system and populate the fragments ArrayList
|
created by the system and populate the fragments ArrayList
|
||||||
|
|
@ -850,21 +870,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
|
||||||
if (uploadCategoriesFragment != null) {
|
if (uploadCategoriesFragment != null) {
|
||||||
uploadCategoriesFragment!!.callback = null
|
uploadCategoriesFragment!!.callback = null
|
||||||
}
|
}
|
||||||
}
|
onBackPressedCallback.remove()
|
||||||
|
|
||||||
/**
|
|
||||||
* Overrides the back button to make sure the user is prepared to lose their progress
|
|
||||||
*/
|
|
||||||
@SuppressLint("MissingSuperCall")
|
|
||||||
override fun onBackPressed() {
|
|
||||||
showAlertDialog(
|
|
||||||
this,
|
|
||||||
getString(R.string.back_button_warning),
|
|
||||||
getString(R.string.back_button_warning_desc),
|
|
||||||
getString(R.string.back_button_continue),
|
|
||||||
getString(R.string.back_button_warning),
|
|
||||||
null
|
|
||||||
) { finish() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue