2017-08-08 16:37:15 -07:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
|
2017-11-24 22:00:30 -08:00
|
|
|
import android.Manifest;
|
2017-10-01 18:11:42 -07:00
|
|
|
import android.animation.Animator;
|
2017-11-14 10:22:54 -08:00
|
|
|
import android.annotation.SuppressLint;
|
2017-08-08 16:37:15 -07:00
|
|
|
import android.app.Activity;
|
2017-10-01 18:11:42 -07:00
|
|
|
import android.content.Context;
|
2017-08-08 16:37:15 -07:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.net.Uri;
|
2017-08-15 21:03:31 -07:00
|
|
|
import android.os.AsyncTask;
|
2017-10-01 18:11:42 -07:00
|
|
|
import android.os.Build;
|
2017-08-08 16:37:15 -07:00
|
|
|
import android.os.Bundle;
|
2017-11-24 22:00:30 -08:00
|
|
|
import android.support.annotation.NonNull;
|
2017-10-01 18:11:42 -07:00
|
|
|
import android.support.annotation.RequiresApi;
|
2017-08-24 17:40:35 -07:00
|
|
|
import android.text.Editable;
|
2017-08-08 16:37:15 -07:00
|
|
|
import android.text.TextUtils;
|
2017-08-24 17:40:35 -07:00
|
|
|
import android.text.TextWatcher;
|
2019-02-13 11:52:55 -08:00
|
|
|
|
2019-03-18 16:09:57 -03:00
|
|
|
import org.thoughtcrime.securesms.avatar.AvatarSelection;
|
2019-02-13 11:52:55 -08:00
|
|
|
import org.thoughtcrime.securesms.components.LabeledEditText;
|
2018-08-01 11:09:24 -04:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2017-08-08 16:37:15 -07:00
|
|
|
import android.view.KeyEvent;
|
2017-10-01 18:11:42 -07:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewAnimationUtils;
|
2017-08-08 16:37:15 -07:00
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.widget.ImageView;
|
2017-09-03 19:44:33 -07:00
|
|
|
import android.widget.TextView;
|
2017-08-08 16:37:15 -07:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
2017-11-14 10:40:15 -08:00
|
|
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
2017-10-01 18:11:42 -07:00
|
|
|
import com.dd.CircularProgressButton;
|
2017-08-08 16:37:15 -07:00
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.components.InputAwareLayout;
|
|
|
|
import org.thoughtcrime.securesms.components.emoji.EmojiDrawer;
|
|
|
|
import org.thoughtcrime.securesms.components.emoji.EmojiToggle;
|
2017-10-16 13:11:42 -07:00
|
|
|
import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto;
|
2017-08-25 12:00:52 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil;
|
2017-08-15 21:03:31 -07:00
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
2017-08-08 16:37:15 -07:00
|
|
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
2017-08-25 12:00:52 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob;
|
2017-10-16 13:11:42 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
2017-11-24 22:00:30 -08:00
|
|
|
import org.thoughtcrime.securesms.permissions.Permissions;
|
2017-08-15 21:03:31 -07:00
|
|
|
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
2017-08-08 16:37:15 -07:00
|
|
|
import org.thoughtcrime.securesms.profiles.ProfileMediaConstraints;
|
|
|
|
import org.thoughtcrime.securesms.profiles.SystemProfileUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
|
|
|
import org.thoughtcrime.securesms.util.BitmapUtil;
|
2017-09-26 17:31:28 -05:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
2019-02-13 11:52:55 -08:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicRegistrationTheme;
|
2017-09-26 17:31:28 -05:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2017-08-08 16:37:15 -07:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
|
|
|
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
2017-08-24 17:40:35 -07:00
|
|
|
import org.whispersystems.signalservice.api.crypto.ProfileCipher;
|
2017-08-08 16:37:15 -07:00
|
|
|
import org.whispersystems.signalservice.api.util.StreamDetails;
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2017-10-16 13:11:42 -07:00
|
|
|
import java.security.SecureRandom;
|
2017-08-08 16:37:15 -07:00
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
2017-11-14 10:22:54 -08:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
2017-09-06 00:29:49 -07:00
|
|
|
public class CreateProfileActivity extends BaseActionBarActivity implements InjectableType {
|
2017-08-08 16:37:15 -07:00
|
|
|
|
|
|
|
private static final String TAG = CreateProfileActivity.class.getSimpleName();
|
|
|
|
|
2017-08-16 12:01:26 -07:00
|
|
|
public static final String NEXT_INTENT = "next_intent";
|
|
|
|
public static final String EXCLUDE_SYSTEM = "exclude_system";
|
|
|
|
|
2019-02-13 11:52:55 -08:00
|
|
|
private final DynamicTheme dynamicTheme = new DynamicRegistrationTheme();
|
2017-09-26 17:31:28 -05:00
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
|
2017-08-08 16:37:15 -07:00
|
|
|
@Inject SignalServiceAccountManager accountManager;
|
|
|
|
|
2017-10-01 18:11:42 -07:00
|
|
|
private InputAwareLayout container;
|
|
|
|
private ImageView avatar;
|
|
|
|
private CircularProgressButton finishButton;
|
2019-02-13 11:52:55 -08:00
|
|
|
private LabeledEditText name;
|
2017-10-01 18:11:42 -07:00
|
|
|
private EmojiToggle emojiToggle;
|
|
|
|
private EmojiDrawer emojiDrawer;
|
|
|
|
private View reveal;
|
2017-08-08 16:37:15 -07:00
|
|
|
|
2017-08-16 12:01:26 -07:00
|
|
|
private Intent nextIntent;
|
2017-08-08 16:37:15 -07:00
|
|
|
private byte[] avatarBytes;
|
2017-08-16 12:01:26 -07:00
|
|
|
private File captureFile;
|
2017-08-08 16:37:15 -07:00
|
|
|
|
|
|
|
@Override
|
2017-09-06 00:29:49 -07:00
|
|
|
public void onCreate(Bundle bundle) {
|
|
|
|
super.onCreate(bundle);
|
2017-08-08 16:37:15 -07:00
|
|
|
|
2017-09-26 17:31:28 -05:00
|
|
|
dynamicTheme.onCreate(this);
|
|
|
|
dynamicLanguage.onCreate(this);
|
|
|
|
|
2017-08-08 16:37:15 -07:00
|
|
|
setContentView(R.layout.profile_create_activity);
|
|
|
|
|
|
|
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
|
|
|
|
initializeResources();
|
|
|
|
initializeEmojiInput();
|
2017-08-16 12:01:26 -07:00
|
|
|
initializeProfileName(getIntent().getBooleanExtra(EXCLUDE_SYSTEM, false));
|
|
|
|
initializeProfileAvatar(getIntent().getBooleanExtra(EXCLUDE_SYSTEM, false));
|
2017-08-08 16:37:15 -07:00
|
|
|
|
|
|
|
ApplicationContext.getInstance(this).injectDependencies(this);
|
|
|
|
}
|
|
|
|
|
2017-09-26 17:31:28 -05:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
|
|
|
dynamicLanguage.onResume(this);
|
|
|
|
}
|
|
|
|
|
2017-08-08 16:37:15 -07:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2019-02-13 11:52:55 -08:00
|
|
|
if (container.isInputOpen()) container.hideCurrentInput(name.getInput());
|
2017-08-08 16:37:15 -07:00
|
|
|
else super.onBackPressed();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
|
|
|
|
if (container.getCurrentInput() == emojiDrawer) {
|
|
|
|
container.hideAttachedInput(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-24 22:00:30 -08:00
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
|
|
|
|
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
|
|
|
|
}
|
|
|
|
|
2017-08-08 16:37:15 -07:00
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
|
|
|
switch (requestCode) {
|
2019-03-18 16:09:57 -03:00
|
|
|
case AvatarSelection.REQUEST_CODE_AVATAR:
|
2017-09-06 16:16:01 -07:00
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
2017-08-08 16:37:15 -07:00
|
|
|
Uri outputFile = Uri.fromFile(new File(getCacheDir(), "cropped"));
|
2017-09-06 16:16:01 -07:00
|
|
|
Uri inputFile = (data != null ? data.getData() : null);
|
2017-08-15 21:03:31 -07:00
|
|
|
|
|
|
|
if (inputFile == null && captureFile != null) {
|
|
|
|
inputFile = Uri.fromFile(captureFile);
|
|
|
|
}
|
|
|
|
|
2017-09-06 16:16:01 -07:00
|
|
|
if (data != null && data.getBooleanExtra("delete", false)) {
|
2017-08-16 12:01:26 -07:00
|
|
|
avatarBytes = null;
|
2017-10-16 13:11:42 -07:00
|
|
|
avatar.setImageDrawable(new ResourceContactPhoto(R.drawable.ic_camera_alt_white_24dp).asDrawable(this, getResources().getColor(R.color.grey_400)));
|
2017-08-16 12:01:26 -07:00
|
|
|
} else {
|
2019-03-18 16:09:57 -03:00
|
|
|
AvatarSelection.circularCropImage(this, inputFile, outputFile, R.string.CropImageActivity_profile_avatar);
|
2017-08-16 12:01:26 -07:00
|
|
|
}
|
2017-08-08 16:37:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2019-03-18 16:09:57 -03:00
|
|
|
case AvatarSelection.REQUEST_CODE_CROP_IMAGE:
|
2017-08-08 16:37:15 -07:00
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
2017-10-16 13:11:42 -07:00
|
|
|
new AsyncTask<Void, Void, byte[]>() {
|
|
|
|
@Override
|
|
|
|
protected byte[] doInBackground(Void... params) {
|
|
|
|
try {
|
2019-03-18 16:09:57 -03:00
|
|
|
BitmapUtil.ScaleResult result = BitmapUtil.createScaledBytes(CreateProfileActivity.this, AvatarSelection.getResultUri(data), new ProfileMediaConstraints());
|
2018-03-18 16:04:33 -07:00
|
|
|
return result.getBitmap();
|
2017-10-16 13:11:42 -07:00
|
|
|
} catch (BitmapDecodingException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(byte[] result) {
|
|
|
|
if (result != null) {
|
|
|
|
avatarBytes = result;
|
|
|
|
GlideApp.with(CreateProfileActivity.this)
|
|
|
|
.load(avatarBytes)
|
2017-11-14 10:40:15 -08:00
|
|
|
.skipMemoryCache(true)
|
|
|
|
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
2017-10-16 13:11:42 -07:00
|
|
|
.circleCrop()
|
|
|
|
.into(avatar);
|
|
|
|
} else {
|
|
|
|
Toast.makeText(CreateProfileActivity.this, R.string.CreateProfileActivity_error_setting_profile_photo, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.execute();
|
2017-08-08 16:37:15 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeResources() {
|
2017-09-05 12:52:50 -07:00
|
|
|
TextView skipButton = ViewUtil.findById(this, R.id.skip_button);
|
|
|
|
|
2017-08-08 16:37:15 -07:00
|
|
|
this.avatar = ViewUtil.findById(this, R.id.avatar);
|
|
|
|
this.name = ViewUtil.findById(this, R.id.name);
|
|
|
|
this.emojiToggle = ViewUtil.findById(this, R.id.emoji_toggle);
|
|
|
|
this.emojiDrawer = ViewUtil.findById(this, R.id.emoji_drawer);
|
|
|
|
this.container = ViewUtil.findById(this, R.id.container);
|
|
|
|
this.finishButton = ViewUtil.findById(this, R.id.finish_button);
|
2017-10-01 18:11:42 -07:00
|
|
|
this.reveal = ViewUtil.findById(this, R.id.reveal);
|
2017-08-16 12:01:26 -07:00
|
|
|
this.nextIntent = getIntent().getParcelableExtra(NEXT_INTENT);
|
2017-08-08 16:37:15 -07:00
|
|
|
|
2017-11-24 22:00:30 -08:00
|
|
|
this.avatar.setOnClickListener(view -> Permissions.with(this)
|
|
|
|
.request(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
|
|
|
.ifNecessary()
|
2019-03-18 16:09:57 -03:00
|
|
|
.onAnyResult(this::startAvatarSelection)
|
2017-11-24 22:00:30 -08:00
|
|
|
.execute());
|
2017-08-08 16:37:15 -07:00
|
|
|
|
2019-02-13 11:52:55 -08:00
|
|
|
this.name.getInput().addTextChangedListener(new TextWatcher() {
|
2017-08-24 17:40:35 -07:00
|
|
|
@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) {
|
2019-02-13 11:52:55 -08:00
|
|
|
name.getInput().setError(getString(R.string.CreateProfileActivity_too_long));
|
2017-08-24 17:40:35 -07:00
|
|
|
finishButton.setEnabled(false);
|
2019-02-13 11:52:55 -08:00
|
|
|
} else if (name.getInput().getError() != null || !finishButton.isEnabled()) {
|
|
|
|
name.getInput().setError(null);
|
2017-08-24 17:40:35 -07:00
|
|
|
finishButton.setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-08-08 16:37:15 -07:00
|
|
|
this.finishButton.setOnClickListener(view -> {
|
2017-10-01 18:11:42 -07:00
|
|
|
this.finishButton.setIndeterminateProgressMode(true);
|
|
|
|
this.finishButton.setProgress(50);
|
2017-08-08 16:37:15 -07:00
|
|
|
handleUpload();
|
|
|
|
});
|
2017-09-03 19:44:33 -07:00
|
|
|
|
2017-09-05 12:52:50 -07:00
|
|
|
skipButton.setOnClickListener(view -> {
|
2017-09-03 19:44:33 -07:00
|
|
|
if (nextIntent != null) startActivity(nextIntent);
|
|
|
|
finish();
|
|
|
|
});
|
2017-08-08 16:37:15 -07:00
|
|
|
}
|
|
|
|
|
2017-08-16 12:01:26 -07:00
|
|
|
private void initializeProfileName(boolean excludeSystem) {
|
2017-08-15 21:03:31 -07:00
|
|
|
if (!TextUtils.isEmpty(TextSecurePreferences.getProfileName(this))) {
|
|
|
|
String profileName = TextSecurePreferences.getProfileName(this);
|
|
|
|
|
|
|
|
name.setText(profileName);
|
2019-02-13 11:52:55 -08:00
|
|
|
name.getInput().setSelection(profileName.length(), profileName.length());
|
2017-08-16 12:01:26 -07:00
|
|
|
} else if (!excludeSystem) {
|
2017-08-15 21:03:31 -07:00
|
|
|
SystemProfileUtil.getSystemProfileName(this).addListener(new ListenableFuture.Listener<String>() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess(String result) {
|
|
|
|
if (!TextUtils.isEmpty(result)) {
|
|
|
|
name.setText(result);
|
2019-02-13 11:52:55 -08:00
|
|
|
name.getInput().setSelection(result.length(), result.length());
|
2017-08-15 21:03:31 -07:00
|
|
|
}
|
2017-08-08 16:37:15 -07:00
|
|
|
}
|
|
|
|
|
2017-08-15 21:03:31 -07:00
|
|
|
@Override
|
|
|
|
public void onFailure(ExecutionException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-08-08 16:37:15 -07:00
|
|
|
|
2017-08-16 12:01:26 -07:00
|
|
|
private void initializeProfileAvatar(boolean excludeSystem) {
|
2017-08-15 21:03:31 -07:00
|
|
|
Address ourAddress = Address.fromSerialized(TextSecurePreferences.getLocalNumber(this));
|
|
|
|
|
|
|
|
if (AvatarHelper.getAvatarFile(this, ourAddress).exists() && AvatarHelper.getAvatarFile(this, ourAddress).length() > 0) {
|
2017-10-16 13:11:42 -07:00
|
|
|
new AsyncTask<Void, Void, byte[]>() {
|
2017-08-15 21:03:31 -07:00
|
|
|
@Override
|
2017-10-16 13:11:42 -07:00
|
|
|
protected byte[] doInBackground(Void... params) {
|
2017-08-15 21:03:31 -07:00
|
|
|
try {
|
2017-10-16 13:11:42 -07:00
|
|
|
return Util.readFully(AvatarHelper.getInputStreamFor(CreateProfileActivity.this, ourAddress));
|
2017-08-15 21:03:31 -07:00
|
|
|
} catch (IOException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
return null;
|
|
|
|
}
|
2017-08-08 16:37:15 -07:00
|
|
|
}
|
|
|
|
|
2017-08-15 21:03:31 -07:00
|
|
|
@Override
|
2017-10-16 13:11:42 -07:00
|
|
|
protected void onPostExecute(byte[] result) {
|
2017-08-15 21:03:31 -07:00
|
|
|
if (result != null) {
|
2017-10-16 13:11:42 -07:00
|
|
|
avatarBytes = result;
|
|
|
|
GlideApp.with(CreateProfileActivity.this)
|
|
|
|
.load(result)
|
|
|
|
.circleCrop()
|
|
|
|
.into(avatar);
|
2017-08-15 21:03:31 -07:00
|
|
|
}
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2017-08-16 12:01:26 -07:00
|
|
|
} else if (!excludeSystem) {
|
2017-08-15 21:03:31 -07:00
|
|
|
SystemProfileUtil.getSystemProfileAvatar(this, new ProfileMediaConstraints()).addListener(new ListenableFuture.Listener<byte[]>() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess(byte[] result) {
|
|
|
|
if (result != null) {
|
|
|
|
avatarBytes = result;
|
2017-10-16 13:11:42 -07:00
|
|
|
GlideApp.with(CreateProfileActivity.this)
|
|
|
|
.load(result)
|
|
|
|
.circleCrop()
|
|
|
|
.into(avatar);
|
2017-08-15 21:03:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(ExecutionException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-08-08 16:37:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeEmojiInput() {
|
|
|
|
this.emojiToggle.attach(emojiDrawer);
|
|
|
|
|
|
|
|
this.emojiToggle.setOnClickListener(v -> {
|
|
|
|
if (container.getCurrentInput() == emojiDrawer) {
|
2019-02-13 11:52:55 -08:00
|
|
|
container.showSoftkey(name.getInput());
|
2017-08-08 16:37:15 -07:00
|
|
|
} else {
|
2019-02-13 11:52:55 -08:00
|
|
|
container.show(name.getInput(), emojiDrawer);
|
2017-08-08 16:37:15 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.emojiDrawer.setEmojiEventListener(new EmojiDrawer.EmojiEventListener() {
|
|
|
|
@Override
|
|
|
|
public void onKeyEvent(KeyEvent keyEvent) {
|
|
|
|
name.dispatchKeyEvent(keyEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEmojiSelected(String emoji) {
|
2019-02-13 11:52:55 -08:00
|
|
|
final int start = name.getInput().getSelectionStart();
|
|
|
|
final int end = name.getInput().getSelectionEnd();
|
2017-08-08 16:37:15 -07:00
|
|
|
|
|
|
|
name.getText().replace(Math.min(start, end), Math.max(start, end), emoji);
|
2019-02-13 11:52:55 -08:00
|
|
|
name.getInput().setSelection(start + emoji.length());
|
2017-08-08 16:37:15 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.container.addOnKeyboardShownListener(() -> emojiToggle.setToEmoji());
|
2019-02-13 11:52:55 -08:00
|
|
|
this.name.setOnClickListener(v -> container.showSoftkey(name.getInput()));
|
2017-08-08 16:37:15 -07:00
|
|
|
}
|
|
|
|
|
2019-03-18 16:09:57 -03:00
|
|
|
private void startAvatarSelection() {
|
|
|
|
captureFile = AvatarSelection.startAvatarSelection(this, avatarBytes != null, true);
|
2017-11-24 22:00:30 -08:00
|
|
|
}
|
|
|
|
|
2017-08-08 16:37:15 -07:00
|
|
|
private void handleUpload() {
|
|
|
|
final String name;
|
|
|
|
final StreamDetails avatar;
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(this.name.getText().toString())) name = null;
|
|
|
|
else name = this.name.getText().toString();
|
|
|
|
|
|
|
|
if (avatarBytes == null || avatarBytes.length == 0) avatar = null;
|
|
|
|
else avatar = new StreamDetails(new ByteArrayInputStream(avatarBytes),
|
|
|
|
"image/jpeg", avatarBytes.length);
|
|
|
|
|
2017-10-01 18:11:42 -07:00
|
|
|
new AsyncTask<Void, Void, Boolean>() {
|
2017-08-08 16:37:15 -07:00
|
|
|
@Override
|
|
|
|
protected Boolean doInBackground(Void... params) {
|
2017-10-01 18:11:42 -07:00
|
|
|
Context context = CreateProfileActivity.this;
|
|
|
|
byte[] profileKey = ProfileKeyUtil.getProfileKey(CreateProfileActivity.this);
|
2017-08-08 16:37:15 -07:00
|
|
|
|
|
|
|
try {
|
2017-08-25 12:00:52 -07:00
|
|
|
accountManager.setProfileName(profileKey, name);
|
2017-10-01 18:11:42 -07:00
|
|
|
TextSecurePreferences.setProfileName(context, name);
|
2017-08-08 16:37:15 -07:00
|
|
|
} catch (IOException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2017-08-25 12:00:52 -07:00
|
|
|
accountManager.setProfileAvatar(profileKey, avatar);
|
2017-10-01 18:11:42 -07:00
|
|
|
AvatarHelper.setAvatar(CreateProfileActivity.this, Address.fromSerialized(TextSecurePreferences.getLocalNumber(context)), avatarBytes);
|
2017-10-16 13:11:42 -07:00
|
|
|
TextSecurePreferences.setProfileAvatarId(CreateProfileActivity.this, new SecureRandom().nextInt());
|
2017-08-08 16:37:15 -07:00
|
|
|
} catch (IOException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-28 08:56:35 -07:00
|
|
|
ApplicationContext.getInstance(context).getJobManager().add(new MultiDeviceProfileKeyUpdateJob());
|
2017-08-25 12:00:52 -07:00
|
|
|
|
2017-08-08 16:37:15 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPostExecute(Boolean result) {
|
|
|
|
super.onPostExecute(result);
|
|
|
|
|
2017-08-15 21:03:31 -07:00
|
|
|
if (result) {
|
|
|
|
if (captureFile != null) captureFile.delete();
|
2017-10-01 18:11:42 -07:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) handleFinishedLollipop();
|
|
|
|
else handleFinishedLegacy();
|
2017-08-15 21:03:31 -07:00
|
|
|
} else {
|
|
|
|
Toast.makeText(CreateProfileActivity.this, R.string.CreateProfileActivity_problem_setting_profile, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
2017-08-08 16:37:15 -07:00
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2017-08-08 16:37:15 -07:00
|
|
|
}
|
|
|
|
|
2017-10-01 18:11:42 -07:00
|
|
|
private void handleFinishedLegacy() {
|
|
|
|
finishButton.setProgress(0);
|
|
|
|
if (nextIntent != null) startActivity(nextIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
|
|
|
private void handleFinishedLollipop() {
|
|
|
|
int[] finishButtonLocation = new int[2];
|
|
|
|
int[] revealLocation = new int[2];
|
|
|
|
|
|
|
|
finishButton.getLocationInWindow(finishButtonLocation);
|
|
|
|
reveal.getLocationInWindow(revealLocation);
|
|
|
|
|
|
|
|
int finishX = finishButtonLocation[0] - revealLocation[0];
|
|
|
|
int finishY = finishButtonLocation[1] - revealLocation[1];
|
|
|
|
|
|
|
|
finishX += finishButton.getWidth() / 2;
|
|
|
|
finishY += finishButton.getHeight() / 2;
|
|
|
|
|
|
|
|
Animator animation = ViewAnimationUtils.createCircularReveal(reveal, finishX, finishY, 0f, (float) Math.max(reveal.getWidth(), reveal.getHeight()));
|
|
|
|
animation.setDuration(500);
|
|
|
|
animation.addListener(new Animator.AnimatorListener() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Animator animation) {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
finishButton.setProgress(0);
|
|
|
|
if (nextIntent != null) startActivity(nextIntent);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animation) {}
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animator animation) {}
|
|
|
|
});
|
|
|
|
|
|
|
|
reveal.setVisibility(View.VISIBLE);
|
|
|
|
animation.start();
|
|
|
|
}
|
2017-08-08 16:37:15 -07:00
|
|
|
}
|