Skip to content

Commit

Permalink
Merge pull request #32 from d4rken-org/onboarding_page
Browse files Browse the repository at this point in the history
Add extra onboarding screen
  • Loading branch information
d4rken authored Sep 12, 2023
2 parents dc30900 + 95708e9 commit 28395ca
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/eu/darken/octi/main/core/GeneralSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class GeneralSettings @Inject constructor(
override val dataStore: DataStore<Preferences>
get() = context.dataStore

val isOnboardingDone = dataStore.createValue("onboarding.finished", false)

val isWelcomeDismissed = dataStore.createValue("onboarding.welcome.dismissed", false)

val isSyncSetupDismissed = dataStore.createValue("onboarding.syncsetup.dismissed", false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import eu.darken.octi.common.WebpageTool
import eu.darken.octi.common.coroutine.AppScope
import eu.darken.octi.common.coroutine.DispatcherProvider
import eu.darken.octi.common.datastore.value
import eu.darken.octi.common.datastore.valueBlocking
import eu.darken.octi.common.debug.logging.Logging.Priority.WARN
import eu.darken.octi.common.debug.logging.log
import eu.darken.octi.common.debug.logging.logTag
Expand Down Expand Up @@ -66,6 +67,12 @@ class DashboardVM @Inject constructor(
private val clipboardHandler: ClipboardHandler,
) : ViewModel3(dispatcherProvider = dispatcherProvider) {

init {
if (!generalSettings.isOnboardingDone.valueBlocking) {
DashboardFragmentDirections.actionDashFragmentToOnboardingFragment().navigate()
}
}

val dashboardEvents = SingleLiveEvent<DashboardEvent>()

private val isManuallyRefreshing = MutableStateFlow(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package eu.darken.octi.main.ui.onboarding.ui

import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import dagger.hilt.android.AndroidEntryPoint
import eu.darken.octi.R
import eu.darken.octi.common.PrivacyPolicy
import eu.darken.octi.common.WebpageTool
import eu.darken.octi.common.uix.Fragment3
import eu.darken.octi.common.viewbinding.viewBinding
import eu.darken.octi.databinding.OnboardingFragmentBinding
import javax.inject.Inject


@AndroidEntryPoint
class OnboardingFragment : Fragment3(R.layout.onboarding_fragment) {

override val vm: OnboardingFragmentVM by viewModels()
override val ui: OnboardingFragmentBinding by viewBinding()

@Inject lateinit var webpageTool: WebpageTool

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
ui.goPrivacyPolicy.setOnClickListener { webpageTool.open(PrivacyPolicy.URL) }
ui.continueAction.setOnClickListener { vm.finishOnboarding() }
super.onViewCreated(view, savedInstanceState)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package eu.darken.octi.main.ui.onboarding.ui

import androidx.lifecycle.SavedStateHandle
import dagger.hilt.android.lifecycle.HiltViewModel
import eu.darken.octi.common.coroutine.DispatcherProvider
import eu.darken.octi.common.datastore.value
import eu.darken.octi.common.debug.logging.logTag
import eu.darken.octi.common.uix.ViewModel3
import eu.darken.octi.main.core.GeneralSettings
import kotlinx.coroutines.flow.*
import javax.inject.Inject

@HiltViewModel
class OnboardingFragmentVM @Inject constructor(
@Suppress("UNUSED_PARAMETER") handle: SavedStateHandle,
private val dispatcherProvider: DispatcherProvider,
private val generalSettings: GeneralSettings,
) : ViewModel3(dispatcherProvider = dispatcherProvider) {

fun finishOnboarding() = launch {
generalSettings.isOnboardingDone.value(true)
OnboardingFragmentDirections.actionOnboardingFragmentToDashFragment().navigate()
}

companion object {
val TAG = logTag("Onboarding", "Fragment", "VM")
}
}
85 changes: 85 additions & 0 deletions app/src/main/res/layout/onboarding_fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="32dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/mascot"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_marginTop="48dp"
android:src="@mipmap/ic_launcher_round"
app:layout_constraintEnd_toEndOf="@id/title"
app:layout_constraintStart_toStartOf="@id/title"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/title"
style="@style/TextAppearance.Material3.HeadlineLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/app_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/mascot" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/body1"
style="@style/TextAppearance.MaterialComponents.Body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/onboarding_body1"
app:layout_constraintTop_toBottomOf="@id/title" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/body2"
style="@style/TextAppearance.MaterialComponents.Body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/onboarding_body2"
app:layout_constraintTop_toBottomOf="@id/body1" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/body3"
style="@style/TextAppearance.MaterialComponents.Body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/onboarding_body3"
app:layout_constraintTop_toBottomOf="@id/body2" />

<com.google.android.material.button.MaterialButton
android:id="@+id/go_privacy_policy"
style="@style/Widget.Material3.Button.TonalButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="32dp"
android:text="@string/settings_privacy_policy_label"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/body3" />

<com.google.android.material.button.MaterialButton
android:id="@+id/continue_action"
style="@style/Widget.Material3.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="32dp"
android:layout_marginTop="32dp"
android:text="@string/general_continue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/go_privacy_policy" />
</androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>
11 changes: 11 additions & 0 deletions app/src/main/res/navigation/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<action
android:id="@+id/action_dashFragment_to_appsListFragment"
app:destination="@id/appsListFragment" />
<action
android:id="@+id/action_dashFragment_to_onboardingFragment"
app:destination="@id/onboardingFragment" />
</fragment>

<fragment
Expand Down Expand Up @@ -107,6 +110,14 @@
android:name="deviceId"
app:argType="eu.darken.octi.sync.core.DeviceId" />
</fragment>
<fragment
android:id="@+id/onboardingFragment"
android:name="eu.darken.octi.main.ui.onboarding.ui.OnboardingFragment"
tools:layout="@layout/onboarding_fragment">
<action
android:id="@+id/action_onboardingFragment_to_dashFragment"
app:destination="@id/dashFragment" />
</fragment>


</navigation>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<string name="general_refresh_action">Refresh</string>
<string name="general_continue">Continue</string>

<string name="onboarding_body1">Octi is a tool for people with multiple Android devices.</string>
<string name="onboarding_body2">It synchronizes information between the devices so you can see one device from all other devices.</string>
<string name="onboarding_body3">You can upgrade to Octi Pro to gain extra features and support development.</string>

<string name="dashboard_click_hint">Some entries can be clicked to view more details.</string>

<string name="debug_debuglog_size_label">Size</string>
Expand Down

0 comments on commit 28395ca

Please sign in to comment.