mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-24 10:51:27 +01:00
Fix loading states for username editing.
This commit is contained in:
@@ -49,7 +49,6 @@ public class UsernameEditFragment extends LoggingFragment {
|
|||||||
|
|
||||||
private UsernameEditViewModel viewModel;
|
private UsernameEditViewModel viewModel;
|
||||||
private UsernameEditFragmentBinding binding;
|
private UsernameEditFragmentBinding binding;
|
||||||
private ImageView suffixProgress;
|
|
||||||
private LifecycleDisposable lifecycleDisposable;
|
private LifecycleDisposable lifecycleDisposable;
|
||||||
private UsernameEditFragmentArgs args;
|
private UsernameEditFragmentArgs args;
|
||||||
|
|
||||||
@@ -128,23 +127,10 @@ public class UsernameEditFragment extends LoggingFragment {
|
|||||||
pipe.setBounds(0, 0, (int) DimensionUnit.DP.toPixels(1f), (int) DimensionUnit.DP.toPixels(20f));
|
pipe.setBounds(0, 0, (int) DimensionUnit.DP.toPixels(1f), (int) DimensionUnit.DP.toPixels(20f));
|
||||||
suffixTextView.setCompoundDrawablesRelative(pipe, null, null, null);
|
suffixTextView.setCompoundDrawablesRelative(pipe, null, null, null);
|
||||||
|
|
||||||
LinearLayout suffixParent = (LinearLayout) suffixTextView.getParent();
|
|
||||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
||||||
|
|
||||||
ViewUtil.setLeftMargin(suffixTextView, (int) DimensionUnit.DP.toPixels(16f));
|
ViewUtil.setLeftMargin(suffixTextView, (int) DimensionUnit.DP.toPixels(16f));
|
||||||
|
|
||||||
binding.usernameTextWrapper.getSuffixTextView().setCompoundDrawablePadding((int) DimensionUnit.DP.toPixels(16f));
|
binding.usernameTextWrapper.getSuffixTextView().setCompoundDrawablePadding((int) DimensionUnit.DP.toPixels(16f));
|
||||||
|
|
||||||
layoutParams.topMargin = suffixTextView.getPaddingTop();
|
|
||||||
layoutParams.bottomMargin = suffixTextView.getPaddingBottom();
|
|
||||||
layoutParams.setMarginEnd(suffixTextView.getPaddingEnd());
|
|
||||||
|
|
||||||
suffixProgress = new ImageView(requireContext());
|
|
||||||
suffixProgress.setImageDrawable(getInProgressDrawable());
|
|
||||||
suffixProgress.setContentDescription(getString(R.string.load_more_header__loading));
|
|
||||||
suffixProgress.setVisibility(View.GONE);
|
|
||||||
suffixParent.addView(suffixProgress, 0, layoutParams);
|
|
||||||
|
|
||||||
suffixTextView.setOnClickListener(this::onLearnMore);
|
suffixTextView.setOnClickListener(this::onLearnMore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +138,6 @@ public class UsernameEditFragment extends LoggingFragment {
|
|||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
binding = null;
|
binding = null;
|
||||||
suffixProgress = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onLearnMore(@Nullable View unused) {
|
private void onLearnMore(@Nullable View unused) {
|
||||||
@@ -216,10 +201,14 @@ public class UsernameEditFragment extends LoggingFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void presentSummary(@NonNull UsernameState usernameState) {
|
private void presentSummary(@NonNull UsernameState usernameState) {
|
||||||
if (usernameState.getUsername() != null || usernameState instanceof UsernameState.Loading) {
|
if (usernameState.getUsername() != null) {
|
||||||
binding.summary.setText(usernameState.getUsername());
|
binding.summary.setText(usernameState.getUsername());
|
||||||
|
binding.summary.setAlpha(1f);
|
||||||
|
} else if (usernameState instanceof UsernameState.Loading) {
|
||||||
|
binding.summary.setAlpha(0.5f);
|
||||||
} else {
|
} else {
|
||||||
binding.summary.setText(R.string.UsernameEditFragment__choose_your_username);
|
binding.summary.setText(R.string.UsernameEditFragment__choose_your_username);
|
||||||
|
binding.summary.setAlpha(1f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,25 +293,12 @@ public class UsernameEditFragment extends LoggingFragment {
|
|||||||
boolean isInProgress = usernameState.isInProgress();
|
boolean isInProgress = usernameState.isInProgress();
|
||||||
|
|
||||||
if (isInProgress) {
|
if (isInProgress) {
|
||||||
suffixProgress.setVisibility(View.VISIBLE);
|
binding.suffixProgress.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
suffixProgress.setVisibility(View.GONE);
|
binding.suffixProgress.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IndeterminateDrawable<CircularProgressIndicatorSpec> getInProgressDrawable() {
|
|
||||||
CircularProgressIndicatorSpec spec = new CircularProgressIndicatorSpec(requireContext(), null);
|
|
||||||
spec.indicatorInset = 0;
|
|
||||||
spec.indicatorSize = (int) DimensionUnit.DP.toPixels(16f);
|
|
||||||
spec.trackColor = ContextCompat.getColor(requireContext(), R.color.signal_colorOnSurfaceVariant);
|
|
||||||
spec.trackThickness = (int) DimensionUnit.DP.toPixels(1f);
|
|
||||||
|
|
||||||
IndeterminateDrawable<CircularProgressIndicatorSpec> drawable = IndeterminateDrawable.createCircularDrawable(requireContext(), spec);
|
|
||||||
drawable.setBounds(0, 0, spec.indicatorSize, spec.indicatorSize);
|
|
||||||
|
|
||||||
return drawable;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onEvent(@NonNull UsernameEditViewModel.Event event) {
|
private void onEvent(@NonNull UsernameEditViewModel.Event event) {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case SUBMIT_SUCCESS:
|
case SUBMIT_SUCCESS:
|
||||||
|
|||||||
@@ -70,6 +70,19 @@
|
|||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||||
|
android:id="@+id/suffix_progress"
|
||||||
|
android:layout_width="16dp"
|
||||||
|
android:layout_height="16dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="@id/username_text_wrapper"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@id/username_text_wrapper"
|
||||||
|
app:indicatorSize="16dp"
|
||||||
|
app:trackThickness="1dp"
|
||||||
|
app:trackColor="@color/transparent"
|
||||||
|
app:indicatorColor="@color/signal_colorOnSurfaceVariant"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/username_error"
|
android:id="@+id/username_error"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.util
|
|||||||
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.thoughtcrime.securesms.assertIs
|
import org.thoughtcrime.securesms.assertIs
|
||||||
import org.thoughtcrime.securesms.assertIsNotNull
|
|
||||||
import org.thoughtcrime.securesms.assertIsNull
|
import org.thoughtcrime.securesms.assertIsNull
|
||||||
import org.thoughtcrime.securesms.util.UsernameUtil.checkUsername
|
import org.thoughtcrime.securesms.util.UsernameUtil.checkUsername
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user