diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/edziennik/librus/DataLibrus.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/edziennik/librus/DataLibrus.kt
index 5c2ffce1..8bae6419 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/edziennik/librus/DataLibrus.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/edziennik/librus/DataLibrus.kt
@@ -148,16 +148,16 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
*/
private var mApiCode: String? = null
var apiCode: String?
- get() { mApiCode = mApiCode ?: profile?.getStudentData("accountCode", null); return mApiCode }
- set(value) { profile?.putStudentData("accountCode", value) ?: return; mApiCode = value }
+ get() { mApiCode = mApiCode ?: loginStore.getLoginData("accountCode", null); return mApiCode }
+ set(value) { loginStore.putLoginData("accountCode", value) ?: return; mApiCode = value }
/**
* A JST login PIN.
* Used only during first login in JST mode.
*/
private var mApiPin: String? = null
var apiPin: String?
- get() { mApiPin = mApiPin ?: profile?.getStudentData("accountPin", null); return mApiPin }
- set(value) { profile?.putStudentData("accountPin", value) ?: return; mApiPin = value }
+ get() { mApiPin = mApiPin ?: loginStore.getLoginData("accountPin", null); return mApiPin }
+ set(value) { loginStore.putLoginData("accountPin", value) ?: return; mApiPin = value }
/**
* A Synergia API access token.
@@ -168,7 +168,7 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
private var mApiAccessToken: String? = null
var apiAccessToken: String?
get() { mApiAccessToken = mApiAccessToken ?: profile?.getStudentData("accountToken", null); return mApiAccessToken }
- set(value) { profile?.putStudentData("accountToken", value) ?: return; mApiAccessToken = value }
+ set(value) { mApiAccessToken = value; profile?.putStudentData("accountToken", value) ?: return; }
/**
* A Synergia API refresh token.
* Used when refreshing the [apiAccessToken] in JST, Synergia modes.
@@ -176,7 +176,7 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
private var mApiRefreshToken: String? = null
var apiRefreshToken: String?
get() { mApiRefreshToken = mApiRefreshToken ?: profile?.getStudentData("accountRefreshToken", null); return mApiRefreshToken }
- set(value) { profile?.putStudentData("accountRefreshToken", value) ?: return; mApiRefreshToken = value }
+ set(value) { mApiRefreshToken = value; profile?.putStudentData("accountRefreshToken", value) ?: return; }
/**
* The expiry time for [apiAccessToken], as a UNIX timestamp.
* Used when refreshing the [apiAccessToken] in JST, Synergia modes.
@@ -185,7 +185,7 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
private var mApiTokenExpiryTime: Long? = null
var apiTokenExpiryTime: Long
get() { mApiTokenExpiryTime = mApiTokenExpiryTime ?: profile?.getStudentData("accountTokenTime", 0L); return mApiTokenExpiryTime ?: 0L }
- set(value) { profile?.putStudentData("accountTokenTime", value) ?: return; mApiTokenExpiryTime = value }
+ set(value) { mApiTokenExpiryTime = value; profile?.putStudentData("accountTokenTime", value) ?: return; }
/* _____ _
/ ____| (_)
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/edziennik/librus/firstlogin/LibrusFirstLogin.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/edziennik/librus/firstlogin/LibrusFirstLogin.kt
index 0b0d2f20..e2ac2275 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/edziennik/librus/firstlogin/LibrusFirstLogin.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/edziennik/librus/firstlogin/LibrusFirstLogin.kt
@@ -85,6 +85,36 @@ class LibrusFirstLogin(val data: DataLibrus, val onSuccess: () -> Unit) {
LibrusLoginApi(data) {
api.apiGet(TAG, "Me") { json ->
+ val profile = Profile()
+
+ val me = json.getJsonObject("Me")
+ val account = me?.getJsonObject("Account")
+ val user = me?.getJsonObject("User")
+
+ profile.putStudentData("isPremium", account?.getBoolean("IsPremium") == true || account?.getBoolean("IsPremiumDemo") == true)
+
+ val isParent = account?.getInt("GroupId") == 5
+ profile.accountNameLong =
+ if (isParent)
+ buildFullName(account?.getString("FirstName"), account?.getString("LastName"))
+ else null
+
+ profile.studentNameLong =
+ buildFullName(user?.getString("FirstName"), user?.getString("LastName"))
+
+ profile.studentNameShort = profile.studentNameLong?.getShortName()
+ profile.name = profile.studentNameLong
+ profile.subname = account.getString("Login")
+ profile.empty = true
+ profile.putStudentData("accountId", account.getInt("Id") ?: 0)
+ profile.putStudentData("accountLogin", profile.subname)
+ profile.putStudentData("accountToken", data.apiAccessToken)
+ profile.putStudentData("accountRefreshToken", data.apiRefreshToken)
+ profile.putStudentData("accountTokenTime", data.apiTokenExpiryTime)
+ profileList.add(profile)
+
+ EventBus.getDefault().post(FirstLoginFinishedEvent(profileList, data.loginStore))
+ onSuccess()
}
}
}
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.java b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.java
index 15352942..7144ccb3 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.java
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.java
@@ -108,7 +108,7 @@ import pl.szczodrzynski.edziennik.utils.models.Date;
AttendanceType.class,
pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson.class,
ConfigEntry.class,
- Metadata.class}, version = 68)
+ Metadata.class}, version = 69)
@TypeConverters({
ConverterTime.class,
ConverterDate.class,
@@ -823,6 +823,12 @@ public abstract class AppDb extends RoomDatabase {
database.execSQL("DELETE FROM metadata WHERE thingType=7");
}
};
+ private static final Migration MIGRATION_68_69 = new Migration(68, 69) {
+ @Override
+ public void migrate(@NonNull SupportSQLiteDatabase database) {
+ database.execSQL("ALTER TABLE loginStores ADD COLUMN loginStoreMode INTEGER NOT NULL DEFAULT 0");
+ }
+ };
public static AppDb getDatabase(final Context context) {
@@ -888,7 +894,8 @@ public abstract class AppDb extends RoomDatabase {
MIGRATION_64_65,
MIGRATION_65_66,
MIGRATION_66_67,
- MIGRATION_67_68
+ MIGRATION_67_68,
+ MIGRATION_68_69
)
.allowMainThreadQueries()
//.fallbackToDestructiveMigration()
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/login/LoginStore.java b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/login/LoginStore.java
index 567f84db..e3d25623 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/login/LoginStore.java
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/login/LoginStore.java
@@ -5,7 +5,6 @@ import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
-import androidx.room.Ignore;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
@@ -28,7 +27,7 @@ public class LoginStore {
@ColumnInfo(name = "loginStoreData")
public JsonObject data;
- @Ignore
+ @ColumnInfo(name = "loginStoreMode")
public int mode = 0;
public static final int LOGIN_MODE_LIBRUS_EMAIL = 0;
public static final int LOGIN_MODE_LIBRUS_SYNERGIA = 1;
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginChooserFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginChooserFragment.java
index f46fa253..a3088685 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginChooserFragment.java
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginChooserFragment.java
@@ -51,6 +51,7 @@ public class LoginChooserFragment extends Fragment {
b.loginMobidziennikLogo.setOnClickListener((v) -> nav.navigate(R.id.loginMobidziennikFragment, null, LoginActivity.navOptions));
b.loginLibrusLogo.setOnClickListener((v) -> nav.navigate(R.id.loginLibrusFragment, null, LoginActivity.navOptions));
+ b.loginLibrusJstLogo.setOnClickListener((v) -> nav.navigate(R.id.loginLibrusJstFragment, null, LoginActivity.navOptions));
b.loginVulcanLogo.setOnClickListener((v) -> nav.navigate(R.id.loginVulcanFragment, null, LoginActivity.navOptions));
b.loginIuczniowieLogo.setOnClickListener((v) -> nav.navigate(R.id.loginIuczniowieFragment, null, LoginActivity.navOptions));
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginLibrusJstFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginLibrusJstFragment.java
new file mode 100644
index 00000000..03cb6807
--- /dev/null
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginLibrusJstFragment.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) Kuba Szczodrzyński 2019-12-13.
+ */
+
+package pl.szczodrzynski.edziennik.ui.modules.login;
+
+import android.os.Bundle;
+import android.text.Editable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.databinding.DataBindingUtil;
+import androidx.fragment.app.Fragment;
+import androidx.navigation.NavController;
+import androidx.navigation.Navigation;
+
+import pl.szczodrzynski.edziennik.App;
+import pl.szczodrzynski.edziennik.R;
+import pl.szczodrzynski.edziennik.api.v2.models.ApiError;
+import pl.szczodrzynski.edziennik.databinding.FragmentLoginLibrusJstBinding;
+import pl.szczodrzynski.edziennik.ui.modules.error.ErrorSnackbar;
+
+import static pl.szczodrzynski.edziennik.api.v2.ErrorsKt.ERROR_LOGIN_LIBRUS_API_INVALID_LOGIN;
+import static pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore.LOGIN_MODE_LIBRUS_JST;
+import static pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore.LOGIN_TYPE_LIBRUS;
+
+public class LoginLibrusJstFragment extends Fragment {
+
+ private App app;
+ private NavController nav;
+ private FragmentLoginLibrusJstBinding b;
+ private static final String TAG = "LoginLibrus";
+ private ErrorSnackbar errorSnackbar;
+
+ public LoginLibrusJstFragment() { }
+
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ if (getActivity() != null) {
+ app = (App) getActivity().getApplicationContext();
+ nav = Navigation.findNavController(getActivity(), R.id.nav_host_fragment);
+ errorSnackbar = ((LoginActivity) getActivity()).errorSnackbar;
+ }
+ else {
+ return null;
+ }
+ b = DataBindingUtil.inflate(inflater, R.layout.fragment_login_librus_jst, container, false);
+ return b.getRoot();
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ assert getContext() != null;
+ assert getActivity() != null;
+
+ view.postDelayed(() -> {
+ ApiError error = LoginActivity.error;
+ if (error != null) {
+ switch (error.getErrorCode()) {
+ case ERROR_LOGIN_LIBRUS_API_INVALID_LOGIN:
+ b.loginCodeLayout.setError(getString(R.string.login_error_incorrect_code_or_pin));
+ break;
+ }
+ errorSnackbar.addError(error).show();
+ LoginActivity.error = null;
+ }
+ }, 100);
+
+ b.helpButton.setOnClickListener((v) -> nav.navigate(R.id.loginLibrusHelpFragment, null, LoginActivity.navOptions));
+ b.backButton.setOnClickListener((v) -> nav.navigateUp());
+
+ b.loginButton.setOnClickListener((v) -> {
+ boolean errors = false;
+
+ b.loginCodeLayout.setError(null);
+ b.loginPinLayout.setError(null);
+
+ Editable codeEditable = b.loginCode.getText();
+ Editable pinEditable = b.loginPin.getText();
+ if (codeEditable == null || codeEditable.length() == 0) {
+ b.loginCodeLayout.setError(getString(R.string.login_error_no_code));
+ errors = true;
+ }
+ if (pinEditable == null || pinEditable.length() == 0) {
+ b.loginPinLayout.setError(getString(R.string.login_error_no_pin));
+ errors = true;
+ }
+
+ if (errors)
+ return;
+ errors = false;
+
+ String code = codeEditable.toString().toUpperCase();
+ String pin = pinEditable.toString();
+ b.loginCode.setText(code);
+ if (!code.matches("[A-Z0-9_]+")) {
+ b.loginCodeLayout.setError(getString(R.string.login_error_incorrect_code));
+ errors = true;
+ }
+ if (!pin.matches("[a-z0-9_]+")) {
+ b.loginPinLayout.setError(getString(R.string.login_error_incorrect_pin));
+ errors = true;
+ }
+
+ if (errors)
+ return;
+ errors = false;
+
+ Bundle args = new Bundle();
+ args.putInt("loginType", LOGIN_TYPE_LIBRUS);
+ args.putInt("loginMode", LOGIN_MODE_LIBRUS_JST);
+ args.putString("accountCode", code);
+ args.putString("accountPin", pin);
+ nav.navigate(R.id.loginProgressFragment, args, LoginActivity.navOptions);
+ });
+ }
+}
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginProgressFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginProgressFragment.java
index 625bb0bf..3cc1b2c8 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginProgressFragment.java
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginProgressFragment.java
@@ -85,8 +85,10 @@ public class LoginProgressFragment extends Fragment {
}
int loginType = args.getInt("loginType", -1);
+ int loginMode = args.getInt("loginMode", 0);
LoginStore loginStore = new LoginStore(-1, loginType, new JsonObject());
+ loginStore.mode = loginMode;
loginStore.copyFrom(args);
if (App.devMode && LoginChooserFragment.fakeLogin) {
diff --git a/app/src/main/res/drawable/login_logo_oswiata.png b/app/src/main/res/drawable/login_logo_oswiata.png
new file mode 100644
index 00000000..7cbf5f10
Binary files /dev/null and b/app/src/main/res/drawable/login_logo_oswiata.png differ
diff --git a/app/src/main/res/layout/fragment_login_chooser.xml b/app/src/main/res/layout/fragment_login_chooser.xml
index 9b7937fa..010237c3 100644
--- a/app/src/main/res/layout/fragment_login_chooser.xml
+++ b/app/src/main/res/layout/fragment_login_chooser.xml
@@ -152,6 +152,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/navigation/nav_login.xml b/app/src/main/res/navigation/nav_login.xml
index 902daba7..c3dd6a38 100644
--- a/app/src/main/res/navigation/nav_login.xml
+++ b/app/src/main/res/navigation/nav_login.xml
@@ -15,6 +15,9 @@
+
@@ -46,6 +49,15 @@
android:id="@+id/action_loginLibrusFragment_to_loginProgressFragment"
app:destination="@id/loginProgressFragment" />
+
+
+
In order to use the app you need a Librus account. You can create it on portal.librus.pl. Use the data you normally enter in the fields marked on the image.
Help - Librus
Log in using your Librus account data (created before on your e-mail address). You can\'t login using the data provided by your school. In case of any problems, use the button below the form.
- Log in - Librus
+ Log in - Librus JST
A migration error has occurred. It\'s already reported, which means I\'ll try to fix it.\n\nYou can continue using the app. In case of any problems try to remove the profile and create it again.
The app got a huge update. If you encounter any problems, feel free to contact me using the Feedback option in the menu.
Szkolny.eu has been updated
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index dfe8e6e5..a16c4fac 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -373,6 +373,7 @@
Pomoc - Librus
Zaloguj się danymi swojego konta Librus (założonego wcześniej na swój adres e-mail). Nie należy logować się danymi otrzymanymi ze swojej szkoły. W razie problemów skorzystaj z przycisku pod formularzem.
Zaloguj się - Librus
+ Zaloguj się - Librus JST
Wystąpił błąd w migracji danych. Został on już zgłoszony, co oznacza, że postaram się go naprawić.\n\nMożesz zacząć korzystać z aplikacji, jednak w przypadku jakichś błędów spróbuj usunąć profil i zalogować się ponownie.
Aplikacja otrzymała dużą aktualizację. Jeżeli będą występować jakieś problemy w działaniu, możesz się ze mną skontaktować używając pozycji Pomoc i opinie w menu.
Szkolny.eu został zaktualizowany
@@ -1061,4 +1062,9 @@
Pobieranie ocen z zachowania...
Synchronizowanie udostępnionych wydarzeń...
Otwieraj menu przyciskiem wstecz
+ Zaloguj się tokenem i kodem PIN, który można wygenerować po zalogowanu się do Synergii w zakładce Aplikacje mobilne.
+ Nieprawidłowy token lub PIN
+ Nieprawidłowy kod lub PIN
+ Nieprawidłowy kod
+ Podaj kod