Improved mitigation for Kivy textfield focus bug

This commit is contained in:
Mark Qvist 2022-10-19 22:59:42 +02:00
parent 645c2790a9
commit 7039c0330f

View File

@ -246,6 +246,11 @@ class SidebandApp(MDApp):
mActivity.startActivity(shareIntent) mActivity.startActivity(shareIntent)
def on_pause(self): def on_pause(self):
if self.sideband:
if self.sideband.getstate("flag.focusfix_pause"):
self.sideband.setstate("flag.focusfix_pause", False)
return True
else:
RNS.log("App pausing...", RNS.LOG_DEBUG) RNS.log("App pausing...", RNS.LOG_DEBUG)
self.sideband.setstate("app.running", True) self.sideband.setstate("app.running", True)
self.sideband.setstate("app.foreground", False) self.sideband.setstate("app.foreground", False)
@ -260,8 +265,15 @@ class SidebandApp(MDApp):
RNS.log("App paused", RNS.LOG_DEBUG) RNS.log("App paused", RNS.LOG_DEBUG)
return True return True
else:
return True
def on_resume(self): def on_resume(self):
if self.sideband:
if self.sideband.getstate("flag.focusfix_resume"):
self.sideband.setstate("flag.focusfix_resume", False)
return True
else:
RNS.log("App resuming...", RNS.LOG_DEBUG) RNS.log("App resuming...", RNS.LOG_DEBUG)
self.sideband.setstate("app.running", True) self.sideband.setstate("app.running", True)
self.sideband.setstate("app.foreground", True) self.sideband.setstate("app.foreground", True)
@ -277,7 +289,7 @@ class SidebandApp(MDApp):
else: else:
RNS.log("Conversations view did not exist", RNS.LOG_DEBUG) RNS.log("Conversations view did not exist", RNS.LOG_DEBUG)
RNS.log("App resumed...", RNS.LOG_DEBUG) RNS.log("App resumed", RNS.LOG_DEBUG)
def on_stop(self): def on_stop(self):
RNS.log("App stopping...", RNS.LOG_DEBUG) RNS.log("App stopping...", RNS.LOG_DEBUG)
@ -383,7 +395,7 @@ class SidebandApp(MDApp):
# the software keyboard on Android. Without this the back # the software keyboard on Android. Without this the back
# button/gesture does not work after the soft-keyboard has # button/gesture does not work after the soft-keyboard has
# appeared for the first time. # appeared for the first time.
if RNS.vendor.platformutils.get_platform() == "android": if RNS.vendor.platformutils.is_android():
BIND_CLASSES = ["kivymd.uix.textfield.textfield.MDTextField",] BIND_CLASSES = ["kivymd.uix.textfield.textfield.MDTextField",]
for e in self.root.ids: for e in self.root.ids:
@ -392,11 +404,6 @@ class SidebandApp(MDApp):
if ts in BIND_CLASSES: if ts in BIND_CLASSES:
te.bind(focus=self.android_focus_fix) te.bind(focus=self.android_focus_fix)
# RNS.log("Bound "+str(e)+" / "+ts)
# else:
# RNS.log("Did not bind "+str(e)+" / "+ts)
# RNS.log(str(e))
self.root.ids.screen_manager.app = self self.root.ids.screen_manager.app = self
self.root.ids.app_version_info.text = "Sideband v"+__version__+" "+__variant__ self.root.ids.app_version_info.text = "Sideband v"+__version__+" "+__variant__
@ -408,6 +415,8 @@ class SidebandApp(MDApp):
if not val: if not val:
@run_on_ui_thread @run_on_ui_thread
def fix_back_button(): def fix_back_button():
self.sideband.setstate("flag.focusfix_pause", True)
self.sideband.setstate("flag.focusfix_resume", True)
activity = autoclass('org.kivy.android.PythonActivity').mActivity activity = autoclass('org.kivy.android.PythonActivity').mActivity
activity.onWindowFocusChanged(False) activity.onWindowFocusChanged(False)
activity.onWindowFocusChanged(True) activity.onWindowFocusChanged(True)