Show ContributorsTab only if you have permission to (#402)
add isRepoAdmin extend Adapters add check to RepoDetails refactor var names reformat code Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: M M Arif <mmarif@swatian.com> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/402 Reviewed-by: M M Arif <mmarif@swatian.com>
This commit is contained in:
parent
ab47e409e9
commit
b8d8b34b0e
@ -125,6 +125,15 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
}
|
||||
}
|
||||
|
||||
// only show Collaborators if you have permission to
|
||||
final View collaboratorTab = vg.getChildAt(9);
|
||||
if (tinyDb.getBoolean("isRepoAdmin")) {
|
||||
collaboratorTab.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
collaboratorTab.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
|
||||
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
|
||||
|
||||
|
@ -7,6 +7,7 @@ import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
@ -21,7 +22,6 @@ import org.mian.gitnex.activities.RepoStargazersActivity;
|
||||
import org.mian.gitnex.activities.RepoWatchersActivity;
|
||||
import org.mian.gitnex.clients.PicassoService;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.helpers.AlertDialogs;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.models.UserRepositories;
|
||||
@ -38,207 +38,211 @@ import retrofit2.Callback;
|
||||
public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepositoriesAdapter.ReposSearchViewHolder> {
|
||||
|
||||
|
||||
private List<UserRepositories> searchedReposList;
|
||||
private Context mCtx;
|
||||
private List<UserRepositories> searchedReposList;
|
||||
private Context mCtx;
|
||||
|
||||
public ExploreRepositoriesAdapter(List<UserRepositories> dataList, Context mCtx) {
|
||||
this.mCtx = mCtx;
|
||||
this.searchedReposList = dataList;
|
||||
}
|
||||
public ExploreRepositoriesAdapter(List<UserRepositories> dataList, Context mCtx) {
|
||||
|
||||
static class ReposSearchViewHolder extends RecyclerView.ViewHolder {
|
||||
this.mCtx = mCtx;
|
||||
this.searchedReposList = dataList;
|
||||
}
|
||||
|
||||
private ImageView image;
|
||||
private TextView mTextView1;
|
||||
private TextView mTextView2;
|
||||
private TextView fullName;
|
||||
private ImageView repoPrivatePublic;
|
||||
private TextView repoStars;
|
||||
private TextView repoForks;
|
||||
private TextView repoOpenIssuesCount;
|
||||
static class ReposSearchViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ReposSearchViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
private ImageView image;
|
||||
private TextView repoName;
|
||||
private TextView repoDescription;
|
||||
private TextView fullName;
|
||||
private CheckBox isRepoAdmin;
|
||||
private ImageView repoPrivatePublic;
|
||||
private TextView repoStars;
|
||||
private TextView repoForks;
|
||||
private TextView repoOpenIssuesCount;
|
||||
|
||||
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);
|
||||
repoForks = itemView.findViewById(R.id.repoForks);
|
||||
repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount);
|
||||
ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu);
|
||||
private ReposSearchViewHolder(View itemView) {
|
||||
|
||||
itemView.setOnClickListener(v -> {
|
||||
super(itemView);
|
||||
|
||||
Context context = v.getContext();
|
||||
TextView repoFullName = v.findViewById(R.id.repoFullName);
|
||||
repoName = itemView.findViewById(R.id.repoName);
|
||||
repoDescription = itemView.findViewById(R.id.repoDescription);
|
||||
image = itemView.findViewById(R.id.imageAvatar);
|
||||
fullName = itemView.findViewById(R.id.repoFullName);
|
||||
isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin);
|
||||
repoPrivatePublic = itemView.findViewById(R.id.imageRepoType);
|
||||
repoStars = itemView.findViewById(R.id.repoStars);
|
||||
repoForks = itemView.findViewById(R.id.repoForks);
|
||||
repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount);
|
||||
ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu);
|
||||
|
||||
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||
intent.putExtra("repoFullName", repoFullName.getText().toString());
|
||||
itemView.setOnClickListener(v -> {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putString("repoFullName", repoFullName.getText().toString());
|
||||
tinyDb.putBoolean("resumeIssues", true);
|
||||
Context context = v.getContext();
|
||||
TextView repoFullName = v.findViewById(R.id.repoFullName);
|
||||
|
||||
//store if user is watching this repo
|
||||
{
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
String[] parts = repoFullName.getText().toString().split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
||||
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||
intent.putExtra("repoFullName", repoFullName.getText().toString());
|
||||
|
||||
WatchRepository watch = new WatchRepository();
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putString("repoFullName", repoFullName.getText().toString());
|
||||
tinyDb.putBoolean("resumeIssues", true);
|
||||
tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked());
|
||||
|
||||
Call<WatchRepository> call;
|
||||
//store if user is watching this repo
|
||||
{
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
String[] parts = repoFullName.getText().toString().split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
||||
|
||||
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
||||
WatchRepository watch = new WatchRepository();
|
||||
|
||||
call.enqueue(new Callback<WatchRepository>() {
|
||||
Call<WatchRepository> call;
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<WatchRepository> call, @NonNull retrofit2.Response<WatchRepository> response) {
|
||||
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
call.enqueue(new Callback<WatchRepository>() {
|
||||
|
||||
tinyDb.putBoolean("repoWatch", response.body().getSubscribed());
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<WatchRepository> call, @NonNull retrofit2.Response<WatchRepository> response) {
|
||||
|
||||
}
|
||||
else {
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
tinyDb.putBoolean("repoWatch", false);
|
||||
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
||||
tinyDb.putBoolean("repoWatch", response.body().getSubscribed());
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
tinyDb.putBoolean("repoWatch", false);
|
||||
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<WatchRepository> call, @NonNull Throwable t) {
|
||||
}
|
||||
|
||||
tinyDb.putBoolean("repoWatch", false);
|
||||
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<WatchRepository> call, @NonNull Throwable t) {
|
||||
|
||||
context.startActivity(intent);
|
||||
tinyDb.putBoolean("repoWatch", false);
|
||||
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
reposDropdownMenu.setOnClickListener(v -> {
|
||||
context.startActivity(intent);
|
||||
|
||||
final Context context = v.getContext();
|
||||
});
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null);
|
||||
reposDropdownMenu.setOnClickListener(v -> {
|
||||
|
||||
TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser);
|
||||
TextView repoStargazers = view.findViewById(R.id.repoStargazers);
|
||||
TextView repoWatchers = view.findViewById(R.id.repoWatchers);
|
||||
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
|
||||
final Context context = v.getContext();
|
||||
|
||||
bottomSheetHeader.setText(fullName.getText());
|
||||
BottomSheetDialog dialog = new BottomSheetDialog(context);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
@SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null);
|
||||
|
||||
repoOpenInBrowser.setOnClickListener(openInBrowser -> {
|
||||
TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser);
|
||||
TextView repoStargazers = view.findViewById(R.id.repoStargazers);
|
||||
TextView repoWatchers = view.findViewById(R.id.repoWatchers);
|
||||
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
|
||||
|
||||
Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class);
|
||||
intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText());
|
||||
context.startActivity(intentOpenInBrowser);
|
||||
dialog.dismiss();
|
||||
bottomSheetHeader.setText(fullName.getText());
|
||||
BottomSheetDialog dialog = new BottomSheetDialog(context);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
|
||||
});
|
||||
repoOpenInBrowser.setOnClickListener(openInBrowser -> {
|
||||
|
||||
repoStargazers.setOnClickListener(stargazers -> {
|
||||
Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class);
|
||||
intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText());
|
||||
context.startActivity(intentOpenInBrowser);
|
||||
dialog.dismiss();
|
||||
|
||||
Intent intent = new Intent(context, RepoStargazersActivity.class);
|
||||
intent.putExtra("repoFullNameForStars", fullName.getText());
|
||||
context.startActivity(intent);
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
});
|
||||
repoStargazers.setOnClickListener(stargazers -> {
|
||||
|
||||
repoWatchers.setOnClickListener(watchers -> {
|
||||
Intent intent = new Intent(context, RepoStargazersActivity.class);
|
||||
intent.putExtra("repoFullNameForStars", fullName.getText());
|
||||
context.startActivity(intent);
|
||||
dialog.dismiss();
|
||||
|
||||
Intent intentW = new Intent(context, RepoWatchersActivity.class);
|
||||
intentW.putExtra("repoFullNameForWatchers", fullName.getText());
|
||||
context.startActivity(intentW);
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
});
|
||||
repoWatchers.setOnClickListener(watchers -> {
|
||||
|
||||
});
|
||||
Intent intentW = new Intent(context, RepoWatchersActivity.class);
|
||||
intentW.putExtra("repoFullNameForWatchers", fullName.getText());
|
||||
context.startActivity(intentW);
|
||||
dialog.dismiss();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ExploreRepositoriesAdapter.ReposSearchViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_repos, parent, false);
|
||||
return new ExploreRepositoriesAdapter.ReposSearchViewHolder(v);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final ExploreRepositoriesAdapter.ReposSearchViewHolder holder, int position) {
|
||||
}
|
||||
|
||||
final UserRepositories currentItem = searchedReposList.get(position);
|
||||
@NonNull
|
||||
@Override
|
||||
public ExploreRepositoriesAdapter.ReposSearchViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_repos, parent, false);
|
||||
return new ExploreRepositoriesAdapter.ReposSearchViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final ExploreRepositoriesAdapter.ReposSearchViewHolder holder, int position) {
|
||||
|
||||
final UserRepositories currentItem = searchedReposList.get(position);
|
||||
|
||||
|
||||
holder.mTextView2.setVisibility(View.GONE);
|
||||
holder.repoDescription.setVisibility(View.GONE);
|
||||
|
||||
ColorGenerator generator = ColorGenerator.MATERIAL;
|
||||
int color = generator.getColor(currentItem.getName());
|
||||
String firstCharacter = String.valueOf(currentItem.getName().charAt(0));
|
||||
ColorGenerator generator = ColorGenerator.MATERIAL;
|
||||
int color = generator.getColor(currentItem.getName());
|
||||
String firstCharacter = String.valueOf(currentItem.getName().charAt(0));
|
||||
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.useFont(Typeface.DEFAULT)
|
||||
.fontSize(18)
|
||||
.toUpperCase()
|
||||
.width(28)
|
||||
.height(28)
|
||||
.endConfig()
|
||||
.buildRoundRect(firstCharacter, color, 3);
|
||||
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).fontSize(18).toUpperCase().width(28).height(28).endConfig().buildRoundRect(firstCharacter, color, 3);
|
||||
|
||||
if (currentItem.getAvatar_url() != null) {
|
||||
if (!currentItem.getAvatar_url().equals("")) {
|
||||
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.image);
|
||||
} else {
|
||||
holder.image.setImageDrawable(drawable);
|
||||
}
|
||||
}
|
||||
else {
|
||||
holder.image.setImageDrawable(drawable);
|
||||
}
|
||||
if(currentItem.getAvatar_url() != null) {
|
||||
if(!currentItem.getAvatar_url().equals("")) {
|
||||
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.image);
|
||||
}
|
||||
else {
|
||||
holder.image.setImageDrawable(drawable);
|
||||
}
|
||||
}
|
||||
else {
|
||||
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.repoForks.setText(currentItem.getForks_count());
|
||||
holder.repoOpenIssuesCount.setText(currentItem.getOpen_issues_count());
|
||||
holder.repoName.setText(currentItem.getName());
|
||||
if(!currentItem.getDescription().equals("")) {
|
||||
holder.repoDescription.setVisibility(View.VISIBLE);
|
||||
holder.repoDescription.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.repoForks.setText(currentItem.getForks_count());
|
||||
holder.repoOpenIssuesCount.setText(currentItem.getOpen_issues_count());
|
||||
if(holder.isRepoAdmin == null) {
|
||||
holder.isRepoAdmin = new CheckBox(mCtx);
|
||||
}
|
||||
holder.isRepoAdmin.setChecked(currentItem.getPermissions().isAdmin());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
|
||||
return searchedReposList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return searchedReposList.size();
|
||||
}
|
||||
}
|
||||
|
@ -4,15 +4,16 @@ import android.annotation.SuppressLint;
|
||||
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.CheckBox;
|
||||
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.amulyakhare.textdrawable.util.ColorGenerator;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
@ -39,249 +40,257 @@ import retrofit2.Callback;
|
||||
|
||||
public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.ReposViewHolder> implements Filterable {
|
||||
|
||||
private List<UserRepositories> reposList;
|
||||
private Context mCtx;
|
||||
private List<UserRepositories> reposListFull;
|
||||
private List<UserRepositories> reposList;
|
||||
private Context mCtx;
|
||||
private List<UserRepositories> reposListFull;
|
||||
|
||||
static class ReposViewHolder extends RecyclerView.ViewHolder {
|
||||
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 repoForks;
|
||||
private TextView repoOpenIssuesCount;
|
||||
private TextView repoType;
|
||||
private ImageView image;
|
||||
private TextView repoName;
|
||||
private TextView repoDescription;
|
||||
private TextView fullName;
|
||||
private CheckBox isRepoAdmin;
|
||||
private ImageView repoPrivatePublic;
|
||||
private TextView repoStars;
|
||||
private TextView repoForks;
|
||||
private TextView repoOpenIssuesCount;
|
||||
private TextView repoType;
|
||||
|
||||
private ReposViewHolder(View itemView) {
|
||||
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);
|
||||
repoForks = itemView.findViewById(R.id.repoForks);
|
||||
repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount);
|
||||
ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu);
|
||||
repoType = itemView.findViewById(R.id.repoType);
|
||||
super(itemView);
|
||||
repoName = itemView.findViewById(R.id.repoName);
|
||||
repoDescription = itemView.findViewById(R.id.repoDescription);
|
||||
isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin);
|
||||
image = itemView.findViewById(R.id.imageAvatar);
|
||||
fullName = itemView.findViewById(R.id.repoFullName);
|
||||
repoPrivatePublic = itemView.findViewById(R.id.imageRepoType);
|
||||
repoStars = itemView.findViewById(R.id.repoStars);
|
||||
repoForks = itemView.findViewById(R.id.repoForks);
|
||||
repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount);
|
||||
ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu);
|
||||
repoType = itemView.findViewById(R.id.repoType);
|
||||
|
||||
itemView.setOnClickListener(v -> {
|
||||
itemView.setOnClickListener(v -> {
|
||||
|
||||
Context context = v.getContext();
|
||||
TextView repoFullName = v.findViewById(R.id.repoFullName);
|
||||
TextView repoType_ = v.findViewById(R.id.repoType);
|
||||
Context context = v.getContext();
|
||||
TextView repoFullName = v.findViewById(R.id.repoFullName);
|
||||
TextView repoType_ = v.findViewById(R.id.repoType);
|
||||
|
||||
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||
intent.putExtra("repoFullName", repoFullName.getText().toString());
|
||||
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.putString("repoType", repoType_.getText().toString());
|
||||
tinyDb.putBoolean("resumeIssues", true);
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putString("repoFullName", repoFullName.getText().toString());
|
||||
tinyDb.putString("repoType", repoType_.getText().toString());
|
||||
tinyDb.putBoolean("resumeIssues", true);
|
||||
tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked());
|
||||
|
||||
//store if user is watching this repo
|
||||
{
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
String[] parts = repoFullName.getText().toString().split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
||||
//store if user is watching this repo
|
||||
{
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
String[] parts = repoFullName.getText().toString().split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
||||
|
||||
WatchRepository watch = new WatchRepository();
|
||||
WatchRepository watch = new WatchRepository();
|
||||
|
||||
Call<WatchRepository> call;
|
||||
Call<WatchRepository> call;
|
||||
|
||||
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
||||
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<WatchRepository>() {
|
||||
call.enqueue(new Callback<WatchRepository>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<WatchRepository> call, @NonNull retrofit2.Response<WatchRepository> response) {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<WatchRepository> call, @NonNull retrofit2.Response<WatchRepository> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
tinyDb.putBoolean("repoWatch", response.body().getSubscribed());
|
||||
tinyDb.putBoolean("repoWatch", response.body().getSubscribed());
|
||||
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
|
||||
tinyDb.putBoolean("repoWatch", false);
|
||||
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
||||
tinyDb.putBoolean("repoWatch", false);
|
||||
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<WatchRepository> call, @NonNull Throwable t) {
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<WatchRepository> call, @NonNull Throwable t) {
|
||||
|
||||
tinyDb.putBoolean("repoWatch", false);
|
||||
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
||||
tinyDb.putBoolean("repoWatch", false);
|
||||
Toasty.info(context, context.getString(R.string.genericApiStatusError));
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
context.startActivity(intent);
|
||||
context.startActivity(intent);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
reposDropdownMenu.setOnClickListener(v -> {
|
||||
reposDropdownMenu.setOnClickListener(v -> {
|
||||
|
||||
final Context context = v.getContext();
|
||||
final Context context = v.getContext();
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null);
|
||||
@SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null);
|
||||
|
||||
TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser);
|
||||
TextView repoStargazers = view.findViewById(R.id.repoStargazers);
|
||||
TextView repoWatchers = view.findViewById(R.id.repoWatchers);
|
||||
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
|
||||
TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser);
|
||||
TextView repoStargazers = view.findViewById(R.id.repoStargazers);
|
||||
TextView repoWatchers = view.findViewById(R.id.repoWatchers);
|
||||
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
|
||||
|
||||
bottomSheetHeader.setText(fullName.getText());
|
||||
BottomSheetDialog dialog = new BottomSheetDialog(context);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
bottomSheetHeader.setText(fullName.getText());
|
||||
BottomSheetDialog dialog = new BottomSheetDialog(context);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
|
||||
repoOpenInBrowser.setOnClickListener(openInBrowser -> {
|
||||
repoOpenInBrowser.setOnClickListener(openInBrowser -> {
|
||||
|
||||
Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class);
|
||||
intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText());
|
||||
context.startActivity(intentOpenInBrowser);
|
||||
dialog.dismiss();
|
||||
Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class);
|
||||
intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText());
|
||||
context.startActivity(intentOpenInBrowser);
|
||||
dialog.dismiss();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
repoStargazers.setOnClickListener(stargazers -> {
|
||||
repoStargazers.setOnClickListener(stargazers -> {
|
||||
|
||||
Intent intent = new Intent(context, RepoStargazersActivity.class);
|
||||
intent.putExtra("repoFullNameForStars", fullName.getText());
|
||||
context.startActivity(intent);
|
||||
dialog.dismiss();
|
||||
Intent intent = new Intent(context, RepoStargazersActivity.class);
|
||||
intent.putExtra("repoFullNameForStars", fullName.getText());
|
||||
context.startActivity(intent);
|
||||
dialog.dismiss();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
repoWatchers.setOnClickListener(watchers -> {
|
||||
repoWatchers.setOnClickListener(watchers -> {
|
||||
|
||||
Intent intentW = new Intent(context, RepoWatchersActivity.class);
|
||||
intentW.putExtra("repoFullNameForWatchers", fullName.getText());
|
||||
context.startActivity(intentW);
|
||||
dialog.dismiss();
|
||||
Intent intentW = new Intent(context, RepoWatchersActivity.class);
|
||||
intentW.putExtra("repoFullNameForWatchers", fullName.getText());
|
||||
context.startActivity(intentW);
|
||||
dialog.dismiss();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.list_repos, parent, false);
|
||||
return new ReposViewHolder(v);
|
||||
}
|
||||
public ReposListAdapter(Context mCtx, List<UserRepositories> reposListMain) {
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ReposViewHolder holder, int position) {
|
||||
this.mCtx = mCtx;
|
||||
this.reposList = reposListMain;
|
||||
reposListFull = new ArrayList<>(reposList);
|
||||
}
|
||||
|
||||
UserRepositories currentItem = reposList.get(position);
|
||||
holder.mTextView2.setVisibility(View.GONE);
|
||||
@NonNull
|
||||
@Override
|
||||
public ReposViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
|
||||
ColorGenerator generator = ColorGenerator.MATERIAL;
|
||||
int color = generator.getColor(currentItem.getName());
|
||||
String firstCharacter = String.valueOf(currentItem.getName().charAt(0));
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_repos, parent, false);
|
||||
return new ReposViewHolder(v);
|
||||
}
|
||||
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.useFont(Typeface.DEFAULT)
|
||||
.fontSize(18)
|
||||
.toUpperCase()
|
||||
.width(28)
|
||||
.height(28)
|
||||
.endConfig()
|
||||
.buildRoundRect(firstCharacter, color, 3);
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ReposViewHolder holder, int position) {
|
||||
|
||||
if (currentItem.getAvatar_url() != null) {
|
||||
if (!currentItem.getAvatar_url().equals("")) {
|
||||
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.image);
|
||||
} else {
|
||||
holder.image.setImageDrawable(drawable);
|
||||
}
|
||||
}
|
||||
else {
|
||||
holder.image.setImageDrawable(drawable);
|
||||
}
|
||||
UserRepositories currentItem = reposList.get(position);
|
||||
holder.repoDescription.setVisibility(View.GONE);
|
||||
|
||||
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);
|
||||
holder.repoType.setText(R.string.strPrivate);
|
||||
}
|
||||
else {
|
||||
holder.repoPrivatePublic.setImageResource(R.drawable.ic_public);
|
||||
holder.repoType.setText(R.string.strPublic);
|
||||
}
|
||||
holder.repoStars.setText(currentItem.getStars_count());
|
||||
holder.repoForks.setText(currentItem.getForks_count());
|
||||
holder.repoOpenIssuesCount.setText(currentItem.getOpen_issues_count());
|
||||
ColorGenerator generator = ColorGenerator.MATERIAL;
|
||||
int color = generator.getColor(currentItem.getName());
|
||||
String firstCharacter = String.valueOf(currentItem.getName().charAt(0));
|
||||
|
||||
}
|
||||
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).fontSize(18).toUpperCase().width(28).height(28).endConfig().buildRoundRect(firstCharacter, color, 3);
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return reposList.size();
|
||||
}
|
||||
if(currentItem.getAvatar_url() != null) {
|
||||
if(!currentItem.getAvatar_url().equals("")) {
|
||||
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.image);
|
||||
}
|
||||
else {
|
||||
holder.image.setImageDrawable(drawable);
|
||||
}
|
||||
}
|
||||
else {
|
||||
holder.image.setImageDrawable(drawable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return reposFilter;
|
||||
}
|
||||
holder.repoName.setText(currentItem.getName());
|
||||
if(!currentItem.getDescription().equals("")) {
|
||||
holder.repoDescription.setVisibility(View.VISIBLE);
|
||||
holder.repoDescription.setText(currentItem.getDescription());
|
||||
}
|
||||
holder.fullName.setText(currentItem.getFullname());
|
||||
if(currentItem.getPrivateFlag()) {
|
||||
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock_bold);
|
||||
holder.repoType.setText(R.string.strPrivate);
|
||||
}
|
||||
else {
|
||||
holder.repoPrivatePublic.setImageResource(R.drawable.ic_public);
|
||||
holder.repoType.setText(R.string.strPublic);
|
||||
}
|
||||
holder.repoStars.setText(currentItem.getStars_count());
|
||||
holder.repoForks.setText(currentItem.getForks_count());
|
||||
holder.repoOpenIssuesCount.setText(currentItem.getOpen_issues_count());
|
||||
if(holder.isRepoAdmin == null) {
|
||||
holder.isRepoAdmin = new CheckBox(mCtx);
|
||||
}
|
||||
holder.isRepoAdmin.setChecked(currentItem.getPermissions().isAdmin());
|
||||
|
||||
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();
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
|
||||
for (UserRepositories item : reposListFull) {
|
||||
if (item.getFullname().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return reposList.size();
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
|
||||
return results;
|
||||
}
|
||||
return reposFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
reposList.clear();
|
||||
reposList.addAll((List) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
@ -46,9 +47,10 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
|
||||
static class OrgReposViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView image;
|
||||
private TextView mTextView1;
|
||||
private TextView mTextView2;
|
||||
private TextView repoName;
|
||||
private TextView repoDescription;
|
||||
private TextView fullName;
|
||||
private CheckBox isRepoAdmin;
|
||||
private ImageView repoPrivatePublic;
|
||||
private TextView repoStars;
|
||||
private TextView repoForks;
|
||||
@ -57,8 +59,9 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
|
||||
|
||||
private OrgReposViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mTextView1 = itemView.findViewById(R.id.repoName);
|
||||
mTextView2 = itemView.findViewById(R.id.repoDescription);
|
||||
repoName = itemView.findViewById(R.id.repoName);
|
||||
repoDescription = itemView.findViewById(R.id.repoDescription);
|
||||
isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin);
|
||||
image = itemView.findViewById(R.id.imageAvatar);
|
||||
fullName = itemView.findViewById(R.id.repoFullName);
|
||||
repoPrivatePublic = itemView.findViewById(R.id.imageRepoType);
|
||||
@ -79,6 +82,7 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
|
||||
tinyDb.putString("repoFullName", fullName.getText().toString());
|
||||
tinyDb.putString("repoType", repoType.getText().toString());
|
||||
tinyDb.putBoolean("resumeIssues", true);
|
||||
tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked());
|
||||
|
||||
//store if user is watching this repo
|
||||
{
|
||||
@ -193,7 +197,7 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
|
||||
public void onBindViewHolder(@NonNull RepositoriesByOrgAdapter.OrgReposViewHolder holder, int position) {
|
||||
|
||||
UserRepositories currentItem = reposList.get(position);
|
||||
holder.mTextView2.setVisibility(View.GONE);
|
||||
holder.repoDescription.setVisibility(View.GONE);
|
||||
|
||||
ColorGenerator generator = ColorGenerator.MATERIAL;
|
||||
int color = generator.getColor(currentItem.getName());
|
||||
@ -220,10 +224,10 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
|
||||
holder.image.setImageDrawable(drawable);
|
||||
}
|
||||
|
||||
holder.mTextView1.setText(currentItem.getName());
|
||||
holder.repoName.setText(currentItem.getName());
|
||||
if (!currentItem.getDescription().equals("")) {
|
||||
holder.mTextView2.setVisibility(View.VISIBLE);
|
||||
holder.mTextView2.setText(currentItem.getDescription());
|
||||
holder.repoDescription.setVisibility(View.VISIBLE);
|
||||
holder.repoDescription.setText(currentItem.getDescription());
|
||||
}
|
||||
holder.fullName.setText(currentItem.getFullname());
|
||||
if(currentItem.getPrivateFlag()) {
|
||||
@ -238,6 +242,11 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
|
||||
holder.repoForks.setText(currentItem.getForks_count());
|
||||
holder.repoOpenIssuesCount.setText(currentItem.getOpen_issues_count());
|
||||
|
||||
if (holder.isRepoAdmin == null) {
|
||||
holder.isRepoAdmin = new CheckBox(mCtx);
|
||||
}
|
||||
holder.isRepoAdmin.setChecked(currentItem.getPermissions().isAdmin());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,6 +7,7 @@ import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
@ -46,9 +47,10 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
|
||||
static class StarredReposViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private ImageView image;
|
||||
private TextView mTextView1;
|
||||
private TextView mTextView2;
|
||||
private TextView repoName;
|
||||
private TextView repoDescription;
|
||||
private TextView fullName;
|
||||
private CheckBox isRepoAdmin;
|
||||
private ImageView repoPrivatePublic;
|
||||
private TextView repoStars;
|
||||
private TextView repoForks;
|
||||
@ -57,8 +59,9 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
|
||||
|
||||
private StarredReposViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
mTextView1 = itemView.findViewById(R.id.repoName);
|
||||
mTextView2 = itemView.findViewById(R.id.repoDescription);
|
||||
repoName = itemView.findViewById(R.id.repoName);
|
||||
repoDescription = itemView.findViewById(R.id.repoDescription);
|
||||
isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin);
|
||||
image = itemView.findViewById(R.id.imageAvatar);
|
||||
fullName = itemView.findViewById(R.id.repoFullName);
|
||||
repoPrivatePublic = itemView.findViewById(R.id.imageRepoType);
|
||||
@ -79,6 +82,7 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
|
||||
tinyDb.putString("repoFullName", fullName.getText().toString());
|
||||
tinyDb.putString("repoType", repoType.getText().toString());
|
||||
tinyDb.putBoolean("resumeIssues", true);
|
||||
tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked());
|
||||
|
||||
//store if user is watching this repo
|
||||
{
|
||||
@ -194,7 +198,7 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
|
||||
public void onBindViewHolder(@NonNull StarredReposListAdapter.StarredReposViewHolder holder, int position) {
|
||||
|
||||
UserRepositories currentItem = reposList.get(position);
|
||||
holder.mTextView2.setVisibility(View.GONE);
|
||||
holder.repoDescription.setVisibility(View.GONE);
|
||||
|
||||
ColorGenerator generator = ColorGenerator.MATERIAL;
|
||||
int color = generator.getColor(currentItem.getName());
|
||||
@ -221,10 +225,10 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
|
||||
holder.image.setImageDrawable(drawable);
|
||||
}
|
||||
|
||||
holder.mTextView1.setText(currentItem.getName());
|
||||
holder.repoName.setText(currentItem.getName());
|
||||
if (!currentItem.getDescription().equals("")) {
|
||||
holder.mTextView2.setVisibility(View.VISIBLE);
|
||||
holder.mTextView2.setText(currentItem.getDescription());
|
||||
holder.repoDescription.setVisibility(View.VISIBLE);
|
||||
holder.repoDescription.setText(currentItem.getDescription());
|
||||
}
|
||||
holder.fullName.setText(currentItem.getFullname());
|
||||
if(currentItem.getPrivateFlag()) {
|
||||
@ -238,6 +242,10 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
|
||||
holder.repoStars.setText(currentItem.getStars_count());
|
||||
holder.repoForks.setText(currentItem.getForks_count());
|
||||
holder.repoOpenIssuesCount.setText(currentItem.getOpen_issues_count());
|
||||
if (holder.isRepoAdmin == null) {
|
||||
holder.isRepoAdmin = new CheckBox(mCtx);
|
||||
}
|
||||
holder.isRepoAdmin.setChecked(currentItem.getPermissions().isAdmin());
|
||||
|
||||
}
|
||||
|
||||
|
@ -30,187 +30,194 @@ import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
+ * Template Author M M Arif
|
||||
+ * Author 6543
|
||||
+ */
|
||||
* + * Template Author M M Arif
|
||||
* + * Author 6543
|
||||
* +
|
||||
*/
|
||||
|
||||
public class ExploreRepositoriesFragment extends Fragment {
|
||||
|
||||
private static String repoNameF = "param2";
|
||||
private static String repoOwnerF = "param1";
|
||||
private ProgressBar mProgressBar;
|
||||
private RecyclerView mRecyclerView;
|
||||
private TextView noData;
|
||||
private TextView searchKeyword;
|
||||
private Boolean repoTypeInclude = true;
|
||||
private String sort = "updated";
|
||||
private String order = "desc";
|
||||
private int limit = 50;
|
||||
private static String repoNameF = "param2";
|
||||
private static String repoOwnerF = "param1";
|
||||
private ProgressBar mProgressBar;
|
||||
private RecyclerView mRecyclerView;
|
||||
private TextView noData;
|
||||
private TextView searchKeyword;
|
||||
private Boolean repoTypeInclude = true;
|
||||
private String sort = "updated";
|
||||
private String order = "desc";
|
||||
private int limit = 50;
|
||||
|
||||
private OnFragmentInteractionListener mListener;
|
||||
private OnFragmentInteractionListener mListener;
|
||||
|
||||
public ExploreRepositoriesFragment() {
|
||||
}
|
||||
public ExploreRepositoriesFragment() {
|
||||
|
||||
public static ExploreRepositoriesFragment newInstance(String param1, String param2) {
|
||||
ExploreRepositoriesFragment fragment = new ExploreRepositoriesFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(repoOwnerF, param1);
|
||||
args.putString(repoNameF, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
String repoName = getArguments().getString(repoNameF);
|
||||
String repoOwner = getArguments().getString(repoOwnerF);
|
||||
}
|
||||
}
|
||||
public static ExploreRepositoriesFragment newInstance(String param1, String param2) {
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
ExploreRepositoriesFragment fragment = new ExploreRepositoriesFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(repoOwnerF, param1);
|
||||
args.putString(repoNameF, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
final View v = inflater.inflate(R.layout.fragment_explore_repo, container, false);
|
||||
//setHasOptionsMenu(true);
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
super.onCreate(savedInstanceState);
|
||||
if(getArguments() != null) {
|
||||
String repoName = getArguments().getString(repoNameF);
|
||||
String repoOwner = getArguments().getString(repoOwnerF);
|
||||
}
|
||||
}
|
||||
|
||||
searchKeyword = v.findViewById(R.id.searchKeyword);
|
||||
noData = v.findViewById(R.id.noData);
|
||||
mProgressBar = v.findViewById(R.id.progress_bar);
|
||||
mRecyclerView = v.findViewById(R.id.recyclerViewReposSearch);
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
final View v = inflater.inflate(R.layout.fragment_explore_repo, container, false);
|
||||
//setHasOptionsMenu(true);
|
||||
|
||||
searchKeyword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
||||
if(!searchKeyword.getText().toString().equals("")) {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
loadSearchReposList(instanceUrl, instanceToken, loginUid, searchKeyword.getText().toString(), repoTypeInclude, sort, order, getContext(), limit);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
int limitDefault = 10;
|
||||
loadDefaultList(instanceUrl, instanceToken, loginUid, repoTypeInclude, sort, order, getContext(), limitDefault);
|
||||
searchKeyword = v.findViewById(R.id.searchKeyword);
|
||||
noData = v.findViewById(R.id.noData);
|
||||
mProgressBar = v.findViewById(R.id.progress_bar);
|
||||
mRecyclerView = v.findViewById(R.id.recyclerViewReposSearch);
|
||||
|
||||
return v;
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
searchKeyword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
|
||||
private void loadDefaultList(String instanceUrl, String instanceToken, String loginUid, Boolean repoTypeInclude, String sort, String order, final Context context, int limit) {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
|
||||
Call<ExploreRepositories> call = RetrofitClient
|
||||
.getInstance(instanceUrl, getContext())
|
||||
.getApiInterface()
|
||||
.queryRepos(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), null, repoTypeInclude, sort, order, limit);
|
||||
if(actionId == EditorInfo.IME_ACTION_SEND) {
|
||||
if(!searchKeyword.getText().toString().equals("")) {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
loadSearchReposList(instanceUrl, instanceToken, loginUid, searchKeyword.getText().toString(), repoTypeInclude, sort, order, getContext(), limit);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
call.enqueue(new Callback<ExploreRepositories>() {
|
||||
int limitDefault = 10;
|
||||
loadDefaultList(instanceUrl, instanceToken, loginUid, repoTypeInclude, sort, order, getContext(), limitDefault);
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<ExploreRepositories> call, @NonNull Response<ExploreRepositories> response) {
|
||||
return v;
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
assert response.body() != null;
|
||||
getReposList(response.body().getSearchedData(), context);
|
||||
} else {
|
||||
Log.i("onResponse", String.valueOf(response.code()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private void loadDefaultList(String instanceUrl, String instanceToken, String loginUid, Boolean repoTypeInclude, String sort, String order, final Context context, int limit) {
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<ExploreRepositories> call, @NonNull Throwable t) {
|
||||
Log.i("onFailure", Objects.requireNonNull(t.getMessage()));
|
||||
}
|
||||
Call<ExploreRepositories> call = RetrofitClient.getInstance(instanceUrl, getContext()).getApiInterface().queryRepos(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), null, repoTypeInclude, sort, order, limit);
|
||||
|
||||
});
|
||||
call.enqueue(new Callback<ExploreRepositories>() {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<ExploreRepositories> call, @NonNull Response<ExploreRepositories> response) {
|
||||
|
||||
private void loadSearchReposList(String instanceUrl, String instanceToken, String loginUid, String searchKeyword, Boolean repoTypeInclude, String sort, String order, final Context context, int limit) {
|
||||
if(response.isSuccessful()) {
|
||||
assert response.body() != null;
|
||||
getReposList(response.body().getSearchedData(), context);
|
||||
}
|
||||
else {
|
||||
Log.i("onResponse", String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
Call<ExploreRepositories> call = RetrofitClient
|
||||
.getInstance(instanceUrl, getContext())
|
||||
.getApiInterface()
|
||||
.queryRepos(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), searchKeyword, repoTypeInclude, sort, order, limit);
|
||||
}
|
||||
|
||||
call.enqueue(new Callback<ExploreRepositories>() {
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<ExploreRepositories> call, @NonNull Throwable t) {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<ExploreRepositories> call, @NonNull Response<ExploreRepositories> response) {
|
||||
Log.i("onFailure", Objects.requireNonNull(t.getMessage()));
|
||||
}
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
assert response.body() != null;
|
||||
getReposList(response.body().getSearchedData(), context);
|
||||
} else {
|
||||
Log.i("onResponse", String.valueOf(response.code()));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<ExploreRepositories> call, @NonNull Throwable t) {
|
||||
Log.i("onFailure", Objects.requireNonNull(t.getMessage()));
|
||||
}
|
||||
private void loadSearchReposList(String instanceUrl, String instanceToken, String loginUid, String searchKeyword, Boolean repoTypeInclude, String sort, String order, final Context context, int limit) {
|
||||
|
||||
});
|
||||
Call<ExploreRepositories> call = RetrofitClient.getInstance(instanceUrl, getContext()).getApiInterface().queryRepos(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), searchKeyword, repoTypeInclude, sort, order, limit);
|
||||
|
||||
}
|
||||
call.enqueue(new Callback<ExploreRepositories>() {
|
||||
|
||||
private void getReposList(List<UserRepositories> dataList, Context context) {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<ExploreRepositories> call, @NonNull Response<ExploreRepositories> response) {
|
||||
|
||||
ExploreRepositoriesAdapter adapter = new ExploreRepositoriesAdapter(dataList, context);
|
||||
if(response.isSuccessful()) {
|
||||
assert response.body() != null;
|
||||
getReposList(response.body().getSearchedData(), context);
|
||||
}
|
||||
else {
|
||||
Log.i("onResponse", String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
|
||||
DividerItemDecoration.VERTICAL);
|
||||
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<ExploreRepositories> call, @NonNull Throwable t) {
|
||||
|
||||
if(adapter.getItemCount() > 0) {
|
||||
Log.i("onFailure", Objects.requireNonNull(t.getMessage()));
|
||||
}
|
||||
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noData.setVisibility(View.GONE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
}
|
||||
|
||||
noData.setVisibility(View.VISIBLE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
private void getReposList(List<UserRepositories> dataList, Context context) {
|
||||
|
||||
}
|
||||
ExploreRepositoriesAdapter adapter = new ExploreRepositoriesAdapter(dataList, context);
|
||||
|
||||
}
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
|
||||
public void onButtonPressed(Uri uri) {
|
||||
if (mListener != null) {
|
||||
mListener.onFragmentInteraction(uri);
|
||||
}
|
||||
}
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), DividerItemDecoration.VERTICAL);
|
||||
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mListener = null;
|
||||
}
|
||||
if(adapter.getItemCount() > 0) {
|
||||
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noData.setVisibility(View.GONE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
noData.setVisibility(View.VISIBLE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onButtonPressed(Uri uri) {
|
||||
|
||||
if(mListener != null) {
|
||||
mListener.onFragmentInteraction(uri);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
|
||||
super.onDetach();
|
||||
mListener = null;
|
||||
}
|
||||
|
||||
public interface OnFragmentInteractionListener {
|
||||
|
||||
void onFragmentInteraction(Uri uri);
|
||||
|
||||
}
|
||||
|
||||
public interface OnFragmentInteractionListener {
|
||||
void onFragmentInteraction(Uri uri);
|
||||
}
|
||||
}
|
||||
|
@ -91,6 +91,7 @@ public class MyRepositoriesFragment extends Fragment {
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
final String userLogin = tinyDb.getString("userLogin");
|
||||
tinyDb.putBoolean("isRepoAdmin", true);
|
||||
|
||||
final SwipeRefreshLayout swipeRefresh = v.findViewById(R.id.pullToRefresh);
|
||||
|
||||
|
@ -9,110 +9,162 @@ import java.util.Date;
|
||||
|
||||
public class UserRepositories {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String full_name;
|
||||
private String description;
|
||||
@SerializedName("private")
|
||||
private boolean privateFlag;
|
||||
private String stars_count;
|
||||
private String watchers_count;
|
||||
private String open_issues_count;
|
||||
private String open_pr_counter;
|
||||
private String release_counter;
|
||||
private String html_url;
|
||||
private String default_branch;
|
||||
private Date created_at;
|
||||
private Date updated_at;
|
||||
private String clone_url;
|
||||
private long size;
|
||||
private String ssh_url;
|
||||
private String website;
|
||||
private String forks_count;
|
||||
private Boolean has_issues;
|
||||
private String avatar_url;
|
||||
private int id;
|
||||
private String name;
|
||||
private String full_name;
|
||||
private String description;
|
||||
@SerializedName("private")
|
||||
private boolean privateFlag;
|
||||
private String stars_count;
|
||||
private String watchers_count;
|
||||
private String open_issues_count;
|
||||
private String open_pr_counter;
|
||||
private String release_counter;
|
||||
private String html_url;
|
||||
private String default_branch;
|
||||
private Date created_at;
|
||||
private Date updated_at;
|
||||
private String clone_url;
|
||||
private long size;
|
||||
private String ssh_url;
|
||||
private String website;
|
||||
private String forks_count;
|
||||
private Boolean has_issues;
|
||||
private String avatar_url;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
private permissionsObject permissions;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public class permissionsObject {
|
||||
|
||||
public String getFullname() {
|
||||
return full_name;
|
||||
}
|
||||
private boolean admin;
|
||||
private boolean push;
|
||||
private boolean pull;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public boolean isAdmin() {
|
||||
|
||||
public Boolean getPrivateFlag() {
|
||||
return privateFlag;
|
||||
}
|
||||
return admin;
|
||||
}
|
||||
|
||||
public String getStars_count() {
|
||||
return stars_count;
|
||||
}
|
||||
public boolean canPush() {
|
||||
|
||||
public String getOpen_pull_count() {
|
||||
return open_pr_counter;
|
||||
}
|
||||
return push;
|
||||
}
|
||||
|
||||
public String getRelease_count() {
|
||||
return release_counter;
|
||||
}
|
||||
public boolean canPull() {
|
||||
|
||||
public String getWatchers_count() {
|
||||
return watchers_count;
|
||||
}
|
||||
return pull;
|
||||
}
|
||||
|
||||
public String getOpen_issues_count() {
|
||||
return open_issues_count;
|
||||
}
|
||||
}
|
||||
|
||||
public String getHtml_url() {
|
||||
return html_url;
|
||||
}
|
||||
public int getId() {
|
||||
|
||||
public String getDefault_branch() {
|
||||
return default_branch;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public Date getCreated_at() {
|
||||
return created_at;
|
||||
}
|
||||
public String getName() {
|
||||
|
||||
public Date getUpdated_at() {
|
||||
return updated_at;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getClone_url() {
|
||||
return clone_url;
|
||||
}
|
||||
public String getFullname() {
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
return full_name;
|
||||
}
|
||||
|
||||
public String getSsh_url() {
|
||||
return ssh_url;
|
||||
}
|
||||
public String getDescription() {
|
||||
|
||||
public String getWebsite() {
|
||||
return website;
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getForks_count() {
|
||||
return forks_count;
|
||||
}
|
||||
public permissionsObject getPermissions() {
|
||||
|
||||
public Boolean getHas_issues() {
|
||||
return has_issues;
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public Boolean getPrivateFlag() {
|
||||
|
||||
return privateFlag;
|
||||
}
|
||||
|
||||
public String getStars_count() {
|
||||
|
||||
return stars_count;
|
||||
}
|
||||
|
||||
public String getOpen_pull_count() {
|
||||
|
||||
return open_pr_counter;
|
||||
}
|
||||
|
||||
public String getRelease_count() {
|
||||
|
||||
return release_counter;
|
||||
}
|
||||
|
||||
public String getWatchers_count() {
|
||||
|
||||
return watchers_count;
|
||||
}
|
||||
|
||||
public String getOpen_issues_count() {
|
||||
|
||||
return open_issues_count;
|
||||
}
|
||||
|
||||
public String getHtml_url() {
|
||||
|
||||
return html_url;
|
||||
}
|
||||
|
||||
public String getDefault_branch() {
|
||||
|
||||
return default_branch;
|
||||
}
|
||||
|
||||
public Date getCreated_at() {
|
||||
|
||||
return created_at;
|
||||
}
|
||||
|
||||
public Date getUpdated_at() {
|
||||
|
||||
return updated_at;
|
||||
}
|
||||
|
||||
public String getClone_url() {
|
||||
|
||||
return clone_url;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
public String getSsh_url() {
|
||||
|
||||
return ssh_url;
|
||||
}
|
||||
|
||||
public String getWebsite() {
|
||||
|
||||
return website;
|
||||
}
|
||||
|
||||
public String getForks_count() {
|
||||
|
||||
return forks_count;
|
||||
}
|
||||
|
||||
public Boolean getHas_issues() {
|
||||
|
||||
return has_issues;
|
||||
}
|
||||
|
||||
public String getAvatar_url() {
|
||||
|
||||
return avatar_url;
|
||||
}
|
||||
|
||||
public String getAvatar_url() {
|
||||
return avatar_url;
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,14 @@
|
||||
android:textSize="16sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/repoIsAdmin"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:buttonTint="#FFFFFF"
|
||||
android:checked="false"
|
||||
android:visibility="gone" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
Loading…
x
Reference in New Issue
Block a user