diff options
author | steckbrief <steckbrief@chefmail.de> | 2016-03-29 22:35:28 +0200 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2016-03-29 22:35:28 +0200 |
commit | a0c4b022de514ef0334b8aa28662338519eb2071 (patch) | |
tree | beceb80779946decd8458910b6864c83a67e93d2 /src/main | |
parent | e388dfc0b8c32ea5916ae6f803217061dac58663 (diff) | |
parent | bcf0d929dda50a3c8c94e5d384840bedc51d4e63 (diff) |
Merge remote-tracking branch 'remotes/origin/trz/rename' into trz/rebase
Conflicts:
src/main/java/eu/siacs/conversations/ui/ChangePasswordActivity.java
src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java
src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java
src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java
Diffstat (limited to 'src/main')
6 files changed, 103 insertions, 70 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ui/TextViewUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/ui/TextViewUtil.java new file mode 100644 index 00000000..bb08014b --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/utils/ui/TextViewUtil.java @@ -0,0 +1,75 @@ +package de.thedevstack.conversationsplus.utils.ui; + +import android.support.annotation.StringRes; +import android.widget.TextView; + +/** + * Created by steckbrief on 29.03.2016. + */ +public final class TextViewUtil { + public static void enable(TextView tv) { + setColorEnabledAndTextResId(tv, null, true, null); + } + + public static void enable(TextView tv, String text) { + setColorEnabledAndText(tv, null, true, text); + } + + public static void enable(TextView tv, Integer color) { + setColorEnabledAndTextResId(tv, color, true, null); + } + + public static void enable(TextView tv, Integer color, @StringRes Integer resid) { + setColorEnabledAndTextResId(tv, color, true, resid); + } + + public static void disable(TextView tv) { + setColorEnabledAndTextResId(tv, null, false, null); + } + + public static void disable(TextView tv, String text) { + setColorEnabledAndText(tv, null, false, text); + } + + public static void disable(TextView tv, Integer color) { + setColorEnabledAndTextResId(tv, color, false, null); + } + + public static void disable(TextView tv, Integer color, @StringRes Integer resid) { + setColorEnabledAndTextResId(tv, color, false, resid); + } + + public static void setColor(TextView tv, Integer color) { + setColorEnabledAndTextResId(tv, color, null, null); + } + + public static void setColorEnabledAndTextResId(TextView tv, Integer color, Boolean enabled, @StringRes Integer resid) { + if (null != color) { + tv.setTextColor(color); + } + + if (enabled != null) { + tv.setEnabled(enabled); + } + if (resid != null) { + tv.setText(resid); + } + } + + public static void setColorEnabledAndText(TextView tv, Integer color, Boolean enabled, String text) { + if (null != color) { + tv.setTextColor(color); + } + + if (enabled != null) { + tv.setEnabled(enabled); + } + if (text != null) { + tv.setText(text); + } + } + + private TextViewUtil() { + // avoid instantiation - helper class + } +} diff --git a/src/main/java/eu/siacs/conversations/ui/ChangePasswordActivity.java b/src/main/java/eu/siacs/conversations/ui/ChangePasswordActivity.java index 5c3f9bb3..9f4a4bc3 100644 --- a/src/main/java/eu/siacs/conversations/ui/ChangePasswordActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ChangePasswordActivity.java @@ -7,6 +7,7 @@ import android.widget.EditText; import android.widget.Toast; import de.thedevstack.conversationsplus.ConversationsPlusColors; +import de.thedevstack.conversationsplus.utils.ui.TextViewUtil; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; @@ -39,9 +40,7 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti mNewPassword.setError(null); mNewPasswordConfirm.setError(null); xmppConnectionService.updateAccountPasswordOnServer(mAccount, newPassword, ChangePasswordActivity.this); - mChangePasswordButton.setEnabled(false); - mChangePasswordButton.setTextColor(ConversationsPlusColors.secondaryText()); - mChangePasswordButton.setText(R.string.updating); + TextViewUtil.disable(mChangePasswordButton, ConversationsPlusColors.secondaryText(), R.string.updating); } } } @@ -92,9 +91,7 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti @Override public void run() { mNewPassword.setError(getString(R.string.could_not_change_password)); - mChangePasswordButton.setEnabled(true); - mChangePasswordButton.setTextColor(ConversationsPlusColors.primaryText()); - mChangePasswordButton.setText(R.string.change_password); + TextViewUtil.enable(mChangePasswordButton, ConversationsPlusColors.primaryText(), R.string.change_password); } }); diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 9e01837a..a01f939c 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -40,6 +40,8 @@ import java.util.concurrent.atomic.AtomicInteger; import de.thedevstack.conversationsplus.ConversationsPlusColors; import de.thedevstack.conversationsplus.ui.listeners.ShowResourcesListDialogListener; +import de.thedevstack.conversationsplus.utils.ui.TextViewUtil; + import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.axolotl.AxolotlService; @@ -117,6 +119,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !accountInfoEdited()) { mAccount.setOption(Account.OPTION_DISABLED, false); + mAccount.setStatus(Account.State.CONNECTING); xmppConnectionService.updateAccount(mAccount); return; } @@ -335,26 +338,18 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate protected void updateSaveButton() { if (accountInfoEdited() && !mInitMode) { - this.mSaveButton.setText(R.string.save); - this.mSaveButton.setEnabled(true); - this.mSaveButton.setTextColor(ConversationsPlusColors.primaryText()); + TextViewUtil.enable(mSaveButton, ConversationsPlusColors.primaryText(), R.string.save); } else if (mAccount != null && (mAccount.getStatus() == Account.State.CONNECTING || mFetchingAvatar)) { - this.mSaveButton.setEnabled(false); - this.mSaveButton.setTextColor(ConversationsPlusColors.secondaryText()); - this.mSaveButton.setText(R.string.account_status_connecting); + TextViewUtil.disable(mSaveButton, ConversationsPlusColors.secondaryText(), R.string.account_status_connecting); } else if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !mInitMode) { - this.mSaveButton.setEnabled(true); - this.mSaveButton.setTextColor(ConversationsPlusColors.primaryText()); - this.mSaveButton.setText(R.string.enable); + TextViewUtil.enable(mSaveButton, ConversationsPlusColors.primaryText(), R.string.enable); } else { - this.mSaveButton.setEnabled(true); - this.mSaveButton.setTextColor(ConversationsPlusColors.primaryText()); + TextViewUtil.enable(mSaveButton, ConversationsPlusColors.primaryText()); if (!mInitMode) { if (mAccount != null && mAccount.isOnlineAndConnected()) { this.mSaveButton.setText(R.string.save); if (!accountInfoEdited()) { - this.mSaveButton.setEnabled(false); - this.mSaveButton.setTextColor(ConversationsPlusColors.secondaryText()); + TextViewUtil.disable(mSaveButton, ConversationsPlusColors.secondaryText()); } } else { this.mSaveButton.setText(R.string.connect); @@ -551,9 +546,8 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setDisplayShowHomeEnabled(false); getActionBar().setHomeButtonEnabled(false); - } - this.mCancelButton.setEnabled(false); - this.mCancelButton.setTextColor(ConversationsPlusColors.secondaryText()); + } + TextViewUtil.disable(mCancelButton, ConversationsPlusColors.secondaryText()); } if (Config.DOMAIN_LOCK == null) { final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this, diff --git a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java index 301baff5..1916947b 100644 --- a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java @@ -24,6 +24,8 @@ import java.io.FileNotFoundException; import de.thedevstack.conversationsplus.ConversationsPlusColors; import de.thedevstack.conversationsplus.utils.ImageUtil; +import de.thedevstack.conversationsplus.utils.ui.TextViewUtil; + import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; @@ -87,8 +89,7 @@ public class PublishProfilePictureActivity extends XmppActivity { public void run() { hintOrWarning.setText(errorCode); hintOrWarning.setTextColor(ConversationsPlusColors.warning()); - publishButton.setText(R.string.publish); - enablePublishButton(); + TextViewUtil.enable(publishButton, ConversationsPlusColors.primaryText(), R.string.publish); } }); @@ -114,8 +115,7 @@ public class PublishProfilePictureActivity extends XmppActivity { @Override public void onClick(View v) { if (avatarUri != null) { - publishButton.setText(R.string.publishing); - disablePublishButton(); + TextViewUtil.disable(publishButton, ConversationsPlusColors.secondaryText(), R.string.publishing); AvatarService.getInstance().publishAvatar(account, avatarUri, avatarPublication); } @@ -288,7 +288,7 @@ public class PublishProfilePictureActivity extends XmppActivity { } if (bm == null) { - disablePublishButton(); + TextViewUtil.disable(this.publishButton, ConversationsPlusColors.secondaryText()); this.hintOrWarning.setTextColor(ConversationsPlusColors.warning()); this.hintOrWarning .setText(R.string.error_publish_avatar_converting); @@ -296,12 +296,11 @@ public class PublishProfilePictureActivity extends XmppActivity { } this.avatar.setImageBitmap(bm); if (support) { - enablePublishButton(); - this.publishButton.setText(R.string.publish); + TextViewUtil.enable(this.publishButton, ConversationsPlusColors.primaryText(), R.string.publish); this.hintOrWarning.setText(R.string.publish_avatar_explanation); this.hintOrWarning.setTextColor(ConversationsPlusColors.primaryText()); } else { - disablePublishButton(); + TextViewUtil.disable(this.publishButton, ConversationsPlusColors.secondaryText()); this.hintOrWarning.setTextColor(ConversationsPlusColors.warning()); this.hintOrWarning .setText(R.string.error_publish_avatar_no_server_support); @@ -315,16 +314,6 @@ public class PublishProfilePictureActivity extends XmppActivity { } } - protected void enablePublishButton() { - this.publishButton.setEnabled(true); - this.publishButton.setTextColor(ConversationsPlusColors.primaryText()); - } - - protected void disablePublishButton() { - this.publishButton.setEnabled(false); - this.publishButton.setTextColor(ConversationsPlusColors.secondaryText()); - } - public void refreshUiReal() { //nothing to do. This Activity doesn't implement any listeners } diff --git a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java index 96a365ef..02a9823d 100644 --- a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java @@ -19,6 +19,7 @@ import java.util.Map; import java.util.Set; import de.thedevstack.conversationsplus.ConversationsPlusColors; +import de.thedevstack.conversationsplus.utils.ui.TextViewUtil; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.axolotl.AxolotlService; @@ -161,8 +162,7 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate ownKeysCard.setVisibility(hasOwnKeys ? View.VISIBLE : View.GONE); foreignKeys.setVisibility(hasForeignKeys ? View.VISIBLE : View.GONE); if(hasPendingKeyFetches()) { - setFetching(); - lock(); + TextViewUtil.disable(this.mSaveButton, ConversationsPlusColors.secondaryText(), R.string.fetching_keys); } else { if (!hasForeignKeys && hasNoOtherTrustedKeys()) { keyErrorMessageCard.setVisibility(View.VISIBLE); @@ -178,7 +178,7 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate foreignKeys.setVisibility(View.GONE); } lockOrUnlockAsNeeded(); - setDone(); + mSaveButton.setText(R.string.done); } } @@ -305,35 +305,16 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate } } - private void unlock() { - mSaveButton.setEnabled(true); - mSaveButton.setTextColor(ConversationsPlusColors.primaryText()); - } - - private void lock() { - mSaveButton.setEnabled(false); - mSaveButton.setTextColor(ConversationsPlusColors.secondaryText()); - } - private void lockOrUnlockAsNeeded() { synchronized (this.foreignKeysToTrust) { for (Jid jid : contactJids) { Map<String, Boolean> fingerprints = foreignKeysToTrust.get(jid); if (hasNoOtherTrustedKeys(jid) && (fingerprints == null || !fingerprints.values().contains(true))) { - lock(); + TextViewUtil.disable(this.mSaveButton, ConversationsPlusColors.secondaryText()); return; } } } - unlock(); - - } - - private void setDone() { - mSaveButton.setText(getString(R.string.done)); - } - - private void setFetching() { - mSaveButton.setText(getString(R.string.fetching_keys)); + TextViewUtil.enable(this.mSaveButton, ConversationsPlusColors.primaryText()); } } diff --git a/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java b/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java index d94c9a1e..a310b6ce 100644 --- a/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java @@ -20,6 +20,7 @@ import net.java.otr4j.OtrException; import net.java.otr4j.session.Session; import de.thedevstack.conversationsplus.ConversationsPlusColors; +import de.thedevstack.conversationsplus.utils.ui.TextViewUtil; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; @@ -381,16 +382,12 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer } protected void activateButton(Button button, int text, View.OnClickListener listener) { - button.setEnabled(true); - button.setTextColor(ConversationsPlusColors.primaryText()); - button.setText(text); + TextViewUtil.enable(button, ConversationsPlusColors.primaryText(), text); button.setOnClickListener(listener); } protected void deactivateButton(Button button, int text) { - button.setEnabled(false); - button.setTextColor(ConversationsPlusColors.secondaryText()); - button.setText(text); + TextViewUtil.disable(button, ConversationsPlusColors.secondaryText(), text); button.setOnClickListener(null); } |