From fa100ab2772e9dd9ae7d185005c3bebf834f8251 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 8 Jun 2022 15:54:23 +0200 Subject: [PATCH] Fix #145 #146 #147 - Issue with Pleroma --- .../android/activities/ProfileActivity.java | 71 +++++++++++-------- .../fedilab/android/ui/drawer/TagAdapter.java | 9 +-- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java index 5fa11421..1a131c75 100644 --- a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java @@ -736,18 +736,25 @@ public class ProfileActivity extends BaseActivity { //Get pinned instances reorderVM.getPinned().observe(ProfileActivity.this, pinned -> { boolean alreadyPinned = false; - for (PinnedTimeline pinnedTimeline : pinned.pinnedTimelines) { - if (pinnedTimeline.remoteInstance != null && pinnedTimeline.remoteInstance.host.compareToIgnoreCase(finalInstanceName) == 0) { - alreadyPinned = true; - break; + boolean present = true; + if (pinned == null) { + pinned = new Pinned(); + pinned.pinnedTimelines = new ArrayList<>(); + present = false; + } else { + for (PinnedTimeline pinnedTimeline : pinned.pinnedTimelines) { + if (pinnedTimeline.remoteInstance != null && pinnedTimeline.remoteInstance.host.compareToIgnoreCase(finalInstanceName) == 0) { + alreadyPinned = true; + break; + } } } if (alreadyPinned) { Toasty.info(ProfileActivity.this, getString(R.string.toast_instance_already_added), Toast.LENGTH_LONG).show(); return; } + RemoteInstance.InstanceType instanceType; if (nodeInfo != null) { - RemoteInstance.InstanceType instanceType; if (nodeInfo.software.name.compareToIgnoreCase("peertube") == 0) { instanceType = RemoteInstance.InstanceType.PEERTUBE; } else if (nodeInfo.software.name.compareToIgnoreCase("pixelfed") == 0) { @@ -759,30 +766,38 @@ public class ProfileActivity extends BaseActivity { } else { instanceType = RemoteInstance.InstanceType.MASTODON; } - RemoteInstance remoteInstance = new RemoteInstance(); - remoteInstance.type = instanceType; - remoteInstance.host = finalInstanceName; - PinnedTimeline pinnedTimeline = new PinnedTimeline(); - pinnedTimeline.remoteInstance = remoteInstance; - pinnedTimeline.displayed = true; - pinnedTimeline.type = Timeline.TimeLineEnum.REMOTE; - pinnedTimeline.position = pinned.pinnedTimelines.size(); - pinned.pinnedTimelines.add(pinnedTimeline); - new Thread(() -> { - try { - new Pinned(ProfileActivity.this).updatePinned(pinned); - runOnUiThread(() -> { - Bundle b = new Bundle(); - b.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true); - Intent intentBD = new Intent(Helper.BROADCAST_DATA); - intentBD.putExtras(b); - LocalBroadcastManager.getInstance(ProfileActivity.this).sendBroadcast(intentBD); - }); - } catch (DBException e) { - e.printStackTrace(); - } - }).start(); + } else { + instanceType = RemoteInstance.InstanceType.MASTODON; } + RemoteInstance remoteInstance = new RemoteInstance(); + remoteInstance.type = instanceType; + remoteInstance.host = finalInstanceName; + PinnedTimeline pinnedTimeline = new PinnedTimeline(); + pinnedTimeline.remoteInstance = remoteInstance; + pinnedTimeline.displayed = true; + pinnedTimeline.type = Timeline.TimeLineEnum.REMOTE; + pinnedTimeline.position = pinned.pinnedTimelines.size(); + pinned.pinnedTimelines.add(pinnedTimeline); + Pinned finalPinned = pinned; + boolean finalPresent = present; + new Thread(() -> { + try { + if (finalPresent) { + new Pinned(ProfileActivity.this).updatePinned(finalPinned); + } else { + new Pinned(ProfileActivity.this).insertPinned(finalPinned); + } + runOnUiThread(() -> { + Bundle b = new Bundle(); + b.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true); + Intent intentBD = new Intent(Helper.BROADCAST_DATA); + intentBD.putExtras(b); + LocalBroadcastManager.getInstance(ProfileActivity.this).sendBroadcast(intentBD); + }); + } catch (DBException e) { + e.printStackTrace(); + } + }).start(); }); return true; diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/TagAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/TagAdapter.java index 8f790da5..09f51610 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/TagAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/TagAdapter.java @@ -59,10 +59,11 @@ public class TagAdapter extends RecyclerView.Adapter { int stat = 0; - - for (History history : historyList) { - trendsEntry.add(0, new Entry(Float.parseFloat(history.day), Float.parseFloat(history.uses))); - stat += Integer.parseInt(history.accounts); + if (historyList != null) { + for (History history : historyList) { + trendsEntry.add(0, new Entry(Float.parseFloat(history.day), Float.parseFloat(history.uses))); + stat += Integer.parseInt(history.accounts); + } } tagViewHolder.binding.tagStats.setText(context.getString(R.string.talking_about, stat)); LineDataSet dataTrending = new LineDataSet(trendsEntry, context.getString(R.string.trending));