forked from github/wulkanowy-mirror
Add dialog with info about dropping support for android 4 (#1221)
This commit is contained in:
parent
1560335749
commit
efafd2094a
@ -2,6 +2,7 @@ package io.github.wulkanowy.data.repositories
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeAverageMode
|
||||
@ -145,6 +146,10 @@ class PreferencesRepository @Inject constructor(
|
||||
R.bool.pref_default_subjects_without_grades
|
||||
)
|
||||
|
||||
var isKitkatDialogDisabled: Boolean
|
||||
get() = sharedPref.getBoolean("kitkat_dialog_disabled", false)
|
||||
set(value) = sharedPref.edit { putBoolean("kitkat_dialog_disabled", value) }
|
||||
|
||||
private fun getString(id: Int, default: Int) = getString(context.getString(id), default)
|
||||
|
||||
private fun getString(id: String, default: Int) =
|
||||
|
@ -3,17 +3,23 @@ package io.github.wulkanowy.ui.modules.splash
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import android.widget.Toast.LENGTH_LONG
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.base.BaseActivity
|
||||
import io.github.wulkanowy.ui.modules.login.LoginActivity
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.openInternetBrowser
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class SplashActivity : BaseActivity<SplashPresenter, ViewBinding>(), SplashView {
|
||||
|
||||
@Inject
|
||||
lateinit var appInfo: AppInfo
|
||||
|
||||
@Inject
|
||||
override lateinit var presenter: SplashPresenter
|
||||
|
||||
@ -40,4 +46,14 @@ class SplashActivity : BaseActivity<SplashPresenter, ViewBinding>(), SplashView
|
||||
override fun showError(text: String, error: Throwable) {
|
||||
Toast.makeText(this, text, LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
override fun showKitkatView() {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.drop_kitkat_title)
|
||||
.setMessage(R.string.drop_kitkat_content)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.setNeutralButton(R.string.drop_kitkat_again) { _, _ -> presenter.onNeutralButtonSelected() }
|
||||
.setOnDismissListener { presenter.onKitkatViewDismissed() }
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package io.github.wulkanowy.ui.modules.splash
|
||||
|
||||
import android.os.Build
|
||||
import io.github.wulkanowy.data.Status
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.flowWithResource
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import timber.log.Timber
|
||||
@ -11,25 +14,47 @@ import javax.inject.Inject
|
||||
|
||||
class SplashPresenter @Inject constructor(
|
||||
errorHandler: ErrorHandler,
|
||||
studentRepository: StudentRepository
|
||||
studentRepository: StudentRepository,
|
||||
private val preferencesRepository: PreferencesRepository,
|
||||
private val appInfo: AppInfo
|
||||
) : BasePresenter<SplashView>(errorHandler, studentRepository) {
|
||||
|
||||
private var externalUrl: String? = null
|
||||
|
||||
fun onAttachView(view: SplashView, externalUrl: String?) {
|
||||
super.onAttachView(view)
|
||||
this.externalUrl = externalUrl
|
||||
|
||||
if (appInfo.systemVersion < Build.VERSION_CODES.LOLLIPOP && !preferencesRepository.isKitkatDialogDisabled) {
|
||||
view.showKitkatView()
|
||||
} else {
|
||||
loadCorrectDataOrUser()
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadCorrectDataOrUser() {
|
||||
if (!externalUrl.isNullOrBlank()) {
|
||||
return view.openExternalUrlAndFinish(externalUrl)
|
||||
view?.openExternalUrlAndFinish(externalUrl!!)
|
||||
return
|
||||
}
|
||||
|
||||
flowWithResource { studentRepository.isCurrentStudentSet() }.onEach {
|
||||
when (it.status) {
|
||||
Status.LOADING -> Timber.d("Is current user set check started")
|
||||
Status.SUCCESS -> with(view) {
|
||||
if (it.data!!) openMainView()
|
||||
else openLoginView()
|
||||
Status.SUCCESS -> {
|
||||
if (it.data!!) view?.openMainView()
|
||||
else view?.openLoginView()
|
||||
}
|
||||
Status.ERROR -> errorHandler.dispatch(it.error!!)
|
||||
}
|
||||
}.launch()
|
||||
}
|
||||
|
||||
fun onKitkatViewDismissed() {
|
||||
loadCorrectDataOrUser()
|
||||
}
|
||||
|
||||
fun onNeutralButtonSelected() {
|
||||
preferencesRepository.isKitkatDialogDisabled = true
|
||||
}
|
||||
}
|
||||
|
@ -9,4 +9,6 @@ interface SplashView : BaseView {
|
||||
fun openMainView()
|
||||
|
||||
fun openExternalUrlAndFinish(url: String)
|
||||
|
||||
fun showKitkatView()
|
||||
}
|
||||
|
@ -541,6 +541,12 @@
|
||||
<string name="channel_debug">Debug</string>
|
||||
|
||||
|
||||
<!--Drop kitkat alert dialog strings-->
|
||||
<string name="drop_kitkat_title">End of support</string>
|
||||
<string name="drop_kitkat_content">We are ending support for your device. No more new features will appear for it in Wulkanowy. However, we will be releasing critical patches until the end of 2021 so you have time to switch to a newer model</string>
|
||||
<string name="drop_kitkat_again">Don\'t show again</string>
|
||||
|
||||
|
||||
<!--Colors-->
|
||||
<string name="all_black">Black</string>
|
||||
<string name="all_red">Red</string>
|
||||
@ -554,6 +560,7 @@
|
||||
<string name="all_copied">Copied</string>
|
||||
<string name="all_undo">Undo</string>
|
||||
|
||||
|
||||
<!--Update helper-->
|
||||
<string name="update_download_started">Download of updates has started…</string>
|
||||
<string name="update_download_success">An update has just been downloaded.</string>
|
||||
|
@ -1,10 +1,13 @@
|
||||
package io.github.wulkanowy.ui.modules.splash
|
||||
|
||||
import io.github.wulkanowy.MainCoroutineRule
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.verify
|
||||
import org.junit.Before
|
||||
@ -22,6 +25,12 @@ class SplashPresenterTest {
|
||||
@MockK
|
||||
lateinit var studentRepository: StudentRepository
|
||||
|
||||
@MockK
|
||||
lateinit var preferencesRepository: PreferencesRepository
|
||||
|
||||
@MockK
|
||||
lateinit var appInfo: AppInfo
|
||||
|
||||
@MockK(relaxed = true)
|
||||
lateinit var errorHandler: ErrorHandler
|
||||
|
||||
@ -30,19 +39,25 @@ class SplashPresenterTest {
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockKAnnotations.init(this)
|
||||
presenter = SplashPresenter(errorHandler, studentRepository)
|
||||
presenter = SplashPresenter(errorHandler, studentRepository, preferencesRepository, appInfo)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOpenLoginView() {
|
||||
every { appInfo.systemVersion } returns 30
|
||||
every { preferencesRepository.isKitkatDialogDisabled } returns true
|
||||
coEvery { studentRepository.isCurrentStudentSet() } returns false
|
||||
|
||||
presenter.onAttachView(splashView, null)
|
||||
verify { splashView.openLoginView() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMainMainView() {
|
||||
every { appInfo.systemVersion } returns 30
|
||||
every { preferencesRepository.isKitkatDialogDisabled } returns true
|
||||
coEvery { studentRepository.isCurrentStudentSet() } returns true
|
||||
|
||||
presenter.onAttachView(splashView, null)
|
||||
verify { splashView.openMainView() }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user