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;
|
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;
|
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;
|
2021-05-29 18:21:48 +02:00
|
|
|
import java.util.Locale;
|
2021-08-03 09:41:40 +02:00
|
|
|
import java.util.concurrent.Executor;
|
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
|
|
|
|
2022-03-27 20:47:08 +02:00
|
|
|
switch(tinyDB.getInt("themeId", 6)) {
|
|
|
|
case 0:
|
|
|
|
setTheme(R.style.AppTheme);
|
|
|
|
break;
|
2020-04-28 14:39:41 +02:00
|
|
|
case 1:
|
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 2:
|
2020-11-29 22:51:35 +01:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
if(TimeHelper.timeBetweenHours(tinyDB.getInt("darkThemeTimeHour", 18), tinyDB.getInt("lightThemeTimeHour", 6), tinyDB.getInt("darkThemeTimeMinute", 0), tinyDB.getInt("lightThemeTimeMinute", 0))) {
|
2020-11-29 22:51:35 +01:00
|
|
|
|
2020-04-28 14:39:41 +02:00
|
|
|
setTheme(R.style.AppTheme);
|
2020-11-29 22:51:35 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2020-04-28 14:39:41 +02:00
|
|
|
setTheme(R.style.AppThemeLight);
|
|
|
|
}
|
|
|
|
break;
|
2020-11-02 16:17:00 +01:00
|
|
|
case 3:
|
2020-11-29 22:51:35 +01:00
|
|
|
|
2020-08-20 18:21:55 +02:00
|
|
|
setTheme(R.style.AppThemeRetro);
|
|
|
|
break;
|
2020-11-02 16:17:00 +01:00
|
|
|
case 4:
|
2022-08-15 16:26:02 +02:00
|
|
|
if(TimeHelper.timeBetweenHours(tinyDB.getInt("darkThemeTimeHour", 18), tinyDB.getInt("lightThemeTimeHour", 6), tinyDB.getInt("darkThemeTimeMinute", 0), tinyDB.getInt("lightThemeTimeMinute", 0))) {
|
2020-11-29 22:51:35 +01:00
|
|
|
|
2020-08-20 18:21:55 +02:00
|
|
|
setTheme(R.style.AppTheme);
|
2020-11-29 22:51:35 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2020-08-20 18:21:55 +02:00
|
|
|
setTheme(R.style.AppThemeRetro);
|
|
|
|
}
|
|
|
|
break;
|
2020-11-29 22:51:35 +01:00
|
|
|
case 5:
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-11-29 22:51:35 +01:00
|
|
|
setTheme(R.style.AppThemePitchBlack);
|
|
|
|
break;
|
2022-03-27 20:47:08 +02:00
|
|
|
case 7:
|
|
|
|
setTheme(R.style.AppThemeSystemPitchBlack);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-05-29 18:21:48 +02:00
|
|
|
String locale = tinyDB.getString("locale");
|
2022-08-15 16:26:02 +02:00
|
|
|
if(locale.isEmpty()) {
|
2021-05-29 18:21:48 +02:00
|
|
|
AppUtil.setAppLocale(getResources(), Locale.getDefault().getLanguage());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
AppUtil.setAppLocale(getResources(), locale);
|
|
|
|
}
|
2021-03-30 16:31:39 +02:00
|
|
|
|
|
|
|
Notifications.startWorker(appCtx);
|
2020-04-12 17:19:33 +02:00
|
|
|
}
|
|
|
|
|
2021-08-03 09:41:40 +02:00
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
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
|
|
|
if(tinyDB.getBoolean("biometricStatus", false) && !tinyDB.getBoolean("biometricLifeCycle")) {
|
2021-08-03 09:41:40 +02:00
|
|
|
|
|
|
|
Executor executor = ContextCompat.getMainExecutor(this);
|
|
|
|
|
|
|
|
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
|
2022-04-25 07:42:52 +02:00
|
|
|
finish();
|
2021-08-03 09:41:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Authentication succeeded, continue to app
|
2022-04-25 07:42:52 +02:00
|
|
|
@Override
|
|
|
|
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
|
|
|
|
super.onAuthenticationSucceeded(result);
|
|
|
|
tinyDB.putBoolean("biometricLifeCycle", true);
|
|
|
|
}
|
2021-08-03 09:41:40 +02:00
|
|
|
|
|
|
|
// Authentication failed, close the app
|
2022-08-15 16:26:02 +02:00
|
|
|
@Override
|
|
|
|
public void onAuthenticationFailed() {
|
2022-04-25 07:42:52 +02:00
|
|
|
super.onAuthenticationFailed();
|
|
|
|
}
|
2021-08-03 09:41:40 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
BiometricPrompt.PromptInfo biometricPromptBuilder = new BiometricPrompt.PromptInfo.Builder().setTitle(getString(R.string.biometricAuthTitle)).setSubtitle(getString(R.string.biometricAuthSubTitle))
|
2021-08-03 09:41:40 +02:00
|
|
|
.setNegativeButtonText(getString(R.string.cancelButton)).build();
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2022-08-15 16:26:02 +02:00
|
|
|
|
2020-01-01 21:03:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|