├── app
├── libs
│ └── .empty
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── themes.xml
│ │ │ ├── values-land
│ │ │ │ └── dimens.xml
│ │ │ ├── values-w1240dp
│ │ │ │ └── dimens.xml
│ │ │ ├── values-w600dp
│ │ │ │ └── dimens.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ ├── layout
│ │ │ │ ├── content_login.xml
│ │ │ │ ├── fragment_second.xml
│ │ │ │ ├── activity_login.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── fragment_first.xml
│ │ │ ├── navigation
│ │ │ │ └── nav_graph.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── johnnymillergh
│ │ │ │ └── android
│ │ │ │ └── androidjetpackmvvmboilerplate
│ │ │ │ ├── common
│ │ │ │ ├── package-info.java
│ │ │ │ ├── configuration
│ │ │ │ │ ├── package-info.java
│ │ │ │ │ ├── database
│ │ │ │ │ │ ├── LocalDateTimeConverters.kt
│ │ │ │ │ │ ├── DemoSQLiteDatabase.kt
│ │ │ │ │ │ └── DatabaseModule.kt
│ │ │ │ │ └── network
│ │ │ │ │ │ └── NetworkModule.kt
│ │ │ │ └── DebounceAndThrottle.kt
│ │ │ │ ├── main
│ │ │ │ ├── dao
│ │ │ │ │ └── UserVisitRecordDao.kt
│ │ │ │ ├── model
│ │ │ │ │ └── UserVisitRecord.kt
│ │ │ │ ├── repository
│ │ │ │ │ └── MainActivityRepository.kt
│ │ │ │ ├── viewmodel
│ │ │ │ │ └── MainActivityVM.kt
│ │ │ │ └── view
│ │ │ │ │ └── MainActivity.kt
│ │ │ │ ├── login
│ │ │ │ ├── service
│ │ │ │ │ └── DemoService.kt
│ │ │ │ ├── viewmodel
│ │ │ │ │ ├── FirstFragmentVM.kt
│ │ │ │ │ └── SecondFragmentVM.kt
│ │ │ │ ├── repository
│ │ │ │ │ └── SecondFragmentRepository.kt
│ │ │ │ ├── model
│ │ │ │ │ └── NetworkUserListItem.kt
│ │ │ │ └── view
│ │ │ │ │ ├── LoginActivity.kt
│ │ │ │ │ ├── FirstFragment.kt
│ │ │ │ │ └── SecondFragment.kt
│ │ │ │ └── AndroidJetpackMvvmBoilerplateApplication.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── github
│ │ │ └── johnnymillergh
│ │ │ └── android
│ │ │ └── androidjetpackmvvmboilerplate
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── johnnymillergh
│ │ └── android
│ │ └── androidjetpackmvvmboilerplate
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── ajmb.keystore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── settings.gradle
├── .github
└── workflows
│ └── main.yml
├── gradle.properties
├── CHANGELOG.md
├── gradlew.bat
├── .gitignore
├── README.md
├── gradlew
└── LICENSE
/app/libs/.empty:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /schemas/
3 |
--------------------------------------------------------------------------------
/ajmb.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/HEAD/ajmb.keystore
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 48dp
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w1240dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 200dp
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 48dp
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/common/package-info.java:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.common;
2 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/common/configuration/package-info.java:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.common.configuration;
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Sep 04 11:43:56 CST 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | dependencyResolutionManagement {
2 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
3 | repositories {
4 | google()
5 | mavenCentral()
6 | jcenter() // Warning: this repository is going to shut down soon
7 | }
8 | }
9 | rootProject.name = "Android Jetpack MVVM Boilerplate"
10 | include ':app'
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
11 |
--------------------------------------------------------------------------------
/app/src/test/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate
2 |
3 | import org.junit.Assert.assertEquals
4 | import org.junit.Test
5 |
6 | /**
7 | * Example local unit test, which will execute on the development machine (host).
8 | *
9 | * See [testing documentation](http://d.android.com/tools/testing).
10 | */
11 | class ExampleUnitTest {
12 | @Test
13 | fun addition_isCorrect() {
14 | assertEquals(4, 2 + 2)
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/main/dao/UserVisitRecordDao.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.main.dao
2 |
3 | import androidx.room.Dao
4 | import androidx.room.Insert
5 | import androidx.room.Query
6 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.main.model.UserVisitRecord
7 |
8 | @Dao
9 | interface UserVisitRecordDao {
10 | @Insert
11 | fun insert(userVisitRecord: UserVisitRecord)
12 |
13 | @Query("SELECT * FROM user_visit_record order by visit_time DESC")
14 | fun selectAll(): List
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/login/service/DemoService.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.service
2 |
3 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.model.NetworkUserListItem
4 | import retrofit2.http.GET
5 |
6 | /**
7 | * DemoService
8 | *
9 | * Change description here.
10 | *
11 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, 9/6/21: 8:47 PM
12 | **/
13 | interface DemoService {
14 | @GET("/repos/square/retrofit/stargazers")
15 | suspend fun getUserList(): List
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Android Jetpack MVVM Boilerplate
3 | LoginActivity
4 |
5 | First Fragment
6 | Second Fragment
7 | Next
8 | Previous
9 |
10 | Hello first fragment
11 | Hello second fragment. Arg: %1$s
12 | Click Me
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/login/viewmodel/FirstFragmentVM.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.viewmodel
2 |
3 | import androidx.lifecycle.MutableLiveData
4 | import androidx.lifecycle.ViewModel
5 | import dagger.hilt.android.lifecycle.HiltViewModel
6 | import javax.inject.Inject
7 |
8 | /**
9 | * FirstFragmentVM
10 | *
11 | * Change description here.
12 | *
13 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, 9/4/21: 7:52 PM
14 | **/
15 | @HiltViewModel
16 | class FirstFragmentVM @Inject constructor() : ViewModel() {
17 | val message = MutableLiveData().apply {
18 | value = "Hello from 1st fragment"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/AndroidJetpackMvvmBoilerplateApplication.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate
2 |
3 | import android.app.Application
4 | import dagger.hilt.android.HiltAndroidApp
5 | import timber.log.Timber
6 |
7 | /**
8 | * AndroidJetpackMvvmBoilerplateApplication
9 | *
10 | * Change description here.
11 | *
12 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 9/4/21 1:20 PM
13 | **/
14 | @HiltAndroidApp
15 | class AndroidJetpackMvvmBoilerplateApplication : Application() {
16 | override fun onCreate() {
17 | super.onCreate()
18 | if (BuildConfig.DEBUG) {
19 | Timber.plant(Timber.DebugTree())
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/main/model/UserVisitRecord.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.main.model;
2 |
3 | import androidx.room.ColumnInfo
4 | import androidx.room.Entity;
5 | import androidx.room.PrimaryKey
6 | import java.time.LocalDateTime
7 |
8 | /**
9 | * Description: UserVisitRecord, change description here.
10 | *
11 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 9/6/2021 4:26 PM
12 | **/
13 | @Entity(tableName = "user_visit_record")
14 | data class UserVisitRecord constructor(
15 | @PrimaryKey(autoGenerate = true)
16 | val id: Long?,
17 | val user: String,
18 | @ColumnInfo(name = "visit_time")
19 | val visitTime: LocalDateTime,
20 | @ColumnInfo(name = "os_version")
21 | val osVersion: String
22 | )
23 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/common/configuration/database/LocalDateTimeConverters.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.common.configuration.database
2 |
3 | import androidx.room.TypeConverter
4 | import java.time.Instant
5 | import java.time.LocalDateTime
6 | import java.time.ZoneOffset
7 |
8 | /**
9 | * Description: LocalDateTimeConverters, change description here.
10 | *
11 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 9/6/2021 5:21 PM
12 | **/
13 | class LocalDateTimeConverters {
14 | @TypeConverter
15 | fun fromTimestamp(value: Long?): LocalDateTime? {
16 | return value?.let { LocalDateTime.ofInstant(Instant.ofEpochMilli(it), ZoneOffset.of("+8")) }
17 | }
18 |
19 | @TypeConverter
20 | fun dateToTimestamp(date: LocalDateTime?): Long? {
21 | return date?.atZone(ZoneOffset.of("+8"))?.toInstant()?.toEpochMilli()
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate
2 |
3 | import androidx.test.ext.junit.runners.AndroidJUnit4
4 | import androidx.test.platform.app.InstrumentationRegistry
5 | import org.junit.Assert.assertEquals
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | /**
10 | * Instrumented test, which will execute on an Android device.
11 | *
12 | * See [testing documentation](http://d.android.com/tools/testing).
13 | */
14 | @RunWith(AndroidJUnit4::class)
15 | class ExampleInstrumentedTest {
16 | @Test
17 | fun useAppContext() {
18 | // Context of the app under test.
19 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
20 | assertEquals(
21 | "com.github.johnnymillergh.android.androidjetpackmvvmboilerplate",
22 | appContext.packageName
23 | )
24 | }
25 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/login/repository/SecondFragmentRepository.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.repository
2 |
3 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.model.NetworkUserListItem
4 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.service.DemoService
5 | import timber.log.Timber
6 | import javax.inject.Inject
7 |
8 | /**
9 | * SecondFragmentRepository
10 | *
11 | * Change description here.
12 | *
13 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, 9/6/21: 8:50 PM
14 | **/
15 | class SecondFragmentRepository @Inject constructor(
16 | private val demoService: DemoService
17 | ) {
18 | suspend fun refreshUserList(): List {
19 | return try {
20 | demoService.getUserList()
21 | } catch (e: Exception) {
22 | Timber.e(
23 | e,
24 | "Exception occurred when getting user list! Exception message: ${e.message}"
25 | )
26 | emptyList()
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/common/configuration/database/DemoSQLiteDatabase.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.common.configuration.database
2 |
3 | import androidx.room.Database
4 | import androidx.room.RoomDatabase
5 | import androidx.room.TypeConverters
6 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.BuildConfig
7 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.main.dao.UserVisitRecordDao
8 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.main.model.UserVisitRecord
9 |
10 | /**
11 | * Description: DemoSQLiteDatabase, change description here.
12 | *
13 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 9/6/2021 3:53 PM
14 | **/
15 | @Database(
16 | entities = [
17 | UserVisitRecord::class
18 | ],
19 | version = BuildConfig.DATABASE_VERSION_CODE
20 | )
21 | @TypeConverters(
22 | value = [
23 | LocalDateTimeConverters::class
24 | ]
25 | )
26 | abstract class DemoSQLiteDatabase : RoomDatabase() {
27 | abstract val userVisitRecordDao: UserVisitRecordDao
28 | }
29 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: Android CI
2 |
3 | # Controls when the workflow will run
4 | on:
5 | # Triggers the workflow on push or pull request events but only for the main branch
6 | push:
7 | branches:
8 | - 'feature/**'
9 | - 'main'
10 | paths-ignore:
11 | - '**.md'
12 |
13 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
14 | jobs:
15 | # This workflow contains a single job called "build"
16 | build:
17 | # The type of runner that the job will run on
18 | runs-on: ubuntu-latest
19 | # Steps represent a sequence of tasks that will be executed as part of the job
20 | steps:
21 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
22 | - uses: actions/checkout@v2
23 | - name: Set Up JDK
24 | uses: actions/setup-java@v2.3.0
25 | with:
26 | java-version: '11.0.10'
27 | distribution: 'adopt-hotspot'
28 | - name: Change Wrapper and Shellscipts Permissions
29 | run: |
30 | chmod +x ./gradlew
31 | # chmod +x ./shell/*.sh
32 | - name: Build Project
33 | run: ./gradlew clean build
34 |
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/navigation/nav_graph.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
17 |
18 |
23 |
24 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
15 |
20 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/common/configuration/database/DatabaseModule.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.common.configuration.database
2 |
3 | import android.content.Context
4 | import androidx.room.Room
5 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.main.dao.UserVisitRecordDao
6 | import dagger.Module
7 | import dagger.Provides
8 | import dagger.hilt.InstallIn
9 | import dagger.hilt.android.qualifiers.ApplicationContext
10 | import dagger.hilt.components.SingletonComponent
11 | import javax.inject.Singleton
12 |
13 | /**
14 | * DatabaseModule
15 | *
16 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 9/6/2021 3:36 PM
17 | */
18 | @Module
19 | @InstallIn(SingletonComponent::class)
20 | object DatabaseModule {
21 | @Provides
22 | @Singleton
23 | fun provideDemoSQLiteDatabase(@ApplicationContext appContext: Context): DemoSQLiteDatabase {
24 | return Room
25 | .databaseBuilder(
26 | appContext,
27 | DemoSQLiteDatabase::class.java,
28 | "DemoSQLite.db"
29 | )
30 | .fallbackToDestructiveMigration()
31 | .build()
32 | }
33 |
34 | @Provides
35 | fun provideChannelDao(demoSQLiteDatabase: DemoSQLiteDatabase): UserVisitRecordDao {
36 | return demoSQLiteDatabase.userVisitRecordDao
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
14 |
15 |
23 |
24 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
33 |
34 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # 1.0 (2021-09-07)
2 |
3 |
4 | ### Features
5 |
6 | * **$app:** add Gradle dependencies ([ab63e88](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/commit/ab63e88fc108bde421b368f3d2f2a48e4dbbcf2b))
7 | * **$app:** add Jetpack MVVM demo ([26c88d5](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/commit/26c88d514ddc9e4a508dd0c7af876e8dc93f8396))
8 | * **$app:** define default global theme ([b89caa9](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/commit/b89caa942ef6fcfb665e41410907e5ddef6c4356))
9 | * **$app:** main activity supports MVVM ([6e7d428](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/commit/6e7d428a6f1a1995fcc9e1accead9a54049119fb))
10 | * **$Retrofit:** support network request ([3059ffc](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/commit/3059ffc0727ea823d961af75805fea3260876499))
11 | * **$Room:** support Room ORM operation ([ca0957c](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/commit/ca0957c97964283869cfe5aa26630a0205b5016d))
12 |
13 |
14 | ### Performance Improvements
15 |
16 | * **$debounce:** refine view's clickable process ([8311178](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/commit/8311178dd7814d13993e8b0586410240c72a6f80))
17 | * **$debounce:** support disable click of the view ([be0269c](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/commit/be0269ca3fb4cdb61db63e4694ae9bf12abe5a01))
18 | * **$RxJava:** support click debounce and throttle ([410460f](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/commit/410460fc48d8eb9694a4f74b1840827f0ae2f40a))
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/main/repository/MainActivityRepository.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.main.repository;
2 |
3 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.common.configuration.database.DemoSQLiteDatabase
4 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.main.model.UserVisitRecord
5 | import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
6 | import io.reactivex.rxjava3.core.Observable
7 | import io.reactivex.rxjava3.core.ObservableEmitter
8 | import io.reactivex.rxjava3.schedulers.Schedulers
9 | import timber.log.Timber
10 | import javax.inject.Inject
11 |
12 | /**
13 | * Description: MainActivityRepository, change description here.
14 | *
15 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 9/6/2021 6:08 PM
16 | **/
17 | class MainActivityRepository @Inject constructor(
18 | private val demoSQLiteDatabase: DemoSQLiteDatabase
19 | ) {
20 | fun saveUserVisitRecord(userVisitRecord: UserVisitRecord) {
21 | Observable.create { emitter: ObservableEmitter ->
22 | Timber.i("Asynchronously saving user visited data. Current thread: ${Thread.currentThread()}")
23 | demoSQLiteDatabase.userVisitRecordDao.insert(userVisitRecord)
24 | emitter.onNext(userVisitRecord)
25 | }
26 | .observeOn(AndroidSchedulers.mainThread())
27 | .subscribeOn(Schedulers.io())
28 | .subscribe {
29 | Timber.i("Saved user visit record into database: $it. Current thread: ${Thread.currentThread()}")
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/login/model/NetworkUserListItem.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.model
2 |
3 |
4 | import com.squareup.moshi.Json
5 | import com.squareup.moshi.JsonClass
6 |
7 | /**
8 | * NetworkUserListItem
9 | *
10 | * Change description here.
11 | *
12 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, 9/6/21: 8:47 PM
13 | **/
14 | @JsonClass(generateAdapter = true)
15 | data class NetworkUserListItem(
16 | @Json(name = "avatar_url")
17 | val avatarUrl: String,
18 | @Json(name = "events_url")
19 | val eventsUrl: String,
20 | @Json(name = "followers_url")
21 | val followersUrl: String,
22 | @Json(name = "following_url")
23 | val followingUrl: String,
24 | @Json(name = "gists_url")
25 | val gistsUrl: String,
26 | @Json(name = "gravatar_id")
27 | val gravatarId: String,
28 | @Json(name = "html_url")
29 | val htmlUrl: String,
30 | @Json(name = "id")
31 | val id: Int,
32 | @Json(name = "login")
33 | val login: String,
34 | @Json(name = "node_id")
35 | val nodeId: String,
36 | @Json(name = "organizations_url")
37 | val organizationsUrl: String,
38 | @Json(name = "received_events_url")
39 | val receivedEventsUrl: String,
40 | @Json(name = "repos_url")
41 | val reposUrl: String,
42 | @Json(name = "site_admin")
43 | val siteAdmin: Boolean,
44 | @Json(name = "starred_url")
45 | val starredUrl: String,
46 | @Json(name = "subscriptions_url")
47 | val subscriptionsUrl: String,
48 | @Json(name = "type")
49 | val type: String,
50 | @Json(name = "url")
51 | val url: String
52 | )
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/login/viewmodel/SecondFragmentVM.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.viewmodel
2 |
3 | import androidx.lifecycle.LiveData
4 | import androidx.lifecycle.MutableLiveData
5 | import androidx.lifecycle.ViewModel
6 | import androidx.lifecycle.viewModelScope
7 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.model.NetworkUserListItem
8 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.repository.SecondFragmentRepository
9 | import dagger.hilt.android.lifecycle.HiltViewModel
10 | import kotlinx.coroutines.Dispatchers
11 | import kotlinx.coroutines.launch
12 | import timber.log.Timber
13 | import javax.inject.Inject
14 |
15 | /**
16 | * SecondFragmentVM
17 | *
18 | * Change description here.
19 | *
20 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, 9/6/21: 9:03 PM
21 | **/
22 | @HiltViewModel
23 | class SecondFragmentVM @Inject constructor(
24 | private val secondFragmentRepository: SecondFragmentRepository
25 | ) : ViewModel() {
26 | private val _userList =
27 | MutableLiveData>(emptyList())
28 | val userList: LiveData> get() = _userList
29 |
30 | init {
31 | viewModelScope.launch(Dispatchers.IO) {
32 | val refreshUserList = secondFragmentRepository.refreshUserList()
33 | if (!refreshUserList.isNullOrEmpty()) {
34 | _userList.postValue(refreshUserList.subList(0, 1))
35 | }
36 | Timber.i("Got user list, current thread: ${Thread.currentThread()}, list: $refreshUserList")
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
11 |
12 |
13 |
17 |
18 |
27 |
28 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/main/viewmodel/MainActivityVM.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.main.viewmodel
2 |
3 | import android.os.Build
4 | import androidx.lifecycle.MutableLiveData
5 | import androidx.lifecycle.ViewModel
6 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.main.model.UserVisitRecord
7 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.main.repository.MainActivityRepository
8 | import dagger.hilt.android.lifecycle.HiltViewModel
9 | import timber.log.Timber
10 | import java.time.LocalDateTime
11 | import javax.inject.Inject
12 |
13 | /**
14 | * MainActivityVM
15 | *
16 | * Change description here.
17 | *
18 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, 9/4/21: 9:41 PM
19 | **/
20 | @HiltViewModel
21 | class MainActivityVM @Inject constructor(
22 | private val mainActivityRepository: MainActivityRepository
23 | ) : ViewModel() {
24 | val clickMeCounter = MutableLiveData(0)
25 | private val helloMessage = MutableLiveData("Hello world!")
26 |
27 | fun increaseClickMeCounter() {
28 | Timber.i("Increase click me counter (MutableLiveData): $clickMeCounter")
29 | clickMeCounter.value = clickMeCounter.value?.inc()
30 | }
31 |
32 | fun concatMessage(): CharSequence {
33 | return "${helloMessage.value}: ${clickMeCounter.value}"
34 | }
35 |
36 | fun saveUserVisitRecord() {
37 | mainActivityRepository.saveUserVisitRecord(
38 | UserVisitRecord(
39 | null,
40 | Build.USER,
41 | LocalDateTime.now(),
42 | Build.VERSION.RELEASE
43 | )
44 | )
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/common/configuration/network/NetworkModule.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.common.configuration.network
2 |
3 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.BuildConfig
4 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.service.DemoService
5 | import dagger.Module
6 | import dagger.Provides
7 | import dagger.hilt.InstallIn
8 | import dagger.hilt.components.SingletonComponent
9 | import okhttp3.OkHttpClient
10 | import okhttp3.logging.HttpLoggingInterceptor
11 | import retrofit2.Retrofit
12 | import retrofit2.converter.moshi.MoshiConverterFactory
13 | import javax.inject.Singleton
14 |
15 | /**
16 | * NetworkModule
17 | *
18 | * Change description here.
19 | *
20 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, 9/6/21: 8:47 PM
21 | **/
22 | @Module
23 | @InstallIn(SingletonComponent::class)
24 | object NetworkModule {
25 | @Provides
26 | @Singleton
27 | fun provideOkHttpClient() = if (BuildConfig.DEBUG) {
28 | val loggingInterceptor = HttpLoggingInterceptor()
29 | loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY)
30 | OkHttpClient.Builder()
31 | .addInterceptor(loggingInterceptor)
32 | .build()
33 | } else {
34 | OkHttpClient
35 | .Builder()
36 | .build()
37 | }
38 |
39 | @Provides
40 | @Singleton
41 | fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit =
42 | Retrofit.Builder()
43 | .addConverterFactory(MoshiConverterFactory.create())
44 | .baseUrl("https://api.github.com")
45 | .client(okHttpClient)
46 | .build()
47 |
48 | @Provides
49 | @Singleton
50 | fun provideApiService(retrofit: Retrofit): DemoService =
51 | retrofit.create(DemoService::class.java)
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/login/view/LoginActivity.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.view
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import androidx.navigation.findNavController
6 | import androidx.navigation.ui.AppBarConfiguration
7 | import androidx.navigation.ui.navigateUp
8 | import androidx.navigation.ui.setupActionBarWithNavController
9 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.R
10 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.common.setDebounceClickListener
11 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.databinding.ActivityLoginBinding
12 | import com.google.android.material.snackbar.Snackbar
13 | import dagger.hilt.android.AndroidEntryPoint
14 |
15 | @AndroidEntryPoint
16 | class LoginActivity : AppCompatActivity() {
17 | private lateinit var appBarConfiguration: AppBarConfiguration
18 | private lateinit var binding: ActivityLoginBinding
19 |
20 | override fun onCreate(savedInstanceState: Bundle?) {
21 | super.onCreate(savedInstanceState)
22 |
23 | binding = ActivityLoginBinding.inflate(layoutInflater)
24 | setContentView(binding.root)
25 |
26 | setSupportActionBar(binding.toolbar)
27 |
28 | val navController = findNavController(R.id.nav_host_fragment_content_login)
29 | appBarConfiguration = AppBarConfiguration(navController.graph)
30 | setupActionBarWithNavController(navController, appBarConfiguration)
31 |
32 | binding.fab.setDebounceClickListener { view ->
33 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
34 | .setAction("Action", null).show()
35 | }
36 | }
37 |
38 | override fun onSupportNavigateUp(): Boolean {
39 | val navController = findNavController(R.id.nav_host_fragment_content_login)
40 | return navController.navigateUp(appBarConfiguration)
41 | || super.onSupportNavigateUp()
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/login/view/FirstFragment.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.view
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import androidx.fragment.app.viewModels
9 | import androidx.navigation.fragment.findNavController
10 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.R
11 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.common.setDebounceClickListener
12 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.databinding.FragmentFirstBinding
13 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.viewmodel.FirstFragmentVM
14 | import dagger.hilt.android.AndroidEntryPoint
15 |
16 | /**
17 | * A simple [Fragment] subclass as the default destination in the navigation.
18 | */
19 | @AndroidEntryPoint
20 | class FirstFragment : Fragment() {
21 | private val vm: FirstFragmentVM by viewModels()
22 |
23 | private var _binding: FragmentFirstBinding? = null
24 |
25 | // This property is only valid between onCreateView and onDestroyView.
26 | private val binding get() = _binding!!
27 |
28 | override fun onCreateView(
29 | inflater: LayoutInflater, container: ViewGroup?,
30 | savedInstanceState: Bundle?
31 | ): View? {
32 | _binding = FragmentFirstBinding.inflate(inflater, container, false)
33 | binding.vm = vm
34 | binding.lifecycleOwner = viewLifecycleOwner
35 | return binding.root
36 | }
37 |
38 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
39 | super.onViewCreated(view, savedInstanceState)
40 |
41 | binding.buttonFirst.setDebounceClickListener(250L) {
42 | findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment)
43 | }
44 | }
45 |
46 | override fun onDestroyView() {
47 | super.onDestroyView()
48 | _binding = null
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/login/view/SecondFragment.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.view
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import androidx.fragment.app.viewModels
9 | import androidx.navigation.fragment.findNavController
10 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.R
11 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.common.setDebounceClickListener
12 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.databinding.FragmentSecondBinding
13 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.viewmodel.SecondFragmentVM
14 | import dagger.hilt.android.AndroidEntryPoint
15 | import kotlinx.android.synthetic.main.fragment_second.*
16 |
17 | /**
18 | * A simple [Fragment] subclass as the second destination in the navigation.
19 | */
20 | @AndroidEntryPoint
21 | class SecondFragment : Fragment() {
22 | private val vm: SecondFragmentVM by viewModels()
23 |
24 | private var _binding: FragmentSecondBinding? = null
25 |
26 | // This property is only valid between onCreateView and onDestroyView.
27 | private val binding get() = _binding!!
28 |
29 | override fun onCreateView(
30 | inflater: LayoutInflater, container: ViewGroup?,
31 | savedInstanceState: Bundle?
32 | ): View? {
33 | _binding = FragmentSecondBinding.inflate(inflater, container, false)
34 | binding.lifecycleOwner = viewLifecycleOwner
35 | return binding.root
36 | }
37 |
38 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
39 | super.onViewCreated(view, savedInstanceState)
40 |
41 | binding.buttonSecond.setDebounceClickListener(250L) {
42 | findNavController().navigate(R.id.action_SecondFragment_to_FirstFragment)
43 | }
44 | vm.userList.observe(viewLifecycleOwner, {
45 | networkResponseTextView.text = it.toString()
46 | })
47 | }
48 |
49 | override fun onDestroyView() {
50 | super.onDestroyView()
51 | _binding = null
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_first.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
11 |
12 |
13 |
17 |
18 |
27 |
28 |
41 |
42 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/main/view/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.main.view
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import android.os.PersistableBundle
6 | import android.widget.Button
7 | import androidx.activity.viewModels
8 | import androidx.appcompat.app.AppCompatActivity
9 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.common.setDebounceClickListener
10 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.databinding.ActivityMainBinding
11 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.login.view.LoginActivity
12 | import com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.main.viewmodel.MainActivityVM
13 | import dagger.hilt.android.AndroidEntryPoint
14 | import kotlinx.android.synthetic.main.activity_main.*
15 | import timber.log.Timber
16 | import java.time.LocalDateTime
17 |
18 | /**
19 | * MainActivity
20 | *
21 | * Change description here.
22 | *
23 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, 9/4/21: 12:15 PM
24 | **/
25 | @AndroidEntryPoint
26 | class MainActivity : AppCompatActivity() {
27 | private val vm: MainActivityVM by viewModels()
28 | private lateinit var binding: ActivityMainBinding
29 |
30 | override fun onCreate(savedInstanceState: Bundle?) {
31 | super.onCreate(savedInstanceState)
32 | binding = ActivityMainBinding.inflate(layoutInflater)
33 | setContentView(binding.root)
34 | binding.vm = vm
35 | setListener()
36 | serObserver()
37 | vm.saveUserVisitRecord()
38 | }
39 |
40 | override fun onPostCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
41 | super.onPostCreate(savedInstanceState, persistentState)
42 | Timber.i("onPostCreate")
43 | }
44 |
45 | private fun serObserver() {
46 | vm.clickMeCounter.observe(this, {
47 | Timber.i("clickMeCounter has changed. newValue: $it")
48 | textView2.text = vm.concatMessage()
49 | })
50 | }
51 |
52 | private fun setListener() {
53 | clickMeButton.setDebounceClickListener(250L) {
54 | vm.increaseClickMeCounter()
55 | Timber.i("${(it as Button).text} was clicked clickMeCounter: ${vm.clickMeCounter.value}")
56 | this.startActivity(Intent(this, LoginActivity().javaClass))
57 | }
58 | }
59 |
60 | override fun onStart() {
61 | super.onStart()
62 | Timber.i("onStart() was called at %s", LocalDateTime.now())
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/johnnymillergh/android/androidjetpackmvvmboilerplate/common/DebounceAndThrottle.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("unused")
2 |
3 | package com.github.johnnymillergh.android.androidjetpackmvvmboilerplate.common
4 |
5 | import android.view.View
6 | import io.reactivex.rxjava3.core.Observable
7 | import io.reactivex.rxjava3.core.ObservableEmitter
8 | import io.reactivex.rxjava3.core.ObservableOnSubscribe
9 | import io.reactivex.rxjava3.disposables.Disposable
10 | import timber.log.Timber
11 | import java.util.concurrent.TimeUnit
12 |
13 | /**
14 | * Set on shake proof click listener
15 | * @receiver View the clickable view
16 | * @param duration Long default 1000 milliseconds
17 | * @param unit TimeUnit default unit is milliseconds
18 | * @param listener Function1<[@kotlin.ParameterName] View, Unit> the listener for executing main processing logic after debouncing click
19 | * @return Disposable Disposable
20 | * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, 9/5/21: 9:49 PM
21 | * @see Android Kotlin 使用 Rxjava 实现防止快速点击(防抖动)
22 | */
23 | @JvmOverloads
24 | fun View.setDebounceClickListener(
25 | duration: Long = 1000L,
26 | unit: TimeUnit = TimeUnit.MILLISECONDS,
27 | disableClick: Boolean = true,
28 | listener: (view: View) -> Unit
29 | ): Disposable {
30 | return Observable.create { emitter: ObservableEmitter ->
31 | setOnClickListener {
32 | if (!emitter.isDisposed) {
33 | if (disableClick && it.isClickable) {
34 | it.isClickable = false
35 | Timber.d("Disabled view click. Current thread: ${Thread.currentThread()}")
36 | }
37 | Timber.d("Emitter is emitting for the next event. Current thread: ${Thread.currentThread()}")
38 | emitter.onNext(it)
39 | }
40 | }
41 | }
42 | .debounce(duration, unit)
43 | .subscribe {
44 | Timber.d("Before executing callback listener. Current thread: ${Thread.currentThread()}")
45 | it.post {
46 | Timber.d("Executing callback listener. Current thread: ${Thread.currentThread()}")
47 | listener(it)
48 | if (disableClick && !it.isClickable) {
49 | it.isClickable = true
50 | Timber.d("Enabled view click. Current thread: ${Thread.currentThread()}")
51 | }
52 | }
53 | }
54 | }
55 |
56 | /**
57 | * Set throttle click listener
58 | * @receiver View the clickable view
59 | * @param duration Long default 1000 milliseconds
60 | * @param unit TimeUnit default unit is milliseconds
61 | * @param listener Function1<[@kotlin.ParameterName] View, Unit> the listener for executing main processing logic after throttling click
62 | * @return Disposable Disposable
63 | */
64 | @JvmOverloads
65 | fun View.setThrottleClickListener(
66 | duration: Long = 1000L,
67 | unit: TimeUnit = TimeUnit.MILLISECONDS,
68 | listener: (view: View) -> Unit
69 | ): Disposable {
70 | return Observable.create(ObservableOnSubscribe { emitter ->
71 | setOnClickListener {
72 | if (!emitter.isDisposed) {
73 | Timber.d("Emitter is emitting for the next event. Current thread: ${Thread.currentThread()}")
74 | emitter.onNext(it)
75 | }
76 | }
77 | })
78 | .throttleFirst(duration, unit)
79 | .subscribe {
80 | Timber.d("Before executing callback listener. Current thread: ${Thread.currentThread()}")
81 | it.post {
82 | Timber.d("Executing callback listener. Current thread: ${Thread.currentThread()}")
83 | listener(it)
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### Example user template template
2 | ### Example user template
3 | *.iml
4 | .gradle
5 | /local.properties
6 | /.idea/caches
7 | /.idea/libraries
8 | /.idea/modules.xml
9 | /.idea/workspace.xml
10 | /.idea/navEditor.xml
11 | /.idea/assetWizardSettings.xml
12 | .DS_Store
13 | /build
14 | /captures
15 | .externalNativeBuild
16 | .cxx
17 | local.properties
18 |
19 | ### Android template
20 | # Built application files
21 | *.apk
22 | *.aar
23 | *.ap_
24 | *.aab
25 |
26 | # Files for the ART/Dalvik VM
27 | *.dex
28 |
29 | # Java class files
30 | *.class
31 |
32 | # Generated files
33 | bin/
34 | gen/
35 | out/
36 | # Uncomment the following line in case you need and you don't have the release build type files in your app
37 | # release/
38 |
39 | # Gradle files
40 | .gradle/
41 | build/
42 |
43 | # Local configuration file (sdk path, etc)
44 | local.properties
45 |
46 | # Proguard folder generated by Eclipse
47 | proguard/
48 |
49 | # Log Files
50 | *.log
51 |
52 | # Android Studio Navigation editor temp files
53 | .navigation/
54 |
55 | # Android Studio captures folder
56 | captures/
57 |
58 | # IntelliJ
59 | *.iml
60 | .idea/workspace.xml
61 | .idea/tasks.xml
62 | .idea/gradle.xml
63 | .idea/assetWizardSettings.xml
64 | .idea/dictionaries
65 | .idea/libraries
66 | # Android Studio 3 in .gitignore file.
67 | .idea/caches
68 | .idea/modules.xml
69 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you
70 | .idea/navEditor.xml
71 |
72 | # Keystore files
73 | # Uncomment the following lines if you do not want to check your keystore files in.
74 | #*.jks
75 | #*.keystore
76 |
77 | # External native build folder generated in Android Studio 2.2 and later
78 | .externalNativeBuild
79 | .cxx/
80 |
81 | # Google Services (e.g. APIs or Firebase)
82 | # google-services.json
83 |
84 | # Freeline
85 | freeline.py
86 | freeline/
87 | freeline_project_description.json
88 |
89 | # fastlane
90 | fastlane/report.xml
91 | fastlane/Preview.html
92 | fastlane/screenshots
93 | fastlane/test_output
94 | fastlane/readme.md
95 |
96 | # Version control
97 | vcs.xml
98 |
99 | # lint
100 | lint/intermediates/
101 | lint/generated/
102 | lint/outputs/
103 | lint/tmp/
104 | # lint/reports/
105 |
106 | # Android Profiling
107 | *.hprof
108 |
109 | ### Gradle template
110 | .gradle
111 | **/build/
112 | !src/**/build/
113 |
114 | # Ignore Gradle GUI config
115 | gradle-app.setting
116 |
117 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
118 | !gradle-wrapper.jar
119 |
120 | # Cache of project
121 | .gradletasknamecache
122 |
123 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
124 | # gradle/wrapper/gradle-wrapper.properties
125 |
126 | # IntelliJ project files
127 | .idea
128 | *.iml
129 | out
130 | gen
131 | ### JetBrains template
132 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
133 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
134 |
135 | # User-specific stuff
136 | .idea/**/workspace.xml
137 | .idea/**/tasks.xml
138 | .idea/**/usage.statistics.xml
139 | .idea/**/dictionaries
140 | .idea/**/shelf
141 |
142 | # Generated files
143 | .idea/**/contentModel.xml
144 |
145 | # Sensitive or high-churn files
146 | .idea/**/dataSources/
147 | .idea/**/dataSources.ids
148 | .idea/**/dataSources.local.xml
149 | .idea/**/sqlDataSources.xml
150 | .idea/**/dynamic.xml
151 | .idea/**/uiDesigner.xml
152 | .idea/**/dbnavigator.xml
153 |
154 | # Gradle
155 | .idea/**/gradle.xml
156 | .idea/**/libraries
157 |
158 | # Gradle and Maven with auto-import
159 | # When using Gradle or Maven with auto-import, you should exclude module files,
160 | # since they will be recreated, and may cause churn. Uncomment if using
161 | # auto-import.
162 | # .idea/artifacts
163 | # .idea/compiler.xml
164 | # .idea/jarRepositories.xml
165 | # .idea/modules.xml
166 | # .idea/*.iml
167 | # .idea/modules
168 | # *.iml
169 | # *.ipr
170 |
171 | # CMake
172 | cmake-build-*/
173 |
174 | # Mongo Explorer plugin
175 | .idea/**/mongoSettings.xml
176 |
177 | # File-based project format
178 | *.iws
179 |
180 | # IntelliJ
181 | out/
182 |
183 | # mpeltonen/sbt-idea plugin
184 | .idea_modules/
185 |
186 | # JIRA plugin
187 | atlassian-ide-plugin.xml
188 |
189 | # Cursive Clojure plugin
190 | .idea/replstate.xml
191 |
192 | # Crashlytics plugin (for Android Studio and IntelliJ)
193 | com_crashlytics_export_strings.xml
194 | crashlytics.properties
195 | crashlytics-build.properties
196 | fabric.properties
197 |
198 | # Editor-based Rest Client
199 | .idea/httpRequests
200 |
201 | # Android studio 3.1+ serialized cache file
202 | .idea/caches/build_file_checksums.ser
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | [](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/releases)
3 | [](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/actions)
4 | [](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/issues)
5 | [](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/network)
6 | [](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate)
7 | [](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/blob/master/LICENSE)
8 | [](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate)
9 | [](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate)
10 | [](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2Fjohnnymillergh%2FAndroidJetpackMVVMBoilerplate)
11 |
12 | # Android Jetpack MVVM Boilerplate
13 |
14 | **Android Jetpack MVVM Boilerplate** a Jetpack based, MVVM boilerplate template project for Modern Android.
15 |
16 |
17 |
18 | ## Features
19 |
20 | Here is the highlights of **Android Jetpack MVVM Boilerplate**:
21 |
22 | 1. Inherited from the most modern and newest Spring frameworks:
23 |
24 | `org.springframework.boot:spring-boot-starter-parent` - [](https://maven-badges.herokuapp.com/maven-central/org.springframework.boot/spring-boot-starter-parent/)
25 | `org.springframework.cloud:spring-cloud-dependencies` - [](https://maven-badges.herokuapp.com/maven-central/org.springframework.cloud/spring-cloud-dependencies/)
26 |
27 |
28 | ## Usage
29 |
30 | 1. Clone or download this project.
31 |
32 | ```sh
33 | $ git clone https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate.git
34 | ```
35 |
36 | 2. Build with latest Android Studio.
37 |
38 | 3. Click the green triangle to Run.
39 |
40 | ## Useful Commands
41 |
42 | ### Gradle
43 |
44 | 1. Compile and package:
45 |
46 | ```sh
47 | $ gradle clean build
48 | ```
49 |
50 |
51 | ### Conventional Changelog CLI
52 |
53 | 1. Install global dependencies (optional if installed):
54 |
55 | ```sh
56 | $ npm install -g conventional-changelog-cli
57 | ```
58 |
59 | 2. This will *not* overwrite any previous changelogs. The above generates a changelog based on commits since the last semver tag that matches the pattern of "Feature", "Fix", "Performance Improvement" or "Breaking Changes".
60 |
61 | ```sh
62 | $ conventional-changelog -p angular -i CHANGELOG.md -s
63 | ```
64 |
65 | 3. If this is your first time using this tool and you want to generate all previous changelogs, you could do:
66 |
67 | ```sh
68 | $ conventional-changelog -p angular -i CHANGELOG.md -s -r 0
69 | ```
70 |
71 | ## CI (Continuous Integration)
72 |
73 | - [GitHub Actions](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/actions) is for building and testing.
74 | - *Deprecated* [Travis CI](https://travis-ci.com/github/johnnymillergh/media-streaming) is for publishing Docker Hub images of SNAPSHOT and RELEASE.
75 |
76 | ## Maintainers
77 |
78 | [@johnnymillergh](https://github.com/johnnymillergh).
79 |
80 | ## Contributing
81 |
82 | Feel free to dive in! [Open an issue](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/issues/new).
83 |
84 | ### Contributors
85 |
86 | This project exists thanks to all the people who contribute.
87 |
88 | - Johnny Miller [[@johnnymillergh](https://github.com/johnnymillergh)]
89 | - …
90 |
91 |
92 | ### Sponsors
93 |
94 | Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://become-a-sponsor.org)]
95 |
96 | ## License
97 |
98 | [Apache License](https://github.com/johnnymillergh/AndroidJetpackMVVMBoilerplate/blob/master/LICENSE) © Johnny Miller
99 |
100 | 2021 - Present
101 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'kotlin-android'
4 | id 'kotlin-kapt'
5 | id 'dagger.hilt.android.plugin'
6 | id 'androidx.navigation.safeargs.kotlin'
7 | id 'org.jetbrains.kotlin.android.extensions'
8 | }
9 |
10 | android {
11 | compileSdk 30
12 | compileSdkVersion 30
13 | buildToolsVersion '31.0.0'
14 |
15 | defaultConfig {
16 | applicationId "com.github.johnnymillergh.android.androidjetpackmvvmboilerplate"
17 | minSdk 26
18 | targetSdk 30
19 | versionCode 1
20 | versionName "1.0"
21 | buildConfigField("int", "DATABASE_VERSION_CODE", "1")
22 |
23 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
24 |
25 | javaCompileOptions {
26 | annotationProcessorOptions {
27 | arguments += [
28 | "room.schemaLocation" : "$projectDir/schemas".toString(),
29 | "room.incremental" : "true",
30 | "room.expandProjection": "true"]
31 | }
32 | }
33 | }
34 |
35 | signingConfigs {
36 | release {
37 | storeFile file("../ajmb.keystore")
38 | storePassword "ajmbpassword"
39 | keyAlias "ajmbReleaseKey"
40 | keyPassword "ajmbpassword"
41 | }
42 | }
43 |
44 | buildTypes {
45 | debug {
46 | applicationIdSuffix ".debug"
47 | versionNameSuffix "-debug"
48 | debuggable true
49 | buildConfigField("String", "BASE_URL", '"http://base-url-debug.com"')
50 | }
51 | /**
52 | * The `initWith` property allows you to copy configurations from other build types,
53 | * then configure only the settings you want to change. This one copies the debug build
54 | * type, and then changes the manifest placeholder and application ID.
55 | */
56 | staging {
57 | initWith debug
58 | applicationIdSuffix ".staging"
59 | versionNameSuffix "-staging"
60 | buildConfigField("String", "BASE_URL", '"http://base-url-staging.com"')
61 | }
62 | release {
63 | buildConfigField("String", "BASE_URL", '"http://base-url.com"')
64 | minifyEnabled true
65 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
66 | signingConfig signingConfigs.release
67 | }
68 | }
69 | compileOptions {
70 | sourceCompatibility JavaVersion.VERSION_11
71 | targetCompatibility JavaVersion.VERSION_11
72 | }
73 | kotlinOptions {
74 | jvmTarget = JavaVersion.VERSION_11
75 | }
76 |
77 | buildFeatures {
78 | dataBinding true
79 | viewBinding true
80 | }
81 | }
82 |
83 | kapt {
84 | correctErrorTypes true
85 | }
86 |
87 | dependencies {
88 | // Android standard dependencies
89 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
90 | implementation 'androidx.core:core-ktx:1.6.0'
91 | implementation 'androidx.appcompat:appcompat:1.3.1'
92 | implementation 'com.google.android.material:material:1.4.0'
93 | implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
94 | implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
95 | implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
96 | testImplementation 'junit:junit:4.13.2'
97 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
98 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
99 |
100 | // Hilt
101 | implementation "com.google.dagger:hilt-android:$hilt_version"
102 | kapt "com.google.dagger:hilt-compiler:$hilt_version"
103 | // For instrumentation tests
104 | androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
105 | androidTestAnnotationProcessor "com.google.dagger:hilt-compiler:$hilt_version"
106 | // For local unit tests
107 | testImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
108 | kaptTest "com.google.dagger:hilt-compiler:$hilt_version"
109 |
110 | // Retrofit for networking
111 | // define a BOM and its version
112 | implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))
113 | // define any required OkHttp artifacts without version
114 | implementation("com.squareup.okhttp3:okhttp")
115 | implementation("com.squareup.okhttp3:logging-interceptor")
116 | implementation 'com.squareup.retrofit2:retrofit:2.9.0'
117 | implementation 'com.squareup.retrofit2:converter-moshi:2.9.0'
118 | implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
119 |
120 | // Moshi
121 | kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshi_version"
122 | implementation "com.squareup.moshi:moshi:$moshi_version"
123 | implementation "com.squareup.moshi:moshi-kotlin:$moshi_version"
124 | implementation "com.squareup.moshi:moshi-adapters:$moshi_version"
125 |
126 | // Coroutines
127 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
128 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
129 |
130 | // Glide
131 | implementation 'com.github.bumptech.glide:glide:4.12.0'
132 | annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
133 |
134 | // Room
135 | implementation "androidx.room:room-runtime:$room_version"
136 | kapt "androidx.room:room-compiler:$room_version"
137 |
138 | // optional - Kotlin Extensions and Coroutines support for Room
139 | implementation "androidx.room:room-ktx:$room_version"
140 |
141 | // Timber
142 | implementation 'com.jakewharton.timber:timber:5.0.1'
143 |
144 | // Leak Canary
145 | debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
146 |
147 | // Other tool libraries
148 | implementation 'cn.hutool:hutool-all:5.7.11'
149 |
150 | implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
151 | // Because RxAndroid releases are few and far between, it is recommended you also
152 | // explicitly depend on RxJava's latest version for bug fixes and new features.
153 | // (see https://github.com/ReactiveX/RxJava/releases for latest 3.x.x version)
154 | implementation 'io.reactivex.rxjava3:rxjava:3.1.1'
155 | }
156 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2021 Johnny Miller (锺俊)
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------