[Android] Store login by default & remember choice

Geoffrey Métais git at videolan.org
Tue Mar 15 18:23:49 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Mar 15 18:23:15 2016 +0100| [1cfe07c65102a8827ebadfdc8f10436286e7354f] | committer: Geoffrey Métais

Store login by default & remember choice

> https://code.videolan.org/videolan/vlc-android/commit/1cfe07c65102a8827ebadfdc8f10436286e7354f
---

 vlc-android/res/layout/vlc_login_dialog.xml         |  1 +
 .../videolan/vlc/gui/dialogs/VlcLoginDialog.java    | 21 +++++++++++++++++++++
 .../vlc/gui/preferences/PreferencesActivity.java    |  1 +
 3 files changed, 23 insertions(+)

diff --git a/vlc-android/res/layout/vlc_login_dialog.xml b/vlc-android/res/layout/vlc_login_dialog.xml
index 03a52ef..82235f8 100644
--- a/vlc-android/res/layout/vlc_login_dialog.xml
+++ b/vlc-android/res/layout/vlc_login_dialog.xml
@@ -59,6 +59,7 @@
                 android:text="@string/store_password"
                 android:layout_alignParentLeft="true"
                 android:layout_margin="5dp"
+                android:checked="@{handler.store()}"
                 android:visibility="@{dialog.asksStore() ? View.VISIBLE : View.GONE}"/>
             <TextView
                 android:id="@+id/warning"
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcLoginDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcLoginDialog.java
index b88bf44..a5d788f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcLoginDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcLoginDialog.java
@@ -24,22 +24,43 @@
 
 package org.videolan.vlc.gui.dialogs;
 
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.support.v7.preference.PreferenceManager;
 import android.view.View;
 
 import org.videolan.libvlc.Dialog;
 import org.videolan.vlc.R;
 import org.videolan.vlc.databinding.VlcLoginDialogBinding;
+import org.videolan.vlc.gui.preferences.PreferencesActivity;
+import org.videolan.vlc.util.Util;
 
 public class VlcLoginDialog extends VlcDialog<Dialog.LoginDialog, VlcLoginDialogBinding> {
 
+    SharedPreferences mSettings;
+
     @Override
     int getLayout() {
         return R.layout.vlc_login_dialog;
     }
 
+    @Override
+    public void onAttach(Context context) {
+        super.onAttach(context);
+        mSettings = PreferenceManager.getDefaultSharedPreferences(context);
+    }
+
     public void onLogin(View v) {
         mVlcDialog.postLogin(mBinding.login.getText().toString().trim(),
                 mBinding.password.getText().toString().trim(), mBinding.store.isChecked());
+        SharedPreferences.Editor editor = mSettings.edit();
+        editor.putBoolean(PreferencesActivity.LOGIN_STORE, mBinding.store.isChecked());
+        Util.commitPreferences(editor);
         dismiss();
     }
+
+    public boolean store() {
+        return mSettings.getBoolean(PreferencesActivity.LOGIN_STORE, true);
+    }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java
index aac5e5e..b62e0e4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesActivity.java
@@ -46,6 +46,7 @@ public class PreferencesActivity extends AppCompatActivity implements PlaybackSe
     public final static String VIDEO_SAVE_SPEED = "save_video_speed";
     public final static String VIDEO_RATE = "video_rate";
     public final static String AUTO_RESCAN = "auto_rescan";
+    public final static String LOGIN_STORE = "store_login";
     public final static int RESULT_RESCAN = RESULT_FIRST_USER + 1;
     public final static int RESULT_RESTART = RESULT_FIRST_USER + 2;
 



More information about the Android mailing list