2022-02-12 14:41:11 +01:00
|
|
|
package org.mian.gitnex.adapters;
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.text.method.LinkMovementMethod;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.core.text.HtmlCompat;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
|
|
|
import org.gitnex.tea4j.models.GitTag;
|
|
|
|
import org.mian.gitnex.R;
|
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.activities.RepoDetailActivity;
|
2022-02-12 14:41:11 +01:00
|
|
|
import org.mian.gitnex.helpers.AlertDialogs;
|
|
|
|
import org.mian.gitnex.helpers.Markdown;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Author qwerty287
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class TagsAdapter extends RecyclerView.Adapter<TagsAdapter.TagsViewHolder> {
|
|
|
|
|
|
|
|
private List<GitTag> tags;
|
|
|
|
private final Context context;
|
|
|
|
private final String repo;
|
|
|
|
private final String owner;
|
|
|
|
|
|
|
|
private OnLoadMoreListener loadMoreListener;
|
|
|
|
private boolean isLoading = false, isMoreDataAvailable = true;
|
|
|
|
|
|
|
|
static class TagsViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
|
|
|
private final TextView tagName;
|
|
|
|
private final TextView tagBody;
|
|
|
|
private final LinearLayout downloadFrame;
|
|
|
|
private final LinearLayout downloads;
|
|
|
|
private final TextView releaseZipDownload;
|
|
|
|
private final TextView releaseTarDownload;
|
|
|
|
private final ImageView downloadDropdownIcon;
|
|
|
|
private final ImageView options;
|
|
|
|
|
|
|
|
private TagsViewHolder(View itemView) {
|
|
|
|
|
|
|
|
super(itemView);
|
|
|
|
|
|
|
|
tagName = itemView.findViewById(R.id.tagName);
|
|
|
|
tagBody = itemView.findViewById(R.id.tagBodyContent);
|
|
|
|
downloadFrame = itemView.findViewById(R.id.downloadFrame);
|
|
|
|
downloads = itemView.findViewById(R.id.downloads);
|
|
|
|
releaseZipDownload = itemView.findViewById(R.id.releaseZipDownload);
|
|
|
|
releaseTarDownload = itemView.findViewById(R.id.releaseTarDownload);
|
|
|
|
downloadDropdownIcon = itemView.findViewById(R.id.downloadDropdownIcon);
|
|
|
|
options = itemView.findViewById(R.id.tagsOptionsMenu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public TagsAdapter(Context ctx, List<GitTag> releasesMain, String repoOwner, String repoName) {
|
|
|
|
this.context = ctx;
|
|
|
|
this.tags = releasesMain;
|
|
|
|
owner = repoOwner;
|
|
|
|
repo = repoName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public TagsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_tags, parent, false);
|
|
|
|
return new TagsViewHolder(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(@NonNull TagsViewHolder holder, int position) {
|
|
|
|
|
|
|
|
GitTag currentItem = tags.get(position);
|
|
|
|
|
|
|
|
holder.tagName.setText(currentItem.getName());
|
|
|
|
|
|
|
|
if(!currentItem.getMessage().equals("")) {
|
|
|
|
Markdown.render(context, currentItem.getMessage(), holder.tagBody);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
holder.tagBody.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
holder.downloadFrame.setOnClickListener(v -> {
|
|
|
|
|
|
|
|
if(holder.downloads.getVisibility() == View.GONE) {
|
|
|
|
|
|
|
|
holder.downloadDropdownIcon.setImageResource(R.drawable.ic_chevron_down);
|
|
|
|
holder.downloads.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
holder.downloadDropdownIcon.setImageResource(R.drawable.ic_chevron_right);
|
|
|
|
holder.downloads.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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
|
|
|
if(!((RepoDetailActivity) context).repository.getPermissions().canPush()) {
|
2022-02-12 14:41:11 +01:00
|
|
|
holder.options.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
holder.options.setOnClickListener(v -> {
|
|
|
|
final Context context = v.getContext();
|
|
|
|
|
|
|
|
@SuppressLint("InflateParams")
|
|
|
|
View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_tag_in_list, null);
|
|
|
|
|
|
|
|
TextView delete = view.findViewById(R.id.tagMenuDelete);
|
|
|
|
|
|
|
|
BottomSheetDialog dialog = new BottomSheetDialog(context);
|
|
|
|
dialog.setContentView(view);
|
|
|
|
dialog.show();
|
|
|
|
|
|
|
|
delete.setOnClickListener(v1 -> {
|
|
|
|
AlertDialogs.tagDeleteDialog(context, currentItem.getName(), owner, repo);
|
|
|
|
dialog.dismiss();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
holder.releaseZipDownload.setText(
|
|
|
|
HtmlCompat.fromHtml("<a href='" + currentItem.getZipballUrl() + "'>" + context.getResources().getString(R.string.zipArchiveDownloadReleasesTab) + "</a> ", HtmlCompat.FROM_HTML_MODE_LEGACY));
|
|
|
|
holder.releaseZipDownload.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
|
|
|
|
holder.releaseTarDownload.setText(
|
|
|
|
HtmlCompat.fromHtml("<a href='" + currentItem.getTarballUrl() + "'>" + context.getResources().getString(R.string.tarArchiveDownloadReleasesTab) + "</a> ", HtmlCompat.FROM_HTML_MODE_LEGACY));
|
|
|
|
holder.releaseTarDownload.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
|
|
|
|
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) {
|
|
|
|
isLoading = true;
|
|
|
|
loadMoreListener.onLoadMore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return tags.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
|
|
|
isMoreDataAvailable = moreDataAvailable;
|
|
|
|
if(!isMoreDataAvailable) {
|
|
|
|
loadMoreListener.onLoadFinished();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void notifyDataChanged() {
|
|
|
|
notifyDataSetChanged();
|
|
|
|
isLoading = false;
|
|
|
|
loadMoreListener.onLoadFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface OnLoadMoreListener {
|
|
|
|
void onLoadMore();
|
|
|
|
void onLoadFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLoadMoreListener(OnLoadMoreListener loadMoreListener) {
|
|
|
|
this.loadMoreListener = loadMoreListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateList(List<GitTag> list) {
|
|
|
|
tags = list;
|
|
|
|
notifyDataChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|