mirror of
https://github.com/bitfireAT/davx5-ose
synced 2024-07-23 11:39:15 +00:00
Make all IntroFragments appear at first start (#452)
* IntroFragments: use (factory,order) List instead of (order,factory) Map to store them * Adapt OpenSourceFragment order
This commit is contained in:
parent
8ffed42eb9
commit
58d4a9f663
|
@ -54,11 +54,10 @@ class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSele
|
|||
super.onCreate(savedInstanceState)
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
// use a separate thread to check whether IntroActivity should be shown
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
// use a separate thread to check whether IntroActivity should be shown
|
||||
if (IntroActivity.shouldShowIntroActivity(this@AccountsActivity)) {
|
||||
if (IntroActivity.shouldShowIntroActivity(this@AccountsActivity))
|
||||
introActivityLauncher.launch(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -210,4 +210,4 @@ class BatteryOptimizationsFragment: Fragment() {
|
|||
override fun create() = BatteryOptimizationsFragment()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ import android.content.Intent
|
|||
import android.os.Bundle
|
||||
import androidx.activity.result.contract.ActivityResultContract
|
||||
import androidx.activity.addCallback
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import at.bitfire.davdroid.R
|
||||
|
@ -33,12 +34,11 @@ class IntroActivity: AppIntro2() {
|
|||
|
||||
companion object {
|
||||
|
||||
@WorkerThread
|
||||
fun shouldShowIntroActivity(activity: Activity): Boolean {
|
||||
val factories = EntryPointAccessors.fromActivity(activity, IntroActivityEntryPoint::class.java).introFragmentFactories()
|
||||
return factories.any {
|
||||
val order = it.getOrder(activity)
|
||||
Logger.log.fine("Found intro fragment factory ${it::class.java} with order $order")
|
||||
order > 0
|
||||
it.getOrder(activity) > 0
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,19 +46,24 @@ class IntroActivity: AppIntro2() {
|
|||
|
||||
private var currentSlide = 0
|
||||
|
||||
@Inject lateinit var introFragmentFactories: Set<@JvmSuppressWildcards IntroFragmentFactory>
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val factoriesWithOrder = introFragmentFactories
|
||||
.associateBy { it.getOrder(this) }
|
||||
.filterKeys { it != IntroFragmentFactory.DONT_SHOW }
|
||||
val factories = EntryPointAccessors.fromActivity(this, IntroActivityEntryPoint::class.java).introFragmentFactories()
|
||||
for (factory in factories)
|
||||
Logger.log.fine("Found intro fragment factory ${factory::class.java} with order ${factory.getOrder(this)}")
|
||||
|
||||
val anyPositiveOrder = factoriesWithOrder.keys.any { it > 0 }
|
||||
val factoriesWithOrder = factories
|
||||
.associateWith { it.getOrder(this) }
|
||||
.filterValues { it != IntroFragmentFactory.DONT_SHOW }
|
||||
|
||||
val anyPositiveOrder = factoriesWithOrder.values.any { it > 0 }
|
||||
if (anyPositiveOrder) {
|
||||
for ((_, factory) in factoriesWithOrder.toSortedMap())
|
||||
val factoriesSortedByOrder = factoriesWithOrder
|
||||
.toList()
|
||||
.sortedBy { (_, v) -> v } // sort by value (= getOrder())
|
||||
for ((factory, _) in factoriesSortedByOrder)
|
||||
addSlide(factory.create())
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ interface IntroFragmentFactory {
|
|||
* @return Order with which an instance of this fragment type shall be created and shown. Possible values:
|
||||
*
|
||||
* * <0: only show the fragment when there is at least one other fragment with positive order (lower numbers are shown first)
|
||||
* * 0: don't show the fragment
|
||||
* * [DONT_SHOW] (0): don't show the fragment
|
||||
* * ≥0: show the fragment (lower numbers are shown first)
|
||||
*/
|
||||
fun getOrder(context: Context): Int
|
||||
|
|
|
@ -21,7 +21,6 @@ import at.bitfire.davdroid.ui.UiUtils
|
|||
import at.bitfire.davdroid.ui.intro.OpenSourceFragment.Model.Companion.SETTING_NEXT_DONATION_POPUP
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
|
@ -48,7 +47,6 @@ class OpenSourceFragment: Fragment() {
|
|||
|
||||
@HiltViewModel
|
||||
class Model @Inject constructor(
|
||||
@ApplicationContext val context: Context,
|
||||
val settings: SettingsManager
|
||||
): ViewModel() {
|
||||
|
||||
|
@ -76,7 +74,7 @@ class OpenSourceFragment: Fragment() {
|
|||
|
||||
override fun getOrder(context: Context) =
|
||||
if (System.currentTimeMillis() > (settingsManager.getLongOrNull(SETTING_NEXT_DONATION_POPUP) ?: 0))
|
||||
100
|
||||
500
|
||||
else
|
||||
0
|
||||
|
||||
|
|
Loading…
Reference in a new issue