From bc2b89c60c1522662c76e044c538349c5c8a15f7 Mon Sep 17 00:00:00 2001 From: Florian Date: Mon, 16 Nov 2020 12:31:21 +0100 Subject: [PATCH] Formatting code + small corrections after finishing the tutorial --- app/src/main/AndroidManifest.xml | 3 ++- .../mvvmtodo/data/PreferencesManager.kt | 1 - .../com/codinginflow/mvvmtodo/data/TaskDao.kt | 2 +- .../codinginflow/mvvmtodo/ui/MainActivity.kt | 2 +- .../mvvmtodo/ui/tasks/TasksAdapter.kt | 6 +++-- .../mvvmtodo/ui/tasks/TasksFragment.kt | 25 +++++++++++++------ .../mvvmtodo/ui/tasks/TasksViewModel.kt | 1 - app/src/main/res/layout/fragment_tasks.xml | 2 +- app/src/main/res/navigation/nav_graph.xml | 11 +++++--- 9 files changed, 34 insertions(+), 19 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ae779f6..425479d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,7 +10,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MVVMTodo"> - diff --git a/app/src/main/java/com/codinginflow/mvvmtodo/data/PreferencesManager.kt b/app/src/main/java/com/codinginflow/mvvmtodo/data/PreferencesManager.kt index 9c97b76..81d102a 100644 --- a/app/src/main/java/com/codinginflow/mvvmtodo/data/PreferencesManager.kt +++ b/app/src/main/java/com/codinginflow/mvvmtodo/data/PreferencesManager.kt @@ -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 diff --git a/app/src/main/java/com/codinginflow/mvvmtodo/data/TaskDao.kt b/app/src/main/java/com/codinginflow/mvvmtodo/data/TaskDao.kt index 146d3f5..3ca7645 100644 --- a/app/src/main/java/com/codinginflow/mvvmtodo/data/TaskDao.kt +++ b/app/src/main/java/com/codinginflow/mvvmtodo/data/TaskDao.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.Flow interface TaskDao { fun getTasks(query: String, sortOrder: SortOrder, hideCompleted: Boolean): Flow> = - when(sortOrder) { + when (sortOrder) { SortOrder.BY_DATE -> getTasksSortedByDateCreated(query, hideCompleted) SortOrder.BY_NAME -> getTasksSortedByName(query, hideCompleted) } diff --git a/app/src/main/java/com/codinginflow/mvvmtodo/ui/MainActivity.kt b/app/src/main/java/com/codinginflow/mvvmtodo/ui/MainActivity.kt index 3d22d47..20fd126 100644 --- a/app/src/main/java/com/codinginflow/mvvmtodo/ui/MainActivity.kt +++ b/app/src/main/java/com/codinginflow/mvvmtodo/ui/MainActivity.kt @@ -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 diff --git a/app/src/main/java/com/codinginflow/mvvmtodo/ui/tasks/TasksAdapter.kt b/app/src/main/java/com/codinginflow/mvvmtodo/ui/tasks/TasksAdapter.kt index 9fe1f3a..b7a78c8 100644 --- a/app/src/main/java/com/codinginflow/mvvmtodo/ui/tasks/TasksAdapter.kt +++ b/app/src/main/java/com/codinginflow/mvvmtodo/ui/tasks/TasksAdapter.kt @@ -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(DiffCallback()) { +class TasksAdapter(private val listener: OnItemClickListener) : + ListAdapter(DiffCallback()) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TasksViewHolder { val binding = ItemTaskBinding.inflate(LayoutInflater.from(parent.context), parent, false) @@ -21,7 +22,8 @@ class TasksAdapter(private val listener: OnItemClickListener) : ListAdapter { - 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 @@ -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 diff --git a/app/src/main/java/com/codinginflow/mvvmtodo/ui/tasks/TasksViewModel.kt b/app/src/main/java/com/codinginflow/mvvmtodo/ui/tasks/TasksViewModel.kt index 0d3a750..b8432ce 100644 --- a/app/src/main/java/com/codinginflow/mvvmtodo/ui/tasks/TasksViewModel.kt +++ b/app/src/main/java/com/codinginflow/mvvmtodo/ui/tasks/TasksViewModel.kt @@ -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 diff --git a/app/src/main/res/layout/fragment_tasks.xml b/app/src/main/res/layout/fragment_tasks.xml index b9a9219..6536461 100644 --- a/app/src/main/res/layout/fragment_tasks.xml +++ b/app/src/main/res/layout/fragment_tasks.xml @@ -1,8 +1,8 @@ + tools:layout="@layout/fragment_add_edit_task"> + app:nullable="true" /> @@ -31,5 +31,8 @@ + android:label="DeleteAllCompletedDialogFragment" /> + \ No newline at end of file