GitNex/app/src/main/java/org/mian/gitnex/fragments/SettingsFragment.java

172 lines
5.3 KiB
Java
Raw Normal View History

package org.mian.gitnex.fragments;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.BaseActivity;
import org.mian.gitnex.activities.MainActivity;
import org.mian.gitnex.activities.SettingsAppearanceActivity;
import org.mian.gitnex.activities.SettingsCodeEditorActivity;
import org.mian.gitnex.activities.SettingsGeneralActivity;
import org.mian.gitnex.activities.SettingsNotificationsActivity;
import org.mian.gitnex.activities.SettingsSecurityActivity;
import org.mian.gitnex.databinding.CustomAboutDialogBinding;
import org.mian.gitnex.databinding.FragmentSettingsBinding;
import org.mian.gitnex.helpers.AppUtil;
/**
* @author M M Arif
*/
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;
private Context ctx;
private MaterialAlertDialogBuilder materialAlertDialogBuilder;
@Nullable @Override
public View onCreateView(
@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
FragmentSettingsBinding fragmentSettingsBinding =
FragmentSettingsBinding.inflate(inflater, container, false);
ctx = getContext();
materialAlertDialogBuilder =
new MaterialAlertDialogBuilder(ctx, R.style.ThemeOverlay_Material3_Dialog_Alert);
((MainActivity) requireActivity())
.setActionBarTitle(getResources().getString(R.string.navSettings));
if (((BaseActivity) requireActivity()).getAccount().requiresVersion("1.12.3")) {
fragmentSettingsBinding.notificationsFrame.setVisibility(View.VISIBLE);
}
fragmentSettingsBinding.generalFrame.setOnClickListener(
generalFrameCall -> startActivity(new Intent(ctx, SettingsGeneralActivity.class)));
fragmentSettingsBinding.appearanceFrame.setOnClickListener(
v1 -> startActivity(new Intent(ctx, SettingsAppearanceActivity.class)));
fragmentSettingsBinding.codeEditorFrame.setOnClickListener(
v1 -> startActivity(new Intent(ctx, SettingsCodeEditorActivity.class)));
2020-04-02 02:59:00 +02:00
fragmentSettingsBinding.securityFrame.setOnClickListener(
v1 -> startActivity(new Intent(ctx, SettingsSecurityActivity.class)));
fragmentSettingsBinding.notificationsFrame.setOnClickListener(
v1 -> startActivity(new Intent(ctx, SettingsNotificationsActivity.class)));
fragmentSettingsBinding.rateAppFrame.setOnClickListener(rateApp -> rateThisApp());
fragmentSettingsBinding.aboutAppFrame.setOnClickListener(aboutApp -> showAboutAppDialog());
fragmentSettingsBinding.navLogout.setOnClickListener(
logout -> {
AppUtil.logout(ctx);
requireActivity()
.overridePendingTransition(
android.R.anim.fade_in, android.R.anim.fade_out);
});
return fragmentSettingsBinding.getRoot();
}
public void showAboutAppDialog() {
CustomAboutDialogBinding aboutAppDialogBinding =
CustomAboutDialogBinding.inflate(LayoutInflater.from(ctx));
View view = aboutAppDialogBinding.getRoot();
materialAlertDialogBuilder.setView(view);
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));
});
aboutAppDialogBinding.feedback.setOnClickListener(
v14 -> {
AppUtil.openUrlInBrowser(
requireContext(), getResources().getString(R.string.feedbackLink));
});
if (AppUtil.isPro(requireContext())) {
aboutAppDialogBinding.layoutFrame1.setVisibility(View.GONE);
}
materialAlertDialogBuilder.show();
}
public void rateThisApp() {
try {
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())));
}
}
@Override
public void onResume() {
super.onResume();
if (refreshParent) {
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;
}
}
}