├── .idea ├── .name ├── .gitignore ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml ├── compiler.xml ├── vcs.xml ├── misc.xml ├── jarRepositories.xml └── gradle.xml ├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ └── strings.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── navigation │ │ │ │ ├── app_nav_graph.xml │ │ │ │ └── details_nav_graph.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── todo │ │ │ │ └── app │ │ │ │ ├── TodoApplication.kt │ │ │ │ ├── MainActivity.kt │ │ │ │ ├── di │ │ │ │ ├── NavigationModule.kt │ │ │ │ ├── AggregatorModule.kt │ │ │ │ ├── DataModule.kt │ │ │ │ └── RouterBindingsModule.kt │ │ │ │ ├── data │ │ │ │ └── AppDatabase.kt │ │ │ │ └── navigation │ │ │ │ ├── AppRouter.kt │ │ │ │ ├── DetailsRouter.kt │ │ │ │ └── BaseRouter.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── todo │ │ │ └── app │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── todo │ │ └── app │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── libs └── base │ ├── data │ ├── consumer-rules.pro │ ├── .gitignore │ ├── src │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── todo │ │ │ │ └── base │ │ │ │ └── data │ │ │ │ ├── cache │ │ │ │ └── Cache.kt │ │ │ │ └── dao │ │ │ │ └── BaseDao.kt │ │ ├── test │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── todo │ │ │ │ └── base │ │ │ │ └── data │ │ │ │ └── ExampleUnitTest.kt │ │ └── androidTest │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── todo │ │ │ └── base │ │ │ └── data │ │ │ └── ExampleInstrumentedTest.kt │ ├── proguard-rules.pro │ └── build.gradle │ ├── view │ ├── consumer-rules.pro │ ├── .gitignore │ ├── src │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── todo │ │ │ │ │ └── base │ │ │ │ │ └── view │ │ │ │ │ ├── navigation │ │ │ │ │ ├── route │ │ │ │ │ │ └── IRoute.kt │ │ │ │ │ ├── router │ │ │ │ │ │ ├── IRouter.kt │ │ │ │ │ │ └── IArgsRouter.kt │ │ │ │ │ ├── fragment │ │ │ │ │ │ ├── IRoutedViewModel.kt │ │ │ │ │ │ ├── RoutedViewModelDelegate.kt │ │ │ │ │ │ └── StackFragment.kt │ │ │ │ │ └── exception │ │ │ │ │ │ └── IllegalRouteException.kt │ │ │ │ │ └── lifecycle │ │ │ │ │ └── LiveDataEvent.kt │ │ │ ├── AndroidManifest.xml │ │ │ └── res │ │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ └── themes.xml │ │ │ │ └── values-night │ │ │ │ └── themes.xml │ │ ├── test │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── todo │ │ │ │ └── base │ │ │ │ └── view │ │ │ │ └── ExampleUnitTest.kt │ │ └── androidTest │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── todo │ │ │ └── base │ │ │ └── view │ │ │ └── ExampleInstrumentedTest.kt │ ├── proguard-rules.pro │ └── build.gradle │ └── domain │ ├── .gitignore │ ├── src │ └── main │ │ └── java │ │ └── com │ │ └── example │ │ └── todo │ │ └── base │ │ ├── domain │ │ ├── IExceptionHandler.kt │ │ ├── FlowUseCaseExtensions.kt │ │ ├── FlowUseCase.kt │ │ └── UseCase.kt │ │ └── data │ │ ├── ITimeLimitedResource.kt │ │ ├── RefreshControl.kt │ │ ├── Resource.kt │ │ └── ResourceGroup.kt │ └── build.gradle ├── features └── todos │ ├── data │ ├── consumer-rules.pro │ ├── .gitignore │ ├── src │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── todo │ │ │ │ └── todos │ │ │ │ └── data │ │ │ │ ├── local │ │ │ │ ├── entity │ │ │ │ │ └── TodoEntity.kt │ │ │ │ ├── mappings │ │ │ │ │ └── TodoMappings.kt │ │ │ │ ├── dao │ │ │ │ │ └── TodoDao.kt │ │ │ │ └── TodosCache.kt │ │ │ │ ├── di │ │ │ │ └── TodoDataModule.kt │ │ │ │ └── remote │ │ │ │ └── MockTodosApi.kt │ │ ├── test │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── todo │ │ │ │ └── todos │ │ │ │ └── data │ │ │ │ └── ExampleUnitTest.kt │ │ └── androidTest │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── todo │ │ │ └── todos │ │ │ └── data │ │ │ └── ExampleInstrumentedTest.kt │ ├── proguard-rules.pro │ └── build.gradle │ ├── view │ ├── consumer-rules.pro │ ├── .gitignore │ ├── src │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── todo │ │ │ │ └── todos │ │ │ │ └── view │ │ │ │ ├── form │ │ │ │ ├── ITodoFormRouter.kt │ │ │ │ ├── TodoFormFragment.kt │ │ │ │ └── TodoFormViewModel.kt │ │ │ │ ├── details │ │ │ │ ├── dialog │ │ │ │ │ ├── IDeleteTodoRouter.kt │ │ │ │ │ └── DeleteTodoDialog.kt │ │ │ │ ├── ITodoDetailsRouter.kt │ │ │ │ ├── TodoDetailsFragment.kt │ │ │ │ └── TodoDetailsViewModel.kt │ │ │ │ ├── list │ │ │ │ ├── ITodoListRouter.kt │ │ │ │ ├── TodoListAdapter.kt │ │ │ │ ├── TodoListFragment.kt │ │ │ │ └── TodoListViewModel.kt │ │ │ │ └── di │ │ │ │ └── TodoFragmentModule.kt │ │ │ └── res │ │ │ ├── menu │ │ │ └── menu_todo_list.xml │ │ │ ├── values │ │ │ └── strings.xml │ │ │ └── layout │ │ │ ├── list_item_todo.xml │ │ │ ├── fragment_todo_list.xml │ │ │ ├── dialog_delete_todo.xml │ │ │ ├── fragment_todo_form.xml │ │ │ └── fragment_todo_details.xml │ ├── proguard-rules.pro │ └── build.gradle │ └── domain │ ├── .gitignore │ ├── src │ └── main │ │ └── java │ │ └── com │ │ └── example │ │ └── todo │ │ └── todos │ │ ├── data │ │ ├── ITodoCache.kt │ │ └── ITodoApi.kt │ │ └── domain │ │ ├── model │ │ └── Todo.kt │ │ ├── usecase │ │ ├── AddTodoUseCase.kt │ │ ├── DeleteTodoUseCase.kt │ │ ├── GetAllTodosUseCase.kt │ │ ├── SetTodoCompletionUseCase.kt │ │ └── GetTodoByIdUseCase.kt │ │ ├── di │ │ └── TodoUseCaseModule.kt │ │ └── repository │ │ └── TodoRepository.kt │ └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── settings.gradle ├── README.md ├── gradle.properties ├── gradlew.bat └── gradlew /.idea/.name: -------------------------------------------------------------------------------- 1 | Todo -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /libs/base/data/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /libs/base/view/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /features/todos/data/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /features/todos/view/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /libs/base/data/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /libs/base/domain/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /libs/base/view/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /features/todos/data/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /features/todos/domain/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /features/todos/view/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | TodoApp 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleweichandt/todo-android-app/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleweichandt/todo-android-app/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleweichandt/todo-android-app/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleweichandt/todo-android-app/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleweichandt/todo-android-app/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleweichandt/todo-android-app/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleweichandt/todo-android-app/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleweichandt/todo-android-app/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleweichandt/todo-android-app/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleweichandt/todo-android-app/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleweichandt/todo-android-app/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /libs/base/domain/src/main/java/com/example/todo/base/domain/IExceptionHandler.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.domain 2 | 3 | interface IExceptionHandler { 4 | fun handle(t: Throwable) 5 | } 6 | -------------------------------------------------------------------------------- /libs/base/view/src/main/java/com/example/todo/base/view/navigation/route/IRoute.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.view.navigation.route 2 | 3 | interface IRoute { 4 | object Back : IRoute 5 | } 6 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /libs/base/data/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /libs/base/view/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /features/todos/data/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /features/todos/view/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/todo/app/TodoApplication.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.app 2 | 3 | import android.app.Application 4 | import dagger.hilt.android.HiltAndroidApp 5 | 6 | @HiltAndroidApp 7 | class TodoApplication : Application() 8 | -------------------------------------------------------------------------------- /features/todos/view/src/main/java/com/example/todo/todos/view/form/ITodoFormRouter.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.view.form 2 | 3 | import com.example.todo.base.view.navigation.router.IRouter 4 | 5 | interface ITodoFormRouter : IRouter 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Jan 30 20:58:37 CET 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip 7 | -------------------------------------------------------------------------------- /features/todos/view/src/main/java/com/example/todo/todos/view/details/dialog/IDeleteTodoRouter.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.view.details.dialog 2 | 3 | import androidx.fragment.app.Fragment 4 | 5 | interface IDeleteTodoRouter { 6 | fun popWithResult(instance: Fragment, result: Boolean) 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /libs/base/view/src/main/java/com/example/todo/base/view/navigation/router/IRouter.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.view.navigation.router 2 | 3 | import androidx.fragment.app.Fragment 4 | import com.example.todo.base.view.navigation.route.IRoute 5 | 6 | interface IRouter { 7 | fun pop(instance: Fragment) 8 | } 9 | -------------------------------------------------------------------------------- /libs/base/domain/src/main/java/com/example/todo/base/data/ITimeLimitedResource.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.data 2 | 3 | import java.util.* 4 | 5 | interface ITimeLimitedResource { 6 | var refreshRate: Long 7 | val lastUpdate: Date? 8 | 9 | suspend fun evict(cleanup: Boolean = false) 10 | } 11 | -------------------------------------------------------------------------------- /libs/base/view/src/main/java/com/example/todo/base/view/navigation/router/IArgsRouter.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.view.navigation.router 2 | 3 | import androidx.fragment.app.Fragment 4 | import java.io.Serializable 5 | 6 | interface IArgsRouter { 7 | fun args(instance: Fragment): Args 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /features/todos/view/src/main/res/menu/menu_todo_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /features/todos/data/src/main/java/com/example/todo/todos/data/local/entity/TodoEntity.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.data.local.entity 2 | 3 | import androidx.room.Entity 4 | import androidx.room.PrimaryKey 5 | 6 | @Entity(tableName = "todo") 7 | data class TodoEntity( 8 | @PrimaryKey val uuid: Long, 9 | val value: String, 10 | val body: String, 11 | val completed: Boolean, 12 | ) 13 | -------------------------------------------------------------------------------- /libs/base/view/src/main/java/com/example/todo/base/view/navigation/fragment/IRoutedViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.view.navigation.fragment 2 | 3 | import androidx.lifecycle.LiveData 4 | import com.example.todo.base.view.lifecycle.LiveDataEvent 5 | import com.example.todo.base.view.navigation.route.IRoute 6 | 7 | interface IRoutedViewModel { 8 | val route: LiveData> 9 | } 10 | -------------------------------------------------------------------------------- /features/todos/data/src/main/java/com/example/todo/todos/data/local/mappings/TodoMappings.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.data.local 2 | 3 | import com.example.todo.todos.data.local.entity.TodoEntity 4 | import com.example.todo.todos.domain.model.Todo 5 | 6 | fun Todo.toEntity() = TodoEntity( 7 | uuid, value, body, completed 8 | ) 9 | 10 | fun TodoEntity.toDomain() = Todo( 11 | value, body, completed, uuid 12 | ) 13 | -------------------------------------------------------------------------------- /features/todos/domain/src/main/java/com/example/todo/todos/data/ITodoCache.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.data 2 | 3 | import com.example.todo.todos.domain.model.Todo 4 | 5 | interface ITodoCache { 6 | suspend fun getAllTodos(): List? 7 | suspend fun getTodoById(id: Long): Todo? 8 | suspend fun storeAllTodos(todos: List) 9 | suspend fun storeTodo(todo: Todo) 10 | suspend fun deleteAllTodos() 11 | } 12 | -------------------------------------------------------------------------------- /libs/base/domain/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | id 'kotlin' 4 | } 5 | 6 | java { 7 | sourceCompatibility = JavaVersion.VERSION_1_8 8 | targetCompatibility = JavaVersion.VERSION_1_8 9 | } 10 | 11 | dependencies { 12 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 13 | 14 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" 15 | 16 | } 17 | -------------------------------------------------------------------------------- /libs/base/view/src/main/java/com/example/todo/base/view/navigation/exception/IllegalRouteException.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.view.navigation.exception 2 | 3 | import androidx.fragment.app.Fragment 4 | import com.example.todo.base.view.navigation.route.IRoute 5 | 6 | class IllegalRouteException(instance: Fragment, route: IRoute) : IllegalStateException( 7 | "unknown route: ${route.javaClass.simpleName} for instance: ${instance.javaClass.simpleName}" 8 | ) 9 | -------------------------------------------------------------------------------- /libs/base/view/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/main/java/com/example/todo/app/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.app 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import dagger.hilt.android.AndroidEntryPoint 6 | 7 | @AndroidEntryPoint 8 | class MainActivity : AppCompatActivity() { 9 | override fun onCreate(savedInstanceState: Bundle?) { 10 | super.onCreate(savedInstanceState) 11 | setContentView(R.layout.activity_main) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/todo/app/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.app 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /features/todos/domain/src/main/java/com/example/todo/todos/data/ITodoApi.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.data 2 | 3 | import com.example.todo.todos.domain.model.Todo 4 | 5 | interface ITodoApi { 6 | suspend fun getAllTodos(): List? 7 | suspend fun getTodoById(id: Long): Todo? 8 | suspend fun addTodo(todo: Todo): Boolean? 9 | suspend fun deleteTodo(todo: Todo): Boolean? 10 | suspend fun updateTodo(todo: Todo, update: Todo): Boolean? 11 | } 12 | -------------------------------------------------------------------------------- /libs/base/data/src/main/java/com/example/todo/base/data/cache/Cache.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.data.cache 2 | 3 | import com.example.todo.base.domain.IExceptionHandler 4 | 5 | abstract class Cache( 6 | private val exceptionHandler: IExceptionHandler 7 | ) { 8 | protected suspend fun runQuery(query: suspend () -> T) = 9 | query.runCatching { invoke() } 10 | .onFailure { exceptionHandler.handle(it) } 11 | .getOrNull() 12 | } 13 | -------------------------------------------------------------------------------- /libs/base/data/src/test/java/com/example/todo/base/data/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.data 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /libs/base/view/src/test/java/com/example/todo/base/view/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.view 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /features/todos/data/src/test/java/com/example/todo/todos/data/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.data 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /features/todos/domain/src/main/java/com/example/todo/todos/domain/model/Todo.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.domain.model 2 | 3 | import java.io.Serializable 4 | 5 | data class Todo( 6 | val value: String = "", 7 | val body: String = "", 8 | val completed: Boolean = false, 9 | val uuid: Long = nextUuid 10 | ) : Serializable { 11 | companion object { 12 | private var uuid: Long = 0 13 | val nextUuid: Long 14 | get() = uuid.also { uuid = it + 1 } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /features/todos/view/src/main/java/com/example/todo/todos/view/list/ITodoListRouter.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.view.list 2 | 3 | import androidx.fragment.app.Fragment 4 | import com.example.todo.base.view.navigation.route.IRoute 5 | import com.example.todo.base.view.navigation.router.IRouter 6 | 7 | interface ITodoListRouter : IRouter { 8 | sealed class TodoListRoute : IRoute { 9 | data class DetailsRoute(val uuid: Long) : TodoListRoute() 10 | object FormRoute : TodoListRoute() 11 | } 12 | 13 | fun push(instance: Fragment, route: TodoListRoute) 14 | } 15 | -------------------------------------------------------------------------------- /features/todos/domain/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | id 'kotlin' 4 | id 'kotlin-kapt' 5 | } 6 | 7 | java { 8 | sourceCompatibility = JavaVersion.VERSION_1_8 9 | targetCompatibility = JavaVersion.VERSION_1_8 10 | } 11 | 12 | dependencies { 13 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 14 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" 15 | 16 | // Dagger 17 | implementation 'com.google.dagger:dagger:2.31.2' 18 | kapt 'com.google.dagger:dagger-compiler:2.31.2' 19 | 20 | api project(':baseDomain') 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/todo/app/di/NavigationModule.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.app.di 2 | 3 | import com.example.todo.app.navigation.AppRouter 4 | import com.example.todo.app.navigation.DetailsRouter 5 | import dagger.Module 6 | import dagger.Provides 7 | import dagger.hilt.InstallIn 8 | import dagger.hilt.components.SingletonComponent 9 | import javax.inject.Singleton 10 | 11 | @Module 12 | @InstallIn(SingletonComponent::class) 13 | object NavigationModule { 14 | @Provides 15 | @Singleton 16 | fun provideAppRouter() = AppRouter() 17 | 18 | @Provides 19 | @Singleton 20 | fun provideDetailsRouter() = DetailsRouter() 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/todo/app/di/AggregatorModule.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.app.di 2 | 3 | import com.example.todo.base.domain.IExceptionHandler 4 | import com.example.todo.todos.domain.di.TodoUseCaseModule 5 | import dagger.Module 6 | import dagger.Provides 7 | import dagger.hilt.InstallIn 8 | import dagger.hilt.components.SingletonComponent 9 | import javax.inject.Singleton 10 | 11 | @Module(includes = [TodoUseCaseModule::class]) 12 | @InstallIn(SingletonComponent::class) 13 | object AggregatorModule { 14 | @Provides 15 | @Singleton 16 | fun provideExceptionHandle() = object : IExceptionHandler { 17 | override fun handle(t: Throwable) {} 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/todo/app/di/DataModule.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.app.di 2 | 3 | import android.app.Application 4 | import com.example.todo.app.data.AppDatabase 5 | import dagger.Module 6 | import dagger.Provides 7 | import dagger.hilt.InstallIn 8 | import dagger.hilt.components.SingletonComponent 9 | import javax.inject.Singleton 10 | 11 | @Module 12 | @InstallIn(SingletonComponent::class) 13 | object DataModule { 14 | @Provides 15 | @Singleton 16 | fun provideAppDatabase(application: Application) = AppDatabase.Builder(application).build() 17 | 18 | @Provides 19 | @Singleton 20 | fun provideTodoDao(database: AppDatabase) = database.todoDao() 21 | } 22 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', 2 | ':baseDomain', 3 | ':baseView', 4 | ':baseData', 5 | ':todosDomain', 6 | ':todosView', 7 | ':todosData' 8 | rootProject.name = "Todo" 9 | 10 | // Libs 11 | // Base 12 | project(':baseDomain').projectDir = new File('libs/base/domain') 13 | project(':baseView').projectDir = new File('libs/base/view') 14 | project(':baseData').projectDir = new File('libs/base/data') 15 | 16 | // Features 17 | // Todos 18 | project(':todosDomain').projectDir = new File('features/todos/domain') 19 | project(':todosView').projectDir = new File('features/todos/view') 20 | project(':todosData').projectDir = new File('features/todos/data') 21 | -------------------------------------------------------------------------------- /libs/base/domain/src/main/java/com/example/todo/base/domain/FlowUseCaseExtensions.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.domain 2 | 3 | import kotlinx.coroutines.ExperimentalCoroutinesApi 4 | import kotlinx.coroutines.flow.Flow 5 | import kotlinx.coroutines.flow.filter 6 | import kotlinx.coroutines.flow.first 7 | import kotlinx.coroutines.flow.toList 8 | 9 | 10 | @ExperimentalCoroutinesApi 11 | suspend operator fun FlowUseCase.invoke() = this(Unit) 12 | 13 | suspend fun Flow>.resolve() = 14 | latest { it is UseCase.Result.Success } ?: first() 15 | 16 | suspend fun Flow.latest(isValid: (T?) -> Boolean = { it != null }): T? = 17 | filter { isValid(it) }.toList().lastOrNull() 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Todo Android App Example 2 | 3 | This example aims to showcase some android patterns i've used across projects i've been worked in. 4 | 5 | ### Showcase 6 | 7 | * Clean architecture with kotlin domain modules 8 | 9 | * Multi module android project 10 | 11 | * Androidx navigation on multi module android projects 12 | 13 | * Offline support using Room Database and kotlin flow **(TODO)** 14 | 15 | ## Contributing 16 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 17 | 18 | Please make sure to update tests as appropriate. 19 | 20 | ## Special Thanks 21 | All [Sync. Money](https://www.sync.money/) Android Team 22 | 23 | ## License 24 | [MIT](https://choosealicense.com/licenses/mit/) 25 | -------------------------------------------------------------------------------- /features/todos/view/src/main/java/com/example/todo/todos/view/details/ITodoDetailsRouter.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.view.details 2 | 3 | import androidx.fragment.app.Fragment 4 | import com.example.todo.base.view.navigation.route.IRoute 5 | import com.example.todo.base.view.navigation.router.IArgsRouter 6 | import com.example.todo.base.view.navigation.router.IRouter 7 | import java.io.Serializable 8 | 9 | interface ITodoDetailsRouter : IRouter, IArgsRouter { 10 | sealed class TodoDetailsRoute : IRoute { 11 | object DeleteTodoDialog : TodoDetailsRoute() 12 | } 13 | 14 | data class TodoDetailsArgs(val uuid: Long) : Serializable 15 | 16 | fun pushForResult(instance: Fragment, route: TodoDetailsRoute, callback: (Boolean) -> Unit) 17 | } 18 | -------------------------------------------------------------------------------- /libs/base/view/src/main/java/com/example/todo/base/view/navigation/fragment/RoutedViewModelDelegate.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.view.navigation.fragment 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.lifecycle.MutableLiveData 5 | import com.example.todo.base.view.lifecycle.LiveDataEvent 6 | import com.example.todo.base.view.navigation.route.IRoute 7 | 8 | class RoutedViewModelDelegate : IRoutedViewModel { 9 | 10 | private val _route = MutableLiveData>() 11 | override val route: LiveData> 12 | get() = _route 13 | 14 | fun pushRoute(route: Route) { 15 | _route.value = LiveDataEvent(route) 16 | } 17 | 18 | fun popRoute() { 19 | _route.value = LiveDataEvent(IRoute.Back) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /features/todos/data/src/main/java/com/example/todo/todos/data/local/dao/TodoDao.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.data.local.dao 2 | 3 | import androidx.room.Dao 4 | import androidx.room.Query 5 | import androidx.room.Transaction 6 | import com.example.todo.base.data.dao.BaseDao 7 | import com.example.todo.todos.data.local.entity.TodoEntity 8 | 9 | @Dao 10 | interface TodoDao : BaseDao { 11 | @Query("SELECT * from todo") 12 | suspend fun getAll(): Array 13 | 14 | @Query("SELECT * from todo WHERE :uuid = uuid") 15 | suspend fun getById(uuid: Long): TodoEntity? 16 | 17 | @Query("DELETE from todo") 18 | suspend fun deleteAll() 19 | } 20 | 21 | @Transaction 22 | suspend fun TodoDao.replaceAll(vararg todos: TodoEntity) { 23 | deleteAll() 24 | insert(*todos) 25 | } 26 | -------------------------------------------------------------------------------- /features/todos/view/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | My TODOs 3 | Add new TODO 4 | Details 5 | Title 6 | Body 7 | Add 8 | Submit 9 | Delete 10 | Yes 11 | No 12 | Delete todo 13 | You are about to delete this TODO.\nAre you sure you want to continue? 14 | 15 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/todo/app/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.app 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.example.todo.app", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /features/todos/domain/src/main/java/com/example/todo/todos/domain/usecase/AddTodoUseCase.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.domain.usecase 2 | 3 | import com.example.todo.base.domain.IExceptionHandler 4 | import com.example.todo.base.domain.UseCase 5 | import com.example.todo.todos.domain.model.Todo 6 | import com.example.todo.todos.domain.repository.TodoRepository 7 | import kotlinx.coroutines.CoroutineDispatcher 8 | import kotlinx.coroutines.Dispatchers 9 | 10 | class AddTodoUseCase( 11 | private val repository: TodoRepository, 12 | handler: IExceptionHandler, 13 | dispatcher: CoroutineDispatcher = Dispatchers.IO 14 | ) : UseCase(handler, dispatcher) { 15 | override suspend fun performAction(param: Todo): Result = 16 | repository.addTodo(param)?.let { Result.Success(it) } ?: Result.Failure() 17 | } 18 | -------------------------------------------------------------------------------- /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/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /features/todos/domain/src/main/java/com/example/todo/todos/domain/usecase/DeleteTodoUseCase.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.domain.usecase 2 | 3 | import com.example.todo.base.domain.IExceptionHandler 4 | import com.example.todo.base.domain.UseCase 5 | import com.example.todo.todos.domain.model.Todo 6 | import com.example.todo.todos.domain.repository.TodoRepository 7 | import kotlinx.coroutines.CoroutineDispatcher 8 | import kotlinx.coroutines.Dispatchers 9 | 10 | class DeleteTodoUseCase( 11 | private val repository: TodoRepository, 12 | handler: IExceptionHandler, 13 | dispatcher: CoroutineDispatcher = Dispatchers.IO 14 | ) : UseCase(handler, dispatcher) { 15 | override suspend fun performAction(param: Todo): Result = 16 | repository.deleteTodo(param)?.let { Result.Success(it) } ?: Result.Failure() 17 | } 18 | -------------------------------------------------------------------------------- /libs/base/data/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 | -------------------------------------------------------------------------------- /libs/base/view/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 | -------------------------------------------------------------------------------- /features/todos/data/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 | -------------------------------------------------------------------------------- /features/todos/data/src/androidTest/java/com/example/todo/todos/data/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.data 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.example.todo.todos.data", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /features/todos/view/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 | -------------------------------------------------------------------------------- /libs/base/data/src/androidTest/java/com/example/todo/base/data/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.data 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.example.todo.base.data.test", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /libs/base/view/src/androidTest/java/com/example/todo/base/view/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.view 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.example.todo.base.view.test", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /libs/base/view/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | -------------------------------------------------------------------------------- /libs/base/view/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | -------------------------------------------------------------------------------- /libs/base/domain/src/main/java/com/example/todo/base/domain/FlowUseCase.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.domain 2 | 3 | import com.example.todo.base.domain.UseCase.Result 4 | import kotlinx.coroutines.CoroutineDispatcher 5 | import kotlinx.coroutines.ExperimentalCoroutinesApi 6 | import kotlinx.coroutines.flow.* 7 | 8 | abstract class FlowUseCase( 9 | private val exceptionHandler: IExceptionHandler, 10 | private val dispatcher: CoroutineDispatcher 11 | ) { 12 | 13 | @ExperimentalCoroutinesApi 14 | @Suppress("TooGenericExceptionCaught") 15 | suspend operator fun invoke(param: TParam) = 16 | performAction(param) 17 | .catch { exception -> 18 | exceptionHandler.handle(exception) 19 | emit(Result.Failure(exception)) 20 | } 21 | .flowOn(dispatcher) 22 | 23 | protected abstract suspend fun performAction(param: TParam): Flow> 24 | } 25 | -------------------------------------------------------------------------------- /features/todos/data/src/main/java/com/example/todo/todos/data/di/TodoDataModule.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.data.di 2 | 3 | import com.example.todo.base.domain.IExceptionHandler 4 | import com.example.todo.todos.data.ITodoApi 5 | import com.example.todo.todos.data.ITodoCache 6 | import com.example.todo.todos.data.local.TodosCache 7 | import com.example.todo.todos.data.local.dao.TodoDao 8 | import com.example.todo.todos.data.remote.MockTodosApi 9 | import dagger.Module 10 | import dagger.Provides 11 | import dagger.hilt.InstallIn 12 | import dagger.hilt.components.SingletonComponent 13 | import javax.inject.Singleton 14 | 15 | @Module 16 | @InstallIn(SingletonComponent::class) 17 | object TodoDataModule { 18 | @Provides 19 | @Singleton 20 | fun provideTodosApi(): ITodoApi = MockTodosApi() 21 | 22 | @Provides 23 | @Singleton 24 | fun provideTodosCache(dao: TodoDao, handler: IExceptionHandler): ITodoCache = 25 | TodosCache(dao, handler) 26 | } 27 | -------------------------------------------------------------------------------- /features/todos/domain/src/main/java/com/example/todo/todos/domain/usecase/GetAllTodosUseCase.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.domain.usecase 2 | 3 | import com.example.todo.base.domain.FlowUseCase 4 | import com.example.todo.base.domain.IExceptionHandler 5 | import com.example.todo.base.domain.UseCase.Result 6 | import com.example.todo.todos.domain.model.Todo 7 | import com.example.todo.todos.domain.repository.TodoRepository 8 | import kotlinx.coroutines.CoroutineDispatcher 9 | import kotlinx.coroutines.Dispatchers 10 | import kotlinx.coroutines.flow.Flow 11 | import kotlinx.coroutines.flow.map 12 | 13 | class GetAllTodosUseCase( 14 | private val repository: TodoRepository, 15 | handler: IExceptionHandler, 16 | dispatcher: CoroutineDispatcher = Dispatchers.IO 17 | ) : FlowUseCase>(handler, dispatcher) { 18 | override suspend fun performAction(param: Boolean): Flow>> = 19 | repository.getAllTodos(param).map { Result.fromNullable(it) } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/todo/app/data/AppDatabase.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.app.data 2 | 3 | import android.app.Application 4 | import androidx.room.Database 5 | import androidx.room.Room 6 | import androidx.room.RoomDatabase 7 | import com.example.todo.todos.data.local.dao.TodoDao 8 | import com.example.todo.todos.data.local.entity.TodoEntity 9 | 10 | private const val DATABASE_VERSION = 1 11 | private const val DATABASE_NAME = "todo-database" 12 | 13 | @Database( 14 | entities = [TodoEntity::class], 15 | version = DATABASE_VERSION, 16 | exportSchema = false 17 | ) 18 | abstract class AppDatabase : RoomDatabase() { 19 | class Builder(private val application: Application) { 20 | private val builder: RoomDatabase.Builder 21 | get() = Room.databaseBuilder(application, AppDatabase::class.java, DATABASE_NAME) 22 | .fallbackToDestructiveMigration() 23 | 24 | fun build(): AppDatabase = builder.build() 25 | } 26 | 27 | abstract fun todoDao(): TodoDao 28 | } 29 | -------------------------------------------------------------------------------- /features/todos/domain/src/main/java/com/example/todo/todos/domain/usecase/SetTodoCompletionUseCase.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.domain.usecase 2 | 3 | import com.example.todo.base.domain.IExceptionHandler 4 | import com.example.todo.base.domain.UseCase 5 | import com.example.todo.todos.domain.model.Todo 6 | import com.example.todo.todos.domain.repository.TodoRepository 7 | import kotlinx.coroutines.CoroutineDispatcher 8 | import kotlinx.coroutines.Dispatchers 9 | 10 | class SetTodoCompletionUseCase( 11 | private val repository: TodoRepository, 12 | handler: IExceptionHandler, 13 | dispatcher: CoroutineDispatcher = Dispatchers.IO 14 | ) : UseCase(handler, dispatcher) { 15 | data class Request( 16 | val item: Todo, 17 | val completion: Boolean 18 | ) 19 | 20 | override suspend fun performAction(param: Request) = 21 | repository.updateTodo(param.item, param.item.copy(completed = param.completion)) 22 | ?.let { Result.Success(it) } ?: Result.Failure() 23 | 24 | } 25 | -------------------------------------------------------------------------------- /features/todos/domain/src/main/java/com/example/todo/todos/domain/usecase/GetTodoByIdUseCase.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.domain.usecase 2 | 3 | import com.example.todo.base.domain.FlowUseCase 4 | import com.example.todo.base.domain.IExceptionHandler 5 | import com.example.todo.base.domain.UseCase.Result 6 | import com.example.todo.todos.domain.model.Todo 7 | import com.example.todo.todos.domain.repository.TodoRepository 8 | import kotlinx.coroutines.CoroutineDispatcher 9 | import kotlinx.coroutines.Dispatchers 10 | import kotlinx.coroutines.flow.map 11 | 12 | class GetTodoByIdUseCase( 13 | private val repository: TodoRepository, 14 | handler: IExceptionHandler, 15 | dispatcher: CoroutineDispatcher = Dispatchers.IO 16 | ) : FlowUseCase(handler, dispatcher) { 17 | data class Request( 18 | val uuid: Long, 19 | val force: Boolean = false 20 | ) 21 | override suspend fun performAction(param: Request) = 22 | repository.getTodoById(param.uuid, param.force).map { Result.fromNullable(it) } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/todo/app/di/RouterBindingsModule.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.app.di 2 | 3 | import com.example.todo.app.navigation.AppRouter 4 | import com.example.todo.app.navigation.DetailsRouter 5 | import com.example.todo.todos.view.details.ITodoDetailsRouter 6 | import com.example.todo.todos.view.details.dialog.IDeleteTodoRouter 7 | import com.example.todo.todos.view.form.ITodoFormRouter 8 | import com.example.todo.todos.view.list.ITodoListRouter 9 | import dagger.Binds 10 | import dagger.Module 11 | import dagger.hilt.InstallIn 12 | import dagger.hilt.android.components.ActivityComponent 13 | 14 | @Module 15 | @InstallIn(ActivityComponent::class) 16 | abstract class RouterBindingsModule { 17 | @Binds 18 | abstract fun bindTodoListRouter(appRouter: AppRouter): ITodoListRouter 19 | 20 | @Binds 21 | abstract fun bindTodoFormRouter(appRouter: AppRouter): ITodoFormRouter 22 | 23 | @Binds 24 | abstract fun bindTodoDetailsRouter(detailsRouter: DetailsRouter): ITodoDetailsRouter 25 | 26 | @Binds 27 | abstract fun bindDeleteTodoRouter(detailsRouter: DetailsRouter): IDeleteTodoRouter 28 | 29 | } 30 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /libs/base/view/src/main/java/com/example/todo/base/view/navigation/fragment/StackFragment.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.view.navigation.fragment 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import androidx.fragment.app.Fragment 6 | import com.example.todo.base.view.lifecycle.consume 7 | import com.example.todo.base.view.navigation.exception.IllegalRouteException 8 | import com.example.todo.base.view.navigation.route.IRoute 9 | import com.example.todo.base.view.navigation.router.IRouter 10 | 11 | abstract class StackFragment : Fragment() { 12 | abstract val router: IRouter 13 | 14 | protected abstract val viewModel: IRoutedViewModel 15 | 16 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 17 | super.onViewCreated(view, savedInstanceState) 18 | observeRoute() 19 | } 20 | 21 | private fun observeRoute() { 22 | viewModel.route.consume(viewLifecycleOwner, this::navigate) 23 | } 24 | 25 | open fun navigate(route: IRoute) { 26 | when (route) { 27 | is IRoute.Back -> router.pop(this) 28 | else -> throw IllegalRouteException(this, route) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /features/todos/view/src/main/java/com/example/todo/todos/view/details/dialog/DeleteTodoDialog.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.view.details.dialog 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.DialogFragment 8 | import com.example.todo.todos.view.databinding.DialogDeleteTodoBinding 9 | import dagger.hilt.android.AndroidEntryPoint 10 | import javax.inject.Inject 11 | 12 | @AndroidEntryPoint 13 | class DeleteTodoDialog : DialogFragment() { 14 | @Inject 15 | lateinit var router: IDeleteTodoRouter 16 | 17 | override fun onCreateView( 18 | inflater: LayoutInflater, container: ViewGroup?, 19 | savedInstanceState: Bundle? 20 | ): View? { 21 | val bindings = DialogDeleteTodoBinding.inflate(inflater, container, false) 22 | bindings.lifecycleOwner = viewLifecycleOwner 23 | bindings.accept.setOnClickListener { onResult(true) } 24 | bindings.dismiss.setOnClickListener { onResult(false) } 25 | return bindings.root 26 | } 27 | 28 | private fun onResult(result: Boolean) { 29 | router.popWithResult(this, result) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /libs/base/domain/src/main/java/com/example/todo/base/domain/UseCase.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.domain 2 | 3 | import kotlinx.coroutines.CoroutineDispatcher 4 | import kotlinx.coroutines.withContext 5 | 6 | abstract class UseCase( 7 | private val exceptionHandler: IExceptionHandler, 8 | private val dispatcher: CoroutineDispatcher 9 | ) { 10 | sealed class Result { 11 | companion object { 12 | fun fromNullable(result: TResultModel?) = when (result) { 13 | null -> Failure() 14 | else -> Success(result) 15 | } 16 | } 17 | 18 | data class Success(val result: TResultModel) : Result() 19 | data class Failure(val error: Throwable? = null) : Result() 20 | } 21 | 22 | suspend operator fun invoke(param: TParam) = try { 23 | withContext(dispatcher) { 24 | performAction(param) 25 | } 26 | } catch (error: Throwable) { 27 | exceptionHandler.handle(error) 28 | Result.Failure(error) 29 | } 30 | 31 | protected abstract suspend fun performAction(param: TParam): Result 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/todo/app/navigation/AppRouter.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.app.navigation 2 | 3 | import androidx.fragment.app.Fragment 4 | import androidx.navigation.fragment.findNavController 5 | import com.example.todo.app.DetailsNavGraphDirections 6 | import com.example.todo.app.R 7 | import com.example.todo.base.view.navigation.exception.IllegalRouteException 8 | import com.example.todo.todos.view.form.ITodoFormRouter 9 | import com.example.todo.todos.view.list.ITodoListRouter 10 | import com.example.todo.todos.view.list.ITodoListRouter.TodoListRoute 11 | import com.example.todo.todos.view.list.TodoListFragmentDirections 12 | 13 | class AppRouter : BaseRouter(), ITodoListRouter, ITodoFormRouter { 14 | override val graphId = R.id.app_nav_graph 15 | 16 | override fun push(instance: Fragment, route: TodoListRoute) { 17 | when (route) { 18 | is TodoListRoute.FormRoute -> TodoListFragmentDirections.actionToForm() 19 | is TodoListRoute.DetailsRoute -> DetailsNavGraphDirections.actionToDetails(route.uuid) 20 | else -> null 21 | }?.let { 22 | instance.findNavController().navigate(it) 23 | } ?: throw IllegalRouteException(instance, route) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /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 22 | -------------------------------------------------------------------------------- /libs/base/view/src/main/java/com/example/todo/base/view/lifecycle/LiveDataEvent.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.view.lifecycle 2 | 3 | import androidx.lifecycle.LifecycleOwner 4 | import androidx.lifecycle.LiveData 5 | import java.io.Serializable 6 | 7 | /** 8 | * Used as a wrapper for data that is exposed via a LiveData that represents an event. 9 | */ 10 | open class LiveDataEvent(private val content: T) : Serializable { 11 | 12 | var hasBeenHandled = false 13 | private set // Allow external read but not write 14 | 15 | /** 16 | * Returns the content and prevents its use again. 17 | */ 18 | fun consume(): T? = if (hasBeenHandled) { 19 | null 20 | } else { 21 | hasBeenHandled = true 22 | content 23 | } 24 | 25 | /** 26 | * Returns the content, even if it's already been handled. 27 | */ 28 | fun peekContent(): T = content 29 | } 30 | 31 | /** 32 | * Extension that will listen for live data events and consume them right away. This allows us to 33 | * avoid writing consume on every block. 34 | */ 35 | fun LiveData>.consume(owner: LifecycleOwner, onChanged: (T) -> Unit) = 36 | this.observe(owner) { 37 | it.consume()?.let { value -> 38 | onChanged(value) 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /features/todos/view/src/main/java/com/example/todo/todos/view/di/TodoFragmentModule.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.view.di 2 | 3 | import com.example.todo.todos.domain.usecase.* 4 | import com.example.todo.todos.view.details.TodoDetailsViewModel 5 | import com.example.todo.todos.view.form.TodoFormViewModel 6 | import com.example.todo.todos.view.list.TodoListViewModel 7 | import dagger.Module 8 | import dagger.Provides 9 | import dagger.hilt.InstallIn 10 | import dagger.hilt.android.components.ViewModelComponent 11 | import dagger.hilt.android.scopes.ViewModelScoped 12 | 13 | @Module 14 | @InstallIn(ViewModelComponent::class) 15 | object TodoFragmentModule { 16 | @Provides 17 | @ViewModelScoped 18 | fun bindsTodoListViewModel( 19 | getAllTodosUseCase: GetAllTodosUseCase, 20 | setTodoCompletionUseCase: SetTodoCompletionUseCase 21 | ) = TodoListViewModel(getAllTodosUseCase, setTodoCompletionUseCase) 22 | 23 | @Provides 24 | @ViewModelScoped 25 | fun bindTodoFormViewModel( 26 | addTodoUseCase: AddTodoUseCase 27 | ) = TodoFormViewModel(addTodoUseCase) 28 | 29 | @Provides 30 | @ViewModelScoped 31 | fun bind( 32 | getTodoByIdUseCase: GetTodoByIdUseCase, 33 | deleteTodoUseCase: DeleteTodoUseCase 34 | ) = TodoDetailsViewModel(getTodoByIdUseCase, deleteTodoUseCase) 35 | } 36 | -------------------------------------------------------------------------------- /features/todos/view/src/main/java/com/example/todo/todos/view/form/TodoFormFragment.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.view.form 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.viewModels 8 | import com.example.todo.base.view.navigation.fragment.StackFragment 9 | import com.example.todo.todos.view.databinding.FragmentTodoFormBinding 10 | import dagger.hilt.android.AndroidEntryPoint 11 | import javax.inject.Inject 12 | 13 | @AndroidEntryPoint 14 | class TodoFormFragment : StackFragment() { 15 | @Inject 16 | override lateinit var router: ITodoFormRouter 17 | 18 | override val viewModel by viewModels() 19 | 20 | override fun onCreateView( 21 | inflater: LayoutInflater, container: ViewGroup?, 22 | savedInstanceState: Bundle? 23 | ): View { 24 | val bindings = FragmentTodoFormBinding.inflate(inflater, container, false) 25 | bindings.vieWModel = viewModel 26 | bindings.lifecycleOwner = viewLifecycleOwner 27 | return bindings.root 28 | } 29 | 30 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 31 | super.onViewCreated(view, savedInstanceState) 32 | observeViewModel() 33 | } 34 | 35 | private fun observeViewModel() { 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 28 | 29 | -------------------------------------------------------------------------------- /libs/base/view/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | compileSdkVersion 30 8 | buildToolsVersion "30.0.3" 9 | 10 | defaultConfig { 11 | minSdkVersion 23 12 | targetSdkVersion 30 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | consumerProguardFiles "consumer-rules.pro" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | compileOptions { 27 | sourceCompatibility JavaVersion.VERSION_1_8 28 | targetCompatibility JavaVersion.VERSION_1_8 29 | } 30 | kotlinOptions { 31 | jvmTarget = '1.8' 32 | } 33 | } 34 | 35 | dependencies { 36 | 37 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 38 | implementation "androidx.core:core-ktx:$core_version" 39 | implementation "androidx.appcompat:appcompat:$compat_version" 40 | implementation "com.google.android.material:material:$material_version" 41 | 42 | testImplementation 'junit:junit:4.+' 43 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 44 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/res/navigation/app_nav_graph.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 15 | 22 | 25 | 26 | 31 | 32 | -------------------------------------------------------------------------------- /libs/base/domain/src/main/java/com/example/todo/base/data/RefreshControl.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.data 2 | 3 | import java.util.* 4 | import java.util.concurrent.TimeUnit 5 | 6 | class RefreshControl( 7 | rate: Long = DEFAULT_REFRESH_RATE_MS, 8 | private var lastUpdateDate: Date? = null 9 | ) : ITimeLimitedResource { 10 | companion object { 11 | val DEFAULT_REFRESH_RATE_MS = TimeUnit.MINUTES.toMillis(5) 12 | } 13 | 14 | interface Listener { 15 | suspend fun cleanup() 16 | } 17 | 18 | private val listeners: MutableList = mutableListOf() 19 | private val children: MutableList = mutableListOf() 20 | 21 | // ITimeLimitedResource 22 | override var refreshRate: Long = rate 23 | override val lastUpdate: Date? 24 | get() = lastUpdateDate 25 | 26 | override suspend fun evict(cleanup: Boolean) { 27 | lastUpdateDate = null 28 | children.forEach { it.evict(cleanup) } 29 | if (cleanup) { 30 | listeners.forEach { it.cleanup() } 31 | } 32 | } 33 | 34 | // Public API 35 | fun createChild(): RefreshControl = 36 | RefreshControl(refreshRate, lastUpdateDate).also { children.add(it) } 37 | 38 | fun addListener(listener: Listener) { 39 | listeners.add(listener) 40 | } 41 | 42 | fun refresh() { 43 | lastUpdateDate = Date() 44 | } 45 | 46 | fun isExpired() = lastUpdateDate?.let { (Date().time - it.time) > refreshRate } ?: true 47 | } 48 | -------------------------------------------------------------------------------- /features/todos/domain/src/main/java/com/example/todo/todos/domain/di/TodoUseCaseModule.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.domain.di 2 | 3 | import com.example.todo.base.domain.IExceptionHandler 4 | import com.example.todo.todos.data.ITodoApi 5 | import com.example.todo.todos.data.ITodoCache 6 | import com.example.todo.todos.domain.repository.TodoRepository 7 | import com.example.todo.todos.domain.usecase.* 8 | import dagger.Module 9 | import dagger.Provides 10 | import javax.inject.Singleton 11 | 12 | @Module 13 | class TodoUseCaseModule { 14 | @Provides 15 | @Singleton 16 | fun provideTodosRepository(cache: ITodoCache, api: ITodoApi) = TodoRepository(cache, api) 17 | 18 | @Provides 19 | fun provideGetAllTodosUseCase(repository: TodoRepository, handler: IExceptionHandler) = 20 | GetAllTodosUseCase(repository, handler) 21 | 22 | @Provides 23 | fun provideGetTodoByIdUseCase(repository: TodoRepository, handler: IExceptionHandler) = 24 | GetTodoByIdUseCase(repository, handler) 25 | 26 | @Provides 27 | fun provideAddTodoUseCase(repository: TodoRepository, handler: IExceptionHandler) = 28 | AddTodoUseCase(repository, handler) 29 | 30 | @Provides 31 | fun provideDeleteTodoUseCase(repository: TodoRepository, handler: IExceptionHandler) = 32 | DeleteTodoUseCase(repository, handler) 33 | 34 | @Provides 35 | fun provideSetTodoCompletionUseCase(repository: TodoRepository, handler: IExceptionHandler) = 36 | SetTodoCompletionUseCase(repository, handler) 37 | } 38 | -------------------------------------------------------------------------------- /features/todos/domain/src/main/java/com/example/todo/todos/domain/repository/TodoRepository.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.domain.repository 2 | 3 | import com.example.todo.base.data.ResourceGroup 4 | import com.example.todo.todos.data.ITodoApi 5 | import com.example.todo.todos.data.ITodoCache 6 | import com.example.todo.todos.domain.model.Todo 7 | import kotlinx.coroutines.flow.Flow 8 | 9 | class TodoRepository( 10 | private val localSource: ITodoCache, 11 | private val remoteSource: ITodoApi 12 | ) { 13 | private val resourceGroup = ResourceGroup( 14 | { remoteSource.getAllTodos() }, 15 | { localSource.getAllTodos() }, 16 | localSource::storeAllTodos, 17 | { id, _ -> remoteSource.getTodoById(id) }, 18 | { id, _ -> localSource.getTodoById(id) }, 19 | localSource::storeTodo, 20 | localSource::deleteAllTodos 21 | ) 22 | 23 | suspend fun getAllTodos(force: Boolean): Flow?> = 24 | resourceGroup.query(Unit, force) 25 | 26 | suspend fun getTodoById(id: Long, force: Boolean): Flow = 27 | resourceGroup.queryByKey(id, Unit, force) 28 | 29 | suspend fun addTodo(todo: Todo): Boolean? = 30 | remoteSource.addTodo(todo).also { resourceGroup.evict() } 31 | 32 | suspend fun deleteTodo(todo: Todo): Boolean? = 33 | remoteSource.deleteTodo(todo).also { resourceGroup.evict() } 34 | 35 | suspend fun updateTodo(todo: Todo, update: Todo): Boolean? = 36 | remoteSource.updateTodo(todo, update).also { resourceGroup.evict() } 37 | } 38 | -------------------------------------------------------------------------------- /libs/base/data/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'kotlin-android' 4 | id 'kotlin-kapt' 5 | } 6 | 7 | android { 8 | compileSdkVersion 30 9 | buildToolsVersion "30.0.3" 10 | 11 | defaultConfig { 12 | minSdkVersion 23 13 | targetSdkVersion 30 14 | versionCode 1 15 | versionName "1.0" 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | consumerProguardFiles "consumer-rules.pro" 19 | } 20 | 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | compileOptions { 28 | sourceCompatibility JavaVersion.VERSION_1_8 29 | targetCompatibility JavaVersion.VERSION_1_8 30 | } 31 | kotlinOptions { 32 | jvmTarget = '1.8' 33 | } 34 | } 35 | 36 | dependencies { 37 | 38 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 39 | implementation "androidx.core:core-ktx:$core_version" 40 | implementation "androidx.appcompat:appcompat:$compat_version" 41 | 42 | // Room 43 | implementation "androidx.room:room-runtime:$room_version" 44 | kapt "androidx.room:room-compiler:$room_version" 45 | implementation "androidx.room:room-ktx:$room_version" 46 | 47 | implementation project(':baseDomain') 48 | 49 | testImplementation 'junit:junit:4.+' 50 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 51 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 52 | } 53 | -------------------------------------------------------------------------------- /libs/base/domain/src/main/java/com/example/todo/base/data/Resource.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.data 2 | 3 | import kotlinx.coroutines.flow.Flow 4 | import kotlinx.coroutines.flow.flow 5 | 6 | class Resource( 7 | private val remoteFetch: suspend (Input) -> Output?, 8 | private val localFetch: suspend (Input) -> Output?, 9 | private val localStore: suspend (Output) -> Unit, 10 | private val localDelete: suspend () -> Unit, 11 | private val refreshControl: RefreshControl = RefreshControl() 12 | ) : RefreshControl.Listener, ITimeLimitedResource by refreshControl { 13 | 14 | init { 15 | refreshControl.addListener(this) 16 | } 17 | 18 | // Public API 19 | suspend fun query(args: Input, force: Boolean = false): Flow = flow { 20 | if (!force) { 21 | fetchFromLocal(args)?.run { emit(this) } 22 | } 23 | if (refreshControl.isExpired() || force) { 24 | fetchFromRemote(args).run { emit(this) } 25 | } 26 | } 27 | 28 | override suspend fun cleanup() { 29 | deleteLocal() 30 | } 31 | 32 | // Private API 33 | private suspend fun deleteLocal() = kotlin.runCatching { 34 | localDelete() 35 | }.getOrNull() 36 | 37 | 38 | private suspend fun fetchFromLocal(args: Input) = kotlin.runCatching { 39 | localFetch(args) 40 | }.getOrNull() 41 | 42 | private suspend fun fetchFromRemote(args: Input) = kotlin.runCatching { 43 | remoteFetch(args) 44 | }.getOrThrow()?.also { 45 | kotlin.runCatching { 46 | localStore(it) 47 | refreshControl.refresh() 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/todo/app/navigation/DetailsRouter.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.app.navigation 2 | 3 | import androidx.fragment.app.Fragment 4 | import androidx.navigation.fragment.findNavController 5 | import androidx.navigation.fragment.navArgs 6 | import com.example.todo.app.R 7 | import com.example.todo.todos.view.details.ITodoDetailsRouter 8 | import com.example.todo.todos.view.details.TodoDetailsFragmentArgs 9 | import com.example.todo.todos.view.details.TodoDetailsFragmentDirections 10 | import com.example.todo.todos.view.details.dialog.IDeleteTodoRouter 11 | 12 | class DetailsRouter : BaseRouter(), ITodoDetailsRouter, IDeleteTodoRouter { 13 | override val graphId = R.id.details_nav_graph 14 | 15 | companion object { 16 | private const val deleteTodoKey = "DeleteTodoDialog:ResultKey" 17 | } 18 | 19 | override fun args(instance: Fragment): ITodoDetailsRouter.TodoDetailsArgs = 20 | instance.navArgs().value.let { 21 | ITodoDetailsRouter.TodoDetailsArgs(it.uuid) 22 | } 23 | 24 | override fun pushForResult( 25 | instance: Fragment, 26 | route: ITodoDetailsRouter.TodoDetailsRoute, 27 | callback: (Boolean) -> Unit 28 | ) { 29 | with(instance.findNavController()) { 30 | observeResultForKey(instance, deleteTodoKey, callback) 31 | navigate(TodoDetailsFragmentDirections.actionToDeleteDialog()) 32 | } 33 | } 34 | 35 | override fun popWithResult(instance: Fragment, result: Boolean) { 36 | with(instance.findNavController()) { 37 | postResult(deleteTodoKey, result) 38 | popBackStack() 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /features/todos/data/src/main/java/com/example/todo/todos/data/local/TodosCache.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.data.local 2 | 3 | import android.util.Log 4 | import com.example.todo.base.data.cache.Cache 5 | import com.example.todo.base.domain.IExceptionHandler 6 | import com.example.todo.todos.data.ITodoCache 7 | import com.example.todo.todos.data.local.dao.TodoDao 8 | import com.example.todo.todos.data.local.dao.replaceAll 9 | import com.example.todo.todos.domain.model.Todo 10 | 11 | class TodosCache( 12 | private val dao: TodoDao, 13 | exceptionHandler: IExceptionHandler 14 | ) : Cache(exceptionHandler), ITodoCache { 15 | companion object { 16 | private const val tag = "LOCAL-SOURCE" 17 | } 18 | override suspend fun getAllTodos() = runQuery { 19 | Log.d(tag, "Get All Todos") 20 | dao.getAll().map { it.toDomain() } 21 | } 22 | 23 | override suspend fun getTodoById(id: Long) = runQuery { 24 | Log.d(tag, "Get Todo $id") 25 | dao.getById(id)?.toDomain() 26 | } 27 | 28 | override suspend fun storeAllTodos(todos: List) { 29 | runQuery { 30 | Log.d(tag, "Add All Todos") 31 | todos.map(Todo::toEntity).let { 32 | dao.replaceAll(*it.toTypedArray()) 33 | } 34 | } 35 | } 36 | 37 | override suspend fun storeTodo(todo: Todo) { 38 | runQuery { 39 | Log.d(tag, "Add Todo ${todo.uuid}") 40 | dao.insert(todo.toEntity()) 41 | } 42 | } 43 | 44 | override suspend fun deleteAllTodos() { 45 | runQuery { 46 | Log.d(tag, "Delete All Todos") 47 | dao.deleteAll() 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /libs/base/data/src/main/java/com/example/todo/base/data/dao/BaseDao.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.data.dao 2 | 3 | import androidx.room.Delete 4 | import androidx.room.Insert 5 | import androidx.room.OnConflictStrategy 6 | import androidx.room.Update 7 | 8 | interface BaseDao { 9 | /** 10 | * Insert an object in the database. 11 | * 12 | * @param obj the object to be inserted. 13 | */ 14 | @Insert(onConflict = OnConflictStrategy.REPLACE) 15 | fun insert(obj: T) 16 | 17 | /** 18 | * Insert an array of objects in the database. 19 | * Will replace with new objects on conflict. 20 | * 21 | * @param obj the objects to be inserted. 22 | */ 23 | @Insert(onConflict = OnConflictStrategy.REPLACE) 24 | fun insert(vararg obj: T) 25 | 26 | /** 27 | * Insert an objects in the database. 28 | * Will ignore new object on conflict. 29 | * 30 | * @param obj the objects to be inserted. 31 | */ 32 | @Insert(onConflict = OnConflictStrategy.IGNORE) 33 | fun insertSoft(obj: T) 34 | 35 | /** 36 | * Insert an array of objects in the database. 37 | * Will ignore new objects on conflict. 38 | * 39 | * @param obj the objects to be inserted. 40 | */ 41 | @Insert(onConflict = OnConflictStrategy.IGNORE) 42 | fun insertSoft(vararg obj: T) 43 | 44 | /** 45 | * Update an object from the database. 46 | * 47 | * @param obj the object to be updated 48 | */ 49 | @Update 50 | fun update(obj: T) 51 | 52 | /** 53 | * Delete an object from the database 54 | * 55 | * @param obj the object to be deleted 56 | */ 57 | @Delete 58 | fun delete(obj: T) 59 | } 60 | -------------------------------------------------------------------------------- /features/todos/data/src/main/java/com/example/todo/todos/data/remote/MockTodosApi.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.data.remote 2 | 3 | import android.util.Log 4 | import com.example.todo.todos.data.ITodoApi 5 | import com.example.todo.todos.domain.model.Todo 6 | import kotlinx.coroutines.delay 7 | 8 | class MockTodosApi: ITodoApi { 9 | companion object { 10 | private const val tag = "REMOTE-SOURCE" 11 | private const val FAKE_DELAY_MS = 2000L 12 | } 13 | private val todos: MutableList = mutableListOf( 14 | Todo("mock", "testt"), 15 | Todo("mock completed", "test", true) 16 | ) 17 | 18 | override suspend fun getAllTodos(): List? { 19 | Log.d(tag, "Get All Todos") 20 | delay(FAKE_DELAY_MS) 21 | return todos 22 | } 23 | 24 | override suspend fun getTodoById(id: Long): Todo? { 25 | Log.d(tag, "Get Todo $id") 26 | delay(FAKE_DELAY_MS) 27 | return todos.find { it.uuid == id } 28 | } 29 | 30 | override suspend fun addTodo(todo: Todo): Boolean? { 31 | Log.d(tag, "Add Todo ${todo.uuid}") 32 | return todos.add(todo) 33 | } 34 | 35 | override suspend fun deleteTodo(todo: Todo): Boolean? { 36 | Log.d(tag, "Delete Todo ${todo.uuid}") 37 | return todos.remove(todo) 38 | } 39 | 40 | override suspend fun updateTodo(todo: Todo, update: Todo): Boolean? { 41 | Log.d(tag, "Update Todo ${todo.uuid}") 42 | return when (val index = todos.indexOf(todo)) { 43 | -1 -> false 44 | else -> { 45 | todos.removeAt(index) 46 | todos.add(index, update) 47 | true 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /libs/base/domain/src/main/java/com/example/todo/base/data/ResourceGroup.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.base.data 2 | 3 | import kotlinx.coroutines.flow.Flow 4 | 5 | class ResourceGroup( 6 | remoteGroupFetch: suspend (Input) -> List?, 7 | localGroupFetch: suspend (Input) -> List?, 8 | localGroupStore: suspend (List) -> Unit, 9 | private val remoteFetch: suspend (Key, Input) -> Output?, 10 | private val localFetch: suspend (Key, Input) -> Output?, 11 | private val localStore: suspend (Output) -> Unit, 12 | localDelete: suspend () -> Unit, 13 | private val refreshControl: RefreshControl = RefreshControl() 14 | ) : ITimeLimitedResource by refreshControl { 15 | private val groupResource = Resource( 16 | remoteGroupFetch, 17 | localGroupFetch, 18 | localGroupStore, 19 | localDelete, 20 | refreshControl 21 | ) 22 | 23 | private val resourceMap: MutableMap> = mutableMapOf() 24 | 25 | // Public API 26 | suspend fun query(args: Input, force: Boolean = false): Flow?> = 27 | groupResource.query(args, force) 28 | 29 | suspend fun queryByKey(key: Key, args: Input, force: Boolean = false): Flow = 30 | singleResource(key).query(args, force) 31 | 32 | // Private API 33 | private fun singleResource(key: Key) = 34 | resourceMap[key] ?: Resource( 35 | { remoteFetch(key, it) }, 36 | { localFetch(key, it) }, 37 | { localStore(it) }, 38 | { }, // Delete will be triggered by parent 39 | refreshControl.createChild() 40 | ).also { resourceMap[key] = it } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /features/todos/data/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'kotlin-android' 4 | id 'kotlin-kapt' 5 | id 'dagger.hilt.android.plugin' 6 | } 7 | 8 | android { 9 | compileSdkVersion 30 10 | buildToolsVersion "30.0.3" 11 | 12 | defaultConfig { 13 | minSdkVersion 23 14 | targetSdkVersion 30 15 | versionCode 1 16 | versionName "1.0" 17 | 18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 19 | consumerProguardFiles "consumer-rules.pro" 20 | } 21 | 22 | buildTypes { 23 | release { 24 | minifyEnabled false 25 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 26 | } 27 | } 28 | compileOptions { 29 | sourceCompatibility JavaVersion.VERSION_1_8 30 | targetCompatibility JavaVersion.VERSION_1_8 31 | } 32 | kotlinOptions { 33 | jvmTarget = '1.8' 34 | } 35 | } 36 | 37 | dependencies { 38 | 39 | // implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 40 | // implementation "androidx.core:core-ktx:$core_version" 41 | // 42 | // Room 43 | implementation "androidx.room:room-runtime:$room_version" 44 | kapt "androidx.room:room-compiler:$room_version" 45 | implementation "androidx.room:room-ktx:$room_version" 46 | 47 | api project(':baseData') 48 | implementation project(':todosDomain') 49 | 50 | //Hilt 51 | implementation "com.google.dagger:hilt-android:$hilt_version" 52 | kapt "com.google.dagger:hilt-android-compiler:$hilt_version" 53 | 54 | testImplementation 'junit:junit:4.+' 55 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 56 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 57 | } 58 | -------------------------------------------------------------------------------- /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/res/navigation/details_nav_graph.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 18 | 19 | 20 | 25 | 28 | 35 | 36 | 41 | 42 | -------------------------------------------------------------------------------- /features/todos/view/src/main/res/layout/list_item_todo.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 11 | 12 | 15 | 16 | 17 | 22 | 23 | 34 | 35 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /features/todos/view/src/main/res/layout/fragment_todo_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 12 | 13 | 14 | 17 | 18 | 23 | 24 | 31 | 32 | 33 | 36 | 37 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /features/todos/view/src/main/java/com/example/todo/todos/view/details/TodoDetailsFragment.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.view.details 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.viewModels 8 | import com.example.todo.base.view.navigation.fragment.StackFragment 9 | import com.example.todo.base.view.navigation.route.IRoute 10 | import com.example.todo.todos.view.databinding.FragmentTodoDetailsBinding 11 | import com.example.todo.todos.view.details.ITodoDetailsRouter.TodoDetailsRoute 12 | 13 | import dagger.hilt.android.AndroidEntryPoint 14 | import javax.inject.Inject 15 | 16 | @AndroidEntryPoint 17 | class TodoDetailsFragment : StackFragment() { 18 | @Inject 19 | override lateinit var router: ITodoDetailsRouter 20 | 21 | private val args by lazy { router.args(this) } 22 | 23 | override val viewModel by viewModels() 24 | 25 | private lateinit var bindings: FragmentTodoDetailsBinding 26 | 27 | override fun onCreateView( 28 | inflater: LayoutInflater, container: ViewGroup?, 29 | savedInstanceState: Bundle? 30 | ): View { 31 | bindings = FragmentTodoDetailsBinding.inflate(inflater, container, false) 32 | bindings.vieWModel = viewModel 33 | bindings.lifecycleOwner = viewLifecycleOwner 34 | with(bindings.swipeRefresh) { 35 | setOnRefreshListener(viewModel) 36 | } 37 | return bindings.root 38 | } 39 | 40 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 41 | super.onViewCreated(view, savedInstanceState) 42 | observeViewModel() 43 | viewModel.onViewCreated(args.uuid) 44 | } 45 | 46 | override fun navigate(route: IRoute) { 47 | when (route) { 48 | is TodoDetailsRoute -> router.pushForResult(this, route, viewModel::onDeleteResult) 49 | else -> super.navigate(route) 50 | } 51 | } 52 | 53 | private fun observeViewModel() { 54 | viewModel.loadingTodo.observe(viewLifecycleOwner) { 55 | bindings.swipeRefresh.isRefreshing = it 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /features/todos/view/src/main/java/com/example/todo/todos/view/form/TodoFormViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.view.form 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.lifecycle.MutableLiveData 5 | import androidx.lifecycle.ViewModel 6 | import androidx.lifecycle.viewModelScope 7 | import com.example.todo.base.domain.UseCase.Result 8 | import com.example.todo.base.view.navigation.fragment.IRoutedViewModel 9 | import com.example.todo.base.view.navigation.fragment.RoutedViewModelDelegate 10 | import com.example.todo.base.view.navigation.route.IRoute 11 | import com.example.todo.todos.domain.model.Todo 12 | import com.example.todo.todos.domain.usecase.AddTodoUseCase 13 | import dagger.hilt.android.lifecycle.HiltViewModel 14 | import kotlinx.coroutines.launch 15 | import javax.inject.Inject 16 | 17 | @HiltViewModel 18 | class TodoFormViewModel( 19 | private val addTodoUseCase: AddTodoUseCase, 20 | private val routerDelegate: RoutedViewModelDelegate = RoutedViewModelDelegate() 21 | ) : ViewModel(), IRoutedViewModel by routerDelegate { 22 | @Inject 23 | constructor( 24 | addTodoUseCase: AddTodoUseCase 25 | ) : this(addTodoUseCase, RoutedViewModelDelegate()) 26 | 27 | private val _readyToSubmit = MutableLiveData(true) 28 | val readyToSubmit: LiveData 29 | get() = _readyToSubmit 30 | 31 | val title = MutableLiveData("") 32 | 33 | val body = MutableLiveData("") 34 | 35 | fun onSubmit() { 36 | if (isValidForm()) { 37 | viewModelScope.launch { 38 | _readyToSubmit.value = false 39 | when (val response = addTodoUseCase(Todo(title.value!!, body.value!!))) { 40 | is Result.Success -> routerDelegate.popRoute() 41 | is Result.Failure -> Unit // TODO handle error 42 | } 43 | _readyToSubmit.value = true 44 | } 45 | } else { 46 | // TODO handle form error 47 | } 48 | } 49 | 50 | private fun isValidForm(): Boolean { 51 | val hasTitle = title.value?.isNotBlank() ?: false 52 | val hasBody = body.value?.isNotBlank() ?: false 53 | return hasTitle && hasBody 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /features/todos/view/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'kotlin-android' 4 | id 'kotlin-kapt' 5 | id 'dagger.hilt.android.plugin' 6 | } 7 | 8 | android { 9 | compileSdkVersion 30 10 | buildToolsVersion "30.0.3" 11 | 12 | defaultConfig { 13 | minSdkVersion 23 14 | targetSdkVersion 30 15 | versionCode 1 16 | versionName "1.0" 17 | 18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 19 | consumerProguardFiles "consumer-rules.pro" 20 | } 21 | 22 | buildTypes { 23 | release { 24 | minifyEnabled false 25 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 26 | } 27 | } 28 | compileOptions { 29 | sourceCompatibility JavaVersion.VERSION_1_8 30 | targetCompatibility JavaVersion.VERSION_1_8 31 | } 32 | kotlinOptions { 33 | jvmTarget = '1.8' 34 | } 35 | buildFeatures { 36 | dataBinding true 37 | } 38 | } 39 | 40 | dependencies { 41 | 42 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 43 | implementation "androidx.core:core-ktx:$core_version" 44 | implementation "androidx.appcompat:appcompat:$compat_version" 45 | implementation "com.google.android.material:material:$material_version" 46 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" 47 | 48 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$viewmodel_version" 49 | implementation "androidx.lifecycle:lifecycle-livedata-ktx:$viewmodel_version" 50 | 51 | implementation "androidx.fragment:fragment-ktx:$fragment_version" 52 | implementation "androidx.legacy:legacy-support-v4:$support_v4_version" 53 | implementation "androidx.constraintlayout:constraintlayout:$constrains_version" 54 | 55 | //Hilt 56 | implementation "com.google.dagger:hilt-android:$hilt_version" 57 | kapt "com.google.dagger:hilt-android-compiler:$hilt_version" 58 | 59 | implementation project(':todosDomain') 60 | implementation project(':baseView') 61 | 62 | testImplementation 'junit:junit:4.+' 63 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 64 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/todo/app/navigation/BaseRouter.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.app.navigation 2 | 3 | import androidx.annotation.IdRes 4 | import androidx.fragment.app.Fragment 5 | import androidx.lifecycle.LifecycleOwner 6 | import androidx.navigation.NavController 7 | import androidx.navigation.fragment.findNavController 8 | import com.example.todo.base.view.lifecycle.LiveDataEvent 9 | import com.example.todo.base.view.lifecycle.consume 10 | import com.example.todo.base.view.navigation.router.IRouter 11 | import java.io.Serializable 12 | 13 | 14 | abstract class BaseRouter : IRouter { 15 | @get:IdRes 16 | abstract val graphId: Int 17 | 18 | override fun pop(instance: Fragment) { 19 | instance.findNavController().popBackStack() 20 | } 21 | 22 | 23 | // Controller Extensions 24 | fun NavController.observeResultForKey( 25 | owner: LifecycleOwner, 26 | key: String, 27 | callback: (value: T) -> Unit 28 | ) { 29 | currentBackStackEntry?.savedStateHandle 30 | ?.let { savedStateHandle -> 31 | savedStateHandle.getLiveData>(key).let { event -> 32 | event.removeObservers(owner) 33 | event.consume(owner) { 34 | savedStateHandle.remove(key) 35 | callback(it) 36 | } 37 | } 38 | } 39 | } 40 | 41 | fun NavController.observeResultForKey( 42 | owner: LifecycleOwner, 43 | key: String, 44 | callback: () -> Unit 45 | ) { 46 | currentBackStackEntry?.savedStateHandle 47 | ?.let { savedStateHandle -> 48 | savedStateHandle.getLiveData>(key).let { event -> 49 | event.removeObservers(owner) 50 | event.consume(owner) { 51 | savedStateHandle.remove(key) 52 | callback() 53 | } 54 | } 55 | } 56 | } 57 | 58 | fun NavController.postResult(key: String, value: T) { 59 | previousBackStackEntry?.savedStateHandle?.set(key, LiveDataEvent(value)) 60 | } 61 | 62 | fun NavController.postResult(key: String) { 63 | previousBackStackEntry?.savedStateHandle?.set(key, LiveDataEvent(Unit)) 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /features/todos/view/src/main/res/layout/dialog_delete_todo.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | 19 | 20 | 28 | 29 | 39 | 40 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /features/todos/view/src/main/java/com/example/todo/todos/view/list/TodoListAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.view.list 2 | 3 | import android.view.LayoutInflater 4 | import android.view.ViewGroup 5 | import androidx.recyclerview.widget.DiffUtil 6 | import androidx.recyclerview.widget.ListAdapter 7 | import androidx.recyclerview.widget.RecyclerView 8 | import com.example.todo.todos.domain.model.Todo 9 | import com.example.todo.todos.view.databinding.ListItemTodoBinding 10 | 11 | class TodoListAdapter( 12 | private val itemCallback: TodoItemCallback 13 | ) : ListAdapter(TodoDiffCallback()) { 14 | class TodoDiffCallback : DiffUtil.ItemCallback() { 15 | override fun areItemsTheSame(oldItem: Todo, newItem: Todo) = 16 | oldItem == newItem 17 | 18 | override fun areContentsTheSame(oldItem: Todo, newItem: Todo): Boolean = 19 | oldItem.uuid == newItem.uuid 20 | 21 | } 22 | 23 | interface TodoItemCallback { 24 | fun onItemSelected(item: Todo) 25 | fun onItemCompletionChanged(item: Todo, completion: Boolean) 26 | } 27 | 28 | class TodoViewHolder( 29 | private val bindings: ListItemTodoBinding, 30 | private val itemCallback: TodoItemCallback 31 | ) : RecyclerView.ViewHolder(bindings.root) { 32 | companion object { 33 | fun create(parent: ViewGroup, itemCallback: TodoItemCallback): TodoViewHolder { 34 | val inflater = LayoutInflater.from(parent.context) 35 | val bindings = ListItemTodoBinding.inflate(inflater, parent, false) 36 | return TodoViewHolder(bindings, itemCallback) 37 | } 38 | } 39 | 40 | fun bind(todo: Todo) { 41 | bindings.item = todo 42 | bindings.complete.setOnCheckedChangeListener { _, isChecked -> 43 | if(isChecked != todo.completed) { 44 | itemCallback.onItemCompletionChanged(todo, isChecked) 45 | } 46 | } 47 | bindings.root.setOnClickListener { itemCallback.onItemSelected(todo) } 48 | bindings.executePendingBindings() 49 | } 50 | } 51 | 52 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TodoViewHolder = 53 | TodoViewHolder.create(parent, itemCallback) 54 | 55 | override fun onBindViewHolder(holder: TodoViewHolder, position: Int) { 56 | holder.bind(getItem(position)) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /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 | } 8 | 9 | android { 10 | compileSdkVersion 30 11 | buildToolsVersion "30.0.3" 12 | 13 | defaultConfig { 14 | applicationId "com.example.todo.app" 15 | minSdkVersion 23 16 | targetSdkVersion 30 17 | versionCode 1 18 | versionName "1.0" 19 | 20 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 21 | } 22 | 23 | buildTypes { 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | compileOptions { 30 | sourceCompatibility JavaVersion.VERSION_1_8 31 | targetCompatibility JavaVersion.VERSION_1_8 32 | } 33 | kotlinOptions { 34 | jvmTarget = '1.8' 35 | } 36 | buildFeatures { 37 | dataBinding true 38 | } 39 | } 40 | 41 | dependencies { 42 | 43 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 44 | implementation "androidx.core:core-ktx:$core_version" 45 | implementation "androidx.appcompat:appcompat:$compat_version" 46 | implementation "com.google.android.material:material:$material_version" 47 | implementation "androidx.constraintlayout:constraintlayout:$constrains_version" 48 | implementation "androidx.fragment:fragment-ktx:$fragment_version" 49 | implementation "androidx.legacy:legacy-support-v4:$support_v4_version" 50 | 51 | // Androidx Navigation 52 | implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" 53 | implementation "androidx.navigation:navigation-ui-ktx:$nav_version" 54 | 55 | // Room 56 | implementation "androidx.room:room-runtime:$room_version" 57 | kapt "androidx.room:room-compiler:$room_version" 58 | implementation "androidx.room:room-ktx:$room_version" 59 | 60 | //Hilt 61 | implementation "com.google.dagger:hilt-android:$hilt_version" 62 | kapt "com.google.dagger:hilt-android-compiler:$hilt_version" 63 | 64 | implementation project(':baseView') 65 | implementation project(':todosView') 66 | implementation project(':todosDomain') 67 | implementation project(':todosData') 68 | 69 | testImplementation 'junit:junit:4.+' 70 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 71 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 72 | } 73 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /features/todos/view/src/main/java/com/example/todo/todos/view/list/TodoListFragment.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.view.list 2 | 3 | import android.os.Bundle 4 | import android.view.LayoutInflater 5 | import android.view.MenuItem 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import androidx.fragment.app.viewModels 9 | import com.example.todo.base.view.navigation.fragment.StackFragment 10 | import com.example.todo.base.view.navigation.route.IRoute 11 | import com.example.todo.todos.view.R 12 | import com.example.todo.todos.view.databinding.FragmentTodoListBinding 13 | import dagger.hilt.android.AndroidEntryPoint 14 | import javax.inject.Inject 15 | 16 | @AndroidEntryPoint 17 | class TodoListFragment : StackFragment() { 18 | @Inject 19 | override lateinit var router: ITodoListRouter 20 | 21 | override val viewModel by viewModels() 22 | 23 | private val adapter by lazy { TodoListAdapter(viewModel) } 24 | 25 | private lateinit var bindings: FragmentTodoListBinding 26 | 27 | override fun onCreateView( 28 | inflater: LayoutInflater, container: ViewGroup?, 29 | savedInstanceState: Bundle? 30 | ): View? { 31 | bindings = FragmentTodoListBinding.inflate(inflater, container, false) 32 | bindings.viewModel = viewModel 33 | bindings.lifecycleOwner = viewLifecycleOwner 34 | bindings.todoList.adapter = adapter 35 | with(bindings.swipeRefresh) { 36 | setOnRefreshListener(viewModel) 37 | } 38 | bindings.toolbar.setOnMenuItemClickListener { onOptionsItemSelected(it) } 39 | return bindings.root 40 | } 41 | 42 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 43 | if (item.itemId == R.id.menu_item_add_todo) { 44 | navigate(ITodoListRouter.TodoListRoute.FormRoute) 45 | return true 46 | } 47 | return super.onOptionsItemSelected(item) 48 | } 49 | 50 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 51 | super.onViewCreated(view, savedInstanceState) 52 | observeViewModel() 53 | viewModel.onViewCreated() 54 | } 55 | 56 | override fun navigate(route: IRoute) { 57 | when (route) { 58 | is ITodoListRouter.TodoListRoute -> router.push(this, route) 59 | else -> super.navigate(route) 60 | } 61 | } 62 | 63 | private fun observeViewModel() { 64 | viewModel.todos.observe(viewLifecycleOwner) { 65 | adapter.submitList(it) 66 | } 67 | viewModel.refreshing.observe(viewLifecycleOwner) { 68 | bindings.swipeRefresh.isRefreshing = it 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /features/todos/view/src/main/java/com/example/todo/todos/view/list/TodoListViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.view.list 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.lifecycle.MutableLiveData 5 | import androidx.lifecycle.ViewModel 6 | import androidx.lifecycle.viewModelScope 7 | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout 8 | import com.example.todo.base.domain.UseCase.Result 9 | import com.example.todo.base.view.navigation.fragment.IRoutedViewModel 10 | import com.example.todo.base.view.navigation.fragment.RoutedViewModelDelegate 11 | import com.example.todo.todos.domain.model.Todo 12 | import com.example.todo.todos.domain.usecase.GetAllTodosUseCase 13 | import com.example.todo.todos.domain.usecase.SetTodoCompletionUseCase 14 | import com.example.todo.todos.view.list.ITodoListRouter.TodoListRoute 15 | import dagger.hilt.android.lifecycle.HiltViewModel 16 | import kotlinx.coroutines.flow.collect 17 | import kotlinx.coroutines.flow.onCompletion 18 | import kotlinx.coroutines.flow.onStart 19 | import kotlinx.coroutines.launch 20 | import javax.inject.Inject 21 | 22 | @HiltViewModel 23 | class TodoListViewModel( 24 | private val getAllTodosUseCase: GetAllTodosUseCase, 25 | private val setTodoCompletionUseCase: SetTodoCompletionUseCase, 26 | private val routerDelegate: RoutedViewModelDelegate = RoutedViewModelDelegate() 27 | ) : ViewModel(), SwipeRefreshLayout.OnRefreshListener, TodoListAdapter.TodoItemCallback, 28 | IRoutedViewModel by routerDelegate { 29 | @Inject 30 | constructor( 31 | getAllTodosUseCase: GetAllTodosUseCase, 32 | setTodoCompletionUseCase: SetTodoCompletionUseCase 33 | ) : this(getAllTodosUseCase, setTodoCompletionUseCase, RoutedViewModelDelegate()) 34 | 35 | private val _todos = MutableLiveData>() 36 | val todos: LiveData> 37 | get() = _todos 38 | 39 | private val _refreshing = MutableLiveData(false) 40 | val refreshing: LiveData 41 | get() = _refreshing 42 | 43 | fun onViewCreated() { 44 | refresh() 45 | } 46 | 47 | override fun onRefresh() { 48 | refresh(true) 49 | } 50 | 51 | override fun onItemSelected(item: Todo) { 52 | routerDelegate.pushRoute(TodoListRoute.DetailsRoute(item.uuid)) 53 | } 54 | 55 | override fun onItemCompletionChanged(item: Todo, completion: Boolean) { 56 | viewModelScope.launch { 57 | when (val response = setTodoCompletionUseCase( 58 | SetTodoCompletionUseCase.Request(item, completion) 59 | )) { 60 | is Result.Success -> refresh() 61 | else -> Unit // TODO handle error 62 | } 63 | } 64 | } 65 | 66 | private fun refresh(force: Boolean = false) { 67 | viewModelScope.launch { 68 | getAllTodosUseCase(force) 69 | .onStart { _refreshing.value = true } 70 | .onCompletion { _refreshing.value = false } 71 | .collect { response -> 72 | when (response) { 73 | is Result.Success -> _todos.value = response.result 74 | else -> Unit //TODO handle error 75 | } 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /features/todos/view/src/main/java/com/example/todo/todos/view/details/TodoDetailsViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.example.todo.todos.view.details 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.lifecycle.MutableLiveData 5 | import androidx.lifecycle.ViewModel 6 | import androidx.lifecycle.viewModelScope 7 | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout 8 | import com.example.todo.base.domain.UseCase.Result 9 | import com.example.todo.base.view.navigation.fragment.IRoutedViewModel 10 | import com.example.todo.base.view.navigation.fragment.RoutedViewModelDelegate 11 | import com.example.todo.base.view.navigation.route.IRoute 12 | import com.example.todo.todos.domain.model.Todo 13 | import com.example.todo.todos.domain.usecase.DeleteTodoUseCase 14 | import com.example.todo.todos.domain.usecase.GetTodoByIdUseCase 15 | import com.example.todo.todos.view.details.ITodoDetailsRouter.TodoDetailsRoute 16 | import dagger.hilt.android.lifecycle.HiltViewModel 17 | import kotlinx.coroutines.flow.collect 18 | import kotlinx.coroutines.flow.onCompletion 19 | import kotlinx.coroutines.flow.onStart 20 | import kotlinx.coroutines.launch 21 | import javax.inject.Inject 22 | 23 | @HiltViewModel 24 | class TodoDetailsViewModel( 25 | private val getTodoByIdUseCase: GetTodoByIdUseCase, 26 | private val deleteTodoUseCase: DeleteTodoUseCase, 27 | private val routerDelegate: RoutedViewModelDelegate = RoutedViewModelDelegate() 28 | ) : ViewModel(), SwipeRefreshLayout.OnRefreshListener, IRoutedViewModel by routerDelegate { 29 | @Inject 30 | constructor( 31 | getTodoByIdUseCase: GetTodoByIdUseCase, 32 | deleteTodoUseCase: DeleteTodoUseCase 33 | ) : this(getTodoByIdUseCase, deleteTodoUseCase, RoutedViewModelDelegate()) 34 | 35 | private var uuid: Long? = null 36 | 37 | private val _loadingTodo = MutableLiveData(true) 38 | val loadingTodo: LiveData 39 | get() = _loadingTodo 40 | 41 | private val _readyToDelete = MutableLiveData(false) 42 | val readyToDelete: LiveData 43 | get() = _readyToDelete 44 | 45 | private val _todo = MutableLiveData() 46 | val todo: LiveData 47 | get() = _todo 48 | 49 | fun onViewCreated(todoUuid: Long) { 50 | uuid = todoUuid 51 | loadTodo() 52 | } 53 | 54 | override fun onRefresh() { 55 | loadTodo(true) 56 | } 57 | 58 | fun onDelete() { 59 | routerDelegate.pushRoute(TodoDetailsRoute.DeleteTodoDialog) 60 | } 61 | 62 | fun onDeleteResult(result: Boolean) { 63 | if (result) { 64 | viewModelScope.launch { 65 | when (val response = deleteTodoUseCase(_todo.value!!)) { 66 | is Result.Success -> routerDelegate.popRoute() 67 | else -> Unit // TODO display error 68 | } 69 | } 70 | } 71 | } 72 | 73 | private fun loadTodo(force: Boolean = false) { 74 | viewModelScope.launch { 75 | uuid?.apply { 76 | getTodoByIdUseCase(GetTodoByIdUseCase.Request(this, force)) 77 | .onStart { 78 | _loadingTodo.value = true 79 | _readyToDelete.value = false 80 | } 81 | .onCompletion { _loadingTodo.value = false } 82 | .collect { response -> 83 | when (response) { 84 | is Result.Success -> { 85 | _todo.value = response.result 86 | _readyToDelete.value = true 87 | } 88 | else -> Unit // TODO display error 89 | } 90 | } 91 | } 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /features/todos/view/src/main/res/layout/fragment_todo_form.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 12 | 13 | 14 | 17 | 18 | 24 | 25 | 34 | 35 | 41 | 42 | 43 | 44 | 52 | 53 | 60 | 61 | 62 | 63 | 71 | 72 | 73 | 76 | 77 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /features/todos/view/src/main/res/layout/fragment_todo_details.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 19 | 20 | 25 | 26 | 31 | 32 | 41 | 42 | 51 | 52 | 61 | 62 | 71 | 72 | 80 | 81 | 82 | 83 | 86 | 87 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 20 | 22 | 23 | 135 | 136 | 138 | 139 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 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 | --------------------------------------------------------------------------------