Redesign and refactor add new account

This commit is contained in:
M M Arif 2023-10-02 12:45:10 +05:00
parent 758ee59a44
commit bc060a21b0
5 changed files with 171 additions and 169 deletions

View File

@ -143,7 +143,8 @@
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|keyboard|keyboardHidden|navigation"/>
<activity
android:name=".activities.AddNewAccountActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|keyboard|keyboardHidden|navigation"/>
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|keyboard|keyboardHidden|navigation"
android:windowSoftInputMode="adjustResize"/>
<activity
android:name=".activities.RepositorySettingsActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|keyboard|keyboardHidden|navigation"/>

View File

@ -3,8 +3,7 @@ package org.mian.gitnex.activities;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.os.Handler;
import android.widget.ArrayAdapter;
import androidx.annotation.NonNull;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -22,7 +21,7 @@ import org.mian.gitnex.database.models.UserAccount;
import org.mian.gitnex.databinding.ActivityAddNewAccountBinding;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.PathsHelper;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.SnackBar;
import org.mian.gitnex.helpers.UrlHelper;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.structs.Protocol;
@ -34,7 +33,6 @@ import retrofit2.Callback;
*/
public class AddNewAccountActivity extends BaseActivity {
private View.OnClickListener onClickListener;
private ActivityAddNewAccountBinding viewBinding;
private String spinnerSelectedValue;
@ -52,8 +50,6 @@ public class AddNewAccountActivity extends BaseActivity {
getWindow().getDecorView().setBackground(new ColorDrawable(Color.TRANSPARENT));
initCloseListener();
viewBinding.close.setOnClickListener(onClickListener);
viewBinding.instanceUrl.setText(getIntent().getStringExtra("instanceUrl"));
viewBinding.loginToken.setText(getIntent().getStringExtra("token"));
String scheme = getIntent().getStringExtra("scheme");
@ -68,20 +64,22 @@ public class AddNewAccountActivity extends BaseActivity {
ArrayAdapter<Protocol> adapterProtocols =
new ArrayAdapter<>(ctx, R.layout.list_spinner_items, Protocol.values());
viewBinding.topAppBar.setNavigationOnClickListener(v -> finish());
viewBinding.protocolSpinner.setAdapter(adapterProtocols);
viewBinding.protocolSpinner.setOnItemClickListener(
(parent, view1, position, id) ->
spinnerSelectedValue = String.valueOf(parent.getItemAtPosition(position)));
viewBinding.addNewAccount.setOnClickListener(
login -> {
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
if (!connToInternet) {
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
} else {
viewBinding.topAppBar.setOnMenuItemClickListener(
menuItem -> {
int id = menuItem.getItemId();
if (id == R.id.addAccount) {
processLogin();
return true;
} else {
return super.onOptionsItemSelected(menuItem);
}
});
}
@ -102,19 +100,26 @@ public class AddNewAccountActivity extends BaseActivity {
if (protocol == null) {
Toasty.error(ctx, getResources().getString(R.string.protocolEmptyError));
SnackBar.error(
ctx,
findViewById(android.R.id.content),
getString(R.string.protocolEmptyError));
return;
}
if (instanceUrlET.equals("")) {
Toasty.error(ctx, getResources().getString(R.string.emptyFieldURL));
SnackBar.error(
ctx, findViewById(android.R.id.content), getString(R.string.emptyFieldURL));
return;
}
if (loginToken.equals("")) {
Toasty.error(ctx, getResources().getString(R.string.loginTokenError));
SnackBar.error(
ctx,
findViewById(android.R.id.content),
getString(R.string.loginTokenError));
return;
}
@ -132,7 +137,8 @@ public class AddNewAccountActivity extends BaseActivity {
} catch (Exception e) {
Toasty.error(ctx, getResources().getString(R.string.malformedUrl));
SnackBar.error(
ctx, findViewById(android.R.id.content), getString(R.string.malformedUrl));
}
}
@ -157,8 +163,10 @@ public class AddNewAccountActivity extends BaseActivity {
if (!Version.valid(version.getVersion())) {
Toasty.error(
ctx, getResources().getString(R.string.versionUnknown));
SnackBar.error(
ctx,
findViewById(android.R.id.content),
getString(R.string.versionUnknown));
return;
}
@ -192,12 +200,18 @@ public class AddNewAccountActivity extends BaseActivity {
login(instanceUrl, loginToken);
} else {
Toasty.warning(
SnackBar.error(
ctx,
getResources().getString(R.string.versionUnsupportedNew));
findViewById(android.R.id.content),
getString(R.string.versionUnsupportedNew));
login(instanceUrl, loginToken);
}
} else if (responseVersion.code() == 401) {
SnackBar.error(
ctx,
findViewById(android.R.id.content),
getString(R.string.unauthorizedApiError));
} else if (responseVersion.code() == 403) {
login(instanceUrl, loginToken);
@ -213,9 +227,10 @@ public class AddNewAccountActivity extends BaseActivity {
public void onFailure(
@NonNull Call<ServerVersion> callVersion, @NonNull Throwable t) {
Log.e("onFailure-versionCheck", t.toString());
Toasty.error(
ctx, getResources().getString(R.string.genericServerResponseError));
SnackBar.error(
ctx,
findViewById(android.R.id.content),
getString(R.string.genericServerResponseError));
}
});
}
@ -291,21 +306,20 @@ public class AddNewAccountActivity extends BaseActivity {
defaultPagingNumber);
UserAccount account = userAccountsApi.getAccountById((int) id);
AppUtil.switchToAccount(AddNewAccountActivity.this, account);
Toasty.success(
SnackBar.success(
ctx,
getResources().getString(R.string.accountAddedMessage));
findViewById(android.R.id.content),
getString(R.string.accountAddedMessage));
MainActivity.refActivity = true;
finish();
new Handler().postDelayed(() -> finish(), 3000);
} else {
UserAccount account =
userAccountsApi.getAccountByName(accountName);
if (account.isLoggedIn()) {
Toasty.warning(
SnackBar.error(
ctx,
getResources()
.getString(
R.string
.accountAlreadyExistsError));
findViewById(android.R.id.content),
getString(R.string.accountAlreadyExistsError));
AppUtil.switchToAccount(ctx, account);
} else {
userAccountsApi.updateTokenByAccountName(
@ -315,34 +329,31 @@ public class AddNewAccountActivity extends BaseActivity {
AddNewAccountActivity.this, account);
}
}
finish();
break;
case 401:
Toasty.error(
SnackBar.error(
ctx,
getResources().getString(R.string.unauthorizedApiError));
findViewById(android.R.id.content),
getString(R.string.unauthorizedApiError));
break;
default:
Toasty.error(
SnackBar.error(
ctx,
getResources()
.getString(
R.string.genericApiError, response.code()));
findViewById(android.R.id.content),
getString(R.string.genericApiError, response.code()));
}
}
@Override
public void onFailure(@NonNull Call<User> call, @NonNull Throwable t) {
Toasty.error(ctx, getResources().getString(R.string.genericError));
SnackBar.error(
ctx,
findViewById(android.R.id.content),
getString(R.string.genericError));
}
});
}
private void initCloseListener() {
onClickListener = view -> finish();
}
}

