├── lib
├── consumer-rules.pro
├── .gitignore
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ └── kotlin
│ │ └── com
│ │ └── ohyooo
│ │ └── lib
│ │ ├── mvvm
│ │ ├── MVVMBaseFragment.kt
│ │ ├── MVVMLifecycle.kt
│ │ ├── MVVMBaseActivity.kt
│ │ ├── MVVMBaseViewModel.kt
│ │ └── MVVMViewModelFactory.kt
│ │ ├── extension
│ │ ├── ContextExtensions.kt
│ │ ├── UnitExtensions.kt
│ │ ├── FragmentExtensions.kt
│ │ └── ActivityExtensions.kt
│ │ ├── adapter
│ │ └── ImageViewAdapter.kt
│ │ └── livedata
│ │ └── SingleLiveEvent.kt
├── proguard-rules.pro
└── build.gradle.kts
├── app
├── .gitignore
├── signkey.jks
├── src
│ └── main
│ │ ├── kotlin
│ │ └── com
│ │ │ └── ohyooo
│ │ │ └── demo
│ │ │ ├── model
│ │ │ └── MainUIItem.kt
│ │ │ ├── viewmodel
│ │ │ └── MainViewModel.kt
│ │ │ ├── app
│ │ │ └── App.kt
│ │ │ └── ui
│ │ │ ├── splash
│ │ │ └── SplashActivity.kt
│ │ │ ├── main
│ │ │ └── MainActivity.kt
│ │ │ └── list
│ │ │ └── ListActivity.kt
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ └── layout
│ │ │ ├── activity_main.xml
│ │ │ └── activity_list.xml
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle.kts
├── network
├── .gitignore
├── consumer-rules.pro
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ └── kotlin
│ │ └── com
│ │ └── ohyooo
│ │ └── network
│ │ ├── model
│ │ ├── BaseResponse.kt
│ │ └── RateLimitResponse.kt
│ │ ├── api
│ │ └── GitHubAPIInterface.kt
│ │ ├── repository
│ │ ├── GithubAPIRepository.kt
│ │ └── BaseRepository.kt
│ │ └── factory
│ │ └── ErrorConverterFactory.kt
├── proguard-rules.pro
└── build.gradle.kts
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
└── libs.versions.toml
├── gradle.properties
├── settings.gradle.kts
├── LICENSE
├── .github
├── workflows
│ ├── update-gradle-wrapper.yml
│ ├── auto-merge.yml
│ └── android.yml
└── dependabot.yml
├── README.md
├── .gitignore
├── gradlew.bat
└── gradlew
/lib/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/lib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/network/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/network/consumer-rules.pro:
--------------------------------------------------------------------------------
1 | -keep class com.ohyooo.network.model.** { *; }
--------------------------------------------------------------------------------
/lib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/network/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/signkey.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ohyooo/MVVMBaseProject/HEAD/app/signkey.jks
--------------------------------------------------------------------------------
/app/src/main/kotlin/com/ohyooo/demo/model/MainUIItem.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.demo.model
2 |
3 |
4 | class MainUIItem
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Demo
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ohyooo/MVVMBaseProject/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ohyooo/MVVMBaseProject/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ohyooo/MVVMBaseProject/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/network/src/main/kotlin/com/ohyooo/network/model/BaseResponse.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.network.model
2 |
3 |
4 | open class BaseResponse(var errorCode: Int = 0, var errorMsg: String? = null)
--------------------------------------------------------------------------------
/lib/src/main/kotlin/com/ohyooo/lib/mvvm/MVVMBaseFragment.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.lib.mvvm
2 |
3 | import androidx.annotation.LayoutRes
4 | import androidx.fragment.app.Fragment
5 |
6 | abstract class MVVMBaseFragment(@LayoutRes layoutId: Int) : Fragment(layoutId)
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/com/ohyooo/demo/viewmodel/MainViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.demo.viewmodel
2 |
3 | import com.ohyooo.demo.model.MainUIItem
4 | import com.ohyooo.lib.mvvm.MVVMBaseViewModel
5 |
6 | class MainViewModel : MVVMBaseViewModel() {
7 | private val ui = MainUIItem()
8 | }
--------------------------------------------------------------------------------
/lib/src/main/kotlin/com/ohyooo/lib/extension/ContextExtensions.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.lib.extension
2 |
3 | import android.content.Context
4 | import android.widget.Toast
5 |
6 | fun Context.showToast(text: String?) {
7 | text ?: return
8 | Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
9 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/network/src/main/kotlin/com/ohyooo/network/api/GitHubAPIInterface.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.network.api
2 |
3 | import com.ohyooo.network.model.RateLimitResponse
4 | import retrofit2.http.GET
5 |
6 | interface GitHubAPIInterface {
7 |
8 | @GET("rate_limit")
9 | suspend fun getRateLimit(): RateLimitResponse
10 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | android.enableR8.fullMode=true
2 | android.useAndroidX=true
3 | #
4 | kapt.include.compile.classpath=false
5 | kapt.incremental.apt=true
6 | #
7 | org.gradle.caching=true
8 | org.gradle.configureondemand=true
9 | org.gradle.daemon=true
10 | org.gradle.jvmargs=-Xmx2048m
11 | org.gradle.parallel.threads=12
12 | org.gradle.parallel=true
13 | org.gradle.vfs.watch=true
14 | org.gradle.workers.max=12
--------------------------------------------------------------------------------
/lib/src/main/kotlin/com/ohyooo/lib/adapter/ImageViewAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.lib.adapter
2 |
3 | import android.graphics.Bitmap
4 | import android.widget.ImageView
5 | import androidx.databinding.BindingAdapter
6 |
7 | object ImageViewAdapter {
8 |
9 | @JvmStatic
10 | @BindingAdapter("bitmap")
11 | fun setBitmap(iv: ImageView, bitmap: Bitmap?) {
12 | iv.setImageBitmap(bitmap)
13 | }
14 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/com/ohyooo/demo/app/App.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.demo.app
2 |
3 | import android.app.Application
4 | import timber.log.Timber
5 |
6 | class App : Application() {
7 | init {
8 | instance = this
9 | }
10 |
11 | override fun onCreate() {
12 | super.onCreate()
13 | Timber.plant(Timber.DebugTree())
14 | }
15 |
16 | companion object {
17 | lateinit var instance: App
18 | private set
19 | }
20 | }
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | @file:Suppress("UnstableApiUsage")
2 |
3 | pluginManagement {
4 | repositories {
5 | google()
6 | mavenCentral()
7 | gradlePluginPortal()
8 | }
9 | }
10 |
11 | dependencyResolutionManagement {
12 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
13 | repositories {
14 | google()
15 | mavenCentral()
16 | }
17 | }
18 |
19 | rootProject.name = "Demo"
20 | include(":app", ":lib", ":network")
--------------------------------------------------------------------------------
/app/src/main/kotlin/com/ohyooo/demo/ui/splash/SplashActivity.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.demo.ui.splash
2 |
3 | import android.app.Activity
4 | import android.content.Intent
5 | import android.os.Bundle
6 | import com.ohyooo.demo.ui.main.MainActivity
7 |
8 | class SplashActivity : Activity() {
9 | override fun onCreate(savedInstanceState: Bundle?) {
10 | super.onCreate(savedInstanceState)
11 | startActivity(Intent(this, MainActivity::class.java))
12 | finish()
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2 | Version 2, December 2004
3 |
4 | Copyright (C) 2004 Sam Hocevar
5 |
6 | Everyone is permitted to copy and distribute verbatim or modified
7 | copies of this license document, and changing it is allowed as long
8 | as the name is changed.
9 |
10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12 |
13 | 0. You just DO WHAT THE FUCK YOU WANT TO.
14 |
--------------------------------------------------------------------------------
/lib/src/main/kotlin/com/ohyooo/lib/mvvm/MVVMLifecycle.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.lib.mvvm
2 |
3 | import androidx.lifecycle.Lifecycle
4 | import androidx.lifecycle.LifecycleObserver
5 | import androidx.lifecycle.OnLifecycleEvent
6 |
7 | interface MVVMLifecycle : LifecycleObserver {
8 | @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
9 | fun onCreate()
10 |
11 | @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
12 | fun onPause()
13 |
14 | @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
15 | fun onResume()
16 |
17 | @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
18 | fun onDestroy()
19 | }
--------------------------------------------------------------------------------
/.github/workflows/update-gradle-wrapper.yml:
--------------------------------------------------------------------------------
1 | name: Update Gradle Wrapper
2 |
3 | on:
4 | workflow_dispatch:
5 | schedule:
6 | - cron: "0 0 * * *"
7 |
8 | jobs:
9 | update-gradle-wrapper:
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - uses: actions/checkout@main
14 |
15 | - name: Setup JDK
16 | uses: actions/setup-java@main
17 | with:
18 | distribution: 'zulu'
19 | java-version: '21'
20 | java-package: jdk
21 | cache: 'gradle'
22 |
23 | - name: Update Gradle Wrapper
24 | uses: gradle-update/update-gradle-wrapper-action@main
25 |
--------------------------------------------------------------------------------
/lib/src/main/kotlin/com/ohyooo/lib/mvvm/MVVMBaseActivity.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.lib.mvvm
2 |
3 | import android.os.Bundle
4 | import androidx.annotation.LayoutRes
5 | import androidx.databinding.DataBindingUtil
6 | import androidx.databinding.ViewDataBinding
7 | import androidx.fragment.app.FragmentActivity
8 |
9 | abstract class MVVMBaseActivity(@LayoutRes val layoutId: Int = 0) : FragmentActivity() {
10 |
11 | override fun onCreate(savedInstanceState: Bundle?) {
12 | super.onCreate(savedInstanceState)
13 | if (layoutId != 0) {
14 | DataBindingUtil.setContentView(this, layoutId)
15 | }
16 | }
17 |
18 | }
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: gradle
4 | directory: /
5 | schedule:
6 | interval: daily
7 | registries:
8 | - maven-google
9 | - gradle-plugin
10 | groups:
11 | maven-dependencies:
12 | patterns:
13 | - "*"
14 |
15 | - package-ecosystem: github-actions
16 | directory: /
17 | schedule:
18 | interval: daily
19 | groups:
20 | github-actions:
21 | patterns:
22 | - "*"
23 |
24 | registries:
25 | maven-google:
26 | type: maven-repository
27 | url: https://dl.google.com/dl/android/maven2/
28 | gradle-plugin:
29 | type: maven-repository
30 | url: https://plugins.gradle.org/m2/
31 |
--------------------------------------------------------------------------------
/lib/src/main/kotlin/com/ohyooo/lib/mvvm/MVVMBaseViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.lib.mvvm
2 |
3 | import android.os.Bundle
4 | import androidx.lifecycle.ViewModel
5 | import com.ohyooo.lib.livedata.SingleLiveEvent
6 |
7 | abstract class MVVMBaseViewModel : ViewModel(), MVVMLifecycle {
8 |
9 | var bundle: Bundle = Bundle()
10 |
11 | val toastLiveData = SingleLiveEvent()
12 |
13 | fun showToast(msg: String?) {
14 | toastLiveData.postValue(msg)
15 | }
16 |
17 | /**
18 | * Lifecycle Start
19 | */
20 | override fun onCreate() {}
21 |
22 | override fun onPause() {}
23 |
24 | override fun onResume() {}
25 |
26 | override fun onDestroy() {}
27 | /**
28 | * Lifecycle End
29 | */
30 | }
--------------------------------------------------------------------------------
/lib/src/main/kotlin/com/ohyooo/lib/extension/UnitExtensions.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.lib.extension
2 |
3 | import android.content.Context
4 | import android.util.TypedValue
5 |
6 | fun Context.dp2px(dp: Float) = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.displayMetrics)
7 |
8 | fun Context.sp2px(sp: Float) = (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, resources.displayMetrics))
9 |
10 | fun Context.pt2px(pt: Float) = (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PT, pt, resources.displayMetrics))
11 |
12 | fun Context.in2px(inch: Float) = (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_IN, inch, resources.displayMetrics))
13 |
14 | fun Context.mm2px(mm: Float) = (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, mm, resources.displayMetrics))
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/lib/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.kts.
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 |
--------------------------------------------------------------------------------
/network/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.kts.
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/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.kts.kts.kts.
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/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
10 |
11 |
12 |
18 |
19 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/com/ohyooo/demo/ui/main/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.demo.ui.main
2 |
3 | import android.os.Bundle
4 | import com.ohyooo.demo.databinding.ActivityMainBinding
5 | import com.ohyooo.demo.viewmodel.MainViewModel
6 | import com.ohyooo.lib.extension.viewModelOf
7 | import com.ohyooo.lib.mvvm.MVVMBaseActivity
8 |
9 | class MainActivity : MVVMBaseActivity() {
10 |
11 | private val vm: MainViewModel by viewModelOf()
12 | private val vdb by lazy { ActivityMainBinding.inflate(layoutInflater).also { it.vm = vm } }
13 |
14 | override fun onCreate(savedInstanceState: Bundle?) {
15 | super.onCreate(savedInstanceState)
16 | setContentView(vdb.root)
17 |
18 | initData()
19 | initViews()
20 | }
21 |
22 | private fun initData() {
23 | }
24 |
25 | private fun initViews() {
26 | vdb.button.setOnClickListener {
27 |
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/.github/workflows/auto-merge.yml:
--------------------------------------------------------------------------------
1 | name: Dependabot Merge
2 |
3 | on:
4 | pull_request_target:
5 | types:
6 | - opened
7 |
8 | jobs:
9 | dependabot-merge:
10 | runs-on: ubuntu-latest
11 | if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
12 | steps:
13 | - uses: peter-evans/find-comment@main
14 | id: find-comment
15 | with:
16 | token: ${{ secrets.ACTIONS_TRIGGER_PAT }}
17 | issue-number: ${{ github.event.pull_request.number }}
18 | body-includes: '@dependabot squash and merge'
19 | - uses: peter-evans/create-or-update-comment@main
20 | with:
21 | token: ${{ secrets.ACTIONS_TRIGGER_PAT }}
22 | comment-id: ${{ steps.find-comment.outputs.comment-id }}
23 | issue-number: ${{ github.event.pull_request.number }}
24 | body: '@dependabot squash and merge'
25 | edit-mode: replace
26 |
--------------------------------------------------------------------------------
/network/src/main/kotlin/com/ohyooo/network/model/RateLimitResponse.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.network.model
2 |
3 |
4 | data class RateLimitResponse(var rate: Rate? = null, var resources: Resources? = null) : BaseResponse()
5 |
6 |
7 | data class Rate(var limit: Int?, var remaining: Int?, var reset: Int?)
8 |
9 |
10 | data class Resources(var core: Core?, var graphql: Graphql?, var integration_manifest: IntegrationManifest?, var search: Search?, var source_import: SourceImport?)
11 |
12 |
13 | data class Core(var limit: Int?, var remaining: Int?, var reset: Int?)
14 |
15 |
16 | data class Graphql(var limit: Int?, var remaining: Int?, var reset: Int?)
17 |
18 |
19 | data class IntegrationManifest(var limit: Int?, var remaining: Int?, var reset: Int?)
20 |
21 |
22 | data class Search(var limit: Int?, var remaining: Int?, var reset: Int?)
23 |
24 |
25 | data class SourceImport(var limit: Int?, var remaining: Int?, var reset: Int?)
26 |
--------------------------------------------------------------------------------
/.github/workflows/android.yml:
--------------------------------------------------------------------------------
1 | name: Android CI
2 |
3 | on:
4 | push:
5 | repository_dispatch:
6 | workflow_dispatch:
7 |
8 | jobs:
9 | build:
10 |
11 | runs-on: ubuntu-latest
12 |
13 | steps:
14 | - uses: actions/checkout@v6
15 |
16 | - name: Get Time
17 | id: time
18 | uses: nanzm/get-time-action@v2.0
19 | with:
20 | timeZone: 8
21 | format: 'YYYYMMDDHHmmss'
22 |
23 | - name: Setup JDK
24 | uses: actions/setup-java@v5
25 | with:
26 | distribution: 'zulu'
27 | java-version: '17'
28 | java-package: jdk
29 |
30 | - name: Grant execute permission for gradlew
31 | run: chmod +x gradlew
32 |
33 | - name: Build APK
34 | run: ./gradlew assembleRelease
35 |
36 | - name: Delete workflow runs
37 | uses: GitRML/delete-workflow-runs@main
38 | with:
39 | retain_days: 3
40 | keep_minimum_runs: 2
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
11 |
12 |
13 |
19 |
20 |
25 |
26 |
--------------------------------------------------------------------------------
/network/src/main/kotlin/com/ohyooo/network/repository/GithubAPIRepository.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.network.repository
2 |
3 | import com.ohyooo.network.api.GitHubAPIInterface
4 | import com.ohyooo.network.factory.ErrorConverterFactory
5 | import com.ohyooo.network.model.RateLimitResponse
6 | import kotlinx.coroutines.Dispatchers
7 | import kotlinx.coroutines.withContext
8 | import retrofit2.Retrofit
9 | import retrofit2.converter.gson.GsonConverterFactory
10 |
11 | object GithubAPIRepository : BaseRepository() {
12 |
13 | private val retrofit: Retrofit = Retrofit.Builder()
14 | .baseUrl("https://api.github.com/")
15 | .addConverterFactory(ErrorConverterFactory())
16 | .addConverterFactory(GsonConverterFactory.create())
17 | .client(httpClient)
18 | .build()
19 |
20 | suspend fun getRateLimit(): RateLimitResponse = withContext(Dispatchers.IO) {
21 | return@withContext getResponse {
22 | retrofit.create(GitHubAPIInterface::class.java).getRateLimit()
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/lib/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.library")
3 | kotlin("android")
4 | }
5 |
6 | android {
7 | namespace = "com.ohyooo.lib"
8 | compileSdk = libs.versions.compile.sdk.get().toInt()
9 | defaultConfig {
10 | minSdk = libs.versions.min.sdk.get().toInt()
11 | proguardFile("consumer-rules.pro")
12 | }
13 | buildTypes {
14 | debug {
15 | isMinifyEnabled = true
16 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "consumer-rules.pro")
17 | }
18 | release {
19 | isMinifyEnabled = true
20 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "consumer-rules.pro")
21 | }
22 | }
23 | compileOptions {
24 | sourceCompatibility = JavaVersion.VERSION_17
25 | targetCompatibility = JavaVersion.VERSION_17
26 | }
27 | buildFeatures {
28 | dataBinding = true
29 | }
30 | }
31 |
32 | dependencies {
33 | implementation(libs.fragmentKtx)
34 | }
35 |
--------------------------------------------------------------------------------
/lib/src/main/kotlin/com/ohyooo/lib/mvvm/MVVMViewModelFactory.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.lib.mvvm
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import androidx.lifecycle.Lifecycle
6 | import androidx.lifecycle.ViewModel
7 | import androidx.lifecycle.ViewModelProvider
8 | import com.ohyooo.lib.extension.bindBaseLiveData
9 |
10 | class MVVMViewModelFactory(private val context: Context, private val lifecycle: Lifecycle) : ViewModelProvider.Factory {
11 | override fun create(modelClass: Class): T {
12 | val clazz = modelClass.newInstance()
13 | if (clazz is MVVMBaseViewModel) {
14 | lifecycle.addObserver(clazz)
15 | if (context is MVVMBaseActivity) {
16 | context.bindBaseLiveData(clazz)
17 | clazz.bundle = context.intent.extras ?: Bundle()
18 | } else if (context is MVVMBaseFragment) {
19 | context.bindBaseLiveData(clazz)
20 | clazz.bundle = context.arguments ?: Bundle()
21 | }
22 | }
23 | return clazz
24 | }
25 | }
--------------------------------------------------------------------------------
/network/build.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | id("com.android.library")
4 | kotlin("android")
5 | }
6 |
7 | android {
8 | namespace = "com.ohyooo.network"
9 | compileSdk = libs.versions.compile.sdk.get().toInt()
10 | defaultConfig {
11 | minSdk = libs.versions.min.sdk.get().toInt()
12 | proguardFile("consumer-rules.pro")
13 | }
14 | buildTypes {
15 | debug {
16 | isMinifyEnabled = true
17 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "consumer-rules.pro")
18 | }
19 | release {
20 | isMinifyEnabled = true
21 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "consumer-rules.pro")
22 | }
23 | }
24 | compileOptions {
25 | sourceCompatibility = JavaVersion.VERSION_17
26 | targetCompatibility = JavaVersion.VERSION_17
27 | }
28 | }
29 |
30 | dependencies {
31 | implementation(libs.coroutines)
32 | //
33 | implementation(libs.retrofit)
34 | implementation(libs.converter)
35 | implementation(libs.log)
36 | }
37 |
--------------------------------------------------------------------------------
/lib/src/main/kotlin/com/ohyooo/lib/extension/FragmentExtensions.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.lib.extension
2 |
3 | import androidx.databinding.DataBindingUtil
4 | import androidx.databinding.ViewDataBinding
5 | import androidx.fragment.app.Fragment
6 | import androidx.fragment.app.activityViewModels
7 | import androidx.fragment.app.viewModels
8 | import androidx.lifecycle.Observer
9 | import androidx.lifecycle.ViewModel
10 | import com.ohyooo.lib.mvvm.MVVMBaseFragment
11 | import com.ohyooo.lib.mvvm.MVVMBaseViewModel
12 | import com.ohyooo.lib.mvvm.MVVMViewModelFactory
13 |
14 | inline fun Fragment.viewDataBindingOf(): VB {
15 | return DataBindingUtil.bind(view!!)!!
16 | }
17 |
18 | inline fun Fragment.viewModelOf(useActivity: Boolean = false): Lazy {
19 | return if (useActivity) {
20 | activityViewModels { MVVMViewModelFactory(requireActivity(), lifecycle) }
21 | } else {
22 | viewModels { MVVMViewModelFactory(context!!, lifecycle) }
23 | }
24 | }
25 |
26 | fun MVVMBaseFragment.bindBaseLiveData(vm: MVVMBaseViewModel) {
27 | vm.toastLiveData.observe(this, Observer { context?.showToast(it) })
28 | }
--------------------------------------------------------------------------------
/network/src/main/kotlin/com/ohyooo/network/repository/BaseRepository.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.network.repository
2 |
3 | import android.util.Log
4 | import com.ohyooo.network.model.BaseResponse
5 | import okhttp3.OkHttpClient
6 | import okhttp3.logging.HttpLoggingInterceptor
7 | import retrofit2.HttpException
8 | import java.util.concurrent.TimeUnit
9 |
10 | abstract class BaseRepository {
11 |
12 | val httpClient: OkHttpClient = OkHttpClient.Builder()
13 | .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
14 | .callTimeout(1, TimeUnit.MINUTES)
15 | .build()
16 |
17 | inline fun getResponse(method: () -> T): T {
18 | var resp = T::class.java.newInstance()
19 | try {
20 | resp = method.invoke()
21 | } catch (e: HttpException) {
22 | Log.e("BaseRepository", "getResponse() " + T::class.java.name)
23 | resp.errorCode = e.code()
24 | resp.errorMsg = e.message
25 | } catch (e: Exception) {
26 | resp.errorCode = 1
27 | resp.errorMsg = e.message
28 | }
29 | return resp
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android MVVM Base Project
2 |
3 | ------
4 |
5 | ## Introduction
6 |
7 | This project is intent to provide a template with basic MVVM architecture framework. You can just copy it to workspace instead of creating a new project from Android Studio.
8 |
9 | Advantages:
10 |
11 | - Simple, easy to read
12 | - Use few libs, save time for gradle syncing
13 | - No dagger or any other DI lib
14 |
15 | ## Module
16 |
17 | ```cmd
18 | ├───app
19 | │ ├───app Application
20 | │ ├───model models
21 | │ ├───ui activities & fragments
22 | │ │ ├───main MainActivity
23 | │ └───viewmodel viewmodels
24 | │
25 | ├───lib
26 | │ ├───adapter databinding adapter
27 | │ ├───extension kotlin extensions
28 | │ └───mvvm MVVM framework
29 | │
30 | └───network
31 | ├───api
32 | ├───model
33 | └───repository
34 | ```
35 |
36 | ## MVVM
37 | Usually, a viwemodel can only aware the destroy of its owner in onClear() method. But after making it implements LifecycleObserver and observing owner's lifecycle in ViewModelProvider.Factory. It can use onCreate() or other lifecycle event now.
38 | Check these codes in MVVMViewModelFactory.kt
39 |
40 | ## Todo
41 | many many things..
--------------------------------------------------------------------------------
/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | application_id = "com.ohyooo.demo"
3 | min_sdk = "21"
4 | target_sdk = "35"
5 | compile_sdk = "35"
6 | version_code = "10"
7 | version_name = "2.10"
8 |
9 | agp = "8.13.2"
10 | kotlin = "2.2.21"
11 | retrofit2 = "3.0.0"
12 |
13 |
14 | [plugins]
15 | agp = { id = "com.android.application", version.ref = "agp" }
16 | kgp = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
17 |
18 | [libraries]
19 |
20 | # Kotlin
21 | stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
22 | coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2"
23 |
24 | # AndroidX
25 | appcompat = "androidx.appcompat:appcompat:1.7.1"
26 | coreKtx = "androidx.core:core-ktx:1.17.0"
27 | fragmentKtx = "androidx.fragment:fragment-ktx:1.8.9"
28 | constraintLayout = "androidx.constraintlayout:constraintlayout:2.2.1"
29 | recyclerview = "androidx.recyclerview:recyclerview:1.4.0"
30 |
31 | # Squareup
32 | retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit2" }
33 | converter = { module = "com.squareup.retrofit2:converter-gson", version.ref = "retrofit2" }
34 | log = "com.squareup.okhttp3:logging-interceptor:5.3.2"
35 |
36 | # Third
37 | timber = "com.jakewharton.timber:timber:5.0.1"
38 |
--------------------------------------------------------------------------------
/lib/src/main/kotlin/com/ohyooo/lib/extension/ActivityExtensions.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.lib.extension
2 |
3 | import android.app.Activity
4 | import android.view.ViewGroup
5 | import androidx.activity.ComponentActivity
6 | import androidx.activity.viewModels
7 | import androidx.databinding.DataBindingUtil
8 | import androidx.databinding.ViewDataBinding
9 | import androidx.fragment.app.Fragment
10 | import androidx.fragment.app.FragmentActivity
11 | import androidx.lifecycle.Observer
12 | import androidx.lifecycle.ViewModel
13 | import com.ohyooo.lib.mvvm.MVVMBaseActivity
14 | import com.ohyooo.lib.mvvm.MVVMBaseViewModel
15 | import com.ohyooo.lib.mvvm.MVVMViewModelFactory
16 |
17 | inline fun Activity.viewDataBindingOf(): VB {
18 | return DataBindingUtil.findBinding((findViewById(android.R.id.content)).getChildAt(0))!!
19 | }
20 |
21 | inline fun ComponentActivity.viewModelOf(): Lazy {
22 | return viewModels { MVVMViewModelFactory(this, lifecycle) }
23 | }
24 |
25 | fun FragmentActivity.replaceFragment(id: Int, fragment: Fragment, tag: String? = null) {
26 | val fm = supportFragmentManager
27 | val ft = fm.beginTransaction()
28 | ft.replace(id, fragment, tag)
29 | ft.commit()
30 | }
31 |
32 | fun MVVMBaseActivity.bindBaseLiveData(vm: MVVMBaseViewModel) {
33 | vm.toastLiveData.observe(this, Observer { showToast(it) })
34 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
18 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/com/ohyooo/demo/ui/list/ListActivity.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.demo.ui.list
2 |
3 | import android.os.Bundle
4 | import android.view.ViewGroup
5 | import android.widget.TextView
6 | import androidx.activity.ComponentActivity
7 | import androidx.recyclerview.widget.RecyclerView
8 | import com.ohyooo.demo.databinding.ActivityListBinding
9 | import com.ohyooo.demo.viewmodel.MainViewModel
10 | import com.ohyooo.lib.extension.viewModelOf
11 |
12 | class ListActivity : ComponentActivity() {
13 |
14 | private val vm: MainViewModel by viewModelOf()
15 | private val vdb by lazy { ActivityListBinding.inflate(layoutInflater).also { it.vm = vm } }
16 |
17 | private val adapter = AA()
18 |
19 | override fun onCreate(savedInstanceState: Bundle?) {
20 | super.onCreate(savedInstanceState)
21 | setContentView(vdb.root)
22 |
23 | initData()
24 | initViews()
25 | }
26 |
27 | private fun initData() {
28 | }
29 |
30 | private fun initViews() {
31 | vdb.list.adapter = adapter
32 | }
33 |
34 | private class AA : RecyclerView.Adapter>() {
35 | private val list = ArrayList()
36 |
37 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
38 | val tv = TextView(parent.context).apply {
39 | layoutParams = RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
40 | setPadding(20, 20, 20, 0)
41 | }
42 | return VH(tv)
43 | }
44 |
45 | override fun onBindViewHolder(vh: VH, position: Int) {
46 | vh.v.text = list[position]
47 | }
48 |
49 | override fun getItemCount() = list.size
50 |
51 | fun update(data: List) {
52 | list.clear()
53 | list.addAll(data)
54 | notifyDataSetChanged()
55 | }
56 | }
57 |
58 | private class VH(val v: V) : RecyclerView.ViewHolder(v)
59 | }
--------------------------------------------------------------------------------
/network/src/main/kotlin/com/ohyooo/network/factory/ErrorConverterFactory.kt:
--------------------------------------------------------------------------------
1 | package com.ohyooo.network.factory
2 |
3 | import android.util.Log
4 | import com.google.gson.Gson
5 | import com.google.gson.TypeAdapter
6 | import com.google.gson.reflect.TypeToken
7 | import com.ohyooo.network.model.BaseResponse
8 | import okhttp3.ResponseBody
9 | import org.json.JSONArray
10 | import org.json.JSONException
11 | import org.json.JSONObject
12 | import retrofit2.Converter
13 | import retrofit2.Retrofit
14 | import java.lang.reflect.Type
15 |
16 | class ErrorConverterFactory : Converter.Factory() {
17 |
18 | override fun responseBodyConverter(type: Type, annotations: Array, retrofit: Retrofit): Converter {
19 | val gson = Gson()
20 | val adapter = gson.getAdapter(TypeToken.get(type))
21 | return ResponseConverter(gson, adapter)
22 | }
23 | }
24 |
25 | class ResponseConverter(private val gson: Gson, private val adapter: TypeAdapter) :
26 | Converter {
27 | override fun convert(value: ResponseBody): T? {
28 | try {
29 | val originalBody = value.string()
30 | return if (isJSONValid(originalBody)) {
31 | adapter.fromJson(originalBody)
32 | } else {
33 | val resp = BaseResponse()
34 | resp.errorCode = -1
35 | resp.errorMsg = "invalid response"
36 | adapter.fromJson(gson.toJson(resp))
37 | }
38 | } catch (e: Exception) {
39 | Log.e("ErrorConverterFactory", "ResponseConverter()")
40 | } finally {
41 | value.close()
42 | }
43 | return null
44 | }
45 |
46 | private fun isJSONValid(test: String?): Boolean {
47 | if (test.isNullOrBlank()) {
48 | return false
49 | }
50 | try {
51 | JSONObject(test)
52 | } catch (e: JSONException) {
53 | try {
54 | JSONArray(test)
55 | } catch (e: JSONException) {
56 | return false
57 | }
58 | }
59 | return true
60 | }
61 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/androidstudio
3 | # Edit at https://www.gitignore.io/?templates=androidstudio
4 |
5 | ### AndroidStudio ###
6 | # Covers files to be ignored for android development using Android Studio.
7 |
8 | # Built application files
9 | *.apk
10 | *.aar
11 | *.ap_
12 |
13 | # Files for the ART/Dalvik VM
14 | *.dex
15 |
16 | # Java class files
17 | *.class
18 |
19 | # Generated files
20 | bin/
21 | gen/
22 | out/
23 |
24 | # Gradle files
25 | .gradle
26 | .gradle/
27 | build/
28 |
29 | # Signing files
30 | .signing/
31 |
32 | # Local configuration file (sdk path, etc)
33 | local.properties
34 |
35 | # Proguard folder generated by Eclipse
36 | proguard/
37 |
38 | # Log Files
39 | *.log
40 |
41 | # Android Studio
42 | /*/build/
43 | /*/release/
44 | /*/debug/
45 | /*/stage/
46 | /*/dev/
47 | /*/local.properties
48 | /*/out
49 | /*/*/build
50 | /*/*/production
51 | captures/
52 | .navigation/
53 | *.ipr
54 | *~
55 | *.swp
56 |
57 | # Android Patch
58 | gen-external-apklibs
59 |
60 | # External native build folder generated in Android Studio 2.2 and later
61 | .externalNativeBuild
62 |
63 | # NDK
64 | obj/
65 |
66 | # IntelliJ IDEA
67 | *.iml
68 | *.iws
69 | /out/
70 |
71 | # User-specific configurations
72 | .idea/
73 |
74 | # OS-specific files
75 | .DS_Store
76 | .DS_Store?
77 | ._*
78 | .Spotlight-V100
79 | .Trashes
80 | ehthumbs.db
81 | Thumbs.db
82 |
83 | # Legacy Eclipse project files
84 | .classpath
85 | .project
86 | .cproject
87 | .settings/
88 |
89 | # Mobile Tools for Java (J2ME)
90 | .mtj.tmp/
91 |
92 | # Package Files #
93 | *.war
94 | *.ear
95 |
96 | # virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)
97 | hs_err_pid*
98 |
99 | ## Plugin-specific files:
100 |
101 | # mpeltonen/sbt-idea plugin
102 | .idea_modules/
103 |
104 | # JIRA plugin
105 | atlassian-ide-plugin.xml
106 |
107 | # Crashlytics plugin (for Android Studio and IntelliJ)
108 | com_crashlytics_export_strings.xml
109 | crashlytics.properties
110 | crashlytics-build.properties
111 | fabric.properties
112 |
113 | ### AndroidStudio Patch ###
114 |
115 | !/gradle/wrapper/gradle-wrapper.jar
116 |
117 | # End of https://www.gitignore.io/api/androidstudio
--------------------------------------------------------------------------------
/lib/src/main/kotlin/com/ohyooo/lib/livedata/SingleLiveEvent.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ohyooo.lib.livedata
18 |
19 | import androidx.annotation.MainThread
20 | import androidx.annotation.Nullable
21 | import androidx.lifecycle.LifecycleOwner
22 | import androidx.lifecycle.MutableLiveData
23 | import androidx.lifecycle.Observer
24 | import java.util.concurrent.atomic.AtomicBoolean
25 |
26 |
27 | /**
28 | * A lifecycle-aware observable that sends only new updates after subscription, used for events like
29 | * navigation and Snackbar messages.
30 | *
31 | *
32 | * This avoids a common problem with events: on configuration change (like rotation) an update
33 | * can be emitted if the observer is active. This LiveData only calls the observable if there's an
34 | * explicit call to setValue() or call().
35 | *
36 | *
37 | * Note that only one observer is going to be notified of changes.
38 | */
39 | class SingleLiveEvent : MutableLiveData() {
40 | private val mPending = AtomicBoolean(false)
41 |
42 | // Multiple observers registered but only one will be notified of changes.
43 | override fun observe(owner: LifecycleOwner, observer: Observer) {
44 | // Observe the internal MutableLiveData
45 | super.observe(owner, Observer {
46 | if (mPending.compareAndSet(true, false)) {
47 | observer.onChanged(it)
48 | }
49 | })
50 | }
51 |
52 | @MainThread
53 | override fun setValue(@Nullable t: T?) {
54 | mPending.set(true)
55 | super.setValue(t)
56 | }
57 |
58 | /**
59 | * Used for cases where T is Void, to make calls cleaner.
60 | */
61 | @MainThread
62 | fun call() {
63 | value = null
64 | }
65 |
66 | }
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | @file:Suppress("UnstableApiUsage")
2 |
3 | plugins {
4 | id("com.android.application")
5 | kotlin("android")
6 | }
7 |
8 | android {
9 | signingConfigs {
10 | getByName("debug") {
11 | storeFile = file("signkey.jks")
12 | storePassword = "123456"
13 | keyPassword = "123456"
14 | keyAlias = "demo"
15 |
16 | enableV3Signing = true
17 | enableV4Signing = true
18 | }
19 | }
20 | namespace = libs.versions.application.id.get()
21 | compileSdk = libs.versions.compile.sdk.get().toInt()
22 | defaultConfig {
23 | applicationId = libs.versions.application.id.get()
24 | minSdk = libs.versions.min.sdk.get().toInt()
25 | targetSdk = libs.versions.target.sdk.get().toInt()
26 | versionCode = libs.versions.version.code.get().toInt()
27 | versionName = libs.versions.target.sdk.get() + hashTag
28 | proguardFile("proguard-rules.pro")
29 | signingConfig = signingConfigs.getByName("debug")
30 | }
31 | buildTypes {
32 | release {
33 | isMinifyEnabled = true
34 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "consumer-rules.pro")
35 | }
36 | }
37 | compileOptions {
38 | sourceCompatibility = JavaVersion.VERSION_17
39 | targetCompatibility = JavaVersion.VERSION_17
40 | }
41 | kotlinOptions {
42 | jvmTarget = "17"
43 | }
44 | buildFeatures {
45 | viewBinding = true
46 | dataBinding = true
47 | }
48 | }
49 |
50 |
51 | dependencies {
52 | implementation(project(":lib"))
53 | implementation(project(":network"))
54 | implementation(libs.appcompat)
55 | implementation(libs.coreKtx)
56 | implementation(libs.fragmentKtx)
57 | implementation(libs.constraintLayout)
58 | implementation(libs.recyclerview)
59 | //
60 | implementation (libs.timber)
61 | }
62 |
63 | val hashTag: String
64 | get() {
65 | if (!File(rootDir.path + "/.git").exists()) return ""
66 | return ProcessBuilder(listOf("git", "rev-parse", "--short", "HEAD"))
67 | .directory(rootDir)
68 | .redirectOutput(ProcessBuilder.Redirect.PIPE)
69 | .redirectError(ProcessBuilder.Redirect.PIPE)
70 | .start()
71 | .apply { waitFor(5, TimeUnit.SECONDS) }
72 | .run {
73 | val error = errorStream.bufferedReader().readText().trim()
74 | if (error.isNotEmpty()) {
75 | ""
76 | } else {
77 | "-" + inputStream.bufferedReader().readText().trim()
78 | }
79 | }
80 | }
--------------------------------------------------------------------------------
/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 | @rem This is normally unused
30 | set APP_BASE_NAME=%~n0
31 | set APP_HOME=%DIRNAME%
32 |
33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35 |
36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38 |
39 | @rem Find java.exe
40 | if defined JAVA_HOME goto findJavaFromJavaHome
41 |
42 | set JAVA_EXE=java.exe
43 | %JAVA_EXE% -version >NUL 2>&1
44 | if %ERRORLEVEL% equ 0 goto execute
45 |
46 | echo.
47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48 | echo.
49 | echo Please set the JAVA_HOME variable in your environment to match the
50 | echo location of your Java installation.
51 |
52 | goto fail
53 |
54 | :findJavaFromJavaHome
55 | set JAVA_HOME=%JAVA_HOME:"=%
56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57 |
58 | if exist "%JAVA_EXE%" goto execute
59 |
60 | echo.
61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62 | echo.
63 | echo Please set the JAVA_HOME variable in your environment to match the
64 | echo location of your Java installation.
65 |
66 | goto fail
67 |
68 | :execute
69 | @rem Setup the command line
70 |
71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72 |
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if %ERRORLEVEL% equ 0 goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | set EXIT_CODE=%ERRORLEVEL%
85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87 | exit /b %EXIT_CODE%
88 |
89 | :mainEnd
90 | if "%OS%"=="Windows_NT" endlocal
91 |
92 | :omega
93 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original 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 POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37 | # * compound commands having a testable exit status, especially «case»;
38 | # * various built-in commands including «command», «set», and «ulimit».
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | # This is normally unused
84 | # shellcheck disable=SC2034
85 | APP_BASE_NAME=${0##*/}
86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
88 |
89 | # Use the maximum available, or set MAX_FD != -1 to use that value.
90 | MAX_FD=maximum
91 |
92 | warn () {
93 | echo "$*"
94 | } >&2
95 |
96 | die () {
97 | echo
98 | echo "$*"
99 | echo
100 | exit 1
101 | } >&2
102 |
103 | # OS specific support (must be 'true' or 'false').
104 | cygwin=false
105 | msys=false
106 | darwin=false
107 | nonstop=false
108 | case "$( uname )" in #(
109 | CYGWIN* ) cygwin=true ;; #(
110 | Darwin* ) darwin=true ;; #(
111 | MSYS* | MINGW* ) msys=true ;; #(
112 | NONSTOP* ) nonstop=true ;;
113 | esac
114 |
115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
116 |
117 |
118 | # Determine the Java command to use to start the JVM.
119 | if [ -n "$JAVA_HOME" ] ; then
120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
121 | # IBM's JDK on AIX uses strange locations for the executables
122 | JAVACMD=$JAVA_HOME/jre/sh/java
123 | else
124 | JAVACMD=$JAVA_HOME/bin/java
125 | fi
126 | if [ ! -x "$JAVACMD" ] ; then
127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
128 |
129 | Please set the JAVA_HOME variable in your environment to match the
130 | location of your Java installation."
131 | fi
132 | else
133 | JAVACMD=java
134 | if ! command -v java >/dev/null 2>&1
135 | then
136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137 |
138 | Please set the JAVA_HOME variable in your environment to match the
139 | location of your Java installation."
140 | fi
141 | fi
142 |
143 | # Increase the maximum file descriptors if we can.
144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
145 | case $MAX_FD in #(
146 | max*)
147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
148 | # shellcheck disable=SC2039,SC3045
149 | MAX_FD=$( ulimit -H -n ) ||
150 | warn "Could not query maximum file descriptor limit"
151 | esac
152 | case $MAX_FD in #(
153 | '' | soft) :;; #(
154 | *)
155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
156 | # shellcheck disable=SC2039,SC3045
157 | ulimit -n "$MAX_FD" ||
158 | warn "Could not set maximum file descriptor limit to $MAX_FD"
159 | esac
160 | fi
161 |
162 | # Collect all arguments for the java command, stacking in reverse order:
163 | # * args from the command line
164 | # * the main class name
165 | # * -classpath
166 | # * -D...appname settings
167 | # * --module-path (only if needed)
168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
169 |
170 | # For Cygwin or MSYS, switch paths to Windows format before running java
171 | if "$cygwin" || "$msys" ; then
172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
174 |
175 | JAVACMD=$( cygpath --unix "$JAVACMD" )
176 |
177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
178 | for arg do
179 | if
180 | case $arg in #(
181 | -*) false ;; # don't mess with options #(
182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
183 | [ -e "$t" ] ;; #(
184 | *) false ;;
185 | esac
186 | then
187 | arg=$( cygpath --path --ignore --mixed "$arg" )
188 | fi
189 | # Roll the args list around exactly as many times as the number of
190 | # args, so each arg winds up back in the position where it started, but
191 | # possibly modified.
192 | #
193 | # NB: a `for` loop captures its iteration list before it begins, so
194 | # changing the positional parameters here affects neither the number of
195 | # iterations, nor the values presented in `arg`.
196 | shift # remove old arg
197 | set -- "$@" "$arg" # push replacement arg
198 | done
199 | fi
200 |
201 |
202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204 |
205 | # Collect all arguments for the java command:
206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207 | # and any embedded shellness will be escaped.
208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209 | # treated as '${Hostname}' itself on the command line.
210 |
211 | set -- \
212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
213 | -classpath "$CLASSPATH" \
214 | org.gradle.wrapper.GradleWrapperMain \
215 | "$@"
216 |
217 | # Stop when "xargs" is not available.
218 | if ! command -v xargs >/dev/null 2>&1
219 | then
220 | die "xargs is not available"
221 | fi
222 |
223 | # Use "xargs" to parse quoted args.
224 | #
225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
226 | #
227 | # In Bash we could simply go:
228 | #
229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
230 | # set -- "${ARGS[@]}" "$@"
231 | #
232 | # but POSIX shell has neither arrays nor command substitution, so instead we
233 | # post-process each arg (as a line of input to sed) to backslash-escape any
234 | # character that might be a shell metacharacter, then use eval to reverse
235 | # that process (while maintaining the separation between arguments), and wrap
236 | # the whole thing up as a single "set" statement.
237 | #
238 | # This will of course break if any of these variables contains a newline or
239 | # an unmatched quote.
240 | #
241 |
242 | eval "set -- $(
243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
244 | xargs -n1 |
245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
246 | tr '\n' ' '
247 | )" '"$@"'
248 |
249 | exec "$JAVACMD" "$@"
250 |
--------------------------------------------------------------------------------