Switch to proper account for popular instances and other ui improvements (#836)

* improve navigation via keyboard

* switch to proper account for popular instances

* ui improvements

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/836
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-Authored-By: M M Arif <mmarif@noreply.codeberg.org>
Co-Committed-By: M M Arif <mmarif@noreply.codeberg.org>
This commit is contained in:
M M Arif 2021-02-25 00:22:11 +01:00 committed by 6543
parent 47d6c68410
commit afffb7c15a
19 changed files with 132 additions and 107 deletions

View File

@ -78,6 +78,13 @@ public class DeepLinksActivity extends BaseActivity {
if(hostUri.toLowerCase().contains(Objects.requireNonNull(data.getHost().toLowerCase()))) {
accountFound = true;
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());
break;
}
}

View File

@ -1,6 +1,7 @@
package org.mian.gitnex.adapters;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -23,12 +24,12 @@ import java.util.List;
public class AssigneesListAdapter extends RecyclerView.Adapter<AssigneesListAdapter.AssigneesViewHolder> {
private Context mCtx;
private List<Collaborators> assigneesList;
private final Context mCtx;
private final List<Collaborators> assigneesList;
private List<String> assigneesStrings = new ArrayList<>();
private List<String> currentAssignees;
private AssigneesListAdapterListener assigneesListener;
private final AssigneesListAdapterListener assigneesListener;
public interface AssigneesListAdapterListener {
@ -45,9 +46,9 @@ public class AssigneesListAdapter extends RecyclerView.Adapter<AssigneesListAdap
static class AssigneesViewHolder extends RecyclerView.ViewHolder {
private CheckBox assigneesSelection;
private TextView assigneesName;
private ImageView assigneesAvatar;
private final CheckBox assigneesSelection;
private final TextView assigneesName;
private final ImageView assigneesAvatar;
private AssigneesViewHolder(View itemView) {
@ -79,7 +80,7 @@ public class AssigneesListAdapter extends RecyclerView.Adapter<AssigneesListAdap
}
else {
holder.assigneesName.setText(currentItem.getFull_name());
holder.assigneesName.setText(Html.fromHtml(currentItem.getFull_name()));
}
PicassoService
.getInstance(mCtx).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(180, 180).centerCrop().into(holder.assigneesAvatar);

View File

@ -32,6 +32,7 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
private final FilesAdapterListener filesListener;
public interface FilesAdapterListener {
void onClickDir(String str);
void onClickFile(String str);
}

View File

@ -10,6 +10,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.PicassoService;
@ -27,19 +28,20 @@ import io.mikael.urlbuilder.UrlBuilder;
public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapter.UserAccountsViewHolder> {
private List<UserAccount> userAccountsList;
private Context mCtx;
private final List<UserAccount> userAccountsList;
private final Context mCtx;
private TinyDB tinyDB;
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 int accountId;
private String accountName;
private final TextView accountUrl;
private final TextView userId;
private final ImageView activeAccount;
private final ImageView deleteAccount;
private final ImageView repoAvatar;
private UserAccountsViewHolder(View itemView) {
@ -50,30 +52,26 @@ 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 -> {
new AlertDialog.Builder(mCtx)
.setIcon(mCtx.getDrawable(R.drawable.ic_delete))
.setIcon(AppCompatResources.getDrawable(mCtx, 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()));
userAccountsApi.deleteAccount(Integer.parseInt(String.valueOf(accountId)));
}).setNeutralButton(mCtx.getResources().getString(R.string.cancelButton), null)
.show();
});
itemView.setOnClickListener(itemEdit -> {
itemView.setOnClickListener(switchAccount -> {
String accountNameSwitch = accountName.getText().toString();
UserAccountsApi userAccountsApi = new UserAccountsApi(mCtx);
UserAccount userAccount = userAccountsApi.getAccountData(accountNameSwitch);
UserAccount userAccount = userAccountsApi.getAccountData(accountName);
if(tinyDB.getInt("currentActiveAccountId") != userAccount.getAccountId()) {
@ -109,7 +107,6 @@ public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapte
notifyItemRemoved(position);
notifyItemRangeChanged(position, userAccountsList.size());
Toasty.success(mCtx, mCtx.getResources().getString(R.string.accountDeletedMessage));
}
@NonNull
@ -131,20 +128,22 @@ public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapte
.withPath("/")
.toString();
holder.accountId.setText(String.valueOf(currentItem.getAccountId()));
holder.accountName.setText(currentItem.getAccountName());
holder.accountId = currentItem.getAccountId();
holder.accountName = currentItem.getAccountName();
holder.userId.setText(String.format("@%s", currentItem.getUserName()));
holder.accountUrl.setText(url);
PicassoService.getInstance(mCtx).get().load(url + "img/favicon.png").placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.repoAvatar);
if(tinyDB.getInt("currentActiveAccountId") == currentItem.getAccountId()) {
holder.activeAccount.setVisibility(View.VISIBLE);
}
else {
holder.deleteAccount.setVisibility(View.VISIBLE);
}
}
@Override

View File

@ -81,6 +81,7 @@
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:singleLine="true"
android:imeOptions="actionSend"
android:inputType="text"
android:textSize="16sp" />

View File

@ -75,6 +75,7 @@
android:inputType="none"
android:textColor="?attr/inputTextColor"
android:labelFor="@+id/protocolSpinner"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
@ -102,7 +103,8 @@
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:maxLines="1"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
@ -130,7 +132,8 @@
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:maxLines="1"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>

View File

@ -81,6 +81,7 @@
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:singleLine="true"
android:inputType="text"
android:textSize="16sp" />

View File

@ -78,6 +78,8 @@
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:inputType="textCapSentences"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
@ -134,6 +136,7 @@
android:inputType="textCapSentences"
android:labelFor="@id/new_file_branches"
android:singleLine="true"
android:imeOptions="actionNext"
android:textColor="?attr/inputTextColor"
android:textSize="16sp" />
@ -164,6 +167,7 @@
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:singleLine="true"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>

View File

@ -78,6 +78,8 @@
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:inputType="textCapSentences"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>

View File

@ -75,6 +75,8 @@
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:inputType="textCapSentences"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>

View File

@ -75,6 +75,8 @@
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:inputType="textCapSentences"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
@ -100,6 +102,8 @@
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
@ -125,6 +129,8 @@
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
@ -150,6 +156,7 @@
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:singleLine="true"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>

View File

@ -75,6 +75,8 @@
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:inputType="textCapSentences"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>

View File

@ -78,6 +78,8 @@
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:inputType="textCapSentences"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>

View File

@ -74,7 +74,9 @@
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:inputType="textCapSentences|textMultiLine"
android:inputType="textCapSentences"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
@ -101,6 +103,8 @@
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:inputType="textCapSentences"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>

View File

@ -75,6 +75,8 @@
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:inputType="textCapSentences"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
@ -103,6 +105,8 @@
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>

View File

@ -75,6 +75,8 @@
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:inputType="textCapSentences"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>

View File

@ -107,6 +107,7 @@
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:inputType="textUri"
android:singleLine="true"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
@ -134,6 +135,7 @@
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:singleLine="true"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
@ -162,6 +164,7 @@
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:inputType="textPassword"
android:singleLine="true"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
@ -193,6 +196,7 @@
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:inputType="number"
android:singleLine="true"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
@ -220,6 +224,7 @@
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:singleLine="true"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>

View File

@ -89,6 +89,8 @@
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:inputType="textCapSentences"
android:singleLine="true"
android:imeOptions="actionNext"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>

View File

@ -1,92 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutUserAccountsFrame"
<RelativeLayout android:id="@+id/layoutFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:layout_margin="15dp"
android:background="?attr/primaryBackgroundColor">
android:background="?attr/primaryBackgroundColor"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/accountId"
android:visibility="gone" />
<ImageView
android:id="@+id/repoAvatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="15dp"
android:contentDescription="@string/repoContentAvatar"
android:src="@drawable/ic_android" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/accountName"
android:visibility="gone" />
<RelativeLayout
android:id="@+id/layoutFrame"
<LinearLayout
android:id="@+id/frameAccountsInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/repoAvatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="15dp"
android:contentDescription="@string/repoContentAvatar"
android:src="@drawable/ic_android" />
<LinearLayout
android:id="@+id/frameAccountsInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_toEndOf="@+id/repoAvatar"
android:layout_marginBottom="10dp">
<TextView
android:id="@+id/userId"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".95"
android:layout_gravity="start"
android:textColor="?attr/primaryTextColor"
android:textSize="16sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/activeAccount"
android:layout_weight=".05"
android:layout_width="10dp"
android:layout_height="20dp"
android:layout_gravity="end"
android:src="@drawable/ic_check"
android:visibility="gone"
android:contentDescription="@string/menuContentDesc" />
<ImageView
android:id="@+id/deleteAccount"
android:layout_weight=".05"
android:layout_width="10dp"
android:layout_height="20dp"
android:layout_gravity="end"
android:src="@drawable/ic_delete"
android:visibility="gone"
android:contentDescription="@string/menuDeleteText" />
</LinearLayout>
android:orientation="horizontal"
android:layout_toEndOf="@+id/repoAvatar"
android:layout_marginBottom="10dp">
<TextView
android:id="@+id/accountUrl"
android:layout_width="match_parent"
android:id="@+id/userId"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_toEndOf="@+id/repoAvatar"
android:layout_below="@+id/frameAccountsInfo"
android:layout_weight=".95"
android:layout_gravity="start"
android:textColor="?attr/primaryTextColor"
android:textSize="14sp" />
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:id="@+id/activeAccount"
android:layout_weight=".05"
android:layout_width="10dp"
android:layout_height="20dp"
android:layout_gravity="end"
android:src="@drawable/ic_check"
android:visibility="gone"
android:contentDescription="@string/menuContentDesc" />
</LinearLayout>
<ImageView
android:id="@+id/deleteAccount"
android:layout_weight=".05"
android:layout_width="10dp"
android:layout_height="20dp"
android:layout_gravity="end"
android:src="@drawable/ic_delete"
android:visibility="gone"
android:contentDescription="@string/menuDeleteText" />
</LinearLayout>
<TextView
android:id="@+id/accountUrl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_toEndOf="@+id/repoAvatar"
android:layout_below="@+id/frameAccountsInfo"
android:textColor="?attr/primaryTextColor"
android:textSize="14sp" />
</RelativeLayout>