forked from github/wulkanowy-mirror
Add dialog with info about dropping support for android 4 (#1221)
This commit is contained in:
@ -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()
|
||||
}
|
||||
|
Reference in New Issue
Block a user