From 941dd2156195962f7f8bf01b0f7802745cfa9484 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 11 Jul 2022 13:34:01 +0200 Subject: [PATCH] Some changes --- .../client/entities/misskey/MisskeyNote.java | 7 +++-- .../android/helper/CrossActionHelper.java | 2 +- .../android/ui/drawer/StatusAdapter.java | 24 ++++++++--------- .../FragmentMastodonNotification.java | 19 -------------- .../timeline/FragmentMastodonTimeline.java | 6 ----- .../FragmentNotificationContainer.java | 26 +++++++++++++------ .../viewmodel/mastodon/TimelinesVM.java | 2 +- 7 files changed, 37 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/client/entities/misskey/MisskeyNote.java b/app/src/main/java/app/fedilab/android/client/entities/misskey/MisskeyNote.java index 438325317..0c5ccaf1f 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/misskey/MisskeyNote.java +++ b/app/src/main/java/app/fedilab/android/client/entities/misskey/MisskeyNote.java @@ -55,7 +55,7 @@ public class MisskeyNote implements Serializable { @SerializedName("emojis") public List emojis; - public static Status convert(MisskeyNote misskeyNote) { + public static Status convert(MisskeyNote misskeyNote, String instance) { Status status = new Status(); status.id = misskeyNote.id; status.in_reply_to_id = misskeyNote.replyId; @@ -64,7 +64,10 @@ public class MisskeyNote implements Serializable { status.spoiler_text = misskeyNote.cw; status.visibility = misskeyNote.visibility; status.created_at = misskeyNote.createdAt; - status.uri = misskeyNote.uri; + if (misskeyNote.url == null) { + misskeyNote.url = "https://" + instance + "/notes/" + misskeyNote.id; + } + status.uri = misskeyNote.uri != null ? misskeyNote.uri : misskeyNote.url; status.url = misskeyNote.url; Account account = new Account(); diff --git a/app/src/main/java/app/fedilab/android/helper/CrossActionHelper.java b/app/src/main/java/app/fedilab/android/helper/CrossActionHelper.java index 1b617e55d..48cea1a0b 100644 --- a/app/src/main/java/app/fedilab/android/helper/CrossActionHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/CrossActionHelper.java @@ -149,7 +149,7 @@ public class CrossActionHelper { } }); } else if (targetedStatus != null) { - searchVM.search(ownerAccount.instance, ownerAccount.token, targetedStatus.url, null, "statuses", false, true, false, 0, null, null, 1) + searchVM.search(ownerAccount.instance, ownerAccount.token, targetedStatus.uri, null, "statuses", false, true, false, 0, null, null, 1) .observe((LifecycleOwner) context, results -> { if (results.statuses != null && results.statuses.size() > 0) { Status status = results.statuses.get(0); 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 6761cfa7c..de1156c54 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 @@ -520,7 +520,7 @@ public class StatusAdapter extends RecyclerView.Adapter holder.binding.actionButtonBookmark.setOnClickListener(v -> { if (remote) { Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); - searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) + searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1) .observe((LifecycleOwner) context, results -> { if (results.statuses != null && results.statuses.size() > 0) { Status fetchedStatus = statusList.get(0); @@ -545,7 +545,7 @@ public class StatusAdapter extends RecyclerView.Adapter holder.binding.statusUserInfo.setOnClickListener(v -> { if (remote) { Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); - searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) + searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1) .observe((LifecycleOwner) context, results -> { if (results.statuses != null && results.statuses.size() > 0) { Status fetchedStatus = results.statuses.get(0); @@ -575,7 +575,7 @@ public class StatusAdapter extends RecyclerView.Adapter holder.binding.statusBoosterAvatar.setOnClickListener(v -> { if (remote) { Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); - searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) + searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1) .observe((LifecycleOwner) context, results -> { if (results.statuses != null && results.statuses.size() > 0) { Status fetchedStatus = results.statuses.get(0); @@ -621,7 +621,7 @@ public class StatusAdapter extends RecyclerView.Adapter alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> { if (remote) { Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); - searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) + searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1) .observe((LifecycleOwner) context, results -> { if (results.statuses != null && results.statuses.size() > 0) { Status fetchedStatus = results.statuses.get(0); @@ -649,7 +649,7 @@ public class StatusAdapter extends RecyclerView.Adapter } else { if (remote) { Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); - searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) + searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1) .observe((LifecycleOwner) context, results -> { if (results.statuses != null && results.statuses.size() > 0) { Status fetchedStatus = results.statuses.get(0); @@ -691,7 +691,7 @@ public class StatusAdapter extends RecyclerView.Adapter alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> { if (remote) { Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); - searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) + searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1) .observe((LifecycleOwner) context, results -> { if (results.statuses != null && results.statuses.size() > 0) { Status fetchedStatus = results.statuses.get(0); @@ -719,7 +719,7 @@ public class StatusAdapter extends RecyclerView.Adapter } else { if (remote) { Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); - searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) + searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1) .observe((LifecycleOwner) context, results -> { if (results.statuses != null && results.statuses.size() > 0) { Status fetchedStatus = results.statuses.get(0); @@ -1094,7 +1094,7 @@ public class StatusAdapter extends RecyclerView.Adapter holder.binding.reblogInfo.setOnClickListener(v -> { if (remote) { Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); - searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) + searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1) .observe((LifecycleOwner) context, results -> { if (results.statuses != null && results.statuses.size() > 0) { Status fetchedStatus = results.statuses.get(0); @@ -1121,7 +1121,7 @@ public class StatusAdapter extends RecyclerView.Adapter holder.binding.favouriteInfo.setOnClickListener(v -> { if (remote) { Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); - searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) + searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1) .observe((LifecycleOwner) context, results -> { if (results.statuses != null && results.statuses.size() > 0) { Status fetchedStatus = results.statuses.get(0); @@ -1254,7 +1254,7 @@ public class StatusAdapter extends RecyclerView.Adapter //Vote on the poll if (remote) { Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); - searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) + searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1) .observe((LifecycleOwner) context, results -> { if (results.statuses != null && results.statuses.size() > 0) { Status fetchedStatus = results.statuses.get(0); @@ -1336,7 +1336,7 @@ public class StatusAdapter extends RecyclerView.Adapter } else { if (remote) { Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); - searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) + searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1) .observe((LifecycleOwner) context, results -> { if (results.statuses != null && results.statuses.size() > 0) { Status fetchedStatus = results.statuses.get(0); @@ -1627,7 +1627,7 @@ public class StatusAdapter extends RecyclerView.Adapter holder.binding.actionButtonReply.setOnClickListener(v -> { if (remote) { Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); - searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.url, null, "statuses", false, true, false, 0, null, null, 1) + searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1) .observe((LifecycleOwner) context, results -> { if (results.statuses != null && results.statuses.size() > 0) { Status fetchedStatus = statusList.get(0); 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 e17d319aa..6d3ce11f6 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,17 +14,14 @@ 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.app.NotificationManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; -import android.service.notification.StatusBarNotification; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -178,22 +175,6 @@ public class FragmentMastodonNotification extends Fragment implements Notificati } - @Override - public void onResume() { - super.onResume(); - NotificationManager mNotificationManager = (NotificationManager) requireActivity().getSystemService(Context.NOTIFICATION_SERVICE); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && BaseMainActivity.currentAccount != null && BaseMainActivity.currentAccount.mastodon_account != null) { - for (StatusBarNotification statusBarNotification : mNotificationManager.getActiveNotifications()) { - if ((BaseMainActivity.currentAccount.mastodon_account.acct + "@" + BaseMainActivity.currentAccount.instance).equals(statusBarNotification.getGroupKey())) { - mNotificationManager.cancel(statusBarNotification.getId()); - } - } - } else { - mNotificationManager.cancelAll(); - } - } - - /** * Intialize the view for notifications * diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index a69d7d38d..b499fb7a8 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -30,7 +30,6 @@ import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; import androidx.localbroadcastmanager.content.LocalBroadcastManager; @@ -188,11 +187,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } } - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - } - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentNotificationContainer.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentNotificationContainer.java index 5cc13408d..2e138d611 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentNotificationContainer.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentNotificationContainer.java @@ -14,15 +14,17 @@ 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.annotation.SuppressLint; +import android.app.NotificationManager; +import android.content.Context; import android.content.SharedPreferences; +import android.os.Build; import android.os.Bundle; +import android.service.notification.StatusBarNotification; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.core.content.ContextCompat; import androidx.core.content.res.ResourcesCompat; @@ -238,6 +240,20 @@ public class FragmentNotificationContainer extends Fragment { return binding.getRoot(); } + @Override + public void onResume() { + super.onResume(); + NotificationManager mNotificationManager = (NotificationManager) requireActivity().getSystemService(Context.NOTIFICATION_SERVICE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && BaseMainActivity.currentAccount != null && BaseMainActivity.currentAccount.mastodon_account != null) { + for (StatusBarNotification statusBarNotification : mNotificationManager.getActiveNotifications()) { + if (statusBarNotification.getGroupKey().contains(BaseMainActivity.currentAccount.mastodon_account.acct + "@" + BaseMainActivity.currentAccount.instance)) { + mNotificationManager.cancel(statusBarNotification.getId()); + } + } + } else { + mNotificationManager.cancelAll(); + } + } public void scrollToTop() { if (binding != null) { @@ -251,11 +267,5 @@ public class FragmentNotificationContainer extends Fragment { } } - @SuppressLint("ApplySharedPref") - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - } } diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java index 465ec9e59..019db2a11 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java @@ -274,7 +274,7 @@ public class TimelinesVM extends AndroidViewModel { List statusList = new ArrayList<>(); if (misskeyNoteList != null) { for (MisskeyNote misskeyNote : misskeyNoteList) { - Status status = MisskeyNote.convert(misskeyNote); + Status status = MisskeyNote.convert(misskeyNote, instance); statusList.add(status); } }