diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/AndroidManifest.xml | 9 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/services/AvatarService.java | 9 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/EditAccountActivity.java | 30 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/EnterNameActivity.java | 80 | ||||
-rw-r--r-- | src/main/res/layout/activity_edit_account.xml | 52 | ||||
-rw-r--r-- | src/main/res/layout/activity_enter_name.xml | 63 | ||||
-rw-r--r-- | src/main/res/values/strings.xml | 4 | ||||
-rw-r--r-- | src/main/res/values/styles.xml | 4 |
8 files changed, 245 insertions, 6 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index fcfee6479..ec4d4c154 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -241,7 +241,7 @@ <activity android:name=".ui.MediaViewerActivity" android:configChanges="orientation|screenSize" - android:theme="@style/ConversationsTheme.FullScreen"></activity> + android:theme="@style/ConversationsTheme.FullScreen" /> <activity android:name=".ui.TrustKeysActivity" android:label="@string/trust_omemo_fingerprints" @@ -263,7 +263,7 @@ android:configChanges="orientation|screenSize" android:label="@string/title_activity_updater" android:launchMode="singleTask" - android:theme="@style/ConversationsTheme"></activity> + android:theme="@style/ConversationsTheme" /> <activity android:name=".ui.ShortcutActivity" android:label="@string/contact"> @@ -275,10 +275,13 @@ android:name="com.theartofdev.edmodo.cropper.CropImageActivity" android:theme="@style/Base.Theme.AppCompat" /> <activity android:name=".ui.MemorizingActivity" /> - <activity android:name=".ui.MediaBrowserActivity" android:label="@string/media_browser" /> + <activity + android:name=".ui.EnterNameActivity" + android:label="@string/enter_your_name" + android:launchMode="singleTask" /> <service android:name=".services.ExportLogsService" /> <service diff --git a/src/main/java/de/pixart/messenger/services/AvatarService.java b/src/main/java/de/pixart/messenger/services/AvatarService.java index bd157f442..edc0a2e67 100644 --- a/src/main/java/de/pixart/messenger/services/AvatarService.java +++ b/src/main/java/de/pixart/messenger/services/AvatarService.java @@ -236,7 +236,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { if (bookmark.getConversation() != null) { return get(bookmark.getConversation(), size, cachedOnly); } else { - final Jid jid = bookmark.getFullJid(); + Jid jid = bookmark.getJid(); Account account = bookmark.getAccount(); Contact contact = jid == null ? null : account.getRoster().getContact(jid); if (contact != null && contact.getAvatarFilename() != null) { @@ -407,8 +407,13 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { } avatar = mXmppConnectionService.getFileBackend().getAvatar(account.getAvatar(), size); if (avatar == null) { + final String displayName = account.getDisplayName(); final String jid = account.getJid().asBareJid().toEscapedString(); - avatar = get(jid, null, size, false); + if (QuickConversationsService.isQuicksy() && !TextUtils.isEmpty(displayName)) { + avatar = get(displayName, jid, size, false); + } else { + avatar = get(jid, null, size, false); + } } mXmppConnectionService.getBitmapCache().put(KEY, avatar); return avatar; diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index 123591b03..d04289d22 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -593,6 +593,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.binding.port.addTextChangedListener(mTextWatcher); this.binding.saveButton.setOnClickListener(this.mSaveButtonClickListener); this.binding.cancelButton.setOnClickListener(this.mCancelButtonClickListener); + this.binding.actionEditYourName.setOnClickListener(this::onEditYourNameClicked); if (savedInstanceState != null && savedInstanceState.getBoolean("showMoreTable")) { changeMoreTableVisibility(true); } @@ -617,6 +618,21 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat }); } + private void onEditYourNameClicked(View view) { + quickEdit(mAccount.getDisplayName(), R.string.your_name, value -> { + final String displayName = value.trim(); + updateDisplayName(displayName); + mAccount.setDisplayName(displayName); + xmppConnectionService.publishDisplayName(mAccount); + refreshAvatar(); + return null; + }, true); + } + + private void refreshAvatar() { + binding.avater.setImageBitmap(avatarService().get(mAccount, (int) getResources().getDimension(R.dimen.avatar_on_details_screen_size))); + } + @Override public boolean onCreateOptionsMenu(final Menu menu) { super.onCreateOptionsMenu(menu); @@ -1011,6 +1027,10 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.binding.accountJid.setEnabled(editable); this.binding.accountJid.setFocusable(editable); this.binding.accountJid.setFocusableInTouchMode(editable); + this.binding.accountJid.setCursorVisible(editable); + + final String displayName = mAccount.getDisplayName(); + updateDisplayName(displayName); final boolean tooglePassword = mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) || !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY); final boolean editPassword = !mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) || (!mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY) && QuickConversationsService.isConversations()) || mAccount.getLastErrorStatus() == Account.State.UNAUTHORIZED; @@ -1228,6 +1248,16 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat return "0"; } + private void updateDisplayName(String displayName) { + if (TextUtils.isEmpty(displayName)) { + this.binding.yourName.setText(R.string.no_name_set_instructions); + this.binding.yourName.setTextAppearance(this, R.style.TextAppearance_Conversations_Body1_Tertiary); + } else { + this.binding.yourName.setText(displayName); + this.binding.yourName.setTextAppearance(this, R.style.TextAppearance_Conversations_Body1); + } + } + private void removeErrorsOnAllBut(TextInputLayout exception) { if (this.binding.accountJidLayout != exception) { this.binding.accountJidLayout.setErrorEnabled(false); diff --git a/src/main/java/de/pixart/messenger/ui/EnterNameActivity.java b/src/main/java/de/pixart/messenger/ui/EnterNameActivity.java new file mode 100644 index 000000000..ac400b9f3 --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/EnterNameActivity.java @@ -0,0 +1,80 @@ +package de.pixart.messenger.ui; + +import android.content.Intent; +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.support.v7.widget.Toolbar; +import android.view.View; + +import java.util.concurrent.atomic.AtomicBoolean; +import de.pixart.messenger.R; +import de.pixart.messenger.databinding.ActivityEnterNameBinding; +import de.pixart.messenger.entities.Account; +import de.pixart.messenger.services.XmppConnectionService; +import de.pixart.messenger.utils.AccountUtils; + +public class EnterNameActivity extends XmppActivity implements XmppConnectionService.OnAccountUpdate { + + private ActivityEnterNameBinding binding; + + private Account account; + + private AtomicBoolean setNick = new AtomicBoolean(false); + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + this.binding = DataBindingUtil.setContentView(this, R.layout.activity_enter_name); + setSupportActionBar((Toolbar) this.binding.toolbar); + this.binding.next.setOnClickListener(this::next); + this.setNick.set(savedInstanceState != null && savedInstanceState.getBoolean("set_nick",false)); + } + + private void next(View view) { + if (account != null) { + + String name = this.binding.name.getText().toString().trim(); + + account.setDisplayName(name); + + xmppConnectionService.publishDisplayName(account); + + Intent intent = new Intent(this, PublishProfilePictureActivity.class); + intent.putExtra(PublishProfilePictureActivity.EXTRA_ACCOUNT, account.getJid().asBareJid().toEscapedString()); + intent.putExtra("setup", true); + startActivity(intent); + } + finish(); + } + + @Override + public void onSaveInstanceState(Bundle savedInstanceState) { + savedInstanceState.putBoolean("set_nick", this.setNick.get()); + super.onSaveInstanceState(savedInstanceState); + } + + @Override + protected void refreshUiReal() { + checkSuggestPreviousNick(); + } + + @Override + void onBackendConnected() { + this.account = AccountUtils.getFirst(xmppConnectionService); + checkSuggestPreviousNick(); + } + + private void checkSuggestPreviousNick() { + String displayName = this.account == null ? null : this.account.getDisplayName(); + if (displayName != null) { + if (setNick.compareAndSet(false, true) && this.binding.name.getText().length() == 0) { + this.binding.name.getText().append(displayName); + } + } + } + + @Override + public void onAccountUpdate() { + refreshUi(); + } +}
\ No newline at end of file diff --git a/src/main/res/layout/activity_edit_account.xml b/src/main/res/layout/activity_edit_account.xml index 56d108b68..163fe270a 100644 --- a/src/main/res/layout/activity_edit_account.xml +++ b/src/main/res/layout/activity_edit_account.xml @@ -42,11 +42,57 @@ android:layout_height="wrap_content" android:padding="@dimen/card_padding_regular"> + <RelativeLayout + android:id="@+id/your_name_box" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_alignParentTop="true" + android:layout_marginBottom="@dimen/activity_vertical_margin"> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentStart="true" + android:layout_alignParentLeft="true" + android:layout_centerVertical="true" + android:layout_toStartOf="@+id/action_edit_your_name" + android:layout_toLeftOf="@+id/action_edit_your_name" + android:orientation="vertical"> + + <TextView + android:id="@+id/your_name" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/no_name_set_instructions" + android:textAppearance="@style/TextAppearance.Conversations.Body1.Tertiary" /> + + <TextView + android:id="@+id/your_name_desc" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/your_name" + android:textAppearance="@style/TextAppearance.Conversations.Caption" /> + </LinearLayout> + + <ImageButton + android:id="@+id/action_edit_your_name" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentEnd="true" + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:alpha="?attr/icon_alpha" + android:background="?attr/selectableItemBackgroundBorderless" + android:padding="@dimen/image_button_padding" + android:src="?attr/icon_edit_body" + android:visibility="visible" /> + </RelativeLayout> + <com.makeramen.roundedimageview.RoundedImageView android:id="@+id/avater" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignParentTop="true" + android:layout_below="@id/your_name_box" android:layout_centerHorizontal="true" android:layout_marginBottom="@dimen/avatar_item_distance" android:adjustViewBounds="true" @@ -513,6 +559,10 @@ </TableRow> </TableLayout> + <View + android:layout_width="match_parent" + android:layout_height="8dp" /> + <RelativeLayout android:id="@+id/pgp_fingerprint_box" android:layout_width="wrap_content" diff --git a/src/main/res/layout/activity_enter_name.xml b/src/main/res/layout/activity_enter_name.xml new file mode 100644 index 000000000..cb446479d --- /dev/null +++ b/src/main/res/layout/activity_enter_name.xml @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="utf-8"?> +<layout xmlns:android="http://schemas.android.com/apk/res/android"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <include + android:id="@+id/toolbar" + layout="@layout/toolbar" /> + + <ScrollView + android:layout_width="match_parent" + android:layout_height="match_parent" + android:fillViewport="true"> + + <RelativeLayout + android:layout_width="match_parent" + android:layout_height="wrap_content"> + + <TextView + android:id="@+id/instructions" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:gravity="center_horizontal" + android:padding="16dp" + android:text="@string/enter_your_name_instructions" + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + + <LinearLayout + android:id="@+id/name_box" + android:layout_width="256dp" + android:layout_height="wrap_content" + android:layout_above="@+id/next" + android:layout_below="@+id/instructions" + android:layout_centerHorizontal="true" + android:orientation="vertical"> + + <EditText + android:id="@+id/name" + style="@style/Widget.Conversations.EditText" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:hint="@string/your_name" + android:imeOptions="flagNoExtractUi" + android:longClickable="false" /> + + </LinearLayout> + + <Button + android:id="@+id/next" + style="@style/Widget.Conversations.Button.Borderless" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentEnd="true" + android:layout_alignParentBottom="true" + android:text="@string/next" + android:textColor="?colorAccent" /> + </RelativeLayout> + </ScrollView> + </LinearLayout> +</layout>
\ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 611334782..96b095277 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -850,4 +850,8 @@ <string name="no_market_app_installed">No market app installed.</string> <string name="group_chat_will_make_your_jabber_id_public">This group chat will make your Jabber ID public</string> <string name="ebook">e-book</string> + <string name="your_name">Your name</string> + <string name="enter_your_name">Enter your name</string> + <string name="enter_your_name_instructions">Please enter your nickname which will be visible to your contacts.</string> + <string name="no_name_set_instructions">No nickname set.</string> </resources> diff --git a/src/main/res/values/styles.xml b/src/main/res/values/styles.xml index 3f693fccc..4418706e1 100644 --- a/src/main/res/values/styles.xml +++ b/src/main/res/values/styles.xml @@ -67,6 +67,10 @@ <item name="android:textColor">?android:textColorSecondary</item> </style> + <style name="TextAppearance.Conversations.Body1.Tertiary" parent="TextAppearance.Conversations.Body1"> + <item name="android:textColor">?android:textColorTertiary</item> + </style> + <style name="TextAppearance.Conversations.Fingerprint" parent="TextAppearance.Conversations.Body1"> <item name="android:fontFamily" tools:targetApi="jelly_bean">monospace</item> <item name="android:typeface">monospace</item> |