show error message when instance has no custom emojis

This commit is contained in:
Conny Duck 2018-04-17 22:39:55 +02:00
parent 145c6a8acb
commit 7f5f0e8dd8
3 changed files with 33 additions and 20 deletions

View file

@ -275,15 +275,18 @@ public final class ComposeActivity
emojiView.setLayoutManager(new GridLayoutManager(this, 3, GridLayoutManager.HORIZONTAL, false)); emojiView.setLayoutManager(new GridLayoutManager(this, 3, GridLayoutManager.HORIZONTAL, false));
enableButton(emojiButton, false, false);
mastodonApi.getCustomEmojis().enqueue(new Callback<List<Emoji>>() { mastodonApi.getCustomEmojis().enqueue(new Callback<List<Emoji>>() {
@Override @Override
public void onResponse(@NonNull Call<List<Emoji>> call, @NonNull Response<List<Emoji>> response) { public void onResponse(@NonNull Call<List<Emoji>> call, @NonNull Response<List<Emoji>> response) {
List<Emoji> emojiList = response.body(); List<Emoji> emojiList = response.body();
if (emojiList != null) { if (emojiList != null) {
emojiView.setAdapter(new EmojiAdapter(emojiList, ComposeActivity.this)); emojiView.setAdapter(new EmojiAdapter(emojiList, ComposeActivity.this));
enableButton(emojiButton, true, emojiList.size() > 0);
EmojiListEntity emojiListEntity = new EmojiListEntity(activeAccount.getDomain(), emojiList); EmojiListEntity emojiListEntity = new EmojiListEntity(activeAccount.getDomain(), emojiList);
TuskyApplication.getDB().emojiListDao().insertOrReplace(emojiListEntity); TuskyApplication.getDB().emojiListDao().insertOrReplace(emojiListEntity);
@ -297,6 +300,7 @@ public final class ComposeActivity
if(emojiListEntity != null) { if(emojiListEntity != null) {
emojiView.setAdapter(new EmojiAdapter(emojiListEntity.getEmojiList(), ComposeActivity.this)); emojiView.setAdapter(new EmojiAdapter(emojiListEntity.getEmojiList(), ComposeActivity.this));
enableButton(emojiButton, true, emojiListEntity.getEmojiList().size() > 0);
} }
} }
}); });
@ -705,14 +709,24 @@ public final class ComposeActivity
} }
private void showEmojis() { private void showEmojis() {
if (emojiBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN || emojiBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
emojiBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
composeOptionsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
addMediaBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
} else { if(emojiView.getAdapter() != null) {
emojiBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); if(emojiView.getAdapter().getItemCount() == 0) {
String errorMessage = getString(R.string.error_no_custom_emojis, accountManager.getActiveAccount().getDomain());
Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT).show();
} else {
if (emojiBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN || emojiBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
emojiBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
composeOptionsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
addMediaBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
} else {
emojiBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
}
}
} }
} }
private void openPickDialog() { private void openPickDialog() {
@ -980,16 +994,10 @@ public final class ComposeActivity
startActivityForResult(intent, MEDIA_PICK_RESULT); startActivityForResult(intent, MEDIA_PICK_RESULT);
} }
private void enableMediaButtons() { private void enableButton(ImageButton button, boolean clickable, boolean colorActive) {
pickButton.setEnabled(true); button.setEnabled(clickable);
ThemeUtils.setDrawableTint(this, pickButton.getDrawable(), ThemeUtils.setDrawableTint(this, button.getDrawable(),
android.R.attr.textColorTertiary); colorActive ? android.R.attr.textColorTertiary : R.attr.compose_media_button_disabled_tint);
}
private void disableMediaButtons() {
pickButton.setEnabled(false);
ThemeUtils.setDrawableTint(this, pickButton.getDrawable(),
R.attr.compose_media_button_disabled_tint);
} }
private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize, private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize,
@ -1016,11 +1024,11 @@ public final class ComposeActivity
if (queuedCount == 1) { if (queuedCount == 1) {
// If there's one video in the queue it is full, so disable the button to queue more. // If there's one video in the queue it is full, so disable the button to queue more.
if (item.type == QueuedMedia.Type.VIDEO) { if (item.type == QueuedMedia.Type.VIDEO) {
disableMediaButtons(); enableButton(pickButton, false, false);
} }
} else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) { } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
// Limit the total media attachments, also. // Limit the total media attachments, also.
disableMediaButtons(); enableButton(pickButton, false, false);
} }
updateHideMediaToggle(); updateHideMediaToggle();
@ -1127,7 +1135,7 @@ public final class ComposeActivity
updateHideMediaToggle(); updateHideMediaToggle();
} }
enableMediaButtons(); enableButton(pickButton, true, true);
cancelReadyingMedia(item); cancelReadyingMedia(item);
} }

View file

@ -264,4 +264,7 @@
<string name="send_toot_notification_saved_content">Eine Kopie des Beitrags wurde in deine Entwürfe gespeichert</string> <string name="send_toot_notification_saved_content">Eine Kopie des Beitrags wurde in deine Entwürfe gespeichert</string>
<string name="send_toot_notification_channel_name">Beiträge senden</string> <string name="send_toot_notification_channel_name">Beiträge senden</string>
<string name="error_no_custom_emojis">Deine Instanz %s hat keine Emojis definiert</string>
</resources> </resources>

View file

@ -296,4 +296,6 @@
<string name="send_toot_notification_cancel_title">Sending cancelled</string> <string name="send_toot_notification_cancel_title">Sending cancelled</string>
<string name="send_toot_notification_saved_content">A copy of the toot has been saved to your drafts</string> <string name="send_toot_notification_saved_content">A copy of the toot has been saved to your drafts</string>
<string name="error_no_custom_emojis">Your instance %s does not have any custom emojis</string>
</resources> </resources>