mirror of https://codeberg.org/gitnex/GitNex.git
Redesign add email screen
This commit is contained in:
parent
079f118b84
commit
8f4c3e5206
|
@ -54,7 +54,8 @@
|
|||
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|keyboard|keyboardHidden|navigation"/>
|
||||
<activity
|
||||
android:name=".activities.AccountSettingsEmailActivity"
|
||||
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.AddCollaboratorToRepositoryActivity"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|keyboard|keyboardHidden|navigation"/>
|
||||
|
@ -73,7 +74,8 @@
|
|||
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|keyboard|keyboardHidden|navigation"/>
|
||||
<activity
|
||||
android:name=".activities.CreateIssueActivity"
|
||||
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.CreateMilestoneActivity"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|keyboard|keyboardHidden|navigation"/>
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.os.Handler;
|
||||
import android.util.Patterns;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import androidx.annotation.NonNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -18,8 +15,7 @@ import org.mian.gitnex.clients.RetrofitClient;
|
|||
import org.mian.gitnex.databinding.ActivityAccountSettingsEmailBinding;
|
||||
import org.mian.gitnex.fragments.AccountSettingsEmailsFragment;
|
||||
import org.mian.gitnex.helpers.AlertDialogs;
|
||||
import org.mian.gitnex.helpers.AppUtil;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.SnackBar;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
|
||||
|
@ -28,8 +24,6 @@ import retrofit2.Callback;
|
|||
*/
|
||||
public class AccountSettingsEmailActivity extends BaseActivity {
|
||||
|
||||
private View.OnClickListener onClickListener;
|
||||
private final View.OnClickListener addEmailListener = v -> processAddNewEmail();
|
||||
private ActivityAccountSettingsEmailBinding activityAccountSettingsEmailBinding;
|
||||
|
||||
@Override
|
||||
|
@ -41,56 +35,42 @@ public class AccountSettingsEmailActivity extends BaseActivity {
|
|||
ActivityAccountSettingsEmailBinding.inflate(getLayoutInflater());
|
||||
setContentView(activityAccountSettingsEmailBinding.getRoot());
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
activityAccountSettingsEmailBinding.topAppBar.setNavigationOnClickListener(v -> finish());
|
||||
|
||||
InputMethodManager imm =
|
||||
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
activityAccountSettingsEmailBinding.topAppBar.setOnMenuItemClickListener(
|
||||
menuItem -> {
|
||||
int id = menuItem.getItemId();
|
||||
|
||||
activityAccountSettingsEmailBinding.userEmail.requestFocus();
|
||||
assert imm != null;
|
||||
imm.showSoftInput(
|
||||
activityAccountSettingsEmailBinding.userEmail, InputMethodManager.SHOW_IMPLICIT);
|
||||
|
||||
initCloseListener();
|
||||
activityAccountSettingsEmailBinding.close.setOnClickListener(onClickListener);
|
||||
|
||||
if (!connToInternet) {
|
||||
|
||||
disableProcessButton();
|
||||
} else {
|
||||
|
||||
activityAccountSettingsEmailBinding.addEmailButton.setOnClickListener(addEmailListener);
|
||||
}
|
||||
if (id == R.id.save) {
|
||||
processAddNewEmail();
|
||||
return true;
|
||||
} else {
|
||||
return super.onOptionsItemSelected(menuItem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void processAddNewEmail() {
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
|
||||
String newUserEmail =
|
||||
Objects.requireNonNull(activityAccountSettingsEmailBinding.userEmail.getText())
|
||||
.toString()
|
||||
.trim();
|
||||
|
||||
if (!connToInternet) {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
return;
|
||||
}
|
||||
|
||||
if (newUserEmail.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.emailErrorEmpty));
|
||||
SnackBar.error(
|
||||
ctx, findViewById(android.R.id.content), getString(R.string.emailErrorEmpty));
|
||||
return;
|
||||
} else if (!Patterns.EMAIL_ADDRESS.matcher(newUserEmail).matches()) {
|
||||
|
||||
Toasty.warning(ctx, getString(R.string.emailErrorInvalid));
|
||||
SnackBar.error(
|
||||
ctx, findViewById(android.R.id.content), getString(R.string.emailErrorInvalid));
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> newEmailList = new ArrayList<>(Arrays.asList(newUserEmail.split(",")));
|
||||
|
||||
disableProcessButton();
|
||||
addNewEmail(newEmailList);
|
||||
}
|
||||
|
||||
|
@ -111,54 +91,44 @@ public class AccountSettingsEmailActivity extends BaseActivity {
|
|||
|
||||
if (response.code() == 201) {
|
||||
|
||||
Toasty.success(ctx, getString(R.string.emailAddedText));
|
||||
SnackBar.info(
|
||||
ctx,
|
||||
findViewById(android.R.id.content),
|
||||
getString(R.string.emailAddedText));
|
||||
AccountSettingsEmailsFragment.refreshEmails = true;
|
||||
enableProcessButton();
|
||||
finish();
|
||||
new Handler().postDelayed(() -> finish(), 3000);
|
||||
} else if (response.code() == 401) {
|
||||
|
||||
enableProcessButton();
|
||||
AlertDialogs.authorizationTokenRevokedDialog(ctx);
|
||||
} else if (response.code() == 403) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||
SnackBar.error(
|
||||
ctx,
|
||||
findViewById(android.R.id.content),
|
||||
getString(R.string.authorizeError));
|
||||
} else if (response.code() == 404) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
||||
SnackBar.error(
|
||||
ctx,
|
||||
findViewById(android.R.id.content),
|
||||
getString(R.string.apiNotFound));
|
||||
} else if (response.code() == 422) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.warning(ctx, ctx.getString(R.string.emailErrorInUse));
|
||||
SnackBar.error(
|
||||
ctx,
|
||||
findViewById(android.R.id.content),
|
||||
getString(R.string.emailErrorInUse));
|
||||
} else {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, getString(R.string.genericError));
|
||||
SnackBar.error(
|
||||
ctx,
|
||||
findViewById(android.R.id.content),
|
||||
getString(R.string.genericError));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Email>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
enableProcessButton();
|
||||
}
|
||||
public void onFailure(@NonNull Call<List<Email>> call, @NonNull Throwable t) {}
|
||||
});
|
||||
}
|
||||
|
||||
private void initCloseListener() {
|
||||
|
||||
onClickListener = view -> finish();
|
||||
}
|
||||
|
||||
private void disableProcessButton() {
|
||||
|
||||
activityAccountSettingsEmailBinding.addEmailButton.setEnabled(false);
|
||||
}
|
||||
|
||||
private void enableProcessButton() {
|
||||
|
||||
activityAccountSettingsEmailBinding.addEmailButton.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,72 +1,63 @@
|
|||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<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">
|
||||
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"
|
||||
tools:ignore="UnusedAttribute">
|
||||
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:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:clickable="true"
|
||||
android:contentDescription="@string/close"
|
||||
android:focusable="true"
|
||||
android:gravity="center_vertical"
|
||||
android:src="@drawable/ic_close"/>
|
||||
<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/pageTitleAddEmail"
|
||||
app:layout_collapseMode="pin"
|
||||
app:menu="@menu/save"
|
||||
app:navigationIcon="@drawable/ic_close" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toolbar_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:text="@string/pageTitleAddEmail"
|
||||
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">
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/userEmailLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dimen8dp"
|
||||
android:layout_marginBottom="@dimen/dimen8dp"
|
||||
android:hint="@string/accountEmailTitle"
|
||||
android:textColorHint="?attr/hintColor"
|
||||
app:boxBackgroundColor="?attr/inputBackgroundColor"
|
||||
app:boxStrokeErrorColor="@color/darkRed"
|
||||
app:endIconMode="clear_text"
|
||||
app:endIconTint="?attr/iconsColor"
|
||||
app:hintTextColor="?attr/hintColor">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/dimen16dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/userEmailLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dimen8dp"
|
||||
android:layout_marginBottom="@dimen/dimen8dp"
|
||||
android:hint="@string/accountEmailTitle"
|
||||
android:textColorHint="?attr/hintColor"
|
||||
app:boxBackgroundColor="?attr/inputBackgroundColor"
|
||||
app:boxStrokeErrorColor="@color/darkRed"
|
||||
app:endIconMode="clear_text"
|
||||
app:endIconTint="?attr/iconsColor"
|
||||
app:hintTextColor="?attr/hintColor">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/userEmail"
|
||||
|
@ -79,15 +70,8 @@
|
|||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/addEmailButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dimen54dp"
|
||||
android:layout_marginTop="@dimen/dimen8dp"
|
||||
android:text="@string/saveButton"
|
||||
android:textColor="?attr/materialCardBackgroundColor"
|
||||
android:textStyle="bold"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
<item
|
||||
android:id="@+id/save"
|
||||
android:icon="@drawable/ic_save"
|
||||
android:orderInCategory="1"
|
||||
android:title="@string/saveButton"
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
|
Loading…
Reference in New Issue