Skip to content

Commit d244827

Browse files
committed
Auto-format run
Change-Id: I3ce50dc5e1ce51f1d3c73fbcee07e6f1f207c9be
1 parent 5111cf3 commit d244827

16 files changed

+60
-56
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
2929
* define which view controls this behavior.
3030
*/
3131
class ScrollChildSwipeRefreshLayout @JvmOverloads constructor(
32-
context: Context,
33-
attrs: AttributeSet? = null
32+
context: Context,
33+
attrs: AttributeSet? = null
3434
) : SwipeRefreshLayout(context, attrs) {
3535

3636
var scrollUpChild: View? = null
3737

3838
override fun canChildScrollUp() =
39-
scrollUpChild?.canScrollVertically(-1) ?: super.canChildScrollUp()
39+
scrollUpChild?.canScrollVertically(-1) ?: super.canChildScrollUp()
4040
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import com.example.android.architecture.blueprints.todoapp.tasks.TasksViewModel
2828
*/
2929
@Suppress("UNCHECKED_CAST")
3030
class ViewModelFactory constructor(
31-
private val tasksRepository: TasksRepository
31+
private val tasksRepository: TasksRepository
3232
) : ViewModelProvider.NewInstanceFactory() {
3333

3434
override fun <T : ViewModel> create(modelClass: Class<T>) =

app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskViewModel.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AddEditTaskViewModel(
4141
val description = MutableLiveData<String>()
4242

4343
private val _dataLoading = MutableLiveData<Boolean>()
44-
val dataLoading: LiveData<Boolean> =_dataLoading
44+
val dataLoading: LiveData<Boolean> = _dataLoading
4545

4646
private val _snackbarText = MutableLiveData<Event<Int>>()
4747
val snackbarMessage: LiveData<Event<Int>> = _snackbarText
@@ -105,11 +105,11 @@ class AddEditTaskViewModel(
105105
val currentDescription = description.value
106106

107107
if (currentTitle == null || currentDescription == null) {
108-
_snackbarText.value = Event(R.string.empty_task_message)
108+
_snackbarText.value = Event(R.string.empty_task_message)
109109
return
110110
}
111111
if (Task(currentTitle, currentDescription).isEmpty) {
112-
_snackbarText.value = Event(R.string.empty_task_message)
112+
_snackbarText.value = Event(R.string.empty_task_message)
113113
return
114114
}
115115

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import java.util.UUID
3131
*/
3232
@Entity(tableName = "tasks")
3333
data class Task @JvmOverloads constructor(
34-
@ColumnInfo(name = "title") var title: String = "",
35-
@ColumnInfo(name = "description") var description: String = "",
36-
@ColumnInfo(name = "completed") var isCompleted: Boolean = false,
37-
@PrimaryKey @ColumnInfo(name = "entryid") var id: String = UUID.randomUUID().toString()
34+
@ColumnInfo(name = "title") var title: String = "",
35+
@ColumnInfo(name = "description") var description: String = "",
36+
@ColumnInfo(name = "completed") var isCompleted: Boolean = false,
37+
@PrimaryKey @ColumnInfo(name = "entryid") var id: String = UUID.randomUUID().toString()
3838
) {
3939

4040
val titleForList: String

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,34 @@ class DefaultTasksRepository(
4545

4646
override suspend fun getTasks(forceUpdate: Boolean): Result<List<Task>> {
4747

48-
wrapEspressoIdlingResource {
49-
50-
return withContext(ioDispatcher) {
51-
// Respond immediately with cache if available and not dirty
52-
if (!forceUpdate) {
53-
cachedTasks?.let { cachedTasks ->
54-
return@withContext Success(cachedTasks.values.sortedBy { it.id })
55-
}
56-
}
57-
58-
val newTasks = fetchTasksFromRemoteOrLocal(forceUpdate)
59-
60-
// Refresh the cache with the new tasks
61-
(newTasks as? Success)?.let { refreshCache(it.data) }
62-
63-
cachedTasks?.values?.let { tasks ->
64-
return@withContext Result.Success(tasks.sortedBy { it.id })
65-
}
66-
67-
(newTasks as? Success)?.let {
68-
if (it.data.isEmpty()) {
69-
return@withContext Result.Success(it.data)
70-
}
71-
}
72-
73-
return@withContext Result.Error(Exception("Illegal state"))
74-
}
75-
}
48+
wrapEspressoIdlingResource {
49+
50+
return withContext(ioDispatcher) {
51+
// Respond immediately with cache if available and not dirty
52+
if (!forceUpdate) {
53+
cachedTasks?.let { cachedTasks ->
54+
return@withContext Success(cachedTasks.values.sortedBy { it.id })
55+
}
56+
}
57+
58+
val newTasks = fetchTasksFromRemoteOrLocal(forceUpdate)
59+
60+
// Refresh the cache with the new tasks
61+
(newTasks as? Success)?.let { refreshCache(it.data) }
62+
63+
cachedTasks?.values?.let { tasks ->
64+
return@withContext Result.Success(tasks.sortedBy { it.id })
65+
}
66+
67+
(newTasks as? Success)?.let {
68+
if (it.data.isEmpty()) {
69+
return@withContext Result.Success(it.data)
70+
}
71+
}
72+
73+
return@withContext Result.Error(Exception("Illegal state"))
74+
}
75+
}
7676
}
7777

7878
private suspend fun fetchTasksFromRemoteOrLocal(forceUpdate: Boolean): Result<List<Task>> {
@@ -191,7 +191,7 @@ class DefaultTasksRepository(
191191
}
192192
}
193193

194-
override suspend fun activateTask(taskId: String) {
194+
override suspend fun activateTask(taskId: String) {
195195
withContext(ioDispatcher) {
196196
getTaskWithId(taskId)?.let {
197197
activateTask(it)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package com.example.android.architecture.blueprints.todoapp.data.source
1717

1818
import com.example.android.architecture.blueprints.todoapp.data.Result
1919
import com.example.android.architecture.blueprints.todoapp.data.Task
20+
2021
/**
2122
* Main entry point for accessing tasks data.
2223
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ import kotlinx.coroutines.withContext
2828
* Concrete implementation of a data source as a db.
2929
*/
3030
class TasksLocalDataSource internal constructor(
31-
private val tasksDao: TasksDao,
31+
private val tasksDao: TasksDao,
3232
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
3333
) : TasksDataSource {
3434

3535
override suspend fun getTasks(): Result<List<Task>> = withContext(ioDispatcher) {
3636
return@withContext try {
3737
Success(tasksDao.getTasks())
38-
} catch(e: Exception) {
38+
} catch (e: Exception) {
3939
Error(e)
4040
}
4141
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ object TasksRemoteDataSource : TasksDataSource {
6767
val newTask = Task(title, description)
6868
TASKS_SERVICE_DATA.put(newTask.id, newTask)
6969
}
70+
7071
override suspend fun saveTask(task: Task) {
7172
TASKS_SERVICE_DATA.put(task.id, task)
7273
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class StatisticsFragment : Fragment() {
3737
private val statisticsViewModel by viewModels<StatisticsViewModel> { getVmFactory() }
3838

3939
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
40-
savedInstanceState: Bundle?): View? {
40+
savedInstanceState: Bundle?): View? {
4141
viewDataBinding = DataBindingUtil.inflate(inflater, R.layout.statistics_frag, container,
42-
false)
42+
false)
4343
return viewDataBinding.root
4444
}
4545

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal fun getActiveAndCompletedStats(tasks: List<Task>?): StatsResult {
2929
val totalTasks = tasks.size
3030
val numberOfActiveTasks = tasks.count { it.isActive }
3131
StatsResult(
32-
activeTasksPercent = 100f * numberOfActiveTasks / tasks.size,
32+
activeTasksPercent = 100f * numberOfActiveTasks / tasks.size,
3333
completedTasksPercent = 100f * (totalTasks - numberOfActiveTasks) / tasks.size
3434
)
3535
}

app/src/main/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailFragment.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ class TaskDetailFragment : Fragment() {
7474
}
7575

7676
override fun onCreateView(
77-
inflater: LayoutInflater,
78-
container: ViewGroup?,
79-
savedInstanceState: Bundle?
77+
inflater: LayoutInflater,
78+
container: ViewGroup?,
79+
savedInstanceState: Bundle?
8080
): View? {
8181
val view = inflater.inflate(R.layout.taskdetail_frag, container, false)
8282
viewDataBinding = TaskdetailFragBinding.bind(view).apply {

app/src/main/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class TaskDetailViewModel(
7575
_editTaskCommand.value = Event(Unit)
7676
}
7777

78-
fun setCompleted(completed: Boolean) = viewModelScope.launch {
78+
fun setCompleted(completed: Boolean) = viewModelScope.launch {
7979
val task = _task.value ?: return@launch
8080
if (completed) {
8181
tasksRepository.completeTask(task)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class TasksFragment : Fragment() {
5353
private lateinit var listAdapter: TasksAdapter
5454

5555
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
56-
savedInstanceState: Bundle?): View? {
56+
savedInstanceState: Bundle?): View? {
5757
viewDataBinding = TasksFragBinding.inflate(inflater, container, false).apply {
5858
viewmodel = viewModel
5959
}
@@ -99,10 +99,10 @@ class TasksFragment : Fragment() {
9999
}
100100

101101
private fun setupNavigation() {
102-
viewModel.openTaskEvent?.observe(this, EventObserver {
102+
viewModel.openTaskEvent.observe(this, EventObserver {
103103
openTaskDetails(it)
104104
})
105-
viewModel.newTaskEvent?.observe(this, EventObserver {
105+
viewModel.newTaskEvent.observe(this, EventObserver {
106106
navigateToAddNewTask()
107107
})
108108
}

app/src/main/java/com/example/android/architecture/blueprints/todoapp/util/EspressoIdlingResource.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ object EspressoIdlingResource {
2424

2525
private const val RESOURCE = "GLOBAL"
2626

27-
@JvmField val countingIdlingResource = SimpleCountingIdlingResource(RESOURCE)
27+
@JvmField
28+
val countingIdlingResource = SimpleCountingIdlingResource(RESOURCE)
2829

2930
fun increment() {
3031
countingIdlingResource.increment()
@@ -37,7 +38,7 @@ object EspressoIdlingResource {
3738
}
3839
}
3940

40-
inline fun <T> wrapEspressoIdlingResource(function: () -> T) : T {
41+
inline fun <T> wrapEspressoIdlingResource(function: () -> T): T {
4142
// Espresso does not work well with coroutines yet. See
4243
// https://github.com/Kotlin/kotlinx.coroutines/issues/982
4344
EspressoIdlingResource.increment() // Set app as busy.

app/src/main/java/com/example/android/architecture/blueprints/todoapp/util/SimpleCountingIdlingResource.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class SimpleCountingIdlingResource(private val resourceName: String) : IdlingRes
3434
private val counter = AtomicInteger(0)
3535

3636
// written from main thread, read from any thread.
37-
@Volatile private var resourceCallback: IdlingResource.ResourceCallback? = null
37+
@Volatile
38+
private var resourceCallback: IdlingResource.ResourceCallback? = null
3839

3940
override fun getName() = resourceName
4041

app/src/main/java/com/example/android/architecture/blueprints/todoapp/util/ViewExt.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import com.google.android.material.snackbar.Snackbar
3535
*/
3636
fun View.showSnackbar(snackbarText: String, timeLength: Int) {
3737
Snackbar.make(this, snackbarText, timeLength).run {
38-
addCallback(object: Snackbar.Callback() {
38+
addCallback(object : Snackbar.Callback() {
3939
override fun onShown(sb: Snackbar?) {
4040
EspressoIdlingResource.increment()
4141
}

0 commit comments

Comments
 (0)