summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java')
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java77
1 files changed, 55 insertions, 22 deletions
diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java
index 2bad15743..75149d012 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java
@@ -27,6 +27,7 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -62,6 +63,7 @@ import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline;
import app.fedilab.android.mastodon.client.entities.app.RemoteInstance;
import app.fedilab.android.mastodon.client.entities.app.TagTimeline;
import app.fedilab.android.mastodon.client.entities.app.Timeline;
+import app.fedilab.android.mastodon.exception.DBException;
import app.fedilab.android.mastodon.helper.CrossActionHelper;
import app.fedilab.android.mastodon.helper.GlideApp;
import app.fedilab.android.mastodon.helper.Helper;
@@ -178,6 +180,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
}
}
};
+ private boolean bundleInitialized;
private boolean retry_for_home_done;
private String lemmy_post_id;
private boolean checkRemotely;
@@ -230,6 +233,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
@Override
public void onResume() {
super.onResume();
+ Log.v(Helper.TAG, "onResume bundleInitialized: " + bundleInitialized);
+ if (!bundleInitialized) {
+ return;
+ }
if (!isViewInitialized) {
isViewInitialized = true;
if (initialStatuses != null) {
@@ -362,39 +369,38 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
- timelinesVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, TimelinesVM.class);
- accountsVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, AccountsVM.class);
- initialStatuses = null;
- lockForResumeCall = 0;
- timelineType = Timeline.TimeLineEnum.HOME;
- canBeFederated = true;
- retry_for_home_done = false;
+
+ bundleInitialized = false;
binding = FragmentPaginationBinding.inflate(inflater, container, false);
- SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
- max_id = statusReport != null ? statusReport.id : null;
- offset = 0;
- rememberPosition = sharedpreferences.getBoolean(getString(R.string.SET_REMEMBER_POSITION), true);
- //Inner marker are only for pinned timelines and main timelines, they have isViewInitialized set to false
- if (max_id == null && !isViewInitialized && rememberPosition) {
- max_id = sharedpreferences.getString(getString(R.string.SET_INNER_MARKER) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance + slug, null);
- }
- //Only fragment in main view pager should not have the view initialized
- //AND Only the first fragment will initialize its view
- flagLoading = false;
if (getArguments() != null) {
long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1);
+ Log.v(Helper.TAG, "onCreateView bundleId: " + bundleId);
if (bundleId != -1) {
new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
} else {
- initializeAfterBundle(getArguments());
+ if (getArguments().containsKey(Helper.ARG_CACHED_ACCOUNT_ID)) {
+ new Thread(() -> {
+ try {
+ accountTimeline = new CachedBundle(requireActivity()).getCachedAccount(currentAccount, getArguments().getString(Helper.ARG_CACHED_ACCOUNT_ID));
+ } catch (DBException e) {
+ throw new RuntimeException(e);
+ }
+ Handler mainHandler = new Handler(Looper.getMainLooper());
+ Runnable myRunnable = () -> {
+ initializeAfterBundle(getArguments());
+ };
+ mainHandler.post(myRunnable);
+ }).start();
+ } else {
+ initializeAfterBundle(getArguments());
+ }
}
}
- boolean displayScrollBar = sharedpreferences.getBoolean(getString(R.string.SET_TIMELINE_SCROLLBAR), false);
- binding.recyclerView.setVerticalScrollBarEnabled(displayScrollBar);
return binding.getRoot();
}
private void initializeAfterBundle(Bundle bundle) {
+ Log.v(Helper.TAG, "initializeAfterBundle: " + bundle);
new Thread(() -> {
if (bundle != null) {
timelineType = (Timeline.TimeLineEnum) bundle.get(Helper.ARG_TIMELINE_TYPE);
@@ -403,6 +409,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
search = bundle.getString(Helper.ARG_SEARCH_KEYWORD, null);
searchCache = bundle.getString(Helper.ARG_SEARCH_KEYWORD_CACHE, null);
pinnedTimeline = (PinnedTimeline) bundle.getSerializable(Helper.ARG_REMOTE_INSTANCE);
+
if (pinnedTimeline != null && pinnedTimeline.remoteInstance != null) {
if (pinnedTimeline.remoteInstance.type != RemoteInstance.InstanceType.NITTER) {
remoteInstance = pinnedTimeline.remoteInstance.host;
@@ -420,7 +427,9 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
isNotPinnedTimeline = isViewInitialized;
tagTimeline = (TagTimeline) bundle.getSerializable(Helper.ARG_TAG_TIMELINE);
bubbleTimeline = (BubbleTimeline) bundle.getSerializable(Helper.ARG_BUBBLE_TIMELINE);
- accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT);
+ if (bundle.containsKey(Helper.ARG_ACCOUNT)) {
+ accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT);
+ }
exclude_replies = !bundle.getBoolean(Helper.ARG_SHOW_REPLIES, true);
checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false);
show_pinned = bundle.getBoolean(Helper.ARG_SHOW_PINNED, false);
@@ -430,9 +439,32 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
minified = bundle.getBoolean(Helper.ARG_MINIFIED, false);
statusReport = (Status) bundle.getSerializable(Helper.ARG_STATUS_REPORT);
initialStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS);
+ Log.v(Helper.TAG, "accountTimeline: " + accountTimeline);
}
+ bundleInitialized = true;
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
+ timelinesVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, TimelinesVM.class);
+ accountsVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, AccountsVM.class);
+ initialStatuses = null;
+ lockForResumeCall = 0;
+ timelineType = Timeline.TimeLineEnum.HOME;
+ canBeFederated = true;
+ retry_for_home_done = false;
+ SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
+ boolean displayScrollBar = sharedpreferences.getBoolean(getString(R.string.SET_TIMELINE_SCROLLBAR), false);
+ binding.recyclerView.setVerticalScrollBarEnabled(displayScrollBar);
+ max_id = statusReport != null ? statusReport.id : null;
+ offset = 0;
+ rememberPosition = sharedpreferences.getBoolean(getString(R.string.SET_REMEMBER_POSITION), true);
+ //Inner marker are only for pinned timelines and main timelines, they have isViewInitialized set to false
+ if (max_id == null && !isViewInitialized && rememberPosition) {
+ max_id = sharedpreferences.getString(getString(R.string.SET_INNER_MARKER) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance + slug, null);
+ }
+ //Only fragment in main view pager should not have the view initialized
+ //AND Only the first fragment will initialize its view
+ flagLoading = false;
+
//When visiting a profile without being authenticated
if (checkRemotely) {
String[] acctArray = accountTimeline.acct.split("@");
@@ -468,6 +500,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
if (timelineType != null) {
slug = timelineType != Timeline.TimeLineEnum.ART ? timelineType.getValue() + (ident != null ? "|" + ident : "") : Timeline.TimeLineEnum.TAG.getValue() + (ident != null ? "|" + ident : "");
}
+
ContextCompat.registerReceiver(requireActivity(), receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
};
mainHandler.post(myRunnable);