@@ -0,0 +1,145 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.models.UserInfo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class AdminGetUsersAdapter extends RecyclerView.Adapter<AdminGetUsersAdapter.UsersViewHolder> implements Filterable {
|
||||
|
||||
private List<UserInfo> usersList;
|
||||
private Context mCtx;
|
||||
private List<UserInfo> usersListFull;
|
||||
|
||||
static class UsersViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView userAvatar;
|
||||
private TextView userFullName;
|
||||
private TextView userEmail;
|
||||
private ImageView userRole;
|
||||
private TextView userName;
|
||||
|
||||
private UsersViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
userAvatar = itemView.findViewById(R.id.userAvatar);
|
||||
userFullName = itemView.findViewById(R.id.userFullName);
|
||||
userName = itemView.findViewById(R.id.userName);
|
||||
userEmail = itemView.findViewById(R.id.userEmail);
|
||||
userRole = itemView.findViewById(R.id.userRole);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public AdminGetUsersAdapter(Context mCtx, List<UserInfo> usersListMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.usersList = usersListMain;
|
||||
usersListFull = new ArrayList<>(usersList);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public AdminGetUsersAdapter.UsersViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.admin_users_list, parent, false);
|
||||
return new AdminGetUsersAdapter.UsersViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull AdminGetUsersAdapter.UsersViewHolder holder, int position) {
|
||||
|
||||
UserInfo currentItem = usersList.get(position);
|
||||
|
||||
if(!currentItem.getFullname().equals("")) {
|
||||
holder.userFullName.setText(currentItem.getFullname());
|
||||
holder.userName.setText(mCtx.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
||||
}
|
||||
else {
|
||||
holder.userFullName.setText(mCtx.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
||||
holder.userName.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(!currentItem.getEmail().equals("")) {
|
||||
holder.userEmail.setText(currentItem.getEmail());
|
||||
}
|
||||
else {
|
||||
holder.userEmail.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(currentItem.getIs_admin()) {
|
||||
holder.userRole.setVisibility(View.VISIBLE);
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.textColor(mCtx.getResources().getColor(R.color.white))
|
||||
.fontSize(44)
|
||||
.width(180)
|
||||
.height(60)
|
||||
.endConfig()
|
||||
.buildRoundRect(mCtx.getResources().getString(R.string.userRoleAdmin).toLowerCase(), mCtx.getResources().getColor(R.color.releasePre), 8);
|
||||
holder.userRole.setImageDrawable(drawable);
|
||||
}
|
||||
else {
|
||||
holder.userRole.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
Picasso.get().load(currentItem.getAvatar()).transform(new RoundedTransformation(100, 0)).resize(140, 140).centerCrop().into(holder.userAvatar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return usersList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return usersFilter;
|
||||
}
|
||||
|
||||
private Filter usersFilter = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
List<UserInfo> filteredList = new ArrayList<>();
|
||||
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
filteredList.addAll(usersListFull);
|
||||
} else {
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
|
||||
for (UserInfo item : usersListFull) {
|
||||
if (item.getEmail().toLowerCase().contains(filterPattern) || item.getFullname().toLowerCase().contains(filterPattern) || item.getUsername().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
usersList.clear();
|
||||
usersList.addAll((List) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.UrlHelper;
|
||||
import org.mian.gitnex.models.Branches;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import java.util.List;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class BranchesAdapter extends RecyclerView.Adapter<BranchesAdapter.BranchesViewHolder> {
|
||||
|
||||
private List<Branches> branchesList;
|
||||
private Context mCtx;
|
||||
|
||||
static class BranchesViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView branchNameTv;
|
||||
private TextView branchCommitAuthor;
|
||||
private TextView branchCommitHash;
|
||||
|
||||
private BranchesViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
branchNameTv = itemView.findViewById(R.id.branchName);
|
||||
branchCommitAuthor = itemView.findViewById(R.id.branchCommitAuthor);
|
||||
branchCommitHash = itemView.findViewById(R.id.branchCommitHash);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public BranchesAdapter(Context mCtx, List<Branches> branchesMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.branchesList = branchesMain;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public BranchesAdapter.BranchesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.branches_list, parent, false);
|
||||
return new BranchesAdapter.BranchesViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull BranchesAdapter.BranchesViewHolder holder, int position) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(mCtx);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
|
||||
Branches currentItem = branchesList.get(position);
|
||||
holder.branchNameTv.setText(currentItem.getName());
|
||||
|
||||
if(currentItem.getCommit().getAuthor().getName() != null || !currentItem.getCommit().getAuthor().getName().equals("")) {
|
||||
holder.branchCommitAuthor.setText(mCtx.getResources().getString(R.string.commitAuthor, currentItem.getCommit().getAuthor().getName()));
|
||||
}
|
||||
else {
|
||||
holder.branchCommitAuthor.setText(mCtx.getResources().getString(R.string.commitAuthor, currentItem.getCommit().getAuthor().getUsername()));
|
||||
}
|
||||
|
||||
holder.branchCommitHash.setText(mCtx.getResources().getString(R.string.commitHash, UrlHelper.cleanUrl(instanceUrl), currentItem.getCommit().getUrl()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return branchesList.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,343 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.vdurmont.emoji.EmojiParser;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.IssueDetailActivity;
|
||||
import org.mian.gitnex.helpers.ClickListener;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.UserMentions;
|
||||
import org.mian.gitnex.models.Issues;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import org.ocpsoft.prettytime.PrettyTime;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import okhttp3.OkHttpClient;
|
||||
import ru.noties.markwon.AbstractMarkwonPlugin;
|
||||
import ru.noties.markwon.Markwon;
|
||||
import ru.noties.markwon.core.CorePlugin;
|
||||
import ru.noties.markwon.core.MarkwonTheme;
|
||||
import ru.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
||||
import ru.noties.markwon.ext.tables.TablePlugin;
|
||||
import ru.noties.markwon.ext.tables.TableTheme;
|
||||
import ru.noties.markwon.ext.tasklist.TaskListPlugin;
|
||||
import ru.noties.markwon.html.HtmlPlugin;
|
||||
import ru.noties.markwon.image.ImagesPlugin;
|
||||
import ru.noties.markwon.image.gif.GifPlugin;
|
||||
import ru.noties.markwon.image.okhttp.OkHttpImagesPlugin;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class ClosedIssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements Filterable {
|
||||
|
||||
private Context context;
|
||||
private final int TYPE_LOAD = 0;
|
||||
private List<Issues> issuesList;
|
||||
private List<Issues> issuesListFull;
|
||||
private ClosedIssuesAdapter.OnLoadMoreListener loadMoreListener;
|
||||
private boolean isLoading = false, isMoreDataAvailable = true;
|
||||
|
||||
public ClosedIssuesAdapter(Context context, List<Issues> issuesListMain) {
|
||||
|
||||
this.context = context;
|
||||
this.issuesList = issuesListMain;
|
||||
issuesListFull = new ArrayList<>(issuesList);
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
|
||||
if(viewType == TYPE_LOAD){
|
||||
return new ClosedIssuesAdapter.IssuesHolder(inflater.inflate(R.layout.repo_detail_issues_list, parent,false));
|
||||
}
|
||||
else {
|
||||
return new ClosedIssuesAdapter.LoadHolder(inflater.inflate(R.layout.row_load,parent,false));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
|
||||
if(position >= getItemCount()-1 && isMoreDataAvailable && !isLoading && loadMoreListener!=null) {
|
||||
|
||||
isLoading = true;
|
||||
loadMoreListener.onLoadMore();
|
||||
|
||||
}
|
||||
|
||||
if(getItemViewType(position) == TYPE_LOAD) {
|
||||
|
||||
((ClosedIssuesAdapter.IssuesHolder)holder).bindData(issuesList.get(position));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
|
||||
if(issuesList.get(position).getTitle() != null) {
|
||||
return TYPE_LOAD;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
|
||||
return issuesList.size();
|
||||
|
||||
}
|
||||
|
||||
class IssuesHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView issueNumber;
|
||||
private ImageView issueAssigneeAvatar;
|
||||
private TextView issueTitle;
|
||||
private TextView issueDescription;
|
||||
//private ImageView issueState;
|
||||
private TextView issueCreatedTime;
|
||||
private TextView issueCommentsCount;
|
||||
private ImageView issueType;
|
||||
|
||||
IssuesHolder(View itemView) {
|
||||
|
||||
super(itemView);
|
||||
|
||||
issueNumber = itemView.findViewById(R.id.issueNumber);
|
||||
issueAssigneeAvatar = itemView.findViewById(R.id.assigneeAvatar);
|
||||
issueTitle = itemView.findViewById(R.id.issueTitle);
|
||||
issueDescription = itemView.findViewById(R.id.issueDescription);
|
||||
issueCommentsCount = itemView.findViewById(R.id.issueCommentsCount);
|
||||
//issueState = itemView.findViewById(R.id.issueStatus);
|
||||
issueCreatedTime = itemView.findViewById(R.id.issueCreatedTime);
|
||||
issueType = itemView.findViewById(R.id.issueType);
|
||||
|
||||
issueTitle.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Context context = v.getContext();
|
||||
//Log.i("issueNumber", issueNumber.getText().toString());
|
||||
|
||||
Intent intent = new Intent(context, IssueDetailActivity.class);
|
||||
intent.putExtra("issueNumber", issueNumber.getText());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putString("issueNumber", issueNumber.getText().toString());
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
issueDescription.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Context context = v.getContext();
|
||||
//Log.i("issueNumber", issueNumber.getText().toString());
|
||||
|
||||
Intent intent = new Intent(context, IssueDetailActivity.class);
|
||||
intent.putExtra("issueNumber", issueNumber.getText());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putString("issueNumber", issueNumber.getText().toString());
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
void bindData(Issues issuesModel){
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(context);
|
||||
final String locale = tinyDb.getString("locale");
|
||||
final String timeFormat = tinyDb.getString("dateFormat");
|
||||
|
||||
final Markwon markwon = Markwon.builder(Objects.requireNonNull(context))
|
||||
.usePlugin(CorePlugin.create())
|
||||
.usePlugin(OkHttpImagesPlugin.create(new OkHttpClient()))
|
||||
.usePlugin(ImagesPlugin.createWithAssets(context))
|
||||
.usePlugin(new AbstractMarkwonPlugin() {
|
||||
@Override
|
||||
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
|
||||
builder
|
||||
.codeTextColor(tinyDb.getInt("codeBlockColor"))
|
||||
.codeBackgroundColor(tinyDb.getInt("codeBlockBackground"))
|
||||
.linkColor(context.getResources().getColor(R.color.lightBlue));
|
||||
}
|
||||
})
|
||||
.usePlugin(TablePlugin.create(context))
|
||||
.usePlugin(TaskListPlugin.create(context))
|
||||
.usePlugin(HtmlPlugin.create())
|
||||
.usePlugin(GifPlugin.create())
|
||||
.usePlugin(StrikethroughPlugin.create())
|
||||
.build();
|
||||
|
||||
if (!issuesModel.getUser().getFull_name().equals("")) {
|
||||
issueAssigneeAvatar.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueCreator) + issuesModel.getUser().getFull_name(), context));
|
||||
} else {
|
||||
issueAssigneeAvatar.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueCreator) + issuesModel.getUser().getLogin(), context));
|
||||
}
|
||||
|
||||
if (issuesModel.getUser().getAvatar_url() != null) {
|
||||
Picasso.get().load(issuesModel.getUser().getAvatar_url()).transform(new RoundedTransformation(100, 0)).resize(200, 200).centerCrop().into(issueAssigneeAvatar);
|
||||
} else {
|
||||
Picasso.get().load(issuesModel.getUser().getAvatar_url()).transform(new RoundedTransformation(100, 0)).resize(200, 200).centerCrop().into(issueAssigneeAvatar);
|
||||
}
|
||||
|
||||
if (issuesModel.getPull_request() == null) {
|
||||
issueType.setImageResource(R.drawable.ic_issues);
|
||||
issueType.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueTypeIssue), context));
|
||||
} else {
|
||||
issueType.setImageResource(R.drawable.ic_merge);
|
||||
issueType.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueTypePullRequest), context));
|
||||
}
|
||||
|
||||
issueTitle.setText(context.getResources().getString(R.string.hash) + issuesModel.getNumber() + " " + issuesModel.getTitle());
|
||||
issueNumber.setText(String.valueOf(issuesModel.getNumber()));
|
||||
issueCommentsCount.setText(String.valueOf(issuesModel.getComments()));
|
||||
|
||||
if (!issuesModel.getBody().equals("")) {
|
||||
String cleanIssueDescription = issuesModel.getBody().trim();
|
||||
issueDescription.setVisibility(View.VISIBLE);
|
||||
final CharSequence bodyWithMD = markwon.toMarkdown(EmojiParser.parseToUnicode(cleanIssueDescription));
|
||||
issueDescription.setText(UserMentions.UserMentionsFunc(context, bodyWithMD, cleanIssueDescription));
|
||||
}
|
||||
else {
|
||||
issueDescription.setText("");
|
||||
issueDescription.setVisibility(View.GONE);
|
||||
}
|
||||
/*if (issuesModel.getState().equals("open")) {
|
||||
issueState.setImageResource(R.drawable.ic_issue_open);
|
||||
issueState.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueStatusTextOpen), context));
|
||||
} else {
|
||||
issueState.setImageResource(R.drawable.ic_issue_closed);
|
||||
issueState.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueStatusTextClosed), context));
|
||||
}*/
|
||||
|
||||
switch (timeFormat) {
|
||||
case "pretty": {
|
||||
PrettyTime prettyTime = new PrettyTime(new Locale(locale));
|
||||
String createdTime = prettyTime.format(issuesModel.getCreated_at());
|
||||
issueCreatedTime.setText(createdTime);
|
||||
issueCreatedTime.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(issuesModel.getCreated_at()), context));
|
||||
break;
|
||||
}
|
||||
case "normal": {
|
||||
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale));
|
||||
String createdTime = formatter.format(issuesModel.getCreated_at());
|
||||
issueCreatedTime.setText(createdTime);
|
||||
break;
|
||||
}
|
||||
case "normal1": {
|
||||
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale));
|
||||
String createdTime = formatter.format(issuesModel.getCreated_at());
|
||||
issueCreatedTime.setText(createdTime);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoadHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
LoadHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
||||
|
||||
isMoreDataAvailable = moreDataAvailable;
|
||||
|
||||
}
|
||||
|
||||
public void notifyDataChanged() {
|
||||
|
||||
notifyDataSetChanged();
|
||||
isLoading = false;
|
||||
|
||||
}
|
||||
|
||||
public interface OnLoadMoreListener {
|
||||
|
||||
void onLoadMore();
|
||||
|
||||
}
|
||||
|
||||
public void setLoadMoreListener(ClosedIssuesAdapter.OnLoadMoreListener loadMoreListener) {
|
||||
|
||||
this.loadMoreListener = loadMoreListener;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return issuesFilter;
|
||||
}
|
||||
|
||||
private Filter issuesFilter = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
List<Issues> filteredList = new ArrayList<>();
|
||||
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
filteredList.addAll(issuesList);
|
||||
} else {
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
|
||||
for (Issues item : issuesList) {
|
||||
if (item.getTitle().toLowerCase().contains(filterPattern) || item.getBody().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
issuesList.clear();
|
||||
issuesList.addAll((List) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.models.Collaborators;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class CollaboratorsAdapter extends BaseAdapter {
|
||||
|
||||
private List<Collaborators> collaboratorsList;
|
||||
private Context mCtx;
|
||||
|
||||
private class ViewHolder {
|
||||
|
||||
private ImageView collaboratorAvatar;
|
||||
private TextView collaboratorName;
|
||||
|
||||
ViewHolder(View v) {
|
||||
collaboratorAvatar = v.findViewById(R.id.collaboratorAvatar);
|
||||
collaboratorName = v.findViewById(R.id.collaboratorName);
|
||||
}
|
||||
}
|
||||
|
||||
public CollaboratorsAdapter(Context mCtx, List<Collaborators> collaboratorsListMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.collaboratorsList = collaboratorsListMain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return collaboratorsList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
@Override
|
||||
public View getView(int position, View finalView, ViewGroup parent) {
|
||||
|
||||
ViewHolder viewHolder = null;
|
||||
|
||||
if (finalView == null) {
|
||||
finalView = LayoutInflater.from(mCtx).inflate(R.layout.collaborators_list, null);
|
||||
viewHolder = new ViewHolder(finalView);
|
||||
finalView.setTag(viewHolder);
|
||||
}
|
||||
else {
|
||||
viewHolder = (ViewHolder) finalView.getTag();
|
||||
}
|
||||
|
||||
initData(viewHolder, position);
|
||||
return finalView;
|
||||
|
||||
}
|
||||
|
||||
private void initData(ViewHolder viewHolder, int position) {
|
||||
|
||||
Collaborators currentItem = collaboratorsList.get(position);
|
||||
Picasso.get().load(currentItem.getAvatar_url()).transform(new RoundedTransformation(100, 0)).resize(200, 200).centerCrop().into(viewHolder.collaboratorAvatar);
|
||||
|
||||
if(!currentItem.getFull_name().equals("")) {
|
||||
viewHolder.collaboratorName.setText(currentItem.getFull_name());
|
||||
}
|
||||
else {
|
||||
viewHolder.collaboratorName.setText(currentItem.getLogin());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.vdurmont.emoji.EmojiParser;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.ReplyToIssueActivity;
|
||||
import org.mian.gitnex.helpers.UserMentions;
|
||||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.models.IssueComments;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import org.mian.gitnex.helpers.ClickListener;
|
||||
import org.ocpsoft.prettytime.PrettyTime;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import okhttp3.OkHttpClient;
|
||||
import ru.noties.markwon.AbstractMarkwonPlugin;
|
||||
import ru.noties.markwon.Markwon;
|
||||
import ru.noties.markwon.core.CorePlugin;
|
||||
import ru.noties.markwon.core.MarkwonTheme;
|
||||
import ru.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
||||
import ru.noties.markwon.ext.tables.TablePlugin;
|
||||
import ru.noties.markwon.ext.tables.TableTheme;
|
||||
import ru.noties.markwon.ext.tasklist.TaskListPlugin;
|
||||
import ru.noties.markwon.html.HtmlPlugin;
|
||||
import ru.noties.markwon.image.ImagesPlugin;
|
||||
import ru.noties.markwon.image.gif.GifPlugin;
|
||||
import ru.noties.markwon.image.okhttp.OkHttpImagesPlugin;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdapter.IssueCommentViewHolder> {
|
||||
|
||||
private List<IssueComments> issuesComments;
|
||||
private Context mCtx;
|
||||
|
||||
static class IssueCommentViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView issueNumber;
|
||||
private TextView commendId;
|
||||
private ImageView issueCommenterAvatar;
|
||||
private TextView issueComment;
|
||||
private TextView issueCommentDate;
|
||||
private ImageView commentsOptionsMenu;
|
||||
private TextView commendBodyRaw;
|
||||
private TextView commentModified;
|
||||
|
||||
private IssueCommentViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
issueNumber = itemView.findViewById(R.id.issueNumber);
|
||||
commendId = itemView.findViewById(R.id.commendId);
|
||||
issueCommenterAvatar = itemView.findViewById(R.id.issueCommenterAvatar);
|
||||
issueComment = itemView.findViewById(R.id.issueComment);
|
||||
issueCommentDate = itemView.findViewById(R.id.issueCommentDate);
|
||||
commentsOptionsMenu = itemView.findViewById(R.id.commentsOptionsMenu);
|
||||
commendBodyRaw = itemView.findViewById(R.id.commendBodyRaw);
|
||||
commentModified = itemView.findViewById(R.id.commentModified);
|
||||
|
||||
commentsOptionsMenu.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
final Context context = v.getContext();
|
||||
Context context_ = new ContextThemeWrapper(context, R.style.popupMenuStyle);
|
||||
|
||||
PopupMenu popupMenu = new PopupMenu(context_, v);
|
||||
popupMenu.inflate(R.menu.issue_comment_menu);
|
||||
|
||||
Object menuHelper;
|
||||
Class[] argTypes;
|
||||
try {
|
||||
|
||||
Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup");
|
||||
fMenuHelper.setAccessible(true);
|
||||
menuHelper = fMenuHelper.get(popupMenu);
|
||||
argTypes = new Class[] { boolean.class };
|
||||
menuHelper.getClass().getDeclaredMethod("setForceShowIcon",
|
||||
argTypes).invoke(menuHelper, true);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
popupMenu.show();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.commentMenuEdit:
|
||||
|
||||
Intent intent = new Intent(context, ReplyToIssueActivity.class);
|
||||
intent.putExtra("commentId", commendId.getText());
|
||||
intent.putExtra("commentAction", "edit");
|
||||
intent.putExtra("commentBody", commendBodyRaw.getText());
|
||||
context.startActivity(intent);
|
||||
break;
|
||||
|
||||
case R.id.commentMenuDelete:
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
popupMenu.show();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public IssueCommentsAdapter(Context mCtx, List<IssueComments> issuesCommentsMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.issuesComments = issuesCommentsMain;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public IssueCommentsAdapter.IssueCommentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.issue_comments, parent, false);
|
||||
return new IssueCommentsAdapter.IssueCommentViewHolder(v);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull IssueCommentsAdapter.IssueCommentViewHolder holder, int position) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(mCtx);
|
||||
final String locale = tinyDb.getString("locale");
|
||||
final String timeFormat = tinyDb.getString("dateFormat");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
|
||||
IssueComments currentItem = issuesComments.get(position);
|
||||
|
||||
if(!loginUid.equals(currentItem.getUser().getUsername())) {
|
||||
holder.commentsOptionsMenu.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
holder.commendId.setText(String.valueOf(currentItem.getId()));
|
||||
holder.commendBodyRaw.setText(currentItem.getBody());
|
||||
|
||||
if (!currentItem.getUser().getFull_name().equals("")) {
|
||||
holder.issueCommenterAvatar.setOnClickListener(new ClickListener(mCtx.getResources().getString(R.string.issueCommenter) + currentItem.getUser().getFull_name(), mCtx));
|
||||
} else {
|
||||
holder.issueCommenterAvatar.setOnClickListener(new ClickListener(mCtx.getResources().getString(R.string.issueCommenter) + currentItem.getUser().getLogin(), mCtx));
|
||||
}
|
||||
|
||||
if (currentItem.getUser().getAvatar_url() != null) {
|
||||
Picasso.get().load(currentItem.getUser().getAvatar_url()).transform(new RoundedTransformation(100, 0)).resize(200, 200).centerCrop().into(holder.issueCommenterAvatar);
|
||||
} else {
|
||||
Picasso.get().load(currentItem.getUser().getAvatar_url()).transform(new RoundedTransformation(100, 0)).resize(200, 200).centerCrop().into(holder.issueCommenterAvatar);
|
||||
}
|
||||
|
||||
String cleanIssueComments = currentItem.getBody().trim();
|
||||
|
||||
final Markwon markwon = Markwon.builder(Objects.requireNonNull(mCtx))
|
||||
.usePlugin(CorePlugin.create())
|
||||
.usePlugin(OkHttpImagesPlugin.create(new OkHttpClient()))
|
||||
.usePlugin(ImagesPlugin.create(mCtx))
|
||||
.usePlugin(new AbstractMarkwonPlugin() {
|
||||
@Override
|
||||
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
|
||||
builder
|
||||
.codeTextColor(tinyDb.getInt("codeBlockColor"))
|
||||
.codeBackgroundColor(tinyDb.getInt("codeBlockBackground"));
|
||||
}
|
||||
})
|
||||
.usePlugin(TablePlugin.create(mCtx))
|
||||
.usePlugin(TaskListPlugin.create(mCtx))
|
||||
.usePlugin(HtmlPlugin.create())
|
||||
.usePlugin(GifPlugin.create())
|
||||
.usePlugin(StrikethroughPlugin.create())
|
||||
.build();
|
||||
|
||||
final CharSequence bodyWithMD = markwon.toMarkdown(EmojiParser.parseToUnicode(cleanIssueComments));
|
||||
holder.issueComment.setText(UserMentions.UserMentionsFunc(mCtx, bodyWithMD, cleanIssueComments));
|
||||
|
||||
String edited;
|
||||
|
||||
if(!currentItem.getUpdated_at().equals(currentItem.getCreated_at())) {
|
||||
edited = mCtx.getResources().getString(R.string.colorfulBulletSpan) + mCtx.getResources().getString(R.string.modifiedText);
|
||||
holder.commentModified.setVisibility(View.VISIBLE);
|
||||
holder.commentModified.setText(edited);
|
||||
holder.commentModified.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(currentItem.getUpdated_at()), mCtx));
|
||||
}
|
||||
else {
|
||||
holder.commentModified.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
switch (timeFormat) {
|
||||
case "pretty": {
|
||||
PrettyTime prettyTime = new PrettyTime(new Locale(locale));
|
||||
String createdTime = prettyTime.format(currentItem.getCreated_at());
|
||||
holder.issueCommentDate.setText(createdTime);
|
||||
holder.issueCommentDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(currentItem.getCreated_at()), mCtx));
|
||||
break;
|
||||
}
|
||||
case "normal": {
|
||||
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + mCtx.getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale));
|
||||
String createdTime = formatter.format(currentItem.getCreated_at());
|
||||
holder.issueCommentDate.setText(createdTime);
|
||||
break;
|
||||
}
|
||||
case "normal1": {
|
||||
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + mCtx.getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale));
|
||||
String createdTime = formatter.format(currentItem.getCreated_at());
|
||||
holder.issueCommentDate.setText(createdTime);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return issuesComments.size();
|
||||
}
|
||||
|
||||
}
|
||||
343
app/src/main/java/org/mian/gitnex/adapters/IssuesAdapter.java
Normal file
343
app/src/main/java/org/mian/gitnex/adapters/IssuesAdapter.java
Normal file
@@ -0,0 +1,343 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.vdurmont.emoji.EmojiParser;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.IssueDetailActivity;
|
||||
import org.mian.gitnex.helpers.ClickListener;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.UserMentions;
|
||||
import org.mian.gitnex.models.Issues;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import org.ocpsoft.prettytime.PrettyTime;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import okhttp3.OkHttpClient;
|
||||
import ru.noties.markwon.AbstractMarkwonPlugin;
|
||||
import ru.noties.markwon.Markwon;
|
||||
import ru.noties.markwon.core.CorePlugin;
|
||||
import ru.noties.markwon.core.MarkwonTheme;
|
||||
import ru.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
||||
import ru.noties.markwon.ext.tables.TablePlugin;
|
||||
import ru.noties.markwon.ext.tables.TableTheme;
|
||||
import ru.noties.markwon.ext.tasklist.TaskListPlugin;
|
||||
import ru.noties.markwon.html.HtmlPlugin;
|
||||
import ru.noties.markwon.image.ImagesPlugin;
|
||||
import ru.noties.markwon.image.gif.GifPlugin;
|
||||
import ru.noties.markwon.image.okhttp.OkHttpImagesPlugin;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements Filterable {
|
||||
|
||||
private Context context;
|
||||
private final int TYPE_LOAD = 0;
|
||||
private List<Issues> issuesList;
|
||||
private List<Issues> issuesListFull;
|
||||
private OnLoadMoreListener loadMoreListener;
|
||||
private boolean isLoading = false, isMoreDataAvailable = true;
|
||||
|
||||
public IssuesAdapter(Context context, List<Issues> issuesListMain) {
|
||||
|
||||
this.context = context;
|
||||
this.issuesList = issuesListMain;
|
||||
issuesListFull = new ArrayList<>(issuesList);
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
|
||||
if(viewType == TYPE_LOAD){
|
||||
return new IssuesHolder(inflater.inflate(R.layout.repo_detail_issues_list, parent,false));
|
||||
}
|
||||
else {
|
||||
return new LoadHolder(inflater.inflate(R.layout.row_load,parent,false));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
|
||||
if(position >= getItemCount()-1 && isMoreDataAvailable && !isLoading && loadMoreListener!=null) {
|
||||
|
||||
isLoading = true;
|
||||
loadMoreListener.onLoadMore();
|
||||
|
||||
}
|
||||
|
||||
if(getItemViewType(position) == TYPE_LOAD) {
|
||||
|
||||
((IssuesHolder)holder).bindData(issuesList.get(position));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
|
||||
if(issuesList.get(position).getTitle() != null) {
|
||||
return TYPE_LOAD;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
|
||||
return issuesList.size();
|
||||
|
||||
}
|
||||
|
||||
class IssuesHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView issueNumber;
|
||||
private ImageView issueAssigneeAvatar;
|
||||
private TextView issueTitle;
|
||||
private TextView issueDescription;
|
||||
//private ImageView issueState;
|
||||
private TextView issueCreatedTime;
|
||||
private TextView issueCommentsCount;
|
||||
private ImageView issueType;
|
||||
|
||||
IssuesHolder(View itemView) {
|
||||
|
||||
super(itemView);
|
||||
|
||||
issueNumber = itemView.findViewById(R.id.issueNumber);
|
||||
issueAssigneeAvatar = itemView.findViewById(R.id.assigneeAvatar);
|
||||
issueTitle = itemView.findViewById(R.id.issueTitle);
|
||||
issueDescription = itemView.findViewById(R.id.issueDescription);
|
||||
issueCommentsCount = itemView.findViewById(R.id.issueCommentsCount);
|
||||
//issueState = itemView.findViewById(R.id.issueStatus);
|
||||
issueCreatedTime = itemView.findViewById(R.id.issueCreatedTime);
|
||||
issueType = itemView.findViewById(R.id.issueType);
|
||||
|
||||
issueTitle.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Context context = v.getContext();
|
||||
//Log.i("issueNumber", issueNumber.getText().toString());
|
||||
|
||||
Intent intent = new Intent(context, IssueDetailActivity.class);
|
||||
intent.putExtra("issueNumber", issueNumber.getText());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putString("issueNumber", issueNumber.getText().toString());
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
issueDescription.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Context context = v.getContext();
|
||||
//Log.i("issueNumber", issueNumber.getText().toString());
|
||||
|
||||
Intent intent = new Intent(context, IssueDetailActivity.class);
|
||||
intent.putExtra("issueNumber", issueNumber.getText());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putString("issueNumber", issueNumber.getText().toString());
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
void bindData(Issues issuesModel){
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(context);
|
||||
final String locale = tinyDb.getString("locale");
|
||||
final String timeFormat = tinyDb.getString("dateFormat");
|
||||
|
||||
final Markwon markwon = Markwon.builder(Objects.requireNonNull(context))
|
||||
.usePlugin(CorePlugin.create())
|
||||
.usePlugin(OkHttpImagesPlugin.create(new OkHttpClient()))
|
||||
.usePlugin(ImagesPlugin.createWithAssets(context))
|
||||
.usePlugin(new AbstractMarkwonPlugin() {
|
||||
@Override
|
||||
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
|
||||
builder
|
||||
.codeTextColor(tinyDb.getInt("codeBlockColor"))
|
||||
.codeBackgroundColor(tinyDb.getInt("codeBlockBackground"))
|
||||
.linkColor(context.getResources().getColor(R.color.lightBlue));
|
||||
}
|
||||
})
|
||||
.usePlugin(TablePlugin.create(context))
|
||||
.usePlugin(TaskListPlugin.create(context))
|
||||
.usePlugin(HtmlPlugin.create())
|
||||
.usePlugin(GifPlugin.create())
|
||||
.usePlugin(StrikethroughPlugin.create())
|
||||
.build();
|
||||
|
||||
if (!issuesModel.getUser().getFull_name().equals("")) {
|
||||
issueAssigneeAvatar.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueCreator) + issuesModel.getUser().getFull_name(), context));
|
||||
} else {
|
||||
issueAssigneeAvatar.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueCreator) + issuesModel.getUser().getLogin(), context));
|
||||
}
|
||||
|
||||
if (issuesModel.getUser().getAvatar_url() != null) {
|
||||
Picasso.get().load(issuesModel.getUser().getAvatar_url()).transform(new RoundedTransformation(100, 0)).resize(200, 200).centerCrop().into(issueAssigneeAvatar);
|
||||
} else {
|
||||
Picasso.get().load(issuesModel.getUser().getAvatar_url()).transform(new RoundedTransformation(100, 0)).resize(200, 200).centerCrop().into(issueAssigneeAvatar);
|
||||
}
|
||||
|
||||
if (issuesModel.getPull_request() == null) {
|
||||
issueType.setImageResource(R.drawable.ic_issues);
|
||||
issueType.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueTypeIssue), context));
|
||||
} else {
|
||||
issueType.setImageResource(R.drawable.ic_merge);
|
||||
issueType.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueTypePullRequest), context));
|
||||
}
|
||||
|
||||
issueTitle.setText(context.getResources().getString(R.string.hash) + issuesModel.getNumber() + " " + issuesModel.getTitle());
|
||||
issueNumber.setText(String.valueOf(issuesModel.getNumber()));
|
||||
issueCommentsCount.setText(String.valueOf(issuesModel.getComments()));
|
||||
|
||||
if (!issuesModel.getBody().equals("")) {
|
||||
String cleanIssueDescription = issuesModel.getBody().trim();
|
||||
issueDescription.setVisibility(View.VISIBLE);
|
||||
final CharSequence bodyWithMD = markwon.toMarkdown(EmojiParser.parseToUnicode(cleanIssueDescription));
|
||||
issueDescription.setText(UserMentions.UserMentionsFunc(context, bodyWithMD, cleanIssueDescription));
|
||||
}
|
||||
else {
|
||||
issueDescription.setText("");
|
||||
issueDescription.setVisibility(View.GONE);
|
||||
}
|
||||
/*if (issuesModel.getState().equals("open")) {
|
||||
issueState.setImageResource(R.drawable.ic_issue_open);
|
||||
issueState.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueStatusTextOpen), context));
|
||||
} else {
|
||||
issueState.setImageResource(R.drawable.ic_issue_closed);
|
||||
issueState.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueStatusTextClosed), context));
|
||||
}*/
|
||||
|
||||
switch (timeFormat) {
|
||||
case "pretty": {
|
||||
PrettyTime prettyTime = new PrettyTime(new Locale(locale));
|
||||
String createdTime = prettyTime.format(issuesModel.getCreated_at());
|
||||
issueCreatedTime.setText(createdTime);
|
||||
issueCreatedTime.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(issuesModel.getCreated_at()), context));
|
||||
break;
|
||||
}
|
||||
case "normal": {
|
||||
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale));
|
||||
String createdTime = formatter.format(issuesModel.getCreated_at());
|
||||
issueCreatedTime.setText(createdTime);
|
||||
break;
|
||||
}
|
||||
case "normal1": {
|
||||
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale));
|
||||
String createdTime = formatter.format(issuesModel.getCreated_at());
|
||||
issueCreatedTime.setText(createdTime);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoadHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
LoadHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
||||
|
||||
isMoreDataAvailable = moreDataAvailable;
|
||||
|
||||
}
|
||||
|
||||
public void notifyDataChanged() {
|
||||
|
||||
notifyDataSetChanged();
|
||||
isLoading = false;
|
||||
|
||||
}
|
||||
|
||||
public interface OnLoadMoreListener {
|
||||
|
||||
void onLoadMore();
|
||||
|
||||
}
|
||||
|
||||
public void setLoadMoreListener(OnLoadMoreListener loadMoreListener) {
|
||||
|
||||
this.loadMoreListener = loadMoreListener;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return issuesFilter;
|
||||
}
|
||||
|
||||
private Filter issuesFilter = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
List<Issues> filteredList = new ArrayList<>();
|
||||
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
filteredList.addAll(issuesList);
|
||||
} else {
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
|
||||
for (Issues item : issuesList) {
|
||||
if (item.getTitle().toLowerCase().contains(filterPattern) || item.getBody().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
issuesList.clear();
|
||||
issuesList.addAll((List) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
177
app/src/main/java/org/mian/gitnex/adapters/LabelsAdapter.java
Normal file
177
app/src/main/java/org/mian/gitnex/adapters/LabelsAdapter.java
Normal file
@@ -0,0 +1,177 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.CreateLabelActivity;
|
||||
import org.mian.gitnex.helpers.AlertDialogs;
|
||||
import org.mian.gitnex.helpers.ColorInverter;
|
||||
import org.mian.gitnex.helpers.LabelWidthCalculator;
|
||||
import org.mian.gitnex.models.Labels;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsViewHolder> {
|
||||
|
||||
private List<Labels> labelsList;
|
||||
final private Context mCtx;
|
||||
private ArrayList<Integer> labelsArray = new ArrayList<>();
|
||||
|
||||
static class LabelsViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView labelTitle;
|
||||
private TextView labelId;
|
||||
private TextView labelColor;
|
||||
private ImageView labelsView;
|
||||
private ImageView labelsOptionsMenu;
|
||||
|
||||
private LabelsViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
labelsView = itemView.findViewById(R.id.labelsView);
|
||||
labelsOptionsMenu = itemView.findViewById(R.id.labelsOptionsMenu);
|
||||
labelTitle = itemView.findViewById(R.id.labelTitle);
|
||||
labelId = itemView.findViewById(R.id.labelId);
|
||||
labelColor = itemView.findViewById(R.id.labelColor);
|
||||
|
||||
labelsOptionsMenu.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
final Context context = v.getContext();
|
||||
Context context_ = new ContextThemeWrapper(context, R.style.popupMenuStyle);
|
||||
|
||||
PopupMenu popupMenu = new PopupMenu(context_, v);
|
||||
popupMenu.inflate(R.menu.labels_menu);
|
||||
|
||||
Object menuHelper;
|
||||
Class[] argTypes;
|
||||
try {
|
||||
|
||||
Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup");
|
||||
fMenuHelper.setAccessible(true);
|
||||
menuHelper = fMenuHelper.get(popupMenu);
|
||||
argTypes = new Class[] { boolean.class };
|
||||
menuHelper.getClass().getDeclaredMethod("setForceShowIcon",
|
||||
argTypes).invoke(menuHelper, true);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
popupMenu.show();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.labelMenuEdit:
|
||||
|
||||
Intent intent = new Intent(context, CreateLabelActivity.class);
|
||||
intent.putExtra("labelId", labelId.getText());
|
||||
intent.putExtra("labelTitle", labelTitle.getText());
|
||||
intent.putExtra("labelColor", labelColor.getText());
|
||||
intent.putExtra("labelAction", "edit");
|
||||
context.startActivity(intent);
|
||||
break;
|
||||
|
||||
case R.id.labelMenuDelete:
|
||||
|
||||
AlertDialogs.labelDeleteDialog(context, labelTitle.getText().toString(), labelId.getText().toString(),
|
||||
context.getResources().getString(R.string.labelDeleteTitle),
|
||||
context.getResources().getString(R.string.labelDeleteMessage),
|
||||
context.getResources().getString(R.string.labelDeletePositiveButton),
|
||||
context.getResources().getString(R.string.labelDeleteNegativeButton));
|
||||
break;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
popupMenu.show();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public LabelsAdapter(Context mCtx, List<Labels> labelsMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.labelsList = labelsMain;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public LabelsAdapter.LabelsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.labels_list, parent, false);
|
||||
return new LabelsAdapter.LabelsViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull LabelsAdapter.LabelsViewHolder holder, int position) {
|
||||
|
||||
Labels currentItem = labelsList.get(position);
|
||||
int width = 33;
|
||||
|
||||
holder.labelTitle.setText(currentItem.getName());
|
||||
holder.labelId.setText(String.valueOf(currentItem.getId()));
|
||||
holder.labelColor.setText(currentItem.getColor());
|
||||
|
||||
String labelColor = currentItem.getColor();
|
||||
String labelName = currentItem.getName();
|
||||
int color = Color.parseColor("#" + labelColor);
|
||||
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
//.useFont(Typeface.DEFAULT)
|
||||
.textColor(new ColorInverter().getContrastColor(color))
|
||||
.fontSize(36)
|
||||
.width(LabelWidthCalculator.customWidth(getMaxLabelLength()))
|
||||
.height(60)
|
||||
.endConfig()
|
||||
.buildRoundRect(labelName, color, 8);
|
||||
holder.labelsView.setImageDrawable(drawable);
|
||||
|
||||
}
|
||||
|
||||
private int getMaxLabelLength() {
|
||||
|
||||
for(int i = 0; i < labelsList.size(); i++) {
|
||||
|
||||
Labels labelItem = labelsList.get(i);
|
||||
labelsArray.add(labelItem.getName().length());
|
||||
|
||||
}
|
||||
|
||||
return Collections.max(labelsArray);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return labelsList.size();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.models.UserInfo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class MembersByOrgAdapter extends BaseAdapter implements Filterable {
|
||||
|
||||
private List<UserInfo> membersList;
|
||||
private Context mCtx;
|
||||
private List<UserInfo> membersListFull;
|
||||
|
||||
private class ViewHolder {
|
||||
|
||||
private ImageView memberAvatar;
|
||||
private TextView memberName;
|
||||
|
||||
ViewHolder(View v) {
|
||||
memberAvatar = v.findViewById(R.id.memberAvatar);
|
||||
memberName = v.findViewById(R.id.memberName);
|
||||
}
|
||||
}
|
||||
|
||||
public MembersByOrgAdapter(Context mCtx, List<UserInfo> membersListMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.membersList = membersListMain;
|
||||
membersListFull = new ArrayList<>(membersList);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return membersList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
@Override
|
||||
public View getView(int position, View finalView, ViewGroup parent) {
|
||||
|
||||
MembersByOrgAdapter.ViewHolder viewHolder = null;
|
||||
|
||||
if (finalView == null) {
|
||||
finalView = LayoutInflater.from(mCtx).inflate(R.layout.members_by_org_list, null);
|
||||
viewHolder = new MembersByOrgAdapter.ViewHolder(finalView);
|
||||
finalView.setTag(viewHolder);
|
||||
}
|
||||
else {
|
||||
viewHolder = (MembersByOrgAdapter.ViewHolder) finalView.getTag();
|
||||
}
|
||||
|
||||
initData(viewHolder, position);
|
||||
return finalView;
|
||||
|
||||
}
|
||||
|
||||
private void initData(MembersByOrgAdapter.ViewHolder viewHolder, int position) {
|
||||
|
||||
UserInfo currentItem = membersList.get(position);
|
||||
Picasso.get().load(currentItem.getAvatar()).transform(new RoundedTransformation(100, 0)).resize(200, 200).centerCrop().into(viewHolder.memberAvatar);
|
||||
|
||||
if(!currentItem.getFullname().equals("")) {
|
||||
viewHolder.memberName.setText(currentItem.getFullname());
|
||||
}
|
||||
else {
|
||||
viewHolder.memberName.setText(currentItem.getLogin());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return membersFilter;
|
||||
}
|
||||
|
||||
private Filter membersFilter = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
List<UserInfo> filteredList = new ArrayList<>();
|
||||
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
filteredList.addAll(membersListFull);
|
||||
} else {
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
|
||||
for (UserInfo item : membersListFull) {
|
||||
if (item.getFullname().toLowerCase().contains(filterPattern) || item.getLogin().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
membersList.clear();
|
||||
membersList.addAll((List) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.vdurmont.emoji.EmojiParser;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.ClickListener;
|
||||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.models.Milestones;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import okhttp3.OkHttpClient;
|
||||
import ru.noties.markwon.AbstractMarkwonPlugin;
|
||||
import ru.noties.markwon.Markwon;
|
||||
import ru.noties.markwon.core.CorePlugin;
|
||||
import ru.noties.markwon.core.MarkwonTheme;
|
||||
import ru.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
||||
import ru.noties.markwon.ext.tables.TablePlugin;
|
||||
import ru.noties.markwon.ext.tables.TableTheme;
|
||||
import ru.noties.markwon.ext.tasklist.TaskListPlugin;
|
||||
import ru.noties.markwon.html.HtmlPlugin;
|
||||
import ru.noties.markwon.image.ImagesPlugin;
|
||||
import ru.noties.markwon.image.gif.GifPlugin;
|
||||
import ru.noties.markwon.image.okhttp.OkHttpImagesPlugin;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class MilestonesAdapter extends RecyclerView.Adapter<MilestonesAdapter.MilestonesViewHolder> implements Filterable {
|
||||
|
||||
private List<Milestones> milestonesList;
|
||||
private Context mCtx;
|
||||
private List<Milestones> milestonesListFull;
|
||||
|
||||
static class MilestonesViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView msTitle;
|
||||
private TextView msDescription;
|
||||
private TextView msOpenIssues;
|
||||
private TextView msClosedIssues;
|
||||
private TextView msDueDate;
|
||||
private ImageView msStatus;
|
||||
|
||||
private MilestonesViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
msTitle = itemView.findViewById(R.id.milestoneTitle);
|
||||
msStatus = itemView.findViewById(R.id.milestoneState);
|
||||
msDescription = itemView.findViewById(R.id.milestoneDescription);
|
||||
msOpenIssues = itemView.findViewById(R.id.milestoneIssuesOpen);
|
||||
msClosedIssues = itemView.findViewById(R.id.milestoneIssuesClosed);
|
||||
msDueDate = itemView.findViewById(R.id.milestoneDueDate);
|
||||
|
||||
/*issueTitle.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Context context = v.getContext();
|
||||
Log.i("issueNumber", issueNumber.getText().toString());
|
||||
|
||||
Intent intent = new Intent(context, IssueDetailActivity.class);
|
||||
intent.putExtra("issueNumber", issueNumber.getText());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putString("issueNumber", issueNumber.getText().toString());
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
});*/
|
||||
}
|
||||
}
|
||||
|
||||
public MilestonesAdapter(Context mCtx, List<Milestones> milestonesMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.milestonesList = milestonesMain;
|
||||
milestonesListFull = new ArrayList<>(milestonesList);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MilestonesAdapter.MilestonesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.milestones_list, parent, false);
|
||||
return new MilestonesAdapter.MilestonesViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MilestonesAdapter.MilestonesViewHolder holder, int position) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(mCtx);
|
||||
final String locale = tinyDb.getString("locale");
|
||||
final String timeFormat = tinyDb.getString("dateFormat");
|
||||
|
||||
Milestones currentItem = milestonesList.get(position);
|
||||
|
||||
final Markwon markwon = Markwon.builder(Objects.requireNonNull(mCtx))
|
||||
.usePlugin(CorePlugin.create())
|
||||
.usePlugin(OkHttpImagesPlugin.create(new OkHttpClient()))
|
||||
.usePlugin(ImagesPlugin.createWithAssets(mCtx))
|
||||
.usePlugin(new AbstractMarkwonPlugin() {
|
||||
@Override
|
||||
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
|
||||
builder
|
||||
.codeTextColor(tinyDb.getInt("codeBlockColor"))
|
||||
.codeBackgroundColor(tinyDb.getInt("codeBlockBackground"))
|
||||
.linkColor(mCtx.getResources().getColor(R.color.lightBlue));
|
||||
}
|
||||
})
|
||||
.usePlugin(TablePlugin.create(mCtx))
|
||||
.usePlugin(TaskListPlugin.create(mCtx))
|
||||
.usePlugin(HtmlPlugin.create())
|
||||
.usePlugin(GifPlugin.create())
|
||||
.usePlugin(StrikethroughPlugin.create())
|
||||
.build();
|
||||
|
||||
holder.msTitle.setText(currentItem.getTitle());
|
||||
//holder.msStatus.setText(currentItem.getState());
|
||||
|
||||
if(currentItem.getState().equals("open")) {
|
||||
|
||||
@SuppressLint("ResourceType") int color = Color.parseColor(mCtx.getResources().getString(R.color.releaseStable));
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
//.useFont(Typeface.DEFAULT)
|
||||
.textColor(mCtx.getResources().getColor(R.color.white))
|
||||
.fontSize(30)
|
||||
.toUpperCase()
|
||||
.width(120)
|
||||
.height(60)
|
||||
.endConfig()
|
||||
.buildRoundRect("open", color, 8);
|
||||
|
||||
holder.msStatus.setImageDrawable(drawable);
|
||||
|
||||
}
|
||||
else if(currentItem.getState().equals("closed")) {
|
||||
|
||||
@SuppressLint("ResourceType") int color = Color.parseColor(mCtx.getResources().getString(R.color.colorRed));
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
//.useFont(Typeface.DEFAULT)
|
||||
.textColor(mCtx.getResources().getColor(R.color.white))
|
||||
.fontSize(30)
|
||||
.toUpperCase()
|
||||
.width(140)
|
||||
.height(60)
|
||||
.endConfig()
|
||||
.buildRoundRect("closed", color, 8);
|
||||
|
||||
holder.msStatus.setImageDrawable(drawable);
|
||||
|
||||
}
|
||||
|
||||
if (!currentItem.getDescription().equals("")) {
|
||||
final CharSequence bodyWithMD = markwon.toMarkdown(EmojiParser.parseToUnicode(currentItem.getDescription()));
|
||||
holder.msDescription.setText(bodyWithMD);
|
||||
}
|
||||
else {
|
||||
holder.msDescription.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
holder.msOpenIssues.setText(String.valueOf(currentItem.getOpen_issues()));
|
||||
holder.msOpenIssues.setOnClickListener(new ClickListener(mCtx.getResources().getString(R.string.milestoneOpenIssues, currentItem.getOpen_issues()), mCtx));
|
||||
|
||||
holder.msClosedIssues.setText(String.valueOf(currentItem.getClosed_issues()));
|
||||
holder.msClosedIssues.setOnClickListener(new ClickListener(mCtx.getResources().getString(R.string.milestoneClosedIssues, currentItem.getClosed_issues()), mCtx));
|
||||
|
||||
if(currentItem.getDue_on() != null) {
|
||||
|
||||
if (timeFormat.equals("normal") || timeFormat.equals("pretty")) {
|
||||
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", new Locale(locale));
|
||||
Date date = null;
|
||||
try {
|
||||
date = formatter.parse(currentItem.getDue_on());
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String dueDate = formatter.format(date);
|
||||
assert date != null;
|
||||
if(date.before(new Date())) {
|
||||
holder.msDueDate.setTextColor(mCtx.getResources().getColor(R.color.darkRed));
|
||||
}
|
||||
|
||||
holder.msDueDate.setText(dueDate);
|
||||
holder.msDueDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToast(currentItem.getDue_on()), mCtx));
|
||||
|
||||
} else if (timeFormat.equals("normal1")) {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", new Locale(locale));
|
||||
Date date1 = null;
|
||||
try {
|
||||
date1 = formatter.parse(currentItem.getDue_on());
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String dueDate = formatter.format(date1);
|
||||
holder.msDueDate.setText(dueDate);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
holder.msDueDate.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return milestonesList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return milestoneFilter;
|
||||
}
|
||||
|
||||
private Filter milestoneFilter = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
List<Milestones> filteredList = new ArrayList<>();
|
||||
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
filteredList.addAll(milestonesListFull);
|
||||
} else {
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
|
||||
for (Milestones item : milestonesListFull) {
|
||||
if (item.getTitle().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
milestonesList.clear();
|
||||
milestonesList.addAll((List) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.TextAppearanceSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.MultiSelectDialog;
|
||||
import org.mian.gitnex.models.MultiSelectModel;
|
||||
import java.util.ArrayList;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.AppCompatCheckBox;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Author com.github.abumoallim, modified by M M Arif
|
||||
*/
|
||||
|
||||
public class MutliSelectAdapter extends RecyclerView.Adapter<MutliSelectAdapter.MultiSelectDialogViewHolder> {
|
||||
|
||||
private ArrayList<MultiSelectModel> mDataSet;
|
||||
private String mSearchQuery = "";
|
||||
private Context mContext;
|
||||
|
||||
public MutliSelectAdapter(ArrayList<MultiSelectModel> dataSet, Context context) {
|
||||
this.mDataSet = dataSet;
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MultiSelectDialogViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.multi_select_item, parent, false);
|
||||
return new MultiSelectDialogViewHolder(view);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final MultiSelectDialogViewHolder holder, int position) {
|
||||
|
||||
if (!mSearchQuery.equals("") && mSearchQuery.length() > 1) {
|
||||
setHighlightedText(position, holder.dialog_name_item);
|
||||
} else {
|
||||
holder.dialog_name_item.setText(mDataSet.get(position).getName());
|
||||
}
|
||||
|
||||
if (mDataSet.get(position).getSelected()) {
|
||||
|
||||
if (!MultiSelectDialog.selectedIdsForCallback.contains(mDataSet.get(position).getId())) {
|
||||
MultiSelectDialog.selectedIdsForCallback.add(mDataSet.get(position).getId());
|
||||
}
|
||||
}
|
||||
|
||||
if (checkForSelection(mDataSet.get(position).getId())) {
|
||||
holder.dialog_item_checkbox.setChecked(true);
|
||||
} else {
|
||||
holder.dialog_item_checkbox.setChecked(false);
|
||||
}
|
||||
|
||||
/*holder.dialog_item_checkbox.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (holder.dialog_item_checkbox.isChecked()) {
|
||||
MultiSelectDialog.selectedIdsForCallback.add(mDataSet.get(holder.getAdapterPosition()).getId());
|
||||
holder.dialog_item_checkbox.setChecked(true);
|
||||
} else {
|
||||
removeFromSelection(mDataSet.get(holder.getAdapterPosition()).getId());
|
||||
holder.dialog_item_checkbox.setChecked(false);
|
||||
}
|
||||
}
|
||||
});*/
|
||||
|
||||
holder.main_container.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (!holder.dialog_item_checkbox.isChecked()) {
|
||||
MultiSelectDialog.selectedIdsForCallback.add(mDataSet.get(holder.getAdapterPosition()).getId());
|
||||
holder.dialog_item_checkbox.setChecked(true);
|
||||
mDataSet.get(holder.getAdapterPosition()).setSelected(true);
|
||||
notifyItemChanged(holder.getAdapterPosition());
|
||||
} else {
|
||||
removeFromSelection(mDataSet.get(holder.getAdapterPosition()).getId());
|
||||
holder.dialog_item_checkbox.setChecked(false);
|
||||
mDataSet.get(holder.getAdapterPosition()).setSelected(false);
|
||||
notifyItemChanged(holder.getAdapterPosition());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void setHighlightedText(int position, TextView textview) {
|
||||
|
||||
String name = mDataSet.get(position).getName();
|
||||
SpannableString str = new SpannableString(name);
|
||||
int endLength = name.toLowerCase().indexOf(mSearchQuery) + mSearchQuery.length();
|
||||
ColorStateList highlightedColor = new ColorStateList(new int[][]{new int[]{}}, new int[]{ContextCompat.getColor(mContext, R.color.colorAccent)});
|
||||
TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(null, Typeface.NORMAL, -1, highlightedColor, null);
|
||||
str.setSpan(textAppearanceSpan, name.toLowerCase().indexOf(mSearchQuery), endLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
textview.setText(str);
|
||||
|
||||
}
|
||||
|
||||
private void removeFromSelection(Integer id) {
|
||||
|
||||
for (int i = 0; i < MultiSelectDialog.selectedIdsForCallback.size(); i++) {
|
||||
if (id.equals(MultiSelectDialog.selectedIdsForCallback.get(i))) {
|
||||
MultiSelectDialog.selectedIdsForCallback.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean checkForSelection(Integer id) {
|
||||
|
||||
for (int i = 0; i < MultiSelectDialog.selectedIdsForCallback.size(); i++) {
|
||||
if (id.equals(MultiSelectDialog.selectedIdsForCallback.get(i))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/*//get selected name string separated by coma
|
||||
public String getDataString() {
|
||||
String data = "";
|
||||
for (int i = 0; i < mDataSet.size(); i++) {
|
||||
if (checkForSelection(mDataSet.get(i).getId())) {
|
||||
data = data + ", " + mDataSet.get(i).getName();
|
||||
}
|
||||
}
|
||||
if (data.length() > 0) {
|
||||
return data.substring(1);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
//get selected name ararylist
|
||||
public ArrayList<String> getSelectedNameList() {
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
for (int i = 0; i < mDataSet.size(); i++) {
|
||||
if (checkForSelection(mDataSet.get(i).getId())) {
|
||||
names.add(mDataSet.get(i).getName());
|
||||
}
|
||||
}
|
||||
// return names.toArray(new String[names.size()]);
|
||||
return names;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDataSet.size();
|
||||
}
|
||||
|
||||
public void setData(ArrayList<MultiSelectModel> data, String query, MutliSelectAdapter mutliSelectAdapter) {
|
||||
|
||||
this.mDataSet = data;
|
||||
this.mSearchQuery = query;
|
||||
mutliSelectAdapter.notifyDataSetChanged();
|
||||
|
||||
}
|
||||
|
||||
class MultiSelectDialogViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView dialog_name_item;
|
||||
private AppCompatCheckBox dialog_item_checkbox;
|
||||
private LinearLayout main_container;
|
||||
|
||||
MultiSelectDialogViewHolder(View view) {
|
||||
|
||||
super(view);
|
||||
dialog_name_item = view.findViewById(R.id.dialog_item_name);
|
||||
dialog_item_checkbox = view.findViewById(R.id.dialog_item_checkbox);
|
||||
main_container = view.findViewById(R.id.main_container);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.RepoDetailActivity;
|
||||
import org.mian.gitnex.models.UserRepositories;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class MyReposListAdapter extends RecyclerView.Adapter<MyReposListAdapter.MyReposViewHolder> implements Filterable {
|
||||
|
||||
private List<UserRepositories> reposList;
|
||||
private Context mCtx;
|
||||
private List<UserRepositories> reposListFull;
|
||||
|
||||
static class MyReposViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView imageMy;
|
||||
private TextView mTextView1My;
|
||||
private TextView mTextView2My;
|
||||
private TextView fullNameMy;
|
||||
private ImageView repoPrivatePublicMy;
|
||||
private TextView repoStarsMy;
|
||||
private TextView repoWatchersMy;
|
||||
private TextView repoOpenIssuesCountMy;
|
||||
|
||||
private MyReposViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mTextView1My = itemView.findViewById(R.id.repoNameMy);
|
||||
mTextView2My = itemView.findViewById(R.id.repoDescriptionMy);
|
||||
imageMy = itemView.findViewById(R.id.imageAvatarMy);
|
||||
fullNameMy = itemView.findViewById(R.id.repoFullNameMy);
|
||||
repoPrivatePublicMy = itemView.findViewById(R.id.imageRepoTypeMy);
|
||||
repoStarsMy = itemView.findViewById(R.id.repoStarsMy);
|
||||
repoWatchersMy = itemView.findViewById(R.id.repoWatchersMy);
|
||||
repoOpenIssuesCountMy = itemView.findViewById(R.id.repoOpenIssuesCountMy);
|
||||
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Context context = v.getContext();
|
||||
|
||||
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||
intent.putExtra("repoFullName", fullNameMy.getText().toString());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putString("repoFullName", fullNameMy.getText().toString());
|
||||
tinyDb.putBoolean("resumeIssues", true);
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public MyReposListAdapter(Context mCtx, List<UserRepositories> reposListMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.reposList = reposListMain;
|
||||
reposListFull = new ArrayList<>(reposList);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MyReposListAdapter.MyReposViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.my_repos_list, parent, false);
|
||||
return new MyReposListAdapter.MyReposViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MyReposListAdapter.MyReposViewHolder holder, int position) {
|
||||
|
||||
UserRepositories currentItem = reposList.get(position);
|
||||
holder.mTextView2My.setVisibility(View.GONE);
|
||||
|
||||
ColorGenerator generator = ColorGenerator.MATERIAL;
|
||||
int color = generator.getColor(currentItem.getName());
|
||||
String charac = String.valueOf(currentItem.getName().charAt(0));
|
||||
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.useFont(Typeface.DEFAULT)
|
||||
.fontSize(16)
|
||||
.toUpperCase()
|
||||
.width(28)
|
||||
.height(28)
|
||||
.endConfig()
|
||||
.buildRound(charac, color);
|
||||
|
||||
holder.imageMy.setImageDrawable(drawable);
|
||||
holder.mTextView1My.setText(currentItem.getName());
|
||||
if (!currentItem.getDescription().equals("")) {
|
||||
holder.mTextView2My.setVisibility(View.VISIBLE);
|
||||
holder.mTextView2My.setText(currentItem.getDescription());
|
||||
}
|
||||
holder.fullNameMy.setText(currentItem.getFullname());
|
||||
if(currentItem.getPrivateFlag()) {
|
||||
holder.repoPrivatePublicMy.setImageResource(R.drawable.ic_lock_bold);
|
||||
}
|
||||
else {
|
||||
holder.repoPrivatePublicMy.setImageResource(R.drawable.ic_public);
|
||||
}
|
||||
holder.repoStarsMy.setText(currentItem.getStars_count());
|
||||
holder.repoWatchersMy.setText(currentItem.getWatchers_count());
|
||||
holder.repoOpenIssuesCountMy.setText(currentItem.getOpen_issues_count());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return reposList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return myReposFilter;
|
||||
}
|
||||
|
||||
private Filter myReposFilter = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
List<UserRepositories> filteredList = new ArrayList<>();
|
||||
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
filteredList.addAll(reposListFull);
|
||||
} else {
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
|
||||
for (UserRepositories item : reposListFull) {
|
||||
if (item.getFullname().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
reposList.clear();
|
||||
reposList.addAll((List) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.OrgDetailActivity;
|
||||
import org.mian.gitnex.models.UserOrganizations;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class OrganizationsListAdapter extends RecyclerView.Adapter<OrganizationsListAdapter.OrganizationsViewHolder> implements Filterable {
|
||||
|
||||
private List<UserOrganizations> orgList;
|
||||
private Context mCtx;
|
||||
private List<UserOrganizations> orgListFull;
|
||||
|
||||
static class OrganizationsViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView image;
|
||||
private TextView mTextView1;
|
||||
private TextView mTextView2;
|
||||
|
||||
private OrganizationsViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mTextView1 = itemView.findViewById(R.id.orgUsername);
|
||||
mTextView2 = itemView.findViewById(R.id.orgDescription);
|
||||
image = itemView.findViewById(R.id.imageAvatar);
|
||||
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Context context = v.getContext();
|
||||
Intent intent = new Intent(context, OrgDetailActivity.class);
|
||||
intent.putExtra("orgName", mTextView1.getText().toString());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putString("orgName", mTextView1.getText().toString());
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public OrganizationsListAdapter(Context mCtx, List<UserOrganizations> orgsListMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.orgList = orgsListMain;
|
||||
orgListFull = new ArrayList<>(orgList);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public OrganizationsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.organizations_list, parent, false);
|
||||
return new OrganizationsViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull OrganizationsViewHolder holder, int position) {
|
||||
|
||||
|
||||
UserOrganizations currentItem = orgList.get(position);
|
||||
holder.mTextView2.setVisibility(View.GONE);
|
||||
|
||||
Picasso.get().load(currentItem.getAvatar_url()).transform(new RoundedTransformation(100, 0)).resize(200, 200).centerCrop().into(holder.image);
|
||||
holder.mTextView1.setText(currentItem.getUsername());
|
||||
if (!currentItem.getDescription().equals("")) {
|
||||
holder.mTextView2.setVisibility(View.VISIBLE);
|
||||
holder.mTextView2.setText(currentItem.getDescription());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return orgList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return orgFilter;
|
||||
}
|
||||
|
||||
private Filter orgFilter = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
List<UserOrganizations> filteredList = new ArrayList<>();
|
||||
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
filteredList.addAll(orgListFull);
|
||||
} else {
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
|
||||
for (UserOrganizations item : orgListFull) {
|
||||
if (item.getUsername().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
orgList.clear();
|
||||
orgList.addAll((List) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.models.Emails;
|
||||
import java.util.List;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class ProfileEmailsAdapter extends RecyclerView.Adapter<ProfileEmailsAdapter.EmailsViewHolder> {
|
||||
|
||||
private List<Emails> emailsList;
|
||||
private Context mCtx;
|
||||
|
||||
static class EmailsViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView emailPrimary;
|
||||
private TextView userEmail;
|
||||
|
||||
private EmailsViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
emailPrimary = itemView.findViewById(R.id.emailPrimary);
|
||||
userEmail = itemView.findViewById(R.id.userEmail);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public ProfileEmailsAdapter(Context mCtx, List<Emails> emailsListMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.emailsList = emailsListMain;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ProfileEmailsAdapter.EmailsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.profile_emails_list, parent, false);
|
||||
return new ProfileEmailsAdapter.EmailsViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ProfileEmailsAdapter.EmailsViewHolder holder, int position) {
|
||||
|
||||
Emails currentItem = emailsList.get(position);
|
||||
|
||||
holder.userEmail.setText(currentItem.getEmail());
|
||||
|
||||
if(currentItem.getPrimary()) {
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.textColor(mCtx.getResources().getColor(R.color.white))
|
||||
.fontSize(36)
|
||||
.width(220)
|
||||
.height(60)
|
||||
.endConfig()
|
||||
.buildRoundRect(mCtx.getResources().getString(R.string.emailTypeText), mCtx.getResources().getColor(R.color.tooltipBackground), 8);
|
||||
holder.emailPrimary.setImageDrawable(drawable);
|
||||
}
|
||||
else {
|
||||
holder.emailPrimary.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return emailsList.size();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.models.UserInfo;
|
||||
import java.util.List;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class ProfileFollowersAdapter extends RecyclerView.Adapter<ProfileFollowersAdapter.FollowersViewHolder> {
|
||||
|
||||
private List<UserInfo> followersList;
|
||||
private Context mCtx;
|
||||
|
||||
static class FollowersViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView userAvatar;
|
||||
private TextView userFullName;
|
||||
private TextView userName;
|
||||
|
||||
private FollowersViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
userAvatar = itemView.findViewById(R.id.userAvatar);
|
||||
userFullName = itemView.findViewById(R.id.userFullName);
|
||||
userName = itemView.findViewById(R.id.userName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public ProfileFollowersAdapter(Context mCtx, List<UserInfo> followersListMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.followersList = followersListMain;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ProfileFollowersAdapter.FollowersViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.profile_followers_list, parent, false);
|
||||
return new ProfileFollowersAdapter.FollowersViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ProfileFollowersAdapter.FollowersViewHolder holder, int position) {
|
||||
|
||||
UserInfo currentItem = followersList.get(position);
|
||||
|
||||
if(!currentItem.getFullname().equals("")) {
|
||||
holder.userFullName.setText(currentItem.getFullname());
|
||||
holder.userName.setText(mCtx.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
||||
}
|
||||
else {
|
||||
holder.userFullName.setText(mCtx.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
||||
holder.userName.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
Picasso.get().load(currentItem.getAvatar()).transform(new RoundedTransformation(100, 0)).resize(140, 140).centerCrop().into(holder.userAvatar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return followersList.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.models.UserInfo;
|
||||
import java.util.List;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class ProfileFollowingAdapter extends RecyclerView.Adapter<ProfileFollowingAdapter.FollowingViewHolder> {
|
||||
|
||||
private List<UserInfo> followingList;
|
||||
private Context mCtx;
|
||||
|
||||
static class FollowingViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView userAvatar;
|
||||
private TextView userFullName;
|
||||
private TextView userName;
|
||||
|
||||
private FollowingViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
userAvatar = itemView.findViewById(R.id.userAvatar);
|
||||
userFullName = itemView.findViewById(R.id.userFullName);
|
||||
userName = itemView.findViewById(R.id.userName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public ProfileFollowingAdapter(Context mCtx, List<UserInfo> followingListMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.followingList = followingListMain;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ProfileFollowingAdapter.FollowingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.profile_following_list, parent, false);
|
||||
return new ProfileFollowingAdapter.FollowingViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ProfileFollowingAdapter.FollowingViewHolder holder, int position) {
|
||||
|
||||
UserInfo currentItem = followingList.get(position);
|
||||
|
||||
if(!currentItem.getFullname().equals("")) {
|
||||
holder.userFullName.setText(currentItem.getFullname());
|
||||
holder.userName.setText(mCtx.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
||||
}
|
||||
else {
|
||||
holder.userFullName.setText(mCtx.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
||||
holder.userName.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
Picasso.get().load(currentItem.getAvatar()).transform(new RoundedTransformation(100, 0)).resize(140, 140).centerCrop().into(holder.userAvatar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return followingList.size();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
152
app/src/main/java/org/mian/gitnex/adapters/ReleasesAdapter.java
Normal file
152
app/src/main/java/org/mian/gitnex/adapters/ReleasesAdapter.java
Normal file
@@ -0,0 +1,152 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.vdurmont.emoji.EmojiParser;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.models.Releases;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import okhttp3.OkHttpClient;
|
||||
import ru.noties.markwon.AbstractMarkwonPlugin;
|
||||
import ru.noties.markwon.Markwon;
|
||||
import ru.noties.markwon.core.CorePlugin;
|
||||
import ru.noties.markwon.core.MarkwonTheme;
|
||||
import ru.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
||||
import ru.noties.markwon.ext.tables.TablePlugin;
|
||||
import ru.noties.markwon.ext.tasklist.TaskListPlugin;
|
||||
import ru.noties.markwon.html.HtmlPlugin;
|
||||
import ru.noties.markwon.image.ImagesPlugin;
|
||||
import ru.noties.markwon.image.gif.GifPlugin;
|
||||
import ru.noties.markwon.image.okhttp.OkHttpImagesPlugin;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.ReleasesViewHolder> {
|
||||
|
||||
private List<Releases> releasesList;
|
||||
private Context mCtx;
|
||||
|
||||
static class ReleasesViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView releaseType;
|
||||
private TextView releaseTitle;
|
||||
private TextView releaseDescription;
|
||||
private TextView releaseDownload;
|
||||
private TextView releaseZipDownload;
|
||||
private TextView releaseTarDownload;
|
||||
private TextView releaseTag;
|
||||
|
||||
private ReleasesViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
releaseType = itemView.findViewById(R.id.releaseType);
|
||||
releaseTitle = itemView.findViewById(R.id.releaseTitle);
|
||||
releaseDescription = itemView.findViewById(R.id.releaseDescription);
|
||||
releaseZipDownload = itemView.findViewById(R.id.releaseZipDownload);
|
||||
releaseTarDownload = itemView.findViewById(R.id.releaseTarDownload);
|
||||
releaseTag = itemView.findViewById(R.id.releaseTag);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public ReleasesAdapter(Context mCtx, List<Releases> releasesMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.releasesList = releasesMain;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ReleasesAdapter.ReleasesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.releases_list, parent, false);
|
||||
return new ReleasesAdapter.ReleasesViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ReleasesAdapter.ReleasesViewHolder holder, int position) {
|
||||
|
||||
Releases currentItem = releasesList.get(position);
|
||||
|
||||
holder.releaseTitle.setText(currentItem.getName());
|
||||
|
||||
if(!currentItem.getTag_name().equals("")) {
|
||||
holder.releaseTag.setText(mCtx.getResources().getString(R.string.releaseTag, currentItem.getTag_name()));
|
||||
}
|
||||
else {
|
||||
holder.releaseTag.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(currentItem.isPrerelease()) {
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
//.useFont(Typeface.DEFAULT)
|
||||
.textColor(mCtx.getResources().getColor(R.color.white))
|
||||
.fontSize(34)
|
||||
.width(260)
|
||||
.height(60)
|
||||
.endConfig()
|
||||
.buildRoundRect(mCtx.getResources().getString(R.string.releaseTypePre), mCtx.getResources().getColor(R.color.releasePre), 8);
|
||||
holder.releaseType.setImageDrawable(drawable);
|
||||
}
|
||||
else {
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
//.useFont(Typeface.DEFAULT)
|
||||
.textColor(mCtx.getResources().getColor(R.color.white))
|
||||
.fontSize(34)
|
||||
.width(260)
|
||||
.height(60)
|
||||
.endConfig()
|
||||
.buildRoundRect(mCtx.getResources().getString(R.string.releaseTypeStable), mCtx.getResources().getColor(R.color.releaseStable), 8);
|
||||
holder.releaseType.setImageDrawable(drawable);
|
||||
}
|
||||
|
||||
final Markwon markwon = Markwon.builder(Objects.requireNonNull(mCtx))
|
||||
.usePlugin(CorePlugin.create())
|
||||
.usePlugin(OkHttpImagesPlugin.create(new OkHttpClient()))
|
||||
.usePlugin(ImagesPlugin.createWithAssets(mCtx))
|
||||
.usePlugin(new AbstractMarkwonPlugin() {
|
||||
@Override
|
||||
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
|
||||
builder
|
||||
.codeTextColor(Color.GREEN)
|
||||
.codeBackgroundColor(Color.BLACK)
|
||||
.linkColor(mCtx.getResources().getColor(R.color.lightBlue));
|
||||
}
|
||||
})
|
||||
.usePlugin(TablePlugin.create(mCtx))
|
||||
.usePlugin(TaskListPlugin.create(mCtx))
|
||||
.usePlugin(HtmlPlugin.create())
|
||||
.usePlugin(GifPlugin.create())
|
||||
.usePlugin(StrikethroughPlugin.create())
|
||||
.build();
|
||||
|
||||
final CharSequence bodyWithMD = markwon.toMarkdown(EmojiParser.parseToUnicode(currentItem.getBody()));
|
||||
|
||||
if(!currentItem.getBody().equals("")) {
|
||||
holder.releaseDescription.setText(bodyWithMD);
|
||||
}
|
||||
else {
|
||||
holder.releaseDescription.setVisibility(View.GONE);
|
||||
}
|
||||
holder.releaseZipDownload.setText(currentItem.getZipball_url());
|
||||
holder.releaseTarDownload.setText(currentItem.getTarball_url());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return releasesList.size();
|
||||
}
|
||||
|
||||
}
|
||||
169
app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java
Normal file
169
app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java
Normal file
@@ -0,0 +1,169 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.RepoDetailActivity;
|
||||
import org.mian.gitnex.models.UserRepositories;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.ReposViewHolder> implements Filterable {
|
||||
|
||||
private List<UserRepositories> reposList;
|
||||
private Context mCtx;
|
||||
private List<UserRepositories> reposListFull;
|
||||
|
||||
static class ReposViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView image;
|
||||
private TextView mTextView1;
|
||||
private TextView mTextView2;
|
||||
private TextView fullName;
|
||||
private ImageView repoPrivatePublic;
|
||||
private TextView repoStars;
|
||||
private TextView repoWatchers;
|
||||
private TextView repoOpenIssuesCount;
|
||||
|
||||
private ReposViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mTextView1 = itemView.findViewById(R.id.repoName);
|
||||
mTextView2 = itemView.findViewById(R.id.repoDescription);
|
||||
image = itemView.findViewById(R.id.imageAvatar);
|
||||
fullName = itemView.findViewById(R.id.repoFullName);
|
||||
repoPrivatePublic = itemView.findViewById(R.id.imageRepoType);
|
||||
repoStars = itemView.findViewById(R.id.repoStars);
|
||||
repoWatchers = itemView.findViewById(R.id.repoWatchers);
|
||||
repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount);
|
||||
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Context context = v.getContext();
|
||||
TextView repoFullName = (TextView) v.findViewById(R.id.repoFullName);
|
||||
|
||||
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||
intent.putExtra("repoFullName", repoFullName.getText().toString());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putString("repoFullName", repoFullName.getText().toString());
|
||||
tinyDb.putBoolean("resumeIssues", true);
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public ReposListAdapter(Context mCtx, List<UserRepositories> reposListMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.reposList = reposListMain;
|
||||
reposListFull = new ArrayList<>(reposList);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ReposViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.repos_list, parent, false);
|
||||
return new ReposViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ReposViewHolder holder, int position) {
|
||||
|
||||
UserRepositories currentItem = reposList.get(position);
|
||||
holder.mTextView2.setVisibility(View.GONE);
|
||||
|
||||
ColorGenerator generator = ColorGenerator.MATERIAL;
|
||||
int color = generator.getColor(currentItem.getName());
|
||||
String charac = String.valueOf(currentItem.getName().charAt(0));
|
||||
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.useFont(Typeface.DEFAULT)
|
||||
.fontSize(16)
|
||||
.toUpperCase()
|
||||
.width(28)
|
||||
.height(28)
|
||||
.endConfig()
|
||||
.buildRound(charac, color);
|
||||
|
||||
holder.image.setImageDrawable(drawable);
|
||||
holder.mTextView1.setText(currentItem.getName());
|
||||
if (!currentItem.getDescription().equals("")) {
|
||||
holder.mTextView2.setVisibility(View.VISIBLE);
|
||||
holder.mTextView2.setText(currentItem.getDescription());
|
||||
}
|
||||
holder.fullName.setText(currentItem.getFullname());
|
||||
if(currentItem.getPrivateFlag()) {
|
||||
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock_bold);
|
||||
}
|
||||
else {
|
||||
holder.repoPrivatePublic.setImageResource(R.drawable.ic_public);
|
||||
}
|
||||
holder.repoStars.setText(currentItem.getStars_count());
|
||||
holder.repoWatchers.setText(currentItem.getWatchers_count());
|
||||
holder.repoOpenIssuesCount.setText(currentItem.getOpen_issues_count());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return reposList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return reposFilter;
|
||||
}
|
||||
|
||||
private Filter reposFilter = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
List<UserRepositories> filteredList = new ArrayList<>();
|
||||
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
filteredList.addAll(reposListFull);
|
||||
} else {
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
|
||||
for (UserRepositories item : reposListFull) {
|
||||
if (item.getFullname().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
reposList.clear();
|
||||
reposList.addAll((List) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.RepoDetailActivity;
|
||||
import org.mian.gitnex.models.UserRepositories;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesByOrgAdapter.OrgReposViewHolder> implements Filterable {
|
||||
|
||||
private List<UserRepositories> reposList;
|
||||
private Context mCtx;
|
||||
private List<UserRepositories> reposListFull;
|
||||
|
||||
static class OrgReposViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView image;
|
||||
private TextView mTextView1;
|
||||
private TextView mTextView2;
|
||||
private TextView fullName;
|
||||
private ImageView repoPrivatePublic;
|
||||
private TextView repoStars;
|
||||
private TextView repoWatchers;
|
||||
private TextView repoOpenIssuesCount;
|
||||
|
||||
private OrgReposViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mTextView1 = itemView.findViewById(R.id.repoName);
|
||||
mTextView2 = itemView.findViewById(R.id.repoDescription);
|
||||
image = itemView.findViewById(R.id.imageAvatar);
|
||||
fullName = itemView.findViewById(R.id.repoFullName);
|
||||
repoPrivatePublic = itemView.findViewById(R.id.imageRepoType);
|
||||
repoStars = itemView.findViewById(R.id.repoStars);
|
||||
repoWatchers = itemView.findViewById(R.id.repoWatchers);
|
||||
repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount);
|
||||
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Context context = v.getContext();
|
||||
|
||||
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||
intent.putExtra("repoFullName", fullName.getText().toString());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putString("repoFullName", fullName.getText().toString());
|
||||
tinyDb.putBoolean("resumeIssues", true);
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public RepositoriesByOrgAdapter(Context mCtx, List<UserRepositories> reposListMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.reposList = reposListMain;
|
||||
reposListFull = new ArrayList<>(reposList);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RepositoriesByOrgAdapter.OrgReposViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.repositories_by_org_list, parent, false);
|
||||
return new RepositoriesByOrgAdapter.OrgReposViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RepositoriesByOrgAdapter.OrgReposViewHolder holder, int position) {
|
||||
|
||||
UserRepositories currentItem = reposList.get(position);
|
||||
holder.mTextView2.setVisibility(View.GONE);
|
||||
|
||||
ColorGenerator generator = ColorGenerator.MATERIAL;
|
||||
int color = generator.getColor(currentItem.getName());
|
||||
String charac = String.valueOf(currentItem.getName().charAt(0));
|
||||
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.useFont(Typeface.DEFAULT)
|
||||
.fontSize(16)
|
||||
.toUpperCase()
|
||||
.width(28)
|
||||
.height(28)
|
||||
.endConfig()
|
||||
.buildRound(charac, color);
|
||||
|
||||
holder.image.setImageDrawable(drawable);
|
||||
holder.mTextView1.setText(currentItem.getName());
|
||||
if (!currentItem.getDescription().equals("")) {
|
||||
holder.mTextView2.setVisibility(View.VISIBLE);
|
||||
holder.mTextView2.setText(currentItem.getDescription());
|
||||
}
|
||||
holder.fullName.setText(currentItem.getFullname());
|
||||
if(currentItem.getPrivateFlag()) {
|
||||
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock_bold);
|
||||
}
|
||||
else {
|
||||
holder.repoPrivatePublic.setImageResource(R.drawable.ic_public);
|
||||
}
|
||||
holder.repoStars.setText(currentItem.getStars_count());
|
||||
holder.repoWatchers.setText(currentItem.getWatchers_count());
|
||||
holder.repoOpenIssuesCount.setText(currentItem.getOpen_issues_count());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return reposList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return orgReposFilter;
|
||||
}
|
||||
|
||||
private Filter orgReposFilter = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
List<UserRepositories> filteredList = new ArrayList<>();
|
||||
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
filteredList.addAll(reposListFull);
|
||||
} else {
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
|
||||
for (UserRepositories item : reposListFull) {
|
||||
if (item.getFullname().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
reposList.clear();
|
||||
reposList.addAll((List) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.RepoDetailActivity;
|
||||
import org.mian.gitnex.models.UserRepositories;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposListAdapter.StarredReposViewHolder> implements Filterable {
|
||||
|
||||
private List<UserRepositories> reposList;
|
||||
private Context mCtx;
|
||||
private List<UserRepositories> reposListFull;
|
||||
|
||||
static class StarredReposViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView image;
|
||||
private TextView mTextView1;
|
||||
private TextView mTextView2;
|
||||
private TextView fullName;
|
||||
private ImageView repoPrivatePublic;
|
||||
private TextView repoStars;
|
||||
private TextView repoWatchers;
|
||||
private TextView repoOpenIssuesCount;
|
||||
|
||||
private StarredReposViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mTextView1 = itemView.findViewById(R.id.repoName);
|
||||
mTextView2 = itemView.findViewById(R.id.repoDescription);
|
||||
image = itemView.findViewById(R.id.imageAvatar);
|
||||
fullName = itemView.findViewById(R.id.repoFullName);
|
||||
repoPrivatePublic = itemView.findViewById(R.id.imageRepoType);
|
||||
repoStars = itemView.findViewById(R.id.repoStars);
|
||||
repoWatchers = itemView.findViewById(R.id.repoWatchers);
|
||||
repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount);
|
||||
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Context context = v.getContext();
|
||||
|
||||
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||
intent.putExtra("repoFullName", fullName.getText().toString());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putString("repoFullName", fullName.getText().toString());
|
||||
tinyDb.putBoolean("resumeIssues", true);
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public StarredReposListAdapter(Context mCtx, List<UserRepositories> reposListMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.reposList = reposListMain;
|
||||
reposListFull = new ArrayList<>(reposList);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public StarredReposListAdapter.StarredReposViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.starred_repos_list, parent, false);
|
||||
return new StarredReposListAdapter.StarredReposViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull StarredReposListAdapter.StarredReposViewHolder holder, int position) {
|
||||
|
||||
UserRepositories currentItem = reposList.get(position);
|
||||
holder.mTextView2.setVisibility(View.GONE);
|
||||
|
||||
ColorGenerator generator = ColorGenerator.MATERIAL;
|
||||
int color = generator.getColor(currentItem.getName());
|
||||
String charac = String.valueOf(currentItem.getName().charAt(0));
|
||||
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.useFont(Typeface.DEFAULT)
|
||||
.fontSize(16)
|
||||
.toUpperCase()
|
||||
.width(28)
|
||||
.height(28)
|
||||
.endConfig()
|
||||
.buildRound(charac, color);
|
||||
|
||||
holder.image.setImageDrawable(drawable);
|
||||
holder.mTextView1.setText(currentItem.getName());
|
||||
if (!currentItem.getDescription().equals("")) {
|
||||
holder.mTextView2.setVisibility(View.VISIBLE);
|
||||
holder.mTextView2.setText(currentItem.getDescription());
|
||||
}
|
||||
holder.fullName.setText(currentItem.getFullname());
|
||||
if(currentItem.getPrivateFlag()) {
|
||||
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock_bold);
|
||||
}
|
||||
else {
|
||||
holder.repoPrivatePublic.setImageResource(R.drawable.ic_public);
|
||||
}
|
||||
holder.repoStars.setText(currentItem.getStars_count());
|
||||
holder.repoWatchers.setText(currentItem.getWatchers_count());
|
||||
holder.repoOpenIssuesCount.setText(currentItem.getOpen_issues_count());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return reposList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return starredReposFilter;
|
||||
}
|
||||
|
||||
private Filter starredReposFilter = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
List<UserRepositories> filteredList = new ArrayList<>();
|
||||
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
filteredList.addAll(reposListFull);
|
||||
} else {
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
|
||||
for (UserRepositories item : reposListFull) {
|
||||
if (item.getFullname().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
reposList.clear();
|
||||
reposList.addAll((List) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.models.UserInfo;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class TeamMembersByOrgAdapter extends BaseAdapter {
|
||||
|
||||
private List<UserInfo> teamMembersList;
|
||||
private Context mCtx;
|
||||
|
||||
private class ViewHolder {
|
||||
|
||||
private ImageView memberAvatar;
|
||||
private TextView memberName;
|
||||
|
||||
ViewHolder(View v) {
|
||||
memberAvatar = v.findViewById(R.id.memberAvatar);
|
||||
memberName = v.findViewById(R.id.memberName);
|
||||
}
|
||||
}
|
||||
|
||||
public TeamMembersByOrgAdapter(Context mCtx, List<UserInfo> membersListMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.teamMembersList = membersListMain;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return teamMembersList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
@Override
|
||||
public View getView(int position, View finalView, ViewGroup parent) {
|
||||
|
||||
TeamMembersByOrgAdapter.ViewHolder viewHolder = null;
|
||||
|
||||
if (finalView == null) {
|
||||
finalView = LayoutInflater.from(mCtx).inflate(R.layout.members_by_team_by_org_list, null);
|
||||
viewHolder = new TeamMembersByOrgAdapter.ViewHolder(finalView);
|
||||
finalView.setTag(viewHolder);
|
||||
}
|
||||
else {
|
||||
viewHolder = (TeamMembersByOrgAdapter.ViewHolder) finalView.getTag();
|
||||
}
|
||||
|
||||
initData(viewHolder, position);
|
||||
return finalView;
|
||||
|
||||
}
|
||||
|
||||
private void initData(TeamMembersByOrgAdapter.ViewHolder viewHolder, int position) {
|
||||
|
||||
UserInfo currentItem = teamMembersList.get(position);
|
||||
Picasso.get().load(currentItem.getAvatar()).transform(new RoundedTransformation(100, 0)).resize(200, 200).centerCrop().into(viewHolder.memberAvatar);
|
||||
|
||||
if(!currentItem.getFullname().equals("")) {
|
||||
viewHolder.memberName.setText(currentItem.getFullname());
|
||||
}
|
||||
else {
|
||||
viewHolder.memberName.setText(currentItem.getLogin());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.TextView;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.OrgTeamMembersActivity;
|
||||
import org.mian.gitnex.models.Teams;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class TeamsByOrgAdapter extends RecyclerView.Adapter<TeamsByOrgAdapter.OrgTeamsViewHolder> implements Filterable {
|
||||
|
||||
private List<Teams> teamList;
|
||||
private Context mCtx;
|
||||
private List<Teams> teamListFull;
|
||||
|
||||
static class OrgTeamsViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView teamTitle;
|
||||
private TextView teamId;
|
||||
private TextView teamDescription;
|
||||
private TextView teamPermission;
|
||||
|
||||
private OrgTeamsViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
teamTitle = itemView.findViewById(R.id.teamTitle);
|
||||
teamId = itemView.findViewById(R.id.teamId);
|
||||
teamDescription = itemView.findViewById(R.id.teamDescription);
|
||||
teamPermission = itemView.findViewById(R.id.teamPermission);
|
||||
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Context context = v.getContext();
|
||||
|
||||
Intent intent = new Intent(context, OrgTeamMembersActivity.class);
|
||||
intent.putExtra("teamTitle", teamTitle.getText().toString());
|
||||
intent.putExtra("teamId", teamId.getText().toString());
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TeamsByOrgAdapter(Context mCtx, List<Teams> teamListMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.teamList = teamListMain;
|
||||
teamListFull = new ArrayList<>(teamList);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public TeamsByOrgAdapter.OrgTeamsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.teams_by_org_list, parent, false);
|
||||
return new TeamsByOrgAdapter.OrgTeamsViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull TeamsByOrgAdapter.OrgTeamsViewHolder holder, int position) {
|
||||
|
||||
Teams currentItem = teamList.get(position);
|
||||
holder.teamId.setText(String.valueOf(currentItem.getId()));
|
||||
holder.teamTitle.setText(currentItem.getName());
|
||||
if (!currentItem.getDescription().equals("")) {
|
||||
holder.teamDescription.setVisibility(View.VISIBLE);
|
||||
holder.teamDescription.setText(currentItem.getDescription());
|
||||
}
|
||||
else {
|
||||
holder.teamDescription.setVisibility(View.GONE);
|
||||
holder.teamDescription.setText("");
|
||||
}
|
||||
holder.teamPermission.setText(mCtx.getResources().getString(R.string.teamPermission, currentItem.getPermission()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return teamList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return orgTeamsFilter;
|
||||
}
|
||||
|
||||
private Filter orgTeamsFilter = new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
List<Teams> filteredList = new ArrayList<>();
|
||||
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
filteredList.addAll(teamListFull);
|
||||
} else {
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
|
||||
for (Teams item : teamListFull) {
|
||||
if (item.getName().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
teamList.clear();
|
||||
teamList.addAll((List) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.actions.CollaboratorActions;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.helpers.AlertDialogs;
|
||||
import org.mian.gitnex.helpers.Authorization;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.models.Collaborators;
|
||||
import org.mian.gitnex.models.UserInfo;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import java.util.List;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class UserSearchAdapter extends RecyclerView.Adapter<UserSearchAdapter.UserSearchViewHolder> {
|
||||
|
||||
private List<UserInfo> usersSearchList;
|
||||
private Context mCtx;
|
||||
|
||||
public UserSearchAdapter(List<UserInfo> dataList, Context mCtx) {
|
||||
this.mCtx = mCtx;
|
||||
this.usersSearchList = dataList;
|
||||
}
|
||||
|
||||
static class UserSearchViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView userAvatar;
|
||||
private TextView userFullName;
|
||||
private TextView userName;
|
||||
private TextView userNameMain;
|
||||
private ImageView addCollaboratorButtonAdd;
|
||||
private ImageView addCollaboratorButtonRemove;
|
||||
|
||||
private String[] permissionList = {"Read", "Write", "Admin"};
|
||||
final private int permissionSelectedChoice = 0;
|
||||
|
||||
private UserSearchViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
userAvatar = itemView.findViewById(R.id.userAvatar);
|
||||
userFullName = itemView.findViewById(R.id.userFullName);
|
||||
userName = itemView.findViewById(R.id.userName);
|
||||
userNameMain = itemView.findViewById(R.id.userNameMain);
|
||||
addCollaboratorButtonAdd = itemView.findViewById(R.id.addCollaboratorButtonAdd);
|
||||
addCollaboratorButtonRemove = itemView.findViewById(R.id.addCollaboratorButtonRemove);
|
||||
|
||||
addCollaboratorButtonAdd.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
final Context context = v.getContext();
|
||||
|
||||
AlertDialog.Builder pBuilder = new AlertDialog.Builder(context, R.style.confirmDialog);
|
||||
|
||||
pBuilder.setTitle(R.string.newTeamPermission);
|
||||
pBuilder.setSingleChoiceItems(permissionList, permissionSelectedChoice, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
|
||||
}
|
||||
})
|
||||
.setCancelable(false)
|
||||
.setNegativeButton(R.string.cancelButton, null)
|
||||
.setPositiveButton(R.string.addButton, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
ListView lw = ((AlertDialog)dialog).getListView();
|
||||
Object checkedItem = lw.getAdapter().getItem(lw.getCheckedItemPosition());
|
||||
|
||||
CollaboratorActions.addCollaborator(context, String.valueOf(checkedItem).toLowerCase(), userNameMain.getText().toString());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog pDialog = pBuilder.create();
|
||||
pDialog.show();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
addCollaboratorButtonRemove.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Context context = v.getContext();
|
||||
|
||||
AlertDialogs.collaboratorRemoveDialog(context, userNameMain.getText().toString(),
|
||||
context.getResources().getString(R.string.removeCollaboratorTitle),
|
||||
context.getResources().getString(R.string.removeCollaboratorMessage),
|
||||
context.getResources().getString(R.string.removeButton),
|
||||
context.getResources().getString(R.string.cancelButton), "fa");
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public UserSearchAdapter.UserSearchViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.collaborators_list_search, parent, false);
|
||||
return new UserSearchAdapter.UserSearchViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final UserSearchAdapter.UserSearchViewHolder holder, int position) {
|
||||
|
||||
final UserInfo currentItem = usersSearchList.get(position);
|
||||
|
||||
holder.userNameMain.setText(currentItem.getUsername());
|
||||
|
||||
if (!currentItem.getFullname().equals("")) {
|
||||
holder.userFullName.setText(currentItem.getFullname());
|
||||
holder.userName.setText(mCtx.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
||||
}
|
||||
else {
|
||||
holder.userFullName.setText(mCtx.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
||||
holder.userName.setText(mCtx.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
||||
}
|
||||
|
||||
if (!currentItem.getAvatar().equals("")) {
|
||||
Picasso.get().load(currentItem.getAvatar()).transform(new RoundedTransformation(100, 0)).resize(200, 200).centerCrop().into(holder.userAvatar);
|
||||
}
|
||||
|
||||
if(getItemCount() > 0) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(mCtx);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
Call<Collaborators> call = RetrofitClient
|
||||
.getInstance(instanceUrl)
|
||||
.getApiInterface()
|
||||
.checkRepoCollaborator(Authorization.returnAuthentication(mCtx, loginUid, instanceToken), repoOwner, repoName, currentItem.getUsername());
|
||||
|
||||
call.enqueue(new Callback<Collaborators>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<Collaborators> call, @NonNull Response<Collaborators> response) {
|
||||
|
||||
if(response.code() == 204) {
|
||||
if(!currentItem.getUsername().equals(loginUid) && !currentItem.getUsername().equals(repoOwner)) {
|
||||
holder.addCollaboratorButtonRemove.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
holder.addCollaboratorButtonRemove.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
else if(response.code() == 404) {
|
||||
if(!currentItem.getUsername().equals(loginUid) && !currentItem.getUsername().equals(repoOwner)) {
|
||||
holder.addCollaboratorButtonAdd.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
holder.addCollaboratorButtonAdd.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
holder.addCollaboratorButtonRemove.setVisibility(View.GONE);
|
||||
holder.addCollaboratorButtonAdd.setVisibility(View.GONE);
|
||||
Log.i("onResponse", String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<Collaborators> call, @NonNull Throwable t) {
|
||||
Log.i("onFailure", t.getMessage());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return usersSearchList.size();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user