Pass ids for pagers

custom_intent
Thomas 10 months ago
parent 85e462e276
commit 08c1ba943b

@ -23,6 +23,7 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Parcel; import android.os.Parcel;
import android.util.Base64; import android.util.Base64;
import android.util.Log;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ -34,6 +35,7 @@ import java.util.Date;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import app.fedilab.android.mastodon.client.entities.api.Account;
import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.api.Status;
import app.fedilab.android.mastodon.exception.DBException; import app.fedilab.android.mastodon.exception.DBException;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
@ -81,19 +83,21 @@ public class CachedBundle {
values.put(Sqlite.COL_BUNDLE, serializeBundle(bundle)); values.put(Sqlite.COL_BUNDLE, serializeBundle(bundle));
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date())); values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date()));
values.put(Sqlite.COL_TYPE, CacheType.ARGS.getValue()); values.put(Sqlite.COL_TYPE, CacheType.ARGS.getValue());
Log.v(Helper.TAG, "insertIntent --> " + currentUser);
if (bundle.containsKey(Helper.ARG_ACCOUNT) && currentUser != null) { if (bundle.containsKey(Helper.ARG_ACCOUNT) && currentUser != null) {
ContentValues valuesAccount = new ContentValues(); ContentValues valuesAccount = new ContentValues();
Bundle bundleAccount = new Bundle(); Bundle bundleAccount = new Bundle();
Account account = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); Account account = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT);
Log.v(Helper.TAG, "account --> " + account);
if (account != null) { if (account != null) {
bundleAccount.putSerializable(Helper.ARG_ACCOUNT, account); bundleAccount.putSerializable(Helper.ARG_ACCOUNT, account);
valuesAccount.put(Sqlite.COL_BUNDLE, serializeBundle(bundleAccount)); valuesAccount.put(Sqlite.COL_BUNDLE, serializeBundle(bundleAccount));
valuesAccount.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date())); valuesAccount.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date()));
valuesAccount.put(Sqlite.COL_TARGET_ID, account.user_id); valuesAccount.put(Sqlite.COL_TARGET_ID, account.id);
valuesAccount.put(Sqlite.COL_USER_ID, currentUser.user_id); valuesAccount.put(Sqlite.COL_USER_ID, currentUser.user_id);
valuesAccount.put(Sqlite.COL_INSTANCE, currentUser.instance); valuesAccount.put(Sqlite.COL_INSTANCE, currentUser.instance);
valuesAccount.put(Sqlite.COL_TYPE, CacheType.ACCOUNT.getValue()); valuesAccount.put(Sqlite.COL_TYPE, CacheType.ACCOUNT.getValue());
removeIntent(currentUser, account.user_id); removeIntent(currentUser, account.id);
db.insertOrThrow(Sqlite.TABLE_INTENT, null, valuesAccount); db.insertOrThrow(Sqlite.TABLE_INTENT, null, valuesAccount);
} }
} }
@ -126,8 +130,12 @@ public class CachedBundle {
Bundle bundle = null; Bundle bundle = null;
try { try {
CachedBundle cachedBundle = getCachedBundle(String.valueOf(id)); CachedBundle cachedBundle = getCachedBundle(String.valueOf(id));
Log.v(Helper.TAG, "cachedBundle --> " + cachedBundle);
if (cachedBundle != null) { if (cachedBundle != null) {
bundle = cachedBundle.bundle; bundle = cachedBundle.bundle;
if (bundle != null) {
Log.v(Helper.TAG, "bundle.containsKey(Helper.ARG_CACHED_ACCOUNT_ID) --> " + bundle.containsKey(Helper.ARG_CACHED_ACCOUNT_ID));
}
if (bundle != null && bundle.containsKey(Helper.ARG_CACHED_ACCOUNT_ID)) { if (bundle != null && bundle.containsKey(Helper.ARG_CACHED_ACCOUNT_ID)) {
Account cachedAccount = getCachedAccount(Account, bundle.getString(Helper.ARG_CACHED_ACCOUNT_ID)); Account cachedAccount = getCachedAccount(Account, bundle.getString(Helper.ARG_CACHED_ACCOUNT_ID));
if (cachedAccount != null) { if (cachedAccount != null) {
@ -171,10 +179,11 @@ public class CachedBundle {
* @param target_id String * @param target_id String
* @return Account {@link Account} * @return Account {@link Account}
*/ */
private Account getCachedAccount(BaseAccount account, String target_id) throws DBException { public Account getCachedAccount(BaseAccount account, String target_id) throws DBException {
if (db == null) { if (db == null) {
throw new DBException("db is null. Wrong initialization."); throw new DBException("db is null. Wrong initialization.");
} }
Log.v(Helper.TAG, "getCachedAccount --> " + account + " -> " + target_id);
if (account == null || target_id == null) { if (account == null || target_id == null) {
return null; return null;
} }
@ -184,10 +193,14 @@ public class CachedBundle {
+ Sqlite.COL_TYPE + " = '" + CacheType.ACCOUNT.getValue() + "' AND " + Sqlite.COL_TYPE + " = '" + CacheType.ACCOUNT.getValue() + "' AND "
+ Sqlite.COL_TARGET_ID + " = '" + target_id + "'", null, null, null, null, "1"); + Sqlite.COL_TARGET_ID + " = '" + target_id + "'", null, null, null, null, "1");
CachedBundle cachedBundle = cursorToCachedBundle(c); CachedBundle cachedBundle = cursorToCachedBundle(c);
if (cachedBundle != null) {
Log.v(Helper.TAG, "cachedBundle.bundle --> " + cachedBundle.bundle);
}
if (cachedBundle != null && cachedBundle.bundle.containsKey(Helper.ARG_ACCOUNT)) { if (cachedBundle != null && cachedBundle.bundle.containsKey(Helper.ARG_ACCOUNT)) {
return (Account) cachedBundle.bundle.getSerializable(Helper.ARG_ACCOUNT); return (Account) cachedBundle.bundle.getSerializable(Helper.ARG_ACCOUNT);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
return null; return null;
} }
return null; return null;

@ -51,6 +51,7 @@ import app.fedilab.android.R;
import app.fedilab.android.databinding.DrawerConversationBinding; import app.fedilab.android.databinding.DrawerConversationBinding;
import app.fedilab.android.databinding.ThumbnailBinding; import app.fedilab.android.databinding.ThumbnailBinding;
import app.fedilab.android.mastodon.activities.ContextActivity; import app.fedilab.android.mastodon.activities.ContextActivity;
import app.fedilab.android.mastodon.activities.DirectMessageActivity;
import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Account;
import app.fedilab.android.mastodon.client.entities.api.Attachment; import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.client.entities.api.Conversation; import app.fedilab.android.mastodon.client.entities.api.Conversation;
@ -58,7 +59,6 @@ import app.fedilab.android.mastodon.client.entities.api.Status;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.helper.MastodonHelper; import app.fedilab.android.mastodon.helper.MastodonHelper;
import app.fedilab.android.mastodon.activities.DirectMessageActivity;
public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

@ -18,6 +18,8 @@ import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -41,6 +43,7 @@ import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.api.Status;
import app.fedilab.android.mastodon.client.entities.api.Statuses; import app.fedilab.android.mastodon.client.entities.api.Statuses;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
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.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.helper.MastodonHelper; import app.fedilab.android.mastodon.helper.MastodonHelper;
@ -74,19 +77,41 @@ public class FragmentMediaProfile extends Fragment {
if (getArguments() != null) { if (getArguments() != null) {
long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1);
new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> { if (bundleId != -1) {
if (bundle != null) { new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); } else {
checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); 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());
} }
}); }
} else {
initializeAfterBundle(null);
} }
return binding.getRoot(); return binding.getRoot();
} }
@Override private void initializeAfterBundle(Bundle bundle) {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); if (bundle != null) {
if (bundle.containsKey(Helper.ARG_ACCOUNT)) {
accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT);
}
checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false);
}
flagLoading = false; flagLoading = false;
accountsVM = new ViewModelProvider(requireActivity()).get(AccountsVM.class); accountsVM = new ViewModelProvider(requireActivity()).get(AccountsVM.class);
mediaStatuses = new ArrayList<>(); mediaStatuses = new ArrayList<>();
@ -122,7 +147,12 @@ public class FragmentMediaProfile extends Fragment {
accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, null, null, true, false, MastodonHelper.statusesPerCall(requireActivity())) accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, null, null, true, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} }
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
} }
/** /**

@ -22,6 +22,8 @@ import static app.fedilab.android.mastodon.helper.MastodonHelper.ACCOUNTS_PER_CA
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -47,6 +49,7 @@ import app.fedilab.android.mastodon.client.entities.api.Pagination;
import app.fedilab.android.mastodon.client.entities.api.RelationShip; import app.fedilab.android.mastodon.client.entities.api.RelationShip;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
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.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.helper.MastodonHelper; import app.fedilab.android.mastodon.helper.MastodonHelper;
import app.fedilab.android.mastodon.ui.drawer.AccountAdapter; import app.fedilab.android.mastodon.ui.drawer.AccountAdapter;
@ -83,7 +86,26 @@ public class FragmentMastodonAccount extends Fragment {
token = currentToken; token = currentToken;
if (getArguments() != null) { if (getArguments() != null) {
long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1);
new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle); if (bundleId != -1) {
new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
} else {
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());
}
}
} else { } else {
initializeAfterBundle(null); initializeAfterBundle(null);
} }
@ -99,7 +121,9 @@ public class FragmentMastodonAccount extends Fragment {
private void initializeAfterBundle(Bundle bundle) { private void initializeAfterBundle(Bundle bundle) {
if (bundle != null) { if (bundle != null) {
search = bundle.getString(Helper.ARG_SEARCH_KEYWORD, null); search = bundle.getString(Helper.ARG_SEARCH_KEYWORD, null);
accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); if (bundle.containsKey(Helper.ARG_ACCOUNT)) {
accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT);
}
followType = (FedilabProfileTLPageAdapter.follow_type) bundle.getSerializable(Helper.ARG_FOLLOW_TYPE); followType = (FedilabProfileTLPageAdapter.follow_type) bundle.getSerializable(Helper.ARG_FOLLOW_TYPE);
viewModelKey = bundle.getString(Helper.ARG_VIEW_MODEL_KEY, ""); viewModelKey = bundle.getString(Helper.ARG_VIEW_MODEL_KEY, "");
timelineType = (Timeline.TimeLineEnum) bundle.get(Helper.ARG_TIMELINE_TYPE); timelineType = (Timeline.TimeLineEnum) bundle.get(Helper.ARG_TIMELINE_TYPE);
@ -119,14 +143,6 @@ public class FragmentMastodonAccount extends Fragment {
token = currentToken; token = currentToken;
} }
} }
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
binding.loader.setVisibility(View.VISIBLE);
binding.recyclerView.setVisibility(View.GONE);
accountsVM = new ViewModelProvider(FragmentMastodonAccount.this).get(viewModelKey, AccountsVM.class); accountsVM = new ViewModelProvider(FragmentMastodonAccount.this).get(viewModelKey, AccountsVM.class);
max_id = null; max_id = null;
offset = 0; offset = 0;
@ -137,6 +153,14 @@ public class FragmentMastodonAccount extends Fragment {
router(true); router(true);
} }
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
binding.loader.setVisibility(View.VISIBLE);
binding.recyclerView.setVisibility(View.GONE);
}
/** /**
* Router for timelines * Router for timelines
*/ */

