Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactored transition when start destination is note screen #46

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/src/main/java/com/jobik/shkiper/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.jobik.shkiper.ui.theme.AppTheme
import com.jobik.shkiper.ui.theme.CustomThemeStyle
import com.jobik.shkiper.ui.theme.ShkiperTheme
import com.jobik.shkiper.util.ContextUtils.adjustFontSize
import com.jobik.shkiper.util.Startup
import com.jobik.shkiper.util.ThemeUtil
import com.jobik.shkiper.util.settings.SettingsManager
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -159,6 +160,7 @@ open class MainActivity : ComponentActivity() {
// Retrieve the extras from the Intent
val extras = intent.extras ?: return null
val noteId = extras.getString(SharedPreferencesKeys.NoteIdExtra, null) ?: return null
Startup.paramNoteId = noteId
return Route.Note.noteId(noteId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,20 @@ import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.navigation.NavHostController
import com.jobik.shkiper.navigation.NavigationHelpers.Companion.navigateToSecondary
import com.jobik.shkiper.navigation.Route
import com.jobik.shkiper.navigation.RouteHelper
import com.jobik.shkiper.navigation.SetupAppScreenNavGraph
import com.jobik.shkiper.screens.layout.NavigationBar.AppNavigationBarState
import kotlinx.coroutines.delay

@Composable
@OptIn(ExperimentalAnimationApi::class)
fun ScreenWrapper(navController: NavHostController, destination: String) {

val startDestination = remember {
defineStartDestination(destination)
}

NavigateToSecondaryRoute(destination, navController)

val connection = remember {
object : NestedScrollConnection {
override fun onPostScroll(
Expand Down Expand Up @@ -60,29 +47,7 @@ fun ScreenWrapper(navController: NavHostController, destination: String) {
) {
SetupAppScreenNavGraph(
navController = navController,
startDestination = startDestination,
startDestination = destination,
)
}
}

@Composable
private fun NavigateToSecondaryRoute(
destination: String,
navController: NavHostController
) {
val isInitialized = rememberSaveable { mutableStateOf(false) }

LaunchedEffect(Unit) {
if (!RouteHelper().isSecondaryRoute(destination)) {
isInitialized.value = true
}
if (isInitialized.value) return@LaunchedEffect
delay(200L)
navController.navigateToSecondary(destination)

isInitialized.value = true
}
}

private fun defineStartDestination(destination: String) =
if (RouteHelper().isSecondaryRoute(destination)) Route.NoteList.route else destination
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.jobik.shkiper.helpers.LinkHelper
import com.jobik.shkiper.navigation.Argument_Note_Id
import com.jobik.shkiper.util.SnackbarHostUtil
import com.jobik.shkiper.util.SnackbarVisualsCustom
import com.jobik.shkiper.util.Startup
import com.jobik.shkiper.widgets.handlers.handleNoteWidgetPin
import com.mohamedrejeb.richeditor.model.RichTextState
import dagger.hilt.android.lifecycle.HiltViewModel
Expand Down Expand Up @@ -77,7 +78,12 @@ class NoteViewModel @Inject constructor(
val screenState: State<NoteScreenState> = _screenState

init {
initializeNote(ObjectId(savedStateHandle[Argument_Note_Id] ?: ""))
val savedState = savedStateHandle[Argument_Note_Id] ?: ""
val noteId = savedState.ifBlank {
Startup.paramNoteId
}

initializeNote(ObjectId(noteId))
viewModelScope.launch {
getReminders()
getHashtags()
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/jobik/shkiper/util/Startup.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.jobik.shkiper.util

object Startup{
var paramNoteId = ""
}