forked from github/szkolny
Compare commits
32 Commits
code-refor
...
v3.9.5-dev
Author | SHA1 | Date | |
---|---|---|---|
16102de619 | |||
472e768369 | |||
131a769c26 | |||
4a0a6c54e4 | |||
c83abe57d5 | |||
c6e2519dcc | |||
74db524db6 | |||
810976d976 | |||
eb0540b5cb | |||
124437fd73 | |||
69b512e3d1 | |||
29d74e14bd | |||
f42ec8435a | |||
1052b824db | |||
0742a6a74c | |||
d4e9e1730f | |||
4eeaa54a47 | |||
5fa7409317 | |||
0bcd190714 | |||
563f08b0ab | |||
1b75424604 | |||
01ac26e67b | |||
434ddd1342 | |||
3925496595 | |||
5711c02170 | |||
ca1c691bf0 | |||
39c8a743bb | |||
14cd548dff | |||
b72324805f | |||
a049effa61 | |||
23d55ec571 | |||
385fe21d16 |
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
@ -6,8 +6,9 @@
|
||||
</configurations>
|
||||
</component>
|
||||
<component name="EntryPointsManager">
|
||||
<list size="1">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.greenrobot.eventbus.Subscribe" />
|
||||
<list size="2">
|
||||
<item index="0" class="java.lang.String" itemvalue="androidx.databinding.BindingAdapter" />
|
||||
<item index="1" class="java.lang.String" itemvalue="org.greenrobot.eventbus.Subscribe" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="NullableNotNullManager">
|
||||
|
@ -1,7 +1,6 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
apply plugin: 'com.google.gms.google-services'
|
||||
apply plugin: 'io.fabric'
|
||||
|
||||
@ -92,7 +91,7 @@ tasks.whenTaskAdded { task ->
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
|
||||
kapt "androidx.room:room-compiler:${versions.room}"
|
||||
annotationProcessor "androidx.room:room-compiler:${versions.room}"
|
||||
debugImplementation "com.amitshekhar.android:debug-db:1.0.5"
|
||||
|
||||
implementation "android.arch.navigation:navigation-fragment-ktx:${versions.navigationFragment}"
|
||||
@ -132,7 +131,7 @@ dependencies {
|
||||
implementation("com.github.ozodrukh:CircularReveal:2.0.1@aar") {transitive = true}
|
||||
implementation "com.heinrichreimersoftware:material-intro:1.5.8" // do not update
|
||||
implementation "com.jaredrummler:colorpicker:1.0.2"
|
||||
implementation "com.squareup.okhttp3:okhttp:3.12.0"
|
||||
implementation "com.squareup.okhttp3:okhttp:3.12.2"
|
||||
implementation "com.theartofdev.edmodo:android-image-cropper:2.8.0" // do not update
|
||||
implementation "com.wdullaer:materialdatetimepicker:4.1.2"
|
||||
implementation "com.yuyh.json:jsonviewer:1.0.6"
|
||||
@ -160,16 +159,17 @@ dependencies {
|
||||
//implementation 'com.github.wulkanowy:uonet-request-signer:master-SNAPSHOT'
|
||||
//implementation 'com.github.kuba2k2.uonet-request-signer:android:master-63f094b14a-1'
|
||||
|
||||
implementation "org.redundent:kotlin-xml-builder:1.5.3"
|
||||
//implementation "org.redundent:kotlin-xml-builder:1.5.3"
|
||||
|
||||
implementation "io.github.wulkanowy:signer-android:0.1.1"
|
||||
|
||||
implementation "androidx.work:work-runtime-ktx:${versions.work}"
|
||||
|
||||
api "com.google.dagger:dagger:${versions.dagger}"
|
||||
api "com.google.dagger:dagger-android-support:${versions.dagger}"
|
||||
kapt "com.google.dagger:dagger-compiler:${versions.dagger}"
|
||||
kapt "com.google.dagger:dagger-android-processor:${versions.dagger}"
|
||||
implementation 'com.hypertrack:hyperlog:0.0.10'
|
||||
|
||||
implementation 'com.github.kuba2k2:RecyclerTabLayout:700f980584'
|
||||
|
||||
implementation 'com.linkedin.android.tachyon:tachyon:1.0.2'
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
@ -39,4 +39,13 @@
|
||||
|
||||
-keep class okhttp3.** { *; }
|
||||
|
||||
-keep class com.google.android.material.tabs.** {*;}
|
||||
-keep class com.google.android.material.tabs.** {*;}
|
||||
|
||||
# ServiceLoader support
|
||||
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
|
||||
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
|
||||
|
||||
# Most of volatile fields are updated with AFU and should not be mangled
|
||||
-keepclassmembernames class kotlinx.** {
|
||||
volatile <fields>;
|
||||
}
|
9
app/sampledata/check/ic_check.xml
Normal file
9
app/sampledata/check/ic_check.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF4caf50"
|
||||
android:pathData="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/>
|
||||
</vector>
|
@ -15,10 +15,14 @@
|
||||
android:theme="@style/SplashTheme"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:ignore="UnusedAttribute">
|
||||
<activity
|
||||
android:name=".ui.modules.login.LoginLibrusCaptchaActivity"
|
||||
android:theme="@android:style/Theme.Dialog"
|
||||
android:excludeFromRecents="true"/>
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/SplashTheme">
|
||||
<intent-filter>
|
||||
@ -29,7 +33,7 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="pl.szczodrzynski.edziennik.ui.modules.messages.MessagesComposeActivity"
|
||||
android:name=".ui.modules.messages.MessagesComposeActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/messages_compose_title"
|
||||
android:theme="@style/AppTheme.Black" />
|
||||
@ -39,7 +43,7 @@
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" />
|
||||
<activity
|
||||
android:name="pl.szczodrzynski.edziennik.ui.modules.login.LoginActivity"
|
||||
android:name=".ui.modules.login.LoginActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/AppTheme.Light" />
|
||||
@ -101,22 +105,18 @@
|
||||
android:excludeFromRecents="true"
|
||||
android:noHistory="true"
|
||||
android:theme="@style/AppTheme.NoDisplay" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.modules.settings.SettingsLicenseActivity"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:theme="@style/AppTheme" />
|
||||
|
||||
<activity
|
||||
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:theme="@style/Base.Theme.AppCompat" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.modules.webpush.WebPushConfigActivity"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:theme="@style/AppTheme.Dark" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.modules.home.CounterActivity"
|
||||
android:theme="@style/AppTheme.Black" />
|
||||
@ -169,7 +169,6 @@
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget_notifications_info" />
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".widgets.luckynumber.WidgetLuckyNumber"
|
||||
android:label="@string/widget_lucky_number_title">
|
||||
@ -188,7 +187,6 @@
|
||||
<action android:name="android.intent.action.USER_PRESENT" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".receivers.BootReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
@ -196,14 +194,7 @@
|
||||
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<service
|
||||
android:name=".sync.MyFirebaseMessagingService"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
|
||||
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<receiver
|
||||
android:name=".sync.FirebaseBroadcastReceiver"
|
||||
android:exported="true"
|
||||
@ -212,6 +203,23 @@
|
||||
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".receivers.SzkolnyReceiver"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="pl.szczodrzynski.edziennik.SZKOLNY_MAIN" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service
|
||||
android:name=".sync.MyFirebaseMessagingService"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
|
||||
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<service
|
||||
android:name=".widgets.timetable.WidgetTimetableService"
|
||||
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
||||
@ -222,14 +230,6 @@
|
||||
|
||||
<service android:name=".Notifier$GetDataRetryService" />
|
||||
|
||||
<receiver
|
||||
android:name=".receivers.SzkolnyReceiver"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="pl.szczodrzynski.edziennik.SZKOLNY_MAIN" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service android:name=".api.v2.ApiService" />
|
||||
</application>
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
@ -244,4 +244,4 @@
|
||||
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
@ -31,57 +31,11 @@
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h3>Wersja 3.1.1, 2019-10-09</h3>
|
||||
<h3>Wersja 4.0, 2019-jeszcze-nie-wiem-kiedy</h3>
|
||||
<ul>
|
||||
<li>Librus: poprawiona synchronizacja kategorii i kolorów ocen.</li>
|
||||
<li>Zmieniony kolor dolnego paska w ciemnym motywie.</li>
|
||||
<li>Zaktualizowany licznik czasu lekcji.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Wersja 3.1, 2019-09-29</h3>
|
||||
<ul>
|
||||
<li>Poprawiony interfejs zadań domowych.</li>
|
||||
<li>Librus: wyświetlanie komentarzy ocen.</li>
|
||||
<li>Librus: wyświetlanie nieobecności nauczycieli w Terminarzu.</li>
|
||||
<li>Librus: usprawniona synchronizacja ocen.</li>
|
||||
<li>Poprawki angielskiego tłumaczenia.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Wersja 3.0.3, 2019-09-26</h3>
|
||||
<ul>
|
||||
<li>Librus: poprawka kilku błędów synchronizacji.</li>
|
||||
<li>Vulcan: prawidłowe oznaczanie wiadomości jako przeczytana.</li>
|
||||
<li>Vulcan: poprawiona synchronizacja wiadomości i frekwencji.</li>
|
||||
<li>Vulcan: poprawka błędów logowania.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Wersja 3.0.2, 2019-09-24</h3>
|
||||
<ul>
|
||||
<li>Librus: pobieranie Bieżących ocen opisowych.</li>
|
||||
<li>Poprawki UI: kolor ikon paska statusu w jasnym motywie.</li>
|
||||
<li>Poprawka braku skanera QR do przekazywania powiadomień.</li>
|
||||
<li>Poprawka wyboru koloru i daty własnego wydarzenia, które crashowały aplikację.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Wersja 3.0.1, 2019-09-19</h3>
|
||||
<ul>
|
||||
<li>Librus: Poprawa błędu synchronizacji.</li>
|
||||
<li>Poprawki UI związane z paskiem nawigacji.</li>
|
||||
<li>Mobidziennik: Pobieranie ocen w niektórych przedmiotach.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Wersja 3.0, 2019-09-13</h3>
|
||||
<ul>
|
||||
<li><b>Nowy wygląd i sposób nawigacji</b> w całej aplikacji.</li>
|
||||
<li>Menu nawigacji można teraz otworzyć przyciskiem na <b>dolnym pasku</b>. Pociągnięcie w górę tego paska wyświetla <b>menu kontekstowe</b> dotyczące danego widoku.</li>
|
||||
<li>Założyliśmy serwer Discord! <a href="https://discord.gg/n9e8pWr">https://discord.gg/n9e8pWr</a></li>
|
||||
<br>
|
||||
<li>Librus: poprawka powielonych ogłoszeń szkolnych.</li>
|
||||
<li>Naprawiłem błąd nieskończonej synchronizacji w Vulcanie.</li>
|
||||
<li>Naprawiłem crash launchera przy dodaniu widgetu.</li>
|
||||
<li>Naprawiłem częste crashe związane z widokiem kalendarza.</li>
|
||||
<li>Nowe, ładniejsze (choć trochę) motywy kolorów.</li>
|
||||
<li>Dużo drobnych poprawek UI i działania aplikacji.</li>
|
||||
<li>UWAGA. To jest wersja in-development. Wiele funkcji może nie działać prawidłowo (lub wcale), co oznacza tylko że nie zostały jeszcze przeniesione
|
||||
z wersji 3.x. Proszę o cierpliwość oraz <b>nie udostępnianie</b> tej wersji <u>nikomu</u>.</li>
|
||||
<li>Bardzo dużo zmian</li>
|
||||
</ul>
|
||||
|
||||
<!--<i>
|
||||
|
@ -22,7 +22,6 @@ import android.util.Pair;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.multidex.MultiDex;
|
||||
import androidx.work.Configuration;
|
||||
|
||||
import com.chuckerteam.chucker.api.ChuckerCollector;
|
||||
@ -37,6 +36,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.hypertrack.hyperlog.HyperLog;
|
||||
import com.mikepenz.iconics.Iconics;
|
||||
import com.mikepenz.iconics.IconicsColor;
|
||||
import com.mikepenz.iconics.IconicsDrawable;
|
||||
@ -60,8 +60,6 @@ import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import cat.ereza.customactivityoncrash.config.CaocConfig;
|
||||
import dagger.android.AndroidInjector;
|
||||
import dagger.android.support.DaggerApplication;
|
||||
import im.wangchao.mhttp.MHttp;
|
||||
import im.wangchao.mhttp.internal.cookie.PersistentCookieJar;
|
||||
import im.wangchao.mhttp.internal.cookie.cache.SetCookieCache;
|
||||
@ -80,11 +78,11 @@ import pl.szczodrzynski.edziennik.data.db.modules.debuglog.DebugLog;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.ProfileFull;
|
||||
import pl.szczodrzynski.edziennik.di.DaggerAppComponent;
|
||||
import pl.szczodrzynski.edziennik.network.NetworkUtils;
|
||||
import pl.szczodrzynski.edziennik.network.TLSSocketFactory;
|
||||
import pl.szczodrzynski.edziennik.sync.SyncWorker;
|
||||
import pl.szczodrzynski.edziennik.ui.modules.base.CrashActivity;
|
||||
import pl.szczodrzynski.edziennik.utils.DebugLogFormat;
|
||||
import pl.szczodrzynski.edziennik.utils.PermissionChecker;
|
||||
import pl.szczodrzynski.edziennik.utils.Themes;
|
||||
import pl.szczodrzynski.edziennik.utils.Utils;
|
||||
@ -94,7 +92,7 @@ import static pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore.LOGIN_
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore.LOGIN_TYPE_MOBIDZIENNIK;
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore.LOGIN_TYPE_VULCAN;
|
||||
|
||||
public class App extends DaggerApplication implements Configuration.Provider {
|
||||
public class App extends androidx.multidex.MultiDexApplication implements Configuration.Provider {
|
||||
private static final String TAG = "App";
|
||||
public static int profileId = -1;
|
||||
private Context mContext;
|
||||
@ -185,17 +183,6 @@ public class App extends DaggerApplication implements Configuration.Provider {
|
||||
return Icon.createWithBitmap(bitmap);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(base);
|
||||
MultiDex.install(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AndroidInjector<? extends DaggerApplication> applicationInjector() {
|
||||
return DaggerAppComponent.factory().create(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
@ -309,6 +296,10 @@ public class App extends DaggerApplication implements Configuration.Provider {
|
||||
}
|
||||
|
||||
if (App.devMode || BuildConfig.DEBUG) {
|
||||
HyperLog.initialize(this);
|
||||
HyperLog.setLogLevel(Log.VERBOSE);
|
||||
HyperLog.setLogFormat(new DebugLogFormat(this));
|
||||
|
||||
ChuckerCollector chuckerCollector = new ChuckerCollector(this, true, RetentionManager.Period.ONE_HOUR);
|
||||
ChuckerInterceptor chuckerInterceptor = new ChuckerInterceptor(this, chuckerCollector);
|
||||
httpBuilder.addInterceptor(chuckerInterceptor);
|
||||
@ -558,7 +549,6 @@ public class App extends DaggerApplication implements Configuration.Provider {
|
||||
appConfig = new AppConfig(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveConfig()
|
||||
{
|
||||
try {
|
||||
@ -740,4 +730,5 @@ public class App extends DaggerApplication implements Configuration.Provider {
|
||||
devMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
21
app/src/main/java/pl/szczodrzynski/edziennik/Binding.java
Normal file
21
app/src/main/java/pl/szczodrzynski/edziennik/Binding.java
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-11-11.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik;
|
||||
|
||||
import android.graphics.Paint;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.databinding.BindingAdapter;
|
||||
|
||||
public class Binding {
|
||||
@BindingAdapter("strikeThrough")
|
||||
public static void strikeThrough(TextView textView, Boolean strikeThrough) {
|
||||
if (strikeThrough) {
|
||||
textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
} else {
|
||||
textView.setPaintFlags(textView.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,12 +4,23 @@ import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Typeface
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.*
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.StrikethroughSpan
|
||||
import android.text.style.StyleSpan
|
||||
import android.util.LongSparseArray
|
||||
import android.util.SparseArray
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.util.forEach
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
@ -326,4 +337,102 @@ fun String.crc32(): Long {
|
||||
return crc.value
|
||||
}
|
||||
|
||||
fun Long.formatDate(format: String = "yyyy-MM-dd HH:mm:ss"): String = SimpleDateFormat(format).format(this)
|
||||
fun Long.formatDate(format: String = "yyyy-MM-dd HH:mm:ss"): String = SimpleDateFormat(format).format(this)
|
||||
|
||||
fun CharSequence?.asColoredSpannable(colorInt: Int): Spannable {
|
||||
val spannable = SpannableString(this)
|
||||
spannable.setSpan(ForegroundColorSpan(colorInt), 0, spannable.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
return spannable
|
||||
}
|
||||
fun CharSequence?.asStrikethroughSpannable(): Spannable {
|
||||
val spannable = SpannableString(this)
|
||||
spannable.setSpan(StrikethroughSpan(), 0, spannable.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
return spannable
|
||||
}
|
||||
fun CharSequence?.asItalicSpannable(): Spannable {
|
||||
val spannable = SpannableString(this)
|
||||
spannable.setSpan(StyleSpan(Typeface.ITALIC), 0, spannable.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
return spannable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new read-only list only of those given elements, that are not empty.
|
||||
* Applies for CharSequence and descendants.
|
||||
*/
|
||||
fun <T : CharSequence> listOfNotEmpty(vararg elements: T): List<T> = elements.filterNot { it.isEmpty() }
|
||||
|
||||
fun List<CharSequence>.concat(delimiter: String? = null): CharSequence {
|
||||
if (this.isEmpty()) {
|
||||
return ""
|
||||
}
|
||||
|
||||
if (this.size == 1) {
|
||||
return this[0]
|
||||
}
|
||||
|
||||
var spanned = false
|
||||
for (piece in this) {
|
||||
if (piece is Spanned) {
|
||||
spanned = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var first = true
|
||||
if (spanned) {
|
||||
val ssb = SpannableStringBuilder()
|
||||
for (piece in this) {
|
||||
if (!first && delimiter != null)
|
||||
ssb.append(delimiter)
|
||||
first = false
|
||||
ssb.append(piece)
|
||||
}
|
||||
return SpannedString(ssb)
|
||||
} else {
|
||||
val sb = StringBuilder()
|
||||
for (piece in this) {
|
||||
if (!first && delimiter != null)
|
||||
sb.append(delimiter)
|
||||
first = false
|
||||
sb.append(piece)
|
||||
}
|
||||
return sb.toString()
|
||||
}
|
||||
}
|
||||
|
||||
fun TextView.setText(@StringRes resid: Int, vararg formatArgs: Any) {
|
||||
text = context.getString(resid, *formatArgs)
|
||||
}
|
||||
|
||||
fun JsonObject(vararg properties: Pair<String, Any>): JsonObject {
|
||||
return JsonObject().apply {
|
||||
for (property in properties) {
|
||||
when (property.second) {
|
||||
is JsonElement -> add(property.first, property.second as JsonElement)
|
||||
is String -> addProperty(property.first, property.second as String)
|
||||
is Char -> addProperty(property.first, property.second as Char)
|
||||
is Number -> addProperty(property.first, property.second as Number)
|
||||
is Boolean -> addProperty(property.first, property.second as Boolean)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun JsonArray?.isNullOrEmpty(): Boolean = (this?.size() ?: 0) == 0
|
||||
fun JsonArray.isEmpty(): Boolean = this.size() == 0
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
inline fun <T : View> T.onClick(crossinline onClickListener: (v: T) -> Unit) {
|
||||
setOnClickListener { v: View ->
|
||||
onClickListener(v as T)
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> LiveData<T>.observeOnce(lifecycleOwner: LifecycleOwner, observer: Observer<T>) {
|
||||
observe(lifecycleOwner, object : Observer<T> {
|
||||
override fun onChanged(t: T?) {
|
||||
observer.onChanged(t)
|
||||
removeObserver(this)
|
||||
}
|
||||
})
|
||||
}
|
@ -2,13 +2,19 @@ package pl.szczodrzynski.edziennik
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.ActivityManager
|
||||
import android.content.*
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.os.*
|
||||
import android.provider.Settings
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.lifecycle.Observer
|
||||
@ -25,13 +31,11 @@ import com.mikepenz.materialdrawer.model.ProfileDrawerItem
|
||||
import com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IProfile
|
||||
import dagger.android.support.DaggerAppCompatActivity
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import pl.droidsonroids.gif.GifDrawable
|
||||
import pl.szczodrzynski.edziennik.App.APP_URL
|
||||
import pl.szczodrzynski.edziennik.api.v2.ApiService
|
||||
import pl.szczodrzynski.edziennik.api.v2.events.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.events.task.EdziennikTask
|
||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface.*
|
||||
@ -53,17 +57,18 @@ import pl.szczodrzynski.edziennik.ui.modules.grades.editor.GradesEditorFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.homework.HomeworkFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.login.LoginActivity
|
||||
import pl.szczodrzynski.edziennik.ui.modules.messages.MessagesDetailsFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.messages.MessageFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.messages.MessagesFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.notifications.NotificationsFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.settings.ProfileManagerFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.settings.SettingsNewFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.v2.TimetableFragment
|
||||
import pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoTouch
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.dpToPx
|
||||
import pl.szczodrzynski.edziennik.utils.appManagerIntentList
|
||||
import pl.szczodrzynski.edziennik.utils.models.NavTarget
|
||||
import pl.szczodrzynski.navlib.*
|
||||
import pl.szczodrzynski.navlib.SystemBarsUtil.Companion.COLOR_HALF_TRANSPARENT
|
||||
@ -78,7 +83,7 @@ import java.io.IOException
|
||||
import java.util.*
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class MainActivity : DaggerAppCompatActivity() {
|
||||
class MainActivity : AppCompatActivity() {
|
||||
companion object {
|
||||
|
||||
var useOldMessages = false
|
||||
@ -198,7 +203,7 @@ class MainActivity : DaggerAppCompatActivity() {
|
||||
list += NavTarget(TARGET_GRADES_EDITOR, R.string.menu_grades_editor, GradesEditorFragment::class)
|
||||
list += NavTarget(TARGET_HELP, R.string.menu_help, HelpFragment::class)
|
||||
list += NavTarget(TARGET_FEEDBACK, R.string.menu_feedback, FeedbackFragment::class)
|
||||
list += NavTarget(TARGET_MESSAGES_DETAILS, R.string.menu_message, MessagesDetailsFragment::class)
|
||||
list += NavTarget(TARGET_MESSAGES_DETAILS, R.string.menu_message, MessageFragment::class)
|
||||
list += NavTarget(DRAWER_ITEM_DEBUG, R.string.menu_debug, DebugFragment::class)
|
||||
|
||||
list
|
||||
@ -518,17 +523,14 @@ class MainActivity : DaggerAppCompatActivity() {
|
||||
fun syncCurrentFeature() {
|
||||
swipeRefreshLayout.isRefreshing = true
|
||||
Toast.makeText(this, fragmentToSyncName(navTargetId), Toast.LENGTH_SHORT).show()
|
||||
ApiService.start(this)
|
||||
val fragmentParam = when (navTargetId) {
|
||||
DRAWER_ITEM_MESSAGES -> MessagesFragment.pageSelection
|
||||
else -> 0
|
||||
}
|
||||
EventBus.getDefault().postSticky(
|
||||
EdziennikTask.syncProfile(
|
||||
App.profileId,
|
||||
listOf(navTargetId to fragmentParam)
|
||||
)
|
||||
)
|
||||
EdziennikTask.syncProfile(
|
||||
App.profileId,
|
||||
listOf(navTargetId to fragmentParam)
|
||||
).enqueue(this)
|
||||
}
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onSyncStartedEvent(event: ApiTaskStartedEvent) {
|
||||
@ -582,29 +584,18 @@ class MainActivity : DaggerAppCompatActivity() {
|
||||
.setMessage(R.string.app_manager_dialog_text)
|
||||
.setPositiveButton(R.string.ok) { dialog, which ->
|
||||
try {
|
||||
val intent = Intent()
|
||||
intent.component = ComponentName(
|
||||
"com.huawei.systemmanager",
|
||||
"com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity"
|
||||
)
|
||||
startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
try {
|
||||
val intent = Intent()
|
||||
intent.component = ComponentName(
|
||||
"com.asus.mobilemanager",
|
||||
"com.asus.mobilemanager.MainActivity"
|
||||
)
|
||||
startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
startActivity(Intent(android.provider.Settings.ACTION_SETTINGS))
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Toast.makeText(this, R.string.app_manager_open_failed, Toast.LENGTH_SHORT).show()
|
||||
for (intent in appManagerIntentList) {
|
||||
if (packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
startActivity(Intent(Settings.ACTION_SETTINGS))
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Toast.makeText(this, R.string.app_manager_open_failed, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
.setNeutralButton(R.string.dont_ask_again) { dialog, which ->
|
||||
@ -710,7 +701,8 @@ class MainActivity : DaggerAppCompatActivity() {
|
||||
}
|
||||
intentTargetId != -1 -> {
|
||||
drawer.currentProfile = app.profile.id
|
||||
loadTarget(intentTargetId, extras)
|
||||
if (navTargetId != intentTargetId)
|
||||
loadTarget(intentTargetId, extras)
|
||||
}
|
||||
else -> {
|
||||
drawer.currentProfile = app.profile.id
|
||||
@ -788,7 +780,7 @@ class MainActivity : DaggerAppCompatActivity() {
|
||||
fun loadProfile(id: Int) = loadProfile(id, navTargetId)
|
||||
fun loadProfile(id: Int, arguments: Bundle?) = loadProfile(id, navTargetId, arguments)
|
||||
fun loadProfile(id: Int, drawerSelection: Int, arguments: Bundle? = null) {
|
||||
d("NavDebug", "loadProfile(id = $id, drawerSelection = $drawerSelection)")
|
||||
//d("NavDebug", "loadProfile(id = $id, drawerSelection = $drawerSelection)")
|
||||
if (app.profile != null && App.profileId == id) {
|
||||
drawer.currentProfile = app.profile.id
|
||||
loadTarget(drawerSelection, arguments)
|
||||
|
@ -90,6 +90,7 @@ class ApiService : Service() {
|
||||
errorList.add(apiError)
|
||||
apiError.throwable?.printStackTrace()
|
||||
if (apiError.isCritical) {
|
||||
taskRunning?.cancel()
|
||||
notification.setCriticalError().post()
|
||||
taskRunning = null
|
||||
taskIsRunning = false
|
||||
@ -154,10 +155,14 @@ class ApiService : Service() {
|
||||
// post an event
|
||||
EventBus.getDefault().post(ApiTaskStartedEvent(taskProfileId, task.profile))
|
||||
|
||||
when (task) {
|
||||
is EdziennikTask -> task.run(app, taskCallback)
|
||||
is NotifyTask -> task.run(app, taskCallback)
|
||||
is ErrorReportTask -> task.run(app, taskCallback, notification, errorList)
|
||||
try {
|
||||
when (task) {
|
||||
is EdziennikTask -> task.run(app, taskCallback)
|
||||
is NotifyTask -> task.run(app, taskCallback)
|
||||
is ErrorReportTask -> task.run(app, taskCallback, notification, errorList)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
taskCallback.onError(ApiError(TAG, EXCEPTION_API_TASK).withThrowable(e))
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,11 +232,13 @@ class ApiService : Service() {
|
||||
____) | __/ | \ V /| | (_| __/ | (_) \ V / __/ | | | | | (_| | __/\__ \
|
||||
|_____/ \___|_| \_/ |_|\___\___| \___/ \_/ \___|_| |_| |_|\__,_|\___||__*/
|
||||
override fun onCreate() {
|
||||
d(TAG, "Service created")
|
||||
EventBus.getDefault().register(this)
|
||||
notification.setIdle().setCloseAction()
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
d(TAG, "Foreground service onStartCommand")
|
||||
startForeground(EdziennikNotification.NOTIFICATION_ID, notification.notification)
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
@ -14,6 +14,14 @@ val SYSTEM_USER_AGENT = System.getProperty("http.agent") ?: "Dalvik/2.1.0 Androi
|
||||
|
||||
val SERVER_USER_AGENT = "Szkolny.eu/${BuildConfig.VERSION_NAME} $SYSTEM_USER_AGENT"
|
||||
|
||||
const val FAKE_LIBRUS_API = "http://librus.szkolny.eu/api"
|
||||
const val FAKE_LIBRUS_PORTAL = "http://librus.szkolny.eu"
|
||||
const val FAKE_LIBRUS_AUTHORIZE = "http://librus.szkolny.eu/authorize.php"
|
||||
const val FAKE_LIBRUS_LOGIN = "http://librus.szkolny.eu/login_action.php"
|
||||
const val FAKE_LIBRUS_TOKEN = "http://librus.szkolny.eu/access_token.php"
|
||||
const val FAKE_LIBRUS_ACCOUNT = "/synergia_accounts_fresh.php?login="
|
||||
const val FAKE_LIBRUS_ACCOUNTS = "/synergia_accounts.php"
|
||||
|
||||
val LIBRUS_USER_AGENT = "$SYSTEM_USER_AGENT LibrusMobileApp"
|
||||
const val SYNERGIA_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Gecko/20100101 Firefox/62.0"
|
||||
const val LIBRUS_CLIENT_ID = "wmSyUMo8llDAs4y9tJVYY92oyZ6h4lAt7KCuy0Gv"
|
||||
|
@ -150,6 +150,7 @@ const val ERROR_IDZIENNIK_API_OTHER = 451
|
||||
|
||||
const val ERROR_TEMPLATE_WEB_OTHER = 801
|
||||
|
||||
const val EXCEPTION_API_TASK = 900
|
||||
const val EXCEPTION_LOGIN_LIBRUS_API_TOKEN = 901
|
||||
const val EXCEPTION_LOGIN_LIBRUS_PORTAL_TOKEN = 902
|
||||
const val EXCEPTION_LIBRUS_PORTAL_SYNERGIA_TOKEN = 903
|
||||
|
@ -66,13 +66,13 @@ val librusLoginMethods = listOf(
|
||||
},
|
||||
|
||||
LoginMethod(LOGIN_TYPE_LIBRUS, LOGIN_METHOD_LIBRUS_SYNERGIA, LibrusLoginSynergia::class.java)
|
||||
.withIsPossible { _, _ -> true }
|
||||
.withIsPossible { _, loginStore -> !loginStore.hasLoginData("fakeLogin") }
|
||||
.withRequiredLoginMethod { profile, _ ->
|
||||
if (profile?.hasStudentData("accountPassword") == false) LOGIN_METHOD_LIBRUS_API else LOGIN_METHOD_NOT_NEEDED
|
||||
},
|
||||
|
||||
LoginMethod(LOGIN_TYPE_LIBRUS, LOGIN_METHOD_LIBRUS_MESSAGES, LibrusLoginMessages::class.java)
|
||||
.withIsPossible { _, _ -> true }
|
||||
.withIsPossible { _, loginStore -> !loginStore.hasLoginData("fakeLogin") }
|
||||
.withRequiredLoginMethod { profile, _ ->
|
||||
if (profile?.hasStudentData("accountPassword") == false) LOGIN_METHOD_LIBRUS_SYNERGIA else LOGIN_METHOD_NOT_NEEDED
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-11-12.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.events
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||
|
||||
data class MessageGetEvent(val message: MessageFull)
|
@ -1,5 +1,6 @@
|
||||
package pl.szczodrzynski.edziennik.api.v2.events.task
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.api.v2.*
|
||||
@ -11,6 +12,7 @@ import pl.szczodrzynski.edziennik.api.v2.mobidziennik.Mobidziennik
|
||||
import pl.szczodrzynski.edziennik.api.v2.template.Template
|
||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.Vulcan
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||
|
||||
open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTask(profileId) {
|
||||
companion object {
|
||||
@ -18,9 +20,9 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
||||
|
||||
fun firstLogin(loginStore: LoginStore) = EdziennikTask(-1, FirstLoginRequest(loginStore))
|
||||
fun sync() = EdziennikTask(-1, SyncRequest())
|
||||
fun syncProfile(profileId: Int, viewIds: List<Pair<Int, Int>>? = null) = EdziennikTask(profileId, SyncProfileRequest(viewIds))
|
||||
fun syncProfile(profileId: Int, viewIds: List<Pair<Int, Int>>? = null, arguments: JsonObject? = null) = EdziennikTask(profileId, SyncProfileRequest(viewIds, arguments))
|
||||
fun syncProfileList(profileList: List<Int>) = EdziennikTask(-1, SyncProfileListRequest(profileList))
|
||||
fun messageGet(profileId: Int, messageId: Int) = EdziennikTask(profileId, MessageGetRequest(messageId))
|
||||
fun messageGet(profileId: Int, message: MessageFull) = EdziennikTask(profileId, MessageGetRequest(message))
|
||||
fun announcementsRead(profileId: Int) = EdziennikTask(profileId, AnnouncementsReadRequest())
|
||||
}
|
||||
|
||||
@ -38,7 +40,7 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
||||
// get the requested profile and login store
|
||||
val profile = app.db.profileDao().getByIdNow(profileId)
|
||||
this.profile = profile
|
||||
if (profile == null || !profile.syncEnabled) {
|
||||
if (profile == null) {
|
||||
return
|
||||
}
|
||||
val loginStore = app.db.loginStoreDao().getByIdNow(profile.loginStoreId) ?: return
|
||||
@ -50,7 +52,7 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
||||
|
||||
private var edziennikInterface: EdziennikInterface? = null
|
||||
|
||||
fun run(app: App, taskCallback: EdziennikCallback) {
|
||||
internal fun run(app: App, taskCallback: EdziennikCallback) {
|
||||
edziennikInterface = when (loginStore.type) {
|
||||
LOGIN_TYPE_LIBRUS -> Librus(app, profile, loginStore, taskCallback)
|
||||
LOGIN_TYPE_MOBIDZIENNIK -> Mobidziennik(app, profile, loginStore, taskCallback)
|
||||
@ -66,8 +68,9 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
||||
when (request) {
|
||||
is SyncProfileRequest -> edziennikInterface?.sync(
|
||||
featureIds = request.viewIds?.flatMap { Features.getIdsByView(it.first, it.second) } ?: Features.getAllIds(),
|
||||
viewId = request.viewIds?.get(0)?.first)
|
||||
is MessageGetRequest -> edziennikInterface?.getMessage(request.messageId)
|
||||
viewId = request.viewIds?.get(0)?.first,
|
||||
arguments = request.arguments)
|
||||
is MessageGetRequest -> edziennikInterface?.getMessage(request.message)
|
||||
is FirstLoginRequest -> edziennikInterface?.firstLogin()
|
||||
is AnnouncementsReadRequest -> edziennikInterface?.markAllAnnouncementsAsRead()
|
||||
}
|
||||
@ -83,8 +86,8 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
||||
|
||||
data class FirstLoginRequest(val loginStore: LoginStore)
|
||||
class SyncRequest
|
||||
data class SyncProfileRequest(val viewIds: List<Pair<Int, Int>>? = null)
|
||||
data class SyncProfileRequest(val viewIds: List<Pair<Int, Int>>? = null, val arguments: JsonObject? = null)
|
||||
data class SyncProfileListRequest(val profileList: List<Int>)
|
||||
data class MessageGetRequest(val messageId: Int)
|
||||
data class MessageGetRequest(val message: MessageFull)
|
||||
class AnnouncementsReadRequest
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ package pl.szczodrzynski.edziennik.api.v2.events.task
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build.VERSION.SDK_INT
|
||||
import android.os.Build.VERSION_CODES.O
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.api.v2.ApiService
|
||||
@ -25,7 +27,12 @@ abstract class IApiTask(open val profileId: Int) {
|
||||
abstract fun cancel()
|
||||
|
||||
fun enqueue(context: Context) {
|
||||
context.startService(Intent(context, ApiService::class.java))
|
||||
Intent(context, ApiService::class.java).let {
|
||||
if (SDK_INT >= O)
|
||||
context.startForegroundService(it)
|
||||
else
|
||||
context.startService(it)
|
||||
}
|
||||
EventBus.getDefault().postSticky(this)
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.idziennik
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.api.v2.CODE_INTERNAL_LIBRUS_ACCOUNT_410
|
||||
import pl.szczodrzynski.edziennik.api.v2.idziennik.data.IdziennikData
|
||||
@ -15,6 +16,7 @@ import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikInterface
|
||||
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.api.v2.prepare
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
|
||||
@ -48,7 +50,8 @@ class Idziennik(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
||||
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
||||
__/ |
|
||||
|__*/
|
||||
override fun sync(featureIds: List<Int>, viewId: Int?) {
|
||||
override fun sync(featureIds: List<Int>, viewId: Int?, arguments: JsonObject?) {
|
||||
data.arguments = arguments
|
||||
data.prepare(idziennikLoginMethods, IdziennikFeatures, featureIds, viewId)
|
||||
d(TAG, "LoginMethod IDs: ${data.targetLoginMethodIds}")
|
||||
d(TAG, "Endpoint IDs: ${data.targetEndpointIds}")
|
||||
@ -59,7 +62,7 @@ class Idziennik(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
||||
}
|
||||
}
|
||||
|
||||
override fun getMessage(messageId: Int) {
|
||||
override fun getMessage(message: MessageFull) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -41,43 +41,43 @@ class IdziennikData(val data: DataIdziennik, val onSuccess: () -> Unit) {
|
||||
when (endpointId) {
|
||||
ENDPOINT_IDZIENNIK_WEB_TIMETABLE -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_timetable)
|
||||
IdziennikWebTimetable(data) { onSuccess() }
|
||||
IdziennikWebTimetable(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_IDZIENNIK_WEB_GRADES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||
IdziennikWebGrades(data) { onSuccess() }
|
||||
IdziennikWebGrades(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_IDZIENNIK_WEB_PROPOSED_GRADES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_proposed_grades)
|
||||
IdziennikWebProposedGrades(data) { onSuccess() }
|
||||
IdziennikWebProposedGrades(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_IDZIENNIK_WEB_EXAMS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_exams)
|
||||
IdziennikWebExams(data) { onSuccess() }
|
||||
IdziennikWebExams(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_IDZIENNIK_WEB_NOTICES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_notices)
|
||||
IdziennikWebNotices(data) { onSuccess() }
|
||||
IdziennikWebNotices(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_IDZIENNIK_WEB_ANNOUNCEMENTS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_announcements)
|
||||
IdziennikWebAnnouncements(data) { onSuccess() }
|
||||
IdziennikWebAnnouncements(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_IDZIENNIK_WEB_ATTENDANCE -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_attendance)
|
||||
IdziennikWebAttendance(data) { onSuccess() }
|
||||
IdziennikWebAttendance(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_IDZIENNIK_API_CURRENT_REGISTER -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
||||
IdziennikApiCurrentRegister(data) { onSuccess() }
|
||||
IdziennikApiCurrentRegister(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_IDZIENNIK_API_MESSAGES_INBOX -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_inbox)
|
||||
IdziennikApiMessagesInbox(data) { onSuccess() }
|
||||
IdziennikApiMessagesInbox(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_IDZIENNIK_API_MESSAGES_SENT -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_outbox)
|
||||
IdziennikApiMessagesSent(data) { onSuccess() }
|
||||
IdziennikApiMessagesSent(data, onSuccess)
|
||||
}
|
||||
else -> onSuccess()
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ class IdziennikApiMessagesInbox(override val data: DataIdziennik,
|
||||
/*messageId*/ messageId
|
||||
)
|
||||
|
||||
data.messageList.add(message)
|
||||
data.messageIgnoreList.add(message)
|
||||
data.messageRecipientList.add(messageRecipient)
|
||||
data.messageMetadataList.add(Metadata(
|
||||
profileId,
|
||||
|
@ -74,7 +74,7 @@ class IdziennikApiMessagesSent(override val data: DataIdziennik,
|
||||
data.messageRecipientIgnoreList.add(messageRecipient)
|
||||
}
|
||||
|
||||
data.messageList.add(message)
|
||||
data.messageIgnoreList.add(message)
|
||||
data.metadataList.add(Metadata(profileId, Metadata.TYPE_MESSAGE, message.id, true, true, sentDate))
|
||||
}
|
||||
|
||||
|
@ -4,9 +4,12 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.interfaces
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||
|
||||
interface EdziennikInterface {
|
||||
fun sync(featureIds: List<Int>, viewId: Int? = null)
|
||||
fun getMessage(messageId: Int)
|
||||
fun sync(featureIds: List<Int>, viewId: Int? = null, arguments: JsonObject? = null)
|
||||
fun getMessage(message: MessageFull)
|
||||
fun markAllAnnouncementsAsRead()
|
||||
fun firstLogin()
|
||||
fun cancel()
|
||||
|
@ -4,20 +4,22 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.librus
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.api.v2.CODE_INTERNAL_LIBRUS_ACCOUNT_410
|
||||
import pl.szczodrzynski.edziennik.api.v2.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback
|
||||
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikInterface
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusData
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.messages.LibrusMessagesGetMessage
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.synergia.LibrusSynergiaMarkAllAnnouncementsAsRead
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.firstlogin.LibrusFirstLogin
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.login.LibrusLogin
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.login.LibrusLoginApi
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.login.LibrusLoginMessages
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.login.LibrusLoginSynergia
|
||||
import pl.szczodrzynski.edziennik.api.v2.librusLoginMethods
|
||||
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.api.v2.prepare
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
|
||||
@ -51,19 +53,44 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
||||
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
||||
__/ |
|
||||
|__*/
|
||||
override fun sync(featureIds: List<Int>, viewId: Int?) {
|
||||
override fun sync(featureIds: List<Int>, viewId: Int?, arguments: JsonObject?) {
|
||||
data.arguments = arguments
|
||||
data.prepare(librusLoginMethods, LibrusFeatures, featureIds, viewId)
|
||||
d(TAG, "LoginMethod IDs: ${data.targetLoginMethodIds}")
|
||||
d(TAG, "Endpoint IDs: ${data.targetEndpointIds}")
|
||||
login()
|
||||
}
|
||||
|
||||
private fun login() {
|
||||
d(TAG, "Trying to login with ${data.targetLoginMethodIds}")
|
||||
if (internalErrorList.isNotEmpty()) {
|
||||
d(TAG, " - Internal errors:")
|
||||
internalErrorList.forEach { d(TAG, " - code $it") }
|
||||
}
|
||||
LibrusLogin(data) {
|
||||
LibrusData(data) {
|
||||
completed()
|
||||
}
|
||||
data()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getMessage(messageId: Int) {
|
||||
private fun data() {
|
||||
d(TAG, "Endpoint IDs: ${data.targetEndpointIds}")
|
||||
if (internalErrorList.isNotEmpty()) {
|
||||
d(TAG, " - Internal errors:")
|
||||
internalErrorList.forEach { d(TAG, " - code $it") }
|
||||
}
|
||||
LibrusData(data) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getMessage(message: MessageFull) {
|
||||
LibrusLoginApi(data) {
|
||||
LibrusLoginSynergia(data) {
|
||||
LibrusLoginMessages(data) {
|
||||
LibrusMessagesGetMessage(data, message) {
|
||||
completed()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun markAllAnnouncementsAsRead() {
|
||||
@ -102,15 +129,70 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
||||
}
|
||||
|
||||
override fun onError(apiError: ApiError) {
|
||||
if (apiError.errorCode in internalErrorList) {
|
||||
// finish immediately if the same error occurs twice during the same sync
|
||||
callback.onError(apiError)
|
||||
return
|
||||
}
|
||||
internalErrorList.add(apiError.errorCode)
|
||||
when (apiError.errorCode) {
|
||||
in internalErrorList -> {
|
||||
// finish immediately if the same error occurs twice during the same sync
|
||||
callback.onError(apiError)
|
||||
ERROR_LIBRUS_PORTAL_ACCESS_DENIED -> {
|
||||
data.loginMethods.remove(LOGIN_METHOD_LIBRUS_PORTAL)
|
||||
data.targetLoginMethodIds.add(LOGIN_METHOD_LIBRUS_PORTAL)
|
||||
data.targetLoginMethodIds.sort()
|
||||
data.portalTokenExpiryTime = 0
|
||||
login()
|
||||
}
|
||||
CODE_INTERNAL_LIBRUS_ACCOUNT_410 -> {
|
||||
internalErrorList.add(apiError.errorCode)
|
||||
loginStore.removeLoginData("refreshToken") // force a clean login
|
||||
//loginLibrus()
|
||||
ERROR_LIBRUS_API_ACCESS_DENIED,
|
||||
ERROR_LIBRUS_API_TOKEN_EXPIRED -> {
|
||||
data.loginMethods.remove(LOGIN_METHOD_LIBRUS_API)
|
||||
data.targetLoginMethodIds.add(LOGIN_METHOD_LIBRUS_API)
|
||||
data.targetLoginMethodIds.sort()
|
||||
data.apiTokenExpiryTime = 0
|
||||
login()
|
||||
}
|
||||
ERROR_LIBRUS_SYNERGIA_ACCESS_DENIED -> {
|
||||
data.loginMethods.remove(LOGIN_METHOD_LIBRUS_SYNERGIA)
|
||||
data.targetLoginMethodIds.add(LOGIN_METHOD_LIBRUS_SYNERGIA)
|
||||
data.targetLoginMethodIds.sort()
|
||||
data.synergiaSessionIdExpiryTime = 0
|
||||
login()
|
||||
}
|
||||
ERROR_LIBRUS_MESSAGES_ACCESS_DENIED -> {
|
||||
data.loginMethods.remove(LOGIN_METHOD_LIBRUS_MESSAGES)
|
||||
data.targetLoginMethodIds.add(LOGIN_METHOD_LIBRUS_MESSAGES)
|
||||
data.targetLoginMethodIds.sort()
|
||||
data.messagesSessionIdExpiryTime = 0
|
||||
login()
|
||||
}
|
||||
ERROR_LOGIN_LIBRUS_PORTAL_NO_CODE,
|
||||
ERROR_LOGIN_LIBRUS_PORTAL_CSRF_MISSING,
|
||||
ERROR_LOGIN_LIBRUS_PORTAL_CODE_REVOKED,
|
||||
ERROR_LOGIN_LIBRUS_PORTAL_CODE_EXPIRED -> {
|
||||
login()
|
||||
}
|
||||
ERROR_LOGIN_LIBRUS_PORTAL_NO_REFRESH,
|
||||
ERROR_LOGIN_LIBRUS_PORTAL_REFRESH_REVOKED,
|
||||
ERROR_LOGIN_LIBRUS_PORTAL_REFRESH_INVALID -> {
|
||||
data.portalRefreshToken = null
|
||||
login()
|
||||
}
|
||||
ERROR_LOGIN_LIBRUS_SYNERGIA_TOKEN_INVALID,
|
||||
ERROR_LOGIN_LIBRUS_SYNERGIA_NO_TOKEN,
|
||||
ERROR_LOGIN_LIBRUS_SYNERGIA_NO_SESSION_ID -> {
|
||||
login()
|
||||
}
|
||||
ERROR_LOGIN_LIBRUS_MESSAGES_NO_SESSION_ID -> {
|
||||
login()
|
||||
}
|
||||
// TODO PORTAL CAPTCHA
|
||||
ERROR_LIBRUS_API_TIMETABLE_NOT_PUBLIC -> {
|
||||
loginStore.putLoginData("timetableNotPublic", true)
|
||||
data()
|
||||
}
|
||||
ERROR_LIBRUS_API_LUCKY_NUMBER_NOT_ACTIVE,
|
||||
ERROR_LIBRUS_API_NOTES_NOT_ACTIVE -> {
|
||||
data()
|
||||
}
|
||||
else -> callback.onError(apiError)
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ open class LibrusApi(open val data: DataLibrus) {
|
||||
|
||||
fun apiGet(tag: String, endpoint: String, method: Int = GET, payload: JsonObject? = null, onSuccess: (json: JsonObject) -> Unit) {
|
||||
|
||||
d(tag, "Request: Librus/Api - $LIBRUS_API_URL/$endpoint")
|
||||
d(tag, "Request: Librus/Api - ${if (data.fakeLogin) FAKE_LIBRUS_API else LIBRUS_API_URL}/$endpoint")
|
||||
|
||||
val callback = object : JsonCallbackHandler() {
|
||||
override fun onSuccess(json: JsonObject?, response: Response?) {
|
||||
@ -90,7 +90,7 @@ open class LibrusApi(open val data: DataLibrus) {
|
||||
}
|
||||
|
||||
Request.builder()
|
||||
.url("$LIBRUS_API_URL/$endpoint")
|
||||
.url("${if (data.fakeLogin) FAKE_LIBRUS_API else LIBRUS_API_URL}/$endpoint")
|
||||
.userAgent(LIBRUS_USER_AGENT)
|
||||
.addHeader("Authorization", "Bearer ${data.apiAccessToken}")
|
||||
.apply {
|
||||
|
@ -45,92 +45,99 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
*/
|
||||
ENDPOINT_LIBRUS_API_ME -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_student_info)
|
||||
LibrusApiMe(data) { onSuccess() }
|
||||
LibrusApiMe(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_SCHOOLS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_school_info)
|
||||
LibrusApiSchools(data) { onSuccess() }
|
||||
LibrusApiSchools(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_CLASSES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_classes)
|
||||
LibrusApiClasses(data) { onSuccess() }
|
||||
LibrusApiClasses(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_VIRTUAL_CLASSES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_teams)
|
||||
LibrusApiVirtualClasses(data) { onSuccess() }
|
||||
LibrusApiVirtualClasses(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_UNITS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_units)
|
||||
LibrusApiUnits(data) { onSuccess() }
|
||||
LibrusApiUnits(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_USERS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_teachers)
|
||||
LibrusApiUsers(data) { onSuccess() }
|
||||
LibrusApiUsers(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_SUBJECTS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_subjects)
|
||||
LibrusApiSubjects(data) { onSuccess() }
|
||||
LibrusApiSubjects(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_CLASSROOMS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_classrooms)
|
||||
LibrusApiClassrooms(data) { onSuccess() }
|
||||
LibrusApiClassrooms(data, onSuccess)
|
||||
}
|
||||
// TODO push config
|
||||
// TODO timetable
|
||||
ENDPOINT_LIBRUS_API_TIMETABLES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_timetable)
|
||||
LibrusApiTimetables(data, onSuccess)
|
||||
}
|
||||
|
||||
ENDPOINT_LIBRUS_API_NORMAL_GRADES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||
LibrusApiGrades(data) { onSuccess() }
|
||||
LibrusApiGrades(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_NORMAL_GC -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grade_categories)
|
||||
LibrusApiGradeCategories(data, onSuccess)
|
||||
}
|
||||
// TODO grades
|
||||
|
||||
ENDPOINT_LIBRUS_API_EVENT_TYPES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_event_types)
|
||||
LibrusApiEventTypes(data) { onSuccess() }
|
||||
LibrusApiEventTypes(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_EVENTS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_events)
|
||||
LibrusApiEvents(data) { onSuccess() }
|
||||
LibrusApiEvents(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_HOMEWORK -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_homework)
|
||||
LibrusApiHomework(data) { onSuccess() }
|
||||
LibrusApiHomework(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_LUCKY_NUMBER -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
||||
LibrusApiLuckyNumber(data) { onSuccess() }
|
||||
LibrusApiLuckyNumber(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_NOTICE_TYPES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_notice_types)
|
||||
LibrusApiNoticeTypes(data) { onSuccess() }
|
||||
LibrusApiNoticeTypes(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_NOTICES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_notices)
|
||||
LibrusApiNotices(data) { onSuccess() }
|
||||
LibrusApiNotices(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_ATTENDANCE_TYPES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_attendance_types)
|
||||
LibrusApiAttendanceTypes(data) { onSuccess() }
|
||||
LibrusApiAttendanceTypes(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_ATTENDANCES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_attendance)
|
||||
LibrusApiAttendances(data) { onSuccess() }
|
||||
LibrusApiAttendances(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_ANNOUNCEMENTS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_announcements)
|
||||
LibrusApiAnnouncements(data) { onSuccess() }
|
||||
LibrusApiAnnouncements(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_PT_MEETINGS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_pt_meetings)
|
||||
LibrusApiPtMeetings(data) { onSuccess() }
|
||||
LibrusApiPtMeetings(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_TEACHER_FREE_DAY_TYPES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_teacher_free_day_types)
|
||||
LibrusApiTeacherFreeDayTypes(data) { onSuccess() }
|
||||
LibrusApiTeacherFreeDayTypes(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_teacher_free_days)
|
||||
LibrusApiTeacherFreeDays(data) { onSuccess() }
|
||||
LibrusApiTeacherFreeDays(data, onSuccess)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -138,11 +145,11 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
*/
|
||||
ENDPOINT_LIBRUS_SYNERGIA_HOMEWORK -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_homework)
|
||||
LibrusSynergiaHomework(data) { onSuccess() }
|
||||
LibrusSynergiaHomework(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_SYNERGIA_INFO -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_student_info)
|
||||
LibrusSynergiaInfo(data) { onSuccess() }
|
||||
LibrusSynergiaInfo(data, onSuccess)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,11 +157,11 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
*/
|
||||
ENDPOINT_LIBRUS_MESSAGES_RECEIVED -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_inbox)
|
||||
LibrusMessagesGetList(data, type = Message.TYPE_RECEIVED) { onSuccess() }
|
||||
LibrusMessagesGetList(data, type = Message.TYPE_RECEIVED, onSuccess = onSuccess)
|
||||
}
|
||||
ENDPOINT_LIBRUS_MESSAGES_SENT -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_outbox)
|
||||
LibrusMessagesGetList(data, type = Message.TYPE_SENT) { onSuccess() }
|
||||
LibrusMessagesGetList(data, type = Message.TYPE_SENT, onSuccess = onSuccess)
|
||||
}
|
||||
|
||||
else -> onSuccess()
|
||||
|
@ -12,13 +12,17 @@ import okhttp3.Cookie
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.parser.Parser
|
||||
import org.redundent.kotlin.xml.PrintOptions
|
||||
import org.redundent.kotlin.xml.xml
|
||||
import pl.szczodrzynski.edziennik.api.v2.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.get
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
import java.io.StringWriter
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
import javax.xml.transform.OutputKeys
|
||||
import javax.xml.transform.TransformerFactory
|
||||
import javax.xml.transform.dom.DOMSource
|
||||
import javax.xml.transform.stream.StreamResult
|
||||
|
||||
open class LibrusMessages(open val data: DataLibrus) {
|
||||
companion object {
|
||||
@ -80,7 +84,27 @@ open class LibrusMessages(open val data: DataLibrus) {
|
||||
.secure().httpOnly().build()
|
||||
))
|
||||
|
||||
val requestXml = xml("service") {
|
||||
|
||||
val docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||
val doc = docBuilder.newDocument()
|
||||
val serviceElement = doc.createElement("service")
|
||||
val headerElement = doc.createElement("header")
|
||||
val dataElement = doc.createElement("data")
|
||||
for ((key, value) in parameters.orEmpty()) {
|
||||
val element = doc.createElement(key)
|
||||
element.appendChild(doc.createTextNode(value.toString()))
|
||||
dataElement.appendChild(element)
|
||||
}
|
||||
serviceElement.appendChild(headerElement)
|
||||
serviceElement.appendChild(dataElement)
|
||||
doc.appendChild(serviceElement)
|
||||
val transformer = TransformerFactory.newInstance().newTransformer()
|
||||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes")
|
||||
val stringWriter = StringWriter()
|
||||
transformer.transform(DOMSource(doc), StreamResult(stringWriter))
|
||||
val requestXml = stringWriter.toString()
|
||||
|
||||
/*val requestXml = xml("service") {
|
||||
"header" { }
|
||||
"data" {
|
||||
for ((key, value) in parameters.orEmpty()) {
|
||||
@ -92,7 +116,7 @@ open class LibrusMessages(open val data: DataLibrus) {
|
||||
}.toString(PrintOptions(
|
||||
singleLineTextElements = true,
|
||||
useSelfClosingTags = true
|
||||
))
|
||||
))*/
|
||||
|
||||
Request.builder()
|
||||
.url("$LIBRUS_MESSAGES_URL/$endpoint")
|
||||
|
@ -24,7 +24,7 @@ open class LibrusPortal(open val data: DataLibrus) {
|
||||
|
||||
fun portalGet(tag: String, endpoint: String, method: Int = GET, payload: JsonObject? = null, onSuccess: (json: JsonObject, response: Response?) -> Unit) {
|
||||
|
||||
d(tag, "Request: Librus/Portal - $LIBRUS_PORTAL_URL$endpoint")
|
||||
d(tag, "Request: Librus/Portal - ${if (data.fakeLogin) FAKE_LIBRUS_PORTAL else LIBRUS_PORTAL_URL}$endpoint")
|
||||
|
||||
val callback = object : JsonCallbackHandler() {
|
||||
override fun onSuccess(json: JsonObject?, response: Response?) {
|
||||
@ -44,7 +44,10 @@ open class LibrusPortal(open val data: DataLibrus) {
|
||||
"Access token is invalid" -> ERROR_LIBRUS_PORTAL_ACCESS_DENIED
|
||||
"ApiDisabled" -> ERROR_LIBRUS_PORTAL_API_DISABLED
|
||||
"Account not found" -> ERROR_LIBRUS_PORTAL_SYNERGIA_NOT_FOUND
|
||||
else -> ERROR_LIBRUS_PORTAL_OTHER
|
||||
else -> when (json.getString("hint")) {
|
||||
"Error while decoding to JSON" -> ERROR_LIBRUS_PORTAL_ACCESS_DENIED
|
||||
else -> ERROR_LIBRUS_PORTAL_OTHER
|
||||
}
|
||||
}.let { errorCode ->
|
||||
data.error(ApiError(tag, errorCode)
|
||||
.withApiResponse(json)
|
||||
@ -78,7 +81,7 @@ open class LibrusPortal(open val data: DataLibrus) {
|
||||
}
|
||||
|
||||
Request.builder()
|
||||
.url(LIBRUS_PORTAL_URL + endpoint)
|
||||
.url((if (data.fakeLogin) FAKE_LIBRUS_PORTAL else LIBRUS_PORTAL_URL) + endpoint)
|
||||
.userAgent(LIBRUS_USER_AGENT)
|
||||
.addHeader("Authorization", "Bearer ${data.portalAccessToken}")
|
||||
.apply {
|
||||
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-5
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
||||
|
||||
import android.graphics.Color
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_NORMAL_GC
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
||||
|
||||
class LibrusApiGradeCategories(override val data: DataLibrus,
|
||||
val onSuccess: () -> Unit) : LibrusApi(data) {
|
||||
companion object {
|
||||
const val TAG = "LibrusApiGradeCategories"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGet(TAG, "Grades/Categories") { json ->
|
||||
json.getJsonArray("Categories")?.asJsonObjectList()?.forEach { category ->
|
||||
val id = category.getLong("Id") ?: return@forEach
|
||||
val name = category.getString("Name") ?: ""
|
||||
val weight = when (category.getBoolean("CountToTheAverage")) {
|
||||
true -> category.getFloat("Weight") ?: 0f
|
||||
else -> 0f
|
||||
}
|
||||
val color = category.getJsonObject("Color")?.getInt("Id")
|
||||
?.let { data.getColor(it) } ?: Color.BLUE
|
||||
|
||||
val gradeCategoryObject = GradeCategory(
|
||||
profileId,
|
||||
id,
|
||||
weight,
|
||||
color,
|
||||
name
|
||||
)
|
||||
|
||||
data.gradeCategories.put(id, gradeCategoryObject)
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_NORMAL_GC, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,192 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-11-10.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
||||
|
||||
import androidx.core.util.isEmpty
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_TIMETABLES
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||
import pl.szczodrzynski.edziennik.api.v2.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
|
||||
class LibrusApiTimetables(override val data: DataLibrus,
|
||||
val onSuccess: () -> Unit) : LibrusApi(data) {
|
||||
companion object {
|
||||
const val TAG = "LibrusApiTimetables"
|
||||
}
|
||||
|
||||
init {
|
||||
if (data.classrooms.isEmpty()) {
|
||||
data.db.classroomDao().getAllNow(profileId).toSparseArray(data.classrooms) { it.id }
|
||||
}
|
||||
|
||||
val currentWeekStart = Date.getToday().let { it.stepForward(0, 0, -it.weekDay) }
|
||||
val getDate = data.arguments?.getString("weekStart") ?: currentWeekStart.stringY_m_d
|
||||
apiGet(TAG, "Timetables?weekStart=$getDate") { json ->
|
||||
val days = json.getJsonObject("Timetable")
|
||||
|
||||
days?.entrySet()?.forEach { (dateString, dayEl) ->
|
||||
val day = dayEl?.asJsonArray
|
||||
|
||||
val lessonDate = dateString?.let { Date.fromY_m_d(it) } ?: return@forEach
|
||||
|
||||
var lessonsFound = false
|
||||
day?.forEach { lessonRangeEl ->
|
||||
val lessonRange = lessonRangeEl?.asJsonArray?.asJsonObjectList()
|
||||
if (lessonRange?.isNullOrEmpty() == false)
|
||||
lessonsFound = true
|
||||
lessonRange?.forEachIndexed { index, lesson ->
|
||||
parseLesson(lessonDate, lesson)
|
||||
}
|
||||
}
|
||||
|
||||
if (day.isNullOrEmpty() || !lessonsFound) {
|
||||
data.lessonNewList += Lesson(profileId, lessonDate.value.toLong()).apply {
|
||||
type = Lesson.TYPE_NO_LESSONS
|
||||
date = lessonDate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val weekStart = Date.fromY_m_d(getDate)
|
||||
val weekEnd = weekStart.clone().stepForward(0, 0, 6)
|
||||
d(TAG, "Clearing lessons between ${weekStart.stringY_m_d} and ${weekEnd.stringY_m_d} - timetable downloaded for $getDate")
|
||||
|
||||
data.toRemove.add(DataRemoveModel.Timetable.between(weekStart, weekEnd))
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_TIMETABLES, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseLesson(lessonDate: Date, lesson: JsonObject) {
|
||||
val isSubstitution = lesson.getBoolean("IsSubstitutionClass") ?: false
|
||||
val isCancelled = lesson.getBoolean("IsCanceled") ?: false
|
||||
|
||||
val lessonNo = lesson.getInt("LessonNo") ?: return
|
||||
val startTime = lesson.getString("HourFrom")?.let { Time.fromH_m(it) } ?: return
|
||||
val endTime = lesson.getString("HourTo")?.let { Time.fromH_m(it) } ?: return
|
||||
val subjectId = lesson.getJsonObject("Subject")?.getLong("Id")
|
||||
val teacherId = lesson.getJsonObject("Teacher")?.getLong("Id")
|
||||
val classroomId = lesson.getJsonObject("Classroom")?.getLong("Id") ?: -1
|
||||
val virtualClassId = lesson.getJsonObject("VirtualClass")?.getLong("Id")
|
||||
val teamId = lesson.getJsonObject("Class")?.getLong("Id") ?: virtualClassId
|
||||
|
||||
val id = lessonDate.combineWith(startTime) / 6L * 10L + (lesson.hashCode() and 0xFFFF)
|
||||
val lessonObject = Lesson(profileId, id)
|
||||
|
||||
if (isSubstitution && isCancelled) {
|
||||
// shifted lesson - source
|
||||
val newDate = lesson.getString("NewDate")?.let { Date.fromY_m_d(it) } ?: return
|
||||
val newLessonNo = lesson.getInt("NewLessonNo") ?: return
|
||||
val newStartTime = lesson.getString("NewHourFrom")?.let { Time.fromH_m(it) } ?: return
|
||||
val newEndTime = lesson.getString("NewHourTo")?.let { Time.fromH_m(it) } ?: return
|
||||
val newSubjectId = lesson.getJsonObject("NewSubject")?.getLong("Id")
|
||||
val newTeacherId = lesson.getJsonObject("NewTeacher")?.getLong("Id")
|
||||
val newClassroomId = lesson.getJsonObject("NewClassroom")?.getLong("Id") ?: -1
|
||||
val newVirtualClassId = lesson.getJsonObject("NewVirtualClass")?.getLong("Id")
|
||||
val newTeamId = lesson.getJsonObject("NewClass")?.getLong("Id") ?: newVirtualClassId
|
||||
|
||||
lessonObject.let {
|
||||
it.type = Lesson.TYPE_SHIFTED_SOURCE
|
||||
it.oldDate = lessonDate
|
||||
it.oldLessonNumber = lessonNo
|
||||
it.oldStartTime = startTime
|
||||
it.oldEndTime = endTime
|
||||
it.oldSubjectId = subjectId
|
||||
it.oldTeacherId = teacherId
|
||||
it.oldTeamId = teamId
|
||||
it.oldClassroom = data.classrooms[classroomId]?.name
|
||||
|
||||
it.date = newDate
|
||||
it.lessonNumber = newLessonNo
|
||||
it.startTime = newStartTime
|
||||
it.endTime = newEndTime
|
||||
it.subjectId = newSubjectId
|
||||
it.teacherId = newTeacherId
|
||||
it.teamId = newTeamId
|
||||
it.classroom = data.classrooms[newClassroomId]?.name
|
||||
}
|
||||
}
|
||||
else if (isSubstitution) {
|
||||
// lesson change OR shifted lesson - target
|
||||
val oldDate = lesson.getString("OrgDate")?.let { Date.fromY_m_d(it) } ?: return
|
||||
val oldLessonNo = lesson.getInt("OrgLessonNo") ?: return
|
||||
val oldStartTime = lesson.getString("OrgHourFrom")?.let { Time.fromH_m(it) } ?: return
|
||||
val oldEndTime = lesson.getString("OrgHourTo")?.let { Time.fromH_m(it) } ?: return
|
||||
val oldSubjectId = lesson.getJsonObject("OrgSubject")?.getLong("Id")
|
||||
val oldTeacherId = lesson.getJsonObject("OrgTeacher")?.getLong("Id")
|
||||
val oldClassroomId = lesson.getJsonObject("OrgClassroom")?.getLong("Id") ?: -1
|
||||
val oldVirtualClassId = lesson.getJsonObject("OrgVirtualClass")?.getLong("Id")
|
||||
val oldTeamId = lesson.getJsonObject("OrgClass")?.getLong("Id") ?: oldVirtualClassId
|
||||
|
||||
lessonObject.let {
|
||||
it.type = if (lessonDate == oldDate && lessonNo == oldLessonNo) Lesson.TYPE_CHANGE else Lesson.TYPE_SHIFTED_TARGET
|
||||
it.oldDate = oldDate
|
||||
it.oldLessonNumber = oldLessonNo
|
||||
it.oldStartTime = oldStartTime
|
||||
it.oldEndTime = oldEndTime
|
||||
it.oldSubjectId = oldSubjectId
|
||||
it.oldTeacherId = oldTeacherId
|
||||
it.oldTeamId = oldTeamId
|
||||
it.oldClassroom = data.classrooms[oldClassroomId]?.name
|
||||
|
||||
it.date = lessonDate
|
||||
it.lessonNumber = lessonNo
|
||||
it.startTime = startTime
|
||||
it.endTime = endTime
|
||||
it.subjectId = subjectId
|
||||
it.teacherId = teacherId
|
||||
it.teamId = teamId
|
||||
it.classroom = data.classrooms[classroomId]?.name
|
||||
}
|
||||
}
|
||||
else if (isCancelled) {
|
||||
lessonObject.let {
|
||||
it.type = Lesson.TYPE_CANCELLED
|
||||
it.oldDate = lessonDate
|
||||
it.oldLessonNumber = lessonNo
|
||||
it.oldStartTime = startTime
|
||||
it.oldEndTime = endTime
|
||||
it.oldSubjectId = subjectId
|
||||
it.oldTeacherId = teacherId
|
||||
it.oldTeamId = teamId
|
||||
it.oldClassroom = data.classrooms[classroomId]?.name
|
||||
}
|
||||
}
|
||||
else {
|
||||
lessonObject.let {
|
||||
it.type = Lesson.TYPE_NORMAL
|
||||
it.date = lessonDate
|
||||
it.lessonNumber = lessonNo
|
||||
it.startTime = startTime
|
||||
it.endTime = endTime
|
||||
it.subjectId = subjectId
|
||||
it.teacherId = teacherId
|
||||
it.teamId = teamId
|
||||
it.classroom = data.classrooms[classroomId]?.name
|
||||
}
|
||||
}
|
||||
|
||||
if (lessonObject.type != Lesson.TYPE_NORMAL) {
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
data.profileId,
|
||||
Metadata.TYPE_LESSON_CHANGE,
|
||||
lessonObject.id,
|
||||
data.profile?.empty ?: false,
|
||||
data.profile?.empty ?: false,
|
||||
System.currentTimeMillis()
|
||||
))
|
||||
}
|
||||
data.lessonNewList.add(lessonObject)
|
||||
}
|
||||
}
|
@ -22,8 +22,8 @@ class LibrusApiUsers(override val data: DataLibrus,
|
||||
|
||||
users?.forEach { user ->
|
||||
val id = user.getLong("Id") ?: return@forEach
|
||||
val firstName = user.getString("FirstName")?.fixWhiteSpaces() ?: ""
|
||||
val lastName = user.getString("LastName")?.fixWhiteSpaces() ?: ""
|
||||
val firstName = user.getString("FirstName")?.fixName() ?: ""
|
||||
val lastName = user.getString("LastName")?.fixName() ?: ""
|
||||
|
||||
data.teacherList.put(id, Teacher(profileId, id, firstName, lastName))
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ class LibrusMessagesGetList(override val data: DataLibrus, private val type: Int
|
||||
id
|
||||
)
|
||||
|
||||
data.messageList.add(messageObject)
|
||||
data.messageIgnoreList.add(messageObject)
|
||||
data.messageRecipientList.add(messageRecipientObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
|
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-11
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.messages
|
||||
|
||||
import android.util.Base64
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import pl.szczodrzynski.edziennik.api.v2.events.MessageGetEvent
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusMessages
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_SENT
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageRecipientFull
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.fixName
|
||||
import pl.szczodrzynski.edziennik.singleOrNull
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import java.nio.charset.Charset
|
||||
|
||||
class LibrusMessagesGetMessage(
|
||||
override val data: DataLibrus,
|
||||
private val messageObject: MessageFull,
|
||||
val onSuccess: () -> Unit
|
||||
) : LibrusMessages(data) {
|
||||
companion object {
|
||||
const val TAG = "LibrusMessagesGetMessage"
|
||||
}
|
||||
|
||||
init { data.profile?.also { profile ->
|
||||
messagesGet(TAG, "GetMessage", parameters = mapOf(
|
||||
"messageId" to messageObject.id,
|
||||
"archive" to 0
|
||||
)) { doc ->
|
||||
val message = doc.select("response GetMessage data").first()
|
||||
|
||||
val body = Base64.decode(message.select("Message").text(), Base64.DEFAULT)
|
||||
.toString(Charset.defaultCharset())
|
||||
.replace("\n", "<br>")
|
||||
.replace("<!\\[CDATA\\[", "")
|
||||
.replace("]]>", "")
|
||||
|
||||
messageObject.apply {
|
||||
this.body = body
|
||||
|
||||
clearAttachments()
|
||||
message.select("attachments ArrayItem").forEach {
|
||||
val attachmentId = it.select("id").text().toLong()
|
||||
val attachmentName = it.select("filename").text()
|
||||
addAttachment(attachmentId, attachmentName, -1)
|
||||
}
|
||||
}
|
||||
|
||||
val messageRecipientList = mutableListOf<MessageRecipientFull>()
|
||||
|
||||
when (messageObject.type) {
|
||||
TYPE_RECEIVED -> {
|
||||
val senderLoginId = message.select("senderId").text()
|
||||
data.teacherList.singleOrNull { it.id == messageObject.senderId }?.loginId = senderLoginId
|
||||
|
||||
val readDateText = message.select("readDate").text()
|
||||
val readDate = when (readDateText.isNotEmpty()) {
|
||||
true -> Date.fromIso(readDateText)
|
||||
else -> 0
|
||||
}
|
||||
|
||||
val messageRecipientObject = MessageRecipientFull(
|
||||
profileId,
|
||||
-1,
|
||||
-1,
|
||||
readDate,
|
||||
messageObject.id
|
||||
)
|
||||
|
||||
messageRecipientObject.fullName = profile.accountNameLong ?: profile.studentNameLong
|
||||
|
||||
messageRecipientList.add(messageRecipientObject)
|
||||
}
|
||||
|
||||
TYPE_SENT -> {
|
||||
|
||||
message.select("receivers ArrayItem").forEach { receiver ->
|
||||
val receiverFirstName = receiver.select("firstName").text().fixName()
|
||||
val receiverLastName = receiver.select("lastName").text().fixName()
|
||||
val receiverLoginId = receiver.select("receiverId").text()
|
||||
|
||||
val teacher = data.teacherList.singleOrNull { it.name == receiverFirstName && it.surname == receiverLastName }
|
||||
val receiverId = teacher?.id ?: -1
|
||||
teacher?.loginId = receiverLoginId
|
||||
|
||||
val readDateText = message.select("readed").text()
|
||||
val readDate = when (readDateText.isNotEmpty()) {
|
||||
true -> Date.fromIso(readDateText)
|
||||
else -> 0
|
||||
}
|
||||
|
||||
val messageRecipientObject = MessageRecipientFull(
|
||||
profileId,
|
||||
receiverId,
|
||||
-1,
|
||||
readDate,
|
||||
messageObject.id
|
||||
)
|
||||
|
||||
messageRecipientObject.fullName = "$receiverFirstName $receiverLastName"
|
||||
|
||||
messageRecipientList.add(messageRecipientObject)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!messageObject.seen) {
|
||||
data.messageMetadataList.add(Metadata(
|
||||
messageObject.profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
messageObject.id,
|
||||
true,
|
||||
true,
|
||||
messageObject.addedDate
|
||||
))
|
||||
}
|
||||
|
||||
messageObject.recipients = messageRecipientList
|
||||
data.messageRecipientList.addAll(messageRecipientList)
|
||||
data.messageList.add(messageObject)
|
||||
|
||||
EventBus.getDefault().postSticky(MessageGetEvent(messageObject))
|
||||
onSuccess()
|
||||
}
|
||||
} ?: onSuccess()}
|
||||
}
|
@ -3,6 +3,7 @@ package pl.szczodrzynski.edziennik.api.v2.librus.firstlogin
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.ERROR_NO_STUDENTS_IN_ACCOUNT
|
||||
import pl.szczodrzynski.edziennik.api.v2.FAKE_LIBRUS_ACCOUNTS
|
||||
import pl.szczodrzynski.edziennik.api.v2.LIBRUS_ACCOUNTS_URL
|
||||
import pl.szczodrzynski.edziennik.api.v2.LOGIN_MODE_LIBRUS_EMAIL
|
||||
import pl.szczodrzynski.edziennik.api.v2.events.FirstLoginFinishedEvent
|
||||
@ -29,7 +30,7 @@ class LibrusFirstLogin(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
if (data.loginStore.mode == LOGIN_MODE_LIBRUS_EMAIL) {
|
||||
// email login: use Portal for account list
|
||||
LibrusLoginPortal(data) {
|
||||
portal.portalGet(TAG, LIBRUS_ACCOUNTS_URL) { json, response ->
|
||||
portal.portalGet(TAG, if (data.fakeLogin) FAKE_LIBRUS_ACCOUNTS else LIBRUS_ACCOUNTS_URL) { json, response ->
|
||||
val accounts = json.getJsonArray("accounts")
|
||||
|
||||
if (accounts == null || accounts.size() < 1) {
|
||||
|
@ -7,14 +7,15 @@ import im.wangchao.mhttp.Response
|
||||
import im.wangchao.mhttp.body.MediaTypeUtils
|
||||
import im.wangchao.mhttp.callback.JsonCallbackHandler
|
||||
import im.wangchao.mhttp.callback.TextCallbackHandler
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import pl.szczodrzynski.edziennik.getInt
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.getUnixDate
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
import java.net.HttpURLConnection.HTTP_UNAUTHORIZED
|
||||
import java.util.ArrayList
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class LibrusLoginPortal(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
@ -42,7 +43,7 @@ class LibrusLoginPortal(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
}
|
||||
else {
|
||||
data.app.cookieJar.clearForDomain("portal.librus.pl")
|
||||
authorize(LIBRUS_AUTHORIZE_URL)
|
||||
authorize(if (data.fakeLogin) FAKE_LIBRUS_AUTHORIZE else LIBRUS_AUTHORIZE_URL)
|
||||
}
|
||||
}}
|
||||
|
||||
@ -86,10 +87,10 @@ class LibrusLoginPortal(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
}
|
||||
|
||||
private fun login(csrfToken: String) {
|
||||
d(TAG, "Request: Librus/Login/Portal - $LIBRUS_LOGIN_URL")
|
||||
d(TAG, "Request: Librus/Login/Portal - ${if (data.fakeLogin) FAKE_LIBRUS_LOGIN else LIBRUS_LOGIN_URL}")
|
||||
|
||||
Request.builder()
|
||||
.url(LIBRUS_LOGIN_URL)
|
||||
.url(if (data.fakeLogin) FAKE_LIBRUS_LOGIN else LIBRUS_LOGIN_URL)
|
||||
.userAgent(LIBRUS_USER_AGENT)
|
||||
.addParameter("email", data.portalEmail)
|
||||
.addParameter("password", data.portalPassword)
|
||||
@ -135,7 +136,7 @@ class LibrusLoginPortal(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
|
||||
private var refreshTokenFailed = false
|
||||
private fun accessToken(code: String?, refreshToken: String?) {
|
||||
d(TAG, "Request: Librus/Login/Portal - $LIBRUS_TOKEN_URL")
|
||||
d(TAG, "Request: Librus/Login/Portal - ${if (data.fakeLogin) FAKE_LIBRUS_TOKEN else LIBRUS_TOKEN_URL}")
|
||||
|
||||
val onSuccess = { json: JsonObject, response: Response? ->
|
||||
data.portalAccessToken = json.getString("access_token")
|
||||
@ -204,7 +205,7 @@ class LibrusLoginPortal(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
}
|
||||
|
||||
Request.builder()
|
||||
.url(LIBRUS_TOKEN_URL)
|
||||
.url(if (data.fakeLogin) FAKE_LIBRUS_TOKEN else LIBRUS_TOKEN_URL)
|
||||
.userAgent(LIBRUS_USER_AGENT)
|
||||
.addParams(params)
|
||||
.post()
|
||||
|
@ -43,7 +43,7 @@ class SynergiaTokenExtractor(override val data: DataLibrus, val onSuccess: () ->
|
||||
val accountLogin = data.apiLogin ?: return false
|
||||
data.portalAccessToken ?: return false
|
||||
|
||||
d(TAG, "Request: Librus/SynergiaTokenExtractor - $LIBRUS_ACCOUNT_URL$accountLogin")
|
||||
d(TAG, "Request: Librus/SynergiaTokenExtractor - ${if (data.fakeLogin) FAKE_LIBRUS_ACCOUNT else LIBRUS_ACCOUNT_URL}$accountLogin")
|
||||
|
||||
val onSuccess = { json: JsonObject, response: Response? ->
|
||||
// synergiaAccount is executed when a synergia token needs a refresh
|
||||
@ -67,7 +67,7 @@ class SynergiaTokenExtractor(override val data: DataLibrus, val onSuccess: () ->
|
||||
}
|
||||
}
|
||||
|
||||
portalGet(TAG, LIBRUS_ACCOUNT_URL+accountLogin, onSuccess = onSuccess)
|
||||
portalGet(TAG, (if (data.fakeLogin) FAKE_LIBRUS_ACCOUNT else LIBRUS_ACCOUNT_URL)+accountLogin, onSuccess = onSuccess)
|
||||
return true
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.mobidziennik
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.api.v2.CODE_INTERNAL_LIBRUS_ACCOUNT_410
|
||||
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback
|
||||
@ -15,6 +16,7 @@ import pl.szczodrzynski.edziennik.api.v2.mobidziennikLoginMethods
|
||||
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.api.v2.prepare
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
|
||||
@ -48,7 +50,8 @@ class Mobidziennik(val app: App, val profile: Profile?, val loginStore: LoginSto
|
||||
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
||||
__/ |
|
||||
|__*/
|
||||
override fun sync(featureIds: List<Int>, viewId: Int?) {
|
||||
override fun sync(featureIds: List<Int>, viewId: Int?, arguments: JsonObject?) {
|
||||
data.arguments = arguments
|
||||
data.prepare(mobidziennikLoginMethods, MobidziennikFeatures, featureIds, viewId)
|
||||
d(TAG, "LoginMethod IDs: ${data.targetLoginMethodIds}")
|
||||
d(TAG, "Endpoint IDs: ${data.targetEndpointIds}")
|
||||
@ -59,7 +62,7 @@ class Mobidziennik(val app: App, val profile: Profile?, val loginStore: LoginSto
|
||||
}
|
||||
}
|
||||
|
||||
override fun getMessage(messageId: Int) {
|
||||
override fun getMessage(message: MessageFull) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,10 @@ const val ENDPOINT_MOBIDZIENNIK_API2_MAIN = 3000
|
||||
|
||||
val MobidziennikFeatures = listOf(
|
||||
// always synced
|
||||
/*Feature(LOGIN_TYPE_MOBIDZIENNIK, FEATURE_ALWAYS_NEEDED, listOf(
|
||||
Feature(LOGIN_TYPE_MOBIDZIENNIK, FEATURE_ALWAYS_NEEDED, listOf(
|
||||
ENDPOINT_MOBIDZIENNIK_API_MAIN to LOGIN_METHOD_MOBIDZIENNIK_WEB,
|
||||
ENDPOINT_MOBIDZIENNIK_WEB_ACCOUNT_EMAIL to LOGIN_METHOD_MOBIDZIENNIK_WEB
|
||||
), listOf(LOGIN_METHOD_MOBIDZIENNIK_WEB)),*/
|
||||
), listOf(LOGIN_METHOD_MOBIDZIENNIK_WEB)), // TODO divide features into separate view IDs (all with API_MAIN)
|
||||
|
||||
// push config
|
||||
/*Feature(LOGIN_TYPE_MOBIDZIENNIK, FEATURE_PUSH_CONFIG, listOf(
|
||||
|
@ -42,7 +42,7 @@ class MobidziennikData(val data: DataMobidziennik, val onSuccess: () -> Unit) {
|
||||
when (endpointId) {
|
||||
ENDPOINT_MOBIDZIENNIK_API_MAIN -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_data)
|
||||
MobidziennikApi(data) { onSuccess() }
|
||||
MobidziennikApi(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_MOBIDZIENNIK_WEB_MESSAGES_INBOX -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_inbox)
|
||||
@ -75,4 +75,4 @@ class MobidziennikData(val data: DataMobidziennik, val onSuccess: () -> Unit) {
|
||||
else -> onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,102 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.App.profileId
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.Lesson
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange
|
||||
import pl.szczodrzynski.edziennik.api.v2.models.DataRemoveModel
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
|
||||
import pl.szczodrzynski.edziennik.fixName
|
||||
import pl.szczodrzynski.edziennik.singleOrNull
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
|
||||
class MobidziennikApiTimetable(val data: DataMobidziennik, rows: List<String>) {
|
||||
init {
|
||||
for (lessonStr in rows) {
|
||||
val lessons = rows.filterNot { it.isEmpty() }.map { it.split("|") }
|
||||
|
||||
val dataStart = Date.getToday()
|
||||
val dataEnd = dataStart.clone().stepForward(0, 0, 7 + (6 - dataStart.weekDay))
|
||||
|
||||
data.toRemove.add(DataRemoveModel.Timetable.between(dataStart.clone(), dataEnd))
|
||||
|
||||
val dataDays = mutableListOf<Int>()
|
||||
while (dataStart <= dataEnd) {
|
||||
dataDays += dataStart.value
|
||||
dataStart.stepForward(0, 0, 1)
|
||||
}
|
||||
|
||||
for (lesson in lessons) {
|
||||
val date = Date.fromYmd(lesson[2])
|
||||
val startTime = Time.fromYmdHm(lesson[3])
|
||||
val endTime = Time.fromYmdHm(lesson[4])
|
||||
val id = date.combineWith(startTime) / 6L * 10L + (lesson.joinToString("|").hashCode() and 0xFFFF)
|
||||
|
||||
dataDays.remove(date.value)
|
||||
|
||||
val subjectId = data.subjectList.singleOrNull { it.longName == lesson[5] }?.id ?: -1
|
||||
val teacherId = data.teacherList.singleOrNull { it.fullNameLastFirst == (lesson[7]+" "+lesson[6]).fixName() }?.id ?: -1
|
||||
val teamId = data.teamList.singleOrNull { it.name == lesson[8]+lesson[9] }?.id ?: -1
|
||||
val classroom = lesson[11]
|
||||
|
||||
Lesson(data.profileId, id).also {
|
||||
when (lesson[1]) {
|
||||
"plan_lekcji", "lekcja" -> {
|
||||
it.type = Lesson.TYPE_NORMAL
|
||||
it.date = date
|
||||
it.startTime = startTime
|
||||
it.endTime = endTime
|
||||
it.subjectId = subjectId
|
||||
it.teacherId = teacherId
|
||||
it.teamId = teamId
|
||||
it.classroom = classroom
|
||||
}
|
||||
"lekcja_odwolana" -> {
|
||||
it.type = Lesson.TYPE_CANCELLED
|
||||
it.date = date
|
||||
it.startTime = startTime
|
||||
it.endTime = endTime
|
||||
it.oldSubjectId = subjectId
|
||||
//it.oldTeacherId = teacherId
|
||||
it.oldTeamId = teamId
|
||||
//it.oldClassroom = classroom
|
||||
}
|
||||
"zastepstwo" -> {
|
||||
it.type = Lesson.TYPE_CHANGE
|
||||
it.date = date
|
||||
it.startTime = startTime
|
||||
it.endTime = endTime
|
||||
it.subjectId = subjectId
|
||||
it.teacherId = teacherId
|
||||
it.teamId = teamId
|
||||
it.classroom = classroom
|
||||
}
|
||||
}
|
||||
|
||||
if (it.type != Lesson.TYPE_NORMAL) {
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
data.profileId,
|
||||
Metadata.TYPE_LESSON_CHANGE,
|
||||
it.id,
|
||||
data.profile?.empty ?: false,
|
||||
data.profile?.empty ?: false,
|
||||
System.currentTimeMillis()
|
||||
))
|
||||
}
|
||||
data.lessonNewList += it
|
||||
}
|
||||
}
|
||||
|
||||
for (day in dataDays) {
|
||||
val lessonDate = Date.fromValue(day)
|
||||
data.lessonNewList += Lesson(profileId, lessonDate.value.toLong()).apply {
|
||||
type = Lesson.TYPE_NO_LESSONS
|
||||
date = lessonDate
|
||||
}
|
||||
}
|
||||
|
||||
/*for (lessonStr in rows) {
|
||||
if (lessonStr.isNotEmpty()) {
|
||||
val lesson = lessonStr.split("|")
|
||||
|
||||
@ -76,9 +162,9 @@ class MobidziennikApiTimetable(val data: DataMobidziennik, rows: List<String>) {
|
||||
if (originalLesson == null) {
|
||||
// original lesson doesn't exist, save a new addition
|
||||
// TODO
|
||||
/*if (!RegisterLessonChange.existsAddition(app.profile, registerLessonChange)) {
|
||||
*//*if (!RegisterLessonChange.existsAddition(app.profile, registerLessonChange)) {
|
||||
app.profile.timetable.addLessonAddition(registerLessonChange);
|
||||
}*/
|
||||
}*//*
|
||||
} else {
|
||||
// original lesson exists, so we need to compare them
|
||||
if (!lessonChange.matches(originalLesson)) {
|
||||
@ -108,6 +194,6 @@ class MobidziennikApiTimetable(val data: DataMobidziennik, rows: List<String>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
@ -8,9 +8,7 @@ import org.jsoup.Jsoup
|
||||
import pl.szczodrzynski.edziennik.DAY
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.ENDPOINT_MOBIDZIENNIK_WEB_MESSAGES_ALL
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.ENDPOINT_MOBIDZIENNIK_WEB_MESSAGES_INBOX
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.MobidziennikWeb
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_SENT
|
||||
@ -79,7 +77,7 @@ class MobidziennikWebMessagesAll(override val data: DataMobidziennik,
|
||||
-1
|
||||
)
|
||||
|
||||
data.messageList.add(message)
|
||||
data.messageIgnoreList.add(message)
|
||||
data.metadataList.add(Metadata(profileId, Metadata.TYPE_MESSAGE, message.id, true, true, addedDate))
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ class MobidziennikWebMessagesInbox(override val data: DataMobidziennik,
|
||||
if (hasAttachments)
|
||||
message.setHasAttachments()
|
||||
|
||||
data.messageList.add(message)
|
||||
data.messageIgnoreList.add(message)
|
||||
data.messageMetadataList.add(
|
||||
Metadata(
|
||||
profileId,
|
||||
|
@ -60,6 +60,8 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
val profileId
|
||||
get() = profile?.id ?: -1
|
||||
|
||||
var arguments: JsonObject? = null
|
||||
|
||||
/**
|
||||
* A callback passed to all [Feature]s and [LoginMethod]s
|
||||
*/
|
||||
@ -133,23 +135,20 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
mTeamClass = value
|
||||
}
|
||||
|
||||
var lessonsToRemove: DataRemoveModel? = null
|
||||
var toRemove = mutableListOf<DataRemoveModel>()
|
||||
|
||||
val lessonList = mutableListOf<Lesson>()
|
||||
val lessonChangeList = mutableListOf<LessonChange>()
|
||||
val lessonNewList = mutableListOf<pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson>()
|
||||
|
||||
var gradesToRemove: DataRemoveModel? = null
|
||||
val gradeList = mutableListOf<Grade>()
|
||||
|
||||
var eventsToRemove: DataRemoveModel? = null
|
||||
val eventList = mutableListOf<Event>()
|
||||
|
||||
var noticesToRemove: DataRemoveModel? = null
|
||||
val noticeList = mutableListOf<Notice>()
|
||||
|
||||
var attendancesToRemove: DataRemoveModel? = null
|
||||
val attendanceList = mutableListOf<Attendance>()
|
||||
|
||||
var announcementsToRemove: DataRemoveModel? = null
|
||||
val announcementList = mutableListOf<Announcement>()
|
||||
|
||||
val luckyNumberList = mutableListOf<LuckyNumber>()
|
||||
@ -157,6 +156,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
val teacherAbsenceList = mutableListOf<TeacherAbsence>()
|
||||
|
||||
val messageList = mutableListOf<Message>()
|
||||
val messageIgnoreList = mutableListOf<Message>()
|
||||
val messageRecipientList = mutableListOf<MessageRecipient>()
|
||||
val messageRecipientIgnoreList = mutableListOf<MessageRecipient>()
|
||||
|
||||
@ -166,6 +166,9 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
val db: AppDb by lazy { app.db }
|
||||
|
||||
init {
|
||||
if (App.devMode) {
|
||||
fakeLogin = loginStore.hasLoginData("fakeLogin")
|
||||
}
|
||||
clear()
|
||||
if (profile != null) {
|
||||
endpointTimers = db.endpointTimerDao().getAllNow(profile.id).toMutableList()
|
||||
@ -180,6 +183,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
fun clear() {
|
||||
loginMethods.clear()
|
||||
|
||||
toRemove.clear()
|
||||
endpointTimers.clear()
|
||||
teacherList.clear()
|
||||
subjectList.clear()
|
||||
@ -195,13 +199,14 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
|
||||
lessonList.clear()
|
||||
lessonChangeList.clear()
|
||||
lessonNewList.clear()
|
||||
gradeList.clear()
|
||||
noticeList.clear()
|
||||
attendanceList.clear()
|
||||
announcementList.clear()
|
||||
luckyNumberList.clear()
|
||||
teacherAbsenceList.clear()
|
||||
messageList.clear()
|
||||
messageIgnoreList.clear()
|
||||
messageRecipientList.clear()
|
||||
messageRecipientIgnoreList.clear()
|
||||
metadataList.clear()
|
||||
@ -248,6 +253,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
app.profile.loginStoreData = loginStore.data
|
||||
}
|
||||
|
||||
// always present and not empty, during every sync
|
||||
db.endpointTimerDao().addAll(endpointTimers)
|
||||
db.teacherDao().clear(profileId)
|
||||
db.teacherDao().addAll(teacherList.values())
|
||||
@ -260,6 +266,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
db.gradeCategoryDao().clear(profileId)
|
||||
db.gradeCategoryDao().addAll(gradeCategories.values())
|
||||
|
||||
// may be empty - extracted from DB on demand, by an endpoint
|
||||
if (classrooms.size > 0)
|
||||
db.classroomDao().addAll(classrooms.values())
|
||||
if (attendanceTypes.size > 0)
|
||||
@ -271,17 +278,29 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
if (teacherAbsenceTypes.size > 0)
|
||||
db.teacherAbsenceTypeDao().addAll(teacherAbsenceTypes.values())
|
||||
|
||||
gradesToRemove?.let { it ->
|
||||
it.removeAll?.let { _ -> db.gradeDao().clear(profileId) }
|
||||
it.removeSemester?.let { semester -> db.gradeDao().clearForSemester(profileId, semester) }
|
||||
// clear DB with DataRemoveModels added by endpoints
|
||||
for (model in toRemove) {
|
||||
when (model) {
|
||||
is DataRemoveModel.Timetable -> model.commit(profileId, db.timetableDao())
|
||||
is DataRemoveModel.Grades -> model.commit(profileId, db.gradeDao())
|
||||
}
|
||||
}
|
||||
|
||||
if (metadataList.isNotEmpty())
|
||||
db.metadataDao().addAllIgnore(metadataList)
|
||||
if (messageMetadataList.isNotEmpty())
|
||||
db.metadataDao().setSeen(messageMetadataList)
|
||||
|
||||
// not extracted from DB - always new data
|
||||
if (lessonList.isNotEmpty()) {
|
||||
db.lessonDao().clear(profile.id)
|
||||
db.lessonDao().addAll(lessonList)
|
||||
}
|
||||
if (lessonChangeList.isNotEmpty())
|
||||
db.lessonChangeDao().addAll(lessonChangeList)
|
||||
if (lessonNewList.isNotEmpty()) {
|
||||
db.timetableDao() += lessonNewList
|
||||
}
|
||||
if (gradeList.isNotEmpty()) {
|
||||
db.gradeDao().addAll(gradeList)
|
||||
}
|
||||
@ -303,15 +322,13 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
db.teacherAbsenceDao().addAll(teacherAbsenceList)
|
||||
|
||||
if (messageList.isNotEmpty())
|
||||
db.messageDao().addAllIgnore(messageList)
|
||||
db.messageDao().addAll(messageList)
|
||||
if (messageIgnoreList.isNotEmpty())
|
||||
db.messageDao().addAllIgnore(messageIgnoreList)
|
||||
if (messageRecipientList.isNotEmpty())
|
||||
db.messageRecipientDao().addAll(messageRecipientList)
|
||||
if (messageRecipientIgnoreList.isNotEmpty())
|
||||
db.messageRecipientDao().addAllIgnore(messageRecipientIgnoreList)
|
||||
if (metadataList.isNotEmpty())
|
||||
db.metadataDao().addAllIgnore(metadataList)
|
||||
if (messageMetadataList.isNotEmpty())
|
||||
db.metadataDao().setSeen(messageMetadataList)
|
||||
}
|
||||
|
||||
fun notifyAndSyncEvents(onSuccess: () -> Unit) {
|
||||
@ -390,8 +407,6 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
|
||||
}
|
||||
|
||||
fun error(apiError: ApiError) {
|
||||
if (apiError.isCritical)
|
||||
cancel()
|
||||
callback.onError(apiError)
|
||||
}
|
||||
|
||||
|
@ -4,28 +4,37 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.models
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeDao
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.TimetableDao
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class DataRemoveModel {
|
||||
var removeAll: Boolean? = null
|
||||
var removeSemester: Int? = null
|
||||
var removeDateFrom: Date? = null
|
||||
var removeDateTo: Date? = null
|
||||
|
||||
constructor() {
|
||||
this.removeAll = true
|
||||
open class DataRemoveModel {
|
||||
class Timetable(private val dateFrom: Date?, private val dateTo: Date?) : DataRemoveModel() {
|
||||
companion object {
|
||||
fun from(dateFrom: Date) = Timetable(dateFrom, null)
|
||||
fun to(dateTo: Date) = Timetable(null, dateTo)
|
||||
fun between(dateFrom: Date, dateTo: Date) = Timetable(dateFrom, dateTo)
|
||||
}
|
||||
fun commit(profileId: Int, dao: TimetableDao) {
|
||||
if (dateFrom != null && dateTo != null) {
|
||||
dao.clearBetweenDates(profileId, dateFrom, dateTo)
|
||||
}
|
||||
else {
|
||||
dateFrom?.let { dateFrom -> dao.clearFromDate(profileId, dateFrom) }
|
||||
dateTo?.let { dateTo -> dao.clearToDate(profileId, dateTo) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constructor(semester: Int) {
|
||||
this.removeSemester = semester
|
||||
}
|
||||
|
||||
constructor(dateFrom: Date?, dateTo: Date) {
|
||||
this.removeDateFrom = dateFrom
|
||||
this.removeDateTo = dateTo
|
||||
}
|
||||
|
||||
constructor(dateFrom: Date) {
|
||||
this.removeDateFrom = dateFrom
|
||||
class Grades(val all: Boolean, val semester: Int?) : DataRemoveModel() {
|
||||
companion object {
|
||||
fun all() = Grades(true, null)
|
||||
fun semester(semester: Int) = Grades(false, semester)
|
||||
}
|
||||
fun commit(profileId: Int, dao: GradeDao) {
|
||||
if (all) {
|
||||
dao.clear(profileId)
|
||||
}
|
||||
semester?.let { dao.clearForSemester(profileId, it) }
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.template
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.api.v2.CODE_INTERNAL_LIBRUS_ACCOUNT_410
|
||||
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback
|
||||
@ -15,6 +16,7 @@ import pl.szczodrzynski.edziennik.api.v2.template.firstlogin.TemplateFirstLogin
|
||||
import pl.szczodrzynski.edziennik.api.v2.template.login.TemplateLogin
|
||||
import pl.szczodrzynski.edziennik.api.v2.templateLoginMethods
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
|
||||
@ -48,7 +50,8 @@ class Template(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
||||
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
||||
__/ |
|
||||
|__*/
|
||||
override fun sync(featureIds: List<Int>, viewId: Int?) {
|
||||
override fun sync(featureIds: List<Int>, viewId: Int?, arguments: JsonObject?) {
|
||||
data.arguments = arguments
|
||||
data.prepare(templateLoginMethods, TemplateFeatures, featureIds, viewId)
|
||||
d(TAG, "LoginMethod IDs: ${data.targetLoginMethodIds}")
|
||||
d(TAG, "Endpoint IDs: ${data.targetEndpointIds}")
|
||||
@ -59,7 +62,7 @@ class Template(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
||||
}
|
||||
}
|
||||
|
||||
override fun getMessage(messageId: Int) {
|
||||
override fun getMessage(message: MessageFull) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.vulcan
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.api.v2.CODE_INTERNAL_LIBRUS_ACCOUNT_410
|
||||
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback
|
||||
@ -15,6 +16,7 @@ import pl.szczodrzynski.edziennik.api.v2.vulcan.firstlogin.VulcanFirstLogin
|
||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.login.VulcanLogin
|
||||
import pl.szczodrzynski.edziennik.api.v2.vulcanLoginMethods
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.d
|
||||
|
||||
@ -48,7 +50,8 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
||||
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
||||
__/ |
|
||||
|__*/
|
||||
override fun sync(featureIds: List<Int>, viewId: Int?) {
|
||||
override fun sync(featureIds: List<Int>, viewId: Int?, arguments: JsonObject?) {
|
||||
data.arguments = arguments
|
||||
data.prepare(vulcanLoginMethods, VulcanFeatures, featureIds, viewId)
|
||||
d(TAG, "LoginMethod IDs: ${data.targetLoginMethodIds}")
|
||||
d(TAG, "Endpoint IDs: ${data.targetEndpointIds}")
|
||||
@ -59,7 +62,7 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
||||
}
|
||||
}
|
||||
|
||||
override fun getMessage(messageId: Int) {
|
||||
override fun getMessage(message: MessageFull) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -38,35 +38,39 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
when (endpointId) {
|
||||
ENDPOINT_VULCAN_API_DICTIONARIES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_dictionaries)
|
||||
VulcanApiDictionaries(data) { onSuccess() }
|
||||
VulcanApiDictionaries(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_GRADES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||
VulcanApiGrades(data) { onSuccess() }
|
||||
VulcanApiGrades(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_GRADES_SUMMARY -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_proposed_grades)
|
||||
VulcanApiProposedGrades(data) { onSuccess() }
|
||||
VulcanApiProposedGrades(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_EVENTS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_events)
|
||||
VulcanApiEvents(data, isHomework = false) { onSuccess() }
|
||||
VulcanApiEvents(data, isHomework = false, onSuccess = onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_HOMEWORK -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_homework)
|
||||
VulcanApiEvents(data, isHomework = true) { onSuccess() }
|
||||
VulcanApiEvents(data, isHomework = true, onSuccess = onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_NOTICES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_notices)
|
||||
VulcanApiNotices(data) { onSuccess() }
|
||||
VulcanApiNotices(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_ATTENDANCE -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_attendance)
|
||||
VulcanApiAttendance(data) { onSuccess() }
|
||||
VulcanApiAttendance(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_MESSAGES_INBOX -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_inbox)
|
||||
VulcanApiMessagesInbox(data) { onSuccess() }
|
||||
VulcanApiMessagesInbox(data, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_API_MESSAGES_SENT -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_outbox)
|
||||
VulcanApiMessagesSent(data, onSuccess)
|
||||
}
|
||||
else -> onSuccess()
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_MESSAGES_INB
|
||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_RECEIVED
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageRecipient
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
@ -20,64 +21,68 @@ class VulcanApiMessagesInbox(override val data: DataVulcan, val onSuccess: () ->
|
||||
const val TAG = "VulcanApiMessagesInbox"
|
||||
}
|
||||
|
||||
init { data.profile?.also { profile ->
|
||||
init {
|
||||
data.profile?.also { profile ->
|
||||
|
||||
val startDate: String = when (profile.empty) {
|
||||
true -> profile.getSemesterStart(profile.currentSemester).stringY_m_d
|
||||
else -> Date.getToday().stepForward(0, -1, 0).stringY_m_d
|
||||
}
|
||||
val endDate: String = profile.getSemesterEnd(profile.currentSemester).stringY_m_d
|
||||
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_MESSAGES_RECEIVED, parameters = mapOf(
|
||||
"DataPoczatkowa" to startDate,
|
||||
"DataKoncowa" to endDate,
|
||||
"LoginId" to data.studentLoginId,
|
||||
"IdUczen" to data.studentId
|
||||
)) { json, _ ->
|
||||
json.getJsonArray("Data").asJsonObjectList()?.forEach { message ->
|
||||
val id = message.getLong("WiadomoscId") ?: return@forEach
|
||||
val subject = message.getString("Tytul") ?: ""
|
||||
val body = message.getString("Tresc") ?: ""
|
||||
|
||||
val senderLoginId = message.getString("NadawcaId") ?: return@forEach
|
||||
val senderId = data.teacherList
|
||||
.singleOrNull { it.loginId == senderLoginId }?.id ?: return@forEach
|
||||
|
||||
val addedDate = message.getLong("DataWyslaniaUnixEpoch")?.let { it * 1000 } ?: -1
|
||||
val readDate = message.getLong("DataPrzeczytaniaUnixEpoch")?.let { it * 1000 } ?: -1
|
||||
|
||||
val messageObject = Message(
|
||||
profileId,
|
||||
id,
|
||||
subject,
|
||||
body,
|
||||
Message.TYPE_RECEIVED,
|
||||
senderId,
|
||||
-1
|
||||
)
|
||||
|
||||
val messageRecipientObject = MessageRecipient(
|
||||
profileId,
|
||||
-1,
|
||||
-1,
|
||||
readDate,
|
||||
id
|
||||
)
|
||||
|
||||
data.messageList.add(messageObject)
|
||||
data.messageRecipientList.add(messageRecipientObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
id,
|
||||
readDate > 0,
|
||||
readDate > 0,
|
||||
addedDate
|
||||
))
|
||||
val startDate: String = when (profile.empty) {
|
||||
true -> profile.getSemesterStart(profile.currentSemester).stringY_m_d
|
||||
else -> Date.getToday().stepForward(0, -1, 0).stringY_m_d
|
||||
}
|
||||
val endDate: String = profile.getSemesterEnd(profile.currentSemester).stringY_m_d
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_MESSAGES_INBOX, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
} ?: onSuccess()}
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_MESSAGES_RECEIVED, parameters = mapOf(
|
||||
"DataPoczatkowa" to startDate,
|
||||
"DataKoncowa" to endDate,
|
||||
"LoginId" to data.studentLoginId,
|
||||
"IdUczen" to data.studentId
|
||||
)) { json, _ ->
|
||||
json.getJsonArray("Data").asJsonObjectList()?.forEach { message ->
|
||||
val id = message.getLong("WiadomoscId") ?: return@forEach
|
||||
val subject = message.getString("Tytul") ?: ""
|
||||
val body = message.getString("Tresc") ?: ""
|
||||
|
||||
val senderLoginId = message.getString("NadawcaId") ?: return@forEach
|
||||
val senderId = data.teacherList
|
||||
.singleOrNull { it.loginId == senderLoginId }?.id ?: return@forEach
|
||||
|
||||
val sentDate = message.getLong("DataWyslaniaUnixEpoch")?.let { it * 1000 }
|
||||
?: -1
|
||||
val readDate = message.getLong("DataPrzeczytaniaUnixEpoch")?.let { it * 1000 }
|
||||
?: -1
|
||||
|
||||
val messageObject = Message(
|
||||
profileId,
|
||||
id,
|
||||
subject,
|
||||
body,
|
||||
TYPE_RECEIVED,
|
||||
senderId,
|
||||
-1
|
||||
)
|
||||
|
||||
val messageRecipientObject = MessageRecipient(
|
||||
profileId,
|
||||
-1,
|
||||
-1,
|
||||
readDate,
|
||||
id
|
||||
)
|
||||
|
||||
data.messageIgnoreList.add(messageObject)
|
||||
data.messageRecipientList.add(messageRecipientObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
id,
|
||||
readDate > 0,
|
||||
readDate > 0,
|
||||
sentDate
|
||||
))
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_MESSAGES_INBOX, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
} ?: onSuccess()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-5
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.vulcan.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_MESSAGES
|
||||
import pl.szczodrzynski.edziennik.api.v2.VULCAN_API_ENDPOINT_MESSAGES_SENT
|
||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_MESSAGES_SENT
|
||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_SENT
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageRecipient
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class VulcanApiMessagesSent(override val data: DataVulcan, val onSuccess: () -> Unit) : VulcanApi(data) {
|
||||
companion object {
|
||||
const val TAG = "VulcanApiMessagesSent"
|
||||
}
|
||||
|
||||
init {
|
||||
data.profile?.also { profile ->
|
||||
val startDate: String = when (profile.empty) {
|
||||
true -> profile.getSemesterStart(profile.currentSemester).stringY_m_d
|
||||
else -> Date.getToday().stepForward(0, -1, 0).stringY_m_d
|
||||
}
|
||||
val endDate: String = profile.getSemesterEnd(profile.currentSemester).stringY_m_d
|
||||
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_MESSAGES_SENT, parameters = mapOf(
|
||||
"DataPoczatkowa" to startDate,
|
||||
"DataKoncowa" to endDate,
|
||||
"LoginId" to data.studentLoginId,
|
||||
"IdUczen" to data.studentId
|
||||
)) { json, _ ->
|
||||
json.getJsonArray("Data")?.asJsonObjectList()?.forEach { message ->
|
||||
val id = message.getLong("WiadomoscId") ?: return@forEach
|
||||
val subject = message.getString("Tytul") ?: ""
|
||||
val body = message.getString("Tresc") ?: ""
|
||||
val readBy = message.getInt("Przeczytane") ?: 0
|
||||
val unreadBy = message.getInt("Nieprzeczytane") ?: 0
|
||||
val sentDate = message.getLong("DataWyslaniaUnixEpoch")?.let { it * 1000 } ?: -1
|
||||
|
||||
val messageObject = Message(
|
||||
profileId,
|
||||
id,
|
||||
subject,
|
||||
body,
|
||||
TYPE_SENT,
|
||||
-1,
|
||||
-1
|
||||
)
|
||||
|
||||
message.getJsonArray("Adresaci")?.asJsonObjectList()
|
||||
?.forEachIndexed { _, recipient ->
|
||||
|
||||
val recipientLoginId = recipient.getString("LoginId")
|
||||
?: return@forEachIndexed
|
||||
val recipientId = data.teacherList.singleOrNull { it.loginId == recipientLoginId }?.id
|
||||
?: return@forEachIndexed
|
||||
|
||||
val readDate: Long = when (readBy) {
|
||||
0 -> 0
|
||||
else -> when (unreadBy) {
|
||||
0 -> 1
|
||||
else -> -1
|
||||
}
|
||||
}
|
||||
|
||||
val messageRecipientObject = MessageRecipient(
|
||||
profileId,
|
||||
recipientId,
|
||||
-1,
|
||||
readDate,
|
||||
id
|
||||
)
|
||||
|
||||
data.messageRecipientList.add(messageRecipientObject)
|
||||
}
|
||||
|
||||
data.messageIgnoreList.add(messageObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_MESSAGE,
|
||||
id,
|
||||
true,
|
||||
true,
|
||||
sentDate
|
||||
))
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_MESSAGES_SENT, 1 * DAY, DRAWER_ITEM_MESSAGES)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,8 +6,6 @@ package pl.szczodrzynski.edziennik.api.v2.vulcan.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanApi
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.getJsonArray
|
||||
|
||||
class VulcanApiTemplate(override val data: DataVulcan, val onSuccess: () -> Unit) : VulcanApi(data) {
|
||||
companion object {
|
||||
@ -15,10 +13,12 @@ class VulcanApiTemplate(override val data: DataVulcan, val onSuccess: () -> Unit
|
||||
}
|
||||
|
||||
init {
|
||||
/* apiGet(TAG, VULCAN_API_ENDPOINT_) { json, _ ->
|
||||
/* data.profile?.also { profile ->
|
||||
apiGet(TAG, VULCAN_API_ENDPOINT_) { json, _ ->
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
data.setSyncNext(ENDPOINT_VULCAN_API_, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
} */
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,6 @@ import androidx.room.TypeConverters;
|
||||
import androidx.room.migration.Migration;
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.db.converters.ConverterDate;
|
||||
import pl.szczodrzynski.edziennik.data.db.converters.ConverterDateInt;
|
||||
import pl.szczodrzynski.edziennik.data.db.converters.ConverterJsonObject;
|
||||
@ -74,9 +72,9 @@ import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherAbsenceTypeDao
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teams.Team;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teams.TeamDao;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.TimetableDao;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
|
||||
@Singleton
|
||||
@Database(entities = {
|
||||
Grade.class,
|
||||
//GradeCategory.class,
|
||||
@ -106,7 +104,8 @@ import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
Classroom.class,
|
||||
NoticeType.class,
|
||||
AttendanceType.class,
|
||||
Metadata.class}, version = 63)
|
||||
pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson.class,
|
||||
Metadata.class}, version = 64)
|
||||
@TypeConverters({
|
||||
ConverterTime.class,
|
||||
ConverterDate.class,
|
||||
@ -117,60 +116,34 @@ import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
public abstract class AppDb extends RoomDatabase {
|
||||
|
||||
public abstract GradeDao gradeDao();
|
||||
|
||||
//public abstract GradeCategoryDao gradeCategoryDao();
|
||||
public abstract TeacherDao teacherDao();
|
||||
|
||||
public abstract TeacherAbsenceDao teacherAbsenceDao();
|
||||
|
||||
public abstract TeacherAbsenceTypeDao teacherAbsenceTypeDao();
|
||||
|
||||
public abstract SubjectDao subjectDao();
|
||||
|
||||
public abstract NoticeDao noticeDao();
|
||||
|
||||
public abstract LessonDao lessonDao();
|
||||
|
||||
public abstract LessonChangeDao lessonChangeDao();
|
||||
|
||||
public abstract TeamDao teamDao();
|
||||
|
||||
public abstract AttendanceDao attendanceDao();
|
||||
|
||||
public abstract EventDao eventDao();
|
||||
|
||||
public abstract EventTypeDao eventTypeDao();
|
||||
|
||||
public abstract LoginStoreDao loginStoreDao();
|
||||
|
||||
public abstract ProfileDao profileDao();
|
||||
|
||||
public abstract LuckyNumberDao luckyNumberDao();
|
||||
|
||||
public abstract AnnouncementDao announcementDao();
|
||||
|
||||
public abstract GradeCategoryDao gradeCategoryDao();
|
||||
|
||||
public abstract FeedbackMessageDao feedbackMessageDao();
|
||||
|
||||
public abstract MessageDao messageDao();
|
||||
|
||||
public abstract MessageRecipientDao messageRecipientDao();
|
||||
|
||||
public abstract DebugLogDao debugLogDao();
|
||||
|
||||
public abstract EndpointTimerDao endpointTimerDao();
|
||||
|
||||
public abstract LessonRangeDao lessonRangeDao();
|
||||
|
||||
public abstract NotificationDao notificationDao();
|
||||
|
||||
public abstract ClassroomDao classroomDao();
|
||||
|
||||
public abstract NoticeTypeDao noticeTypeDao();
|
||||
|
||||
public abstract AttendanceTypeDao attendanceTypeDao();
|
||||
|
||||
public abstract TimetableDao timetableDao();
|
||||
public abstract MetadataDao metadataDao();
|
||||
|
||||
private static volatile AppDb INSTANCE;
|
||||
@ -759,6 +732,37 @@ public abstract class AppDb extends RoomDatabase {
|
||||
database.execSQL("ALTER TABLE profiles ADD COLUMN studentSchoolYear TEXT DEFAULT NULL");
|
||||
}
|
||||
};
|
||||
private static final Migration MIGRATION_63_64 = new Migration(63, 64) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
//database.execSQL("ALTER TABLE lessons RENAME TO lessonsOld;");
|
||||
database.execSQL("CREATE TABLE timetable (" +
|
||||
"profileId INTEGER NOT NULL," +
|
||||
"id INTEGER NOT NULL," +
|
||||
"type INTEGER NOT NULL," +
|
||||
|
||||
"date TEXT DEFAULT NULL," +
|
||||
"lessonNumber INTEGER DEFAULT NULL," +
|
||||
"startTime TEXT DEFAULT NULL," +
|
||||
"endTime TEXT DEFAULT NULL," +
|
||||
"subjectId INTEGER DEFAULT NULL," +
|
||||
"teacherId INTEGER DEFAULT NULL," +
|
||||
"teamId INTEGER DEFAULT NULL," +
|
||||
"classroom TEXT DEFAULT NULL," +
|
||||
|
||||
"oldDate TEXT DEFAULT NULL," +
|
||||
"oldLessonNumber INTEGER DEFAULT NULL," +
|
||||
"oldStartTime TEXT DEFAULT NULL," +
|
||||
"oldEndTime TEXT DEFAULT NULL," +
|
||||
"oldSubjectId INTEGER DEFAULT NULL," +
|
||||
"oldTeacherId INTEGER DEFAULT NULL," +
|
||||
"oldTeamId INTEGER DEFAULT NULL," +
|
||||
"oldClassroom TEXT DEFAULT NULL," +
|
||||
"PRIMARY KEY(id));");
|
||||
database.execSQL("CREATE INDEX index_lessons_profileId_type_date ON timetable (profileId, type, date);");
|
||||
database.execSQL("CREATE INDEX index_lessons_profileId_type_oldDate ON timetable (profileId, type, oldDate);");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static AppDb getDatabase(final Context context) {
|
||||
@ -819,7 +823,8 @@ public abstract class AppDb extends RoomDatabase {
|
||||
MIGRATION_59_60,
|
||||
MIGRATION_60_61,
|
||||
MIGRATION_61_62,
|
||||
MIGRATION_62_63
|
||||
MIGRATION_62_63,
|
||||
MIGRATION_63_64
|
||||
)
|
||||
.allowMainThreadQueries()
|
||||
//.fallbackToDestructiveMigration()
|
||||
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.db
|
||||
|
||||
import android.content.Context
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
internal class DatabaseModule {
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideDatabase(context: Context) = AppDb.getDatabase(context)
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideEventDao(database: AppDb) = database.eventDao()
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideMetadataDao(database: AppDb) = database.metadataDao()
|
||||
}
|
@ -5,6 +5,7 @@ import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.Ignore;
|
||||
import androidx.room.Index;
|
||||
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
||||
|
||||
@ -85,6 +86,23 @@ public class Event {
|
||||
this.teamId = teamId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Event clone() throws CloneNotSupportedException {
|
||||
return new Event(
|
||||
profileId,
|
||||
id,
|
||||
eventDate.clone(),
|
||||
startTime == null ? null : startTime.clone(),
|
||||
topic,
|
||||
color,
|
||||
type,
|
||||
addedManually,
|
||||
subjectId,
|
||||
teacherId,
|
||||
teamId
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Event{" +
|
||||
|
@ -1,22 +1,19 @@
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.events;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.sqlite.db.SimpleSQLiteQuery;
|
||||
import androidx.sqlite.db.SupportSQLiteQuery;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.RawQuery;
|
||||
import androidx.room.Transaction;
|
||||
import androidx.sqlite.db.SimpleSQLiteQuery;
|
||||
import androidx.sqlite.db.SupportSQLiteQuery;
|
||||
import androidx.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
||||
|
||||
@ -24,7 +21,6 @@ import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_HOMEWORK;
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_LESSON_CHANGE;
|
||||
|
||||
@Singleton
|
||||
@Dao
|
||||
public abstract class EventDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
@ -38,32 +34,26 @@ public abstract class EventDao {
|
||||
|
||||
@Query("DELETE FROM events WHERE profileId = :profileId AND eventId = :id")
|
||||
public abstract void remove(int profileId, long id);
|
||||
|
||||
@Query("DELETE FROM metadata WHERE profileId = :profileId AND thingType = :thingType AND thingId = :thingId")
|
||||
public abstract void removeMetadata(int profileId, int thingType, long thingId);
|
||||
|
||||
@Transaction
|
||||
public void remove(int profileId, int type, long id) {
|
||||
remove(profileId, id);
|
||||
removeMetadata(profileId, type == Event.TYPE_HOMEWORK ? TYPE_HOMEWORK : TYPE_EVENT, id);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public void remove(Event event) {
|
||||
remove(event.profileId, event.type, event.id);
|
||||
}
|
||||
|
||||
@Transaction
|
||||
public void remove(int profileId, Event event) {
|
||||
remove(profileId, event.type, event.id);
|
||||
}
|
||||
|
||||
@Query("DELETE FROM events WHERE teamId = :teamId AND eventId = :id")
|
||||
public abstract void removeByTeamId(long teamId, long id);
|
||||
|
||||
@RawQuery(observedEntities = {Event.class})
|
||||
abstract LiveData<List<EventFull>> getAll(SupportSQLiteQuery query);
|
||||
|
||||
public LiveData<List<EventFull>> getAll(int profileId, String filter) {
|
||||
String query = "SELECT \n" +
|
||||
"*, \n" +
|
||||
@ -81,31 +71,24 @@ public abstract class EventDao {
|
||||
Log.d("DB", query);
|
||||
return getAll(new SimpleSQLiteQuery(query));
|
||||
}
|
||||
|
||||
public LiveData<List<EventFull>> getAll(int profileId) {
|
||||
return getAll(profileId, "1");
|
||||
}
|
||||
|
||||
public List<EventFull> getAllNow(int profileId) {
|
||||
return getAllNow(profileId, "1");
|
||||
}
|
||||
|
||||
public LiveData<List<EventFull>> getAllWhere(int profileId, String filter) {
|
||||
return getAll(profileId, filter);
|
||||
}
|
||||
|
||||
public LiveData<List<EventFull>> getAllByType(int profileId, int type, String filter) {
|
||||
return getAll(profileId, "eventType = "+type+" AND "+filter);
|
||||
}
|
||||
|
||||
public LiveData<List<EventFull>> getAllByDate(int profileId, @NonNull Date date) {
|
||||
return getAll(profileId, "eventDate = '"+date.getStringY_m_d()+"'");
|
||||
}
|
||||
|
||||
public List<EventFull> getAllByDateNow(int profileId, @NonNull Date date) {
|
||||
return getAllNow(profileId, "eventDate = '"+date.getStringY_m_d()+"'");
|
||||
}
|
||||
|
||||
public LiveData<List<EventFull>> getAllByDateTime(int profileId, @NonNull Date date, Time time) {
|
||||
if (time == null)
|
||||
return getAllByDate(profileId, date);
|
||||
@ -114,7 +97,6 @@ public abstract class EventDao {
|
||||
|
||||
@RawQuery
|
||||
abstract List<EventFull> getAllNow(SupportSQLiteQuery query);
|
||||
|
||||
public List<EventFull> getAllNow(int profileId, String filter) {
|
||||
return getAllNow(new SimpleSQLiteQuery("SELECT \n" +
|
||||
"*, \n" +
|
||||
@ -130,7 +112,6 @@ public abstract class EventDao {
|
||||
"WHERE events.profileId = "+profileId+" AND events.eventBlacklisted = 0 AND "+filter+"\n" +
|
||||
"ORDER BY eventStartTime, addedDate ASC"));
|
||||
}
|
||||
|
||||
public List<EventFull> getNotNotifiedNow(int profileId) {
|
||||
return getAllNow(profileId, "notified = 0");
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import androidx.room.Entity;
|
||||
import androidx.room.Ignore;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.ProfileFull;
|
||||
@ -73,7 +74,7 @@ public class LoginStore {
|
||||
if (data == null)
|
||||
return defaultValue;
|
||||
JsonElement element = data.get(key);
|
||||
if (element != null) {
|
||||
if (element != null && !(element instanceof JsonNull)) {
|
||||
return element.getAsString();
|
||||
}
|
||||
return defaultValue;
|
||||
@ -83,7 +84,7 @@ public class LoginStore {
|
||||
if (data == null)
|
||||
return defaultValue;
|
||||
JsonElement element = data.get(key);
|
||||
if (element != null) {
|
||||
if (element != null && !(element instanceof JsonNull)) {
|
||||
return element.getAsInt();
|
||||
}
|
||||
return defaultValue;
|
||||
@ -93,7 +94,7 @@ public class LoginStore {
|
||||
if (data == null)
|
||||
return defaultValue;
|
||||
JsonElement element = data.get(key);
|
||||
if (element != null) {
|
||||
if (element != null && !(element instanceof JsonNull)) {
|
||||
return element.getAsLong();
|
||||
}
|
||||
return defaultValue;
|
||||
@ -103,7 +104,7 @@ public class LoginStore {
|
||||
if (data == null)
|
||||
return defaultValue;
|
||||
JsonElement element = data.get(key);
|
||||
if (element != null) {
|
||||
if (element != null && !(element instanceof JsonNull)) {
|
||||
return element.getAsFloat();
|
||||
}
|
||||
return defaultValue;
|
||||
@ -112,7 +113,7 @@ public class LoginStore {
|
||||
if (data == null)
|
||||
return defaultValue;
|
||||
JsonElement element = data.get(key);
|
||||
if (element != null) {
|
||||
if (element != null && !(element instanceof JsonNull)) {
|
||||
return element.getAsBoolean();
|
||||
}
|
||||
return defaultValue;
|
||||
|
@ -1,19 +1,19 @@
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.messages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.Ignore;
|
||||
import androidx.room.Index;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity(tableName = "messages",
|
||||
primaryKeys = {"profileId", "messageId"},
|
||||
indices = {@Index(value = {"profileId"})})
|
||||
public class Message {
|
||||
int profileId;
|
||||
public int profileId;
|
||||
|
||||
@ColumnInfo(name = "messageId")
|
||||
public long id;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.messages;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
@ -11,6 +10,8 @@ import androidx.room.RawQuery;
|
||||
import androidx.sqlite.db.SimpleSQLiteQuery;
|
||||
import androidx.sqlite.db.SupportSQLiteQuery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata;
|
||||
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_DELETED;
|
||||
@ -23,6 +24,9 @@ public abstract class MessageDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
public abstract long add(Message message);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
public abstract void addAll(List<Message> messageList);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
public abstract void addAllIgnore(List<Message> messageList);
|
||||
|
||||
@ -56,6 +60,7 @@ public abstract class MessageDao {
|
||||
"ORDER BY addedDate DESC"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MessageFull getById(int profileId, long messageId) {
|
||||
return getOneNow(new SimpleSQLiteQuery("SELECT \n" +
|
||||
"*, \n" +
|
||||
|
@ -1,13 +1,15 @@
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.messages;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.room.Ignore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.room.Ignore;
|
||||
|
||||
public class MessageFull extends Message {
|
||||
public String senderFullName = null;
|
||||
@Ignore
|
||||
@Nullable
|
||||
public List<MessageRecipientFull> recipients = null;
|
||||
|
||||
public MessageFull addRecipient(MessageRecipientFull recipient) {
|
||||
|
@ -9,8 +9,7 @@ import androidx.room.Transaction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.notices.Notice;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.announcements.Announcement;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.attendance.Attendance;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.Event;
|
||||
@ -18,7 +17,6 @@ import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.notices.Notice;
|
||||
import pl.szczodrzynski.edziennik.utils.models.UnreadCounter;
|
||||
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_ANNOUNCEMENT;
|
||||
@ -30,7 +28,6 @@ import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_MESSAGE;
|
||||
import static pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata.TYPE_NOTICE;
|
||||
|
||||
@Singleton
|
||||
@Dao
|
||||
public abstract class MetadataDao {
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
@ -46,6 +43,7 @@ public abstract class MetadataDao {
|
||||
abstract void updateNotified(int profileId, int thingType, long thingId, boolean notified);
|
||||
|
||||
|
||||
|
||||
@Transaction
|
||||
public void setSeen(List<Metadata> metadataList) {
|
||||
for (Metadata metadata: metadataList) {
|
||||
@ -154,6 +152,7 @@ public abstract class MetadataDao {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Query("UPDATE metadata SET seen = :seen WHERE profileId = :profileId AND thingType = :thingType")
|
||||
public abstract void setAllSeen(int profileId, int thingType, boolean seen);
|
||||
|
||||
@ -167,6 +166,7 @@ public abstract class MetadataDao {
|
||||
public abstract void setAllNotified(int profileId, boolean notified);
|
||||
|
||||
|
||||
|
||||
@Query("SELECT count() FROM metadata WHERE profileId = :profileId AND thingType = :thingType AND seen = 0")
|
||||
public abstract LiveData<Integer> countUnseen(int profileId, int thingType);
|
||||
|
||||
@ -183,6 +183,7 @@ public abstract class MetadataDao {
|
||||
public abstract LiveData<Integer> countUnseen();
|
||||
|
||||
|
||||
|
||||
@Query("DELETE FROM metadata WHERE profileId = :profileId AND thingType = :thingType AND thingId = :thingId")
|
||||
public abstract void delete(int profileId, int thingType, long thingId);
|
||||
|
||||
@ -190,10 +191,12 @@ public abstract class MetadataDao {
|
||||
public abstract void deleteAll(int profileId);
|
||||
|
||||
|
||||
|
||||
@Query("SELECT profileId, thingType, COUNT(thingId) AS count FROM metadata WHERE seen = 0 GROUP BY profileId, thingType")
|
||||
public abstract LiveData<List<UnreadCounter>> getUnreadCounts();
|
||||
|
||||
|
||||
|
||||
@Query("DELETE FROM metadata WHERE profileId = :profileId AND thingType = "+TYPE_GRADE+" AND thingId NOT IN (SELECT gradeId FROM grades WHERE profileId = :profileId);")
|
||||
public abstract void deleteUnusedGrades(int profileId);
|
||||
|
||||
|
@ -4,12 +4,20 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.timetable
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
|
||||
open class Lesson(val profileId: Int) {
|
||||
@Entity(tableName = "timetable",
|
||||
indices = [
|
||||
Index(value = ["profileId", "type", "date"]),
|
||||
Index(value = ["profileId", "type", "oldDate"])
|
||||
])
|
||||
open class Lesson(val profileId: Int, @PrimaryKey val id: Long) {
|
||||
companion object {
|
||||
const val TYPE_NO_LESSONS = -1
|
||||
const val TYPE_NORMAL = 0
|
||||
const val TYPE_CANCELLED = 1
|
||||
const val TYPE_CHANGE = 2
|
||||
@ -17,15 +25,14 @@ open class Lesson(val profileId: Int) {
|
||||
const val TYPE_SHIFTED_TARGET = 4 /* target lesson */
|
||||
}
|
||||
|
||||
@ColumnInfo(name = "lessonType")
|
||||
var type: Int = TYPE_NORMAL
|
||||
|
||||
var date: Date? = null
|
||||
var lessonNumber: Int? = null
|
||||
var startTime: Time? = null
|
||||
var endTime: Time? = null
|
||||
var teacherId: Long? = null
|
||||
var subjectId: Long? = null
|
||||
var teacherId: Long? = null
|
||||
var teamId: Long? = null
|
||||
var classroom: String? = null
|
||||
|
||||
@ -33,8 +40,58 @@ open class Lesson(val profileId: Int) {
|
||||
var oldLessonNumber: Int? = null
|
||||
var oldStartTime: Time? = null
|
||||
var oldEndTime: Time? = null
|
||||
var oldTeacherId: Long? = null
|
||||
var oldSubjectId: Long? = null
|
||||
var oldTeacherId: Long? = null
|
||||
var oldTeamId: Long? = null
|
||||
var oldClassroom: String? = null
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "Lesson(profileId=$profileId, " +
|
||||
"id=$id, " +
|
||||
"type=$type, " +
|
||||
"date=$date, " +
|
||||
"lessonNumber=$lessonNumber, " +
|
||||
"startTime=$startTime, " +
|
||||
"endTime=$endTime, " +
|
||||
"subjectId=$subjectId, " +
|
||||
"teacherId=$teacherId, " +
|
||||
"teamId=$teamId, " +
|
||||
"classroom=$classroom, " +
|
||||
"oldDate=$oldDate, " +
|
||||
"oldLessonNumber=$oldLessonNumber, " +
|
||||
"oldStartTime=$oldStartTime, " +
|
||||
"oldEndTime=$oldEndTime, " +
|
||||
"oldSubjectId=$oldSubjectId, " +
|
||||
"oldTeacherId=$oldTeacherId, " +
|
||||
"oldTeamId=$oldTeamId, " +
|
||||
"oldClassroom=$oldClassroom)"
|
||||
}
|
||||
}
|
||||
/*
|
||||
DROP TABLE lessons;
|
||||
DROP TABLE lessonChanges;
|
||||
CREATE TABLE lessons (
|
||||
profileId INTEGER NOT NULL,
|
||||
type INTEGER NOT NULL,
|
||||
|
||||
date TEXT DEFAULT NULL,
|
||||
lessonNumber INTEGER DEFAULT NULL,
|
||||
startTime TEXT DEFAULT NULL,
|
||||
endTime TEXT DEFAULT NULL,
|
||||
teacherId INTEGER DEFAULT NULL,
|
||||
subjectId INTEGER DEFAULT NULL,
|
||||
teamId INTEGER DEFAULT NULL,
|
||||
classroom TEXT DEFAULT NULL,
|
||||
|
||||
oldDate TEXT DEFAULT NULL,
|
||||
oldLessonNumber INTEGER DEFAULT NULL,
|
||||
oldStartTime TEXT DEFAULT NULL,
|
||||
oldEndTime TEXT DEFAULT NULL,
|
||||
oldTeacherId INTEGER DEFAULT NULL,
|
||||
oldSubjectId INTEGER DEFAULT NULL,
|
||||
oldTeamId INTEGER DEFAULT NULL,
|
||||
oldClassroom TEXT DEFAULT NULL,
|
||||
|
||||
PRIMARY KEY(profileId)
|
||||
);
|
||||
*/
|
@ -0,0 +1,88 @@
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.timetable
|
||||
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
|
||||
class LessonFull(profileId: Int, id: Long) : Lesson(profileId, id) {
|
||||
var subjectName: String? = null
|
||||
var teacherName: String? = null
|
||||
var teamName: String? = null
|
||||
var oldSubjectName: String? = null
|
||||
var oldTeacherName: String? = null
|
||||
var oldTeamName: String? = null
|
||||
|
||||
val displayDate: Date?
|
||||
get() {
|
||||
if (type == TYPE_SHIFTED_SOURCE)
|
||||
return oldDate
|
||||
return date ?: oldDate
|
||||
}
|
||||
val displayLessonNumber: Int?
|
||||
get() {
|
||||
if (type == TYPE_SHIFTED_SOURCE)
|
||||
return oldLessonNumber
|
||||
return lessonNumber ?: oldLessonNumber
|
||||
}
|
||||
val displayStartTime: Time?
|
||||
get() {
|
||||
if (type == TYPE_SHIFTED_SOURCE)
|
||||
return oldStartTime
|
||||
return startTime ?: oldStartTime
|
||||
}
|
||||
val displayEndTime: Time?
|
||||
get() {
|
||||
if (type == TYPE_SHIFTED_SOURCE)
|
||||
return oldEndTime
|
||||
return endTime ?: oldEndTime
|
||||
}
|
||||
|
||||
val displaySubjectName: String?
|
||||
get() {
|
||||
if (type == TYPE_SHIFTED_SOURCE)
|
||||
return oldSubjectName
|
||||
return subjectName ?: oldSubjectName
|
||||
}
|
||||
val displayTeacherName: String?
|
||||
get() {
|
||||
if (type == TYPE_SHIFTED_SOURCE)
|
||||
return oldTeacherName
|
||||
return teacherName ?: oldTeacherName
|
||||
}
|
||||
val displayTeamName: String?
|
||||
get() {
|
||||
if (type == TYPE_SHIFTED_SOURCE)
|
||||
return oldTeamName
|
||||
return teamName ?: oldTeamName
|
||||
}
|
||||
|
||||
val displayClassroom: String?
|
||||
get() {
|
||||
if (type == TYPE_SHIFTED_SOURCE)
|
||||
return oldClassroom
|
||||
return classroom ?: oldClassroom
|
||||
}
|
||||
|
||||
val displayTeamId: Long?
|
||||
get() {
|
||||
if (type == TYPE_SHIFTED_SOURCE)
|
||||
return oldTeamId
|
||||
return teamId ?: oldTeamId
|
||||
}
|
||||
val displaySubjectId: Long?
|
||||
get() {
|
||||
if (type == TYPE_SHIFTED_SOURCE)
|
||||
return oldSubjectId
|
||||
return subjectId ?: oldSubjectId
|
||||
}
|
||||
val displayTeacherId: Long?
|
||||
get() {
|
||||
if (type == TYPE_SHIFTED_SOURCE)
|
||||
return oldTeacherId
|
||||
return teacherId ?: oldTeacherId
|
||||
}
|
||||
|
||||
// metadata
|
||||
var seen: Boolean = false
|
||||
var notified: Boolean = false
|
||||
var addedDate: Long = 0
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package pl.szczodrzynski.edziennik.data.db.modules.timetable
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
@Dao
|
||||
interface TimetableDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
operator fun plusAssign(lessonList: List<Lesson>)
|
||||
|
||||
@Query("DELETE FROM timetable WHERE profileId = :profileId")
|
||||
fun clear(profileId: Int)
|
||||
|
||||
@Query("DELETE FROM timetable WHERE profileId = :profileId AND (type != 3 AND date >= :dateFrom) OR ((type = 3 OR type = 1) AND oldDate >= :dateFrom)")
|
||||
fun clearFromDate(profileId: Int, dateFrom: Date)
|
||||
@Query("DELETE FROM timetable WHERE profileId = :profileId AND (type != 3 AND date <= :dateTo) OR ((type = 3 OR type = 1) AND oldDate <= :dateTo)")
|
||||
fun clearToDate(profileId: Int, dateTo: Date)
|
||||
@Query("DELETE FROM timetable WHERE profileId = :profileId AND (type != 3 AND date >= :dateFrom AND date <= :dateTo) OR ((type = 3 OR type = 1) AND oldDate >= :dateFrom AND oldDate <= :dateTo)")
|
||||
fun clearBetweenDates(profileId: Int, dateFrom: Date, dateTo: Date)
|
||||
|
||||
@Query("""
|
||||
SELECT
|
||||
timetable.*,
|
||||
subjects.subjectLongName AS subjectName,
|
||||
teachers.teacherName ||" "|| teachers.teacherSurname AS teacherName,
|
||||
teams.teamName AS teamName,
|
||||
oldS.subjectLongName AS oldSubjectName,
|
||||
oldT.teacherName ||" "|| oldT.teacherSurname AS oldTeacherName,
|
||||
oldG.teamName AS oldTeamName,
|
||||
metadata.seen, metadata.notified, metadata.addedDate
|
||||
FROM timetable
|
||||
LEFT JOIN subjects USING(profileId, subjectId)
|
||||
LEFT JOIN teachers USING(profileId, teacherId)
|
||||
LEFT JOIN teams USING(profileId, teamId)
|
||||
LEFT JOIN subjects AS oldS ON timetable.profileId = oldS.profileId AND timetable.oldSubjectId = oldS.subjectId
|
||||
LEFT JOIN teachers AS oldT ON timetable.profileId = oldT.profileId AND timetable.oldTeacherId = oldT.teacherId
|
||||
LEFT JOIN teams AS oldG ON timetable.profileId = oldG.profileId AND timetable.oldTeamId = oldG.teamId
|
||||
LEFT JOIN metadata ON id = thingId AND thingType = ${Metadata.TYPE_LESSON_CHANGE} AND metadata.profileId = timetable.profileId
|
||||
WHERE timetable.profileId = :profileId AND (type != 3 AND date = :date) OR ((type = 3 OR type = 1) AND oldDate = :date)
|
||||
ORDER BY id, type
|
||||
""")
|
||||
fun getForDate(profileId: Int, date: Date) : LiveData<List<LessonFull>>
|
||||
|
||||
@Query("""
|
||||
SELECT
|
||||
timetable.*,
|
||||
subjects.subjectLongName AS subjectName,
|
||||
teachers.teacherName ||" "|| teachers.teacherSurname AS teacherName,
|
||||
teams.teamName AS teamName,
|
||||
oldS.subjectLongName AS oldSubjectName,
|
||||
oldT.teacherName ||" "|| oldT.teacherSurname AS oldTeacherName,
|
||||
oldG.teamName AS oldTeamName,
|
||||
metadata.seen, metadata.notified, metadata.addedDate
|
||||
FROM timetable
|
||||
LEFT JOIN subjects USING(profileId, subjectId)
|
||||
LEFT JOIN teachers USING(profileId, teacherId)
|
||||
LEFT JOIN teams USING(profileId, teamId)
|
||||
LEFT JOIN subjects AS oldS ON timetable.profileId = oldS.profileId AND timetable.oldSubjectId = oldS.subjectId
|
||||
LEFT JOIN teachers AS oldT ON timetable.profileId = oldT.profileId AND timetable.oldTeacherId = oldT.teacherId
|
||||
LEFT JOIN teams AS oldG ON timetable.profileId = oldG.profileId AND timetable.oldTeamId = oldG.teamId
|
||||
LEFT JOIN metadata ON id = thingId AND thingType = ${Metadata.TYPE_LESSON_CHANGE} AND metadata.profileId = timetable.profileId
|
||||
WHERE timetable.profileId = :profileId AND ((type != 3 AND date > :today) OR ((type = 3 OR type = 1) AND oldDate > :today)) AND timetable.subjectId = :subjectId
|
||||
ORDER BY id, type
|
||||
LIMIT 1
|
||||
""")
|
||||
fun getNextWithSubject(profileId: Int, today: Date, subjectId: Long) : LiveData<LessonFull>
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.di
|
||||
|
||||
import dagger.Component
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.support.AndroidSupportInjectionModule
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.data.db.DatabaseModule
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
@Component(modules = [
|
||||
AndroidSupportInjectionModule::class,
|
||||
BindingModule::class,
|
||||
AppModule::class,
|
||||
DatabaseModule::class
|
||||
])
|
||||
interface AppComponent : AndroidInjector<App> {
|
||||
|
||||
@Component.Factory
|
||||
interface Factory : AndroidInjector.Factory<App>
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.di
|
||||
|
||||
import android.content.Context
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
internal class AppModule {
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideContext(app: App): Context = app
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.di
|
||||
|
||||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.di.scopes.PerActivity
|
||||
import pl.szczodrzynski.edziennik.di.scopes.PerFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.homework.HomeworkFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.homework.list.HomeworkListFragment
|
||||
|
||||
@Module
|
||||
@Suppress("unused")
|
||||
internal abstract class BindingModule {
|
||||
|
||||
/**
|
||||
* ACTIVITIES
|
||||
*/
|
||||
|
||||
@PerActivity
|
||||
@ContributesAndroidInjector
|
||||
abstract fun bindMainActivity(): MainActivity
|
||||
|
||||
/**
|
||||
* FRAGMENTS
|
||||
*/
|
||||
|
||||
@PerFragment
|
||||
@ContributesAndroidInjector
|
||||
abstract fun bindHomeworkFragment(): HomeworkFragment
|
||||
|
||||
@PerFragment
|
||||
@ContributesAndroidInjector
|
||||
abstract fun bindHomeworkListFragment(): HomeworkListFragment
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.di.scopes
|
||||
|
||||
import javax.inject.Scope
|
||||
|
||||
@Scope
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class PerActivity
|
@ -1,11 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.di.scopes
|
||||
|
||||
import javax.inject.Scope
|
||||
|
||||
@Scope
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class PerFragment
|
@ -112,7 +112,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
|
||||
app.notifier.postAll(profile);
|
||||
app.saveConfig("notifications");*/
|
||||
d(TAG, "Syncing profile " + profile.getId());
|
||||
EdziennikTask.Companion.syncProfile(profile.getId(), null).enqueue(app);
|
||||
EdziennikTask.Companion.syncProfile(profile.getId(), null, null).enqueue(app);
|
||||
} else {
|
||||
/*app.notifier.add(new Notification(app.getContext(), remoteMessage.getData().get("message"))
|
||||
.withProfileData(profile.id, profile.name)
|
||||
@ -123,7 +123,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
|
||||
app.notifier.postAll(profile);
|
||||
app.saveConfig("notifications");*/
|
||||
d(TAG, "Syncing profile " + profile.getId());
|
||||
EdziennikTask.Companion.syncProfile(profile.getId(), null).enqueue(app);
|
||||
EdziennikTask.Companion.syncProfile(profile.getId(), null, null).enqueue(app);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.base
|
||||
|
||||
import android.widget.Toast
|
||||
import dagger.android.support.DaggerFragment
|
||||
|
||||
abstract class BaseFragment<T : BasePresenter<out BaseView>> : DaggerFragment(), BaseView {
|
||||
|
||||
abstract var presenter: T
|
||||
|
||||
override fun showMessage(text: String) {
|
||||
Toast.makeText(activity, text, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
presenter.onDetachView()
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.base
|
||||
|
||||
open class BasePresenter<T : BaseView> {
|
||||
|
||||
var view: T? = null
|
||||
|
||||
open fun onAttachView(view: T) {
|
||||
this.view = view
|
||||
}
|
||||
|
||||
open fun onDetachView() {
|
||||
view = null
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.base
|
||||
|
||||
interface BaseView {
|
||||
|
||||
fun showMessage(text: String)
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-11-12.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.dialogs.event
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
|
||||
class EventAddTypeDialog(
|
||||
val activity: Activity,
|
||||
val profileId: Int,
|
||||
val date: Date? = null,
|
||||
val time: Time? = null
|
||||
) {
|
||||
companion object {
|
||||
private const val TAG = "EventAddTypeDialog"
|
||||
}
|
||||
|
||||
private lateinit var dialog: AlertDialog
|
||||
|
||||
init { run {
|
||||
dialog = MaterialAlertDialogBuilder(activity)
|
||||
.setItems(R.array.main_menu_add_options) { dialog, which ->
|
||||
dialog.dismiss()
|
||||
EventManualDialog(activity, profileId)
|
||||
.show(
|
||||
activity.application as App,
|
||||
null,
|
||||
date,
|
||||
time,
|
||||
when (which) {
|
||||
1 -> EventManualDialog.DIALOG_HOMEWORK
|
||||
else -> EventManualDialog.DIALOG_EVENT
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
.setNegativeButton(R.string.cancel) { dialog, _ -> dialog.dismiss() }
|
||||
.show()
|
||||
}}
|
||||
}
|
@ -0,0 +1,379 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-11-12.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.dialogs.event
|
||||
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.Observer
|
||||
import com.google.android.material.datepicker.MaterialDatePicker
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.*
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teams.Team
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull
|
||||
import pl.szczodrzynski.edziennik.databinding.DialogEventManualV2Binding
|
||||
import pl.szczodrzynski.edziennik.utils.TextInputDropDown
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class EventManualV2Dialog(
|
||||
val activity: AppCompatActivity,
|
||||
val profileId: Int,
|
||||
val defaultLesson: LessonFull? = null,
|
||||
val defaultDate: Date? = null,
|
||||
val defaultTime: Time? = null,
|
||||
val defaultType: Int? = null,
|
||||
val editingEvent: Event? = null
|
||||
) : CoroutineScope {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "EventManualDialog"
|
||||
}
|
||||
|
||||
private lateinit var job: Job
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = job + Dispatchers.Main
|
||||
|
||||
private val app by lazy { activity.application as App }
|
||||
private lateinit var b: DialogEventManualV2Binding
|
||||
private lateinit var dialog: AlertDialog
|
||||
private lateinit var event: Event
|
||||
private var defaultLoaded = false
|
||||
|
||||
init { run {
|
||||
job = Job()
|
||||
|
||||
b = DialogEventManualV2Binding.inflate(activity.layoutInflater)
|
||||
dialog = MaterialAlertDialogBuilder(activity)
|
||||
.setTitle(R.string.dialog_event_manual_title)
|
||||
.setView(b.root)
|
||||
.setNegativeButton(R.string.cancel) { dialog, _ -> dialog.dismiss() }
|
||||
.setPositiveButton(R.string.save) { _, _ -> saveEvent() }
|
||||
.show()
|
||||
|
||||
event = editingEvent?.clone() ?: Event().also { event ->
|
||||
event.profileId = profileId
|
||||
/*defaultDate?.let {
|
||||
event.eventDate = it
|
||||
b.date = it
|
||||
}
|
||||
defaultTime?.let {
|
||||
event.startTime = it
|
||||
b.time = it
|
||||
}
|
||||
defaultType?.let {
|
||||
event.type = it
|
||||
}*/
|
||||
}
|
||||
|
||||
loadLists()
|
||||
}}
|
||||
|
||||
private fun loadLists() { launch {
|
||||
val deferred = async(Dispatchers.Default) {
|
||||
// get the team list
|
||||
val teams = app.db.teamDao().getAllNow(profileId)
|
||||
b.teamDropdown.clear()
|
||||
b.teamDropdown += TextInputDropDown.Item(
|
||||
-1,
|
||||
activity.getString(R.string.dialog_event_manual_no_team),
|
||||
""
|
||||
)
|
||||
b.teamDropdown += teams.map { TextInputDropDown.Item(it.id, it.name, tag = it) }
|
||||
|
||||
// get the subject list
|
||||
val subjects = app.db.subjectDao().getAllNow(profileId)
|
||||
b.subjectDropdown.clear()
|
||||
b.subjectDropdown += TextInputDropDown.Item(
|
||||
-1,
|
||||
activity.getString(R.string.dialog_event_manual_no_subject),
|
||||
""
|
||||
)
|
||||
b.subjectDropdown += subjects.map { TextInputDropDown.Item(it.id, it.longName, tag = it) }
|
||||
|
||||
// get the teacher list
|
||||
val teachers = app.db.teacherDao().getAllNow(profileId)
|
||||
b.teacherDropdown.clear()
|
||||
b.teacherDropdown += TextInputDropDown.Item(
|
||||
-1,
|
||||
activity.getString(R.string.dialog_event_manual_no_teacher),
|
||||
""
|
||||
)
|
||||
b.teacherDropdown += teachers.map { TextInputDropDown.Item(it.id, it.fullName, tag = it) }
|
||||
}
|
||||
deferred.await()
|
||||
|
||||
b.teamDropdown.isEnabled = true
|
||||
b.subjectDropdown.isEnabled = true
|
||||
b.teacherDropdown.isEnabled = true
|
||||
|
||||
// copy IDs from event being edited
|
||||
editingEvent?.let {
|
||||
b.teamDropdown.select(it.teamId)
|
||||
b.subjectDropdown.select(it.subjectId)
|
||||
b.teacherDropdown.select(it.teacherId)
|
||||
}
|
||||
|
||||
// copy IDs from the LessonFull
|
||||
defaultLesson?.let {
|
||||
b.teamDropdown.select(it.displayTeamId)
|
||||
b.subjectDropdown.select(it.displaySubjectId)
|
||||
b.teacherDropdown.select(it.displayTeacherId)
|
||||
}
|
||||
|
||||
loadDates()
|
||||
}}
|
||||
|
||||
private fun loadDates() { launch {
|
||||
val date = Date.getToday()
|
||||
val today = date.value
|
||||
var weekDay = date.weekDay
|
||||
|
||||
val deferred = async(Dispatchers.Default) {
|
||||
val dates = mutableListOf<TextInputDropDown.Item>()
|
||||
// item choosing the next lesson of specific subject
|
||||
b.subjectDropdown.selected?.let {
|
||||
if (it.tag is Subject) {
|
||||
dates += TextInputDropDown.Item(
|
||||
-it.id,
|
||||
activity.getString(R.string.dialog_event_manual_date_next_lesson, it.tag.longName)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// TODAY
|
||||
dates += TextInputDropDown.Item(
|
||||
date.value.toLong(),
|
||||
activity.getString(R.string.dialog_event_manual_date_today, date.formattedString),
|
||||
tag = date.clone()
|
||||
)
|
||||
|
||||
// TOMORROW
|
||||
if (weekDay < 4) {
|
||||
date.stepForward(0, 0, 1)
|
||||
weekDay++
|
||||
dates += TextInputDropDown.Item(
|
||||
date.value.toLong(),
|
||||
activity.getString(R.string.dialog_event_manual_date_tomorrow, date.formattedString),
|
||||
tag = date.clone()
|
||||
)
|
||||
}
|
||||
// REMAINING SCHOOL DAYS OF THE CURRENT WEEK
|
||||
while (weekDay < 4) {
|
||||
date.stepForward(0, 0, 1) // step one day forward
|
||||
weekDay++
|
||||
dates += TextInputDropDown.Item(
|
||||
date.value.toLong(),
|
||||
activity.getString(R.string.dialog_event_manual_date_this_week, Week.getFullDayName(weekDay), date.formattedString),
|
||||
tag = date.clone()
|
||||
)
|
||||
}
|
||||
// go to next week Monday
|
||||
date.stepForward(0, 0, -weekDay + 7)
|
||||
weekDay = 0
|
||||
// ALL SCHOOL DAYS OF THE NEXT WEEK
|
||||
while (weekDay < 4) {
|
||||
dates += TextInputDropDown.Item(
|
||||
date.value.toLong(),
|
||||
activity.getString(R.string.dialog_event_manual_date_next_week, Week.getFullDayName(weekDay), date.formattedString),
|
||||
tag = date.clone()
|
||||
)
|
||||
date.stepForward(0, 0, 1) // step one day forward
|
||||
weekDay++
|
||||
}
|
||||
dates += TextInputDropDown.Item(
|
||||
-1L,
|
||||
activity.getString(R.string.dialog_event_manual_date_other)
|
||||
)
|
||||
dates
|
||||
}
|
||||
|
||||
val dates = deferred.await()
|
||||
b.dateDropdown.clear().append(dates)
|
||||
|
||||
editingEvent?.let {
|
||||
b.dateDropdown.select(it.eventDate.value.toLong())
|
||||
}
|
||||
|
||||
defaultLesson?.let {
|
||||
b.dateDropdown.select(it.displayDate?.value?.toLong())
|
||||
}
|
||||
|
||||
if (b.dateDropdown.selected == null) {
|
||||
b.dateDropdown.select(today.toLong())
|
||||
}
|
||||
|
||||
b.dateDropdown.isEnabled = true
|
||||
|
||||
b.dateDropdown.setOnChangeListener { item ->
|
||||
when {
|
||||
// next lesson with specified subject
|
||||
item.id < -1 -> {
|
||||
app.db.timetableDao().getNextWithSubject(profileId, Date.getToday(), -item.id).observeOnce(activity, Observer {
|
||||
val lessonDate = it?.displayDate ?: return@Observer
|
||||
b.dateDropdown.selected = TextInputDropDown.Item(
|
||||
lessonDate.value.toLong(),
|
||||
lessonDate.formattedString,
|
||||
tag = lessonDate
|
||||
)
|
||||
// TODO load correct hour when selecting next lesson
|
||||
b.dateDropdown.updateText()
|
||||
it.let {
|
||||
b.teamDropdown.select(it.displayTeamId)
|
||||
b.subjectDropdown.select(it.displaySubjectId)
|
||||
b.teacherDropdown.select(it.displayTeacherId)
|
||||
}
|
||||
defaultLoaded = false
|
||||
loadHours()
|
||||
})
|
||||
return@setOnChangeListener false
|
||||
}
|
||||
// custom date
|
||||
item.id == -1L -> {
|
||||
MaterialDatePicker.Builder
|
||||
.datePicker()
|
||||
.setSelection((b.dateDropdown.selectedId?.let { Date.fromValue(it.toInt()) } ?: Date.getToday()).inMillis)
|
||||
.build()
|
||||
.apply {
|
||||
addOnPositiveButtonClickListener {
|
||||
val dateSelected = Date.fromMillis(it)
|
||||
b.dateDropdown.selected = TextInputDropDown.Item(
|
||||
dateSelected.value.toLong(),
|
||||
dateSelected.formattedString,
|
||||
tag = dateSelected
|
||||
)
|
||||
b.dateDropdown.updateText()
|
||||
loadHours()
|
||||
}
|
||||
show(this@EventManualV2Dialog.activity.supportFragmentManager, "MaterialDatePicker")
|
||||
}
|
||||
|
||||
return@setOnChangeListener false
|
||||
}
|
||||
// a specific date
|
||||
else -> {
|
||||
b.dateDropdown.select(item)
|
||||
loadHours()
|
||||
}
|
||||
}
|
||||
return@setOnChangeListener true
|
||||
}
|
||||
|
||||
loadHours()
|
||||
}}
|
||||
|
||||
private fun loadHours() {
|
||||
b.timeDropdown.isEnabled = false
|
||||
// get the selected date
|
||||
val date = b.dateDropdown.selectedId?.let { Date.fromValue(it.toInt()) } ?: return
|
||||
// get all lessons for selected date
|
||||
app.db.timetableDao().getForDate(profileId, date).observeOnce(activity, Observer { lessons ->
|
||||
val hours = mutableListOf<TextInputDropDown.Item>()
|
||||
// add All day time choice
|
||||
hours += TextInputDropDown.Item(
|
||||
0L,
|
||||
activity.getString(R.string.dialog_event_manual_all_day)
|
||||
)
|
||||
lessons.forEach { lesson ->
|
||||
if (lesson.type == Lesson.TYPE_NO_LESSONS) {
|
||||
// indicate there are no lessons this day
|
||||
hours += TextInputDropDown.Item(
|
||||
-2L,
|
||||
activity.getString(R.string.dialog_event_manual_no_lessons)
|
||||
)
|
||||
return@forEach
|
||||
}
|
||||
// create the lesson caption
|
||||
val text = listOfNotEmpty(
|
||||
lesson.displayStartTime?.stringHM ?: "",
|
||||
lesson.displaySubjectName?.let {
|
||||
when {
|
||||
lesson.type == Lesson.TYPE_CANCELLED -> it.asStrikethroughSpannable()
|
||||
lesson.type != Lesson.TYPE_NORMAL -> it.asItalicSpannable()
|
||||
else -> it
|
||||
}
|
||||
} ?: ""
|
||||
)
|
||||
// add an item with LessonFull as the tag
|
||||
hours += TextInputDropDown.Item(
|
||||
lesson.displayStartTime?.value?.toLong() ?: -1,
|
||||
text.concat(" "),
|
||||
tag = lesson
|
||||
)
|
||||
}
|
||||
b.timeDropdown.clear().append(hours)
|
||||
|
||||
if (defaultLoaded) {
|
||||
b.timeDropdown.deselect()
|
||||
// select the TEAM_CLASS if possible
|
||||
b.teamDropdown.items.singleOrNull {
|
||||
it.tag is Team && it.tag.type == Team.TYPE_CLASS
|
||||
}?.let {
|
||||
b.teamDropdown.select(it)
|
||||
} ?: b.teamDropdown.deselect()
|
||||
|
||||
// clear subject, teacher selection
|
||||
b.subjectDropdown.deselect()
|
||||
b.teacherDropdown.deselect()
|
||||
}
|
||||
else {
|
||||
editingEvent?.let {
|
||||
b.timeDropdown.select(it.startTime?.value?.toLong())
|
||||
}
|
||||
|
||||
defaultLesson?.let {
|
||||
b.timeDropdown.select(it.displayStartTime?.value?.toLong())
|
||||
}
|
||||
}
|
||||
defaultLoaded = true
|
||||
b.timeDropdown.isEnabled = true
|
||||
|
||||
// attach a listener to time dropdown
|
||||
b.timeDropdown.setOnChangeListener { item ->
|
||||
when {
|
||||
// custom start hour
|
||||
item.id == -1L -> {
|
||||
|
||||
return@setOnChangeListener false
|
||||
}
|
||||
// no lessons this day
|
||||
item.id == -2L -> {
|
||||
b.timeDropdown.deselect()
|
||||
return@setOnChangeListener false
|
||||
}
|
||||
// selected a specific lesson
|
||||
else -> {
|
||||
if (item.tag is LessonFull) {
|
||||
// update team, subject, teacher dropdowns,
|
||||
// using the LessonFull from item tag
|
||||
b.teamDropdown.deselect()
|
||||
b.subjectDropdown.deselect()
|
||||
b.teacherDropdown.deselect()
|
||||
item.tag.displayTeamId?.let {
|
||||
b.teamDropdown.select(it)
|
||||
}
|
||||
item.tag.displaySubjectId?.let {
|
||||
b.subjectDropdown.select(it)
|
||||
}
|
||||
item.tag.displayTeacherId?.let {
|
||||
b.teacherDropdown.select(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return@setOnChangeListener true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun saveEvent() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-11-11.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.dialogs.timetable
|
||||
|
||||
import android.content.Intent
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull
|
||||
import pl.szczodrzynski.edziennik.databinding.DialogLessonDetailsBinding
|
||||
import pl.szczodrzynski.edziennik.setText
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualV2Dialog
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.v2.TimetableFragment
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||
|
||||
class LessonDetailsDialog(
|
||||
val activity: AppCompatActivity,
|
||||
val lesson: LessonFull
|
||||
) {
|
||||
companion object {
|
||||
private const val TAG = "LessonDetailsDialog"
|
||||
}
|
||||
|
||||
private lateinit var b: DialogLessonDetailsBinding
|
||||
private lateinit var dialog: AlertDialog
|
||||
|
||||
init { run {
|
||||
b = DialogLessonDetailsBinding.inflate(activity.layoutInflater)
|
||||
dialog = MaterialAlertDialogBuilder(activity)
|
||||
.setView(b.root)
|
||||
.setPositiveButton(R.string.close) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}
|
||||
.setNeutralButton(R.string.add) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
EventManualV2Dialog(activity, lesson.profileId, lesson)
|
||||
/*MaterialAlertDialogBuilder(activity)
|
||||
.setItems(R.array.main_menu_add_options) { dialog2, which ->
|
||||
dialog2.dismiss()
|
||||
EventManualDialog(activity, lesson.profileId)
|
||||
.show(
|
||||
activity.application as App,
|
||||
null,
|
||||
lesson.displayDate,
|
||||
lesson.displayStartTime,
|
||||
when (which) {
|
||||
1 -> EventManualDialog.DIALOG_HOMEWORK
|
||||
else -> EventManualDialog.DIALOG_EVENT
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
.setNegativeButton(R.string.cancel) { dialog2, _ -> dialog2.dismiss() }
|
||||
.show()*/
|
||||
}
|
||||
.show()
|
||||
update()
|
||||
}}
|
||||
|
||||
private fun update() {
|
||||
b.lesson = lesson
|
||||
val lessonDate = lesson.displayDate ?: return
|
||||
b.lessonDate.text = Week.getFullDayName(lessonDate.weekDay) + ", " + lessonDate.formattedString
|
||||
|
||||
if (lesson.type >= Lesson.TYPE_SHIFTED_SOURCE) {
|
||||
b.shiftedLayout.visibility = View.VISIBLE
|
||||
var otherLessonDate: Date? = null
|
||||
when (lesson.type) {
|
||||
Lesson.TYPE_SHIFTED_SOURCE -> {
|
||||
otherLessonDate = lesson.date
|
||||
when {
|
||||
lesson.date != lesson.oldDate -> b.shiftedText.setText(
|
||||
R.string.timetable_lesson_shifted_other_day,
|
||||
lesson.date?.stringY_m_d ?: "?",
|
||||
lesson.startTime?.stringHM ?: "?"
|
||||
)
|
||||
lesson.startTime != lesson.oldStartTime -> b.shiftedText.setText(
|
||||
R.string.timetable_lesson_shifted_same_day,
|
||||
lesson.startTime?.stringHM ?: "?"
|
||||
)
|
||||
else -> b.shiftedText.setText(R.string.timetable_lesson_shifted)
|
||||
}
|
||||
}
|
||||
Lesson.TYPE_SHIFTED_TARGET -> {
|
||||
otherLessonDate = lesson.oldDate
|
||||
when {
|
||||
lesson.date != lesson.oldDate -> b.shiftedText.setText(
|
||||
R.string.timetable_lesson_shifted_from_other_day,
|
||||
lesson.oldDate?.stringY_m_d ?: "?",
|
||||
lesson.oldStartTime?.stringHM ?: "?"
|
||||
)
|
||||
lesson.startTime != lesson.oldStartTime -> b.shiftedText.setText(
|
||||
R.string.timetable_lesson_shifted_from_same_day,
|
||||
lesson.oldStartTime?.stringHM ?: "?"
|
||||
)
|
||||
else -> b.shiftedText.setText(R.string.timetable_lesson_shifted_from)
|
||||
}
|
||||
}
|
||||
}
|
||||
b.shiftedGoTo.setOnClickListener {
|
||||
dialog.dismiss()
|
||||
val dateStr = otherLessonDate?.stringY_m_d ?: return@setOnClickListener
|
||||
val intent = Intent(TimetableFragment.ACTION_SCROLL_TO_DATE).apply {
|
||||
putExtra("date", dateStr)
|
||||
}
|
||||
activity.sendBroadcast(intent)
|
||||
}
|
||||
}
|
||||
else {
|
||||
b.shiftedLayout.visibility = View.GONE
|
||||
}
|
||||
|
||||
if (lesson.type < Lesson.TYPE_SHIFTED_SOURCE && lesson.oldSubjectId != null && lesson.subjectId != lesson.oldSubjectId) {
|
||||
b.oldSubjectName = lesson.oldSubjectName
|
||||
}
|
||||
if (lesson.type != Lesson.TYPE_CANCELLED && lesson.subjectId != null) {
|
||||
b.subjectName = lesson.subjectName
|
||||
}
|
||||
|
||||
if (lesson.type < Lesson.TYPE_SHIFTED_SOURCE && lesson.oldTeacherId != null && lesson.teacherId != lesson.oldTeacherId) {
|
||||
b.oldTeacherName = lesson.oldTeacherName
|
||||
}
|
||||
if (lesson.type != Lesson.TYPE_CANCELLED && lesson.teacherId != null) {
|
||||
b.teacherName = lesson.teacherName
|
||||
}
|
||||
|
||||
if (lesson.oldClassroom != null && lesson.classroom != lesson.oldClassroom) {
|
||||
b.oldClassroom = lesson.oldClassroom
|
||||
}
|
||||
if (lesson.type != Lesson.TYPE_CANCELLED && lesson.classroom != null) {
|
||||
b.classroom = lesson.classroom
|
||||
}
|
||||
|
||||
if (lesson.type < Lesson.TYPE_SHIFTED_SOURCE && lesson.oldTeamId != null && lesson.teamId != lesson.oldTeamId) {
|
||||
b.oldTeamName = lesson.oldTeamName
|
||||
}
|
||||
if (lesson.type != Lesson.TYPE_CANCELLED && lesson.teamId != null) {
|
||||
b.teamName = lesson.teamName
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@ -30,11 +31,14 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.work.WorkManager;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.chuckerteam.chucker.api.Chucker;
|
||||
import com.hypertrack.hyperlog.HyperLog;
|
||||
import com.mikepenz.iconics.IconicsColor;
|
||||
import com.mikepenz.iconics.IconicsDrawable;
|
||||
import com.mikepenz.iconics.IconicsSize;
|
||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -50,6 +54,7 @@ import pl.szczodrzynski.edziennik.databinding.CardLuckyNumberBinding;
|
||||
import pl.szczodrzynski.edziennik.databinding.CardUpdateBinding;
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentHomeBinding;
|
||||
import pl.szczodrzynski.edziennik.receivers.BootReceiver;
|
||||
import pl.szczodrzynski.edziennik.ui.modules.login.LoginLibrusCaptchaActivity;
|
||||
import pl.szczodrzynski.edziennik.ui.modules.messages.MessagesComposeActivity;
|
||||
import pl.szczodrzynski.edziennik.utils.Colors;
|
||||
import pl.szczodrzynski.edziennik.utils.Themes;
|
||||
@ -104,6 +109,27 @@ public class HomeFragment extends Fragment {
|
||||
|
||||
b.pruneWorkButton.setOnClickListener((v -> WorkManager.getInstance(app).pruneWork()));
|
||||
|
||||
b.runChucker.setOnClickListener((v -> {
|
||||
startActivity(Chucker.getLaunchIntent(activity, 1));
|
||||
}));
|
||||
|
||||
b.librusCaptchaButton.setOnClickListener((v -> {
|
||||
startActivity(new Intent(activity, LoginLibrusCaptchaActivity.class));
|
||||
}));
|
||||
|
||||
b.getLogs.setOnClickListener((v -> {
|
||||
File logs = HyperLog.getDeviceLogsInFile(activity, true);
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
|
||||
if(logs.exists()) {
|
||||
intent.setType("text/plain");
|
||||
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+logs.getAbsolutePath()));
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, "Share debug logs");
|
||||
intent.putExtra(Intent.EXTRA_TEXT, "Share debug logs");
|
||||
startActivity(Intent.createChooser(intent, "Share debug logs"));
|
||||
}
|
||||
}));
|
||||
|
||||
//((TextView)v.findViewById(R.id.nextSync)).setText(getString(R.string.next_sync_format,Time.fromMillis(app.appJobs.syncJobTime).getStringHMS()));
|
||||
|
||||
|
||||
|
@ -0,0 +1,132 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.homework;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.os.AsyncTask;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import pl.szczodrzynski.edziennik.App;
|
||||
import pl.szczodrzynski.edziennik.R;
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull;
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog;
|
||||
import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment;
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||
|
||||
import static pl.szczodrzynski.edziennik.utils.Utils.bs;
|
||||
|
||||
public class HomeworkAdapter extends RecyclerView.Adapter<HomeworkAdapter.ViewHolder> {
|
||||
private Context context;
|
||||
private List<EventFull> homeworkList;
|
||||
|
||||
//getting the context and product list with constructor
|
||||
public HomeworkAdapter(Context mCtx, List<EventFull> homeworkList) {
|
||||
this.context = mCtx;
|
||||
this.homeworkList = homeworkList;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
//inflating and returning our view holder
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate(R.layout.row_homework_item, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
public static String dayDiffString(Context context, int dayDiff) {
|
||||
if (dayDiff > 0) {
|
||||
if (dayDiff == 1) {
|
||||
return context.getString(R.string.tomorrow);
|
||||
}
|
||||
else if (dayDiff == 2) {
|
||||
return context.getString(R.string.the_day_after);
|
||||
}
|
||||
return HomeFragment.plural(context, R.plurals.time_till_days, Math.abs(dayDiff));
|
||||
}
|
||||
else if (dayDiff < 0) {
|
||||
if (dayDiff == -1) {
|
||||
return context.getString(R.string.yesterday);
|
||||
}
|
||||
else if (dayDiff == -2) {
|
||||
return context.getString(R.string.the_day_before);
|
||||
}
|
||||
return context.getString(R.string.ago_format, HomeFragment.plural(context, R.plurals.time_till_days, Math.abs(dayDiff)));
|
||||
}
|
||||
return context.getString(R.string.today);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
App app = (App) context.getApplicationContext();
|
||||
|
||||
EventFull homework = homeworkList.get(position);
|
||||
|
||||
int diffDays = Date.diffDays(homework.eventDate, Date.getToday());
|
||||
|
||||
holder.homeworkItemHomeworkDate.setText(app.getString(R.string.date_relative_format, homework.eventDate.getFormattedString(), dayDiffString(context, diffDays)));
|
||||
holder.homeworkItemTopic.setText(homework.topic);
|
||||
holder.homeworkItemSubjectTeacher.setText(context.getString(R.string.homework_subject_teacher_format, bs(homework.subjectLongName), bs(homework.teacherFullName)));
|
||||
holder.homeworkItemTeamDate.setText(context.getString(R.string.homework_team_date_format, bs(homework.teamName), Date.fromMillis(homework.addedDate).getFormattedStringShort()));
|
||||
|
||||
if (!homework.seen) {
|
||||
holder.homeworkItemTopic.setBackground(context.getResources().getDrawable(R.drawable.bg_rounded_8dp));
|
||||
holder.homeworkItemTopic.getBackground().setColorFilter(new PorterDuffColorFilter(0x692196f3, PorterDuff.Mode.MULTIPLY));
|
||||
homework.seen = true;
|
||||
AsyncTask.execute(() -> {
|
||||
app.db.metadataDao().setSeen(App.profileId, homework, true);
|
||||
});
|
||||
}
|
||||
else {
|
||||
holder.homeworkItemTopic.setBackground(null);
|
||||
}
|
||||
|
||||
holder.homeworkItemEdit.setVisibility((homework.addedManually ? View.VISIBLE : View.GONE));
|
||||
holder.homeworkItemEdit.setOnClickListener(v -> {
|
||||
new EventManualDialog(context).show(app, homework, null, null, EventManualDialog.DIALOG_HOMEWORK);
|
||||
});
|
||||
|
||||
if (homework.sharedBy == null) {
|
||||
holder.homeworkItemSharedBy.setVisibility(View.GONE);
|
||||
}
|
||||
else if (homework.sharedByName != null) {
|
||||
holder.homeworkItemSharedBy.setText(app.getString(R.string.event_shared_by_format, (homework.sharedBy.equals("self") ? app.getString(R.string.event_shared_by_self) : homework.sharedByName)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return homeworkList.size();
|
||||
}
|
||||
|
||||
class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
CardView homeworkItemCard;
|
||||
TextView homeworkItemTopic;
|
||||
TextView homeworkItemHomeworkDate;
|
||||
TextView homeworkItemSharedBy;
|
||||
TextView homeworkItemSubjectTeacher;
|
||||
TextView homeworkItemTeamDate;
|
||||
Button homeworkItemEdit;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
homeworkItemCard = itemView.findViewById(R.id.homeworkItemCard);
|
||||
homeworkItemTopic = itemView.findViewById(R.id.homeworkItemTopic);
|
||||
homeworkItemHomeworkDate = itemView.findViewById(R.id.homeworkItemHomeworkDate);
|
||||
homeworkItemSharedBy = itemView.findViewById(R.id.homeworkItemSharedBy);
|
||||
homeworkItemSubjectTeacher = itemView.findViewById(R.id.homeworkItemSubjectTeacher);
|
||||
homeworkItemTeamDate = itemView.findViewById(R.id.homeworkItemTeamDate);
|
||||
homeworkItemEdit = itemView.findViewById(R.id.homeworkItemEdit);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,77 +1,84 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.homework
|
||||
|
||||
import android.os.AsyncTask
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentHomeworkBinding
|
||||
import pl.szczodrzynski.edziennik.ui.base.BaseFragment
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog
|
||||
import pl.szczodrzynski.edziennik.ui.modules.homework.list.HomeworkListFragment
|
||||
import pl.szczodrzynski.edziennik.ui.modules.messages.MessagesFragment
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetPrimaryItem
|
||||
import pl.szczodrzynski.navlib.bottomsheet.items.BottomSheetSeparatorItem
|
||||
import javax.inject.Inject
|
||||
|
||||
class HomeworkFragment : BaseFragment<HomeworkPresenter>(), HomeworkView {
|
||||
class HomeworkFragment : Fragment() {
|
||||
companion object {
|
||||
var pageSelection = 0
|
||||
}
|
||||
|
||||
private lateinit var app: App
|
||||
private lateinit var activity: MainActivity
|
||||
private lateinit var b: FragmentHomeworkBinding
|
||||
|
||||
@Inject
|
||||
override lateinit var presenter: HomeworkPresenter
|
||||
|
||||
@Inject
|
||||
lateinit var app: App
|
||||
|
||||
override val markAsReadSuccessString: String
|
||||
get() = getString(R.string.main_menu_mark_as_read_success)
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
presenter.onAttachView(this)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
activity = (getActivity() as MainActivity)
|
||||
activity = (getActivity() as MainActivity?) ?: return null
|
||||
if (context == null)
|
||||
return null
|
||||
app = activity.application as App
|
||||
context!!.theme.applyStyle(Themes.appTheme, true)
|
||||
if (app.profile == null)
|
||||
return inflater.inflate(R.layout.fragment_loading, container, false)
|
||||
// activity, context and profile is valid
|
||||
b = FragmentHomeworkBinding.inflate(inflater)
|
||||
b.refreshLayout.setParent(activity.swipeRefreshLayout)
|
||||
return b.root
|
||||
}
|
||||
|
||||
override fun initView() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
// TODO check if app, activity, b can be null
|
||||
if (app.profile == null || !isAdded)
|
||||
return
|
||||
|
||||
b.refreshLayout.setParent(activity.swipeRefreshLayout)
|
||||
|
||||
activity.bottomSheet.prependItems(
|
||||
BottomSheetPrimaryItem(true)
|
||||
.withTitle(R.string.menu_add_event)
|
||||
.withDescription(R.string.menu_add_event_desc)
|
||||
.withIcon(CommunityMaterial.Icon.cmd_calendar_plus)
|
||||
.withOnClickListener(View.OnClickListener { presenter.onAddEventClick() }),
|
||||
BottomSheetSeparatorItem(true),
|
||||
BottomSheetPrimaryItem(true)
|
||||
.withTitle(R.string.menu_mark_as_read)
|
||||
.withIcon(CommunityMaterial.Icon.cmd_eye_check)
|
||||
.withOnClickListener(View.OnClickListener { presenter.onMarkAsReadClick() }))
|
||||
.withTitle(R.string.menu_add_event)
|
||||
.withDescription(R.string.menu_add_event_desc)
|
||||
.withIcon(CommunityMaterial.Icon.cmd_calendar_plus)
|
||||
.withOnClickListener(View.OnClickListener {
|
||||
activity.bottomSheet.close()
|
||||
EventManualDialog(activity).show(app, null, null, null, EventManualDialog.DIALOG_HOMEWORK)
|
||||
}),
|
||||
BottomSheetSeparatorItem(true),
|
||||
BottomSheetPrimaryItem(true)
|
||||
.withTitle(R.string.menu_mark_as_read)
|
||||
.withIcon(CommunityMaterial.Icon.cmd_eye_check)
|
||||
.withOnClickListener(View.OnClickListener {
|
||||
activity.bottomSheet.close()
|
||||
AsyncTask.execute { app.db.metadataDao().setAllSeen(App.profileId, Metadata.TYPE_HOMEWORK, true) }
|
||||
Toast.makeText(activity, R.string.main_menu_mark_as_read_success, Toast.LENGTH_SHORT).show()
|
||||
}))
|
||||
|
||||
b.viewPager.adapter = MessagesFragment.Adapter(childFragmentManager).also { adapter ->
|
||||
adapter.addFragment(HomeworkListFragment.newInstance(HomeworkDate.CURRENT), getString(R.string.homework_tab_current))
|
||||
adapter.addFragment(HomeworkListFragment.newInstance(HomeworkDate.PAST), getString(R.string.homework_tab_past))
|
||||
adapter.addFragment(HomeworkListFragment().also { fragment ->
|
||||
fragment.arguments = Bundle().also { args ->
|
||||
args.putInt("homeworkDate", HomeworkDate.CURRENT)
|
||||
}
|
||||
}, getString(R.string.homework_tab_current))
|
||||
|
||||
adapter.addFragment(HomeworkListFragment().also { fragment ->
|
||||
fragment.arguments = Bundle().also { args ->
|
||||
args.putInt("homeworkDate", HomeworkDate.PAST)
|
||||
}
|
||||
}, getString(R.string.homework_tab_past))
|
||||
}
|
||||
|
||||
b.viewPager.currentItem = pageSelection
|
||||
@ -79,7 +86,9 @@ class HomeworkFragment : BaseFragment<HomeworkPresenter>(), HomeworkView {
|
||||
b.viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||
override fun onPageScrollStateChanged(state: Int) {}
|
||||
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
|
||||
override fun onPageSelected(position: Int) = presenter.onPageSelected(position)
|
||||
override fun onPageSelected(position: Int) {
|
||||
pageSelection = position
|
||||
}
|
||||
})
|
||||
|
||||
b.tabLayout.setupWithViewPager(b.viewPager)
|
||||
@ -87,21 +96,11 @@ class HomeworkFragment : BaseFragment<HomeworkPresenter>(), HomeworkView {
|
||||
activity.navView.bottomBar.fabEnable = true
|
||||
activity.navView.bottomBar.fabExtendedText = getString(R.string.add)
|
||||
activity.navView.bottomBar.fabIcon = CommunityMaterial.Icon2.cmd_plus
|
||||
activity.navView.setFabOnClickListener(View.OnClickListener { presenter.onHomeworkAddFabClick() })
|
||||
activity.navView.setFabOnClickListener(View.OnClickListener {
|
||||
EventManualDialog(activity).show(app, null, null, null, EventManualDialog.DIALOG_HOMEWORK)
|
||||
})
|
||||
|
||||
activity.gainAttention()
|
||||
activity.gainAttentionFAB()
|
||||
}
|
||||
|
||||
override fun setPageSelection(position: Int) {
|
||||
pageSelection = position
|
||||
}
|
||||
|
||||
override fun closeBottomSheet() {
|
||||
activity.bottomSheet.close()
|
||||
}
|
||||
|
||||
override fun showAddHomeworkDialog() {
|
||||
EventManualDialog(activity).show(app, null, null, null, EventManualDialog.DIALOG_HOMEWORK)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,77 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.homework
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.databinding.HomeworkListBinding
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.Event
|
||||
import pl.szczodrzynski.edziennik.getInt
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
|
||||
class HomeworkListFragment : Fragment() {
|
||||
|
||||
private lateinit var app: App
|
||||
private lateinit var activity: MainActivity
|
||||
private lateinit var b: HomeworkListBinding
|
||||
|
||||
private var homeworkDate = HomeworkDate.CURRENT
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
activity = (getActivity() as MainActivity?) ?: return null
|
||||
if (context == null)
|
||||
return null
|
||||
app = activity.application as App
|
||||
context!!.theme.applyStyle(Themes.appTheme, true)
|
||||
if (app.profile == null)
|
||||
return inflater.inflate(R.layout.fragment_loading, container, false)
|
||||
// activity, context and profile is valid
|
||||
b = HomeworkListBinding.inflate(inflater)
|
||||
return b.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
// TODO check if app, activity, b can be null
|
||||
if (app.profile == null || !isAdded)
|
||||
return
|
||||
|
||||
if (arguments != null) {
|
||||
homeworkDate = arguments.getInt("homeworkDate", HomeworkDate.CURRENT)
|
||||
}
|
||||
|
||||
val layoutManager = LinearLayoutManager(context)
|
||||
layoutManager.reverseLayout = true
|
||||
layoutManager.stackFromEnd = true
|
||||
|
||||
b.homeworkView.setHasFixedSize(true)
|
||||
b.homeworkView.layoutManager = layoutManager
|
||||
|
||||
val filter = when(homeworkDate) {
|
||||
HomeworkDate.CURRENT -> "eventDate > '" + Date.getToday().stringY_m_d + "'"
|
||||
else -> "eventDate <= '" + Date.getToday().stringY_m_d + "'"
|
||||
}
|
||||
|
||||
app.db.eventDao()
|
||||
.getAllByType(App.profileId, Event.TYPE_HOMEWORK, filter)
|
||||
.observe(this, Observer { homeworkList ->
|
||||
if (app.profile == null || !isAdded) return@Observer
|
||||
|
||||
if (homeworkList != null && homeworkList.size > 0) {
|
||||
val adapter = HomeworkAdapter(context, homeworkList)
|
||||
b.homeworkView.adapter = adapter
|
||||
b.homeworkView.visibility = View.VISIBLE
|
||||
b.homeworkNoData.visibility = View.GONE
|
||||
} else {
|
||||
b.homeworkView.visibility = View.GONE
|
||||
b.homeworkNoData.visibility = View.VISIBLE
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.modules.homework
|
||||
|
||||
import android.os.AsyncTask
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.MetadataDao
|
||||
import pl.szczodrzynski.edziennik.ui.base.BasePresenter
|
||||
import javax.inject.Inject
|
||||
|
||||
class HomeworkPresenter @Inject constructor(
|
||||
private val metadataDao: MetadataDao
|
||||
) : BasePresenter<HomeworkView>() {
|
||||
|
||||
override fun onAttachView(view: HomeworkView) {
|
||||
super.onAttachView(view)
|
||||
view.initView()
|
||||
}
|
||||
|
||||
fun onPageSelected(position: Int) {
|
||||
view?.setPageSelection(position)
|
||||
}
|
||||
|
||||
fun onAddEventClick() {
|
||||
view?.apply {
|
||||
closeBottomSheet()
|
||||
showAddHomeworkDialog()
|
||||
}
|
||||
}
|
||||
|
||||
fun onMarkAsReadClick() {
|
||||
view?.apply {
|
||||
closeBottomSheet()
|
||||
AsyncTask.execute {
|
||||
metadataDao.setAllSeen(App.profileId, Metadata.TYPE_HOMEWORK, true)
|
||||
}
|
||||
showMessage(markAsReadSuccessString)
|
||||
}
|
||||
}
|
||||
|
||||
fun onHomeworkAddFabClick() {
|
||||
view?.showAddHomeworkDialog()
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.modules.homework
|
||||
|
||||
import pl.szczodrzynski.edziennik.ui.base.BaseView
|
||||
|
||||
interface HomeworkView : BaseView {
|
||||
|
||||
val markAsReadSuccessString: String
|
||||
|
||||
fun initView()
|
||||
|
||||
fun closeBottomSheet()
|
||||
|
||||
fun showAddHomeworkDialog()
|
||||
|
||||
fun setPageSelection(position: Int)
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.modules.homework.list
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.PorterDuffColorFilter
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.AsyncTask
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.MetadataDao
|
||||
import pl.szczodrzynski.edziennik.databinding.RowHomeworkItemBinding
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.bs
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.abs
|
||||
|
||||
class HomeworkListAdapter @Inject constructor(
|
||||
private val metadataDao: MetadataDao
|
||||
) : RecyclerView.Adapter<HomeworkListAdapter.ViewHolder>() {
|
||||
|
||||
val homeworkList: MutableList<EventFull> = mutableListOf()
|
||||
lateinit var onItemEditClick: (homework: EventFull) -> Unit
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val b: RowHomeworkItemBinding = DataBindingUtil.inflate(inflater, R.layout.row_homework_item, parent, false)
|
||||
return ViewHolder(b)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val homework = homeworkList[position]
|
||||
|
||||
holder.apply {
|
||||
val diffDaysString = dateDiffString(Date.diffDays(homework.eventDate, Date.getToday()))
|
||||
|
||||
b.homeworkItemHomeworkDate.text = getString(R.string.date_relative_format, homework.eventDate.formattedString, diffDaysString)
|
||||
b.homeworkItemTopic.text = homework.topic
|
||||
b.homeworkItemSubjectTeacher.text = getString(R.string.homework_subject_teacher_format, bs(homework.subjectLongName), bs(homework.teacherFullName))
|
||||
b.homeworkItemTeamDate.text = getString(R.string.homework_team_date_format, bs(homework.teamName), Date.fromMillis(homework.addedDate).formattedStringShort)
|
||||
|
||||
when {
|
||||
!homework.seen -> {
|
||||
b.homeworkItemTopic.apply {
|
||||
background = getDrawable(R.drawable.bg_rounded_8dp)
|
||||
background.colorFilter = PorterDuffColorFilter(0x692196f3, PorterDuff.Mode.MULTIPLY)
|
||||
}
|
||||
|
||||
homework.seen = true
|
||||
AsyncTask.execute {
|
||||
metadataDao.setSeen(App.profileId, homework, true)
|
||||
}
|
||||
}
|
||||
else -> b.homeworkItemTopic.background = null
|
||||
}
|
||||
|
||||
b.homeworkItemEdit.apply {
|
||||
visibility = if (homework.addedManually) VISIBLE else GONE
|
||||
setOnClickListener { onItemEditClick(homework) }
|
||||
}
|
||||
|
||||
b.homeworkItemSharedBy.apply {
|
||||
when {
|
||||
homework.sharedBy == null -> visibility = GONE
|
||||
homework.sharedByName != null -> text = getString(R.string.event_shared_by_format,
|
||||
when (homework.sharedBy == "self") {
|
||||
true -> getString(R.string.event_shared_by_self)
|
||||
else -> homework.sharedByName
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount() = homeworkList.size
|
||||
|
||||
class ViewHolder(val b: RowHomeworkItemBinding) : RecyclerView.ViewHolder(b.root) {
|
||||
fun getString(resId: Int): String = itemView.context.getString(resId)
|
||||
fun getString(resId: Int, vararg formatArgs: Any): String = itemView.context.getString(resId, *formatArgs)
|
||||
fun getDrawable(resId: Int): Drawable? = ContextCompat.getDrawable(itemView.context, resId)
|
||||
|
||||
val resources: Resources get() = itemView.context.resources
|
||||
|
||||
fun dateDiffString(diff: Int): String {
|
||||
return when {
|
||||
diff > 0 -> when (diff) {
|
||||
1 -> getString(R.string.tomorrow)
|
||||
2 -> getString(R.string.the_day_after)
|
||||
else -> resources.getQuantityString(R.plurals.time_till_days, abs(diff), abs(diff))
|
||||
}
|
||||
diff < 0 -> when (diff) {
|
||||
-1 -> getString(R.string.yesterday)
|
||||
-2 -> getString(R.string.the_day_before)
|
||||
else -> getString(R.string.ago_format, resources.getQuantityString(R.plurals.time_till_days, abs(diff), abs(diff)))
|
||||
}
|
||||
else -> getString(R.string.today)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.modules.homework.list
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull
|
||||
import pl.szczodrzynski.edziennik.databinding.HomeworkListBinding
|
||||
import pl.szczodrzynski.edziennik.ui.base.BaseFragment
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.event.EventManualDialog
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
import javax.inject.Inject
|
||||
|
||||
class HomeworkListFragment : BaseFragment<HomeworkListPresenter>(), HomeworkListView {
|
||||
|
||||
private lateinit var activity: MainActivity
|
||||
private lateinit var b: HomeworkListBinding
|
||||
|
||||
@Inject
|
||||
override lateinit var presenter: HomeworkListPresenter
|
||||
|
||||
@Inject
|
||||
lateinit var app: App
|
||||
|
||||
@Inject
|
||||
lateinit var homeworkAdapter: HomeworkListAdapter
|
||||
|
||||
override val viewLifecycle: Lifecycle
|
||||
get() = lifecycle
|
||||
|
||||
companion object {
|
||||
private const val ARGUMENT_KEY = "homeworkDate"
|
||||
|
||||
fun newInstance(homeworkDate: Int) = HomeworkListFragment().apply {
|
||||
arguments = Bundle().apply { putInt(ARGUMENT_KEY, homeworkDate) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
presenter.onAttachView(this, arguments?.getInt(ARGUMENT_KEY))
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
activity = (getActivity() as MainActivity?) ?: return null
|
||||
if (context == null)
|
||||
return null
|
||||
context!!.theme.applyStyle(Themes.appTheme, true)
|
||||
if (app.profile == null)
|
||||
return inflater.inflate(R.layout.fragment_loading, container, false)
|
||||
// activity, context and profile is valid
|
||||
b = HomeworkListBinding.inflate(inflater)
|
||||
return b.root
|
||||
}
|
||||
|
||||
override fun initView() {
|
||||
// TODO check if app, activity, b can be null
|
||||
if (app.profile == null || !isAdded)
|
||||
return
|
||||
|
||||
val layoutManager = LinearLayoutManager(context).apply {
|
||||
reverseLayout = true
|
||||
stackFromEnd = true
|
||||
}
|
||||
|
||||
homeworkAdapter.onItemEditClick = presenter::onItemEditClick
|
||||
|
||||
b.homeworkView.apply {
|
||||
setHasFixedSize(true)
|
||||
this.layoutManager = layoutManager
|
||||
adapter = homeworkAdapter
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateData(data: List<EventFull>) {
|
||||
homeworkAdapter.apply {
|
||||
homeworkList.apply {
|
||||
clear()
|
||||
addAll(data)
|
||||
}
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
override fun showContent(show: Boolean) {
|
||||
b.homeworkView.visibility = if (show) VISIBLE else GONE
|
||||
}
|
||||
|
||||
override fun showNoData(show: Boolean) {
|
||||
b.homeworkNoData.visibility = if (show) VISIBLE else GONE
|
||||
}
|
||||
|
||||
override fun showEditHomeworkDialog(homework: EventFull) {
|
||||
EventManualDialog(context).show(app, homework, null, null, EventManualDialog.DIALOG_HOMEWORK)
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.modules.homework.list
|
||||
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.EventDao
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull
|
||||
import pl.szczodrzynski.edziennik.ui.base.BasePresenter
|
||||
import pl.szczodrzynski.edziennik.ui.modules.homework.HomeworkDate
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import javax.inject.Inject
|
||||
|
||||
class HomeworkListPresenter @Inject constructor(
|
||||
private val app: App,
|
||||
private val eventDao: EventDao
|
||||
) : BasePresenter<HomeworkListView>() {
|
||||
|
||||
fun onAttachView(view: HomeworkListView, homeworkDate: Int?) {
|
||||
super.onAttachView(view)
|
||||
view.initView()
|
||||
loadData(homeworkDate ?: HomeworkDate.CURRENT)
|
||||
}
|
||||
|
||||
private fun loadData(homeworkDate: Int) {
|
||||
val today = Date.getToday().stringY_m_d
|
||||
|
||||
val filter = when (homeworkDate) {
|
||||
HomeworkDate.CURRENT -> "eventDate > '$today'"
|
||||
else -> "eventDate <= '$today'"
|
||||
}
|
||||
|
||||
view?.run {
|
||||
eventDao.getAllByType(App.profileId, Event.TYPE_HOMEWORK, filter)
|
||||
.observe({ viewLifecycle }, { homeworkList ->
|
||||
if (app.profile == null) return@observe
|
||||
|
||||
if (homeworkList != null && homeworkList.size > 0) {
|
||||
updateData(homeworkList)
|
||||
showContent(true)
|
||||
showNoData(false)
|
||||
} else {
|
||||
showContent(false)
|
||||
showNoData(true)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fun onItemEditClick(homework: EventFull) {
|
||||
view?.showEditHomeworkDialog(homework)
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.modules.homework.list
|
||||
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull
|
||||
import pl.szczodrzynski.edziennik.ui.base.BaseView
|
||||
|
||||
interface HomeworkListView : BaseView {
|
||||
|
||||
val viewLifecycle: Lifecycle
|
||||
|
||||
fun initView()
|
||||
|
||||
fun updateData(data: List<EventFull>)
|
||||
|
||||
fun showContent(show: Boolean)
|
||||
|
||||
fun showNoData(show: Boolean)
|
||||
|
||||
fun showEditHomeworkDialog(homework: EventFull)
|
||||
}
|
@ -26,6 +26,7 @@ public class LoginChooserFragment extends Fragment {
|
||||
private NavController nav;
|
||||
private FragmentLoginChooserBinding b;
|
||||
private static final String TAG = "LoginTemplate";
|
||||
public static boolean fakeLogin = false;
|
||||
|
||||
public LoginChooserFragment() { }
|
||||
|
||||
@ -71,6 +72,10 @@ public class LoginChooserFragment extends Fragment {
|
||||
b.cancelButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
b.fakeLogin.setVisibility(App.devMode ? View.VISIBLE : View.GONE);
|
||||
b.fakeLogin.setChecked(fakeLogin);
|
||||
b.fakeLogin.setOnCheckedChangeListener((v, isChecked) -> fakeLogin = isChecked);
|
||||
|
||||
b.helpButton.setOnClickListener((v -> {
|
||||
startActivity(new Intent(getActivity(), FeedbackActivity.class));
|
||||
}));
|
||||
|
@ -0,0 +1,116 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.login
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Base64
|
||||
import android.webkit.JavascriptInterface
|
||||
import android.webkit.WebView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.api.v2.LIBRUS_USER_AGENT
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.hexFromColorInt
|
||||
import java.nio.charset.Charset
|
||||
|
||||
class LoginLibrusCaptchaActivity : AppCompatActivity() {
|
||||
companion object {
|
||||
private const val TAG = "LoginLibrusCaptchaActivity"
|
||||
}
|
||||
|
||||
private lateinit var webView: WebView
|
||||
private lateinit var dialog: AlertDialog
|
||||
private lateinit var jsInterface: CaptchaCallbackInterface
|
||||
|
||||
@SuppressLint("AddJavascriptInterface", "SetJavaScriptEnabled")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setTheme(Themes.appThemeNoDisplay)
|
||||
setFinishOnTouchOutside(false)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
WebView.setWebContentsDebuggingEnabled(true)
|
||||
}
|
||||
|
||||
val base64Content = """
|
||||
PCFET0NUWVBFIGh0bWw+PGh0bWw+PGhlYWQ+PHNjcmlwdCBzcmM9Imh0dHBzOi8vd3d3Lmdvb2ds
|
||||
ZS5jb20vcmVjYXB0Y2hhL2FwaS5qcz9vbmxvYWQ9cmVhZHkmcmVuZGVyPWV4cGxpY2l0Ij48L3Nj
|
||||
cmlwdD48L2hlYWQ+PGJvZHk+PGJyPjxjZW50ZXIgaWQ9ImdyIj48L2NlbnRlcj48YnI+PHNjcmlw
|
||||
dD5mdW5jdGlvbiByZWFkeSgpe2dyZWNhcHRjaGEucmVuZGVyKCdncicse3NpdGVrZXk6JzZMZjQ4
|
||||
bW9VQUFBQUFCOUNsaGR2SHI0NmdSV1ItQ04zMUNYUVBHMlUnLHRoZW1lOidUSEVNRScsY2FsbGJh
|
||||
Y2s6ZnVuY3Rpb24oZSl7d2luZG93LmlmLmNhbGxiYWNrKGUpO30sImV4cGlyZWQtY2FsbGJhY2si
|
||||
OmZ1bmN0aW9uKCl7d2luZG93LmlmLmV4cGlyZWRDYWxsYmFjayhlKTt9LCJlcnJvci1jYWxsYmFj
|
||||
ayI6ZnVuY3Rpb24oKXt3aW5kb3cuaWYuZXJyb3JDYWxsYmFjayhlKTt9fSk7fTwvc2NyaXB0Pjwv
|
||||
Ym9keT48L2h0bWw+"""
|
||||
|
||||
val backgroundColor = if (Themes.isDark) 0x424242 else 0xffffff
|
||||
val backgroundColorString = hexFromColorInt(backgroundColor)
|
||||
|
||||
val htmlContent = Base64.decode(base64Content, Base64.DEFAULT)
|
||||
.toString(Charset.defaultCharset())
|
||||
.replace("COLOR", backgroundColorString, true)
|
||||
.replace("THEME", if (Themes.isDark) "dark" else "light")
|
||||
|
||||
jsInterface = object : CaptchaCallbackInterface {
|
||||
@JavascriptInterface
|
||||
override fun callback(recaptchaResponse: String) {
|
||||
MaterialDialog.Builder(this@LoginLibrusCaptchaActivity)
|
||||
.title("Captcha checked")
|
||||
.content("Response: $recaptchaResponse")
|
||||
.positiveText("OK")
|
||||
.show()
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
override fun expiredCallback() {
|
||||
MaterialDialog.Builder(this@LoginLibrusCaptchaActivity)
|
||||
.title("Captcha expired")
|
||||
.content("Captcha expired")
|
||||
.positiveText("OK")
|
||||
.show()
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
override fun errorCallback() {
|
||||
MaterialDialog.Builder(this@LoginLibrusCaptchaActivity)
|
||||
.title("Captcha error")
|
||||
.content("Captcha error")
|
||||
.positiveText("OK")
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
webView = WebView(this).apply {
|
||||
//setBackgroundColor((backgroundColor.toLong() or 0xff000000).toInt())
|
||||
setBackgroundColor(Color.TRANSPARENT)
|
||||
settings.javaScriptEnabled = true
|
||||
settings.userAgentString = LIBRUS_USER_AGENT
|
||||
addJavascriptInterface(jsInterface, "if")
|
||||
loadDataWithBaseURL("https://portal.librus.pl/rodzina/login/", htmlContent, "text/html", "UTF-8", null)
|
||||
setLayerType(WebView.LAYER_TYPE_SOFTWARE, null)
|
||||
}
|
||||
|
||||
dialog = MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.login_librus_captcha_title)
|
||||
.setView(webView)
|
||||
.setNegativeButton(R.string.cancel) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
finish()
|
||||
}
|
||||
.setCancelable(false)
|
||||
.show()
|
||||
}
|
||||
|
||||
interface CaptchaCallbackInterface {
|
||||
@JavascriptInterface
|
||||
fun callback(recaptchaResponse: String)
|
||||
@JavascriptInterface
|
||||
fun expiredCallback()
|
||||
@JavascriptInterface
|
||||
fun errorCallback()
|
||||
}
|
||||
}
|
@ -89,6 +89,10 @@ public class LoginProgressFragment extends Fragment {
|
||||
LoginStore loginStore = new LoginStore(-1, loginType, new JsonObject());
|
||||
loginStore.copyFrom(args);
|
||||
|
||||
if (App.devMode && LoginChooserFragment.fakeLogin) {
|
||||
loginStore.putLoginData("fakeLogin", true);
|
||||
}
|
||||
|
||||
EdziennikTask.Companion.firstLogin(loginStore).enqueue(getContext());
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,319 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-11-12.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.modules.messages
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.text.Html
|
||||
import android.text.TextUtils
|
||||
import android.view.Gravity.CENTER_VERTICAL
|
||||
import android.view.Gravity.END
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ProgressBar
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.mikepenz.iconics.IconicsColor
|
||||
import com.mikepenz.iconics.IconicsDrawable
|
||||
import com.mikepenz.iconics.IconicsSize
|
||||
import com.mikepenz.iconics.typeface.IIcon
|
||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
||||
import com.mikepenz.iconics.utils.sizeDp
|
||||
import kotlinx.coroutines.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.api.v2.events.MessageGetEvent
|
||||
import pl.szczodrzynski.edziennik.api.v2.events.task.EdziennikTask
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message.TYPE_SENT
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||
import pl.szczodrzynski.edziennik.databinding.MessageFragmentBinding
|
||||
import pl.szczodrzynski.edziennik.onClick
|
||||
import pl.szczodrzynski.edziennik.utils.Anim
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.getStringFromFile
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.readableFileSize
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
import pl.szczodrzynski.navlib.colorAttr
|
||||
import java.io.File
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.math.min
|
||||
|
||||
class MessageFragment : Fragment(), CoroutineScope {
|
||||
companion object {
|
||||
private const val TAG = "MessageFragment"
|
||||
}
|
||||
|
||||
private lateinit var app: App
|
||||
private lateinit var activity: MainActivity
|
||||
private lateinit var b: MessageFragmentBinding
|
||||
|
||||
private lateinit var job: Job
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = job + Dispatchers.Main
|
||||
|
||||
private lateinit var message: MessageFull
|
||||
private var attachmentList = mutableListOf<Attachment>()
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
activity = (getActivity() as MainActivity?) ?: return null
|
||||
context ?: return null
|
||||
app = activity.application as App
|
||||
context!!.theme.applyStyle(Themes.appTheme, true)
|
||||
b = MessageFragmentBinding.inflate(inflater)
|
||||
job = Job()
|
||||
return b.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
// TODO check if app, activity, b can be null
|
||||
if (app.profile == null || !isAdded)
|
||||
return
|
||||
|
||||
b.closeButton.setImageDrawable(
|
||||
IconicsDrawable(activity, CommunityMaterial.Icon2.cmd_window_close)
|
||||
.colorAttr(activity, android.R.attr.textColorSecondary)
|
||||
.sizeDp(12)
|
||||
)
|
||||
b.closeButton.setOnClickListener { activity.navigateUp() }
|
||||
|
||||
val messageId = arguments?.getLong("messageId")
|
||||
if (messageId == null) {
|
||||
activity.navigateUp()
|
||||
return
|
||||
}
|
||||
|
||||
launch {
|
||||
val deferred = async(Dispatchers.Default) {
|
||||
val msg = app.db.messageDao().getById(App.profileId, messageId)?.also {
|
||||
it.recipients = app.db.messageRecipientDao().getAllByMessageId(it.profileId, it.id)
|
||||
if (it.body != null && !it.seen) {
|
||||
app.db.metadataDao().setSeen(it.profileId, message, true)
|
||||
}
|
||||
}
|
||||
msg
|
||||
}
|
||||
val msg = deferred.await() ?: run {
|
||||
return@launch
|
||||
}
|
||||
message = msg
|
||||
b.subject.text = message.subject
|
||||
checkMessage()
|
||||
}
|
||||
|
||||
// click to expand subject and sender
|
||||
b.subject.onClick {
|
||||
it.maxLines = if (it.maxLines == 30) 2 else 30
|
||||
}
|
||||
b.sender.onClick {
|
||||
it.maxLines = if (it.maxLines == 30) 2 else 30
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
||||
fun onMessageGetEvent(event: MessageGetEvent) {
|
||||
// TODO remove this: message = event.message
|
||||
showMessage()
|
||||
}
|
||||
|
||||
private fun checkMessage() {
|
||||
if (message.body == null) {
|
||||
EdziennikTask.messageGet(App.profileId, message).enqueue(activity)
|
||||
return
|
||||
}
|
||||
|
||||
var readByAll = true
|
||||
message.recipients?.forEach { recipient ->
|
||||
if (recipient.id == -1L)
|
||||
recipient.fullName = app.profile.accountNameLong ?: app.profile.studentNameLong
|
||||
if (message.type == TYPE_SENT && recipient.readDate < 1)
|
||||
readByAll = false
|
||||
}
|
||||
// if a sent msg is not read by everyone, download it again to check the read status
|
||||
if (!readByAll) {
|
||||
EdziennikTask.messageGet(App.profileId, message).enqueue(activity)
|
||||
return
|
||||
}
|
||||
|
||||
showMessage()
|
||||
}
|
||||
|
||||
private fun showMessage() {
|
||||
b.body.text = Html.fromHtml(message.body?.replace("\\[META:[A-z0-9]+;[0-9-]+]".toRegex(), ""))
|
||||
b.date.text = getString(R.string.messages_date_time_format, Date.fromMillis(message.addedDate).formattedStringShort, Time.fromMillis(message.addedDate).stringHM)
|
||||
|
||||
val messageInfo = MessagesUtils.getMessageInfo(app, message, 40, 20, 14, 10)
|
||||
b.profileBackground.setImageBitmap(messageInfo.profileImage)
|
||||
b.sender.text = messageInfo.profileName
|
||||
|
||||
b.subject.text = message.subject
|
||||
|
||||
val messageRecipients = StringBuilder("<ul>")
|
||||
message.recipients?.forEach { recipient ->
|
||||
when (recipient.readDate) {
|
||||
-1L -> messageRecipients.append(getString(
|
||||
R.string.messages_recipients_list_unknown_state_format,
|
||||
recipient.fullName
|
||||
))
|
||||
0L -> messageRecipients.append(getString(
|
||||
R.string.messages_recipients_list_unread_format,
|
||||
recipient.fullName
|
||||
))
|
||||
1L -> messageRecipients.append(getString(
|
||||
R.string.messages_recipients_list_read_unknown_date_format,
|
||||
recipient.fullName
|
||||
))
|
||||
else -> messageRecipients.append(getString(
|
||||
R.string.messages_recipients_list_read_format,
|
||||
recipient.fullName,
|
||||
Date.fromMillis(recipient.readDate).formattedString,
|
||||
Time.fromMillis(recipient.readDate).stringHM
|
||||
))
|
||||
}
|
||||
}
|
||||
messageRecipients.append("</ul>")
|
||||
b.recipients.text = Html.fromHtml(messageRecipients.toString())
|
||||
|
||||
showAttachments()
|
||||
|
||||
b.progress.visibility = View.GONE
|
||||
Anim.fadeIn(b.content, 200, null)
|
||||
MessagesFragment.pageSelection = min(message.type, 1)
|
||||
}
|
||||
|
||||
private fun showAttachments() {
|
||||
if (message.attachmentIds != null) {
|
||||
val insertPoint = b.attachments
|
||||
|
||||
val chipLayoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
chipLayoutParams.setMargins(0, Utils.dpToPx(8), 0, Utils.dpToPx(8))
|
||||
|
||||
val progressLayoutParams = FrameLayout.LayoutParams(Utils.dpToPx(18), Utils.dpToPx(18))
|
||||
progressLayoutParams.setMargins(Utils.dpToPx(8), 0, Utils.dpToPx(8), 0)
|
||||
progressLayoutParams.gravity = END or CENTER_VERTICAL
|
||||
|
||||
// CREATE VIEWS AND AN OBJECT FOR EVERY ATTACHMENT
|
||||
|
||||
message.attachmentNames.forEachIndexed { index, name ->
|
||||
val messageId = message.id
|
||||
val id = message.attachmentIds[index]
|
||||
val size = message.attachmentSizes[index]
|
||||
// create the parent
|
||||
val attachmentLayout = FrameLayout(b.root.context)
|
||||
attachmentLayout.setPadding(Utils.dpToPx(16), 0, Utils.dpToPx(16), 0)
|
||||
|
||||
val attachmentChip = Chip(attachmentLayout.context)
|
||||
//attachmentChip.setChipBackgroundColorResource(ThemeUtils.getChipColorRes());
|
||||
attachmentChip.layoutParams = chipLayoutParams
|
||||
attachmentChip.height = Utils.dpToPx(40)
|
||||
|
||||
// show the file size or not
|
||||
if (size == -1L)
|
||||
attachmentChip.text = getString(R.string.messages_attachment_no_size_format, name)
|
||||
else
|
||||
attachmentChip.text = getString(R.string.messages_attachment_format, name, readableFileSize(size))
|
||||
attachmentChip.ellipsize = TextUtils.TruncateAt.MIDDLE
|
||||
|
||||
// create an icon for the attachment
|
||||
var icon: IIcon = CommunityMaterial.Icon.cmd_file
|
||||
when (Utils.getExtensionFromFileName(name)) {
|
||||
"txt" -> icon = CommunityMaterial.Icon.cmd_file_document
|
||||
"doc", "docx", "odt", "rtf" -> icon = CommunityMaterial.Icon.cmd_file_word
|
||||
"xls", "xlsx", "ods" -> icon = CommunityMaterial.Icon.cmd_file_excel
|
||||
"ppt", "pptx", "odp" -> icon = CommunityMaterial.Icon.cmd_file_powerpoint
|
||||
"pdf" -> icon = CommunityMaterial.Icon.cmd_file_pdf
|
||||
"mp3", "wav", "aac" -> icon = CommunityMaterial.Icon.cmd_file_music
|
||||
"mp4", "avi", "3gp", "mkv", "flv" -> icon = CommunityMaterial.Icon.cmd_file_video
|
||||
"jpg", "jpeg", "png", "bmp", "gif" -> icon = CommunityMaterial.Icon.cmd_file_image
|
||||
"zip", "rar", "tar", "7z" -> icon = CommunityMaterial.Icon.cmd_file_lock
|
||||
}
|
||||
attachmentChip.chipIcon = IconicsDrawable(activity).color(IconicsColor.colorRes(R.color.colorPrimary)).icon(icon).size(IconicsSize.dp(26))
|
||||
attachmentChip.closeIcon = IconicsDrawable(activity).icon(CommunityMaterial.Icon.cmd_check).size(IconicsSize.dp(18)).color(IconicsColor.colorInt(Utils.getAttr(activity, android.R.attr.textColorPrimary)))
|
||||
attachmentChip.isCloseIconVisible = false
|
||||
// set the object's index in the attachmentList as the tag
|
||||
attachmentChip.tag = index
|
||||
attachmentChip.setOnClickListener { v ->
|
||||
if (v.tag is Int) {
|
||||
// TODO downloadAttachment(v.tag as Int)
|
||||
}
|
||||
}
|
||||
attachmentLayout.addView(attachmentChip)
|
||||
|
||||
val attachmentProgress = ProgressBar(attachmentLayout.context)
|
||||
attachmentProgress.layoutParams = progressLayoutParams
|
||||
attachmentProgress.visibility = View.GONE
|
||||
attachmentLayout.addView(attachmentProgress)
|
||||
|
||||
insertPoint.addView(attachmentLayout)
|
||||
// create an object and add to the list
|
||||
val a = Attachment(App.profileId, messageId, id, name, size, attachmentLayout, attachmentChip, attachmentProgress)
|
||||
attachmentList.add(a)
|
||||
// check if the file is already downloaded. Show the check icon if necessary and set `downloaded` to true.
|
||||
checkAttachment(a)
|
||||
|
||||
}
|
||||
} else {
|
||||
// no attachments found
|
||||
b.attachmentsTitle.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkAttachment(attachment: Attachment) {
|
||||
val storageDir = Environment.getExternalStoragePublicDirectory("Szkolny.eu")
|
||||
storageDir.mkdirs()
|
||||
|
||||
val attachmentDataFile = File(storageDir, "." + attachment.profileId + "_" + attachment.messageId + "_" + attachment.attachmentId)
|
||||
if (attachmentDataFile.exists()) {
|
||||
try {
|
||||
val attachmentFileName = getStringFromFile(attachmentDataFile)
|
||||
val attachmentFile = File(attachmentFileName)
|
||||
if (attachmentFile.exists()) {
|
||||
attachment.downloaded = attachmentFileName
|
||||
attachment.chip.isCloseIconVisible = true
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
//app.apiEdziennik.guiReportException(activity, 355, e)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
EventBus.getDefault().register(this)
|
||||
super.onStart()
|
||||
}
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
EventBus.getDefault().unregister(this)
|
||||
}
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
job.cancel()
|
||||
}
|
||||
|
||||
private class Attachment(
|
||||
var profileId: Int,
|
||||
var messageId: Long,
|
||||
var attachmentId: Long,
|
||||
var attachmentName: String,
|
||||
var attachmentSize: Long,
|
||||
var parent: FrameLayout,
|
||||
var chip: Chip,
|
||||
var progressBar: ProgressBar
|
||||
) {
|
||||
/**
|
||||
* An absolute path of the downloaded file. `null` if not downloaded yet.
|
||||
*/
|
||||
internal var downloaded: String? = null
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.messages
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.text.InputType
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -10,18 +8,14 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentPagerAdapter
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_MESSAGES
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.api.v2.LOGIN_TYPE_LIBRUS
|
||||
import pl.szczodrzynski.edziennik.api.v2.events.ApiTaskErrorEvent
|
||||
import pl.szczodrzynski.edziennik.api.v2.events.ApiTaskFinishedEvent
|
||||
import pl.szczodrzynski.edziennik.api.v2.events.task.EdziennikTask
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentMessagesBinding
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
@ -92,7 +86,7 @@ class MessagesFragment : Fragment() {
|
||||
|
||||
b.tabLayout.setupWithViewPager(b.viewPager)
|
||||
|
||||
if (app.profile.loginStoreType == LOGIN_TYPE_LIBRUS && app.profile.getStudentData("accountPassword", null) == null) {
|
||||
/*if (app.profile.loginStoreType == LOGIN_TYPE_LIBRUS && app.profile.getStudentData("accountPassword", null) == null) {
|
||||
MaterialDialog.Builder(activity)
|
||||
.title("Wiadomości w systemie Synergia")
|
||||
.content("Moduł Wiadomości w aplikacji Szkolny.eu jest przeglądarką zasobów szkolnego konta Synergia. Z tego powodu, musisz wpisać swoje hasło do tego konta, aby móc korzystać z tej funkcji.")
|
||||
@ -115,7 +109,7 @@ class MessagesFragment : Fragment() {
|
||||
.show()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
|
@ -533,7 +533,7 @@ public class SettingsNewFragment extends MaterialAboutFragment {
|
||||
syncCardIntervalItem.setChecked(app.appConfig.registerSyncEnabled);
|
||||
syncCardIntervalItem.setOnClickAction(() -> {
|
||||
List<CharSequence> intervalNames = new ArrayList<>();
|
||||
if (App.devMode) {
|
||||
if (App.devMode && false) {
|
||||
intervalNames.add(HomeFragment.plural(activity, R.plurals.time_till_seconds, 30));
|
||||
intervalNames.add(HomeFragment.plural(activity, R.plurals.time_till_minutes, 2));
|
||||
}
|
||||
@ -545,7 +545,7 @@ public class SettingsNewFragment extends MaterialAboutFragment {
|
||||
intervalNames.add(HomeFragment.plural(activity, R.plurals.time_till_hours, 3));
|
||||
intervalNames.add(HomeFragment.plural(activity, R.plurals.time_till_hours, 4));
|
||||
List<Integer> intervals = new ArrayList<>();
|
||||
if (App.devMode) {
|
||||
if (App.devMode && false) {
|
||||
intervals.add(30);
|
||||
intervals.add(2 * 60);
|
||||
}
|
||||
|
@ -0,0 +1,132 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.timetable.v2
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.api.v2.LOGIN_TYPE_LIBRUS
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentTimetableV2Binding
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class TimetableFragment : Fragment() {
|
||||
companion object {
|
||||
private const val TAG = "TimetableFragment"
|
||||
const val ACTION_SCROLL_TO_DATE = "pl.szczodrzynski.edziennik.timetable.SCROLL_TO_DATE"
|
||||
}
|
||||
|
||||
private lateinit var app: App
|
||||
private lateinit var activity: MainActivity
|
||||
private lateinit var b: FragmentTimetableV2Binding
|
||||
private var fabShown = false
|
||||
private val items = mutableListOf<Date>()
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
activity = (getActivity() as MainActivity?) ?: return null
|
||||
if (context == null)
|
||||
return null
|
||||
app = activity.application as App
|
||||
context!!.theme.applyStyle(Themes.appTheme, true)
|
||||
if (app.profile == null)
|
||||
return inflater.inflate(R.layout.fragment_loading, container, false)
|
||||
// activity, context and profile is valid
|
||||
b = FragmentTimetableV2Binding.inflate(inflater)
|
||||
return b.root
|
||||
}
|
||||
|
||||
private val broadcastReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, i: Intent) {
|
||||
if (!isAdded)
|
||||
return
|
||||
val dateStr = i.extras?.getString("date", null) ?: return
|
||||
val date = Date.fromY_m_d(dateStr)
|
||||
b.viewPager.setCurrentItem(items.indexOf(date), true)
|
||||
}
|
||||
}
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
activity.registerReceiver(broadcastReceiver, IntentFilter(ACTION_SCROLL_TO_DATE))
|
||||
}
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
activity.unregisterReceiver(broadcastReceiver)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
// TODO check if app, activity, b can be null
|
||||
if (app.profile == null || !isAdded)
|
||||
return
|
||||
|
||||
if (app.profile.loginStoreType == LOGIN_TYPE_LIBRUS && app.profile.getLoginData("timetableNotPublic", false)) {
|
||||
b.timetableLayout.visibility = View.GONE
|
||||
b.timetableNotPublicLayout.visibility = View.VISIBLE
|
||||
return
|
||||
}
|
||||
b.timetableLayout.visibility = View.VISIBLE
|
||||
b.timetableNotPublicLayout.visibility = View.GONE
|
||||
|
||||
items.clear()
|
||||
|
||||
val monthDayCount = listOf(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
|
||||
|
||||
val today = Date.getToday().value
|
||||
val yearStart = app.profile.dateSemester1Start?.clone() ?: return
|
||||
val yearEnd = app.profile.dateYearEnd ?: return
|
||||
while (yearStart.value <= yearEnd.value) {
|
||||
items += yearStart.clone()
|
||||
var maxDays = monthDayCount[yearStart.month-1]
|
||||
if (yearStart.month == 2 && yearStart.isLeap)
|
||||
maxDays++
|
||||
yearStart.day++
|
||||
if (yearStart.day > maxDays) {
|
||||
yearStart.day = 1
|
||||
yearStart.month++
|
||||
}
|
||||
if (yearStart.month > 12) {
|
||||
yearStart.month = 1
|
||||
yearStart.year++
|
||||
}
|
||||
}
|
||||
|
||||
val pagerAdapter = TimetablePagerAdapter(fragmentManager ?: return, items)
|
||||
b.viewPager.offscreenPageLimit = 2
|
||||
b.viewPager.adapter = pagerAdapter
|
||||
b.viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||
override fun onPageScrollStateChanged(state: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun onPageSelected(position: Int) {
|
||||
activity.navView.bottomBar.fabEnable = items[position].value != today
|
||||
if (activity.navView.bottomBar.fabEnable && !fabShown) {
|
||||
activity.gainAttentionFAB()
|
||||
fabShown = true
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
b.tabLayout.setUpWithViewPager(b.viewPager)
|
||||
b.tabLayout.setCurrentItem(items.indexOfFirst { it.value == today }, false)
|
||||
|
||||
//activity.navView.bottomBar.fabEnable = true
|
||||
activity.navView.bottomBar.fabExtendedText = getString(pl.szczodrzynski.edziennik.R.string.timetable_today)
|
||||
activity.navView.bottomBar.fabIcon = CommunityMaterial.Icon.cmd_calendar_today
|
||||
activity.navView.setFabOnClickListener(View.OnClickListener {
|
||||
b.tabLayout.setCurrentItem(items.indexOfFirst { it.value == today }, true)
|
||||
})
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.timetable.v2
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Week
|
||||
|
||||
class TimetablePagerAdapter(val fragmentManager: FragmentManager, val items: List<Date>) : FragmentStatePagerAdapter(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
|
||||
companion object {
|
||||
private const val TAG = "TimetablePagerAdapter"
|
||||
}
|
||||
|
||||
private val today by lazy { Date.getToday() }
|
||||
private val weekStart by lazy { today.clone().stepForward(0, 0, -today.weekDay) }
|
||||
private val weekEnd by lazy { weekStart.clone().stepForward(0, 0, 6) }
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
return pl.szczodrzynski.edziennik.ui.modules.timetable.v2.day.TimetableDayFragment(items[position])
|
||||
/*return TimetableDayFragment().apply {
|
||||
arguments = Bundle().also {
|
||||
it.putLong("date", items[position].value.toLong())
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
return items.size
|
||||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence? {
|
||||
val date = items[position]
|
||||
val pageTitle = StringBuilder(Week.getFullDayName(date.weekDay))
|
||||
if (date > weekEnd || date < weekStart) {
|
||||
pageTitle.append(", ").append(date.stringDm)
|
||||
}
|
||||
return pageTitle
|
||||
}
|
||||
}
|
@ -0,0 +1,281 @@
|
||||
package pl.szczodrzynski.edziennik.ui.modules.timetable.v2.day
|
||||
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.PorterDuffColorFilter
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
import com.linkedin.android.tachyon.DayView
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_TIMETABLE
|
||||
import pl.szczodrzynski.edziennik.api.v2.LOGIN_TYPE_LIBRUS
|
||||
import pl.szczodrzynski.edziennik.api.v2.events.task.EdziennikTask
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull
|
||||
import pl.szczodrzynski.edziennik.databinding.FragmentTimetableV2DayBinding
|
||||
import pl.szczodrzynski.edziennik.databinding.TimetableLessonBinding
|
||||
import pl.szczodrzynski.edziennik.ui.dialogs.timetable.LessonDetailsDialog
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.navlib.getColorFromAttr
|
||||
import java.util.*
|
||||
import kotlin.math.min
|
||||
|
||||
class TimetableDayFragment(val date: Date) : Fragment() {
|
||||
companion object {
|
||||
private const val TAG = "TimetableDayFragment"
|
||||
}
|
||||
|
||||
private lateinit var app: App
|
||||
private lateinit var activity: MainActivity
|
||||
private lateinit var b: FragmentTimetableV2DayBinding
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
activity = (getActivity() as MainActivity?) ?: return null
|
||||
if (context == null)
|
||||
return null
|
||||
app = activity.application as App
|
||||
b = FragmentTimetableV2DayBinding.inflate(inflater)
|
||||
Log.d(TAG, "onCreateView, date=$date")
|
||||
return b.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
// TODO check if app, activity, b can be null
|
||||
if (app.profile == null || !isAdded)
|
||||
return
|
||||
|
||||
Log.d(TAG, "onViewCreated, date=$date")
|
||||
|
||||
// Inflate a label view for each hour the day view will display
|
||||
val hourLabelViews = ArrayList<View>()
|
||||
for (i in b.day.startHour..b.day.endHour) {
|
||||
val hourLabelView = layoutInflater.inflate(R.layout.timetable_hour_label, b.day, false) as TextView
|
||||
hourLabelView.text = "$i:00"
|
||||
hourLabelViews.add(hourLabelView)
|
||||
}
|
||||
b.day.setHourLabelViews(hourLabelViews)
|
||||
|
||||
app.db.timetableDao().getForDate(App.profileId, date).observe(this, Observer<List<LessonFull>> { lessons ->
|
||||
buildLessonViews(lessons)
|
||||
})
|
||||
}
|
||||
|
||||
private fun buildLessonViews(lessons: List<LessonFull>) {
|
||||
if (lessons.isEmpty()) {
|
||||
b.dayScroll.visibility = View.GONE
|
||||
b.noTimetableLayout.visibility = View.VISIBLE
|
||||
b.noLessonsLayout.visibility = View.GONE
|
||||
val weekStart = date.clone().stepForward(0, 0, -date.weekDay).stringY_m_d
|
||||
b.noTimetableSync.onClick {
|
||||
it.isEnabled = false
|
||||
EdziennikTask.syncProfile(
|
||||
profileId = App.profileId,
|
||||
viewIds = listOf(
|
||||
DRAWER_ITEM_TIMETABLE to 0
|
||||
),
|
||||
arguments = JsonObject(
|
||||
"weekStart" to weekStart
|
||||
)
|
||||
).enqueue(activity)
|
||||
}
|
||||
b.noTimetableWeek.setText(R.string.timetable_no_timetable_week, weekStart)
|
||||
return
|
||||
}
|
||||
if (lessons.size == 1 && lessons[0].type == Lesson.TYPE_NO_LESSONS) {
|
||||
b.dayScroll.visibility = View.GONE
|
||||
b.noTimetableLayout.visibility = View.GONE
|
||||
b.noLessonsLayout.visibility = View.VISIBLE
|
||||
return
|
||||
}
|
||||
|
||||
// reload the fragment when: no lessons, user wants to sync the week, the timetable is not public, pager gets removed
|
||||
if (app.profile.loginStoreType == LOGIN_TYPE_LIBRUS && app.profile.getLoginData("timetableNotPublic", false)) {
|
||||
activity.reloadTarget()
|
||||
// TODO fix for (not really)possible infinite loops
|
||||
return
|
||||
}
|
||||
|
||||
b.dayScroll.visibility = View.VISIBLE
|
||||
b.noTimetableLayout.visibility = View.GONE
|
||||
b.noLessonsLayout.visibility = View.GONE
|
||||
|
||||
var firstEventMinute = 24*60
|
||||
|
||||
val eventViews = mutableListOf<View>()
|
||||
val eventTimeRanges = mutableListOf<DayView.EventTimeRange>()
|
||||
|
||||
// Reclaim all of the existing event views so we can reuse them if needed, this process
|
||||
// can be useful if your day view is hosted in a recycler view for example
|
||||
val recycled = b.day.removeEventViews()
|
||||
var remaining = recycled?.size ?: 0
|
||||
|
||||
val arrowRight = " → "
|
||||
val bullet = " • "
|
||||
val colorSecondary = getColorFromAttr(activity, android.R.attr.textColorSecondary)
|
||||
|
||||
for (lesson in lessons) {
|
||||
val startTime = lesson.displayStartTime ?: continue
|
||||
val endTime = lesson.displayEndTime ?: continue
|
||||
|
||||
firstEventMinute = min(firstEventMinute, startTime.hour*60 + startTime.minute)
|
||||
|
||||
// Try to recycle an existing event view if there are enough left, otherwise inflate
|
||||
// a new one
|
||||
val eventView = (if (remaining > 0) recycled?.get(--remaining) else layoutInflater.inflate(R.layout.timetable_lesson, b.day, false))
|
||||
?: continue
|
||||
val lb = TimetableLessonBinding.bind(eventView)
|
||||
eventViews += eventView
|
||||
|
||||
eventView.tag = lesson
|
||||
|
||||
eventView.setOnClickListener {
|
||||
Log.d(TAG, "Clicked ${it.tag}")
|
||||
if (isAdded && it.tag is LessonFull)
|
||||
LessonDetailsDialog(activity, it.tag as LessonFull)
|
||||
}
|
||||
|
||||
|
||||
val timeRange = "${startTime.stringHM} - ${endTime.stringHM}".asColoredSpannable(colorSecondary)
|
||||
|
||||
// teacher
|
||||
val teacherInfo = if (lesson.teacherId != null && lesson.teacherId == lesson.oldTeacherId)
|
||||
lesson.teacherName ?: "?"
|
||||
else
|
||||
mutableListOf<CharSequence>().apply {
|
||||
lesson.oldTeacherName?.let { add(it.asStrikethroughSpannable()) }
|
||||
lesson.teacherName?.let { add(it) }
|
||||
}.concat(arrowRight)
|
||||
|
||||
// team
|
||||
val teamInfo = if (lesson.teamId != null && lesson.teamId == lesson.oldTeamId)
|
||||
lesson.teamName ?: "?"
|
||||
else
|
||||
mutableListOf<CharSequence>().apply {
|
||||
lesson.oldTeamName?.let { add(it.asStrikethroughSpannable()) }
|
||||
lesson.teamName?.let { add(it) }
|
||||
}.concat(arrowRight)
|
||||
|
||||
// classroom
|
||||
val classroomInfo = if (lesson.classroom != null && lesson.classroom == lesson.oldClassroom)
|
||||
lesson.classroom ?: "?"
|
||||
else
|
||||
mutableListOf<CharSequence>().apply {
|
||||
lesson.oldClassroom?.let { add(it.asStrikethroughSpannable()) }
|
||||
lesson.classroom?.let { add(it) }
|
||||
}.concat(arrowRight)
|
||||
|
||||
|
||||
lb.lessonNumber = lesson.displayLessonNumber
|
||||
lb.subjectName.text = lesson.displaySubjectName?.let {
|
||||
if (lesson.type == Lesson.TYPE_CANCELLED || lesson.type == Lesson.TYPE_SHIFTED_SOURCE)
|
||||
it.asStrikethroughSpannable().asColoredSpannable(colorSecondary)
|
||||
else
|
||||
it
|
||||
}
|
||||
lb.detailsFirst.text = listOfNotEmpty(timeRange, classroomInfo).concat(bullet)
|
||||
lb.detailsSecond.text = listOfNotEmpty(teacherInfo, teamInfo).concat(bullet)
|
||||
|
||||
//lb.subjectName.typeface = Typeface.create("sans-serif-light", Typeface.BOLD)
|
||||
when (lesson.type) {
|
||||
Lesson.TYPE_NORMAL -> {
|
||||
lb.annotationVisible = false
|
||||
}
|
||||
Lesson.TYPE_CANCELLED -> {
|
||||
lb.annotationVisible = true
|
||||
lb.annotation.setText(R.string.timetable_lesson_cancelled)
|
||||
lb.annotation.background.colorFilter = PorterDuffColorFilter(
|
||||
getColorFromAttr(activity, R.attr.timetable_lesson_cancelled_color),
|
||||
PorterDuff.Mode.SRC_ATOP
|
||||
)
|
||||
//lb.subjectName.typeface = Typeface.DEFAULT
|
||||
}
|
||||
Lesson.TYPE_CHANGE -> {
|
||||
lb.annotationVisible = true
|
||||
if (lesson.subjectId != lesson.oldSubjectId && lesson.teacherId != lesson.oldTeacherId) {
|
||||
lb.annotation.setText(
|
||||
R.string.timetable_lesson_change_format,
|
||||
"${lesson.oldSubjectName ?: "?"}, ${lesson.oldTeacherName ?: "?"}"
|
||||
)
|
||||
}
|
||||
else if (lesson.subjectId != lesson.oldSubjectId) {
|
||||
lb.annotation.setText(
|
||||
R.string.timetable_lesson_change_format,
|
||||
lesson.oldSubjectName ?: "?"
|
||||
)
|
||||
}
|
||||
else if (lesson.teacherId != lesson.oldTeacherId) {
|
||||
lb.annotation.setText(
|
||||
R.string.timetable_lesson_change_format,
|
||||
lesson.oldTeacherName ?: "?"
|
||||
)
|
||||
}
|
||||
else {
|
||||
lb.annotation.setText(R.string.timetable_lesson_change)
|
||||
}
|
||||
|
||||
lb.annotation.background.colorFilter = PorterDuffColorFilter(
|
||||
getColorFromAttr(activity, R.attr.timetable_lesson_change_color),
|
||||
PorterDuff.Mode.SRC_ATOP
|
||||
)
|
||||
}
|
||||
Lesson.TYPE_SHIFTED_SOURCE -> {
|
||||
lb.annotationVisible = true
|
||||
when {
|
||||
lesson.date != lesson.oldDate -> lb.annotation.setText(
|
||||
R.string.timetable_lesson_shifted_other_day,
|
||||
lesson.date?.stringY_m_d ?: "?",
|
||||
lesson.startTime?.stringHM ?: "?"
|
||||
)
|
||||
lesson.startTime != lesson.oldStartTime -> lb.annotation.setText(
|
||||
R.string.timetable_lesson_shifted_same_day,
|
||||
lesson.startTime?.stringHM ?: "?"
|
||||
)
|
||||
else -> lb.annotation.setText(R.string.timetable_lesson_shifted)
|
||||
}
|
||||
|
||||
lb.annotation.background.colorFilter = PorterDuffColorFilter(
|
||||
getColorFromAttr(activity, R.attr.timetable_lesson_shifted_source_color),
|
||||
PorterDuff.Mode.SRC_ATOP
|
||||
)
|
||||
}
|
||||
Lesson.TYPE_SHIFTED_TARGET -> {
|
||||
lb.annotationVisible = true
|
||||
when {
|
||||
lesson.date != lesson.oldDate -> lb.annotation.setText(
|
||||
R.string.timetable_lesson_shifted_from_other_day,
|
||||
lesson.oldDate?.stringY_m_d ?: "?",
|
||||
lesson.oldStartTime?.stringHM ?: "?"
|
||||
)
|
||||
lesson.startTime != lesson.oldStartTime -> lb.annotation.setText(
|
||||
R.string.timetable_lesson_shifted_from_same_day,
|
||||
lesson.oldStartTime?.stringHM ?: "?"
|
||||
)
|
||||
else -> lb.annotation.setText(R.string.timetable_lesson_shifted_from)
|
||||
}
|
||||
|
||||
lb.annotation.background.colorFilter = PorterDuffColorFilter(
|
||||
getColorFromAttr(activity, R.attr.timetable_lesson_shifted_target_color),
|
||||
PorterDuff.Mode.SRC_ATOP
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// The day view needs the event time ranges in the start minute/end minute format,
|
||||
// so calculate those here
|
||||
val startMinute = 60 * (lesson.displayStartTime?.hour ?: 0) + (lesson.displayStartTime?.minute ?: 0)
|
||||
val endMinute = startMinute + 45
|
||||
eventTimeRanges.add(DayView.EventTimeRange(startMinute, endMinute))
|
||||
}
|
||||
|
||||
val minuteHeight = (b.day.getHourTop(1) - b.day.getHourTop(0)).toFloat() / 60f
|
||||
val firstEventTop = (firstEventMinute - b.day.startHour * 60) * minuteHeight
|
||||
b.day.setEventViews(eventViews, eventTimeRanges)
|
||||
b.dayScroll.scrollTo(0, firstEventTop.toInt())
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package pl.szczodrzynski.edziennik.utils
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
|
||||
val appManagerIntentList = listOf(
|
||||
Intent().setClassName("com.miui.powerkeeper", "com.miui.powerkeeper.ui.HiddenAppsConfigActivity")
|
||||
.putExtra("packageName", "pl.szczodrzynski.edziennik")
|
||||
.putExtra("package_label", "Szkolny.eu"),
|
||||
Intent().setComponent(ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")),
|
||||
Intent().setComponent(ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity")),
|
||||
Intent().setComponent(ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity")),
|
||||
Intent().setComponent(ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity")),
|
||||
Intent().setComponent(ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity")),
|
||||
Intent().setComponent(ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity")),
|
||||
Intent().setComponent(ComponentName("com.coloros.safecenter", "com.coloros.safecenter.startupapp.StartupAppListActivity")),
|
||||
Intent().setComponent(ComponentName("com.oppo.safe", "com.oppo.safe.permission.startup.StartupAppListActivity")),
|
||||
Intent().setComponent(ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity")),
|
||||
Intent().setComponent(ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager")),
|
||||
Intent().setComponent(ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity")),
|
||||
Intent().setComponent(ComponentName("com.samsung.android.lool", "com.samsung.android.sm.ui.battery.BatteryActivity")),
|
||||
Intent().setComponent(ComponentName("com.htc.pitroad", "com.htc.pitroad.landingpage.activity.LandingPageActivity")),
|
||||
Intent().setComponent(ComponentName("com.asus.mobilemanager", "com.asus.mobilemanager.MainActivity"))
|
||||
)
|
@ -0,0 +1,10 @@
|
||||
package pl.szczodrzynski.edziennik.utils
|
||||
|
||||
import android.content.Context
|
||||
import com.hypertrack.hyperlog.LogFormat
|
||||
|
||||
class DebugLogFormat(context: Context) : LogFormat(context) {
|
||||
override fun getFormattedLogMessage(logLevelName: String?, tag: String?, message: String?, timeStamp: String?, senderName: String?, osVersion: String?, deviceUUID: String?): String {
|
||||
return "${timeStamp?.replace("[TZ]".toRegex(), " ")}D/$tag: $message"
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
|
||||
import pl.szczodrzynski.edziennik.R;
|
||||
|
||||
public class TextInputDropDown extends TextInputEditText {
|
||||
public TextInputDropDown(Context context) {
|
||||
super(context);
|
||||
create(context);
|
||||
}
|
||||
|
||||
public TextInputDropDown(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
create(context);
|
||||
}
|
||||
|
||||
public TextInputDropDown(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
create(context);
|
||||
}
|
||||
|
||||
public void create(Context context) {
|
||||
Drawable drawable = context.getResources().getDrawable(R.drawable.dropdown_arrow);
|
||||
Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
|
||||
DrawableCompat.setTint(wrappedDrawable, Themes.INSTANCE.getPrimaryTextColor(context));
|
||||
|
||||
setCompoundDrawablesWithIntrinsicBounds(null, null, wrappedDrawable, null);
|
||||
setFocusableInTouchMode(false);
|
||||
setCursorVisible(false);
|
||||
setLongClickable(false);
|
||||
setMaxLines(1);
|
||||
setInputType(0);
|
||||
setKeyListener(null);
|
||||
setOnFocusChangeListener((v, hasFocus) -> {
|
||||
if (!hasFocus) {
|
||||
v.setFocusableInTouchMode(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public final void setOnClickListener(OnClickListener onClickListener) {
|
||||
super.setOnClickListener(v -> {
|
||||
setFocusableInTouchMode(true);
|
||||
requestFocus();
|
||||
onClickListener.onClick(v);
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,142 @@
|
||||
package pl.szczodrzynski.edziennik.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
|
||||
class TextInputDropDown : TextInputEditText {
|
||||
constructor(context: Context) : super(context) {
|
||||
create(context)
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
|
||||
create(context)
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
|
||||
create(context)
|
||||
}
|
||||
|
||||
var items = mutableListOf<Item>()
|
||||
private var onChangeListener: ((item: Item) -> Boolean)? = null
|
||||
|
||||
var selected: Item? = null
|
||||
val selectedId
|
||||
get() = selected?.id
|
||||
|
||||
fun updateText() {
|
||||
setText(selected?.displayText ?: selected?.text)
|
||||
}
|
||||
|
||||
fun create(context: Context) {
|
||||
val drawable = context.resources.getDrawable(R.drawable.dropdown_arrow)
|
||||
val wrappedDrawable = DrawableCompat.wrap(drawable)
|
||||
DrawableCompat.setTint(wrappedDrawable, Themes.getPrimaryTextColor(context))
|
||||
|
||||
setCompoundDrawablesWithIntrinsicBounds(null, null, wrappedDrawable, null)
|
||||
isFocusableInTouchMode = false
|
||||
isCursorVisible = false
|
||||
isLongClickable = false
|
||||
maxLines = 1
|
||||
inputType = 0
|
||||
keyListener = null
|
||||
setOnFocusChangeListener { v, hasFocus ->
|
||||
if (!hasFocus) {
|
||||
v.isFocusableInTouchMode = false
|
||||
}
|
||||
}
|
||||
|
||||
setOnClickListener {
|
||||
isFocusableInTouchMode = true
|
||||
requestFocus()
|
||||
val popup = PopupMenu(context, this)
|
||||
|
||||
items.forEachIndexed { index, item ->
|
||||
popup.menu.add(0, item.id.toInt(), index, item.text)
|
||||
}
|
||||
|
||||
popup.setOnMenuItemClickListener { menuItem ->
|
||||
val item = items[menuItem.order]
|
||||
if (onChangeListener?.invoke(item) != false) {
|
||||
select(item)
|
||||
}
|
||||
clearFocus()
|
||||
true
|
||||
}
|
||||
|
||||
popup.setOnDismissListener {
|
||||
clearFocus()
|
||||
}
|
||||
|
||||
popup.show()
|
||||
}
|
||||
}
|
||||
|
||||
fun select(item: Item) {
|
||||
selected = item
|
||||
updateText()
|
||||
}
|
||||
|
||||
fun select(id: Long?) {
|
||||
items.singleOrNull { it.id == id }?.let { select(it) }
|
||||
}
|
||||
|
||||
fun select(tag: Any?) {
|
||||
items.singleOrNull { it.tag == tag }?.let { select(it) }
|
||||
}
|
||||
|
||||
fun select(index: Int) {
|
||||
items.getOrNull(index)?.let { select(it) }
|
||||
}
|
||||
|
||||
fun deselect(): TextInputDropDown {
|
||||
selected = null
|
||||
text = null
|
||||
return this
|
||||
}
|
||||
|
||||
fun clear(): TextInputDropDown {
|
||||
items.clear()
|
||||
return this
|
||||
}
|
||||
|
||||
fun append(items: List<Item>): TextInputDropDown {
|
||||
this.items.addAll(items)
|
||||
return this
|
||||
}
|
||||
|
||||
fun prepend(items: List<Item>): TextInputDropDown{
|
||||
this.items.addAll(0, items)
|
||||
return this
|
||||
}
|
||||
|
||||
operator fun plusAssign(items: Item) {
|
||||
this.items.add(items)
|
||||
}
|
||||
operator fun plusAssign(items: List<Item>) {
|
||||
this.items.addAll(items)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the listener called when other item is selected.
|
||||
*
|
||||
* The listener should return true to allow the item to be selected, false otherwise.
|
||||
*/
|
||||
fun setOnChangeListener(onChangeListener: ((item: Item) -> Boolean)? = null): TextInputDropDown {
|
||||
this.onChangeListener = onChangeListener
|
||||
return this
|
||||
}
|
||||
|
||||
override fun setOnClickListener(onClickListener: OnClickListener?) {
|
||||
super.setOnClickListener { v ->
|
||||
isFocusableInTouchMode = true
|
||||
requestFocus()
|
||||
onClickListener!!.onClick(v)
|
||||
}
|
||||
}
|
||||
|
||||
class Item(val id: Long, val text: CharSequence, val displayText: CharSequence? = null, val tag: Any? = null)
|
||||
}
|
@ -26,6 +26,8 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
import com.hypertrack.hyperlog.HyperLog;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
@ -106,15 +108,15 @@ public class Utils {
|
||||
|
||||
public static void d(String TAG, String message) {
|
||||
if (App.devMode) {
|
||||
Log.d("Szkolny/"+TAG, message);
|
||||
HyperLog.d("Szkolny/"+TAG, message);
|
||||
//debugLog.add(TAG+": "+message);
|
||||
}
|
||||
}
|
||||
public static void c(String TAG, String message) {
|
||||
if (App.devMode) {
|
||||
/*if (App.devMode) {
|
||||
Log.d(TAG, "// " + message);
|
||||
///debugLog.add(TAG+": // "+message);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
package pl.szczodrzynski.edziennik.utils.models;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Calendar;
|
||||
@ -131,6 +132,13 @@ public class Date implements Comparable<Date> {
|
||||
return year * 10000 + month * 100 + day;
|
||||
}
|
||||
|
||||
public static Date fromValue(int value) {
|
||||
int year = value / 10000;
|
||||
int month = (value-year*10000) / 100;
|
||||
int day = (value-year*10000-month*100);
|
||||
return new Date(year, month, day);
|
||||
}
|
||||
|
||||
public String getStringValue()
|
||||
{
|
||||
return Integer.toString(getValue());
|
||||
@ -182,6 +190,10 @@ public class Date implements Comparable<Date> {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLeap() {
|
||||
return ((year & 3) == 0) && ((year % 100) != 0 || (year % 400) == 0);
|
||||
}
|
||||
|
||||
public static Date getToday()
|
||||
{
|
||||
Calendar cal = Calendar.getInstance();
|
||||
@ -214,6 +226,11 @@ public class Date implements Comparable<Date> {
|
||||
return this.getValue() - o.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return obj instanceof Date && this.getValue() == ((Date) obj).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Date{" +
|
||||
|
@ -1,5 +1,7 @@
|
||||
package pl.szczodrzynski.edziennik.utils.models;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public class Time {
|
||||
@ -173,6 +175,11 @@ public class Time {
|
||||
return (currentTime.getValue() >= startTime.getValue() && currentTime.getValue() <= endTime.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return obj instanceof Time && this.getValue() == ((Time) obj).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Time{" +
|
||||
|
10
app/src/main/res/drawable-v21/bg_rounded_ripple_4dp.xml
Normal file
10
app/src/main/res/drawable-v21/bg_rounded_ripple_4dp.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?android:attr/colorControlHighlight">
|
||||
<item android:id="@android:id/mask">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#000000" />
|
||||
<corners android:radius="4dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user