restart app when pinned changes

This commit is contained in:
sk
2023-01-21 19:55:51 +01:00
parent 187190c07e
commit 4b6a0b71a0
4 changed files with 21 additions and 41 deletions

View File

@@ -64,7 +64,6 @@ import me.grishka.appkit.utils.V;
public class HomeTabFragment extends MastodonToolbarFragment implements ScrollableToTop, OnBackPressedListener { public class HomeTabFragment extends MastodonToolbarFragment implements ScrollableToTop, OnBackPressedListener {
private static final int ANNOUNCEMENTS_RESULT = 654; private static final int ANNOUNCEMENTS_RESULT = 654;
private static final int PINNED_UPDATED_RESULT = 523;
private String accountID; private String accountID;
private MenuItem announcements; private MenuItem announcements;
@@ -86,7 +85,7 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab
private Fragment[] fragments; private Fragment[] fragments;
private FrameLayout[] tabViews; private FrameLayout[] tabViews;
private TimelineDefinition[] timelines; private TimelineDefinition[] timelines;
private Map<Integer, TimelineDefinition> timelinesByMenuItem = new HashMap<>(); private final Map<Integer, TimelineDefinition> timelinesByMenuItem = new HashMap<>();
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@@ -378,11 +377,11 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab
args.putString("listID", list.id); args.putString("listID", list.id);
args.putString("listTitle", list.title); args.putString("listTitle", list.title);
args.putInt("repliesPolicy", list.repliesPolicy.ordinal()); args.putInt("repliesPolicy", list.repliesPolicy.ordinal());
Nav.goForResult(getActivity(), ListTimelineFragment.class, args, PINNED_UPDATED_RESULT, this); Nav.go(getActivity(), ListTimelineFragment.class, args);
} else if ((hashtag = hashtagsItems.get(id)) != null) { } else if ((hashtag = hashtagsItems.get(id)) != null) {
args.putString("hashtag", hashtag.name); args.putString("hashtag", hashtag.name);
args.putBoolean("following", hashtag.following); args.putBoolean("following", hashtag.following);
Nav.goForResult(getActivity(), HashtagTimelineFragment.class, args, PINNED_UPDATED_RESULT, this); Nav.go(getActivity(), HashtagTimelineFragment.class, args);
} else { } else {
TimelineDefinition tl = timelinesByMenuItem.get(id); TimelineDefinition tl = timelinesByMenuItem.get(id);
if (tl != null) { if (tl != null) {
@@ -511,8 +510,6 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab
announcements.setIcon(R.drawable.ic_fluent_megaphone_24_regular); announcements.setIcon(R.drawable.ic_fluent_megaphone_24_regular);
announcements.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); announcements.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
UiUtils.insetPopupMenuIcon(getContext(), announcements); UiUtils.insetPopupMenuIcon(getContext(), announcements);
} else if (reqCode == PINNED_UPDATED_RESULT && result != null && result.getBoolean("pinnedUpdated", false)) {
UiUtils.restartApp();
} }
} }
@@ -546,6 +543,13 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab
} }
} }
@Override
protected void onShown() {
super.onShown();
Object pinnedTimelines = GlobalUserPreferences.pinnedTimelines.get(accountID);
if (pinnedTimelines != null && timelineDefinitions != pinnedTimelines) UiUtils.restartApp();
}
@Override @Override
public void onViewStateRestored(Bundle savedInstanceState) { public void onViewStateRestored(Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState); super.onViewStateRestored(savedInstanceState);

View File

@@ -38,7 +38,6 @@ public class ListTimelineFragment extends PinnableStatusListFragment {
private String listTitle; private String listTitle;
private ListTimeline.RepliesPolicy repliesPolicy; private ListTimeline.RepliesPolicy repliesPolicy;
private ImageButton fab; private ImageButton fab;
private Bundle resultArgs = new Bundle();
public ListTimelineFragment() { public ListTimelineFragment() {
setListLayoutId(R.layout.recycler_fragment_with_fab); setListLayoutId(R.layout.recycler_fragment_with_fab);
@@ -51,7 +50,6 @@ public class ListTimelineFragment extends PinnableStatusListFragment {
listID = args.getString("listID"); listID = args.getString("listID");
listTitle = args.getString("listTitle"); listTitle = args.getString("listTitle");
repliesPolicy = ListTimeline.RepliesPolicy.values()[args.getInt("repliesPolicy", 0)]; repliesPolicy = ListTimeline.RepliesPolicy.values()[args.getInt("repliesPolicy", 0)];
resultArgs.putString("listID", listID);
setTitle(listTitle); setTitle(listTitle);
setHasOptionsMenu(true); setHasOptionsMenu(true);
@@ -95,9 +93,11 @@ public class ListTimelineFragment extends PinnableStatusListFragment {
setTitle(list.title); setTitle(list.title);
listTitle = list.title; listTitle = list.title;
repliesPolicy = list.repliesPolicy; repliesPolicy = list.repliesPolicy;
resultArgs.putString("listTitle", listTitle); Bundle result = new Bundle();
resultArgs.putInt("repliesPolicy", repliesPolicy.ordinal()); result.putString("listID", listID);
setResult(true, resultArgs); result.putString("listTitle", listTitle);
result.putInt("repliesPolicy", repliesPolicy.ordinal());
setResult(true, result);
} }
@Override @Override
@@ -110,19 +110,16 @@ public class ListTimelineFragment extends PinnableStatusListFragment {
.show(); .show();
} else if (item.getItemId() == R.id.delete) { } else if (item.getItemId() == R.id.delete) {
UiUtils.confirmDeleteList(getActivity(), accountID, listID, listTitle, () -> { UiUtils.confirmDeleteList(getActivity(), accountID, listID, listTitle, () -> {
resultArgs.putBoolean("deleted", true); Bundle result = new Bundle();
setResult(true, resultArgs); result.putBoolean("deleted", true);
result.putString("listID", listID);
setResult(true, result);
Nav.finish(this); Nav.finish(this);
}); });
} }
return true; return true;
} }
@Override
public Bundle getResultArgs() {
return resultArgs;
}
@Override @Override
protected TimelineDefinition makeTimelineDefinition() { protected TimelineDefinition makeTimelineDefinition() {
return TimelineDefinition.ofList(listID, listTitle); return TimelineDefinition.ofList(listID, listTitle);

View File

@@ -47,7 +47,6 @@ public class ListTimelinesFragment extends BaseRecyclerFragment<ListTimeline> im
private HashMap<String, Boolean> userInList = new HashMap<>(); private HashMap<String, Boolean> userInList = new HashMap<>();
private int inProgress = 0; private int inProgress = 0;
private ListsAdapter adapter; private ListsAdapter adapter;
private boolean pinnedUpdated;
public ListTimelinesFragment() { public ListTimelinesFragment() {
super(10); super(10);
@@ -76,12 +75,6 @@ public class ListTimelinesFragment extends BaseRecyclerFragment<ListTimeline> im
loadData(); loadData();
} }
@Override
public void onDestroy() {
super.onDestroy();
if (pinnedUpdated) UiUtils.restartApp();
}
@Override @Override
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
@@ -167,7 +160,6 @@ public class ListTimelinesFragment extends BaseRecyclerFragment<ListTimeline> im
@Override @Override
public void onFragmentResult(int reqCode, boolean listChanged, Bundle result){ public void onFragmentResult(int reqCode, boolean listChanged, Bundle result){
if (reqCode == LIST_CHANGED_RESULT && listChanged) { if (reqCode == LIST_CHANGED_RESULT && listChanged) {
if (result.getBoolean("pinnedUpdated")) pinnedUpdated = true;
String listID = result.getString("listID"); String listID = result.getString("listID");
for (int i = 0; i < data.size(); i++) { for (int i = 0; i < data.size(); i++) {
ListTimeline item = data.get(i); ListTimeline item = data.get(i);

View File

@@ -15,7 +15,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public abstract class PinnableStatusListFragment extends StatusListFragment { public abstract class PinnableStatusListFragment extends StatusListFragment {
protected boolean pinnedUpdated;
protected List<TimelineDefinition> pinnedTimelines; protected List<TimelineDefinition> pinnedTimelines;
@Override @Override
@@ -54,7 +53,7 @@ public abstract class PinnableStatusListFragment extends StatusListFragment {
} }
protected void togglePin(MenuItem pin) { protected void togglePin(MenuItem pin) {
pinnedUpdated = true; onPinnedUpdated(true);
getToolbar().performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK); getToolbar().performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK);
TimelineDefinition def = makeTimelineDefinition(); TimelineDefinition def = makeTimelineDefinition();
boolean pinned = isPinned(); boolean pinned = isPinned();
@@ -66,17 +65,5 @@ public abstract class PinnableStatusListFragment extends StatusListFragment {
updatePinButton(pin); updatePinButton(pin);
} }
protected Bundle getResultArgs() { public void onPinnedUpdated(boolean pinned) {}
return new Bundle();
}
@Override
public void onDestroy() {
super.onDestroy();
Bundle resultArgs = getResultArgs();
if (pinnedUpdated) {
resultArgs.putBoolean("pinnedUpdated", true);
setResult(true, resultArgs);
}
}
} }