diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index 5b8c80a7..38571c9b 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -222,7 +222,6 @@ public class StatusAdapter extends RecyclerView.Adapter holder.binding.actionButtonFavorite.setInActiveImageTintColor(theme_icons_color); holder.binding.actionButtonBookmark.setInActiveImageTintColor(theme_icons_color); holder.binding.actionButtonBoost.setInActiveImageTintColor(theme_icons_color); - //holder.binding.actionButtonBoost.setColors(R.color.marked_icon, R.color.marked_icon); if (theme_text_header_2_line != -1) { Pattern hashAcct; diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java index c47f77a9..b7754526 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java @@ -14,6 +14,10 @@ package app.fedilab.android.ui.fragment.timeline; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; @@ -23,6 +27,7 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -37,6 +42,7 @@ import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; import app.fedilab.android.client.mastodon.entities.Notification; import app.fedilab.android.client.mastodon.entities.Notifications; +import app.fedilab.android.client.mastodon.entities.Status; import app.fedilab.android.databinding.FragmentPaginationBinding; import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.MastodonHelper; @@ -58,6 +64,46 @@ public class FragmentMastodonNotification extends Fragment { private NotificationTypeEnum notificationType; private List excludeType; + private final BroadcastReceiver receive_action = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + Bundle b = intent.getExtras(); + if (b != null) { + Status receivedStatus = (Status) b.getSerializable(Helper.ARG_STATUS_ACTION); + if (receivedStatus != null && notificationAdapter != null) { + int position = getPosition(receivedStatus); + if (position >= 0) { + if (notifications.get(position).status != null) { + notifications.get(position).status.reblog = receivedStatus.reblog; + notifications.get(position).status.favourited = receivedStatus.favourited; + notifications.get(position).status.bookmarked = receivedStatus.bookmarked; + notificationAdapter.notifyItemChanged(position); + } + } + } + } + } + }; + + /** + * Return the position of the status in the ArrayList + * + * @param status - Status to fetch + * @return position or -1 if not found + */ + private int getPosition(Status status) { + int position = 0; + boolean found = false; + for (Notification _notification : notifications) { + if (_notification.status != null && _notification.status.id.compareTo(status.id) == 0) { + found = true; + break; + } + position++; + } + return found ? position : -1; + } + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -113,6 +159,7 @@ public class FragmentMastodonNotification extends Fragment { } notificationsVM.getNotifications(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null, null, null, MastodonHelper.statusesPerCall(requireActivity()), excludeType, null) .observe(getViewLifecycleOwner(), this::initializeNotificationView); + LocalBroadcastManager.getInstance(requireActivity()).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION)); return root; } @@ -207,6 +254,7 @@ public class FragmentMastodonNotification extends Fragment { public void onDestroyView() { super.onDestroyView(); binding.recyclerView.setAdapter(null); + LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(receive_action); notificationAdapter = null; binding = null; }