Skip to content

Commit 0aba5dc

Browse files
ceruleanotterJoseAlcerreca
authored andcommitted
Cleanup variable and function names
1 parent e56a062 commit 0aba5dc

File tree

11 files changed

+43
-41
lines changed

11 files changed

+43
-41
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import com.example.android.architecture.blueprints.todoapp.EventObserver
2727
import com.example.android.architecture.blueprints.todoapp.R
2828
import com.example.android.architecture.blueprints.todoapp.databinding.AddtaskFragBinding
2929
import com.example.android.architecture.blueprints.todoapp.tasks.ADD_EDIT_RESULT_OK
30-
import com.example.android.architecture.blueprints.todoapp.util.getVmFactory
30+
import com.example.android.architecture.blueprints.todoapp.util.getViewModelFactory
3131
import com.example.android.architecture.blueprints.todoapp.util.setupRefreshLayout
3232
import com.example.android.architecture.blueprints.todoapp.util.setupSnackbar
3333
import com.google.android.material.snackbar.Snackbar
@@ -41,7 +41,9 @@ class AddEditTaskFragment : Fragment() {
4141

4242
private val args: AddEditTaskFragmentArgs by navArgs()
4343

44-
private val viewModel by viewModels<AddEditTaskViewModel> { getVmFactory() }
44+
private val viewModel by viewModels<AddEditTaskViewModel> {
45+
getViewModelFactory()
46+
}
4547

4648
override fun onCreateView(
4749
inflater: LayoutInflater, container: ViewGroup?,
@@ -65,7 +67,7 @@ class AddEditTaskFragment : Fragment() {
6567
}
6668

6769
private fun setupSnackbar() {
68-
view?.setupSnackbar(this, viewModel.snackbarMessage, Snackbar.LENGTH_SHORT)
70+
view?.setupSnackbar(this, viewModel.snackbarText, Snackbar.LENGTH_SHORT)
6971
}
7072

7173
private fun setupNavigation() {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ class AddEditTaskViewModel(
4444
val dataLoading: LiveData<Boolean> = _dataLoading
4545

4646
private val _snackbarText = MutableLiveData<Event<Int>>()
47-
val snackbarMessage: LiveData<Event<Int>> = _snackbarText
47+
val snackbarText: LiveData<Event<Int>> = _snackbarText
4848

49-
private val _taskUpdated = MutableLiveData<Event<Unit>>()
50-
val taskUpdatedEvent: LiveData<Event<Unit>> = _taskUpdated
49+
private val _taskUpdatedEvent = MutableLiveData<Event<Unit>>()
50+
val taskUpdatedEvent: LiveData<Event<Unit>> = _taskUpdatedEvent
5151

5252
private var taskId: String? = null
5353

@@ -124,7 +124,7 @@ class AddEditTaskViewModel(
124124

125125
private fun createTask(newTask: Task) = viewModelScope.launch {
126126
tasksRepository.saveTask(newTask)
127-
_taskUpdated.value = Event(Unit)
127+
_taskUpdatedEvent.value = Event(Unit)
128128
}
129129

130130
private fun updateTask(task: Task) {
@@ -133,7 +133,7 @@ class AddEditTaskViewModel(
133133
}
134134
viewModelScope.launch {
135135
tasksRepository.saveTask(task)
136-
_taskUpdated.value = Event(Unit)
136+
_taskUpdatedEvent.value = Event(Unit)
137137
}
138138
}
139139
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import androidx.fragment.app.Fragment
2424
import androidx.fragment.app.viewModels
2525
import com.example.android.architecture.blueprints.todoapp.R
2626
import com.example.android.architecture.blueprints.todoapp.databinding.StatisticsFragBinding
27-
import com.example.android.architecture.blueprints.todoapp.util.getVmFactory
27+
import com.example.android.architecture.blueprints.todoapp.util.getViewModelFactory
2828
import com.example.android.architecture.blueprints.todoapp.util.setupRefreshLayout
2929

3030
/**
@@ -34,7 +34,7 @@ class StatisticsFragment : Fragment() {
3434

3535
private lateinit var viewDataBinding: StatisticsFragBinding
3636

37-
private val statisticsViewModel by viewModels<StatisticsViewModel> { getVmFactory() }
37+
private val viewModel by viewModels<StatisticsViewModel> { getViewModelFactory() }
3838

3939
override fun onCreateView(
4040
inflater: LayoutInflater, container: ViewGroup?,
@@ -49,9 +49,9 @@ class StatisticsFragment : Fragment() {
4949

5050
override fun onActivityCreated(savedInstanceState: Bundle?) {
5151
super.onActivityCreated(savedInstanceState)
52-
viewDataBinding.viewmodel = statisticsViewModel
52+
viewDataBinding.viewmodel = viewModel
5353
viewDataBinding.lifecycleOwner = this.viewLifecycleOwner
5454
this.setupRefreshLayout(viewDataBinding.refreshLayout)
55-
statisticsViewModel.start()
55+
viewModel.start()
5656
}
5757
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import com.example.android.architecture.blueprints.todoapp.EventObserver
3030
import com.example.android.architecture.blueprints.todoapp.R
3131
import com.example.android.architecture.blueprints.todoapp.databinding.TaskdetailFragBinding
3232
import com.example.android.architecture.blueprints.todoapp.tasks.DELETE_RESULT_OK
33-
import com.example.android.architecture.blueprints.todoapp.util.getVmFactory
33+
import com.example.android.architecture.blueprints.todoapp.util.getViewModelFactory
3434
import com.example.android.architecture.blueprints.todoapp.util.setupRefreshLayout
3535
import com.example.android.architecture.blueprints.todoapp.util.setupSnackbar
3636
import com.google.android.material.snackbar.Snackbar
@@ -43,23 +43,23 @@ class TaskDetailFragment : Fragment() {
4343

4444
private val args: TaskDetailFragmentArgs by navArgs()
4545

46-
private val viewModel by viewModels<TaskDetailViewModel> { getVmFactory() }
46+
private val viewModel by viewModels<TaskDetailViewModel> { getViewModelFactory() }
4747

4848
override fun onActivityCreated(savedInstanceState: Bundle?) {
4949
super.onActivityCreated(savedInstanceState)
5050
setupFab()
51-
view?.setupSnackbar(this, viewModel.snackbarMessage, Snackbar.LENGTH_SHORT)
51+
view?.setupSnackbar(this, viewModel.snackbarText, Snackbar.LENGTH_SHORT)
5252
setupNavigation()
5353
this.setupRefreshLayout(viewDataBinding.refreshLayout)
5454
}
5555

5656
private fun setupNavigation() {
57-
viewModel.deleteTaskCommand.observe(this, EventObserver {
57+
viewModel.deleteTaskEvent.observe(this, EventObserver {
5858
val action = TaskDetailFragmentDirections
5959
.actionTaskDetailFragmentToTasksFragment(DELETE_RESULT_OK)
6060
findNavController().navigate(action)
6161
})
62-
viewModel.editTaskCommand.observe(this, EventObserver {
62+
viewModel.editTaskEvent.observe(this, EventObserver {
6363
val action = TaskDetailFragmentDirections
6464
.actionTaskDetailFragmentToAddEditTaskFragment(
6565
args.taskId,

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ class TaskDetailViewModel(
4646
private val _dataLoading = MutableLiveData<Boolean>()
4747
val dataLoading: LiveData<Boolean> = _dataLoading
4848

49-
private val _editTaskCommand = MutableLiveData<Event<Unit>>()
50-
val editTaskCommand: LiveData<Event<Unit>> = _editTaskCommand
49+
private val _editTaskEvent = MutableLiveData<Event<Unit>>()
50+
val editTaskEvent: LiveData<Event<Unit>> = _editTaskEvent
5151

52-
private val _deleteTaskCommand = MutableLiveData<Event<Unit>>()
53-
val deleteTaskCommand: LiveData<Event<Unit>> = _deleteTaskCommand
52+
private val _deleteTaskEvent = MutableLiveData<Event<Unit>>()
53+
val deleteTaskEvent: LiveData<Event<Unit>> = _deleteTaskEvent
5454

5555
private val _snackbarText = MutableLiveData<Event<Int>>()
56-
val snackbarMessage: LiveData<Event<Int>> = _snackbarText
56+
val snackbarText: LiveData<Event<Int>> = _snackbarText
5757

5858
private val taskId: String?
5959
get() = _task.value?.id
@@ -67,12 +67,12 @@ class TaskDetailViewModel(
6767
fun deleteTask() = viewModelScope.launch {
6868
taskId?.let {
6969
tasksRepository.deleteTask(it)
70-
_deleteTaskCommand.value = Event(Unit)
70+
_deleteTaskEvent.value = Event(Unit)
7171
}
7272
}
7373

7474
fun editTask() {
75-
_editTaskCommand.value = Event(Unit)
75+
_editTaskEvent.value = Event(Unit)
7676
}
7777

7878
fun setCompleted(completed: Boolean) = viewModelScope.launch {

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
@@ -32,7 +32,7 @@ import com.example.android.architecture.blueprints.todoapp.EventObserver
3232
import com.example.android.architecture.blueprints.todoapp.R
3333
import com.example.android.architecture.blueprints.todoapp.data.Task
3434
import com.example.android.architecture.blueprints.todoapp.databinding.TasksFragBinding
35-
import com.example.android.architecture.blueprints.todoapp.util.getVmFactory
35+
import com.example.android.architecture.blueprints.todoapp.util.getViewModelFactory
3636
import com.example.android.architecture.blueprints.todoapp.util.setupRefreshLayout
3737
import com.example.android.architecture.blueprints.todoapp.util.setupSnackbar
3838
import com.google.android.material.floatingactionbutton.FloatingActionButton
@@ -44,7 +44,7 @@ import timber.log.Timber
4444
*/
4545
class TasksFragment : Fragment() {
4646

47-
private val viewModel by viewModels<TasksViewModel> { getVmFactory() }
47+
private val viewModel by viewModels<TasksViewModel> { getViewModelFactory() }
4848

4949
private val args: TasksFragmentArgs by navArgs()
5050

@@ -110,7 +110,7 @@ class TasksFragment : Fragment() {
110110
}
111111

112112
private fun setupSnackbar() {
113-
view?.setupSnackbar(this, viewModel.snackbarMessage, Snackbar.LENGTH_SHORT)
113+
view?.setupSnackbar(this, viewModel.snackbarText, Snackbar.LENGTH_SHORT)
114114
arguments?.let {
115115
viewModel.showEditResultMessage(args.userMessage)
116116
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class TasksViewModel(
5858
val tasksAddViewVisible: LiveData<Boolean> = _tasksAddViewVisible
5959

6060
private val _snackbarText = MutableLiveData<Event<Int>>()
61-
val snackbarMessage: LiveData<Event<Int>> = _snackbarText
61+
val snackbarText: LiveData<Event<Int>> = _snackbarText
6262

6363
private var _currentFiltering = TasksFilterType.ALL_TASKS
6464

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import androidx.fragment.app.Fragment
2323
import com.example.android.architecture.blueprints.todoapp.TodoApplication
2424
import com.example.android.architecture.blueprints.todoapp.ViewModelFactory
2525

26-
fun Fragment.getVmFactory(): ViewModelFactory {
26+
fun Fragment.getViewModelFactory(): ViewModelFactory {
2727
val repository = (requireContext().applicationContext as TodoApplication).taskRepository
2828
return ViewModelFactory(repository)
2929
}

app/src/test/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskViewModelTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,6 @@ class AddEditTaskViewModelTest {
149149
addEditTaskViewModel.saveTask()
150150

151151
// Then the snackbar shows an error
152-
assertSnackbarMessage(addEditTaskViewModel.snackbarMessage, string.empty_task_message)
152+
assertSnackbarMessage(addEditTaskViewModel.snackbarText, string.empty_task_message)
153153
}
154154
}

app/src/test/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailViewModelTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class TaskDetailViewModelTest {
8181

8282
// Then the task is completed and the snackbar shows the correct message
8383
assertThat(tasksRepository.tasksServiceData[task.id]?.isCompleted).isTrue()
84-
assertSnackbarMessage(taskDetailViewModel.snackbarMessage, R.string.task_marked_complete)
84+
assertSnackbarMessage(taskDetailViewModel.snackbarText, R.string.task_marked_complete)
8585
}
8686

8787
@Test
@@ -98,7 +98,7 @@ class TaskDetailViewModelTest {
9898

9999
// Then the task is not completed and the snackbar shows the correct message
100100
assertThat(tasksRepository.tasksServiceData[task.id]?.isCompleted).isFalse()
101-
assertSnackbarMessage(taskDetailViewModel.snackbarMessage, R.string.task_marked_active)
101+
assertSnackbarMessage(taskDetailViewModel.snackbarText, R.string.task_marked_active)
102102

103103
}
104104

@@ -117,7 +117,7 @@ class TaskDetailViewModelTest {
117117
@Test
118118
fun updateSnackbar_nullValue() {
119119
// Before setting the Snackbar text, get its current value
120-
val snackbarText = taskDetailViewModel.snackbarMessage.value
120+
val snackbarText = taskDetailViewModel.snackbarText.value
121121

122122
// Check that the value is null
123123
assertThat(snackbarText).isNull()
@@ -129,7 +129,7 @@ class TaskDetailViewModelTest {
129129
taskDetailViewModel.editTask()
130130

131131
// Then the event is triggered
132-
val value = getValue(taskDetailViewModel.editTaskCommand)
132+
val value = getValue(taskDetailViewModel.editTaskEvent)
133133
assertThat(value.getContentIfNotHandled()).isNotNull()
134134
}
135135

0 commit comments

Comments
 (0)