2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
import android.app.Dialog;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.content.Context;
|
2020-10-23 20:13:13 +02:00
|
|
|
import android.content.Intent;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.Typeface;
|
2020-10-09 17:47:52 +02:00
|
|
|
import android.graphics.drawable.ColorDrawable;
|
2019-09-29 18:44:42 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.net.Uri;
|
2020-04-11 22:17:24 +02:00
|
|
|
import android.os.Build;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
2020-10-09 17:47:52 +02:00
|
|
|
import android.os.Looper;
|
2020-03-08 15:14:46 +01:00
|
|
|
import android.text.Html;
|
2019-09-29 18:44:42 +02:00
|
|
|
import android.text.Spanned;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.util.Log;
|
|
|
|
import android.view.Gravity;
|
2020-10-09 17:47:52 +02:00
|
|
|
import android.view.LayoutInflater;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.ScrollView;
|
2020-04-30 12:42:22 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2020-10-29 14:13:19 +01:00
|
|
|
import androidx.core.content.ContextCompat;
|
2020-04-30 12:42:22 +02:00
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
|
|
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
2019-06-03 23:25:05 +02:00
|
|
|
import com.amulyakhare.textdrawable.TextDrawable;
|
2020-10-09 17:47:52 +02:00
|
|
|
import com.google.gson.JsonElement;
|
2019-06-03 23:25:05 +02:00
|
|
|
import com.vdurmont.emoji.EmojiParser;
|
|
|
|
import org.mian.gitnex.R;
|
2020-10-09 17:47:52 +02:00
|
|
|
import org.mian.gitnex.actions.AssigneesActions;
|
|
|
|
import org.mian.gitnex.actions.LabelsActions;
|
|
|
|
import org.mian.gitnex.adapters.AssigneesListAdapter;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.adapters.IssueCommentsAdapter;
|
2020-10-09 17:47:52 +02:00
|
|
|
import org.mian.gitnex.adapters.LabelsListAdapter;
|
2020-04-01 13:26:32 +02:00
|
|
|
import org.mian.gitnex.clients.PicassoService;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
2020-10-09 17:47:52 +02:00
|
|
|
import org.mian.gitnex.databinding.ActivityIssueDetailBinding;
|
|
|
|
import org.mian.gitnex.databinding.CustomAssigneesSelectionDialogBinding;
|
|
|
|
import org.mian.gitnex.databinding.CustomLabelsSelectionDialogBinding;
|
2020-10-12 20:11:23 +02:00
|
|
|
import org.mian.gitnex.fragments.BottomSheetReplyFragment;
|
2020-03-16 20:28:03 +01:00
|
|
|
import org.mian.gitnex.fragments.BottomSheetSingleIssueFragment;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.helpers.AlertDialogs;
|
2020-07-22 21:32:42 +02:00
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.helpers.Authorization;
|
2020-04-30 12:42:22 +02:00
|
|
|
import org.mian.gitnex.helpers.ClickListener;
|
|
|
|
import org.mian.gitnex.helpers.ColorInverter;
|
2020-04-12 20:33:41 +02:00
|
|
|
import org.mian.gitnex.helpers.LabelWidthCalculator;
|
2020-04-30 12:42:22 +02:00
|
|
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.helpers.TimeHelper;
|
2020-07-07 19:15:01 +02:00
|
|
|
import org.mian.gitnex.helpers.TinyDB;
|
2020-10-09 17:47:52 +02:00
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.helpers.UserMentions;
|
2020-05-21 20:58:00 +02:00
|
|
|
import org.mian.gitnex.helpers.Version;
|
2020-10-09 17:47:52 +02:00
|
|
|
import org.mian.gitnex.models.Collaborators;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.models.Issues;
|
2020-10-09 17:47:52 +02:00
|
|
|
import org.mian.gitnex.models.Labels;
|
|
|
|
import org.mian.gitnex.models.UpdateIssueAssignees;
|
2020-05-21 20:58:00 +02:00
|
|
|
import org.mian.gitnex.models.WatchInfo;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.viewmodels.IssueCommentsViewModel;
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
2020-10-09 17:47:52 +02:00
|
|
|
import java.util.ArrayList;
|
2019-09-29 18:44:42 +02:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
2020-10-09 17:47:52 +02:00
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
import java.util.List;
|
2019-06-03 23:25:05 +02:00
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Objects;
|
2020-04-30 12:42:22 +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;
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
import retrofit2.Response;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
public class IssueDetailActivity extends BaseActivity implements LabelsListAdapter.LabelsListAdapterListener, AssigneesListAdapter.AssigneesListAdapterListener, BottomSheetSingleIssueFragment.BottomSheetListener {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-30 12:42:22 +02:00
|
|
|
private IssueCommentsAdapter adapter;
|
|
|
|
final Context ctx = this;
|
|
|
|
private Context appCtx;
|
2020-10-09 17:47:52 +02:00
|
|
|
private TinyDB tinyDb;
|
|
|
|
|
|
|
|
private String instanceUrl;
|
|
|
|
private String loginUid;
|
|
|
|
private String instanceToken;
|
|
|
|
private String repoOwner;
|
|
|
|
private String repoName;
|
|
|
|
private int issueIndex;
|
|
|
|
|
|
|
|
private LabelsListAdapter labelsAdapter;
|
|
|
|
private AssigneesListAdapter assigneesAdapter;
|
|
|
|
|
|
|
|
private List<Integer> currentLabelsIds = new ArrayList<>();
|
|
|
|
private List<Integer> labelsIds = new ArrayList<>();
|
|
|
|
private List<Labels> labelsList = new ArrayList<>();
|
|
|
|
private List<Collaborators> assigneesList = new ArrayList<>();
|
|
|
|
private List<String> assigneesListData = new ArrayList<>();
|
|
|
|
private List<String> currentAssignees = new ArrayList<>();
|
|
|
|
|
|
|
|
private Dialog dialogLabels;
|
|
|
|
private Dialog dialogAssignees;
|
|
|
|
|
|
|
|
private CustomLabelsSelectionDialogBinding labelsBinding;
|
|
|
|
private CustomAssigneesSelectionDialogBinding assigneesBinding;
|
|
|
|
private ActivityIssueDetailBinding viewBinding;
|
2020-04-30 12:42:22 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected int getLayoutResourceId() {
|
|
|
|
|
|
|
|
return R.layout.activity_issue_detail;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
appCtx = getApplicationContext();
|
2020-10-09 17:47:52 +02:00
|
|
|
tinyDb = new TinyDB(appCtx);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding = ActivityIssueDetailBinding.inflate(getLayoutInflater());
|
|
|
|
View view = viewBinding.getRoot();
|
|
|
|
setContentView(view);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
instanceUrl = tinyDb.getString("instanceUrl");
|
|
|
|
loginUid = tinyDb.getString("loginUid");
|
|
|
|
instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
2020-04-30 12:42:22 +02:00
|
|
|
String repoFullName = tinyDb.getString("repoFullName");
|
|
|
|
String[] parts = repoFullName.split("/");
|
2020-10-09 17:47:52 +02:00
|
|
|
repoOwner = parts[0];
|
|
|
|
repoName = parts[1];
|
|
|
|
issueIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
|
|
|
|
|
|
|
|
setSupportActionBar(viewBinding.toolbar);
|
2020-04-30 12:42:22 +02:00
|
|
|
Objects.requireNonNull(getSupportActionBar()).setTitle(repoName);
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.recyclerView.setHasFixedSize(true);
|
|
|
|
viewBinding.recyclerView.setNestedScrollingEnabled(false);
|
|
|
|
viewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
|
|
|
|
|
|
|
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(viewBinding.recyclerView.getContext(), DividerItemDecoration.VERTICAL);
|
|
|
|
viewBinding.recyclerView.addItemDecoration(dividerItemDecoration);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-12 20:11:23 +02:00
|
|
|
viewBinding.addNewComment.setOnClickListener(v -> BottomSheetReplyFragment.newInstance(new Bundle()).show(getSupportFragmentManager(), "replyBottomSheet"));
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
labelsAdapter = new LabelsListAdapter(labelsList, IssueDetailActivity.this, currentLabelsIds);
|
|
|
|
assigneesAdapter = new AssigneesListAdapter(ctx, assigneesList, IssueDetailActivity.this, currentAssignees);
|
|
|
|
LabelsActions.getCurrentIssueLabels(ctx, instanceUrl, loginUid, instanceToken, repoOwner, repoName, issueIndex, currentLabelsIds);
|
|
|
|
AssigneesActions.getCurrentIssueAssignees(ctx, instanceUrl, loginUid, instanceToken, repoOwner, repoName, issueIndex, currentAssignees);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
|
|
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.scrollViewComments.setOnScrollChangeListener((v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
if((scrollY - oldScrollY) > 0 && viewBinding.addNewComment.isShown()) {
|
|
|
|
viewBinding.addNewComment.setVisibility(View.GONE);
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
|
|
|
else if((scrollY - oldScrollY) < 0) {
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.addNewComment.setVisibility(View.VISIBLE);
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
if(!viewBinding.scrollViewComments.canScrollVertically(1)) { // bottom
|
|
|
|
viewBinding.addNewComment.setVisibility(View.GONE);
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
if(!viewBinding.scrollViewComments.canScrollVertically(-1)) { // top
|
|
|
|
viewBinding.addNewComment.setVisibility(View.VISIBLE);
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.pullToRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.pullToRefresh.setRefreshing(false);
|
2020-07-22 21:32:42 +02:00
|
|
|
IssueCommentsViewModel
|
|
|
|
.loadIssueComments(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex,
|
|
|
|
ctx);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
|
|
|
}, 500));
|
|
|
|
|
|
|
|
Typeface myTypeface;
|
|
|
|
|
|
|
|
switch(tinyDb.getInt("customFontId", -1)) {
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
myTypeface = Typeface.createFromAsset(Objects.requireNonNull(ctx).getAssets(), "fonts/manroperegular.ttf");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
myTypeface = Typeface.createFromAsset(Objects.requireNonNull(ctx).getAssets(), "fonts/sourcecodeproregular.ttf");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
myTypeface = Typeface.createFromAsset(Objects.requireNonNull(ctx).getAssets(), "fonts/roboto.ttf");
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.toolbarTitle.setTypeface(myTypeface);
|
|
|
|
viewBinding.toolbarTitle.setText(repoName);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
|
|
|
getSingleIssue(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
|
|
|
|
fetchDataAsync(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
@Override
|
|
|
|
public void onButtonClicked(String text) {
|
|
|
|
|
|
|
|
switch(text) {
|
|
|
|
|
|
|
|
case "showLabels":
|
|
|
|
showLabels();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "showAssignees":
|
|
|
|
showAssignees();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void labelsInterface(List<String> data) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void labelsIdsInterface(List<Integer> data) {
|
|
|
|
|
|
|
|
labelsIds = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void assigneesInterface(List<String> data) {
|
|
|
|
|
|
|
|
assigneesListData = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showAssignees() {
|
|
|
|
|
|
|
|
assigneesAdapter.updateList(currentAssignees);
|
|
|
|
dialogAssignees = new Dialog(ctx, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
|
|
|
|
dialogAssignees.setCancelable(false);
|
|
|
|
|
|
|
|
if (dialogAssignees.getWindow() != null) {
|
|
|
|
|
|
|
|
dialogAssignees.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
|
|
|
}
|
|
|
|
|
|
|
|
assigneesBinding = CustomAssigneesSelectionDialogBinding.inflate(LayoutInflater.from(ctx));
|
|
|
|
|
|
|
|
View view = assigneesBinding.getRoot();
|
|
|
|
dialogAssignees.setContentView(view);
|
|
|
|
|
|
|
|
assigneesBinding.cancel.setOnClickListener(assigneesBinding_ -> {
|
|
|
|
|
|
|
|
currentAssignees = new ArrayList<>(new LinkedHashSet<>(currentAssignees));
|
|
|
|
assigneesListData = new ArrayList<>(new LinkedHashSet<>(assigneesListData));
|
|
|
|
Collections.sort(assigneesListData);
|
|
|
|
Collections.sort(currentAssignees);
|
|
|
|
|
|
|
|
if(!assigneesListData.equals(currentAssignees)) {
|
|
|
|
|
|
|
|
updateIssueAssignees();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
dialogAssignees.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-10-29 13:53:03 +01:00
|
|
|
dialogAssignees.show();
|
2020-10-09 17:47:52 +02:00
|
|
|
AssigneesActions.getRepositoryAssignees(ctx, instanceUrl, instanceToken, repoOwner, repoName, assigneesList, dialogAssignees, assigneesAdapter, assigneesBinding);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showLabels() {
|
|
|
|
|
|
|
|
labelsAdapter.updateList(currentLabelsIds);
|
|
|
|
dialogLabels = new Dialog(ctx, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
|
|
|
|
dialogLabels.setCancelable(false);
|
|
|
|
|
|
|
|
if (dialogLabels.getWindow() != null) {
|
|
|
|
|
|
|
|
dialogLabels.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
|
|
|
}
|
|
|
|
|
|
|
|
labelsBinding = CustomLabelsSelectionDialogBinding.inflate(LayoutInflater.from(ctx));
|
|
|
|
|
|
|
|
View view = labelsBinding.getRoot();
|
|
|
|
dialogLabels.setContentView(view);
|
|
|
|
|
|
|
|
labelsBinding.cancel.setOnClickListener(labelsBinding_ -> {
|
|
|
|
|
|
|
|
currentLabelsIds = new ArrayList<>(new LinkedHashSet<>(currentLabelsIds));
|
|
|
|
labelsIds = new ArrayList<>(new LinkedHashSet<>(labelsIds));
|
|
|
|
Collections.sort(labelsIds);
|
|
|
|
Collections.sort(currentLabelsIds);
|
|
|
|
|
|
|
|
if(!labelsIds.equals(currentLabelsIds)) {
|
|
|
|
|
|
|
|
updateIssueLabels();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
dialogLabels.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-10-29 13:53:03 +01:00
|
|
|
dialogLabels.show();
|
2020-10-09 17:47:52 +02:00
|
|
|
LabelsActions.getRepositoryLabels(ctx, instanceUrl, instanceToken, repoOwner, repoName, labelsList, dialogLabels, labelsAdapter, labelsBinding);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateIssueAssignees() {
|
|
|
|
|
|
|
|
UpdateIssueAssignees updateAssigneeJson = new UpdateIssueAssignees(assigneesListData);
|
|
|
|
|
|
|
|
Call<JsonElement> call3;
|
|
|
|
|
|
|
|
call3 = RetrofitClient
|
|
|
|
.getInstance(instanceUrl, ctx)
|
|
|
|
.getApiInterface()
|
|
|
|
.patchIssueAssignees(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, updateAssigneeJson);
|
|
|
|
|
|
|
|
call3.enqueue(new Callback<JsonElement>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response2) {
|
|
|
|
|
|
|
|
if(response2.code() == 201) {
|
|
|
|
|
|
|
|
Toasty.success(ctx, ctx.getString(R.string.assigneesUpdated));
|
|
|
|
|
|
|
|
dialogAssignees.dismiss();
|
|
|
|
|
|
|
|
viewBinding.frameAssignees.removeAllViews();
|
|
|
|
viewBinding.frameLabels.removeAllViews();
|
|
|
|
getSingleIssue(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
|
|
|
|
currentAssignees.clear();
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() -> AssigneesActions.getCurrentIssueAssignees(ctx, instanceUrl, loginUid, instanceToken, repoOwner, repoName, issueIndex, currentAssignees), 1000);
|
|
|
|
}
|
|
|
|
else if(response2.code() == 401) {
|
|
|
|
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
|
|
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
|
|
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
|
|
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
|
|
}
|
|
|
|
else if(response2.code() == 403) {
|
|
|
|
|
|
|
|
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
|
|
|
}
|
|
|
|
else if(response2.code() == 404) {
|
|
|
|
|
|
|
|
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
Toasty.error(ctx, getString(R.string.genericError));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateIssueLabels() {
|
|
|
|
|
|
|
|
Labels patchIssueLabels = new Labels(labelsIds);
|
|
|
|
|
|
|
|
Call<JsonElement> call = RetrofitClient
|
|
|
|
.getInstance(instanceUrl, ctx)
|
|
|
|
.getApiInterface()
|
|
|
|
.updateIssueLabels(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, patchIssueLabels);
|
|
|
|
|
|
|
|
call.enqueue(new Callback<JsonElement>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
|
|
|
|
|
|
|
if(response.code() == 200) {
|
|
|
|
|
|
|
|
Toasty.success(ctx, ctx.getString(R.string.labelsUpdated));
|
|
|
|
dialogLabels.dismiss();
|
|
|
|
|
|
|
|
viewBinding.frameAssignees.removeAllViews();
|
|
|
|
viewBinding.frameLabels.removeAllViews();
|
|
|
|
getSingleIssue(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
|
|
|
|
currentLabelsIds.clear();
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() -> LabelsActions.getCurrentIssueLabels(ctx, instanceUrl, loginUid, instanceToken, repoOwner, repoName, issueIndex, currentLabelsIds), 1000);
|
|
|
|
}
|
|
|
|
else if(response.code() == 401) {
|
|
|
|
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
|
|
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
|
|
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
|
|
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
|
|
}
|
|
|
|
else if(response.code() == 403) {
|
|
|
|
|
|
|
|
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
|
|
|
}
|
|
|
|
else if(response.code() == 404) {
|
|
|
|
|
|
|
|
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
Toasty.error(ctx, getString(R.string.genericError));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-30 12:42:22 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
|
|
|
int id = item.getItemId();
|
|
|
|
|
2020-10-29 14:13:19 +01:00
|
|
|
if(id == android.R.id.home) {
|
|
|
|
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(id == R.id.genericMenu) {
|
|
|
|
|
|
|
|
BottomSheetSingleIssueFragment bottomSheet = new BottomSheetSingleIssueFragment();
|
|
|
|
bottomSheet.show(getSupportFragmentManager(), "singleIssueBottomSheet");
|
|
|
|
return true;
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
2020-10-29 14:13:19 +01:00
|
|
|
else {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-29 14:13:19 +01:00
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
|
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
if(tinyDb.getBoolean("commentPosted")) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.scrollViewComments.post(() -> {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
IssueCommentsViewModel
|
|
|
|
.loadIssueComments(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex,
|
|
|
|
ctx);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() -> viewBinding.scrollViewComments.fullScroll(ScrollView.FOCUS_DOWN), 1000);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
tinyDb.putBoolean("commentPosted", false);
|
2020-04-30 12:42:22 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tinyDb.getBoolean("commentEdited")) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.scrollViewComments.post(() -> {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
IssueCommentsViewModel
|
|
|
|
.loadIssueComments(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex,
|
|
|
|
ctx);
|
2020-05-30 18:59:52 +02:00
|
|
|
tinyDb.putBoolean("commentEdited", false);
|
2020-04-30 12:42:22 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tinyDb.getBoolean("singleIssueUpdate")) {
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.frameAssignees.removeAllViews();
|
|
|
|
viewBinding.frameLabels.removeAllViews();
|
2020-05-30 18:59:52 +02:00
|
|
|
getSingleIssue(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
|
|
|
|
tinyDb.putBoolean("singleIssueUpdate", false);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tinyDb.getBoolean("issueEdited")) {
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.frameAssignees.removeAllViews();
|
|
|
|
viewBinding.frameLabels.removeAllViews();
|
2020-05-30 18:59:52 +02:00
|
|
|
getSingleIssue(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
|
|
|
|
tinyDb.putBoolean("issueEdited", false);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fetchDataAsync(String instanceUrl, String instanceToken, String owner, String repo, int index, String loginUid) {
|
|
|
|
|
|
|
|
IssueCommentsViewModel issueCommentsModel = new ViewModelProvider(this).get(IssueCommentsViewModel.class);
|
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
issueCommentsModel.getIssueCommentList(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), owner, repo, index, ctx)
|
|
|
|
.observe(this, issueCommentsMain -> {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
assert issueCommentsMain != null;
|
2020-07-22 21:32:42 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
if(issueCommentsMain.size() > 0) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.divider.setVisibility(View.VISIBLE);
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
|
|
|
|
2020-10-12 20:11:23 +02:00
|
|
|
adapter = new IssueCommentsAdapter(ctx, getSupportFragmentManager(), issueCommentsMain);
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.recyclerView.setAdapter(adapter);
|
2020-07-22 21:32:42 +02:00
|
|
|
});
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void getSingleIssue(String instanceUrl, String instanceToken, String repoOwner, String repoName, int issueIndex, String loginUid) {
|
|
|
|
|
|
|
|
final TinyDB tinyDb = new TinyDB(appCtx);
|
2020-07-22 21:32:42 +02:00
|
|
|
Call<Issues> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
|
|
|
|
.getIssueByIndex(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
|
|
|
call.enqueue(new Callback<Issues>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<Issues> call, @NonNull Response<Issues> response) {
|
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
if(response.code() == 200) {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
Issues singleIssue = response.body();
|
|
|
|
assert singleIssue != null;
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issuePrState.setVisibility(View.VISIBLE);
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-09-13 06:52:30 +02:00
|
|
|
if(singleIssue.getPull_request() != null) {
|
|
|
|
|
|
|
|
if(singleIssue.getPull_request().isMerged()) { // merged
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issuePrState.setImageResource(R.drawable.ic_pull_request_merged);
|
2020-09-13 06:52:30 +02:00
|
|
|
}
|
|
|
|
else if(!singleIssue.getPull_request().isMerged() && singleIssue.getState().equals("closed")) { // closed
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issuePrState.setImageResource(R.drawable.ic_pull_request_closed);
|
2020-09-13 06:52:30 +02:00
|
|
|
}
|
|
|
|
else { // open
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issuePrState.setImageResource(R.drawable.ic_pull_request);
|
2020-09-13 06:52:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(singleIssue.getState().equals("closed")) { // issue closed
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issuePrState.setImageResource(R.drawable.ic_issue_closed_red);
|
2020-09-13 06:52:30 +02:00
|
|
|
}
|
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
final Markwon markwon = Markwon.builder(Objects.requireNonNull(ctx)).usePlugin(CorePlugin.create())
|
|
|
|
.usePlugin(ImagesPlugin.create(plugin -> {
|
|
|
|
plugin.addSchemeHandler(new SchemeHandler() {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public ImageItem handle(@NonNull String raw, @NonNull Uri uri) {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
final int resourceId = ctx.getResources()
|
|
|
|
.getIdentifier(raw.substring("drawable://".length()), "drawable", ctx.getPackageName());
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-29 14:13:19 +01:00
|
|
|
final Drawable drawable = ContextCompat.getDrawable(ctx, resourceId);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
assert drawable != null;
|
|
|
|
return ImageItem.withResult(drawable);
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public Collection<String> supportedSchemes() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
return Collections.singleton("drawable");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
plugin.placeholderProvider(drawable -> null);
|
|
|
|
plugin.addMediaDecoder(GifMediaDecoder.create(false));
|
|
|
|
plugin.addMediaDecoder(SvgMediaDecoder.create(ctx.getResources()));
|
|
|
|
plugin.addMediaDecoder(SvgMediaDecoder.create());
|
|
|
|
plugin.defaultMediaDecoder(DefaultMediaDecoder.create(ctx.getResources()));
|
|
|
|
plugin.defaultMediaDecoder(DefaultMediaDecoder.create());
|
2020-05-30 18:59:52 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
})).usePlugin(new AbstractMarkwonPlugin() {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
@Override
|
|
|
|
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
|
2020-05-30 18:59:52 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
builder.codeTextColor(tinyDb.getInt("codeBlockColor")).codeBackgroundColor(tinyDb.getInt("codeBlockBackground"))
|
|
|
|
.linkColor(getResources().getColor(R.color.lightBlue));
|
|
|
|
}
|
|
|
|
}).usePlugin(TablePlugin.create(ctx)).usePlugin(TaskListPlugin.create(ctx)).usePlugin(HtmlPlugin.create())
|
|
|
|
.usePlugin(StrikethroughPlugin.create()).usePlugin(LinkifyPlugin.create()).build();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
TinyDB tinyDb = new TinyDB(appCtx);
|
|
|
|
final String locale = tinyDb.getString("locale");
|
|
|
|
final String timeFormat = tinyDb.getString("dateFormat");
|
|
|
|
tinyDb.putString("issueState", singleIssue.getState());
|
|
|
|
tinyDb.putString("issueTitle", singleIssue.getTitle());
|
2020-08-12 09:31:06 +02:00
|
|
|
tinyDb.putString("singleIssueHtmlUrl", singleIssue.getHtml_url());
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
PicassoService.getInstance(ctx).get().load(singleIssue.getUser().getAvatar_url()).placeholder(R.drawable.loader_animated)
|
2020-10-09 17:47:52 +02:00
|
|
|
.transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(viewBinding.assigneeAvatar);
|
2020-07-22 21:32:42 +02:00
|
|
|
String issueNumber_ = "<font color='" + appCtx.getResources().getColor(R.color.lightGray) + "'>" + appCtx.getResources()
|
|
|
|
.getString(R.string.hash) + singleIssue.getNumber() + "</font>";
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issueTitle.setText(Html.fromHtml(issueNumber_ + " " + singleIssue.getTitle()));
|
2020-05-30 18:59:52 +02:00
|
|
|
String cleanIssueDescription = singleIssue.getBody().trim();
|
|
|
|
Spanned bodyWithMD = markwon.toMarkdown(EmojiParser.parseToUnicode(cleanIssueDescription));
|
2020-10-09 17:47:52 +02:00
|
|
|
markwon.setParsedMarkdown(viewBinding.issueDescription, UserMentions.UserMentionsFunc(ctx, bodyWithMD, cleanIssueDescription));
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
RelativeLayout.LayoutParams paramsDesc = (RelativeLayout.LayoutParams) viewBinding.issueDescription.getLayoutParams();
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(80, 80);
|
|
|
|
params1.setMargins(15, 0, 0, 0);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
if(singleIssue.getAssignees() != null) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.assigneesScrollView.setVisibility(View.VISIBLE);
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
for(int i = 0; i < singleIssue.getAssignees().size(); i++) {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
ImageView assigneesView = new ImageView(ctx);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
PicassoService.getInstance(ctx).get().load(singleIssue.getAssignees().get(i).getAvatar_url())
|
|
|
|
.placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(100, 100).centerCrop()
|
|
|
|
.into(assigneesView);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.frameAssignees.addView(assigneesView);
|
2020-05-30 18:59:52 +02:00
|
|
|
assigneesView.setLayoutParams(params1);
|
|
|
|
if(!singleIssue.getAssignees().get(i).getFull_name().equals("")) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
assigneesView.setOnClickListener(
|
|
|
|
new ClickListener(getString(R.string.assignedTo, singleIssue.getAssignees().get(i).getFull_name()), ctx));
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
2020-05-30 18:59:52 +02:00
|
|
|
else {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
assigneesView.setOnClickListener(
|
|
|
|
new ClickListener(getString(R.string.assignedTo, singleIssue.getAssignees().get(i).getLogin()), ctx));
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.assigneesScrollView.setVisibility(View.GONE);
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT);
|
2020-05-30 18:59:52 +02:00
|
|
|
params.setMargins(0, 0, 15, 0);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
if(singleIssue.getLabels() != null) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.labelsScrollView.setVisibility(View.VISIBLE);
|
2020-07-22 21:32:42 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
for(int i = 0; i < singleIssue.getLabels().size(); i++) {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
String labelColor = singleIssue.getLabels().get(i).getColor();
|
|
|
|
String labelName = singleIssue.getLabels().get(i).getName();
|
|
|
|
int color = Color.parseColor("#" + labelColor);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
ImageView labelsView = new ImageView(ctx);
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.frameLabels.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
viewBinding.frameLabels.setGravity(Gravity.START | Gravity.TOP);
|
2020-05-30 18:59:52 +02:00
|
|
|
labelsView.setLayoutParams(params);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
int height = AppUtil.getPixelsFromDensity(ctx, 25);
|
|
|
|
int textSize = AppUtil.getPixelsFromScaledDensity(ctx, 15);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT)
|
|
|
|
.textColor(new ColorInverter().getContrastColor(color)).fontSize(textSize)
|
|
|
|
.width(LabelWidthCalculator.calculateLabelWidth(labelName, Typeface.DEFAULT, textSize, AppUtil.getPixelsFromDensity(ctx, 10)))
|
|
|
|
.height(height).endConfig().buildRoundRect(labelName, color, AppUtil.getPixelsFromDensity(ctx, 5));
|
|
|
|
|
|
|
|
labelsView.setImageDrawable(drawable);
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.frameLabels.addView(labelsView);
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.labelsScrollView.setVisibility(View.GONE);
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
if(singleIssue.getDue_date() != null) {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
if(timeFormat.equals("normal") || timeFormat.equals("pretty")) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", new Locale(locale));
|
|
|
|
String dueDate = formatter.format(singleIssue.getDue_date());
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issueDueDate.setText(dueDate);
|
|
|
|
viewBinding.issueDueDate
|
2020-07-22 21:32:42 +02:00
|
|
|
.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(singleIssue.getDue_date()), ctx));
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
2020-05-30 18:59:52 +02:00
|
|
|
else if(timeFormat.equals("normal1")) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", new Locale(locale));
|
|
|
|
String dueDate = formatter.format(singleIssue.getDue_date());
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issueDueDate.setText(dueDate);
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issueDueDate.setVisibility(View.GONE);
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
String edited;
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
if(!singleIssue.getUpdated_at().equals(singleIssue.getCreated_at())) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
edited = getString(R.string.colorfulBulletSpan) + getString(R.string.modifiedText);
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issueModified.setVisibility(View.VISIBLE);
|
|
|
|
viewBinding.issueModified.setText(edited);
|
|
|
|
viewBinding.issueModified
|
2020-07-22 21:32:42 +02:00
|
|
|
.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(singleIssue.getUpdated_at()), ctx));
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issueModified.setVisibility(View.INVISIBLE);
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
if((singleIssue.getDue_date() == null && singleIssue.getMilestone() == null) && singleIssue.getAssignees() != null) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
paramsDesc.setMargins(0, 35, 0, 0);
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issueDescription.setLayoutParams(paramsDesc);
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
|
|
|
else if(singleIssue.getDue_date() == null && singleIssue.getMilestone() == null) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
paramsDesc.setMargins(0, 55, 0, 0);
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issueDescription.setLayoutParams(paramsDesc);
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
|
|
|
else if(singleIssue.getAssignees() == null) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
paramsDesc.setMargins(0, 35, 0, 0);
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issueDescription.setLayoutParams(paramsDesc);
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
paramsDesc.setMargins(0, 15, 0, 0);
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issueDescription.setLayoutParams(paramsDesc);
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issueCreatedTime.setText(TimeHelper.formatTime(singleIssue.getCreated_at(), new Locale(locale), timeFormat, ctx));
|
|
|
|
viewBinding.issueCreatedTime.setVisibility(View.VISIBLE);
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
if(timeFormat.equals("pretty")) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issueCreatedTime
|
2020-07-22 21:32:42 +02:00
|
|
|
.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(singleIssue.getCreated_at()), ctx));
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(singleIssue.getMilestone() != null) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
viewBinding.issueMilestone.setVisibility(View.VISIBLE);
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issueMilestone.setText(getString(R.string.issueMilestone, singleIssue.getMilestone().getTitle()));
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.issueMilestone.setVisibility(View.GONE);
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
2020-04-30 12:42:22 +02:00
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
if(!singleIssue.getUser().getFull_name().equals("")) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.assigneeAvatar.setOnClickListener(
|
2020-07-22 21:32:42 +02:00
|
|
|
new ClickListener(ctx.getResources().getString(R.string.issueCreator) + singleIssue.getUser().getFull_name(), ctx));
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
2020-05-30 18:59:52 +02:00
|
|
|
else {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.assigneeAvatar.setOnClickListener(
|
2020-07-22 21:32:42 +02:00
|
|
|
new ClickListener(ctx.getResources().getString(R.string.issueCreator) + singleIssue.getUser().getLogin(), ctx));
|
2020-05-30 18:59:52 +02:00
|
|
|
}
|
|
|
|
|
2020-10-09 17:47:52 +02:00
|
|
|
viewBinding.progressBar.setVisibility(View.GONE);
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
|
|
|
else if(response.code() == 401) {
|
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
|
|
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
|
|
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
|
|
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
2020-04-30 12:42:22 +02:00
|
|
|
|
|
|
|
}
|
2020-10-23 20:13:13 +02:00
|
|
|
else if(response.code() == 404) {
|
|
|
|
|
|
|
|
if(tinyDb.getString("issueType").equals("Issue")) {
|
|
|
|
|
|
|
|
Toasty.warning(ctx, getResources().getString(R.string.noDataIssueTab));
|
|
|
|
}
|
|
|
|
else if(tinyDb.getString("issueType").equals("Pull")) {
|
|
|
|
|
|
|
|
Toasty.warning(ctx, getResources().getString(R.string.noDataPullRequests));
|
|
|
|
}
|
|
|
|
|
|
|
|
Intent mainIntent = new Intent(ctx, MainActivity.class);
|
|
|
|
ctx.startActivity(mainIntent);
|
|
|
|
finish();
|
|
|
|
}
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Issues> call, @NonNull Throwable t) {
|
|
|
|
|
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
}
|
2020-05-30 18:59:52 +02:00
|
|
|
|
2020-04-30 12:42:22 +02:00
|
|
|
});
|
|
|
|
|
2020-05-21 20:58:00 +02:00
|
|
|
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
|
|
|
|
2020-07-22 21:32:42 +02:00
|
|
|
Call<WatchInfo> call2 = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
|
|
|
|
.checkIssueWatchStatus(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
|
2020-05-21 20:58:00 +02:00
|
|
|
|
|
|
|
call2.enqueue(new Callback<WatchInfo>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<WatchInfo> call, @NonNull Response<WatchInfo> response) {
|
|
|
|
|
|
|
|
if(response.isSuccessful()) {
|
|
|
|
|
2020-05-30 18:59:52 +02:00
|
|
|
assert response.body() != null;
|
2020-05-21 20:58:00 +02:00
|
|
|
tinyDb.putBoolean("issueSubscribed", response.body().getSubscribed());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
tinyDb.putBoolean("issueSubscribed", false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
|
|
|
|
|
|
|
|
tinyDb.putBoolean("issueSubscribed", false);
|
|
|
|
}
|
2020-05-30 18:59:52 +02:00
|
|
|
|
2020-05-21 20:58:00 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-30 12:42:22 +02:00
|
|
|
}
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|