From fa32540471e496a360c0a0df38d23eb1b662b294 Mon Sep 17 00:00:00 2001 From: Leonidius20 <25536411+Leonidius20@users.noreply.github.com> Date: Thu, 18 Jul 2024 12:56:55 +0300 Subject: [PATCH] changed rec screen layout --- .../recordings_list/RecordingsListFragment.kt | 48 ++++++++--- app/src/main/res/drawable/ic_stop.xml | 8 +- app/src/main/res/layout/activity_main.xml | 4 +- app/src/main/res/layout/fragment_home.xml | 80 +++++++++++++++---- app/src/main/res/layout/rename_dialog.xml | 2 +- app/src/main/res/values/dimens.xml | 2 + 6 files changed, 111 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/io/github/leonidius20/recorder/ui/recordings_list/RecordingsListFragment.kt b/app/src/main/java/io/github/leonidius20/recorder/ui/recordings_list/RecordingsListFragment.kt index 076f007..3b9fecf 100644 --- a/app/src/main/java/io/github/leonidius20/recorder/ui/recordings_list/RecordingsListFragment.kt +++ b/app/src/main/java/io/github/leonidius20/recorder/ui/recordings_list/RecordingsListFragment.kt @@ -207,32 +207,54 @@ class RecordingsListFragment : Fragment() { // if success // todo: first stop actionmode, then show rename dialog, so that the need for payloads is evident + + + + + + actionMode!!.finish() + + showRenameDialog(position) // probably not very sustainable when we will implement + // restoring the dialog after screen rotation. Maybe it is better to restore selected + // items and then take position from there + + + } + + /** + * shows rename dialog for the first time or after activity recreation + */ + fun showRenameDialog(position: Int) { + // todo: dialog being shown is a part of UI state. It should be stored in viewmodel + // and there should be a "render" function that simply renders out the state that is + // saved in viewmodel + // todo: it is lost when screen rotates - val dialogView = RenameDialogBinding.inflate(layoutInflater) + + // todo: this right here is a "feature envy" code smell. Need to refactor + // and reachitect the ui state logic + + //todo: dialog fragment with callback? + viewModel.renameFileNewName.value = viewModel.recordings.value!![position].name + + val dialogView = RenameDialogBinding.inflate(layoutInflater) AlertDialog.Builder(requireContext()) .setTitle(R.string.recordings_list_choose_new_name) .setView(dialogView.root) .setPositiveButton(android.R.string.ok) { d, i -> - + onRenameDialogSubmitted(position) } .show() + } - actionMode!!.finish() + private fun onRenameDialogSubmitted(position: Int) { val newData = viewModel.recordings.value!![position].copy( - name = "new name" + name = viewModel.renameFileNewName.value!! ) + // todo: actually rename in Repository adapter.replaceItemAt(position, newData) } - /** - * shows rename dialog for the first time or after activity recreation - */ - fun showRenameDialog() {} - - fun onRenameDialogSubmitted() { - - } - } \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_stop.xml b/app/src/main/res/drawable/ic_stop.xml index 817d57b..3b01f11 100644 --- a/app/src/main/res/drawable/ic_stop.xml +++ b/app/src/main/res/drawable/ic_stop.xml @@ -1,4 +1,10 @@ - + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 7bde173..b4e9fdf 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -27,8 +27,8 @@ + + -