forked from github/wulkanowy-mirror
Migration to Wulkanowy SDK (#336)
This commit is contained in:

committed by
Rafał Borcz

parent
826ea32fc0
commit
304c49d61e
@ -11,8 +11,6 @@ import dagger.android.AndroidInjector
|
||||
import dagger.android.support.DaggerApplication
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.utils.Log
|
||||
import io.github.wulkanowy.data.db.SharedPrefProvider
|
||||
import io.github.wulkanowy.data.db.SharedPrefProvider.Companion.APP_VERSION_CODE_KEY
|
||||
import io.github.wulkanowy.di.DaggerAppComponent
|
||||
import io.github.wulkanowy.services.sync.SyncWorkerFactory
|
||||
import io.github.wulkanowy.ui.base.ThemeManager
|
||||
@ -35,9 +33,6 @@ class WulkanowyApp : DaggerApplication(), Configuration.Provider {
|
||||
@Inject
|
||||
lateinit var themeManager: ThemeManager
|
||||
|
||||
@Inject
|
||||
lateinit var sharedPrefProvider: SharedPrefProvider
|
||||
|
||||
@Inject
|
||||
lateinit var appInfo: AppInfo
|
||||
|
||||
@ -52,7 +47,6 @@ class WulkanowyApp : DaggerApplication(), Configuration.Provider {
|
||||
RxJavaPlugins.setErrorHandler(::onError)
|
||||
Lingver.init(this)
|
||||
themeManager.applyDefaultTheme()
|
||||
migrateSharedPreferences()
|
||||
|
||||
initLogging()
|
||||
initCrashlytics(this, appInfo)
|
||||
@ -68,13 +62,6 @@ class WulkanowyApp : DaggerApplication(), Configuration.Provider {
|
||||
registerActivityLifecycleCallbacks(ActivityLifecycleLogger())
|
||||
}
|
||||
|
||||
private fun migrateSharedPreferences() {
|
||||
if (sharedPrefProvider.getLong(APP_VERSION_CODE_KEY, -1) < 48) { // #596
|
||||
sharedPrefProvider.delete(getString(R.string.pref_key_grade_modifier_plus))
|
||||
sharedPrefProvider.delete(getString(R.string.pref_key_grade_modifier_minus))
|
||||
}
|
||||
}
|
||||
|
||||
private fun onError(error: Throwable) {
|
||||
//RxJava's too deep stack traces may cause SOE on older android devices
|
||||
val cause = error.cause
|
||||
|
@ -1,35 +0,0 @@
|
||||
package io.github.wulkanowy.data
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import java.net.URL
|
||||
import javax.inject.Inject
|
||||
|
||||
class ApiHelper @Inject constructor(private val api: Api) {
|
||||
|
||||
fun initApi(student: Student) {
|
||||
api.apply {
|
||||
email = student.email
|
||||
password = student.password
|
||||
symbol = student.symbol
|
||||
schoolSymbol = student.schoolSymbol
|
||||
studentId = student.studentId
|
||||
classId = student.classId
|
||||
host = URL(student.endpoint).run { host + ":$port".removeSuffix(":-1") }
|
||||
ssl = student.endpoint.startsWith("https")
|
||||
loginType = Api.LoginType.valueOf(student.loginType)
|
||||
useNewStudent = true
|
||||
}
|
||||
}
|
||||
|
||||
fun initApi(email: String, password: String, symbol: String, endpoint: String) {
|
||||
api.apply {
|
||||
this.email = email
|
||||
this.password = password
|
||||
this.symbol = symbol
|
||||
host = URL(endpoint).run { host + ":$port".removeSuffix(":-1") }
|
||||
ssl = endpoint.startsWith("https")
|
||||
useNewStudent = true
|
||||
}
|
||||
}
|
||||
}
|
@ -11,12 +11,10 @@ import com.readystatesoftware.chuck.api.ChuckInterceptor
|
||||
import com.readystatesoftware.chuck.api.RetentionManager
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.AppDatabase
|
||||
import io.github.wulkanowy.data.db.SharedPrefProvider
|
||||
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import okhttp3.logging.HttpLoggingInterceptor.Level.BASIC
|
||||
import okhttp3.logging.HttpLoggingInterceptor.Level.NONE
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import timber.log.Timber
|
||||
import javax.inject.Singleton
|
||||
|
||||
@ -33,15 +31,14 @@ internal class RepositoryModule {
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideApi(chuckCollector: ChuckCollector, context: Context): Api {
|
||||
return Api().apply {
|
||||
logLevel = NONE
|
||||
fun provideSdk(chuckCollector: ChuckCollector, context: Context): Sdk {
|
||||
return Sdk().apply {
|
||||
androidVersion = android.os.Build.VERSION.RELEASE
|
||||
buildTag = android.os.Build.MODEL
|
||||
setInterceptor(HttpLoggingInterceptor(HttpLoggingInterceptor.Logger { Timber.d(it) }).setLevel(BASIC))
|
||||
setSimpleHttpLogger { Timber.d(it) }
|
||||
|
||||
// for debug only
|
||||
setInterceptor(ChuckInterceptor(context, chuckCollector).maxContentLength(250000L), true, 0)
|
||||
addInterceptor(ChuckInterceptor(context, chuckCollector).maxContentLength(250000L), true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +52,7 @@ internal class RepositoryModule {
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideDatabase(context: Context) = AppDatabase.newInstance(context)
|
||||
fun provideDatabase(context: Context, sharedPrefProvider: SharedPrefProvider) = AppDatabase.newInstance(context, sharedPrefProvider)
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
|
30
app/src/main/java/io/github/wulkanowy/data/SdkHelper.kt
Normal file
30
app/src/main/java/io/github/wulkanowy/data/SdkHelper.kt
Normal file
@ -0,0 +1,30 @@
|
||||
package io.github.wulkanowy.data
|
||||
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import javax.inject.Inject
|
||||
|
||||
class SdkHelper @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun init(student: Student) {
|
||||
sdk.apply {
|
||||
email = student.email
|
||||
password = student.password
|
||||
symbol = student.symbol
|
||||
schoolSymbol = student.schoolSymbol
|
||||
studentId = student.studentId
|
||||
classId = student.classId
|
||||
|
||||
if (Sdk.Mode.valueOf(student.loginMode) != Sdk.Mode.API) {
|
||||
scrapperBaseUrl = student.scrapperBaseUrl
|
||||
loginType = Sdk.ScrapperLoginType.valueOf(student.loginType)
|
||||
}
|
||||
loginId = student.userLoginId
|
||||
|
||||
mode = Sdk.Mode.valueOf(student.loginMode)
|
||||
mobileBaseUrl = student.mobileBaseUrl
|
||||
certKey = student.certificateKey
|
||||
privateKey = student.privateKey
|
||||
}
|
||||
}
|
||||
}
|
@ -58,6 +58,7 @@ import io.github.wulkanowy.data.db.migrations.Migration15
|
||||
import io.github.wulkanowy.data.db.migrations.Migration16
|
||||
import io.github.wulkanowy.data.db.migrations.Migration17
|
||||
import io.github.wulkanowy.data.db.migrations.Migration18
|
||||
import io.github.wulkanowy.data.db.migrations.Migration19
|
||||
import io.github.wulkanowy.data.db.migrations.Migration2
|
||||
import io.github.wulkanowy.data.db.migrations.Migration3
|
||||
import io.github.wulkanowy.data.db.migrations.Migration4
|
||||
@ -100,9 +101,9 @@ import javax.inject.Singleton
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
|
||||
companion object {
|
||||
const val VERSION_SCHEMA = 18
|
||||
const val VERSION_SCHEMA = 19
|
||||
|
||||
fun getMigrations(): Array<Migration> {
|
||||
fun getMigrations(sharedPrefProvider: SharedPrefProvider): Array<Migration> {
|
||||
return arrayOf(
|
||||
Migration2(),
|
||||
Migration3(),
|
||||
@ -120,16 +121,17 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
Migration15(),
|
||||
Migration16(),
|
||||
Migration17(),
|
||||
Migration18()
|
||||
Migration18(),
|
||||
Migration19(sharedPrefProvider)
|
||||
)
|
||||
}
|
||||
|
||||
fun newInstance(context: Context): AppDatabase {
|
||||
fun newInstance(context: Context, sharedPrefProvider: SharedPrefProvider): AppDatabase {
|
||||
return Room.databaseBuilder(context, AppDatabase::class.java, "wulkanowy_database")
|
||||
.setJournalMode(TRUNCATE)
|
||||
.fallbackToDestructiveMigrationFrom(VERSION_SCHEMA + 1)
|
||||
.fallbackToDestructiveMigrationOnDowngrade()
|
||||
.addMigrations(*getMigrations())
|
||||
.addMigrations(*getMigrations(sharedPrefProvider))
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,12 @@ class SharedPrefProvider @Inject constructor(private val sharedPref: SharedPrefe
|
||||
|
||||
fun getLong(key: String, defaultValue: Long) = sharedPref.getLong(key, defaultValue)
|
||||
|
||||
fun getString(key: String, defaultValue: String): String = sharedPref.getString(key, defaultValue) ?: defaultValue
|
||||
|
||||
fun putString(key: String, value: String, sync: Boolean = false) {
|
||||
sharedPref.edit(sync) { putString(key, value) }
|
||||
}
|
||||
|
||||
fun delete(key: String) {
|
||||
sharedPref.edit().remove(key).apply()
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ data class Grade(
|
||||
|
||||
val entry: String,
|
||||
|
||||
val value: Int,
|
||||
val value: Double,
|
||||
|
||||
val modifier: Double,
|
||||
|
||||
|
@ -29,6 +29,8 @@ data class Message(
|
||||
|
||||
val subject: String,
|
||||
|
||||
var content: String,
|
||||
|
||||
val date: LocalDateTime,
|
||||
|
||||
@ColumnInfo(name = "folder_id")
|
||||
@ -50,6 +52,4 @@ data class Message(
|
||||
|
||||
@ColumnInfo(name = "is_notified")
|
||||
var isNotified: Boolean = true
|
||||
|
||||
var content: String? = null
|
||||
}
|
||||
|
@ -10,10 +10,27 @@ import java.io.Serializable
|
||||
@Entity(tableName = "Students", indices = [Index(value = ["email", "symbol", "student_id", "school_id", "class_id"], unique = true)])
|
||||
data class Student(
|
||||
|
||||
val endpoint: String,
|
||||
@ColumnInfo(name = "scrapper_base_url")
|
||||
val scrapperBaseUrl: String,
|
||||
|
||||
@ColumnInfo(name = "mobile_base_url")
|
||||
val mobileBaseUrl: String,
|
||||
|
||||
@ColumnInfo(name = "login_type")
|
||||
val loginType: String,
|
||||
|
||||
@ColumnInfo(name = "login_mode")
|
||||
val loginMode: String,
|
||||
|
||||
@ColumnInfo(name = "certificate_key")
|
||||
val certificateKey: String,
|
||||
|
||||
@ColumnInfo(name = "private_key")
|
||||
val privateKey: String,
|
||||
|
||||
@ColumnInfo(name = "is_parent")
|
||||
val isParent: Boolean,
|
||||
|
||||
val email: String,
|
||||
|
||||
var password: String,
|
||||
@ -23,6 +40,9 @@ data class Student(
|
||||
@ColumnInfo(name = "student_id")
|
||||
val studentId: Int,
|
||||
|
||||
@ColumnInfo(name = "user_login_id")
|
||||
val userLoginId: Int,
|
||||
|
||||
@ColumnInfo(name = "student_name")
|
||||
val studentName: String,
|
||||
|
||||
|
@ -0,0 +1,119 @@
|
||||
package io.github.wulkanowy.data.db.migrations
|
||||
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
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)
|
||||
migrateSharedPreferences()
|
||||
}
|
||||
|
||||
private fun migrateMessages(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE Messages")
|
||||
database.execSQL("""
|
||||
CREATE TABLE IF NOT EXISTS Messages (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
is_notified INTEGER NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
real_id INTEGER NOT NULL,
|
||||
message_id INTEGER NOT NULL,
|
||||
sender_name TEXT NOT NULL,
|
||||
sender_id INTEGER NOT NULL,
|
||||
recipient_name TEXT NOT NULL,
|
||||
subject TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
date INTEGER NOT NULL,
|
||||
folder_id INTEGER NOT NULL,
|
||||
unread INTEGER NOT NULL,
|
||||
unread_by INTEGER NOT NULL,
|
||||
read_by INTEGER NOT NULL,
|
||||
removed INTEGER NOT NULL
|
||||
)
|
||||
""")
|
||||
}
|
||||
|
||||
private fun migrateGrades(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("DROP TABLE Grades")
|
||||
database.execSQL("""
|
||||
CREATE TABLE IF NOT EXISTS Grades (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
is_read INTEGER NOT NULL,
|
||||
is_notified INTEGER NOT NULL,
|
||||
semester_id INTEGER NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
subject TEXT NOT NULL,
|
||||
entry TEXT NOT NULL,
|
||||
value REAL NOT NULL,
|
||||
modifier REAL NOT NULL,
|
||||
comment TEXT NOT NULL,
|
||||
color TEXT NOT NULL,
|
||||
grade_symbol TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
weight TEXT NOT NULL,
|
||||
weightValue REAL NOT NULL,
|
||||
date INTEGER NOT NULL,
|
||||
teacher TEXT NOT NULL
|
||||
)
|
||||
""")
|
||||
}
|
||||
|
||||
private fun migrateStudents(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
CREATE TABLE IF NOT EXISTS Students_tmp (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
scrapper_base_url TEXT NOT NULL,
|
||||
mobile_base_url TEXT NOT NULL,
|
||||
is_parent INTEGER NOT NULL,
|
||||
login_type TEXT NOT NULL,
|
||||
login_mode TEXT NOT NULL,
|
||||
certificate_key TEXT NOT NULL,
|
||||
private_key TEXT NOT NULL,
|
||||
email TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
symbol TEXT NOT NULL,
|
||||
student_id INTEGER NOT NULL,
|
||||
user_login_id INTEGER NOT NULL,
|
||||
student_name TEXT NOT NULL,
|
||||
school_id TEXT NOT NULL,
|
||||
school_name TEXT NOT NULL,
|
||||
class_name TEXT NOT NULL,
|
||||
class_id INTEGER NOT NULL,
|
||||
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;")
|
||||
|
||||
database.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)")
|
||||
}
|
||||
|
||||
private fun migrateSharedPreferences() {
|
||||
if (sharedPrefProvider.getString("grade_modifier_plus", "0.0") == "0.0") {
|
||||
sharedPrefProvider.putString("grade_modifier_plus", "0.33")
|
||||
}
|
||||
if (sharedPrefProvider.getString("grade_modifier_minus", "0.0") == "0.0") {
|
||||
sharedPrefProvider.putString("grade_modifier_minus", "0.33")
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +1,24 @@
|
||||
package io.github.wulkanowy.data.repositories.attendance
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.Attendance
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.utils.toLocalDate
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import org.threeten.bp.LocalDate
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class AttendanceRemote @Inject constructor(private val api: Api) {
|
||||
class AttendanceRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getAttendance(semester: Semester, startDate: LocalDate, endDate: LocalDate): Single<List<Attendance>> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { it.getAttendance(startDate, endDate) }.map { attendance ->
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getAttendance(startDate, endDate, semester.semesterId)
|
||||
.map { attendance ->
|
||||
attendance.map {
|
||||
Attendance(
|
||||
studentId = semester.studentId,
|
||||
diaryId = semester.diaryId,
|
||||
date = it.date.toLocalDate(),
|
||||
date = it.date,
|
||||
number = it.number,
|
||||
subject = it.subject,
|
||||
name = it.name,
|
||||
|
@ -1,18 +1,18 @@
|
||||
package io.github.wulkanowy.data.repositories.attendancesummary
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.AttendanceSummary
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class AttendanceSummaryRemote @Inject constructor(private val api: Api) {
|
||||
class AttendanceSummaryRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getAttendanceSummary(semester: Semester, subjectId: Int): Single<List<AttendanceSummary>> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { api.getAttendanceSummary(subjectId) }.map { attendance ->
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getAttendanceSummary(subjectId)
|
||||
.map { attendance ->
|
||||
attendance.map {
|
||||
AttendanceSummary(
|
||||
studentId = semester.studentId,
|
||||
|
@ -1,27 +1,25 @@
|
||||
package io.github.wulkanowy.data.repositories.completedlessons
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.api.toLocalDate
|
||||
import io.github.wulkanowy.data.db.entities.CompletedLesson
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import org.threeten.bp.LocalDate
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class CompletedLessonsRemote @Inject constructor(private val api: Api) {
|
||||
class CompletedLessonsRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getCompletedLessons(semester: Semester, startDate: LocalDate, endDate: LocalDate): Single<List<CompletedLesson>> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { it.getCompletedLessons(startDate, endDate) }
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getCompletedLessons(startDate, endDate)
|
||||
.map { lessons ->
|
||||
lessons.map {
|
||||
it.absence
|
||||
CompletedLesson(
|
||||
studentId = semester.studentId,
|
||||
diaryId = semester.diaryId,
|
||||
date = it.date.toLocalDate(),
|
||||
date = it.date,
|
||||
number = it.number,
|
||||
subject = it.subject,
|
||||
topic = it.topic,
|
||||
|
@ -1,26 +1,25 @@
|
||||
package io.github.wulkanowy.data.repositories.exam
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.Exam
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.utils.toLocalDate
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import org.threeten.bp.LocalDate
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class ExamRemote @Inject constructor(private val api: Api) {
|
||||
class ExamRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getExams(semester: Semester, startDate: LocalDate, endDate: LocalDate): Single<List<Exam>> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { it.getExams(startDate, endDate) }.map { exams ->
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getExams(startDate, endDate, semester.semesterId)
|
||||
.map { exams ->
|
||||
exams.map {
|
||||
Exam(
|
||||
studentId = semester.studentId,
|
||||
diaryId = semester.diaryId,
|
||||
date = it.date.toLocalDate(),
|
||||
entryDate = it.entryDate.toLocalDate(),
|
||||
date = it.date,
|
||||
entryDate = it.entryDate,
|
||||
subject = it.subject,
|
||||
group = it.group,
|
||||
type = it.type,
|
||||
|
@ -1,35 +1,33 @@
|
||||
package io.github.wulkanowy.data.repositories.grade
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.Grade
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.utils.toLocalDate
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class GradeRemote @Inject constructor(private val api: Api) {
|
||||
class GradeRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getGrades(semester: Semester): Single<List<Grade>> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { it.getGrades(semester.semesterId) }
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getGrades(semester.semesterId)
|
||||
.map { grades ->
|
||||
grades.map {
|
||||
Grade(
|
||||
semesterId = semester.semesterId,
|
||||
studentId = semester.studentId,
|
||||
semesterId = semester.semesterId,
|
||||
subject = it.subject,
|
||||
entry = it.entry,
|
||||
value = it.value,
|
||||
modifier = it.modifier,
|
||||
comment = it.comment,
|
||||
color = it.color,
|
||||
gradeSymbol = it.symbol.orEmpty(),
|
||||
description = it.description.orEmpty(),
|
||||
gradeSymbol = it.symbol,
|
||||
description = it.description,
|
||||
weight = it.weight,
|
||||
weightValue = it.weightValue,
|
||||
date = it.date.toLocalDate(),
|
||||
date = it.date,
|
||||
teacher = it.teacher
|
||||
)
|
||||
}
|
||||
|
@ -1,24 +1,23 @@
|
||||
package io.github.wulkanowy.data.repositories.gradessummary
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.GradeSummary
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class GradeSummaryRemote @Inject constructor(private val api: Api) {
|
||||
class GradeSummaryRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getGradeSummary(semester: Semester): Single<List<GradeSummary>> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { it.getGradesSummary(semester.semesterId) }
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getGradesSummary(semester.semesterId)
|
||||
.map { gradesSummary ->
|
||||
gradesSummary.map {
|
||||
GradeSummary(
|
||||
semesterId = semester.semesterId,
|
||||
studentId = semester.studentId,
|
||||
position = it.order,
|
||||
position = 0,
|
||||
subject = it.name,
|
||||
predictedGrade = it.predicted,
|
||||
finalGrade = it.final,
|
||||
|
@ -1,39 +1,36 @@
|
||||
package io.github.wulkanowy.data.repositories.gradestatistics
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.GradePointsStatistics
|
||||
import io.github.wulkanowy.data.db.entities.GradeStatistics
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class GradeStatisticsRemote @Inject constructor(private val api: Api) {
|
||||
class GradeStatisticsRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getGradeStatistics(semester: Semester, isSemester: Boolean): Single<List<GradeStatistics>> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap {
|
||||
if (isSemester) it.getGradesAnnualStatistics(semester.semesterId)
|
||||
else it.getGradesPartialStatistics(semester.semesterId)
|
||||
}
|
||||
.map { gradeStatistics ->
|
||||
gradeStatistics.map {
|
||||
GradeStatistics(
|
||||
semesterId = semester.semesterId,
|
||||
studentId = semester.studentId,
|
||||
subject = it.subject,
|
||||
grade = it.gradeValue,
|
||||
amount = it.amount ?: 0,
|
||||
semester = isSemester
|
||||
)
|
||||
}
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).let {
|
||||
if (isSemester) it.getGradesAnnualStatistics(semester.semesterId)
|
||||
else it.getGradesPartialStatistics(semester.semesterId)
|
||||
}.map { gradeStatistics ->
|
||||
gradeStatistics.map {
|
||||
GradeStatistics(
|
||||
semesterId = semester.semesterId,
|
||||
studentId = semester.studentId,
|
||||
subject = it.subject,
|
||||
grade = it.gradeValue,
|
||||
amount = it.amount,
|
||||
semester = isSemester
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getGradePointsStatistics(semester: Semester): Single<List<GradePointsStatistics>> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { it.getGradesPointsStatistics(semester.semesterId) }
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getGradesPointsStatistics(semester.semesterId)
|
||||
.map { gradePointsStatistics ->
|
||||
gradePointsStatistics.map {
|
||||
GradePointsStatistics(
|
||||
|
@ -1,27 +1,25 @@
|
||||
package io.github.wulkanowy.data.repositories.homework
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.Homework
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.utils.toLocalDate
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import org.threeten.bp.LocalDate
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class HomeworkRemote @Inject constructor(private val api: Api) {
|
||||
class HomeworkRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getHomework(semester: Semester, startDate: LocalDate, endDate: LocalDate): Single<List<Homework>> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { it.getHomework(startDate, endDate) }
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getHomework(startDate, endDate)
|
||||
.map { homework ->
|
||||
homework.map {
|
||||
Homework(
|
||||
semesterId = semester.semesterId,
|
||||
studentId = semester.studentId,
|
||||
date = it.date.toLocalDate(),
|
||||
entryDate = it.entryDate.toLocalDate(),
|
||||
date = it.date,
|
||||
entryDate = it.entryDate,
|
||||
subject = it.subject,
|
||||
content = it.content,
|
||||
teacher = it.teacher,
|
||||
|
@ -1,20 +1,18 @@
|
||||
package io.github.wulkanowy.data.repositories.luckynumber
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.LuckyNumber
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Maybe
|
||||
import io.reactivex.Single
|
||||
import org.threeten.bp.LocalDate
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class LuckyNumberRemote @Inject constructor(private val api: Api) {
|
||||
class LuckyNumberRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getLuckyNumber(semester: Semester): Maybe<LuckyNumber> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMapMaybe { it.getLuckyNumber() }
|
||||
return sdk.getLuckyNumber()
|
||||
.map {
|
||||
LuckyNumber(
|
||||
studentId = semester.studentId,
|
||||
|
@ -1,23 +1,23 @@
|
||||
package io.github.wulkanowy.data.repositories.message
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.api.messages.Folder
|
||||
import io.github.wulkanowy.api.messages.SentMessage
|
||||
import io.github.wulkanowy.data.db.entities.Message
|
||||
import io.github.wulkanowy.data.db.entities.Recipient
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.utils.toLocalDateTime
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.github.wulkanowy.sdk.pojo.Folder
|
||||
import io.github.wulkanowy.sdk.pojo.SentMessage
|
||||
import io.reactivex.Single
|
||||
import org.threeten.bp.LocalDateTime.now
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import io.github.wulkanowy.api.messages.Recipient as ApiRecipient
|
||||
import io.github.wulkanowy.sdk.pojo.Recipient as SdkRecipient
|
||||
|
||||
@Singleton
|
||||
class MessageRemote @Inject constructor(private val api: Api) {
|
||||
class MessageRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getMessages(student: Student, folder: MessageFolder): Single<List<Message>> {
|
||||
return api.getMessages(Folder.valueOf(folder.name)).map { messages ->
|
||||
fun getMessages(student: Student, semester: Semester, folder: MessageFolder): Single<List<Message>> {
|
||||
return sdk.getMessages(Folder.valueOf(folder.name), semester.start.atStartOfDay(), semester.end.atStartOfDay()).map { messages ->
|
||||
messages.map {
|
||||
Message(
|
||||
studentId = student.id.toInt(),
|
||||
@ -27,7 +27,8 @@ class MessageRemote @Inject constructor(private val api: Api) {
|
||||
senderId = it.senderId ?: 0,
|
||||
recipient = it.recipient.orEmpty(),
|
||||
subject = it.subject.trim(),
|
||||
date = it.date?.toLocalDateTime() ?: now(),
|
||||
date = it.date ?: now(),
|
||||
content = it.content.orEmpty(),
|
||||
folderId = it.folderId,
|
||||
unread = it.unread ?: false,
|
||||
unreadBy = it.unreadBy ?: 0,
|
||||
@ -39,27 +40,28 @@ class MessageRemote @Inject constructor(private val api: Api) {
|
||||
}
|
||||
|
||||
fun getMessagesContent(message: Message, markAsRead: Boolean = false): Single<String> {
|
||||
return api.getMessageContent(message.messageId, message.folderId, markAsRead, message.realId)
|
||||
return sdk.getMessageContent(message.messageId, message.folderId, markAsRead, message.realId)
|
||||
}
|
||||
|
||||
fun sendMessage(subject: String, content: String, recipients: List<Recipient>): Single<SentMessage> {
|
||||
return api.sendMessage(
|
||||
return sdk.sendMessage(
|
||||
subject = subject,
|
||||
content = content,
|
||||
recipients = recipients.map {
|
||||
ApiRecipient(
|
||||
SdkRecipient(
|
||||
id = it.realId,
|
||||
name = it.realName,
|
||||
loginId = it.loginId,
|
||||
reportingUnitId = it.unitId,
|
||||
role = it.role,
|
||||
hash = it.hash
|
||||
hash = it.hash,
|
||||
shortName = it.name
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun deleteMessage(message: Message): Single<Boolean> {
|
||||
return api.deleteMessages(listOf(Pair(message.realId, message.folderId)))
|
||||
return sdk.deleteMessages(listOf(Pair(message.realId, message.folderId)))
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,13 @@ package io.github.wulkanowy.data.repositories.message
|
||||
|
||||
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
|
||||
import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingSettings
|
||||
import io.github.wulkanowy.api.messages.SentMessage
|
||||
import io.github.wulkanowy.data.ApiHelper
|
||||
import io.github.wulkanowy.data.SdkHelper
|
||||
import io.github.wulkanowy.data.db.entities.Message
|
||||
import io.github.wulkanowy.data.db.entities.Recipient
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.message.MessageFolder.RECEIVED
|
||||
import io.github.wulkanowy.sdk.pojo.SentMessage
|
||||
import io.github.wulkanowy.utils.uniqueSubtract
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Maybe
|
||||
@ -21,16 +22,16 @@ class MessageRepository @Inject constructor(
|
||||
private val settings: InternetObservingSettings,
|
||||
private val local: MessageLocal,
|
||||
private val remote: MessageRemote,
|
||||
private val apiHelper: ApiHelper
|
||||
private val sdkHelper: SdkHelper
|
||||
) {
|
||||
|
||||
fun getMessages(student: Student, folder: MessageFolder, forceRefresh: Boolean = false, notify: Boolean = false): Single<List<Message>> {
|
||||
return Single.just(apiHelper.initApi(student))
|
||||
fun getMessages(student: Student, semester: Semester, folder: MessageFolder, forceRefresh: Boolean = false, notify: Boolean = false): Single<List<Message>> {
|
||||
return Single.just(sdkHelper.init(student))
|
||||
.flatMap { _ ->
|
||||
local.getMessages(student, folder).filter { !forceRefresh }
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
.flatMap {
|
||||
if (it) remote.getMessages(student, folder)
|
||||
if (it) remote.getMessages(student, semester, folder)
|
||||
else Single.error(UnknownHostException())
|
||||
}.flatMap { new ->
|
||||
local.getMessages(student, folder).toSingle(emptyList())
|
||||
@ -47,10 +48,10 @@ class MessageRepository @Inject constructor(
|
||||
}
|
||||
|
||||
fun getMessage(student: Student, messageDbId: Long, markAsRead: Boolean = false): Single<Message> {
|
||||
return Single.just(apiHelper.initApi(student))
|
||||
return Single.just(sdkHelper.init(student))
|
||||
.flatMap { _ ->
|
||||
local.getMessage(messageDbId)
|
||||
.filter { !it.content.isNullOrEmpty() }
|
||||
.filter { it.content.isNotEmpty() }
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
.flatMap {
|
||||
if (it) local.getMessage(messageDbId).toSingle()
|
||||
@ -60,7 +61,7 @@ class MessageRepository @Inject constructor(
|
||||
remote.getMessagesContent(dbMessage, markAsRead).doOnSuccess {
|
||||
local.updateMessages(listOf(dbMessage.copy(unread = false).apply {
|
||||
id = dbMessage.id
|
||||
content = it
|
||||
content = content.ifBlank { it }
|
||||
}))
|
||||
}
|
||||
}.flatMap {
|
||||
|
@ -1,25 +1,23 @@
|
||||
package io.github.wulkanowy.data.repositories.mobiledevice
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.MobileDevice
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.pojos.MobileDeviceToken
|
||||
import io.github.wulkanowy.utils.toLocalDateTime
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class MobileDeviceRemote @Inject constructor(private val api: Api) {
|
||||
class MobileDeviceRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getDevices(semester: Semester): Single<List<MobileDevice>> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { api.getRegisteredDevices() }
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getRegisteredDevices()
|
||||
.map { devices ->
|
||||
devices.map {
|
||||
MobileDevice(
|
||||
studentId = semester.studentId,
|
||||
date = it.date.toLocalDateTime(),
|
||||
date = it.date,
|
||||
deviceId = it.id,
|
||||
name = it.name
|
||||
)
|
||||
@ -28,13 +26,11 @@ class MobileDeviceRemote @Inject constructor(private val api: Api) {
|
||||
}
|
||||
|
||||
fun unregisterDevice(semester: Semester, device: MobileDevice): Single<Boolean> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { api.unregisterDevice(device.deviceId) }
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).unregisterDevice(device.deviceId)
|
||||
}
|
||||
|
||||
fun getToken(semester: Semester): Single<MobileDeviceToken> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { api.getToken() }
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getToken()
|
||||
.map {
|
||||
MobileDeviceToken(
|
||||
token = it.token,
|
||||
|
@ -1,24 +1,22 @@
|
||||
package io.github.wulkanowy.data.repositories.note
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.Note
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.utils.toLocalDate
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class NoteRemote @Inject constructor(private val api: Api) {
|
||||
class NoteRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getNotes(semester: Semester): Single<List<Note>> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { it.getNotes() }
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getNotes(semester.semesterId)
|
||||
.map { notes ->
|
||||
notes.map {
|
||||
Note(
|
||||
studentId = semester.studentId,
|
||||
date = it.date.toLocalDate(),
|
||||
date = it.date,
|
||||
teacher = it.teacher,
|
||||
category = it.category,
|
||||
content = it.content
|
||||
|
@ -1,34 +1,34 @@
|
||||
package io.github.wulkanowy.data.repositories.recipient
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.Message
|
||||
import io.github.wulkanowy.data.db.entities.Recipient
|
||||
import io.github.wulkanowy.data.db.entities.ReportingUnit
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import io.github.wulkanowy.api.messages.Recipient as ApiRecipient
|
||||
import io.github.wulkanowy.sdk.pojo.Recipient as SdkRecipient
|
||||
|
||||
@Singleton
|
||||
class RecipientRemote @Inject constructor(private val api: Api) {
|
||||
class RecipientRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getRecipients(role: Int, unit: ReportingUnit): Single<List<Recipient>> {
|
||||
return api.getRecipients(unit.realId, role)
|
||||
return sdk.getRecipients(unit.realId, role)
|
||||
.map { recipients ->
|
||||
recipients.map { it.toRecipient() }
|
||||
}
|
||||
}
|
||||
|
||||
fun getMessageRecipients(message: Message): Single<List<Recipient>> {
|
||||
return api.getMessageRecipients(message.messageId, message.senderId)
|
||||
return sdk.getMessageRecipients(message.messageId, message.senderId)
|
||||
.map { recipients ->
|
||||
recipients.map { it.toRecipient() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun ApiRecipient.toRecipient(): Recipient {
|
||||
private fun SdkRecipient.toRecipient(): Recipient {
|
||||
return Recipient(
|
||||
studentId = api.studentId,
|
||||
studentId = sdk.studentId,
|
||||
realId = id,
|
||||
realName = name,
|
||||
name = shortName,
|
||||
|
@ -2,7 +2,7 @@ package io.github.wulkanowy.data.repositories.recipient
|
||||
|
||||
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
|
||||
import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingSettings
|
||||
import io.github.wulkanowy.data.ApiHelper
|
||||
import io.github.wulkanowy.data.SdkHelper
|
||||
import io.github.wulkanowy.data.db.entities.Message
|
||||
import io.github.wulkanowy.data.db.entities.Recipient
|
||||
import io.github.wulkanowy.data.db.entities.ReportingUnit
|
||||
@ -18,11 +18,11 @@ class RecipientRepository @Inject constructor(
|
||||
private val settings: InternetObservingSettings,
|
||||
private val local: RecipientLocal,
|
||||
private val remote: RecipientRemote,
|
||||
private val apiHelper: ApiHelper
|
||||
private val sdkHelper: SdkHelper
|
||||
) {
|
||||
|
||||
fun getRecipients(student: Student, role: Int, unit: ReportingUnit, forceRefresh: Boolean = false): Single<List<Recipient>> {
|
||||
return Single.just(apiHelper.initApi(student))
|
||||
return Single.just(sdkHelper.init(student))
|
||||
.flatMap { _ ->
|
||||
local.getRecipients(student, role, unit).filter { !forceRefresh }
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
@ -43,7 +43,7 @@ class RecipientRepository @Inject constructor(
|
||||
}
|
||||
|
||||
fun getMessageRecipients(student: Student, message: Message): Single<List<Recipient>> {
|
||||
return Single.just(apiHelper.initApi(student))
|
||||
return Single.just(sdkHelper.init(student))
|
||||
.flatMap { ReactiveNetwork.checkInternetConnectivity(settings) }
|
||||
.flatMap {
|
||||
if (it) remote.getMessageRecipients(message)
|
||||
|
@ -1,19 +1,19 @@
|
||||
package io.github.wulkanowy.data.repositories.reportingunit
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.ReportingUnit
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class ReportingUnitRemote @Inject constructor(private val api: Api) {
|
||||
class ReportingUnitRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getReportingUnits(): Single<List<ReportingUnit>> {
|
||||
return api.getReportingUnits().map {
|
||||
return sdk.getReportingUnits().map {
|
||||
it.map { unit ->
|
||||
ReportingUnit(
|
||||
studentId = api.studentId,
|
||||
studentId = sdk.studentId,
|
||||
realId = unit.id,
|
||||
roles = unit.roles,
|
||||
senderId = unit.senderId,
|
||||
|
@ -2,7 +2,7 @@ package io.github.wulkanowy.data.repositories.reportingunit
|
||||
|
||||
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
|
||||
import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingSettings
|
||||
import io.github.wulkanowy.data.ApiHelper
|
||||
import io.github.wulkanowy.data.SdkHelper
|
||||
import io.github.wulkanowy.data.db.entities.ReportingUnit
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.utils.uniqueSubtract
|
||||
@ -17,11 +17,11 @@ class ReportingUnitRepository @Inject constructor(
|
||||
private val settings: InternetObservingSettings,
|
||||
private val local: ReportingUnitLocal,
|
||||
private val remote: ReportingUnitRemote,
|
||||
private val apiHelper: ApiHelper
|
||||
private val sdkHelper: SdkHelper
|
||||
) {
|
||||
|
||||
fun getReportingUnits(student: Student, forceRefresh: Boolean = false): Single<List<ReportingUnit>> {
|
||||
return Single.just(apiHelper.initApi(student))
|
||||
return Single.just(sdkHelper.init(student))
|
||||
.flatMap { _ ->
|
||||
local.getReportingUnits(student).filter { !forceRefresh }
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
@ -40,7 +40,7 @@ class ReportingUnitRepository @Inject constructor(
|
||||
}
|
||||
|
||||
fun getReportingUnit(student: Student, unitId: Int): Maybe<ReportingUnit> {
|
||||
return Maybe.just(apiHelper.initApi(student))
|
||||
return Maybe.just(sdkHelper.init(student))
|
||||
.flatMap { _ ->
|
||||
local.getReportingUnit(student, unitId)
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
|
@ -1,16 +1,15 @@
|
||||
package io.github.wulkanowy.data.repositories.school
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.School
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
|
||||
class SchoolRemote @Inject constructor(private val api: Api) {
|
||||
class SchoolRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getSchoolInfo(semester: Semester): Single<School> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { it.getSchool() }
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getSchool()
|
||||
.map {
|
||||
School(
|
||||
studentId = semester.studentId,
|
||||
|
@ -1,35 +1,32 @@
|
||||
package io.github.wulkanowy.data.repositories.semester
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class SemesterRemote @Inject constructor(private val api: Api) {
|
||||
class SemesterRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getSemesters(student: Student): Single<List<Semester>> {
|
||||
return api.getSemesters().map { semesters ->
|
||||
semesters.map { semester ->
|
||||
return sdk.getSemesters().map { semesters ->
|
||||
semesters.map {
|
||||
Semester(
|
||||
studentId = student.studentId,
|
||||
diaryId = semester.diaryId,
|
||||
diaryName = semester.diaryName,
|
||||
schoolYear = semester.schoolYear,
|
||||
semesterId = semester.semesterId,
|
||||
semesterName = semester.semesterNumber,
|
||||
isCurrent = semester.current,
|
||||
start = semester.start,
|
||||
end = semester.end,
|
||||
classId = semester.classId,
|
||||
unitId = semester.unitId
|
||||
diaryId = it.diaryId,
|
||||
diaryName = it.diaryName,
|
||||
schoolYear = it.schoolYear,
|
||||
semesterId = it.semesterId,
|
||||
semesterName = it.semesterNumber,
|
||||
isCurrent = it.current,
|
||||
start = it.start,
|
||||
end = it.end,
|
||||
classId = it.classId,
|
||||
unitId = it.unitId
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@ package io.github.wulkanowy.data.repositories.semester
|
||||
|
||||
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
|
||||
import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingSettings
|
||||
import io.github.wulkanowy.data.ApiHelper
|
||||
import io.github.wulkanowy.data.SdkHelper
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.utils.uniqueSubtract
|
||||
@ -18,11 +18,11 @@ class SemesterRepository @Inject constructor(
|
||||
private val remote: SemesterRemote,
|
||||
private val local: SemesterLocal,
|
||||
private val settings: InternetObservingSettings,
|
||||
private val apiHelper: ApiHelper
|
||||
private val sdkHelper: SdkHelper
|
||||
) {
|
||||
|
||||
fun getSemesters(student: Student, forceRefresh: Boolean = false): Single<List<Semester>> {
|
||||
return Maybe.just(apiHelper.initApi(student))
|
||||
return Maybe.just(sdkHelper.init(student))
|
||||
.flatMap { local.getSemesters(student).filter { !forceRefresh } }
|
||||
.switchIfEmpty(ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
.flatMap {
|
||||
|
@ -3,6 +3,7 @@ package io.github.wulkanowy.data.repositories.student
|
||||
import android.content.Context
|
||||
import io.github.wulkanowy.data.db.dao.StudentDao
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.github.wulkanowy.utils.security.decrypt
|
||||
import io.github.wulkanowy.utils.security.encrypt
|
||||
import io.reactivex.Completable
|
||||
@ -18,7 +19,12 @@ class StudentLocal @Inject constructor(
|
||||
) {
|
||||
|
||||
fun saveStudents(students: List<Student>): Single<List<Long>> {
|
||||
return Single.fromCallable { studentDb.insertAll(students.map { it.copy(password = encrypt(it.password, context)) }) }
|
||||
return Single.fromCallable {
|
||||
studentDb.insertAll(students.map {
|
||||
if (Sdk.Mode.valueOf(it.loginMode) != Sdk.Mode.API) it.copy(password = encrypt(it.password, context))
|
||||
else it
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fun getStudents(decryptPass: Boolean): Maybe<List<Student>> {
|
||||
@ -28,7 +34,11 @@ class StudentLocal @Inject constructor(
|
||||
}
|
||||
|
||||
fun getCurrentStudent(decryptPass: Boolean): Maybe<Student> {
|
||||
return studentDb.loadCurrent().map { it.apply { if (decryptPass) password = decrypt(password) } }
|
||||
return studentDb.loadCurrent().map {
|
||||
it.apply {
|
||||
if (decryptPass && Sdk.Mode.valueOf(loginMode) != Sdk.Mode.API) password = decrypt(password)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setCurrentStudent(student: Student): Completable {
|
||||
|
@ -1,34 +1,51 @@
|
||||
package io.github.wulkanowy.data.repositories.student
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import org.threeten.bp.LocalDateTime.now
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import io.github.wulkanowy.sdk.pojo.Student as SdkStudent
|
||||
|
||||
@Singleton
|
||||
class StudentRemote @Inject constructor(private val api: Api) {
|
||||
class StudentRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getStudents(email: String, password: String, endpoint: String): Single<List<Student>> {
|
||||
return api.getStudents().map { students ->
|
||||
students.map { student ->
|
||||
Student(
|
||||
email = email,
|
||||
password = password,
|
||||
symbol = student.symbol,
|
||||
studentId = student.studentId,
|
||||
studentName = student.studentName,
|
||||
schoolSymbol = student.schoolSymbol,
|
||||
schoolName = student.schoolName,
|
||||
className = student.className,
|
||||
classId = student.classId,
|
||||
endpoint = endpoint,
|
||||
loginType = student.loginType.name,
|
||||
isCurrent = false,
|
||||
registrationDate = now()
|
||||
)
|
||||
}
|
||||
private fun mapStudents(students: List<SdkStudent>, email: String, password: String): List<Student> {
|
||||
return students.map { student ->
|
||||
Student(
|
||||
email = email,
|
||||
password = password,
|
||||
isParent = student.isParent,
|
||||
symbol = student.symbol,
|
||||
studentId = student.studentId,
|
||||
userLoginId = student.userLoginId,
|
||||
studentName = student.studentName,
|
||||
schoolSymbol = student.schoolSymbol,
|
||||
schoolName = student.schoolName,
|
||||
className = student.className,
|
||||
classId = student.classId,
|
||||
scrapperBaseUrl = student.scrapperBaseUrl,
|
||||
loginType = student.loginType.name,
|
||||
isCurrent = false,
|
||||
registrationDate = now(),
|
||||
mobileBaseUrl = student.mobileBaseUrl,
|
||||
privateKey = student.privateKey,
|
||||
certificateKey = student.certificateKey,
|
||||
loginMode = student.loginMode.name
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun getStudentsMobileApi(token: String, pin: String, symbol: String): Single<List<Student>> {
|
||||
return sdk.getStudentsFromMobileApi(token, pin, symbol).map { mapStudents(it, "", "") }
|
||||
}
|
||||
|
||||
fun getStudentsScrapper(email: String, password: String, scrapperBaseUrl: String, symbol: String): Single<List<Student>> {
|
||||
return sdk.getStudentsFromScrapper(email, password, scrapperBaseUrl, symbol).map { mapStudents(it, email, password) }
|
||||
}
|
||||
|
||||
fun getStudentsHybrid(email: String, password: String, scrapperBaseUrl: String, symbol: String): Single<List<Student>> {
|
||||
return sdk.getStudentsHybrid(email, password, scrapperBaseUrl, symbol).map { mapStudents(it, email, password) }
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package io.github.wulkanowy.data.repositories.student
|
||||
|
||||
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
|
||||
import com.github.pwittchen.reactivenetwork.library.rx2.internet.observing.InternetObservingSettings
|
||||
import io.github.wulkanowy.data.ApiHelper
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.exceptions.NoCurrentStudentException
|
||||
import io.reactivex.Completable
|
||||
@ -16,21 +15,32 @@ import javax.inject.Singleton
|
||||
class StudentRepository @Inject constructor(
|
||||
private val local: StudentLocal,
|
||||
private val remote: StudentRemote,
|
||||
private val settings: InternetObservingSettings,
|
||||
private val apiHelper: ApiHelper
|
||||
private val settings: InternetObservingSettings
|
||||
) {
|
||||
|
||||
fun isStudentSaved(): Single<Boolean> = local.getStudents(false).isEmpty.map { !it }
|
||||
|
||||
fun isCurrentStudentSet(): Single<Boolean> = local.getCurrentStudent(false).isEmpty.map { !it }
|
||||
|
||||
fun getStudents(email: String, password: String, endpoint: String, symbol: String = ""): Single<List<Student>> {
|
||||
return ReactiveNetwork.checkInternetConnectivity(settings)
|
||||
.flatMap {
|
||||
apiHelper.initApi(email, password, symbol, endpoint)
|
||||
if (it) remote.getStudents(email, password, endpoint)
|
||||
else Single.error(UnknownHostException("No internet connection"))
|
||||
}
|
||||
fun getStudentsApi(pin: String, symbol: String, token: String): Single<List<Student>> {
|
||||
return ReactiveNetwork.checkInternetConnectivity(settings).flatMap {
|
||||
if (it) remote.getStudentsMobileApi(token, pin, symbol)
|
||||
else Single.error(UnknownHostException("No internet connection"))
|
||||
}
|
||||
}
|
||||
|
||||
fun getStudentsScrapper(email: String, password: String, endpoint: String, symbol: String = ""): Single<List<Student>> {
|
||||
return ReactiveNetwork.checkInternetConnectivity(settings).flatMap {
|
||||
if (it) remote.getStudentsScrapper(email, password, endpoint, symbol)
|
||||
else Single.error(UnknownHostException("No internet connection"))
|
||||
}
|
||||
}
|
||||
|
||||
fun getStudentsHybrid(email: String, password: String, endpoint: String, symbol: String): Single<List<Student>> {
|
||||
return ReactiveNetwork.checkInternetConnectivity(settings).flatMap {
|
||||
if (it) remote.getStudentsHybrid(email, password, endpoint, symbol)
|
||||
else Single.error(UnknownHostException("No internet connection"))
|
||||
}
|
||||
}
|
||||
|
||||
fun getSavedStudents(decryptPass: Boolean = true): Single<List<Student>> {
|
||||
|
@ -1,25 +1,24 @@
|
||||
package io.github.wulkanowy.data.repositories.subject
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Subject
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class SubjectRemote @Inject constructor(private val api: Api) {
|
||||
class SubjectRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getSubjects(semester: Semester): Single<List<Subject>> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { api.getSubjects() }
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getSubjects()
|
||||
.map { subjects ->
|
||||
subjects.map {
|
||||
Subject(
|
||||
studentId = semester.studentId,
|
||||
diaryId = semester.diaryId,
|
||||
name = it.name,
|
||||
realId = it.value
|
||||
realId = it.id
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,17 @@
|
||||
package io.github.wulkanowy.data.repositories.teacher
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Teacher
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class TeacherRemote @Inject constructor(private val api: Api) {
|
||||
class TeacherRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getTeachers(semester: Semester): Single<List<Teacher>> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { it.getTeachers() }
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getTeachers(semester.semesterId)
|
||||
.map { teachers ->
|
||||
teachers.map {
|
||||
Teacher(
|
||||
|
@ -1,30 +1,27 @@
|
||||
package io.github.wulkanowy.data.repositories.timetable
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Timetable
|
||||
import io.github.wulkanowy.utils.toLocalDate
|
||||
import io.github.wulkanowy.utils.toLocalDateTime
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.reactivex.Single
|
||||
import org.threeten.bp.LocalDate
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class TimetableRemote @Inject constructor(private val api: Api) {
|
||||
class TimetableRemote @Inject constructor(private val sdk: Sdk) {
|
||||
|
||||
fun getTimetable(semester: Semester, startDate: LocalDate, endDate: LocalDate): Single<List<Timetable>> {
|
||||
return Single.just(api.apply { diaryId = semester.diaryId })
|
||||
.flatMap { it.getTimetable(startDate, endDate) }
|
||||
return sdk.switchDiary(semester.diaryId, semester.schoolYear).getTimetable(startDate, endDate)
|
||||
.map { lessons ->
|
||||
lessons.map {
|
||||
Timetable(
|
||||
studentId = semester.studentId,
|
||||
diaryId = semester.diaryId,
|
||||
number = it.number,
|
||||
start = it.start.toLocalDateTime(),
|
||||
end = it.end.toLocalDateTime(),
|
||||
date = it.date.toLocalDate(),
|
||||
start = it.start,
|
||||
end = it.end,
|
||||
date = it.date,
|
||||
subject = it.subject,
|
||||
subjectOld = it.subjectOld,
|
||||
group = it.group,
|
||||
|
@ -11,10 +11,10 @@ import androidx.work.WorkerParameters
|
||||
import com.squareup.inject.assisted.Assisted
|
||||
import com.squareup.inject.assisted.AssistedInject
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.api.interceptor.FeatureDisabledException
|
||||
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
|
||||
import io.github.wulkanowy.data.repositories.semester.SemesterRepository
|
||||
import io.github.wulkanowy.data.repositories.student.StudentRepository
|
||||
import io.github.wulkanowy.sdk.exception.FeatureDisabledException
|
||||
import io.github.wulkanowy.services.sync.channels.DebugChannel
|
||||
import io.github.wulkanowy.services.sync.works.Work
|
||||
import io.github.wulkanowy.utils.getCompatColor
|
||||
@ -78,4 +78,3 @@ class SyncWorker @AssistedInject constructor(
|
||||
fun create(appContext: Context, workerParameters: WorkerParameters): ListenableWorker
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ class MessageWork @Inject constructor(
|
||||
) : Work {
|
||||
|
||||
override fun create(student: Student, semester: Semester): Completable {
|
||||
return messageRepository.getMessages(student, RECEIVED, true, preferencesRepository.isNotificationsEnable)
|
||||
return messageRepository.getMessages(student, semester, RECEIVED, true, preferencesRepository.isNotificationsEnable)
|
||||
.flatMap { messageRepository.getNotNotifiedMessages(student) }
|
||||
.flatMapCompletable {
|
||||
if (it.isNotEmpty()) notify(it)
|
||||
|
@ -1,10 +1,10 @@
|
||||
package io.github.wulkanowy.ui.base
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.os.Build.VERSION.SDK_INT
|
||||
import android.os.Build.VERSION_CODES.LOLLIPOP
|
||||
import android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
import android.os.Build.VERSION.SDK_INT
|
||||
import android.os.Build.VERSION_CODES.LOLLIPOP
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
|
@ -3,11 +3,12 @@ package io.github.wulkanowy.ui.base
|
||||
import android.content.res.Resources
|
||||
import com.readystatesoftware.chuck.api.ChuckCollector
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.api.interceptor.FeatureDisabledException
|
||||
import io.github.wulkanowy.api.interceptor.ServiceUnavailableException
|
||||
import io.github.wulkanowy.api.login.BadCredentialsException
|
||||
import io.github.wulkanowy.api.login.NotLoggedInException
|
||||
import io.github.wulkanowy.data.exceptions.NoCurrentStudentException
|
||||
import io.github.wulkanowy.sdk.exception.BadCredentialsException
|
||||
import io.github.wulkanowy.sdk.exception.FeatureDisabledException
|
||||
import io.github.wulkanowy.sdk.exception.FeatureNotAvailableException
|
||||
import io.github.wulkanowy.sdk.exception.NotLoggedInException
|
||||
import io.github.wulkanowy.sdk.exception.ServiceUnavailableException
|
||||
import io.github.wulkanowy.utils.security.ScramblerException
|
||||
import timber.log.Timber
|
||||
import java.net.SocketTimeoutException
|
||||
@ -38,6 +39,7 @@ open class ErrorHandler @Inject constructor(protected val resources: Resources,
|
||||
is FeatureDisabledException -> showErrorMessage(getString(R.string.error_feature_disabled), error)
|
||||
is ScramblerException, is BadCredentialsException -> onSessionExpired()
|
||||
is NoCurrentStudentException -> onNoCurrentStudent()
|
||||
is FeatureNotAvailableException -> showErrorMessage(getString(R.string.error_feature_not_available), error)
|
||||
else -> showErrorMessage(getString(R.string.error_unknown), error)
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.grade.GradeRepository
|
||||
import io.github.wulkanowy.data.repositories.gradessummary.GradeSummaryRepository
|
||||
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.github.wulkanowy.utils.calcAverage
|
||||
import io.github.wulkanowy.utils.changeModifier
|
||||
import io.reactivex.Maybe
|
||||
@ -40,7 +41,7 @@ class GradeAverageProvider @Inject constructor(
|
||||
.map { secondGrades -> secondGrades + firstGrades }
|
||||
}
|
||||
}.map { grades ->
|
||||
grades.map { it.changeModifier(plusModifier, minusModifier) }
|
||||
grades.map { if (student.loginMode == Sdk.Mode.SCRAPPER.name) it.changeModifier(plusModifier, minusModifier) else it }
|
||||
.groupBy { it.subject }
|
||||
.mapValues { it.value.calcAverage() }
|
||||
})
|
||||
@ -54,7 +55,7 @@ class GradeAverageProvider @Inject constructor(
|
||||
return getAverageFromGradeSummary(selectedSemester, forceRefresh)
|
||||
.switchIfEmpty(gradeRepository.getGrades(student, selectedSemester, forceRefresh)
|
||||
.map { grades ->
|
||||
grades.map { it.changeModifier(plusModifier, minusModifier) }
|
||||
grades.map { if (student.loginMode == Sdk.Mode.SCRAPPER.name) it.changeModifier(plusModifier, minusModifier) else it }
|
||||
.groupBy { it.subject }
|
||||
.mapValues { it.value.calcAverage() }
|
||||
})
|
||||
|
@ -13,7 +13,6 @@ import androidx.appcompat.app.AlertDialog
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.base.BaseFragmentPagerAdapter
|
||||
import io.github.wulkanowy.ui.base.ErrorDialog
|
||||
import io.github.wulkanowy.ui.modules.grade.details.GradeDetailsFragment
|
||||
import io.github.wulkanowy.ui.modules.grade.statistics.GradeStatisticsFragment
|
||||
import io.github.wulkanowy.ui.modules.grade.summary.GradeSummaryFragment
|
||||
|
@ -18,7 +18,6 @@ import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Grade
|
||||
import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.base.ErrorDialog
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeFragment
|
||||
import io.github.wulkanowy.ui.modules.grade.GradeView
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
|
@ -8,6 +8,7 @@ import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.ui.base.BaseActivity
|
||||
import io.github.wulkanowy.ui.base.BaseFragmentPagerAdapter
|
||||
import io.github.wulkanowy.ui.modules.login.advanced.LoginAdvancedFragment
|
||||
import io.github.wulkanowy.ui.modules.login.form.LoginFormFragment
|
||||
import io.github.wulkanowy.ui.modules.login.studentselect.LoginStudentSelectFragment
|
||||
import io.github.wulkanowy.ui.modules.login.symbol.LoginSymbolFragment
|
||||
@ -50,7 +51,8 @@ class LoginActivity : BaseActivity<LoginPresenter>(), LoginView {
|
||||
addFragments(listOf(
|
||||
LoginFormFragment.newInstance(),
|
||||
LoginSymbolFragment.newInstance(),
|
||||
LoginStudentSelectFragment.newInstance()
|
||||
LoginStudentSelectFragment.newInstance(),
|
||||
LoginAdvancedFragment.newInstance()
|
||||
))
|
||||
}
|
||||
|
||||
@ -93,4 +95,8 @@ class LoginActivity : BaseActivity<LoginPresenter>(), LoginView {
|
||||
fun onSymbolFragmentAccountLogged(students: List<Student>) {
|
||||
presenter.onSymbolViewAccountLogged(students)
|
||||
}
|
||||
|
||||
fun onAdvancedLoginClick() {
|
||||
presenter.onAdvancedLoginClick()
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import android.content.res.Resources
|
||||
import android.database.sqlite.SQLiteConstraintException
|
||||
import com.readystatesoftware.chuck.api.ChuckCollector
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.api.login.BadCredentialsException
|
||||
import io.github.wulkanowy.sdk.exception.BadCredentialsException
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -6,6 +6,7 @@ import dagger.android.ContributesAndroidInjector
|
||||
import io.github.wulkanowy.di.scopes.PerActivity
|
||||
import io.github.wulkanowy.di.scopes.PerFragment
|
||||
import io.github.wulkanowy.ui.base.BaseFragmentPagerAdapter
|
||||
import io.github.wulkanowy.ui.modules.login.advanced.LoginAdvancedFragment
|
||||
import io.github.wulkanowy.ui.modules.login.form.LoginFormFragment
|
||||
import io.github.wulkanowy.ui.modules.login.studentselect.LoginStudentSelectFragment
|
||||
import io.github.wulkanowy.ui.modules.login.symbol.LoginSymbolFragment
|
||||
@ -26,6 +27,10 @@ internal abstract class LoginModule {
|
||||
@ContributesAndroidInjector
|
||||
abstract fun bindLoginFormFragment(): LoginFormFragment
|
||||
|
||||
@PerFragment
|
||||
@ContributesAndroidInjector
|
||||
abstract fun bindLoginAdvancedFragment(): LoginAdvancedFragment
|
||||
|
||||
@PerFragment
|
||||
@ContributesAndroidInjector
|
||||
abstract fun bindLoginSymbolFragment(): LoginSymbolFragment
|
||||
|
@ -45,6 +45,10 @@ class LoginPresenter @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun onAdvancedLoginClick() {
|
||||
view?.switchView(3)
|
||||
}
|
||||
|
||||
fun onViewSelected(index: Int) {
|
||||
view?.apply {
|
||||
when (index) {
|
||||
@ -58,7 +62,7 @@ class LoginPresenter @Inject constructor(
|
||||
Timber.i("Back pressed in login view")
|
||||
view?.apply {
|
||||
when (currentViewIndex) {
|
||||
1, 2 -> switchView(0)
|
||||
1, 2, 3 -> switchView(0)
|
||||
else -> default()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,227 @@
|
||||
package io.github.wulkanowy.ui.modules.login.advanced
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.github.wulkanowy.ui.base.BaseFragment
|
||||
import io.github.wulkanowy.ui.modules.login.LoginActivity
|
||||
import io.github.wulkanowy.ui.modules.login.form.LoginSymbolAdapter
|
||||
import io.github.wulkanowy.utils.hideSoftInput
|
||||
import io.github.wulkanowy.utils.showSoftInput
|
||||
import kotlinx.android.synthetic.main.fragment_login_advanced.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class LoginAdvancedFragment : BaseFragment(), LoginAdvancedView {
|
||||
|
||||
@Inject
|
||||
lateinit var presenter: LoginAdvancedPresenter
|
||||
|
||||
companion object {
|
||||
fun newInstance() = LoginAdvancedFragment()
|
||||
}
|
||||
|
||||
override val formLoginType: String
|
||||
get() = when (loginTypeSwitch.checkedRadioButtonId) {
|
||||
R.id.loginTypeApi -> "API"
|
||||
R.id.loginTypeScrapper -> "SCRAPPER"
|
||||
else -> "HYBRID"
|
||||
}
|
||||
|
||||
override val formNameValue: String
|
||||
get() = loginFormName.text.toString().trim()
|
||||
|
||||
override val formPassValue: String
|
||||
get() = loginFormPass.text.toString().trim()
|
||||
|
||||
private lateinit var hostKeys: Array<String>
|
||||
|
||||
private lateinit var hostValues: Array<String>
|
||||
|
||||
override val formHostValue: String?
|
||||
get() = hostValues.getOrNull(hostKeys.indexOf(loginFormHost.text.toString()))
|
||||
|
||||
override val formPinValue: String
|
||||
get() = loginFormPin.text.toString().trim()
|
||||
|
||||
override val formSymbolValue: String
|
||||
get() = loginFormSymbol.text.toString().trim()
|
||||
|
||||
override val formTokenValue: String
|
||||
get() = loginFormToken.text.toString().trim()
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_login_advanced, container, false)
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
presenter.onAttachView(this)
|
||||
}
|
||||
|
||||
override fun initView() {
|
||||
hostKeys = resources.getStringArray(R.array.hosts_keys)
|
||||
hostValues = resources.getStringArray(R.array.hosts_values)
|
||||
|
||||
loginFormName.doOnTextChanged { _, _, _, _ -> presenter.onNameTextChanged() }
|
||||
loginFormPass.doOnTextChanged { _, _, _, _ -> presenter.onPassTextChanged() }
|
||||
loginFormPin.doOnTextChanged { _, _, _, _ -> presenter.onPinTextChanged() }
|
||||
loginFormSymbol.doOnTextChanged { _, _, _, _ -> presenter.onSymbolTextChanged() }
|
||||
loginFormToken.doOnTextChanged { _, _, _, _ -> presenter.onTokenTextChanged() }
|
||||
loginFormHost.setOnItemClickListener { _, _, _, _ -> presenter.onHostSelected() }
|
||||
loginFormSignIn.setOnClickListener { presenter.onSignInClick() }
|
||||
|
||||
loginTypeSwitch.setOnCheckedChangeListener { _, checkedId ->
|
||||
presenter.onLoginModeSelected(when (checkedId) {
|
||||
R.id.loginTypeApi -> Sdk.Mode.API
|
||||
R.id.loginTypeScrapper -> Sdk.Mode.SCRAPPER
|
||||
else -> Sdk.Mode.HYBRID
|
||||
})
|
||||
}
|
||||
|
||||
loginFormSymbol.setAdapter(ArrayAdapter(requireContext(), android.R.layout.simple_list_item_1, resources.getStringArray(R.array.symbols_values)))
|
||||
|
||||
with(loginFormHost) {
|
||||
setText(hostKeys.getOrElse(0) { "" })
|
||||
setAdapter(LoginSymbolAdapter(context, R.layout.support_simple_spinner_dropdown_item, hostKeys))
|
||||
}
|
||||
}
|
||||
|
||||
override fun setDefaultCredentials(name: String, pass: String, symbol: String, token: String, pin: String) {
|
||||
loginFormName.setText(name)
|
||||
loginFormPass.setText(pass)
|
||||
loginFormToken.setText(token)
|
||||
loginFormSymbol.setText(symbol)
|
||||
loginFormPin.setText(pin)
|
||||
}
|
||||
|
||||
override fun setErrorNameRequired() {
|
||||
loginFormNameLayout.run {
|
||||
requestFocus()
|
||||
error = getString(R.string.login_field_required)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setErrorPassRequired(focus: Boolean) {
|
||||
loginFormPassLayout.run {
|
||||
if (focus) requestFocus()
|
||||
error = getString(R.string.login_field_required)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setErrorPassInvalid(focus: Boolean) {
|
||||
loginFormPassLayout.run {
|
||||
if (focus) requestFocus()
|
||||
error = getString(R.string.login_invalid_password)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setErrorPassIncorrect() {
|
||||
loginFormPassLayout.run {
|
||||
requestFocus()
|
||||
error = getString(R.string.login_incorrect_password)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setErrorPinRequired() {
|
||||
loginFormPinLayout.run {
|
||||
requestFocus()
|
||||
error = getString(R.string.login_field_required)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setErrorSymbolRequired() {
|
||||
loginFormSymbolLayout.run {
|
||||
requestFocus()
|
||||
error = getString(R.string.login_field_required)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setErrorTokenRequired() {
|
||||
loginFormTokenLayout.run {
|
||||
requestFocus()
|
||||
error = getString(R.string.login_field_required)
|
||||
}
|
||||
}
|
||||
|
||||
override fun clearNameError() {
|
||||
loginFormNameLayout.error = null
|
||||
}
|
||||
|
||||
override fun clearPassError() {
|
||||
loginFormPassLayout.error = null
|
||||
}
|
||||
|
||||
override fun clearPinKeyError() {
|
||||
loginFormPinLayout.error = null
|
||||
}
|
||||
|
||||
override fun clearSymbolError() {
|
||||
loginFormSymbolLayout.error = null
|
||||
}
|
||||
|
||||
override fun clearTokenError() {
|
||||
loginFormTokenLayout.error = null
|
||||
}
|
||||
|
||||
override fun showOnlyHybridModeInputs() {
|
||||
loginFormNameLayout.visibility = View.VISIBLE
|
||||
loginFormPassLayout.visibility = View.VISIBLE
|
||||
loginFormHostLayout.visibility = View.VISIBLE
|
||||
loginFormPinLayout.visibility = View.GONE
|
||||
loginFormSymbolLayout.visibility = View.VISIBLE
|
||||
loginFormTokenLayout.visibility = View.GONE
|
||||
}
|
||||
|
||||
override fun showOnlyScrapperModeInputs() {
|
||||
loginFormNameLayout.visibility = View.VISIBLE
|
||||
loginFormPassLayout.visibility = View.VISIBLE
|
||||
loginFormHostLayout.visibility = View.VISIBLE
|
||||
loginFormPinLayout.visibility = View.GONE
|
||||
loginFormSymbolLayout.visibility = View.VISIBLE
|
||||
loginFormTokenLayout.visibility = View.GONE
|
||||
}
|
||||
|
||||
override fun showOnlyMobileApiModeInputs() {
|
||||
loginFormNameLayout.visibility = View.GONE
|
||||
loginFormPassLayout.visibility = View.GONE
|
||||
loginFormHostLayout.visibility = View.GONE
|
||||
loginFormPinLayout.visibility = View.VISIBLE
|
||||
loginFormSymbolLayout.visibility = View.VISIBLE
|
||||
loginFormTokenLayout.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
override fun showSoftKeyboard() {
|
||||
activity?.showSoftInput()
|
||||
}
|
||||
|
||||
override fun hideSoftKeyboard() {
|
||||
activity?.hideSoftInput()
|
||||
}
|
||||
|
||||
override fun showProgress(show: Boolean) {
|
||||
loginFormProgress.visibility = if (show) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
override fun showContent(show: Boolean) {
|
||||
loginFormContainer.visibility = if (show) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
override fun notifyParentAccountLogged(students: List<Student>) {
|
||||
(activity as? LoginActivity)?.onFormFragmentAccountLogged(students, Triple(
|
||||
loginFormName.text.toString(),
|
||||
loginFormPass.text.toString(),
|
||||
resources.getStringArray(R.array.hosts_values)[1]
|
||||
))
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
presenter.onDetachView()
|
||||
}
|
||||
}
|
@ -0,0 +1,185 @@
|
||||
package io.github.wulkanowy.ui.modules.login.advanced
|
||||
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.student.StudentRepository
|
||||
import io.github.wulkanowy.sdk.Sdk
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
||||
import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
|
||||
import io.github.wulkanowy.utils.SchedulersProvider
|
||||
import io.github.wulkanowy.utils.ifNullOrBlank
|
||||
import io.reactivex.Single
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class LoginAdvancedPresenter @Inject constructor(
|
||||
schedulers: SchedulersProvider,
|
||||
studentRepository: StudentRepository,
|
||||
private val loginErrorHandler: LoginErrorHandler,
|
||||
private val analytics: FirebaseAnalyticsHelper
|
||||
) : BasePresenter<LoginAdvancedView>(loginErrorHandler, studentRepository, schedulers) {
|
||||
|
||||
override fun onAttachView(view: LoginAdvancedView) {
|
||||
super.onAttachView(view)
|
||||
view.run {
|
||||
initView()
|
||||
showOnlyScrapperModeInputs()
|
||||
loginErrorHandler.onBadCredentials = {
|
||||
setErrorPassIncorrect()
|
||||
showSoftKeyboard()
|
||||
Timber.i("Entered wrong username or password")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onHostSelected() {
|
||||
view?.apply {
|
||||
clearPassError()
|
||||
clearNameError()
|
||||
if (formHostValue?.contains("fakelog") == true) {
|
||||
setDefaultCredentials("jan@fakelog.cf", "jan123", "powiatwulkanowy", "FK100000", "999999")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onLoginModeSelected(type: Sdk.Mode) {
|
||||
view?.run {
|
||||
when (type) {
|
||||
Sdk.Mode.API -> showOnlyMobileApiModeInputs()
|
||||
Sdk.Mode.SCRAPPER -> showOnlyScrapperModeInputs()
|
||||
Sdk.Mode.HYBRID -> showOnlyHybridModeInputs()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onPassTextChanged() {
|
||||
view?.clearPassError()
|
||||
}
|
||||
|
||||
fun onNameTextChanged() {
|
||||
view?.clearNameError()
|
||||
}
|
||||
|
||||
fun onPinTextChanged() {
|
||||
view?.clearPinKeyError()
|
||||
}
|
||||
|
||||
fun onSymbolTextChanged() {
|
||||
view?.clearSymbolError()
|
||||
}
|
||||
|
||||
fun onTokenTextChanged() {
|
||||
view?.clearTokenError()
|
||||
}
|
||||
|
||||
fun onSignInClick() {
|
||||
if (!validateCredentials()) return
|
||||
|
||||
disposable.add(getStudentsAppropriatesToLoginType()
|
||||
.subscribeOn(schedulers.backgroundThread)
|
||||
.observeOn(schedulers.mainThread)
|
||||
.doOnSubscribe {
|
||||
view?.apply {
|
||||
hideSoftKeyboard()
|
||||
showProgress(true)
|
||||
showContent(false)
|
||||
}
|
||||
Timber.i("Login started")
|
||||
}
|
||||
.doFinally {
|
||||
view?.apply {
|
||||
showProgress(false)
|
||||
showContent(true)
|
||||
}
|
||||
}
|
||||
.subscribe({
|
||||
Timber.i("Login result: Success")
|
||||
analytics.logEvent("registration_form", "success" to true, "students" to it.size, "error" to "No error")
|
||||
view?.notifyParentAccountLogged(it)
|
||||
}, {
|
||||
Timber.i("Login result: An exception occurred")
|
||||
analytics.logEvent("registration_form", "success" to false, "students" to -1, "error" to it.message.ifNullOrBlank { "No message" })
|
||||
loginErrorHandler.dispatch(it)
|
||||
}))
|
||||
}
|
||||
|
||||
private fun getStudentsAppropriatesToLoginType(): Single<List<Student>> {
|
||||
val email = view?.formNameValue.orEmpty()
|
||||
val password = view?.formPassValue.orEmpty()
|
||||
val endpoint = view?.formHostValue.orEmpty()
|
||||
|
||||
val pin = view?.formPinValue.orEmpty()
|
||||
val symbol = view?.formSymbolValue.orEmpty()
|
||||
val token = view?.formTokenValue.orEmpty()
|
||||
|
||||
return when (Sdk.Mode.valueOf(view?.formLoginType ?: "")) {
|
||||
Sdk.Mode.API -> studentRepository.getStudentsApi(pin, symbol, token)
|
||||
Sdk.Mode.SCRAPPER -> studentRepository.getStudentsScrapper(email, password, endpoint, symbol)
|
||||
Sdk.Mode.HYBRID -> studentRepository.getStudentsHybrid(email, password, endpoint, symbol)
|
||||
}
|
||||
}
|
||||
|
||||
private fun validateCredentials(): Boolean {
|
||||
val login = view?.formNameValue.orEmpty()
|
||||
val password = view?.formPassValue.orEmpty()
|
||||
|
||||
val pin = view?.formPinValue.orEmpty()
|
||||
val symbol = view?.formSymbolValue.orEmpty()
|
||||
val token = view?.formTokenValue.orEmpty()
|
||||
|
||||
var isCorrect = true
|
||||
|
||||
when (Sdk.Mode.valueOf(view?.formLoginType ?: "")) {
|
||||
Sdk.Mode.API -> {
|
||||
if (pin.isEmpty()) {
|
||||
view?.setErrorPinRequired()
|
||||
isCorrect = false
|
||||
}
|
||||
|
||||
if (symbol.isEmpty()) {
|
||||
view?.setErrorSymbolRequired()
|
||||
isCorrect = false
|
||||
}
|
||||
|
||||
if (token.isEmpty()) {
|
||||
view?.setErrorTokenRequired()
|
||||
isCorrect = false
|
||||
}
|
||||
}
|
||||
Sdk.Mode.SCRAPPER -> {
|
||||
if (login.isEmpty()) {
|
||||
view?.setErrorNameRequired()
|
||||
isCorrect = false
|
||||
}
|
||||
|
||||
if (password.isEmpty()) {
|
||||
view?.setErrorPassRequired(focus = isCorrect)
|
||||
isCorrect = false
|
||||
}
|
||||
|
||||
if (password.length < 6 && password.isNotEmpty()) {
|
||||
view?.setErrorPassInvalid(focus = isCorrect)
|
||||
isCorrect = false
|
||||
}
|
||||
}
|
||||
Sdk.Mode.HYBRID -> {
|
||||
if (login.isEmpty()) {
|
||||
view?.setErrorNameRequired()
|
||||
isCorrect = false
|
||||
}
|
||||
|
||||
if (password.isEmpty()) {
|
||||
view?.setErrorPassRequired(focus = isCorrect)
|
||||
isCorrect = false
|
||||
}
|
||||
|
||||
if (password.length < 6 && password.isNotEmpty()) {
|
||||
view?.setErrorPassInvalid(focus = isCorrect)
|
||||
isCorrect = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isCorrect
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package io.github.wulkanowy.ui.modules.login.advanced
|
||||
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.ui.base.BaseView
|
||||
|
||||
interface LoginAdvancedView : BaseView {
|
||||
|
||||
val formNameValue: String
|
||||
|
||||
val formPassValue: String
|
||||
|
||||
val formHostValue: String?
|
||||
|
||||
val formLoginType: String
|
||||
|
||||
val formPinValue: String
|
||||
|
||||
val formSymbolValue: String
|
||||
|
||||
val formTokenValue: String
|
||||
|
||||
fun initView()
|
||||
|
||||
fun setDefaultCredentials(name: String, pass: String, symbol: String, token: String, pin: String)
|
||||
|
||||
fun setErrorNameRequired()
|
||||
|
||||
fun setErrorPassRequired(focus: Boolean)
|
||||
|
||||
fun setErrorPassInvalid(focus: Boolean)
|
||||
|
||||
fun setErrorPassIncorrect()
|
||||
|
||||
fun clearNameError()
|
||||
|
||||
fun clearPassError()
|
||||
|
||||
fun clearPinKeyError()
|
||||
|
||||
fun clearSymbolError()
|
||||
|
||||
fun clearTokenError()
|
||||
|
||||
fun showSoftKeyboard()
|
||||
|
||||
fun hideSoftKeyboard()
|
||||
|
||||
fun showProgress(show: Boolean)
|
||||
|
||||
fun showContent(show: Boolean)
|
||||
|
||||
fun notifyParentAccountLogged(students: List<Student>)
|
||||
|
||||
fun setErrorPinRequired()
|
||||
|
||||
fun setErrorSymbolRequired()
|
||||
|
||||
fun setErrorTokenRequired()
|
||||
|
||||
fun showOnlyHybridModeInputs()
|
||||
|
||||
fun showOnlyScrapperModeInputs()
|
||||
|
||||
fun showOnlyMobileApiModeInputs()
|
||||
}
|
@ -61,6 +61,7 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
|
||||
loginFormPass.doOnTextChanged { _, _, _, _ -> presenter.onPassTextChanged() }
|
||||
loginFormHost.setOnItemClickListener { _, _, _, _ -> presenter.onHostSelected() }
|
||||
loginFormSignIn.setOnClickListener { presenter.onSignInClick() }
|
||||
loginFormAdvancedButton.setOnClickListener { presenter.onAdvancedLoginClick() }
|
||||
loginFormPrivacyLink.setOnClickListener { presenter.onPrivacyLinkClick() }
|
||||
loginFormFaq.setOnClickListener { presenter.onFaqClick() }
|
||||
loginFormContactEmail.setOnClickListener { presenter.onEmailClick() }
|
||||
@ -134,14 +135,7 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun showVersion() {
|
||||
with(loginFormVersion) {
|
||||
visibility = VISIBLE
|
||||
text = "${getString(R.string.app_name)} ${appInfo.versionName}"
|
||||
}
|
||||
}
|
||||
|
||||
override fun showPrivacyPolicy() {
|
||||
loginFormPrivacyLink.visibility = VISIBLE
|
||||
loginFormVersion.text = "v${appInfo.versionName}"
|
||||
}
|
||||
|
||||
override fun notifyParentAccountLogged(students: List<Student>, loginData: Triple<String, String, String>) {
|
||||
@ -156,6 +150,10 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
|
||||
loginFormContact.visibility = if (show) VISIBLE else GONE
|
||||
}
|
||||
|
||||
override fun openAdvancedLogin() {
|
||||
(activity as? LoginActivity)?.onAdvancedLoginClick()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
presenter.onDetachView()
|
||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.ui.modules.login.form
|
||||
import io.github.wulkanowy.data.repositories.student.StudentRepository
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
||||
import io.github.wulkanowy.utils.AppInfo
|
||||
import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
|
||||
import io.github.wulkanowy.utils.SchedulersProvider
|
||||
import io.github.wulkanowy.utils.ifNullOrBlank
|
||||
@ -14,8 +13,7 @@ class LoginFormPresenter @Inject constructor(
|
||||
schedulers: SchedulersProvider,
|
||||
studentRepository: StudentRepository,
|
||||
private val loginErrorHandler: LoginErrorHandler,
|
||||
private val analytics: FirebaseAnalyticsHelper,
|
||||
private val appInfo: AppInfo
|
||||
private val analytics: FirebaseAnalyticsHelper
|
||||
) : BasePresenter<LoginFormView>(loginErrorHandler, studentRepository, schedulers) {
|
||||
|
||||
override fun onAttachView(view: LoginFormView) {
|
||||
@ -23,7 +21,7 @@ class LoginFormPresenter @Inject constructor(
|
||||
view.run {
|
||||
initView()
|
||||
showContact(false)
|
||||
if (appInfo.isDebug) showVersion() else showPrivacyPolicy()
|
||||
showVersion()
|
||||
|
||||
loginErrorHandler.onBadCredentials = {
|
||||
setErrorPassIncorrect()
|
||||
@ -37,6 +35,10 @@ class LoginFormPresenter @Inject constructor(
|
||||
view?.openPrivacyPolicyPage()
|
||||
}
|
||||
|
||||
fun onAdvancedLoginClick() {
|
||||
view?.openAdvancedLogin()
|
||||
}
|
||||
|
||||
fun onHostSelected() {
|
||||
view?.apply {
|
||||
clearPassError()
|
||||
@ -56,13 +58,13 @@ class LoginFormPresenter @Inject constructor(
|
||||
}
|
||||
|
||||
fun onSignInClick() {
|
||||
val email = view?.formNameValue.orEmpty()
|
||||
val password = view?.formPassValue.orEmpty()
|
||||
val endpoint = view?.formHostValue.orEmpty()
|
||||
val email = view?.formNameValue.orEmpty().trim()
|
||||
val password = view?.formPassValue.orEmpty().trim()
|
||||
val endpoint = view?.formHostValue.orEmpty().trim()
|
||||
|
||||
if (!validateCredentials(email, password)) return
|
||||
|
||||
disposable.add(studentRepository.getStudents(email, password, endpoint)
|
||||
disposable.add(studentRepository.getStudentsScrapper(email, password, endpoint)
|
||||
.subscribeOn(schedulers.backgroundThread)
|
||||
.observeOn(schedulers.mainThread)
|
||||
.doOnSubscribe {
|
||||
@ -81,11 +83,11 @@ class LoginFormPresenter @Inject constructor(
|
||||
}
|
||||
.subscribe({
|
||||
Timber.i("Login result: Success")
|
||||
analytics.logEvent("registration_form", "success" to true, "students" to it.size, "endpoint" to endpoint, "error" to "No error")
|
||||
analytics.logEvent("registration_form", "success" to true, "students" to it.size, "scrapperBaseUrl" to endpoint, "error" to "No error")
|
||||
view?.notifyParentAccountLogged(it, Triple(email, password, endpoint))
|
||||
}, {
|
||||
Timber.i("Login result: An exception occurred")
|
||||
analytics.logEvent("registration_form", "success" to false, "students" to -1, "endpoint" to endpoint, "error" to it.message.ifNullOrBlank { "No message" })
|
||||
analytics.logEvent("registration_form", "success" to false, "students" to -1, "scrapperBaseUrl" to endpoint, "error" to it.message.ifNullOrBlank { "No message" })
|
||||
loginErrorHandler.dispatch(it)
|
||||
view?.showContact(true)
|
||||
}))
|
||||
|
@ -37,8 +37,6 @@ interface LoginFormView : BaseView {
|
||||
|
||||
fun showVersion()
|
||||
|
||||
fun showPrivacyPolicy()
|
||||
|
||||
fun notifyParentAccountLogged(students: List<Student>, loginData: Triple<String, String, String>)
|
||||
|
||||
fun openPrivacyPolicyPage()
|
||||
@ -48,4 +46,6 @@ interface LoginFormView : BaseView {
|
||||
fun openFaqPage()
|
||||
|
||||
fun openEmail()
|
||||
|
||||
fun openAdvancedLogin()
|
||||
}
|
||||
|
@ -79,11 +79,11 @@ class LoginStudentSelectPresenter @Inject constructor(
|
||||
Timber.i("Registration started")
|
||||
}
|
||||
.subscribe({
|
||||
students.forEach { analytics.logEvent("registration_student_select", "success" to true, "endpoint" to it.endpoint, "symbol" to it.symbol, "error" to "No error") }
|
||||
students.forEach { analytics.logEvent("registration_student_select", "success" to true, "scrapperBaseUrl" to it.scrapperBaseUrl, "symbol" to it.symbol, "error" to "No error") }
|
||||
Timber.i("Registration result: Success")
|
||||
view?.openMainView()
|
||||
}, { error ->
|
||||
students.forEach { analytics.logEvent("registration_student_select", "success" to false, "endpoint" to it.endpoint, "symbol" to it.symbol, "error" to error.message.ifNullOrBlank { "No message" }) }
|
||||
students.forEach { analytics.logEvent("registration_student_select", "success" to false, "scrapperBaseUrl" to it.scrapperBaseUrl, "symbol" to it.symbol, "error" to error.message.ifNullOrBlank { "No message" }) }
|
||||
Timber.i("Registration result: An exception occurred ")
|
||||
loginErrorHandler.dispatch(error)
|
||||
view?.apply {
|
||||
|
@ -44,7 +44,7 @@ class LoginSymbolPresenter @Inject constructor(
|
||||
|
||||
disposable.add(
|
||||
Single.fromCallable { if (loginData == null) throw IllegalArgumentException("Login data is null") else loginData }
|
||||
.flatMap { studentRepository.getStudents(it.first, it.second, it.third, symbol) }
|
||||
.flatMap { studentRepository.getStudentsScrapper(it.first, it.second, it.third, symbol) }
|
||||
.subscribeOn(schedulers.backgroundThread)
|
||||
.observeOn(schedulers.mainThread)
|
||||
.doOnSubscribe {
|
||||
@ -62,7 +62,7 @@ class LoginSymbolPresenter @Inject constructor(
|
||||
}
|
||||
}
|
||||
.subscribe({
|
||||
analytics.logEvent("registration_symbol", "success" to true, "students" to it.size, "endpoint" to loginData?.third, "symbol" to symbol, "error" to "No error")
|
||||
analytics.logEvent("registration_symbol", "success" to true, "students" to it.size, "scrapperBaseUrl" to loginData?.third, "symbol" to symbol, "error" to "No error")
|
||||
view?.apply {
|
||||
if (it.isEmpty()) {
|
||||
Timber.i("Login with symbol result: Empty student list")
|
||||
@ -75,7 +75,7 @@ class LoginSymbolPresenter @Inject constructor(
|
||||
}
|
||||
}, {
|
||||
Timber.i("Login with symbol result: An exception occurred")
|
||||
analytics.logEvent("registration_symbol", "success" to false, "students" to -1, "endpoint" to loginData?.third, "symbol" to symbol, "error" to it.message.ifNullOrBlank { "No message" })
|
||||
analytics.logEvent("registration_symbol", "success" to false, "students" to -1, "scrapperBaseUrl" to loginData?.third, "symbol" to symbol, "error" to it.message.ifNullOrBlank { "No message" })
|
||||
loginErrorHandler.dispatch(it)
|
||||
view?.showContact(true)
|
||||
}))
|
||||
|
@ -9,6 +9,7 @@ import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Message
|
||||
import io.github.wulkanowy.data.repositories.message.MessageFolder
|
||||
import io.github.wulkanowy.utils.toFormattedString
|
||||
import kotlinx.android.extensions.LayoutContainer
|
||||
import kotlinx.android.synthetic.main.item_message.*
|
||||
@ -27,7 +28,7 @@ class MessageItem(val message: Message, private val noSubjectString: String) :
|
||||
val style = if (message.unread) BOLD else NORMAL
|
||||
|
||||
messageItemAuthor.run {
|
||||
text = if (message.recipient.isNotBlank()) message.recipient else message.sender
|
||||
text = if (message.folderId == MessageFolder.SENT.id) message.recipient else message.sender
|
||||
setTypeface(null, style)
|
||||
}
|
||||
messageItemSubject.run {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.wulkanowy.ui.modules.message.preview
|
||||
|
||||
import io.github.wulkanowy.data.db.entities.Message
|
||||
import io.github.wulkanowy.data.repositories.message.MessageFolder
|
||||
import io.github.wulkanowy.data.repositories.message.MessageRepository
|
||||
import io.github.wulkanowy.data.repositories.student.StudentRepository
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
@ -63,14 +64,14 @@ class MessagePreviewPresenter @Inject constructor(
|
||||
message.let {
|
||||
setSubject(if (it.subject.isNotBlank()) it.subject else noSubjectString)
|
||||
setDate(it.date.toFormattedString("yyyy-MM-dd HH:mm:ss"))
|
||||
setContent(it.content.orEmpty())
|
||||
setContent(it.content)
|
||||
initOptions()
|
||||
|
||||
if (it.recipient.isNotBlank()) setRecipient(it.recipient)
|
||||
if (it.folderId == MessageFolder.SENT.id) setRecipient(it.recipient)
|
||||
else setSender(it.sender)
|
||||
}
|
||||
}
|
||||
analytics.logEvent("load_message_preview", "length" to message.content?.length)
|
||||
analytics.logEvent("load_message_preview", "length" to message.content.length)
|
||||
}) {
|
||||
Timber.i("Loading message $id preview result: An exception occurred ")
|
||||
retryCallback = { onMessageLoadRetry() }
|
||||
|
@ -4,6 +4,7 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||
import io.github.wulkanowy.data.db.entities.Message
|
||||
import io.github.wulkanowy.data.repositories.message.MessageFolder
|
||||
import io.github.wulkanowy.data.repositories.message.MessageRepository
|
||||
import io.github.wulkanowy.data.repositories.semester.SemesterRepository
|
||||
import io.github.wulkanowy.data.repositories.student.StudentRepository
|
||||
import io.github.wulkanowy.ui.base.BasePresenter
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
@ -18,6 +19,7 @@ class MessageTabPresenter @Inject constructor(
|
||||
errorHandler: ErrorHandler,
|
||||
studentRepository: StudentRepository,
|
||||
private val messageRepository: MessageRepository,
|
||||
private val semesterRepository: SemesterRepository,
|
||||
private val analytics: FirebaseAnalyticsHelper
|
||||
) : BasePresenter<MessageTabView>(errorHandler, studentRepository, schedulers) {
|
||||
|
||||
@ -76,8 +78,11 @@ class MessageTabPresenter @Inject constructor(
|
||||
disposable.apply {
|
||||
clear()
|
||||
add(studentRepository.getCurrentStudent()
|
||||
.flatMap { messageRepository.getMessages(it, folder, forceRefresh) }
|
||||
.map { items -> items.map { MessageItem(it, view?.noSubjectString.orEmpty()) } }
|
||||
.flatMap { student ->
|
||||
semesterRepository.getCurrentSemester(student)
|
||||
.flatMap { messageRepository.getMessages(student, it, folder, forceRefresh) }
|
||||
.map { items -> items.map { MessageItem(it, view?.noSubjectString.orEmpty()) } }
|
||||
}
|
||||
.subscribeOn(schedulers.backgroundThread)
|
||||
.observeOn(schedulers.mainThread)
|
||||
.doFinally {
|
||||
|
@ -20,7 +20,6 @@ import io.github.wulkanowy.ui.modules.mobiledevice.MobileDeviceFragment
|
||||
import io.github.wulkanowy.ui.modules.note.NoteFragment
|
||||
import io.github.wulkanowy.ui.modules.schoolandteachers.SchoolAndTeachersFragment
|
||||
import io.github.wulkanowy.ui.modules.settings.SettingsFragment
|
||||
import io.github.wulkanowy.ui.modules.schoolandteachers.teacher.TeacherFragment
|
||||
import io.github.wulkanowy.utils.getCompatDrawable
|
||||
import io.github.wulkanowy.utils.setOnItemClickListener
|
||||
import kotlinx.android.synthetic.main.fragment_more.*
|
||||
|
@ -2,7 +2,7 @@ package io.github.wulkanowy.ui.modules.timetable.completed
|
||||
|
||||
import android.content.res.Resources
|
||||
import com.readystatesoftware.chuck.api.ChuckCollector
|
||||
import io.github.wulkanowy.api.interceptor.FeatureDisabledException
|
||||
import io.github.wulkanowy.sdk.exception.FeatureDisabledException
|
||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -28,7 +28,6 @@ import io.github.wulkanowy.utils.SchedulersProvider
|
||||
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
||||
import io.github.wulkanowy.utils.nextSchoolDay
|
||||
import io.github.wulkanowy.utils.previousSchoolDay
|
||||
import io.github.wulkanowy.utils.shortcutWeekDayName
|
||||
import io.github.wulkanowy.utils.toFormattedString
|
||||
import io.reactivex.Maybe
|
||||
import org.threeten.bp.LocalDate
|
||||
|
@ -32,7 +32,7 @@ fun Grade.getBackgroundColor(theme: String): Int {
|
||||
"B16CF1" -> R.color.grade_purple
|
||||
else -> R.color.grade_material_default
|
||||
}
|
||||
"material" -> when (value) {
|
||||
"material" -> when (value.toInt()) {
|
||||
6 -> R.color.grade_material_six
|
||||
5 -> R.color.grade_material_five
|
||||
4 -> R.color.grade_material_four
|
||||
@ -41,7 +41,7 @@ fun Grade.getBackgroundColor(theme: String): Int {
|
||||
1 -> R.color.grade_material_one
|
||||
else -> R.color.grade_material_default
|
||||
}
|
||||
else -> when (value) {
|
||||
else -> when (value.toInt()) {
|
||||
6 -> R.color.grade_vulcan_six
|
||||
5 -> R.color.grade_vulcan_five
|
||||
4 -> R.color.grade_vulcan_four
|
||||
|
@ -14,7 +14,6 @@ import android.security.keystore.KeyProperties.DIGEST_SHA512
|
||||
import android.security.keystore.KeyProperties.ENCRYPTION_PADDING_RSA_OAEP
|
||||
import android.security.keystore.KeyProperties.PURPOSE_DECRYPT
|
||||
import android.security.keystore.KeyProperties.PURPOSE_ENCRYPT
|
||||
import android.util.Base64
|
||||
import android.util.Base64.DEFAULT
|
||||
import android.util.Base64.decode
|
||||
import android.util.Base64.encode
|
||||
@ -60,7 +59,7 @@ fun encrypt(plainText: String, context: Context): String {
|
||||
if (plainText.isEmpty()) throw ScramblerException("Text to be encrypted is empty")
|
||||
|
||||
if (SDK_INT < JELLY_BEAN_MR2) {
|
||||
return String(Base64.encode(plainText.toByteArray(KEY_CHARSET), DEFAULT), KEY_CHARSET)
|
||||
return String(encode(plainText.toByteArray(KEY_CHARSET), DEFAULT), KEY_CHARSET)
|
||||
}
|
||||
|
||||
return try {
|
||||
|
Reference in New Issue
Block a user