Drop support for android 4.x (#1232)

This commit is contained in:
Rafał Borcz
2021-04-03 11:56:07 +02:00
committed by GitHub
parent 0bdd33ef4a
commit 6cb4ea4b0f
31 changed files with 42 additions and 165 deletions

View File

@ -2,14 +2,12 @@ package io.github.wulkanowy
import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.util.Log.DEBUG
import android.util.Log.INFO
import android.util.Log.VERBOSE
import android.webkit.WebView
import androidx.fragment.app.FragmentManager
import androidx.hilt.work.HiltWorkerFactory
import androidx.multidex.MultiDex
import androidx.work.Configuration
import com.yariksoffice.lingver.Lingver
import dagger.hilt.android.HiltAndroidApp
@ -43,11 +41,6 @@ class WulkanowyApp : Application(), Configuration.Provider {
@Inject
lateinit var analyticsHelper: AnalyticsHelper
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
MultiDex.install(this)
}
@SuppressLint("UnsafeOptInUsageWarning")
override fun onCreate() {
super.onCreate()

View File

@ -15,6 +15,7 @@ class AppCreatorRepository @Inject constructor(
private val dispatchers: DispatchersProvider
) {
@Suppress("BlockingMethodInNonBlockingContext")
suspend fun getAppCreators() = withContext(dispatchers.backgroundThread) {
val moshi = Moshi.Builder().build()
val type = Types.newParameterizedType(List::class.java, Contributor::class.java)

View File

@ -2,7 +2,6 @@ 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
@ -151,10 +150,6 @@ class PreferencesRepository @Inject constructor(
R.string.pref_key_optional_arithmetic_average,
R.bool.pref_default_optional_arithmetic_average
)
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)

View File

@ -4,9 +4,6 @@ import android.content.Intent
import android.content.Intent.EXTRA_EMAIL
import android.content.Intent.EXTRA_STREAM
import android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION
import android.net.Uri
import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES.LOLLIPOP
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
@ -81,8 +78,7 @@ class LogViewerFragment : BaseFragment<FragmentLogviewerBinding>(R.layout.fragme
putExtra(EXTRA_EMAIL, arrayOf("wulkanowyinc@gmail.com"))
addFlags(FLAG_GRANT_READ_URI_PERMISSION)
putParcelableArrayListExtra(EXTRA_STREAM, ArrayList(files.map {
if (SDK_INT < LOLLIPOP) Uri.fromFile(it)
else FileProvider.getUriForFile(requireContext(), "$APPLICATION_ID.fileprovider", it)
FileProvider.getUriForFile(requireContext(), "$APPLICATION_ID.fileprovider", it)
}))
}

View File

@ -14,7 +14,7 @@ import timber.log.Timber
import javax.inject.Inject
class AccountEditPresenter @Inject constructor(
private val appInfo: AppInfo,
appInfo: AppInfo,
errorHandler: ErrorHandler,
studentRepository: StudentRepository
) : BasePresenter<AccountEditView>(errorHandler, studentRepository) {

View File

@ -5,15 +5,11 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import io.github.wulkanowy.data.db.entities.Grade
import io.github.wulkanowy.data.db.entities.GradeSummary
import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.repositories.PreferencesRepository
import io.github.wulkanowy.databinding.ItemGradeSummaryBinding
import io.github.wulkanowy.databinding.ScrollableHeaderGradeSummaryBinding
import io.github.wulkanowy.sdk.Sdk
import io.github.wulkanowy.utils.calcAverage
import io.github.wulkanowy.utils.changeModifier
import java.util.Locale
import javax.inject.Inject

View File

@ -8,7 +8,6 @@ import io.github.wulkanowy.data.db.entities.LuckyNumber
import io.github.wulkanowy.databinding.ItemLuckyNumberHistoryBinding
import io.github.wulkanowy.utils.toFormattedString
import io.github.wulkanowy.utils.weekDayName
import java.util.Locale
import javax.inject.Inject
class LuckyNumberHistoryAdapter @Inject constructor() :

View File

@ -15,7 +15,6 @@ import io.github.wulkanowy.ui.modules.main.MainView
import io.github.wulkanowy.ui.widgets.DividerItemDecoration
import io.github.wulkanowy.utils.SchooldaysRangeLimiter
import io.github.wulkanowy.utils.dpToPx
import io.github.wulkanowy.utils.getThemeAttrColor
import java.time.LocalDate
import javax.inject.Inject

View File

@ -9,8 +9,6 @@ import android.content.pm.ShortcutInfo
import android.content.pm.ShortcutManager
import android.graphics.drawable.Icon
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES.LOLLIPOP
import android.os.Build.VERSION_CODES.P
import android.os.Bundle
import android.view.Menu
@ -211,7 +209,7 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
@SuppressLint("NewApi")
override fun initView() {
with(binding.mainToolbar) {
if (SDK_INT >= LOLLIPOP) stateListAnimator = null
stateListAnimator = null
setBackgroundColor(
overlayProvider.compositeOverlayWithThemeSurfaceColorIfNeeded(dpToPx(4f))
)

View File

@ -24,7 +24,7 @@ class MainPresenter @Inject constructor(
private val analytics: AnalyticsHelper,
) : BasePresenter<MainView>(errorHandler, studentRepository) {
var studentsWitSemesters: List<StudentWithSemesters>? = null
private var studentsWitSemesters: List<StudentWithSemesters>? = null
fun onAttachView(view: MainView, initMenu: MainView.Section?) {
super.onAttachView(view)

View File

@ -8,7 +8,6 @@ import dagger.hilt.android.AndroidEntryPoint
import io.github.wulkanowy.R
import io.github.wulkanowy.databinding.FragmentMoreBinding
import io.github.wulkanowy.ui.base.BaseFragment
import io.github.wulkanowy.ui.modules.about.AboutFragment
import io.github.wulkanowy.ui.modules.conference.ConferenceFragment
import io.github.wulkanowy.ui.modules.homework.HomeworkFragment
import io.github.wulkanowy.ui.modules.luckynumber.LuckyNumberFragment

View File

@ -2,4 +2,4 @@ package io.github.wulkanowy.ui.modules.settings.advanced
import io.github.wulkanowy.ui.base.BaseView
interface AdvancedView : BaseView {}
interface AdvancedView : BaseView

View File

@ -3,10 +3,8 @@ 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
@ -46,14 +44,4 @@ 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()
}
}

View File

@ -1,12 +1,9 @@
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
@ -15,26 +12,13 @@ import javax.inject.Inject
class SplashPresenter @Inject constructor(
errorHandler: ErrorHandler,
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()) {
view?.openExternalUrlAndFinish(externalUrl!!)
view.openExternalUrlAndFinish(externalUrl)
return
}
@ -42,19 +26,11 @@ class SplashPresenter @Inject constructor(
when (it.status) {
Status.LOADING -> Timber.d("Is current user set check started")
Status.SUCCESS -> {
if (it.data!!) view?.openMainView()
else view?.openLoginView()
if (it.data!!) view.openMainView()
else view.openLoginView()
}
Status.ERROR -> errorHandler.dispatch(it.error!!)
}
}.launch()
}
fun onKitkatViewDismissed() {
loadCorrectDataOrUser()
}
fun onNeutralButtonSelected() {
preferencesRepository.isKitkatDialogDisabled = true
}
}

View File

@ -9,6 +9,4 @@ interface SplashView : BaseView {
fun openMainView()
fun openExternalUrlAndFinish(url: String)
fun showKitkatView()
}

View File

@ -113,7 +113,7 @@ class TimetableWidgetFactory(
}
} catch (e: Exception) {
Timber.e(e, "An error has occurred in timetable widget factory")
emptyList<Timetable>()
emptyList()
}
@SuppressLint("DefaultLocale")

View File

@ -230,7 +230,7 @@ class TimetableWidgetProvider : HiltBroadcastReceiver() {
private suspend fun getStudent(studentId: Long, appWidgetId: Int) = try {
val students = studentRepository.getSavedStudents(false)
val student = students.singleOrNull { it -> it.student.id == studentId }?.student
val student = students.singleOrNull { it.student.id == studentId }?.student
when {
student != null -> student
studentId != 0L && studentRepository.isCurrentStudentSet() -> {

View File

@ -58,10 +58,6 @@ private val cipher: Cipher
fun encrypt(plainText: String, context: Context): String {
if (plainText.isEmpty()) throw ScramblerException("Text to be encrypted is empty")
if (SDK_INT < JELLY_BEAN_MR2) {
return String(encode(plainText.toByteArray(KEY_CHARSET), DEFAULT), KEY_CHARSET)
}
return try {
if (!isKeyPairExists) generateKeyPair(context)
@ -90,10 +86,6 @@ fun decrypt(cipherText: String): String {
if (cipherText.isEmpty()) throw ScramblerException("Text to be encrypted is empty")
return try {
if (SDK_INT < JELLY_BEAN_MR2 || cipherText.length < 250) {
return String(decode(cipherText.toByteArray(KEY_CHARSET), DEFAULT), KEY_CHARSET)
}
if (!isKeyPairExists) throw ScramblerException("KeyPair doesn't exist")
cipher.let {