mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-31 21:42:44 +01:00
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.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import androidx.core.content.edit
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import io.github.wulkanowy.R
|
import io.github.wulkanowy.R
|
||||||
import io.github.wulkanowy.ui.modules.grade.GradeAverageMode
|
import io.github.wulkanowy.ui.modules.grade.GradeAverageMode
|
||||||
@ -145,6 +146,10 @@ class PreferencesRepository @Inject constructor(
|
|||||||
R.bool.pref_default_subjects_without_grades
|
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: Int, default: Int) = getString(context.getString(id), default)
|
||||||
|
|
||||||
private fun getString(id: String, default: Int) =
|
private fun getString(id: String, default: Int) =
|
||||||
|
@ -3,17 +3,23 @@ package io.github.wulkanowy.ui.modules.splash
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import android.widget.Toast.LENGTH_LONG
|
import android.widget.Toast.LENGTH_LONG
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import io.github.wulkanowy.R
|
||||||
import io.github.wulkanowy.ui.base.BaseActivity
|
import io.github.wulkanowy.ui.base.BaseActivity
|
||||||
import io.github.wulkanowy.ui.modules.login.LoginActivity
|
import io.github.wulkanowy.ui.modules.login.LoginActivity
|
||||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||||
|
import io.github.wulkanowy.utils.AppInfo
|
||||||
import io.github.wulkanowy.utils.openInternetBrowser
|
import io.github.wulkanowy.utils.openInternetBrowser
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class SplashActivity : BaseActivity<SplashPresenter, ViewBinding>(), SplashView {
|
class SplashActivity : BaseActivity<SplashPresenter, ViewBinding>(), SplashView {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var appInfo: AppInfo
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
override lateinit var presenter: SplashPresenter
|
override lateinit var presenter: SplashPresenter
|
||||||
|
|
||||||
@ -40,4 +46,14 @@ class SplashActivity : BaseActivity<SplashPresenter, ViewBinding>(), SplashView
|
|||||||
override fun showError(text: String, error: Throwable) {
|
override fun showError(text: String, error: Throwable) {
|
||||||
Toast.makeText(this, text, LENGTH_LONG).show()
|
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
|
package io.github.wulkanowy.ui.modules.splash
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import io.github.wulkanowy.data.Status
|
import io.github.wulkanowy.data.Status
|
||||||
|
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||||
import io.github.wulkanowy.ui.base.BasePresenter
|
import io.github.wulkanowy.ui.base.BasePresenter
|
||||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||||
|
import io.github.wulkanowy.utils.AppInfo
|
||||||
import io.github.wulkanowy.utils.flowWithResource
|
import io.github.wulkanowy.utils.flowWithResource
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@ -11,25 +14,47 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class SplashPresenter @Inject constructor(
|
class SplashPresenter @Inject constructor(
|
||||||
errorHandler: ErrorHandler,
|
errorHandler: ErrorHandler,
|
||||||
studentRepository: StudentRepository
|
studentRepository: StudentRepository,
|
||||||
|
private val preferencesRepository: PreferencesRepository,
|
||||||
|
private val appInfo: AppInfo
|
||||||
) : BasePresenter<SplashView>(errorHandler, studentRepository) {
|
) : BasePresenter<SplashView>(errorHandler, studentRepository) {
|
||||||
|
|
||||||
|
private var externalUrl: String? = null
|
||||||
|
|
||||||
fun onAttachView(view: SplashView, externalUrl: String?) {
|
fun onAttachView(view: SplashView, externalUrl: String?) {
|
||||||
super.onAttachView(view)
|
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()) {
|
if (!externalUrl.isNullOrBlank()) {
|
||||||
return view.openExternalUrlAndFinish(externalUrl)
|
view?.openExternalUrlAndFinish(externalUrl!!)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
flowWithResource { studentRepository.isCurrentStudentSet() }.onEach {
|
flowWithResource { studentRepository.isCurrentStudentSet() }.onEach {
|
||||||
when (it.status) {
|
when (it.status) {
|
||||||
Status.LOADING -> Timber.d("Is current user set check started")
|
Status.LOADING -> Timber.d("Is current user set check started")
|
||||||
Status.SUCCESS -> with(view) {
|
Status.SUCCESS -> {
|
||||||
if (it.data!!) openMainView()
|
if (it.data!!) view?.openMainView()
|
||||||
else openLoginView()
|
else view?.openLoginView()
|
||||||
}
|
}
|
||||||
Status.ERROR -> errorHandler.dispatch(it.error!!)
|
Status.ERROR -> errorHandler.dispatch(it.error!!)
|
||||||
}
|
}
|
||||||
}.launch()
|
}.launch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onKitkatViewDismissed() {
|
||||||
|
loadCorrectDataOrUser()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onNeutralButtonSelected() {
|
||||||
|
preferencesRepository.isKitkatDialogDisabled = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,4 +9,6 @@ interface SplashView : BaseView {
|
|||||||
fun openMainView()
|
fun openMainView()
|
||||||
|
|
||||||
fun openExternalUrlAndFinish(url: String)
|
fun openExternalUrlAndFinish(url: String)
|
||||||
|
|
||||||
|
fun showKitkatView()
|
||||||
}
|
}
|
||||||
|
@ -541,6 +541,12 @@
|
|||||||
<string name="channel_debug">Debug</string>
|
<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-->
|
<!--Colors-->
|
||||||
<string name="all_black">Black</string>
|
<string name="all_black">Black</string>
|
||||||
<string name="all_red">Red</string>
|
<string name="all_red">Red</string>
|
||||||
@ -554,6 +560,7 @@
|
|||||||
<string name="all_copied">Copied</string>
|
<string name="all_copied">Copied</string>
|
||||||
<string name="all_undo">Undo</string>
|
<string name="all_undo">Undo</string>
|
||||||
|
|
||||||
|
|
||||||
<!--Update helper-->
|
<!--Update helper-->
|
||||||
<string name="update_download_started">Download of updates has started…</string>
|
<string name="update_download_started">Download of updates has started…</string>
|
||||||
<string name="update_download_success">An update has just been downloaded.</string>
|
<string name="update_download_success">An update has just been downloaded.</string>
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package io.github.wulkanowy.ui.modules.splash
|
package io.github.wulkanowy.ui.modules.splash
|
||||||
|
|
||||||
import io.github.wulkanowy.MainCoroutineRule
|
import io.github.wulkanowy.MainCoroutineRule
|
||||||
|
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||||
|
import io.github.wulkanowy.utils.AppInfo
|
||||||
import io.mockk.MockKAnnotations
|
import io.mockk.MockKAnnotations
|
||||||
import io.mockk.coEvery
|
import io.mockk.coEvery
|
||||||
|
import io.mockk.every
|
||||||
import io.mockk.impl.annotations.MockK
|
import io.mockk.impl.annotations.MockK
|
||||||
import io.mockk.verify
|
import io.mockk.verify
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
@ -22,6 +25,12 @@ class SplashPresenterTest {
|
|||||||
@MockK
|
@MockK
|
||||||
lateinit var studentRepository: StudentRepository
|
lateinit var studentRepository: StudentRepository
|
||||||
|
|
||||||
|
@MockK
|
||||||
|
lateinit var preferencesRepository: PreferencesRepository
|
||||||
|
|
||||||
|
@MockK
|
||||||
|
lateinit var appInfo: AppInfo
|
||||||
|
|
||||||
@MockK(relaxed = true)
|
@MockK(relaxed = true)
|
||||||
lateinit var errorHandler: ErrorHandler
|
lateinit var errorHandler: ErrorHandler
|
||||||
|
|
||||||
@ -30,19 +39,25 @@ class SplashPresenterTest {
|
|||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
MockKAnnotations.init(this)
|
MockKAnnotations.init(this)
|
||||||
presenter = SplashPresenter(errorHandler, studentRepository)
|
presenter = SplashPresenter(errorHandler, studentRepository, preferencesRepository, appInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testOpenLoginView() {
|
fun testOpenLoginView() {
|
||||||
|
every { appInfo.systemVersion } returns 30
|
||||||
|
every { preferencesRepository.isKitkatDialogDisabled } returns true
|
||||||
coEvery { studentRepository.isCurrentStudentSet() } returns false
|
coEvery { studentRepository.isCurrentStudentSet() } returns false
|
||||||
|
|
||||||
presenter.onAttachView(splashView, null)
|
presenter.onAttachView(splashView, null)
|
||||||
verify { splashView.openLoginView() }
|
verify { splashView.openLoginView() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testMainMainView() {
|
fun testMainMainView() {
|
||||||
|
every { appInfo.systemVersion } returns 30
|
||||||
|
every { preferencesRepository.isKitkatDialogDisabled } returns true
|
||||||
coEvery { studentRepository.isCurrentStudentSet() } returns true
|
coEvery { studentRepository.isCurrentStudentSet() } returns true
|
||||||
|
|
||||||
presenter.onAttachView(splashView, null)
|
presenter.onAttachView(splashView, null)
|
||||||
verify { splashView.openMainView() }
|
verify { splashView.openMainView() }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user