From 224ead33bf1fa4d89a9385417f28b46c5c358a05 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sun, 23 May 2021 22:29:11 +0200 Subject: [PATCH] Fix going back from about fragment (#908) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Describe what your pull request does and which issue you’re targeting This PR fixes the problem that you can't go back from the "About" section in the settings and it changes the action bar behaviour of the about fragment to keep the design consistent (see below). The activity action bar is hidden [here](https://codeberg.org/qwerty287/GitNex/src/commit/82ffeefdc4f071e5f35f8cec9dd16eca564be7ea/app/src/main/java/org/mian/gitnex/fragments/AboutFragment.java#L35), as the about fragment uses it's own (in my implementation) to keep the design consistent (currently, all sections of the settings are own activitys and their action bar has a close button, except the about section). If you don't like this, I can remove it, but currently, it doesn't look nice integrated. Closes #905 - [X] I carefully read the [contribution guidelines](https://codeberg.org/GitNex/GitNex/src/branch/main/CONTRIBUTING.md). - [X] I'm following the code standards as defined [here](https://codeberg.org/gitnex/GitNex/wiki/Code-Standards). - [X] By submitting this pull request, I permit GitNex to license my work under the [GNU General Public License v3](https://codeberg.org/GitNex/GitNex/src/branch/main/LICENSE). Co-authored-by: qwerty287 Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/908 Reviewed-by: M M Arif Co-authored-by: qwerty287 Co-committed-by: qwerty287 --- .../mian/gitnex/fragments/AboutFragment.java | 18 +++++++- app/src/main/res/layout/fragment_about.xml | 41 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mian/gitnex/fragments/AboutFragment.java b/app/src/main/java/org/mian/gitnex/fragments/AboutFragment.java index c26aeb9f..727321b3 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/AboutFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/AboutFragment.java @@ -6,6 +6,7 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import org.mian.gitnex.R; @@ -13,6 +14,7 @@ import org.mian.gitnex.activities.MainActivity; import org.mian.gitnex.databinding.FragmentAboutBinding; import org.mian.gitnex.helpers.AppUtil; import org.mian.gitnex.helpers.TinyDB; +import java.util.Objects; /** * Author M M Arif @@ -30,7 +32,21 @@ public class AboutFragment extends Fragment { viewBinding.userServerVersion.setText(tinyDb.getString("giteaVersion")); viewBinding.appBuild.setText(String.valueOf(AppUtil.getAppBuildNo(requireContext()))); - ((MainActivity) requireActivity()).setActionBarTitle(getResources().getString(R.string.pageTitleAbout)); + Objects.requireNonNull(((MainActivity) requireActivity()).getSupportActionBar()).hide(); + + viewBinding.close.setOnClickListener(v15 -> { + requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SettingsFragment()).commit(); + Objects.requireNonNull(((MainActivity) requireActivity()).getSupportActionBar()).show(); + }); + + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SettingsFragment()).commit(); + Objects.requireNonNull(((MainActivity) requireActivity()).getSupportActionBar()).show(); + } + }; + requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), callback); viewBinding.donationLinkPatreon.setOnClickListener(v12 -> { diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml index 4ed2cf06..b8137b93 100644 --- a/app/src/main/res/layout/fragment_about.xml +++ b/app/src/main/res/layout/fragment_about.xml @@ -3,6 +3,46 @@ android:layout_width="match_parent" android:layout_height="match_parent" > + + + + + + + + + + + +