Skip to content

Commit

Permalink
Display user profile information in settings activity
Browse files Browse the repository at this point in the history
Allow for editing

// FREEBIE
  • Loading branch information
moxie0 committed Aug 28, 2017
1 parent df99deb commit c11f2ed
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 25 deletions.
12 changes: 12 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,18 @@
android:theme="@style/TextSecure.LightTheme"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>

<activity android:name=".ClearProfileAvatarActivity"
android:theme="@style/Theme.AppCompat.Dialog.Alert"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"
android:icon="@drawable/clear_profile_avatar"
android:label="@string/AndroidManifest_remove_photo">

<intent-filter>
<action android:name="org.thoughtcrime.securesms.action.CLEAR_PROFILE_PHOTO"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>

<service android:enabled="true" android:name="org.thoughtcrime.securesms.service.WebRtcCallService"/>

<service android:enabled="true" android:name=".service.ApplicationMigrationService"/>
Expand Down
Binary file added res/drawable-hdpi/clear_profile_avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/clear_profile_avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/clear_profile_avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/clear_profile_avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxxhdpi/clear_profile_avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion res/layout/profile_create_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

<ImageView android:id="@+id/avatar"
android:layout_width="64dp"
android:layout_height="64dp"/>
android:layout_height="64dp"
android:transitionName="avatar"/>

<org.thoughtcrime.securesms.components.emoji.EmojiEditText
android:id="@+id/name"
Expand Down
35 changes: 35 additions & 0 deletions res/layout/profile_preference_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">

<ImageView android:id="@+id/avatar"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_margin="16dp"
android:transitionName="avatar"/>

<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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"/>

<TextView android:id="@+id/number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="+14151231234"/>

</LinearLayout>

</LinearLayout>
18 changes: 14 additions & 4 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
<!-- CallScreen -->
<string name="CallScreen_Incoming_call">Incoming call</string>

<!-- ClearProfileActivity -->
<string name="ClearProfileActivity_remove">Remove</string>
<string name="ClearProfileActivity_remove_profile_photo">Remove profile photo?</string>

<!-- ConfirmIdentityDialog -->
<string name="ConfirmIdentityDialog_your_safety_number_with_s_has_changed">Your safety number with %1$s has changed. This could either mean that someone is trying to intercept your communication, or that %2$s simply reinstalled Signal.</string>
<string name="ConfirmIdentityDialog_you_may_wish_to_verify_your_safety_number_with_this_contact">You may wish to verify your safety number with this contact.</string>
Expand Down Expand Up @@ -613,6 +617,14 @@
<string name="UpdateApkReadyListener_Signal_update">Signal update</string>
<string name="UpdateApkReadyListener_a_new_version_of_signal_is_available_tap_to_update">A new version of Signal is available, tap to update</string>

<!-- UntrustedSendDialog -->
<string name="UntrustedSendDialog_send_message">Send message?</string>
<string name="UntrustedSendDialog_send">Send</string>

<!-- UnverifiedSendDialog -->
<string name="UnverifiedSendDialog_send_message">Send message?</string>
<string name="UnverifiedSendDialog_send">Send</string>

<!-- VerifyIdentityActivity -->
<string name="VerifyIdentityActivity_your_contact_is_running_an_old_version_of_signal">Your contact is running an old version of Signal. Please ask them to update before verifying your safety number.</string>
<string name="VerifyIdentityActivity_your_contact_is_running_a_newer_version_of_Signal">Your contact is running a newer version of Signal with an incompatible QR code format. Please update to compare.</string>
Expand Down Expand Up @@ -1087,6 +1099,7 @@
<string name="AndroidManifest__linked_devices">Linked devices</string>
<string name="AndroidManifest__invite_friends">Invite friends</string>
<string name="AndroidManifest_archived_conversations">Archived conversations</string>
<string name="AndroidManifest_remove_photo">Remove photo</string>

<!-- arrays.xml -->
<string name="arrays__import_export">Import / export</string>
Expand Down Expand Up @@ -1409,10 +1422,7 @@

<!-- transport_selection_list_item -->
<string name="transport_selection_list_item__transport_icon">Transport icon</string>
<string name="UntrustedSendDialog_send_message">Send message?</string>
<string name="UntrustedSendDialog_send">Send</string>
<string name="UnverifiedSendDialog_send_message">Send message?</string>
<string name="UnverifiedSendDialog_send">Send</string>



