Improve behavior of Android's back button in file browser (#1006)

Co-authored-by: qwerty287 <ndev@web.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1006
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
This commit is contained in:
qwerty287 2021-10-24 12:17:54 +02:00 committed by M M Arif
parent 2cf702982a
commit b4d08a6733
1 changed files with 19 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
@ -121,6 +122,24 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter
});
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
if(path.size() == 0 || RepoDetailActivity.mViewPager.getCurrentItem() != 1) {
requireActivity().finish();
return;
}
path.remove(path.size() - 1);
binding.breadcrumbsView.removeLastItem();
if(path.size() == 0) {
fetchDataAsync(Authorization.get(getContext()), repoOwner, repoName, ref);
} else {
fetchDataAsyncSub(Authorization.get(getContext()), repoOwner, repoName, path.toString(), ref);
}
}
});
((RepoDetailActivity) requireActivity()).setFragmentRefreshListenerFiles(repoBranch -> {
path.clear();