mirror of
https://github.com/oxen-io/session-android.git
synced 2025-03-13 21:30:56 +00:00
Add length limit feedback when setting profile name
// FREEBIE
This commit is contained in:
parent
3e22c37425
commit
beed9d8034
@ -18,12 +18,13 @@
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginStart="10dp">
|
||||
|
||||
<TextView android:id="@+id/profile_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:textSize="20sp"
|
||||
tools:text="Voltarine DeClyre"/>
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
||||
android:id="@+id/profile_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:textSize="20sp"
|
||||
tools:text="Voltarine DeClyre"/>
|
||||
|
||||
<TextView android:id="@+id/number"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -237,6 +237,7 @@
|
||||
<string name="CreateProfileActivity_updating_profile">Updating profile</string>
|
||||
<string name="CreateProfileActivity_updating_and_encrypting_profile">Updating and encrypting profile</string>
|
||||
<string name="CreateProfileActivity_profile_photo">Profile photo</string>
|
||||
<string name="CreateProfileActivity_too_long">Too long</string>
|
||||
|
||||
<!-- CustomDefaultPreference -->
|
||||
<string name="CustomDefaultPreference_using_custom">Using custom: %s</string>
|
||||
@ -1446,6 +1447,7 @@
|
||||
<string name="transport_selection_list_item__transport_icon">Transport icon</string>
|
||||
|
||||
|
||||
|
||||
<!-- EOF -->
|
||||
|
||||
</resources>
|
||||
|
@ -42,6 +42,7 @@ import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.AppearancePreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.CorrectedPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.NotificationsPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.ProfilePreference;
|
||||
import org.thoughtcrime.securesms.preferences.SmsMmsPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.preferences.ChatsPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
@ -171,6 +172,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
}
|
||||
|
||||
private void setCategorySummaries() {
|
||||
((ProfilePreference)this.findPreference(PREFERENCE_CATEGORY_PROFILE)).refresh();
|
||||
|
||||
this.findPreference(PREFERENCE_CATEGORY_SMS_MMS)
|
||||
.setSummary(SmsMmsPreferenceFragment.getSummary(getActivity()));
|
||||
this.findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS)
|
||||
@ -284,7 +287,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
Intent intent = new Intent(preference.getContext(), CreateProfileActivity.class);
|
||||
intent.putExtra(CreateProfileActivity.EXCLUDE_SYSTEM, true);
|
||||
|
||||
((BaseActionBarActivity)getActivity()).startActivitySceneTransition(intent, getActivity().findViewById(R.id.avatar), "avatar");
|
||||
getActivity().startActivity(intent);
|
||||
// ((BaseActionBarActivity)getActivity()).startActivitySceneTransition(intent, getActivity().findViewById(R.id.avatar), "avatar");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,9 @@ import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.KeyEvent;
|
||||
@ -48,6 +50,7 @@ import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
||||
import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask;
|
||||
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
||||
import org.whispersystems.signalservice.api.crypto.ProfileCipher;
|
||||
import org.whispersystems.signalservice.api.util.StreamDetails;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@ -177,6 +180,23 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i
|
||||
startActivityForResult(chooserIntent, REQUEST_CODE_AVATAR);
|
||||
});
|
||||
|
||||
this.name.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (s.toString().getBytes().length > ProfileCipher.NAME_PADDED_LENGTH) {
|
||||
name.setError(getString(R.string.CreateProfileActivity_too_long));
|
||||
finishButton.setEnabled(false);
|
||||
} else if (name.getError() != null || !finishButton.isEnabled()) {
|
||||
name.setError(null);
|
||||
finishButton.setEnabled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.finishButton.setOnClickListener(view -> {
|
||||
handleUpload();
|
||||
});
|
||||
|
@ -83,6 +83,7 @@ public class ContactPhotoFactory {
|
||||
.load(new AvatarPhotoUri(address))
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.skipMemoryCache(true)
|
||||
.centerCrop()
|
||||
.into(targetSize, targetSize)
|
||||
.get();
|
||||
|
@ -2,9 +2,12 @@ package org.thoughtcrime.securesms.preferences;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.preference.Preference;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
@ -16,11 +19,16 @@ import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhotoFactory;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
|
||||
public class ProfilePreference extends Preference {
|
||||
|
||||
private ImageView avatarView;
|
||||
private TextView profileNameView;
|
||||
private TextView profileNumberView;
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public ProfilePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
@ -50,27 +58,42 @@ public class ProfilePreference extends Preference {
|
||||
protected void onBindView(View view) {
|
||||
super.onBindView(view);
|
||||
|
||||
final ImageView avatar = ViewUtil.findById(view, R.id.avatar);
|
||||
final TextView profileName = ViewUtil.findById(view, R.id.profile_name);
|
||||
final TextView profileNumber = ViewUtil.findById(view, R.id.number);
|
||||
final Address localAddress = Address.fromSerialized(TextSecurePreferences.getLocalNumber(getContext()));
|
||||
avatarView = ViewUtil.findById(view, R.id.avatar);
|
||||
profileNameView = ViewUtil.findById(view, R.id.profile_name);
|
||||
profileNumberView = ViewUtil.findById(view, R.id.number);
|
||||
|
||||
new AsyncTask<Void, Void, ContactPhoto>() {
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
if (profileNumberView == null) return;
|
||||
|
||||
final Address localAddress = Address.fromSerialized(TextSecurePreferences.getLocalNumber(getContext()));
|
||||
final String profileName = TextSecurePreferences.getProfileName(getContext());
|
||||
|
||||
new AsyncTask<Void, Void, Drawable>() {
|
||||
@Override
|
||||
protected ContactPhoto doInBackground(Void... params) {
|
||||
return ContactPhotoFactory.getSignalAvatarContactPhoto(getContext(), localAddress, null, getContext().getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size));
|
||||
protected @NonNull Drawable doInBackground(Void... params) {
|
||||
if (AvatarHelper.getAvatarFile(getContext(), localAddress).exists()) {
|
||||
return ContactPhotoFactory.getSignalAvatarContactPhoto(getContext(), localAddress, profileName,
|
||||
getContext().getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size))
|
||||
.asDrawable(getContext(), 0);
|
||||
} else {
|
||||
return ContactPhotoFactory.getResourceContactPhoto(R.drawable.ic_camera_alt_white_24dp)
|
||||
.asDrawable(getContext(), getContext().getResources().getColor(R.color.grey_400));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(ContactPhoto contactPhoto) {
|
||||
avatar.setImageDrawable(contactPhoto.asDrawable(getContext(), 0));
|
||||
protected void onPostExecute(@NonNull Drawable contactPhoto) {
|
||||
avatarView.setImageDrawable(contactPhoto);
|
||||
}
|
||||
}.execute();
|
||||
|
||||
if (!TextUtils.isEmpty(TextSecurePreferences.getProfileName(getContext()))) {
|
||||
profileName.setText(TextSecurePreferences.getProfileName(getContext()));
|
||||
if (!TextUtils.isEmpty(profileName)) {
|
||||
profileNameView.setText(profileName);
|
||||
}
|
||||
|
||||
profileNumber.setText(localAddress.toPhoneString());
|
||||
profileNumberView.setText(localAddress.toPhoneString());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user