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