Finalize sticker picker

This commit is contained in:
Arne 2024-10-16 13:41:31 +02:00
parent 0fb173afae
commit 943a766493
3 changed files with 34 additions and 2 deletions

View file

@ -58,6 +58,7 @@ import androidx.core.app.RemoteInput;
import androidx.core.content.ContextCompat;
import de.monocles.chat.EmojiSearch;
import de.monocles.chat.EmojiSearchOld;
import de.monocles.chat.WebxdcUpdate;
import com.google.common.base.Objects;
@ -498,6 +499,7 @@ public class XmppConnectionService extends Service {
private final BroadcastReceiver mInternalRestrictedEventReceiver = new RestrictedEventReceiver(Arrays.asList(TorServiceUtils.ACTION_STATUS));
private final BroadcastReceiver mInternalScreenEventReceiver = new InternalEventReceiver();
private EmojiSearch emojiSearch = null;
private EmojiSearchOld emojiSearchOld = null;
private static String generateFetchKey(Account account, final Avatar avatar) {
return account.getJid().asBareJid() + "_" + avatar.owner + "_" + avatar.sha1sum;
@ -784,6 +786,7 @@ public class XmppConnectionService extends Service {
}
if (file.length() < 129000) {
emojiSearch.addEmoji(new EmojiSearch.CustomEmoji(filename, cids[0].toString(), icon, file.getParentFile().getName()));
emojiSearchOld.addEmoji(new EmojiSearchOld.CustomEmoji(filename, cids[0].toString(), icon, file.getParentFile().getName()));
}
}
} catch (final Exception e) {
@ -1473,6 +1476,7 @@ public class XmppConnectionService extends Service {
java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.FINEST);
LibIdnXmppStringprep.setup();
emojiSearch = new EmojiSearch(this);
emojiSearchOld = new EmojiSearchOld(this);
setTheme(R.style.Theme_Conversations3);
ThemeHelper.applyCustomColors(this);
if (Compatibility.runsTwentySix()) {
@ -6078,6 +6082,10 @@ public class XmppConnectionService extends Service {
}
}
public EmojiSearchOld emojiSearchOld() {
return emojiSearchOld;
}
public interface OnMamPreferencesFetched {
void onPreferencesFetched(Element prefs);

View file

@ -322,6 +322,7 @@ public class ConversationFragment extends XmppFragment
private int identiconWidth = -1;
private File savingAsSticker = null;
private EmojiSearch emojiSearch = null;
private EmojiSearchOld emojiSearchOld = null;
File dirStickers = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + "Stickers");
//Gifspaths
private File[] files;
@ -1859,6 +1860,29 @@ public class ConversationFragment extends XmppFragment
emojiSearch = activity.xmppConnectionService.emojiSearch();
}
}
if (emojiSearchOld == null && activity != null && activity.xmppConnectionService != null) {
emojiSearchOld = activity.xmppConnectionService.emojiSearchOld();
}
if (emojiSearchOld == null || binding.stickersview == null) return;
binding.stickersview.setAdapter(emojiSearchOld.makeAdapter(activity));
final Pattern lastColonPattern = Pattern.compile("");
Editable s = binding.textinput.getText();
Handler emojiDebounce = new Handler(Looper.getMainLooper());
emojiDebounce.removeCallbacksAndMessages(null);
emojiDebounce.postDelayed(() -> {
Matcher lastColonMatcher = lastColonPattern.matcher(s);
int lastColon = 0;
while(lastColonMatcher.find()) lastColon = lastColonMatcher.end();
final String q = s.toString().substring(lastColon);
EmojiSearchOld.EmojiSearchAdapter adapter = ((EmojiSearchOld.EmojiSearchAdapter) binding.stickersview.getAdapter());
if (adapter != null) {
adapter.search(q);
}
}, 400L);
}
protected void newThreadTutorialToast(String s) {

View file

@ -34,7 +34,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.EmojiSearchRowBinding;
import eu.siacs.conversations.databinding.EmojiSearchRowOldBinding;
import eu.siacs.conversations.utils.ReplacingSerialSingleThreadExecutor;
public class EmojiSearchOld {
@ -209,7 +209,7 @@ public class EmojiSearchOld {
@Override
public View getView(int position, View view, ViewGroup parent) {
EmojiSearchRowBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.emoji_search_row_old, parent, false);
EmojiSearchRowOldBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.emoji_search_row_old, parent, false);
if (getItem(position) instanceof CustomEmoji) {
binding.nonunicode.setText(getItem(position).toInsert());
binding.nonunicode.setVisibility(View.VISIBLE);