2019-06-03 23:25:05 +02:00
|
|
|
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;
|
2020-07-07 19:15:01 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2019-06-03 23:25:05 +02:00
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
2019-10-11 22:03:01 +02:00
|
|
|
import org.mian.gitnex.actions.RepositoryActions;
|
2022-06-26 09:16:35 +02:00
|
|
|
import org.mian.gitnex.activities.BaseActivity;
|
2023-01-19 12:55:19 +01:00
|
|
|
import org.mian.gitnex.activities.CreateIssueActivity;
|
|
|
|
import org.mian.gitnex.activities.CreatePullRequestActivity;
|
|
|
|
import org.mian.gitnex.activities.RepoDetailActivity;
|
2021-01-26 16:10:31 +01:00
|
|
|
import org.mian.gitnex.databinding.BottomSheetRepoBinding;
|
2022-06-26 09:16:35 +02:00
|
|
|
import org.mian.gitnex.helpers.contexts.AccountContext;
|
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;
|
2021-12-15 20:20:49 +01:00
|
|
|
import org.mian.gitnex.structs.BottomSheetListener;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
/**
|
2022-06-26 09:16:35 +02:00
|
|
|
* @author M M Arif
|
2019-06-03 23:25:05 +02:00
|
|
|
*/
|
2020-03-16 20:28:03 +01:00
|
|
|
public class BottomSheetRepoFragment extends BottomSheetDialogFragment {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private final RepositoryContext repository;
|
|
|
|
private BottomSheetListener bmListener;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Nullable @Override
|
|
|
|
public View onCreateView(
|
|
|
|
@NonNull LayoutInflater inflater,
|
|
|
|
@Nullable ViewGroup container,
|
|
|
|
@Nullable Bundle savedInstanceState) {
|
2021-01-26 16:10:31 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
BottomSheetRepoBinding bottomSheetRepoBinding =
|
|
|
|
BottomSheetRepoBinding.inflate(inflater, container, false);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2023-01-19 12:55:19 +01:00
|
|
|
final Context ctx = getContext();
|
|
|
|
|
2022-06-26 09:16:35 +02:00
|
|
|
AccountContext account = ((BaseActivity) requireActivity()).getAccount();
|
|
|
|
|
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
|
|
|
TextView createLabel = bottomSheetRepoBinding.createLabel;
|
2022-08-15 16:26:02 +02:00
|
|
|
TextView createIssue = bottomSheetRepoBinding.createNewIssue;
|
|
|
|
TextView createMilestone = bottomSheetRepoBinding.createNewMilestone;
|
|
|
|
TextView addCollaborator = bottomSheetRepoBinding.addCollaborator;
|
|
|
|
TextView createRelease = bottomSheetRepoBinding.createRelease;
|
|
|
|
TextView openWebRepo = bottomSheetRepoBinding.openWebRepo;
|
|
|
|
TextView newFile = bottomSheetRepoBinding.newFile;
|
|
|
|
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;
|
|
|
|
TextView createPullRequest = bottomSheetRepoBinding.createPullRequest;
|
2022-06-26 09:16:35 +02:00
|
|
|
TextView createWiki = bottomSheetRepoBinding.createWiki;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
boolean canPush = repository.getPermissions().isPush();
|
2022-09-21 07:43:00 +02:00
|
|
|
if (!canPush) {
|
2022-08-15 16:26:02 +02:00
|
|
|
createMilestone.setVisibility(View.GONE);
|
|
|
|
createLabel.setVisibility(View.GONE);
|
|
|
|
createRelease.setVisibility(View.GONE);
|
|
|
|
newFile.setVisibility(View.GONE);
|
|
|
|
}
|
2022-02-11 15:27:31 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (!account.requiresVersion("1.16")) {
|
2022-06-26 09:16:35 +02:00
|
|
|
createWiki.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
boolean archived = repository.getRepository().isArchived();
|
2022-09-21 07:43:00 +02:00
|
|
|
if (archived) {
|
2022-08-15 16:26:02 +02:00
|
|
|
createIssue.setVisibility(View.GONE);
|
|
|
|
createPullRequest.setVisibility(View.GONE);
|
|
|
|
createMilestone.setVisibility(View.GONE);
|
|
|
|
createLabel.setVisibility(View.GONE);
|
|
|
|
createRelease.setVisibility(View.GONE);
|
|
|
|
newFile.setVisibility(View.GONE);
|
|
|
|
createWiki.setVisibility(View.GONE);
|
|
|
|
}
|
2022-02-11 15:27:31 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
createLabel.setOnClickListener(
|
|
|
|
v112 -> {
|
|
|
|
bmListener.onButtonClicked("label");
|
|
|
|
dismiss();
|
|
|
|
});
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (repository.getRepository().isHasIssues() && !archived) {
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
createIssue.setVisibility(View.VISIBLE);
|
2022-09-21 07:43:00 +02:00
|
|
|
createIssue.setOnClickListener(
|
|
|
|
v12 -> {
|
2023-01-19 12:55:19 +01:00
|
|
|
((RepoDetailActivity) requireActivity())
|
|
|
|
.createIssueLauncher.launch(
|
|
|
|
repository.getIntent(ctx, CreateIssueActivity.class));
|
2022-09-21 07:43:00 +02:00
|
|
|
dismiss();
|
|
|
|
});
|
|
|
|
} else {
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
createIssue.setVisibility(View.GONE);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (repository.getRepository().isHasPullRequests() && !archived) {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
createPullRequest.setVisibility(View.VISIBLE);
|
2022-09-21 07:43:00 +02:00
|
|
|
createPullRequest.setOnClickListener(
|
2023-01-19 12:55:19 +01:00
|
|
|
v12 -> {
|
|
|
|
((RepoDetailActivity) requireActivity())
|
|
|
|
.createPrLauncher.launch(
|
|
|
|
repository.getIntent(ctx, CreatePullRequestActivity.class));
|
2022-09-21 07:43:00 +02:00
|
|
|
dismiss();
|
|
|
|
});
|
|
|
|
} else {
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
createPullRequest.setVisibility(View.GONE);
|
|
|
|
}
|
2020-09-24 18:51:20 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
createMilestone.setOnClickListener(
|
|
|
|
v13 -> {
|
|
|
|
bmListener.onButtonClicked("newMilestone");
|
|
|
|
dismiss();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (repository.getPermissions().isAdmin()) {
|
|
|
|
|
|
|
|
repoSettings.setOnClickListener(
|
|
|
|
repoSettingsView -> {
|
|
|
|
bmListener.onButtonClicked("repoSettings");
|
|
|
|
dismiss();
|
|
|
|
});
|
|
|
|
|
|
|
|
addCollaborator.setOnClickListener(
|
|
|
|
v1 -> {
|
|
|
|
bmListener.onButtonClicked("addCollaborator");
|
|
|
|
dismiss();
|
|
|
|
});
|
|
|
|
|
|
|
|
createWiki.setOnClickListener(
|
|
|
|
v1 -> {
|
|
|
|
bmListener.onButtonClicked("createWiki");
|
|
|
|
dismiss();
|
|
|
|
});
|
|
|
|
} else {
|
2020-09-13 06:54:05 +02:00
|
|
|
|
2020-06-22 17:59:36 +02:00
|
|
|
addCollaborator.setVisibility(View.GONE);
|
2020-09-13 06:54:05 +02:00
|
|
|
repoSettings.setVisibility(View.GONE);
|
2022-06-26 09:16:35 +02:00
|
|
|
createWiki.setVisibility(View.GONE);
|
2020-06-22 17:59:36 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
createRelease.setOnClickListener(
|
|
|
|
v14 -> {
|
|
|
|
bmListener.onButtonClicked("createRelease");
|
|
|
|
dismiss();
|
|
|
|
});
|
|
|
|
|
|
|
|
shareRepository.setOnClickListener(
|
|
|
|
v15 -> {
|
|
|
|
bmListener.onButtonClicked("shareRepo");
|
|
|
|
dismiss();
|
|
|
|
});
|
|
|
|
|
|
|
|
openWebRepo.setOnClickListener(
|
|
|
|
v16 -> {
|
|
|
|
bmListener.onButtonClicked("openWebRepo");
|
|
|
|
dismiss();
|
|
|
|
});
|
|
|
|
|
|
|
|
copyRepoUrl.setOnClickListener(
|
|
|
|
copyUrl -> {
|
|
|
|
bmListener.onButtonClicked("copyRepoUrl");
|
|
|
|
dismiss();
|
|
|
|
});
|
|
|
|
|
|
|
|
newFile.setOnClickListener(
|
|
|
|
v17 -> {
|
|
|
|
bmListener.onButtonClicked("newFile");
|
|
|
|
dismiss();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (repository.isStarred()) {
|
2019-10-11 22:03:01 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
starRepository.setVisibility(View.GONE);
|
2022-09-21 07:43:00 +02:00
|
|
|
unStarRepository.setOnClickListener(
|
|
|
|
v18 -> {
|
|
|
|
RepositoryActions.unStarRepository(getContext(), repository);
|
|
|
|
bmListener.onButtonClicked("unstar");
|
|
|
|
dismiss();
|
|
|
|
});
|
2019-10-11 22:03:01 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
} else {
|
2019-10-11 22:03:01 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
unStarRepository.setVisibility(View.GONE);
|
2022-09-21 07:43:00 +02:00
|
|
|
starRepository.setOnClickListener(
|
|
|
|
v19 -> {
|
|
|
|
RepositoryActions.starRepository(getContext(), repository);
|
|
|
|
bmListener.onButtonClicked("star");
|
|
|
|
dismiss();
|
|
|
|
});
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-10-12 11:00:36 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (repository.isWatched()) {
|
2019-10-12 11:00:36 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
watchRepository.setVisibility(View.GONE);
|
2022-09-21 07:43:00 +02:00
|
|
|
unWatchRepository.setOnClickListener(
|
|
|
|
v110 -> {
|
|
|
|
RepositoryActions.unWatchRepository(getContext(), repository);
|
|
|
|
bmListener.onButtonClicked("unwatch");
|
|
|
|
dismiss();
|
|
|
|
});
|
2019-10-12 11:00:36 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
} else {
|
2019-10-12 11:00:36 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
unWatchRepository.setVisibility(View.GONE);
|
2022-09-21 07:43:00 +02:00
|
|
|
watchRepository.setOnClickListener(
|
|
|
|
v111 -> {
|
|
|
|
RepositoryActions.watchRepository(getContext(), repository);
|
|
|
|
bmListener.onButtonClicked("watch");
|
|
|
|
dismiss();
|
|
|
|
});
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-10-11 22:03:01 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
return bottomSheetRepoBinding.getRoot();
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
@Override
|
|
|
|
public void onAttach(@NonNull Context context) {
|
|
|
|
super.onAttach(context);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
try {
|
|
|
|
bmListener = (BottomSheetListener) context;
|
2022-09-21 07:43:00 +02:00
|
|
|
} catch (ClassCastException e) {
|
2022-08-15 16:26:02 +02:00
|
|
|
throw new ClassCastException(context + " must implement BottomSheetListener");
|
|
|
|
}
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|