Skip to content

Commit ab80ca8

Browse files
Merge pull request #24 from ceruleanotter/naming-cleanup
Naming cleanup
2 parents e8eb141 + b529dd5 commit ab80ca8

File tree

27 files changed

+158
-149
lines changed

27 files changed

+158
-149
lines changed

app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/tasks/AppNavigationTest.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,21 @@ class AppNavigationTest {
102102

103103
// Start statistics screen.
104104
onView(withId(R.id.nav_view))
105-
.perform(navigateTo(R.id.statisticsFragment))
105+
.perform(navigateTo(R.id.statistics_fragment_dest))
106106

107107
// Check that statistics screen was opened.
108-
onView(withId(R.id.statistics)).check(matches(isDisplayed()))
108+
onView(withId(R.id.statistics_layout)).check(matches(isDisplayed()))
109109

110110
onView(withId(R.id.drawer_layout))
111111
.check(matches(isClosed(Gravity.START))) // Left Drawer should be closed.
112112
.perform(open()) // Open Drawer
113113

114114
// Start tasks screen.
115115
onView(withId(R.id.nav_view))
116-
.perform(navigateTo(R.id.tasksFragment))
116+
.perform(navigateTo(R.id.tasks_fragment_dest))
117117

118118
// Check that tasks screen was opened.
119-
onView(withId(R.id.tasksContainer)).check(matches(isDisplayed()))
119+
onView(withId(R.id.tasks_container_layout)).check(matches(isDisplayed()))
120120
}
121121

122122
@Test
@@ -150,7 +150,7 @@ class AppNavigationTest {
150150

151151
// When the user navigates to the stats screen
152152
activityScenario.onActivity {
153-
it.findNavController(R.id.nav_host_fragment).navigate(R.id.statisticsFragment)
153+
it.findNavController(R.id.nav_host_fragment).navigate(R.id.statistics_fragment_dest)
154154
}
155155

156156
// Then check that left drawer is closed at startup
@@ -182,7 +182,7 @@ class AppNavigationTest {
182182
// Click on the task on the list
183183
onView(withText("UI <- button")).perform(click())
184184
// Click on the edit task button
185-
onView(withId(R.id.fab_edit_task)).perform(click())
185+
onView(withId(R.id.edit_task_fab)).perform(click())
186186

187187
// Confirm that if we click "<-" once, we end up back at the task details page
188188
onView(
@@ -191,7 +191,7 @@ class AppNavigationTest {
191191
.getToolbarNavigationContentDescription()
192192
)
193193
).perform(click())
194-
onView(withId(R.id.task_detail_title)).check(matches(isDisplayed()))
194+
onView(withId(R.id.task_detail_title_text)).check(matches(isDisplayed()))
195195

196196
// Confirm that if we click "<-" a second time, we end up back at the home screen
197197
onView(
@@ -200,7 +200,7 @@ class AppNavigationTest {
200200
.getToolbarNavigationContentDescription()
201201
)
202202
).perform(click())
203-
onView(withId(R.id.tasksContainer)).check(matches(isDisplayed()))
203+
onView(withId(R.id.tasks_container_layout)).check(matches(isDisplayed()))
204204
}
205205

206206
@Test
@@ -215,14 +215,14 @@ class AppNavigationTest {
215215
// Click on the task on the list
216216
onView(withText("Back button")).perform(click())
217217
// Click on the edit task button
218-
onView(withId(R.id.fab_edit_task)).perform(click())
218+
onView(withId(R.id.edit_task_fab)).perform(click())
219219

220220
// Confirm that if we click back once, we end up back at the task details page
221221
pressBack()
222-
onView(withId(R.id.task_detail_title)).check(matches(isDisplayed()))
222+
onView(withId(R.id.task_detail_title_text)).check(matches(isDisplayed()))
223223

224224
// Confirm that if we click back a second time, we end up back at the home screen
225225
pressBack()
226-
onView(withId(R.id.tasksContainer)).check(matches(isDisplayed()))
226+
onView(withId(R.id.tasks_container_layout)).check(matches(isDisplayed()))
227227
}
228228
}

