Compare commits
73 Commits
Author | SHA1 | Date | |
---|---|---|---|
1fe464a289 | |||
497acf9d68 | |||
976eb5a772 | |||
9ececeb4e9 | |||
096fe359e7 | |||
a98e8398fd | |||
d8c4926a97 | |||
17c139b559 | |||
ddbcc7a04c | |||
9f9eb60280 | |||
f893170dec | |||
cff08d6322 | |||
9dee7f01f6 | |||
8324a9cac3 | |||
5316e3e1bf | |||
81e80181f2 | |||
6ee38e9259 | |||
40df80371c | |||
a3596c35b8 | |||
66b7ea4cb4 | |||
770749e158 | |||
0aa83b020e | |||
4d1218d1d3 | |||
0ea6cbc8ed | |||
eb31f9578f | |||
f69d50d2c1 | |||
8a424ee6a4 | |||
7dfa48bbe3 | |||
d811cdb919 | |||
e2f2e21081 | |||
c812310497 | |||
7f6475cf35 | |||
a2a7d2ebb2 | |||
a5bc45c5da | |||
5646befbd7 | |||
75f496b5d2 | |||
23d989d22a | |||
9e013f7cd9 | |||
c63a7c03f1 | |||
5ceee84f0e | |||
7f4539fd27 | |||
71ebf1260b | |||
784ee58384 | |||
eceef3f582 | |||
0d950fbd86 | |||
003d63b516 | |||
b4c0440a8e | |||
137c305295 | |||
2c40c221c3 | |||
e82ac78d4a | |||
59d46ce956 | |||
17caa8ecbd | |||
e9540b4012 | |||
643ad60455 | |||
01f892ce5c | |||
f61b6a5e78 | |||
650cf7484e | |||
037cbb0b19 | |||
e49835e89e | |||
c64be2fab0 | |||
ce9cb35172 | |||
7fa9219c7b | |||
1fe1618220 | |||
d9bab2af78 | |||
06b6d88dd1 | |||
3bf27baed5 | |||
6802d74002 | |||
3fd2683df7 | |||
b708c70ea2 | |||
aba08e6aa9 | |||
124b6dfd79 | |||
1dbaa8bfdc | |||
25ac171298 |
10
.idea/migrations.xml
generated
Normal file
10
.idea/migrations.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectMigrations">
|
||||
<option name="MigrateToGradleLocalJavaHome">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -27,8 +27,8 @@ android {
|
||||
testApplicationId "io.github.tests.wulkanowy"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 34
|
||||
versionCode 135
|
||||
versionName "2.2.3"
|
||||
versionCode 144
|
||||
versionName "2.3.4"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
resValue "string", "app_name", "Wulkanowy"
|
||||
@ -113,6 +113,7 @@ android {
|
||||
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
buildConfig true
|
||||
}
|
||||
|
||||
bundle {
|
||||
@ -161,8 +162,8 @@ play {
|
||||
defaultToAppBundles = false
|
||||
track = 'production'
|
||||
releaseStatus = ReleaseStatus.IN_PROGRESS
|
||||
userFraction = 0.01d
|
||||
updatePriority = 3
|
||||
userFraction = 0.99d
|
||||
updatePriority = 1
|
||||
enabled.set(false)
|
||||
}
|
||||
|
||||
@ -183,28 +184,28 @@ huaweiPublish {
|
||||
}
|
||||
|
||||
ext {
|
||||
work_manager = "2.8.1"
|
||||
android_hilt = "1.0.0"
|
||||
room = "2.6.0"
|
||||
chucker = "3.5.2"
|
||||
mockk = "1.13.8"
|
||||
work_manager = "2.9.0"
|
||||
android_hilt = "1.1.0"
|
||||
room = "2.6.1"
|
||||
chucker = "4.0.0"
|
||||
mockk = "1.13.9"
|
||||
coroutines = "1.7.3"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'io.github.wulkanowy:sdk:2.2.3'
|
||||
implementation 'io.github.wulkanowy:sdk:2.3.6'
|
||||
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
|
||||
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines"
|
||||
|
||||
implementation 'androidx.core:core-ktx:1.12.0'
|
||||
implementation 'androidx.core:core-splashscreen:1.0.1'
|
||||
implementation "androidx.activity:activity-ktx:1.8.0"
|
||||
implementation "androidx.activity:activity-ktx:1.8.2"
|
||||
implementation "androidx.appcompat:appcompat:1.6.1"
|
||||
implementation "androidx.fragment:fragment-ktx:1.6.1"
|
||||
implementation "androidx.annotation:annotation:1.7.0"
|
||||
implementation "androidx.fragment:fragment-ktx:1.6.2"
|
||||
implementation "androidx.annotation:annotation:1.7.1"
|
||||
|
||||
implementation "androidx.preference:preference-ktx:1.2.1"
|
||||
implementation "androidx.recyclerview:recyclerview:1.3.2"
|
||||
@ -217,7 +218,7 @@ dependencies {
|
||||
implementation "com.github.PhilJay:MPAndroidChart:v3.1.0"
|
||||
implementation 'com.github.lopspower:CircularImageView:4.3.0'
|
||||
|
||||
implementation "androidx.work:work-runtime-ktx:$work_manager"
|
||||
implementation "androidx.work:work-runtime:$work_manager"
|
||||
playImplementation "androidx.work:work-gcm:$work_manager"
|
||||
|
||||
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.6.2"
|
||||
@ -237,33 +238,36 @@ dependencies {
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
|
||||
implementation "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0"
|
||||
implementation "com.squareup.okhttp3:logging-interceptor:4.12.0"
|
||||
implementation "com.squareup.okhttp3:okhttp-urlconnection:4.12.0"
|
||||
|
||||
implementation "com.jakewharton.timber:timber:5.0.1"
|
||||
implementation "at.favre.lib:slf4j-timber:1.0.1"
|
||||
implementation 'com.github.Faierbel:slf4j-timber:2.0'
|
||||
implementation 'com.github.bastienpaulfr:Treessence:1.1.2'
|
||||
implementation "com.mikepenz:aboutlibraries-core:$about_libraries"
|
||||
implementation "io.coil-kt:coil:2.4.0"
|
||||
implementation 'io.coil-kt:coil:2.5.0'
|
||||
implementation "io.github.wulkanowy:AppKillerManager:3.0.1"
|
||||
implementation 'me.xdrop:fuzzywuzzy:1.4.0'
|
||||
implementation 'com.fredporciuncula:flow-preferences:1.9.1'
|
||||
implementation 'org.apache.commons:commons-text:1.10.0'
|
||||
implementation 'org.apache.commons:commons-text:1.11.0'
|
||||
|
||||
playImplementation platform('com.google.firebase:firebase-bom:32.4.0')
|
||||
playImplementation 'com.google.firebase:firebase-analytics-ktx'
|
||||
playImplementation 'com.google.firebase:firebase-messaging:'
|
||||
playImplementation platform('com.google.firebase:firebase-bom:32.7.0')
|
||||
playImplementation 'com.google.firebase:firebase-analytics'
|
||||
playImplementation 'com.google.firebase:firebase-messaging'
|
||||
playImplementation 'com.google.firebase:firebase-crashlytics:'
|
||||
playImplementation 'com.google.firebase:firebase-config-ktx'
|
||||
playImplementation 'com.google.android.play:core:1.10.3'
|
||||
playImplementation 'com.google.android.play:core-ktx:1.8.1'
|
||||
playImplementation 'com.google.android.gms:play-services-ads:22.4.0'
|
||||
playImplementation "com.google.android.play:integrity:1.2.0"
|
||||
playImplementation 'com.google.firebase:firebase-config'
|
||||
|
||||
playImplementation 'com.google.android.gms:play-services-ads:22.6.0'
|
||||
playImplementation "com.google.android.play:integrity:1.3.0"
|
||||
playImplementation 'com.google.android.play:app-update-ktx:2.1.0'
|
||||
playImplementation 'com.google.android.play:review-ktx:2.0.1'
|
||||
playImplementation "com.google.android.ump:user-messaging-platform:2.1.0"
|
||||
|
||||
hmsImplementation 'com.huawei.hms:hianalytics:6.12.0.300'
|
||||
hmsImplementation 'com.huawei.agconnect:agconnect-crash:1.9.1.301'
|
||||
hmsImplementation 'com.huawei.agconnect:agconnect-crash:1.9.1.303'
|
||||
|
||||
releaseImplementation "com.github.ChuckerTeam.Chucker:library-no-op:$chucker"
|
||||
releaseImplementation "com.github.chuckerteam.chucker:library-no-op:$chucker"
|
||||
|
||||
debugImplementation "com.github.ChuckerTeam.Chucker:library:$chucker"
|
||||
debugImplementation "com.github.chuckerteam.chucker:library:$chucker"
|
||||
debugImplementation 'com.github.amitshekhariitbhu.Android-Debug-Database:debug-db:1.0.6'
|
||||
debugImplementation 'com.github.haroldadmin:WhatTheStack:1.0.0-alpha04'
|
||||
|
||||
@ -272,7 +276,7 @@ dependencies {
|
||||
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines"
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
|
||||
|
||||
testImplementation 'org.robolectric:robolectric:4.10.3'
|
||||
testImplementation 'org.robolectric:robolectric:4.11.1'
|
||||
testImplementation "androidx.test:runner:1.5.2"
|
||||
testImplementation "androidx.test.ext:junit:1.1.5"
|
||||
testImplementation "androidx.test:core:1.5.0"
|
||||
|
@ -1,7 +1,7 @@
|
||||
apply plugin: "jacoco"
|
||||
|
||||
jacoco {
|
||||
toolVersion "0.8.10"
|
||||
toolVersion "0.8.11"
|
||||
reportsDirectory.set(file("$buildDir/reports"))
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import android.view.View
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.ui.modules.dashboard.DashboardItem
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import javax.inject.Inject
|
||||
|
||||
@Suppress("unused")
|
||||
@ -13,9 +14,11 @@ class AdsHelper @Inject constructor(
|
||||
private val preferencesRepository: PreferencesRepository
|
||||
) {
|
||||
|
||||
val isMobileAdsSdkInitialized = MutableStateFlow(false)
|
||||
val canShowAd = false
|
||||
|
||||
fun initialize() {
|
||||
preferencesRepository.isAdsEnabled = false
|
||||
preferencesRepository.isAgreeToProcessData = false
|
||||
preferencesRepository.selectedDashboardTiles -= DashboardItem.Tile.ADS
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
package io.github.wulkanowy.utils
|
||||
|
||||
import android.view.View
|
||||
import javax.inject.Inject
|
||||
|
||||
class InAppUpdateHelper @Inject constructor() {
|
||||
|
||||
lateinit var messageContainer: View
|
||||
|
||||
fun checkAndInstallUpdates() {}
|
||||
|
||||
fun onResume() {}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package io.github.wulkanowy.utils
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.View
|
||||
import javax.inject.Inject
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
class UpdateHelper @Inject constructor() {
|
||||
|
||||
lateinit var messageContainer: View
|
||||
|
||||
fun checkAndInstallUpdates(activity: Activity) {}
|
||||
|
||||
fun onActivityResult(requestCode: Int, resultCode: Int) {}
|
||||
|
||||
fun onResume(activity: Activity) {}
|
||||
}
|
@ -5,6 +5,7 @@ import android.view.View
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.ui.modules.dashboard.DashboardItem
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import javax.inject.Inject
|
||||
|
||||
@Suppress("unused")
|
||||
@ -12,10 +13,11 @@ class AdsHelper @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
private val preferencesRepository: PreferencesRepository
|
||||
) {
|
||||
val isMobileAdsSdkInitialized = MutableStateFlow(false)
|
||||
val canShowAd = false
|
||||
|
||||
fun initialize() {
|
||||
preferencesRepository.isAdsEnabled = false
|
||||
preferencesRepository.isAgreeToProcessData = false
|
||||
preferencesRepository.selectedDashboardTiles -= DashboardItem.Tile.ADS
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
package io.github.wulkanowy.utils
|
||||
|
||||
import android.view.View
|
||||
import javax.inject.Inject
|
||||
|
||||
class InAppUpdateHelper @Inject constructor() {
|
||||
|
||||
lateinit var messageContainer: View
|
||||
|
||||
fun checkAndInstallUpdates() {}
|
||||
|
||||
fun onResume() {}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package io.github.wulkanowy.utils
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.View
|
||||
import javax.inject.Inject
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
class UpdateHelper @Inject constructor() {
|
||||
|
||||
lateinit var messageContainer: View
|
||||
|
||||
fun checkAndInstallUpdates(activity: Activity) {}
|
||||
|
||||
fun onActivityResult(requestCode: Int, resultCode: Int) {}
|
||||
|
||||
fun onResume(activity: Activity) {}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package io.github.wulkanowy
|
||||
|
||||
import android.app.Application
|
||||
import android.util.Log.*
|
||||
import android.util.Log.DEBUG
|
||||
import android.util.Log.INFO
|
||||
import android.util.Log.VERBOSE
|
||||
import androidx.hilt.work.HiltWorkerFactory
|
||||
import androidx.work.Configuration
|
||||
import com.yariksoffice.lingver.Lingver
|
||||
@ -9,16 +11,19 @@ import dagger.hilt.android.HiltAndroidApp
|
||||
import fr.bipi.treessence.file.FileLoggerTree
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.ui.base.ThemeManager
|
||||
import io.github.wulkanowy.utils.*
|
||||
import io.github.wulkanowy.utils.ActivityLifecycleLogger
|
||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.CrashLogExceptionTree
|
||||
import io.github.wulkanowy.utils.CrashLogTree
|
||||
import io.github.wulkanowy.utils.DebugLogTree
|
||||
import io.github.wulkanowy.utils.RemoteConfigHelper
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltAndroidApp
|
||||
class WulkanowyApp : Application(), Configuration.Provider {
|
||||
|
||||
@Inject
|
||||
lateinit var workerFactory: HiltWorkerFactory
|
||||
|
||||
@Inject
|
||||
lateinit var themeManager: ThemeManager
|
||||
|
||||
@ -32,16 +37,21 @@ class WulkanowyApp : Application(), Configuration.Provider {
|
||||
lateinit var analyticsHelper: AnalyticsHelper
|
||||
|
||||
@Inject
|
||||
lateinit var adsHelper: AdsHelper
|
||||
lateinit var remoteConfigHelper: RemoteConfigHelper
|
||||
|
||||
@Inject
|
||||
lateinit var remoteConfigHelper: RemoteConfigHelper
|
||||
lateinit var workerFactory: HiltWorkerFactory
|
||||
|
||||
override val workManagerConfiguration: Configuration
|
||||
get() = Configuration.Builder()
|
||||
.setWorkerFactory(workerFactory)
|
||||
.setMinimumLoggingLevel(if (appInfo.isDebug) VERBOSE else INFO)
|
||||
.build()
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
initializeAppLanguage()
|
||||
themeManager.applyDefaultTheme()
|
||||
adsHelper.initialize()
|
||||
remoteConfigHelper.initialize()
|
||||
initLogging()
|
||||
}
|
||||
@ -74,9 +84,4 @@ class WulkanowyApp : Application(), Configuration.Provider {
|
||||
analyticsHelper.logEvent("language", "startup" to preferencesRepository.appLanguage)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getWorkManagerConfiguration() = Configuration.Builder()
|
||||
.setWorkerFactory(workerFactory)
|
||||
.setMinimumLoggingLevel(if (appInfo.isDebug) VERBOSE else INFO)
|
||||
.build()
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.RemoteConfigHelper
|
||||
import io.github.wulkanowy.utils.WebkitCookieManagerProxy
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.OkHttpClient
|
||||
@ -43,6 +44,7 @@ internal class DataModule {
|
||||
buildTag = android.os.Build.MODEL
|
||||
userAgentTemplate = remoteConfig.userAgentTemplate
|
||||
setSimpleHttpLogger { Timber.d(it) }
|
||||
setAdditionalCookieManager(WebkitCookieManagerProxy())
|
||||
|
||||
// for debug only
|
||||
addInterceptor(chuckerInterceptor, network = true)
|
||||
|
@ -1,6 +1,16 @@
|
||||
package io.github.wulkanowy.data
|
||||
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.emitAll
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.takeWhile
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import timber.log.Timber
|
||||
@ -131,7 +141,7 @@ inline fun <ResultType, RequestType> networkBoundResource(
|
||||
query().map { Resource.Success(filterResult(it)) }
|
||||
} catch (throwable: Throwable) {
|
||||
onFetchFailed(throwable)
|
||||
query().map { Resource.Error(throwable) }
|
||||
flowOf(Resource.Error(throwable))
|
||||
}
|
||||
} else {
|
||||
query().map { Resource.Success(filterResult(it)) }
|
||||
@ -165,7 +175,7 @@ inline fun <ResultType, RequestType, T> networkBoundResource(
|
||||
query().map { Resource.Success(mapResult(it)) }
|
||||
} catch (throwable: Throwable) {
|
||||
onFetchFailed(throwable)
|
||||
query().map { Resource.Error(throwable) }
|
||||
flowOf(Resource.Error(throwable))
|
||||
}
|
||||
} else {
|
||||
query().map { Resource.Success(mapResult(it)) }
|
||||
|
@ -1,11 +1,16 @@
|
||||
package io.github.wulkanowy.data.db.dao
|
||||
|
||||
import androidx.room.*
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.Transaction
|
||||
import androidx.room.Update
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.db.entities.StudentName
|
||||
import io.github.wulkanowy.data.db.entities.StudentNickAndAvatar
|
||||
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
@ -47,6 +52,9 @@ abstract class StudentDao {
|
||||
@Query("UPDATE Students SET is_current = 0")
|
||||
abstract suspend fun resetCurrent()
|
||||
|
||||
@Query("DELETE FROM Students WHERE email = :email AND user_name = :userName")
|
||||
abstract suspend fun deleteByEmailAndUserName(email: String, userName: String)
|
||||
|
||||
@Transaction
|
||||
open suspend fun switchCurrent(id: Long) {
|
||||
resetCurrent()
|
||||
|
@ -5,7 +5,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration10 : Migration(9, 10) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Grades_Summary RENAME TO GradesSummary")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Grades_Summary RENAME TO GradesSummary")
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration11 : Migration(10, 11) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS Grades_temp (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
is_read INTEGER NOT NULL,
|
||||
@ -26,9 +27,10 @@ class Migration11 : Migration(10, 11) {
|
||||
date INTEGER NOT NULL,
|
||||
teacher TEXT NOT NULL
|
||||
)
|
||||
""")
|
||||
database.execSQL("INSERT INTO Grades_temp SELECT * FROM Grades")
|
||||
database.execSQL("DROP TABLE Grades")
|
||||
database.execSQL("ALTER TABLE Grades_temp RENAME TO Grades")
|
||||
"""
|
||||
)
|
||||
db.execSQL("INSERT INTO Grades_temp SELECT * FROM Grades")
|
||||
db.execSQL("DROP TABLE Grades")
|
||||
db.execSQL("ALTER TABLE Grades_temp RENAME TO Grades")
|
||||
}
|
||||
}
|
||||
|
@ -5,16 +5,17 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration12 : Migration(11, 12) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
createTempStudentsTable(database)
|
||||
replaceStudentTable(database)
|
||||
updateStudentsWithClassId(database, getStudentsIds(database))
|
||||
removeStudentsWithNoClassId(database)
|
||||
ensureThereIsOnlyOneCurrentStudent(database)
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
createTempStudentsTable(db)
|
||||
replaceStudentTable(db)
|
||||
updateStudentsWithClassId(db, getStudentsIds(db))
|
||||
removeStudentsWithNoClassId(db)
|
||||
ensureThereIsOnlyOneCurrentStudent(db)
|
||||
}
|
||||
|
||||
private fun createTempStudentsTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
private fun createTempStudentsTable(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS Students_tmp (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
endpoint TEXT NOT NULL,
|
||||
@ -30,15 +31,16 @@ class Migration12 : Migration(11, 12) {
|
||||
registration_date INTEGER NOT NULL,
|
||||
class_id INTEGER NOT NULL
|
||||
)
|
||||
""")
|
||||
database.execSQL("CREATE UNIQUE INDEX index_Students_email_symbol_student_id_school_id_class_id ON Students_tmp (email, symbol, student_id, school_id, class_id)")
|
||||
"""
|
||||
)
|
||||
db.execSQL("CREATE UNIQUE INDEX index_Students_email_symbol_student_id_school_id_class_id ON Students_tmp (email, symbol, student_id, school_id, class_id)")
|
||||
}
|
||||
|
||||
private fun replaceStudentTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN class_id INTEGER DEFAULT 0 NOT NULL")
|
||||
database.execSQL("INSERT INTO Students_tmp SELECT * FROM Students")
|
||||
database.execSQL("DROP TABLE Students")
|
||||
database.execSQL("ALTER TABLE Students_tmp RENAME TO Students")
|
||||
private fun replaceStudentTable(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Students ADD COLUMN class_id INTEGER DEFAULT 0 NOT NULL")
|
||||
db.execSQL("INSERT INTO Students_tmp SELECT * FROM Students")
|
||||
db.execSQL("DROP TABLE Students")
|
||||
db.execSQL("ALTER TABLE Students_tmp RENAME TO Students")
|
||||
}
|
||||
|
||||
private fun getStudentsIds(database: SupportSQLiteDatabase): List<Int> {
|
||||
@ -54,18 +56,18 @@ class Migration12 : Migration(11, 12) {
|
||||
return students
|
||||
}
|
||||
|
||||
private fun updateStudentsWithClassId(database: SupportSQLiteDatabase, students: List<Int>) {
|
||||
private fun updateStudentsWithClassId(db: SupportSQLiteDatabase, students: List<Int>) {
|
||||
students.forEach {
|
||||
database.execSQL("UPDATE Students SET class_id = IFNULL((SELECT class_id FROM Semesters WHERE student_id = $it), 0) WHERE student_id = $it")
|
||||
db.execSQL("UPDATE Students SET class_id = IFNULL((SELECT class_id FROM Semesters WHERE student_id = $it), 0) WHERE student_id = $it")
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeStudentsWithNoClassId(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DELETE FROM Students WHERE class_id = 0")
|
||||
private fun removeStudentsWithNoClassId(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DELETE FROM Students WHERE class_id = 0")
|
||||
}
|
||||
|
||||
private fun ensureThereIsOnlyOneCurrentStudent(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("UPDATE Students SET is_current = 0")
|
||||
database.execSQL("UPDATE Students SET is_current = 1 WHERE id = (SELECT MAX(id) FROM Students)")
|
||||
private fun ensureThereIsOnlyOneCurrentStudent(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("UPDATE Students SET is_current = 0")
|
||||
db.execSQL("UPDATE Students SET is_current = 1 WHERE id = (SELECT MAX(id) FROM Students)")
|
||||
}
|
||||
}
|
||||
|
@ -5,27 +5,30 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration13 : Migration(12, 13) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
addClassNameToStudents(database, getStudentsIds(database))
|
||||
updateSemestersTable(database)
|
||||
markAtLeastAndOnlyOneSemesterAtCurrent(database, getStudentsAndClassIds(database))
|
||||
clearMessagesTable(database)
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
addClassNameToStudents(db, getStudentsIds(db))
|
||||
updateSemestersTable(db)
|
||||
markAtLeastAndOnlyOneSemesterAtCurrent(db, getStudentsAndClassIds(db))
|
||||
clearMessagesTable(db)
|
||||
}
|
||||
|
||||
private fun addClassNameToStudents(database: SupportSQLiteDatabase, students: List<Pair<Int, String>>) {
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN class_name TEXT DEFAULT \"\" NOT NULL")
|
||||
private fun addClassNameToStudents(
|
||||
db: SupportSQLiteDatabase,
|
||||
students: List<Pair<Int, String>>
|
||||
) {
|
||||
db.execSQL("ALTER TABLE Students ADD COLUMN class_name TEXT DEFAULT \"\" NOT NULL")
|
||||
|
||||
students.forEach { (id, name) ->
|
||||
val schoolName = name.substringAfter(" - ")
|
||||
val className = name.substringBefore(" - ", "").replace("Klasa ", "")
|
||||
database.execSQL("UPDATE Students SET class_name = '$className' WHERE id = '$id'")
|
||||
database.execSQL("UPDATE Students SET school_name = '$schoolName' WHERE id = '$id'")
|
||||
db.execSQL("UPDATE Students SET class_name = '$className' WHERE id = '$id'")
|
||||
db.execSQL("UPDATE Students SET school_name = '$schoolName' WHERE id = '$id'")
|
||||
}
|
||||
}
|
||||
|
||||
private fun getStudentsIds(database: SupportSQLiteDatabase): MutableList<Pair<Int, String>> {
|
||||
private fun getStudentsIds(db: SupportSQLiteDatabase): MutableList<Pair<Int, String>> {
|
||||
val students = mutableListOf<Pair<Int, String>>()
|
||||
database.query("SELECT id, school_name FROM Students").use {
|
||||
db.query("SELECT id, school_name FROM Students").use {
|
||||
if (it.moveToFirst()) {
|
||||
do {
|
||||
students.add(it.getInt(0) to it.getString(1))
|
||||
@ -36,15 +39,15 @@ class Migration13 : Migration(12, 13) {
|
||||
return students
|
||||
}
|
||||
|
||||
private fun updateSemestersTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Semesters ADD COLUMN school_year INTEGER DEFAULT 1970 NOT NULL")
|
||||
database.execSQL("ALTER TABLE Semesters ADD COLUMN start INTEGER DEFAULT 0 NOT NULL")
|
||||
database.execSQL("ALTER TABLE Semesters ADD COLUMN `end` INTEGER DEFAULT 0 NOT NULL")
|
||||
private fun updateSemestersTable(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Semesters ADD COLUMN school_year INTEGER DEFAULT 1970 NOT NULL")
|
||||
db.execSQL("ALTER TABLE Semesters ADD COLUMN start INTEGER DEFAULT 0 NOT NULL")
|
||||
db.execSQL("ALTER TABLE Semesters ADD COLUMN `end` INTEGER DEFAULT 0 NOT NULL")
|
||||
}
|
||||
|
||||
private fun getStudentsAndClassIds(database: SupportSQLiteDatabase): List<Pair<Int, Int>> {
|
||||
private fun getStudentsAndClassIds(db: SupportSQLiteDatabase): List<Pair<Int, Int>> {
|
||||
val students = mutableListOf<Pair<Int, Int>>()
|
||||
database.query("SELECT student_id, class_id FROM Students").use {
|
||||
db.query("SELECT student_id, class_id FROM Students").use {
|
||||
if (it.moveToFirst()) {
|
||||
do {
|
||||
students.add(it.getInt(0) to it.getInt(1))
|
||||
@ -55,14 +58,17 @@ class Migration13 : Migration(12, 13) {
|
||||
return students
|
||||
}
|
||||
|
||||
private fun markAtLeastAndOnlyOneSemesterAtCurrent(database: SupportSQLiteDatabase, students: List<Pair<Int, Int>>) {
|
||||
private fun markAtLeastAndOnlyOneSemesterAtCurrent(
|
||||
db: SupportSQLiteDatabase,
|
||||
students: List<Pair<Int, Int>>
|
||||
) {
|
||||
students.forEach { (studentId, classId) ->
|
||||
database.execSQL("UPDATE Semesters SET is_current = 0 WHERE student_id = '$studentId' AND class_id = '$classId'")
|
||||
database.execSQL("UPDATE Semesters SET is_current = 1 WHERE id = (SELECT id FROM Semesters WHERE student_id = '$studentId' AND class_id = '$classId' ORDER BY semester_id DESC)")
|
||||
db.execSQL("UPDATE Semesters SET is_current = 0 WHERE student_id = '$studentId' AND class_id = '$classId'")
|
||||
db.execSQL("UPDATE Semesters SET is_current = 1 WHERE id = (SELECT id FROM Semesters WHERE student_id = '$studentId' AND class_id = '$classId' ORDER BY semester_id DESC)")
|
||||
}
|
||||
}
|
||||
|
||||
private fun clearMessagesTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DELETE FROM Messages")
|
||||
private fun clearMessagesTable(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DELETE FROM Messages")
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,10 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration14 : Migration(13, 14) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS GradesSummary")
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE IF EXISTS GradesSummary")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS GradesSummary (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
semester_id INTEGER NOT NULL,
|
||||
|
@ -5,8 +5,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration15 : Migration(14, 15) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS MobileDevices (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
@ -14,6 +15,7 @@ class Migration15 : Migration(14, 15) {
|
||||
name TEXT NOT NULL,
|
||||
date INTEGER NOT NULL
|
||||
)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration16 : Migration(15, 16) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS Teachers (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
@ -15,6 +16,7 @@ class Migration16 : Migration(15, 16) {
|
||||
name TEXT NOT NULL,
|
||||
short_name TEXT NOT NULL
|
||||
)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,14 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration17 : Migration(16, 17) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
createGradesPointsStatisticsTable(database)
|
||||
truncateSemestersTable(database)
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
createGradesPointsStatisticsTable(db)
|
||||
truncateSemestersTable(db)
|
||||
}
|
||||
|
||||
private fun createGradesPointsStatisticsTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
private fun createGradesPointsStatisticsTable(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS GradesPointsStatistics(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
@ -20,10 +21,11 @@ class Migration17 : Migration(16, 17) {
|
||||
others REAL NOT NULL,
|
||||
student REAL NOT NULL
|
||||
)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
private fun truncateSemestersTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DELETE FROM Semesters")
|
||||
private fun truncateSemestersTable(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DELETE FROM Semesters")
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration18 : Migration(17, 18) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS School (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
|
@ -6,16 +6,17 @@ import io.github.wulkanowy.data.db.SharedPrefProvider
|
||||
|
||||
class Migration19(private val sharedPrefProvider: SharedPrefProvider) : Migration(18, 19) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
migrateMessages(database)
|
||||
migrateGrades(database)
|
||||
migrateStudents(database)
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
migrateMessages(db)
|
||||
migrateGrades(db)
|
||||
migrateStudents(db)
|
||||
migrateSharedPreferences()
|
||||
}
|
||||
|
||||
private fun migrateMessages(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE Messages")
|
||||
database.execSQL("""
|
||||
private fun migrateMessages(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE Messages")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS Messages (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
is_notified INTEGER NOT NULL,
|
||||
@ -34,12 +35,14 @@ class Migration19(private val sharedPrefProvider: SharedPrefProvider) : Migratio
|
||||
read_by INTEGER NOT NULL,
|
||||
removed INTEGER NOT NULL
|
||||
)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
private fun migrateGrades(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE Grades")
|
||||
database.execSQL("""
|
||||
private fun migrateGrades(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE Grades")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS Grades (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
is_read INTEGER NOT NULL,
|
||||
@ -59,11 +62,13 @@ class Migration19(private val sharedPrefProvider: SharedPrefProvider) : Migratio
|
||||
date INTEGER NOT NULL,
|
||||
teacher TEXT NOT NULL
|
||||
)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
private fun migrateStudents(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
private fun migrateStudents(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS Students_tmp (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
scrapper_base_url TEXT NOT NULL,
|
||||
@ -86,26 +91,29 @@ class Migration19(private val sharedPrefProvider: SharedPrefProvider) : Migratio
|
||||
is_current INTEGER NOT NULL,
|
||||
registration_date INTEGER NOT NULL
|
||||
)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN scrapperBaseUrl TEXT NOT NULL DEFAULT \"\";")
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN apiBaseUrl TEXT NOT NULL DEFAULT \"\";")
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN is_parent INT NOT NULL DEFAULT 0;")
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN loginMode TEXT NOT NULL DEFAULT \"\";")
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN certificateKey TEXT NOT NULL DEFAULT \"\";")
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN privateKey TEXT NOT NULL DEFAULT \"\";")
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN user_login_id INTEGER NOT NULL DEFAULT 0;")
|
||||
db.execSQL("ALTER TABLE Students ADD COLUMN scrapperBaseUrl TEXT NOT NULL DEFAULT \"\";")
|
||||
db.execSQL("ALTER TABLE Students ADD COLUMN apiBaseUrl TEXT NOT NULL DEFAULT \"\";")
|
||||
db.execSQL("ALTER TABLE Students ADD COLUMN is_parent INT NOT NULL DEFAULT 0;")
|
||||
db.execSQL("ALTER TABLE Students ADD COLUMN loginMode TEXT NOT NULL DEFAULT \"\";")
|
||||
db.execSQL("ALTER TABLE Students ADD COLUMN certificateKey TEXT NOT NULL DEFAULT \"\";")
|
||||
db.execSQL("ALTER TABLE Students ADD COLUMN privateKey TEXT NOT NULL DEFAULT \"\";")
|
||||
db.execSQL("ALTER TABLE Students ADD COLUMN user_login_id INTEGER NOT NULL DEFAULT 0;")
|
||||
|
||||
database.execSQL("""
|
||||
db.execSQL(
|
||||
"""
|
||||
INSERT INTO Students_tmp(
|
||||
id, scrapper_base_url, mobile_base_url, is_parent, login_type, login_mode, certificate_key, private_key, email, password, symbol, student_id, user_login_id, student_name, school_id, school_name, school_id, school_name, class_name, class_id, is_current, registration_date)
|
||||
SELECT
|
||||
id, endpoint, apiBaseUrl, is_parent, loginType, "SCRAPPER", certificateKey, privateKey, email, password, symbol, student_id, user_login_id, student_name, school_id, school_name, school_id, school_name, class_name, class_id, is_current, registration_date
|
||||
FROM Students
|
||||
""")
|
||||
database.execSQL("DROP TABLE Students")
|
||||
database.execSQL("ALTER TABLE Students_tmp RENAME TO Students")
|
||||
database.execSQL("CREATE UNIQUE INDEX index_Students_email_symbol_student_id_school_id_class_id ON Students (email, symbol, student_id, school_id, class_id)")
|
||||
"""
|
||||
)
|
||||
db.execSQL("DROP TABLE Students")
|
||||
db.execSQL("ALTER TABLE Students_tmp RENAME TO Students")
|
||||
db.execSQL("CREATE UNIQUE INDEX index_Students_email_symbol_student_id_school_id_class_id ON Students (email, symbol, student_id, school_id, class_id)")
|
||||
}
|
||||
|
||||
private fun migrateSharedPreferences() {
|
||||
|
@ -5,14 +5,16 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration2 : Migration(1, 2) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS LuckyNumbers (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
is_notified INTEGER NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
date INTEGER NOT NULL,
|
||||
lucky_number INTEGER NOT NULL)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,15 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration20 : Migration(19, 20) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
migrateTimetable(database)
|
||||
truncateSubjects(database)
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
migrateTimetable(db)
|
||||
truncateSubjects(db)
|
||||
}
|
||||
|
||||
private fun migrateTimetable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE Timetable")
|
||||
database.execSQL("""
|
||||
private fun migrateTimetable(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE Timetable")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS `Timetable` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`student_id` INTEGER NOT NULL,
|
||||
@ -33,10 +34,11 @@ class Migration20 : Migration(19, 20) {
|
||||
`changes` INTEGER NOT NULL,
|
||||
`canceled` INTEGER NOT NULL
|
||||
)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
private fun truncateSubjects(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DELETE FROM Subjects")
|
||||
private fun truncateSubjects(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DELETE FROM Subjects")
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,11 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration21 : Migration(20, 21) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Attendance ADD COLUMN excusable INTEGER NOT NULL DEFAULT 0")
|
||||
database.execSQL("ALTER TABLE Attendance ADD COLUMN time_id INTEGER NOT NULL DEFAULT 0")
|
||||
database.execSQL("ALTER TABLE Attendance ADD COLUMN excuse_status TEXT DEFAULT NULL")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Attendance ADD COLUMN excusable INTEGER NOT NULL DEFAULT 0")
|
||||
db.execSQL("ALTER TABLE Attendance ADD COLUMN time_id INTEGER NOT NULL DEFAULT 0")
|
||||
db.execSQL("ALTER TABLE Attendance ADD COLUMN excuse_status TEXT DEFAULT NULL")
|
||||
|
||||
database.execSQL("DELETE FROM Semesters")
|
||||
db.execSQL("DELETE FROM Semesters")
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration22 : Migration(21, 22) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN school_short TEXT NOT NULL DEFAULT ''")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Students ADD COLUMN school_short TEXT NOT NULL DEFAULT ''")
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration23 : Migration(22, 23) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Notes ADD COLUMN teacher_symbol TEXT NOT NULL DEFAULT ''")
|
||||
database.execSQL("ALTER TABLE Notes ADD COLUMN category_type INTEGER NOT NULL DEFAULT 0")
|
||||
database.execSQL("ALTER TABLE Notes ADD COLUMN is_points_show INTEGER NOT NULL DEFAULT 0")
|
||||
database.execSQL("ALTER TABLE Notes ADD COLUMN points INTEGER NOT NULL DEFAULT 0")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Notes ADD COLUMN teacher_symbol TEXT NOT NULL DEFAULT ''")
|
||||
db.execSQL("ALTER TABLE Notes ADD COLUMN category_type INTEGER NOT NULL DEFAULT 0")
|
||||
db.execSQL("ALTER TABLE Notes ADD COLUMN is_points_show INTEGER NOT NULL DEFAULT 0")
|
||||
db.execSQL("ALTER TABLE Notes ADD COLUMN points INTEGER NOT NULL DEFAULT 0")
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,10 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration24 : Migration(23, 24) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Messages ADD COLUMN has_attachments INTEGER NOT NULL DEFAULT 0")
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Messages ADD COLUMN has_attachments INTEGER NOT NULL DEFAULT 0")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS MessageAttachments (
|
||||
real_id INTEGER NOT NULL,
|
||||
message_id INTEGER NOT NULL,
|
||||
@ -16,6 +17,7 @@ class Migration24 : Migration(23, 24) {
|
||||
filename TEXT NOT NULL,
|
||||
PRIMARY KEY(real_id)
|
||||
)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration25 : Migration(24, 25) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Homework ADD COLUMN is_done INTEGER NOT NULL DEFAULT 0")
|
||||
database.execSQL("ALTER TABLE Homework ADD COLUMN attachments TEXT NOT NULL DEFAULT \"[]\"")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Homework ADD COLUMN is_done INTEGER NOT NULL DEFAULT 0")
|
||||
db.execSQL("ALTER TABLE Homework ADD COLUMN attachments TEXT NOT NULL DEFAULT \"[]\"")
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration26 : Migration(25, 26) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE GradesSummary ADD COLUMN is_predicted_grade_notified INTEGER NOT NULL DEFAULT 1")
|
||||
database.execSQL("ALTER TABLE GradesSummary ADD COLUMN is_final_grade_notified INTEGER NOT NULL DEFAULT 1")
|
||||
database.execSQL("ALTER TABLE GradesSummary ADD COLUMN predicted_grade_last_change INTEGER NOT NULL DEFAULT 0")
|
||||
database.execSQL("ALTER TABLE GradesSummary ADD COLUMN final_grade_last_change INTEGER NOT NULL DEFAULT 0")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE GradesSummary ADD COLUMN is_predicted_grade_notified INTEGER NOT NULL DEFAULT 1")
|
||||
db.execSQL("ALTER TABLE GradesSummary ADD COLUMN is_final_grade_notified INTEGER NOT NULL DEFAULT 1")
|
||||
db.execSQL("ALTER TABLE GradesSummary ADD COLUMN predicted_grade_last_change INTEGER NOT NULL DEFAULT 0")
|
||||
db.execSQL("ALTER TABLE GradesSummary ADD COLUMN final_grade_last_change INTEGER NOT NULL DEFAULT 0")
|
||||
}
|
||||
}
|
||||
|
@ -5,24 +5,25 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration27 : Migration(26, 27) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN user_name TEXT NOT NULL DEFAULT \"\"")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Students ADD COLUMN user_name TEXT NOT NULL DEFAULT \"\"")
|
||||
|
||||
val students = getStudentsIdsAndNames(database)
|
||||
val units = getReportingUnits(database)
|
||||
val students = getStudentsIdsAndNames(db)
|
||||
val units = getReportingUnits(db)
|
||||
|
||||
students.forEach { (id, userLoginId, studentName) ->
|
||||
val userNameFromUnits = units.singleOrNull { (senderId, _) -> senderId == userLoginId }?.second
|
||||
val userNameFromUnits =
|
||||
units.singleOrNull { (senderId, _) -> senderId == userLoginId }?.second
|
||||
val normalizedStudentName = studentName.split(" ").asReversed().joinToString(" ")
|
||||
|
||||
val userName = userNameFromUnits ?: normalizedStudentName
|
||||
database.execSQL("UPDATE Students SET user_name = '$userName' WHERE id = '$id'")
|
||||
db.execSQL("UPDATE Students SET user_name = '$userName' WHERE id = '$id'")
|
||||
}
|
||||
}
|
||||
|
||||
private fun getStudentsIdsAndNames(database: SupportSQLiteDatabase): MutableList<Triple<Long, Int, String>> {
|
||||
private fun getStudentsIdsAndNames(db: SupportSQLiteDatabase): MutableList<Triple<Long, Int, String>> {
|
||||
val students = mutableListOf<Triple<Long, Int, String>>()
|
||||
database.query("SELECT id, user_login_id, student_name FROM Students").use {
|
||||
db.query("SELECT id, user_login_id, student_name FROM Students").use {
|
||||
if (it.moveToFirst()) {
|
||||
do {
|
||||
students.add(Triple(it.getLong(0), it.getInt(1), it.getString(2)))
|
||||
@ -33,9 +34,9 @@ class Migration27 : Migration(26, 27) {
|
||||
return students
|
||||
}
|
||||
|
||||
private fun getReportingUnits(database: SupportSQLiteDatabase): MutableList<Pair<Int, String>> {
|
||||
private fun getReportingUnits(db: SupportSQLiteDatabase): MutableList<Pair<Int, String>> {
|
||||
val units = mutableListOf<Pair<Int, String>>()
|
||||
database.query("SELECT sender_id, sender_name FROM ReportingUnits").use {
|
||||
db.query("SELECT sender_id, sender_name FROM ReportingUnits").use {
|
||||
if (it.moveToFirst()) {
|
||||
do {
|
||||
units.add(it.getInt(0) to it.getString(1))
|
||||
|
@ -5,8 +5,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration28 : Migration(27, 28) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS Conferences (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
|
@ -5,9 +5,10 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration29 : Migration(28, 29) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS GradesStatistics")
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE IF EXISTS GradesStatistics")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS GradeSemesterStatistics (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
@ -16,8 +17,10 @@ class Migration29 : Migration(28, 29) {
|
||||
amounts TEXT NOT NULL,
|
||||
student_grade INTEGER NOT NULL
|
||||
)
|
||||
""")
|
||||
database.execSQL("""
|
||||
"""
|
||||
)
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS GradePartialStatistics (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
|
@ -5,8 +5,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration3 : Migration(2, 3) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS CompletedLesson (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
|
@ -5,8 +5,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration30 : Migration(29, 30) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE TimetableAdditional (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
@ -16,6 +17,7 @@ class Migration30 : Migration(29, 30) {
|
||||
date INTEGER NOT NULL,
|
||||
subject TEXT NOT NULL
|
||||
)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration31 : Migration(30, 31) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL(
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""CREATE TABLE IF NOT EXISTS StudentInfo (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
|
@ -5,8 +5,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration32 : Migration(31, 32) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN nick TEXT NOT NULL DEFAULT \"\"")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Students ADD COLUMN nick TEXT NOT NULL DEFAULT \"\"")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,10 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration33 : Migration(32, 33) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS StudentInfo")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE IF EXISTS StudentInfo")
|
||||
|
||||
database.execSQL(
|
||||
db.execSQL(
|
||||
"""CREATE TABLE IF NOT EXISTS StudentInfo (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
|
@ -5,9 +5,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration34 : Migration(33, 34) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DELETE FROM ReportingUnits")
|
||||
database.execSQL("DELETE FROM Recipients")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DELETE FROM ReportingUnits")
|
||||
db.execSQL("DELETE FROM Recipients")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,13 +7,13 @@ import io.github.wulkanowy.utils.AppInfo
|
||||
|
||||
class Migration35(private val appInfo: AppInfo) : Migration(34, 35) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN `avatar_color` INTEGER NOT NULL DEFAULT 0")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Students ADD COLUMN `avatar_color` INTEGER NOT NULL DEFAULT 0")
|
||||
|
||||
database.query("SELECT * FROM Students").use {
|
||||
db.query("SELECT * FROM Students").use {
|
||||
while (it.moveToNext()) {
|
||||
val studentId = it.getLongOrNull(0)
|
||||
database.execSQL(
|
||||
db.execSQL(
|
||||
"""
|
||||
UPDATE Students
|
||||
SET avatar_color = ${appInfo.defaultColorsForAvatar.random()}
|
||||
|
@ -5,8 +5,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration36 : Migration(35, 36) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Exams ADD COLUMN is_notified INTEGER NOT NULL DEFAULT 1")
|
||||
database.execSQL("ALTER TABLE Homework ADD COLUMN is_notified INTEGER NOT NULL DEFAULT 1")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Exams ADD COLUMN is_notified INTEGER NOT NULL DEFAULT 1")
|
||||
db.execSQL("ALTER TABLE Homework ADD COLUMN is_notified INTEGER NOT NULL DEFAULT 1")
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration37 : Migration(36, 37) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL(
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS TimetableHeaders (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
|
@ -5,8 +5,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration38 : Migration(37, 38) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS `SchoolAnnouncements` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`student_id` INTEGER NOT NULL,
|
||||
@ -14,6 +15,7 @@ class Migration38 : Migration(37, 38) {
|
||||
`subject` TEXT NOT NULL,
|
||||
`content` TEXT NOT NULL
|
||||
)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration39 : Migration(38, 39) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Conferences ADD COLUMN is_notified INTEGER NOT NULL DEFAULT 1")
|
||||
database.execSQL("ALTER TABLE SchoolAnnouncements ADD COLUMN is_notified INTEGER NOT NULL DEFAULT 1")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Conferences ADD COLUMN is_notified INTEGER NOT NULL DEFAULT 1")
|
||||
db.execSQL("ALTER TABLE SchoolAnnouncements ADD COLUMN is_notified INTEGER NOT NULL DEFAULT 1")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,10 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration4 : Migration(3, 4) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS Messages")
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE IF EXISTS Messages")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS Messages (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
is_notified INTEGER NOT NULL,
|
||||
|
@ -5,8 +5,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration40 : Migration(39, 40) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL(
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS `Notifications` (
|
||||
`student_id` INTEGER NOT NULL,
|
||||
@ -20,4 +20,4 @@ class Migration40 : Migration(39, 40) {
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ import io.github.wulkanowy.data.enums.GradeExpandMode
|
||||
|
||||
class Migration41(private val sharedPrefProvider: SharedPrefProvider) : Migration(40, 41) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
migrateSharedPreferences()
|
||||
database.execSQL("ALTER TABLE Homework ADD COLUMN is_added_by_user INTEGER NOT NULL DEFAULT 0")
|
||||
db.execSQL("ALTER TABLE Homework ADD COLUMN is_added_by_user INTEGER NOT NULL DEFAULT 0")
|
||||
}
|
||||
|
||||
private fun migrateSharedPreferences() {
|
||||
@ -18,4 +18,4 @@ class Migration41(private val sharedPrefProvider: SharedPrefProvider) : Migratio
|
||||
}
|
||||
sharedPrefProvider.delete("pref_key_expand_grade")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration42 : Migration(41, 42) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL(
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""CREATE TABLE IF NOT EXISTS `AdminMessages` (
|
||||
`id` INTEGER NOT NULL,
|
||||
`title` TEXT NOT NULL,
|
||||
@ -21,4 +21,4 @@ class Migration42 : Migration(41, 42) {
|
||||
PRIMARY KEY(`id`))"""
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration43 : Migration(42, 43) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Timetable ADD COLUMN is_notified INTEGER NOT NULL DEFAULT 1")
|
||||
database.execSQL("ALTER TABLE Attendance ADD COLUMN is_notified INTEGER NOT NULL DEFAULT 1")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Timetable ADD COLUMN is_notified INTEGER NOT NULL DEFAULT 1")
|
||||
db.execSQL("ALTER TABLE Attendance ADD COLUMN is_notified INTEGER NOT NULL DEFAULT 1")
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration44 : Migration(43, 44) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE AdminMessages ADD COLUMN is_dismissible INTEGER NOT NULL DEFAULT 0")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE AdminMessages ADD COLUMN is_dismissible INTEGER NOT NULL DEFAULT 0")
|
||||
}
|
||||
}
|
||||
|
@ -8,65 +8,65 @@ import java.time.ZoneOffset
|
||||
|
||||
class Migration46 : Migration(45, 46) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
migrateConferences(database)
|
||||
migrateMessages(database)
|
||||
migrateMobileDevices(database)
|
||||
migrateNotifications(database)
|
||||
migrateTimetable(database)
|
||||
migrateTimetableAdditional(database)
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
migrateConferences(db)
|
||||
migrateMessages(db)
|
||||
migrateMobileDevices(db)
|
||||
migrateNotifications(db)
|
||||
migrateTimetable(db)
|
||||
migrateTimetableAdditional(db)
|
||||
}
|
||||
|
||||
private fun migrateConferences(database: SupportSQLiteDatabase) {
|
||||
database.query("SELECT * FROM Conferences").use {
|
||||
private fun migrateConferences(db: SupportSQLiteDatabase) {
|
||||
db.query("SELECT * FROM Conferences").use {
|
||||
while (it.moveToNext()) {
|
||||
val id = it.getLong(it.getColumnIndexOrThrow("id"))
|
||||
val timestampLocal = it.getLong(it.getColumnIndexOrThrow("date"))
|
||||
val timestampUtc = timestampLocal.timestampLocalToUTC()
|
||||
|
||||
database.execSQL("UPDATE Conferences SET date = $timestampUtc WHERE id = $id")
|
||||
db.execSQL("UPDATE Conferences SET date = $timestampUtc WHERE id = $id")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun migrateMessages(database: SupportSQLiteDatabase) {
|
||||
database.query("SELECT * FROM Messages").use {
|
||||
private fun migrateMessages(db: SupportSQLiteDatabase) {
|
||||
db.query("SELECT * FROM Messages").use {
|
||||
while (it.moveToNext()) {
|
||||
val id = it.getLong(it.getColumnIndexOrThrow("id"))
|
||||
val timestampLocal = it.getLong(it.getColumnIndexOrThrow("date"))
|
||||
val timestampUtc = timestampLocal.timestampLocalToUTC()
|
||||
|
||||
database.execSQL("UPDATE Messages SET date = $timestampUtc WHERE id = $id")
|
||||
db.execSQL("UPDATE Messages SET date = $timestampUtc WHERE id = $id")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun migrateMobileDevices(database: SupportSQLiteDatabase) {
|
||||
database.query("SELECT * FROM MobileDevices").use {
|
||||
private fun migrateMobileDevices(db: SupportSQLiteDatabase) {
|
||||
db.query("SELECT * FROM MobileDevices").use {
|
||||
while (it.moveToNext()) {
|
||||
val id = it.getLong(it.getColumnIndexOrThrow("id"))
|
||||
val timestampLocal = it.getLong(it.getColumnIndexOrThrow("date"))
|
||||
val timestampUtc = timestampLocal.timestampLocalToUTC()
|
||||
|
||||
database.execSQL("UPDATE MobileDevices SET date = $timestampUtc WHERE id = $id")
|
||||
db.execSQL("UPDATE MobileDevices SET date = $timestampUtc WHERE id = $id")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun migrateNotifications(database: SupportSQLiteDatabase) {
|
||||
database.query("SELECT * FROM Notifications").use {
|
||||
private fun migrateNotifications(db: SupportSQLiteDatabase) {
|
||||
db.query("SELECT * FROM Notifications").use {
|
||||
while (it.moveToNext()) {
|
||||
val id = it.getLong(it.getColumnIndexOrThrow("id"))
|
||||
val timestampLocal = it.getLong(it.getColumnIndexOrThrow("date"))
|
||||
val timestampUtc = timestampLocal.timestampLocalToUTC()
|
||||
|
||||
database.execSQL("UPDATE Notifications SET date = $timestampUtc WHERE id = $id")
|
||||
db.execSQL("UPDATE Notifications SET date = $timestampUtc WHERE id = $id")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun migrateTimetable(database: SupportSQLiteDatabase) {
|
||||
database.query("SELECT * FROM Timetable").use {
|
||||
private fun migrateTimetable(db: SupportSQLiteDatabase) {
|
||||
db.query("SELECT * FROM Timetable").use {
|
||||
while (it.moveToNext()) {
|
||||
val id = it.getLong(it.getColumnIndexOrThrow("id"))
|
||||
val timestampLocalStart = it.getLong(it.getColumnIndexOrThrow("start"))
|
||||
@ -74,13 +74,13 @@ class Migration46 : Migration(45, 46) {
|
||||
val timestampUtcStart = timestampLocalStart.timestampLocalToUTC()
|
||||
val timestampUtcEnd = timestampLocalEnd.timestampLocalToUTC()
|
||||
|
||||
database.execSQL("UPDATE Timetable SET start = $timestampUtcStart, end = $timestampUtcEnd WHERE id = $id")
|
||||
db.execSQL("UPDATE Timetable SET start = $timestampUtcStart, end = $timestampUtcEnd WHERE id = $id")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun migrateTimetableAdditional(database: SupportSQLiteDatabase) {
|
||||
database.query("SELECT * FROM TimetableAdditional").use {
|
||||
private fun migrateTimetableAdditional(db: SupportSQLiteDatabase) {
|
||||
db.query("SELECT * FROM TimetableAdditional").use {
|
||||
while (it.moveToNext()) {
|
||||
val id = it.getLong(it.getColumnIndexOrThrow("id"))
|
||||
val timestampLocalStart = it.getLong(it.getColumnIndexOrThrow("start"))
|
||||
@ -88,7 +88,7 @@ class Migration46 : Migration(45, 46) {
|
||||
val timestampUtcStart = timestampLocalStart.timestampLocalToUTC()
|
||||
val timestampUtcEnd = timestampLocalEnd.timestampLocalToUTC()
|
||||
|
||||
database.execSQL("UPDATE TimetableAdditional SET start = $timestampUtcStart, end = $timestampUtcEnd WHERE id = $id")
|
||||
db.execSQL("UPDATE TimetableAdditional SET start = $timestampUtcStart, end = $timestampUtcEnd WHERE id = $id")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration49 : Migration(48, 49) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS SchoolAnnouncements")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE IF EXISTS SchoolAnnouncements")
|
||||
|
||||
database.execSQL(
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS `SchoolAnnouncements` (
|
||||
`user_login_id` INTEGER NOT NULL,
|
||||
|
@ -7,11 +7,16 @@ import java.time.ZoneOffset
|
||||
|
||||
class Migration5 : Migration(4, 5) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Students ADD COLUMN registration_date INTEGER DEFAULT 0 NOT NULL")
|
||||
database.execSQL("UPDATE Students SET registration_date = '${now().atZone(ZoneOffset.UTC).toInstant().toEpochMilli()}'")
|
||||
database.execSQL("DROP TABLE IF EXISTS Notes")
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Students ADD COLUMN registration_date INTEGER DEFAULT 0 NOT NULL")
|
||||
db.execSQL(
|
||||
"UPDATE Students SET registration_date = '${
|
||||
now().atZone(ZoneOffset.UTC).toInstant().toEpochMilli()
|
||||
}'"
|
||||
)
|
||||
db.execSQL("DROP TABLE IF EXISTS Notes")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS Notes (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
is_read INTEGER NOT NULL,
|
||||
@ -21,6 +26,7 @@ class Migration5 : Migration(4, 5) {
|
||||
teacher TEXT NOT NULL,
|
||||
category TEXT NOT NULL,
|
||||
content TEXT NOT NULL)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration50 : Migration(49, 50) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS MobileDevices")
|
||||
database.execSQL(
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE IF EXISTS MobileDevices")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS `MobileDevices` (
|
||||
`user_login_id` INTEGER NOT NULL,
|
||||
|
@ -5,17 +5,17 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration51 : Migration(50, 51) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
createMailboxTable(database)
|
||||
recreateMessagesTable(database)
|
||||
recreateMessageAttachmentsTable(database)
|
||||
recreateRecipientsTable(database)
|
||||
deleteReportingUnitTable(database)
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
createMailboxTable(db)
|
||||
recreateMessagesTable(db)
|
||||
recreateMessageAttachmentsTable(db)
|
||||
recreateRecipientsTable(db)
|
||||
deleteReportingUnitTable(db)
|
||||
}
|
||||
|
||||
private fun createMailboxTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS Mailboxes")
|
||||
database.execSQL(
|
||||
private fun createMailboxTable(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE IF EXISTS Mailboxes")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS `Mailboxes` (
|
||||
`globalKey` TEXT NOT NULL,
|
||||
@ -30,9 +30,9 @@ class Migration51 : Migration(50, 51) {
|
||||
)
|
||||
}
|
||||
|
||||
private fun recreateMessagesTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS Messages")
|
||||
database.execSQL(
|
||||
private fun recreateMessagesTable(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE IF EXISTS Messages")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS `Messages` (
|
||||
`message_global_key` TEXT NOT NULL,
|
||||
@ -52,9 +52,9 @@ class Migration51 : Migration(50, 51) {
|
||||
)
|
||||
}
|
||||
|
||||
private fun recreateMessageAttachmentsTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS MessageAttachments")
|
||||
database.execSQL(
|
||||
private fun recreateMessageAttachmentsTable(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE IF EXISTS MessageAttachments")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS `MessageAttachments` (
|
||||
`real_id` INTEGER NOT NULL,
|
||||
@ -66,9 +66,9 @@ class Migration51 : Migration(50, 51) {
|
||||
)
|
||||
}
|
||||
|
||||
private fun recreateRecipientsTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS Recipients")
|
||||
database.execSQL(
|
||||
private fun recreateRecipientsTable(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE IF EXISTS Recipients")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS `Recipients` (
|
||||
`mailboxGlobalKey` TEXT NOT NULL,
|
||||
@ -82,7 +82,7 @@ class Migration51 : Migration(50, 51) {
|
||||
)
|
||||
}
|
||||
|
||||
private fun deleteReportingUnitTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS ReportingUnits")
|
||||
private fun deleteReportingUnitTable(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE IF EXISTS ReportingUnits")
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,14 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration53 : Migration(52, 53) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
createMailboxTable(database)
|
||||
recreateMessagesTable(database)
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
createMailboxTable(db)
|
||||
recreateMessagesTable(db)
|
||||
}
|
||||
|
||||
private fun createMailboxTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS Mailboxes")
|
||||
database.execSQL(
|
||||
private fun createMailboxTable(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE IF EXISTS Mailboxes")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS `Mailboxes` (
|
||||
`globalKey` TEXT NOT NULL,
|
||||
@ -29,9 +29,9 @@ class Migration53 : Migration(52, 53) {
|
||||
)
|
||||
}
|
||||
|
||||
private fun recreateMessagesTable(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS Messages")
|
||||
database.execSQL(
|
||||
private fun recreateMessagesTable(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE IF EXISTS Messages")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS `Messages` (
|
||||
`email` TEXT NOT NULL,
|
||||
|
@ -5,22 +5,24 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration54 : Migration(53, 54) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
migrateResman(database)
|
||||
removeTomaszowMazowieckiStudents(database)
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
migrateResman(db)
|
||||
removeTomaszowMazowieckiStudents(db)
|
||||
}
|
||||
|
||||
private fun migrateResman(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
private fun migrateResman(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
UPDATE Students SET
|
||||
scrapper_base_url = 'https://vulcan.net.pl',
|
||||
login_type = 'ADFSLightScoped',
|
||||
symbol = 'rzeszowprojekt'
|
||||
WHERE scrapper_base_url = 'https://resman.pl'
|
||||
""".trimIndent())
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
private fun removeTomaszowMazowieckiStudents(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DELETE FROM Students WHERE symbol = 'tomaszowmazowiecki'")
|
||||
private fun removeTomaszowMazowieckiStudents(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DELETE FROM Students WHERE symbol = 'tomaszowmazowiecki'")
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration6 : Migration(5, 6) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS ReportingUnits (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
@ -15,9 +16,11 @@ class Migration6 : Migration(5, 6) {
|
||||
sender_id INTEGER NOT NULL,
|
||||
sender_name TEXT NOT NULL,
|
||||
roles TEXT NOT NULL)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
database.execSQL("""
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS Recipients (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
@ -28,10 +31,11 @@ class Migration6 : Migration(5, 6) {
|
||||
unit_id INTEGER NOT NULL,
|
||||
role INTEGER NOT NULL,
|
||||
hash TEXT NOT NULL)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
database.execSQL("DELETE FROM Semesters WHERE 1")
|
||||
database.execSQL("ALTER TABLE Semesters ADD COLUMN class_id INTEGER DEFAULT 0 NOT NULL")
|
||||
database.execSQL("ALTER TABLE Semesters ADD COLUMN unit_id INTEGER DEFAULT 0 NOT NULL")
|
||||
db.execSQL("DELETE FROM Semesters WHERE 1")
|
||||
db.execSQL("ALTER TABLE Semesters ADD COLUMN class_id INTEGER DEFAULT 0 NOT NULL")
|
||||
db.execSQL("ALTER TABLE Semesters ADD COLUMN unit_id INTEGER DEFAULT 0 NOT NULL")
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration7 : Migration(6, 7) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS GradesStatistics (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
@ -15,6 +16,7 @@ class Migration7 : Migration(6, 7) {
|
||||
grade INTEGER NOT NULL,
|
||||
amount INTEGER NOT NULL,
|
||||
is_semester INTEGER NOT NULL)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration8 : Migration(7, 8) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE Timetable ADD COLUMN subjectOld TEXT DEFAULT \"\" NOT NULL")
|
||||
database.execSQL("ALTER TABLE Timetable ADD COLUMN roomOld TEXT DEFAULT \"\" NOT NULL")
|
||||
database.execSQL("ALTER TABLE Timetable ADD COLUMN teacherOld TEXT DEFAULT \"\" NOT NULL")
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE Timetable ADD COLUMN subjectOld TEXT DEFAULT \"\" NOT NULL")
|
||||
db.execSQL("ALTER TABLE Timetable ADD COLUMN roomOld TEXT DEFAULT \"\" NOT NULL")
|
||||
db.execSQL("ALTER TABLE Timetable ADD COLUMN teacherOld TEXT DEFAULT \"\" NOT NULL")
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,10 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration9 : Migration(8, 9) {
|
||||
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE IF EXISTS Messages")
|
||||
database.execSQL("""
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("DROP TABLE IF EXISTS Messages")
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS Messages (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
|
@ -35,12 +35,15 @@ class LuckyNumberRepository @Inject constructor(
|
||||
fetch = {
|
||||
sdk.init(student).getLuckyNumber(student.schoolShortName)?.mapToEntity(student)
|
||||
},
|
||||
saveFetchResult = { old, new ->
|
||||
if (new != old) {
|
||||
old?.let { luckyNumberDb.deleteAll(listOfNotNull(it)) }
|
||||
luckyNumberDb.insertAll(listOfNotNull((new?.apply {
|
||||
if (notify) isNotified = false
|
||||
})))
|
||||
saveFetchResult = { oldLuckyNumber, newLuckyNumber ->
|
||||
newLuckyNumber ?: return@networkBoundResource
|
||||
|
||||
if (newLuckyNumber != oldLuckyNumber) {
|
||||
val updatedLuckNumberList =
|
||||
listOf(newLuckyNumber.apply { if (notify) isNotified = false })
|
||||
|
||||
oldLuckyNumber?.let { luckyNumberDb.deleteAll(listOfNotNull(it)) }
|
||||
luckyNumberDb.insertAll(updatedLuckNumberList)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -9,7 +9,12 @@ import com.fredporciuncula.flow.preferences.Preference
|
||||
import com.fredporciuncula.flow.preferences.Serializer
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.enums.*
|
||||
import io.github.wulkanowy.data.enums.AppTheme
|
||||
import io.github.wulkanowy.data.enums.GradeColorTheme
|
||||
import io.github.wulkanowy.data.enums.GradeExpandMode
|
||||
import io.github.wulkanowy.data.enums.GradeSortingMode
|
||||
import io.github.wulkanowy.data.enums.TimetableGapsMode
|
||||
import io.github.wulkanowy.data.enums.TimetableMode
|
||||
import io.github.wulkanowy.ui.modules.dashboard.DashboardItem
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeAverageMode
|
||||
import io.github.wulkanowy.ui.modules.settings.appearance.menuorder.AppMenuItem
|
||||
@ -18,7 +23,7 @@ import kotlinx.coroutines.flow.map
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@ -303,19 +308,6 @@ class PreferencesRepository @Inject constructor(
|
||||
get() = sharedPref.getBoolean(PREF_KEY_APP_SUPPORT_SHOWN, false)
|
||||
set(value) = sharedPref.edit { putBoolean(PREF_KEY_APP_SUPPORT_SHOWN, value) }
|
||||
|
||||
var isAgreeToProcessData: Boolean
|
||||
get() = getBoolean(
|
||||
R.string.pref_key_ads_consent_data_processing,
|
||||
R.bool.pref_default_ads_consent_data_processing
|
||||
)
|
||||
set(value) = sharedPref.edit {
|
||||
putBoolean(context.getString(R.string.pref_key_ads_consent_data_processing), value)
|
||||
}
|
||||
|
||||
var isPersonalizedAdsEnabled: Boolean
|
||||
get() = sharedPref.getBoolean(PREF_KEY_PERSONALIZED_ADS_ENABLED, false)
|
||||
set(value) = sharedPref.edit { putBoolean(PREF_KEY_PERSONALIZED_ADS_ENABLED, value) }
|
||||
|
||||
val isAdsEnabledFlow = flowSharedPref.getBoolean(
|
||||
context.getString(R.string.pref_key_ads_enabled),
|
||||
context.resources.getBoolean(R.bool.pref_default_ads_enabled)
|
||||
@ -398,7 +390,6 @@ class PreferencesRepository @Inject constructor(
|
||||
private const val PREF_KEY_IN_APP_REVIEW_DATE = "in_app_review_date"
|
||||
private const val PREF_KEY_IN_APP_REVIEW_DONE = "in_app_review_done"
|
||||
private const val PREF_KEY_APP_SUPPORT_SHOWN = "app_support_shown"
|
||||
private const val PREF_KEY_PERSONALIZED_ADS_ENABLED = "personalized_ads_enabled"
|
||||
private const val PREF_KEY_ADMIN_DISMISSED_MESSAGE_IDS = "admin_message_dismissed_ids"
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package io.github.wulkanowy.data.repositories
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.withTransaction
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.data.db.AppDatabase
|
||||
import io.github.wulkanowy.data.db.dao.SemesterDao
|
||||
import io.github.wulkanowy.data.db.dao.StudentDao
|
||||
@ -17,20 +15,19 @@ import io.github.wulkanowy.data.pojos.RegisterUser
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.github.wulkanowy.utils.DispatchersProvider
|
||||
import io.github.wulkanowy.utils.init
|
||||
import io.github.wulkanowy.utils.security.decrypt
|
||||
import io.github.wulkanowy.utils.security.encrypt
|
||||
import io.github.wulkanowy.utils.security.Scrambler
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class StudentRepository @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
private val dispatchers: DispatchersProvider,
|
||||
private val studentDb: StudentDao,
|
||||
private val semesterDb: SemesterDao,
|
||||
private val sdk: Sdk,
|
||||
private val appDatabase: AppDatabase
|
||||
private val appDatabase: AppDatabase,
|
||||
private val scrambler: Scrambler,
|
||||
) {
|
||||
|
||||
suspend fun isCurrentStudentSet() = studentDb.loadCurrent()?.isCurrent ?: false
|
||||
@ -68,7 +65,7 @@ class StudentRepository @Inject constructor(
|
||||
student = student.apply {
|
||||
if (decryptPass && Sdk.Mode.valueOf(student.loginMode) != Sdk.Mode.HEBE) {
|
||||
student.password = withContext(dispatchers.io) {
|
||||
decrypt(student.password)
|
||||
scrambler.decrypt(student.password)
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -86,7 +83,7 @@ class StudentRepository @Inject constructor(
|
||||
}.apply {
|
||||
if (decryptPass && Sdk.Mode.valueOf(student.loginMode) != Sdk.Mode.HEBE) {
|
||||
student.password = withContext(dispatchers.io) {
|
||||
decrypt(student.password)
|
||||
scrambler.decrypt(student.password)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -96,7 +93,7 @@ class StudentRepository @Inject constructor(
|
||||
|
||||
if (decryptPass && Sdk.Mode.valueOf(student.loginMode) != Sdk.Mode.HEBE) {
|
||||
student.password = withContext(dispatchers.io) {
|
||||
decrypt(student.password)
|
||||
scrambler.decrypt(student.password)
|
||||
}
|
||||
}
|
||||
return student
|
||||
@ -107,7 +104,7 @@ class StudentRepository @Inject constructor(
|
||||
|
||||
if (decryptPass && Sdk.Mode.valueOf(student.loginMode) != Sdk.Mode.HEBE) {
|
||||
student.password = withContext(dispatchers.io) {
|
||||
decrypt(student.password)
|
||||
scrambler.decrypt(student.password)
|
||||
}
|
||||
}
|
||||
return student
|
||||
@ -120,7 +117,7 @@ class StudentRepository @Inject constructor(
|
||||
it.apply {
|
||||
if (Sdk.Mode.valueOf(it.loginMode) != Sdk.Mode.HEBE) {
|
||||
password = withContext(dispatchers.io) {
|
||||
encrypt(password, context)
|
||||
scrambler.encrypt(password)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -166,4 +163,15 @@ class StudentRepository @Inject constructor(
|
||||
|
||||
studentDb.update(studentName)
|
||||
}
|
||||
|
||||
suspend fun deleteStudentsAssociatedWithAccount(student: Student) {
|
||||
studentDb.deleteByEmailAndUserName(student.email, student.userName)
|
||||
}
|
||||
|
||||
suspend fun clearAll() {
|
||||
withContext(dispatchers.io) {
|
||||
scrambler.clearKeyPair()
|
||||
appDatabase.clearAllTables()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,8 +65,6 @@ class TimetableNotificationSchedulerHelper @Inject constructor(
|
||||
range = lesson.start..lesson.end,
|
||||
requestCode = getRequestCode(lesson.start, studentId)
|
||||
)
|
||||
|
||||
Timber.d("TimetableNotification canceled: type 1 & 2, subject: ${lesson.subject}, start: ${lesson.start}, student: $studentId")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.google.android.material.snackbar.Snackbar
|
||||
import com.google.android.material.snackbar.Snackbar.LENGTH_LONG
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.modules.auth.AuthDialog
|
||||
import io.github.wulkanowy.ui.modules.captcha.CaptchaDialog
|
||||
import io.github.wulkanowy.ui.modules.login.LoginActivity
|
||||
import io.github.wulkanowy.utils.FragmentLifecycleLogger
|
||||
import io.github.wulkanowy.utils.getThemeAttrColor
|
||||
@ -68,11 +69,24 @@ abstract class BaseActivity<T : BasePresenter<out BaseView>, VB : ViewBinding> :
|
||||
} else Toast.makeText(this, text, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
override fun showExpiredDialog() {
|
||||
override fun showExpiredCredentialsDialog() {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.main_expired_credentials_title)
|
||||
.setMessage(R.string.main_expired_credentials_description)
|
||||
.setPositiveButton(R.string.main_log_in) { _, _ -> presenter.onConfirmExpiredCredentialsSelected() }
|
||||
.setNegativeButton(android.R.string.cancel) { _, _ -> }
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun onCaptchaVerificationRequired(url: String?) {
|
||||
CaptchaDialog.newInstance(url).show(supportFragmentManager, "captcha_dialog")
|
||||
}
|
||||
|
||||
override fun showDecryptionFailedDialog() {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.main_session_expired)
|
||||
.setMessage(R.string.main_session_relogin)
|
||||
.setPositiveButton(R.string.main_log_in) { _, _ -> presenter.onExpiredLoginSelected() }
|
||||
.setPositiveButton(R.string.main_log_in) { _, _ -> presenter.onConfirmDecryptionFailedSelected() }
|
||||
.setNegativeButton(android.R.string.cancel) { _, _ -> }
|
||||
.show()
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import android.widget.Toast
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.google.android.material.elevation.SurfaceColors
|
||||
import io.github.wulkanowy.ui.modules.auth.AuthDialog
|
||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||
import io.github.wulkanowy.utils.lifecycleAwareVariable
|
||||
import javax.inject.Inject
|
||||
@ -28,8 +27,16 @@ abstract class BaseDialogFragment<VB : ViewBinding> : DialogFragment(), BaseView
|
||||
Toast.makeText(context, text, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
override fun showExpiredDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showExpiredDialog()
|
||||
override fun showExpiredCredentialsDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showExpiredCredentialsDialog()
|
||||
}
|
||||
|
||||
override fun onCaptchaVerificationRequired(url: String?) {
|
||||
(activity as? BaseActivity<*, *>)?.onCaptchaVerificationRequired(url)
|
||||
}
|
||||
|
||||
override fun showDecryptionFailedDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showDecryptionFailedDialog()
|
||||
}
|
||||
|
||||
override fun openClearLoginView() {
|
||||
@ -41,7 +48,7 @@ abstract class BaseDialogFragment<VB : ViewBinding> : DialogFragment(), BaseView
|
||||
}
|
||||
|
||||
override fun showAuthDialog() {
|
||||
AuthDialog.newInstance().show(childFragmentManager, "auth_dialog")
|
||||
(activity as? BaseActivity<*, *>)?.showAuthDialog()
|
||||
}
|
||||
|
||||
override fun showErrorDetailsDialog(error: Throwable) {
|
||||
|
@ -7,7 +7,6 @@ import androidx.viewbinding.ViewBinding
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.google.android.material.snackbar.Snackbar.LENGTH_LONG
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.modules.auth.AuthDialog
|
||||
import io.github.wulkanowy.utils.lifecycleAwareVariable
|
||||
|
||||
abstract class BaseFragment<VB : ViewBinding>(@LayoutRes layoutId: Int) : Fragment(layoutId),
|
||||
@ -39,12 +38,20 @@ abstract class BaseFragment<VB : ViewBinding>(@LayoutRes layoutId: Int) : Fragme
|
||||
}
|
||||
}
|
||||
|
||||
override fun showExpiredDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showExpiredDialog()
|
||||
override fun showExpiredCredentialsDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showExpiredCredentialsDialog()
|
||||
}
|
||||
|
||||
override fun onCaptchaVerificationRequired(url: String?) {
|
||||
(activity as? BaseActivity<*, *>)?.onCaptchaVerificationRequired(url)
|
||||
}
|
||||
|
||||
override fun showDecryptionFailedDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showDecryptionFailedDialog()
|
||||
}
|
||||
|
||||
override fun showAuthDialog() {
|
||||
AuthDialog.newInstance().show(childFragmentManager, "auth_dialog")
|
||||
(activity as? BaseActivity<*, *>)?.showAuthDialog()
|
||||
}
|
||||
|
||||
override fun openClearLoginView() {
|
||||
|
@ -28,20 +28,38 @@ open class BasePresenter<T : BaseView>(
|
||||
this.view = view
|
||||
errorHandler.apply {
|
||||
showErrorMessage = view::showError
|
||||
onSessionExpired = view::showExpiredDialog
|
||||
onExpiredCredentials = view::showExpiredCredentialsDialog
|
||||
onCaptchaVerificationRequired = view::onCaptchaVerificationRequired
|
||||
onDecryptionFailed = view::showDecryptionFailedDialog
|
||||
onNoCurrentStudent = view::openClearLoginView
|
||||
onPasswordChangeRequired = view::showChangePasswordSnackbar
|
||||
onAuthorizationRequired = view::showAuthDialog
|
||||
}
|
||||
}
|
||||
|
||||
fun onExpiredLoginSelected() {
|
||||
Timber.i("Attempt to switch the student after the session expires")
|
||||
fun onConfirmDecryptionFailedSelected() {
|
||||
Timber.i("Attempt to clear all data")
|
||||
|
||||
presenterScope.launch {
|
||||
runCatching { studentRepository.clearAll() }
|
||||
.onFailure {
|
||||
Timber.i("Clear data result: An exception occurred")
|
||||
errorHandler.dispatch(it)
|
||||
}
|
||||
.onSuccess {
|
||||
Timber.i("Clear data result: Open login view")
|
||||
view?.openClearLoginView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onConfirmExpiredCredentialsSelected() {
|
||||
Timber.i("Attempt to delete students associated with the account and switch to new student")
|
||||
|
||||
presenterScope.launch {
|
||||
runCatching {
|
||||
val student = studentRepository.getCurrentStudent(false)
|
||||
studentRepository.logoutStudent(student)
|
||||
studentRepository.deleteStudentsAssociatedWithAccount(student)
|
||||
|
||||
val students = studentRepository.getSavedStudents(false)
|
||||
if (students.isNotEmpty()) {
|
||||
@ -50,11 +68,11 @@ open class BasePresenter<T : BaseView>(
|
||||
}
|
||||
}
|
||||
.onFailure {
|
||||
Timber.i("Switch student result: An exception occurred")
|
||||
Timber.i("Delete students result: An exception occurred")
|
||||
errorHandler.dispatch(it)
|
||||
}
|
||||
.onSuccess {
|
||||
Timber.i("Switch student result: Open login view")
|
||||
Timber.i("Delete students result: Open login view")
|
||||
view?.openClearLoginView()
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,11 @@ interface BaseView {
|
||||
|
||||
fun showMessage(text: String)
|
||||
|
||||
fun showExpiredDialog()
|
||||
fun showExpiredCredentialsDialog()
|
||||
|
||||
fun onCaptchaVerificationRequired(url: String?)
|
||||
|
||||
fun showDecryptionFailedDialog()
|
||||
|
||||
fun showAuthDialog()
|
||||
|
||||
|
@ -4,6 +4,7 @@ import android.content.Context
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.data.exceptions.NoCurrentStudentException
|
||||
import io.github.wulkanowy.sdk.scrapper.exception.AuthorizationRequiredException
|
||||
import io.github.wulkanowy.sdk.scrapper.exception.CloudflareVerificationException
|
||||
import io.github.wulkanowy.sdk.scrapper.login.BadCredentialsException
|
||||
import io.github.wulkanowy.sdk.scrapper.login.PasswordChangeRequiredException
|
||||
import io.github.wulkanowy.utils.getErrorString
|
||||
@ -15,7 +16,9 @@ open class ErrorHandler @Inject constructor(@ApplicationContext protected val co
|
||||
|
||||
var showErrorMessage: (String, Throwable) -> Unit = { _, _ -> }
|
||||
|
||||
var onSessionExpired: () -> Unit = {}
|
||||
var onExpiredCredentials: () -> Unit = {}
|
||||
|
||||
var onDecryptionFailed: () -> Unit = {}
|
||||
|
||||
var onNoCurrentStudent: () -> Unit = {}
|
||||
|
||||
@ -23,6 +26,8 @@ open class ErrorHandler @Inject constructor(@ApplicationContext protected val co
|
||||
|
||||
var onAuthorizationRequired: () -> Unit = {}
|
||||
|
||||
var onCaptchaVerificationRequired: (url: String?) -> Unit = {}
|
||||
|
||||
fun dispatch(error: Throwable) {
|
||||
Timber.e(error, "An exception occurred while the Wulkanowy was running")
|
||||
proceed(error)
|
||||
@ -32,15 +37,18 @@ open class ErrorHandler @Inject constructor(@ApplicationContext protected val co
|
||||
showErrorMessage(context.resources.getErrorString(error), error)
|
||||
when (error) {
|
||||
is PasswordChangeRequiredException -> onPasswordChangeRequired(error.redirectUrl)
|
||||
is ScramblerException, is BadCredentialsException -> onSessionExpired()
|
||||
is ScramblerException -> onDecryptionFailed()
|
||||
is BadCredentialsException -> onExpiredCredentials()
|
||||
is NoCurrentStudentException -> onNoCurrentStudent()
|
||||
is AuthorizationRequiredException -> onAuthorizationRequired()
|
||||
is CloudflareVerificationException -> onCaptchaVerificationRequired(error.originalUrl)
|
||||
}
|
||||
}
|
||||
|
||||
open fun clear() {
|
||||
showErrorMessage = { _, _ -> }
|
||||
onSessionExpired = {}
|
||||
onExpiredCredentials = {}
|
||||
onDecryptionFailed = {}
|
||||
onNoCurrentStudent = {}
|
||||
onPasswordChangeRequired = {}
|
||||
onAuthorizationRequired = {}
|
||||
|
@ -0,0 +1,86 @@
|
||||
package io.github.wulkanowy.ui.modules.captcha
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.core.os.bundleOf
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.databinding.DialogCaptchaBinding
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.github.wulkanowy.ui.base.BaseDialogFragment
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class CaptchaDialog : BaseDialogFragment<DialogCaptchaBinding>() {
|
||||
|
||||
@Inject
|
||||
lateinit var sdk: Sdk
|
||||
|
||||
private var webView: WebView? = null
|
||||
|
||||
companion object {
|
||||
const val CAPTCHA_SUCCESS = "captcha_success"
|
||||
private const val CAPTCHA_URL = "captcha_url"
|
||||
private const val CAPTCHA_CHECK_JS = "document.getElementById('challenge-running') == null"
|
||||
|
||||
fun newInstance(url: String?): CaptchaDialog {
|
||||
return CaptchaDialog().apply {
|
||||
arguments = bundleOf(CAPTCHA_URL to url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View = DialogCaptchaBinding.inflate(inflater).apply { binding = this }.root
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
isCancelable = false
|
||||
binding.captchaRefresh.setOnClickListener {
|
||||
binding.captchaWebview.loadUrl(arguments?.getString(CAPTCHA_URL).orEmpty())
|
||||
}
|
||||
binding.captchaClose.setOnClickListener { dismiss() }
|
||||
|
||||
with(binding.captchaWebview) {
|
||||
webView = this
|
||||
with(settings) {
|
||||
javaScriptEnabled = true
|
||||
userAgentString = sdk.userAgent
|
||||
}
|
||||
|
||||
webViewClient = object : WebViewClient() {
|
||||
override fun onPageFinished(view: WebView?, url: String?) {
|
||||
view?.evaluateJavascript(CAPTCHA_CHECK_JS) {
|
||||
if (it == "true") {
|
||||
onChallengeAccepted()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadUrl(arguments?.getString(CAPTCHA_URL).orEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
private fun onChallengeAccepted() {
|
||||
runCatching { parentFragmentManager.setFragmentResult(CAPTCHA_SUCCESS, bundleOf()) }
|
||||
.onFailure { Timber.e(it) }
|
||||
showMessage(getString(R.string.captcha_verified_message))
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
webView?.destroy()
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ import io.github.wulkanowy.databinding.FragmentDashboardBinding
|
||||
import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.modules.account.accountdetails.AccountDetailsFragment
|
||||
import io.github.wulkanowy.ui.modules.attendance.summary.AttendanceSummaryFragment
|
||||
import io.github.wulkanowy.ui.modules.captcha.CaptchaDialog.Companion.CAPTCHA_SUCCESS
|
||||
import io.github.wulkanowy.ui.modules.conference.ConferenceFragment
|
||||
import io.github.wulkanowy.ui.modules.dashboard.adapters.DashboardAdapter
|
||||
import io.github.wulkanowy.ui.modules.exam.ExamFragment
|
||||
@ -30,7 +31,13 @@ import io.github.wulkanowy.ui.modules.message.MessageFragment
|
||||
import io.github.wulkanowy.ui.modules.notificationscenter.NotificationsCenterFragment
|
||||
import io.github.wulkanowy.ui.modules.schoolannouncement.SchoolAnnouncementFragment
|
||||
import io.github.wulkanowy.ui.modules.timetable.TimetableFragment
|
||||
import io.github.wulkanowy.utils.*
|
||||
import io.github.wulkanowy.utils.capitalise
|
||||
import io.github.wulkanowy.utils.dpToPx
|
||||
import io.github.wulkanowy.utils.getErrorString
|
||||
import io.github.wulkanowy.utils.getThemeAttrColor
|
||||
import io.github.wulkanowy.utils.openInternetBrowser
|
||||
import io.github.wulkanowy.utils.toFormattedString
|
||||
import timber.log.Timber
|
||||
import java.time.LocalDate
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -57,6 +64,9 @@ class DashboardFragment : BaseFragment<FragmentDashboardBinding>(R.layout.fragme
|
||||
return ((recyclerWidth - margin) / resources.displayMetrics.density).toInt()
|
||||
}
|
||||
|
||||
override val isViewEmpty
|
||||
get() = dashboardAdapter.itemCount == 0
|
||||
|
||||
companion object {
|
||||
|
||||
fun newInstance() = DashboardFragment()
|
||||
@ -72,6 +82,13 @@ class DashboardFragment : BaseFragment<FragmentDashboardBinding>(R.layout.fragme
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
binding = FragmentDashboardBinding.bind(view)
|
||||
presenter.onAttachView(this)
|
||||
initializeCaptchaResultObserver()
|
||||
}
|
||||
|
||||
private fun initializeCaptchaResultObserver() {
|
||||
childFragmentManager.setFragmentResultListener(CAPTCHA_SUCCESS, this) { _, _ ->
|
||||
presenter.onRetryAfterCaptcha()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
|
@ -1,19 +1,46 @@
|
||||
package io.github.wulkanowy.ui.modules.dashboard
|
||||
|
||||
import io.github.wulkanowy.data.*
|
||||
import io.github.wulkanowy.data.Resource
|
||||
import io.github.wulkanowy.data.dataOrNull
|
||||
import io.github.wulkanowy.data.db.entities.AdminMessage
|
||||
import io.github.wulkanowy.data.db.entities.LuckyNumber
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.enums.MessageFolder
|
||||
import io.github.wulkanowy.data.enums.MessageType
|
||||
import io.github.wulkanowy.data.repositories.*
|
||||
import io.github.wulkanowy.data.errorOrNull
|
||||
import io.github.wulkanowy.data.flatResourceFlow
|
||||
import io.github.wulkanowy.data.mapResourceData
|
||||
import io.github.wulkanowy.data.onResourceError
|
||||
import io.github.wulkanowy.data.repositories.AttendanceSummaryRepository
|
||||
import io.github.wulkanowy.data.repositories.ConferenceRepository
|
||||
import io.github.wulkanowy.data.repositories.ExamRepository
|
||||
import io.github.wulkanowy.data.repositories.GradeRepository
|
||||
import io.github.wulkanowy.data.repositories.HomeworkRepository
|
||||
import io.github.wulkanowy.data.repositories.LuckyNumberRepository
|
||||
import io.github.wulkanowy.data.repositories.MessageRepository
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.data.repositories.SchoolAnnouncementRepository
|
||||
import io.github.wulkanowy.data.repositories.SemesterRepository
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.data.repositories.TimetableRepository
|
||||
import io.github.wulkanowy.domain.adminmessage.GetAppropriateAdminMessageUseCase
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
import io.github.wulkanowy.utils.AdsHelper
|
||||
import io.github.wulkanowy.utils.calculatePercentage
|
||||
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.emitAll
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.filterNot
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.merge
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import java.time.Instant
|
||||
@ -48,6 +75,11 @@ class DashboardPresenter @Inject constructor(
|
||||
|
||||
private val firstLoadedItemList = mutableListOf<DashboardItem.Type>()
|
||||
|
||||
private val selectedDashboardTiles
|
||||
get() = preferencesRepository.selectedDashboardTiles
|
||||
.filterNot { it == DashboardItem.Tile.ADS && !adsHelper.canShowAd }
|
||||
.toSet()
|
||||
|
||||
private lateinit var lastError: Throwable
|
||||
|
||||
override fun onAttachView(view: DashboardView) {
|
||||
@ -59,10 +91,19 @@ class DashboardPresenter @Inject constructor(
|
||||
showContent(false)
|
||||
}
|
||||
|
||||
val selectedDashboardTilesFlow = preferencesRepository.selectedDashboardTilesFlow
|
||||
.map { selectedDashboardTiles }
|
||||
val isAdsEnabledFlow = preferencesRepository.isAdsEnabledFlow
|
||||
.filter { (adsHelper.canShowAd && it) || !it }
|
||||
.map { selectedDashboardTiles }
|
||||
val isMobileAdsSdkInitializedFlow = adsHelper.isMobileAdsSdkInitialized
|
||||
.filter { it }
|
||||
.map { selectedDashboardTiles }
|
||||
|
||||
merge(
|
||||
preferencesRepository.selectedDashboardTilesFlow,
|
||||
preferencesRepository.isAdsEnabledFlow
|
||||
.map { preferencesRepository.selectedDashboardTiles }
|
||||
selectedDashboardTilesFlow,
|
||||
isAdsEnabledFlow,
|
||||
isMobileAdsSdkInitializedFlow
|
||||
)
|
||||
.onEach { loadData(tilesToLoad = it) }
|
||||
.launch("dashboard_pref")
|
||||
@ -71,7 +112,7 @@ class DashboardPresenter @Inject constructor(
|
||||
fun onAdminMessageDismissed(adminMessage: AdminMessage) {
|
||||
preferencesRepository.dismissedAdminMessageIds += adminMessage.id
|
||||
|
||||
loadData(preferencesRepository.selectedDashboardTiles)
|
||||
loadData(selectedDashboardTiles)
|
||||
}
|
||||
|
||||
fun onDragAndDropEnd(list: List<DashboardItem>) {
|
||||
@ -187,7 +228,7 @@ class DashboardPresenter @Inject constructor(
|
||||
|
||||
fun onSwipeRefresh() {
|
||||
Timber.i("Force refreshing the dashboard")
|
||||
loadData(preferencesRepository.selectedDashboardTiles, forceRefresh = true)
|
||||
loadData(selectedDashboardTiles, forceRefresh = true)
|
||||
}
|
||||
|
||||
fun onRetry() {
|
||||
@ -195,7 +236,15 @@ class DashboardPresenter @Inject constructor(
|
||||
showErrorView(false)
|
||||
showProgress(true)
|
||||
}
|
||||
loadData(preferencesRepository.selectedDashboardTiles, forceRefresh = true)
|
||||
loadData(selectedDashboardTiles, forceRefresh = true)
|
||||
}
|
||||
|
||||
fun onRetryAfterCaptcha() {
|
||||
view?.run {
|
||||
showErrorView(false)
|
||||
showProgress(true)
|
||||
}
|
||||
loadData(selectedDashboardTiles, forceRefresh = true)
|
||||
}
|
||||
|
||||
fun onViewReselected() {
|
||||
@ -216,7 +265,7 @@ class DashboardPresenter @Inject constructor(
|
||||
}
|
||||
|
||||
fun onDashboardTileSettingsSelected(): Boolean {
|
||||
view?.showDashboardTileSettings(preferencesRepository.selectedDashboardTiles.toList())
|
||||
view?.showDashboardTileSettings(selectedDashboardTiles.toList())
|
||||
return true
|
||||
}
|
||||
|
||||
@ -232,7 +281,7 @@ class DashboardPresenter @Inject constructor(
|
||||
|
||||
private fun loadHorizontalGroup(student: Student, forceRefresh: Boolean) {
|
||||
flow {
|
||||
val selectedTiles = preferencesRepository.selectedDashboardTiles
|
||||
val selectedTiles = selectedDashboardTiles
|
||||
val flowSuccess = flowOf(Resource.Success(null))
|
||||
|
||||
val luckyNumberFlow = luckyNumberRepository.getLuckyNumber(student, forceRefresh)
|
||||
@ -275,7 +324,7 @@ class DashboardPresenter @Inject constructor(
|
||||
) { luckyNumberResource, messageResource, attendanceResource ->
|
||||
val resList = listOf(luckyNumberResource, messageResource, attendanceResource)
|
||||
|
||||
DashboardItem.HorizontalGroup(
|
||||
resList to DashboardItem.HorizontalGroup(
|
||||
isLoading = resList.any { it is Resource.Loading },
|
||||
error = resList.map { it.errorOrNull }.let { errors ->
|
||||
if (errors.all { it != null }) {
|
||||
@ -300,9 +349,9 @@ class DashboardPresenter @Inject constructor(
|
||||
)
|
||||
})
|
||||
}
|
||||
.filterNot { it.isLoading && forceRefresh }
|
||||
.filterNot { (_, it) -> it.isLoading && forceRefresh }
|
||||
.distinctUntilChanged()
|
||||
.onEach {
|
||||
.onEach { (_, it) ->
|
||||
updateData(it, forceRefresh)
|
||||
|
||||
if (it.isLoading) {
|
||||
@ -320,7 +369,7 @@ class DashboardPresenter @Inject constructor(
|
||||
)
|
||||
errorHandler.dispatch(it)
|
||||
}
|
||||
.launch("horizontal_group ${if (forceRefresh) "-forceRefresh" else ""}")
|
||||
.launchWithUniqueRefreshJob("horizontal_group", forceRefresh)
|
||||
}
|
||||
|
||||
private fun loadGrades(student: Student, forceRefresh: Boolean) {
|
||||
@ -813,6 +862,28 @@ class DashboardPresenter @Inject constructor(
|
||||
onEach {
|
||||
if (it is Resource.Success) {
|
||||
cancelJobs(jobName)
|
||||
} else if (it is Resource.Error) {
|
||||
cancelJobs(jobName)
|
||||
}
|
||||
}.launch(jobName)
|
||||
} else {
|
||||
launch(jobName)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmName("launchWithUniqueRefreshJobHorizontalGroup")
|
||||
private fun Flow<Pair<List<Resource<*>>, *>>.launchWithUniqueRefreshJob(
|
||||
name: String,
|
||||
forceRefresh: Boolean
|
||||
) {
|
||||
val jobName = if (forceRefresh) "$name-forceRefresh" else name
|
||||
|
||||
if (forceRefresh) {
|
||||
onEach { (resources, _) ->
|
||||
if (resources.all { it is Resource.Success<*> }) {
|
||||
cancelJobs(jobName)
|
||||
} else if (resources.any { it is Resource.Error<*> }) {
|
||||
cancelJobs(jobName)
|
||||
}
|
||||
}.launch(jobName)
|
||||
} else {
|
||||
|
@ -6,6 +6,8 @@ interface DashboardView : BaseView {
|
||||
|
||||
val tileWidth: Int
|
||||
|
||||
val isViewEmpty: Boolean
|
||||
|
||||
fun initView()
|
||||
|
||||
fun updateData(data: List<DashboardItem>)
|
||||
@ -27,6 +29,5 @@ interface DashboardView : BaseView {
|
||||
fun popViewToRoot()
|
||||
|
||||
fun openNotificationsCenterView()
|
||||
|
||||
fun openInternetBrowser(url: String)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.github.wulkanowy.ui.modules.debug
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.webkit.CookieManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import io.github.wulkanowy.R
|
||||
@ -58,6 +59,10 @@ class DebugFragment : BaseFragment<FragmentDebugBinding>(R.layout.fragment_debug
|
||||
(activity as? MainActivity)?.pushView(NotificationDebugFragment.newInstance())
|
||||
}
|
||||
|
||||
override fun clearWebkitCookies() {
|
||||
CookieManager.getInstance().removeAllCookies(null)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
presenter.onDetachView()
|
||||
super.onDestroyView()
|
||||
|
@ -15,6 +15,7 @@ class DebugPresenter @Inject constructor(
|
||||
val items = listOf(
|
||||
DebugItem(R.string.logviewer_title),
|
||||
DebugItem(R.string.notification_debug_title),
|
||||
DebugItem(R.string.debug_cookies_clear),
|
||||
)
|
||||
|
||||
override fun onAttachView(view: DebugView) {
|
||||
@ -31,6 +32,7 @@ class DebugPresenter @Inject constructor(
|
||||
when (item.title) {
|
||||
R.string.logviewer_title -> view?.openLogViewer()
|
||||
R.string.notification_debug_title -> view?.openNotificationsDebug()
|
||||
R.string.debug_cookies_clear -> view?.clearWebkitCookies()
|
||||
else -> Timber.d("Unknown debug item: $item")
|
||||
}
|
||||
}
|
||||
|
@ -11,4 +11,6 @@ interface DebugView : BaseView {
|
||||
fun openLogViewer()
|
||||
|
||||
fun openNotificationsDebug()
|
||||
|
||||
fun clearWebkitCookies()
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class GradeSummaryPresenter @Inject constructor(
|
||||
val student = studentRepository.getCurrentStudent()
|
||||
averageProvider.getGradesDetailsWithAverage(student, semesterId, forceRefresh)
|
||||
}
|
||||
.logResourceStatus("load grade summary", showData = true)
|
||||
.logResourceStatus("load grade summary")
|
||||
.mapResourceData { createGradeSummaryItems(it) }
|
||||
.onResourceData {
|
||||
view?.run {
|
||||
|
@ -23,7 +23,7 @@ import io.github.wulkanowy.ui.modules.login.symbol.LoginSymbolFragment
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.ui.modules.notifications.NotificationsFragment
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.UpdateHelper
|
||||
import io.github.wulkanowy.utils.InAppUpdateHelper
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
@ -33,7 +33,7 @@ class LoginActivity : BaseActivity<LoginPresenter, ActivityLoginBinding>(), Logi
|
||||
override lateinit var presenter: LoginPresenter
|
||||
|
||||
@Inject
|
||||
lateinit var updateHelper: UpdateHelper
|
||||
lateinit var inAppUpdateHelper: InAppUpdateHelper
|
||||
|
||||
@Inject
|
||||
lateinit var appInfo: AppInfo
|
||||
@ -47,10 +47,10 @@ class LoginActivity : BaseActivity<LoginPresenter, ActivityLoginBinding>(), Logi
|
||||
setContentView(ActivityLoginBinding.inflate(layoutInflater).apply { binding = this }.root)
|
||||
setSupportActionBar(binding.loginToolbar)
|
||||
messageContainer = binding.loginContainer
|
||||
updateHelper.messageContainer = binding.loginContainer
|
||||
inAppUpdateHelper.messageContainer = binding.loginContainer
|
||||
|
||||
presenter.onAttachView(this)
|
||||
updateHelper.checkAndInstallUpdates(this)
|
||||
inAppUpdateHelper.checkAndInstallUpdates()
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
openFragment(LoginFormFragment.newInstance(), clearBackStack = true)
|
||||
@ -117,14 +117,6 @@ class LoginActivity : BaseActivity<LoginPresenter, ActivityLoginBinding>(), Logi
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
updateHelper.onResume(this)
|
||||
}
|
||||
|
||||
//https://developer.android.com/guide/playcore/in-app-updates#status_callback
|
||||
@Deprecated("Deprecated in Java")
|
||||
@Suppress("DEPRECATION")
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
updateHelper.onActivityResult(requestCode, resultCode)
|
||||
inAppUpdateHelper.onResume()
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
import androidx.fragment.app.setFragmentResultListener
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.AdminMessage
|
||||
@ -14,6 +15,7 @@ import io.github.wulkanowy.data.pojos.RegisterUser
|
||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||
import io.github.wulkanowy.databinding.FragmentLoginFormBinding
|
||||
import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.modules.captcha.CaptchaDialog
|
||||
import io.github.wulkanowy.ui.modules.dashboard.viewholders.AdminMessageViewHolder
|
||||
import io.github.wulkanowy.ui.modules.login.LoginActivity
|
||||
import io.github.wulkanowy.ui.modules.login.LoginData
|
||||
@ -72,6 +74,13 @@ class LoginFormFragment : BaseFragment<FragmentLoginFormBinding>(R.layout.fragme
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
binding = FragmentLoginFormBinding.bind(view)
|
||||
presenter.onAttachView(this)
|
||||
initializeCaptchaResultObserver()
|
||||
}
|
||||
|
||||
private fun initializeCaptchaResultObserver() {
|
||||
setFragmentResultListener(CaptchaDialog.CAPTCHA_SUCCESS) { _, _ ->
|
||||
presenter.onRetryAfterCaptcha()
|
||||
}
|
||||
}
|
||||
|
||||
override fun initView() {
|
||||
|
@ -152,6 +152,10 @@ class LoginFormPresenter @Inject constructor(
|
||||
)
|
||||
}
|
||||
|
||||
fun onRetryAfterCaptcha() {
|
||||
onSignInClick()
|
||||
}
|
||||
|
||||
fun onSignInClick() {
|
||||
val loginData = getLoginData()
|
||||
|
||||
|
@ -9,9 +9,14 @@ import android.view.MenuItem
|
||||
import android.view.ViewGroup.MarginLayoutParams
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.addCallback
|
||||
import androidx.core.view.*
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
@ -23,16 +28,32 @@ import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
||||
import io.github.wulkanowy.databinding.ActivityMainBinding
|
||||
import io.github.wulkanowy.databinding.DialogAdsConsentBinding
|
||||
import io.github.wulkanowy.ui.base.BaseActivity
|
||||
import io.github.wulkanowy.ui.modules.Destination
|
||||
import io.github.wulkanowy.ui.modules.account.accountquick.AccountQuickDialog
|
||||
import io.github.wulkanowy.ui.modules.auth.AuthDialog
|
||||
import io.github.wulkanowy.ui.modules.captcha.CaptchaDialog
|
||||
import io.github.wulkanowy.ui.modules.settings.appearance.menuorder.AppMenuItem
|
||||
import io.github.wulkanowy.utils.*
|
||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.InAppReviewHelper
|
||||
import io.github.wulkanowy.utils.InAppUpdateHelper
|
||||
import io.github.wulkanowy.utils.createNameInitialsDrawable
|
||||
import io.github.wulkanowy.utils.dpToPx
|
||||
import io.github.wulkanowy.utils.nickOrName
|
||||
import io.github.wulkanowy.utils.safelyPopFragments
|
||||
import io.github.wulkanowy.utils.setOnViewChangeListener
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainView,
|
||||
@ -45,7 +66,7 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
|
||||
lateinit var analytics: AnalyticsHelper
|
||||
|
||||
@Inject
|
||||
lateinit var updateHelper: UpdateHelper
|
||||
lateinit var inAppUpdateHelper: InAppUpdateHelper
|
||||
|
||||
@Inject
|
||||
lateinit var inAppReviewHelper: InAppReviewHelper
|
||||
@ -62,6 +83,8 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
|
||||
private val navController =
|
||||
FragNavController(supportFragmentManager, R.id.main_fragment_container)
|
||||
|
||||
private val captchaVerificationEvent = MutableSharedFlow<String?>()
|
||||
|
||||
companion object {
|
||||
|
||||
private const val EXTRA_START_DESTINATION = "start_destination_json"
|
||||
@ -100,7 +123,7 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
|
||||
this.savedInstanceState = savedInstanceState
|
||||
messageContainer = binding.mainMessageContainer
|
||||
messageAnchor = binding.mainMessageContainer
|
||||
updateHelper.messageContainer = binding.mainFragmentContainer
|
||||
inAppUpdateHelper.messageContainer = binding.mainFragmentContainer
|
||||
onBackCallback = onBackPressedDispatcher.addCallback(this, enabled = false) {
|
||||
presenter.onBackPressed()
|
||||
}
|
||||
@ -109,19 +132,12 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
|
||||
?.takeIf { savedInstanceState == null }
|
||||
|
||||
presenter.onAttachView(this, destination)
|
||||
updateHelper.checkAndInstallUpdates(this)
|
||||
inAppUpdateHelper.checkAndInstallUpdates()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
updateHelper.onResume(this)
|
||||
}
|
||||
|
||||
//https://developer.android.com/guide/playcore/in-app-updates#status_callback
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
updateHelper.onActivityResult(requestCode, resultCode)
|
||||
inAppUpdateHelper.onResume()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
@ -140,6 +156,7 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
|
||||
initializeToolbar()
|
||||
initializeBottomNavigation(startMenuIndex, rootAppMenuItems)
|
||||
initializeNavController(startMenuIndex, rootUpdatedDestinations)
|
||||
initializeCaptchaVerificationEvent()
|
||||
}
|
||||
|
||||
private fun initializeNavController(
|
||||
@ -319,38 +336,25 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun showPrivacyPolicyDialog() {
|
||||
val dialogAdsConsentBinding = DialogAdsConsentBinding.inflate(layoutInflater)
|
||||
|
||||
val dialog = MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.pref_ads_consent_title)
|
||||
.setMessage(R.string.pref_ads_consent_description)
|
||||
.setView(dialogAdsConsentBinding.root)
|
||||
.show()
|
||||
|
||||
dialogAdsConsentBinding.adsConsentOver.setOnCheckedChangeListener { _, isChecked ->
|
||||
dialogAdsConsentBinding.adsConsentPersonalised.isEnabled = isChecked
|
||||
}
|
||||
|
||||
dialogAdsConsentBinding.adsConsentPersonalised.setOnClickListener {
|
||||
presenter.onPrivacyAgree(true)
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
dialogAdsConsentBinding.adsConsentNonPersonalised.setOnClickListener {
|
||||
presenter.onPrivacyAgree(false)
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
dialogAdsConsentBinding.adsConsentPrivacy.setOnClickListener { presenter.onPrivacySelected() }
|
||||
dialogAdsConsentBinding.adsConsentCancel.setOnClickListener { dialog.cancel() }
|
||||
@OptIn(FlowPreview::class)
|
||||
private fun initializeCaptchaVerificationEvent() {
|
||||
captchaVerificationEvent
|
||||
.debounce(1.seconds)
|
||||
.onEach { url ->
|
||||
Timber.d("Showing captcha dialog for: $url")
|
||||
showDialogFragment(CaptchaDialog.newInstance(url))
|
||||
}
|
||||
.launchIn(lifecycleScope)
|
||||
}
|
||||
|
||||
override fun openPrivacyPolicy() {
|
||||
openInternetBrowser(
|
||||
"https://wulkanowy.github.io/polityka-prywatnosci.html",
|
||||
::showMessage
|
||||
)
|
||||
override fun onCaptchaVerificationRequired(url: String?) {
|
||||
lifecycleScope.launch {
|
||||
captchaVerificationEvent.emit(url)
|
||||
}
|
||||
}
|
||||
|
||||
override fun showAuthDialog() {
|
||||
showDialogFragment(AuthDialog.newInstance())
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
|
@ -19,7 +19,6 @@ import io.github.wulkanowy.utils.AdsHelper
|
||||
import io.github.wulkanowy.utils.AnalyticsHelper
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
import timber.log.Timber
|
||||
import java.time.Duration
|
||||
@ -52,6 +51,7 @@ class MainPresenter @Inject constructor(
|
||||
destinationType in rootDestinationTypeList -> {
|
||||
rootDestinationTypeList.indexOf(destinationType)
|
||||
}
|
||||
|
||||
else -> 4
|
||||
}
|
||||
|
||||
@ -110,6 +110,7 @@ class MainPresenter @Inject constructor(
|
||||
is AccountView,
|
||||
is StudentInfoView,
|
||||
is AccountDetailsView -> false
|
||||
|
||||
else -> true
|
||||
}
|
||||
|
||||
@ -148,20 +149,8 @@ class MainPresenter @Inject constructor(
|
||||
}
|
||||
|
||||
fun onEnableAdsSelected() {
|
||||
view?.showPrivacyPolicyDialog()
|
||||
}
|
||||
|
||||
fun onPrivacyAgree(isPersonalizedAds: Boolean) {
|
||||
preferencesRepository.isAgreeToProcessData = true
|
||||
preferencesRepository.isPersonalizedAdsEnabled = isPersonalizedAds
|
||||
|
||||
adsHelper.initialize()
|
||||
|
||||
preferencesRepository.isAdsEnabled = true
|
||||
}
|
||||
|
||||
fun onPrivacySelected() {
|
||||
view?.openPrivacyPolicy()
|
||||
adsHelper.initialize()
|
||||
}
|
||||
|
||||
private fun checkInAppReview() {
|
||||
@ -189,8 +178,8 @@ class MainPresenter @Inject constructor(
|
||||
.getOrElse { return@launch }
|
||||
|
||||
if (Instant.now().minus(Duration.ofDays(28)).isAfter(student.registrationDate)) {
|
||||
view?.showAppSupport()
|
||||
preferencesRepository.isAppSupportShown = true
|
||||
view?.showAppSupport()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,10 +46,6 @@ interface MainView : BaseView {
|
||||
|
||||
fun showAppSupport()
|
||||
|
||||
fun showPrivacyPolicyDialog()
|
||||
|
||||
fun openPrivacyPolicy()
|
||||
|
||||
fun openMoreDestination(destination: Destination)
|
||||
|
||||
interface MainChildView {
|
||||
|
@ -3,6 +3,7 @@ package io.github.wulkanowy.ui.modules.settings
|
||||
import android.os.Bundle
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.base.BaseActivity
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import timber.log.Timber
|
||||
|
||||
@ -24,7 +25,11 @@ class SettingsFragment : PreferenceFragmentCompat(), MainView.TitledView, Settin
|
||||
|
||||
override fun showMessage(text: String) {}
|
||||
|
||||
override fun showExpiredDialog() {}
|
||||
override fun showExpiredCredentialsDialog() {}
|
||||
|
||||
override fun onCaptchaVerificationRequired(url: String?) = Unit
|
||||
|
||||
override fun showDecryptionFailedDialog() {}
|
||||
|
||||
override fun openClearLoginView() {}
|
||||
|
||||
|
@ -8,7 +8,6 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.base.BaseActivity
|
||||
import io.github.wulkanowy.ui.base.ErrorDialog
|
||||
import io.github.wulkanowy.ui.modules.auth.AuthDialog
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import javax.inject.Inject
|
||||
@ -47,8 +46,16 @@ class AdvancedFragment : PreferenceFragmentCompat(),
|
||||
(activity as? BaseActivity<*, *>)?.showMessage(text)
|
||||
}
|
||||
|
||||
override fun showExpiredDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showExpiredDialog()
|
||||
override fun showExpiredCredentialsDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showExpiredCredentialsDialog()
|
||||
}
|
||||
|
||||
override fun onCaptchaVerificationRequired(url: String?) {
|
||||
(activity as? BaseActivity<*, *>)?.onCaptchaVerificationRequired(url)
|
||||
}
|
||||
|
||||
override fun showDecryptionFailedDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showDecryptionFailedDialog()
|
||||
}
|
||||
|
||||
override fun showChangePasswordSnackbar(redirectUrl: String) {
|
||||
@ -64,7 +71,7 @@ class AdvancedFragment : PreferenceFragmentCompat(),
|
||||
}
|
||||
|
||||
override fun showAuthDialog() {
|
||||
AuthDialog.newInstance().show(childFragmentManager, "auth_dialog")
|
||||
(activity as? BaseActivity<*, *>)?.showAuthDialog()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -9,7 +9,6 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.base.BaseActivity
|
||||
import io.github.wulkanowy.ui.base.ErrorDialog
|
||||
import io.github.wulkanowy.ui.modules.auth.AuthDialog
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import javax.inject.Inject
|
||||
@ -63,8 +62,16 @@ class AppearanceFragment : PreferenceFragmentCompat(),
|
||||
(activity as? BaseActivity<*, *>)?.showMessage(text)
|
||||
}
|
||||
|
||||
override fun showExpiredDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showExpiredDialog()
|
||||
override fun showExpiredCredentialsDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showExpiredCredentialsDialog()
|
||||
}
|
||||
|
||||
override fun onCaptchaVerificationRequired(url: String?) {
|
||||
(activity as? BaseActivity<*, *>)?.onCaptchaVerificationRequired(url)
|
||||
}
|
||||
|
||||
override fun showDecryptionFailedDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showDecryptionFailedDialog()
|
||||
}
|
||||
|
||||
override fun showChangePasswordSnackbar(redirectUrl: String) {
|
||||
@ -80,7 +87,7 @@ class AppearanceFragment : PreferenceFragmentCompat(),
|
||||
}
|
||||
|
||||
override fun showAuthDialog() {
|
||||
AuthDialog.newInstance().show(childFragmentManager, "auth_dialog")
|
||||
(activity as? BaseActivity<*, *>)?.showAuthDialog()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -21,7 +21,6 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.base.BaseActivity
|
||||
import io.github.wulkanowy.ui.base.ErrorDialog
|
||||
import io.github.wulkanowy.ui.modules.auth.AuthDialog
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.openInternetBrowser
|
||||
@ -133,8 +132,16 @@ class NotificationsFragment : PreferenceFragmentCompat(),
|
||||
(activity as? BaseActivity<*, *>)?.showMessage(text)
|
||||
}
|
||||
|
||||
override fun showExpiredDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showExpiredDialog()
|
||||
override fun showExpiredCredentialsDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showExpiredCredentialsDialog()
|
||||
}
|
||||
|
||||
override fun onCaptchaVerificationRequired(url: String?) {
|
||||
(activity as? BaseActivity<*, *>)?.onCaptchaVerificationRequired(url)
|
||||
}
|
||||
|
||||
override fun showDecryptionFailedDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showDecryptionFailedDialog()
|
||||
}
|
||||
|
||||
override fun showChangePasswordSnackbar(redirectUrl: String) {
|
||||
@ -150,7 +157,7 @@ class NotificationsFragment : PreferenceFragmentCompat(),
|
||||
}
|
||||
|
||||
override fun showAuthDialog() {
|
||||
AuthDialog.newInstance().show(childFragmentManager, "auth_dialog")
|
||||
(activity as? BaseActivity<*, *>)?.showAuthDialog()
|
||||
}
|
||||
|
||||
override fun showFixSyncDialog() {
|
||||
|
@ -10,7 +10,6 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.base.BaseActivity
|
||||
import io.github.wulkanowy.ui.base.ErrorDialog
|
||||
import io.github.wulkanowy.ui.modules.auth.AuthDialog
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -84,8 +83,16 @@ class SyncFragment : PreferenceFragmentCompat(),
|
||||
}
|
||||
}
|
||||
|
||||
override fun showExpiredDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showExpiredDialog()
|
||||
override fun showExpiredCredentialsDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showExpiredCredentialsDialog()
|
||||
}
|
||||
|
||||
override fun onCaptchaVerificationRequired(url: String?) {
|
||||
(activity as? BaseActivity<*, *>)?.onCaptchaVerificationRequired(url)
|
||||
}
|
||||
|
||||
override fun showDecryptionFailedDialog() {
|
||||
(activity as? BaseActivity<*, *>)?.showDecryptionFailedDialog()
|
||||
}
|
||||
|
||||
override fun showChangePasswordSnackbar(redirectUrl: String) {
|
||||
@ -101,7 +108,7 @@ class SyncFragment : PreferenceFragmentCompat(),
|
||||
}
|
||||
|
||||
override fun showAuthDialog() {
|
||||
AuthDialog.newInstance().show(childFragmentManager, "auth_dialog")
|
||||
(activity as? BaseActivity<*, *>)?.showAuthDialog()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -3,6 +3,7 @@ package io.github.wulkanowy.utils
|
||||
import android.content.res.Resources
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.sdk.exception.FeatureNotAvailableException
|
||||
import io.github.wulkanowy.sdk.scrapper.exception.CloudflareVerificationException
|
||||
import io.github.wulkanowy.sdk.scrapper.exception.FeatureDisabledException
|
||||
import io.github.wulkanowy.sdk.scrapper.exception.ScrapperException
|
||||
import io.github.wulkanowy.sdk.scrapper.exception.ServiceUnavailableException
|
||||
@ -34,6 +35,7 @@ fun Resources.getErrorString(error: Throwable): String = when (error) {
|
||||
is FeatureNotAvailableException -> R.string.error_feature_not_available
|
||||
is VulcanException -> R.string.error_unknown_uonet
|
||||
is ScrapperException -> R.string.error_unknown_app
|
||||
is CloudflareVerificationException -> R.string.error_cloudflare_captcha
|
||||
is SSLHandshakeException -> when {
|
||||
error.isCausedByCertificateNotValidNow() -> R.string.error_invalid_device_datetime
|
||||
else -> R.string.error_timeout
|
||||
|
@ -11,6 +11,7 @@ fun Sdk.init(student: Student): Sdk {
|
||||
schoolSymbol = student.schoolSymbol
|
||||
studentId = student.studentId
|
||||
classId = student.classId
|
||||
emptyCookieJarInterceptor = true
|
||||
|
||||
if (Sdk.Mode.valueOf(student.loginMode) == Sdk.Mode.HEBE) {
|
||||
mobileBaseUrl = student.mobileBaseUrl
|
||||
|
@ -0,0 +1,58 @@
|
||||
package io.github.wulkanowy.utils
|
||||
|
||||
import java.net.CookiePolicy
|
||||
import java.net.CookieStore
|
||||
import java.net.HttpCookie
|
||||
import java.net.URI
|
||||
import android.webkit.CookieManager as WebkitCookieManager
|
||||
import java.net.CookieManager as JavaCookieManager
|
||||
|
||||
class WebkitCookieManagerProxy : JavaCookieManager(null, CookiePolicy.ACCEPT_ALL) {
|
||||
|
||||
private val webkitCookieManager: WebkitCookieManager = WebkitCookieManager.getInstance()
|
||||
|
||||
override fun put(uri: URI?, responseHeaders: Map<String?, List<String?>>?) {
|
||||
if (uri == null || responseHeaders == null) return
|
||||
val url = uri.toString()
|
||||
for (headerKey in responseHeaders.keys) {
|
||||
if (headerKey == null || !(
|
||||
headerKey.equals("Set-Cookie2", ignoreCase = true) ||
|
||||
headerKey.equals("Set-Cookie", ignoreCase = true)
|
||||
)
|
||||
) continue
|
||||
|
||||
// process each of the headers
|
||||
for (headerValue in responseHeaders[headerKey].orEmpty()) {
|
||||
webkitCookieManager.setCookie(url, headerValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override operator fun get(
|
||||
uri: URI?,
|
||||
requestHeaders: Map<String?, List<String?>?>?
|
||||
): Map<String, List<String>> {
|
||||
require(!(uri == null || requestHeaders == null)) { "Argument is null" }
|
||||
val res = mutableMapOf<String, List<String>>()
|
||||
val cookie = webkitCookieManager.getCookie(uri.toString())
|
||||
if (cookie != null) res["Cookie"] = listOf(cookie)
|
||||
return res
|
||||
}
|
||||
|
||||
override fun getCookieStore(): CookieStore {
|
||||
val cookies = super.getCookieStore()
|
||||
return object : CookieStore {
|
||||
override fun add(uri: URI?, cookie: HttpCookie?) = cookies.add(uri, cookie)
|
||||
override fun get(uri: URI?): List<HttpCookie> = cookies.get(uri)
|
||||
override fun getCookies(): List<HttpCookie> = cookies.cookies
|
||||
override fun getURIs(): List<URI> = cookies.urIs
|
||||
override fun remove(uri: URI?, cookie: HttpCookie?): Boolean =
|
||||
cookies.remove(uri, cookie)
|
||||
|
||||
override fun removeAll(): Boolean {
|
||||
webkitCookieManager.removeAllCookies(null)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ import android.util.Base64.DEFAULT
|
||||
import android.util.Base64.decode
|
||||
import android.util.Base64.encode
|
||||
import android.util.Base64.encodeToString
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import timber.log.Timber
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
@ -33,108 +34,124 @@ import javax.crypto.CipherInputStream
|
||||
import javax.crypto.CipherOutputStream
|
||||
import javax.crypto.spec.OAEPParameterSpec
|
||||
import javax.crypto.spec.PSource.PSpecified
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import javax.security.auth.x500.X500Principal
|
||||
|
||||
private const val KEYSTORE_NAME = "AndroidKeyStore"
|
||||
@Singleton
|
||||
class Scrambler @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
) {
|
||||
private val keyCharset = Charset.forName("UTF-8")
|
||||
|
||||
private const val KEY_ALIAS = "wulkanowy_password"
|
||||
private val isKeyPairExists: Boolean
|
||||
get() = keyStore.getKey(KEY_ALIAS, null) != null
|
||||
|
||||
private val KEY_CHARSET = Charset.forName("UTF-8")
|
||||
private val keyStore: KeyStore
|
||||
get() = KeyStore.getInstance(KEYSTORE_NAME).apply { load(null) }
|
||||
|
||||
private val isKeyPairExists: Boolean
|
||||
get() = keyStore.getKey(KEY_ALIAS, null) != null
|
||||
private val cipher: Cipher
|
||||
get() {
|
||||
return if (SDK_INT >= M) Cipher.getInstance(
|
||||
"RSA/ECB/OAEPWithSHA-256AndMGF1Padding",
|
||||
"AndroidKeyStoreBCWorkaround"
|
||||
)
|
||||
else Cipher.getInstance("RSA/ECB/PKCS1Padding", "AndroidOpenSSL")
|
||||
}
|
||||
|
||||
private val keyStore: KeyStore
|
||||
get() = KeyStore.getInstance(KEYSTORE_NAME).apply { load(null) }
|
||||
fun encrypt(plainText: String): String {
|
||||
if (plainText.isEmpty()) throw ScramblerException("Text to be encrypted is empty")
|
||||
|
||||
private val cipher: Cipher
|
||||
get() {
|
||||
return if (SDK_INT >= M) Cipher.getInstance(
|
||||
"RSA/ECB/OAEPWithSHA-256AndMGF1Padding",
|
||||
"AndroidKeyStoreBCWorkaround"
|
||||
)
|
||||
else Cipher.getInstance("RSA/ECB/PKCS1Padding", "AndroidOpenSSL")
|
||||
return try {
|
||||
if (!isKeyPairExists) generateKeyPair()
|
||||
|
||||
cipher.let {
|
||||
if (SDK_INT >= M) {
|
||||
OAEPParameterSpec("SHA-256", "MGF1", SHA1, PSpecified.DEFAULT).let { spec ->
|
||||
it.init(ENCRYPT_MODE, keyStore.getCertificate(KEY_ALIAS).publicKey, spec)
|
||||
}
|
||||
} else it.init(ENCRYPT_MODE, keyStore.getCertificate(KEY_ALIAS).publicKey)
|
||||
|
||||
ByteArrayOutputStream().let { output ->
|
||||
CipherOutputStream(output, it).apply {
|
||||
write(plainText.toByteArray(keyCharset))
|
||||
close()
|
||||
}
|
||||
encodeToString(output.toByteArray(), DEFAULT)
|
||||
}
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
Timber.e(exception, "An error occurred while encrypting text")
|
||||
String(encode(plainText.toByteArray(keyCharset), DEFAULT), keyCharset)
|
||||
}
|
||||
}
|
||||
|
||||
fun encrypt(plainText: String, context: Context): String {
|
||||
if (plainText.isEmpty()) throw ScramblerException("Text to be encrypted is empty")
|
||||
fun decrypt(cipherText: String): String {
|
||||
if (cipherText.isEmpty()) throw ScramblerException("Text to be encrypted is empty")
|
||||
|
||||
return try {
|
||||
if (!isKeyPairExists) generateKeyPair(context)
|
||||
return try {
|
||||
if (!isKeyPairExists) throw ScramblerException("KeyPair doesn't exist")
|
||||
|
||||
cipher.let {
|
||||
if (SDK_INT >= M) {
|
||||
OAEPParameterSpec("SHA-256", "MGF1", SHA1, PSpecified.DEFAULT).let { spec ->
|
||||
it.init(ENCRYPT_MODE, keyStore.getCertificate(KEY_ALIAS).publicKey, spec)
|
||||
cipher.let {
|
||||
if (SDK_INT >= M) {
|
||||
OAEPParameterSpec("SHA-256", "MGF1", SHA1, PSpecified.DEFAULT).let { spec ->
|
||||
it.init(DECRYPT_MODE, keyStore.getKey(KEY_ALIAS, null), spec)
|
||||
}
|
||||
} else it.init(DECRYPT_MODE, keyStore.getKey(KEY_ALIAS, null))
|
||||
|
||||
CipherInputStream(
|
||||
ByteArrayInputStream(decode(cipherText, DEFAULT)),
|
||||
it
|
||||
).let { input ->
|
||||
val values = ArrayList<Byte>()
|
||||
var nextByte: Int
|
||||
while (run { nextByte = input.read(); nextByte } != -1) {
|
||||
values.add(nextByte.toByte())
|
||||
}
|
||||
val bytes = ByteArray(values.size)
|
||||
for (i in bytes.indices) {
|
||||
bytes[i] = values[i]
|
||||
}
|
||||
String(bytes, 0, bytes.size, keyCharset)
|
||||
}
|
||||
} else it.init(ENCRYPT_MODE, keyStore.getCertificate(KEY_ALIAS).publicKey)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
throw ScramblerException("An error occurred while decrypting text", e)
|
||||
}
|
||||
}
|
||||
|
||||
ByteArrayOutputStream().let { output ->
|
||||
CipherOutputStream(output, it).apply {
|
||||
write(plainText.toByteArray(KEY_CHARSET))
|
||||
close()
|
||||
}
|
||||
encodeToString(output.toByteArray(), DEFAULT)
|
||||
private fun generateKeyPair() {
|
||||
(if (SDK_INT >= M) {
|
||||
KeyGenParameterSpec.Builder(KEY_ALIAS, PURPOSE_DECRYPT or PURPOSE_ENCRYPT)
|
||||
.setDigests(DIGEST_SHA256, DIGEST_SHA512)
|
||||
.setEncryptionPaddings(ENCRYPTION_PADDING_RSA_OAEP)
|
||||
.setCertificateSerialNumber(BigInteger.TEN)
|
||||
.setCertificateSubject(X500Principal("CN=Wulkanowy"))
|
||||
.build()
|
||||
} else {
|
||||
KeyPairGeneratorSpec.Builder(context)
|
||||
.setAlias(KEY_ALIAS)
|
||||
.setSubject(X500Principal("CN=Wulkanowy"))
|
||||
.setSerialNumber(BigInteger.TEN)
|
||||
.setStartDate(Calendar.getInstance().time)
|
||||
.setEndDate(Calendar.getInstance().apply { add(YEAR, 99) }.time)
|
||||
.build()
|
||||
}).let {
|
||||
KeyPairGenerator.getInstance("RSA", KEYSTORE_NAME).apply {
|
||||
initialize(it)
|
||||
genKeyPair()
|
||||
}
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
Timber.e(exception, "An error occurred while encrypting text")
|
||||
String(encode(plainText.toByteArray(KEY_CHARSET), DEFAULT), KEY_CHARSET)
|
||||
Timber.i("A new KeyPair has been generated")
|
||||
}
|
||||
|
||||
fun clearKeyPair() {
|
||||
keyStore.deleteEntry(KEY_ALIAS)
|
||||
Timber.i("KeyPair has been cleared")
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private const val KEYSTORE_NAME = "AndroidKeyStore"
|
||||
private const val KEY_ALIAS = "wulkanowy_password"
|
||||
}
|
||||
}
|
||||
|
||||
fun decrypt(cipherText: String): String {
|
||||
if (cipherText.isEmpty()) throw ScramblerException("Text to be encrypted is empty")
|
||||
|
||||
return try {
|
||||
if (!isKeyPairExists) throw ScramblerException("KeyPair doesn't exist")
|
||||
|
||||
cipher.let {
|
||||
if (SDK_INT >= M) {
|
||||
OAEPParameterSpec("SHA-256", "MGF1", SHA1, PSpecified.DEFAULT).let { spec ->
|
||||
it.init(DECRYPT_MODE, keyStore.getKey(KEY_ALIAS, null), spec)
|
||||
}
|
||||
} else it.init(DECRYPT_MODE, keyStore.getKey(KEY_ALIAS, null))
|
||||
|
||||
CipherInputStream(ByteArrayInputStream(decode(cipherText, DEFAULT)), it).let { input ->
|
||||
val values = ArrayList<Byte>()
|
||||
var nextByte: Int
|
||||
while (run { nextByte = input.read(); nextByte } != -1) {
|
||||
values.add(nextByte.toByte())
|
||||
}
|
||||
val bytes = ByteArray(values.size)
|
||||
for (i in bytes.indices) {
|
||||
bytes[i] = values[i]
|
||||
}
|
||||
String(bytes, 0, bytes.size, KEY_CHARSET)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
throw ScramblerException("An error occurred while decrypting text", e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateKeyPair(context: Context) {
|
||||
(if (SDK_INT >= M) {
|
||||
KeyGenParameterSpec.Builder(KEY_ALIAS, PURPOSE_DECRYPT or PURPOSE_ENCRYPT)
|
||||
.setDigests(DIGEST_SHA256, DIGEST_SHA512)
|
||||
.setEncryptionPaddings(ENCRYPTION_PADDING_RSA_OAEP)
|
||||
.setCertificateSerialNumber(BigInteger.TEN)
|
||||
.setCertificateSubject(X500Principal("CN=Wulkanowy"))
|
||||
.build()
|
||||
} else {
|
||||
KeyPairGeneratorSpec.Builder(context)
|
||||
.setAlias(KEY_ALIAS)
|
||||
.setSubject(X500Principal("CN=Wulkanowy"))
|
||||
.setSerialNumber(BigInteger.TEN)
|
||||
.setStartDate(Calendar.getInstance().time)
|
||||
.setEndDate(Calendar.getInstance().apply { add(YEAR, 99) }.time)
|
||||
.build()
|
||||
}).let {
|
||||
KeyPairGenerator.getInstance("RSA", KEYSTORE_NAME).apply {
|
||||
initialize(it)
|
||||
genKeyPair()
|
||||
}
|
||||
}
|
||||
Timber.i("A new KeyPair has been generated")
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
Wersja 2.2.3
|
||||
Wersja 2.3.4
|
||||
|
||||
— ułatwiliśmy przełączenie dnia na weekend w planie lekcji przy użyciu strzałek
|
||||
— poprawiliśmy wsparcie dla statystyk ocen z systemem punktowym
|
||||
— poprawiliśmy sortowanie nauczycieli w widoku Szkoła i nauczyciele
|
||||
— dodaliśmy obsługę captchy, co umożliwi używanie apki np. na odmianie ResMan Rzeszów
|
||||
— naprawiliśmy wyświetlanie frekwencji w szkołach używających eduOne (piszcie, jeśli nadal nie działa)
|
||||
|
||||
Pełna lista zmian: https://github.com/wulkanowy/wulkanowy/releases
|
||||
|
@ -1,79 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/ads_consent_privacy"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:insetLeft="0dp"
|
||||
android:insetTop="0dp"
|
||||
android:insetRight="0dp"
|
||||
android:insetBottom="0dp"
|
||||
android:padding="0dp"
|
||||
android:text="@string/pref_ads_privacy_policy"
|
||||
android:textAllCaps="false"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.google.android.material.checkbox.MaterialCheckBox
|
||||
android:id="@+id/ads_consent_over"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="17dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/pref_ads_over_18_years_old"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintTop_toBottomOf="@id/ads_consent_privacy" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/ads_consent_personalised"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:enabled="false"
|
||||
android:insetLeft="0dp"
|
||||
android:insetTop="0dp"
|
||||
android:insetRight="0dp"
|
||||
android:insetBottom="0dp"
|
||||
android:text="@string/pref_ads_option_personalized"
|
||||
app:layout_constraintTop_toBottomOf="@id/ads_consent_over" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/ads_consent_non_personalised"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:insetLeft="0dp"
|
||||
android:insetTop="0dp"
|
||||
android:insetRight="0dp"
|
||||
android:insetBottom="0dp"
|
||||
android:text="@string/pref_ads_option_non_personalized"
|
||||
app:layout_constraintBottom_toTopOf="@id/ads_consent_cancel"
|
||||
app:layout_constraintTop_toBottomOf="@id/ads_consent_personalised"
|
||||
app:layout_constraintVertical_bias="0" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/ads_consent_cancel"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:insetLeft="0dp"
|
||||
android:insetTop="0dp"
|
||||
android:insetRight="0dp"
|
||||
android:insetBottom="0dp"
|
||||
android:text="@android:string/cancel"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintVertical_bias="0" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
51
app/src/main/res/layout/dialog_captcha.xml
Normal file
51
app/src/main/res/layout/dialog_captcha.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:minWidth="350dp"
|
||||
tools:context=".ui.modules.captcha.CaptchaDialog">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/captcha_dialog_title"
|
||||
app:layout_constraintBottom_toBottomOf="@id/captcha_close"
|
||||
app:layout_constraintEnd_toStartOf="@id/captcha_refresh"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/captcha_refresh"
|
||||
style="@style/Widget.Material3.Button.IconButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:contentDescription="@string/logviewer_refresh"
|
||||
app:icon="@drawable/ic_refresh"
|
||||
app:iconTint="?colorOnSurface"
|
||||
app:layout_constraintEnd_toStartOf="@id/captcha_close"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/captcha_close"
|
||||
style="@style/Widget.Material3.Button.IconButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:contentDescription="@string/all_close"
|
||||
app:icon="@drawable/ic_all_close_circle"
|
||||
app:iconTint="?colorOnSurface"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<WebView
|
||||
android:id="@+id/captcha_webview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/captcha_close" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -13,6 +13,7 @@
|
||||
<string name="logviewer_title">Prohlížeč protokolů</string>
|
||||
<string name="debug_title">Ladění</string>
|
||||
<string name="notification_debug_title">Ladění oznámení</string>
|
||||
<string name="debug_cookies_clear">Vymazat soubory cookie webview</string>
|
||||
<string name="contributors_title">Tvůrci</string>
|
||||
<string name="license_title">Licence</string>
|
||||
<string name="message_title">Zprávy</string>
|
||||
@ -96,6 +97,8 @@
|
||||
<string name="main_log_in">Přihlásit se</string>
|
||||
<string name="main_session_expired">Relace vypršela</string>
|
||||
<string name="main_session_relogin">Relace vypršela. Přihlaste se prosím znovu</string>
|
||||
<string name="main_expired_credentials_description">Heslo k vašemu účtu bylo změněno. Musíte se znovu přihlásit do Wulkanového</string>
|
||||
<string name="main_expired_credentials_title">Heslo bylo změněno</string>
|
||||
<string name="main_support_title">Podpora aplikace</string>
|
||||
<string name="main_support_description">Líbí se Vám tato aplikace? Podpořte její vývoj tím, že povolíte neinvazivní reklamy, které můžete kdykoliv vypnout</string>
|
||||
<string name="main_support_positive">Zapnout reklamy</string>
|
||||
@ -760,7 +763,7 @@
|
||||
<string name="pref_ads_support_category_name">Podpora</string>
|
||||
<string name="pref_ads_privacy_policy">Ochrana osobních údajů</string>
|
||||
<string name="pref_ads_agreements">Souhlasy</string>
|
||||
<string name="pref_ads_consent">Souhlas se zpracováním údajů souvisejících s reklamami</string>
|
||||
<string name="pref_ads_consent">Zobrazit souhlas se zpracováním údajů</string>
|
||||
<string name="pref_ads_show_in_app">Zobrazit reklamy v aplikaci</string>
|
||||
<string name="pref_ads_support">Podívejte se na jednu reklamu pro podporu projektu</string>
|
||||
<string name="pref_ads_privacy_title">Souhlas se zpracováním dat</string>
|
||||
@ -769,13 +772,6 @@
|
||||
<string name="pref_ads_privacy_link">Ochrana osobních údajů</string>
|
||||
<string name="pref_ads_loading">Reklama se načítá</string>
|
||||
<string name="pref_ads_once_per_visit">Děkujeme za vaši podporu, vraťte se později pro více reklam</string>
|
||||
<string name="pref_ads_consent_title">Můžeme použít Vaše data k zobrazení reklam?</string>
|
||||
<string name="pref_ads_consent_description">Volbu můžete kdykoliv změnit v nastavení aplikace. Můžeme použít Vaše data k zobrazení reklam šitých pro vás nebo pomocí méně vašich dat zobrazovat nepřizpůsobené reklamy. Podrobnosti naleznete v našich Zásadách ochrany osobních údajů</string>
|
||||
<string name="pref_ads_summary_personalized">Přizpůsobené reklamy</string>
|
||||
<string name="pref_ads_summary_non_personalized">Nepřizpůsobené reklamy</string>
|
||||
<string name="pref_ads_over_18_years_old">Je mi více než 18 let</string>
|
||||
<string name="pref_ads_option_personalized">Ano, přizpůsobené reklamy</string>
|
||||
<string name="pref_ads_option_non_personalized">Ano, nepřizpůsobené reklamy</string>
|
||||
<string name="pref_settings_advanced_title">Pokročilé</string>
|
||||
<string name="pref_settings_appearance_title">Vzhled a chování</string>
|
||||
<string name="pref_settings_notifications_title">Oznámení</string>
|
||||
@ -838,6 +834,9 @@
|
||||
<string name="auth_title">Autorizace</string>
|
||||
<string name="auth_description">Pro provoz aplikace potřebujeme potvrdit vaši identitu. Zadejte PESEL žáka <b>%1$s</b> v níže uvedeném poli</string>
|
||||
<string name="auth_button_skip">Zatím přeskočit</string>
|
||||
<!--Captcha-->
|
||||
<string name="captcha_dialog_title">Probíhá ověřování. Počkejte…</string>
|
||||
<string name="captcha_verified_message">Úspěšně ověřeno</string>
|
||||
<!--Errors-->
|
||||
<string name="error_no_internet">Žádné internetové připojení</string>
|
||||
<string name="error_invalid_device_datetime">Vyskytla se chyba. Zkontrolujte hodiny svého zařízení</string>
|
||||
@ -847,6 +846,7 @@
|
||||
<string name="error_service_unavailable">Probíhá údržba deníku UONET+. Zkuste to později znovu</string>
|
||||
<string name="error_unknown_uonet">Neznámá chyba deniku UONET+. Prosím zkuste to znovu později</string>
|
||||
<string name="error_unknown_app">Neznámá chyba aplikace. Prosím zkuste to znovu později</string>
|
||||
<string name="error_cloudflare_captcha">Vyžadováno ověření Captcha</string>
|
||||
<string name="error_unknown">Vyskytla se neočekávaná chyba</string>
|
||||
<string name="error_feature_disabled">Funkce je deaktivována přes vaší školou</string>
|
||||
<string name="error_feature_not_available">Funkce není k dispozici. Přihlaste se v jiném režimu než Mobile API</string>
|
||||
|
@ -13,6 +13,7 @@
|
||||
<string name="logviewer_title">Log viewer</string>
|
||||
<string name="debug_title">Debug</string>
|
||||
<string name="notification_debug_title">Notification debug</string>
|
||||
<string name="debug_cookies_clear">Clear webview cookies</string>
|
||||
<string name="contributors_title">Contributors</string>
|
||||
<string name="license_title">Licenses</string>
|
||||
<string name="message_title">Messages</string>
|
||||
@ -96,6 +97,8 @@
|
||||
<string name="main_log_in">Log in</string>
|
||||
<string name="main_session_expired">Session expired</string>
|
||||
<string name="main_session_relogin">Session expired, log in again</string>
|
||||
<string name="main_expired_credentials_description">Your account password has been changed. You need to log in to Wulkanowy again</string>
|
||||
<string name="main_expired_credentials_title">Password changed</string>
|
||||
<string name="main_support_title">Application support</string>
|
||||
<string name="main_support_description">Do you like this app? Support its development by enabling non-invasive ads that you can disable at any time</string>
|
||||
<string name="main_support_positive">Enable ads</string>
|
||||
@ -670,7 +673,7 @@
|
||||
<string name="pref_ads_support_category_name">Support</string>
|
||||
<string name="pref_ads_privacy_policy">Privacy Policy</string>
|
||||
<string name="pref_ads_agreements">Agreements</string>
|
||||
<string name="pref_ads_consent">Consent to processing of data related to ads</string>
|
||||
<string name="pref_ads_consent">Show consent to data processing</string>
|
||||
<string name="pref_ads_show_in_app">Show ads in app</string>
|
||||
<string name="pref_ads_support">Watch single ad to support project</string>
|
||||
<string name="pref_ads_privacy_title">Consent to data processing</string>
|
||||
@ -679,13 +682,6 @@
|
||||
<string name="pref_ads_privacy_link">Privacy policy</string>
|
||||
<string name="pref_ads_loading">Ad is loading</string>
|
||||
<string name="pref_ads_once_per_visit">Thank you for your support, come back later for more ads</string>
|
||||
<string name="pref_ads_consent_title">Can we use your data to display ads?</string>
|
||||
<string name="pref_ads_consent_description">You can change your choice anytime in the app settings. We may use your data to display ads tailored to you or, using less of your data, display non-personalized ads. Please see our Privacy Policy for details</string>
|
||||
<string name="pref_ads_summary_personalized">Personalized ads</string>
|
||||
<string name="pref_ads_summary_non_personalized">Non-personalized ads</string>
|
||||
<string name="pref_ads_over_18_years_old">I am over 18 years old</string>
|
||||
<string name="pref_ads_option_personalized">Yes, personalized ads</string>
|
||||
<string name="pref_ads_option_non_personalized">Yes, non-personalized ads</string>
|
||||
<string name="pref_settings_advanced_title">Advanced</string>
|
||||
<string name="pref_settings_appearance_title">Appearance & Behavior</string>
|
||||
<string name="pref_settings_notifications_title">Notifications</string>
|
||||
@ -748,6 +744,9 @@
|
||||
<string name="auth_title">Authorization</string>
|
||||
<string name="auth_description">To operate the application, we need to confirm your identity. Please enter the student\'s PESEL <b>%1$s</b> in the field below</string>
|
||||
<string name="auth_button_skip">Skip for now</string>
|
||||
<!--Captcha-->
|
||||
<string name="captcha_dialog_title">Verification is in progress. Wait…</string>
|
||||
<string name="captcha_verified_message">Verified successfully</string>
|
||||
<!--Errors-->
|
||||
<string name="error_no_internet">No internet connection</string>
|
||||
<string name="error_invalid_device_datetime">An error occurred. Check your device clock</string>
|
||||
@ -757,6 +756,7 @@
|
||||
<string name="error_service_unavailable">Maintenance underway UONET + register. Try again later</string>
|
||||
<string name="error_unknown_uonet">Unknown UONET + register error. Try again later</string>
|
||||
<string name="error_unknown_app">Unknown application error. Please try again later</string>
|
||||
<string name="error_cloudflare_captcha">Captcha verification required</string>
|
||||
<string name="error_unknown">An unexpected error occurred</string>
|
||||
<string name="error_feature_disabled">Feature disabled by your school</string>
|
||||
<string name="error_feature_not_available">Feature not available. Login in a mode other than Mobile API</string>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user