Skip to content

Commit

Permalink
Merge pull request #289 from naz013/feature/REM-923_Move_note_preview…
Browse files Browse the repository at this point in the history
…_to_the_fragment

REM-923 - Move note preview to the fragment
  • Loading branch information
naz013 authored Jan 18, 2025
2 parents 604014f + dc1590d commit 96826df
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 118 deletions.
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,6 @@
<activity
android:name=".notes.preview.ImagePreviewActivity"
android:exported="false" />
<activity
android:name=".notes.preview.NotePreviewActivity"
android:exported="false" />
<activity
android:name=".reminder.dialog.ReminderDialog29Activity"
android:excludeFromRecents="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.elementary.tasks.core.data.Commands
import com.github.naz013.feature.common.coroutine.DispatcherProvider
import com.github.naz013.feature.common.viewmodel.mutableLiveDataOf
import com.github.naz013.feature.common.livedata.toLiveData
import com.github.naz013.feature.common.livedata.toSingleEvent
import com.github.naz013.feature.common.viewmodel.mutableLiveDataOf
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

open class BaseProgressViewModel(
protected val dispatcherProvider: DispatcherProvider
Expand All @@ -21,7 +21,7 @@ open class BaseProgressViewModel(
val isInProgress = _isInProgress.toLiveData()

private val _error = mutableLiveDataOf<String>()
val error = _error.toLiveData()
val error = _error.toSingleEvent()

protected fun postInProgress(isInProgress: Boolean) {
_isInProgress.postValue(isInProgress)
Expand All @@ -35,17 +35,6 @@ open class BaseProgressViewModel(
_error.postValue(error)
}

protected fun withResult(doWork: ((error: String) -> Unit) -> Commands) {
viewModelScope.launch(dispatcherProvider.default()) {
postInProgress(true)
val commands = runBlocking {
doWork.invoke { postError(it) }
}
postInProgress(false)
postCommand(commands)
}
}

protected fun withProgressSuspend(doWork: suspend ((error: String) -> Unit) -> Unit) {
viewModelScope.launch(dispatcherProvider.default()) {
postInProgress(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.elementary.tasks.birthdays.preview.PreviewBirthdayFragment
import com.elementary.tasks.core.arch.BaseProgressViewModel
import com.elementary.tasks.googletasks.preview.PreviewGoogleTaskFragment
import com.elementary.tasks.groups.create.EditGroupFragment
import com.elementary.tasks.notes.preview.NotePreviewActivity
import com.elementary.tasks.notes.preview.PreviewNoteFragment
import com.elementary.tasks.places.create.EditPlaceFragment
import com.elementary.tasks.reminder.preview.PreviewReminderFragment
import com.github.naz013.common.datetime.DateTimeManager
Expand Down Expand Up @@ -102,7 +102,8 @@ class GlobalSearchViewModel(
this == EditGroupFragment::class.java ||
this == EditPlaceFragment::class.java ||
this == PreviewGoogleTaskFragment::class.java ||
this == PreviewReminderFragment::class.java
this == PreviewReminderFragment::class.java ||
this == PreviewNoteFragment::class.java
}

private fun Class<*>.destinationId(): Int? {
Expand All @@ -127,6 +128,10 @@ class GlobalSearchViewModel(
R.id.previewReminderFragment
}

this == PreviewNoteFragment::class.java -> {
R.id.previewNoteFragment
}

else -> null
}
}
Expand Down Expand Up @@ -193,7 +198,7 @@ class GlobalSearchViewModel(
ObjectType.GROUP -> EditGroupFragment::class.java
ObjectType.PLACE -> EditPlaceFragment::class.java
ObjectType.GOOGLE_TASK -> PreviewGoogleTaskFragment::class.java
ObjectType.NOTE -> NotePreviewActivity::class.java
ObjectType.NOTE -> PreviewNoteFragment::class.java
ObjectType.BIRTHDAY -> PreviewBirthdayFragment::class.java
ObjectType.REMINDER -> PreviewReminderFragment::class.java
}
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/java/com/elementary/tasks/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.elementary.tasks.home.scheduleview.ScheduleAdapter
import com.elementary.tasks.home.scheduleview.ScheduleHomeViewModel
import com.elementary.tasks.home.scheduleview.ScheduleModel
import com.elementary.tasks.navigation.topfragment.BaseSearchableFragment
import com.elementary.tasks.notes.preview.NotePreviewActivity
import com.elementary.tasks.other.PrivacyPolicyActivity
import com.elementary.tasks.whatsnew.WhatsNewManager
import com.github.naz013.analytics.Screen
Expand All @@ -32,7 +31,6 @@ import com.github.naz013.common.intent.IntentKeys
import com.github.naz013.domain.Reminder
import com.github.naz013.feature.common.livedata.nonNullObserve
import com.github.naz013.ui.common.fragment.startActivity
import com.github.naz013.ui.common.login.LoginApi
import com.github.naz013.ui.common.view.applyTopInsets
import com.github.naz013.ui.common.view.gone
import com.github.naz013.ui.common.view.visible
Expand Down Expand Up @@ -68,8 +66,13 @@ class HomeFragment :
showEventTypeSelectionDialog(time)
},
onNoteClickListener = { _, id ->
LoginApi.openLogged(requireContext(), NotePreviewActivity::class.java) {
putExtra(IntentKeys.INTENT_ID, id)
navigate {
navigate(
R.id.previewNoteFragment,
Bundle().apply {
putString(IntentKeys.INTENT_ID, id)
}
)
}
},
onGoogleTaskClickListener = { _, id ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.github.naz013.navigation.EditReminderScreen
import com.github.naz013.navigation.SettingsScreen
import com.github.naz013.navigation.ViewBirthdayScreen
import com.github.naz013.navigation.ViewGoogleTaskScreen
import com.github.naz013.navigation.ViewNoteScreen
import com.github.naz013.navigation.ViewReminderScreen

class ScreenDestinationIdResolver {
Expand All @@ -29,6 +30,7 @@ class ScreenDestinationIdResolver {
is EditGoogleTaskScreen -> R.id.editGoogleTaskFragment
is ViewReminderScreen -> R.id.previewReminderFragment
is EditReminderScreen -> R.id.buildReminderFragment
is ViewNoteScreen -> R.id.previewNoteFragment
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import android.os.Bundle
import com.elementary.tasks.home.BottomNavActivity
import com.elementary.tasks.notes.create.CreateNoteActivity
import com.elementary.tasks.notes.preview.NotePreviewActivity
import com.github.naz013.logging.Logger
import com.github.naz013.navigation.ActivityDestination
import com.github.naz013.navigation.DeepLinkDestination
Expand All @@ -14,6 +13,7 @@ import com.github.naz013.navigation.EditGoogleTaskScreen
import com.github.naz013.navigation.EditReminderScreen
import com.github.naz013.navigation.ViewBirthdayScreen
import com.github.naz013.navigation.ViewGoogleTaskScreen
import com.github.naz013.navigation.ViewNoteScreen
import com.github.naz013.navigation.ViewReminderScreen
import com.github.naz013.ui.common.context.buildIntent
import com.github.naz013.ui.common.login.LoginApi
Expand Down Expand Up @@ -91,6 +91,13 @@ class ActivityNavigationDispatcher(
}
}

DestinationScreen.NotePreview -> {
val deepLinkDestination = ViewNoteScreen(bundle)
Bundle(bundle).apply {
putParcelable(DeepLinkDestination.KEY, deepLinkDestination)
}
}

else -> bundle
}
}
Expand All @@ -99,7 +106,7 @@ class ActivityNavigationDispatcher(
return when (destinationScreen) {
DestinationScreen.ReminderPreview -> BottomNavActivity::class.java
DestinationScreen.ReminderCreate -> BottomNavActivity::class.java
DestinationScreen.NotePreview -> NotePreviewActivity::class.java
DestinationScreen.NotePreview -> BottomNavActivity::class.java
DestinationScreen.NoteCreate -> CreateNoteActivity::class.java
DestinationScreen.BirthdayPreview -> BottomNavActivity::class.java
DestinationScreen.BirthdayCreate -> BottomNavActivity::class.java
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/elementary/tasks/notes/KoinModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.elementary.tasks.notes.create.CreateNoteViewModel
import com.elementary.tasks.notes.list.NotesViewModel
import com.elementary.tasks.notes.list.archived.ArchivedNotesViewModel
import com.elementary.tasks.notes.preview.ImagesSingleton
import com.elementary.tasks.notes.preview.NotePreviewViewModel
import com.elementary.tasks.notes.preview.PreviewNoteViewModel
import com.elementary.tasks.notes.preview.reminders.ReminderToUiNoteAttachedReminder
import com.elementary.tasks.notes.work.DeleteNoteBackupWorker
import com.elementary.tasks.notes.work.NoteSingleBackupWorker
Expand Down Expand Up @@ -75,7 +75,7 @@ val noteModule = module {
)
}
viewModel { (id: String) ->
NotePreviewViewModel(
PreviewNoteViewModel(
id,
get(),
get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ import com.elementary.tasks.core.data.ui.note.UiNoteList
import com.elementary.tasks.core.interfaces.ActionsListener
import com.elementary.tasks.core.utils.ListActions
import com.elementary.tasks.core.utils.TelephonyUtil
import com.github.naz013.ui.common.Dialogues
import com.elementary.tasks.core.utils.ui.SearchMenuHandler
import com.github.naz013.ui.common.view.ViewUtils
import com.elementary.tasks.core.views.recyclerview.SpaceBetweenItemDecoration
import com.elementary.tasks.core.views.recyclerview.StaggeredSpaceItemDecoration
import com.elementary.tasks.databinding.FragmentNotesBinding
import com.elementary.tasks.navigation.topfragment.BaseTopToolbarFragment
import com.elementary.tasks.notes.create.CreateNoteActivity
import com.elementary.tasks.notes.preview.ImagePreviewActivity
import com.elementary.tasks.notes.preview.ImagesSingleton
import com.elementary.tasks.notes.preview.NotePreviewActivity
import com.github.naz013.analytics.Screen
import com.github.naz013.analytics.ScreenUsedEvent
import com.github.naz013.common.Permissions
Expand All @@ -35,11 +32,12 @@ import com.github.naz013.domain.note.NoteWithImages
import com.github.naz013.feature.common.android.SystemServiceProvider
import com.github.naz013.feature.common.livedata.nonNullObserve
import com.github.naz013.logging.Logger
import com.github.naz013.ui.common.Dialogues
import com.github.naz013.ui.common.context.startActivity
import com.github.naz013.ui.common.fragment.dp2px
import com.github.naz013.ui.common.fragment.startActivity
import com.github.naz013.ui.common.fragment.toast
import com.github.naz013.ui.common.login.LoginApi
import com.github.naz013.ui.common.view.ViewUtils
import com.github.naz013.ui.common.view.applyBottomInsets
import com.github.naz013.ui.common.view.gone
import com.github.naz013.ui.common.view.visible
Expand Down Expand Up @@ -321,8 +319,13 @@ class NotesFragment : BaseTopToolbarFragment<FragmentNotesBinding>() {
override fun getTitle(): String = getString(R.string.notes)

private fun previewNote(id: String?) {
startActivity(NotePreviewActivity::class.java) {
putExtra(IntentKeys.INTENT_ID, id)
navigate {
navigate(
R.id.previewNoteFragment,
Bundle().apply {
putString(IntentKeys.INTENT_ID, id)
}
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import com.elementary.tasks.core.data.ui.note.UiNoteList
import com.elementary.tasks.core.interfaces.ActionsListener
import com.elementary.tasks.core.utils.ListActions
import com.elementary.tasks.core.utils.TelephonyUtil
import com.github.naz013.ui.common.Dialogues
import com.elementary.tasks.core.utils.ui.SearchMenuHandler
import com.github.naz013.ui.common.view.ViewUtils
import com.elementary.tasks.core.views.recyclerview.SpaceBetweenItemDecoration
import com.elementary.tasks.core.views.recyclerview.StaggeredSpaceItemDecoration
import com.elementary.tasks.databinding.FragmentNotesBinding
Expand All @@ -28,18 +26,19 @@ import com.elementary.tasks.notes.list.NoteSortProcessor
import com.elementary.tasks.notes.list.NotesRecyclerAdapter
import com.elementary.tasks.notes.preview.ImagePreviewActivity
import com.elementary.tasks.notes.preview.ImagesSingleton
import com.elementary.tasks.notes.preview.NotePreviewActivity
import com.github.naz013.analytics.Screen
import com.github.naz013.analytics.ScreenUsedEvent
import com.github.naz013.common.intent.IntentKeys
import com.github.naz013.domain.note.NoteWithImages
import com.github.naz013.feature.common.android.SystemServiceProvider
import com.github.naz013.feature.common.livedata.nonNullObserve
import com.github.naz013.logging.Logger
import com.github.naz013.ui.common.Dialogues
import com.github.naz013.ui.common.fragment.dp2px
import com.github.naz013.ui.common.fragment.startActivity
import com.github.naz013.ui.common.fragment.toast
import com.github.naz013.ui.common.login.LoginApi
import com.github.naz013.ui.common.view.ViewUtils
import com.github.naz013.ui.common.view.gone
import com.github.naz013.ui.common.view.visible
import com.github.naz013.ui.common.view.visibleGone
Expand Down Expand Up @@ -314,8 +313,11 @@ class ArchivedNotesFragment : BaseToolbarFragment<FragmentNotesBinding>() {
override fun getTitle(): String = getString(R.string.notes_archive)

private fun previewNote(id: String?) {
startActivity(NotePreviewActivity::class.java) {
putExtra(IntentKeys.INTENT_ID, id)
navigate {
navigate(
R.id.previewNoteFragment,
Bundle().apply { putString(IntentKeys.INTENT_ID, id) }
)
}
}
}
Loading

0 comments on commit 96826df

Please sign in to comment.