@ -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);

@ -17,6 +17,8 @@ package app.fedilab.android.mastodon.ui.fragment.timeline;
import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -37,6 +39,7 @@ import app.fedilab.android.databinding.FragmentProfileTimelinesBinding;
import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Account;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle; import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
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.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.ui.pageadapter.FedilabProfilePageAdapter; import app.fedilab.android.mastodon.ui.pageadapter.FedilabProfilePageAdapter;
@ -51,25 +54,25 @@ public class FragmentProfileTimeline extends Fragment {
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
binding = FragmentProfileTimelinesBinding.inflate(inflater, container, false); binding = FragmentProfileTimelinesBinding.inflate(inflater, container, false);
if (getArguments() != null) { if (getArguments() != null) {
long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); new Thread(() -> {
if (bundleId != -1) { String cached_account_id = getArguments().getString(Helper.ARG_CACHED_ACCOUNT_ID);
new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> { try {
account = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); account = new CachedBundle(requireActivity()).getCachedAccount(currentAccount, cached_account_id);
checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); } catch (DBException e) {
}); e.printStackTrace();
} else { }
account = (Account) getArguments().getSerializable(Helper.ARG_ACCOUNT);
checkRemotely = getArguments().getBoolean(Helper.ARG_CHECK_REMOTELY, false); checkRemotely = getArguments().getBoolean(Helper.ARG_CHECK_REMOTELY, false);
} Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = this::initializeAfterBundle;
mainHandler.post(myRunnable);
}).start();
} }
return binding.getRoot(); return binding.getRoot();
} }
@Override private void initializeAfterBundle() {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.toots))); binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.toots)));
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.replies))); binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.replies)));
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.media))); binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.media)));
@ -167,5 +170,10 @@ public class FragmentProfileTimeline extends Fragment {
} }
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
} }

