GitNex-Android-App/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java

836 lines
36 KiB
Java
Raw Normal View History

package org.mian.gitnex.adapters;
import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-11-08 19:58:47 +01:00
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.text.HtmlCompat;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;
import com.amulyakhare.textdrawable.TextDrawable;
2020-04-01 11:44:38 +02:00
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.card.MaterialCardView;
import com.vdurmont.emoji.EmojiParser;
import org.apache.commons.lang3.StringUtils;
import org.gitnex.tea4j.v2.models.TimelineComment;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
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.BaseActivity;
import org.mian.gitnex.activities.CommitDetailActivity;
import org.mian.gitnex.activities.IssueDetailActivity;
import org.mian.gitnex.activities.ProfileActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.fragments.BottomSheetReplyFragment;
import org.mian.gitnex.fragments.IssuesFragment;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.ColorInverter;
import org.mian.gitnex.helpers.LabelWidthCalculator;
import org.mian.gitnex.helpers.Markdown;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
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.IssueContext;
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-11-08 19:58:47 +01:00
import org.mian.gitnex.views.ReactionList;
import org.mian.gitnex.views.ReactionSpinner;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import retrofit2.Call;
import retrofit2.Callback;
/**
* @author M M Arif
*/
public class IssueCommentsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final Context context;
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-11-08 19:58:47 +01:00
private final TinyDB tinyDB;
private final Bundle bundle;
private final FragmentManager fragmentManager;
private final Runnable onInteractedListener;
private final Locale locale;
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 IssueContext issue;
private List<TimelineComment> issuesComments;
private OnLoadMoreListener loadMoreListener;
private boolean isLoading = false, isMoreDataAvailable = true, timelineLastView = false;
private Intent intent;
public IssueCommentsAdapter(Context ctx, Bundle bundle, List<TimelineComment> issuesCommentsMain, FragmentManager fragmentManager, Runnable onInteractedListener, IssueContext issue) {
this.context = ctx;
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-11-08 19:58:47 +01:00
this.bundle = bundle;
this.issuesComments = issuesCommentsMain;
this.fragmentManager = fragmentManager;
this.onInteractedListener = onInteractedListener;
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-11-08 19:58:47 +01:00
tinyDB = TinyDB.getInstance(ctx);
locale = ctx.getResources().getConfiguration().locale;
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
this.issue = issue;
}
private void updateAdapter(int position) {
issuesComments.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, issuesComments.size());
}
private void deleteIssueComment(final Context ctx, final int commentId, int position) {
Call<Void> call = RetrofitClient.getApiInterface(ctx).issueDeleteComment(issue.getRepository().getOwner(), issue.getRepository().getName(), (long) commentId);
call.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<Void> call, @NonNull retrofit2.Response<Void> response) {
switch(response.code()) {
case 204:
updateAdapter(position);
Toasty.success(ctx, ctx.getResources().getString(R.string.deleteCommentSuccess));
IssuesFragment.resumeIssues = true;
break;
case 401:
AlertDialogs.authorizationTokenRevokedDialog(ctx);
break;
case 403:
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
break;
case 404:
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
break;
default:
Toasty.error(ctx, ctx.getString(R.string.genericError));
}
}
@Override
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
Toasty.error(ctx, ctx.getResources().getString(R.string.genericServerResponseError));
}
});
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(context);
return new IssueCommentViewHolder(inflater.inflate(R.layout.list_issue_comments, parent, false));
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) {
isLoading = true;
loadMoreListener.onLoadMore();
timelineLastView = true;
}
((IssueCommentsAdapter.IssueCommentViewHolder) holder).bindData(issuesComments.get(position));
}
public void notifyDataChanged() {
notifyItemInserted(issuesComments.size());
isLoading = false;
loadMoreListener.onLoadFinished();
}
public void setMoreDataAvailable(boolean moreDataAvailable) {
isMoreDataAvailable = moreDataAvailable;
if(!isMoreDataAvailable) {
loadMoreListener.onLoadFinished();
}
}
public void setLoadMoreListener(OnLoadMoreListener loadMoreListener) {
this.loadMoreListener = loadMoreListener;
}
public void updateList(List<TimelineComment> list) {
issuesComments = list;
notifyDataChanged();
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public int getItemCount() {
return issuesComments.size();
}
public interface OnLoadMoreListener {
void onLoadMore();
void onLoadFinished();
}
class IssueCommentViewHolder extends RecyclerView.ViewHolder {
private final ImageView avatar;
private final TextView author;
private final TextView information;
Improve md rendering (#1008) * the first commits close https://codeberg.org/gitnex/GitNex/issues/925 * instead of using `TextView`s, it now uses `RecyclerView`s as they are supported by `Markwon` too and especially tables look better * see https://noties.io/Markwon/docs/v4/recycler/ and https://noties.io/Markwon/docs/v4/recycler-table/ * I replaced the `TextView`s on issue descriptions, comments, file viewer and the README viewer with a `RecyclerView` * the second parts close https://codeberg.org/gitnex/GitNex/issues/993 * images are now displayed if content is rendered using a `RecyclerView` * it seems that there is an issue with the `PicassoImagesPlugin` with `TextView`s, with `RecyclerView`s it's working * the third parts render issue/PR links like #1 as links, that closes https://codeberg.org/gitnex/GitNex/issues/72 * therefore, I added an URL prefix to the deep links named `gitnex` so that it is possible to open links from any instance by using `gitnex` instead of `http`/`https` * Full links are rendered as #index too * code is mostly from the sample app (https://github.com/noties/Markwon/blob/master/app-sample/src/main/java/io/noties/markwon/app/samples/GithubUserIssueInlineParsingSample.java#L60-L110) * I undid https://codeberg.org/gitnex/GitNex/pulls/995 because it wouldn't work if you have code block (starting/ending with ```) with newlines in it, I found another solution (see [the issue on gh](https://github.com/noties/Markwon/issues/168#issuecomment-622943057) and https://codeberg.org/gitnex/GitNex/commit/ef9bdbfb902029784a3ca6367ab484a6e76a93d9) * in the next commits (https://codeberg.org/gitnex/GitNex/compare/dd99f435eedf272bc14ac48034b198b38df34dd3...2021a719514594b3b3e0d3cc93100ea25ba5ec87), I fixed and improved various things * commit links are only rendered as short SHA * supports relative attachment links (addresses #993) * don't render email addresses as user mentions However, one thing isn't working right now: * the `LinkifyPlugin` is not working with `RecyclerView`s right now * I would like to change the way how the links are rendered and to open the activities directly instead of opening the deeplinkactivity close https://codeberg.org/gitnex/GitNex/issues/925 close https://codeberg.org/gitnex/GitNex/issues/993 close https://codeberg.org/gitnex/GitNex/issues/72 Co-authored-by: qwerty287 <ndev@web.de> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1008 Reviewed-by: 6543 <6543@noreply.codeberg.org> Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org> Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2021-12-15 23:39:04 +01:00
private final RecyclerView comment;
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-11-08 19:58:47 +01:00
private final LinearLayout commentReactionBadges;
private final MaterialCardView commentView;
private final RelativeLayout timelineView;
private final LinearLayout timelineData;
private final ImageView timelineIcon;
private String userLoginId;
private TimelineComment issueComment;
private final LinearLayout timelineDividerView;
private final FrameLayout timelineLine2;
private IssueCommentViewHolder(View view) {
super(view);
avatar = view.findViewById(R.id.avatar);
author = view.findViewById(R.id.author);
information = view.findViewById(R.id.information);
ImageView menu = view.findViewById(R.id.menu);
comment = view.findViewById(R.id.comment);
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-11-08 19:58:47 +01:00
commentReactionBadges = view.findViewById(R.id.commentReactionBadges);
commentView = view.findViewById(R.id.comment_view);
timelineView = view.findViewById(R.id.timeline_view);
timelineData = view.findViewById(R.id.timeline_data);
timelineIcon = view.findViewById(R.id.timeline_icon);
timelineDividerView = view.findViewById(R.id.timeline_divider_view);
timelineLine2 = view.findViewById(R.id.timeline_line_2);
menu.setOnClickListener(v -> {
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
final String loginUid = ((BaseActivity) context).getAccount().getAccount().getUserName();
@SuppressLint("InflateParams") View vw = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_issue_comments, null);
TextView commentMenuEdit = vw.findViewById(R.id.commentMenuEdit);
TextView commentShare = vw.findViewById(R.id.issueCommentShare);
TextView commentMenuQuote = vw.findViewById(R.id.commentMenuQuote);
TextView commentMenuCopy = vw.findViewById(R.id.commentMenuCopy);
TextView commentMenuDelete = vw.findViewById(R.id.commentMenuDelete);
TextView issueCommentCopyUrl = vw.findViewById(R.id.issueCommentCopyUrl);
TextView open = vw.findViewById(R.id.open);
Hide actions if the user can't use them (#977) closes #919 TODO - [X] repo and file actions (create release, label...) - [X] allow for repo admins - [x] label actions (edit, delete) - [x] allow for repo admins - [X] issue/pr action that are available for creators (close...) - [X] allow for creator - [X] allow for repo admins - [x] pr actions that are allowed when having push access to pr source (there was a bug in Gitea that makes that this was not working and these features were not accessible -> https://github.com/go-gitea/gitea/issues/17181) - [x] allow deleting of head branch/updates only if you can do this - [x] issue/pr action that are available for repo admins (merge) - [x] allow for repo admins - [x] milestone actions (close/reopen) - [x] allow for repo admins - [x] comment actions (delete, edit...) - [X] allow for creators - [x] allow for repo admins - [x] org actions (create label, team, repo; req gitea 1.16.0) - [x] actions when creating/editing issues - [x] delete head when merging - [x] All actions available to instance admins? (handled through API) Maybe as extras: - [x] Allow close/reopen also for PRs - [x] Improve handling of these (multiple btns for the same action) Co-authored-by: qwerty287 <ndev@web.de> Co-authored-by: M M Arif <mmarif@noreply.codeberg.org> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/977 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org> Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org> Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-02-11 15:27:31 +01:00
LinearLayout linearLayout = vw.findViewById(R.id.commentReactionButtons);
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(issue.getRepository().getRepository().isArchived()) {
Hide actions if the user can't use them (#977) closes #919 TODO - [X] repo and file actions (create release, label...) - [X] allow for repo admins - [x] label actions (edit, delete) - [x] allow for repo admins - [X] issue/pr action that are available for creators (close...) - [X] allow for creator - [X] allow for repo admins - [x] pr actions that are allowed when having push access to pr source (there was a bug in Gitea that makes that this was not working and these features were not accessible -> https://github.com/go-gitea/gitea/issues/17181) - [x] allow deleting of head branch/updates only if you can do this - [x] issue/pr action that are available for repo admins (merge) - [x] allow for repo admins - [x] milestone actions (close/reopen) - [x] allow for repo admins - [x] comment actions (delete, edit...) - [X] allow for creators - [x] allow for repo admins - [x] org actions (create label, team, repo; req gitea 1.16.0) - [x] actions when creating/editing issues - [x] delete head when merging - [x] All actions available to instance admins? (handled through API) Maybe as extras: - [x] Allow close/reopen also for PRs - [x] Improve handling of these (multiple btns for the same action) Co-authored-by: qwerty287 <ndev@web.de> Co-authored-by: M M Arif <mmarif@noreply.codeberg.org> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/977 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org> Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org> Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-02-11 15:27:31 +01:00
commentMenuEdit.setVisibility(View.GONE);
commentMenuDelete.setVisibility(View.GONE);
commentMenuQuote.setVisibility(View.GONE);
linearLayout.setVisibility(View.GONE);
}
if(!loginUid.contentEquals(issueComment.getUser().getLogin()) && !issue.getRepository().getPermissions().isPush()) {
commentMenuEdit.setVisibility(View.GONE);
commentMenuDelete.setVisibility(View.GONE);
}
if(issueComment.getBody().isEmpty()) {
commentMenuCopy.setVisibility(View.GONE);
}
BottomSheetDialog dialog = new BottomSheetDialog(context);
dialog.setContentView(vw);
dialog.show();
TextView loadReactions = new TextView(context);
loadReactions.setText(context.getString(R.string.genericWaitFor));
loadReactions.setGravity(Gravity.CENTER);
loadReactions.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 160));
linearLayout.addView(loadReactions);
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-11-08 19:58:47 +01:00
Bundle bundle1 = new Bundle();
bundle1.putAll(bundle);
bundle1.putInt("commentId", Math.toIntExact(issueComment.getId()));
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-11-08 19:58:47 +01:00
ReactionSpinner reactionSpinner = new ReactionSpinner(context, bundle1);
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-11-08 19:58:47 +01:00
reactionSpinner.setOnInteractedListener(() -> {
onInteractedListener.run();
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-11-08 19:58:47 +01:00
dialog.dismiss();
});
reactionSpinner.setOnLoadingFinishedListener(() -> {
linearLayout.removeView(loadReactions);
reactionSpinner.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 160));
linearLayout.addView(reactionSpinner);
});
Add Issue/Comment Reactions (#557) Minor performance improvements. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions Improving color of selected elements. First, fully working implementation of reactions. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/list_issue_comments.xml (Hopefully) fixing merge issues. Merge branch 'master' of https://codeberg.org/gitnex/GitNex into issue-reactions  Conflicts:  app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java  app/src/main/res/layout/activity_issue_detail.xml  app/src/main/res/layout/bottom_sheet_issue_comments.xml  app/src/main/res/layout/bottom_sheet_single_issue.xml  app/src/main/res/values/colors.xml Moving reactions below time frame on comments. Merge branch 'master' into layout-reactions Add IssueReactions Merge remote-tracking branch 'origin/layout-reactions' into layout-reactions Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Merge branch 'master' into layout-reactions Applying to pulls and issues. Merge branch 'master' of https://gitea.com/gitnex/GitNex into layout-reactions Providing external layouts. Some improvements. Adding comment emote indications. Adding circle around emotes. Adding some padding. First tests. Co-authored-by: opyale <opyale@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/557 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-11-08 19:58:47 +01:00
commentMenuEdit.setOnClickListener(v1 -> {
Bundle bundle = new Bundle();
bundle.putInt("commentId", Math.toIntExact(issueComment.getId()));
bundle.putString("commentAction", "edit");
bundle.putString("commentBody", issueComment.getBody());
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
BottomSheetReplyFragment bottomSheetReplyFragment = BottomSheetReplyFragment.newInstance(bundle, issue);
bottomSheetReplyFragment.setOnInteractedListener(onInteractedListener);
bottomSheetReplyFragment.show(fragmentManager, "replyBottomSheet");
dialog.dismiss();
});
commentShare.setOnClickListener(v1 -> {
AppUtil.sharingIntent(context, issueComment.getHtmlUrl());
dialog.dismiss();
});
issueCommentCopyUrl.setOnClickListener(v1 -> {
AppUtil.copyToClipboard(context, issueComment.getHtmlUrl(), context.getString(R.string.copyIssueUrlToastMsg));
dialog.dismiss();
});
open.setOnClickListener(v1 -> {
AppUtil.openUrlInBrowser(context, issueComment.getHtmlUrl());
dialog.dismiss();
});
commentMenuQuote.setOnClickListener(v1 -> {
StringBuilder stringBuilder = new StringBuilder();
String commenterName = issueComment.getUser().getLogin();
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(!commenterName.equals(((BaseActivity) context).getAccount().getAccount().getUserName())) {
stringBuilder.append("@").append(commenterName).append("\n\n");
}
String[] lines = issueComment.getBody().split("\\R");
for(String line : lines) {
stringBuilder.append(">").append(line).append("\n");
}
stringBuilder.append("\n");
Bundle bundle = new Bundle();
bundle.putString("commentBody", stringBuilder.toString());
bundle.putBoolean("cursorToEnd", true);
dialog.dismiss();
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
BottomSheetReplyFragment.newInstance(bundle, issue).show(fragmentManager, "replyBottomSheet");
});
commentMenuCopy.setOnClickListener(v1 -> {
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(context).getSystemService(Context.CLIPBOARD_SERVICE);
assert clipboard != null;
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
ClipData clip = ClipData.newPlainText("Comment on issue #" + issue.getIssueIndex(), issueComment.getBody());
clipboard.setPrimaryClip(clip);
dialog.dismiss();
Toasty.success(context, context.getString(R.string.copyIssueCommentToastMsg));
});
commentMenuDelete.setOnClickListener(v1 -> {
deleteIssueComment(context, Math.toIntExact(issueComment.getId()), getBindingAdapterPosition());
dialog.dismiss();
});
});
new Handler().postDelayed(() -> {
if(!AppUtil.checkGhostUsers(userLoginId)) {
avatar.setOnClickListener(loginId -> {
Intent intent = new Intent(context, ProfileActivity.class);
intent.putExtra("username", userLoginId);
context.startActivity(intent);
});
avatar.setOnLongClickListener(loginId -> {
AppUtil.copyToClipboard(context, userLoginId, context.getString(R.string.copyLoginIdToClipBoard, userLoginId));
return true;
});
}
}, 500);
}
void bindData(TimelineComment timelineComment) {
int fontSize = 14;
String timeFormat = tinyDB.getString("dateFormat", "pretty");
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
userLoginId = timelineComment.getUser().getLogin();
this.issueComment = timelineComment;
if(timelineLastView) {
//timelineLine2.setVisibility(View.GONE);
}
StringBuilder informationBuilder = null;
if(issueComment.getCreatedAt() != null) {
if(timeFormat.equals("pretty")) {
informationBuilder = new StringBuilder(TimeHelper.formatTime(issueComment.getCreatedAt(), locale, "pretty", context));
information.setOnClickListener(v -> TimeHelper.customDateFormatForToastDateFormat(issueComment.getCreatedAt()));
}
else if(timeFormat.equals("normal")) {
informationBuilder = new StringBuilder(TimeHelper.formatTime(issueComment.getCreatedAt(), locale, "normal", context));
}
if(!issueComment.getCreatedAt().equals(issueComment.getUpdatedAt())) {
if(informationBuilder != null) {
informationBuilder.append(context.getString(R.string.colorfulBulletSpan)).append(context.getString(R.string.modifiedText));
}
}
}
// label view in timeline
if(issueComment.getType().equalsIgnoreCase("label")) {
int color = Color.parseColor("#" + issueComment.getLabel().getColor());
int height = AppUtil.getPixelsFromDensity(context, 20);
int textSize = AppUtil.getPixelsFromScaledDensity(context, 12);
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).textColor(new ColorInverter().getContrastColor(color)).fontSize(textSize)
.width(LabelWidthCalculator.calculateLabelWidth(issueComment.getLabel().getName(), Typeface.DEFAULT, textSize, AppUtil.getPixelsFromDensity(context, 10))).height(height).endConfig()
.buildRoundRect(issueComment.getLabel().getName(), color, AppUtil.getPixelsFromDensity(context, 18));
TextView textView = new TextView(context);
String startText;
String endText = context.getString(R.string.timelineLabelEnd, informationBuilder);
if(issueComment.getBody().equals("")) {
startText = context.getString(R.string.timelineRemovedLabelStart, issueComment.getUser().getLogin());
timelineIcon.setColorFilter(context.getResources().getColor(R.color.iconIssuePrClosedColor, null));
}
else {
startText = context.getString(R.string.timelineAddedLabelStart, issueComment.getUser().getLogin());
}
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_tag));
SpannableString spannableString = new SpannableString(startText + " " + endText);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
ImageSpan image = new ImageSpan(drawable);
new Handler().postDelayed(() -> {
spannableString.setSpan(image, startText.length(), startText.length() + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(spannableString);
timelineData.addView(textView);
}, 250);
}
// pull/push/commit data view in timeline
else if(issueComment.getType().equalsIgnoreCase("pull_push")) {
TextView start = new TextView(context);
JSONObject commitsObj = null;
try {
commitsObj = new JSONObject(issueComment.getBody());
}
catch(JSONException ignored) {}
JSONArray commitsShaArray = null;
try {
commitsShaArray = Objects.requireNonNull(commitsObj).getJSONArray("commit_ids");
}
catch(JSONException ignored) {}
String commitText = context.getResources().getString(R.string.commits).toLowerCase();
if(Objects.requireNonNull(commitsShaArray).length() == 1) {
commitText = context.getResources().getString(R.string.commitText).toLowerCase();
}
String commitString = context.getString(R.string.timelineAddedCommit, issueComment.getUser().getLogin()) + commitText + " " + informationBuilder;
start.setText(HtmlCompat.fromHtml(commitString, HtmlCompat.FROM_HTML_MODE_LEGACY));
start.setTextSize(fontSize);
timelineData.setOrientation(LinearLayout.VERTICAL);
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_commit));
timelineData.addView(start);
for(int i = 0; i < Objects.requireNonNull(commitsShaArray).length(); i++) {
try {
String timelineCommits = "<font color='" + ResourcesCompat.getColor(context.getResources(), R.color.lightBlue, null) + "'>" + StringUtils.substring(String.valueOf(commitsShaArray.get(i)), 0, 10) + "</font>";
TextView dynamicCommitTv = new TextView(context);
dynamicCommitTv.setId(View.generateViewId());
dynamicCommitTv.setText(HtmlCompat.fromHtml(timelineCommits, HtmlCompat.FROM_HTML_MODE_LEGACY));
JSONArray finalCommitsArray = commitsShaArray;
int finalI = i;
dynamicCommitTv.setOnClickListener(v14 -> {
intent = IssueContext.fromIntent(((IssueDetailActivity) context).getIntent()).getRepository().getIntent(context, CommitDetailActivity.class);
try {
intent.putExtra("sha", (String) finalCommitsArray.get(finalI));
}
catch(JSONException ignored) {}
context.startActivity(intent);
});
timelineData.setOrientation(LinearLayout.VERTICAL);
timelineData.addView(dynamicCommitTv);
}
catch(JSONException ignored) {}
}
}
// assignees data view in timeline
else if(issueComment.getType().equalsIgnoreCase("assignees")) {
TextView start = new TextView(context);
if(issueComment.isRemovedAssignee()) {
if(issueComment.getUser().getLogin().equalsIgnoreCase(issueComment.getAssignee().getLogin())) {
start.setText(context.getString(R.string.timelineAssigneesRemoved, issueComment.getUser().getLogin(), informationBuilder));
}
else {
start.setText(context.getString(R.string.timelineAssigneesUnassigned, issueComment.getAssignee().getLogin(), issueComment.getUser().getLogin(), informationBuilder));
}
timelineIcon.setColorFilter(context.getResources().getColor(R.color.iconIssuePrClosedColor, null));
}
else {
if(issueComment.getUser().getLogin().equalsIgnoreCase(issueComment.getAssignee().getLogin())) {
start.setText(context.getString(R.string.timelineAssigneesSelfAssigned, issueComment.getUser().getLogin(), informationBuilder));
}
else {
start.setText(context.getString(R.string.timelineAssigneesAssigned, issueComment.getAssignee().getLogin(), issueComment.getUser().getLogin(), informationBuilder));
}
}
start.setTextSize(fontSize);
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_person));
timelineData.addView(start);
}
// milestone data view in timeline
else if(issueComment.getType().equalsIgnoreCase("milestone")) {
TextView start = new TextView(context);
if(issueComment.getMilestone() != null) {
start.setText(context.getString(R.string.timelineMilestoneAdded, issueComment.getUser().getLogin(), issueComment.getMilestone().getTitle(), informationBuilder));
}
else {
start.setText(context.getString(R.string.timelineMilestoneRemoved, issueComment.getUser().getLogin(), issueComment.getOldMilestone().getTitle(), informationBuilder));
timelineIcon.setColorFilter(context.getResources().getColor(R.color.iconIssuePrClosedColor, null));
}
start.setTextSize(fontSize);
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_milestone));
timelineData.addView(start);
}
// status view in timeline
else if(issueComment.getType().equalsIgnoreCase("close") || issueComment.getType().equalsIgnoreCase("reopen") || issueComment.getType().equalsIgnoreCase("merge_pull") || issueComment.getType()
.equalsIgnoreCase("commit_ref")) {
TextView start = new TextView(context);
if(issue.getIssueType().equalsIgnoreCase("Issue")) {
if(issueComment.getType().equals("close")) {
start.setText(context.getString(R.string.timelineStatusClosedIssue, issueComment.getUser().getLogin(), informationBuilder));
timelineIcon.setColorFilter(context.getResources().getColor(R.color.iconIssuePrClosedColor, null));
}
else if(issueComment.getType().equalsIgnoreCase("reopen")) {
start.setText(context.getString(R.string.timelineStatusReopenedIssue, issueComment.getUser().getLogin(), informationBuilder));
}
else if(issueComment.getType().equalsIgnoreCase("commit_ref")) {
String commitString = context.getString(R.string.timelineStatusRefIssue, issueComment.getUser().getLogin()) + "<font color='" + ResourcesCompat.getColor(context.getResources(), R.color.lightBlue, null) + "'>" + context.getResources().getString(R.string.commitText).toLowerCase() + "</font> " + informationBuilder;
start.setText(HtmlCompat.fromHtml(commitString, HtmlCompat.FROM_HTML_MODE_LEGACY));
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_bookmark));
start.setOnClickListener(v14 -> {
intent = IssueContext.fromIntent(((IssueDetailActivity) context).getIntent()).getRepository().getIntent(context, CommitDetailActivity.class);
intent.putExtra("sha", issueComment.getRefCommitSha());
context.startActivity(intent);
});
}
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_issue));
}
else if(issue.getIssueType().equalsIgnoreCase("Pull")) {
if(issueComment.getType().equalsIgnoreCase("close")) {
start.setText(context.getString(R.string.timelineStatusClosedPr, issueComment.getUser().getLogin(), informationBuilder));
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_pull_request));
timelineIcon.setColorFilter(context.getResources().getColor(R.color.iconIssuePrClosedColor, null));
}
else if(issueComment.getType().equalsIgnoreCase("merge_pull")) {
start.setText(context.getString(R.string.timelineStatusMergedPr, issueComment.getUser().getLogin(), informationBuilder));
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_pull_request));
timelineIcon.setColorFilter(context.getResources().getColor(R.color.iconPrMergedColor, null));
}
else if(issueComment.getType().equalsIgnoreCase("commit_ref")) {
String commitString = context.getString(R.string.timelineStatusRefPr, issueComment.getUser().getLogin()) + "<font color='" + ResourcesCompat.getColor(context.getResources(), R.color.lightBlue, null) + "'>" + context.getResources().getString(R.string.commitText).toLowerCase() + "</font> " + informationBuilder;
start.setText(HtmlCompat.fromHtml(commitString, HtmlCompat.FROM_HTML_MODE_LEGACY));
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_bookmark));
start.setOnClickListener(v14 -> {
intent = IssueContext.fromIntent(((IssueDetailActivity) context).getIntent()).getRepository().getIntent(context, CommitDetailActivity.class);
intent.putExtra("sha", issueComment.getRefCommitSha());
context.startActivity(intent);
});
}
else {
start.setText(context.getString(R.string.timelineStatusReopenedPr, issueComment.getUser().getLogin(), informationBuilder));
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_pull_request));
}
}
start.setTextSize(fontSize);
timelineData.addView(start);
}
// review data view in timeline
else if(issueComment.getType().equalsIgnoreCase("review_request") || issueComment.getType().equalsIgnoreCase("review") || issueComment.getType().equalsIgnoreCase("dismiss_review")) {
TextView start = new TextView(context);
if(issueComment.getType().equalsIgnoreCase("review")) {
timelineView.setVisibility(View.GONE);
timelineDividerView.setVisibility(View.GONE);
}
else if(issueComment.getType().equalsIgnoreCase("dismiss_review")) {
timelineView.setVisibility(View.GONE);
timelineDividerView.setVisibility(View.GONE);
}
else if(issueComment.getType().equalsIgnoreCase("review_request")) {
start.setText(context.getString(R.string.timelineReviewRequest, issueComment.getUser().getLogin(), issueComment.getAssignee().getLogin(), informationBuilder));
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_unwatch));
}
start.setTextSize(fontSize);
timelineData.addView(start);
}
// change title data view in timeline
else if(issueComment.getType().equalsIgnoreCase("change_title")) {
TextView start = new TextView(context);
start.setText(context.getString(R.string.timelineChangeTitle, issueComment.getUser().getLogin(), issueComment.getOldTitle(), issueComment.getNewTitle(), informationBuilder));
start.setTextSize(fontSize);
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_edit));
timelineData.addView(start);
}
// lock/unlock data view in timeline
else if(issueComment.getType().equalsIgnoreCase("lock") || issueComment.getType().equalsIgnoreCase("unlock")) {
TextView start = new TextView(context);
if(issueComment.getType().equalsIgnoreCase("lock")) {
start.setText(context.getString(R.string.timelineLocked, issueComment.getUser().getLogin(), issueComment.getBody(), informationBuilder));
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_lock));
}
else if(issueComment.getType().equalsIgnoreCase("unlock")) {
start.setText(context.getString(R.string.timelineUnlocked, issueComment.getUser().getLogin(), informationBuilder));
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_key));
}
start.setTextSize(fontSize);
timelineData.addView(start);
}
// dependency data view in timeline
else if(issueComment.getType().equalsIgnoreCase("add_dependency") || issueComment.getType().equalsIgnoreCase("remove_dependency")) {
TextView start = new TextView(context);
if(issueComment.getType().equalsIgnoreCase("add_dependency")) {
start.setText(context.getString(R.string.timelineDependencyAdded, issueComment.getUser().getLogin(), issueComment.getDependentIssue().getNumber(), informationBuilder));
}
else if(issueComment.getType().equalsIgnoreCase("remove_dependency")) {
start.setText(context.getString(R.string.timelineDependencyRemoved, issueComment.getUser().getLogin(), issueComment.getDependentIssue().getNumber(), informationBuilder));
timelineIcon.setColorFilter(context.getResources().getColor(R.color.iconIssuePrClosedColor, null));
}
start.setTextSize(fontSize);
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_dependency));
timelineData.addView(start);
}
// project data view in timeline
else if(issueComment.getType().equalsIgnoreCase("project") || issueComment.getType().equalsIgnoreCase("project_board")) {
TextView start = new TextView(context);
if(issueComment.getProjectId() > 0) {
start.setText(context.getString(R.string.timelineProjectAdded, issueComment.getUser().getLogin(), informationBuilder));
}
else {
start.setText(context.getString(R.string.timelineProjectRemoved, issueComment.getUser().getLogin(), informationBuilder));
timelineIcon.setColorFilter(context.getResources().getColor(R.color.iconIssuePrClosedColor, null));
}
start.setTextSize(fontSize);
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_kanban));
timelineData.addView(start);
}
// due date/deadline data view in timeline
else if(issueComment.getType().equalsIgnoreCase("added_deadline") || issueComment.getType().equalsIgnoreCase("modified_deadline") || issueComment.getType().equalsIgnoreCase("removed_deadline")) {
TextView start = new TextView(context);
if(issueComment.getType().equalsIgnoreCase("added_deadline")) {
start.setText(context.getString(R.string.timelineDueDateAdded, issueComment.getUser().getLogin(), issueComment.getBody(), informationBuilder));
}
else if(issueComment.getType().equalsIgnoreCase("modified_deadline")) {
start.setText(
context.getString(R.string.timelineDueDateModified, issueComment.getUser().getLogin(), issueComment.getBody().split("\\|")[0], issueComment.getBody().split("\\|")[1], informationBuilder));
}
else if(issueComment.getType().equalsIgnoreCase("removed_deadline")) {
start.setText(context.getString(R.string.timelineDueDateRemoved, issueComment.getUser().getLogin(), issueComment.getBody(), informationBuilder));
timelineIcon.setColorFilter(context.getResources().getColor(R.color.iconIssuePrClosedColor, null));
}
start.setTextSize(fontSize);
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_clock));
timelineData.addView(start);
}
// branch data view in timeline
else if(issueComment.getType().equalsIgnoreCase("change_target_branch") || issueComment.getType().equalsIgnoreCase("delete_branch")) {
TextView start = new TextView(context);
if(issueComment.getType().equalsIgnoreCase("change_target_branch")) {
start.setText(context.getString(R.string.timelineBranchChanged, issueComment.getUser().getLogin(), issueComment.getOldRef(), issueComment.getNewRef(), informationBuilder));
}
else if(issueComment.getType().equalsIgnoreCase("delete_branch")) {
start.setText(context.getString(R.string.timelineBranchDeleted, issueComment.getUser().getLogin(), issueComment.getOldRef(), informationBuilder));
timelineIcon.setColorFilter(context.getResources().getColor(R.color.iconIssuePrClosedColor, null));
}
start.setTextSize(fontSize);
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_branch));
timelineData.addView(start);
}
// time tracking data view in timeline
else if(issueComment.getType().equalsIgnoreCase("start_tracking") || issueComment.getType().equalsIgnoreCase("stop_tracking") || issueComment.getType()
.equalsIgnoreCase("cancel_tracking") || issueComment.getType().equalsIgnoreCase("add_time_manual") || issueComment.getType().equalsIgnoreCase("delete_time_manual")) {
TextView start = new TextView(context);
if(issueComment.getType().equalsIgnoreCase("start_tracking")) {
start.setText(context.getString(R.string.timelineTimeTrackingStart, issueComment.getUser().getLogin(), informationBuilder));
}
else if(issueComment.getType().equalsIgnoreCase("stop_tracking")) {
start.setText(context.getString(R.string.timelineTimeTrackingStop, issueComment.getUser().getLogin(), informationBuilder));
}
else if(issueComment.getType().equalsIgnoreCase("cancel_tracking")) {
start.setText(context.getString(R.string.timelineTimeTrackingCancel, issueComment.getUser().getLogin(), informationBuilder));
timelineIcon.setColorFilter(context.getResources().getColor(R.color.iconIssuePrClosedColor, null));
}
else if(issueComment.getType().equalsIgnoreCase("add_time_manual")) {
start.setText(context.getString(R.string.timelineTimeTrackingAddManualTime, issueComment.getUser().getLogin(), issueComment.getBody(), informationBuilder));
}
else if(issueComment.getType().equalsIgnoreCase("delete_time_manual")) {
start.setText(context.getString(R.string.timelineTimeTrackingDeleteManualTime, issueComment.getUser().getLogin(), issueComment.getBody(), informationBuilder));
timelineIcon.setColorFilter(context.getResources().getColor(R.color.iconIssuePrClosedColor, null));
}
start.setTextSize(fontSize);
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_clock));
timelineData.addView(start);
}
// issue/pr refs data view in timeline
else if(issueComment.getType().equalsIgnoreCase("change_issue_ref") || issueComment.getType().equalsIgnoreCase("issue_ref") || issueComment.getType().equalsIgnoreCase("comment_ref") || issueComment.getType()
.equalsIgnoreCase("pull_ref")) {
RecyclerView recyclerView = new RecyclerView(context);
if(issueComment.getType().equalsIgnoreCase("change_issue_ref")) {
String text = context.getString(R.string.timelineChangeIssueRef, issueComment.getUser().getLogin(), issueComment.getNewRef(), informationBuilder);
Markdown.render(context, EmojiParser.parseToUnicode(text), recyclerView, issue.getRepository());
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_branch));
}
else if(issueComment.getType().equalsIgnoreCase("comment_ref") || issueComment.getType().equalsIgnoreCase("issue_ref") || issueComment.getType().equalsIgnoreCase("pull_ref")) {
if(issue.getIssueType().equalsIgnoreCase("Issue")) {
String text = context.getString(R.string.timelineRefIssue, issueComment.getUser().getLogin(), issueComment.getRefIssue().getNumber(), informationBuilder);
Markdown.render(context, EmojiParser.parseToUnicode(text), recyclerView, issue.getRepository());
}
else if(issue.getIssueType().equalsIgnoreCase("Pull")) {
String text = context.getString(R.string.timelineRefPr, issueComment.getUser().getLogin(), issueComment.getRefIssue().getNumber(), informationBuilder);
Markdown.render(context, EmojiParser.parseToUnicode(text), recyclerView, issue.getRepository());
}
timelineIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_bookmark));
}
timelineData.addView(recyclerView);
}
// code data view in timeline
else if(issueComment.getType().equalsIgnoreCase("code")) {
timelineView.setVisibility(View.GONE);
timelineDividerView.setVisibility(View.GONE);
}
// schedule pr view in timeline
else if(issueComment.getType().equalsIgnoreCase("pull_scheduled_merge") || issueComment.getType().equalsIgnoreCase("pull_cancel_scheduled_merge")) {
timelineView.setVisibility(View.GONE);
timelineDividerView.setVisibility(View.GONE);
}
else {
timelineView.setVisibility(View.GONE);
}
// comment data view in timeline
if(issueComment.getType().equalsIgnoreCase("comment")) {
author.setText(issueComment.getUser().getLogin());
PicassoService.getInstance(context).get().load(issueComment.getUser().getAvatarUrl()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0))
.resize(AppUtil.getPixelsFromDensity(context, 35), AppUtil.getPixelsFromDensity(context, 35)).centerCrop().into(avatar);
Markdown.render(context, EmojiParser.parseToUnicode(issueComment.getBody()), comment, issue.getRepository());
information.setText(informationBuilder);
Bundle bundle1 = new Bundle();
bundle1.putAll(bundle);
bundle1.putInt("commentId", Math.toIntExact(issueComment.getId()));
ReactionList reactionList = new ReactionList(context, bundle1);
commentReactionBadges.addView(reactionList);
reactionList.setOnReactionAddedListener(() -> {
if(commentReactionBadges.getVisibility() != View.VISIBLE) {
commentReactionBadges.post(() -> commentReactionBadges.setVisibility(View.VISIBLE));
}
});
}
else {
commentView.setVisibility(View.GONE);
}
}
}
}