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

131 lines
3.6 KiB
Java
Raw Normal View History

package org.mian.gitnex.fragments;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
2019-10-11 22:03:01 +02:00
import org.mian.gitnex.actions.RepositoryActions;
import org.mian.gitnex.databinding.BottomSheetRepoBinding;
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
import org.mian.gitnex.helpers.contexts.RepositoryContext;
import org.mian.gitnex.structs.BottomSheetListener;
/**
* @author M M Arif
*/
public class BottomSheetRepoFragment extends BottomSheetDialogFragment {
private final RepositoryContext repository;
private BottomSheetListener bmListener;
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 BottomSheetRepoFragment(RepositoryContext repository) {
this.repository = repository;
}
@Nullable @Override
public View onCreateView(
@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
BottomSheetRepoBinding bottomSheetRepoBinding =
BottomSheetRepoBinding.inflate(inflater, container, false);
TextView openWebRepo = bottomSheetRepoBinding.openWebRepo;
TextView starRepository = bottomSheetRepoBinding.starRepository;
TextView unStarRepository = bottomSheetRepoBinding.unStarRepository;
TextView watchRepository = bottomSheetRepoBinding.watchRepository;
TextView unWatchRepository = bottomSheetRepoBinding.unWatchRepository;
TextView shareRepository = bottomSheetRepoBinding.shareRepository;
TextView copyRepoUrl = bottomSheetRepoBinding.copyRepoUrl;
TextView repoSettings = bottomSheetRepoBinding.repoSettings;
if (repository.getPermissions().isAdmin()) {
repoSettings.setOnClickListener(
repoSettingsView -> {
bmListener.onButtonClicked("repoSettings");
dismiss();
});
} else {
repoSettings.setVisibility(View.GONE);
}
shareRepository.setOnClickListener(
v15 -> {
bmListener.onButtonClicked("shareRepo");
dismiss();
});
openWebRepo.setOnClickListener(
v16 -> {
bmListener.onButtonClicked("openWebRepo");
dismiss();
});
copyRepoUrl.setOnClickListener(
copyUrl -> {
bmListener.onButtonClicked("copyRepoUrl");
dismiss();
});
if (repository.isStarred()) {
2019-10-11 22:03:01 +02:00
starRepository.setVisibility(View.GONE);
unStarRepository.setOnClickListener(
v18 -> {
RepositoryActions.unStarRepository(getContext(), repository);
bmListener.onButtonClicked("unstar");
dismiss();
});
} else {
2019-10-11 22:03:01 +02:00
unStarRepository.setVisibility(View.GONE);
starRepository.setOnClickListener(
v19 -> {
RepositoryActions.starRepository(getContext(), repository);
bmListener.onButtonClicked("star");
dismiss();
});
}
if (repository.isWatched()) {
watchRepository.setVisibility(View.GONE);
unWatchRepository.setOnClickListener(
v110 -> {
RepositoryActions.unWatchRepository(getContext(), repository);
bmListener.onButtonClicked("unwatch");
dismiss();
});
} else {
unWatchRepository.setVisibility(View.GONE);
watchRepository.setOnClickListener(
v111 -> {
RepositoryActions.watchRepository(getContext(), repository);
bmListener.onButtonClicked("watch");
dismiss();
});
}
2019-10-11 22:03:01 +02:00
return bottomSheetRepoBinding.getRoot();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
try {
bmListener = (BottomSheetListener) context;
} catch (ClassCastException e) {
throw new ClassCastException(context + " must implement BottomSheetListener");
}
}
}