This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing issue where rotating the screen would navigate to the initial screen --------- Co-authored-by: John Oberhauser <j.git-global@obez.io>
- Loading branch information
1 parent
f524a97
commit 5db7422
Showing
8 changed files
with
144 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package social.firefly | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Parcelable | ||
import social.firefly.core.datastore.UserPreferencesDatastoreManager | ||
import social.firefly.core.navigation.Event | ||
import social.firefly.core.navigation.EventRelay | ||
import social.firefly.core.share.ShareInfo | ||
|
||
class IntentHandler( | ||
private val eventRelay: EventRelay, | ||
private val userPreferencesDatastoreManager: UserPreferencesDatastoreManager, | ||
) { | ||
|
||
fun handleIntent(intent: Intent) { | ||
if (!userPreferencesDatastoreManager.isLoggedInToAtLeastOneAccount) return | ||
when { | ||
intent.action == Intent.ACTION_SEND -> { | ||
when { | ||
intent.type == "text/plain" -> { | ||
handleSendTextIntentReceived(intent) | ||
} | ||
intent.type?.contains("image") == true -> { | ||
handleSendImageIntentReceived(intent) | ||
} | ||
intent.type?.contains("video") == true -> { | ||
handleSendVideoIntentReceived(intent) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun handleSendTextIntentReceived(intent: Intent) { | ||
intent.getStringExtra(Intent.EXTRA_TEXT)?.let { sharedText -> | ||
ShareInfo.sharedText = sharedText | ||
eventRelay.emitEvent(Event.ChooseAccountForSharing) | ||
} | ||
} | ||
|
||
private fun handleSendImageIntentReceived(intent: Intent) { | ||
(intent.getParcelableExtra<Parcelable>(Intent.EXTRA_STREAM) as? Uri)?.let { sharedUri -> | ||
ShareInfo.sharedImageUri = sharedUri | ||
eventRelay.emitEvent(Event.ChooseAccountForSharing) | ||
} | ||
} | ||
|
||
private fun handleSendVideoIntentReceived(intent: Intent) { | ||
(intent.getParcelableExtra<Parcelable>(Intent.EXTRA_STREAM) as? Uri)?.let { sharedUri -> | ||
ShareInfo.sharedVideoUri = sharedUri | ||
eventRelay.emitEvent(Event.ChooseAccountForSharing) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package social.firefly.splash | ||
|
||
import androidx.activity.ComponentActivity | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.compose.composable | ||
import org.koin.androidx.compose.koinViewModel | ||
import social.firefly.ui.bottombar.Routes | ||
|
||
fun NavGraphBuilder.splashScreen() { | ||
composable(route = Routes.SPLASH) { | ||
SplashScreen() | ||
} | ||
} | ||
|
||
@Composable | ||
private fun SplashScreen( | ||
viewModel: SplashViewModel = koinViewModel() | ||
) { | ||
val activity = LocalContext.current as? ComponentActivity | ||
LaunchedEffect(Unit) { | ||
viewModel.initialize(activity?.intent) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/kotlin/social/firefly/splash/SplashViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package social.firefly.splash | ||
|
||
import android.content.Intent | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.launch | ||
import social.firefly.IntentHandler | ||
import social.firefly.core.datastore.UserPreferencesDatastoreManager | ||
import social.firefly.core.navigation.NavigationDestination | ||
import social.firefly.core.navigation.usecases.NavigateTo | ||
import social.firefly.core.repository.mastodon.TimelineRepository | ||
import social.firefly.core.usecase.mastodon.auth.UpdateAllLoggedInAccounts | ||
import social.firefly.ui.AppState | ||
|
||
class SplashViewModel( | ||
private val navigateTo: NavigateTo, | ||
private val userPreferencesDatastoreManager: UserPreferencesDatastoreManager, | ||
private val timelineRepository: TimelineRepository, | ||
private val updateAllLoggedInAccounts: UpdateAllLoggedInAccounts, | ||
private val intentHandler: IntentHandler, | ||
) : ViewModel() { | ||
|
||
fun initialize(intent: Intent?) { | ||
viewModelScope.launch { | ||
// Do any cleanup necessary before navigating away from the splash screen | ||
timelineRepository.deleteHomeTimeline() | ||
|
||
AppState.navigationCollectionCompletable.await() | ||
|
||
if (userPreferencesDatastoreManager.isLoggedInToAtLeastOneAccount) { | ||
navigateTo(NavigationDestination.Tabs) | ||
intent?.let { intentHandler.handleIntent(intent) } | ||
updateAllLoggedInAccounts() | ||
} else { | ||
navigateTo(NavigationDestination.Auth) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters