Skip to content

Commit

Permalink
add switch for login method
Browse files Browse the repository at this point in the history
  • Loading branch information
zfdang committed Apr 25, 2022
1 parent 09fe087 commit 7b54d95
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatDelegate;

import androidx.preference.CheckBoxPreference;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
Expand Down Expand Up @@ -45,6 +44,7 @@ public class MyPreferenceFragment extends PreferenceFragmentCompat {
CheckBoxPreference setting_volume_key_scroll;
ListPreference setting_fontsize_control;
CheckBoxPreference image_quality_control;
CheckBoxPreference login_with_verification;
CheckBoxPreference image_source_cdn;
CheckBoxPreference board_master_only;

Expand Down Expand Up @@ -162,6 +162,19 @@ public class MyPreferenceFragment extends PreferenceFragmentCompat {
}
});

login_with_verification = (CheckBoxPreference) findPreference("setting_login_with_verification");
login_with_verification.setChecked(Settings.getInstance().isLoginWithVerification());
login_with_verification.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean value = Settings.getInstance().isLoginWithVerification();
if (newValue instanceof Boolean) {
value = (Boolean) newValue;
}
Settings.getInstance().setLoginWithVerification(value);
return true;
}
});

image_source_cdn = (CheckBoxPreference) findPreference("setting_image_source_cdn");
image_source_cdn.setChecked(Settings.getInstance().isImageSourceCDN());
image_source_cdn.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
Expand Down
19 changes: 16 additions & 3 deletions app/src/main/java/com/zfdang/zsmth_android/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import com.zfdang.SMTHApplication;
import com.zfdang.devicemodeltomarketingname.DeviceMarketingName;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
* Usage:
* String username = Settings.getInstance().getUsername();
Expand Down Expand Up @@ -199,6 +196,21 @@ public void setLoadOriginalImage(boolean bLoadOriginalImage) {
}
}

// use normal login, or with verification
private static final String LOGIN_WITH_VERIFICATION = "LOGIN_WITH_VERIFICATION";
private boolean bLoginWithVerification;

public boolean isLoginWithVerification() {
return bLoginWithVerification;
}

public void setLoginWithVerification(boolean value) {
if (this.bLoginWithVerification != value) {
this.bLoginWithVerification = value;
mEditor.putBoolean(LOGIN_WITH_VERIFICATION, this.bLoginWithVerification);
mEditor.commit();
}
}

// load image from cdn, or from smth website directly
// https://www.mysmth.net/nForum/#!article/PocketLife/3100239
Expand Down Expand Up @@ -471,6 +483,7 @@ private void initSettings() {
mTarget = mPreference.getString(FORWARD_TAEGET, "");

bLoadOriginalImage = mPreference.getBoolean(LOAD_ORIGINAL_IMAGE, false);
bLoginWithVerification = mPreference.getBoolean(LOGIN_WITH_VERIFICATION, true);
bImageSourceCDN = mPreference.getBoolean(IMAGE_SOURCE_CDN, true);

bBoardMasterOnly = mPreference.getBoolean(BOARD_MASTER_ONLY, false);
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
android:summaryOn="总是加载原图(加载失败的可能性较大)"
android:title="图片质量"/>

<CheckBoxPreference
android:defaultValue="on"
android:key="setting_login_with_verification"
android:summaryOff="使用简单登录"
android:summaryOn="使用带验证的登录"
android:title="登录方式"/>

<CheckBoxPreference
android:defaultValue="on"
android:key="setting_image_source_cdn"
Expand Down

0 comments on commit 7b54d95

Please sign in to comment.