Skip to content

Commit

Permalink
提供no-op能力,开放存储正式环境账号功能
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed Sep 3, 2021
1 parent a320779 commit 6732014
Show file tree
Hide file tree
Showing 17 changed files with 336 additions and 20 deletions.
47 changes: 41 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# account cacher

测试账号加密后保存到sd卡(.yuv/databases/包名.testaccount2.db), 便于下次直接选择,不用再记账号.
测试账号加密后保存到sd卡(.yuv/databases/名字+testaccount2.db), 便于下次直接选择,不用再记账号.

默认只存储dev和test账号,不存储release账号(可配置存储).

提供no-op功能,便于上线.



只存储dev和test账号,不存储release账号.

会申请存储权限. 暂未适配Android api 30(即Android 11)存储权限



Expand All @@ -23,6 +27,10 @@ Add it in your root build.gradle at the end of repositories:
}
```



## 普通工程

**Step 2.** Add the dependency

```css
Expand All @@ -31,23 +39,49 @@ Add it in your root build.gradle at the end of repositories:
}
```

## 组件化工程

```groovy
dependencies {
implementation 'com.github.hss01248:accountCacher:1.0.0'
}
```











# api



![image-20210528093344350](/Users/hss/Library/Application Support/typora-user-images/image-20210528093344350.png)
![image-20210903101416745](https://gitee.com/hss012489/picbed/raw/master/picgo/1630635264025-image-20210903101416745.jpg)



```java
AccountCacher.storeReleaseAccount = true;//配置可存储正式环境账号
/*
* @param dbName 可以为空. 为空则存储于默认数据库
* @param hasAdaptScopedStorage 是否已经适配Android11的分区存储
*/
public static void init(@Nullable String dbName, boolean hasAdaptScopedStorage) {

public static void configHostType(int dev,int test,int release){
TYPE_RELEASE = release;
TYPE_DEV = dev;
TYPE_TEST = test;
}



/**
* 不会在正式环境弹出
*
* @param activity
* @param countryCode
Expand Down Expand Up @@ -79,4 +113,5 @@ public static void configHostType(int dev,int test,int release){

登录成功后调用:

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

6 changes: 3 additions & 3 deletions accountcache/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ plugins {
}

android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
compileSdkVersion 30
buildToolsVersion "30.0.0"

defaultConfig {
minSdkVersion 16
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"

Expand Down
2 changes: 2 additions & 0 deletions accountcache/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
package="com.hss01248.accountcache">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>


</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@
public class AccountCacher {


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

static boolean hasAdaptScopedStorage;
static String dbName = "";
/**
* 是否存储正式环境账号,默认false,可以设置为true
*/
public static boolean storeReleaseAccount;

public static void configHostType(int dev, int test, int release) {
TYPE_RELEASE = release;
Expand All @@ -58,18 +61,20 @@ static void init(Application application) {
}

/**
* 不会在正式环境弹出
*
* @param activity
* @param countryCode
* @param callback
*/
public static void selectAccount(int hostType, FragmentActivity activity, String countryCode, AccountCallback callback) {
init(activity.getApplication());
if (isNotDevOrTest(hostType)) {
callback.onError(new Throwable("isUrlRelease"));
return;
if(!storeReleaseAccount){
if ( isNotDevOrTest(hostType)) {
callback.onError(new Throwable("isUrlRelease"));
return;
}
}

/*if (clickCount < 2) {
clickCount++;
return;
Expand Down Expand Up @@ -182,9 +187,15 @@ private static String descs(int currentHostType) {
*/
public static void saveAccount(Activity activity, int currentHostType, final String countryCode, String account, String pw) {
init(activity.getApplication());
if (isNotDevOrTest(currentHostType) || TextUtils.isEmpty(account)) {
if(TextUtils.isEmpty(account)){
return;
}
if(!storeReleaseAccount){
if (isNotDevOrTest(currentHostType)) {
return;
}
}



XXPermissions.with(activity)
Expand Down
7 changes: 6 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ 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: ':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'
}

configurations {
// all*.exclude group: '', module: ''
}

project.afterEvaluate {
project.android.applicationVariants.each {variant ->
/*project.tasks.create(name : "showAllDependencies${variant.name.capitalize()}", group : "help", description: "Print all sdk(s) infomation. author:sodino") {
Expand Down
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/remote2.gradle'
//apply from: 'https://raw.githubusercontent.com/hss01248/flipperUtil/master/remote3.gradle'
repositories {
google()
jcenter()
Expand Down
1 change: 1 addition & 0 deletions no-op/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
39 changes: 39 additions & 0 deletions no-op/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
plugins {
id 'com.android.library'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.2.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
api "com.google.code.gson:gson:2.8.5"
}
Empty file added no-op/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions no-op/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.hss01248.accountcache.no_op;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.hss01248.accountcache.no_op.test", appContext.getPackageName());
}
}
5 changes: 5 additions & 0 deletions no-op/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hss01248.accountcache.no_op">

</manifest>
63 changes: 63 additions & 0 deletions no-op/src/main/java/com/hss01248/accountcache/AccountCacher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.hss01248.accountcache;

import android.app.Activity;

import android.app.Application;


import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;


/**
* by hss
* data:2020-04-27
* desc:
*/
public class AccountCacher {




public static boolean storeReleaseAccount;

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

}

/**
* 非必须
*
* @param dbName 可以为空. 为空则存储于默认数据库
* @param hasAdaptScopedStorage 是否已经适配Android11的分区存储
*/
public static void init(@Nullable String dbName, boolean hasAdaptScopedStorage) {

}

/**
*
* @param activity
* @param countryCode
* @param callback
*/
public static void selectAccount(int hostType, FragmentActivity activity, String countryCode, AccountCallback callback) {

}



/**
* 登录成功后,保存账号密码
* 不会保存正式服的账号密码
*
* @param countryCode
* @param account
* @param pw
*/
public static void saveAccount(Activity activity, int currentHostType, final String countryCode, String account, String pw) {

}


}
13 changes: 13 additions & 0 deletions no-op/src/main/java/com/hss01248/accountcache/AccountCallback.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.hss01248.accountcache;

/**
* by hss
* data:2020-04-27
* desc:
*/
public interface AccountCallback {

void onSuccess(DebugAccount account);

void onError(Throwable error);
}
Loading

0 comments on commit 6732014

Please sign in to comment.