[Android] Network login: fix cancel event

Geoffrey Métais git at videolan.org
Thu Sep 12 16:34:35 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Sep 12 16:14:47 2019 +0200| [8320cad2d587d9d817c4da3bf7e9420d554a00fd] | committer: Geoffrey Métais

Network login: fix cancel event

> https://code.videolan.org/videolan/vlc-android/commit/8320cad2d587d9d817c4da3bf7e9420d554a00fd
---

 .../src/org/videolan/vlc/gui/dialogs/VlcDialog.kt  | 10 ++++-----
 .../org/videolan/vlc/gui/dialogs/VlcLoginDialog.kt | 25 +++++++++++++---------
 2 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcDialog.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcDialog.kt
index 0e04b242e..8b0c3400c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcDialog.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcDialog.kt
@@ -65,17 +65,15 @@ abstract class VlcDialog<T : Dialog, B : ViewDataBinding> : DialogFragment() {
 
     override fun onDestroy() {
         super.onDestroy()
-        if (::vlcDialog.isInitialized)
-            vlcDialog.dismiss()
-        activity!!.finish()
+        if (::vlcDialog.isInitialized) vlcDialog.dismiss()
+        activity?.finish()
     }
 
-    fun onCancel(v: View) {
+    open fun onCancel(v: View) {
         dismiss()
     }
 
     override fun dismiss() {
-        if (isResumed)
-            super.dismiss()
+        if (isResumed) super.dismiss()
     }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcLoginDialog.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcLoginDialog.kt
index 69b70270b..74f4dade5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcLoginDialog.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcLoginDialog.kt
@@ -25,6 +25,7 @@
 package org.videolan.vlc.gui.dialogs
 
 import android.content.Context
+import android.content.DialogInterface
 import android.content.Intent
 import android.content.SharedPreferences
 import android.os.Bundle
@@ -41,11 +42,10 @@ import org.videolan.vlc.util.Settings
 
 class VlcLoginDialog : VlcDialog<Dialog.LoginDialog, VlcLoginDialogBinding>(), View.OnFocusChangeListener {
 
-    private lateinit var mSettings: SharedPreferences
+    private lateinit var settings: SharedPreferences
 
 
-    override val layout: Int
-        get() = R.layout.vlc_login_dialog
+    override val layout= R.layout.vlc_login_dialog
 
 
     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@@ -59,27 +59,32 @@ class VlcLoginDialog : VlcDialog<Dialog.LoginDialog, VlcLoginDialogBinding>(), V
 
     override fun onAttach(context: Context) {
         super.onAttach(context)
-        mSettings = Settings.getInstance(requireActivity())
+        settings = Settings.getInstance(requireActivity())
     }
 
     fun onLogin(v: View) {
         vlcDialog.postLogin(binding.login.text.toString().trim(),
                 binding.password.text.toString().trim(), binding.store.isChecked)
-        mSettings.edit().putBoolean(LOGIN_STORE, binding.store.isChecked).apply()
+        settings.edit().putBoolean(LOGIN_STORE, binding.store.isChecked).apply()
         dismiss()
     }
 
-    fun store(): Boolean {
-        return mSettings.getBoolean(LOGIN_STORE, true)
-    }
+    fun store() = settings.getBoolean(LOGIN_STORE, true)
 
     override fun onFocusChange(v: View, hasFocus: Boolean) {
         if (hasFocus) UiTools.setKeyboardVisibility(v, v is EditText)
     }
 
-    override fun onDestroy() {
+    // Cancel from LibVLC
+    override fun onCancel(dialog: DialogInterface) {
+        LocalBroadcastManager.getInstance(requireContext()).sendBroadcast(Intent(ACTION_DIALOG_CANCELED))
+        super.onCancel(dialog)
+    }
+
+    // Cancel from UI
+    override fun onCancel(v: View) {
         LocalBroadcastManager.getInstance(requireContext()).sendBroadcast(Intent(ACTION_DIALOG_CANCELED))
-        super.onDestroy()
+        super.onCancel(v)
     }
 
     companion object {



More information about the Android mailing list