2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.fragments;
|
|
|
|
|
2020-09-27 09:36:57 +02:00
|
|
|
import android.content.ActivityNotFoundException;
|
2020-11-03 20:14:24 +01:00
|
|
|
import android.content.Context;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.content.Intent;
|
2020-09-27 09:36:57 +02:00
|
|
|
import android.net.Uri;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2020-04-07 22:39:08 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.fragment.app.Fragment;
|
2022-08-07 21:34:02 +02:00
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.R;
|
2022-09-14 20:40:44 +02:00
|
|
|
import org.mian.gitnex.activities.BaseActivity;
|
|
|
|
import org.mian.gitnex.activities.MainActivity;
|
|
|
|
import org.mian.gitnex.activities.SettingsAppearanceActivity;
|
2023-06-13 07:23:27 +02:00
|
|
|
import org.mian.gitnex.activities.SettingsCodeEditorActivity;
|
2022-09-14 20:40:44 +02:00
|
|
|
import org.mian.gitnex.activities.SettingsGeneralActivity;
|
|
|
|
import org.mian.gitnex.activities.SettingsNotificationsActivity;
|
|
|
|
import org.mian.gitnex.activities.SettingsSecurityActivity;
|
2021-05-30 19:28:14 +02:00
|
|
|
import org.mian.gitnex.databinding.CustomAboutDialogBinding;
|
2021-01-26 16:10:31 +01:00
|
|
|
import org.mian.gitnex.databinding.FragmentSettingsBinding;
|
2021-05-30 19:28:14 +02:00
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
/**
|
2022-07-29 14:08:44 +02:00
|
|
|
* @author M M Arif
|
2019-06-03 23:25:05 +02:00
|
|
|
*/
|
|
|
|
public class SettingsFragment extends Fragment {
|
|
|
|
|
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 static boolean refreshParent = false;
|
|
|
|
|
2020-11-03 20:14:24 +01:00
|
|
|
private Context ctx;
|
2022-08-07 21:34:02 +02:00
|
|
|
private MaterialAlertDialogBuilder materialAlertDialogBuilder;
|
2020-11-03 20:14:24 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Nullable @Override
|
|
|
|
public View onCreateView(
|
|
|
|
@NonNull LayoutInflater inflater,
|
|
|
|
@Nullable ViewGroup container,
|
|
|
|
@Nullable Bundle savedInstanceState) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
FragmentSettingsBinding fragmentSettingsBinding =
|
|
|
|
FragmentSettingsBinding.inflate(inflater, container, false);
|
2021-01-26 16:10:31 +01:00
|
|
|
|
2020-11-03 20:14:24 +01:00
|
|
|
ctx = getContext();
|
2022-09-21 07:43:00 +02:00
|
|
|
materialAlertDialogBuilder =
|
|
|
|
new MaterialAlertDialogBuilder(ctx, R.style.ThemeOverlay_Material3_Dialog_Alert);
|
2020-03-05 21:56:42 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
((MainActivity) requireActivity())
|
|
|
|
.setActionBarTitle(getResources().getString(R.string.navSettings));
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (((BaseActivity) requireActivity()).getAccount().requiresVersion("1.12.3")) {
|
2020-11-03 20:14:24 +01:00
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
fragmentSettingsBinding.notificationsFrame.setVisibility(View.VISIBLE);
|
2020-11-03 20:14:24 +01:00
|
|
|
}
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
fragmentSettingsBinding.generalFrame.setOnClickListener(
|
|
|
|
generalFrameCall -> startActivity(new Intent(ctx, SettingsGeneralActivity.class)));
|
2020-11-03 20:14:24 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
fragmentSettingsBinding.appearanceFrame.setOnClickListener(
|
|
|
|
v1 -> startActivity(new Intent(ctx, SettingsAppearanceActivity.class)));
|
2020-10-23 20:13:13 +02:00
|
|
|
|
2023-06-13 07:23:27 +02:00
|
|
|
fragmentSettingsBinding.codeEditorFrame.setOnClickListener(
|
|
|
|
v1 -> startActivity(new Intent(ctx, SettingsCodeEditorActivity.class)));
|
2020-04-02 02:59:00 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
fragmentSettingsBinding.securityFrame.setOnClickListener(
|
|
|
|
v1 -> startActivity(new Intent(ctx, SettingsSecurityActivity.class)));
|
2020-07-09 13:55:09 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
fragmentSettingsBinding.notificationsFrame.setOnClickListener(
|
|
|
|
v1 -> startActivity(new Intent(ctx, SettingsNotificationsActivity.class)));
|
2020-04-04 21:20:25 +02:00
|
|
|
|
2021-05-30 19:28:14 +02:00
|
|
|
fragmentSettingsBinding.rateAppFrame.setOnClickListener(rateApp -> rateThisApp());
|
2020-09-27 09:36:57 +02:00
|
|
|
|
2021-05-30 19:28:14 +02:00
|
|
|
fragmentSettingsBinding.aboutAppFrame.setOnClickListener(aboutApp -> showAboutAppDialog());
|
2020-09-27 09:36:57 +02:00
|
|
|
|
2023-03-26 08:11:59 +02:00
|
|
|
fragmentSettingsBinding.navLogout.setOnClickListener(
|
|
|
|
logout -> {
|
|
|
|
AppUtil.logout(ctx);
|
|
|
|
requireActivity()
|
|
|
|
.overridePendingTransition(
|
|
|
|
android.R.anim.fade_in, android.R.anim.fade_out);
|
|
|
|
});
|
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
return fragmentSettingsBinding.getRoot();
|
2021-05-30 19:28:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void showAboutAppDialog() {
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
CustomAboutDialogBinding aboutAppDialogBinding =
|
|
|
|
CustomAboutDialogBinding.inflate(LayoutInflater.from(ctx));
|
2021-05-30 19:28:14 +02:00
|
|
|
View view = aboutAppDialogBinding.getRoot();
|
2022-08-07 21:34:02 +02:00
|
|
|
|
|
|
|
materialAlertDialogBuilder.setView(view);
|
2021-05-30 19:28:14 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
aboutAppDialogBinding.appVersionBuild.setText(
|
|
|
|
getString(
|
|
|
|
R.string.appVersionBuild,
|
|
|
|
AppUtil.getAppVersion(ctx),
|
|
|
|
AppUtil.getAppBuildNo(ctx)));
|
|
|
|
aboutAppDialogBinding.userServerVersion.setText(
|
|
|
|
((BaseActivity) requireActivity()).getAccount().getServerVersion().toString());
|
|
|
|
|
|
|
|
aboutAppDialogBinding.donationLinkPatreon.setOnClickListener(
|
|
|
|
v12 -> {
|
|
|
|
AppUtil.openUrlInBrowser(
|
|
|
|
requireContext(),
|
|
|
|
getResources().getString(R.string.supportLinkPatreon));
|
|
|
|
});
|
|
|
|
|
|
|
|
aboutAppDialogBinding.donationLinkBuyMeaCoffee.setOnClickListener(
|
|
|
|
v11 -> {
|
|
|
|
AppUtil.openUrlInBrowser(
|
|
|
|
requireContext(),
|
|
|
|
getResources().getString(R.string.supportLinkBuyMeaCoffee));
|
|
|
|
});
|
|
|
|
|
|
|
|
aboutAppDialogBinding.translateLink.setOnClickListener(
|
|
|
|
v13 -> {
|
|
|
|
AppUtil.openUrlInBrowser(
|
|
|
|
requireContext(), getResources().getString(R.string.crowdInLink));
|
|
|
|
});
|
|
|
|
|
|
|
|
aboutAppDialogBinding.appWebsite.setOnClickListener(
|
|
|
|
v14 -> {
|
|
|
|
AppUtil.openUrlInBrowser(
|
|
|
|
requireContext(), getResources().getString(R.string.appWebsiteLink));
|
|
|
|
});
|
|
|
|
|
2023-06-13 07:23:27 +02:00
|
|
|
aboutAppDialogBinding.feedback.setOnClickListener(
|
|
|
|
v14 -> {
|
|
|
|
AppUtil.openUrlInBrowser(
|
|
|
|
requireContext(), getResources().getString(R.string.feedbackLink));
|
|
|
|
});
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (AppUtil.isPro(requireContext())) {
|
2023-06-13 07:23:27 +02:00
|
|
|
aboutAppDialogBinding.layoutFrame1.setVisibility(View.GONE);
|
2021-05-30 19:28:14 +02:00
|
|
|
}
|
2021-03-21 16:56:54 +01:00
|
|
|
|
2022-08-07 21:34:02 +02:00
|
|
|
materialAlertDialogBuilder.show();
|
2020-04-07 22:39:08 +02:00
|
|
|
}
|
|
|
|
|
2020-09-27 09:36:57 +02:00
|
|
|
public void rateThisApp() {
|
|
|
|
|
|
|
|
try {
|
2022-09-21 07:43:00 +02:00
|
|
|
startActivity(
|
|
|
|
new Intent(
|
|
|
|
Intent.ACTION_VIEW,
|
|
|
|
Uri.parse(
|
|
|
|
"market://details?id=" + requireActivity().getPackageName())));
|
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
startActivity(
|
|
|
|
new Intent(
|
|
|
|
Intent.ACTION_VIEW,
|
|
|
|
Uri.parse(
|
|
|
|
"https://play.google.com/store/apps/details?id="
|
|
|
|
+ requireActivity().getPackageName())));
|
2020-09-27 09:36:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:39:08 +02:00
|
|
|
@Override
|
2020-04-26 15:36:33 +02:00
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2020-04-07 22:39:08 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (refreshParent) {
|
2020-09-27 09:36:57 +02:00
|
|
|
requireActivity().recreate();
|
|
|
|
requireActivity().overridePendingTransition(0, 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
|
|
|
refreshParent = false;
|
2020-04-26 15:36:33 +02:00
|
|
|
}
|
2020-04-07 22:39:08 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|