2020-07-29 21:46:58 +02:00
|
|
|
package org.mian.gitnex.adapters;
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
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.CheckBox;
|
|
|
|
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 org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.activities.RepoDetailActivity;
|
|
|
|
import org.mian.gitnex.clients.PicassoService;
|
2022-08-15 16:26:02 +02:00
|
|
|
import org.mian.gitnex.helpers.*;
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
import org.mian.gitnex.helpers.contexts.RepositoryContext;
|
2021-04-13 16:19:42 +02:00
|
|
|
import org.ocpsoft.prettytime.PrettyTime;
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
2020-07-29 21:46:58 +02:00
|
|
|
import java.util.List;
|
2021-04-13 16:19:42 +02:00
|
|
|
import java.util.Locale;
|
2020-07-29 21:46:58 +02:00
|
|
|
|
|
|
|
/**
|
2022-03-28 19:57:47 +02:00
|
|
|
* @author M M Arif
|
2020-07-29 21:46:58 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class RepoForksAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|
|
|
|
2021-04-13 16:19:42 +02:00
|
|
|
private final Context context;
|
2022-04-18 09:10:54 +02:00
|
|
|
private List<org.gitnex.tea4j.v2.models.Repository> forksList;
|
2022-02-25 23:35:51 +01:00
|
|
|
private Runnable loadMoreListener;
|
2020-07-29 21:46:58 +02:00
|
|
|
private boolean isLoading = false;
|
|
|
|
private boolean isMoreDataAvailable = true;
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
public RepoForksAdapter(Context ctx, List<org.gitnex.tea4j.v2.models.Repository> forksListMain) {
|
2020-07-29 21:46:58 +02:00
|
|
|
|
2021-04-13 16:19:42 +02:00
|
|
|
this.context = ctx;
|
2020-07-29 21:46:58 +02:00
|
|
|
this.forksList = forksListMain;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
2021-04-13 16:19:42 +02:00
|
|
|
LayoutInflater inflater = LayoutInflater.from(context);
|
2022-03-28 19:57:47 +02:00
|
|
|
return new RepoForksAdapter.ForksHolder(inflater.inflate(R.layout.list_repositories, parent, false));
|
2020-07-29 21:46:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
|
|
|
|
|
|
|
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) {
|
|
|
|
isLoading = true;
|
2022-02-25 23:35:51 +01:00
|
|
|
loadMoreListener.run();
|
2020-07-29 21:46:58 +02:00
|
|
|
}
|
2022-03-28 19:57:47 +02:00
|
|
|
((RepoForksAdapter.ForksHolder) holder).bindData(forksList.get(position));
|
2020-07-29 21:46:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
2022-03-28 19:57:47 +02:00
|
|
|
return position;
|
2020-07-29 21:46:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return forksList.size();
|
|
|
|
}
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
|
|
|
isMoreDataAvailable = moreDataAvailable;
|
|
|
|
}
|
2020-07-29 21:46:58 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
|
public void notifyDataChanged() {
|
|
|
|
notifyDataSetChanged();
|
|
|
|
isLoading = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLoadMoreListener(Runnable loadMoreListener) {
|
|
|
|
this.loadMoreListener = loadMoreListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateList(List<org.gitnex.tea4j.v2.models.Repository> list) {
|
|
|
|
forksList = list;
|
|
|
|
notifyDataChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
class ForksHolder extends RecyclerView.ViewHolder {
|
2021-04-13 16:19:42 +02:00
|
|
|
|
|
|
|
private final ImageView image;
|
|
|
|
private final TextView repoName;
|
|
|
|
private final TextView orgName;
|
|
|
|
private final TextView repoDescription;
|
|
|
|
private final TextView repoStars;
|
|
|
|
private final TextView repoLastUpdated;
|
2022-08-15 16:26:02 +02:00
|
|
|
private org.gitnex.tea4j.v2.models.Repository userRepositories;
|
|
|
|
private CheckBox isRepoAdmin;
|
2020-07-29 21:46:58 +02:00
|
|
|
|
|
|
|
ForksHolder(View itemView) {
|
|
|
|
|
|
|
|
super(itemView);
|
|
|
|
repoName = itemView.findViewById(R.id.repoName);
|
2021-04-13 16:19:42 +02:00
|
|
|
orgName = itemView.findViewById(R.id.orgName);
|
2020-07-29 21:46:58 +02:00
|
|
|
repoDescription = itemView.findViewById(R.id.repoDescription);
|
|
|
|
isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin);
|
|
|
|
image = itemView.findViewById(R.id.imageAvatar);
|
|
|
|
repoStars = itemView.findViewById(R.id.repoStars);
|
2021-04-13 16:19:42 +02:00
|
|
|
repoLastUpdated = itemView.findViewById(R.id.repoLastUpdated);
|
2020-07-29 21:46:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("SetTextI18n")
|
2022-04-18 09:10:54 +02:00
|
|
|
void bindData(org.gitnex.tea4j.v2.models.Repository forksModel) {
|
2020-07-29 21:46:58 +02:00
|
|
|
|
2021-04-13 16:19:42 +02:00
|
|
|
TinyDB tinyDb = TinyDB.getInstance(context);
|
|
|
|
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
|
|
|
|
2021-05-30 19:28:14 +02:00
|
|
|
Locale locale = context.getResources().getConfiguration().locale;
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
String timeFormat = tinyDb.getString("dateFormat", "pretty");
|
2021-04-13 16:19:42 +02:00
|
|
|
this.userRepositories = forksModel;
|
|
|
|
orgName.setText(forksModel.getFullName().split("/")[0]);
|
|
|
|
repoName.setText(forksModel.getFullName().split("/")[1]);
|
2022-08-07 22:03:17 +02:00
|
|
|
repoStars.setText(AppUtil.numberFormatter(forksModel.getStarsCount()));
|
2021-04-13 16:19:42 +02:00
|
|
|
|
2022-04-04 09:32:03 +02:00
|
|
|
ColorGenerator generator = ColorGenerator.Companion.getMATERIAL();
|
2020-07-29 21:46:58 +02:00
|
|
|
int color = generator.getColor(forksModel.getName());
|
2021-04-15 17:05:56 +02:00
|
|
|
String firstCharacter = String.valueOf(forksModel.getFullName().charAt(0));
|
2020-07-29 21:46:58 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).fontSize(18).toUpperCase().width(28).height(28).endConfig().buildRoundRect(firstCharacter, color, 3);
|
2020-07-29 21:46:58 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
if(forksModel.getAvatarUrl() != null) {
|
|
|
|
if(!forksModel.getAvatarUrl().equals("")) {
|
2022-08-15 16:26:02 +02:00
|
|
|
PicassoService.getInstance(context).get().load(forksModel.getAvatarUrl()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop()
|
|
|
|
.into(image);
|
2020-07-29 21:46:58 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
image.setImageDrawable(drawable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
image.setImageDrawable(drawable);
|
|
|
|
}
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
if(forksModel.getUpdatedAt() != null) {
|
2021-04-13 16:19:42 +02:00
|
|
|
|
|
|
|
switch(timeFormat) {
|
|
|
|
case "pretty": {
|
2021-05-30 19:28:14 +02:00
|
|
|
PrettyTime prettyTime = new PrettyTime(locale);
|
2022-04-18 09:10:54 +02:00
|
|
|
String createdTime = prettyTime.format(forksModel.getUpdatedAt());
|
2021-04-13 16:19:42 +02:00
|
|
|
repoLastUpdated.setText(context.getString(R.string.lastUpdatedAt, createdTime));
|
2022-04-18 09:10:54 +02:00
|
|
|
repoLastUpdated.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(forksModel.getUpdatedAt()), context));
|
2021-04-13 16:19:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "normal": {
|
2021-05-30 19:28:14 +02:00
|
|
|
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale);
|
2022-04-18 09:10:54 +02:00
|
|
|
String createdTime = formatter.format(forksModel.getUpdatedAt());
|
2021-04-13 16:19:42 +02:00
|
|
|
repoLastUpdated.setText(context.getString(R.string.lastUpdatedAt, createdTime));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "normal1": {
|
2021-05-30 19:28:14 +02:00
|
|
|
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale);
|
2022-04-18 09:10:54 +02:00
|
|
|
String createdTime = formatter.format(forksModel.getUpdatedAt());
|
2021-04-13 16:19:42 +02:00
|
|
|
repoLastUpdated.setText(context.getString(R.string.lastUpdatedAt, createdTime));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-07-29 21:46:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2021-04-13 16:19:42 +02:00
|
|
|
repoLastUpdated.setVisibility(View.GONE);
|
2020-07-29 21:46:58 +02:00
|
|
|
}
|
|
|
|
|
2021-04-13 16:19:42 +02:00
|
|
|
if(!forksModel.getDescription().equals("")) {
|
|
|
|
repoDescription.setText(forksModel.getDescription());
|
|
|
|
}
|
2021-04-15 17:05:56 +02:00
|
|
|
else {
|
|
|
|
repoDescription.setText(context.getString(R.string.noDataDescription));
|
|
|
|
}
|
2020-07-29 21:46:58 +02:00
|
|
|
|
|
|
|
if(isRepoAdmin == null) {
|
2021-04-13 16:19:42 +02:00
|
|
|
isRepoAdmin = new CheckBox(context);
|
2020-07-29 21:46:58 +02:00
|
|
|
}
|
|
|
|
isRepoAdmin.setChecked(forksModel.getPermissions().isAdmin());
|
|
|
|
|
|
|
|
itemView.setOnClickListener(v -> {
|
|
|
|
|
|
|
|
Context context = v.getContext();
|
|
|
|
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
RepositoryContext repo = new RepositoryContext(userRepositories, context);
|
2022-05-21 11:38:15 +02:00
|
|
|
repo.saveToDB(context);
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
Intent intent = repo.getIntent(context, RepoDetailActivity.class);
|
2020-07-29 21:46:58 +02:00
|
|
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|