├── app ├── .gitignore ├── proguard-debug-rules.pro ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── org │ │ │ │ └── xdty │ │ │ │ └── template │ │ │ │ ├── model │ │ │ │ ├── database │ │ │ │ │ ├── Database.java │ │ │ │ │ └── DatabaseImpl.java │ │ │ │ ├── setting │ │ │ │ │ ├── Setting.java │ │ │ │ │ └── SettingImpl.java │ │ │ │ ├── permission │ │ │ │ │ ├── Permission.java │ │ │ │ │ └── PermissionImpl.java │ │ │ │ └── db │ │ │ │ │ └── BaseManual.java │ │ │ │ ├── utils │ │ │ │ ├── Constants.java │ │ │ │ ├── Utils.java │ │ │ │ └── OkHttp.java │ │ │ │ ├── contract │ │ │ │ └── MainContract.java │ │ │ │ ├── jni │ │ │ │ └── Native.java │ │ │ │ ├── di │ │ │ │ ├── MainComponent.java │ │ │ │ ├── AppComponent.java │ │ │ │ └── modules │ │ │ │ │ ├── MainModule.java │ │ │ │ │ └── AppModule.java │ │ │ │ ├── presenter │ │ │ │ └── MainPresenter.java │ │ │ │ ├── application │ │ │ │ └── Application.java │ │ │ │ └── activity │ │ │ │ └── MainActivity.java │ │ ├── cpp │ │ │ └── native-lib.cpp │ │ └── AndroidManifest.xml │ ├── debug │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── org │ │ │ └── xdty │ │ │ └── template │ │ │ └── application │ │ │ └── DebugApplication.java │ ├── test │ │ └── java │ │ │ └── org │ │ │ └── xdty │ │ │ └── template │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── org │ │ └── xdty │ │ └── template │ │ └── ExampleInstrumentedTest.java ├── proguard-test-rules.pro ├── CMakeLists.txt ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── signing.properties.example ├── manifest.properties.example ├── gradle.properties ├── .gitlab-ci.yml ├── .gitignore ├── manifest.gradle ├── template.sh ├── signing.gradle ├── README.md ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /app/proguard-debug-rules.pro: -------------------------------------------------------------------------------- 1 | # Proguard rules that are applied to your test apk/code. 2 | -dontobfuscate -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Manual 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/Template/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/Template/master/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/Template/master/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /signing.properties.example: -------------------------------------------------------------------------------- 1 | storeFile=release.jks 2 | storePassword=keystore_password 3 | keyAlias=key_alias 4 | keyPassword=key_password 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/Template/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/Template/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /manifest.properties.example: -------------------------------------------------------------------------------- 1 | API_KEY=YOUR_API_KEY 2 | JUHE_API_KEY=YOUR_API_KEY 3 | LEANCLOUD_APP_ID=YOUR_APP_ID 4 | LEANCLOUD_APP_KEY=YOUR_APP_KEY -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/model/database/Database.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.model.database; 2 | 3 | public interface Database { 4 | } 5 | -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/model/setting/Setting.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.model.setting; 2 | 3 | public interface Setting { 4 | } 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/Template/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/Template/master/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/Template/master/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/Template/master/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/model/permission/Permission.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.model.permission; 2 | 3 | public interface Permission { 4 | } 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/Template/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/Template/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/utils/Constants.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.utils; 2 | 3 | public final class Constants { 4 | public final static String DB_NAME = "manual.db"; 5 | public final static int DB_VERSION = 1; 6 | } 7 | -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/contract/MainContract.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.contract; 2 | 3 | public interface MainContract { 4 | interface View { 5 | } 6 | 7 | interface Presenter { 8 | void start(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Feb 12 20:18:21 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/cpp/native-lib.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern "C" JNIEXPORT jstring 5 | 6 | JNICALL 7 | Java_org_xdty_template_jni_Native_stringFromJNI( 8 | JNIEnv *env, 9 | jobject /* this */) { 10 | std::string hello = "Hello from C++"; 11 | return env->NewStringUTF(hello.c_str()); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/jni/Native.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.jni; 2 | 3 | public class Native { 4 | 5 | public native String stringFromJNI(); 6 | 7 | private Native() {} 8 | 9 | public static Native getInstance() { 10 | return SingletonHelper.sINSTANCE; 11 | } 12 | 13 | private final static class SingletonHelper { 14 | private final static Native sINSTANCE = new Native(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/proguard-test-rules.pro: -------------------------------------------------------------------------------- 1 | # Proguard rules that are applied to your test apk/code. 2 | -dontobfuscate 3 | 4 | -ignorewarnings 5 | 6 | -keepattributes *Annotation* 7 | 8 | -dontnote junit.framework.** 9 | -dontnote junit.runner.** 10 | 11 | -dontwarn android.test.** 12 | -dontwarn android.support.test.** 13 | -dontwarn org.junit.** 14 | -dontwarn org.hamcrest.** 15 | -dontwarn com.squareup.javawriter.JavaWriter 16 | # Uncomment this if you use Mockito 17 | #-dontwarn org.mockito.** -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/di/MainComponent.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.di; 2 | 3 | import org.xdty.template.activity.MainActivity; 4 | import org.xdty.template.di.modules.AppModule; 5 | import org.xdty.template.di.modules.MainModule; 6 | 7 | import javax.inject.Singleton; 8 | 9 | import dagger.Component; 10 | 11 | @Singleton 12 | @Component(modules = { MainModule.class, AppModule.class }) 13 | public interface MainComponent { 14 | void inject(MainActivity mainActivity); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/test/java/org/xdty/template/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/presenter/MainPresenter.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.presenter; 2 | 3 | import org.xdty.template.application.Application; 4 | import org.xdty.template.contract.MainContract; 5 | 6 | public class MainPresenter implements MainContract.Presenter{ 7 | 8 | private MainContract.View mView; 9 | 10 | public MainPresenter(MainContract.View view) { 11 | mView = view; 12 | Application.getAppComponent().inject(this); 13 | } 14 | 15 | @Override 16 | public void start() { 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.utils; 2 | 3 | import com.google.gson.Gson; 4 | 5 | public class Utils { 6 | 7 | private Gson mGson; 8 | 9 | private Utils() { 10 | mGson = new Gson(); 11 | } 12 | 13 | public Gson getGson() { 14 | return mGson; 15 | } 16 | 17 | public static Utils getInstance() { 18 | return SingletonHelper.sINSTANCE; 19 | } 20 | 21 | private final static class SingletonHelper { 22 | private final static Utils sINSTANCE = new Utils(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/model/permission/PermissionImpl.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.model.permission; 2 | 3 | import android.content.Context; 4 | 5 | public class PermissionImpl implements Permission { 6 | 7 | private PermissionImpl() {} 8 | 9 | public void init(Context context) { 10 | 11 | } 12 | 13 | public static PermissionImpl getInstance() { 14 | return SingletonHelper.sINSTANCE; 15 | } 16 | 17 | private final static class SingletonHelper { 18 | private final static PermissionImpl sINSTANCE = new PermissionImpl(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/model/db/BaseManual.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.model.db; 2 | 3 | import io.requery.Column; 4 | import io.requery.Entity; 5 | import io.requery.Generated; 6 | import io.requery.Key; 7 | import io.requery.Table; 8 | 9 | @Table(name = "manual") 10 | @Entity 11 | public abstract class BaseManual { 12 | @Key 13 | @Generated 14 | @Column(name = "ID") 15 | int id; 16 | 17 | @Column(name = "COMMAND") 18 | String command; 19 | 20 | @Column(name = "DOCUMENT") 21 | String document; 22 | 23 | @Column(name = "UPDATE_TIME") 24 | long updateTime; 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/di/AppComponent.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.di; 2 | 3 | import org.xdty.template.application.Application; 4 | import org.xdty.template.di.modules.AppModule; 5 | import org.xdty.template.model.database.DatabaseImpl; 6 | import org.xdty.template.presenter.MainPresenter; 7 | 8 | import javax.inject.Singleton; 9 | 10 | import dagger.Component; 11 | 12 | @Singleton 13 | @Component(modules = AppModule.class) 14 | public interface AppComponent { 15 | void inject(Application application); 16 | 17 | void inject(MainPresenter mainPresenter); 18 | 19 | void inject(DatabaseImpl database); 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/di/modules/MainModule.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.di.modules; 2 | 3 | import org.xdty.template.contract.MainContract; 4 | import org.xdty.template.presenter.MainPresenter; 5 | 6 | import dagger.Module; 7 | import dagger.Provides; 8 | 9 | @Module 10 | public class MainModule { 11 | private MainContract.View mView; 12 | 13 | public MainModule(MainContract.View view) { 14 | mView = view; 15 | } 16 | 17 | @Provides 18 | MainContract.View provideView() { 19 | return mView; 20 | } 21 | 22 | @Provides 23 | MainContract.Presenter providePresenter() { 24 | return new MainPresenter(mView); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/model/database/DatabaseImpl.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.model.database; 2 | 3 | import org.xdty.template.application.Application; 4 | 5 | import javax.inject.Inject; 6 | 7 | import io.requery.Persistable; 8 | import io.requery.sql.EntityDataStore; 9 | 10 | public class DatabaseImpl implements Database { 11 | 12 | @Inject 13 | EntityDataStore mDataStore; 14 | 15 | private DatabaseImpl() { 16 | Application.getAppComponent().inject(this); 17 | } 18 | 19 | public static DatabaseImpl getInstance() { 20 | return SingletonHelper.sINSTANCE; 21 | } 22 | 23 | private final static class SingletonHelper { 24 | private final static DatabaseImpl sINSTANCE = new DatabaseImpl(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/model/setting/SettingImpl.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.model.setting; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.preference.PreferenceManager; 6 | 7 | public class SettingImpl implements Setting { 8 | 9 | private SharedPreferences mPrefs; 10 | 11 | private SettingImpl() { 12 | } 13 | 14 | public static SettingImpl getInstance() { 15 | return SingletonHelper.sINSTANCE; 16 | } 17 | 18 | public void init(Context context) { 19 | mPrefs = PreferenceManager.getDefaultSharedPreferences(context); 20 | } 21 | 22 | private final static class SingletonHelper { 23 | private final static SettingImpl sINSTANCE = new SettingImpl(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | android.enableJetifier=true 10 | android.useAndroidX=true 11 | org.gradle.jvmargs=-Xmx1536m 12 | # When configured, Gradle will run in incubating parallel mode. 13 | # This option should only be used with decoupled projects. More details, visit 14 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 15 | # org.gradle.parallel=true 16 | -------------------------------------------------------------------------------- /app/src/androidTest/java/org/xdty/template/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template; 2 | 3 | import android.content.Context; 4 | import androidx.test.InstrumentationRegistry; 5 | import androidx.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("org.xdty.template", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | image: xdtianyu/docker:openjdk8 2 | before_script: 3 | - git submodule sync --recursive 4 | - git submodule update --init --recursive 5 | - source /opt/setup-android-sdk.sh 6 | - source /opt/setup-android-ndk.sh 7 | - openssl aes-256-cbc -K $encrypted_key -iv $encrypted_iv -in release.jks.enc -out release.jks -d 8 | stages: 9 | - build 10 | - deploy 11 | build: 12 | stage: build 13 | script: 14 | - ./gradlew assembleDebug 15 | - ./gradlew assembleRelease 16 | artifacts: 17 | paths: 18 | - "**/build/outputs/apk/**/*.apk" 19 | - "**/build/outputs/mapping/release/mapping.txt" 20 | expire_in: 1 day 21 | release: 22 | stage: deploy 23 | script: 24 | - cp app/build/outputs/apk/release/*.apk . 25 | - cp app/build/outputs/mapping/release/mapping.txt . 26 | artifacts: 27 | paths: 28 | - "*.apk" 29 | - "mapping.txt" 30 | only: 31 | - tags 32 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 19 | 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Windows thumbnail db 19 | Thumbs.db 20 | 21 | # OSX files 22 | .DS_Store 23 | 24 | # Eclipse project files 25 | .classpath 26 | .project 27 | 28 | # Android Studio 29 | *.iml 30 | .idea 31 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs. 32 | .gradle 33 | build/ 34 | 35 | #NDK 36 | obj/ 37 | 38 | /*/out 39 | /*/*/build 40 | /*/*/production 41 | *.iws 42 | *.ipr 43 | *~ 44 | *.swp 45 | 46 | # release key file 47 | release.jks 48 | signing.properties 49 | manifest.properties 50 | 51 | *.log 52 | .externalNativeBuild 53 | 54 | *.iws 55 | *.ipr 56 | *~ 57 | *.swp 58 | 59 | # release key file 60 | release.jks 61 | signing.properties 62 | manifest.properties 63 | 64 | *.log 65 | -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/application/Application.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.application; 2 | 3 | import org.xdty.template.di.AppComponent; 4 | import org.xdty.template.di.DaggerAppComponent; 5 | import org.xdty.template.di.modules.AppModule; 6 | 7 | public class Application extends android.app.Application { 8 | 9 | static { 10 | System.loadLibrary("native-lib"); 11 | } 12 | 13 | private static AppComponent sAppComponent; 14 | 15 | private static Application sApplication; 16 | 17 | 18 | public static AppComponent getAppComponent() { 19 | return sAppComponent; 20 | } 21 | 22 | public static Application getApplication() { 23 | return sApplication; 24 | } 25 | 26 | @Override 27 | public void onCreate() { 28 | super.onCreate(); 29 | sApplication = this; 30 | 31 | sAppComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build(); 32 | sAppComponent.inject(this); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /manifest.gradle: -------------------------------------------------------------------------------- 1 | def manifestProperties = "manifest.properties" 2 | def manifestKeys = [ 3 | API_KEY : { x -> x }, 4 | ] 5 | 6 | // Find manifest.properties in project root, or in $HOME/.gradle 7 | def f = ["${rootDir}/${manifestProperties}", "${gradle.gradleUserHomeDir}/${manifestProperties}"].find { 8 | file(it).exists() 9 | } 10 | 11 | if (f) { 12 | logger.info "Loading manifest properties from ${f}" 13 | def props = new Properties() 14 | props.load(new FileInputStream(f)) 15 | 16 | // For each property apply it to the release manifest config 17 | manifestKeys.any { k, fn -> 18 | if (!props.containsKey(k)) { 19 | logger.error "Missing property ${k}" 20 | android.defaultConfig.manifestPlaceholders = null 21 | return true 22 | } 23 | android.defaultConfig.manifestPlaceholders[k] = fn(props[k]) 24 | logger.info "Setting property ${k}" 25 | } 26 | } else { 27 | logger.info "Missing ${manifestProperties} file" 28 | android.defaultConfig.manifestPlaceholders["API_KEY"] = "${System.env.API_KEY}" 29 | } 30 | -------------------------------------------------------------------------------- /template.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "$1" ]; then 4 | echo "$0 com.example.app" 5 | exit 0 6 | fi 7 | 8 | PKG="$1" 9 | ORIGIN_PATH="org.xdty.template" 10 | 11 | find ./app -type f -exec sed -i "s/${ORIGIN_PATH//./\\.}/$PKG/g" {} \; 12 | find ./app -type f -name *.cpp -exec sed -i "s/${ORIGIN_PATH//./_}/${PKG//./_}/g" {} \; 13 | 14 | ORIGIN_PATH="${ORIGIN_PATH//./\/}" 15 | PKG_PATH="${PKG//./\/}" 16 | 17 | mkdir -p "app/src/androidTest/java/${PKG_PATH}" 18 | mkdir -p "app/src/debug/java/${PKG_PATH}" 19 | mkdir -p "app/src/main/java/${PKG_PATH}" 20 | mkdir -p "app/src/test/java/${PKG_PATH}" 21 | 22 | mv app/src/androidTest/java/$ORIGIN_PATH/* "app/src/androidTest/java/${PKG_PATH}" 23 | mv app/src/debug/java/$ORIGIN_PATH/* "app/src/debug/java/${PKG_PATH}" 24 | mv app/src/main/java/$ORIGIN_PATH/* "app/src/main/java/${PKG_PATH}" 25 | mv app/src/test/java/$ORIGIN_PATH/* "app/src/test/java/${PKG_PATH}" 26 | 27 | rm -r "app/src/androidTest/java/$ORIGIN_PATH" 28 | rm -r "app/src/debug/java/$ORIGIN_PATH" 29 | rm -r "app/src/main/java/$ORIGIN_PATH" 30 | rm -r "app/src/test/java/$ORIGIN_PATH" 31 | 32 | find . -type d -empty -delete 33 | find . -type d -empty -delete 34 | -------------------------------------------------------------------------------- /signing.gradle: -------------------------------------------------------------------------------- 1 | def signingProperties = "signing.properties" 2 | def signingKeys = [ 3 | storeFile : { x -> rootProject.file(x) }, 4 | storePassword: { x -> x }, 5 | keyAlias : { x -> x }, 6 | keyPassword : { x -> x }, 7 | ] 8 | 9 | // Find signing.properties in project root, or in $HOME/.gradle 10 | def f = ["${rootDir}/${signingProperties}", "${gradle.gradleUserHomeDir}/${signingProperties}"].find { 11 | file(it).exists() 12 | } 13 | 14 | if (f) { 15 | logger.info "Loading signing properties from ${f}" 16 | def props = new Properties() 17 | props.load(new FileInputStream(f)) 18 | 19 | // For each property apply it to the release signing config 20 | signingKeys.any { k, fn -> 21 | if (!props.containsKey(k)) { 22 | logger.error "Missing property ${k}" 23 | android.buildTypes.release.signingConfig = null 24 | return true 25 | } 26 | android.signingConfigs.release[k] = fn(props[k]) 27 | logger.info "Setting property ${k}" 28 | } 29 | } else { 30 | logger.info "Missing ${signingProperties} file" 31 | android.signingConfigs.release["storeFile"] = rootProject.file("release.jks") 32 | android.signingConfigs.release["storePassword"] = "${System.env.KEYSTORE_PASSWORD}" 33 | android.signingConfigs.release["keyAlias"] = "${System.env.ALIAS}" 34 | android.signingConfigs.release["keyPassword"] = "${System.env.ALIAS_PASSWORD}" 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.activity; 2 | 3 | import android.os.Bundle; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import android.widget.TextView; 6 | 7 | import org.xdty.template.R; 8 | import org.xdty.template.application.Application; 9 | import org.xdty.template.contract.MainContract; 10 | import org.xdty.template.di.DaggerMainComponent; 11 | import org.xdty.template.di.modules.AppModule; 12 | import org.xdty.template.di.modules.MainModule; 13 | import org.xdty.template.jni.Native; 14 | import org.xdty.template.model.permission.Permission; 15 | 16 | import javax.inject.Inject; 17 | 18 | public class MainActivity extends AppCompatActivity implements MainContract.View { 19 | 20 | @Inject 21 | MainContract.Presenter mPresenter; 22 | 23 | @Inject 24 | Permission mPermission; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | 30 | DaggerMainComponent.builder() 31 | .appModule(new AppModule(Application.getApplication())) 32 | .mainModule(new MainModule(this)) 33 | .build() 34 | .inject(this); 35 | 36 | setContentView(R.layout.activity_main); 37 | 38 | TextView tv = findViewById(R.id.sample_text); 39 | tv.setText(Native.getInstance().stringFromJNI()); 40 | 41 | mPresenter.start(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /app/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # For more information about using CMake with Android Studio, read the 2 | # documentation: https://d.android.com/studio/projects/add-native-code.html 3 | 4 | # Sets the minimum version of CMake required to build the native library. 5 | 6 | cmake_minimum_required(VERSION 3.4.1) 7 | 8 | # Creates and names a library, sets it as either STATIC 9 | # or SHARED, and provides the relative paths to its source code. 10 | # You can define multiple libraries, and CMake builds them for you. 11 | # Gradle automatically packages shared libraries with your APK. 12 | 13 | add_library( # Sets the name of the library. 14 | native-lib 15 | 16 | # Sets the library as a shared library. 17 | SHARED 18 | 19 | # Provides a relative path to your source file(s). 20 | src/main/cpp/native-lib.cpp ) 21 | 22 | # Searches for a specified prebuilt library and stores the path as a 23 | # variable. Because CMake includes system libraries in the search path by 24 | # default, you only need to specify the name of the public NDK library 25 | # you want to add. CMake verifies that the library exists before 26 | # completing its build. 27 | 28 | find_library( # Sets the name of the path variable. 29 | log-lib 30 | 31 | # Specifies the name of the NDK library that 32 | # you want CMake to locate. 33 | log ) 34 | 35 | # Specifies libraries CMake should link to your target library. You 36 | # can link multiple libraries, such as libraries you define in this 37 | # build script, prebuilt third-party libraries, or system libraries. 38 | 39 | target_link_libraries( # Specifies the target library. 40 | native-lib 41 | 42 | # Links the target library to the log library 43 | # included in the NDK. 44 | ${log-lib} ) -------------------------------------------------------------------------------- /app/src/debug/java/org/xdty/template/application/DebugApplication.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.application; 2 | 3 | import android.os.StrictMode; 4 | 5 | import com.facebook.stetho.Stetho; 6 | import com.facebook.stetho.okhttp3.StethoInterceptor; 7 | 8 | import org.xdty.template.utils.OkHttp; 9 | 10 | import io.reactivex.Completable; 11 | import io.reactivex.functions.Action; 12 | import io.reactivex.schedulers.Schedulers; 13 | 14 | public class DebugApplication extends Application { 15 | private final static String TAG = DebugApplication.class.getSimpleName(); 16 | 17 | @Override 18 | public void onCreate() { 19 | 20 | StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() 21 | .detectAll() 22 | .penaltyLog() 23 | .build()); 24 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() 25 | .detectLeakedSqlLiteObjects() 26 | .detectLeakedClosableObjects() 27 | .penaltyLog() 28 | //.penaltyDeath() 29 | .build()); 30 | 31 | Completable.fromAction(new Action() { 32 | @Override 33 | public void run() throws Exception { 34 | Stetho.initialize( 35 | Stetho.newInitializerBuilder(DebugApplication.this) 36 | .enableDumpapp( 37 | Stetho.defaultDumperPluginsProvider(DebugApplication.this)) 38 | .enableWebKitInspector(Stetho.defaultInspectorModulesProvider( 39 | DebugApplication.this)) 40 | .build()); 41 | } 42 | }).subscribeOn(Schedulers.io()).subscribe(); 43 | 44 | OkHttp.getInstance().addNetworkInterceptor(new StethoInterceptor()); 45 | 46 | super.onCreate(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/utils/OkHttp.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.utils; 2 | 3 | import java.io.IOException; 4 | 5 | import okhttp3.HttpUrl; 6 | import okhttp3.Interceptor; 7 | import okhttp3.OkHttpClient; 8 | import okhttp3.Request; 9 | import okhttp3.Response; 10 | import okhttp3.logging.HttpLoggingInterceptor; 11 | 12 | public class OkHttp { 13 | private OkHttpClient.Builder mOkHttpBuilder; 14 | 15 | private OkHttp() { 16 | HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); 17 | loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.NONE); 18 | 19 | Interceptor interceptor = new Interceptor() { 20 | @Override 21 | public Response intercept(Chain chain) throws IOException { 22 | Request request = chain.request(); 23 | HttpUrl url = request.url() 24 | .newBuilder() 25 | //.addQueryParameter("timestamp", 26 | // Long.toString(System.currentTimeMillis() / 1000 / 60)) 27 | .build(); 28 | request = request.newBuilder().url(url).build(); 29 | return chain.proceed(request); 30 | } 31 | }; 32 | 33 | mOkHttpBuilder = new OkHttpClient.Builder() 34 | .addInterceptor(loggingInterceptor) 35 | .addInterceptor(interceptor); 36 | } 37 | 38 | public static OkHttp getInstance() { 39 | return SingletonHelper.INSTANCE; 40 | } 41 | 42 | public void addNetworkInterceptor(Interceptor interceptor) { 43 | mOkHttpBuilder.addNetworkInterceptor(interceptor); 44 | } 45 | 46 | public OkHttpClient client() { 47 | return mOkHttpBuilder.build(); 48 | } 49 | 50 | private static class SingletonHelper { 51 | private final static OkHttp INSTANCE = new OkHttp(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Android Studio Project Template 2 | 3 | 构建新的 Android Studio 工程,快速开始你的新 App 开发 4 | 5 | #### 集成的模块和功能库 6 | 7 | - [x] 一键修改包名及包路径结构 8 | - [x] 自动签名 9 | - [x] 版本号自动修改 (根据 git tag 及 tag 计数修改) 10 | - [x] 模块化 11 | - [x] 数据库ORM 12 | - [x] 优先单实例 13 | - [x] MVP 14 | - [x] Dagger2 15 | - [x] OkHttp3 16 | - [x] retrofit2 17 | - [x] Rxjava 18 | - [x] requerydb 19 | - [x] gson 20 | - [x] glide 21 | - [x] stetho (debug only) 22 | - [x] jni 23 | - [x] .gitignore 24 | - [x] test 依赖 25 | - [x] gitlab ci 26 | 27 | #### 使用 28 | 1\. 下载模板源码 29 | 30 | ```shell 31 | git clone https://github.com/xdtianyu/template 32 | ``` 33 | 34 | 2\. 更改包名 35 | 36 | 将应用包名更改为 `com.example.myapp` 37 | 38 | ```shell 39 | ./template.sh com.example.myapp 40 | ``` 41 | 42 | 3\. 使用 Android Studio 打开工程,`Build->Make Project` 会提示找不到 `release.jks` 43 | 44 | 4\. 拷贝或新建 `release.jks` 文件,放置在工程根目录。按照 `signing.properties.example` 文件新建 `signing.properties` 文件并修改签名密码和别名。 45 | 46 | 5\. 再次编译及安装应用 47 | 48 | #### 其他 49 | 50 | 1\. `manifest.properties` 可以用来替换 `manifest` 中的 `meta-data` 数据。和 `signing.properties` 相同,在 CI 编译服务器中不存在这些属性时,`gradle` 会读取系统环境变量替换这些信息。 51 | 52 | 2\. github ci 需要配置 `Secret variables` 53 | 54 | | 环境变量 | 说明 | 55 | | ----------------- | ------------------------- | 56 | | ALIAS | release.jks 别名 | 57 | | ALIAS_PASSWORD | release.jks 别名密码 | 58 | | API_KEY | 可选,注册在 Manifest 的 APK_KEY | 59 | | KEYSTORE_PASSWORD | release.jks 密码 | 60 | | encrypted_iv | release.jks.enc 解密 iv | 61 | | encrypted_key | release.jks.enc 解密 key | 62 | 63 | 要配置 gitlab 自动编译签名支持,需要将 `release.jks` 文件加密为 `release.jks.enc` 64 | 65 | **通过一个密文生成 iv 和 key** 66 | 67 | 替换 `I_AM_PUBLIC_AND_NOT_USED_FOR_RELEASE` 为任意字符串,建议30位以上随机字符串 68 | 69 | ```shell 70 | openssl enc -nosalt -aes-256-cbc -pass pass:I_AM_PUBLIC_AND_NOT_USED_FOR_RELEASE -P 71 | ``` 72 | 73 | ```shell 74 | key=12CF1B5E0D192628AA922230549EEDFD889E6CF7463933C6DABD9A1300FCA23D 75 | iv =66813CF28D04CD129D57436B78DECBA4 76 | ``` 77 | 78 | **使用生成的 key 和 iv 加密 release.jks 文件** 79 | 80 | 注意替换其中的 key 和 iv 值 81 | 82 | ``` 83 | openssl aes-256-cbc -K 12CF1B5E0D192628AA922230549EEDFD889E6CF7463933C6DABD9A1300FCA23D -iv 66813CF28D04CD129D57436B78DECBA4 -in release.jks -out release.jks.enc -e 84 | ``` 85 | 86 | 将 `release.jks.enc` 文件提交到代码仓库,同时配置 gitlab `Secret variables` 中的环境变量。 -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/ty/Android/Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | ##---------------Begin: proguard configuration for Gson ---------- 20 | # Gson uses generic type information stored in a class file when working with fields. Proguard 21 | # removes such information by default, so configure it to keep all of it. 22 | -keepattributes Signature 23 | 24 | # Gson specific classes 25 | -keep class sun.misc.Unsafe { *; } 26 | -keep class com.google.gson.stream.** { *; } 27 | -keepattributes *Annotation* 28 | -dontwarn javax.annotation.** 29 | -dontwarn javax.persistence.** 30 | -dontwarn javax.inject.** 31 | -dontwarn sun.misc.Unsafe 32 | 33 | # Application classes that will be serialized/deserialized over Gson 34 | -keep class org.xdty.phone.number.model.** { *; } 35 | 36 | # OKHttp 37 | -dontwarn rx.** 38 | 39 | -dontwarn okio.** 40 | 41 | -dontwarn com.squareup.okhttp.** 42 | -keep class com.squareup.okhttp.** { *; } 43 | -keep interface com.squareup.okhttp.** { *; } 44 | 45 | -dontwarn okhttp3.** 46 | -keep class okhttp3.** { *;} 47 | -keep interface okhttp3.** { *; } 48 | 49 | -dontwarn retrofit.** 50 | -dontwarn retrofit.appengine.UrlFetchClient 51 | -keep class retrofit.** { *; } 52 | -keepclasseswithmembers class * { 53 | @retrofit.http.* ; 54 | } 55 | 56 | -dontwarn retrofit2.** 57 | -dontwarn retrofit.appengine.UrlFetchClient 58 | -keep class retrofit.** { *; } 59 | -keepclasseswithmembers class * { 60 | @retrofit.http.* ; 61 | } 62 | 63 | # Retrofit 2.X 64 | ## https://square.github.io/retrofit/ ## 65 | 66 | -dontwarn retrofit2.** 67 | -keep class retrofit2.** { *; } 68 | -keepattributes Signature 69 | -keepattributes Exceptions 70 | 71 | -keepclasseswithmembers class * { 72 | @retrofit2.http.* ; 73 | } 74 | 75 | # Sugar 76 | -keep public class * extends com.orm.SugarApp 77 | -keep public class * extends com.orm.SugarRecord 78 | 79 | -keep class android.support.v7.** { public protected *; } 80 | -keep class android.support.v4.** { public protected *; } 81 | 82 | -keep class org.xdty.** { *; } 83 | -keep class com.facebook.stetho.** {*;} -------------------------------------------------------------------------------- /app/src/main/java/org/xdty/template/di/modules/AppModule.java: -------------------------------------------------------------------------------- 1 | package org.xdty.template.di.modules; 2 | 3 | import com.google.gson.Gson; 4 | 5 | import org.xdty.template.BuildConfig; 6 | import org.xdty.template.application.Application; 7 | import org.xdty.template.model.database.Database; 8 | import org.xdty.template.model.database.DatabaseImpl; 9 | import org.xdty.template.model.db.Models; 10 | import org.xdty.template.model.permission.Permission; 11 | import org.xdty.template.model.permission.PermissionImpl; 12 | import org.xdty.template.model.setting.Setting; 13 | import org.xdty.template.model.setting.SettingImpl; 14 | import org.xdty.template.utils.Constants; 15 | import org.xdty.template.utils.OkHttp; 16 | import org.xdty.template.utils.Utils; 17 | 18 | import javax.inject.Singleton; 19 | 20 | import dagger.Module; 21 | import dagger.Provides; 22 | import io.requery.Persistable; 23 | import io.requery.android.sqlite.DatabaseSource; 24 | import io.requery.sql.Configuration; 25 | import io.requery.sql.ConfigurationBuilder; 26 | import io.requery.sql.EntityDataStore; 27 | import okhttp3.OkHttpClient; 28 | 29 | @Module 30 | public class AppModule { 31 | private Application app; 32 | 33 | public AppModule(Application application) { 34 | app = application; 35 | } 36 | 37 | @Singleton 38 | @Provides 39 | public Application provideApplication() { 40 | return app; 41 | } 42 | 43 | @Singleton 44 | @Provides 45 | public Setting provideSetting(Application app) { 46 | SettingImpl setting = SettingImpl.getInstance(); 47 | setting.init(app); 48 | return setting; 49 | } 50 | 51 | @Singleton 52 | @Provides 53 | public Database provideDatabase() { 54 | return DatabaseImpl.getInstance(); 55 | } 56 | 57 | @Singleton 58 | @Provides 59 | public Permission providePermission(Application app) { 60 | PermissionImpl permission = PermissionImpl.getInstance(); 61 | permission.init(app); 62 | return permission; 63 | } 64 | 65 | @Singleton 66 | @Provides 67 | public Utils provideUtils() { 68 | return Utils.getInstance(); 69 | } 70 | 71 | @Singleton 72 | @Provides 73 | public Gson provideGson(Utils utils) { 74 | return utils.getGson(); 75 | } 76 | 77 | @Singleton 78 | @Provides 79 | public EntityDataStore provideDatabaseSource() { 80 | 81 | DatabaseSource source = new DatabaseSource(app, Models.DEFAULT, 82 | Constants.DB_NAME, Constants.DB_VERSION) { 83 | @Override 84 | protected void onConfigure(ConfigurationBuilder builder) { 85 | super.onConfigure(builder); 86 | builder.setQuoteColumnNames(true); 87 | } 88 | }; 89 | source.setLoggingEnabled(BuildConfig.DEBUG); 90 | Configuration configuration = source.getConfiguration(); 91 | 92 | return new EntityDataStore<>(configuration); 93 | } 94 | 95 | @Singleton 96 | @Provides 97 | public OkHttpClient provideOkHttpClient() { 98 | return OkHttp.getInstance().client(); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim() 4 | def gitTag = 'git describe --abbrev=0 --tags' 5 | .execute([], project.rootDir).text.trim().replaceAll("v", "") 6 | def gitTagCount = Integer.parseInt('git rev-list --tags --no-walk --count' 7 | .execute([], project.rootDir).text.trim()) 8 | 9 | android { 10 | compileSdkVersion rootProject.ext.compileSdkVersion 11 | defaultConfig { 12 | applicationId "org.xdty.template" 13 | minSdkVersion rootProject.ext.minSdkVersion 14 | targetSdkVersion rootProject.ext.targetSdkVersion 15 | 16 | versionCode gitTagCount 17 | versionName gitTag 18 | 19 | buildConfigField "String", "GIT_SHA", "\"${gitSha}\"" 20 | 21 | setProperty("archivesBaseName", "$rootProject.name-v$versionName") 22 | 23 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 24 | externalNativeBuild { 25 | cmake { 26 | cppFlags "-frtti -fexceptions" 27 | } 28 | } 29 | } 30 | 31 | signingConfigs { 32 | release 33 | } 34 | 35 | buildTypes { 36 | debug { 37 | minifyEnabled true 38 | shrinkResources true 39 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 40 | 'proguard-debug-rules.pro', 'proguard-rules.pro' 41 | testProguardFile('proguard-test-rules.pro') 42 | signingConfig signingConfigs.release 43 | } 44 | release { 45 | minifyEnabled true 46 | shrinkResources true 47 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 48 | signingConfig signingConfigs.release 49 | } 50 | } 51 | 52 | packagingOptions { 53 | exclude 'META-INF/maven/com.google.guava/guava/pom.properties' 54 | exclude 'META-INF/maven/com.google.guava/guava/pom.xml' 55 | } 56 | 57 | externalNativeBuild { 58 | cmake { 59 | path "CMakeLists.txt" 60 | } 61 | } 62 | } 63 | 64 | dependencies { 65 | implementation fileTree(dir: 'libs', include: ['*.jar']) 66 | implementation "androidx.appcompat:appcompat:${rootProject.ext.supportVersion}" 67 | 68 | implementation "androidx.cardview:cardview:${rootProject.ext.cardVersion}" 69 | implementation "androidx.recyclerview:recyclerview:${rootProject.ext.supportVersion}" 70 | implementation "com.google.android.material:material:${rootProject.ext.materialVersion}" 71 | implementation "androidx.browser:browser:${rootProject.ext.browserVersion}" 72 | 73 | implementation "androidx.constraintlayout:constraintlayout:${rootProject.ext.constraintVersion}" 74 | 75 | 76 | implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' 77 | implementation 'io.reactivex.rxjava2:rxjava:2.1.12' 78 | implementation "com.google.dagger:dagger:${rootProject.ext.daggerVersion}" 79 | annotationProcessor "com.google.dagger:dagger-compiler:${rootProject.ext.daggerVersion}" 80 | 81 | implementation "io.requery:requery:${rootProject.ext.requeryVersion}" 82 | implementation "io.requery:requery-android:${rootProject.ext.requeryVersion}" 83 | annotationProcessor "io.requery:requery-processor:${rootProject.ext.requeryVersion}" 84 | 85 | implementation 'com.google.code.gson:gson:2.8.2' 86 | implementation 'com.squareup.okhttp3:okhttp:3.10.0' 87 | implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1' 88 | implementation 'com.squareup.retrofit2:retrofit:2.3.0' 89 | implementation 'com.squareup.retrofit2:converter-gson:2.2.0' 90 | 91 | implementation 'com.github.bumptech.glide:glide:3.7.0' 92 | implementation('com.github.bumptech.glide:okhttp3-integration:1.4.0') { 93 | exclude group: 'glide-parent' 94 | } 95 | 96 | debugImplementation 'com.facebook.stetho:stetho:1.4.2' 97 | debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.4.2' 98 | debugImplementation 'com.facebook.stetho:stetho-okhttp:1.4.2' 99 | debugImplementation 'com.facebook.stetho:stetho-urlconnection:1.4.2' 100 | 101 | testImplementation 'junit:junit:4.12' 102 | androidTestImplementation 'androidx.test:runner:1.1.2-alpha01' 103 | 104 | androidTestImplementation "androidx.test.espresso:espresso-core:${rootProject.ext.espressoVersion}" 105 | androidTestImplementation "androidx.test.espresso:espresso-intents:${rootProject.ext.espressoVersion}" 106 | androidTestImplementation "androidx.test.espresso:espresso-idling-resource:${rootProject.ext.espressoVersion}" 107 | 108 | androidTestImplementation('androidx.test.espresso:espresso-contrib:3.1.0-alpha4') { 109 | exclude group: 'com.android.support', module: 'appcompat-v7' 110 | exclude group: 'com.android.support', module: 'support-v4' 111 | exclude group: 'com.android.support', module: 'design' 112 | exclude module: 'recyclerview-v7' 113 | } 114 | 115 | androidTestImplementation "androidx.annotation:annotation:${rootProject.ext.supportVersion}" 116 | 117 | androidTestImplementation 'androidx.test:runner:1.1.2-alpha01' 118 | // UiAutomator Testing 119 | androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' 120 | androidTestImplementation 'org.hamcrest:hamcrest-integration:1.3' 121 | 122 | androidTestImplementation 'androidx.test:rules:1.1.2-alpha01' 123 | 124 | } 125 | 126 | apply from: '../signing.gradle' 127 | apply from: '../manifest.gradle' -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 11 | 16 | 21 | 26 | 31 | 36 | 41 | 46 | 51 | 56 | 61 | 66 | 71 | 76 | 81 | 86 | 91 | 96 | 101 | 106 | 111 | 116 | 121 | 126 | 131 | 136 | 141 | 146 | 151 | 156 | 161 | 166 | 171 | 172 | --------------------------------------------------------------------------------