2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.adapters;
|
|
|
|
|
2020-04-01 11:44:38 +02:00
|
|
|
import android.annotation.SuppressLint;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2020-06-30 16:43:27 +02:00
|
|
|
import android.content.res.ColorStateList;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.graphics.Color;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
2020-06-30 16:43:27 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.core.widget.ImageViewCompat;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2020-04-01 11:44:38 +02:00
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
2022-08-07 21:34:02 +02:00
|
|
|
import com.google.android.material.card.MaterialCardView;
|
2022-09-21 07:43:00 +02:00
|
|
|
import java.util.List;
|
2022-04-18 09:10:54 +02:00
|
|
|
import org.gitnex.tea4j.v2.models.Label;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.activities.CreateLabelActivity;
|
2022-02-11 15:27:31 +01:00
|
|
|
import org.mian.gitnex.activities.OrganizationDetailActivity;
|
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;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.helpers.AlertDialogs;
|
|
|
|
import org.mian.gitnex.helpers.ColorInverter;
|
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;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
/**
|
2022-07-29 14:08:44 +02:00
|
|
|
* @author M M Arif
|
2019-06-03 23:25:05 +02:00
|
|
|
*/
|
2022-08-15 16:26:02 +02:00
|
|
|
public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsViewHolder> {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private final List<Label> labelsList;
|
|
|
|
private final String type;
|
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
|
|
|
private final String orgName;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
public LabelsAdapter(Context ctx, List<Label> labelsMain, String type, String orgName) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
this.labelsList = labelsMain;
|
|
|
|
this.type = type;
|
|
|
|
this.orgName = orgName;
|
|
|
|
}
|
2020-06-30 16:43:27 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@NonNull @Override
|
|
|
|
public LabelsAdapter.LabelsViewHolder onCreateViewHolder(
|
|
|
|
@NonNull ViewGroup parent, int viewType) {
|
|
|
|
View v =
|
|
|
|
LayoutInflater.from(parent.getContext())
|
|
|
|
.inflate(R.layout.list_labels, parent, false);
|
2022-08-15 16:26:02 +02:00
|
|
|
return new LabelsAdapter.LabelsViewHolder(v);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(@NonNull LabelsAdapter.LabelsViewHolder holder, int position) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
Label currentItem = labelsList.get(position);
|
|
|
|
holder.labels = currentItem;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
String labelColor = currentItem.getColor();
|
|
|
|
String labelName = currentItem.getName();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
int color = Color.parseColor("#" + labelColor);
|
|
|
|
int contrastColor = new ColorInverter().getContrastColor(color);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
ImageViewCompat.setImageTintList(holder.labelIcon, ColorStateList.valueOf(contrastColor));
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
holder.labelName.setTextColor(contrastColor);
|
|
|
|
holder.labelName.setText(labelName);
|
|
|
|
holder.labelView.setCardBackgroundColor(color);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return labelsList.size();
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
|
public void notifyDataChanged() {
|
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
class LabelsViewHolder extends RecyclerView.ViewHolder {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private final MaterialCardView labelView;
|
|
|
|
private final ImageView labelIcon;
|
|
|
|
private final TextView labelName;
|
|
|
|
private Label labels;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private LabelsViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
labelView = itemView.findViewById(R.id.labelView);
|
|
|
|
labelIcon = itemView.findViewById(R.id.labelIcon);
|
|
|
|
labelName = itemView.findViewById(R.id.labelName);
|
|
|
|
ImageView labelsOptionsMenu = itemView.findViewById(R.id.labelsOptionsMenu);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if ((type.equals("repo")
|
|
|
|
&& !((RepoDetailActivity) itemView.getContext())
|
|
|
|
.repository
|
|
|
|
.getPermissions()
|
|
|
|
.isPush())
|
|
|
|
|| (type.equals("org")
|
|
|
|
&& (((OrganizationDetailActivity) itemView.getContext()).permissions
|
|
|
|
== null
|
|
|
|
|| !((OrganizationDetailActivity) itemView.getContext())
|
|
|
|
.permissions.isIsOwner()))) {
|
2022-08-15 16:26:02 +02:00
|
|
|
labelsOptionsMenu.setVisibility(View.GONE);
|
|
|
|
}
|
2022-09-21 07:43:00 +02:00
|
|
|
labelsOptionsMenu.setOnClickListener(
|
|
|
|
v -> {
|
|
|
|
final Context context = v.getContext();
|
|
|
|
|
|
|
|
@SuppressLint("InflateParams")
|
|
|
|
View view =
|
|
|
|
LayoutInflater.from(context)
|
|
|
|
.inflate(R.layout.bottom_sheet_labels_in_list, null);
|
|
|
|
|
|
|
|
TextView labelMenuEdit = view.findViewById(R.id.labelMenuEdit);
|
|
|
|
TextView labelMenuDelete = view.findViewById(R.id.labelMenuDelete);
|
|
|
|
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
|
|
|
|
|
|
|
|
bottomSheetHeader.setText(labels.getName());
|
|
|
|
BottomSheetDialog dialog = new BottomSheetDialog(context);
|
|
|
|
dialog.setContentView(view);
|
|
|
|
dialog.show();
|
|
|
|
|
|
|
|
labelMenuEdit.setOnClickListener(
|
|
|
|
editLabel -> {
|
|
|
|
Intent intent = new Intent(context, CreateLabelActivity.class);
|
|
|
|
intent.putExtra("labelId", String.valueOf(labels.getId()));
|
|
|
|
intent.putExtra("labelTitle", labels.getName());
|
|
|
|
intent.putExtra("labelColor", labels.getColor());
|
|
|
|
intent.putExtra("labelAction", "edit");
|
|
|
|
intent.putExtra("type", type);
|
|
|
|
intent.putExtra("orgName", orgName);
|
|
|
|
if (type.equals("repo")) {
|
|
|
|
intent.putExtra(
|
|
|
|
RepositoryContext.INTENT_EXTRA,
|
|
|
|
((RepoDetailActivity) itemView.getContext())
|
|
|
|
.repository);
|
|
|
|
}
|
|
|
|
context.startActivity(intent);
|
|
|
|
dialog.dismiss();
|
|
|
|
});
|
|
|
|
|
|
|
|
labelMenuDelete.setOnClickListener(
|
|
|
|
deleteLabel -> {
|
|
|
|
RepositoryContext repo;
|
|
|
|
if (type.equals("repo")) {
|
|
|
|
repo =
|
|
|
|
((RepoDetailActivity) itemView.getContext())
|
|
|
|
.repository;
|
|
|
|
} else {
|
|
|
|
repo = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
AlertDialogs.labelDeleteDialog(
|
|
|
|
context,
|
|
|
|
labels.getName(),
|
|
|
|
String.valueOf(labels.getId()),
|
|
|
|
type,
|
|
|
|
orgName,
|
|
|
|
repo);
|
|
|
|
dialog.dismiss();
|
|
|
|
});
|
|
|
|
});
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2022-08-07 21:34:02 +02:00
|
|
|
}
|
2020-06-30 16:43:27 +02:00
|
|
|
}
|