2020-10-23 20:13:13 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.View;
|
2021-12-17 20:56:12 +01:00
|
|
|
import android.widget.CompoundButton;
|
2020-10-23 20:13:13 +02:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2021-12-17 20:56:12 +01:00
|
|
|
import com.google.android.material.switchmaterial.SwitchMaterial;
|
2020-10-23 20:13:13 +02:00
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.databinding.ActivitySettingsGeneralBinding;
|
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
2020-10-29 14:13:19 +01:00
|
|
|
import org.mian.gitnex.helpers.Version;
|
2020-10-23 20:13:13 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class SettingsGeneralActivity extends BaseActivity {
|
|
|
|
|
|
|
|
private ActivitySettingsGeneralBinding viewBinding;
|
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
|
2020-10-29 14:13:19 +01:00
|
|
|
private List<String> homeScreenList;
|
|
|
|
private static int homeScreenSelectedChoice = 0;
|
|
|
|
|
2021-06-05 16:07:05 +02:00
|
|
|
private List<String> linkHandlerDefaultScreen;
|
2020-10-29 14:13:19 +01:00
|
|
|
private static int defaultLinkHandlerScreenSelectedChoice = 0;
|
2020-10-23 20:13:13 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
viewBinding = ActivitySettingsGeneralBinding.inflate(getLayoutInflater());
|
2021-01-26 18:43:25 +01:00
|
|
|
setContentView(viewBinding.getRoot());
|
2020-10-23 20:13:13 +02:00
|
|
|
|
|
|
|
initCloseListener();
|
|
|
|
viewBinding.close.setOnClickListener(onClickListener);
|
|
|
|
|
2020-10-29 14:13:19 +01:00
|
|
|
// home screen
|
2021-06-05 16:07:05 +02:00
|
|
|
String[] appHomeDefaultScreen = getResources().getStringArray(R.array.appDefaultHomeScreen);
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2021-06-05 16:07:05 +02:00
|
|
|
String[] appHomeDefaultScreenNew = getResources().getStringArray(R.array.appDefaultHomeScreenNew);
|
2020-10-29 14:13:19 +01: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
|
|
|
if(getAccount().requiresVersion("1.12.3")) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2021-06-05 16:07:05 +02:00
|
|
|
appHomeDefaultScreen = appHomeDefaultScreenNew;
|
2020-10-29 14:13:19 +01:00
|
|
|
}
|
|
|
|
|
2021-06-05 16:07:05 +02:00
|
|
|
homeScreenList = new ArrayList<>(Arrays.asList(appHomeDefaultScreen));
|
2020-10-29 14:13:19 +01:00
|
|
|
String[] homeScreenArray = new String[homeScreenList.size()];
|
|
|
|
homeScreenList.toArray(homeScreenArray);
|
|
|
|
|
|
|
|
if(homeScreenSelectedChoice == 0) {
|
|
|
|
|
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
|
|
|
homeScreenSelectedChoice = tinyDB.getInt("homeScreenId", 0);
|
2021-12-15 20:37:53 +01:00
|
|
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.navMyRepos));
|
2020-10-29 14:13:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(homeScreenSelectedChoice == 1) {
|
|
|
|
|
|
|
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleStarredRepos));
|
|
|
|
}
|
|
|
|
else if(homeScreenSelectedChoice == 2) {
|
|
|
|
|
2021-12-15 20:37:53 +01:00
|
|
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.navOrg));
|
2020-10-29 14:13:19 +01:00
|
|
|
}
|
|
|
|
else if(homeScreenSelectedChoice == 3) {
|
|
|
|
|
2021-12-15 20:37:53 +01:00
|
|
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.navRepos));
|
2020-10-29 14:13:19 +01:00
|
|
|
}
|
|
|
|
else if(homeScreenSelectedChoice == 4) {
|
|
|
|
|
2021-12-15 20:37:53 +01:00
|
|
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.navProfile));
|
2020-10-29 14:13:19 +01:00
|
|
|
}
|
|
|
|
else if(homeScreenSelectedChoice == 5) {
|
|
|
|
|
|
|
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleExplore));
|
|
|
|
}
|
|
|
|
else if(homeScreenSelectedChoice == 6) {
|
|
|
|
|
|
|
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.titleDrafts));
|
|
|
|
}
|
|
|
|
else if(homeScreenSelectedChoice == 7) {
|
|
|
|
|
|
|
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleNotifications));
|
|
|
|
}
|
|
|
|
|
|
|
|
viewBinding.homeScreenFrame.setOnClickListener(setDefaultHomeScreen -> {
|
|
|
|
|
|
|
|
AlertDialog.Builder hsBuilder = new AlertDialog.Builder(SettingsGeneralActivity.this);
|
|
|
|
|
|
|
|
hsBuilder.setTitle(R.string.settingsHomeScreenSelectorDialogTitle);
|
|
|
|
hsBuilder.setCancelable(homeScreenSelectedChoice != -1);
|
|
|
|
|
|
|
|
hsBuilder.setSingleChoiceItems(homeScreenArray, homeScreenSelectedChoice, (dialogInterfaceHomeScreen, i) -> {
|
|
|
|
|
|
|
|
homeScreenSelectedChoice = i;
|
|
|
|
viewBinding.homeScreenSelected.setText(homeScreenArray[i]);
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putInt("homeScreenId", i);
|
2020-10-29 14:13:19 +01:00
|
|
|
|
|
|
|
dialogInterfaceHomeScreen.dismiss();
|
|
|
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
|
|
});
|
|
|
|
|
|
|
|
AlertDialog hsDialog = hsBuilder.create();
|
|
|
|
hsDialog.show();
|
|
|
|
});
|
|
|
|
// home screen
|
|
|
|
|
|
|
|
// link handler
|
2021-06-05 16:07:05 +02:00
|
|
|
String[] linkHandlerDefaultScreenList = getResources().getStringArray(R.array.linkHandlerDefaultScreen);
|
|
|
|
linkHandlerDefaultScreen = new ArrayList<>(Arrays.asList(linkHandlerDefaultScreenList));
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2021-06-05 16:07:05 +02:00
|
|
|
String[] linksArray = new String[linkHandlerDefaultScreen.size()];
|
|
|
|
linkHandlerDefaultScreen.toArray(linksArray);
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2021-06-05 16:07:05 +02:00
|
|
|
defaultLinkHandlerScreenSelectedChoice = tinyDB.getInt("defaultScreenId");
|
|
|
|
viewBinding.generalDeepLinkSelected.setText(linksArray[defaultLinkHandlerScreenSelectedChoice]);
|
2020-10-23 20:13:13 +02:00
|
|
|
|
|
|
|
viewBinding.setDefaultLinkHandler.setOnClickListener(setDefaultLinkHandler -> {
|
|
|
|
|
|
|
|
AlertDialog.Builder dlBuilder = new AlertDialog.Builder(SettingsGeneralActivity.this);
|
|
|
|
dlBuilder.setTitle(R.string.linkSelectorDialogTitle);
|
|
|
|
|
2020-10-29 14:13:19 +01:00
|
|
|
dlBuilder.setCancelable(defaultLinkHandlerScreenSelectedChoice != -1);
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-10-29 14:13:19 +01:00
|
|
|
dlBuilder.setSingleChoiceItems(linksArray, defaultLinkHandlerScreenSelectedChoice, (dialogInterfaceHomeScreen, i) -> {
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2020-10-29 14:13:19 +01:00
|
|
|
defaultLinkHandlerScreenSelectedChoice = i;
|
2020-10-23 20:13:13 +02:00
|
|
|
viewBinding.generalDeepLinkSelected.setText(linksArray[i]);
|
2020-11-02 16:17:00 +01:00
|
|
|
tinyDB.putInt("defaultScreenId", i);
|
2020-10-23 20:13:13 +02:00
|
|
|
|
|
|
|
dialogInterfaceHomeScreen.dismiss();
|
|
|
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
|
|
});
|
|
|
|
|
|
|
|
AlertDialog dlDialog = dlBuilder.create();
|
|
|
|
dlDialog.show();
|
|
|
|
});
|
2020-10-29 14:13:19 +01:00
|
|
|
// link handler
|
2021-12-17 20:56:12 +01:00
|
|
|
|
|
|
|
// custom tabs
|
|
|
|
viewBinding.switchTabs.setChecked(tinyDB.getBoolean("useCustomTabs"));
|
|
|
|
viewBinding.switchTabs.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
|
tinyDB.putBoolean("useCustomTabs", isChecked);
|
|
|
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
|
|
});
|
|
|
|
viewBinding.customTabsFrame.setOnClickListener(v -> viewBinding.switchTabs.setChecked(!viewBinding.switchTabs.isChecked()));
|
|
|
|
// custom tabs
|
2020-10-23 20:13:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initCloseListener() { onClickListener = view -> finish(); }
|
|
|
|
}
|