2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 05:37:43 +00:00

Fix onBackPressed after screen rotation

Moved onBackPressedDispatcher.addCallback(s) to onResume
This commit is contained in:
Dmitry Yudin 2023-04-24 17:37:19 +00:00 committed by Albert Vaca Cintora
parent 8639938584
commit 71706879d0

View File

@ -89,7 +89,6 @@ class MainActivity : AppCompatActivity(), OnSharedPreferenceChangeListener {
it.addDrawerListener(mDrawerToggle) it.addDrawerListener(mDrawerToggle)
it.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START) it.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START)
} ?: { } ?: {
closeDrawerCallback.isEnabled = false
supportActionBar?.setDisplayShowHomeEnabled(false) supportActionBar?.setDisplayShowHomeEnabled(false)
supportActionBar?.setHomeButtonEnabled(false) supportActionBar?.setHomeButtonEnabled(false)
} }
@ -110,13 +109,11 @@ class MainActivity : AppCompatActivity(), OnSharedPreferenceChangeListener {
} }
MENU_ENTRY_SETTINGS -> { MENU_ENTRY_SETTINGS -> {
// mCurrentDevice = null
preferences.edit().putString(STATE_SELECTED_DEVICE, null).apply() preferences.edit().putString(STATE_SELECTED_DEVICE, null).apply()
setContentFragment(SettingsFragment()) setContentFragment(SettingsFragment())
} }
MENU_ENTRY_ABOUT -> { MENU_ENTRY_ABOUT -> {
// mCurrentDevice = null
preferences.edit().putString(STATE_SELECTED_DEVICE, null).apply() preferences.edit().putString(STATE_SELECTED_DEVICE, null).apply()
setContentFragment(newInstance(getApplicationAboutData(this))) setContentFragment(newInstance(getApplicationAboutData(this)))
} }
@ -187,9 +184,6 @@ class MainActivity : AppCompatActivity(), OnSharedPreferenceChangeListener {
else -> setContentFragment(PairingFragment()) else -> setContentFragment(PairingFragment())
} }
} }
onBackPressedDispatcher.addCallback(mainFragmentCallback)
onBackPressedDispatcher.addCallback(closeDrawerCallback)
} }
override fun onDestroy() { override fun onDestroy() {
@ -274,11 +268,16 @@ class MainActivity : AppCompatActivity(), OnSharedPreferenceChangeListener {
service.addDeviceListChangedCallback(this::class.simpleName) { updateDeviceList() } service.addDeviceListChangedCallback(this::class.simpleName) { updateDeviceList() }
} }
updateDeviceList() updateDeviceList()
onBackPressedDispatcher.addCallback(mainFragmentCallback)
onBackPressedDispatcher.addCallback(closeDrawerCallback)
if (mDrawerLayout == null) closeDrawerCallback.isEnabled = false
} }
override fun onStop() { override fun onStop() {
BackgroundService.RunCommand(this) { service: BackgroundService -> service.removeDeviceListChangedCallback(this::class.simpleName) } BackgroundService.RunCommand(this) { service: BackgroundService -> service.removeDeviceListChangedCallback(this::class.simpleName) }
super.onStop() super.onStop()
mainFragmentCallback.remove()
closeDrawerCallback.remove()
} }
@JvmOverloads @JvmOverloads