Probably fix empty emoji picker

This commit is contained in:
Grishka 2022-04-08 00:24:11 +03:00
parent cfcd50cb76
commit d14fc624f9
4 changed files with 33 additions and 2 deletions

View File

@ -10,6 +10,7 @@ import android.util.Log;
import com.google.gson.JsonParseException;
import org.joinmastodon.android.E;
import org.joinmastodon.android.MastodonApp;
import org.joinmastodon.android.R;
import org.joinmastodon.android.api.MastodonAPIController;
@ -18,6 +19,7 @@ import org.joinmastodon.android.api.requests.instance.GetCustomEmojis;
import org.joinmastodon.android.api.requests.accounts.GetOwnAccount;
import org.joinmastodon.android.api.requests.instance.GetInstance;
import org.joinmastodon.android.api.requests.oauth.CreateOAuthApp;
import org.joinmastodon.android.events.EmojiUpdatedEvent;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.Application;
import org.joinmastodon.android.model.Emoji;
@ -260,7 +262,7 @@ public class AccountSessionManager{
.exec(session.getID());
}
private void updateInstanceInfo(String domain){
public void updateInstanceInfo(String domain){
new GetInstance()
.setCallback(new Callback<>(){
@Override
@ -277,6 +279,7 @@ public class AccountSessionManager{
customEmojis.put(domain, groupCustomEmojis(emojis));
instancesLastUpdated.put(domain, emojis.lastUpdated);
MastodonAPIController.runInBackground(()->writeInstanceInfoFile(emojis, domain));
E.post(new EmojiUpdatedEvent(domain));
}
@Override

View File

@ -0,0 +1,9 @@
package org.joinmastodon.android.events;
public class EmojiUpdatedEvent{
public String instanceDomain;
public EmojiUpdatedEvent(String instanceDomain){
this.instanceDomain=instanceDomain;
}
}

View File

@ -196,6 +196,9 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
Nav.finish(this);
return;
}
if(customEmojis.isEmpty()){
AccountSessionManager.getInstance().updateInstanceInfo(instanceDomain);
}
if(instance.maxTootChars>0)
charLimit=instance.maxTootChars;
@ -546,7 +549,9 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
}
private void onCustomEmojiClick(Emoji emoji){
mainEditText.getText().replace(mainEditText.getSelectionStart(), mainEditText.getSelectionEnd(), ':'+emoji.shortcode+':');
int start=mainEditText.getSelectionStart();
String prefix=start>0 && !Character.isWhitespace(mainEditText.getText().charAt(start-1)) ? " :" : ":";
mainEditText.getText().replace(start, mainEditText.getSelectionEnd(), prefix+emoji.shortcode+':');
}
private void updateToolbar(){

View File

@ -1,5 +1,6 @@
package org.joinmastodon.android.ui;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.TypedArray;
import android.graphics.Rect;
@ -11,7 +12,11 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.otto.Subscribe;
import org.joinmastodon.android.R;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.events.EmojiUpdatedEvent;
import org.joinmastodon.android.model.Emoji;
import org.joinmastodon.android.model.EmojiCategory;
import org.joinmastodon.android.ui.utils.UiUtils;
@ -102,6 +107,15 @@ public class CustomEmojiPopupKeyboard extends PopupKeyboard{
this.listener=listener;
}
@SuppressLint("NotifyDataSetChanged")
@Subscribe
public void onEmojiUpdated(EmojiUpdatedEvent ev){
if(ev.instanceDomain.equals(domain)){
emojis=AccountSessionManager.getInstance().getCustomEmojis(domain);
adapter.notifyDataSetChanged();
}
}
private class SingleCategoryAdapter extends UsableRecyclerView.Adapter<RecyclerView.ViewHolder> implements ImageLoaderRecyclerAdapter{
private final EmojiCategory category;
private final List<ImageLoaderRequest> requests;