Skip to content

Commit

Permalink
Merge pull request #57 from Efimj/enhancement/move-onboarding-to-dialog
Browse files Browse the repository at this point in the history
Enhancement/move onboarding to dialog
  • Loading branch information
Efimj authored Jun 26, 2024
2 parents 75b0ff2 + 10afa0b commit e40053b
Show file tree
Hide file tree
Showing 27 changed files with 27,043 additions and 1,451 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,7 @@ dependencies {
// implementation("me.onebone:toolbar-compose:2.3.5")
// Compose collapsing toolbar (nonofficial)
implementation(libs.composecollapsingtoolbar)

// Konfetti to make confetti
implementation (libs.konfetti.compose)
}
3 changes: 1 addition & 2 deletions app/src/main/java/com/jobik/shkiper/SharedPreferencesKeys.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ object SharedPreferencesKeys {
const val ApplicationStorageName = "ApplicationStorageName"
const val ApplicationSettings = "ApplicationSettings"
const val ApplicationUiMode = "ApplicationUiMode"
const val OnboardingFinishedData = "1"
const val OnboardingFinishedData = "2"
const val OnboardingPageFinishedData = "OnboardingPageFinishedData"
const val CountOfferReview = "CountOfferReview"
const val LastDateReviewOffer = "LastDateReviewOffer"
const val Localization = "Localization"
const val Statistics = "Statistics"
const val LastBannerSupportDeveloperShowingDate = "LastBannerSupportDeveloperShowingDate"

}
38 changes: 30 additions & 8 deletions app/src/main/java/com/jobik/shkiper/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.jobik.shkiper.activity
import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
Expand All @@ -18,7 +19,6 @@ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.jobik.shkiper.NotepadApplication
import com.jobik.shkiper.SharedPreferencesKeys
import com.jobik.shkiper.SharedPreferencesKeys.OnboardingFinishedData
import com.jobik.shkiper.database.models.NotePosition
import com.jobik.shkiper.navigation.Screen
import com.jobik.shkiper.screens.layout.AppLayout
import com.jobik.shkiper.services.billing.BillingService
Expand Down Expand Up @@ -72,19 +72,14 @@ open class MainActivity : ComponentActivity() {
checkForUpdates()

setContent {
val onboarding = rememberSaveable { mutableStateOf(checkIsOnboarding(this)) }

SecureModeManager()
UpdateStatistics()

ShkiperTheme(
darkTheme = ThemeUtil.isDarkMode.value ?: isSystemInDarkTheme(),
style = ThemeUtil.themeStyle.value ?: CustomThemeStyle.PastelPurple
style = ThemeUtil.themeStyle.value ?: CustomThemeStyle.MaterialDynamicColors
) {
OnboardingDialog(
isVisible = onboarding.value,
onFinish = { onboarding.value = false })

OnboardingProvider()
AppLayout(startDestination)
if (canShowOfferReview.value) {
OfferWriteReview { canShowOfferReview.value = false }
Expand All @@ -93,6 +88,33 @@ open class MainActivity : ComponentActivity() {
}
}

@Composable
private fun OnboardingProvider() {
val onboarding = rememberSaveable { mutableStateOf(checkIsOnboarding(this)) }

val context = LocalContext.current
OnboardingDialog(
isVisible = onboarding.value,
onFinish = {
onboarding.value = false;
try {
val sharedPreferences =
context.getSharedPreferences(
SharedPreferencesKeys.ApplicationStorageName,
MODE_PRIVATE
)
sharedPreferences.edit()
.putString(
SharedPreferencesKeys.OnboardingPageFinishedData,
OnboardingFinishedData
)
.apply()
} catch (e: Exception) {
Log.i("onboarding - onFinished", e.toString())
}
})
}

@Composable
private fun UpdateStatistics() {
val context = LocalContext.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ShareReceiverActivity : AppCompatActivity() {
setContent {
ShkiperTheme(
darkTheme = ThemeUtil.isDarkMode.value ?: isSystemInDarkTheme(),
style = ThemeUtil.themeStyle.value ?: CustomThemeStyle.PastelPurple
style = ThemeUtil.themeStyle.value ?: CustomThemeStyle.MaterialDynamicColors
) {
Box(
Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fun AboutNotepadScreen() {
.horizontalScroll(rememberScrollState()),
horizontalAlignment = Alignment.Start
) {
val link = stringResource(R.string.GameOfLifeLink)
val link = stringResource(R.string.game_of_life_link)
Card(
modifier = Modifier
.height(160.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package com.jobik.shkiper.screens.layout.navigation

import androidx.annotation.StringRes
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateIntAsState
import androidx.compose.animation.core.spring
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
Expand Down Expand Up @@ -53,16 +57,16 @@ fun CustomBottomNavigationItem(properties: CustomBottomNavigationItem) {
label = "contentColor"
)

IconButton(
Box(
modifier = Modifier
.fillMaxHeight()
.aspectRatio(1f),
colors = IconButtonDefaults.iconButtonColors(
contentColor = contentColor.value,
),
onClick = {
properties.onClick()
}
.aspectRatio(1f)
.clickable(
indication = null, // Remove ripple effect
interactionSource = remember { MutableInteractionSource() },
onClick = { properties.onClick() }
),
contentAlignment = Alignment.Center
) {
Icon(
imageVector = properties.icon,
Expand Down Expand Up @@ -93,7 +97,11 @@ fun CustomBottomNavigation(items: List<CustomBottomNavigationItem>) {

val indicatorOffset by animateIntAsState(
targetValue = lastIndex * (buttonWidth + spacerBetween.px),
label = ""
animationSpec = spring(
dampingRatio = Spring.DampingRatioNoBouncy,
stiffness = Spring.StiffnessMediumLow
),
label = "indicatorOffset"
)

Surface(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jobik.shkiper.screens.layout.navigation

import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.expandHorizontally
import androidx.compose.animation.fadeIn
Expand Down Expand Up @@ -218,32 +219,34 @@ private fun Navigation(
val navBackStackEntry = navController.currentBackStackEntryAsState().value
val currentDestination = navBackStackEntry?.destination

val isNoteList = currentDestination?.hierarchy?.any {
it.hasRoute(Screen.NoteList::class)
} == true

BackHandler(enabled = isNoteList && notePosition != NotePosition.MAIN) {
onNotePositionChange(NotePosition.MAIN)
}

val navigationItems = listOf(
CustomBottomNavigationItem(
icon = Icons.Outlined.AutoAwesomeMosaic,
isSelected = currentDestination?.hierarchy?.any {
it.hasRoute(Screen.NoteList::class)
} == true && notePosition == NotePosition.MAIN,
isSelected = isNoteList && notePosition == NotePosition.MAIN,
description = R.string.Notes,
) {
navController.navigateToMain(destination = Screen.NoteList)
onNotePositionChange(NotePosition.MAIN)
},
CustomBottomNavigationItem(
icon = Icons.Outlined.Archive,
isSelected = currentDestination?.hierarchy?.any {
it.hasRoute(Screen.NoteList::class)
} == true && notePosition == NotePosition.ARCHIVE,
isSelected = isNoteList && notePosition == NotePosition.ARCHIVE,
description = R.string.Archive,
) {
navController.navigateToMain(destination = Screen.NoteList)
onNotePositionChange(NotePosition.ARCHIVE)
},
CustomBottomNavigationItem(
icon = Icons.Outlined.Delete,
isSelected = currentDestination?.hierarchy?.any {
it.hasRoute(Screen.NoteList::class)
} == true && notePosition == NotePosition.DELETE,
isSelected = isNoteList && notePosition == NotePosition.DELETE,
description = R.string.Basket,
) {
navController.navigateToMain(destination = Screen.NoteList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.jobik.shkiper.screens.settings
import android.app.Activity
import android.content.Context
import android.os.Build
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedContent
Expand Down Expand Up @@ -42,10 +43,12 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
Expand Down Expand Up @@ -165,14 +168,18 @@ private fun OtherSettings(navController: NavController) {
title = stringResource(R.string.StatisticsPage),
onClick = { navController.navigateToSecondary(Screen.Statistics) }
)
val isOnboarding = rememberSaveable { mutableStateOf(false) }
var isOnboarding by rememberSaveable { mutableStateOf(false) }

SettingsItem(
icon = Icons.Outlined.ViewCarousel,
title = stringResource(R.string.OnboardingPage),
onClick = { isOnboarding.value = true }
onClick = { isOnboarding = true }
)
OnboardingDialog(isVisible = isOnboarding.value) {
isOnboarding.value = false
BackHandler(isOnboarding) {
isOnboarding = isOnboarding.not()
}
OnboardingDialog(isVisible = isOnboarding) {
isOnboarding = false
}
}
}
Expand Down Expand Up @@ -330,7 +337,8 @@ private fun SettingsColorThemePicker(settingsViewModel: SettingsViewModel) {
val colorValues =
if (isDarkMode == true) CustomThemeStyle.entries.map { it.dark } else CustomThemeStyle.entries.map { it.light }
val colorValuesName = CustomThemeStyle.entries
val selectedThemeName = ThemeUtil.themeStyle.value?.name ?: CustomThemeStyle.PastelPurple.name
val selectedThemeName =
ThemeUtil.themeStyle.value?.name ?: CustomThemeStyle.MaterialDynamicColors.name
val context = LocalContext.current

Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SettingsViewModel @Inject constructor(
ThemeUtil.saveThemeMode(
context = application.applicationContext,
mode = !(ThemeUtil.isDarkMode.value ?: false),
newThemeStyle = ThemeUtil.themeStyle.value ?: CustomThemeStyle.PastelPurple
newThemeStyle = ThemeUtil.themeStyle.value ?: CustomThemeStyle.MaterialDynamicColors
)
}

Expand Down
Loading

0 comments on commit e40053b

Please sign in to comment.