Working pagers

This commit is contained in:
Thomas 2024-01-11 12:02:22 +01:00
parent 08c1ba943b
commit b052547cc4
6 changed files with 121 additions and 182 deletions

View file

@ -23,7 +23,6 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Parcel;
import android.util.Base64;
import android.util.Log;
import com.google.gson.annotations.SerializedName;
@ -83,12 +82,10 @@ public class CachedBundle {
values.put(Sqlite.COL_BUNDLE, serializeBundle(bundle));
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date()));
values.put(Sqlite.COL_TYPE, CacheType.ARGS.getValue());
Log.v(Helper.TAG, "insertIntent --> " + currentUser);
if (bundle.containsKey(Helper.ARG_ACCOUNT) && currentUser != null) {
ContentValues valuesAccount = new ContentValues();
Bundle bundleAccount = new Bundle();
Account account = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT);
Log.v(Helper.TAG, "account --> " + account);
if (account != null) {
bundleAccount.putSerializable(Helper.ARG_ACCOUNT, account);
valuesAccount.put(Sqlite.COL_BUNDLE, serializeBundle(bundleAccount));
@ -130,12 +127,8 @@ public class CachedBundle {
Bundle bundle = null;
try {
CachedBundle cachedBundle = getCachedBundle(String.valueOf(id));
Log.v(Helper.TAG, "cachedBundle --> " + cachedBundle);
if (cachedBundle != null) {
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)) {
Account cachedAccount = getCachedAccount(Account, bundle.getString(Helper.ARG_CACHED_ACCOUNT_ID));
if (cachedAccount != null) {
@ -183,7 +176,6 @@ public class CachedBundle {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
Log.v(Helper.TAG, "getCachedAccount --> " + account + " -> " + target_id);
if (account == null || target_id == null) {
return null;
}
@ -193,9 +185,6 @@ public class CachedBundle {
+ Sqlite.COL_TYPE + " = '" + CacheType.ACCOUNT.getValue() + "' AND "
+ Sqlite.COL_TARGET_ID + " = '" + target_id + "'", null, null, null, null, "1");
CachedBundle cachedBundle = cursorToCachedBundle(c);
if (cachedBundle != null) {
Log.v(Helper.TAG, "cachedBundle.bundle --> " + cachedBundle.bundle);
}
if (cachedBundle != null && cachedBundle.bundle.containsKey(Helper.ARG_ACCOUNT)) {
return (Account) cachedBundle.bundle.getSerializable(Helper.ARG_ACCOUNT);
}

View file

@ -18,8 +18,6 @@ import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -81,21 +79,14 @@ public class FragmentMediaProfile extends Fragment {
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());
try {
accountTimeline = new CachedBundle(requireActivity()).getCachedAccount(currentAccount, getArguments().getString(Helper.ARG_CACHED_ACCOUNT_ID));
} catch (DBException e) {
e.printStackTrace();
}
}
initializeAfterBundle(getArguments());
}
} else {
initializeAfterBundle(null);

View file

@ -22,8 +22,6 @@ import static app.fedilab.android.mastodon.helper.MastodonHelper.ACCOUNTS_PER_CA
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -90,21 +88,14 @@ public class FragmentMastodonAccount extends Fragment {
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());
try {
accountTimeline = new CachedBundle(requireActivity()).getCachedAccount(currentAccount, getArguments().getString(Helper.ARG_CACHED_ACCOUNT_ID));
} catch (DBException e) {
e.printStackTrace();
}
}
initializeAfterBundle(getArguments());
}
} else {
initializeAfterBundle(null);

View file

@ -27,7 +27,6 @@ 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;
@ -180,7 +179,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
}
}
};
private boolean bundleInitialized;
private boolean retry_for_home_done;
private String lemmy_post_id;
private boolean checkRemotely;
@ -233,10 +231,6 @@ 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) {
@ -370,141 +364,125 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
bundleInitialized = false;
timelineType = Timeline.TimeLineEnum.HOME;
binding = FragmentPaginationBinding.inflate(inflater, container, 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 {
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());
try {
accountTimeline = new CachedBundle(requireActivity()).getCachedAccount(currentAccount, getArguments().getString(Helper.ARG_CACHED_ACCOUNT_ID));
} catch (DBException e) {
e.printStackTrace();
}
}
initializeAfterBundle(getArguments());
}
}
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);
lemmy_post_id = bundle.getString(Helper.ARG_LEMMY_POST_ID, null);
list_id = bundle.getString(Helper.ARG_LIST_ID, null);
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 (bundle != null) {
timelineType = (Timeline.TimeLineEnum) bundle.get(Helper.ARG_TIMELINE_TYPE);
lemmy_post_id = bundle.getString(Helper.ARG_LEMMY_POST_ID, null);
list_id = bundle.getString(Helper.ARG_LIST_ID, null);
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;
} else {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
remoteInstance = sharedpreferences.getString(getString(R.string.SET_NITTER_HOST), getString(R.string.DEFAULT_NITTER_HOST)).toLowerCase();
canBeFederated = false;
}
}
if (timelineType == Timeline.TimeLineEnum.TREND_MESSAGE_PUBLIC) {
if (pinnedTimeline != null && pinnedTimeline.remoteInstance != null) {
if (pinnedTimeline.remoteInstance.type != RemoteInstance.InstanceType.NITTER) {
remoteInstance = pinnedTimeline.remoteInstance.host;
} else {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
remoteInstance = sharedpreferences.getString(getString(R.string.SET_NITTER_HOST), getString(R.string.DEFAULT_NITTER_HOST)).toLowerCase();
canBeFederated = false;
}
publicTrendsDomain = bundle.getString(Helper.ARG_REMOTE_INSTANCE_STRING, null);
isViewInitialized = bundle.getBoolean(Helper.ARG_INITIALIZE_VIEW, true);
isNotPinnedTimeline = isViewInitialized;
tagTimeline = (TagTimeline) bundle.getSerializable(Helper.ARG_TAG_TIMELINE);
bubbleTimeline = (BubbleTimeline) bundle.getSerializable(Helper.ARG_BUBBLE_TIMELINE);
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);
exclude_reblogs = !bundle.getBoolean(Helper.ARG_SHOW_REBLOGS, true);
media_only = bundle.getBoolean(Helper.ARG_SHOW_MEDIA_ONY, false);
viewModelKey = bundle.getString(Helper.ARG_VIEW_MODEL_KEY, "");
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;
if (timelineType == Timeline.TimeLineEnum.TREND_MESSAGE_PUBLIC) {
canBeFederated = false;
}
publicTrendsDomain = bundle.getString(Helper.ARG_REMOTE_INSTANCE_STRING, null);
isViewInitialized = bundle.getBoolean(Helper.ARG_INITIALIZE_VIEW, true);
isNotPinnedTimeline = isViewInitialized;
tagTimeline = (TagTimeline) bundle.getSerializable(Helper.ARG_TAG_TIMELINE);
bubbleTimeline = (BubbleTimeline) bundle.getSerializable(Helper.ARG_BUBBLE_TIMELINE);
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);
exclude_reblogs = !bundle.getBoolean(Helper.ARG_SHOW_REBLOGS, true);
media_only = bundle.getBoolean(Helper.ARG_SHOW_MEDIA_ONY, false);
viewModelKey = bundle.getString(Helper.ARG_VIEW_MODEL_KEY, "");
minified = bundle.getBoolean(Helper.ARG_MINIFIED, false);
statusReport = (Status) bundle.getSerializable(Helper.ARG_STATUS_REPORT);
initialStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS);
}
//When visiting a profile without being authenticated
if (checkRemotely) {
String[] acctArray = accountTimeline.acct.split("@");
if (acctArray.length > 1) {
remoteInstance = acctArray[1];
}
if (remoteInstance != null && remoteInstance.equalsIgnoreCase(currentInstance)) {
checkRemotely = false;
} else if (remoteInstance == null) {
checkRemotely = false;
}
}
if (tagTimeline != null) {
ident = "@T@" + tagTimeline.name;
if (tagTimeline.isART) {
timelineType = Timeline.TimeLineEnum.ART;
}
} else if (bubbleTimeline != null) {
ident = "@B@Bubble";
} else if (list_id != null) {
ident = "@l@" + list_id;
} else if (remoteInstance != null && !checkRemotely) {
if (pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) {
ident = "@R@" + pinnedTimeline.remoteInstance.host;
} else {
ident = "@R@" + remoteInstance;
}
} else if (search != null) {
ident = "@S@" + search;
} else {
ident = null;
}
if (timelineType != null) {
slug = timelineType != Timeline.TimeLineEnum.ART ? timelineType.getValue() + (ident != null ? "|" + ident : "") : Timeline.TimeLineEnum.TAG.getValue() + (ident != null ? "|" + ident : "");
}
timelinesVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, TimelinesVM.class);
accountsVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, AccountsVM.class);
initialStatuses = null;
lockForResumeCall = 0;
ContextCompat.registerReceiver(requireActivity(), receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
};
mainHandler.post(myRunnable);
}).start();
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("@");
if (acctArray.length > 1) {
remoteInstance = acctArray[1];
}
if (remoteInstance != null && remoteInstance.equalsIgnoreCase(currentInstance)) {
checkRemotely = false;
} else if (remoteInstance == null) {
checkRemotely = false;
}
}
if (tagTimeline != null) {
ident = "@T@" + tagTimeline.name;
if (tagTimeline.isART) {
timelineType = Timeline.TimeLineEnum.ART;
}
} else if (bubbleTimeline != null) {
ident = "@B@Bubble";
} else if (list_id != null) {
ident = "@l@" + list_id;
} else if (remoteInstance != null && !checkRemotely) {
if (pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) {
ident = "@R@" + pinnedTimeline.remoteInstance.host;
} else {
ident = "@R@" + remoteInstance;
}
} else if (search != null) {
ident = "@S@" + search;
} else {
ident = null;
}
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);
}
/**

View file

@ -17,8 +17,6 @@ package app.fedilab.android.mastodon.ui.fragment.timeline;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@ -54,20 +52,15 @@ public class FragmentProfileTimeline extends Fragment {
ViewGroup container, Bundle savedInstanceState) {
binding = FragmentProfileTimelinesBinding.inflate(inflater, container, false);
if (getArguments() != null) {
new Thread(() -> {
String cached_account_id = getArguments().getString(Helper.ARG_CACHED_ACCOUNT_ID);
try {
account = new CachedBundle(requireActivity()).getCachedAccount(currentAccount, cached_account_id);
} catch (DBException e) {
e.printStackTrace();
}
checkRemotely = getArguments().getBoolean(Helper.ARG_CHECK_REMOTELY, false);
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = this::initializeAfterBundle;
mainHandler.post(myRunnable);
}).start();
String cached_account_id = getArguments().getString(Helper.ARG_CACHED_ACCOUNT_ID);
try {
account = new CachedBundle(requireActivity()).getCachedAccount(currentAccount, cached_account_id);
} catch (DBException e) {
e.printStackTrace();
}
checkRemotely = getArguments().getBoolean(Helper.ARG_CHECK_REMOTELY, false);
initializeAfterBundle();
}
return binding.getRoot();
}

View file

@ -15,7 +15,6 @@ package app.fedilab.android.mastodon.ui.pageadapter;
* see <http://www.gnu.org/licenses>. */
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
@ -58,8 +57,6 @@ public class FedilabProfilePageAdapter extends FragmentStatePagerAdapter {
Bundle bundle = new Bundle();
bundle.putString(Helper.ARG_VIEW_MODEL_KEY, "FEDILAB_" + position);
FragmentMastodonTimeline fragmentMastodonTimeline;
Log.v(Helper.TAG, ">>>>>>>>>FedilabProfilePageAdapter: " + account);
Log.v(Helper.TAG, ">>>>>>>>>FedilabProfilePageAdapter ID: " + account.id);
switch (position) {
case 0 -> {
fragmentMastodonTimeline = new FragmentMastodonTimeline();