Multiple accounts support (#624)
Title update Color clean up switch to another account and update the token at login Add new account Add fab button for new account and activity update libs Remove account from Manage accounts list Co-authored-by: M M Arif <mmarif@swatian.com> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/624 Reviewed-by: 6543 <6543@noreply.codeberg.org>
This commit is contained in:
@@ -86,7 +86,7 @@ public class AdminGetUsersAdapter extends RecyclerView.Adapter<AdminGetUsersAdap
|
||||
holder.userRole.setVisibility(View.VISIBLE);
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.textColor(mCtx.getResources().getColor(R.color.white))
|
||||
.textColor(mCtx.getResources().getColor(R.color.colorWhite))
|
||||
.fontSize(44)
|
||||
.width(180)
|
||||
.height(60)
|
||||
|
||||
@@ -58,7 +58,7 @@ public class ProfileEmailsAdapter extends RecyclerView.Adapter<ProfileEmailsAdap
|
||||
if(currentItem.getPrimary()) {
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.textColor(mCtx.getResources().getColor(R.color.white))
|
||||
.textColor(mCtx.getResources().getColor(R.color.colorWhite))
|
||||
.fontSize(36)
|
||||
.width(220)
|
||||
.height(60)
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.clients.PicassoService;
|
||||
import org.mian.gitnex.database.api.UserAccountsApi;
|
||||
import org.mian.gitnex.database.models.UserAccount;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
@@ -28,13 +32,15 @@ public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapte
|
||||
private Context mCtx;
|
||||
private TinyDB tinyDB;
|
||||
|
||||
static class UserAccountsViewHolder extends RecyclerView.ViewHolder {
|
||||
class UserAccountsViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView accountUrl;
|
||||
private TextView userId;
|
||||
private ImageView activeAccount;
|
||||
private ImageView deleteAccount;
|
||||
private ImageView repoAvatar;
|
||||
private TextView accountId;
|
||||
private TextView accountName;
|
||||
|
||||
private UserAccountsViewHolder(View itemView) {
|
||||
|
||||
@@ -45,14 +51,48 @@ public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapte
|
||||
activeAccount = itemView.findViewById(R.id.activeAccount);
|
||||
deleteAccount = itemView.findViewById(R.id.deleteAccount);
|
||||
repoAvatar = itemView.findViewById(R.id.repoAvatar);
|
||||
accountId = itemView.findViewById(R.id.accountId);
|
||||
accountName = itemView.findViewById(R.id.accountName);
|
||||
|
||||
deleteAccount.setOnClickListener(itemDelete -> {
|
||||
// use later to delete an account
|
||||
|
||||
new AlertDialog.Builder(mCtx)
|
||||
.setIcon(mCtx.getDrawable(R.drawable.ic_delete))
|
||||
.setTitle(mCtx.getResources().getString(R.string.removeAccountPopupTitle))
|
||||
.setMessage(mCtx.getResources().getString(R.string.removeAccountPopupMessage))
|
||||
.setPositiveButton(mCtx.getResources().getString(R.string.removeButton), (dialog, which) -> {
|
||||
|
||||
updateLayoutByPosition(getAdapterPosition());
|
||||
UserAccountsApi userAccountsApi = new UserAccountsApi(mCtx);
|
||||
userAccountsApi.deleteAccount(Integer.parseInt(accountId.getText().toString()));
|
||||
}).setNeutralButton(mCtx.getResources().getString(R.string.cancelButton), null)
|
||||
.show();
|
||||
|
||||
});
|
||||
|
||||
itemView.setOnClickListener(itemEdit -> {
|
||||
// use later to switch account
|
||||
|
||||
String accountNameSwitch = accountName.getText().toString();
|
||||
UserAccountsApi userAccountsApi = new UserAccountsApi(mCtx);
|
||||
UserAccount userAccount = userAccountsApi.getAccountData(accountNameSwitch);
|
||||
|
||||
Log.e("userAccount", userAccount.getInstanceUrl());
|
||||
|
||||
if(tinyDB.getInt("currentActiveAccountId") != userAccount.getAccountId()) {
|
||||
|
||||
String url = UrlBuilder.fromString(userAccount.getInstanceUrl())
|
||||
.withPath("/")
|
||||
.toString();
|
||||
|
||||
tinyDB.putString("loginUid", userAccount.getUserName());
|
||||
tinyDB.putString("userLogin", userAccount.getUserName());
|
||||
tinyDB.putString(userAccount.getUserName() + "-token", userAccount.getToken());
|
||||
tinyDB.putString("instanceUrl", userAccount.getInstanceUrl());
|
||||
tinyDB.putInt("currentActiveAccountId", userAccount.getAccountId());
|
||||
|
||||
Toasty.success(mCtx, mCtx.getResources().getString(R.string.switchAccountSuccess, userAccount.getUserName(), url));
|
||||
((Activity) mCtx).recreate();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -66,7 +106,7 @@ public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapte
|
||||
this.userAccountsList = userAccountsListMain;
|
||||
}
|
||||
|
||||
private void deleteAccount(int position) {
|
||||
private void updateLayoutByPosition(int position) {
|
||||
|
||||
userAccountsList.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
@@ -94,6 +134,8 @@ public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapte
|
||||
.withPath("/")
|
||||
.toString();
|
||||
|
||||
holder.accountId.setText(String.valueOf(currentItem.getAccountId()));
|
||||
holder.accountName.setText(currentItem.getAccountName());
|
||||
holder.userId.setText(String.format("@%s", currentItem.getUserName()));
|
||||
holder.accountUrl.setText(url);
|
||||
|
||||
@@ -103,7 +145,7 @@ public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapte
|
||||
holder.activeAccount.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
holder.deleteAccount.setVisibility(View.GONE);
|
||||
holder.deleteAccount.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user