@ -15,6 +15,7 @@ package app.fedilab.android.mastodon.ui.pageadapter;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -56,29 +57,31 @@ public class FedilabProfilePageAdapter extends FragmentStatePagerAdapter {
public Fragment getItem(int position) { public Fragment getItem(int position) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(Helper.ARG_VIEW_MODEL_KEY, "FEDILAB_" + position); bundle.putString(Helper.ARG_VIEW_MODEL_KEY, "FEDILAB_" + position);
FragmentMastodonTimeline fragmentProfileTimeline; FragmentMastodonTimeline fragmentMastodonTimeline;
Log.v(Helper.TAG, ">>>>>>>>>FedilabProfilePageAdapter: " + account);
Log.v(Helper.TAG, ">>>>>>>>>FedilabProfilePageAdapter ID: " + account.id);
switch (position) { switch (position) {
case 0 -> { case 0 -> {
fragmentProfileTimeline = new FragmentMastodonTimeline(); fragmentMastodonTimeline = new FragmentMastodonTimeline();
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE); bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE);
bundle.putSerializable(Helper.ARG_CACHED_ACCOUNT_ID, account.id); bundle.putSerializable(Helper.ARG_CACHED_ACCOUNT_ID, account.id);
bundle.putBoolean(Helper.ARG_SHOW_PINNED, true); bundle.putBoolean(Helper.ARG_SHOW_PINNED, true);
bundle.putBoolean(Helper.ARG_SHOW_REPLIES, false); bundle.putBoolean(Helper.ARG_SHOW_REPLIES, false);
bundle.putBoolean(Helper.ARG_SHOW_REBLOGS, true); bundle.putBoolean(Helper.ARG_SHOW_REBLOGS, true);
bundle.putBoolean(Helper.ARG_CHECK_REMOTELY, checkRemotely); bundle.putBoolean(Helper.ARG_CHECK_REMOTELY, checkRemotely);
fragmentProfileTimeline.setArguments(bundle); fragmentMastodonTimeline.setArguments(bundle);
return fragmentProfileTimeline; return fragmentMastodonTimeline;
} }
case 1 -> { case 1 -> {
fragmentProfileTimeline = new FragmentMastodonTimeline(); fragmentMastodonTimeline = new FragmentMastodonTimeline();
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE); bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE);
bundle.putSerializable(Helper.ARG_CACHED_ACCOUNT_ID, account.id); bundle.putSerializable(Helper.ARG_CACHED_ACCOUNT_ID, account.id);
bundle.putBoolean(Helper.ARG_SHOW_PINNED, false); bundle.putBoolean(Helper.ARG_SHOW_PINNED, false);
bundle.putBoolean(Helper.ARG_SHOW_REPLIES, true); bundle.putBoolean(Helper.ARG_SHOW_REPLIES, true);
bundle.putBoolean(Helper.ARG_SHOW_REBLOGS, false); bundle.putBoolean(Helper.ARG_SHOW_REBLOGS, false);
bundle.putBoolean(Helper.ARG_CHECK_REMOTELY, checkRemotely); bundle.putBoolean(Helper.ARG_CHECK_REMOTELY, checkRemotely);
fragmentProfileTimeline.setArguments(bundle); fragmentMastodonTimeline.setArguments(bundle);
return fragmentProfileTimeline; return fragmentMastodonTimeline;
} }
case 2 -> { case 2 -> {
FragmentMediaProfile fragmentMediaProfile = new FragmentMediaProfile(); FragmentMediaProfile fragmentMediaProfile = new FragmentMediaProfile();

Loading…
Cancel
Save