<!-- EOF -->
Expand Down
4 changes: 4 additions & 0 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<org.thoughtcrime.securesms.preferences.ProfilePreference
android:key="preference_category_profile"/>

<Preference android:key="preference_category_sms_mms"
android:title="@string/preferences__sms_mms"
android:icon="@drawable/ic_textsms_24dp"/>
Expand Down
16 changes: 16 additions & 0 deletions src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.app.AppCompatActivity;

import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.preferences.AdvancedPreferenceFragment;
Expand All @@ -60,6 +61,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
{
private static final String TAG = ApplicationPreferencesActivity.class.getSimpleName();

private static final String PREFERENCE_CATEGORY_PROFILE = "preference_category_profile";
private static final String PREFERENCE_CATEGORY_SMS_MMS = "preference_category_sms_mms";
private static final String PREFERENCE_CATEGORY_NOTIFICATIONS = "preference_category_notifications";
private static final String PREFERENCE_CATEGORY_APP_PROTECTION = "preference_category_app_protection";
Expand Down Expand Up @@ -138,6 +140,8 @@ public void onCreate(Bundle icicle) {
addPreferencesFromResource(R.xml.preferences);

MasterSecret masterSecret = getArguments().getParcelable("master_secret");
this.findPreference(PREFERENCE_CATEGORY_PROFILE)
.setOnPreferenceClickListener(new ProfileClickListener());
this.findPreference(PREFERENCE_CATEGORY_SMS_MMS)
.setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_SMS_MMS));
this.findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS)
Expand Down Expand Up @@ -273,5 +277,17 @@ public boolean onPreferenceClick(Preference preference) {
return true;
}
}

private class ProfileClickListener implements Preference.OnPreferenceClickListener {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(preference.getContext(), CreateProfileActivity.class);
intent.putExtra(CreateProfileActivity.EXCLUDE_SYSTEM, true);

((BaseActionBarActivity)getActivity()).startActivitySceneTransition(intent, getActivity().findViewById(R.id.avatar), "avatar");
return true;
}
}
}

}
26 changes: 26 additions & 0 deletions src/org/thoughtcrime/securesms/ClearProfileAvatarActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.thoughtcrime.securesms;


import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AlertDialog;

public class ClearProfileAvatarActivity extends Activity {

@Override
public void onResume() {
super.onResume();

new AlertDialog.Builder(this)
.setTitle(R.string.ClearProfileActivity_remove_profile_photo)
.setNegativeButton(android.R.string.cancel, (dialog, which) -> finish())
.setPositiveButton(R.string.ClearProfileActivity_remove, (dialog, which) -> {
Intent result = new Intent();
result.putExtra("delete", true);
setResult(Activity.RESULT_OK, result);
finish();
})
.show();
}

}
53 changes: 34 additions & 19 deletions src/org/thoughtcrime/securesms/CreateProfileActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;

import javax.inject.Inject;
Expand All @@ -63,6 +65,9 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i

private static final String TAG = CreateProfileActivity.class.getSimpleName();

public static final String NEXT_INTENT = "next_intent";
public static final String EXCLUDE_SYSTEM = "exclude_system";

private static final int REQUEST_CODE_AVATAR = 1;

@Inject SignalServiceAccountManager accountManager;
Expand All @@ -74,8 +79,9 @@ public class CreateProfileActivity extends PassphraseRequiredActionBarActivity i
private EmojiToggle emojiToggle;
private EmojiDrawer emojiDrawer;

private Intent nextIntent;
private byte[] avatarBytes;
private File captureFile;
private File captureFile;

@Override
public void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
Expand All @@ -88,8 +94,8 @@ public void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {

initializeResources();
initializeEmojiInput();
initializeProfileName();
initializeProfileAvatar();
initializeProfileName(getIntent().getBooleanExtra(EXCLUDE_SYSTEM, false));
initializeProfileAvatar(getIntent().getBooleanExtra(EXCLUDE_SYSTEM, false));

ApplicationContext.getInstance(this).injectDependencies(this);
}
Expand Down Expand Up @@ -123,7 +129,13 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
inputFile = Uri.fromFile(captureFile);
}

new Crop(inputFile).output(outputFile).asSquare().start(this);
if (data.getBooleanExtra("delete", false)) {
avatarBytes = null;
avatar.setImageDrawable(ContactPhotoFactory.getResourceContactPhoto(R.drawable.ic_camera_alt_white_24dp)
.asDrawable(this, getResources().getColor(R.color.grey_400)));
} else {
new Crop(inputFile).output(outputFile).asSquare().start(this);
}
}

