Skip to content

Commit 9920a6f

Browse files
committed
Fixes comments, some code style
Change-Id: I5c8d7ea2528f0b30d6994e2ea6e25a5e9dda8f6b
1 parent 703ab42 commit 9920a6f

File tree

8 files changed

+22
-29
lines changed

8 files changed

+22
-29
lines changed

app/src/main/java/com/example/android/architecture/blueprints/todoapp/data/source/TasksDataSource.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ import com.example.android.architecture.blueprints.todoapp.data.Result
1919
import com.example.android.architecture.blueprints.todoapp.data.Task
2020
/**
2121
* Main entry point for accessing tasks data.
22-
*
23-
*
24-
* For simplicity, only getTasks() and getTask() have callbacks. Consider adding callbacks to other
25-
* methods to inform the user of network/database errors or successful operations.
26-
* For example, when a new task is created, it's synchronously stored in cache but usually every
27-
* operation on database or network should be executed in a different thread.
2822
*/
2923
interface TasksDataSource {
3024

app/src/main/java/com/example/android/architecture/blueprints/todoapp/data/source/TasksRepository.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ package com.example.android.architecture.blueprints.todoapp.data.source
1919
import com.example.android.architecture.blueprints.todoapp.data.Result
2020
import com.example.android.architecture.blueprints.todoapp.data.Task
2121

22+
/**
23+
* Interface to the data layer.
24+
*/
2225
interface TasksRepository {
2326

2427
suspend fun getTasks(forceUpdate: Boolean = false): Result<List<Task>>
@@ -40,4 +43,4 @@ interface TasksRepository {
4043
suspend fun deleteAllTasks()
4144

4245
suspend fun deleteTask(taskId: String)
43-
}
46+
}

app/src/main/java/com/example/android/architecture/blueprints/todoapp/data/source/local/TasksLocalDataSource.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,15 @@ class TasksLocalDataSource internal constructor(
6262
}
6363

6464
override suspend fun completeTask(taskId: String) {
65-
// Not required for the local data source because the {@link DefaultTasksRepository} handles
66-
// converting from a {@code taskId} to a {@link task} using its cached data.
65+
tasksDao.updateCompleted(taskId, true)
6766
}
6867

6968
override suspend fun activateTask(task: Task) = withContext(ioDispatcher) {
7069
tasksDao.updateCompleted(task.id, false)
7170
}
7271

7372
override suspend fun activateTask(taskId: String) {
74-
// Not required for the local data source because the {@link DefaultTasksRepository} handles
75-
// converting from a {@code taskId} to a {@link task} using its cached data.
73+
tasksDao.updateCompleted(taskId, false)
7674
}
7775

7876
override suspend fun clearCompletedTasks() = withContext<Unit>(ioDispatcher) {

app/src/main/java/com/example/android/architecture/blueprints/todoapp/data/source/local/ToDoDatabase.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import com.example.android.architecture.blueprints.todoapp.data.Task
2222

2323
/**
2424
* The Room Database that contains the Task table.
25+
*
26+
* Note that exportSchema should be true in production databases.
2527
*/
2628
@Database(entities = [Task::class], version = 1, exportSchema = false)
2729
abstract class ToDoDatabase : RoomDatabase() {
2830

2931
abstract fun taskDao(): TasksDao
30-
}
32+
}

app/src/main/java/com/example/android/architecture/blueprints/todoapp/statistics/StatisticsViewModel.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ import com.example.android.architecture.blueprints.todoapp.util.wrapEspressoIdli
2727
import kotlinx.coroutines.launch
2828

2929
/**
30-
* Exposes the data to be used in the statistics screen.
31-
*
32-
*
33-
* This ViewModel uses both [ObservableField]s ([ObservableBoolean]s in this case) and
34-
* [Bindable] getters. The values in [ObservableField]s are used directly in the layout,
35-
* whereas the [Bindable] getters allow us to add some logic to it. This is
36-
* preferable to having logic in the XML layout.
30+
* ViewModel for the statistics screen.
3731
*/
3832
class StatisticsViewModel(
3933
private val tasksRepository: TasksRepository

app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksActivity.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import androidx.navigation.ui.setupWithNavController
2828
import com.example.android.architecture.blueprints.todoapp.R
2929
import com.google.android.material.navigation.NavigationView
3030

31+
/**
32+
* Main activity for the todoapp. Holds the Navigation Host Fragment and the Drawer, Toolbar, etc.
33+
*/
3134
class TasksActivity : AppCompatActivity() {
3235

3336
private lateinit var drawerLayout: DrawerLayout
@@ -39,18 +42,19 @@ class TasksActivity : AppCompatActivity() {
3942
setupNavigationDrawer()
4043
setSupportActionBar(findViewById(R.id.toolbar))
4144

42-
val navController : NavController = findNavController(R.id.nav_host_fragment)
45+
val navController: NavController = findNavController(R.id.nav_host_fragment)
4346
appBarConfiguration =
4447
AppBarConfiguration.Builder(R.id.tasksFragment, R.id.statisticsFragment)
4548
.setDrawerLayout(drawerLayout)
4649
.build()
4750
setupActionBarWithNavController(navController, appBarConfiguration)
4851
findViewById<NavigationView>(R.id.nav_view)
49-
.setupWithNavController(navController)
52+
.setupWithNavController(navController)
5053
}
5154

5255
override fun onSupportNavigateUp(): Boolean {
53-
return findNavController(R.id.nav_host_fragment).navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
56+
return findNavController(R.id.nav_host_fragment).navigateUp(appBarConfiguration)
57+
|| super.onSupportNavigateUp()
5458
}
5559

5660
private fun setupNavigationDrawer() {
@@ -64,4 +68,4 @@ class TasksActivity : AppCompatActivity() {
6468
// Keys for navigation
6569
const val ADD_EDIT_RESULT_OK = Activity.RESULT_FIRST_USER + 1
6670
const val DELETE_RESULT_OK = Activity.RESULT_FIRST_USER + 2
67-
const val EDIT_RESULT_OK = Activity.RESULT_FIRST_USER + 3
71+
const val EDIT_RESULT_OK = Activity.RESULT_FIRST_USER + 3

app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksAdapter.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import com.example.android.architecture.blueprints.todoapp.data.Task
2424
import com.example.android.architecture.blueprints.todoapp.databinding.TaskItemBinding
2525
import com.example.android.architecture.blueprints.todoapp.tasks.TasksAdapter.ViewHolder
2626

27+
/**
28+
* Adapter for the task list. Has a reference to the [TasksViewModel] to send actions back to it.
29+
*/
2730
class TasksAdapter(private val viewModel: TasksViewModel) :
2831
ListAdapter<Task, ViewHolder>(TaskDiffCallback()) {
2932

app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksViewModel.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ import kotlinx.coroutines.launch
3333
import java.util.ArrayList
3434

3535
/**
36-
* Exposes the data to be used in the task list screen.
37-
*
38-
*
39-
* [BaseObservable] implements a listener registration mechanism which is notified when a
40-
* property changes. This is done by assigning a [Bindable] annotation to the property's
41-
* getter method.
36+
* ViewModel for the task list screen.
4237
*/
4338
class TasksViewModel(
4439
private val tasksRepository: TasksRepository

0 commit comments

Comments
 (0)