2021-02-13 20:31:38 +01:00
|
|
|
package org.mian.gitnex.core;
|
|
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
import android.content.Context;
|
2023-03-10 19:50:15 +01:00
|
|
|
import com.google.android.material.color.DynamicColors;
|
2021-02-13 20:31:38 +01:00
|
|
|
import org.acra.ACRA;
|
|
|
|
import org.acra.BuildConfig;
|
|
|
|
import org.acra.ReportField;
|
|
|
|
import org.acra.config.CoreConfigurationBuilder;
|
|
|
|
import org.acra.config.LimiterConfigurationBuilder;
|
|
|
|
import org.acra.config.MailSenderConfigurationBuilder;
|
2022-04-25 07:42:52 +02:00
|
|
|
import org.acra.config.NotificationConfigurationBuilder;
|
2021-02-13 20:31:38 +01:00
|
|
|
import org.acra.data.StringFormat;
|
|
|
|
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.database.models.UserAccount;
|
2024-03-18 06:12:24 +01:00
|
|
|
import org.mian.gitnex.helpers.AppDatabaseSettings;
|
2021-02-13 20:31:38 +01:00
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
|
|
|
import org.mian.gitnex.helpers.FontsOverride;
|
|
|
|
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-02-13 20:31:38 +01:00
|
|
|
import org.mian.gitnex.notifications.Notifications;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author opyale
|
|
|
|
*/
|
|
|
|
public class MainApplication extends Application {
|
|
|
|
|
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 currentAccount;
|
2022-08-15 16:26:02 +02:00
|
|
|
private TinyDB tinyDB;
|
2021-02-13 20:31:38 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
|
|
|
|
super.onCreate();
|
|
|
|
|
2021-04-13 20:56:50 +02:00
|
|
|
Context appCtx = getApplicationContext();
|
2021-02-13 20:31:38 +01:00
|
|
|
tinyDB = TinyDB.getInstance(appCtx);
|
|
|
|
|
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
|
|
|
currentAccount = AccountContext.fromId(tinyDB.getInt("currentActiveAccountId", 0), appCtx);
|
2021-08-03 09:41:40 +02:00
|
|
|
|
2024-03-18 06:12:24 +01:00
|
|
|
AppDatabaseSettings.initDefaultSettings(getApplicationContext());
|
|
|
|
|
|
|
|
if (Boolean.parseBoolean(
|
|
|
|
AppDatabaseSettings.getSettingsValue(getApplicationContext(), "prefsMigration"))) {
|
|
|
|
AppDatabaseSettings.prefsMigration(getApplicationContext());
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDatabaseSettings.updateSettingsValue(
|
|
|
|
getApplicationContext(), "false", AppDatabaseSettings.APP_BIOMETRIC_LIFE_CYCLE_KEY);
|
2021-02-13 20:31:38 +01:00
|
|
|
|
2022-04-25 07:42:52 +02:00
|
|
|
FontsOverride.setDefaultFont(getBaseContext());
|
2021-02-13 20:31:38 +01:00
|
|
|
|
2021-03-30 16:31:39 +02:00
|
|
|
Notifications.createChannels(appCtx);
|
2023-03-10 19:50:15 +01:00
|
|
|
DynamicColors.applyToActivitiesIfAvailable(this);
|
2021-03-30 16:31:39 +02:00
|
|
|
|
2024-03-18 06:12:24 +01:00
|
|
|
if (Boolean.parseBoolean(
|
|
|
|
AppDatabaseSettings.getSettingsValue(
|
2024-03-24 12:16:17 +01:00
|
|
|
getApplicationContext(), AppDatabaseSettings.APP_CRASH_REPORTS_KEY))) {
|
2021-02-13 20:31:38 +01:00
|
|
|
|
2022-10-01 06:16:19 +02:00
|
|
|
CoreConfigurationBuilder ACRABuilder = new CoreConfigurationBuilder();
|
2021-02-13 20:31:38 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
ACRABuilder.withBuildConfigClass(BuildConfig.class)
|
|
|
|
.withReportContent(
|
|
|
|
ReportField.ANDROID_VERSION,
|
|
|
|
ReportField.PHONE_MODEL,
|
|
|
|
ReportField.STACK_TRACE,
|
|
|
|
ReportField.AVAILABLE_MEM_SIZE,
|
|
|
|
ReportField.BRAND)
|
|
|
|
.setReportFormat(StringFormat.KEY_VALUE_LIST);
|
2022-10-01 06:16:19 +02:00
|
|
|
|
|
|
|
ACRABuilder.withPluginConfigurations(
|
|
|
|
new NotificationConfigurationBuilder()
|
|
|
|
.withTitle(getString(R.string.crashTitle))
|
|
|
|
.withResIcon(R.drawable.gitnex_transparent)
|
|
|
|
.withChannelName(getString(R.string.setCrashReports))
|
|
|
|
.withText(getString(R.string.crashMessage))
|
|
|
|
.build());
|
|
|
|
|
|
|
|
ACRABuilder.withPluginConfigurations(
|
|
|
|
new MailSenderConfigurationBuilder()
|
|
|
|
.withMailTo(getResources().getString(R.string.appEmail))
|
|
|
|
.withSubject(
|
|
|
|
getResources()
|
|
|
|
.getString(
|
|
|
|
R.string.crashReportEmailSubject,
|
2024-03-24 12:16:17 +01:00
|
|
|
AppUtil.getAppBuildNo(getApplicationContext())))
|
2022-10-01 06:16:19 +02:00
|
|
|
.withReportAsFile(true)
|
|
|
|
.build());
|
|
|
|
|
|
|
|
ACRABuilder.withPluginConfigurations(
|
|
|
|
new LimiterConfigurationBuilder().withEnabled(true).build());
|
2021-02-13 20:31:38 +01:00
|
|
|
|
|
|
|
ACRA.init(this, ACRABuilder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-24 12:16:17 +01:00
|
|
|
@Override
|
|
|
|
protected void attachBaseContext(Context context) {
|
|
|
|
|
|
|
|
super.attachBaseContext(context);
|
|
|
|
|
|
|
|
tinyDB = TinyDB.getInstance(context);
|
|
|
|
}
|
|
|
|
|
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 boolean switchToAccount(UserAccount userAccount, boolean tmp) {
|
2022-09-21 07:43:00 +02:00
|
|
|
if (!tmp || tinyDB.getInt("currentActiveAccountId") != userAccount.getAccountId()) {
|
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
|
|
|
currentAccount = new AccountContext(userAccount);
|
2022-09-21 07:43:00 +02:00
|
|
|
if (!tmp) {
|
2022-08-15 16:26:02 +02:00
|
|
|
tinyDB.putInt("currentActiveAccountId", userAccount.getAccountId());
|
|
|
|
}
|
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
|
|
|
return true;
|
2021-03-09 22:15:42 +01:00
|
|
|
}
|
2021-04-13 20:56:50 +02:00
|
|
|
|
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
|
|
|
return false;
|
2021-02-13 20:31:38 +01:00
|
|
|
}
|
|
|
|
}
|