From df320324e217420ebd0d730bffd42ac8a792e293 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 16 Jun 2022 18:37:14 +0200 Subject: [PATCH] Some fixes --- .../app/fedilab/android/BaseMainActivity.java | 7 ++++--- .../activities/AnnouncementActivity.java | 6 +++--- .../android/activities/ComposeActivity.java | 21 ++++++++++++++----- .../ui/drawer/AnnouncementAdapter.java | 8 +++---- .../android/ui/drawer/ComposeAdapter.java | 16 ++++---------- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 869cf38f4..811fa5f0c 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -74,6 +74,7 @@ import com.jaredrummler.cyanea.Cyanea; import java.io.File; import java.lang.ref.WeakReference; +import java.util.HashMap; import java.util.List; import java.util.regex.Pattern; @@ -131,7 +132,7 @@ import es.dmoral.toasty.Toasty; public abstract class BaseMainActivity extends BaseActivity implements NetworkStateReceiver.NetworkStateReceiverListener { public static String currentInstance, currentToken, currentUserID, client_id, client_secret, software; - public static List emojis; + public static HashMap> emojis = new HashMap<>(); public static Account.API api; public static boolean admin; public static WeakReference accountWeakReference; @@ -731,10 +732,10 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt binding.toolbarSearch.setOnSearchClickListener(v -> binding.tabLayout.setVisibility(View.VISIBLE)); //For receiving data from other activities LocalBroadcastManager.getInstance(BaseMainActivity.this).registerReceiver(broadcast_data, new IntentFilter(Helper.BROADCAST_DATA)); - if (emojis == null) { + if (emojis == null || !emojis.containsKey(MainActivity.currentInstance)) { new Thread(() -> { try { - emojis = new EmojiInstance(BaseMainActivity.this).getEmojiList(BaseMainActivity.currentInstance); + emojis.put(currentInstance, new EmojiInstance(BaseMainActivity.this).getEmojiList(BaseMainActivity.currentInstance)); } catch (DBException e) { e.printStackTrace(); } diff --git a/app/src/main/java/app/fedilab/android/activities/AnnouncementActivity.java b/app/src/main/java/app/fedilab/android/activities/AnnouncementActivity.java index 2cfd5a1bf..8b5e147c1 100644 --- a/app/src/main/java/app/fedilab/android/activities/AnnouncementActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/AnnouncementActivity.java @@ -15,6 +15,7 @@ package app.fedilab.android.activities; * see . */ +import static app.fedilab.android.BaseMainActivity.currentInstance; import static app.fedilab.android.BaseMainActivity.emojis; import android.graphics.drawable.ColorDrawable; @@ -24,7 +25,6 @@ import android.view.MenuItem; import androidx.appcompat.app.ActionBar; import androidx.core.content.ContextCompat; -import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; import app.fedilab.android.client.entities.api.EmojiInstance; import app.fedilab.android.databinding.ActivityAnnouncementBinding; @@ -59,10 +59,10 @@ public class AnnouncementActivity extends BaseActivity { } Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_tags, new FragmentMastodonAnnouncement(), null, null, null); - if (emojis == null) { + if (emojis == null || !emojis.containsKey(currentInstance)) { new Thread(() -> { try { - emojis = new EmojiInstance(AnnouncementActivity.this).getEmojiList(BaseMainActivity.currentInstance); + emojis.put(currentInstance, new EmojiInstance(AnnouncementActivity.this).getEmojiList(currentInstance)); } catch (DBException e) { e.printStackTrace(); } diff --git a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java index f09369dc5..525bbd66a 100644 --- a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java @@ -15,6 +15,8 @@ package app.fedilab.android.activities; * see . */ +import static app.fedilab.android.BaseMainActivity.currentInstance; +import static app.fedilab.android.BaseMainActivity.emojis; import static app.fedilab.android.ui.drawer.ComposeAdapter.prepareDraft; import android.Manifest; @@ -63,6 +65,7 @@ import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; import app.fedilab.android.client.entities.api.Attachment; import app.fedilab.android.client.entities.api.Context; +import app.fedilab.android.client.entities.api.EmojiInstance; import app.fedilab.android.client.entities.api.Mention; import app.fedilab.android.client.entities.api.ScheduledStatus; import app.fedilab.android.client.entities.api.Status; @@ -199,7 +202,15 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana if (token == null) { token = account.token; } - + if (emojis == null || !emojis.containsKey(currentInstance)) { + new Thread(() -> { + try { + emojis.put(currentInstance, new EmojiInstance(ComposeActivity.this).getEmojiList(currentInstance)); + } catch (DBException e) { + e.printStackTrace(); + } + }).start(); + } StatusesVM statusesVM = new ViewModelProvider(ComposeActivity.this).get(StatusesVM.class); //Empty compose List statusDraftList = new ArrayList<>(); @@ -207,10 +218,10 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana statusDraftList.add(status); if (statusReplyId != null && statusDraft != null) {//Delete and redraft - statusesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusReplyId) + statusesVM.getStatus(currentInstance, BaseMainActivity.currentToken, statusReplyId) .observe(ComposeActivity.this, status1 -> { if (status1 != null) { - statusesVM.getContext(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusReplyId) + statusesVM.getContext(currentInstance, BaseMainActivity.currentToken, statusReplyId) .observe(ComposeActivity.this, statusContext -> { if (statusContext != null) { initializeContextRedraftView(statusContext, status1); @@ -297,7 +308,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); binding.recyclerView.setLayoutManager(mLayoutManager); binding.recyclerView.setAdapter(composeAdapter); - statusesVM.getContext(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusReply.id) + statusesVM.getContext(currentInstance, BaseMainActivity.currentToken, statusReply.id) .observe(ComposeActivity.this, this::initializeContextView); }; mainHandler.post(myRunnable); @@ -639,7 +650,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana delayToPass = (date.getTime() - new Date().getTime()); } Data inputData = new Data.Builder() - .putString(Helper.ARG_INSTANCE, BaseMainActivity.currentInstance) + .putString(Helper.ARG_INSTANCE, currentInstance) .putString(Helper.ARG_TOKEN, BaseMainActivity.currentToken) .putString(Helper.ARG_USER_ID, BaseMainActivity.currentUserID) .putLong(Helper.ARG_STATUS_DRAFT_ID, statusDraft.id) diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/AnnouncementAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/AnnouncementAdapter.java index 0153460c8..41471cff8 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/AnnouncementAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/AnnouncementAdapter.java @@ -150,12 +150,12 @@ public class AnnouncementAdapter extends RecyclerView.Adapter 0) { GridView gridView = new GridView(context); - gridView.setAdapter(new EmojiAdapter(emojis)); + gridView.setAdapter(new EmojiAdapter(emojis.get(MainActivity.currentInstance))); gridView.setNumColumns(5); gridView.setOnItemClickListener((parent, view, index, id) -> { - String emojiStr = emojis.get(index).shortcode; - String url = emojis.get(index).url; - String static_url = emojis.get(index).static_url; + String emojiStr = emojis.get(MainActivity.currentInstance).get(index).shortcode; + String url = emojis.get(MainActivity.currentInstance).get(index).url; + String static_url = emojis.get(MainActivity.currentInstance).get(index).static_url; boolean alreadyAdded = false; for (Reaction reaction : announcement.reactions) { if (reaction.name.compareTo(emojiStr) == 0) { diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java index c1b938720..272ce173c 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java @@ -83,6 +83,7 @@ import java.util.regex.Pattern; import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; import app.fedilab.android.activities.ComposeActivity; +import app.fedilab.android.activities.MainActivity; import app.fedilab.android.client.entities.api.Attachment; import app.fedilab.android.client.entities.api.Emoji; import app.fedilab.android.client.entities.api.EmojiInstance; @@ -1005,16 +1006,7 @@ public class ComposeAdapter extends RecyclerView.Adapter { - try { - emojis = new EmojiInstance(context).getEmojiList(BaseMainActivity.currentInstance); - } catch (DBException e) { - e.printStackTrace(); - } - }).start(); - } + ComposeViewHolder holder = (ComposeViewHolder) viewHolder; @@ -1235,10 +1227,10 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { GridView gridView = new GridView(context); - gridView.setAdapter(new EmojiAdapter(emojis)); + gridView.setAdapter(new EmojiAdapter(emojis.get(MainActivity.currentInstance))); gridView.setNumColumns(5); gridView.setOnItemClickListener((parent, view, position, id) -> { - holder.binding.content.getText().insert(holder.binding.content.getSelectionStart(), " :" + emojis.get(position).shortcode + ": "); + holder.binding.content.getText().insert(holder.binding.content.getSelectionStart(), " :" + emojis.get(MainActivity.currentInstance).get(position).shortcode + ": "); alertDialogEmoji.dismiss(); }); gridView.setPadding(paddingDp, paddingDp, paddingDp, paddingDp);