├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── lucasmontano │ │ └── tasks │ │ ├── MainTestRunner.kt │ │ ├── data │ │ ├── InitDatabaseWorkerTest.kt │ │ └── TaskDaoTest.kt │ │ └── utilities │ │ └── LiveDataTestUtil.kt │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── tasks.json │ ├── java │ │ └── com │ │ │ └── lucasmontano │ │ │ └── tasks │ │ │ ├── TasksApplication.kt │ │ │ ├── binding │ │ │ └── GlideAdapter.kt │ │ │ ├── data │ │ │ ├── AppDatabase.kt │ │ │ ├── Converters.kt │ │ │ ├── dao │ │ │ │ └── TaskDao.kt │ │ │ ├── domain │ │ │ │ └── TaskDomain.kt │ │ │ ├── entities │ │ │ │ └── TaskEntity.kt │ │ │ ├── mappers │ │ │ │ └── ModelMappers.kt │ │ │ └── repositories │ │ │ │ └── TaskRepository.kt │ │ │ ├── di │ │ │ └── DatabaseModule.kt │ │ │ ├── ui │ │ │ ├── MainActivity.kt │ │ │ ├── TaskListFragment.kt │ │ │ └── models │ │ │ │ └── TaskUiModel.kt │ │ │ ├── utilities │ │ │ └── Constants.kt │ │ │ ├── viewmodels │ │ │ └── TaskListViewModel.kt │ │ │ └── workers │ │ │ └── InitDatabaseWorker.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── fragment_task_list.xml │ │ └── item_task.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.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 │ │ ├── navigation │ │ └── nav_main.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── lucasmontano │ └── tasks │ ├── TestUtilities.kt │ └── viewmodels │ └── TaskListViewModelTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties └── settings.gradle /README.md: -------------------------------------------------------------------------------- 1 | # Intro 2 | A Task management app inspired by [Sunflower](https://github.com/android/sunflower) to illustrate Android development best practices with Android Jetpack. 3 | 4 | ## How to Start 5 | - Install the latest version of Android Studio from the Stable Channel. 6 | - Install the right version of Java, if necessary (1.8 at the moment). 7 | - Import this project in Android Studio. 8 | - Do a gradle Sync and resolve any eventual problems. 9 | 10 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'kotlin-kapt' 5 | apply plugin: 'dagger.hilt.android.plugin' 6 | 7 | android { 8 | compileSdkVersion 30 9 | buildToolsVersion "30.0.2" 10 | 11 | buildFeatures { 12 | dataBinding true 13 | } 14 | 15 | compileOptions { 16 | sourceCompatibility JavaVersion.VERSION_1_8 17 | targetCompatibility JavaVersion.VERSION_1_8 18 | } 19 | 20 | kotlinOptions { 21 | jvmTarget = JavaVersion.VERSION_1_8.toString() 22 | } 23 | 24 | defaultConfig { 25 | applicationId "com.lucasmontano.tasks" 26 | minSdkVersion 28 27 | targetSdkVersion 30 28 | versionCode 1 29 | versionName "1.0" 30 | 31 | // TODO change to MainTestRunner when implementing ui tests 32 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 33 | } 34 | 35 | buildTypes { 36 | release { 37 | minifyEnabled false 38 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 39 | } 40 | } 41 | } 42 | 43 | dependencies { 44 | def room_version = "2.2.5" 45 | def work_version = "2.4.0" 46 | def assistedInject_version = "0.5.2" 47 | def hilt_version = "2.28.3-alpha" 48 | def hiltViewModel_version = "1.0.0-alpha02" 49 | def nav_version = "2.3.1" 50 | 51 | implementation fileTree(dir: "libs", include: ["*.jar"]) 52 | 53 | // Core 54 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 55 | implementation 'androidx.core:core-ktx:1.3.2' 56 | implementation 'androidx.appcompat:appcompat:1.2.0' 57 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 58 | 59 | // Navigation 60 | implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" 61 | implementation "androidx.navigation:navigation-ui-ktx:$nav_version" 62 | 63 | // Tasks, Workers 64 | implementation "androidx.work:work-runtime-ktx:$work_version" 65 | 66 | // Data 67 | implementation "androidx.room:room-runtime:$room_version" 68 | kapt "androidx.room:room-compiler:$room_version" 69 | implementation "androidx.room:room-ktx:$room_version" 70 | implementation 'com.google.code.gson:gson:2.8.6' 71 | 72 | // DI 73 | compileOnly "com.squareup.inject:assisted-inject-annotations-dagger2:$assistedInject_version" 74 | kapt "com.squareup.inject:assisted-inject-processor-dagger2:$assistedInject_version" 75 | implementation "com.google.dagger:hilt-android:$hilt_version" 76 | kapt "com.google.dagger:hilt-android-compiler:$hilt_version" 77 | implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hiltViewModel_version" 78 | kapt "androidx.hilt:hilt-compiler:$hiltViewModel_version" 79 | 80 | // Others 81 | implementation 'com.github.bumptech.glide:glide:4.11.0' 82 | annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' 83 | 84 | // Test helpers 85 | testImplementation "androidx.room:room-testing:$room_version" 86 | testImplementation 'junit:junit:4.13' 87 | testImplementation "io.mockk:mockk:1.10.2" 88 | testImplementation 'androidx.arch.core:core-testing:2.1.0' 89 | 90 | androidTestImplementation 'androidx.arch.core:core-testing:2.1.0' 91 | androidTestImplementation "androidx.work:work-testing:$work_version" 92 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 93 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 94 | 95 | testImplementation "com.google.dagger:hilt-android-testing:$hilt_version" 96 | kaptTest "com.google.dagger:hilt-android-compiler:$hilt_version" 97 | 98 | androidTestImplementation "androidx.navigation:navigation-testing:$nav_version" 99 | androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_version" 100 | kaptAndroidTest "com.google.dagger:hilt-android-compiler:$hilt_version" 101 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /app/src/androidTest/java/com/lucasmontano/tasks/MainTestRunner.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.lucasmontano.tasks 18 | 19 | import android.app.Application 20 | import android.content.Context 21 | import androidx.test.runner.AndroidJUnitRunner 22 | import dagger.hilt.android.testing.HiltTestApplication 23 | 24 | // A custom runner to set up the instrumented application class for tests. 25 | class MainTestRunner : AndroidJUnitRunner() { 26 | 27 | override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application { 28 | return super.newApplication(cl, HiltTestApplication::class.java.name, context) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/lucasmontano/tasks/data/InitDatabaseWorkerTest.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.data 2 | 3 | import android.content.Context 4 | import androidx.test.core.app.ApplicationProvider 5 | import androidx.work.ListenableWorker.Result 6 | import androidx.work.WorkManager 7 | import androidx.work.testing.TestListenableWorkerBuilder 8 | import com.lucasmontano.tasks.workers.InitDatabaseWorker 9 | import org.hamcrest.CoreMatchers.`is` 10 | import org.junit.Assert.assertThat 11 | import org.junit.Before 12 | import org.junit.Test 13 | import org.junit.runner.RunWith 14 | import org.junit.runners.JUnit4 15 | 16 | @RunWith(JUnit4::class) 17 | class InitDatabaseWorkerTest { 18 | private lateinit var context: Context 19 | private lateinit var workManager: WorkManager 20 | 21 | @Before 22 | fun setup() { 23 | context = ApplicationProvider.getApplicationContext() 24 | workManager = WorkManager.getInstance(context) 25 | } 26 | 27 | @Test 28 | fun testRefreshMainDataWork() { 29 | val worker = TestListenableWorkerBuilder(context).build() 30 | val result = worker.startWork().get() 31 | assertThat(result, `is`(Result.success())) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/lucasmontano/tasks/data/TaskDaoTest.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.data 2 | 3 | import androidx.arch.core.executor.testing.InstantTaskExecutorRule 4 | import androidx.room.Room 5 | import androidx.test.ext.junit.runners.AndroidJUnit4 6 | import androidx.test.platform.app.InstrumentationRegistry 7 | import com.lucasmontano.tasks.data.dao.TaskDao 8 | import com.lucasmontano.tasks.data.entities.TaskEntity 9 | import com.lucasmontano.tasks.utilities.getValue 10 | import kotlinx.coroutines.runBlocking 11 | import org.hamcrest.Matchers.equalTo 12 | import org.junit.After 13 | import org.junit.Assert.assertThat 14 | import org.junit.Before 15 | import org.junit.Rule 16 | import org.junit.Test 17 | import org.junit.runner.RunWith 18 | 19 | @RunWith(AndroidJUnit4::class) 20 | class TaskDaoTest { 21 | private lateinit var database: AppDatabase 22 | private lateinit var dao: TaskDao 23 | 24 | private val taskA = TaskEntity("a", "Task A") 25 | private val taskB = TaskEntity("b", "Task B") 26 | private val taskC = TaskEntity("c", "Task C") 27 | 28 | @get:Rule 29 | var instantTaskExecutorRule = InstantTaskExecutorRule() 30 | 31 | @Before 32 | fun createDb() = runBlocking { 33 | val context = InstrumentationRegistry.getInstrumentation().targetContext 34 | database = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java).build() 35 | dao = database.taskDao() 36 | dao.insertAll(listOf(taskA, taskB, taskC)) 37 | } 38 | 39 | @After 40 | fun closeDb() { 41 | database.close() 42 | } 43 | 44 | @Test 45 | fun testGetAllTasks() { 46 | val taskList = getValue(dao.getAllTasks()) 47 | assertThat(taskList.size, equalTo(3)) 48 | assertThat(taskList[0], equalTo(taskA)) 49 | assertThat(taskList[1], equalTo(taskB)) 50 | assertThat(taskList[2], equalTo(taskC)) 51 | } 52 | 53 | @Test 54 | fun testGetTask() { 55 | assertThat(getValue(dao.getTask(taskA.taskId)), equalTo(taskA)) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/lucasmontano/tasks/utilities/LiveDataTestUtil.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.lucasmontano.tasks.utilities 18 | 19 | import androidx.lifecycle.LiveData 20 | import java.util.concurrent.CountDownLatch 21 | import java.util.concurrent.TimeUnit 22 | 23 | /** 24 | * Helper method for testing LiveData objects, from 25 | * https://github.com/googlesamples/android-architecture-components. 26 | * 27 | * Get the value from a LiveData object. We're waiting for LiveData to emit, for 2 seconds. 28 | * Once we got a notification via onChanged, we stop observing. 29 | */ 30 | @Throws(InterruptedException::class) 31 | fun getValue(liveData: LiveData): T { 32 | val data = arrayOfNulls(1) 33 | val latch = CountDownLatch(1) 34 | liveData.observeForever { o -> 35 | data[0] = o 36 | latch.countDown() 37 | } 38 | latch.await(2, TimeUnit.SECONDS) 39 | 40 | @Suppress("UNCHECKED_CAST") 41 | return data[0] as T 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/assets/tasks.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "A", 4 | "title": "Clonar o repositorio do Lucas Montano" 5 | }, 6 | { 7 | "id": "B", 8 | "title": "Hello World!" 9 | }, 10 | { 11 | "id": "C", 12 | "title": "Criar uma lista de tarefas" 13 | }, 14 | { 15 | "id": "D", 16 | "title": "Customizar o aplicativo de tarefas" 17 | } 18 | ] -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/TasksApplication.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks 2 | 3 | import android.app.Application 4 | import dagger.hilt.android.HiltAndroidApp 5 | 6 | @HiltAndroidApp 7 | class TasksApplication : Application() 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/binding/GlideAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.binding 2 | 3 | import android.widget.ImageView 4 | import androidx.databinding.BindingAdapter 5 | import com.bumptech.glide.Glide 6 | import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions 7 | 8 | @BindingAdapter("imageFromUrl") 9 | fun bindImageFromUrl(view: ImageView, imageUrl: String?) { 10 | if (!imageUrl.isNullOrEmpty()) { 11 | Glide.with(view.context) 12 | .load(imageUrl) 13 | .transition(DrawableTransitionOptions.withCrossFade()) 14 | .into(view) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/data/AppDatabase.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.data 2 | 3 | import android.content.Context 4 | import androidx.room.Database 5 | import androidx.room.Room 6 | import androidx.room.RoomDatabase 7 | import androidx.room.TypeConverters 8 | import androidx.sqlite.db.SupportSQLiteDatabase 9 | import androidx.work.OneTimeWorkRequestBuilder 10 | import androidx.work.WorkManager 11 | import com.lucasmontano.tasks.data.dao.TaskDao 12 | import com.lucasmontano.tasks.data.entities.TaskEntity 13 | import com.lucasmontano.tasks.utilities.DATABASE_NAME 14 | import com.lucasmontano.tasks.workers.InitDatabaseWorker 15 | 16 | @Database( 17 | entities = [TaskEntity::class], 18 | version = 1, 19 | exportSchema = false 20 | ) 21 | @TypeConverters(Converters::class) 22 | abstract class AppDatabase : RoomDatabase() { 23 | 24 | abstract fun taskDao(): TaskDao 25 | 26 | companion object { 27 | 28 | @Volatile 29 | private var instance: AppDatabase? = null 30 | 31 | fun getInstance(context: Context): AppDatabase { 32 | return instance ?: synchronized(this) { 33 | instance ?: buildDatabase(context).also { instance = it } 34 | } 35 | } 36 | 37 | private fun buildDatabase(context: Context): AppDatabase { 38 | return Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME) 39 | .addCallback( 40 | object : RoomDatabase.Callback() { 41 | override fun onCreate(db: SupportSQLiteDatabase) { 42 | super.onCreate(db) 43 | val request = OneTimeWorkRequestBuilder().build() 44 | WorkManager.getInstance(context).enqueue(request) 45 | } 46 | } 47 | ) 48 | .build() 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/data/Converters.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.data 2 | 3 | import androidx.room.TypeConverter 4 | import java.util.* 5 | 6 | /** 7 | * Type converters to allow Room to reference complex data types. 8 | */ 9 | class Converters { 10 | @TypeConverter 11 | fun calendarToDatestamp(calendar: Calendar): Long = calendar.timeInMillis 12 | 13 | @TypeConverter 14 | fun datestampToCalendar(value: Long): Calendar = 15 | Calendar.getInstance().apply { timeInMillis = value } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/data/dao/TaskDao.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.data.dao 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.room.Dao 5 | import androidx.room.Insert 6 | import androidx.room.OnConflictStrategy 7 | import androidx.room.Query 8 | import com.lucasmontano.tasks.data.entities.TaskEntity 9 | import com.lucasmontano.tasks.utilities.DATABASE_TABLE_TASKS 10 | 11 | @Dao 12 | interface TaskDao { 13 | @Query("SELECT * FROM $DATABASE_TABLE_TASKS ORDER BY title") 14 | fun getAllTasks(): LiveData> 15 | 16 | @Query("SELECT * FROM $DATABASE_TABLE_TASKS WHERE id = :taskId") 17 | fun getTask(taskId: String): LiveData 18 | 19 | @Insert(onConflict = OnConflictStrategy.REPLACE) 20 | suspend fun insertAll(taskList: List) 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/data/domain/TaskDomain.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.data.domain 2 | 3 | data class TaskDomain(val title: String) -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/data/entities/TaskEntity.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.data.entities 2 | 3 | import androidx.room.ColumnInfo 4 | import androidx.room.Entity 5 | import androidx.room.PrimaryKey 6 | import com.google.gson.annotations.SerializedName 7 | import com.lucasmontano.tasks.utilities.DATABASE_TABLE_TASKS 8 | 9 | @Entity(tableName = DATABASE_TABLE_TASKS) 10 | data class TaskEntity( 11 | @PrimaryKey 12 | @ColumnInfo(name = "id") 13 | @SerializedName("id") 14 | val taskId: String, 15 | val title: String 16 | ) { 17 | 18 | override fun toString() = title 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/data/mappers/ModelMappers.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.data.mappers 2 | 3 | import com.lucasmontano.tasks.data.domain.TaskDomain 4 | import com.lucasmontano.tasks.data.entities.TaskEntity 5 | 6 | fun TaskEntity.toDomainModel() = TaskDomain(title = this.title) 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/data/repositories/TaskRepository.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.data.repositories 2 | 3 | import androidx.lifecycle.Transformations 4 | import com.lucasmontano.tasks.data.dao.TaskDao 5 | import com.lucasmontano.tasks.data.mappers.toDomainModel 6 | import javax.inject.Inject 7 | import javax.inject.Singleton 8 | 9 | @Singleton 10 | class TaskRepository @Inject constructor(private val taskDao: TaskDao) { 11 | 12 | fun getAllTasks() = Transformations.map(taskDao.getAllTasks()) { tasks -> 13 | tasks.map { 14 | it.toDomainModel() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/di/DatabaseModule.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.lucasmontano.tasks.di 18 | 19 | import android.content.Context 20 | import com.lucasmontano.tasks.data.AppDatabase 21 | import com.lucasmontano.tasks.data.dao.TaskDao 22 | import dagger.Module 23 | import dagger.Provides 24 | import dagger.hilt.InstallIn 25 | import dagger.hilt.android.components.ApplicationComponent 26 | import dagger.hilt.android.qualifiers.ApplicationContext 27 | import javax.inject.Singleton 28 | 29 | @InstallIn(ApplicationComponent::class) 30 | @Module 31 | class DatabaseModule { 32 | 33 | @Singleton 34 | @Provides 35 | fun provideAppDatabase(@ApplicationContext context: Context): AppDatabase { 36 | return AppDatabase.getInstance(context) 37 | } 38 | 39 | @Provides 40 | fun provideTaskDao(appDatabase: AppDatabase): TaskDao { 41 | return appDatabase.taskDao() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/ui/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.ui 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import com.lucasmontano.tasks.R 6 | import dagger.hilt.android.AndroidEntryPoint 7 | 8 | @AndroidEntryPoint 9 | class MainActivity : AppCompatActivity() { 10 | 11 | override fun onCreate(savedInstanceState: Bundle?) { 12 | super.onCreate(savedInstanceState) 13 | setContentView(R.layout.activity_main) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/ui/TaskListFragment.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.ui 2 | 3 | import android.os.Bundle 4 | import android.util.Log 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import androidx.fragment.app.Fragment 9 | import androidx.fragment.app.viewModels 10 | import androidx.lifecycle.Observer 11 | import com.lucasmontano.tasks.databinding.FragmentTaskListBinding 12 | import com.lucasmontano.tasks.viewmodels.TaskListViewModel 13 | import dagger.hilt.android.AndroidEntryPoint 14 | 15 | @AndroidEntryPoint 16 | class TaskListFragment : Fragment() { 17 | 18 | private val viewModel: TaskListViewModel by viewModels() 19 | 20 | private lateinit var binding: FragmentTaskListBinding 21 | 22 | override fun onCreateView( 23 | inflater: LayoutInflater, 24 | container: ViewGroup?, 25 | savedInstanceState: Bundle? 26 | ): View? { 27 | binding = FragmentTaskListBinding.inflate(inflater, container, false) 28 | context ?: return binding.root 29 | 30 | binding.lifecycleOwner = viewLifecycleOwner 31 | 32 | subscribeToUiState() 33 | 34 | return binding.root 35 | } 36 | 37 | private fun subscribeToUiState() { 38 | viewModel.uiState.observe(viewLifecycleOwner, Observer { uiState -> 39 | uiState.tasks.forEach { 40 | Log.d(TAG, it.title) 41 | } 42 | }) 43 | } 44 | 45 | companion object { 46 | 47 | val TAG: String = TaskListFragment::class.java.simpleName 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/ui/models/TaskUiModel.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.ui.models 2 | 3 | data class TaskUiModel(val title: String) -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/utilities/Constants.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.utilities 2 | 3 | // Data 4 | const val DATABASE_NAME = "tasks-db" 5 | const val DATA_FILENAME = "tasks.json" 6 | const val DATABASE_TABLE_TASKS = "tasks" -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/viewmodels/TaskListViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.viewmodels 2 | 3 | import androidx.hilt.lifecycle.ViewModelInject 4 | import androidx.lifecycle.LiveData 5 | import androidx.lifecycle.MutableLiveData 6 | import androidx.lifecycle.Transformations 7 | import androidx.lifecycle.ViewModel 8 | import com.lucasmontano.tasks.data.domain.TaskDomain 9 | import com.lucasmontano.tasks.data.repositories.TaskRepository 10 | import com.lucasmontano.tasks.ui.models.TaskUiModel 11 | 12 | class TaskListViewModel @ViewModelInject internal constructor( 13 | taskRepository: TaskRepository 14 | ) : ViewModel() { 15 | 16 | private val filter = MutableLiveData() 17 | 18 | private val tasks: LiveData> = Transformations.switchMap(filter) { 19 | when (filter.value) { 20 | is FilterState.ToDo -> { 21 | Transformations.map(taskRepository.getAllTasks()) { tasks -> 22 | tasks.toUiModel() 23 | } 24 | } 25 | is FilterState.Done -> { 26 | Transformations.map(taskRepository.getAllTasks()) { tasks -> 27 | tasks.toUiModel() 28 | } 29 | } 30 | else -> { 31 | null 32 | } 33 | } 34 | } 35 | 36 | val uiState: LiveData = Transformations.switchMap(tasks) { 37 | MutableLiveData(ViewState(it)) 38 | } 39 | 40 | init { 41 | filter.postValue(FilterState.ToDo) 42 | } 43 | 44 | private fun List.toUiModel(): List { 45 | return this.map { 46 | TaskUiModel(title = it.title) 47 | } 48 | } 49 | 50 | data class ViewState(val tasks: List) 51 | 52 | private sealed class FilterState { 53 | object Done : FilterState() 54 | object ToDo : FilterState() 55 | } 56 | } -------------------------------------------------------------------------------- /app/src/main/java/com/lucasmontano/tasks/workers/InitDatabaseWorker.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.workers 2 | 3 | import android.content.Context 4 | import android.util.Log 5 | import androidx.work.CoroutineWorker 6 | import androidx.work.WorkerParameters 7 | import com.google.gson.stream.JsonReader 8 | import com.lucasmontano.tasks.data.AppDatabase 9 | import com.lucasmontano.tasks.data.entities.TaskEntity 10 | import com.lucasmontano.tasks.utilities.DATA_FILENAME 11 | import kotlinx.coroutines.Dispatchers 12 | import kotlinx.coroutines.coroutineScope 13 | import kotlinx.coroutines.withContext 14 | import java.io.IOException 15 | import java.io.InputStream 16 | import java.io.InputStreamReader 17 | 18 | 19 | class InitDatabaseWorker( 20 | context: Context, 21 | workerParams: WorkerParameters 22 | ) : CoroutineWorker(context, workerParams) { 23 | 24 | override suspend fun doWork(): Result = coroutineScope { 25 | try { 26 | val tasks: List = withContext(Dispatchers.IO) { 27 | applicationContext.assets.open(DATA_FILENAME).use { inputStream -> 28 | readJsonStream(inputStream) 29 | } 30 | } 31 | 32 | val database = AppDatabase.getInstance(applicationContext) 33 | database.taskDao().insertAll(tasks) 34 | 35 | Result.success() 36 | } catch (ex: Exception) { 37 | Log.e(TAG, "Error initializing database", ex) 38 | Result.failure() 39 | } 40 | } 41 | 42 | @Throws(IOException::class) 43 | fun readJsonStream(`in`: InputStream?): List { 44 | val reader = JsonReader(InputStreamReader(`in`, "UTF-8")) 45 | return reader.use { 46 | readMessagesArray(it) 47 | } 48 | } 49 | 50 | @Throws(IOException::class) 51 | fun readMessagesArray(reader: JsonReader): List { 52 | val messages: MutableList = ArrayList() 53 | reader.beginArray() 54 | while (reader.hasNext()) { 55 | messages.add(readMessage(reader)) 56 | } 57 | reader.endArray() 58 | return messages 59 | } 60 | 61 | @Throws(IOException::class) 62 | fun readMessage(reader: JsonReader): TaskEntity { 63 | var id = "" 64 | var title = "" 65 | reader.beginObject() 66 | while (reader.hasNext()) { 67 | when (reader.nextName()) { 68 | "id" -> { 69 | id = reader.nextString() 70 | } 71 | "title" -> { 72 | title = reader.nextString() 73 | } 74 | else -> { 75 | reader.skipValue() 76 | } 77 | } 78 | } 79 | reader.endObject() 80 | return TaskEntity(taskId = id, title = title) 81 | } 82 | 83 | companion object { 84 | private val TAG = this::class.simpleName 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_task_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_task.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 19 | 20 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasmontano/todo/9136623154746924946b6c8cf43a71ea5917ac5d/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasmontano/todo/9136623154746924946b6c8cf43a71ea5917ac5d/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasmontano/todo/9136623154746924946b6c8cf43a71ea5917ac5d/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasmontano/todo/9136623154746924946b6c8cf43a71ea5917ac5d/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasmontano/todo/9136623154746924946b6c8cf43a71ea5917ac5d/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasmontano/todo/9136623154746924946b6c8cf43a71ea5917ac5d/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasmontano/todo/9136623154746924946b6c8cf43a71ea5917ac5d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasmontano/todo/9136623154746924946b6c8cf43a71ea5917ac5d/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasmontano/todo/9136623154746924946b6c8cf43a71ea5917ac5d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasmontano/todo/9136623154746924946b6c8cf43a71ea5917ac5d/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/navigation/nav_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #6200EE 4 | #3700B3 5 | #03DAC5 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | My Tasks 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/test/java/com/lucasmontano/tasks/TestUtilities.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.lucasmontano.tasks 18 | 19 | import androidx.lifecycle.LiveData 20 | import java.util.concurrent.CountDownLatch 21 | import java.util.concurrent.TimeUnit 22 | 23 | /** 24 | * Helper method for testing LiveData objects, from 25 | * https://github.com/googlesamples/android-architecture-components. 26 | * 27 | * Get the value from a LiveData object. We're waiting for LiveData to emit, for 2 seconds. 28 | * Once we got a notification via onChanged, we stop observing. 29 | */ 30 | @Throws(InterruptedException::class) 31 | fun getValueUnitTest(liveData: LiveData): T { 32 | val data = arrayOfNulls(1) 33 | val latch = CountDownLatch(1) 34 | liveData.observeForever { o -> 35 | data[0] = o 36 | latch.countDown() 37 | } 38 | latch.await(2, TimeUnit.SECONDS) 39 | 40 | @Suppress("UNCHECKED_CAST") 41 | return data[0] as T 42 | } 43 | -------------------------------------------------------------------------------- /app/src/test/java/com/lucasmontano/tasks/viewmodels/TaskListViewModelTest.kt: -------------------------------------------------------------------------------- 1 | package com.lucasmontano.tasks.viewmodels 2 | 3 | import androidx.arch.core.executor.testing.InstantTaskExecutorRule 4 | import androidx.lifecycle.MutableLiveData 5 | import com.lucasmontano.tasks.data.domain.TaskDomain 6 | import com.lucasmontano.tasks.data.repositories.TaskRepository 7 | import com.lucasmontano.tasks.getValueUnitTest 8 | import io.mockk.MockKAnnotations 9 | import io.mockk.every 10 | import io.mockk.impl.annotations.MockK 11 | import org.junit.Assert.assertTrue 12 | import org.junit.Before 13 | import org.junit.Rule 14 | import org.junit.Test 15 | 16 | class TaskListViewModelTest { 17 | 18 | @Rule 19 | @JvmField 20 | val instantExecutor = InstantTaskExecutorRule() 21 | 22 | @MockK(relaxed = true) 23 | lateinit var repository: TaskRepository 24 | 25 | private lateinit var viewModel: TaskListViewModel 26 | 27 | private val taskA = TaskDomain( 28 | "Task A" 29 | ) 30 | private val taskB = TaskDomain( 31 | "Task B" 32 | ) 33 | private val taskC = TaskDomain( 34 | "Task C" 35 | ) 36 | 37 | @Before 38 | fun setUp() { 39 | MockKAnnotations.init(this) 40 | 41 | viewModel = TaskListViewModel(repository) 42 | 43 | every { 44 | repository.getAllTasks() 45 | } returns MutableLiveData( 46 | listOf( 47 | taskA, taskB, taskC 48 | ) 49 | ) 50 | } 51 | 52 | @Test 53 | @Throws(InterruptedException::class) 54 | fun `when initializing the viewmodel, ToDo tasks are listed`() { 55 | assertTrue(getValueUnitTest(viewModel.uiState).tasks.isNotEmpty()) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | ext.kotlin_version = "1.3.72" 4 | repositories { 5 | google() 6 | jcenter() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:4.1.1' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | classpath 'com.google.dagger:hilt-android-gradle-plugin:2.28.3-alpha' 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m 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 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lucasmontano/todo/9136623154746924946b6c8cf43a71ea5917ac5d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Nov 16 20:24:38 CET 2020 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-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file must *NOT* be checked into Version Control Systems, 2 | # as it contains information specific to your local configuration. 3 | # 4 | # Location of the SDK. This is only used by Gradle. 5 | # For customization when using a Version Control System, please read the 6 | # header note. 7 | #Mon Nov 16 20:10:23 CET 2020 8 | sdk.dir=/Users/lucasmontano/Library/Android/sdk 9 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name = "Tasks" --------------------------------------------------------------------------------