Skip to content

Commit 6f7c380

Browse files
committed
wip
1 parent 27381c7 commit 6f7c380

24 files changed

+212
-102
lines changed

FlowCrypt/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ dependencies {
377377
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:${rootProject.ext.lifecycleVersion}"
378378
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.4.1"
379379
implementation "androidx.lifecycle:lifecycle-process:2.4.1"
380+
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.5.0-alpha01")
380381
implementation "androidx.room:room-runtime:$roomVersion"
381382
implementation "androidx.room:room-ktx:$roomVersion"
382383
implementation "androidx.paging:paging-runtime-ktx:$pagingVersion"
@@ -391,6 +392,7 @@ dependencies {
391392
implementation "androidx.navigation:navigation-runtime-ktx:${rootProject.ext.navVersion}"
392393
implementation("androidx.navigation:navigation-dynamic-features-fragment:${rootProject.ext.navVersion}")
393394

395+
394396
//https://developers.google.com/android/guides/setup
395397
implementation 'com.google.android.gms:play-services-base:18.0.1'
396398
implementation 'com.google.android.gms:play-services-auth:20.1.0'

FlowCrypt/src/androidTest/java/com/flowcrypt/email/base/BaseTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ abstract class BaseTest : BaseActivityTestImplementation {
7171
fun registerCountingIdlingResource() {
7272
activityScenario?.onActivity { activity ->
7373
val baseActivity = (activity as? BaseActivity) ?: return@onActivity
74-
countingIdlingResource = baseActivity.countingIdlingResource
74+
countingIdlingResource = countingIdlingResource
7575
countingIdlingResource?.let { IdlingRegistry.getInstance().register(it) }
7676
}
7777
}

FlowCrypt/src/main/java/com/flowcrypt/email/extensions/FragmentExt.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ package com.flowcrypt.email.extensions
77

88
import android.widget.Toast
99
import androidx.annotation.IdRes
10+
import androidx.appcompat.app.ActionBar
1011
import androidx.fragment.app.DialogFragment
1112
import androidx.lifecycle.Lifecycle
1213
import androidx.lifecycle.LifecycleEventObserver
1314
import androidx.navigation.NavController
1415
import androidx.navigation.Navigation
1516
import com.flowcrypt.email.NavGraphDirections
1617
import com.flowcrypt.email.R
18+
import com.flowcrypt.email.ui.activity.MainActivity
1719
import com.flowcrypt.email.ui.activity.fragment.FeedbackFragment
1820
import com.flowcrypt.email.ui.activity.fragment.dialog.FixNeedPassphraseIssueDialogFragment
1921
import com.flowcrypt.email.ui.activity.fragment.dialog.InfoDialogFragment
@@ -27,6 +29,12 @@ import com.flowcrypt.email.util.UIUtil
2729
* E-mail: DenBond7@gmail.com
2830
*/
2931

32+
val androidx.fragment.app.Fragment.mainActivity: MainActivity?
33+
get() = activity as? MainActivity
34+
35+
val androidx.fragment.app.Fragment.actionBar: ActionBar?
36+
get() = mainActivity?.supportActionBar
37+
3038
val androidx.fragment.app.Fragment.navController: NavController?
3139
get() = activity?.let {
3240
try {

FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/LauncherViewModel.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.app.Application
99
import androidx.lifecycle.viewModelScope
1010
import androidx.preference.PreferenceManager
1111
import com.flowcrypt.email.R
12+
import com.flowcrypt.email.database.entity.AccountEntity
1213
import com.flowcrypt.email.jetpack.workmanager.ForwardedAttachmentsDownloaderWorker
1314
import com.flowcrypt.email.jetpack.workmanager.MessagesSenderWorker
1415
import com.flowcrypt.email.service.FeedbackJobIntentService
@@ -28,8 +29,8 @@ import kotlinx.coroutines.launch
2829
* E-mail: DenBond7@gmail.com
2930
*/
3031
class LauncherViewModel(application: Application) : AccountViewModel(application) {
31-
private val isLoadingMutableStateFlow = MutableStateFlow(true)
32-
val isLoadingStateFlow = isLoadingMutableStateFlow.asStateFlow()
32+
private val isInitLoadingCompletedMutableStateFlow = MutableStateFlow<InitData?>(null)
33+
val isInitLoadingCompletedStateFlow = isInitLoadingCompletedMutableStateFlow.asStateFlow()
3334

3435
init {
3536
viewModelScope.launch {
@@ -43,7 +44,10 @@ class LauncherViewModel(application: Application) : AccountViewModel(application
4344
FeedbackJobIntentService.enqueueWork(application)
4445
FileAndDirectoryUtils.cleanDir(CacheManager.getCurrentMsgTempDir())
4546

46-
isLoadingMutableStateFlow.value = false
47+
isInitLoadingCompletedMutableStateFlow.value =
48+
InitData(roomDatabase.accountDao().getActiveAccountSuspend())
4749
}
4850
}
51+
52+
data class InitData(val accountEntity: AccountEntity?)
4953
}

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/MainActivity.kt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import androidx.activity.viewModels
1414
import androidx.appcompat.app.AppCompatActivity
1515
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
1616
import androidx.core.view.GravityCompat
17+
import androidx.drawerlayout.widget.DrawerLayout
18+
import androidx.lifecycle.Lifecycle
1719
import androidx.lifecycle.lifecycleScope
20+
import androidx.lifecycle.repeatOnLifecycle
1821
import androidx.navigation.NavController
1922
import androidx.navigation.NavDestination
2023
import androidx.navigation.NavGraph
@@ -24,6 +27,7 @@ import androidx.navigation.ui.NavigationUI
2427
import androidx.navigation.ui.navigateUp
2528
import androidx.work.WorkManager
2629
import com.flowcrypt.email.BuildConfig
30+
import com.flowcrypt.email.NavGraphDirections
2731
import com.flowcrypt.email.R
2832
import com.flowcrypt.email.api.email.FoldersManager
2933
import com.flowcrypt.email.api.email.JavaEmailConstants
@@ -67,7 +71,7 @@ class MainActivity : AppCompatActivity(), NavController.OnDestinationChangedList
6771
override fun onCreate(savedInstanceState: Bundle?) {
6872
installSplashScreen().apply {
6973
setKeepOnScreenCondition {
70-
launcherViewModel.isLoadingStateFlow.value
74+
launcherViewModel.isInitLoadingCompletedStateFlow.value == null
7175
}
7276
}
7377
super.onCreate(savedInstanceState)
@@ -76,6 +80,7 @@ class MainActivity : AppCompatActivity(), NavController.OnDestinationChangedList
7680
handleAccountAuthenticatorResponse()
7781
initAccountViewModel()
7882
setupLabelsViewModel()
83+
setupDefaultRouting(savedInstanceState)
7984
}
8085

8186
override fun onOptionsItemSelected(item: MenuItem): Boolean {
@@ -129,6 +134,12 @@ class MainActivity : AppCompatActivity(), NavController.OnDestinationChangedList
129134

130135
}
131136

137+
fun setDrawerLockMode(isLocked: Boolean) {
138+
binding.drawerLayout.setDrawerLockMode(
139+
if (isLocked) DrawerLayout.LOCK_MODE_LOCKED_CLOSED else DrawerLayout.LOCK_MODE_UNLOCKED
140+
)
141+
}
142+
132143
private fun initViews() {
133144
binding = ActivityMainBinding.inflate(layoutInflater)
134145
val view = binding.root
@@ -233,6 +244,27 @@ class MainActivity : AppCompatActivity(), NavController.OnDestinationChangedList
233244
}
234245
}
235246

247+
private fun setupDefaultRouting(savedInstanceState: Bundle?) {
248+
if (savedInstanceState == null) {
249+
lifecycleScope.launch {
250+
repeatOnLifecycle(Lifecycle.State.STARTED) {
251+
launcherViewModel.isInitLoadingCompletedStateFlow.collect { initData ->
252+
initData?.let {
253+
val startDestination = when {
254+
initData.accountEntity != null -> {
255+
NavGraphDirections.actionGlobalToEmailListFragment()
256+
}
257+
258+
else -> NavGraphDirections.actionGlobalToMainSignInFragment()
259+
}
260+
navController.navigate(startDestination)
261+
}
262+
}
263+
}
264+
}
265+
}
266+
}
267+
236268
private fun addOutboxLabel(foldersManager: FoldersManager, mailLabels: MenuItem?, label: String) {
237269
val menuItem = mailLabels?.subMenu?.getItem(mailLabels.subMenu.size() - 1) ?: return
238270

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/AttesterSettingsFragment.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class AttesterSettingsFragment : BaseFragment(), ListProgressBehaviour {
8080
it?.let {
8181
when (it.status) {
8282
Result.Status.LOADING -> {
83-
baseActivity.countingIdlingResource.incrementSafely()
83+
countingIdlingResource.incrementSafely()
8484
if (sRL?.isRefreshing != true || attesterKeyAdapter.itemCount == 0) {
8585
sRL?.isRefreshing = false
8686
showProgress()
@@ -97,12 +97,12 @@ class AttesterSettingsFragment : BaseFragment(), ListProgressBehaviour {
9797
showEmptyView()
9898
}
9999
}
100-
baseActivity.countingIdlingResource.decrementSafely()
100+
countingIdlingResource.decrementSafely()
101101
}
102102

103103
Result.Status.ERROR -> {
104104
sRL?.isRefreshing = false
105-
baseActivity.countingIdlingResource.decrementSafely()
105+
countingIdlingResource.decrementSafely()
106106
}
107107

108108
Result.Status.EXCEPTION -> {
@@ -121,7 +121,7 @@ class AttesterSettingsFragment : BaseFragment(), ListProgressBehaviour {
121121
accountPublicKeyServersViewModel.refreshData()
122122
}
123123

124-
baseActivity.countingIdlingResource.decrementSafely()
124+
countingIdlingResource.decrementSafely()
125125
}
126126
}
127127
}

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/AuthorizeAndSearchBackupsFragment.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,21 @@ class AuthorizeAndSearchBackupsFragment : BaseFragment(), ProgressBehaviour {
7777
it?.let {
7878
when (it.status) {
7979
Result.Status.LOADING -> {
80-
baseActivity.countingIdlingResource.incrementSafely()
80+
countingIdlingResource.incrementSafely()
8181
showProgress(it.progressMsg)
8282
}
8383

8484
Result.Status.SUCCESS -> {
8585
loadPrivateKeysViewModel.fetchAvailableKeys(args.account)
86-
baseActivity.countingIdlingResource.decrementSafely()
86+
countingIdlingResource.decrementSafely()
8787
}
8888

8989
else -> {
9090
setFragmentResult(
9191
REQUEST_KEY_CHECK_ACCOUNT_SETTINGS,
9292
bundleOf(KEY_CHECK_ACCOUNT_SETTINGS_RESULT to it)
9393
)
94-
baseActivity.countingIdlingResource.decrementSafely()
94+
countingIdlingResource.decrementSafely()
9595
navController?.navigateUp()
9696
}
9797
}
@@ -103,7 +103,7 @@ class AuthorizeAndSearchBackupsFragment : BaseFragment(), ProgressBehaviour {
103103
loadPrivateKeysViewModel.privateKeysLiveData.observe(viewLifecycleOwner) {
104104
when (it.status) {
105105
Result.Status.LOADING -> {
106-
baseActivity.countingIdlingResource.incrementSafely()
106+
countingIdlingResource.incrementSafely()
107107
showProgress(it.progressMsg)
108108
}
109109

@@ -112,7 +112,7 @@ class AuthorizeAndSearchBackupsFragment : BaseFragment(), ProgressBehaviour {
112112
REQUEST_KEY_SEARCH_BACKUPS,
113113
bundleOf(KEY_PRIVATE_KEY_BACKUPS_RESULT to it)
114114
)
115-
baseActivity.countingIdlingResource.decrementSafely()
115+
countingIdlingResource.decrementSafely()
116116
navController?.navigateUp()
117117
}
118118
}

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/BackupKeysFragment.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class BackupKeysFragment : BaseFragment(), ProgressBehaviour {
182182
it?.let {
183183
when (it.status) {
184184
Result.Status.LOADING -> {
185-
baseActivity.countingIdlingResource.incrementSafely()
185+
countingIdlingResource.incrementSafely()
186186
showProgress(getString(R.string.processing))
187187
areBackupsSavingNow = true
188188
}
@@ -197,7 +197,7 @@ class BackupKeysFragment : BaseFragment(), ProgressBehaviour {
197197
showContent()
198198
showInfoSnackbar(binding?.root, getString(R.string.error_occurred_please_try_again))
199199
}
200-
baseActivity.countingIdlingResource.decrementSafely()
200+
countingIdlingResource.decrementSafely()
201201
}
202202

203203
Result.Status.ERROR, Result.Status.EXCEPTION -> {
@@ -215,7 +215,7 @@ class BackupKeysFragment : BaseFragment(), ProgressBehaviour {
215215
)
216216
}
217217
privateKeysViewModel.saveBackupAsFileLiveData.value = Result.none()
218-
baseActivity.countingIdlingResource.decrementSafely()
218+
countingIdlingResource.decrementSafely()
219219
}
220220

221221
else -> {
@@ -229,7 +229,7 @@ class BackupKeysFragment : BaseFragment(), ProgressBehaviour {
229229
backupsViewModel.postBackupLiveData.observe(viewLifecycleOwner, {
230230
when (it.status) {
231231
Result.Status.LOADING -> {
232-
baseActivity.countingIdlingResource.incrementSafely()
232+
countingIdlingResource.incrementSafely()
233233
isPrivateKeySendingNow = true
234234
showProgress(getString(R.string.processing))
235235
}
@@ -238,7 +238,7 @@ class BackupKeysFragment : BaseFragment(), ProgressBehaviour {
238238
isPrivateKeySendingNow = false
239239
toast(R.string.backed_up_successfully)
240240
navController?.popBackStack(R.id.mainSettingsFragment, false)
241-
baseActivity.countingIdlingResource.decrementSafely()
241+
countingIdlingResource.decrementSafely()
242242
}
243243

244244
Result.Status.EXCEPTION -> {
@@ -250,7 +250,7 @@ class BackupKeysFragment : BaseFragment(), ProgressBehaviour {
250250
}
251251

252252
backupsViewModel.postBackupLiveData.value = Result.none()
253-
baseActivity.countingIdlingResource.decrementSafely()
253+
countingIdlingResource.decrementSafely()
254254
}
255255

256256
else -> {

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/ChangePassphraseOfImportedKeysFragment.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class ChangePassphraseOfImportedKeysFragment : BaseFragment(), ProgressBehaviour
104104
it?.let {
105105
when (it.status) {
106106
Result.Status.LOADING -> {
107-
baseActivity.countingIdlingResource.incrementSafely()
107+
countingIdlingResource.incrementSafely()
108108
isBackEnabled = false
109109
showProgress(getString(R.string.please_wait_while_pass_phrase_will_be_changed))
110110
}
@@ -115,9 +115,9 @@ class ChangePassphraseOfImportedKeysFragment : BaseFragment(), ProgressBehaviour
115115
//making backups is not allowed by OrgRules.
116116
isBackEnabled = true
117117
showContent()
118-
baseActivity.countingIdlingResource.decrementSafely()
118+
countingIdlingResource.decrementSafely()
119119
} else {
120-
baseActivity.countingIdlingResource.decrementSafely()
120+
countingIdlingResource.decrementSafely()
121121
loadPrivateKeysViewModel.fetchAvailableKeys(args.accountEntity)
122122
}
123123
}
@@ -135,7 +135,7 @@ class ChangePassphraseOfImportedKeysFragment : BaseFragment(), ProgressBehaviour
135135
Passphrase.fromPassword(args.passphrase)
136136
)
137137
}
138-
baseActivity.countingIdlingResource.decrementSafely()
138+
countingIdlingResource.decrementSafely()
139139
}
140140

141141
else -> {
@@ -148,19 +148,19 @@ class ChangePassphraseOfImportedKeysFragment : BaseFragment(), ProgressBehaviour
148148
it?.let {
149149
when (it.status) {
150150
Result.Status.LOADING -> {
151-
baseActivity.countingIdlingResource.incrementSafely()
151+
countingIdlingResource.incrementSafely()
152152
showProgress(getString(R.string.please_wait_while_backup_will_be_saved))
153153
}
154154

155155
Result.Status.SUCCESS -> {
156156
isBackEnabled = true
157157
showContent()
158-
baseActivity.countingIdlingResource.decrementSafely()
158+
countingIdlingResource.decrementSafely()
159159
}
160160

161161
Result.Status.ERROR, Result.Status.EXCEPTION -> {
162162
navigateToMakeBackupFragment()
163-
baseActivity.countingIdlingResource.decrementSafely()
163+
countingIdlingResource.decrementSafely()
164164
}
165165

166166
else -> {
@@ -176,14 +176,14 @@ class ChangePassphraseOfImportedKeysFragment : BaseFragment(), ProgressBehaviour
176176
when (it.status) {
177177
Result.Status.LOADING -> {
178178
if (it.progress == null) {
179-
baseActivity.countingIdlingResource.incrementSafely()
179+
countingIdlingResource.incrementSafely()
180180
}
181181
showProgress(getString(R.string.searching_backups))
182182
}
183183

184184
Result.Status.SUCCESS -> {
185185
val keyDetailsList = it.data
186-
baseActivity.countingIdlingResource.decrementSafely()
186+
countingIdlingResource.decrementSafely()
187187
if (keyDetailsList?.isEmpty() == true) {
188188
navigateToMakeBackupFragment()
189189
} else {
@@ -193,7 +193,7 @@ class ChangePassphraseOfImportedKeysFragment : BaseFragment(), ProgressBehaviour
193193

194194
Result.Status.ERROR, Result.Status.EXCEPTION -> {
195195
navigateToMakeBackupFragment()
196-
baseActivity.countingIdlingResource.decrementSafely()
196+
countingIdlingResource.decrementSafely()
197197
}
198198

199199
else -> {

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/CheckKeysFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class CheckKeysFragment : BaseFragment() {
184184
checkPrivateKeysViewModel.checkPrvKeysLiveData.observe(viewLifecycleOwner) {
185185
when (it.status) {
186186
Result.Status.LOADING -> {
187-
baseActivity.countingIdlingResource.incrementSafely()
187+
countingIdlingResource.incrementSafely()
188188
binding?.progressBar?.visibility = View.VISIBLE
189189
}
190190

@@ -248,7 +248,7 @@ class CheckKeysFragment : BaseFragment() {
248248
else -> {
249249
}
250250
}
251-
baseActivity.countingIdlingResource.decrementSafely()
251+
countingIdlingResource.decrementSafely()
252252
}
253253
}
254254
}

0 commit comments

Comments
 (0)