2020-01-01 21:03:53 +01:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
import android.content.Context;
|
2020-01-01 21:03:53 +01:00
|
|
|
import android.os.Bundle;
|
2021-08-03 09:41:40 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2020-01-01 21:03:53 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
2021-08-03 09:41:40 +02:00
|
|
|
import androidx.biometric.BiometricPrompt;
|
|
|
|
import androidx.core.content.ContextCompat;
|
2022-09-21 07:43:00 +02:00
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.concurrent.Executor;
|
2020-01-07 13:27:05 +01:00
|
|
|
import org.mian.gitnex.R;
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
import org.mian.gitnex.core.MainApplication;
|
2024-03-18 06:12:24 +01:00
|
|
|
import org.mian.gitnex.helpers.AppDatabaseSettings;
|
2020-07-07 19:15:01 +02:00
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
2020-04-11 08:06:39 +02:00
|
|
|
import org.mian.gitnex.helpers.TimeHelper;
|
2020-07-07 19:15:01 +02:00
|
|
|
import org.mian.gitnex.helpers.TinyDB;
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
import org.mian.gitnex.helpers.contexts.AccountContext;
|
2021-03-30 16:31:39 +02:00
|
|
|
import org.mian.gitnex.notifications.Notifications;
|
2020-01-01 21:03:53 +01:00
|
|
|
|
|
|
|
/**
|
2022-07-29 14:08:44 +02:00
|
|
|
* @author M M Arif
|
2020-01-01 21:03:53 +01:00
|
|
|
*/
|
|
|
|
public abstract class BaseActivity extends AppCompatActivity {
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
protected TinyDB tinyDB;
|
|
|
|
|
|
|
|
protected Context ctx = this;
|
|
|
|
protected Context appCtx;
|
|
|
|
|
2020-04-12 17:19:33 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
2021-02-13 20:31:38 +01:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
this.appCtx = getApplicationContext();
|
|
|
|
this.tinyDB = TinyDB.getInstance(appCtx);
|
2020-04-12 17:19:33 +02:00
|
|
|
|
2024-03-18 06:12:24 +01:00
|
|
|
switch (Integer.parseInt(
|
|
|
|
AppDatabaseSettings.getSettingsValue(ctx, AppDatabaseSettings.APP_THEME_KEY))) {
|
2022-03-27 20:47:08 +02:00
|
|
|
case 0:
|
|
|
|
setTheme(R.style.AppTheme);
|
|
|
|
break;
|
2020-04-28 14:39:41 +02:00
|
|
|
case 1:
|
|
|
|
setTheme(R.style.AppThemeLight);
|
|
|
|
break;
|
2020-11-02 16:17:00 +01:00
|
|
|
case 2:
|
2022-09-21 07:43:00 +02:00
|
|
|
if (TimeHelper.timeBetweenHours(
|
2024-03-18 06:12:24 +01:00
|
|
|
Integer.parseInt(
|
|
|
|
AppDatabaseSettings.getSettingsValue(
|
|
|
|
ctx, AppDatabaseSettings.APP_THEME_AUTO_DARK_HOUR_KEY)),
|
|
|
|
Integer.parseInt(
|
|
|
|
AppDatabaseSettings.getSettingsValue(
|
|
|
|
ctx, AppDatabaseSettings.APP_THEME_AUTO_LIGHT_HOUR_KEY)),
|
|
|
|
Integer.parseInt(
|
|
|
|
AppDatabaseSettings.getSettingsValue(
|
|
|
|
ctx, AppDatabaseSettings.APP_THEME_AUTO_DARK_MIN_KEY)),
|
|
|
|
Integer.parseInt(
|
|
|
|
AppDatabaseSettings.getSettingsValue(
|
|
|
|
ctx, AppDatabaseSettings.APP_THEME_AUTO_LIGHT_MIN_KEY)))) {
|
2020-11-29 22:51:35 +01:00
|
|
|
|
2020-04-28 14:39:41 +02:00
|
|
|
setTheme(R.style.AppTheme);
|
2022-09-21 07:43:00 +02:00
|
|
|
} else {
|
2020-11-29 22:51:35 +01:00
|
|
|
|
2020-04-28 14:39:41 +02:00
|
|
|
setTheme(R.style.AppThemeLight);
|
|
|
|
}
|
|
|
|
break;
|
2020-11-02 16:17:00 +01:00
|
|
|
case 3:
|
2020-08-20 18:21:55 +02:00
|
|
|
setTheme(R.style.AppThemeRetro);
|
|
|
|
break;
|
2020-11-02 16:17:00 +01:00
|
|
|
case 4:
|
2022-09-21 07:43:00 +02:00
|
|
|
if (TimeHelper.timeBetweenHours(
|
2024-03-18 06:12:24 +01:00
|
|
|
Integer.parseInt(
|
|
|
|
AppDatabaseSettings.getSettingsValue(
|
|
|
|
ctx, AppDatabaseSettings.APP_THEME_AUTO_DARK_HOUR_KEY)),
|
|
|
|
Integer.parseInt(
|
|
|
|
AppDatabaseSettings.getSettingsValue(
|
|
|
|
ctx, AppDatabaseSettings.APP_THEME_AUTO_LIGHT_HOUR_KEY)),
|
|
|
|
Integer.parseInt(
|
|
|
|
AppDatabaseSettings.getSettingsValue(
|
|
|
|
ctx, AppDatabaseSettings.APP_THEME_AUTO_DARK_MIN_KEY)),
|
|
|
|
Integer.parseInt(
|
|
|
|
AppDatabaseSettings.getSettingsValue(
|
|
|
|
ctx, AppDatabaseSettings.APP_THEME_AUTO_LIGHT_MIN_KEY)))) {
|
2020-11-29 22:51:35 +01:00
|
|
|
|
2020-08-20 18:21:55 +02:00
|
|
|
setTheme(R.style.AppTheme);
|
2022-09-21 07:43:00 +02:00
|
|
|
} else {
|
2020-11-29 22:51:35 +01:00
|
|
|
|
2020-08-20 18:21:55 +02:00
|
|
|
setTheme(R.style.AppThemeRetro);
|
|
|
|
}
|
|
|
|
break;
|
2020-11-29 22:51:35 +01:00
|
|
|
case 5:
|
|
|
|
setTheme(R.style.AppThemePitchBlack);
|
|
|
|
break;
|
2022-03-27 20:47:08 +02:00
|
|
|
case 7:
|
|
|
|
setTheme(R.style.AppThemeSystemPitchBlack);
|
|
|
|
break;
|
2023-03-10 19:50:15 +01:00
|
|
|
case 8:
|
|
|
|
setTheme(R.style.AppThemeDynamicSystem);
|
|
|
|
break;
|
2023-09-20 17:30:21 +02:00
|
|
|
case 9:
|
|
|
|
setTheme(R.style.AppThemeCodebergDark);
|
|
|
|
break;
|
2020-11-02 16:17:00 +01:00
|
|
|
default:
|
2022-03-27 20:47:08 +02:00
|
|
|
setTheme(R.style.AppThemeSystem);
|
|
|
|
break;
|
2020-04-12 17:19:33 +02:00
|
|
|
}
|
|
|
|
|
2024-03-18 06:12:24 +01:00
|
|
|
String[] locale =
|
|
|
|
AppDatabaseSettings.getSettingsValue(ctx, AppDatabaseSettings.APP_LOCALE_KEY)
|
|
|
|
.split("\\|");
|
|
|
|
|
|
|
|
if (locale[0].equals("0")) {
|
2021-05-29 18:21:48 +02:00
|
|
|
AppUtil.setAppLocale(getResources(), Locale.getDefault().getLanguage());
|
2022-09-21 07:43:00 +02:00
|
|
|
} else {
|
2024-03-18 06:12:24 +01:00
|
|
|
AppUtil.setAppLocale(getResources(), locale[1]);
|
2021-05-29 18:21:48 +02:00
|
|
|
}
|
2021-03-30 16:31:39 +02:00
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
Notifications.startWorker(ctx);
|
2020-04-12 17:19:33 +02:00
|
|
|
}
|
|
|
|
|
2021-08-03 09:41:40 +02:00
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
2024-03-18 06:12:24 +01:00
|
|
|
if (Boolean.parseBoolean(
|
|
|
|
AppDatabaseSettings.getSettingsValue(
|
|
|
|
ctx, AppDatabaseSettings.APP_BIOMETRIC_KEY))
|
|
|
|
&& !Boolean.parseBoolean(
|
|
|
|
AppDatabaseSettings.getSettingsValue(
|
|
|
|
ctx, AppDatabaseSettings.APP_BIOMETRIC_LIFE_CYCLE_KEY))) {
|
2021-08-03 09:41:40 +02:00
|
|
|
|
|
|
|
Executor executor = ContextCompat.getMainExecutor(this);
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
BiometricPrompt biometricPrompt =
|
|
|
|
new BiometricPrompt(
|
|
|
|
this,
|
|
|
|
executor,
|
|
|
|
new BiometricPrompt.AuthenticationCallback() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAuthenticationError(
|
|
|
|
int errorCode, @NonNull CharSequence errString) {
|
|
|
|
|
|
|
|
super.onAuthenticationError(errorCode, errString);
|
|
|
|
|
|
|
|
// Authentication error, close the app
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Authentication succeeded, continue to app
|
|
|
|
@Override
|
|
|
|
public void onAuthenticationSucceeded(
|
|
|
|
@NonNull BiometricPrompt.AuthenticationResult result) {
|
|
|
|
super.onAuthenticationSucceeded(result);
|
2024-03-18 06:12:24 +01:00
|
|
|
AppDatabaseSettings.updateSettingsValue(
|
|
|
|
getApplicationContext(),
|
|
|
|
"true",
|
|
|
|
AppDatabaseSettings.APP_BIOMETRIC_LIFE_CYCLE_KEY);
|
2022-09-21 07:43:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Authentication failed, close the app
|
|
|
|
@Override
|
|
|
|
public void onAuthenticationFailed() {
|
|
|
|
super.onAuthenticationFailed();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
BiometricPrompt.PromptInfo biometricPromptBuilder =
|
|
|
|
new BiometricPrompt.PromptInfo.Builder()
|
|
|
|
.setTitle(getString(R.string.biometricAuthTitle))
|
|
|
|
.setSubtitle(getString(R.string.biometricAuthSubTitle))
|
|
|
|
.setNegativeButtonText(getString(R.string.cancelButton))
|
|
|
|
.build();
|
2021-08-03 09:41:40 +02:00
|
|
|
|
|
|
|
biometricPrompt.authenticate(biometricPromptBuilder);
|
|
|
|
}
|
|
|
|
}
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
|
|
|
|
public AccountContext getAccount() {
|
|
|
|
return ((MainApplication) getApplication()).currentAccount;
|
|
|
|
}
|
2020-01-01 21:03:53 +01:00
|
|
|
}
|