Skip to content

Commit

Permalink
优化逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed Sep 3, 2021
1 parent 6732014 commit 56bd0cc
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 16 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,37 @@ public static void configHostType(int dev,int test,int release){

saveAccount(Activity activity, int currentHostType, final String countryCode, String account, String pw)

# 示例代码

```java
public class BaseApp extends MultiDexApplication {

@Override
public void onCreate() {
super.onCreate();
AccountCacher.init("",true);
AccountCacher.storeReleaseAccount = true;
AccountCacher.configHostType(1,3,0);
}
}


登录页面:
AccountCacher.selectAccount(环境类型, this, "国家码", new AccountCallback() {
@Override
public void onSuccess(DebugAccount account) {
//将DebugAccount里的用户名密码 设置给登录页面的用户名,密码输入框
}

@Override
public void onError(Throwable error) {
error.printStackTrace();
}
});

//注册/登录成功后:
AccountCacher.saveAccount(this,环境类型,"国家码","用户名","明文密码");
```



Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public class AccountCacher {


static Application app;
static int TYPE_RELEASE = 0;
static int TYPE_TEST = 3;
static int TYPE_DEV = 1;
public static int TYPE_RELEASE = 0;
public static int TYPE_TEST = 3;
public static int TYPE_DEV = 1;

static boolean hasAdaptScopedStorage;
static String dbName = "";
Expand Down
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ android {
targetSdkVersion 30
versionCode 1
versionName "1.0"
multiDexEnabled true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -25,7 +26,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug{
minifyEnabled true
minifyEnabled false
}
}
compileOptions {
Expand All @@ -39,8 +40,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
//implementation project(path: ':accountcache')
implementation project(path: ':no-op')
implementation project(path: ':accountcache')
//implementation project(path: ':no-op')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hss01248.accountcacherdemo">

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".BaseApp"
android:requestLegacyExternalStorage="true"
android:theme="@style/Theme.AccountCacher">
<activity android:name=".MainActivity">
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/hss01248/accountcacherdemo/BaseApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.hss01248.accountcacherdemo;

import androidx.multidex.MultiDexApplication;

import com.hss01248.accountcache.AccountCacher;

public class BaseApp extends MultiDexApplication {

@Override
public void onCreate() {
super.onCreate();
AccountCacher.init("",true);
AccountCacher.storeReleaseAccount = true;
AccountCacher.configHostType(1,3,0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AccountCacher.init("",true);
}

public void select(View view) {
AccountCacher.selectAccount(AccountCacher.TYPE_TEST, this, "in", new AccountCallback() {
AccountCacher.selectAccount(0, this, "ch", new AccountCallback() {
@Override
public void onSuccess(DebugAccount account) {
Toast.makeText(MainActivity.this,account.toString(),Toast.LENGTH_LONG).show();
InputDialogUtil.showDialog(MainActivity.this, account, new InPutCallback() {
@Override
public void onGet(String account, String pw) {
AccountCacher.saveAccount(MainActivity.this,AccountCacher.TYPE_TEST,"in",account,pw);
AccountCacher.saveAccount(MainActivity.this,0,"ch",account,pw);
}
});
}
Expand All @@ -41,8 +40,8 @@ public void onError(Throwable error) {
}

public void save(View view) {
AccountCacher.saveAccount(this,AccountCacher.TYPE_TEST,"in","xiaomihuawei","1234556x");
AccountCacher.saveAccount(this,AccountCacher.TYPE_TEST,"in","bigfish","987654321y");
AccountCacher.saveAccount(this,AccountCacher.TYPE_TEST,"in","19684579154","abcdefg");
AccountCacher.saveAccount(this,0,"ch","xiaomihuawei","1234556x");
AccountCacher.saveAccount(this,0,"ch","bigfish","987654321y");
AccountCacher.saveAccount(this,1,"ch","19684579154","abcdefg");
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import java.util.function.Consumer

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
//apply from: 'https://raw.githubusercontent.com/hss01248/flipperUtil/master/remote3.gradle'
apply from: 'https://raw.githubusercontent.com/hss01248/flipperUtil/master/remote3.gradle'
repositories {
google()
jcenter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ public class AccountCacher {




public static int TYPE_RELEASE = 0;
public static int TYPE_TEST = 3;
public static int TYPE_DEV = 1;
public static boolean storeReleaseAccount;

public static void configHostType(int dev, int test, int release) {

TYPE_RELEASE = release;
TYPE_DEV = dev;
TYPE_TEST = test;
}

/**
Expand Down

0 comments on commit 56bd0cc

Please sign in to comment.