2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.adapters;
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Color;
|
2019-09-29 18:44:42 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.text.Spanned;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.Filter;
|
|
|
|
import android.widget.Filterable;
|
|
|
|
import android.widget.ImageView;
|
2019-09-27 23:32:31 +02:00
|
|
|
import android.widget.ProgressBar;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.widget.TextView;
|
|
|
|
import com.amulyakhare.textdrawable.TextDrawable;
|
2020-04-08 20:31:27 +02:00
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
2019-06-03 23:25:05 +02:00
|
|
|
import com.vdurmont.emoji.EmojiParser;
|
|
|
|
import org.mian.gitnex.R;
|
2020-04-08 20:31:27 +02:00
|
|
|
import org.mian.gitnex.actions.MilestoneActions;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.helpers.ClickListener;
|
|
|
|
import org.mian.gitnex.helpers.TimeHelper;
|
|
|
|
import org.mian.gitnex.models.Milestones;
|
|
|
|
import org.mian.gitnex.util.TinyDB;
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.ArrayList;
|
2019-09-29 18:44:42 +02:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
2019-06-03 23:25:05 +02:00
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Objects;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2019-09-29 18:44:42 +02:00
|
|
|
import io.noties.markwon.AbstractMarkwonPlugin;
|
|
|
|
import io.noties.markwon.Markwon;
|
|
|
|
import io.noties.markwon.core.CorePlugin;
|
|
|
|
import io.noties.markwon.core.MarkwonTheme;
|
|
|
|
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
|
|
|
import io.noties.markwon.ext.tables.TablePlugin;
|
|
|
|
import io.noties.markwon.ext.tasklist.TaskListPlugin;
|
|
|
|
import io.noties.markwon.html.HtmlPlugin;
|
|
|
|
import io.noties.markwon.image.DefaultMediaDecoder;
|
|
|
|
import io.noties.markwon.image.ImageItem;
|
|
|
|
import io.noties.markwon.image.ImagesPlugin;
|
|
|
|
import io.noties.markwon.image.SchemeHandler;
|
|
|
|
import io.noties.markwon.image.gif.GifMediaDecoder;
|
|
|
|
import io.noties.markwon.image.svg.SvgMediaDecoder;
|
|
|
|
import io.noties.markwon.linkify.LinkifyPlugin;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class MilestonesAdapter extends RecyclerView.Adapter<MilestonesAdapter.MilestonesViewHolder> implements Filterable {
|
|
|
|
|
|
|
|
private List<Milestones> milestonesList;
|
|
|
|
private Context mCtx;
|
|
|
|
private List<Milestones> milestonesListFull;
|
|
|
|
|
|
|
|
static class MilestonesViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
2020-04-08 20:31:27 +02:00
|
|
|
private TextView milestoneId;
|
2019-06-03 23:25:05 +02:00
|
|
|
private TextView msTitle;
|
|
|
|
private TextView msDescription;
|
|
|
|
private TextView msOpenIssues;
|
|
|
|
private TextView msClosedIssues;
|
|
|
|
private TextView msDueDate;
|
|
|
|
private ImageView msStatus;
|
2019-09-27 23:32:31 +02:00
|
|
|
private ProgressBar msProgress;
|
2020-04-08 20:31:27 +02:00
|
|
|
private TextView milestoneStatus;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
private MilestonesViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
|
2020-04-08 20:31:27 +02:00
|
|
|
milestoneId = itemView.findViewById(R.id.milestoneId);
|
2019-06-03 23:25:05 +02:00
|
|
|
msTitle = itemView.findViewById(R.id.milestoneTitle);
|
|
|
|
msStatus = itemView.findViewById(R.id.milestoneState);
|
|
|
|
msDescription = itemView.findViewById(R.id.milestoneDescription);
|
|
|
|
msOpenIssues = itemView.findViewById(R.id.milestoneIssuesOpen);
|
|
|
|
msClosedIssues = itemView.findViewById(R.id.milestoneIssuesClosed);
|
|
|
|
msDueDate = itemView.findViewById(R.id.milestoneDueDate);
|
2019-09-27 23:32:31 +02:00
|
|
|
msProgress = itemView.findViewById(R.id.milestoneProgress);
|
2020-04-08 20:31:27 +02:00
|
|
|
ImageView milestonesMenu = itemView.findViewById(R.id.milestonesMenu);
|
|
|
|
milestoneStatus = itemView.findViewById(R.id.milestoneStatus);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-08 20:31:27 +02:00
|
|
|
milestonesMenu.setOnClickListener(v -> {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-08 20:31:27 +02:00
|
|
|
Context ctx = v.getContext();
|
|
|
|
int milestoneId_ = Integer.parseInt(milestoneId.getText().toString());
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-08 20:31:27 +02:00
|
|
|
@SuppressLint("InflateParams") View view = LayoutInflater.from(ctx).inflate(R.layout.bottom_sheet_milestones_in_list, null);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-08 20:31:27 +02:00
|
|
|
TextView closeMilestone = view.findViewById(R.id.closeMilestone);
|
|
|
|
TextView openMilestone = view.findViewById(R.id.openMilestone);
|
|
|
|
|
|
|
|
BottomSheetDialog dialog = new BottomSheetDialog(ctx);
|
|
|
|
dialog.setContentView(view);
|
|
|
|
dialog.show();
|
|
|
|
|
|
|
|
if(milestoneStatus.getText().toString().equals("open")) {
|
|
|
|
|
|
|
|
closeMilestone.setVisibility(View.VISIBLE);
|
|
|
|
openMilestone.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
closeMilestone.setVisibility(View.GONE);
|
|
|
|
openMilestone.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
closeMilestone.setOnClickListener(v12 -> {
|
|
|
|
|
|
|
|
MilestoneActions.closeMilestone(ctx, milestoneId_);
|
|
|
|
dialog.dismiss();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
openMilestone.setOnClickListener(v12 -> {
|
|
|
|
|
|
|
|
MilestoneActions.openMilestone(ctx, milestoneId_);
|
|
|
|
dialog.dismiss();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public MilestonesAdapter(Context mCtx, List<Milestones> milestonesMain) {
|
|
|
|
this.mCtx = mCtx;
|
|
|
|
this.milestonesList = milestonesMain;
|
|
|
|
milestonesListFull = new ArrayList<>(milestonesList);
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public MilestonesAdapter.MilestonesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
2020-03-28 11:52:09 +01:00
|
|
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_milestones, parent, false);
|
2019-06-03 23:25:05 +02:00
|
|
|
return new MilestonesAdapter.MilestonesViewHolder(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(@NonNull MilestonesAdapter.MilestonesViewHolder holder, int position) {
|
|
|
|
|
|
|
|
final TinyDB tinyDb = new TinyDB(mCtx);
|
|
|
|
final String locale = tinyDb.getString("locale");
|
|
|
|
final String timeFormat = tinyDb.getString("dateFormat");
|
|
|
|
|
|
|
|
Milestones currentItem = milestonesList.get(position);
|
|
|
|
|
2020-04-08 20:31:27 +02:00
|
|
|
holder.milestoneId.setText(String.valueOf(currentItem.getId()));
|
|
|
|
holder.milestoneStatus.setText(currentItem.getState());
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
final Markwon markwon = Markwon.builder(Objects.requireNonNull(mCtx))
|
|
|
|
.usePlugin(CorePlugin.create())
|
2020-04-08 20:31:27 +02:00
|
|
|
.usePlugin(ImagesPlugin.create(plugin -> {
|
|
|
|
plugin.addSchemeHandler(new SchemeHandler() {
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public ImageItem handle(@NonNull String raw, @NonNull Uri uri) {
|
|
|
|
|
|
|
|
final int resourceId = mCtx.getResources().getIdentifier(
|
|
|
|
raw.substring("drawable://".length()),
|
|
|
|
"drawable",
|
|
|
|
mCtx.getPackageName());
|
|
|
|
|
|
|
|
final Drawable drawable = mCtx.getDrawable(resourceId);
|
|
|
|
|
|
|
|
assert drawable != null;
|
|
|
|
return ImageItem.withResult(drawable);
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public Collection<String> supportedSchemes() {
|
|
|
|
return Collections.singleton("drawable");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
plugin.placeholderProvider(drawable -> null);
|
|
|
|
plugin.addMediaDecoder(GifMediaDecoder.create(false));
|
|
|
|
plugin.addMediaDecoder(SvgMediaDecoder.create(mCtx.getResources()));
|
|
|
|
plugin.addMediaDecoder(SvgMediaDecoder.create());
|
|
|
|
plugin.defaultMediaDecoder(DefaultMediaDecoder.create(mCtx.getResources()));
|
|
|
|
plugin.defaultMediaDecoder(DefaultMediaDecoder.create());
|
2019-09-29 18:44:42 +02:00
|
|
|
}))
|
2019-06-03 23:25:05 +02:00
|
|
|
.usePlugin(new AbstractMarkwonPlugin() {
|
|
|
|
@Override
|
|
|
|
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
|
|
|
|
builder
|
|
|
|
.codeTextColor(tinyDb.getInt("codeBlockColor"))
|
|
|
|
.codeBackgroundColor(tinyDb.getInt("codeBlockBackground"))
|
|
|
|
.linkColor(mCtx.getResources().getColor(R.color.lightBlue));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.usePlugin(TablePlugin.create(mCtx))
|
|
|
|
.usePlugin(TaskListPlugin.create(mCtx))
|
|
|
|
.usePlugin(HtmlPlugin.create())
|
|
|
|
.usePlugin(StrikethroughPlugin.create())
|
2019-09-29 18:44:42 +02:00
|
|
|
.usePlugin(LinkifyPlugin.create())
|
2019-06-03 23:25:05 +02:00
|
|
|
.build();
|
|
|
|
|
2019-09-29 18:44:42 +02:00
|
|
|
Spanned msTitle = markwon.toMarkdown(currentItem.getTitle());
|
|
|
|
markwon.setParsedMarkdown(holder.msTitle, msTitle);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
if(currentItem.getState().equals("open")) {
|
|
|
|
|
|
|
|
@SuppressLint("ResourceType") int color = Color.parseColor(mCtx.getResources().getString(R.color.releaseStable));
|
|
|
|
TextDrawable drawable = TextDrawable.builder()
|
|
|
|
.beginConfig()
|
|
|
|
//.useFont(Typeface.DEFAULT)
|
|
|
|
.textColor(mCtx.getResources().getColor(R.color.white))
|
|
|
|
.fontSize(30)
|
|
|
|
.toUpperCase()
|
|
|
|
.width(120)
|
|
|
|
.height(60)
|
|
|
|
.endConfig()
|
|
|
|
.buildRoundRect("open", color, 8);
|
|
|
|
|
|
|
|
holder.msStatus.setImageDrawable(drawable);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(currentItem.getState().equals("closed")) {
|
|
|
|
|
|
|
|
@SuppressLint("ResourceType") int color = Color.parseColor(mCtx.getResources().getString(R.color.colorRed));
|
|
|
|
TextDrawable drawable = TextDrawable.builder()
|
|
|
|
.beginConfig()
|
|
|
|
//.useFont(Typeface.DEFAULT)
|
|
|
|
.textColor(mCtx.getResources().getColor(R.color.white))
|
|
|
|
.fontSize(30)
|
|
|
|
.toUpperCase()
|
|
|
|
.width(140)
|
|
|
|
.height(60)
|
|
|
|
.endConfig()
|
|
|
|
.buildRoundRect("closed", color, 8);
|
|
|
|
|
|
|
|
holder.msStatus.setImageDrawable(drawable);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!currentItem.getDescription().equals("")) {
|
|
|
|
final CharSequence bodyWithMD = markwon.toMarkdown(EmojiParser.parseToUnicode(currentItem.getDescription()));
|
|
|
|
holder.msDescription.setText(bodyWithMD);
|
|
|
|
}
|
|
|
|
else {
|
2020-04-13 09:48:23 +02:00
|
|
|
holder.msDescription.setText("");
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
holder.msOpenIssues.setText(String.valueOf(currentItem.getOpen_issues()));
|
|
|
|
holder.msOpenIssues.setOnClickListener(new ClickListener(mCtx.getResources().getString(R.string.milestoneOpenIssues, currentItem.getOpen_issues()), mCtx));
|
|
|
|
|
|
|
|
holder.msClosedIssues.setText(String.valueOf(currentItem.getClosed_issues()));
|
|
|
|
holder.msClosedIssues.setOnClickListener(new ClickListener(mCtx.getResources().getString(R.string.milestoneClosedIssues, currentItem.getClosed_issues()), mCtx));
|
|
|
|
|
2019-09-27 23:32:31 +02:00
|
|
|
if ((currentItem.getOpen_issues() + currentItem.getClosed_issues()) > 0) {
|
2019-10-01 12:05:26 +02:00
|
|
|
|
2019-09-27 23:32:31 +02:00
|
|
|
if (currentItem.getOpen_issues() == 0) {
|
|
|
|
holder.msProgress.setProgress(100);
|
2019-10-01 19:45:21 +02:00
|
|
|
holder.msProgress.setOnClickListener(new ClickListener(mCtx.getResources().getString(R.string.milestoneCompletion, 100), mCtx));
|
2019-09-27 23:32:31 +02:00
|
|
|
}
|
2019-10-01 12:05:26 +02:00
|
|
|
else {
|
|
|
|
int msCompletion = 100 * currentItem.getClosed_issues() / (currentItem.getOpen_issues() + currentItem.getClosed_issues());
|
|
|
|
holder.msProgress.setOnClickListener(new ClickListener(mCtx.getResources().getString(R.string.milestoneCompletion, msCompletion), mCtx));
|
|
|
|
holder.msProgress.setProgress(msCompletion);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
2019-09-27 23:58:23 +02:00
|
|
|
holder.msProgress.setProgress(0);
|
2019-10-01 12:05:26 +02:00
|
|
|
holder.msProgress.setOnClickListener(new ClickListener(mCtx.getResources().getString(R.string.milestoneCompletion, 0), mCtx));
|
2019-09-27 23:32:31 +02:00
|
|
|
}
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
if(currentItem.getDue_on() != null) {
|
|
|
|
|
|
|
|
if (timeFormat.equals("normal") || timeFormat.equals("pretty")) {
|
|
|
|
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", new Locale(locale));
|
|
|
|
Date date = null;
|
|
|
|
try {
|
|
|
|
date = formatter.parse(currentItem.getDue_on());
|
|
|
|
} catch (ParseException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
assert date != null;
|
2020-04-08 20:31:27 +02:00
|
|
|
String dueDate = formatter.format(date);
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
if(date.before(new Date())) {
|
|
|
|
holder.msDueDate.setTextColor(mCtx.getResources().getColor(R.color.darkRed));
|
|
|
|
}
|
|
|
|
|
2020-04-08 20:31:27 +02:00
|
|
|
holder.msDueDate.setText(mCtx.getResources().getString(R.string.dueDate, dueDate));
|
2019-06-03 23:25:05 +02:00
|
|
|
holder.msDueDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToast(currentItem.getDue_on()), mCtx));
|
|
|
|
|
|
|
|
} else if (timeFormat.equals("normal1")) {
|
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", new Locale(locale));
|
|
|
|
Date date1 = null;
|
|
|
|
try {
|
|
|
|
date1 = formatter.parse(currentItem.getDue_on());
|
|
|
|
} catch (ParseException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2020-04-13 09:48:23 +02:00
|
|
|
assert date1 != null;
|
2019-06-03 23:25:05 +02:00
|
|
|
String dueDate = formatter.format(date1);
|
2020-04-08 20:31:27 +02:00
|
|
|
holder.msDueDate.setText(mCtx.getResources().getString(R.string.dueDate, dueDate));
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
2020-04-13 09:48:23 +02:00
|
|
|
holder.msDueDate.setText("");
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return milestonesList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Filter getFilter() {
|
|
|
|
return milestoneFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
private Filter milestoneFilter = new Filter() {
|
2020-04-08 20:31:27 +02:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
@Override
|
|
|
|
protected FilterResults performFiltering(CharSequence constraint) {
|
|
|
|
List<Milestones> filteredList = new ArrayList<>();
|
|
|
|
|
|
|
|
if (constraint == null || constraint.length() == 0) {
|
|
|
|
filteredList.addAll(milestonesListFull);
|
|
|
|
} else {
|
|
|
|
String filterPattern = constraint.toString().toLowerCase().trim();
|
|
|
|
|
|
|
|
for (Milestones item : milestonesListFull) {
|
|
|
|
if (item.getTitle().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
|
|
|
|
filteredList.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FilterResults results = new FilterResults();
|
|
|
|
results.values = filteredList;
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void publishResults(CharSequence constraint, FilterResults results) {
|
|
|
|
milestonesList.clear();
|
|
|
|
milestonesList.addAll((List) results.values);
|
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
2020-04-08 20:31:27 +02:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|