forked from github/szkolny
[Models] Remove unused models and classes.
This commit is contained in:
parent
904be34a87
commit
840ab4b0c4
@ -1,541 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2020-1-19.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik;
|
||||
|
||||
/*public class AppOld extends androidx.multidex.MultiDexApplication implements Configuration.Provider {
|
||||
private static final String TAG = "App";
|
||||
public static int profileId = -1;
|
||||
private Context mContext;
|
||||
|
||||
@Override
|
||||
public Configuration getWorkManagerConfiguration() {
|
||||
return new Configuration.Builder()
|
||||
.setMinimumLoggingLevel(Log.VERBOSE)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
public static final int REQUEST_TIMEOUT = 10 * 1000;
|
||||
|
||||
// notifications
|
||||
//public NotificationManager mNotificationManager;
|
||||
//public final String NOTIFICATION_CHANNEL_ID_UPDATES = "4566";
|
||||
//public String NOTIFICATION_CHANNEL_NAME_UPDATES;
|
||||
public Notifier notifier;
|
||||
|
||||
public static final String APP_URL = "://edziennik.szczodrzynski.pl/app/";
|
||||
|
||||
public ShortcutManager shortcutManager;
|
||||
|
||||
public PermissionChecker permissionChecker;
|
||||
|
||||
public String signature = "";
|
||||
public String deviceId = "";
|
||||
|
||||
public AppDb db;
|
||||
public void debugLog(String text) {
|
||||
if (!devMode)
|
||||
return;
|
||||
db.debugLogDao().add(new DebugLog(Utils.getCurrentTimeUsingCalendar()+": "+text));
|
||||
}
|
||||
public void debugLogAsync(String text) {
|
||||
if (!devMode)
|
||||
return;
|
||||
AsyncTask.execute(() -> {
|
||||
db.debugLogDao().add(new DebugLog(Utils.getCurrentTimeUsingCalendar()+": "+text));
|
||||
});
|
||||
}
|
||||
|
||||
// network & APIs
|
||||
public NetworkUtils networkUtils;
|
||||
public PersistentCookieJar cookieJar;
|
||||
public OkHttpClient http;
|
||||
public OkHttpClient httpLazy;
|
||||
|
||||
public SharedPreferences appSharedPrefs; // sharedPreferences for APPCONFIG + JOBS STORE
|
||||
public AppConfig appConfig; // APPCONFIG: common for all profiles
|
||||
//public AppProfile profile; // current profile
|
||||
public SharedPreferences registerStore; // sharedPreferences for REGISTER
|
||||
//public Register register; // REGISTER for current profile, read from registerStore
|
||||
|
||||
public Profile profile;
|
||||
public Config config;
|
||||
private static Config mConfig;
|
||||
public static Config getConfig() {
|
||||
return mConfig;
|
||||
}
|
||||
|
||||
// other stuff
|
||||
public Gson gson;
|
||||
public String requestScheme = "https";
|
||||
public boolean unreadBadgesAvailable = true;
|
||||
|
||||
public static boolean devMode = false;
|
||||
|
||||
public static final boolean UPDATES_ON_PLAY_STORE = true;
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
public Icon getDesktopIconFromIconics(IIcon icon) {
|
||||
final IconicsDrawable drawable = new IconicsDrawable(mContext, icon)
|
||||
.color(IconicsColor.colorInt(Color.WHITE))
|
||||
.size(IconicsSize.dp(48))
|
||||
.padding(IconicsSize.dp(8))
|
||||
.backgroundColor(IconicsColor.colorRes(R.color.colorPrimaryDark))
|
||||
.roundedCorners(IconicsSize.dp(10));
|
||||
//drawable.setStyle(Paint.Style.FILL);
|
||||
final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
||||
final Canvas canvas = new Canvas(bitmap);
|
||||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||
drawable.draw(canvas);
|
||||
|
||||
return Icon.createWithBitmap(bitmap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
|
||||
CaocConfig.Builder.create()
|
||||
.backgroundMode(CaocConfig.BACKGROUND_MODE_SHOW_CUSTOM) //default: CaocConfig.BACKGROUND_MODE_SHOW_CUSTOM
|
||||
.enabled(true) //default: true
|
||||
.showErrorDetails(true) //default: true
|
||||
.showRestartButton(true) //default: true
|
||||
.logErrorOnRestart(true) //default: true
|
||||
.trackActivities(true) //default: false
|
||||
.minTimeBetweenCrashesMs(2000) //default: 3000
|
||||
.errorDrawable(R.drawable.ic_rip) //default: bug image
|
||||
.restartActivity(MainActivity.class) //default: null (your app's launch activity)
|
||||
.errorActivity(CrashActivity.class) //default: null (default error activity)
|
||||
//.eventListener(new YourCustomEventListener()) //default: null
|
||||
.apply();
|
||||
mContext = this;
|
||||
db = AppDb.getDatabase(this);
|
||||
gson = new Gson();
|
||||
networkUtils = new NetworkUtils(this);
|
||||
|
||||
config = new Config(db);
|
||||
config.migrate(this);
|
||||
mConfig = config;
|
||||
|
||||
Iconics.init(getApplicationContext());
|
||||
Iconics.registerFont(SzkolnyFont.INSTANCE);
|
||||
|
||||
notifier = new Notifier(this);
|
||||
permissionChecker = new PermissionChecker(mContext);
|
||||
|
||||
deviceId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
|
||||
cookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(this));
|
||||
|
||||
appSharedPrefs = getSharedPreferences(getString(R.string.preference_file_global), Context.MODE_PRIVATE);
|
||||
|
||||
loadConfig();
|
||||
|
||||
Signing.INSTANCE.getCert(this);
|
||||
|
||||
Themes.INSTANCE.setThemeInt(config.getUi().getTheme());
|
||||
|
||||
try {
|
||||
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
|
||||
for (Signature signature: packageInfo.signatures) {
|
||||
byte[] signatureBytes = signature.toByteArray();
|
||||
MessageDigest md = MessageDigest.getInstance("SHA");
|
||||
md.update(signatureBytes);
|
||||
this.signature = Base64.encodeToString(md.digest(), Base64.NO_WRAP);
|
||||
//Log.d(TAG, "Signature is "+this.signature);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if ("f054761fbdb6a238".equals(deviceId) || BuildConfig.DEBUG) {
|
||||
devMode = true;
|
||||
}
|
||||
else if (config.getDevModePassword() != null) {
|
||||
checkDevModePassword();
|
||||
}
|
||||
|
||||
OkHttpClient.Builder httpBuilder = new OkHttpClient.Builder()
|
||||
.cache(null)
|
||||
.followRedirects(true)
|
||||
.followSslRedirects(true)
|
||||
.retryOnConnectionFailure(true)
|
||||
.cookieJar(cookieJar)
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(20, TimeUnit.SECONDS)
|
||||
.readTimeout(40, TimeUnit.SECONDS);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
try {
|
||||
try {
|
||||
ProviderInstaller.installIfNeeded(this);
|
||||
} catch (Exception e) {
|
||||
Log.e("OkHttpTLSCompat", "Play Services not found or outdated");
|
||||
X509TrustManager x509TrustManager = null;
|
||||
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
trustManagerFactory.init((KeyStore) null);
|
||||
for (TrustManager trustManager: trustManagerFactory.getTrustManagers()) {
|
||||
if (trustManager instanceof X509TrustManager)
|
||||
x509TrustManager = (X509TrustManager) trustManager;
|
||||
}
|
||||
|
||||
SSLContext sc = SSLContext.getInstance("TLSv1.2");
|
||||
sc.init(null, null, null);
|
||||
httpBuilder.sslSocketFactory(new TLSSocketFactory(sc.getSocketFactory()), x509TrustManager);
|
||||
|
||||
ConnectionSpec cs = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
|
||||
.tlsVersions(TlsVersion.TLS_1_0)
|
||||
.tlsVersions(TlsVersion.TLS_1_1)
|
||||
.tlsVersions(TlsVersion.TLS_1_2)
|
||||
.build();
|
||||
|
||||
List<ConnectionSpec> specs = new ArrayList<>();
|
||||
specs.add(cs);
|
||||
specs.add(ConnectionSpec.COMPATIBLE_TLS);
|
||||
specs.add(ConnectionSpec.CLEARTEXT);
|
||||
|
||||
httpBuilder.connectionSpecs(specs);
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception exc) {
|
||||
Log.e("OkHttpTLSCompat", "Error while setting TLS 1.2", exc);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
http = httpBuilder.build();
|
||||
httpLazy = http.newBuilder().followRedirects(false).followSslRedirects(false).build();
|
||||
|
||||
MHttp.instance()
|
||||
.customOkHttpClient(http);
|
||||
|
||||
//register = new Register(mContext);
|
||||
|
||||
//profileLoadById(appSharedPrefs.getInt("current_profile_id", 1));
|
||||
|
||||
if (config.getSync().getEnabled()) {
|
||||
SyncWorker.Companion.scheduleNext(this, false);
|
||||
}
|
||||
else {
|
||||
SyncWorker.Companion.cancelNext(this);
|
||||
}
|
||||
|
||||
db.metadataDao().countUnseen().observeForever(count -> {
|
||||
Log.d("MainActivity", "Overall unseen count changed");
|
||||
assert count != null;
|
||||
if (unreadBadgesAvailable) {
|
||||
unreadBadgesAvailable = ShortcutBadger.applyCount(this, count);
|
||||
}
|
||||
});
|
||||
|
||||
//new IonCookieManager(mContext);
|
||||
|
||||
new Handler().post(() -> {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
shortcutManager = getSystemService(ShortcutManager.class);
|
||||
|
||||
ShortcutInfo shortcutTimetable = new ShortcutInfo.Builder(mContext, "item_timetable")
|
||||
.setShortLabel(getString(R.string.shortcut_timetable)).setLongLabel(getString(R.string.shortcut_timetable))
|
||||
.setIcon(Icon.createWithResource(this, R.mipmap.ic_shortcut_timetable))
|
||||
//.setIcon(getDesktopIconFromIconics(CommunityMaterial.Icon2.cmd_timetable))
|
||||
.setIntent(new Intent(Intent.ACTION_MAIN, null, this, MainActivity.class)
|
||||
.putExtra("fragmentId", MainActivity.DRAWER_ITEM_TIMETABLE))
|
||||
.build();
|
||||
|
||||
ShortcutInfo shortcutAgenda = new ShortcutInfo.Builder(mContext, "item_agenda")
|
||||
.setShortLabel(getString(R.string.shortcut_agenda)).setLongLabel(getString(R.string.shortcut_agenda))
|
||||
.setIcon(Icon.createWithResource(this, R.mipmap.ic_shortcut_agenda))
|
||||
//.setIcon(getDesktopIconFromIconics(CommunityMaterial.Icon.cmd_calendar))
|
||||
.setIntent(new Intent(Intent.ACTION_MAIN, null, this, MainActivity.class)
|
||||
.putExtra("fragmentId", MainActivity.DRAWER_ITEM_AGENDA))
|
||||
.build();
|
||||
|
||||
ShortcutInfo shortcutGrades = new ShortcutInfo.Builder(mContext, "item_grades")
|
||||
.setShortLabel(getString(R.string.shortcut_grades)).setLongLabel(getString(R.string.shortcut_grades))
|
||||
.setIcon(Icon.createWithResource(this, R.mipmap.ic_shortcut_grades))
|
||||
//.setIcon(getDesktopIconFromIconics(CommunityMaterial.Icon2.cmd_numeric_5_box))
|
||||
.setIntent(new Intent(Intent.ACTION_MAIN, null, this, MainActivity.class)
|
||||
.putExtra("fragmentId", MainActivity.DRAWER_ITEM_GRADES))
|
||||
.build();
|
||||
|
||||
ShortcutInfo shortcutHomework = new ShortcutInfo.Builder(mContext, "item_homeworks")
|
||||
.setShortLabel(getString(R.string.shortcut_homework)).setLongLabel(getString(R.string.shortcut_homework))
|
||||
.setIcon(Icon.createWithResource(this, R.mipmap.ic_shortcut_homework))
|
||||
//.setIcon(getDesktopIconFromIconics(SzkolnyFont.Icon.szf_file_document_edit))
|
||||
.setIntent(new Intent(Intent.ACTION_MAIN, null, this, MainActivity.class)
|
||||
.putExtra("fragmentId", MainActivity.DRAWER_ITEM_HOMEWORK))
|
||||
.build();
|
||||
|
||||
ShortcutInfo shortcutMessages = new ShortcutInfo.Builder(mContext, "item_messages")
|
||||
.setShortLabel(getString(R.string.shortcut_messages)).setLongLabel(getString(R.string.shortcut_messages))
|
||||
.setIcon(Icon.createWithResource(this, R.mipmap.ic_shortcut_messages))
|
||||
//.setIcon(getDesktopIconFromIconics(CommunityMaterial.Icon.cmd_email))
|
||||
.setIntent(new Intent(Intent.ACTION_MAIN, null, this, MainActivity.class)
|
||||
.putExtra("fragmentId", MainActivity.DRAWER_ITEM_MESSAGES ))
|
||||
.build();
|
||||
|
||||
shortcutManager.setDynamicShortcuts(Arrays.asList(shortcutTimetable, shortcutAgenda, shortcutGrades, shortcutHomework, shortcutMessages));
|
||||
}
|
||||
|
||||
if (config.getAppInstalledTime() == 0) {
|
||||
try {
|
||||
config.setAppInstalledTime(getPackageManager().getPackageInfo(getPackageName(), 0).firstInstallTime);
|
||||
config.setAppRateSnackbarTime(config.getAppInstalledTime() + 7 * 24 * 60 * 60 * 1000);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
FirebaseApp pushMobidziennikApp = FirebaseApp.initializeApp(
|
||||
this,
|
||||
new FirebaseOptions.Builder()
|
||||
.setApiKey("AIzaSyCi5LmsZ5BBCQnGtrdvWnp1bWLCNP8OWQE")
|
||||
.setApplicationId("1:747285019373:android:f6341bf7b158621d")
|
||||
.build(),
|
||||
"Mobidziennik2"
|
||||
);
|
||||
|
||||
FirebaseApp pushLibrusApp = FirebaseApp.initializeApp(
|
||||
this,
|
||||
new FirebaseOptions.Builder()
|
||||
.setApiKey("AIzaSyDfTuEoYPKdv4aceEws1CO3n0-HvTndz-o")
|
||||
.setApplicationId("1:513056078587:android:1e29083b760af544")
|
||||
.build(),
|
||||
"Librus"
|
||||
);
|
||||
|
||||
FirebaseApp pushVulcanApp = FirebaseApp.initializeApp(
|
||||
this,
|
||||
new FirebaseOptions.Builder()
|
||||
.setApiKey("AIzaSyDW8MUtanHy64_I0oCpY6cOxB3jrvJd_iA")
|
||||
.setApplicationId("1:987828170337:android:ac97431a0a4578c3")
|
||||
.build(),
|
||||
"Vulcan"
|
||||
);
|
||||
|
||||
if (config.getRunSync()) {
|
||||
config.setRunSync(false);
|
||||
EdziennikTask.Companion.sync().enqueue(this);
|
||||
}
|
||||
|
||||
try {
|
||||
final long startTime = System.currentTimeMillis();
|
||||
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(instanceIdResult -> {
|
||||
if (!instanceIdResult.getToken().equals(config.getSync().getTokenApp())) {
|
||||
Log.d(TAG, "Token for App is " + instanceIdResult.getToken());
|
||||
config.getSync().setTokenApp(instanceIdResult.getToken());
|
||||
}
|
||||
});
|
||||
FirebaseInstanceId.getInstance(pushMobidziennikApp).getInstanceId().addOnSuccessListener(instanceIdResult -> {
|
||||
if (!instanceIdResult.getToken().equals(config.getSync().getTokenMobidziennik())) {
|
||||
Log.d(TAG, "Token for Mobidziennik2 is " + instanceIdResult.getToken());
|
||||
config.getSync().setTokenMobidziennik(instanceIdResult.getToken());
|
||||
config.getSync().setTokenMobidziennikList(new ArrayList<>());
|
||||
}
|
||||
});
|
||||
FirebaseInstanceId.getInstance(pushLibrusApp).getInstanceId().addOnSuccessListener(instanceIdResult -> {
|
||||
if (!instanceIdResult.getToken().equals(config.getSync().getTokenLibrus())) {
|
||||
Log.d(TAG, "Token for Librus is " + instanceIdResult.getToken());
|
||||
config.getSync().setTokenLibrus(instanceIdResult.getToken());
|
||||
config.getSync().setTokenLibrusList(new ArrayList<>());
|
||||
}
|
||||
});
|
||||
FirebaseInstanceId.getInstance(pushVulcanApp).getInstanceId().addOnSuccessListener(instanceIdResult -> {
|
||||
if (!instanceIdResult.getToken().equals(config.getSync().getTokenVulcan())) {
|
||||
Log.d(TAG, "Token for Vulcan is " + instanceIdResult.getToken());
|
||||
config.getSync().setTokenVulcan(instanceIdResult.getToken());
|
||||
config.getSync().setTokenVulcanList(new ArrayList<>());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
FirebaseMessaging.getInstance().subscribeToTopic(getPackageName());
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void loadConfig()
|
||||
{
|
||||
appConfig = new AppConfig(this);
|
||||
|
||||
|
||||
if (appSharedPrefs.contains("config")) {
|
||||
// remove old-format config, save the new one and empty the incorrectly-nulled config
|
||||
appConfig = gson.fromJson(appSharedPrefs.getString("config", ""), AppConfig.class);
|
||||
appSharedPrefs.edit().remove("config").apply();
|
||||
saveConfig();
|
||||
appConfig = new AppConfig(this);
|
||||
}
|
||||
|
||||
if (appSharedPrefs.contains("profiles")) {
|
||||
SharedPreferences.Editor appSharedPrefsEditor = appSharedPrefs.edit();
|
||||
|
||||
appSharedPrefsEditor.remove("profiles");
|
||||
appSharedPrefsEditor.apply();
|
||||
//profilesSave();
|
||||
}
|
||||
|
||||
|
||||
Map<String,?> keys = appSharedPrefs.getAll();
|
||||
for (Map.Entry<String,?> entry : keys.entrySet()) {
|
||||
if (entry.getKey().startsWith("app.appConfig.")) {
|
||||
String fieldName = entry.getKey().replace("app.appConfig.", "");
|
||||
|
||||
try {
|
||||
Field field = AppConfig.class.getField(fieldName);
|
||||
Object object;
|
||||
try {
|
||||
object = gson.fromJson(entry.getValue().toString(), field.getGenericType());
|
||||
} catch (JsonSyntaxException e) {
|
||||
Log.d(TAG, "For field "+fieldName);
|
||||
e.printStackTrace();
|
||||
object = entry.getValue().toString();
|
||||
}
|
||||
if (object != null)
|
||||
field.set(appConfig, object);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
Log.w(TAG, "Should remove app.appConfig."+fieldName);
|
||||
//appSharedPrefs.edit().remove("app.appConfig."+fieldName).apply(); TODO migration
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (appConfig == null) {
|
||||
appConfig = new AppConfig(this);
|
||||
}
|
||||
}
|
||||
public void saveConfig()
|
||||
{
|
||||
try {
|
||||
appConfig.savePending = false;
|
||||
|
||||
SharedPreferences.Editor appSharedPrefsEditor = appSharedPrefs.edit();
|
||||
|
||||
JsonObject appConfigJson = gson.toJsonTree(appConfig).getAsJsonObject();
|
||||
for (Map.Entry<String, JsonElement> entry : appConfigJson.entrySet()) {
|
||||
String jsonObj;
|
||||
jsonObj = entry.getValue().toString();
|
||||
|
||||
appSharedPrefsEditor.putString("app.appConfig." + entry.getKey(), jsonObj);
|
||||
}
|
||||
|
||||
appSharedPrefsEditor.apply();
|
||||
}
|
||||
catch (ConcurrentModificationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//appSharedPrefs.edit().putString("config", gson.toJson(appConfig)).apply();
|
||||
}
|
||||
public void saveConfig(String ... fieldNames)
|
||||
{
|
||||
appConfig.savePending = false;
|
||||
|
||||
SharedPreferences.Editor appSharedPrefsEditor = appSharedPrefs.edit();
|
||||
|
||||
for (String fieldName: fieldNames) {
|
||||
try {
|
||||
Object object = AppConfig.class.getField(fieldName).get(appConfig);
|
||||
appSharedPrefsEditor.putString("app.appConfig."+fieldName, gson.toJson(object));
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ConcurrentModificationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
appSharedPrefsEditor.apply();
|
||||
//appSharedPrefs.edit().putString("config", gson.toJson(appConfig)).apply();
|
||||
}
|
||||
|
||||
public void profileSave() {
|
||||
AsyncTask.execute(() -> {
|
||||
db.profileDao().add(profile);
|
||||
});
|
||||
}
|
||||
|
||||
public void profileSaveAsync() {
|
||||
AsyncTask.execute(() -> {
|
||||
db.profileDao().add(profile);
|
||||
});
|
||||
}
|
||||
public void profileSaveAsync(Profile profile) {
|
||||
AsyncTask.execute(() -> {
|
||||
db.profileDao().add(profile);
|
||||
});
|
||||
}
|
||||
|
||||
public void profileLoadById(int id) {
|
||||
profileLoadById(id, false);
|
||||
}
|
||||
public void profileLoadById(int id, boolean loadedLast) {
|
||||
//Log.d(TAG, "Loading ID "+id);
|
||||
|
||||
if (profile == null || profile.getId() != id) {
|
||||
profile = db.profileDao().getByIdNow(id);
|
||||
|
||||
if (profile != null) {
|
||||
MainActivity.Companion.setUseOldMessages(profile.getLoginStoreType() == LOGIN_TYPE_MOBIDZIENNIK && appConfig.mobidziennikOldMessages == 1);
|
||||
profileId = profile.getId();
|
||||
appSharedPrefs.edit().putInt("current_profile_id", profile.getId()).apply();
|
||||
config.setProfile(profileId);
|
||||
}
|
||||
else if (!loadedLast) {
|
||||
profileLoadById(profileLastId(), true);
|
||||
}
|
||||
else {
|
||||
profileId = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int profileFirstId() {
|
||||
Integer id = db.profileDao().getFirstId();
|
||||
return id == null ? 1 : id;
|
||||
}
|
||||
|
||||
public int profileLastId() {
|
||||
Integer id = db.profileDao().getLastId();
|
||||
return id == null ? 1 : id;
|
||||
}
|
||||
|
||||
|
||||
public Context getContext()
|
||||
{
|
||||
return mContext;
|
||||
}
|
||||
|
||||
public void checkDevModePassword() {
|
||||
try {
|
||||
devMode = Utils.AESCrypt.decrypt("nWFVxY65Pa8/aRrT7EylNAencmOD+IxUY2Gg/beiIWY=", config.getDevModePassword()).equals("ok here you go it's enabled now")
|
||||
|| BuildConfig.DEBUG;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
devMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
}*/
|
@ -1,39 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.utils.models;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import pl.szczodrzynski.edziennik.App;
|
||||
import pl.szczodrzynski.edziennik.ui.widgets.WidgetConfig;
|
||||
|
||||
public class AppConfig {
|
||||
|
||||
public List<Notification> notifications;
|
||||
|
||||
public AppConfig(App _app) {
|
||||
notifications = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Map<Integer, WidgetConfig> widgetTimetableConfigs = new TreeMap<>();
|
||||
|
||||
public boolean savePending = false;
|
||||
|
||||
|
||||
public String updateVersion = "";
|
||||
public String updateUrl = "";
|
||||
public String updateFilename = "";
|
||||
public boolean updateMandatory = false;
|
||||
public boolean updateDirect = false;
|
||||
|
||||
public boolean webPushEnabled = false;
|
||||
|
||||
|
||||
public int mobidziennikOldMessages = -1;
|
||||
|
||||
@NonNull
|
||||
public boolean dontShowAppManagerDialog = false;
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.utils.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static pl.szczodrzynski.edziennik.utils.Utils.contains;
|
||||
|
||||
public class Endpoint {
|
||||
public boolean defaultActive;
|
||||
|
||||
public boolean onlyFullSync;
|
||||
|
||||
public boolean enabled;
|
||||
|
||||
public Endpoint(String name, boolean defaultActive, boolean onlyFullSync, List<String> changedEndpoints) {
|
||||
this.defaultActive = defaultActive;
|
||||
this.onlyFullSync = onlyFullSync;
|
||||
this.enabled = defaultActive;
|
||||
if (changedEndpoints == null)
|
||||
return;
|
||||
if (contains(changedEndpoints, name))
|
||||
this.enabled = !this.enabled;
|
||||
/*for (String changedEndpoint: changedEndpoints) {
|
||||
if (changedEndpoint.equals(name))
|
||||
this.enabled = !this.enabled;
|
||||
}*/
|
||||
}
|
||||
}
|
@ -1,168 +0,0 @@
|
||||
package pl.szczodrzynski.edziennik.utils.models;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import pl.szczodrzynski.edziennik.R;
|
||||
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_AUTO_ARCHIVING;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_ERROR;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_FEEDBACK_MESSAGE;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_GENERAL;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_LUCKY_NUMBER;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_NEW_ANNOUNCEMENT;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_NEW_ATTENDANCE;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_NEW_EVENT;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_NEW_GRADE;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_NEW_HOMEWORK;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_NEW_MESSAGE;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_NEW_NOTICE;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_NEW_SHARED_EVENT;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_SERVER_MESSAGE;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_TIMETABLE_CHANGED;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_TIMETABLE_LESSON_CHANGE;
|
||||
import static pl.szczodrzynski.edziennik.data.db.entity.Notification.TYPE_UPDATE;
|
||||
|
||||
public class Notification {
|
||||
public int profileId;
|
||||
public String title;
|
||||
public boolean notified;
|
||||
public boolean seen;
|
||||
public int redirectFragmentId;
|
||||
public JsonObject extras;
|
||||
public int type;
|
||||
public String text;
|
||||
public long addedDate;
|
||||
public int id;
|
||||
|
||||
public Notification(Context context, String text) {
|
||||
this.profileId = -1;
|
||||
this.title = context.getString(R.string.notification);
|
||||
this.type = TYPE_GENERAL;
|
||||
this.text = text;
|
||||
this.redirectFragmentId = -1;
|
||||
this.extras = new JsonObject();
|
||||
this.notified = false;
|
||||
this.seen = false;
|
||||
this.addedDate = System.currentTimeMillis();
|
||||
this.id = new Random().nextInt(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public Notification withProfileData(int profileId, String profileName) {
|
||||
this.profileId = profileId;
|
||||
this.title = profileName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Notification withProfileData(int profileId) {
|
||||
this.profileId = profileId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Notification withTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Notification withType(int type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Notification withFragmentRedirect(int redirectFragmentId) {
|
||||
this.redirectFragmentId = redirectFragmentId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Notification withLongExtra(String key, long value) {
|
||||
this.extras.addProperty(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Notification withStringExtra(String key, String value) {
|
||||
this.extras.addProperty(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Notification withAddedDate(long addedDate) {
|
||||
this.addedDate = addedDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static String stringType(Context context, int errorCode)
|
||||
{
|
||||
switch (errorCode) {
|
||||
case TYPE_UPDATE:
|
||||
return context.getString(R.string.notification_type_update);
|
||||
case TYPE_ERROR:
|
||||
return context.getString(R.string.notification_type_error);
|
||||
case TYPE_TIMETABLE_CHANGED:
|
||||
return context.getString(R.string.notification_type_timetable_change);
|
||||
case TYPE_TIMETABLE_LESSON_CHANGE:
|
||||
return context.getString(R.string.notification_type_timetable_lesson_change);
|
||||
case TYPE_NEW_GRADE:
|
||||
return context.getString(R.string.notification_type_new_grade);
|
||||
case TYPE_NEW_EVENT:
|
||||
return context.getString(R.string.notification_type_new_event);
|
||||
case TYPE_NEW_HOMEWORK:
|
||||
return context.getString(R.string.notification_type_new_homework);
|
||||
case TYPE_NEW_SHARED_EVENT:
|
||||
return context.getString(R.string.notification_type_new_shared_event);
|
||||
case TYPE_NEW_MESSAGE:
|
||||
return context.getString(R.string.notification_type_new_message);
|
||||
case TYPE_NEW_NOTICE:
|
||||
return context.getString(R.string.notification_type_notice);
|
||||
case TYPE_NEW_ATTENDANCE:
|
||||
return context.getString(R.string.notification_type_attendance);
|
||||
case TYPE_SERVER_MESSAGE:
|
||||
return context.getString(R.string.notification_type_server_message);
|
||||
case TYPE_LUCKY_NUMBER:
|
||||
return context.getString(R.string.notification_type_lucky_number);
|
||||
case TYPE_FEEDBACK_MESSAGE:
|
||||
return context.getString(R.string.notification_type_feedback_message);
|
||||
case TYPE_NEW_ANNOUNCEMENT:
|
||||
return context.getString(R.string.notification_type_new_announcement);
|
||||
case TYPE_AUTO_ARCHIVING:
|
||||
return context.getString(R.string.notification_type_auto_archiving);
|
||||
default:
|
||||
case TYPE_GENERAL:
|
||||
return context.getString(R.string.notification_type_general);
|
||||
}
|
||||
}
|
||||
|
||||
public void fillIntent(Intent intent) {
|
||||
if (profileId != -1)
|
||||
intent.putExtra("profileId", profileId);
|
||||
|
||||
/*if (redirectFragmentId == DRAWER_ITEM_MESSAGES)
|
||||
redirectFragmentId = DRAWER_ITEM_MESSAGES_INBOX;*/
|
||||
|
||||
if (redirectFragmentId != -1)
|
||||
intent.putExtra("fragmentId", redirectFragmentId);
|
||||
|
||||
try {
|
||||
for (Map.Entry<String, JsonElement> entry: extras.entrySet()) {
|
||||
JsonElement value = entry.getValue();
|
||||
if (!value.isJsonPrimitive())
|
||||
continue;
|
||||
JsonPrimitive primitive = value.getAsJsonPrimitive();
|
||||
if (primitive.isNumber()) {
|
||||
intent.putExtra(entry.getKey(), primitive.getAsLong());
|
||||
}
|
||||
else if (primitive.isString()) {
|
||||
intent.putExtra(entry.getKey(), primitive.getAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user