Skip to content

Commit 6f21231

Browse files
Merges naming cleanup and lint fixes
2 parents e56a062 + 1b93c50 commit 6f21231

File tree

33 files changed

+178
-179
lines changed

33 files changed

+178
-179
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Android Architecture Blueprints v2
22
<p align="center">
3-
<img src="https://github.com/googlesamples/android-architecture/wiki/images/aab-logov2.png" alt="Android Architecture Blueprints"/>
3+
<img src="https://github.com/googlesamples/android-architecture/wiki/images/aab-logov2.png" alt="Illustration by Virginia Poltrack"/>
44
</p>
55

66
Android Architecture Blueprints is a project to showcase different architectural approaches to developing Android apps. In its different branches you'll find the same app (a TODO app) implemented with small differences.

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: 27 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,11 @@ 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))
131+
.perform(typeText("TITLE1"), closeSoftKeyboard())
132+
onView(withId(R.id.add_task_description_edit_text)).perform(typeText("DESCRIPTION"))
133+
onView(withId(R.id.save_task_fab)).perform(click())
133134

134135
// Open it in details view
135136
onView(withText("TITLE1")).perform(click())
@@ -177,7 +178,7 @@ class TasksActivityTest {
177178
onView(withText(taskTitle)).perform(click())
178179

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

182183
// Click on the navigation up button to go back to the list
183184
onView(
@@ -187,7 +188,7 @@ class TasksActivityTest {
187188
).perform(click())
188189

189190
// Check that the task is marked as completed
190-
onView(allOf(withId(R.id.complete), hasSibling(withText(taskTitle))))
191+
onView(allOf(withId(R.id.complete_checkbox), hasSibling(withText(taskTitle))))
191192
.check(matches(isChecked()))
192193
}
193194

@@ -204,7 +205,7 @@ class TasksActivityTest {
204205
// Click on the task on the list
205206
onView(withText(taskTitle)).perform(click())
206207
// Click on the checkbox in task details screen
207-
onView(withId(R.id.task_detail_complete)).perform(click())
208+
onView(withId(R.id.task_detail_complete_checkbox)).perform(click())
208209

209210
// Click on the navigation up button to go back to the list
210211
onView(
@@ -214,7 +215,7 @@ class TasksActivityTest {
214215
).perform(click())
215216

216217
// Check that the task is marked as active
217-
onView(allOf(withId(R.id.complete), hasSibling(withText(taskTitle))))
218+
onView(allOf(withId(R.id.complete_checkbox), hasSibling(withText(taskTitle))))
218219
.check(matches(not(isChecked())))
219220
}
220221

@@ -231,9 +232,9 @@ class TasksActivityTest {
231232
// Click on the task on the list
232233
onView(withText(taskTitle)).perform(click())
233234
// Click on the checkbox in task details screen
234-
onView(withId(R.id.task_detail_complete)).perform(click())
235+
onView(withId(R.id.task_detail_complete_checkbox)).perform(click())
235236
// Click again to restore it to original state
236-
onView(withId(R.id.task_detail_complete)).perform(click())
237+
onView(withId(R.id.task_detail_complete_checkbox)).perform(click())
237238

238239
// Click on the navigation up button to go back to the list
239240
onView(
@@ -243,7 +244,7 @@ class TasksActivityTest {
243244
).perform(click())
244245

245246
// Check that the task is marked as active
246-
onView(allOf(withId(R.id.complete), hasSibling(withText(taskTitle))))
247+
onView(allOf(withId(R.id.complete_checkbox), hasSibling(withText(taskTitle))))
247248
.check(matches(not(isChecked())))
248249
}
249250

@@ -260,9 +261,9 @@ class TasksActivityTest {
260261
// Click on the task on the list
261262
onView(withText(taskTitle)).perform(click())
262263
// Click on the checkbox in task details screen
263-
onView(withId(R.id.task_detail_complete)).perform(click())
264+
onView(withId(R.id.task_detail_complete_checkbox)).perform(click())
264265
// Click again to restore it to original state
265-
onView(withId(R.id.task_detail_complete)).perform(click())
266+
onView(withId(R.id.task_detail_complete_checkbox)).perform(click())
266267

267268
// Click on the navigation up button to go back to the list
268269
onView(
@@ -272,7 +273,7 @@ class TasksActivityTest {
272273
).perform(click())
273274

274275
// Check that the task is marked as active
275-
onView(allOf(withId(R.id.complete), hasSibling(withText(taskTitle))))
276+
onView(allOf(withId(R.id.complete_checkbox), hasSibling(withText(taskTitle))))
276277
.check(matches(isChecked()))
277278
}
278279

@@ -283,10 +284,11 @@ class TasksActivityTest {
283284
dataBindingIdlingResource.monitorActivity(activityScenario)
284285

285286
// 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())
287+
onView(withId(R.id.add_task_fab)).perform(click())
288+
onView(withId(R.id.add_task_title_edit_text))
289+
.perform(typeText("title"), closeSoftKeyboard())
290+
onView(withId(R.id.add_task_description_edit_text)).perform(typeText("description"))
291+
onView(withId(R.id.save_task_fab)).perform(click())
290292

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import androidx.lifecycle.Observer
2222
*/
2323
open class Event<out T>(private val content: T) {
2424

25+
@Suppress("MemberVisibilityCanBePrivate")
2526
var hasBeenHandled = false
2627
private set // Allow external read but not write
2728

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 {

0 commit comments

Comments
 (0)