Loading app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java +16 −3 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ 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; Loading @@ -34,6 +35,7 @@ import java.util.Date; import java.util.zip.GZIPInputStream; 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.exception.DBException; import app.fedilab.android.mastodon.helper.Helper; Loading Loading @@ -81,19 +83,21 @@ 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)); 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_INSTANCE, currentUser.instance); valuesAccount.put(Sqlite.COL_TYPE, CacheType.ACCOUNT.getValue()); removeIntent(currentUser, account.user_id); removeIntent(currentUser, account.id); db.insertOrThrow(Sqlite.TABLE_INTENT, null, valuesAccount); } } Loading Loading @@ -126,8 +130,12 @@ 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) { Loading Loading @@ -171,10 +179,11 @@ public class CachedBundle { * @param target_id String * @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) { throw new DBException("db is null. Wrong initialization."); } Log.v(Helper.TAG, "getCachedAccount --> " + account + " -> " + target_id); if (account == null || target_id == null) { return null; } Loading @@ -184,10 +193,14 @@ 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); } } catch (Exception e) { e.printStackTrace(); return null; } return null; Loading app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ConversationAdapter.java +1 −1 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import app.fedilab.android.R; import app.fedilab.android.databinding.DrawerConversationBinding; import app.fedilab.android.databinding.ThumbnailBinding; 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.Attachment; import app.fedilab.android.mastodon.client.entities.api.Conversation; Loading @@ -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.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; import app.fedilab.android.mastodon.activities.DirectMessageActivity; public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { Loading app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMediaProfile.java +38 −8 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ 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; Loading @@ -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.Statuses; 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.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; Loading Loading @@ -74,19 +77,41 @@ public class FragmentMediaProfile extends Fragment { if (getArguments() != null) { long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> { if (bundle != null) { accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); 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 { initializeAfterBundle(null); } return binding.getRoot(); } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); private void initializeAfterBundle(Bundle bundle) { 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; accountsVM = new ViewModelProvider(requireActivity()).get(AccountsVM.class); mediaStatuses = new ArrayList<>(); Loading Loading @@ -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())) .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); } } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); } /** Loading app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java +34 −10 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ 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; Loading @@ -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.app.CachedBundle; 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.MastodonHelper; import app.fedilab.android.mastodon.ui.drawer.AccountAdapter; Loading Loading @@ -83,7 +86,26 @@ public class FragmentMastodonAccount extends Fragment { token = currentToken; if (getArguments() != null) { long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); 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 { initializeAfterBundle(null); } Loading @@ -99,7 +121,9 @@ public class FragmentMastodonAccount extends Fragment { private void initializeAfterBundle(Bundle bundle) { if (bundle != null) { search = bundle.getString(Helper.ARG_SEARCH_KEYWORD, null); if (bundle.containsKey(Helper.ARG_ACCOUNT)) { accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); } followType = (FedilabProfileTLPageAdapter.follow_type) bundle.getSerializable(Helper.ARG_FOLLOW_TYPE); viewModelKey = bundle.getString(Helper.ARG_VIEW_MODEL_KEY, ""); timelineType = (Timeline.TimeLineEnum) bundle.get(Helper.ARG_TIMELINE_TYPE); Loading @@ -119,14 +143,6 @@ public class FragmentMastodonAccount extends Fragment { 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); max_id = null; offset = 0; Loading @@ -137,6 +153,14 @@ public class FragmentMastodonAccount extends Fragment { 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 */ Loading app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java +55 −22 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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) { Loading Loading @@ -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 { 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); Loading @@ -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; Loading @@ -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); 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); Loading @@ -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("@"); Loading Loading @@ -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); Loading Loading
app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java +16 −3 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ 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; Loading @@ -34,6 +35,7 @@ import java.util.Date; import java.util.zip.GZIPInputStream; 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.exception.DBException; import app.fedilab.android.mastodon.helper.Helper; Loading Loading @@ -81,19 +83,21 @@ 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)); 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_INSTANCE, currentUser.instance); valuesAccount.put(Sqlite.COL_TYPE, CacheType.ACCOUNT.getValue()); removeIntent(currentUser, account.user_id); removeIntent(currentUser, account.id); db.insertOrThrow(Sqlite.TABLE_INTENT, null, valuesAccount); } } Loading Loading @@ -126,8 +130,12 @@ 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) { Loading Loading @@ -171,10 +179,11 @@ public class CachedBundle { * @param target_id String * @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) { throw new DBException("db is null. Wrong initialization."); } Log.v(Helper.TAG, "getCachedAccount --> " + account + " -> " + target_id); if (account == null || target_id == null) { return null; } Loading @@ -184,10 +193,14 @@ 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); } } catch (Exception e) { e.printStackTrace(); return null; } return null; Loading
app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ConversationAdapter.java +1 −1 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import app.fedilab.android.R; import app.fedilab.android.databinding.DrawerConversationBinding; import app.fedilab.android.databinding.ThumbnailBinding; 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.Attachment; import app.fedilab.android.mastodon.client.entities.api.Conversation; Loading @@ -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.helper.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; import app.fedilab.android.mastodon.activities.DirectMessageActivity; public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { Loading
app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMediaProfile.java +38 −8 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ 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; Loading @@ -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.Statuses; 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.Helper; import app.fedilab.android.mastodon.helper.MastodonHelper; Loading Loading @@ -74,19 +77,41 @@ public class FragmentMediaProfile extends Fragment { if (getArguments() != null) { long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> { if (bundle != null) { accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); 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 { initializeAfterBundle(null); } return binding.getRoot(); } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); private void initializeAfterBundle(Bundle bundle) { 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; accountsVM = new ViewModelProvider(requireActivity()).get(AccountsVM.class); mediaStatuses = new ArrayList<>(); Loading Loading @@ -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())) .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); } } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); } /** Loading
app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java +34 −10 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ 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; Loading @@ -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.app.CachedBundle; 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.MastodonHelper; import app.fedilab.android.mastodon.ui.drawer.AccountAdapter; Loading Loading @@ -83,7 +86,26 @@ public class FragmentMastodonAccount extends Fragment { token = currentToken; if (getArguments() != null) { long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); 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 { initializeAfterBundle(null); } Loading @@ -99,7 +121,9 @@ public class FragmentMastodonAccount extends Fragment { private void initializeAfterBundle(Bundle bundle) { if (bundle != null) { search = bundle.getString(Helper.ARG_SEARCH_KEYWORD, null); if (bundle.containsKey(Helper.ARG_ACCOUNT)) { accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); } followType = (FedilabProfileTLPageAdapter.follow_type) bundle.getSerializable(Helper.ARG_FOLLOW_TYPE); viewModelKey = bundle.getString(Helper.ARG_VIEW_MODEL_KEY, ""); timelineType = (Timeline.TimeLineEnum) bundle.get(Helper.ARG_TIMELINE_TYPE); Loading @@ -119,14 +143,6 @@ public class FragmentMastodonAccount extends Fragment { 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); max_id = null; offset = 0; Loading @@ -137,6 +153,14 @@ public class FragmentMastodonAccount extends Fragment { 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 */ Loading
app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java +55 −22 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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) { Loading Loading @@ -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 { 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); Loading @@ -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; Loading @@ -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); 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); Loading @@ -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("@"); Loading Loading @@ -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); Loading