diff options
author | Stefan Niedermann <info@niedermann.it> | 2023-04-13 18:36:16 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2023-04-13 18:48:01 +0300 |
commit | d605c77eb3157cf68b4de7dcd094465249acc38c (patch) | |
tree | da71cae2c345de3624db982c64e1dcd83702b369 /app/src | |
parent | d5ec0d0607d555aa7a0f365a2cb7f5a83f9e1257 (diff) |
feat(import): Improve import experience
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java | 38 | ||||
-rw-r--r-- | app/src/main/res/layout/activity_import_account.xml | 111 |
2 files changed, 87 insertions, 62 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java index c8c6447d0..0cdb85450 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java @@ -18,6 +18,8 @@ import androidx.core.content.ContextCompat; import androidx.lifecycle.ViewModelProvider; import androidx.preference.PreferenceManager; +import com.bumptech.glide.Glide; +import com.bumptech.glide.request.RequestOptions; import com.nextcloud.android.sso.AccountImporter; import com.nextcloud.android.sso.api.ParsedResponse; import com.nextcloud.android.sso.exceptions.AccountImportCancelledException; @@ -77,7 +79,7 @@ public class ImportAccountActivity extends AppCompatActivity { : getString(R.string.welcome_text, getString(R.string.app_name)))); binding.addButton.setOnClickListener((v) -> { - binding.status.setText(""); + binding.progressText.setText(""); binding.addButton.setEnabled(false); binding.updateDeckButton.setVisibility(View.GONE); try { @@ -113,16 +115,15 @@ public class ImportAccountActivity extends AppCompatActivity { AccountImporter.onActivityResult(requestCode, resultCode, data, ImportAccountActivity.this, new AccountImporter.IAccountAccessGranted() { @Override public void accountAccessGranted(SingleSignOnAccount account) { + final var accountToCreate = new Account(account.name, account.userId, account.url); + runOnUiThread(() -> { - binding.status.setText(null); - binding.status.setVisibility(View.GONE); binding.progressCircular.setVisibility(View.VISIBLE); - binding.progressText.setVisibility(View.VISIBLE); binding.progressCircular.setIndeterminate(true); binding.progressText.setText(R.string.progress_import_indeterminate); + setAvatar(accountToCreate); }); - final var accountToCreate = new Account(account.name, account.userId, account.url); importAccountViewModel.createAccount(accountToCreate, new IResponseCallback<>() { @Override public void onResponse(Account createdAccount) { @@ -235,6 +236,7 @@ public class ImportAccountActivity extends AppCompatActivity { } runOnUiThread(() -> binding.addButton.setEnabled(true)); restoreWifiPref(); + resetAvatar(); } }); } @@ -265,6 +267,28 @@ public class ImportAccountActivity extends AppCompatActivity { importAccountViewModel.deleteAccount(accountId); runOnUiThread(() -> binding.addButton.setEnabled(true)); restoreWifiPref(); + resetAvatar(); + } + + private void resetAvatar() { + runOnUiThread(() -> + Glide + .with(binding.image.getContext()) + .load(R.mipmap.ic_launcher) + .into(binding.image) + ); + } + + private void setAvatar(@NonNull Account account) { + runOnUiThread(() -> + Glide + .with(binding.image.getContext()) + .load(account.getAvatarUrl(binding.image.getWidth())) + .apply(RequestOptions.circleCropTransform()) + .placeholder(R.mipmap.ic_launcher) + .error(R.mipmap.ic_launcher) + .into(binding.image) + ); } private void setStatusText(@StringRes int statusText) { @@ -275,9 +299,7 @@ public class ImportAccountActivity extends AppCompatActivity { runOnUiThread(() -> { binding.updateDeckButton.setVisibility(View.GONE); binding.progressCircular.setVisibility(View.GONE); - binding.progressText.setVisibility(View.GONE); - binding.status.setVisibility(View.VISIBLE); - binding.status.setText(statusText); + binding.progressText.setText(statusText); }); } diff --git a/app/src/main/res/layout/activity_import_account.xml b/app/src/main/res/layout/activity_import_account.xml index b247804ed..c88808b48 100644 --- a/app/src/main/res/layout/activity_import_account.xml +++ b/app/src/main/res/layout/activity_import_account.xml @@ -7,93 +7,96 @@ android:layout_height="match_parent" android:fillViewport="true"> - <RelativeLayout - android:id="@+id/relativeLayout" + + <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="vertical" - android:padding="@dimen/spacer_2x"> + android:layout_height="wrap_content"> - <androidx.appcompat.widget.AppCompatImageView + <ImageView android:id="@+id/image" - android:layout_width="match_parent" + android:layout_width="96dp" android:layout_height="96dp" android:layout_above="@+id/welcome_text" android:layout_gravity="center" android:layout_marginBottom="32dp" android:contentDescription="@null" - android:tint="@color/fg_secondary" - app:srcCompat="@drawable/ic_app_logo" /> + android:src="@mipmap/ic_launcher" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + <com.google.android.material.progressindicator.CircularProgressIndicator + android:id="@+id/progress_circular" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:indeterminate="true" + android:indeterminateTint="@color/defaultBrand" + android:progressTint="@color/defaultBrand" + android:visibility="gone" + app:indicatorColor="@color/defaultBrand" + app:indicatorSize="104dp" + app:layout_constraintBottom_toBottomOf="@id/image" + app:layout_constraintEnd_toEndOf="@id/image" + app:layout_constraintStart_toStartOf="@id/image" + app:layout_constraintTop_toTopOf="@id/image" + app:trackCornerRadius="4dp" + app:trackThickness="4dp" + tools:visibility="visible" /> - <TextView + <com.google.android.material.textview.MaterialTextView android:id="@+id/welcome_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" + android:layout_marginTop="@dimen/spacer_3x" android:layout_marginBottom="48dp" android:gravity="center_horizontal" + android:text="@string/welcome_text" android:textSize="24sp" - tools:text="Welcome to Nextcloud Deck" /> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/image" /> - <Button + <com.google.android.material.button.MaterialButton android:id="@+id/add_button" - style="@style/Widget.Material3.Button.ElevatedButton" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_below="@id/welcome_text" - android:layout_centerHorizontal="true" - android:paddingHorizontal="32dp" - android:paddingVertical="24dp" - android:text="@string/choose_account" - app:backgroundTint="@color/defaultBrand" /> - - <TextView - android:id="@+id/status" + style="@style/Widget.Material3.Button" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_below="@id/add_button" - android:layout_centerHorizontal="true" - android:layout_marginTop="32dp" - android:gravity="center_horizontal" - android:textAlignment="center" - android:textColor="@color/fg_secondary" - android:textSize="18sp" - tools:text="@string/you_have_to_be_connected_to_the_internet_in_order_to_add_an_account" /> - - <ProgressBar - android:id="@+id/progress_circular" - style="?android:attr/progressBarStyleHorizontal" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_below="@id/add_button" - android:layout_centerHorizontal="true" android:layout_marginTop="@dimen/spacer_4x" - android:indeterminate="true" - android:indeterminateTint="@color/defaultBrand" - android:progressTint="@color/defaultBrand" - android:visibility="gone" /> + android:backgroundTint="@color/defaultBrand" + android:paddingHorizontal="@dimen/spacer_4x" + android:paddingVertical="@dimen/spacer_3x" + android:text="@string/choose_account" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/welcome_text" /> - <TextView + <com.google.android.material.textview.MaterialTextView android:id="@+id/progress_text" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_below="@id/progress_circular" - android:layout_centerHorizontal="true" - android:layout_marginTop="@dimen/spacer_2x" - android:visibility="gone" - tools:text="@string/progress_import_indeterminate" /> + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/add_button" + tools:maxLength="40" + tools:text="@tools:sample/lorem/random" /> - <Button + <com.google.android.material.button.MaterialButton android:id="@+id/update_deck_button" - style="@style/Widget.AppCompat.Button.Borderless.Colored" + style="@style/Widget.Material3.Button.OutlinedButton" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_below="@id/status" android:layout_centerHorizontal="true" android:layout_marginTop="16dp" android:text="@string/simple_update" android:textColor="@color/defaultBrand" android:visibility="gone" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/progress_text" tools:visibility="visible" /> - </RelativeLayout> + </androidx.constraintlayout.widget.ConstraintLayout> + </ScrollView>
\ No newline at end of file |