Introduce two styles(dorts and text). Let the user choose. default is dot. Extend it to explore issues

This commit is contained in:
M M Arif
2022-03-16 15:23:22 +05:00
parent ba6a0a636f
commit bb31bb84c0
8 changed files with 308 additions and 70 deletions

View File

@@ -100,6 +100,16 @@ public class SettingsAppearanceActivity extends BaseActivity {
});
activitySettingsAppearanceBinding.counterBadgeFrame.setOnClickListener(v -> counterBadgesSwitch.setChecked(!counterBadgesSwitch.isChecked()));
// show labels in lists(issues, pr) - default is color dots
activitySettingsAppearanceBinding.switchLabelsInListBadge.setChecked(tinyDB.getBoolean("showLabelsInList", true));
activitySettingsAppearanceBinding.switchLabelsInListBadge.setOnCheckedChangeListener((buttonView, isChecked) -> {
tinyDB.putBoolean("showLabelsInList", isChecked);
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
});
activitySettingsAppearanceBinding.labelsInListFrame.setOnClickListener(v -> activitySettingsAppearanceBinding.switchLabelsInListBadge.setChecked(!activitySettingsAppearanceBinding.switchLabelsInListBadge.isChecked()));
// theme selection dialog
themeFrame.setOnClickListener(view -> {

View File

@@ -3,15 +3,21 @@ package org.mian.gitnex.adapters;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.text.HtmlCompat;
import androidx.recyclerview.widget.RecyclerView;
import com.amulyakhare.textdrawable.TextDrawable;
import org.gitnex.tea4j.models.Issues;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.BaseActivity;
@@ -23,6 +29,8 @@ import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.ClickListener;
import org.mian.gitnex.helpers.ColorInverter;
import org.mian.gitnex.helpers.LabelWidthCalculator;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.helpers.TinyDB;
@@ -98,6 +106,10 @@ public class ExploreIssuesAdapter extends RecyclerView.Adapter<RecyclerView.View
private final TextView issueTitle;
private final TextView issueCreatedTime;
private final TextView issueCommentsCount;
private final HorizontalScrollView labelsScrollViewWithText;
private final LinearLayout frameLabels;
private final HorizontalScrollView labelsScrollViewDots;
private final LinearLayout frameLabelsDots;
IssuesHolder(View itemView) {
super(itemView);
@@ -105,14 +117,17 @@ public class ExploreIssuesAdapter extends RecyclerView.Adapter<RecyclerView.View
issueTitle = itemView.findViewById(R.id.issueTitle);
issueCommentsCount = itemView.findViewById(R.id.issueCommentsCount);
issueCreatedTime = itemView.findViewById(R.id.issueCreatedTime);
labelsScrollViewWithText = itemView.findViewById(R.id.labelsScrollViewWithText);
frameLabels = itemView.findViewById(R.id.frameLabels);
labelsScrollViewDots = itemView.findViewById(R.id.labelsScrollViewDots);
frameLabelsDots = itemView.findViewById(R.id.frameLabelsDots);
itemView.setOnClickListener(v -> {
String[] parts = issue.getRepository().getFull_name().split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
int currentActiveAccountId = ((BaseActivity) context).getAccount().getAccount().getAccountId();
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
@@ -171,6 +186,68 @@ public class ExploreIssuesAdapter extends RecyclerView.Adapter<RecyclerView.View
issueTitle.setText(HtmlCompat.fromHtml(issueNumber_ + " " + issue.getTitle(), HtmlCompat.FROM_HTML_MODE_LEGACY));
issueCommentsCount.setText(String.valueOf(issue.getComments()));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 15, 0);
if(issue.getLabels() != null) {
if(!tinyDb.getBoolean("showLabelsInList")) { // default
labelsScrollViewWithText.setVisibility(View.GONE);
labelsScrollViewDots.setVisibility(View.VISIBLE);
frameLabelsDots.removeAllViews();
for(int i = 0; i < issue.getLabels().size(); i++) {
String labelColor = issue.getLabels().get(i).getColor();
int color = Color.parseColor("#" + labelColor);
ImageView labelsView = new ImageView(context);
frameLabelsDots.setOrientation(LinearLayout.HORIZONTAL);
frameLabelsDots.setGravity(Gravity.START | Gravity.TOP);
labelsView.setLayoutParams(params);
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).width(54).height(54).endConfig().buildRound("", color);
labelsView.setImageDrawable(drawable);
frameLabelsDots.addView(labelsView);
}
}
else {
labelsScrollViewDots.setVisibility(View.GONE);
labelsScrollViewWithText.setVisibility(View.VISIBLE);
frameLabels.removeAllViews();
for(int i = 0; i < issue.getLabels().size(); i++) {
String labelColor = issue.getLabels().get(i).getColor();
String labelName = issue.getLabels().get(i).getName();
int color = Color.parseColor("#" + labelColor);
ImageView labelsView = new ImageView(context);
frameLabels.setOrientation(LinearLayout.HORIZONTAL);
frameLabels.setGravity(Gravity.START | Gravity.TOP);
labelsView.setLayoutParams(params);
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(labelName, Typeface.DEFAULT, textSize, AppUtil.getPixelsFromDensity(context, 8))).height(height).endConfig().buildRoundRect(labelName, color, AppUtil.getPixelsFromDensity(context, 18));
labelsView.setImageDrawable(drawable);
frameLabels.addView(labelsView);
}
}
}
else {
labelsScrollViewDots.setVisibility(View.GONE);
labelsScrollViewWithText.setVisibility(View.GONE);
}
switch(timeFormat) {
case "pretty": {
PrettyTime prettyTime = new PrettyTime(locale);

View File

@@ -111,8 +111,10 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private final TextView issueTitle;
private final TextView issueCreatedTime;
private final TextView issueCommentsCount;
private final HorizontalScrollView labelsScrollView;
private final HorizontalScrollView labelsScrollViewWithText;
private final LinearLayout frameLabels;
private final HorizontalScrollView labelsScrollViewDots;
private final LinearLayout frameLabelsDots;
IssuesHolder(View itemView) {
@@ -121,8 +123,10 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
issueTitle = itemView.findViewById(R.id.issueTitle);
issueCommentsCount = itemView.findViewById(R.id.issueCommentsCount);
issueCreatedTime = itemView.findViewById(R.id.issueCreatedTime);
labelsScrollView = itemView.findViewById(R.id.labelsScrollView);
labelsScrollViewWithText = itemView.findViewById(R.id.labelsScrollViewWithText);
frameLabels = itemView.findViewById(R.id.frameLabels);
labelsScrollViewDots = itemView.findViewById(R.id.labelsScrollViewDots);
frameLabelsDots = itemView.findViewById(R.id.frameLabelsDots);
issueAssigneeAvatar.setOnLongClickListener(loginId -> {
AppUtil.copyToClipboard(context, issueObject.getUser().getLogin(), context.getString(R.string.copyLoginIdToClipBoard, issueObject.getUser().getLogin()));
@@ -174,34 +178,59 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
if(issue.getLabels() != null) {
labelsScrollView.setVisibility(View.VISIBLE);
frameLabels.removeAllViews();
if(!tinyDb.getBoolean("showLabelsInList")) { // default
for(int i = 0; i < issue.getLabels().size(); i++) {
labelsScrollViewWithText.setVisibility(View.GONE);
labelsScrollViewDots.setVisibility(View.VISIBLE);
frameLabelsDots.removeAllViews();
String labelColor = issue.getLabels().get(i).getColor();
String labelName = issue.getLabels().get(i).getName();
int color = Color.parseColor("#" + labelColor);
for(int i = 0; i < issue.getLabels().size(); i++) {
ImageView labelsView = new ImageView(context);
frameLabels.setOrientation(LinearLayout.HORIZONTAL);
frameLabels.setGravity(Gravity.START | Gravity.TOP);
labelsView.setLayoutParams(params);
String labelColor = issue.getLabels().get(i).getColor();
int color = Color.parseColor("#" + labelColor);
int height = AppUtil.getPixelsFromDensity(context, 20);
int textSize = AppUtil.getPixelsFromScaledDensity(context, 12);
ImageView labelsView = new ImageView(context);
frameLabelsDots.setOrientation(LinearLayout.HORIZONTAL);
frameLabelsDots.setGravity(Gravity.START | Gravity.TOP);
labelsView.setLayoutParams(params);
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT)
.textColor(new ColorInverter().getContrastColor(color)).fontSize(textSize)
.width(LabelWidthCalculator.calculateLabelWidth(labelName, Typeface.DEFAULT, textSize, AppUtil.getPixelsFromDensity(context, 8)))
.height(height).endConfig().buildRoundRect(labelName, color, AppUtil.getPixelsFromDensity(context, 18));
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).width(54).height(54).endConfig().buildRound("", color);
labelsView.setImageDrawable(drawable);
frameLabels.addView(labelsView);
labelsView.setImageDrawable(drawable);
frameLabelsDots.addView(labelsView);
}
}
else {
labelsScrollViewDots.setVisibility(View.GONE);
labelsScrollViewWithText.setVisibility(View.VISIBLE);
frameLabels.removeAllViews();
for(int i = 0; i < issue.getLabels().size(); i++) {
String labelColor = issue.getLabels().get(i).getColor();
String labelName = issue.getLabels().get(i).getName();
int color = Color.parseColor("#" + labelColor);
ImageView labelsView = new ImageView(context);
frameLabels.setOrientation(LinearLayout.HORIZONTAL);
frameLabels.setGravity(Gravity.START | Gravity.TOP);
labelsView.setLayoutParams(params);
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(labelName, Typeface.DEFAULT, textSize, AppUtil.getPixelsFromDensity(context, 8))).height(height).endConfig().buildRoundRect(labelName, color, AppUtil.getPixelsFromDensity(context, 18));
labelsView.setImageDrawable(drawable);
frameLabels.addView(labelsView);
}
}
}
else {
labelsScrollView.setVisibility(View.GONE);
labelsScrollViewDots.setVisibility(View.GONE);
labelsScrollViewWithText.setVisibility(View.GONE);
}
switch(timeFormat) {
@@ -233,31 +262,27 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
static class LoadHolder extends RecyclerView.ViewHolder {
LoadHolder(View itemView) {
super(itemView);
}
}
public void setMoreDataAvailable(boolean moreDataAvailable) {
isMoreDataAvailable = moreDataAvailable;
}
@SuppressLint("NotifyDataSetChanged")
public void notifyDataChanged() {
notifyDataSetChanged();
isLoading = false;
}
public void setLoadMoreListener(Runnable loadMoreListener) {
this.loadMoreListener = loadMoreListener;
}
public void updateList(List<Issues> list) {
issuesList = list;
notifyDataSetChanged();
notifyDataChanged();
}
}

View File

@@ -105,8 +105,10 @@ public class PullRequestsAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
private final TextView prTitle;
private final TextView prCreatedTime;
private final TextView prCommentsCount;
private final HorizontalScrollView labelsScrollView;
private final HorizontalScrollView labelsScrollViewWithText;
private final LinearLayout frameLabels;
private final HorizontalScrollView labelsScrollViewDots;
private final LinearLayout frameLabelsDots;
PullRequestsHolder(View itemView) {
@@ -115,8 +117,10 @@ public class PullRequestsAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
prTitle = itemView.findViewById(R.id.prTitle);
prCommentsCount = itemView.findViewById(R.id.prCommentsCount);
prCreatedTime = itemView.findViewById(R.id.prCreatedTime);
labelsScrollView = itemView.findViewById(R.id.labelsScrollView);
labelsScrollViewWithText = itemView.findViewById(R.id.labelsScrollViewWithText);
frameLabels = itemView.findViewById(R.id.frameLabels);
labelsScrollViewDots = itemView.findViewById(R.id.labelsScrollViewDots);
frameLabelsDots = itemView.findViewById(R.id.frameLabelsDots);
itemView.setOnClickListener(v -> {
Intent intent = new IssueContext(
@@ -165,34 +169,59 @@ public class PullRequestsAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
if(pullRequest.getLabels() != null) {
labelsScrollView.setVisibility(View.VISIBLE);
frameLabels.removeAllViews();
if(!tinyDb.getBoolean("showLabelsInList")) { // default
for(int i = 0; i < pullRequest.getLabels().size(); i++) {
labelsScrollViewWithText.setVisibility(View.GONE);
labelsScrollViewDots.setVisibility(View.VISIBLE);
frameLabelsDots.removeAllViews();
String labelColor = pullRequest.getLabels().get(i).getColor();
String labelName = pullRequest.getLabels().get(i).getName();
int color = Color.parseColor("#" + labelColor);
for(int i = 0; i < pullRequest.getLabels().size(); i++) {
ImageView labelsView = new ImageView(context);
frameLabels.setOrientation(LinearLayout.HORIZONTAL);
frameLabels.setGravity(Gravity.START | Gravity.TOP);
labelsView.setLayoutParams(params);
String labelColor = pullRequest.getLabels().get(i).getColor();
int color = Color.parseColor("#" + labelColor);
int height = AppUtil.getPixelsFromDensity(context, 20);
int textSize = AppUtil.getPixelsFromScaledDensity(context, 12);
ImageView labelsView = new ImageView(context);
frameLabelsDots.setOrientation(LinearLayout.HORIZONTAL);
frameLabelsDots.setGravity(Gravity.START | Gravity.TOP);
labelsView.setLayoutParams(params);
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT)
.textColor(new ColorInverter().getContrastColor(color)).fontSize(textSize)
.width(LabelWidthCalculator.calculateLabelWidth(labelName, Typeface.DEFAULT, textSize, AppUtil.getPixelsFromDensity(context, 8)))
.height(height).endConfig().buildRoundRect(labelName, color, AppUtil.getPixelsFromDensity(context, 18));
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).width(54).height(54).endConfig().buildRound("", color);
labelsView.setImageDrawable(drawable);
frameLabels.addView(labelsView);
labelsView.setImageDrawable(drawable);
frameLabelsDots.addView(labelsView);
}
}
else {
labelsScrollViewDots.setVisibility(View.GONE);
labelsScrollViewWithText.setVisibility(View.VISIBLE);
frameLabels.removeAllViews();
for(int i = 0; i < pullRequest.getLabels().size(); i++) {
String labelColor = pullRequest.getLabels().get(i).getColor();
String labelName = pullRequest.getLabels().get(i).getName();
int color = Color.parseColor("#" + labelColor);
ImageView labelsView = new ImageView(context);
frameLabels.setOrientation(LinearLayout.HORIZONTAL);
frameLabels.setGravity(Gravity.START | Gravity.TOP);
labelsView.setLayoutParams(params);
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(labelName, Typeface.DEFAULT, textSize, AppUtil.getPixelsFromDensity(context, 8))).height(height).endConfig().buildRoundRect(labelName, color, AppUtil.getPixelsFromDensity(context, 18));
labelsView.setImageDrawable(drawable);
frameLabels.addView(labelsView);
}
}
}
else {
labelsScrollView.setVisibility(View.GONE);
labelsScrollViewDots.setVisibility(View.GONE);
labelsScrollViewWithText.setVisibility(View.GONE);
}
String prNumber_ = "<font color='" + ResourcesCompat.getColor(context.getResources(), R.color.lightGray, null) + "'>" + context.getResources().getString(R.string.hash) + pullRequest.getNumber() + "</font>";
@@ -219,6 +248,7 @@ public class PullRequestsAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
isMoreDataAvailable = moreDataAvailable;
}
@SuppressLint("NotifyDataSetChanged")
public void notifyDataChanged() {
notifyDataSetChanged();
isLoading = false;
@@ -230,6 +260,6 @@ public class PullRequestsAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
public void updateList(List<PullRequests> list) {
prList = list;
notifyDataSetChanged();
notifyDataChanged();
}
}

View File

@@ -245,4 +245,46 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/labelsInListFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<TextView
android:id="@+id/tvLabelsInListHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="44dp"
android:layout_marginEnd="24dp"
android:text="@string/settingsLabelsInListHeader"
android:textColor="?attr/primaryTextColor"
android:textSize="16sp" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/switchLabelsInListBadge"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_gravity="end"
android:layout_toEndOf="@+id/tvLabelsInListHeader"
android:gravity="end"
android:paddingStart="0dp"
android:paddingEnd="25dp"
android:switchMinWidth="56dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/switchLabelsInListBadge"
android:layout_marginStart="44dp"
android:layout_marginEnd="44dp"
android:text="@string/settingsLabelsInListHint"
android:textColor="?attr/hintColor"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>

View File

@@ -26,23 +26,49 @@
android:contentDescription="@string/generalImgContentText"
tools:src="@tools:sample/avatars" />
<TextView
android:id="@+id/issueTitle"
android:layout_width="wrap_content"
<LinearLayout
android:id="@+id/titleLabelsSection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center_vertical"
android:text="@string/strFilter"
android:textAlignment="gravity"
android:textColor="?attr/primaryTextColor"
android:textSize="16sp"
tools:text="Id illum odio repellat omnis fuga deserunt aut. Ut est aut similique qui incidunt quia et." />
android:orientation="vertical">
<TextView
android:id="@+id/issueTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center_vertical"
android:text="@string/newIssueTitle"
android:textAlignment="gravity"
android:textColor="?attr/primaryTextColor"
android:textSize="16sp"
tools:text="Id illum odio repellat omnis fuga deserunt aut. Ut est aut similique qui incidunt quia et." />
<HorizontalScrollView
android:id="@+id/labelsScrollViewDots"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foregroundGravity="right"
android:layout_marginBottom="8dp"
android:scrollbarThumbHorizontal="@android:color/transparent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/frameLabelsDots"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp" />
</HorizontalScrollView>
</LinearLayout>
</LinearLayout>
<HorizontalScrollView
android:id="@+id/labelsScrollViewWithText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/labelsScrollView"
android:foregroundGravity="right"
android:layout_marginBottom="8dp"
android:scrollbarThumbHorizontal="@android:color/transparent"

View File

@@ -27,22 +27,48 @@
android:contentDescription="@string/generalImgContentText"
android:src="@drawable/ic_android" />
<TextView
android:id="@+id/prTitle"
android:layout_width="wrap_content"
<LinearLayout
android:id="@+id/titleLabelsSection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center_vertical"
android:textAlignment="gravity"
android:text="@string/strFilter"
android:textColor="?attr/primaryTextColor"
android:textSize="16sp" />
android:orientation="vertical">
<TextView
android:id="@+id/prTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center_vertical"
android:textAlignment="gravity"
android:text="@string/newIssueTitle"
android:textColor="?attr/primaryTextColor"
android:textSize="16sp" />
<HorizontalScrollView
android:id="@+id/labelsScrollViewDots"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foregroundGravity="right"
android:layout_marginBottom="8dp"
android:scrollbarThumbHorizontal="@android:color/transparent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/frameLabelsDots"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp" />
</HorizontalScrollView>
</LinearLayout>
</LinearLayout>
<HorizontalScrollView
android:id="@+id/labelsScrollViewWithText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/labelsScrollView"
android:foregroundGravity="right"
android:layout_marginBottom="8dp"
android:scrollbarThumbHorizontal="@android:color/transparent"

View File

@@ -262,6 +262,8 @@
<string name="generalDeepLinkSelectedText">N/A</string>
<string name="linkSelectorDialogTitle">Select Default Link Handler Screen</string>
<string name="settingsBiometricHeader">Biometric Support</string>
<string name="settingsLabelsInListHeader">Labels With Text Support</string>
<string name="settingsLabelsInListHint">Enabling this will show labels with text in issues and pr lists, default are color dots</string>
<!-- settings -->
<string name="noMoreData">No more data available</string>