View File

@ -1,155 +1,134 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layoutNewAccount"
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/primaryBackgroundColor"
android:orientation="vertical">
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Widget.AppCompat.SearchView"
app:elevation="@dimen/dimen0dp"
app:layout_constraintTop_toTopOf="parent">
android:background="?attr/primaryBackgroundColor"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
<com.google.android.material.appbar.CollapsingToolbarLayout
style="?attr/collapsingToolbarLayoutLargeStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/primaryBackgroundColor">
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:contentScrim="?attr/primaryBackgroundColor"
android:layout_height="?attr/collapsingToolbarLayoutLargeSize">
<ImageView
android:id="@+id/close"
android:layout_width="@dimen/dimen26dp"
android:layout_height="@dimen/dimen26dp"
android:layout_marginStart="@dimen/dimen16dp"
android:layout_marginEnd="@dimen/dimen16dp"
android:contentDescription="@string/close"
android:gravity="center_vertical"
android:src="@drawable/ic_arrow_back"/>
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/topAppBar"
android:layout_width="match_parent"
android:elevation="0dp"
android:layout_height="?attr/actionBarSize"
app:title="@string/addNewAccount"
app:layout_collapseMode="pin"
app:menu="@menu/add_new_account_menu"
app:navigationIcon="@drawable/ic_arrow_back" />
<TextView
android:id="@+id/toolbarTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/dimen20dp"
android:ellipsize="none"
android:scrollbars="horizontal"
android:singleLine="true"
android:text="@string/addNewAccount"
android:textColor="?attr/primaryTextColor"
android:textSize="@dimen/dimen20sp"/>
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/dimen16dp"
app:layout_constraintTop_toTopOf="parent">
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/protocolSpinnerLayout"
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimen8dp"
android:layout_marginBottom="@dimen/dimen8dp"
android:hint="@string/protocol"
android:textColorHint="?attr/hintColor"
app:boxBackgroundColor="?attr/inputBackgroundColor"
app:endIconTint="?attr/iconsColor"
app:hintTextColor="?attr/hintColor">
android:orientation="vertical"
android:padding="@dimen/dimen16dp"
app:layout_constraintTop_toTopOf="parent">
<AutoCompleteTextView
android:id="@+id/protocolSpinner"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/protocolSpinnerLayout"
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="none"
android:labelFor="@+id/protocolSpinner"
android:textColor="?attr/inputTextColor"
android:textSize="@dimen/dimen16sp"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/instanceUrlLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimen8dp"
android:layout_marginBottom="@dimen/dimen8dp"
android:hint="@string/instanceUrl"
android:textColorHint="?attr/hintColor"
app:boxBackgroundColor="?attr/inputBackgroundColor"
app:boxStrokeErrorColor="@color/darkRed"
app:endIconMode="clear_text"
app:endIconTint="?attr/iconsColor"
app:hintTextColor="?attr/hintColor"
app:startIconDrawable="@drawable/ic_link"
app:startIconTint="?attr/iconsColor"
app:helperText="@string/instanceHelperText">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/instanceUrl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:singleLine="true"
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:layout_marginTop="@dimen/dimen8dp"
android:layout_marginBottom="@dimen/dimen8dp"
android:hint="@string/protocol"
android:textColorHint="?attr/hintColor"
android:textSize="@dimen/dimen16sp"/>
app:endIconTint="?attr/iconsColor"
app:hintTextColor="?attr/hintColor">
</com.google.android.material.textfield.TextInputLayout>
<AutoCompleteTextView
android:id="@+id/protocolSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="none"
android:labelFor="@+id/protocolSpinner"
android:textColor="?attr/inputTextColor"
android:textSize="@dimen/dimen16sp" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/loginTokenLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimen8dp"
android:layout_marginBottom="@dimen/dimen8dp"
android:hint="@string/copyToken"
android:textColorHint="?attr/hintColor"
app:boxBackgroundColor="?attr/inputBackgroundColor"
app:boxStrokeErrorColor="@color/darkRed"
app:endIconMode="clear_text"
app:endIconTint="?attr/iconsColor"
app:hintTextColor="?attr/hintColor"
app:startIconDrawable="@drawable/ic_lock"
app:startIconTint="?attr/iconsColor">
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/loginToken"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/instanceUrlLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:singleLine="true"
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:layout_marginTop="@dimen/dimen8dp"
android:layout_marginBottom="@dimen/dimen8dp"
android:hint="@string/instanceUrl"
android:textColorHint="?attr/hintColor"
android:textSize="@dimen/dimen16sp"/>
app:boxStrokeErrorColor="@color/darkRed"
app:endIconMode="clear_text"
app:endIconTint="?attr/iconsColor"
app:hintTextColor="?attr/hintColor"
app:startIconDrawable="@drawable/ic_link"
app:startIconTint="?attr/iconsColor"
app:helperText="@string/instanceHelperText">
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/instanceUrl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:singleLine="true"
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:textSize="@dimen/dimen16sp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/addNewAccount"
android:layout_width="match_parent"
android:layout_height="@dimen/dimen54dp"
android:layout_marginTop="@dimen/dimen8dp"
android:text="@string/addNewAccountText"
android:textColor="?attr/materialCardBackgroundColor"
android:textSize="@dimen/dimen16sp"
android:textStyle="bold"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/loginTokenLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimen8dp"
android:layout_marginBottom="@dimen/dimen8dp"
android:hint="@string/copyToken"
android:textColorHint="?attr/hintColor"
app:boxStrokeErrorColor="@color/darkRed"
app:endIconMode="clear_text"
app:endIconTint="?attr/iconsColor"
app:hintTextColor="?attr/hintColor"
app:startIconDrawable="@drawable/ic_lock"
app:startIconTint="?attr/iconsColor">
</LinearLayout>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/loginToken"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:singleLine="true"
android:textColor="?attr/inputTextColor"
android:textColorHighlight="?attr/hintColor"
android:textColorHint="?attr/hintColor"
android:textSize="@dimen/dimen16sp" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/addAccount"
android:orderInCategory="0"
android:title="@string/addNewAccountText"
app:showAsAction="ifRoom" />
</menu>

View File

@ -657,7 +657,7 @@
<string name="removeAccountPopupTitle">Remove Account</string>
<string name="removeAccountPopupMessage">Are you sure you want to remove this account from the app?\n\nThis will remove all the data related to this account on the app only.</string>
<string name="addNewAccount">New Account</string>
<string name="addNewAccountText">Add New Account</string>
<string name="addNewAccountText">Add Account</string>
<string name="accountAlreadyExistsError">Account already exists in the app</string>
<string name="accountAddedMessage">Account added successfully</string>
<string name="switchAccountSuccess">Switched to account : %1$s@%2$s</string>