2020-08-18 16:10:46 +02:00
|
|
|
package org.mian.gitnex.adapters;
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.app.Dialog;
|
|
|
|
import android.content.Context;
|
2021-12-17 18:50:03 +01:00
|
|
|
import android.content.Intent;
|
2020-08-18 16:10:46 +02:00
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.drawable.ColorDrawable;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2021-12-17 18:50:03 +01:00
|
|
|
import android.widget.Button;
|
2020-08-18 16:10:46 +02:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.drawerlayout.widget.DrawerLayout;
|
2021-12-17 18:50:03 +01:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
2020-08-18 16:10:46 +02:00
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2022-09-21 07:43:00 +02:00
|
|
|
import io.mikael.urlbuilder.UrlBuilder;
|
|
|
|
import java.util.List;
|
2020-08-18 16:10:46 +02:00
|
|
|
import org.mian.gitnex.R;
|
2021-12-17 18:50:03 +01:00
|
|
|
import org.mian.gitnex.activities.AddNewAccountActivity;
|
2020-08-18 16:10:46 +02:00
|
|
|
import org.mian.gitnex.clients.PicassoService;
|
|
|
|
import org.mian.gitnex.database.models.UserAccount;
|
2021-04-13 16:19:42 +02:00
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
2020-08-18 16:10:46 +02:00
|
|
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
|
|
|
|
|
|
|
/**
|
2022-05-05 16:57:22 +02:00
|
|
|
* @author M M Arif
|
2020-08-18 16:10:46 +02:00
|
|
|
*/
|
2022-09-21 07:43:00 +02:00
|
|
|
public class UserAccountsNavAdapter
|
|
|
|
extends RecyclerView.Adapter<UserAccountsNavAdapter.UserAccountsViewHolder> {
|
2020-08-18 16:10:46 +02:00
|
|
|
|
2022-05-05 16:57:22 +02:00
|
|
|
private final DrawerLayout drawer;
|
2021-04-13 16:19:42 +02:00
|
|
|
private final List<UserAccount> userAccountsList;
|
|
|
|
private final Context context;
|
2020-08-18 16:10:46 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
public UserAccountsNavAdapter(
|
|
|
|
Context ctx, List<UserAccount> userAccountsListMain, DrawerLayout drawerLayout) {
|
2020-08-18 16:10:46 +02:00
|
|
|
|
2021-04-13 16:19:42 +02:00
|
|
|
this.context = ctx;
|
2020-08-18 16:10:46 +02:00
|
|
|
this.userAccountsList = userAccountsListMain;
|
2022-05-05 16:57:22 +02:00
|
|
|
this.drawer = drawerLayout;
|
2020-08-18 16:10:46 +02:00
|
|
|
}
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@NonNull @Override
|
|
|
|
public UserAccountsNavAdapter.UserAccountsViewHolder onCreateViewHolder(
|
|
|
|
@NonNull ViewGroup parent, int viewType) {
|
2020-08-18 16:10:46 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
View v =
|
|
|
|
LayoutInflater.from(parent.getContext())
|
|
|
|
.inflate(R.layout.nav_user_accounts, parent, false);
|
2020-08-18 16:10:46 +02:00
|
|
|
return new UserAccountsViewHolder(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("DefaultLocale")
|
|
|
|
@Override
|
2022-09-21 07:43:00 +02:00
|
|
|
public void onBindViewHolder(
|
|
|
|
@NonNull UserAccountsNavAdapter.UserAccountsViewHolder holder, int position) {
|
2020-08-18 16:10:46 +02:00
|
|
|
|
|
|
|
UserAccount currentItem = userAccountsList.get(position);
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
String url = UrlBuilder.fromString(currentItem.getInstanceUrl()).withPath("/").toString();
|
2020-08-18 16:10:46 +02:00
|
|
|
|
2022-08-26 19:00:08 +02:00
|
|
|
int imageSize = AppUtil.getPixelsFromDensity(context, 36);
|
2021-04-13 16:19:42 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
PicassoService.getInstance(context)
|
|
|
|
.get()
|
|
|
|
.load(url + "assets/img/favicon.png")
|
|
|
|
.placeholder(R.drawable.loader_animated)
|
|
|
|
.transform(new RoundedTransformation(18, 0))
|
|
|
|
.resize(imageSize, imageSize)
|
|
|
|
.centerCrop()
|
|
|
|
.into(holder.userAccountAvatar);
|
2020-08-18 16:10:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
|
2022-08-26 19:00:08 +02:00
|
|
|
return Math.min(userAccountsList.size(), 3);
|
2020-08-18 16:10:46 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
private void customDialogUserAccountsList() {
|
2020-08-18 16:10:46 +02:00
|
|
|
|
2021-04-13 16:19:42 +02:00
|
|
|
Dialog dialog = new Dialog(context, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
|
2020-08-18 16:10:46 +02:00
|
|
|
dialog.setContentView(R.layout.custom_user_accounts_dialog);
|
|
|
|
|
2021-12-17 18:50:03 +01:00
|
|
|
RecyclerView listView = dialog.findViewById(R.id.accountsList);
|
|
|
|
Button newAccount = dialog.findViewById(R.id.newAccount);
|
2020-08-18 16:10:46 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (dialog.getWindow() != null) {
|
2020-08-18 16:10:46 +02:00
|
|
|
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
|
|
|
}
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
newAccount.setOnClickListener(
|
|
|
|
item -> {
|
|
|
|
context.startActivity(new Intent(context, AddNewAccountActivity.class));
|
|
|
|
dialog.dismiss();
|
|
|
|
});
|
2020-08-18 16:10:46 +02:00
|
|
|
|
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
|
|
|
UserAccountsAdapter arrayAdapter = new UserAccountsAdapter(context, dialog);
|
2021-12-17 18:50:03 +01:00
|
|
|
listView.setLayoutManager(new LinearLayoutManager(context));
|
2020-08-18 16:10:46 +02:00
|
|
|
listView.setAdapter(arrayAdapter);
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
class UserAccountsViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
|
|
|
private final ImageView userAccountAvatar;
|
|
|
|
|
|
|
|
private UserAccountsViewHolder(View itemView) {
|
|
|
|
|
|
|
|
super(itemView);
|
|
|
|
|
|
|
|
userAccountAvatar = itemView.findViewById(R.id.userAccountAvatar);
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
itemView.setOnClickListener(
|
|
|
|
item -> {
|
|
|
|
customDialogUserAccountsList();
|
|
|
|
drawer.closeDrawers();
|
|
|
|
});
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-18 16:10:46 +02:00
|
|
|
}
|