From 81700e7b84a57e263d8b6ac33dd08841ad7aab83 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Sun, 26 Mar 2017 18:26:47 -0400 Subject: [PATCH] Adds an indicator of visibility to the send button in the composer. Closes #38 --- .../keylesspalace/tusky/ComposeActivity.java | 50 +++++++++++++++---- .../main/res/drawable/send_private_dark.xml | 9 ++++ .../main/res/drawable/send_private_light.xml | 9 ++++ app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values/attrs.xml | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 2 + 7 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 app/src/main/res/drawable/send_private_dark.xml create mode 100644 app/src/main/res/drawable/send_private_light.xml diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index 7c731227..9c2fa611 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -29,6 +29,7 @@ import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; import android.media.MediaMetadataRetriever; import android.media.ThumbnailUtils; import android.net.Uri; @@ -114,6 +115,7 @@ public class ComposeActivity extends BaseActivity { private int currentFlags; private ProgressDialog finishingUploadDialog; private EditText contentWarningEditor; + private Button floatingBtn; private ImageButton pickBtn; private Button nsfwBtn; @@ -330,7 +332,7 @@ public class ComposeActivity extends BaseActivity { SharedPreferences preferences = getSharedPreferences( getString(R.string.preferences_file_key), Context.MODE_PRIVATE); - Button floatingBtn = (Button) findViewById(R.id.floating_btn); + floatingBtn = (Button) findViewById(R.id.floating_btn); pickBtn = (ImageButton) findViewById(R.id.compose_photo_pick); nsfwBtn = (Button) findViewById(R.id.action_toggle_nsfw); ImageButton visibilityBtn = (ImageButton) findViewById(R.id.action_toggle_visibility); @@ -360,10 +362,11 @@ public class ComposeActivity extends BaseActivity { } }); + String startingVisibility; ArrayList savedMediaQueued = null; if (savedInstanceState != null) { showMarkSensitive = savedInstanceState.getBoolean("showMarkSensitive"); - statusVisibility = savedInstanceState.getString("statusVisibility"); + startingVisibility = savedInstanceState.getString("statusVisibility"); statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive"); statusHideText = savedInstanceState.getBoolean("statusHideText"); // Keep these until everything needed to put them in the queue is finished initializing. @@ -377,7 +380,7 @@ public class ComposeActivity extends BaseActivity { } } else { showMarkSensitive = false; - statusVisibility = preferences.getString("rememberedVisibility", "public"); + startingVisibility = preferences.getString("rememberedVisibility", "public"); statusMarkSensitive = false; statusHideText = false; } @@ -395,19 +398,22 @@ public class ComposeActivity extends BaseActivity { inReplyToId = intent.getStringExtra("in_reply_to_id"); String replyVisibility = intent.getStringExtra("reply_visibility"); - if (replyVisibility != null) { + if (replyVisibility != null && startingVisibility != null) { // Lowest possible visibility setting in response - if (statusVisibility.equals("private") || replyVisibility.equals("private")) { - statusVisibility = "private"; - } else if (statusVisibility.equals("unlisted") || replyVisibility.equals("unlisted")) { - statusVisibility = "unlisted"; + if (startingVisibility.equals("private") || replyVisibility.equals("private")) { + startingVisibility = "private"; + } else if (startingVisibility.equals("unlisted") || replyVisibility.equals("unlisted")) { + startingVisibility = "unlisted"; } else { - statusVisibility = replyVisibility; + startingVisibility = replyVisibility; } } mentionedUsernames = intent.getStringArrayExtra("mentioned_usernames"); } + /* Only after the starting visibility is determined and the send button is initialised can + * the status visibility be set. */ + setStatusVisibility(startingVisibility); textEditor = createEditText(null); // new String[] { "image/gif", "image/webp" } if (savedInstanceState != null) { @@ -488,6 +494,30 @@ public class ComposeActivity extends BaseActivity { } } + private void setStatusVisibility(String visibility) { + statusVisibility = visibility; + switch (visibility) { + case "public": { + floatingBtn.setText(R.string.action_send_public); + floatingBtn.setCompoundDrawables(null, null, null, null); + break; + } + case "private": { + floatingBtn.setText(R.string.action_send); + Drawable lock = ThemeUtils.getDrawable(this, R.attr.compose_send_private_drawable, + R.drawable.send_private_dark); + lock.setBounds(0, 0, lock.getIntrinsicWidth(), lock.getIntrinsicHeight()); + floatingBtn.setCompoundDrawables(null, null, lock, null); + break; + } + default: { + floatingBtn.setText(R.string.action_send); + floatingBtn.setCompoundDrawables(null, null, null, null); + break; + } + } + } + private void showComposeOptions() { ComposeOptionsFragment fragment = ComposeOptionsFragment.newInstance( statusVisibility, statusHideText, inReplyToId != null, @@ -502,7 +532,7 @@ public class ComposeActivity extends BaseActivity { @Override public void onVisibilityChanged(String visibility) { - statusVisibility = visibility; + setStatusVisibility(visibility); } @Override diff --git a/app/src/main/res/drawable/send_private_dark.xml b/app/src/main/res/drawable/send_private_dark.xml new file mode 100644 index 00000000..2b5117ca --- /dev/null +++ b/app/src/main/res/drawable/send_private_dark.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/send_private_light.xml b/app/src/main/res/drawable/send_private_light.xml new file mode 100644 index 00000000..eb698a94 --- /dev/null +++ b/app/src/main/res/drawable/send_private_light.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 6216f89d..8d17fe88 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -60,6 +60,7 @@ Melden Löschen TOOT + TOOT! Erneut versuchen Markiere Mediendatei als sensibel Verstecke Text hinter Warnung diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 8b573a80..a46e72a0 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -33,6 +33,7 @@ + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9522cb0f..54d69113 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -63,6 +63,7 @@ Report Delete TOOT + TOOT! Retry Mark media sensitive Hide text behind warning diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index e3855284..d7c933cf 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -51,6 +51,7 @@ @color/compose_media_button_disabled_dark @color/color_accent_dark @drawable/border_background_dark + @drawable/send_private_dark @color/notification_content_faded_dark @color/notification_icon_tint_dark @color/color_background_dark @@ -138,6 +139,7 @@ @color/compose_media_button_disabled_light @color/compose_mention_light @drawable/border_background_light + @drawable/send_private_light @color/notification_content_faded_light @color/notification_icon_tint_light @color/report_status_background_light