|
|
@ -27,6 +27,7 @@ import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Looper;
|
|
|
|
import android.os.Looper;
|
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
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.RemoteInstance;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.app.TagTimeline;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.app.TagTimeline;
|
|
|
|
import app.fedilab.android.mastodon.client.entities.app.Timeline;
|
|
|
|
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.CrossActionHelper;
|
|
|
|
import app.fedilab.android.mastodon.helper.GlideApp;
|
|
|
|
import app.fedilab.android.mastodon.helper.GlideApp;
|
|
|
|
import app.fedilab.android.mastodon.helper.Helper;
|
|
|
|
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 boolean retry_for_home_done;
|
|
|
|
private String lemmy_post_id;
|
|
|
|
private String lemmy_post_id;
|
|
|
|
private boolean checkRemotely;
|
|
|
|
private boolean checkRemotely;
|
|
|
@ -230,6 +233,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
Log.v(Helper.TAG, "onResume bundleInitialized: " + bundleInitialized);
|
|
|
|
|
|
|
|
if (!bundleInitialized) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!isViewInitialized) {
|
|
|
|
if (!isViewInitialized) {
|
|
|
|
isViewInitialized = true;
|
|
|
|
isViewInitialized = true;
|
|
|
|
if (initialStatuses != null) {
|
|
|
|
if (initialStatuses != null) {
|
|
|
@ -362,39 +369,38 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|
|
|
|
|
|
|
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
|
|
|
ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
timelinesVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, TimelinesVM.class);
|
|
|
|
|
|
|
|
accountsVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, AccountsVM.class);
|
|
|
|
bundleInitialized = false;
|
|
|
|
initialStatuses = null;
|
|
|
|
|
|
|
|
lockForResumeCall = 0;
|
|
|
|
|
|
|
|
timelineType = Timeline.TimeLineEnum.HOME;
|
|
|
|
|
|
|
|
canBeFederated = true;
|
|
|
|
|
|
|
|
retry_for_home_done = false;
|
|
|
|
|
|
|
|
binding = FragmentPaginationBinding.inflate(inflater, container, 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) {
|
|
|
|
if (getArguments() != null) {
|
|
|
|
long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1);
|
|
|
|
long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1);
|
|
|
|
|
|
|
|
Log.v(Helper.TAG, "onCreateView bundleId: " + bundleId);
|
|
|
|
if (bundleId != -1) {
|
|
|
|
if (bundleId != -1) {
|
|
|
|
new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
|
|
|
|
new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
|
|
|
|
} else {
|
|
|
|
} 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();
|
|
|
|
return binding.getRoot();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initializeAfterBundle(Bundle bundle) {
|
|
|
|
private void initializeAfterBundle(Bundle bundle) {
|
|
|
|
|
|
|
|
Log.v(Helper.TAG, "initializeAfterBundle: " + bundle);
|
|
|
|
new Thread(() -> {
|
|
|
|
new Thread(() -> {
|
|
|
|
if (bundle != null) {
|
|
|
|
if (bundle != null) {
|
|
|
|
timelineType = (Timeline.TimeLineEnum) bundle.get(Helper.ARG_TIMELINE_TYPE);
|
|
|
|
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);
|
|
|
|
search = bundle.getString(Helper.ARG_SEARCH_KEYWORD, null);
|
|
|
|
searchCache = bundle.getString(Helper.ARG_SEARCH_KEYWORD_CACHE, null);
|
|
|
|
searchCache = bundle.getString(Helper.ARG_SEARCH_KEYWORD_CACHE, null);
|
|
|
|
pinnedTimeline = (PinnedTimeline) bundle.getSerializable(Helper.ARG_REMOTE_INSTANCE);
|
|
|
|
pinnedTimeline = (PinnedTimeline) bundle.getSerializable(Helper.ARG_REMOTE_INSTANCE);
|
|
|
|
|
|
|
|
|
|
|
|
if (pinnedTimeline != null && pinnedTimeline.remoteInstance != null) {
|
|
|
|
if (pinnedTimeline != null && pinnedTimeline.remoteInstance != null) {
|
|
|
|
if (pinnedTimeline.remoteInstance.type != RemoteInstance.InstanceType.NITTER) {
|
|
|
|
if (pinnedTimeline.remoteInstance.type != RemoteInstance.InstanceType.NITTER) {
|
|
|
|
remoteInstance = pinnedTimeline.remoteInstance.host;
|
|
|
|
remoteInstance = pinnedTimeline.remoteInstance.host;
|
|
|
@ -420,7 +427,9 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|
|
|
isNotPinnedTimeline = isViewInitialized;
|
|
|
|
isNotPinnedTimeline = isViewInitialized;
|
|
|
|
tagTimeline = (TagTimeline) bundle.getSerializable(Helper.ARG_TAG_TIMELINE);
|
|
|
|
tagTimeline = (TagTimeline) bundle.getSerializable(Helper.ARG_TAG_TIMELINE);
|
|
|
|
bubbleTimeline = (BubbleTimeline) bundle.getSerializable(Helper.ARG_BUBBLE_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);
|
|
|
|
exclude_replies = !bundle.getBoolean(Helper.ARG_SHOW_REPLIES, true);
|
|
|
|
checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false);
|
|
|
|
checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false);
|
|
|
|
show_pinned = bundle.getBoolean(Helper.ARG_SHOW_PINNED, 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);
|
|
|
|
minified = bundle.getBoolean(Helper.ARG_MINIFIED, false);
|
|
|
|
statusReport = (Status) bundle.getSerializable(Helper.ARG_STATUS_REPORT);
|
|
|
|
statusReport = (Status) bundle.getSerializable(Helper.ARG_STATUS_REPORT);
|
|
|
|
initialStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS);
|
|
|
|
initialStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS);
|
|
|
|
|
|
|
|
Log.v(Helper.TAG, "accountTimeline: " + accountTimeline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bundleInitialized = true;
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
|
|
Runnable myRunnable = () -> {
|
|
|
|
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
|
|
|
|
//When visiting a profile without being authenticated
|
|
|
|
if (checkRemotely) {
|
|
|
|
if (checkRemotely) {
|
|
|
|
String[] acctArray = accountTimeline.acct.split("@");
|
|
|
|
String[] acctArray = accountTimeline.acct.split("@");
|
|
|
@ -468,6 +500,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|
|
|
if (timelineType != null) {
|
|
|
|
if (timelineType != null) {
|
|
|
|
slug = timelineType != Timeline.TimeLineEnum.ART ? timelineType.getValue() + (ident != null ? "|" + ident : "") : Timeline.TimeLineEnum.TAG.getValue() + (ident != null ? "|" + ident : "");
|
|
|
|
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);
|
|
|
|
ContextCompat.registerReceiver(requireActivity(), receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|
mainHandler.post(myRunnable);
|
|
|
|