Add popup after login for the tutorial
This commit is contained in:
parent
9ebeda23a3
commit
212ae778fb
|
@ -5,6 +5,7 @@ import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.provider.Settings
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
|
@ -20,6 +21,8 @@ import org.pixeldroid.app.BuildConfig
|
||||||
import org.pixeldroid.app.R
|
import org.pixeldroid.app.R
|
||||||
import org.pixeldroid.app.databinding.ActivityLoginBinding
|
import org.pixeldroid.app.databinding.ActivityLoginBinding
|
||||||
import org.pixeldroid.app.main.MainActivity
|
import org.pixeldroid.app.main.MainActivity
|
||||||
|
import org.pixeldroid.app.settings.SettingsActivity
|
||||||
|
import org.pixeldroid.app.settings.TutorialSettingsDialog.Companion.START_TUTORIAL
|
||||||
import org.pixeldroid.app.utils.BaseActivity
|
import org.pixeldroid.app.utils.BaseActivity
|
||||||
import org.pixeldroid.app.utils.api.PixelfedAPI
|
import org.pixeldroid.app.utils.api.PixelfedAPI
|
||||||
import org.pixeldroid.app.utils.openUrl
|
import org.pixeldroid.app.utils.openUrl
|
||||||
|
@ -89,11 +92,25 @@ class LoginActivity : BaseActivity() {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
model.finishedLogin.collectLatest {
|
model.finishedLogin.collectLatest {
|
||||||
if (it) {
|
when (it) {
|
||||||
val intent = Intent(this@LoginActivity, MainActivity::class.java)
|
LoginActivityViewModel.FinishedLogin.Finished -> {
|
||||||
intent.flags =
|
val intent = Intent(this@LoginActivity, MainActivity::class.java)
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
intent.flags =
|
||||||
startActivity(intent)
|
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
LoginActivityViewModel.FinishedLogin.FinishedFirstTime -> MaterialAlertDialogBuilder(binding.root.context)
|
||||||
|
.setMessage(R.string.first_time_question)
|
||||||
|
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||||
|
val intent = Intent(this@LoginActivity, SettingsActivity::class.java)
|
||||||
|
intent.flags =
|
||||||
|
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||||
|
intent.putExtra(START_TUTORIAL, true)
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.skip_tutorial) { _, _ -> model.finishLogin()}
|
||||||
|
.show()
|
||||||
|
LoginActivityViewModel.FinishedLogin.NotFinished -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,10 @@ class LoginActivityViewModel @Inject constructor(
|
||||||
private val _loadingState: MutableStateFlow<LoginState> = MutableStateFlow(LoginState(LoginState.LoadingState.Resting))
|
private val _loadingState: MutableStateFlow<LoginState> = MutableStateFlow(LoginState(LoginState.LoadingState.Resting))
|
||||||
val loadingState = _loadingState.asStateFlow()
|
val loadingState = _loadingState.asStateFlow()
|
||||||
|
|
||||||
private val _finishedLogin = MutableStateFlow(false)
|
enum class FinishedLogin {
|
||||||
|
NotFinished, Finished, FinishedFirstTime
|
||||||
|
}
|
||||||
|
private val _finishedLogin = MutableStateFlow(FinishedLogin.NotFinished)
|
||||||
val finishedLogin = _finishedLogin.asStateFlow()
|
val finishedLogin = _finishedLogin.asStateFlow()
|
||||||
|
|
||||||
private val _promptOauth: MutableStateFlow<PromptOAuth?> = MutableStateFlow(null)
|
private val _promptOauth: MutableStateFlow<PromptOAuth?> = MutableStateFlow(null)
|
||||||
|
@ -207,6 +210,7 @@ class LoginActivityViewModel @Inject constructor(
|
||||||
|
|
||||||
private suspend fun storeUser(accessToken: String, refreshToken: String?, clientId: String, clientSecret: String, instance: String) {
|
private suspend fun storeUser(accessToken: String, refreshToken: String?, clientId: String, clientSecret: String, instance: String) {
|
||||||
try {
|
try {
|
||||||
|
val firstTime = db.userDao().getActiveUser() == null
|
||||||
val user = pixelfedAPI.verifyCredentials("Bearer $accessToken")
|
val user = pixelfedAPI.verifyCredentials("Bearer $accessToken")
|
||||||
db.userDao().deActivateActiveUsers()
|
db.userDao().deActivateActiveUsers()
|
||||||
addUser(
|
addUser(
|
||||||
|
@ -220,12 +224,14 @@ class LoginActivityViewModel @Inject constructor(
|
||||||
clientSecret = clientSecret
|
clientSecret = clientSecret
|
||||||
)
|
)
|
||||||
apiHolder.setToCurrentUser()
|
apiHolder.setToCurrentUser()
|
||||||
|
|
||||||
|
fetchNotifications()
|
||||||
|
|
||||||
|
_finishedLogin.value = if(firstTime) FinishedLogin.FinishedFirstTime else FinishedLogin.Finished
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
return failedRegistration(R.string.verify_credentials)
|
return failedRegistration(R.string.verify_credentials)
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchNotifications()
|
|
||||||
_finishedLogin.value = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the latest notifications of this account, to avoid launching old notifications
|
// Fetch the latest notifications of this account, to avoid launching old notifications
|
||||||
|
@ -280,4 +286,8 @@ class LoginActivityViewModel @Inject constructor(
|
||||||
_loadingState.value = LoginState(LoginState.LoadingState.Resting)
|
_loadingState.value = LoginState(LoginState.LoadingState.Resting)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun finishLogin() {
|
||||||
|
_finishedLogin.value = FinishedLogin.Finished
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -22,6 +22,7 @@ import kotlinx.coroutines.launch
|
||||||
import org.pixeldroid.app.R
|
import org.pixeldroid.app.R
|
||||||
import org.pixeldroid.app.databinding.SettingsBinding
|
import org.pixeldroid.app.databinding.SettingsBinding
|
||||||
import org.pixeldroid.app.main.MainActivity
|
import org.pixeldroid.app.main.MainActivity
|
||||||
|
import org.pixeldroid.app.settings.TutorialSettingsDialog.Companion.START_TUTORIAL
|
||||||
import org.pixeldroid.app.utils.setThemeFromPreferences
|
import org.pixeldroid.app.utils.setThemeFromPreferences
|
||||||
import org.pixeldroid.common.ThemedActivity
|
import org.pixeldroid.common.ThemedActivity
|
||||||
|
|
||||||
|
@ -46,6 +47,20 @@ class SettingsActivity : ThemedActivity(), SharedPreferences.OnSharedPreferenceC
|
||||||
.commit()
|
.commit()
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
|
||||||
|
val showTutorial = intent.getBooleanExtra(START_TUTORIAL, false)
|
||||||
|
|
||||||
|
if(showTutorial){
|
||||||
|
lifecycleScope.launch {
|
||||||
|
var target =
|
||||||
|
(supportFragmentManager.findFragmentByTag("topsettingsfragment") as? SettingsFragment)?.scrollToArrangeTabs(10)
|
||||||
|
while (target == null) {
|
||||||
|
target = (supportFragmentManager.findFragmentByTag("topsettingsfragment") as? SettingsFragment)?.scrollToArrangeTabs(10)
|
||||||
|
delay(100)
|
||||||
|
}
|
||||||
|
target.performClick()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onBackPressedDispatcher.addCallback(this /* lifecycle owner */) {
|
onBackPressedDispatcher.addCallback(this /* lifecycle owner */) {
|
||||||
// Handle the back button event
|
// Handle the back button event
|
||||||
// If a setting (for example language or theme) was changed, the main activity should be
|
// If a setting (for example language or theme) was changed, the main activity should be
|
||||||
|
@ -111,9 +126,9 @@ class SettingsActivity : ThemedActivity(), SharedPreferences.OnSharedPreferenceC
|
||||||
fun customTabsTutorial(){
|
fun customTabsTutorial(){
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
var target =
|
var target =
|
||||||
(supportFragmentManager.findFragmentByTag("topsettingsfragment") as? SettingsFragment)?.scrollToArrangeTabs()
|
(supportFragmentManager.findFragmentByTag("topsettingsfragment") as? SettingsFragment)?.scrollToArrangeTabs(5)
|
||||||
while (target == null) {
|
while (target == null) {
|
||||||
target = (supportFragmentManager.findFragmentByTag("topsettingsfragment") as? SettingsFragment)?.scrollToArrangeTabs()
|
target = (supportFragmentManager.findFragmentByTag("topsettingsfragment") as? SettingsFragment)?.scrollToArrangeTabs(5)
|
||||||
delay(100)
|
delay(100)
|
||||||
}
|
}
|
||||||
TapTargetView.showFor(
|
TapTargetView.showFor(
|
||||||
|
@ -157,9 +172,8 @@ class SettingsActivity : ThemedActivity(), SharedPreferences.OnSharedPreferenceC
|
||||||
super.onDisplayPreferenceDialog(preference)
|
super.onDisplayPreferenceDialog(preference)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun scrollToArrangeTabs(): View? {
|
fun scrollToArrangeTabs(position: Int): View? {
|
||||||
//Hardcoded because it's too annoying to find!
|
//Hardcoded positions because it's too annoying to find!
|
||||||
val position = 5
|
|
||||||
|
|
||||||
if (listView != null && position != -1) {
|
if (listView != null && position != -1) {
|
||||||
listView.post {
|
listView.post {
|
||||||
|
|
|
@ -368,4 +368,6 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
|
||||||
<string name="tutorial_choice">What could you use some help with?</string>
|
<string name="tutorial_choice">What could you use some help with?</string>
|
||||||
<string name="dm_tutorial">Direct Messages: keep in touch!</string>
|
<string name="dm_tutorial">Direct Messages: keep in touch!</string>
|
||||||
<string name="custom_tabs_tutorial">Customize what tabs show up on the main PixelDroid screen!</string>
|
<string name="custom_tabs_tutorial">Customize what tabs show up on the main PixelDroid screen!</string>
|
||||||
|
<string name="first_time_question">It seems like it might be your first time using PixelDroid. Do you want to open a tutorial? You can always find the tutorials in the settings.</string>
|
||||||
|
<string name="skip_tutorial">No, continue</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue