aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java112
1 files changed, 55 insertions, 57 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java b/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java
index d4b5c6fa4..e79a5026d 100644
--- a/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java
@@ -6,6 +6,8 @@ import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
+import android.support.annotation.StringRes;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -24,11 +26,12 @@ import de.pixart.messenger.Config;
import de.pixart.messenger.R;
import de.pixart.messenger.entities.Account;
import de.pixart.messenger.persistance.FileBackend;
+import de.pixart.messenger.services.XmppConnectionService;
import de.pixart.messenger.utils.FileUtils;
import de.pixart.messenger.utils.PhoneHelper;
import de.pixart.messenger.xmpp.pep.Avatar;
-public class PublishProfilePictureActivity extends XmppActivity {
+public class PublishProfilePictureActivity extends XmppActivity implements XmppConnectionService.OnAccountUpdate {
private static final int REQUEST_CHOOSE_FILE_AND_CROP = 0xac23;
private static final int REQUEST_CHOOSE_FILE = 0xac24;
@@ -42,6 +45,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
private Uri defaultUri;
private Account account;
private boolean support = false;
+ private boolean publishing = false;
private OnLongClickListener backToDefaultListener = new OnLongClickListener() {
@Override
@@ -76,8 +80,8 @@ public class PublishProfilePictureActivity extends XmppActivity {
hintOrWarning.setText(errorCode);
hintOrWarning.setTextColor(getWarningTextColor());
hintOrWarning.setVisibility(View.VISIBLE);
- publishButton.setText(R.string.publish);
- enablePublishButton();
+ publishing = false;
+ togglePublishButton(true,R.string.publish);
});
}
@@ -102,10 +106,9 @@ public class PublishProfilePictureActivity extends XmppActivity {
@Override
public void onClick(View v) {
if (avatarUri != null) {
- publishButton.setText(R.string.publishing);
- disablePublishButton();
- xmppConnectionService.publishAvatar(account, avatarUri,
- avatarPublication);
+ publishing = true;
+ togglePublishButton(false, R.string.publishing);
+ xmppConnectionService.publishAvatar(account, avatarUri, avatarPublication);
}
}
});
@@ -219,42 +222,30 @@ public class PublishProfilePictureActivity extends XmppActivity {
protected void onBackendConnected() {
this.account = extractAccount(getIntent());
if (this.account != null) {
- if (this.account.getXmppConnection() != null) {
- this.support = this.account.getXmppConnection().getFeatures().pep();
- }
- if (this.avatarUri == null) {
- if (this.account.getAvatar() != null || this.defaultUri == null) {
- this.avatar.setImageBitmap(avatarService().get(account, getPixel(Config.AVATAR_SIZE)));
- if (this.defaultUri != null) {
- this.avatar.setOnLongClickListener(this.backToDefaultListener);
- } else {
- this.secondaryHint.setVisibility(View.INVISIBLE);
- }
- if (!support) {
- this.hintOrWarning.setVisibility(View.VISIBLE);
- this.hintOrWarning.setTextColor(getWarningTextColor());
- if (account.getStatus() == Account.State.ONLINE) {
- this.hintOrWarning.setText(R.string.error_publish_avatar_no_server_support);
- } else {
- this.hintOrWarning.setText(R.string.error_publish_avatar_offline);
- }
- }
- } else {
- this.avatarUri = this.defaultUri;
- loadImageIntoPreview(this.defaultUri);
- this.secondaryHint.setVisibility(View.INVISIBLE);
- }
- } else {
- loadImageIntoPreview(avatarUri);
- }
- String account;
- if (Config.DOMAIN_LOCK != null) {
- account = this.account.getJid().getLocalpart();
+ reloadAvatar();
+ }
+ }
+
+ private void reloadAvatar() {
+ this.support = this.account.getXmppConnection() != null && this.account.getXmppConnection().getFeatures().pep();
+ if (this.avatarUri == null) {
+ if (this.account.getAvatar() != null || this.defaultUri == null) {
+ loadImageIntoPreview(null);
} else {
- account = this.account.getJid().toBareJid().toString();
+ this.avatarUri = this.defaultUri;
+ loadImageIntoPreview(this.defaultUri);
}
- this.accountTextView.setText(account);
+ } else {
+ loadImageIntoPreview(avatarUri);
}
+ String account;
+ if (Config.DOMAIN_LOCK != null) {
+ account = this.account.getJid().getLocalpart();
+ } else {
+ account = this.account.getJid().toBareJid().toString();
+ }
+ this.accountTextView.setText(account);
+
}
@Override
@@ -270,14 +261,18 @@ public class PublishProfilePictureActivity extends XmppActivity {
protected void loadImageIntoPreview(Uri uri) {
Bitmap bm = null;
- try {
- bm = xmppConnectionService.getFileBackend().cropCenterSquare(uri, getPixel(Config.AVATAR_SIZE));
- } catch (Exception e) {
- e.printStackTrace();
+ if (uri == null) {
+ bm = avatarService().get(account, getPixel(Config.AVATAR_SIZE));
+ } else {
+ try {
+ bm = xmppConnectionService.getFileBackend().cropCenterSquare(uri, getPixel(192));
+ } catch (Exception e) {
+ Log.d(Config.LOGTAG, "unable to load bitmap into image view", e);
+ }
}
if (bm == null) {
- disablePublishButton();
+ togglePublishButton(false, R.string.publish);
this.hintOrWarning.setVisibility(View.VISIBLE);
this.hintOrWarning.setTextColor(getWarningTextColor());
this.hintOrWarning.setText(R.string.error_publish_avatar_converting);
@@ -285,11 +280,10 @@ public class PublishProfilePictureActivity extends XmppActivity {
}
this.avatar.setImageBitmap(bm);
if (support) {
- enablePublishButton();
- this.publishButton.setText(R.string.publish);
+ togglePublishButton(uri != null, R.string.publish);
this.hintOrWarning.setVisibility(View.INVISIBLE);
} else {
- disablePublishButton();
+ togglePublishButton(false, R.string.publish);
this.hintOrWarning.setVisibility(View.VISIBLE);
this.hintOrWarning.setTextColor(getWarningTextColor());
if (account.getStatus() == Account.State.ONLINE) {
@@ -298,7 +292,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
this.hintOrWarning.setText(R.string.error_publish_avatar_offline);
}
}
- if (this.defaultUri != null && uri.equals(this.defaultUri)) {
+ if (this.defaultUri == null || this.defaultUri.equals(uri)) {
this.secondaryHint.setVisibility(View.INVISIBLE);
this.avatar.setOnLongClickListener(null);
} else if (this.defaultUri != null) {
@@ -307,17 +301,21 @@ public class PublishProfilePictureActivity extends XmppActivity {
}
}
- protected void enablePublishButton() {
- this.publishButton.setEnabled(true);
- this.publishButton.setTextColor(getPrimaryTextColor());
+ protected void togglePublishButton(boolean enabled, @StringRes int res) {
+ final boolean status = enabled && !publishing;
+ this.publishButton.setText(publishing ? R.string.publishing : res);
+ this.publishButton.setEnabled(status);
+ this.publishButton.setTextColor(status ? getPrimaryTextColor() : getSecondaryTextColor());
}
- protected void disablePublishButton() {
- this.publishButton.setEnabled(false);
- this.publishButton.setTextColor(getSecondaryTextColor());
+ public void refreshUiReal() {
+ if (this.account != null) {
+ reloadAvatar();
+ }
}
- public void refreshUiReal() {
- //nothing to do. This Activity doesn't implement any listeners
+ @Override
+ public void onAccountUpdate() {
+ refreshUi();
}
}