break;
Expand All @@ -148,6 +160,7 @@ private void initializeResources() {
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);
this.nextIntent = getIntent().getParcelableExtra(NEXT_INTENT);

this.avatar.setImageDrawable(ContactPhotoFactory.getResourceContactPhoto(R.drawable.ic_camera_alt_white_24dp)
.asDrawable(this, getResources().getColor(R.color.grey_400)));
Expand All @@ -160,7 +173,7 @@ private void initializeResources() {
captureFile = null;
}

Intent chooserIntent = createAvatarSelectionIntent(captureFile);
Intent chooserIntent = createAvatarSelectionIntent(captureFile, avatarBytes != null);
startActivityForResult(chooserIntent, REQUEST_CODE_AVATAR);
});

Expand All @@ -169,13 +182,13 @@ private void initializeResources() {
});
}

private void initializeProfileName() {
private void initializeProfileName(boolean excludeSystem) {
if (!TextUtils.isEmpty(TextSecurePreferences.getProfileName(this))) {
String profileName = TextSecurePreferences.getProfileName(this);

name.setText(profileName);
name.setSelection(profileName.length(), profileName.length());
} else {
} else if (!excludeSystem) {
SystemProfileUtil.getSystemProfileName(this).addListener(new ListenableFuture.Listener<String>() {
@Override
public void onSuccess(String result) {
Expand All @@ -193,7 +206,7 @@ public void onFailure(ExecutionException e) {
}
}

private void initializeProfileAvatar() {
private void initializeProfileAvatar(boolean excludeSystem) {
Address ourAddress = Address.fromSerialized(TextSecurePreferences.getLocalNumber(this));

if (AvatarHelper.getAvatarFile(this, ourAddress).exists() && AvatarHelper.getAvatarFile(this, ourAddress).length() > 0) {
Expand All @@ -217,7 +230,7 @@ protected void onPostExecute(Pair<byte[], ContactPhoto> result) {
}
}
}.execute();
} else {
} else if (!excludeSystem) {
SystemProfileUtil.getSystemProfileAvatar(this, new ProfileMediaConstraints()).addListener(new ListenableFuture.Listener<byte[]>() {
@Override
public void onSuccess(byte[] result) {
Expand Down Expand Up @@ -266,8 +279,9 @@ public void onEmojiSelected(String emoji) {
this.name.setOnClickListener(v -> container.showSoftkey(name));
}

private Intent createAvatarSelectionIntent(@Nullable File captureFile) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
private Intent createAvatarSelectionIntent(@Nullable File captureFile, boolean includeClear) {
List<Intent> extraIntents = new LinkedList<>();
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");

if (!IntentUtils.isResolvable(CreateProfileActivity.this, galleryIntent)) {
Expand All @@ -276,23 +290,23 @@ private Intent createAvatarSelectionIntent(@Nullable File captureFile) {
}

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(EXTRA_OUTPUT, Uri.fromFile(captureFile));

if (captureFile != null && cameraIntent.resolveActivity(getPackageManager()) != null) {
cameraIntent.putExtra(EXTRA_OUTPUT, Uri.fromFile(captureFile));
} else {
cameraIntent = null;
extraIntents.add(cameraIntent);
}

if (includeClear) {
extraIntents.add(new Intent("org.thoughtcrime.securesms.action.CLEAR_PROFILE_PHOTO"));
}

Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.CreateProfileActivity_profile_photo));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents.toArray(new Intent[0]));

if (cameraIntent != null) {
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {cameraIntent});
}

return chooserIntent;
}


private void handleUpload() {
final String name;
final StreamDetails avatar;
Expand Down Expand Up @@ -342,7 +356,8 @@ public void onPostExecute(Boolean result) {

if (result) {
if (captureFile != null) captureFile.delete();
startActivity(new Intent(CreateProfileActivity.this, ConversationListActivity.class));
if (nextIntent != null) startActivity(nextIntent);

finish();
} else {
Toast.makeText(CreateProfileActivity.this, R.string.CreateProfileActivity_problem_setting_profile, Toast.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ private void handleVerificationComplete() {
}

shutdownService();
startActivity(new Intent(this, CreateProfileActivity.class));
Intent intent = new Intent(this, CreateProfileActivity.class);
intent.putExtra(CreateProfileActivity.NEXT_INTENT, new Intent(this, ConversationListActivity.class));
startActivity(intent);
finish();
}

Expand Down
Loading

0 comments on commit c11f2ed

Please sign in to comment.