2021-08-02 20:04:33 +02:00
|
|
|
package org.mian.gitnex.adapters.profile;
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.content.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
|
|
|
import android.content.Intent;
|
2021-08-02 20:04:33 +02:00
|
|
|
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;
|
2022-04-18 09:10:54 +02:00
|
|
|
import org.gitnex.tea4j.v2.models.Repository;
|
2021-08-02 20:04:33 +02:00
|
|
|
import org.mian.gitnex.R;
|
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.activities.RepoDetailActivity;
|
2021-08-02 20:04:33 +02:00
|
|
|
import org.mian.gitnex.clients.PicassoService;
|
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.database.api.BaseApi;
|
|
|
|
import org.mian.gitnex.database.api.RepositoriesApi;
|
2021-08-02 20:04:33 +02:00
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
|
|
|
import org.mian.gitnex.helpers.ClickListener;
|
|
|
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
|
|
|
import org.mian.gitnex.helpers.TimeHelper;
|
|
|
|
import org.mian.gitnex.helpers.TinyDB;
|
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-08-02 20:04:33 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
/**
|
2022-03-28 19:57:47 +02:00
|
|
|
* @author M M Arif
|
2021-08-02 20:04:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class RepositoriesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|
|
|
|
|
|
|
private final Context context;
|
2022-04-18 09:10:54 +02:00
|
|
|
private List<Repository> reposList;
|
2022-02-25 23:35:51 +01:00
|
|
|
private Runnable loadMoreListener;
|
2021-08-02 20:04:33 +02:00
|
|
|
private boolean isLoading = false, isMoreDataAvailable = true;
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
public RepositoriesAdapter(Context ctx, List<Repository> reposListMain) {
|
2021-08-02 20:04:33 +02:00
|
|
|
this.context = ctx;
|
|
|
|
this.reposList = reposListMain;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
|
|
|
|
|
LayoutInflater inflater = LayoutInflater.from(context);
|
2022-03-28 19:57:47 +02:00
|
|
|
return new RepositoriesAdapter.RepositoriesHolder(inflater.inflate(R.layout.list_repositories, parent, false));
|
2021-08-02 20:04:33 +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();
|
2021-08-02 20:04:33 +02:00
|
|
|
}
|
2022-03-28 19:57:47 +02:00
|
|
|
((RepositoriesAdapter.RepositoriesHolder) holder).bindData(reposList.get(position));
|
2021-08-02 20:04:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
2022-03-28 19:57:47 +02:00
|
|
|
return position;
|
2021-08-02 20:04:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return reposList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
class RepositoriesHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
private Repository userRepositories;
|
2021-08-02 20:04:33 +02:00
|
|
|
|
|
|
|
private final ImageView avatar;
|
|
|
|
private final TextView repoName;
|
|
|
|
private final TextView orgName;
|
|
|
|
private final TextView repoDescription;
|
|
|
|
private CheckBox isRepoAdmin;
|
|
|
|
private final TextView repoStars;
|
|
|
|
private final TextView repoLastUpdated;
|
|
|
|
|
|
|
|
RepositoriesHolder(View itemView) {
|
|
|
|
|
|
|
|
super(itemView);
|
|
|
|
repoName = itemView.findViewById(R.id.repoName);
|
|
|
|
orgName = itemView.findViewById(R.id.orgName);
|
|
|
|
repoDescription = itemView.findViewById(R.id.repoDescription);
|
|
|
|
isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin);
|
|
|
|
avatar = itemView.findViewById(R.id.imageAvatar);
|
|
|
|
repoStars = itemView.findViewById(R.id.repoStars);
|
|
|
|
repoLastUpdated = itemView.findViewById(R.id.repoLastUpdated);
|
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
|
|
|
|
|
|
|
itemView.setOnClickListener(v -> {
|
|
|
|
Context context = v.getContext();
|
|
|
|
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);
|
|
|
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
});
|
|
|
|
|
2021-08-02 20:04:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("SetTextI18n")
|
2022-04-18 09:10:54 +02:00
|
|
|
void bindData(Repository userRepositories) {
|
2021-08-02 20:04:33 +02:00
|
|
|
|
|
|
|
this.userRepositories = userRepositories;
|
|
|
|
TinyDB tinyDb = TinyDB.getInstance(context);
|
|
|
|
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
|
|
|
|
|
|
|
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-08-02 20:04:33 +02:00
|
|
|
|
|
|
|
orgName.setText(userRepositories.getFullName().split("/")[0]);
|
|
|
|
repoName.setText(userRepositories.getFullName().split("/")[1]);
|
2022-04-18 09:10:54 +02:00
|
|
|
repoStars.setText(String.valueOf(userRepositories.getStarsCount()));
|
2021-08-02 20:04:33 +02:00
|
|
|
|
2022-04-04 09:32:03 +02:00
|
|
|
ColorGenerator generator = ColorGenerator.Companion.getMATERIAL();
|
2021-08-02 20:04:33 +02:00
|
|
|
int color = generator.getColor(userRepositories.getName());
|
|
|
|
String firstCharacter = String.valueOf(userRepositories.getFullName().charAt(0));
|
|
|
|
|
|
|
|
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).fontSize(18).toUpperCase().width(28).height(28).endConfig().buildRoundRect(firstCharacter, color, 3);
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
if(userRepositories.getAvatarUrl() != null) {
|
|
|
|
if(!userRepositories.getAvatarUrl().equals("")) {
|
2021-08-02 20:04:33 +02:00
|
|
|
PicassoService
|
2022-04-18 09:10:54 +02:00
|
|
|
.getInstance(context).get().load(userRepositories.getAvatarUrl()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop().into(avatar);
|
2021-08-02 20:04:33 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
avatar.setImageDrawable(drawable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
avatar.setImageDrawable(drawable);
|
|
|
|
}
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
if(userRepositories.getUpdatedAt() != null) {
|
2021-08-02 20:04:33 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
repoLastUpdated.setText(context.getString(R.string.lastUpdatedAt, TimeHelper.formatTime(userRepositories.getUpdatedAt(), locale, timeFormat, context)));
|
2021-08-02 20:04:33 +02:00
|
|
|
if(timeFormat.equals("pretty")) {
|
2022-04-18 09:10:54 +02:00
|
|
|
repoLastUpdated.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(userRepositories.getUpdatedAt()), context));
|
2021-08-02 20:04:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
repoLastUpdated.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!userRepositories.getDescription().equals("")) {
|
|
|
|
repoDescription.setText(userRepositories.getDescription());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
repoDescription.setText(context.getString(R.string.noDataDescription));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isRepoAdmin == null) {
|
|
|
|
isRepoAdmin = new CheckBox(context);
|
|
|
|
}
|
|
|
|
isRepoAdmin.setChecked(userRepositories.getPermissions().isAdmin());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
|
|
|
isMoreDataAvailable = moreDataAvailable;
|
|
|
|
}
|
|
|
|
|
2022-03-28 19:57:47 +02:00
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
2021-08-02 20:04:33 +02:00
|
|
|
public void notifyDataChanged() {
|
|
|
|
notifyDataSetChanged();
|
|
|
|
isLoading = false;
|
|
|
|
}
|
|
|
|
|
2022-02-25 23:35:51 +01:00
|
|
|
public void setLoadMoreListener(Runnable loadMoreListener) {
|
2021-08-02 20:04:33 +02:00
|
|
|
this.loadMoreListener = loadMoreListener;
|
|
|
|
}
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
public void updateList(List<Repository> list) {
|
2021-08-02 20:04:33 +02:00
|
|
|
reposList = list;
|
2022-03-28 19:57:47 +02:00
|
|
|
notifyDataChanged();
|
2021-08-02 20:04:33 +02:00
|
|
|
}
|
|
|
|
}
|