mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 00:02:20 +02:00
Add Keep me logged in option
This commit is contained in:
parent
3d677d8e5a
commit
a1221ebd69
5 changed files with 85 additions and 57 deletions
|
@ -24,6 +24,9 @@
|
|||
#include <udt/PacketHeaders.h>
|
||||
#include <SettingHandle.h>
|
||||
|
||||
#define AUTO_LOGOUT_SETTING_NAME "wallet/autoLogout"
|
||||
#define WALLET_USERNAME_SETTING_NAME "wallet/savedUsername"
|
||||
|
||||
QAndroidJniObject __interfaceActivity;
|
||||
QAndroidJniObject __loginCompletedListener;
|
||||
QAndroidJniObject __signupCompletedListener;
|
||||
|
@ -258,6 +261,55 @@ JNIEXPORT jstring JNICALL Java_io_highfidelity_hifiinterface_fragment_HomeFragme
|
|||
return env->NewStringUTF(lastLocation.toString().toLatin1().data());
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_io_highfidelity_hifiinterface_HifiUtils_updateHifiSetting(JNIEnv *env, jobject instance,
|
||||
jstring group_, jstring key_,
|
||||
jboolean value_) {
|
||||
const char *c_group = env->GetStringUTFChars(group_, 0);
|
||||
const char *c_key = env->GetStringUTFChars(key_, 0);
|
||||
|
||||
const QString group = QString::fromUtf8(c_group);
|
||||
const QString key = QString::fromUtf8(c_key);
|
||||
|
||||
env->ReleaseStringUTFChars(group_, c_group);
|
||||
env->ReleaseStringUTFChars(key_, c_key);
|
||||
|
||||
bool value = value_;
|
||||
|
||||
Setting::Handle<bool> setting { QStringList() << group << key , !value };
|
||||
setting.set(value);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_io_highfidelity_hifiinterface_HifiUtils_getHifiSettingBoolean(JNIEnv *env,
|
||||
jobject instance,
|
||||
jstring group_,
|
||||
jstring key_,
|
||||
jboolean defaultValue) {
|
||||
const char *c_group = env->GetStringUTFChars(group_, 0);
|
||||
const char *c_key = env->GetStringUTFChars(key_, 0);
|
||||
|
||||
const QString group = QString::fromUtf8(c_group);
|
||||
const QString key = QString::fromUtf8(c_key);
|
||||
|
||||
env->ReleaseStringUTFChars(group_, c_group);
|
||||
env->ReleaseStringUTFChars(key_, c_key);
|
||||
|
||||
Setting::Handle<bool> setting { QStringList() << group << key , defaultValue};
|
||||
return setting.get();
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_io_highfidelity_hifiinterface_HifiUtils_isUserLoggedIn(JNIEnv *env, jobject instance) {
|
||||
return DependencyManager::get<AccountManager>()->isLoggedIn();
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_io_highfidelity_hifiinterface_HifiUtils_isKeepingLoggedIn(JNIEnv *env, jobject instance) {
|
||||
Setting::Handle<bool> setting(AUTO_LOGOUT_SETTING_NAME, true);
|
||||
return !setting.get();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_io_highfidelity_hifiinterface_fragment_LoginFragment_cancelLogin(JNIEnv *env, jobject instance) {
|
||||
|
||||
|
@ -277,7 +329,8 @@ Java_io_highfidelity_hifiinterface_fragment_SignupFragment_cancelLogin(JNIEnv *e
|
|||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_io_highfidelity_hifiinterface_fragment_LoginFragment_login(JNIEnv *env, jobject instance,
|
||||
jstring username_, jstring password_) {
|
||||
jstring username_, jstring password_,
|
||||
jboolean keepLoggedIn) {
|
||||
const char *c_username = env->GetStringUTFChars(username_, 0);
|
||||
const char *c_password = env->GetStringUTFChars(password_, 0);
|
||||
QString username = QString(c_username);
|
||||
|
@ -289,11 +342,14 @@ Java_io_highfidelity_hifiinterface_fragment_LoginFragment_login(JNIEnv *env, job
|
|||
|
||||
__loginCompletedListener = QAndroidJniObject(instance);
|
||||
|
||||
QObject::connect(accountManager.data(), &AccountManager::loginComplete, [](const QUrl& authURL) {
|
||||
QObject::connect(accountManager.data(), &AccountManager::loginComplete, [username, keepLoggedIn](const QUrl& authURL) {
|
||||
jboolean jSuccess = (jboolean) true;
|
||||
if (__loginCompletedListener.isValid()) {
|
||||
__loginCompletedListener.callMethod<void>("handleLoginCompleted", "(Z)V", jSuccess);
|
||||
}
|
||||
Setting::Handle<QVariant>(AUTO_LOGOUT_SETTING_NAME).set(!keepLoggedIn);
|
||||
QString usernameToSave = keepLoggedIn ? username : "";
|
||||
Setting::Handle<QVariant>(WALLET_USERNAME_SETTING_NAME).set(usernameToSave);
|
||||
});
|
||||
|
||||
QObject::connect(accountManager.data(), &AccountManager::loginFailed, []() {
|
||||
|
@ -311,8 +367,9 @@ JNIEXPORT void JNICALL
|
|||
Java_io_highfidelity_hifiinterface_fragment_SignupFragment_login(JNIEnv *env,
|
||||
jobject instance,
|
||||
jstring username_,
|
||||
jstring password_) {
|
||||
Java_io_highfidelity_hifiinterface_fragment_LoginFragment_login(env, instance, username_, password_);
|
||||
jstring password_,
|
||||
jboolean keepLoggedIn) {
|
||||
Java_io_highfidelity_hifiinterface_fragment_LoginFragment_login(env, instance, username_, password_, keepLoggedIn);
|
||||
}
|
||||
|
||||
JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeInitAfterAppLoaded(JNIEnv* env, jobject obj) {
|
||||
|
@ -387,10 +444,6 @@ Java_io_highfidelity_hifiinterface_SplashActivity_registerLoadCompleteListener(J
|
|||
});
|
||||
|
||||
}
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_io_highfidelity_hifiinterface_HifiUtils_isUserLoggedIn(JNIEnv *env, jobject instance) {
|
||||
return DependencyManager::get<AccountManager>()->isLoggedIn();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_io_highfidelity_hifiinterface_MainActivity_logout(JNIEnv *env, jobject instance) {
|
||||
|
@ -445,46 +498,6 @@ JNIEXPORT void Java_io_highfidelity_hifiinterface_WebViewActivity_nativeProcessU
|
|||
AndroidHelper::instance().processURL(QString::fromUtf8(nativeString));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_io_highfidelity_hifiinterface_fragment_SettingsFragment_updateHifiSetting(JNIEnv *env,
|
||||
jobject instance,
|
||||
jstring group_,
|
||||
jstring key_,
|
||||
jboolean value_) {
|
||||
const char *c_group = env->GetStringUTFChars(group_, 0);
|
||||
const char *c_key = env->GetStringUTFChars(key_, 0);
|
||||
|
||||
const QString group = QString::fromUtf8(c_group);
|
||||
const QString key = QString::fromUtf8(c_key);
|
||||
|
||||
env->ReleaseStringUTFChars(group_, c_group);
|
||||
env->ReleaseStringUTFChars(key_, c_key);
|
||||
|
||||
bool value = value_;
|
||||
|
||||
Setting::Handle<bool> setting { QStringList() << group << key , !value };
|
||||
setting.set(value);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_io_highfidelity_hifiinterface_fragment_SettingsFragment_getHifiSettingBoolean(JNIEnv *env,
|
||||
jobject instance,
|
||||
jstring group_,
|
||||
jstring key_,
|
||||
jboolean defaultValue) {
|
||||
const char *c_group = env->GetStringUTFChars(group_, 0);
|
||||
const char *c_key = env->GetStringUTFChars(key_, 0);
|
||||
|
||||
const QString group = QString::fromUtf8(c_group);
|
||||
const QString key = QString::fromUtf8(c_key);
|
||||
|
||||
env->ReleaseStringUTFChars(group_, c_group);
|
||||
env->ReleaseStringUTFChars(key_, c_key);
|
||||
|
||||
Setting::Handle<bool> setting { QStringList() << group << key , defaultValue};
|
||||
return setting.get();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_io_highfidelity_hifiinterface_receiver_HeadsetStateReceiver_notifyHeadsetOn(JNIEnv *env,
|
||||
jobject instance,
|
||||
|
|
|
@ -66,5 +66,8 @@ public class HifiUtils {
|
|||
|
||||
public native boolean isUserLoggedIn();
|
||||
|
||||
public native void updateHifiSetting(String group, String key, boolean value);
|
||||
public native boolean getHifiSettingBoolean(String group, String key, boolean defaultValue);
|
||||
|
||||
public native boolean isKeepingLoggedIn();
|
||||
}
|
||||
|
|
|
@ -12,11 +12,13 @@ import android.view.ViewGroup;
|
|||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.qtproject.qt5.android.QtNative;
|
||||
|
||||
import io.highfidelity.hifiinterface.HifiUtils;
|
||||
import io.highfidelity.hifiinterface.R;
|
||||
|
||||
import static org.qtproject.qt5.android.QtActivityDelegate.ApplicationActive;
|
||||
|
@ -29,13 +31,14 @@ public class LoginFragment extends Fragment
|
|||
private EditText mPassword;
|
||||
private TextView mError;
|
||||
private Button mLoginButton;
|
||||
private CheckBox mKeepMeLoggedInCheckbox;
|
||||
private ViewGroup mLoginForm;
|
||||
private ViewGroup mLoggingInFrame;
|
||||
private ViewGroup mLoggedInFrame;
|
||||
private boolean mLoginInProgress;
|
||||
private boolean mLoginSuccess;
|
||||
|
||||
public native void login(String username, String password, Fragment usernameChangedListener);
|
||||
public native void login(String username, String password, boolean keepLoggedIn);
|
||||
public native void cancelLogin();
|
||||
|
||||
private LoginFragment.OnLoginInteractionListener mListener;
|
||||
|
@ -61,6 +64,7 @@ public class LoginFragment extends Fragment
|
|||
mLoginForm = rootView.findViewById(R.id.loginForm);
|
||||
mLoggingInFrame = rootView.findViewById(R.id.loggingInFrame);
|
||||
mLoggedInFrame = rootView.findViewById(R.id.loggedInFrame);
|
||||
mKeepMeLoggedInCheckbox = rootView.findViewById(R.id.keepMeLoggedIn);
|
||||
|
||||
rootView.findViewById(R.id.forgotPassword).setOnClickListener(view -> onForgotPasswordClicked());
|
||||
|
||||
|
@ -73,6 +77,8 @@ public class LoginFragment extends Fragment
|
|||
rootView.findViewById(R.id.takeMeInWorld).setOnClickListener(view -> skipLogin());
|
||||
mPassword.setOnEditorActionListener((textView, actionId, keyEvent) -> onPasswordEditorAction(textView, actionId, keyEvent));
|
||||
|
||||
mKeepMeLoggedInCheckbox.setChecked(HifiUtils.getInstance().isKeepingLoggedIn());
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
|
@ -147,7 +153,8 @@ public class LoginFragment extends Fragment
|
|||
showActivityIndicator();
|
||||
mLoginInProgress = true;
|
||||
mLoginSuccess = false;
|
||||
login(username, password, this);
|
||||
boolean keepUserLoggedIn = mKeepMeLoggedInCheckbox.isChecked();
|
||||
login(username, password, keepUserLoggedIn);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,13 +7,11 @@ import android.preference.Preference;
|
|||
import android.preference.PreferenceFragment;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import io.highfidelity.hifiinterface.HifiUtils;
|
||||
import io.highfidelity.hifiinterface.R;
|
||||
|
||||
public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
public native void updateHifiSetting(String group, String key, boolean value);
|
||||
public native boolean getHifiSettingBoolean(String group, String key, boolean defaultValue);
|
||||
|
||||
private final String HIFI_SETTINGS_ANDROID_GROUP = "Android";
|
||||
private final String HIFI_SETTINGS_AEC_KEY = "aec";
|
||||
private final String PREFERENCE_KEY_AEC = "aec";
|
||||
|
@ -28,7 +26,7 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer
|
|||
}
|
||||
|
||||
getPreferenceScreen().getSharedPreferences().edit().putBoolean(PREFERENCE_KEY_AEC,
|
||||
getHifiSettingBoolean(HIFI_SETTINGS_ANDROID_GROUP, HIFI_SETTINGS_AEC_KEY, false));
|
||||
HifiUtils.getInstance().getHifiSettingBoolean(HIFI_SETTINGS_ANDROID_GROUP, HIFI_SETTINGS_AEC_KEY, false));
|
||||
}
|
||||
|
||||
public static SettingsFragment newInstance() {
|
||||
|
@ -54,7 +52,7 @@ public class SettingsFragment extends PreferenceFragment implements SharedPrefer
|
|||
Preference pref = findPreference(key);
|
||||
switch (key) {
|
||||
case "aec":
|
||||
updateHifiSetting(HIFI_SETTINGS_ANDROID_GROUP, HIFI_SETTINGS_AEC_KEY, sharedPreferences.getBoolean(key, false));
|
||||
HifiUtils.getInstance().updateHifiSetting(HIFI_SETTINGS_ANDROID_GROUP, HIFI_SETTINGS_AEC_KEY, sharedPreferences.getBoolean(key, false));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -10,11 +10,13 @@ import android.view.ViewGroup;
|
|||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.qtproject.qt5.android.QtNative;
|
||||
|
||||
import io.highfidelity.hifiinterface.HifiUtils;
|
||||
import io.highfidelity.hifiinterface.R;
|
||||
|
||||
import static org.qtproject.qt5.android.QtActivityDelegate.ApplicationActive;
|
||||
|
@ -29,6 +31,7 @@ public class SignupFragment extends Fragment
|
|||
private TextView mError;
|
||||
private TextView mActivityText;
|
||||
private Button mSignupButton;
|
||||
private CheckBox mKeepMeLoggedInCheckbox;
|
||||
|
||||
private ViewGroup mSignupForm;
|
||||
private ViewGroup mLoggingInFrame;
|
||||
|
@ -40,7 +43,7 @@ public class SignupFragment extends Fragment
|
|||
|
||||
public native void signup(String email, String username, String password); // move to SignupFragment
|
||||
public native void cancelSignup();
|
||||
public native void login(String username, String password);
|
||||
public native void login(String username, String password, boolean keepLoggedIn);
|
||||
public native void cancelLogin();
|
||||
|
||||
private SignupFragment.OnSignupInteractionListener mListener;
|
||||
|
@ -65,6 +68,7 @@ public class SignupFragment extends Fragment
|
|||
mError = rootView.findViewById(R.id.error);
|
||||
mSignupButton = rootView.findViewById(R.id.signupButton);
|
||||
mActivityText = rootView.findViewById(R.id.activityText);
|
||||
mKeepMeLoggedInCheckbox = rootView.findViewById(R.id.keepMeLoggedIn);
|
||||
|
||||
mSignupForm = rootView.findViewById(R.id.signupForm);
|
||||
mLoggedInFrame = rootView.findViewById(R.id.loggedInFrame);
|
||||
|
@ -78,6 +82,8 @@ public class SignupFragment extends Fragment
|
|||
|
||||
mPassword.setOnEditorActionListener((textView, actionId, keyEvent) -> onPasswordEditorAction(textView, actionId, keyEvent));
|
||||
|
||||
mKeepMeLoggedInCheckbox.setChecked(HifiUtils.getInstance().isKeepingLoggedIn());
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
|
@ -201,7 +207,8 @@ public class SignupFragment extends Fragment
|
|||
mActivityText.setText(R.string.logging_in);
|
||||
});
|
||||
mLoginInProgress = true;
|
||||
login(username, password);
|
||||
boolean keepUserLoggedIn = mKeepMeLoggedInCheckbox.isChecked();
|
||||
login(username, password, keepUserLoggedIn);
|
||||
}
|
||||
|
||||
public void handleSignupFailed(String error) {
|
||||
|
|
Loading…
Reference in a new issue