feat: readd recent emoji support
This commit is contained in:
parent
c3f3a9be7e
commit
b5123ff865
|
@ -12,9 +12,11 @@ import org.joinmastodon.android.R;
|
|||
import org.joinmastodon.android.api.MastodonAPIController;
|
||||
import org.joinmastodon.android.api.session.AccountSession;
|
||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||
import org.joinmastodon.android.fragments.HasAccountID;
|
||||
import org.joinmastodon.android.model.viewmodel.ListItem;
|
||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -24,9 +26,11 @@ import me.grishka.appkit.utils.MergeRecyclerAdapter;
|
|||
import me.grishka.appkit.utils.SingleViewRecyclerAdapter;
|
||||
import me.grishka.appkit.utils.V;
|
||||
|
||||
public class SettingsAboutAppFragment extends BaseSettingsFragment<Void>{
|
||||
public class SettingsAboutAppFragment extends BaseSettingsFragment<Void> implements HasAccountID{
|
||||
private ListItem<Void> mediaCacheItem;
|
||||
|
||||
// MOSHIDON
|
||||
private ListItem<Void> clearRecentEmojisItem;
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -37,6 +41,7 @@ public class SettingsAboutAppFragment extends BaseSettingsFragment<Void>{
|
|||
new ListItem<>(R.string.mo_settings_contribute, 0, R.drawable.ic_fluent_open_24_regular, ()->UiUtils.launchWebBrowser(getActivity(), getString(R.string.mo_repo_url))),
|
||||
new ListItem<>(R.string.settings_tos, 0, R.drawable.ic_fluent_open_24_regular, ()->UiUtils.launchWebBrowser(getActivity(), "https://"+s.domain+"/terms")),
|
||||
new ListItem<>(R.string.settings_privacy_policy, 0, R.drawable.ic_fluent_open_24_regular, ()->UiUtils.launchWebBrowser(getActivity(), getString(R.string.privacy_policy_url)), 0, true),
|
||||
clearRecentEmojisItem=new ListItem<>(R.string.mo_clear_recent_emoji, 0, this::onClearRecentEmojisClick),
|
||||
mediaCacheItem=new ListItem<>(R.string.settings_clear_cache, 0, this::onClearMediaCacheClick)
|
||||
));
|
||||
|
||||
|
@ -73,10 +78,21 @@ public class SettingsAboutAppFragment extends BaseSettingsFragment<Void>{
|
|||
});
|
||||
}
|
||||
|
||||
private void onClearRecentEmojisClick(){
|
||||
getLocalPrefs().recentEmojis=new HashMap<>();
|
||||
getLocalPrefs().save();
|
||||
Toast.makeText(getContext(), R.string.mo_recent_emoji_cleared, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private void updateMediaCacheItem(){
|
||||
long size=ImageCache.getInstance(getActivity()).getDiskCache().size();
|
||||
mediaCacheItem.subtitle=UiUtils.formatFileSize(getActivity(), size, false);
|
||||
mediaCacheItem.isEnabled=size>0;
|
||||
rebindItem(mediaCacheItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccountID(){
|
||||
return accountID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,11 +30,15 @@ import org.joinmastodon.android.GlobalUserPreferences;
|
|||
import org.joinmastodon.android.R;
|
||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||
import org.joinmastodon.android.events.EmojiUpdatedEvent;
|
||||
import org.joinmastodon.android.fragments.HasAccountID;
|
||||
import org.joinmastodon.android.model.Emoji;
|
||||
import org.joinmastodon.android.model.EmojiCategory;
|
||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -52,7 +56,9 @@ import me.grishka.appkit.utils.MergeRecyclerAdapter;
|
|||
import me.grishka.appkit.utils.V;
|
||||
import me.grishka.appkit.views.UsableRecyclerView;
|
||||
|
||||
public class CustomEmojiPopupKeyboard extends PopupKeyboard{
|
||||
public class CustomEmojiPopupKeyboard extends PopupKeyboard implements HasAccountID{
|
||||
//determines how many emoji need to be clicked, before it disappears from the recent emojis
|
||||
private static final int NEW_RECENT_VALUE=15;
|
||||
private List<EmojiCategory> emojis;
|
||||
private UsableRecyclerView list;
|
||||
private ListImageLoaderWrapper imgLoader;
|
||||
|
@ -104,6 +110,17 @@ public class CustomEmojiPopupKeyboard extends PopupKeyboard{
|
|||
list.setPadding(V.dp(16), 0, V.dp(16), 0);
|
||||
imgLoader=new ListImageLoaderWrapper(activity, list, new RecyclerViewDelegate(list), null);
|
||||
|
||||
// inject category with last used emojis
|
||||
if (!getLocalPrefs().recentEmojis.isEmpty()) {
|
||||
List<Emoji> allAvailableEmojis = emojis.stream().flatMap(category -> category.emojis.stream()).collect(Collectors.toList());
|
||||
List<Emoji> recentEmojiList = new ArrayList<>();
|
||||
for (String emojiCode : getLocalPrefs().recentEmojis.keySet().stream().sorted(Comparator.comparingInt(getLocalPrefs().recentEmojis::get).reversed()).collect(Collectors.toList())) {
|
||||
Optional<Emoji> element = allAvailableEmojis.stream().filter(e -> e.shortcode.equals(emojiCode)).findFirst();
|
||||
element.ifPresent(recentEmojiList::add);
|
||||
}
|
||||
emojis.add(0, new EmojiCategory(activity.getString(R.string.mo_emoji_recent), recentEmojiList));
|
||||
}
|
||||
|
||||
for(EmojiCategory category:emojis)
|
||||
adapter.addAdapter(new SingleCategoryAdapter(category));
|
||||
list.setAdapter(adapter);
|
||||
|
@ -193,6 +210,11 @@ public class CustomEmojiPopupKeyboard extends PopupKeyboard{
|
|||
bottomPanel.addView(backspace, new FrameLayout.LayoutParams(V.dp(48), V.dp(48), Gravity.END | Gravity.CENTER_VERTICAL));
|
||||
}
|
||||
|
||||
//remove recently used afterwards, it would get duplicated otherwise
|
||||
if (!getLocalPrefs().recentEmojis.isEmpty()) {
|
||||
emojis.remove(0);
|
||||
}
|
||||
|
||||
return ll;
|
||||
}
|
||||
|
||||
|
@ -209,6 +231,11 @@ public class CustomEmojiPopupKeyboard extends PopupKeyboard{
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccountID(){
|
||||
return accountID;
|
||||
}
|
||||
|
||||
private class SingleCategoryAdapter extends UsableRecyclerView.Adapter<RecyclerView.ViewHolder> implements ImageLoaderRecyclerAdapter{
|
||||
private final EmojiCategory category;
|
||||
private final List<ImageLoaderRequest> requests;
|
||||
|
@ -278,6 +305,19 @@ public class CustomEmojiPopupKeyboard extends PopupKeyboard{
|
|||
}
|
||||
}
|
||||
|
||||
private void increaseEmojiCount(Emoji emoji) {
|
||||
Integer usageCount = getLocalPrefs().recentEmojis.get(emoji.shortcode);
|
||||
if (usageCount != null) {
|
||||
getLocalPrefs().recentEmojis.put(emoji.shortcode, usageCount + 1);
|
||||
} else {
|
||||
getLocalPrefs().recentEmojis.put(emoji.shortcode, NEW_RECENT_VALUE);
|
||||
}
|
||||
|
||||
getLocalPrefs().recentEmojis.entrySet().removeIf(e -> e.getValue() <= 0);
|
||||
getLocalPrefs().recentEmojis.replaceAll((k, v) -> v - 1);
|
||||
getLocalPrefs().save();
|
||||
}
|
||||
|
||||
private class EmojiViewHolder extends BindableViewHolder<Emoji> implements ImageLoaderViewHolder, UsableRecyclerView.Clickable{
|
||||
public int positionWithinCategory;
|
||||
public EmojiViewHolder(){
|
||||
|
@ -309,6 +349,7 @@ public class CustomEmojiPopupKeyboard extends PopupKeyboard{
|
|||
|
||||
@Override
|
||||
public void onClick(){
|
||||
increaseEmojiCount(item);
|
||||
listener.onEmojiSelected(item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,4 +95,5 @@
|
|||
<string name="mo_mention_reblogger_automatically">Automatically mention account who reblogged the post in replies</string>
|
||||
<string name="mo_confirm_unfollow_title">Unfollow Account</string>
|
||||
<string name="mo_confirm_unfollow">Confirm to unfollow %s</string>
|
||||
<string name="mo_recent_emoji_cleared">Recent emoji cleared</string>
|
||||
</resources>
|
Loading…
Reference in New Issue