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

Fix #565: Domain on-boarding flag #574

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
android:name=".mydownloads.MyDownloadsActivity"
android:screenOrientation="portrait"
android:theme="@style/OppiaThemeWithoutActionBar" />
<activity
android:name=".onboarding.OnBoardingActivity"
android:screenOrientation="portrait"
android:theme="@style/OppiaThemeWithoutActionBar" />
<activity
android:name=".player.exploration.ExplorationActivity"
android:screenOrientation="portrait"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.oppia.app.help.HelpActivity
import org.oppia.app.home.HomeActivity
import org.oppia.app.home.continueplaying.ContinuePlayingActivity
import org.oppia.app.mydownloads.MyDownloadsActivity
import org.oppia.app.onboarding.OnBoardingActivity
import org.oppia.app.player.exploration.ExplorationActivity
import org.oppia.app.profile.AddProfileActivity
import org.oppia.app.profile.AdminAuthActivity
Expand All @@ -18,6 +19,7 @@ import org.oppia.app.settings.profile.ProfileEditActivity
import org.oppia.app.settings.profile.ProfileListActivity
import org.oppia.app.settings.profile.ProfileRenameActivity
import org.oppia.app.settings.profile.ProfileResetPinActivity
import org.oppia.app.splash.SplashActivity
import org.oppia.app.story.StoryActivity
import org.oppia.app.story.testing.StoryFragmentTestActivity
import org.oppia.app.testing.AudioFragmentTestActivity
Expand Down Expand Up @@ -66,13 +68,15 @@ interface ActivityComponent {
fun inject(htmlParserTestActivity: HtmlParserTestActivity)
fun inject(myDownloadsActivity: MyDownloadsActivity)
fun inject(navigationDrawerTestActivity: NavigationDrawerTestActivity)
fun inject(onBoardingActivity: OnBoardingActivity)
fun inject(pinPasswordActivity: PinPasswordActivity)
fun inject(profileActivity: ProfileActivity)
fun inject(questionPlayerActivity: QuestionPlayerActivity)
fun inject(profileEditActivity: ProfileEditActivity)
fun inject(profileListActivity: ProfileListActivity)
fun inject(profileRenameActivity: ProfileRenameActivity)
fun inject(profileResetPinActivity: ProfileResetPinActivity)
fun inject(splashActivity: SplashActivity)
fun inject(storyActivity: StoryActivity)
fun inject(topicActivity: TopicActivity)
fun inject(topicTestActivity: TopicTestActivity)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.oppia.app.onboarding

import android.os.Bundle
import org.oppia.app.activity.InjectableAppCompatActivity
import org.oppia.app.profile.ProfileActivity
import javax.inject.Inject

/** An activity that shows a temporary on-boarding screen until the app is on-boarded then navigates to [ProfileActivity]. */
class OnBoardingActivity : InjectableAppCompatActivity() {

@Inject lateinit var onBoardingActivityPresenter: OnBoardingActivityPresenter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityComponent.inject(this)
onBoardingActivityPresenter.handleOnCreate()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.oppia.app.onboarding

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.on_boarding_activity.*
import org.oppia.app.R
import org.oppia.app.activity.ActivityScope
import org.oppia.app.profile.ProfileActivity
import org.oppia.domain.OnBoardingFlowController
import javax.inject.Inject

/** The presenter for [OnBoardingActivity]. */
@ActivityScope
class OnBoardingActivityPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val onBoardingFlowController: OnBoardingFlowController
) {

fun handleOnCreate() {
activity.setContentView(R.layout.on_boarding_activity)
activity.on_board.setOnClickListener { subscribeOnBoarding() }
}

private fun subscribeOnBoarding() {
onBoardingFlowController.markOnBoardingFlowCompleted()
val intent = Intent(activity, ProfileActivity::class.java)
activity.startActivity(intent)
activity.finish()
}
}
18 changes: 7 additions & 11 deletions app/src/main/java/org/oppia/app/splash/SplashActivity.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package org.oppia.app.splash

import android.content.Intent
import android.os.Bundle
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import org.oppia.app.R
import org.oppia.app.activity.InjectableAppCompatActivity
import org.oppia.app.profile.ProfileActivity
import javax.inject.Inject

/** An activity that shows a temporary loading page until the app is fully loaded then navigates to [ProfileActivity]. */
class SplashActivity : AppCompatActivity() {
class SplashActivity : InjectableAppCompatActivity() {

@Inject lateinit var splashActivityPresenter: SplashActivityPresenter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.splash_activity)

window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
val intent = Intent(this@SplashActivity, ProfileActivity::class.java)
startActivity(intent)
finish()
activityComponent.inject(this)
splashActivityPresenter.handleOnCreate()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.oppia.app.splash

import android.content.Intent
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.Transformations
import org.oppia.app.R
import org.oppia.app.activity.ActivityScope
import org.oppia.app.model.OnBoardingFlow
import org.oppia.app.onboarding.OnBoardingActivity
import org.oppia.app.profile.ProfileActivity
import org.oppia.domain.OnBoardingFlowController
import org.oppia.util.data.AsyncResult
import javax.inject.Inject

/** The presenter for [SplashActivity]. */
@ActivityScope
class SplashActivityPresenter @Inject constructor(
private val activity: AppCompatActivity,
onBoardingFlowController: OnBoardingFlowController
) {

private val onBoardingFlowData = onBoardingFlowController.getOnBoardingFlow()

fun handleOnCreate() {
activity.setContentView(R.layout.splash_activity)
activity.window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
subscribeToOnBoardingFlow()
}

private fun showOnBoardingActivity() {
val intent = Intent(activity, OnBoardingActivity::class.java)
activity.startActivity(intent)
activity.finish()
}

private fun subscribeToOnBoardingFlow() {
getOnBoardingFlow().observe(activity, Observer<OnBoardingFlow> { result ->
if (result.alreadyOnBoardedApp) {
val intent = Intent(activity, ProfileActivity::class.java)
activity.startActivity(intent)
activity.finish()
} else {
showOnBoardingActivity()
}
})
}

private fun getOnBoardingFlow(): LiveData<OnBoardingFlow> {
// If there's an error loading the data, assume the default.
return Transformations.map(onBoardingFlowData, ::processOnBoardingFlowResult)
}

private fun processOnBoardingFlowResult(onBoardingResult: AsyncResult<OnBoardingFlow>): OnBoardingFlow {
if (onBoardingResult.isFailure()) {
}
return onBoardingResult.getOrDefault(OnBoardingFlow.getDefaultInstance())
}
}
13 changes: 13 additions & 0 deletions app/src/main/res/layout/on_boarding_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/on_board"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="on-board" />
</LinearLayout>
Loading