mirror of
https://codeberg.org/gitnex/GitNex
synced 2025-03-09 16:10:50 +01:00
Add support for commit statuses (#1212)
Addresses https://codeberg.org/gitnex/GitNex/issues/435 but only supports commits and not PRs. Co-authored-by: qwerty287 <ndev@web.de> Co-authored-by: M M Arif <mmarif@noreply.codeberg.org> Co-authored-by: M M Arif <mmarif@swatian.com> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1212 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>
This commit is contained in:
parent
f0a1db1ef2
commit
16f547fed2
@ -0,0 +1,120 @@
|
|||||||
|
package org.mian.gitnex.adapters;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.ColorStateList;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.widget.ImageViewCompat;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import java.util.List;
|
||||||
|
import org.gitnex.tea4j.v2.models.CommitStatus;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author qwerty287
|
||||||
|
*/
|
||||||
|
public class CommitStatusesAdapter
|
||||||
|
extends RecyclerView.Adapter<CommitStatusesAdapter.CommitStatusesViewHolder> {
|
||||||
|
|
||||||
|
private final List<CommitStatus> statuses;
|
||||||
|
|
||||||
|
static class CommitStatusesViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
private CommitStatus status;
|
||||||
|
|
||||||
|
private final TextView name;
|
||||||
|
private final TextView description;
|
||||||
|
private final ImageView icon;
|
||||||
|
|
||||||
|
private CommitStatusesViewHolder(View itemView) {
|
||||||
|
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
icon = itemView.findViewById(R.id.statusIcon);
|
||||||
|
name = itemView.findViewById(R.id.name);
|
||||||
|
description = itemView.findViewById(R.id.description);
|
||||||
|
|
||||||
|
itemView.setOnClickListener(taskInfo -> openUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openUrl() {
|
||||||
|
if (status.getTargetUrl() != null && !status.getTargetUrl().equals("")) {
|
||||||
|
AppUtil.openUrlInBrowser(itemView.getContext(), status.getTargetUrl());
|
||||||
|
} else {
|
||||||
|
Toasty.info(
|
||||||
|
itemView.getContext(),
|
||||||
|
itemView.getContext().getString(R.string.statusNoUrl));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommitStatusesAdapter(List<CommitStatus> statuses) {
|
||||||
|
this.statuses = statuses;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull @Override
|
||||||
|
public CommitStatusesAdapter.CommitStatusesViewHolder onCreateViewHolder(
|
||||||
|
@NonNull ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
|
View v =
|
||||||
|
LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.list_commit_status, parent, false);
|
||||||
|
return new CommitStatusesAdapter.CommitStatusesViewHolder(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(
|
||||||
|
@NonNull CommitStatusesAdapter.CommitStatusesViewHolder holder, int position) {
|
||||||
|
|
||||||
|
CommitStatus currentItem = statuses.get(position);
|
||||||
|
Context ctx = holder.itemView.getContext();
|
||||||
|
|
||||||
|
holder.status = currentItem;
|
||||||
|
holder.name.setText(currentItem.getContext());
|
||||||
|
holder.description.setText(currentItem.getDescription());
|
||||||
|
switch (currentItem.getStatus().toLowerCase()) {
|
||||||
|
case "pending":
|
||||||
|
holder.icon.setImageResource(R.drawable.ic_dot_fill);
|
||||||
|
ImageViewCompat.setImageTintList(
|
||||||
|
holder.icon,
|
||||||
|
ColorStateList.valueOf(
|
||||||
|
ctx.getResources().getColor(R.color.lightYellow, null)));
|
||||||
|
break;
|
||||||
|
case "success":
|
||||||
|
holder.icon.setImageResource(R.drawable.ic_check);
|
||||||
|
ImageViewCompat.setImageTintList(
|
||||||
|
holder.icon,
|
||||||
|
ColorStateList.valueOf(
|
||||||
|
ctx.getResources().getColor(R.color.colorLightGreen, null)));
|
||||||
|
break;
|
||||||
|
case "error":
|
||||||
|
case "failure":
|
||||||
|
holder.icon.setImageResource(R.drawable.ic_close);
|
||||||
|
ImageViewCompat.setImageTintList(
|
||||||
|
holder.icon,
|
||||||
|
ColorStateList.valueOf(
|
||||||
|
ctx.getResources().getColor(R.color.iconIssuePrClosedColor, null)));
|
||||||
|
break;
|
||||||
|
case "warning":
|
||||||
|
holder.icon.setImageResource(R.drawable.ic_warning);
|
||||||
|
ImageViewCompat.setImageTintList(
|
||||||
|
holder.icon,
|
||||||
|
ColorStateList.valueOf(
|
||||||
|
ctx.getResources().getColor(R.color.lightYellow, null)));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
holder.icon.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return statuses.size();
|
||||||
|
}
|
||||||
|
}
|
@ -18,9 +18,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.gitnex.tea4j.v2.models.Commit;
|
import org.gitnex.tea4j.v2.models.Commit;
|
||||||
|
import org.gitnex.tea4j.v2.models.CommitStatus;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.activities.BaseActivity;
|
import org.mian.gitnex.activities.BaseActivity;
|
||||||
import org.mian.gitnex.activities.ProfileActivity;
|
import org.mian.gitnex.activities.ProfileActivity;
|
||||||
|
import org.mian.gitnex.adapters.CommitStatusesAdapter;
|
||||||
import org.mian.gitnex.adapters.DiffFilesAdapter;
|
import org.mian.gitnex.adapters.DiffFilesAdapter;
|
||||||
import org.mian.gitnex.clients.PicassoService;
|
import org.mian.gitnex.clients.PicassoService;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
@ -84,6 +86,18 @@ public class CommitDetailFragment extends Fragment {
|
|||||||
|
|
||||||
getCommit();
|
getCommit();
|
||||||
getDiff();
|
getDiff();
|
||||||
|
getStatuses();
|
||||||
|
|
||||||
|
binding.statuses.setOnClickListener(
|
||||||
|
view -> {
|
||||||
|
if (binding.statusesLv.getVisibility() == View.GONE) {
|
||||||
|
binding.statusesExpandCollapse.setImageResource(R.drawable.ic_chevron_up);
|
||||||
|
binding.statusesLv.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
binding.statusesExpandCollapse.setImageResource(R.drawable.ic_chevron_down);
|
||||||
|
binding.statusesLv.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
binding.close.setOnClickListener((v) -> requireActivity().finish());
|
binding.close.setOnClickListener((v) -> requireActivity().finish());
|
||||||
|
|
||||||
@ -371,9 +385,74 @@ public class CommitDetailFragment extends Fragment {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getStatuses() {
|
||||||
|
RetrofitClient.getApiInterface(requireContext())
|
||||||
|
.repoListStatuses(repoOwner, repoName, sha, null, null, null, null)
|
||||||
|
.enqueue(
|
||||||
|
new Callback<>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(
|
||||||
|
@NonNull Call<List<CommitStatus>> call,
|
||||||
|
@NonNull Response<List<CommitStatus>> response) {
|
||||||
|
|
||||||
|
checkLoading();
|
||||||
|
|
||||||
|
if (!response.isSuccessful() || response.body() == null) {
|
||||||
|
onFailure(call, new Throwable());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.body().size() < 1) {
|
||||||
|
binding.statusesLvMain.setVisibility(View.GONE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// merge statuses: a status can be added multiple times with the
|
||||||
|
// same context, so we only use the newest one
|
||||||
|
ArrayList<CommitStatus> result = new ArrayList<>();
|
||||||
|
for (CommitStatus c : response.body()) {
|
||||||
|
CommitStatus statusInList = null;
|
||||||
|
for (CommitStatus s : result) {
|
||||||
|
if (Objects.equals(s.getContext(), c.getContext())) {
|
||||||
|
statusInList = s;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (statusInList != null) {
|
||||||
|
// if the status that's already in the list was created
|
||||||
|
// before this one, replace it
|
||||||
|
if (statusInList.getCreatedAt().before(c.getCreatedAt())) {
|
||||||
|
result.remove(statusInList);
|
||||||
|
result.add(c);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result.add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.statusesList.setLayoutManager(
|
||||||
|
new LinearLayoutManager(requireContext()));
|
||||||
|
binding.statusesList.setAdapter(new CommitStatusesAdapter(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(
|
||||||
|
@NonNull Call<List<CommitStatus>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
checkLoading();
|
||||||
|
if (getContext() != null) {
|
||||||
|
Toasty.error(
|
||||||
|
requireContext(), getString(R.string.genericError));
|
||||||
|
requireActivity().finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void checkLoading() {
|
private void checkLoading() {
|
||||||
loadingFinished += 1;
|
loadingFinished += 1;
|
||||||
if (loadingFinished >= 2) {
|
if (loadingFinished >= 3) {
|
||||||
binding.progressBar.setVisibility(View.GONE);
|
binding.progressBar.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import android.util.Base64;
|
|||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import androidx.annotation.AttrRes;
|
||||||
import androidx.annotation.ColorInt;
|
import androidx.annotation.ColorInt;
|
||||||
import androidx.browser.customtabs.CustomTabColorSchemeParams;
|
import androidx.browser.customtabs.CustomTabColorSchemeParams;
|
||||||
import androidx.browser.customtabs.CustomTabsIntent;
|
import androidx.browser.customtabs.CustomTabsIntent;
|
||||||
@ -330,7 +331,7 @@ public class AppUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ColorInt
|
@ColorInt
|
||||||
public static int getColorFromAttribute(Context context, int resid) {
|
public static int getColorFromAttribute(Context context, @AttrRes int resid) {
|
||||||
|
|
||||||
TypedValue typedValue = new TypedValue();
|
TypedValue typedValue = new TypedValue();
|
||||||
context.getTheme().resolveAttribute(resid, typedValue, true);
|
context.getTheme().resolveAttribute(resid, typedValue, true);
|
||||||
|
10
app/src/main/res/drawable/ic_dot_fill.xml
Normal file
10
app/src/main/res/drawable/ic_dot_fill.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="16dp"
|
||||||
|
android:height="16dp"
|
||||||
|
android:viewportWidth="16"
|
||||||
|
android:viewportHeight="16">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M8,4a4,4 0,1 0,0 8,4 4,0 0,0 0,-8z"
|
||||||
|
android:fillType="evenOdd"/>
|
||||||
|
</vector>
|
@ -181,6 +181,67 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/statusesLvMain"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:foreground="?android:attr/selectableItemBackground"
|
||||||
|
android:background="?attr/materialCardBackgroundColor"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:paddingTop="@dimen/dimen8dp"
|
||||||
|
android:id="@+id/statuses"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:padding="@dimen/dimen2dp"
|
||||||
|
android:minHeight="@dimen/dimen48dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/commitStatuses"
|
||||||
|
android:textSize="@dimen/dimen16sp"
|
||||||
|
android:paddingTop="@dimen/dimen10dp"
|
||||||
|
android:layout_weight="0.9"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingBottom="@dimen/dimen10dp"
|
||||||
|
android:paddingStart="@dimen/dimen0dp"
|
||||||
|
android:paddingEnd="@dimen/dimen0dp"
|
||||||
|
android:textColor="?attr/primaryTextColor"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/statusesExpandCollapse"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0.1"
|
||||||
|
android:layout_gravity="center_vertical|end"
|
||||||
|
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/generalImgContentText"
|
||||||
|
app:srcCompat="@drawable/ic_chevron_down"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:visibility="gone"
|
||||||
|
android:id="@+id/statusesLv"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/statusesList"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="@dimen/dimen16sp"
|
||||||
|
android:textColor="?attr/primaryTextColor"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
61
app/src/main/res/layout/list_commit_status.xml
Normal file
61
app/src/main/res/layout/list_commit_status.xml
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
style="?attr/materialCardViewFilledStyle"
|
||||||
|
android:background="?android:attr/selectableItemBackground"
|
||||||
|
app:cardElevation="@dimen/dimen0dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/mainLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:foreground="?android:attr/selectableItemBackground"
|
||||||
|
android:background="?attr/materialCardBackgroundColor"
|
||||||
|
android:padding="@dimen/dimen6dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/statusIcon"
|
||||||
|
android:layout_width="@dimen/dimen24dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:contentDescription="@string/commitStatuses"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:layout_marginEnd="@dimen/dimen16dp"
|
||||||
|
tools:src="@drawable/ic_dot_fill"
|
||||||
|
tools:tint="@color/lightYellow"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/name"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="@dimen/dimen6dp"
|
||||||
|
android:textColor="?attr/primaryTextColor"
|
||||||
|
android:textSize="@dimen/dimen16sp"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/description"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="@dimen/dimen6dp"
|
||||||
|
android:textColor="?attr/primaryTextColor"
|
||||||
|
android:textSize="@dimen/dimen12sp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@ -844,4 +844,7 @@
|
|||||||
<string name="timelineRefPr">%1$s referenced this pull request in #%2$d %3$s</string>
|
<string name="timelineRefPr">%1$s referenced this pull request in #%2$d %3$s</string>
|
||||||
<string name="timelineStatusRefIssue"><![CDATA[%1$s referenced this issue from a <font color=\'%2$d\'>%3$s</font> %4$s]]></string>
|
<string name="timelineStatusRefIssue"><![CDATA[%1$s referenced this issue from a <font color=\'%2$d\'>%3$s</font> %4$s]]></string>
|
||||||
|
|
||||||
|
<string name="commitStatuses">Statuses</string>
|
||||||
|
<string name="statusNoUrl">This status has no linked target URL.</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user