app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksActivityTest.kt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ class TasksActivityTest {
102102

103103
// Click on the task on the list and verify that all the data is correct
104104
onView(withText("TITLE1")).perform(click())
105-
onView(withId(R.id.task_detail_title)).check(matches(withText("TITLE1")))
106-
onView(withId(R.id.task_detail_description)).check(matches(withText("DESCRIPTION")))
107-
onView(withId(R.id.task_detail_complete)).check(matches(not(isChecked())))
105+
onView(withId(R.id.task_detail_title_text)).check(matches(withText("TITLE1")))
106+
onView(withId(R.id.task_detail_description_text)).check(matches(withText("DESCRIPTION")))
107+
onView(withId(R.id.task_detail_complete_checkbox)).check(matches(not(isChecked())))
108108

109109
// Click on the edit button, edit, and save
110-
onView(withId(R.id.fab_edit_task)).perform(click())
111-
onView(withId(R.id.add_task_title)).perform(replaceText("NEW TITLE"))
112-
onView(withId(R.id.add_task_description)).perform(replaceText("NEW DESCRIPTION"))
113-
onView(withId(R.id.fab_save_task)).perform(click())
110+
onView(withId(R.id.edit_task_fab)).perform(click())
111+
onView(withId(R.id.add_task_title_edit_text)).perform(replaceText("NEW TITLE"))
112+
onView(withId(R.id.add_task_description_edit_text)).perform(replaceText("NEW DESCRIPTION"))
113+
onView(withId(R.id.save_task_fab)).perform(click())
114114

115115
// Verify task is displayed on screen in the task list.
116116
onView(withText("NEW TITLE")).check(matches(isDisplayed()))
@@ -126,10 +126,10 @@ class TasksActivityTest {
126126
dataBindingIdlingResource.monitorActivity(activityScenario)
127127

128128
// Add active task
129-
onView(withId(R.id.fab_add_task)).perform(click())
130-
onView(withId(R.id.add_task_title)).perform(typeText("TITLE1"), closeSoftKeyboard())
131-
onView(withId(R.id.add_task_description)).perform(typeText("DESCRIPTION"))
132-
onView(withId(R.id.fab_save_task)).perform(click())
129+
onView(withId(R.id.add_task_fab)).perform(click())
130+
onView(withId(R.id.add_task_title_edit_text)).perform(typeText("TITLE1"), closeSoftKeyboard())
131+
onView(withId(R.id.add_task_description_edit_text)).perform(typeText("DESCRIPTION"))
132+
onView(withId(R.id.save_task_fab)).perform(click())
133133

134134
// Open it in details view
135135
onView(withText("TITLE1")).perform(click())
@@ -177,7 +177,7 @@ class TasksActivityTest {
177177
onView(withText(taskTitle)).perform(click())
178178

179179
// Click on the checkbox in task details screen
180-
onView(withId(R.id.task_detail_complete)).perform(click())
180+
onView(withId(R.id.task_detail_complete_checkbox)).perform(click())
181181

182182
// Click on the navigation up button to go back to the list
183183
onView(
@@ -187,7 +187,7 @@ class TasksActivityTest {
187187
).perform(click())
188188

189189
// Check that the task is marked as completed
190-
onView(allOf(withId(R.id.complete), hasSibling(withText(taskTitle))))
190+
onView(allOf(withId(R.id.complete_checkbox), hasSibling(withText(taskTitle))))
191191
.check(matches(isChecked()))
192192
}
193193

@@ -204,7 +204,7 @@ class TasksActivityTest {
204204
// Click on the task on the list
205205
onView(withText(taskTitle)).perform(click())
206206
// Click on the checkbox in task details screen
207-
onView(withId(R.id.task_detail_complete)).perform(click())
207+
onView(withId(R.id.task_detail_complete_checkbox)).perform(click())
208208

209209
// Click on the navigation up button to go back to the list
210210
onView(
@@ -214,7 +214,7 @@ class TasksActivityTest {
214214
).perform(click())
215215

216216
// Check that the task is marked as active
217-
onView(allOf(withId(R.id.complete), hasSibling(withText(taskTitle))))
217+
onView(allOf(withId(R.id.complete_checkbox), hasSibling(withText(taskTitle))))
218218
.check(matches(not(isChecked())))
219219
}
220220

@@ -231,9 +231,9 @@ class TasksActivityTest {
231231
// Click on the task on the list
232232
onView(withText(taskTitle)).perform(click())
233233
// Click on the checkbox in task details screen
234-
onView(withId(R.id.task_detail_complete)).perform(click())
234+
onView(withId(R.id.task_detail_complete_checkbox)).perform(click())
235235
// Click again to restore it to original state
236-
onView(withId(R.id.task_detail_complete)).perform(click())
236+
onView(withId(R.id.task_detail_complete_checkbox)).perform(click())
237237

238238
// Click on the navigation up button to go back to the list
239239
onView(
@@ -243,7 +243,7 @@ class TasksActivityTest {
243243
).perform(click())
244244

245245
// Check that the task is marked as active
246-
onView(allOf(withId(R.id.complete), hasSibling(withText(taskTitle))))
246+
onView(allOf(withId(R.id.complete_checkbox), hasSibling(withText(taskTitle))))
247247
.check(matches(not(isChecked())))
248248
}
249249

@@ -260,9 +260,9 @@ class TasksActivityTest {
260260
// Click on the task on the list
261261
onView(withText(taskTitle)).perform(click())
262262
// Click on the checkbox in task details screen
263-
onView(withId(R.id.task_detail_complete)).perform(click())
263+
onView(withId(R.id.task_detail_complete_checkbox)).perform(click())
264264
// Click again to restore it to original state
265-
onView(withId(R.id.task_detail_complete)).perform(click())
265+
onView(withId(R.id.task_detail_complete_checkbox)).perform(click())
266266

267267
// Click on the navigation up button to go back to the list
268268
onView(
@@ -272,7 +272,7 @@ class TasksActivityTest {
272272
).perform(click())
273273

274274
// Check that the task is marked as active
275-
onView(allOf(withId(R.id.complete), hasSibling(withText(taskTitle))))
275+
onView(allOf(withId(R.id.complete_checkbox), hasSibling(withText(taskTitle))))
276276
.check(matches(isChecked()))
277277
}
278278

@@ -283,10 +283,10 @@ class TasksActivityTest {
283283
dataBindingIdlingResource.monitorActivity(activityScenario)
284284

285285
// Click on the "+" button, add details, and save
286-
onView(withId(R.id.fab_add_task)).perform(click())
287-
onView(withId(R.id.add_task_title)).perform(typeText("title"), closeSoftKeyboard())
288-
onView(withId(R.id.add_task_description)).perform(typeText("description"))
289-
onView(withId(R.id.fab_save_task)).perform(click())
286+
onView(withId(R.id.add_task_fab)).perform(click())
287+
onView(withId(R.id.add_task_title_edit_text)).perform(typeText("title"), closeSoftKeyboard())
288+
onView(withId(R.id.add_task_description_edit_text)).perform(typeText("description"))
289+
onView(withId(R.id.save_task_fab)).perform(click())
290290

291291
// Then verify task is displayed on screen
292292
onView(withText("title")).check(matches(isDisplayed()))

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

Lines changed: 3 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,7 @@ 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> { getViewModelFactory() }
4545

4646
override fun onCreateView(
4747
inflater: LayoutInflater, container: ViewGroup?,
@@ -65,7 +65,7 @@ class AddEditTaskFragment : Fragment() {
6565
}
6666

6767
private fun setupSnackbar() {
68-
view?.setupSnackbar(this, viewModel.snackbarMessage, Snackbar.LENGTH_SHORT)
68+
view?.setupSnackbar(this, viewModel.snackbarText, Snackbar.LENGTH_SHORT)
6969
}
7070

7171
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: 6 additions & 6 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,
@@ -70,7 +70,7 @@ class TaskDetailFragment : Fragment() {
7070
}
7171

7272
private fun setupFab() {
73-
activity?.findViewById<View>(R.id.fab_edit_task)?.setOnClickListener {
73+
activity?.findViewById<View>(R.id.edit_task_fab)?.setOnClickListener {
7474
viewModel.editTask()
7575
}
7676
}

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/TasksActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class TasksActivity : AppCompatActivity() {
4444

4545
val navController: NavController = findNavController(R.id.nav_host_fragment)
4646
appBarConfiguration =
47-
AppBarConfiguration.Builder(R.id.tasksFragment, R.id.statisticsFragment)
47+
AppBarConfiguration.Builder(R.id.tasks_fragment_dest, R.id.statistics_fragment_dest)
4848
.setDrawerLayout(drawerLayout)
4949
.build()
5050
setupActionBarWithNavController(navController, appBarConfiguration)

0 commit comments

Comments
 (0)