Skip to content

Commit

Permalink
Formatting code + small corrections after finishing the tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
codinginflow authored and Florian Walther committed Nov 16, 2020
1 parent 4517c20 commit bc2b89c
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 19 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MVVMTodo">
<activity android:name="com.codinginflow.mvvmtodo.ui.MainActivity"
<activity
android:name="com.codinginflow.mvvmtodo.ui.MainActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.codinginflow.mvvmtodo.data

import android.content.Context
import android.util.Log
import androidx.datastore.createDataStore
import androidx.datastore.preferences.createDataStore
import androidx.datastore.preferences.edit
import androidx.datastore.preferences.emptyPreferences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.Flow
interface TaskDao {

fun getTasks(query: String, sortOrder: SortOrder, hideCompleted: Boolean): Flow<List<Task>> =
when(sortOrder) {
when (sortOrder) {
SortOrder.BY_DATE -> getTasksSortedByDateCreated(query, hideCompleted)
SortOrder.BY_NAME -> getTasksSortedByName(query, hideCompleted)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.codinginflow.mvvmtodo.ui

import android.app.Activity
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import androidx.recyclerview.widget.RecyclerView
import com.codinginflow.mvvmtodo.data.Task
import com.codinginflow.mvvmtodo.databinding.ItemTaskBinding

class TasksAdapter(private val listener: OnItemClickListener) : ListAdapter<Task, TasksAdapter.TasksViewHolder>(DiffCallback()) {
class TasksAdapter(private val listener: OnItemClickListener) :
ListAdapter<Task, TasksAdapter.TasksViewHolder>(DiffCallback()) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TasksViewHolder {
val binding = ItemTaskBinding.inflate(LayoutInflater.from(parent.context), parent, false)
Expand All @@ -21,7 +22,8 @@ class TasksAdapter(private val listener: OnItemClickListener) : ListAdapter<Task
holder.bind(currentItem)
}

inner class TasksViewHolder(private val binding: ItemTaskBinding) : RecyclerView.ViewHolder(binding.root) {
inner class TasksViewHolder(private val binding: ItemTaskBinding) :
RecyclerView.ViewHolder(binding.root) {

init {
binding.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ class TasksFragment : Fragment(R.layout.fragment_tasks), TasksAdapter.OnItemClic
setHasFixedSize(true)
}

ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(0,
ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) {
ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(
0,
ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT
) {
override fun onMove(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
Expand Down Expand Up @@ -87,18 +89,27 @@ class TasksFragment : Fragment(R.layout.fragment_tasks), TasksAdapter.OnItemClic
}.show()
}
is TasksViewModel.TasksEvent.NavigateToAddTaskScreen -> {
val action = TasksFragmentDirections.actionTasksFragmentToAddEditTaskFragment(null, "New Task")
val action =
TasksFragmentDirections.actionTasksFragmentToAddEditTaskFragment(
null,
"New Task"
)
findNavController().navigate(action)
}
is TasksViewModel.TasksEvent.NavigateToEditTaskScreen -> {
val action = TasksFragmentDirections.actionTasksFragmentToAddEditTaskFragment(event.task, "Edit Task")
val action =
TasksFragmentDirections.actionTasksFragmentToAddEditTaskFragment(
event.task,
"Edit Task"
)
findNavController().navigate(action)
}
is TasksViewModel.TasksEvent.ShowTaskSavedConfirmationMessage -> {
Snackbar.make(requireView(), event.msg, Snackbar.LENGTH_SHORT).show()
}
TasksViewModel.TasksEvent.NavigateToDeleteAllCompletedScreen -> {
val action = TasksFragmentDirections.actionGlobalDeleteAllCompletedDialogFragment()
is TasksViewModel.TasksEvent.NavigateToDeleteAllCompletedScreen -> {
val action =
TasksFragmentDirections.actionGlobalDeleteAllCompletedDialogFragment()
findNavController().navigate(action)
}
}.exhaustive
Expand Down Expand Up @@ -139,7 +150,7 @@ class TasksFragment : Fragment(R.layout.fragment_tasks), TasksAdapter.OnItemClic
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when(item.itemId) {
return when (item.itemId) {
R.id.action_sort_by_name -> {
viewModel.onSortOrderSelected(SortOrder.BY_NAME)
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.codinginflow.mvvmtodo.data.TaskDao
import com.codinginflow.mvvmtodo.ui.ADD_TASK_RESULT_OK
import com.codinginflow.mvvmtodo.ui.EDIT_TASK_RESULT_OK
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.receiveAsFlow
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_tasks.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ui.tasks.TasksFragment">

<androidx.recyclerview.widget.RecyclerView
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@
android:id="@+id/addEditTaskFragment"
android:name="com.codinginflow.mvvmtodo.ui.addedittask.AddEditTaskFragment"
android:label="{title}"
tools:layout="@layout/fragment_add_edit_task" >
tools:layout="@layout/fragment_add_edit_task">
<argument
android:name="task"
android:defaultValue="@null"
app:argType="com.codinginflow.mvvmtodo.data.Task"
app:nullable="true"
android:defaultValue="@null" />
app:nullable="true" />
<argument
android:name="title"
app:argType="string" />
</fragment>
<dialog
android:id="@+id/deleteAllCompletedDialogFragment"
android:name="com.codinginflow.mvvmtodo.ui.deleteallcompleted.DeleteAllCompletedDialogFragment"
android:label="DeleteAllCompletedDialogFragment" /><action android:id="@+id/action_global_deleteAllCompletedDialogFragment" app:destination="@id/deleteAllCompletedDialogFragment"/>
android:label="DeleteAllCompletedDialogFragment" />
<action
android:id="@+id/action_global_deleteAllCompletedDialogFragment"
app:destination="@id/deleteAllCompletedDialogFragment" />
</navigation>

0 comments on commit bc2b89c

Please sign in to comment.