2017-01-20 09:09:10 +01:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
2017-04-10 02:12:31 +02:00
|
|
|
* This file is a part of Tusky.
|
2017-01-20 09:09:10 +01:00
|
|
|
*
|
2017-04-10 02:12:31 +02:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-01-20 09:09:10 +01:00
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-04-10 02:12:31 +02:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
2017-01-20 09:09:10 +01:00
|
|
|
*
|
2017-04-10 02:12:31 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2017-01-20 09:09:10 +01:00
|
|
|
|
2017-05-05 00:55:34 +02:00
|
|
|
package com.keylesspalace.tusky.fragment;
|
2017-01-07 23:24:02 +01:00
|
|
|
|
|
|
|
import android.content.Context;
|
2019-03-04 19:24:27 +01:00
|
|
|
import android.content.Intent;
|
2017-04-07 09:40:59 +02:00
|
|
|
import android.content.SharedPreferences;
|
2020-06-07 19:37:34 +02:00
|
|
|
import android.net.Uri;
|
2017-01-07 23:24:02 +01:00
|
|
|
import android.os.Bundle;
|
2017-05-23 21:34:31 +02:00
|
|
|
import android.util.Log;
|
2017-01-07 23:24:02 +01:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2018-05-27 10:22:12 +02:00
|
|
|
import android.widget.ProgressBar;
|
2017-01-07 23:24:02 +01:00
|
|
|
|
2019-10-22 21:18:20 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.arch.core.util.Function;
|
|
|
|
import androidx.core.util.Pair;
|
|
|
|
import androidx.core.widget.ContentLoadingProgressBar;
|
|
|
|
import androidx.lifecycle.Lifecycle;
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
import androidx.recyclerview.widget.AsyncDifferConfig;
|
|
|
|
import androidx.recyclerview.widget.AsyncListDiffer;
|
|
|
|
import androidx.recyclerview.widget.DiffUtil;
|
|
|
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.ListUpdateCallback;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import androidx.recyclerview.widget.SimpleItemAnimator;
|
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
2019-03-04 19:24:27 +01:00
|
|
|
import com.keylesspalace.tusky.AccountListActivity;
|
|
|
|
import com.keylesspalace.tusky.BaseActivity;
|
2017-05-05 00:55:34 +02:00
|
|
|
import com.keylesspalace.tusky.R;
|
2019-03-16 14:38:29 +01:00
|
|
|
import com.keylesspalace.tusky.adapter.StatusBaseViewHolder;
|
2017-05-05 00:55:34 +02:00
|
|
|
import com.keylesspalace.tusky.adapter.TimelineAdapter;
|
2018-05-27 10:22:12 +02:00
|
|
|
import com.keylesspalace.tusky.appstore.BlockEvent;
|
2019-11-19 10:15:32 +01:00
|
|
|
import com.keylesspalace.tusky.appstore.BookmarkEvent;
|
2019-06-11 15:56:27 +02:00
|
|
|
import com.keylesspalace.tusky.appstore.DomainMuteEvent;
|
2018-05-27 10:22:12 +02:00
|
|
|
import com.keylesspalace.tusky.appstore.EventHub;
|
|
|
|
import com.keylesspalace.tusky.appstore.FavoriteEvent;
|
2020-03-24 21:06:04 +01:00
|
|
|
import com.keylesspalace.tusky.appstore.MuteConversationEvent;
|
2018-05-27 10:22:12 +02:00
|
|
|
import com.keylesspalace.tusky.appstore.MuteEvent;
|
2018-11-12 21:09:39 +01:00
|
|
|
import com.keylesspalace.tusky.appstore.PreferenceChangedEvent;
|
2018-05-27 10:22:12 +02:00
|
|
|
import com.keylesspalace.tusky.appstore.ReblogEvent;
|
|
|
|
import com.keylesspalace.tusky.appstore.StatusComposedEvent;
|
|
|
|
import com.keylesspalace.tusky.appstore.StatusDeletedEvent;
|
|
|
|
import com.keylesspalace.tusky.appstore.UnfollowEvent;
|
2018-11-12 21:09:39 +01:00
|
|
|
import com.keylesspalace.tusky.db.AccountManager;
|
2018-03-27 19:47:00 +02:00
|
|
|
import com.keylesspalace.tusky.di.Injectable;
|
2019-03-20 19:25:26 +01:00
|
|
|
import com.keylesspalace.tusky.entity.Filter;
|
2019-04-22 10:11:00 +02:00
|
|
|
import com.keylesspalace.tusky.entity.Poll;
|
2017-03-09 00:27:37 +01:00
|
|
|
import com.keylesspalace.tusky.entity.Status;
|
2017-08-04 11:44:10 +02:00
|
|
|
import com.keylesspalace.tusky.interfaces.ActionButtonActivity;
|
2019-05-15 12:43:16 +02:00
|
|
|
import com.keylesspalace.tusky.interfaces.RefreshableFragment;
|
2019-04-08 15:40:16 +02:00
|
|
|
import com.keylesspalace.tusky.interfaces.ReselectableFragment;
|
2017-05-05 00:55:34 +02:00
|
|
|
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
2017-06-30 08:31:58 +02:00
|
|
|
import com.keylesspalace.tusky.network.MastodonApi;
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
import com.keylesspalace.tusky.repository.Placeholder;
|
|
|
|
import com.keylesspalace.tusky.repository.TimelineRepository;
|
|
|
|
import com.keylesspalace.tusky.repository.TimelineRequestMode;
|
2020-12-23 19:13:37 +01:00
|
|
|
import com.keylesspalace.tusky.settings.PrefKeys;
|
2020-03-02 19:34:31 +01:00
|
|
|
import com.keylesspalace.tusky.util.CardViewMode;
|
2017-11-06 16:19:15 +01:00
|
|
|
import com.keylesspalace.tusky.util.Either;
|
2020-06-07 19:37:34 +02:00
|
|
|
import com.keylesspalace.tusky.util.HttpHeaderLink;
|
2019-06-11 15:56:27 +02:00
|
|
|
import com.keylesspalace.tusky.util.LinkHelper;
|
2019-03-04 19:24:27 +01:00
|
|
|
import com.keylesspalace.tusky.util.ListStatusAccessibilityDelegate;
|
2017-07-14 03:39:17 +02:00
|
|
|
import com.keylesspalace.tusky.util.ListUtils;
|
2017-07-12 21:54:52 +02:00
|
|
|
import com.keylesspalace.tusky.util.PairedList;
|
2019-12-30 21:37:20 +01:00
|
|
|
import com.keylesspalace.tusky.util.StatusDisplayOptions;
|
2019-01-31 19:03:34 +01:00
|
|
|
import com.keylesspalace.tusky.util.StringUtils;
|
2017-07-12 21:54:52 +02:00
|
|
|
import com.keylesspalace.tusky.util.ViewDataUtils;
|
2019-01-28 19:02:31 +01:00
|
|
|
import com.keylesspalace.tusky.view.BackgroundMessageView;
|
2017-05-29 12:14:09 +02:00
|
|
|
import com.keylesspalace.tusky.view.EndlessOnScrollListener;
|
2017-07-12 21:54:52 +02:00
|
|
|
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
2017-01-07 23:24:02 +01:00
|
|
|
|
2019-01-28 19:02:31 +01:00
|
|
|
import java.io.IOException;
|
2020-05-15 22:10:29 +02:00
|
|
|
import java.util.ArrayList;
|
2019-03-20 19:25:26 +01:00
|
|
|
import java.util.Collections;
|
2017-04-15 20:23:07 +02:00
|
|
|
import java.util.Iterator;
|
2017-01-07 23:24:02 +01:00
|
|
|
import java.util.List;
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
import java.util.ListIterator;
|
2019-03-16 14:38:29 +01:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2017-01-07 23:24:02 +01:00
|
|
|
|
2018-03-27 19:47:00 +02:00
|
|
|
import javax.inject.Inject;
|
|
|
|
|
2018-06-24 10:53:19 +02:00
|
|
|
import at.connyduck.sparkbutton.helpers.Utils;
|
2019-04-08 15:40:16 +02:00
|
|
|
import io.reactivex.Observable;
|
2018-05-27 10:22:12 +02:00
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
2019-01-28 19:02:31 +01:00
|
|
|
import kotlin.Unit;
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
import kotlin.collections.CollectionsKt;
|
2019-04-21 08:24:06 +02:00
|
|
|
import kotlin.jvm.functions.Function1;
|
2017-03-09 00:27:37 +01:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
2017-05-10 04:36:05 +02:00
|
|
|
import retrofit2.Response;
|
2017-03-09 00:27:37 +01:00
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
import static com.uber.autodispose.AutoDispose.autoDisposable;
|
|
|
|
import static com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider.from;
|
|
|
|
|
2017-01-23 06:19:30 +01:00
|
|
|
public class TimelineFragment extends SFragment implements
|
2017-04-25 13:30:57 +02:00
|
|
|
SwipeRefreshLayout.OnRefreshListener,
|
|
|
|
StatusActionListener,
|
2019-05-15 12:43:16 +02:00
|
|
|
Injectable, ReselectableFragment, RefreshableFragment {
|
2017-11-03 22:17:31 +01:00
|
|
|
private static final String TAG = "TimelineF"; // logging tag
|
2017-07-12 21:54:52 +02:00
|
|
|
private static final String KIND_ARG = "kind";
|
2020-05-15 22:10:29 +02:00
|
|
|
private static final String ID_ARG = "id";
|
|
|
|
private static final String HASHTAGS_ARG = "hastags";
|
2019-05-15 12:43:16 +02:00
|
|
|
private static final String ARG_ENABLE_SWIPE_TO_REFRESH = "arg.enable.swipe.to.refresh";
|
2017-01-07 23:24:02 +01:00
|
|
|
|
2017-11-03 22:17:31 +01:00
|
|
|
private static final int LOAD_AT_ONCE = 30;
|
2019-05-15 12:43:16 +02:00
|
|
|
private boolean isSwipeToRefreshEnabled = true;
|
|
|
|
private boolean isNeedRefresh;
|
2017-11-03 22:17:31 +01:00
|
|
|
|
2017-05-05 00:55:34 +02:00
|
|
|
public enum Kind {
|
2017-01-07 23:24:02 +01:00
|
|
|
HOME,
|
2017-03-31 04:31:17 +02:00
|
|
|
PUBLIC_LOCAL,
|
|
|
|
PUBLIC_FEDERATED,
|
2017-01-27 01:34:32 +01:00
|
|
|
TAG,
|
2017-01-28 04:33:43 +01:00
|
|
|
USER,
|
2019-01-21 08:37:25 +01:00
|
|
|
USER_PINNED,
|
2018-06-18 13:26:18 +02:00
|
|
|
USER_WITH_REPLIES,
|
2018-01-06 19:01:37 +01:00
|
|
|
FAVOURITES,
|
2019-11-19 10:15:32 +01:00
|
|
|
LIST,
|
|
|
|
BOOKMARKS
|
2017-01-07 23:24:02 +01:00
|
|
|
}
|
|
|
|
|
2017-06-30 08:31:58 +02:00
|
|
|
private enum FetchEnd {
|
|
|
|
TOP,
|
|
|
|
BOTTOM,
|
2017-11-03 22:17:31 +01:00
|
|
|
MIDDLE
|
2017-06-30 08:31:58 +02:00
|
|
|
}
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
@Inject
|
|
|
|
public EventHub eventHub;
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
@Inject
|
2019-03-30 15:18:16 +01:00
|
|
|
TimelineRepository timelineRepo;
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
|
2018-11-12 21:09:39 +01:00
|
|
|
@Inject
|
|
|
|
public AccountManager accountManager;
|
|
|
|
|
2018-10-15 19:47:50 +02:00
|
|
|
private boolean eventRegistered = false;
|
2018-03-27 19:47:00 +02:00
|
|
|
|
2017-01-07 23:24:02 +01:00
|
|
|
private SwipeRefreshLayout swipeRefreshLayout;
|
2018-05-27 10:22:12 +02:00
|
|
|
private RecyclerView recyclerView;
|
|
|
|
private ProgressBar progressBar;
|
2019-05-15 12:43:16 +02:00
|
|
|
private ContentLoadingProgressBar topProgressBar;
|
2019-01-28 19:02:31 +01:00
|
|
|
private BackgroundMessageView statusView;
|
2018-05-27 10:22:12 +02:00
|
|
|
|
2017-01-07 23:24:02 +01:00
|
|
|
private TimelineAdapter adapter;
|
|
|
|
private Kind kind;
|
2020-05-15 22:10:29 +02:00
|
|
|
private String id;
|
|
|
|
private List<String> tags;
|
2020-06-07 19:37:34 +02:00
|
|
|
/**
|
|
|
|
* For some timeline kinds we must use LINK headers and not just status ids.
|
|
|
|
*/
|
|
|
|
private String nextId;
|
2017-01-18 19:35:07 +01:00
|
|
|
private LinearLayoutManager layoutManager;
|
|
|
|
private EndlessOnScrollListener scrollListener;
|
2017-04-15 20:23:07 +02:00
|
|
|
private boolean filterRemoveReplies;
|
|
|
|
private boolean filterRemoveReblogs;
|
2017-04-22 10:41:49 +02:00
|
|
|
private boolean hideFab;
|
2017-06-30 08:31:58 +02:00
|
|
|
private boolean bottomLoading;
|
2018-05-27 10:22:12 +02:00
|
|
|
|
|
|
|
private boolean didLoadEverythingBottom;
|
2017-11-30 20:12:09 +01:00
|
|
|
private boolean alwaysShowSensitiveMedia;
|
2019-07-28 19:59:52 +02:00
|
|
|
private boolean alwaysOpenSpoiler;
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
private boolean initialUpdateFailed = false;
|
2017-11-30 20:12:09 +01:00
|
|
|
|
2017-11-06 16:19:15 +01:00
|
|
|
private PairedList<Either<Placeholder, Status>, StatusViewData> statuses =
|
|
|
|
new PairedList<>(new Function<Either<Placeholder, Status>, StatusViewData>() {
|
|
|
|
@Override
|
|
|
|
public StatusViewData apply(Either<Placeholder, Status> input) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Status status = input.asRightOrNull();
|
2017-11-06 16:19:15 +01:00
|
|
|
if (status != null) {
|
Add support for collapsible statuses when they exceed 500 characters (#825)
* Update Gradle plugin to work with Android Studio 3.3 Canary
Android Studio 3.1.4 Stable doesn't render layout previews in this project
for whatever reason. Switching to the latest 3.3 Canary release fixes the
issue without affecting Gradle scripts but requires the new Android Gradle
plugin to match the new Android Studio release.
This commit will be reverted once development on the feature is done.
* Update gradle build script to allow installing debug builds alongside store version
This will allow developers, testers, etc to work on Tusky will not having to worry
about overwriting, uninstalling, fiddling with a preinstalled application which would
mean having to login again every time the development cycle starts/finishes and
manually reinstalling the app.
* Add UI changes to support collapsing statuses
The button uses subtle styling to not be distracting like the CW button on the timeline
The button is toggleable, full width to match the status textbox hitbox width and also
is shorter to not be too intrusive between the status text and images, or the post below
* Update status data model to store whether the message has been collapsed
* Update status action listener to notify of collapsed state changing
Provide stubs in all implementing classes and mark as TODO the stubs that
require a proper implementation for the feature to work.
* Add implementation code to handle status collapse/expand in timeline
Code has not been added elsewhere to simplify testing.
Once the code will be considered stable it will be also included in other
status action listener implementers.
* Add preferences so that users can toggle the collapsing of long posts
This is currently limited to a simple toggle, it would be nice to implement
a more advanced UI to offer the user more control over the feature.
* Update Gradle plugin to work with latest Android Studio 3.3 Canary 8
Just like the other commit, this will be reverted once the feature is working.
I simply don't want to deal with what changes in my installation of Android
Studio 3.1.4 Stable which breaks the layout preview rendering.
* Update data models and utils for statuses to better handle collapsing
I forgot that data isn't available from the API and can't really be built
from scratch using existing data due to preferences.
A new, extra boolean should fix the issue.
* Fix search breaking due to newly introduced variables in utils classes
* Fix timeline breaking due to newly introduced variables in utils classes
* Fix item status text for collapsed toggle being shown in the wrong state
* Update timeline fragment to refresh the list when collapsed settings change
* Add support for status content collapse in timeline viewholder
* Fix view holder truncating posts using temporary debug settings at 50 chars
* Add toggle support to notification layout as well
* Add support for collapsed statuses to search results
* Add support for expandable content to notifications too
* Update codebase with some suggested changes by @charlang
* Update more code with more suggestions and move null-safety into view data
* Update even more code with even more suggested code changes
* Revert a0a41ca and 0ee004d (Android Studio 3.1 to Android Studio 3.3 updates)
* Add an input filter utility class to reuse code for trimming statuses
* Update UI of statuses to show a taller collapsible button
* Update notification fragment logging to simplify null checks
* Add smartness to SmartLengthInputFilter such as word trimming and runway
* Fix posts with show more button even if bad ratio didn't collapse
* Fix thread view showing button but not collapsing by implementing the feature
* Fix spannable losing spans when collapsed and restore length to 500 characters
* Remove debug build suffix as per request
* Fix all the merging happened in f66d689, 623cad2 and 7056ba5
* Fix notification button spanning full width rather than content width
* Add a way to access a singleton to smart filter and use clearer code
* Update view holders using smart input filters to use more singletons
* Fix code style lacking spaces before boolean checks in ifs and others
* Remove all code related to collapsibility preferences, strings included
* Update style to match content warning toggle button
* Update strings to give cleaner differentiation between CW and collapse
* Update smart filter code to use fully qualified names to avoid confusion
2018-09-19 19:51:20 +02:00
|
|
|
return ViewDataUtils.statusToViewData(
|
|
|
|
status,
|
2019-07-28 19:59:52 +02:00
|
|
|
alwaysShowSensitiveMedia,
|
|
|
|
alwaysOpenSpoiler
|
Add support for collapsible statuses when they exceed 500 characters (#825)
* Update Gradle plugin to work with Android Studio 3.3 Canary
Android Studio 3.1.4 Stable doesn't render layout previews in this project
for whatever reason. Switching to the latest 3.3 Canary release fixes the
issue without affecting Gradle scripts but requires the new Android Gradle
plugin to match the new Android Studio release.
This commit will be reverted once development on the feature is done.
* Update gradle build script to allow installing debug builds alongside store version
This will allow developers, testers, etc to work on Tusky will not having to worry
about overwriting, uninstalling, fiddling with a preinstalled application which would
mean having to login again every time the development cycle starts/finishes and
manually reinstalling the app.
* Add UI changes to support collapsing statuses
The button uses subtle styling to not be distracting like the CW button on the timeline
The button is toggleable, full width to match the status textbox hitbox width and also
is shorter to not be too intrusive between the status text and images, or the post below
* Update status data model to store whether the message has been collapsed
* Update status action listener to notify of collapsed state changing
Provide stubs in all implementing classes and mark as TODO the stubs that
require a proper implementation for the feature to work.
* Add implementation code to handle status collapse/expand in timeline
Code has not been added elsewhere to simplify testing.
Once the code will be considered stable it will be also included in other
status action listener implementers.
* Add preferences so that users can toggle the collapsing of long posts
This is currently limited to a simple toggle, it would be nice to implement
a more advanced UI to offer the user more control over the feature.
* Update Gradle plugin to work with latest Android Studio 3.3 Canary 8
Just like the other commit, this will be reverted once the feature is working.
I simply don't want to deal with what changes in my installation of Android
Studio 3.1.4 Stable which breaks the layout preview rendering.
* Update data models and utils for statuses to better handle collapsing
I forgot that data isn't available from the API and can't really be built
from scratch using existing data due to preferences.
A new, extra boolean should fix the issue.
* Fix search breaking due to newly introduced variables in utils classes
* Fix timeline breaking due to newly introduced variables in utils classes
* Fix item status text for collapsed toggle being shown in the wrong state
* Update timeline fragment to refresh the list when collapsed settings change
* Add support for status content collapse in timeline viewholder
* Fix view holder truncating posts using temporary debug settings at 50 chars
* Add toggle support to notification layout as well
* Add support for collapsed statuses to search results
* Add support for expandable content to notifications too
* Update codebase with some suggested changes by @charlang
* Update more code with more suggestions and move null-safety into view data
* Update even more code with even more suggested code changes
* Revert a0a41ca and 0ee004d (Android Studio 3.1 to Android Studio 3.3 updates)
* Add an input filter utility class to reuse code for trimming statuses
* Update UI of statuses to show a taller collapsible button
* Update notification fragment logging to simplify null checks
* Add smartness to SmartLengthInputFilter such as word trimming and runway
* Fix posts with show more button even if bad ratio didn't collapse
* Fix thread view showing button but not collapsing by implementing the feature
* Fix spannable losing spans when collapsed and restore length to 500 characters
* Remove debug build suffix as per request
* Fix all the merging happened in f66d689, 623cad2 and 7056ba5
* Fix notification button spanning full width rather than content width
* Add a way to access a singleton to smart filter and use clearer code
* Update view holders using smart input filters to use more singletons
* Fix code style lacking spaces before boolean checks in ifs and others
* Remove all code related to collapsibility preferences, strings included
* Update style to match content warning toggle button
* Update strings to give cleaner differentiation between CW and collapse
* Update smart filter code to use fully qualified names to avoid confusion
2018-09-19 19:51:20 +02:00
|
|
|
);
|
2017-11-06 16:19:15 +01:00
|
|
|
} else {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Placeholder placeholder = input.asLeft();
|
|
|
|
return new StatusViewData.Placeholder(placeholder.getId(), false);
|
2017-11-06 16:19:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-01-07 23:24:02 +01:00
|
|
|
|
|
|
|
public static TimelineFragment newInstance(Kind kind) {
|
2019-05-15 12:43:16 +02:00
|
|
|
return newInstance(kind, null);
|
2017-01-07 23:24:02 +01:00
|
|
|
}
|
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
public static TimelineFragment newInstance(Kind kind, @Nullable String hashtagOrId) {
|
|
|
|
return newInstance(kind, hashtagOrId, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static TimelineFragment newInstance(Kind kind, @Nullable String hashtagOrId, boolean enableSwipeToRefresh) {
|
2017-01-27 01:34:32 +01:00
|
|
|
TimelineFragment fragment = new TimelineFragment();
|
2020-05-15 22:10:29 +02:00
|
|
|
Bundle arguments = new Bundle(3);
|
2017-07-12 21:54:52 +02:00
|
|
|
arguments.putString(KIND_ARG, kind.name());
|
2020-05-15 22:10:29 +02:00
|
|
|
arguments.putString(ID_ARG, hashtagOrId);
|
2019-05-15 12:43:16 +02:00
|
|
|
arguments.putBoolean(ARG_ENABLE_SWIPE_TO_REFRESH, enableSwipeToRefresh);
|
2017-01-27 01:34:32 +01:00
|
|
|
fragment.setArguments(arguments);
|
|
|
|
return fragment;
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:10:29 +02:00
|
|
|
public static TimelineFragment newHashtagInstance(@NonNull List<String> hashtags) {
|
|
|
|
TimelineFragment fragment = new TimelineFragment();
|
|
|
|
Bundle arguments = new Bundle(3);
|
|
|
|
arguments.putString(KIND_ARG, Kind.TAG.name());
|
|
|
|
arguments.putStringArrayList(HASHTAGS_ARG, new ArrayList<>(hashtags));
|
|
|
|
arguments.putBoolean(ARG_ENABLE_SWIPE_TO_REFRESH, true);
|
|
|
|
fragment.setArguments(arguments);
|
|
|
|
return fragment;
|
|
|
|
}
|
|
|
|
|
2017-01-07 23:24:02 +01:00
|
|
|
@Override
|
2018-07-02 22:12:27 +02:00
|
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2020-04-06 11:46:38 +02:00
|
|
|
Bundle arguments = requireArguments();
|
2017-07-12 21:54:52 +02:00
|
|
|
kind = Kind.valueOf(arguments.getString(KIND_ARG));
|
2020-05-15 22:10:29 +02:00
|
|
|
if (kind == Kind.USER
|
2019-01-21 08:37:25 +01:00
|
|
|
|| kind == Kind.USER_PINNED
|
2018-07-02 22:12:27 +02:00
|
|
|
|| kind == Kind.USER_WITH_REPLIES
|
|
|
|
|| kind == Kind.LIST) {
|
2020-05-15 22:10:29 +02:00
|
|
|
id = arguments.getString(ID_ARG);
|
|
|
|
}
|
2020-06-07 19:37:34 +02:00
|
|
|
if (kind == Kind.TAG) {
|
2020-05-15 22:10:29 +02:00
|
|
|
tags = arguments.getStringArrayList(HASHTAGS_ARG);
|
2017-01-27 01:34:32 +01:00
|
|
|
}
|
2018-07-08 10:16:19 +02:00
|
|
|
|
2019-12-30 21:37:20 +01:00
|
|
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
|
|
|
StatusDisplayOptions statusDisplayOptions = new StatusDisplayOptions(
|
|
|
|
preferences.getBoolean("animateGifAvatars", false),
|
|
|
|
accountManager.getActiveAccount().getMediaPreviewEnabled(),
|
|
|
|
preferences.getBoolean("absoluteTimeView", false),
|
|
|
|
preferences.getBoolean("showBotOverlay", true),
|
2020-03-02 19:34:31 +01:00
|
|
|
preferences.getBoolean("useBlurhash", true),
|
|
|
|
preferences.getBoolean("showCardsInTimelines", false) ?
|
|
|
|
CardViewMode.INDENTED :
|
2020-03-03 21:27:26 +01:00
|
|
|
CardViewMode.NONE,
|
2020-12-23 19:13:37 +01:00
|
|
|
preferences.getBoolean("confirmReblogs", true),
|
|
|
|
preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false)
|
2019-12-30 21:37:20 +01:00
|
|
|
);
|
|
|
|
adapter = new TimelineAdapter(dataSource, statusDisplayOptions, this);
|
2018-07-08 10:16:19 +02:00
|
|
|
|
2019-05-15 12:43:16 +02:00
|
|
|
isSwipeToRefreshEnabled = arguments.getBoolean(ARG_ENABLE_SWIPE_TO_REFRESH, true);
|
|
|
|
|
2018-07-02 22:12:27 +02:00
|
|
|
}
|
2017-01-07 23:24:02 +01:00
|
|
|
|
2018-07-02 22:12:27 +02:00
|
|
|
@Override
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
|
|
|
Bundle savedInstanceState) {
|
2017-04-07 09:40:59 +02:00
|
|
|
final View rootView = inflater.inflate(R.layout.fragment_timeline, container, false);
|
2017-01-07 23:24:02 +01:00
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
recyclerView = rootView.findViewById(R.id.recyclerView);
|
|
|
|
swipeRefreshLayout = rootView.findViewById(R.id.swipeRefreshLayout);
|
|
|
|
progressBar = rootView.findViewById(R.id.progressBar);
|
2019-01-28 19:02:31 +01:00
|
|
|
statusView = rootView.findViewById(R.id.statusView);
|
2019-05-15 12:43:16 +02:00
|
|
|
topProgressBar = rootView.findViewById(R.id.topProgressBar);
|
2018-05-27 10:22:12 +02:00
|
|
|
|
|
|
|
setupSwipeRefreshLayout();
|
|
|
|
setupRecyclerView();
|
|
|
|
updateAdapter();
|
|
|
|
setupTimelinePreferences();
|
|
|
|
|
|
|
|
if (statuses.isEmpty()) {
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
bottomLoading = true;
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
this.sendInitialRequest();
|
2018-05-27 10:22:12 +02:00
|
|
|
} else {
|
|
|
|
progressBar.setVisibility(View.GONE);
|
2019-05-15 12:43:16 +02:00
|
|
|
if (isNeedRefresh)
|
|
|
|
onRefresh();
|
2018-05-27 10:22:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return rootView;
|
|
|
|
}
|
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
private void sendInitialRequest() {
|
|
|
|
if (this.kind == Kind.HOME) {
|
|
|
|
this.tryCache();
|
|
|
|
} else {
|
2019-02-05 20:06:00 +01:00
|
|
|
sendFetchTimelineRequest(null, null, null, FetchEnd.BOTTOM, -1);
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void tryCache() {
|
|
|
|
// Request timeline from disk to make it quick, then replace it with timeline from
|
|
|
|
// the server to update it
|
2019-02-05 20:06:00 +01:00
|
|
|
this.timelineRepo.getStatuses(null, null, null, LOAD_AT_ONCE,
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
TimelineRequestMode.DISK)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
|
|
|
.subscribe(statuses -> {
|
|
|
|
filterStatuses(statuses);
|
|
|
|
|
|
|
|
if (statuses.size() > 1) {
|
|
|
|
this.clearPlaceholdersForResponse(statuses);
|
|
|
|
this.statuses.clear();
|
|
|
|
this.statuses.addAll(statuses);
|
|
|
|
this.updateAdapter();
|
|
|
|
this.progressBar.setVisibility(View.GONE);
|
|
|
|
// Request statuses including current top to refresh all of them
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateCurrent();
|
2019-06-24 21:43:14 +02:00
|
|
|
this.loadAbove();
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateCurrent() {
|
|
|
|
if (this.statuses.isEmpty()) {
|
2019-09-23 17:09:13 +02:00
|
|
|
return;
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
}
|
2019-09-23 17:09:13 +02:00
|
|
|
|
|
|
|
String topId = CollectionsKt.first(this.statuses, Either::isRight).asRight().getId();
|
|
|
|
|
2019-02-05 20:06:00 +01:00
|
|
|
this.timelineRepo.getStatuses(topId, null, null, LOAD_AT_ONCE,
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
TimelineRequestMode.NETWORK)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
|
|
|
.subscribe(
|
|
|
|
(statuses) -> {
|
|
|
|
this.initialUpdateFailed = false;
|
|
|
|
// When cached timeline is too old, we would replace it with nothing
|
|
|
|
if (!statuses.isEmpty()) {
|
|
|
|
filterStatuses(statuses);
|
|
|
|
|
2019-09-23 17:09:13 +02:00
|
|
|
if (!this.statuses.isEmpty()) {
|
2019-06-24 21:43:14 +02:00
|
|
|
// clear old cached statuses
|
2019-07-10 06:52:13 +02:00
|
|
|
Iterator<Either<Placeholder, Status>> iterator = this.statuses.iterator();
|
2019-06-24 21:43:14 +02:00
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Either<Placeholder, Status> item = iterator.next();
|
2019-10-22 21:18:20 +02:00
|
|
|
if (item.isRight()) {
|
2019-06-24 21:43:14 +02:00
|
|
|
Status status = item.asRight();
|
2019-07-10 06:52:13 +02:00
|
|
|
if (status.getId().length() < topId.length() || status.getId().compareTo(topId) < 0) {
|
|
|
|
|
2019-06-24 21:43:14 +02:00
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Placeholder placeholder = item.asLeft();
|
2019-07-10 06:52:13 +02:00
|
|
|
if (placeholder.getId().length() < topId.length() || placeholder.getId().compareTo(topId) < 0) {
|
|
|
|
|
2019-06-24 21:43:14 +02:00
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
}
|
2019-06-24 21:43:14 +02:00
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
this.statuses.addAll(statuses);
|
|
|
|
this.updateAdapter();
|
|
|
|
}
|
|
|
|
this.bottomLoading = false;
|
2019-06-24 21:43:14 +02:00
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
},
|
|
|
|
(e) -> {
|
|
|
|
this.initialUpdateFailed = true;
|
|
|
|
// Indicate that we are not loading anymore
|
|
|
|
this.progressBar.setVisibility(View.GONE);
|
|
|
|
this.swipeRefreshLayout.setRefreshing(false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
private void setupTimelinePreferences() {
|
2018-11-12 21:09:39 +01:00
|
|
|
alwaysShowSensitiveMedia = accountManager.getActiveAccount().getAlwaysShowSensitiveMedia();
|
2019-07-28 19:59:52 +02:00
|
|
|
alwaysOpenSpoiler = accountManager.getActiveAccount().getAlwaysOpenSpoiler();
|
2017-01-07 23:24:02 +01:00
|
|
|
|
2019-12-30 21:37:20 +01:00
|
|
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
2018-02-08 19:12:02 +01:00
|
|
|
boolean filter = preferences.getBoolean("tabFilterHomeReplies", true);
|
|
|
|
filterRemoveReplies = kind == Kind.HOME && !filter;
|
|
|
|
|
|
|
|
filter = preferences.getBoolean("tabFilterHomeBoosts", true);
|
|
|
|
filterRemoveReblogs = kind == Kind.HOME && !filter;
|
2019-03-20 19:25:26 +01:00
|
|
|
reloadFilters(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean filterContextMatchesKind(Kind kind, List<String> filterContext) {
|
|
|
|
// home, notifications, public, thread
|
2019-04-08 15:40:16 +02:00
|
|
|
switch (kind) {
|
2019-03-20 19:25:26 +01:00
|
|
|
case HOME:
|
2020-11-22 19:02:38 +01:00
|
|
|
case LIST:
|
2019-03-20 19:25:26 +01:00
|
|
|
return filterContext.contains(Filter.HOME);
|
|
|
|
case PUBLIC_FEDERATED:
|
|
|
|
case PUBLIC_LOCAL:
|
|
|
|
case TAG:
|
|
|
|
return filterContext.contains(Filter.PUBLIC);
|
|
|
|
case FAVOURITES:
|
|
|
|
return (filterContext.contains(Filter.PUBLIC) || filterContext.contains(Filter.NOTIFICATIONS));
|
2020-05-08 19:17:02 +02:00
|
|
|
case USER:
|
|
|
|
case USER_WITH_REPLIES:
|
|
|
|
case USER_PINNED:
|
|
|
|
return filterContext.contains(Filter.ACCOUNT);
|
2019-03-20 19:25:26 +01:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-02-08 19:12:02 +01:00
|
|
|
|
2019-07-08 12:57:53 +02:00
|
|
|
@Override
|
2019-09-24 20:33:29 +02:00
|
|
|
protected boolean filterIsRelevant(@NonNull Filter filter) {
|
2019-07-08 12:57:53 +02:00
|
|
|
return filterContextMatchesKind(kind, filter.getContext());
|
2019-03-20 19:25:26 +01:00
|
|
|
}
|
2018-05-27 10:22:12 +02:00
|
|
|
|
2019-07-08 12:57:53 +02:00
|
|
|
@Override
|
|
|
|
protected void refreshAfterApplyingFilters() {
|
|
|
|
fullyRefresh();
|
2018-05-27 10:22:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setupSwipeRefreshLayout() {
|
2019-05-15 12:43:16 +02:00
|
|
|
swipeRefreshLayout.setEnabled(isSwipeToRefreshEnabled);
|
|
|
|
if (isSwipeToRefreshEnabled) {
|
|
|
|
swipeRefreshLayout.setOnRefreshListener(this);
|
|
|
|
swipeRefreshLayout.setColorSchemeResources(R.color.tusky_blue);
|
|
|
|
}
|
2018-05-27 10:22:12 +02:00
|
|
|
}
|
2018-04-05 22:58:44 +02:00
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
private void setupRecyclerView() {
|
2019-03-04 19:24:27 +01:00
|
|
|
recyclerView.setAccessibilityDelegateCompat(
|
2019-04-07 16:32:58 +02:00
|
|
|
new ListStatusAccessibilityDelegate(recyclerView, this, statuses::getPairedItemOrNull));
|
2018-07-05 21:32:49 +02:00
|
|
|
Context context = recyclerView.getContext();
|
2018-05-27 10:22:12 +02:00
|
|
|
recyclerView.setHasFixedSize(true);
|
|
|
|
layoutManager = new LinearLayoutManager(context);
|
|
|
|
recyclerView.setLayoutManager(layoutManager);
|
|
|
|
DividerItemDecoration divider = new DividerItemDecoration(
|
|
|
|
context, layoutManager.getOrientation());
|
|
|
|
recyclerView.addItemDecoration(divider);
|
2017-05-10 04:36:05 +02:00
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
// CWs are expanded without animation, buttons animate itself, we don't need it basically
|
|
|
|
((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
|
2017-07-14 23:09:44 +02:00
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
recyclerView.setAdapter(adapter);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void deleteStatusById(String id) {
|
|
|
|
for (int i = 0; i < statuses.size(); i++) {
|
|
|
|
Either<Placeholder, Status> either = statuses.get(i);
|
|
|
|
if (either.isRight()
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
&& id.equals(either.asRight().getId())) {
|
2018-05-27 10:22:12 +02:00
|
|
|
statuses.remove(either);
|
|
|
|
updateAdapter();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-10-15 19:47:50 +02:00
|
|
|
if (statuses.size() == 0) {
|
2019-01-28 19:02:31 +01:00
|
|
|
showNothing();
|
2018-09-02 13:23:36 +02:00
|
|
|
}
|
2017-05-10 04:36:05 +02:00
|
|
|
}
|
|
|
|
|
2019-01-28 19:02:31 +01:00
|
|
|
private void showNothing() {
|
|
|
|
statusView.setVisibility(View.VISIBLE);
|
|
|
|
statusView.setup(R.drawable.elephant_friend_empty, R.string.message_empty, null);
|
|
|
|
}
|
|
|
|
|
2017-05-10 04:36:05 +02:00
|
|
|
@Override
|
|
|
|
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
|
2017-04-12 10:32:05 +02:00
|
|
|
/* This is delayed until onActivityCreated solely because MainActivity.composeButton isn't
|
|
|
|
* guaranteed to be set until then. */
|
2017-08-04 11:44:10 +02:00
|
|
|
if (actionButtonPresent()) {
|
2017-04-12 10:32:05 +02:00
|
|
|
/* Use a modified scroll listener that both loads more statuses as it goes, and hides
|
|
|
|
* the follow button on down-scroll. */
|
2017-08-05 11:34:50 +02:00
|
|
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
2017-04-22 10:41:49 +02:00
|
|
|
hideFab = preferences.getBoolean("fabHide", false);
|
2017-04-12 10:32:05 +02:00
|
|
|
scrollListener = new EndlessOnScrollListener(layoutManager) {
|
|
|
|
@Override
|
|
|
|
public void onScrolled(RecyclerView view, int dx, int dy) {
|
|
|
|
super.onScrolled(view, dx, dy);
|
|
|
|
|
2017-08-05 11:34:50 +02:00
|
|
|
ActionButtonActivity activity = (ActionButtonActivity) getActivity();
|
|
|
|
FloatingActionButton composeButton = activity.getActionButton();
|
|
|
|
|
2017-08-04 11:44:10 +02:00
|
|
|
if (composeButton != null) {
|
|
|
|
if (hideFab) {
|
|
|
|
if (dy > 0 && composeButton.isShown()) {
|
|
|
|
composeButton.hide(); // hides the button if we're scrolling down
|
|
|
|
} else if (dy < 0 && !composeButton.isShown()) {
|
|
|
|
composeButton.show(); // shows it if we are scrolling up
|
|
|
|
}
|
|
|
|
} else if (!composeButton.isShown()) {
|
|
|
|
composeButton.show();
|
2017-04-12 10:32:05 +02:00
|
|
|
}
|
2017-11-03 22:17:31 +01:00
|
|
|
}
|
2017-04-12 10:32:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-05-27 10:22:12 +02:00
|
|
|
public void onLoadMore(int totalItemsCount, RecyclerView view) {
|
2017-07-12 21:54:52 +02:00
|
|
|
TimelineFragment.this.onLoadMore();
|
2017-04-12 10:32:05 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// Just use the basic scroll listener to load more statuses.
|
|
|
|
scrollListener = new EndlessOnScrollListener(layoutManager) {
|
|
|
|
@Override
|
2018-05-27 10:22:12 +02:00
|
|
|
public void onLoadMore(int totalItemsCount, RecyclerView view) {
|
2017-07-12 21:54:52 +02:00
|
|
|
TimelineFragment.this.onLoadMore();
|
2017-04-12 10:32:05 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
recyclerView.addOnScrollListener(scrollListener);
|
2018-07-12 21:21:53 +02:00
|
|
|
|
2018-10-15 19:47:50 +02:00
|
|
|
if (!eventRegistered) {
|
|
|
|
eventHub.getEvents()
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
|
|
|
.subscribe(event -> {
|
|
|
|
if (event instanceof FavoriteEvent) {
|
|
|
|
FavoriteEvent favEvent = ((FavoriteEvent) event);
|
|
|
|
handleFavEvent(favEvent);
|
|
|
|
} else if (event instanceof ReblogEvent) {
|
|
|
|
ReblogEvent reblogEvent = (ReblogEvent) event;
|
|
|
|
handleReblogEvent(reblogEvent);
|
2019-11-19 10:15:32 +01:00
|
|
|
} else if (event instanceof BookmarkEvent) {
|
|
|
|
BookmarkEvent bookmarkEvent = (BookmarkEvent) event;
|
|
|
|
handleBookmarkEvent(bookmarkEvent);
|
2020-03-24 21:06:04 +01:00
|
|
|
} else if (event instanceof MuteConversationEvent) {
|
|
|
|
MuteConversationEvent muteEvent = (MuteConversationEvent) event;
|
|
|
|
handleMuteConversationEvent(muteEvent);
|
2018-10-15 19:47:50 +02:00
|
|
|
} else if (event instanceof UnfollowEvent) {
|
|
|
|
if (kind == Kind.HOME) {
|
|
|
|
String id = ((UnfollowEvent) event).getAccountId();
|
|
|
|
removeAllByAccountId(id);
|
|
|
|
}
|
|
|
|
} else if (event instanceof BlockEvent) {
|
2019-02-27 20:03:28 +01:00
|
|
|
if (kind != Kind.USER && kind != Kind.USER_WITH_REPLIES && kind != Kind.USER_PINNED) {
|
2018-10-15 19:47:50 +02:00
|
|
|
String id = ((BlockEvent) event).getAccountId();
|
|
|
|
removeAllByAccountId(id);
|
|
|
|
}
|
|
|
|
} else if (event instanceof MuteEvent) {
|
2019-02-27 20:03:28 +01:00
|
|
|
if (kind != Kind.USER && kind != Kind.USER_WITH_REPLIES && kind != Kind.USER_PINNED) {
|
2018-10-15 19:47:50 +02:00
|
|
|
String id = ((MuteEvent) event).getAccountId();
|
|
|
|
removeAllByAccountId(id);
|
|
|
|
}
|
2019-06-11 15:56:27 +02:00
|
|
|
} else if (event instanceof DomainMuteEvent) {
|
|
|
|
if (kind != Kind.USER && kind != Kind.USER_WITH_REPLIES && kind != Kind.USER_PINNED) {
|
|
|
|
String instance = ((DomainMuteEvent) event).getInstance();
|
|
|
|
removeAllByInstance(instance);
|
|
|
|
}
|
2018-10-15 19:47:50 +02:00
|
|
|
} else if (event instanceof StatusDeletedEvent) {
|
2019-02-27 20:03:28 +01:00
|
|
|
if (kind != Kind.USER && kind != Kind.USER_WITH_REPLIES && kind != Kind.USER_PINNED) {
|
2018-10-15 19:47:50 +02:00
|
|
|
String id = ((StatusDeletedEvent) event).getStatusId();
|
|
|
|
deleteStatusById(id);
|
|
|
|
}
|
|
|
|
} else if (event instanceof StatusComposedEvent) {
|
|
|
|
Status status = ((StatusComposedEvent) event).getStatus();
|
|
|
|
handleStatusComposeEvent(status);
|
2018-11-12 21:09:39 +01:00
|
|
|
} else if (event instanceof PreferenceChangedEvent) {
|
|
|
|
onPreferenceChanged(((PreferenceChangedEvent) event).getPreferenceKey());
|
2018-07-12 21:21:53 +02:00
|
|
|
}
|
2018-10-15 19:47:50 +02:00
|
|
|
});
|
|
|
|
eventRegistered = true;
|
|
|
|
}
|
2017-04-12 10:32:05 +02:00
|
|
|
}
|
|
|
|
|
2017-06-26 11:15:47 +02:00
|
|
|
@Override
|
|
|
|
public void onRefresh() {
|
2019-05-15 12:43:16 +02:00
|
|
|
if (isSwipeToRefreshEnabled)
|
|
|
|
swipeRefreshLayout.setEnabled(true);
|
2019-01-28 19:02:31 +01:00
|
|
|
this.statusView.setVisibility(View.GONE);
|
2019-05-15 12:43:16 +02:00
|
|
|
isNeedRefresh = false;
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
if (this.initialUpdateFailed) {
|
|
|
|
updateCurrent();
|
|
|
|
}
|
2019-06-24 21:43:14 +02:00
|
|
|
|
|
|
|
this.loadAbove();
|
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void loadAbove() {
|
2019-02-05 20:06:00 +01:00
|
|
|
String firstOrNull = null;
|
|
|
|
String secondOrNull = null;
|
|
|
|
for (int i = 0; i < this.statuses.size(); i++) {
|
|
|
|
Either<Placeholder, Status> status = this.statuses.get(i);
|
|
|
|
if (status.isRight()) {
|
|
|
|
firstOrNull = status.asRight().getId();
|
|
|
|
if (i + 1 < statuses.size() && statuses.get(i + 1).isRight()) {
|
|
|
|
secondOrNull = statuses.get(i + 1).asRight().getId();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
if (firstOrNull != null) {
|
2019-02-05 20:06:00 +01:00
|
|
|
this.sendFetchTimelineRequest(null, firstOrNull, secondOrNull, FetchEnd.TOP, -1);
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
} else {
|
2019-02-05 20:06:00 +01:00
|
|
|
this.sendFetchTimelineRequest(null, null, null, FetchEnd.BOTTOM, -1);
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
}
|
2017-06-26 11:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReply(int position) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
super.reply(statuses.get(position).asRight());
|
2017-06-26 11:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReblog(final boolean reblog, final int position) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
final Status status = statuses.get(position).asRight();
|
|
|
|
timelineCases.reblog(status, reblog)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
|
|
|
.subscribe(
|
|
|
|
(newStatus) -> setRebloggedForStatus(position, status, reblog),
|
|
|
|
(err) -> Log.d(TAG, "Failed to reblog status " + status.getId(), err)
|
|
|
|
);
|
2017-06-26 11:15:47 +02:00
|
|
|
}
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
private void setRebloggedForStatus(int position, Status status, boolean reblog) {
|
|
|
|
status.setReblogged(reblog);
|
|
|
|
|
|
|
|
if (status.getReblog() != null) {
|
|
|
|
status.getReblog().setReblogged(reblog);
|
|
|
|
}
|
|
|
|
|
|
|
|
Pair<StatusViewData.Concrete, Integer> actual =
|
|
|
|
findStatusAndPosition(position, status);
|
|
|
|
if (actual == null) return;
|
|
|
|
|
|
|
|
StatusViewData newViewData =
|
|
|
|
new StatusViewData.Builder(actual.first)
|
|
|
|
.setReblogged(reblog)
|
|
|
|
.createStatusViewData();
|
|
|
|
statuses.setPairedItem(actual.second, newViewData);
|
|
|
|
updateAdapter();
|
|
|
|
}
|
|
|
|
|
2017-06-26 11:15:47 +02:00
|
|
|
@Override
|
|
|
|
public void onFavourite(final boolean favourite, final int position) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
final Status status = statuses.get(position).asRight();
|
|
|
|
|
|
|
|
timelineCases.favourite(status, favourite)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
|
|
|
.subscribe(
|
|
|
|
(newStatus) -> setFavouriteForStatus(position, newStatus, favourite),
|
|
|
|
(err) -> Log.d(TAG, "Failed to favourite status " + status.getId(), err)
|
|
|
|
);
|
2017-06-26 11:15:47 +02:00
|
|
|
}
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
private void setFavouriteForStatus(int position, Status status, boolean favourite) {
|
|
|
|
status.setFavourited(favourite);
|
|
|
|
|
|
|
|
if (status.getReblog() != null) {
|
|
|
|
status.getReblog().setFavourited(favourite);
|
|
|
|
}
|
|
|
|
|
|
|
|
Pair<StatusViewData.Concrete, Integer> actual =
|
|
|
|
findStatusAndPosition(position, status);
|
|
|
|
if (actual == null) return;
|
|
|
|
|
|
|
|
StatusViewData newViewData = new StatusViewData
|
|
|
|
.Builder(actual.first)
|
|
|
|
.setFavourited(favourite)
|
|
|
|
.createStatusViewData();
|
|
|
|
statuses.setPairedItem(actual.second, newViewData);
|
|
|
|
updateAdapter();
|
|
|
|
}
|
|
|
|
|
2019-11-19 10:15:32 +01:00
|
|
|
@Override
|
|
|
|
public void onBookmark(final boolean bookmark, final int position) {
|
|
|
|
final Status status = statuses.get(position).asRight();
|
|
|
|
|
|
|
|
timelineCases.bookmark(status, bookmark)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
|
|
|
.subscribe(
|
|
|
|
(newStatus) -> setBookmarkForStatus(position, newStatus, bookmark),
|
|
|
|
(err) -> Log.d(TAG, "Failed to favourite status " + status.getId(), err)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setBookmarkForStatus(int position, Status status, boolean bookmark) {
|
|
|
|
status.setBookmarked(bookmark);
|
|
|
|
|
|
|
|
if (status.getReblog() != null) {
|
|
|
|
status.getReblog().setBookmarked(bookmark);
|
|
|
|
}
|
|
|
|
|
|
|
|
Pair<StatusViewData.Concrete, Integer> actual =
|
|
|
|
findStatusAndPosition(position, status);
|
|
|
|
if (actual == null) return;
|
|
|
|
|
|
|
|
StatusViewData newViewData = new StatusViewData
|
|
|
|
.Builder(actual.first)
|
|
|
|
.setBookmarked(bookmark)
|
|
|
|
.createStatusViewData();
|
|
|
|
statuses.setPairedItem(actual.second, newViewData);
|
|
|
|
updateAdapter();
|
|
|
|
}
|
|
|
|
|
2019-04-22 10:11:00 +02:00
|
|
|
public void onVoteInPoll(int position, @NonNull List<Integer> choices) {
|
2019-05-05 08:26:17 +02:00
|
|
|
|
2019-04-22 10:11:00 +02:00
|
|
|
final Status status = statuses.get(position).asRight();
|
|
|
|
|
2019-05-05 08:26:17 +02:00
|
|
|
Poll votedPoll = status.getActionableStatus().getPoll().votedCopy(choices);
|
|
|
|
|
|
|
|
setVoteForPoll(position, status, votedPoll);
|
2019-04-22 10:11:00 +02:00
|
|
|
|
|
|
|
timelineCases.voteInPoll(status, choices)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this)))
|
|
|
|
.subscribe(
|
|
|
|
(newPoll) -> setVoteForPoll(position, status, newPoll),
|
|
|
|
(t) -> Log.d(TAG,
|
|
|
|
"Failed to vote in poll: " + status.getId(), t)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setVoteForPoll(int position, Status status, Poll newPoll) {
|
|
|
|
Pair<StatusViewData.Concrete, Integer> actual =
|
|
|
|
findStatusAndPosition(position, status);
|
|
|
|
if (actual == null) return;
|
|
|
|
|
|
|
|
StatusViewData newViewData = new StatusViewData
|
|
|
|
.Builder(actual.first)
|
|
|
|
.setPoll(newPoll)
|
|
|
|
.createStatusViewData();
|
|
|
|
statuses.setPairedItem(actual.second, newViewData);
|
|
|
|
updateAdapter();
|
|
|
|
}
|
|
|
|
|
2017-06-26 11:15:47 +02:00
|
|
|
@Override
|
2019-02-12 19:22:37 +01:00
|
|
|
public void onMore(@NonNull View view, final int position) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
super.more(statuses.get(position).asRight(), view, position);
|
2017-06-26 11:15:47 +02:00
|
|
|
}
|
|
|
|
|
2017-06-28 10:10:56 +02:00
|
|
|
@Override
|
|
|
|
public void onOpenReblog(int position) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
super.openReblog(statuses.get(position).asRight());
|
2017-07-12 21:54:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onExpandedChange(boolean expanded, int position) {
|
2017-11-06 16:19:15 +01:00
|
|
|
StatusViewData newViewData = new StatusViewData.Builder(
|
|
|
|
((StatusViewData.Concrete) statuses.getPairedItem(position)))
|
2017-07-12 21:54:52 +02:00
|
|
|
.setIsExpanded(expanded).createStatusViewData();
|
|
|
|
statuses.setPairedItem(position, newViewData);
|
2018-05-27 10:22:12 +02:00
|
|
|
updateAdapter();
|
2017-07-12 21:54:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContentHiddenChange(boolean isShowing, int position) {
|
2017-11-06 16:19:15 +01:00
|
|
|
StatusViewData newViewData = new StatusViewData.Builder(
|
|
|
|
((StatusViewData.Concrete) statuses.getPairedItem(position)))
|
2017-07-12 21:54:52 +02:00
|
|
|
.setIsShowingSensitiveContent(isShowing).createStatusViewData();
|
|
|
|
statuses.setPairedItem(position, newViewData);
|
2018-05-27 10:22:12 +02:00
|
|
|
updateAdapter();
|
2017-06-28 10:10:56 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 19:24:27 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onShowReblogs(int position) {
|
|
|
|
String statusId = statuses.get(position).asRight().getId();
|
|
|
|
Intent intent = AccountListActivity.newIntent(getContext(), AccountListActivity.Type.REBLOGGED, statusId);
|
|
|
|
((BaseActivity) getActivity()).startActivityWithSlideInAnimation(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onShowFavs(int position) {
|
|
|
|
String statusId = statuses.get(position).asRight().getId();
|
|
|
|
Intent intent = AccountListActivity.newIntent(getContext(), AccountListActivity.Type.FAVOURITED, statusId);
|
|
|
|
((BaseActivity) getActivity()).startActivityWithSlideInAnimation(intent);
|
|
|
|
}
|
|
|
|
|
2017-11-03 22:17:31 +01:00
|
|
|
@Override
|
|
|
|
public void onLoadMore(int position) {
|
|
|
|
//check bounds before accessing list,
|
|
|
|
if (statuses.size() >= position && position > 0) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Status fromStatus = statuses.get(position - 1).asRightOrNull();
|
|
|
|
Status toStatus = statuses.get(position + 1).asRightOrNull();
|
2019-02-05 20:06:00 +01:00
|
|
|
String maxMinusOne =
|
|
|
|
statuses.size() > position + 1 && statuses.get(position + 2).isRight()
|
|
|
|
? statuses.get(position + 1).asRight().getId()
|
|
|
|
: null;
|
2017-11-06 16:19:15 +01:00
|
|
|
if (fromStatus == null || toStatus == null) {
|
|
|
|
Log.e(TAG, "Failed to load more at " + position + ", wrong placeholder position");
|
|
|
|
return;
|
|
|
|
}
|
2019-02-05 20:06:00 +01:00
|
|
|
sendFetchTimelineRequest(fromStatus.getId(), toStatus.getId(), maxMinusOne,
|
|
|
|
FetchEnd.MIDDLE, position);
|
2017-11-03 22:17:31 +01:00
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Placeholder placeholder = statuses.get(position).asLeft();
|
|
|
|
StatusViewData newViewData = new StatusViewData.Placeholder(placeholder.getId(), true);
|
2017-11-03 22:17:31 +01:00
|
|
|
statuses.setPairedItem(position, newViewData);
|
2018-05-27 10:22:12 +02:00
|
|
|
updateAdapter();
|
2017-11-03 22:17:31 +01:00
|
|
|
} else {
|
2017-11-06 16:19:15 +01:00
|
|
|
Log.e(TAG, "error loading more");
|
2017-11-03 22:17:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add support for collapsible statuses when they exceed 500 characters (#825)
* Update Gradle plugin to work with Android Studio 3.3 Canary
Android Studio 3.1.4 Stable doesn't render layout previews in this project
for whatever reason. Switching to the latest 3.3 Canary release fixes the
issue without affecting Gradle scripts but requires the new Android Gradle
plugin to match the new Android Studio release.
This commit will be reverted once development on the feature is done.
* Update gradle build script to allow installing debug builds alongside store version
This will allow developers, testers, etc to work on Tusky will not having to worry
about overwriting, uninstalling, fiddling with a preinstalled application which would
mean having to login again every time the development cycle starts/finishes and
manually reinstalling the app.
* Add UI changes to support collapsing statuses
The button uses subtle styling to not be distracting like the CW button on the timeline
The button is toggleable, full width to match the status textbox hitbox width and also
is shorter to not be too intrusive between the status text and images, or the post below
* Update status data model to store whether the message has been collapsed
* Update status action listener to notify of collapsed state changing
Provide stubs in all implementing classes and mark as TODO the stubs that
require a proper implementation for the feature to work.
* Add implementation code to handle status collapse/expand in timeline
Code has not been added elsewhere to simplify testing.
Once the code will be considered stable it will be also included in other
status action listener implementers.
* Add preferences so that users can toggle the collapsing of long posts
This is currently limited to a simple toggle, it would be nice to implement
a more advanced UI to offer the user more control over the feature.
* Update Gradle plugin to work with latest Android Studio 3.3 Canary 8
Just like the other commit, this will be reverted once the feature is working.
I simply don't want to deal with what changes in my installation of Android
Studio 3.1.4 Stable which breaks the layout preview rendering.
* Update data models and utils for statuses to better handle collapsing
I forgot that data isn't available from the API and can't really be built
from scratch using existing data due to preferences.
A new, extra boolean should fix the issue.
* Fix search breaking due to newly introduced variables in utils classes
* Fix timeline breaking due to newly introduced variables in utils classes
* Fix item status text for collapsed toggle being shown in the wrong state
* Update timeline fragment to refresh the list when collapsed settings change
* Add support for status content collapse in timeline viewholder
* Fix view holder truncating posts using temporary debug settings at 50 chars
* Add toggle support to notification layout as well
* Add support for collapsed statuses to search results
* Add support for expandable content to notifications too
* Update codebase with some suggested changes by @charlang
* Update more code with more suggestions and move null-safety into view data
* Update even more code with even more suggested code changes
* Revert a0a41ca and 0ee004d (Android Studio 3.1 to Android Studio 3.3 updates)
* Add an input filter utility class to reuse code for trimming statuses
* Update UI of statuses to show a taller collapsible button
* Update notification fragment logging to simplify null checks
* Add smartness to SmartLengthInputFilter such as word trimming and runway
* Fix posts with show more button even if bad ratio didn't collapse
* Fix thread view showing button but not collapsing by implementing the feature
* Fix spannable losing spans when collapsed and restore length to 500 characters
* Remove debug build suffix as per request
* Fix all the merging happened in f66d689, 623cad2 and 7056ba5
* Fix notification button spanning full width rather than content width
* Add a way to access a singleton to smart filter and use clearer code
* Update view holders using smart input filters to use more singletons
* Fix code style lacking spaces before boolean checks in ifs and others
* Remove all code related to collapsibility preferences, strings included
* Update style to match content warning toggle button
* Update strings to give cleaner differentiation between CW and collapse
* Update smart filter code to use fully qualified names to avoid confusion
2018-09-19 19:51:20 +02:00
|
|
|
@Override
|
|
|
|
public void onContentCollapsedChange(boolean isCollapsed, int position) {
|
|
|
|
if (position < 0 || position >= statuses.size()) {
|
|
|
|
Log.e(TAG, String.format("Tried to access out of bounds status position: %d of %d", position, statuses.size() - 1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusViewData status = statuses.getPairedItem(position);
|
|
|
|
if (!(status instanceof StatusViewData.Concrete)) {
|
|
|
|
// Statuses PairedList contains a base type of StatusViewData.Concrete and also doesn't
|
|
|
|
// check for null values when adding values to it although this doesn't seem to be an issue.
|
|
|
|
Log.e(TAG, String.format(
|
|
|
|
"Expected StatusViewData.Concrete, got %s instead at position: %d of %d",
|
|
|
|
status == null ? "<null>" : status.getClass().getSimpleName(),
|
|
|
|
position,
|
2018-10-15 19:47:50 +02:00
|
|
|
statuses.size() - 1
|
Add support for collapsible statuses when they exceed 500 characters (#825)
* Update Gradle plugin to work with Android Studio 3.3 Canary
Android Studio 3.1.4 Stable doesn't render layout previews in this project
for whatever reason. Switching to the latest 3.3 Canary release fixes the
issue without affecting Gradle scripts but requires the new Android Gradle
plugin to match the new Android Studio release.
This commit will be reverted once development on the feature is done.
* Update gradle build script to allow installing debug builds alongside store version
This will allow developers, testers, etc to work on Tusky will not having to worry
about overwriting, uninstalling, fiddling with a preinstalled application which would
mean having to login again every time the development cycle starts/finishes and
manually reinstalling the app.
* Add UI changes to support collapsing statuses
The button uses subtle styling to not be distracting like the CW button on the timeline
The button is toggleable, full width to match the status textbox hitbox width and also
is shorter to not be too intrusive between the status text and images, or the post below
* Update status data model to store whether the message has been collapsed
* Update status action listener to notify of collapsed state changing
Provide stubs in all implementing classes and mark as TODO the stubs that
require a proper implementation for the feature to work.
* Add implementation code to handle status collapse/expand in timeline
Code has not been added elsewhere to simplify testing.
Once the code will be considered stable it will be also included in other
status action listener implementers.
* Add preferences so that users can toggle the collapsing of long posts
This is currently limited to a simple toggle, it would be nice to implement
a more advanced UI to offer the user more control over the feature.
* Update Gradle plugin to work with latest Android Studio 3.3 Canary 8
Just like the other commit, this will be reverted once the feature is working.
I simply don't want to deal with what changes in my installation of Android
Studio 3.1.4 Stable which breaks the layout preview rendering.
* Update data models and utils for statuses to better handle collapsing
I forgot that data isn't available from the API and can't really be built
from scratch using existing data due to preferences.
A new, extra boolean should fix the issue.
* Fix search breaking due to newly introduced variables in utils classes
* Fix timeline breaking due to newly introduced variables in utils classes
* Fix item status text for collapsed toggle being shown in the wrong state
* Update timeline fragment to refresh the list when collapsed settings change
* Add support for status content collapse in timeline viewholder
* Fix view holder truncating posts using temporary debug settings at 50 chars
* Add toggle support to notification layout as well
* Add support for collapsed statuses to search results
* Add support for expandable content to notifications too
* Update codebase with some suggested changes by @charlang
* Update more code with more suggestions and move null-safety into view data
* Update even more code with even more suggested code changes
* Revert a0a41ca and 0ee004d (Android Studio 3.1 to Android Studio 3.3 updates)
* Add an input filter utility class to reuse code for trimming statuses
* Update UI of statuses to show a taller collapsible button
* Update notification fragment logging to simplify null checks
* Add smartness to SmartLengthInputFilter such as word trimming and runway
* Fix posts with show more button even if bad ratio didn't collapse
* Fix thread view showing button but not collapsing by implementing the feature
* Fix spannable losing spans when collapsed and restore length to 500 characters
* Remove debug build suffix as per request
* Fix all the merging happened in f66d689, 623cad2 and 7056ba5
* Fix notification button spanning full width rather than content width
* Add a way to access a singleton to smart filter and use clearer code
* Update view holders using smart input filters to use more singletons
* Fix code style lacking spaces before boolean checks in ifs and others
* Remove all code related to collapsibility preferences, strings included
* Update style to match content warning toggle button
* Update strings to give cleaner differentiation between CW and collapse
* Update smart filter code to use fully qualified names to avoid confusion
2018-09-19 19:51:20 +02:00
|
|
|
));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusViewData updatedStatus = new StatusViewData.Builder((StatusViewData.Concrete) status)
|
|
|
|
.setCollapsed(isCollapsed)
|
|
|
|
.createStatusViewData();
|
|
|
|
statuses.setPairedItem(position, updatedStatus);
|
|
|
|
updateAdapter();
|
|
|
|
}
|
|
|
|
|
2017-06-26 11:15:47 +02:00
|
|
|
@Override
|
2019-03-04 19:24:27 +01:00
|
|
|
public void onViewMedia(int position, int attachmentIndex, @Nullable View view) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Status status = statuses.get(position).asRightOrNull();
|
2018-05-10 20:13:25 +02:00
|
|
|
if (status == null) return;
|
|
|
|
super.viewMedia(attachmentIndex, status, view);
|
2017-06-26 11:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onViewThread(int position) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
super.viewThread(statuses.get(position).asRight());
|
2017-06-26 11:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onViewTag(String tag) {
|
2020-05-15 22:10:29 +02:00
|
|
|
if (kind == Kind.TAG && tags.size() == 1 && tags.contains(tag)) {
|
2017-06-26 11:15:47 +02:00
|
|
|
// If already viewing a tag page, then ignore any request to view that tag again.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.viewTag(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onViewAccount(String id) {
|
2020-05-15 22:10:29 +02:00
|
|
|
if ((kind == Kind.USER || kind == Kind.USER_WITH_REPLIES) && this.id.equals(id)) {
|
2017-06-26 11:15:47 +02:00
|
|
|
/* If already viewing an account page, then any requests to view that account page
|
|
|
|
* should be ignored. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.viewAccount(id);
|
|
|
|
}
|
|
|
|
|
2018-11-12 21:09:39 +01:00
|
|
|
private void onPreferenceChanged(String key) {
|
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
2017-06-26 11:15:47 +02:00
|
|
|
switch (key) {
|
|
|
|
case "fabHide": {
|
|
|
|
hideFab = sharedPreferences.getBoolean("fabHide", false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "mediaPreviewEnabled": {
|
2018-11-12 21:09:39 +01:00
|
|
|
boolean enabled = accountManager.getActiveAccount().getMediaPreviewEnabled();
|
2018-06-25 17:20:41 +02:00
|
|
|
boolean oldMediaPreviewEnabled = adapter.getMediaPreviewEnabled();
|
2018-08-17 04:53:38 +02:00
|
|
|
if (enabled != oldMediaPreviewEnabled) {
|
2018-06-25 17:20:41 +02:00
|
|
|
adapter.setMediaPreviewEnabled(enabled);
|
|
|
|
fullyRefresh();
|
|
|
|
}
|
2017-06-26 11:15:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-06-30 08:31:58 +02:00
|
|
|
case "tabFilterHomeReplies": {
|
|
|
|
boolean filter = sharedPreferences.getBoolean("tabFilterHomeReplies", true);
|
|
|
|
boolean oldRemoveReplies = filterRemoveReplies;
|
|
|
|
filterRemoveReplies = kind == Kind.HOME && !filter;
|
|
|
|
if (adapter.getItemCount() > 1 && oldRemoveReplies != filterRemoveReplies) {
|
|
|
|
fullyRefresh();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "tabFilterHomeBoosts": {
|
|
|
|
boolean filter = sharedPreferences.getBoolean("tabFilterHomeBoosts", true);
|
|
|
|
boolean oldRemoveReblogs = filterRemoveReblogs;
|
|
|
|
filterRemoveReblogs = kind == Kind.HOME && !filter;
|
|
|
|
if (adapter.getItemCount() > 1 && oldRemoveReblogs != filterRemoveReblogs) {
|
|
|
|
fullyRefresh();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-03-20 19:25:26 +01:00
|
|
|
case Filter.HOME:
|
|
|
|
case Filter.NOTIFICATIONS:
|
|
|
|
case Filter.THREAD:
|
2020-05-08 19:17:02 +02:00
|
|
|
case Filter.PUBLIC:
|
|
|
|
case Filter.ACCOUNT: {
|
2019-03-20 19:25:26 +01:00
|
|
|
if (filterContextMatchesKind(kind, Collections.singletonList(key))) {
|
|
|
|
reloadFilters(true);
|
2018-04-05 22:58:44 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-11-30 20:12:09 +01:00
|
|
|
case "alwaysShowSensitiveMedia": {
|
|
|
|
//it is ok if only newly loaded statuses are affected, no need to fully refresh
|
2018-11-12 21:09:39 +01:00
|
|
|
alwaysShowSensitiveMedia = accountManager.getActiveAccount().getAlwaysShowSensitiveMedia();
|
Add support for collapsible statuses when they exceed 500 characters (#825)
* Update Gradle plugin to work with Android Studio 3.3 Canary
Android Studio 3.1.4 Stable doesn't render layout previews in this project
for whatever reason. Switching to the latest 3.3 Canary release fixes the
issue without affecting Gradle scripts but requires the new Android Gradle
plugin to match the new Android Studio release.
This commit will be reverted once development on the feature is done.
* Update gradle build script to allow installing debug builds alongside store version
This will allow developers, testers, etc to work on Tusky will not having to worry
about overwriting, uninstalling, fiddling with a preinstalled application which would
mean having to login again every time the development cycle starts/finishes and
manually reinstalling the app.
* Add UI changes to support collapsing statuses
The button uses subtle styling to not be distracting like the CW button on the timeline
The button is toggleable, full width to match the status textbox hitbox width and also
is shorter to not be too intrusive between the status text and images, or the post below
* Update status data model to store whether the message has been collapsed
* Update status action listener to notify of collapsed state changing
Provide stubs in all implementing classes and mark as TODO the stubs that
require a proper implementation for the feature to work.
* Add implementation code to handle status collapse/expand in timeline
Code has not been added elsewhere to simplify testing.
Once the code will be considered stable it will be also included in other
status action listener implementers.
* Add preferences so that users can toggle the collapsing of long posts
This is currently limited to a simple toggle, it would be nice to implement
a more advanced UI to offer the user more control over the feature.
* Update Gradle plugin to work with latest Android Studio 3.3 Canary 8
Just like the other commit, this will be reverted once the feature is working.
I simply don't want to deal with what changes in my installation of Android
Studio 3.1.4 Stable which breaks the layout preview rendering.
* Update data models and utils for statuses to better handle collapsing
I forgot that data isn't available from the API and can't really be built
from scratch using existing data due to preferences.
A new, extra boolean should fix the issue.
* Fix search breaking due to newly introduced variables in utils classes
* Fix timeline breaking due to newly introduced variables in utils classes
* Fix item status text for collapsed toggle being shown in the wrong state
* Update timeline fragment to refresh the list when collapsed settings change
* Add support for status content collapse in timeline viewholder
* Fix view holder truncating posts using temporary debug settings at 50 chars
* Add toggle support to notification layout as well
* Add support for collapsed statuses to search results
* Add support for expandable content to notifications too
* Update codebase with some suggested changes by @charlang
* Update more code with more suggestions and move null-safety into view data
* Update even more code with even more suggested code changes
* Revert a0a41ca and 0ee004d (Android Studio 3.1 to Android Studio 3.3 updates)
* Add an input filter utility class to reuse code for trimming statuses
* Update UI of statuses to show a taller collapsible button
* Update notification fragment logging to simplify null checks
* Add smartness to SmartLengthInputFilter such as word trimming and runway
* Fix posts with show more button even if bad ratio didn't collapse
* Fix thread view showing button but not collapsing by implementing the feature
* Fix spannable losing spans when collapsed and restore length to 500 characters
* Remove debug build suffix as per request
* Fix all the merging happened in f66d689, 623cad2 and 7056ba5
* Fix notification button spanning full width rather than content width
* Add a way to access a singleton to smart filter and use clearer code
* Update view holders using smart input filters to use more singletons
* Fix code style lacking spaces before boolean checks in ifs and others
* Remove all code related to collapsibility preferences, strings included
* Update style to match content warning toggle button
* Update strings to give cleaner differentiation between CW and collapse
* Update smart filter code to use fully qualified names to avoid confusion
2018-09-19 19:51:20 +02:00
|
|
|
break;
|
2017-11-30 20:12:09 +01:00
|
|
|
}
|
2017-06-26 11:15:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-12 21:54:52 +02:00
|
|
|
@Override
|
|
|
|
public void removeItem(int position) {
|
|
|
|
statuses.remove(position);
|
2018-05-27 10:22:12 +02:00
|
|
|
updateAdapter();
|
2017-07-12 21:54:52 +02:00
|
|
|
}
|
|
|
|
|
2018-06-25 14:44:29 +02:00
|
|
|
private void removeAllByAccountId(String accountId) {
|
2017-07-12 21:54:52 +02:00
|
|
|
// using iterator to safely remove items while iterating
|
2017-11-06 16:19:15 +01:00
|
|
|
Iterator<Either<Placeholder, Status>> iterator = statuses.iterator();
|
2017-07-12 21:54:52 +02:00
|
|
|
while (iterator.hasNext()) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Status status = iterator.next().asRightOrNull();
|
2019-06-22 08:05:24 +02:00
|
|
|
if (status != null &&
|
|
|
|
(status.getAccount().getId().equals(accountId) || status.getActionableStatus().getAccount().getId().equals(accountId))) {
|
2017-07-12 21:54:52 +02:00
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
}
|
2018-05-27 10:22:12 +02:00
|
|
|
updateAdapter();
|
2017-07-12 21:54:52 +02:00
|
|
|
}
|
|
|
|
|
2019-06-11 15:56:27 +02:00
|
|
|
private void removeAllByInstance(String instance) {
|
|
|
|
// using iterator to safely remove items while iterating
|
|
|
|
Iterator<Either<Placeholder, Status>> iterator = statuses.iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Status status = iterator.next().asRightOrNull();
|
|
|
|
if (status != null && LinkHelper.getDomain(status.getAccount().getUrl()).equals(instance)) {
|
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateAdapter();
|
|
|
|
}
|
|
|
|
|
2017-07-12 21:54:52 +02:00
|
|
|
private void onLoadMore() {
|
2018-05-27 10:22:12 +02:00
|
|
|
if (didLoadEverythingBottom || bottomLoading) {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-28 21:10:38 +01:00
|
|
|
|
2019-04-08 15:40:16 +02:00
|
|
|
if (statuses.size() == 0) {
|
2019-03-28 21:10:38 +01:00
|
|
|
sendInitialRequest();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
bottomLoading = true;
|
|
|
|
|
|
|
|
Either<Placeholder, Status> last = statuses.get(statuses.size() - 1);
|
|
|
|
Placeholder placeholder;
|
|
|
|
if (last.isRight()) {
|
2019-01-31 19:03:34 +01:00
|
|
|
final String placeholderId = StringUtils.dec(last.asRight().getId());
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
placeholder = new Placeholder(placeholderId);
|
|
|
|
statuses.add(new Either.Left<>(placeholder));
|
2018-05-27 10:22:12 +02:00
|
|
|
} else {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
placeholder = last.asLeft();
|
2018-05-27 10:22:12 +02:00
|
|
|
}
|
|
|
|
statuses.setPairedItem(statuses.size() - 1,
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
new StatusViewData.Placeholder(placeholder.getId(), true));
|
2018-05-27 10:22:12 +02:00
|
|
|
|
|
|
|
updateAdapter();
|
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
String bottomId = null;
|
2020-06-07 19:37:34 +02:00
|
|
|
if (kind == Kind.FAVOURITES || kind == Kind.BOOKMARKS) {
|
|
|
|
bottomId = this.nextId;
|
|
|
|
} else {
|
|
|
|
final ListIterator<Either<Placeholder, Status>> iterator =
|
|
|
|
this.statuses.listIterator(this.statuses.size());
|
|
|
|
while (iterator.hasPrevious()) {
|
|
|
|
Either<Placeholder, Status> previous = iterator.previous();
|
|
|
|
if (previous.isRight()) {
|
|
|
|
bottomId = previous.asRight().getId();
|
|
|
|
break;
|
|
|
|
}
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-05 20:06:00 +01:00
|
|
|
sendFetchTimelineRequest(bottomId, null, null, FetchEnd.BOTTOM, -1);
|
2017-06-26 11:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void fullyRefresh() {
|
2018-05-27 10:22:12 +02:00
|
|
|
statuses.clear();
|
|
|
|
updateAdapter();
|
2018-06-25 18:20:45 +02:00
|
|
|
bottomLoading = true;
|
2019-02-05 20:06:00 +01:00
|
|
|
sendFetchTimelineRequest(null, null, null, FetchEnd.BOTTOM, -1);
|
2017-06-26 11:15:47 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 11:44:10 +02:00
|
|
|
private boolean actionButtonPresent() {
|
2019-11-19 10:15:32 +01:00
|
|
|
return kind != Kind.TAG && kind != Kind.FAVOURITES && kind != Kind.BOOKMARKS &&
|
2018-05-27 10:22:12 +02:00
|
|
|
getActivity() instanceof ActionButtonActivity;
|
2017-04-12 10:32:05 +02:00
|
|
|
}
|
|
|
|
|
2017-01-18 19:35:07 +01:00
|
|
|
private void jumpToTop() {
|
2019-04-08 15:40:16 +02:00
|
|
|
if (isAdded()) {
|
|
|
|
layoutManager.scrollToPosition(0);
|
|
|
|
recyclerView.stopScroll();
|
|
|
|
scrollListener.reset();
|
|
|
|
}
|
2017-01-18 19:35:07 +01:00
|
|
|
}
|
|
|
|
|
2020-05-15 22:10:29 +02:00
|
|
|
private Call<List<Status>> getFetchCallByTimelineType(String fromId, String uptoId) {
|
2017-06-30 08:31:58 +02:00
|
|
|
MastodonApi api = mastodonApi;
|
|
|
|
switch (kind) {
|
|
|
|
default:
|
2017-07-12 21:54:52 +02:00
|
|
|
case HOME:
|
2018-07-25 21:50:09 +02:00
|
|
|
return api.homeTimeline(fromId, uptoId, LOAD_AT_ONCE);
|
2017-07-12 21:54:52 +02:00
|
|
|
case PUBLIC_FEDERATED:
|
2017-11-03 22:17:31 +01:00
|
|
|
return api.publicTimeline(null, fromId, uptoId, LOAD_AT_ONCE);
|
2017-07-12 21:54:52 +02:00
|
|
|
case PUBLIC_LOCAL:
|
2017-11-03 22:17:31 +01:00
|
|
|
return api.publicTimeline(true, fromId, uptoId, LOAD_AT_ONCE);
|
2017-07-12 21:54:52 +02:00
|
|
|
case TAG:
|
2020-05-15 22:10:29 +02:00
|
|
|
String firstHashtag = tags.get(0);
|
|
|
|
List<String> additionalHashtags = tags.subList(1, tags.size());
|
|
|
|
return api.hashtagTimeline(firstHashtag, additionalHashtags, null, fromId, uptoId, LOAD_AT_ONCE);
|
2017-07-12 21:54:52 +02:00
|
|
|
case USER:
|
2020-05-15 22:10:29 +02:00
|
|
|
return api.accountStatuses(id, fromId, uptoId, LOAD_AT_ONCE, true, null, null);
|
2019-01-21 08:37:25 +01:00
|
|
|
case USER_PINNED:
|
2020-05-15 22:10:29 +02:00
|
|
|
return api.accountStatuses(id, fromId, uptoId, LOAD_AT_ONCE, null, null, true);
|
2018-06-18 13:26:18 +02:00
|
|
|
case USER_WITH_REPLIES:
|
2020-05-15 22:10:29 +02:00
|
|
|
return api.accountStatuses(id, fromId, uptoId, LOAD_AT_ONCE, null, null, null);
|
2017-07-12 21:54:52 +02:00
|
|
|
case FAVOURITES:
|
2017-11-03 22:17:31 +01:00
|
|
|
return api.favourites(fromId, uptoId, LOAD_AT_ONCE);
|
2019-11-19 10:15:32 +01:00
|
|
|
case BOOKMARKS:
|
|
|
|
return api.bookmarks(fromId, uptoId, LOAD_AT_ONCE);
|
2018-01-06 19:01:37 +01:00
|
|
|
case LIST:
|
2020-05-15 22:10:29 +02:00
|
|
|
return api.listTimeline(id, fromId, uptoId, LOAD_AT_ONCE);
|
2017-06-30 08:31:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-05 20:06:00 +01:00
|
|
|
private void sendFetchTimelineRequest(@Nullable String maxId, @Nullable String sinceId,
|
|
|
|
@Nullable String sinceIdMinusOne,
|
2017-11-03 22:17:31 +01:00
|
|
|
final FetchEnd fetchEnd, final int pos) {
|
2019-05-15 12:43:16 +02:00
|
|
|
if (isAdded() && (fetchEnd == FetchEnd.TOP || fetchEnd == FetchEnd.BOTTOM && maxId == null && progressBar.getVisibility() != View.VISIBLE) && !isSwipeToRefreshEnabled)
|
|
|
|
topProgressBar.show();
|
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
if (kind == Kind.HOME) {
|
|
|
|
TimelineRequestMode mode;
|
|
|
|
// allow getting old statuses/fallbacks for network only for for bottom loading
|
|
|
|
if (fetchEnd == FetchEnd.BOTTOM) {
|
|
|
|
mode = TimelineRequestMode.ANY;
|
|
|
|
} else {
|
|
|
|
mode = TimelineRequestMode.NETWORK;
|
2017-03-09 00:27:37 +01:00
|
|
|
}
|
2019-02-05 20:06:00 +01:00
|
|
|
timelineRepo.getStatuses(maxId, sinceId, sinceIdMinusOne, LOAD_AT_ONCE, mode)
|
2019-01-28 19:02:31 +01:00
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
|
|
|
.subscribe(
|
|
|
|
(result) -> onFetchTimelineSuccess(result, fetchEnd, pos),
|
|
|
|
(err) -> onFetchTimelineFailure(new Exception(err), fetchEnd, pos)
|
|
|
|
);
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
} else {
|
|
|
|
Callback<List<Status>> callback = new Callback<List<Status>>() {
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<List<Status>> call, @NonNull Response<List<Status>> response) {
|
|
|
|
if (response.isSuccessful()) {
|
2020-06-07 19:37:34 +02:00
|
|
|
@Nullable
|
|
|
|
String newNextId = extractNextId(response);
|
|
|
|
if (newNextId != null) {
|
|
|
|
// when we reach the bottom of the list, we won't have a new link. If
|
|
|
|
// we blindly write `null` here we will start loading from the top
|
|
|
|
// again.
|
|
|
|
nextId = newNextId;
|
|
|
|
}
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
onFetchTimelineSuccess(liftStatusList(response.body()), fetchEnd, pos);
|
|
|
|
} else {
|
|
|
|
onFetchTimelineFailure(new Exception(response.message()), fetchEnd, pos);
|
|
|
|
}
|
|
|
|
}
|
2017-03-09 00:27:37 +01:00
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<List<Status>> call, @NonNull Throwable t) {
|
|
|
|
onFetchTimelineFailure((Exception) t, fetchEnd, pos);
|
|
|
|
}
|
|
|
|
};
|
2017-03-09 00:27:37 +01:00
|
|
|
|
2020-05-15 22:10:29 +02:00
|
|
|
Call<List<Status>> listCall = getFetchCallByTimelineType(maxId, sinceId);
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
callList.add(listCall);
|
|
|
|
listCall.enqueue(callback);
|
|
|
|
}
|
2017-06-30 08:31:58 +02:00
|
|
|
}
|
|
|
|
|
2020-06-07 19:37:34 +02:00
|
|
|
@Nullable
|
|
|
|
private String extractNextId(Response<?> response) {
|
|
|
|
String linkHeader = response.headers().get("Link");
|
|
|
|
if (linkHeader == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
List<HttpHeaderLink> links = HttpHeaderLink.parse(linkHeader);
|
|
|
|
HttpHeaderLink nextHeader = HttpHeaderLink.findByRelationType(links, "next");
|
|
|
|
if (nextHeader == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Uri nextLink = nextHeader.uri;
|
|
|
|
if (nextLink == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return nextLink.getQueryParameter("max_id");
|
|
|
|
}
|
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
private void onFetchTimelineSuccess(List<Either<Placeholder, Status>> statuses,
|
2017-11-03 22:17:31 +01:00
|
|
|
FetchEnd fetchEnd, int pos) {
|
2018-05-27 10:22:12 +02:00
|
|
|
|
2017-11-06 16:19:15 +01:00
|
|
|
// We filled the hole (or reached the end) if the server returned less statuses than we
|
|
|
|
// we asked for.
|
2017-11-03 22:17:31 +01:00
|
|
|
boolean fullFetch = statuses.size() >= LOAD_AT_ONCE;
|
2017-06-30 08:31:58 +02:00
|
|
|
filterStatuses(statuses);
|
|
|
|
switch (fetchEnd) {
|
|
|
|
case TOP: {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
updateStatuses(statuses, fullFetch);
|
2017-11-03 22:17:31 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MIDDLE: {
|
2017-11-06 16:19:15 +01:00
|
|
|
replacePlaceholderWithStatuses(statuses, fullFetch, pos);
|
2017-01-27 01:34:32 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-06-30 08:31:58 +02:00
|
|
|
case BOTTOM: {
|
2018-05-27 10:22:12 +02:00
|
|
|
if (!this.statuses.isEmpty()
|
|
|
|
&& !this.statuses.get(this.statuses.size() - 1).isRight()) {
|
|
|
|
this.statuses.remove(this.statuses.size() - 1);
|
|
|
|
updateAdapter();
|
|
|
|
}
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
|
|
|
|
if (!statuses.isEmpty() && !statuses.get(statuses.size() - 1).isRight()) {
|
|
|
|
// Removing placeholder if it's the last one from the cache
|
|
|
|
statuses.remove(statuses.size() - 1);
|
|
|
|
}
|
2018-05-27 10:22:12 +02:00
|
|
|
int oldSize = this.statuses.size();
|
|
|
|
if (this.statuses.size() > 1) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
addItems(statuses);
|
2017-06-30 08:31:58 +02:00
|
|
|
} else {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
updateStatuses(statuses, fullFetch);
|
2017-06-30 08:31:58 +02:00
|
|
|
}
|
2018-05-27 10:22:12 +02:00
|
|
|
if (this.statuses.size() == oldSize) {
|
|
|
|
// This may be a brittle check but seems like it works
|
|
|
|
// Can we check it using headers somehow? Do all server support them?
|
|
|
|
didLoadEverythingBottom = true;
|
|
|
|
}
|
2017-02-21 03:32:10 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-01-07 23:24:02 +01:00
|
|
|
}
|
2019-05-15 12:43:16 +02:00
|
|
|
if (isAdded()) {
|
|
|
|
topProgressBar.hide();
|
|
|
|
updateBottomLoadingState(fetchEnd);
|
|
|
|
progressBar.setVisibility(View.GONE);
|
|
|
|
swipeRefreshLayout.setRefreshing(false);
|
|
|
|
swipeRefreshLayout.setEnabled(true);
|
|
|
|
if (this.statuses.size() == 0) {
|
|
|
|
this.showNothing();
|
|
|
|
} else {
|
|
|
|
this.statusView.setVisibility(View.GONE);
|
|
|
|
}
|
2018-05-27 10:22:12 +02:00
|
|
|
}
|
2017-06-30 08:31:58 +02:00
|
|
|
}
|
|
|
|
|
2017-11-03 22:17:31 +01:00
|
|
|
private void onFetchTimelineFailure(Exception exception, FetchEnd fetchEnd, int position) {
|
2018-08-17 04:53:38 +02:00
|
|
|
if (isAdded()) {
|
2018-07-08 10:16:19 +02:00
|
|
|
swipeRefreshLayout.setRefreshing(false);
|
2019-05-15 12:43:16 +02:00
|
|
|
topProgressBar.hide();
|
2018-07-08 10:16:19 +02:00
|
|
|
|
|
|
|
if (fetchEnd == FetchEnd.MIDDLE && !statuses.get(position).isRight()) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Placeholder placeholder = statuses.get(position).asLeftOrNull();
|
2018-07-08 10:16:19 +02:00
|
|
|
StatusViewData newViewData;
|
|
|
|
if (placeholder == null) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Status above = statuses.get(position - 1).asRight();
|
2019-01-31 19:03:34 +01:00
|
|
|
String newId = StringUtils.dec(above.getId());
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
placeholder = new Placeholder(newId);
|
2018-07-08 10:16:19 +02:00
|
|
|
}
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
newViewData = new StatusViewData.Placeholder(placeholder.getId(), false);
|
2018-07-08 10:16:19 +02:00
|
|
|
statuses.setPairedItem(position, newViewData);
|
|
|
|
updateAdapter();
|
2019-01-28 19:02:31 +01:00
|
|
|
} else if (this.statuses.isEmpty()) {
|
|
|
|
swipeRefreshLayout.setEnabled(false);
|
|
|
|
this.statusView.setVisibility(View.VISIBLE);
|
|
|
|
if (exception instanceof IOException) {
|
|
|
|
this.statusView.setup(R.drawable.elephant_offline, R.string.error_network, __ -> {
|
|
|
|
this.progressBar.setVisibility(View.VISIBLE);
|
|
|
|
this.onRefresh();
|
|
|
|
return Unit.INSTANCE;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.statusView.setup(R.drawable.elephant_error, R.string.error_generic, __ -> {
|
|
|
|
this.progressBar.setVisibility(View.VISIBLE);
|
|
|
|
this.onRefresh();
|
|
|
|
return Unit.INSTANCE;
|
|
|
|
});
|
|
|
|
}
|
2018-05-27 10:22:12 +02:00
|
|
|
}
|
2017-11-03 22:17:31 +01:00
|
|
|
|
2018-07-08 10:16:19 +02:00
|
|
|
Log.e(TAG, "Fetch Failure: " + exception.getMessage());
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
updateBottomLoadingState(fetchEnd);
|
2018-07-08 10:16:19 +02:00
|
|
|
progressBar.setVisibility(View.GONE);
|
|
|
|
}
|
2017-01-07 23:24:02 +01:00
|
|
|
}
|
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
private void updateBottomLoadingState(FetchEnd fetchEnd) {
|
2019-11-19 10:15:32 +01:00
|
|
|
if (fetchEnd == FetchEnd.BOTTOM) {
|
|
|
|
bottomLoading = false;
|
2017-01-07 23:24:02 +01:00
|
|
|
}
|
2017-02-21 23:55:37 +01:00
|
|
|
}
|
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
private void filterStatuses(List<Either<Placeholder, Status>> statuses) {
|
|
|
|
Iterator<Either<Placeholder, Status>> it = statuses.iterator();
|
2017-04-15 20:23:07 +02:00
|
|
|
while (it.hasNext()) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Status status = it.next().asRightOrNull();
|
|
|
|
if (status != null
|
|
|
|
&& ((status.getInReplyToId() != null && filterRemoveReplies)
|
2018-04-05 22:58:44 +02:00
|
|
|
|| (status.getReblog() != null && filterRemoveReblogs)
|
2020-10-13 18:30:39 +02:00
|
|
|
|| shouldFilterStatus(status.getActionableStatus()))) {
|
2017-04-15 20:23:07 +02:00
|
|
|
it.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-12 21:54:52 +02:00
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
private void updateStatuses(List<Either<Placeholder, Status>> newStatuses, boolean fullFetch) {
|
2017-07-14 03:39:17 +02:00
|
|
|
if (ListUtils.isEmpty(newStatuses)) {
|
2019-07-16 19:51:44 +02:00
|
|
|
updateAdapter();
|
2017-07-12 21:54:52 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-11-06 16:19:15 +01:00
|
|
|
|
2017-07-12 21:54:52 +02:00
|
|
|
if (statuses.isEmpty()) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
statuses.addAll(newStatuses);
|
2017-07-12 21:54:52 +02:00
|
|
|
} else {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Either<Placeholder, Status> lastOfNew = newStatuses.get(newStatuses.size() - 1);
|
2017-07-12 21:54:52 +02:00
|
|
|
int index = statuses.indexOf(lastOfNew);
|
2017-11-03 22:17:31 +01:00
|
|
|
|
2019-03-30 15:18:16 +01:00
|
|
|
if (index >= 0) {
|
|
|
|
statuses.subList(0, index).clear();
|
2017-07-12 21:54:52 +02:00
|
|
|
}
|
2019-03-30 15:18:16 +01:00
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
int newIndex = newStatuses.indexOf(statuses.get(0));
|
2017-07-12 21:54:52 +02:00
|
|
|
if (newIndex == -1) {
|
2017-11-06 16:19:15 +01:00
|
|
|
if (index == -1 && fullFetch) {
|
2019-01-31 19:03:34 +01:00
|
|
|
String placeholderId = StringUtils.inc(
|
|
|
|
CollectionsKt.last(newStatuses, Either::isRight).asRight().getId());
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
newStatuses.add(new Either.Left<>(new Placeholder(placeholderId)));
|
2017-11-03 22:17:31 +01:00
|
|
|
}
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
statuses.addAll(0, newStatuses);
|
2017-07-12 21:54:52 +02:00
|
|
|
} else {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
statuses.addAll(0, newStatuses.subList(0, newIndex));
|
2017-07-12 21:54:52 +02:00
|
|
|
}
|
|
|
|
}
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
// Remove all consecutive placeholders
|
|
|
|
removeConsecutivePlaceholders();
|
2018-05-27 10:22:12 +02:00
|
|
|
updateAdapter();
|
2017-07-12 21:54:52 +02:00
|
|
|
}
|
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
private void removeConsecutivePlaceholders() {
|
|
|
|
for (int i = 0; i < statuses.size() - 1; i++) {
|
2019-06-24 21:43:14 +02:00
|
|
|
if (statuses.get(i).isLeft() && statuses.get(i + 1).isLeft()) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
statuses.remove(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addItems(List<Either<Placeholder, Status>> newStatuses) {
|
2017-07-14 23:09:44 +02:00
|
|
|
if (ListUtils.isEmpty(newStatuses)) {
|
|
|
|
return;
|
|
|
|
}
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Either<Placeholder, Status> last = null;
|
2018-05-27 10:22:12 +02:00
|
|
|
for (int i = statuses.size() - 1; i >= 0; i--) {
|
|
|
|
if (statuses.get(i).isRight()) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
last = statuses.get(i);
|
2018-05-27 10:22:12 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-11-06 16:19:15 +01:00
|
|
|
// I was about to replace findStatus with indexOf but it is incorrect to compare value
|
|
|
|
// types by ID anyway and we should change equals() for Status, I think, so this makes sense
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
if (last != null && !newStatuses.contains(last)) {
|
|
|
|
statuses.addAll(newStatuses);
|
|
|
|
removeConsecutivePlaceholders();
|
2018-05-27 10:22:12 +02:00
|
|
|
updateAdapter();
|
2017-07-12 21:54:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
/**
|
|
|
|
* For certain requests we don't want to see placeholders, they will be removed some other way
|
|
|
|
*/
|
|
|
|
private void clearPlaceholdersForResponse(List<Either<Placeholder, Status>> statuses) {
|
2019-06-24 21:43:14 +02:00
|
|
|
CollectionsKt.removeAll(statuses, Either::isLeft);
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void replacePlaceholderWithStatuses(List<Either<Placeholder, Status>> newStatuses,
|
|
|
|
boolean fullFetch, int pos) {
|
|
|
|
Either<Placeholder, Status> placeholder = statuses.get(pos);
|
2019-06-24 21:43:14 +02:00
|
|
|
if (placeholder.isLeft()) {
|
2017-11-03 22:17:31 +01:00
|
|
|
statuses.remove(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ListUtils.isEmpty(newStatuses)) {
|
2018-05-27 10:22:12 +02:00
|
|
|
updateAdapter();
|
2017-11-03 22:17:31 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-06 16:19:15 +01:00
|
|
|
if (fullFetch) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
newStatuses.add(placeholder);
|
2017-11-03 22:17:31 +01:00
|
|
|
}
|
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
statuses.addAll(pos, newStatuses);
|
|
|
|
removeConsecutivePlaceholders();
|
2017-11-03 22:17:31 +01:00
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
updateAdapter();
|
2017-11-03 22:17:31 +01:00
|
|
|
|
2017-07-12 21:54:52 +02:00
|
|
|
}
|
2017-11-06 16:19:15 +01:00
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
private int findStatusOrReblogPositionById(@NonNull String statusId) {
|
|
|
|
for (int i = 0; i < statuses.size(); i++) {
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Status status = statuses.get(i).asRightOrNull();
|
2018-05-27 10:22:12 +02:00
|
|
|
if (status != null
|
|
|
|
&& (statusId.equals(status.getId())
|
|
|
|
|| (status.getReblog() != null
|
|
|
|
&& statusId.equals(status.getReblog().getId())))) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-04-21 08:24:06 +02:00
|
|
|
private final Function1<Status, Either<Placeholder, Status>> statusLifter =
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Either.Right::new;
|
2017-11-06 16:19:15 +01:00
|
|
|
|
2019-11-19 10:15:32 +01:00
|
|
|
@Nullable
|
|
|
|
private Pair<StatusViewData.Concrete, Integer>
|
2017-11-06 16:19:15 +01:00
|
|
|
findStatusAndPosition(int position, Status status) {
|
|
|
|
StatusViewData.Concrete statusToUpdate;
|
|
|
|
int positionToUpdate;
|
|
|
|
StatusViewData someOldViewData = statuses.getPairedItem(position);
|
|
|
|
|
|
|
|
// Unlikely, but data could change between the request and response
|
|
|
|
if ((someOldViewData instanceof StatusViewData.Placeholder) ||
|
2018-03-03 13:24:03 +01:00
|
|
|
!((StatusViewData.Concrete) someOldViewData).getId().equals(status.getId())) {
|
2017-11-06 16:19:15 +01:00
|
|
|
// try to find the status we need to update
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
int foundPos = statuses.indexOf(new Either.Right<>(status));
|
2017-11-06 16:19:15 +01:00
|
|
|
if (foundPos < 0) return null; // okay, it's hopeless, give up
|
|
|
|
statusToUpdate = ((StatusViewData.Concrete)
|
|
|
|
statuses.getPairedItem(foundPos));
|
|
|
|
positionToUpdate = position;
|
|
|
|
} else {
|
|
|
|
statusToUpdate = (StatusViewData.Concrete) someOldViewData;
|
|
|
|
positionToUpdate = position;
|
|
|
|
}
|
|
|
|
return new Pair<>(statusToUpdate, positionToUpdate);
|
|
|
|
}
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
private void handleReblogEvent(@NonNull ReblogEvent reblogEvent) {
|
|
|
|
int pos = findStatusOrReblogPositionById(reblogEvent.getStatusId());
|
|
|
|
if (pos < 0) return;
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Status status = statuses.get(pos).asRight();
|
2018-05-27 10:22:12 +02:00
|
|
|
setRebloggedForStatus(pos, status, reblogEvent.getReblog());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleFavEvent(@NonNull FavoriteEvent favEvent) {
|
|
|
|
int pos = findStatusOrReblogPositionById(favEvent.getStatusId());
|
|
|
|
if (pos < 0) return;
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
Status status = statuses.get(pos).asRight();
|
2018-05-27 10:22:12 +02:00
|
|
|
setFavouriteForStatus(pos, status, favEvent.getFavourite());
|
|
|
|
}
|
|
|
|
|
2019-11-19 10:15:32 +01:00
|
|
|
private void handleBookmarkEvent(@NonNull BookmarkEvent bookmarkEvent) {
|
|
|
|
int pos = findStatusOrReblogPositionById(bookmarkEvent.getStatusId());
|
|
|
|
if (pos < 0) return;
|
|
|
|
Status status = statuses.get(pos).asRight();
|
|
|
|
setBookmarkForStatus(pos, status, bookmarkEvent.getBookmark());
|
|
|
|
}
|
|
|
|
|
2020-03-24 21:06:04 +01:00
|
|
|
private void handleMuteConversationEvent(@NonNull MuteConversationEvent event) {
|
|
|
|
fullyRefresh();
|
|
|
|
}
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
private void handleStatusComposeEvent(@NonNull Status status) {
|
|
|
|
switch (kind) {
|
|
|
|
case HOME:
|
|
|
|
case PUBLIC_FEDERATED:
|
|
|
|
case PUBLIC_LOCAL:
|
|
|
|
break;
|
|
|
|
case USER:
|
2018-06-18 13:26:18 +02:00
|
|
|
case USER_WITH_REPLIES:
|
2020-05-15 22:10:29 +02:00
|
|
|
if (status.getAccount().getId().equals(id)) {
|
2018-05-27 10:22:12 +02:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case TAG:
|
|
|
|
case FAVOURITES:
|
|
|
|
case LIST:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
onRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<Either<Placeholder, Status>> liftStatusList(List<Status> list) {
|
2019-04-21 08:24:06 +02:00
|
|
|
return CollectionsKt.map(list, statusLifter);
|
2017-11-06 16:19:15 +01:00
|
|
|
}
|
2018-05-27 10:22:12 +02:00
|
|
|
|
|
|
|
private void updateAdapter() {
|
|
|
|
differ.submitList(statuses.getPairedCopy());
|
|
|
|
}
|
|
|
|
|
|
|
|
private final ListUpdateCallback listUpdateCallback = new ListUpdateCallback() {
|
|
|
|
@Override
|
|
|
|
public void onInserted(int position, int count) {
|
2018-08-17 04:53:38 +02:00
|
|
|
if (isAdded()) {
|
2018-07-08 10:16:19 +02:00
|
|
|
adapter.notifyItemRangeInserted(position, count);
|
|
|
|
Context context = getContext();
|
2020-08-21 18:51:05 +02:00
|
|
|
// scroll up when new items at the top are loaded while being in the first position
|
|
|
|
// https://github.com/tuskyapp/Tusky/pull/1905#issuecomment-677819724
|
|
|
|
if (position == 0 && context != null && adapter.getItemCount() != count) {
|
2019-05-15 12:43:16 +02:00
|
|
|
if (isSwipeToRefreshEnabled)
|
|
|
|
recyclerView.scrollBy(0, Utils.dpToPx(context, -30));
|
|
|
|
else
|
|
|
|
recyclerView.scrollToPosition(0);
|
2018-07-08 10:16:19 +02:00
|
|
|
}
|
2018-05-27 10:22:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRemoved(int position, int count) {
|
|
|
|
adapter.notifyItemRangeRemoved(position, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMoved(int fromPosition, int toPosition) {
|
|
|
|
adapter.notifyItemMoved(fromPosition, toPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChanged(int position, int count, Object payload) {
|
|
|
|
adapter.notifyItemRangeChanged(position, count, payload);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
private final AsyncListDiffer<StatusViewData>
|
|
|
|
differ = new AsyncListDiffer<>(listUpdateCallback,
|
|
|
|
new AsyncDifferConfig.Builder<>(diffCallback).build());
|
|
|
|
|
|
|
|
private final TimelineAdapter.AdapterDataSource<StatusViewData> dataSource =
|
|
|
|
new TimelineAdapter.AdapterDataSource<StatusViewData>() {
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return differ.getCurrentList().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StatusViewData getItemAt(int pos) {
|
|
|
|
return differ.getCurrentList().get(pos);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private static final DiffUtil.ItemCallback<StatusViewData> diffCallback
|
|
|
|
= new DiffUtil.ItemCallback<StatusViewData>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areItemsTheSame(StatusViewData oldItem, StatusViewData newItem) {
|
|
|
|
return oldItem.getViewDataId() == newItem.getViewDataId();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
public boolean areContentsTheSame(StatusViewData oldItem, @NonNull StatusViewData newItem) {
|
2019-03-16 14:38:29 +01:00
|
|
|
return false; //Items are different always. It allows to refresh timestamp on every view holder update
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public Object getChangePayload(@NonNull StatusViewData oldItem, @NonNull StatusViewData newItem) {
|
2019-04-08 15:40:16 +02:00
|
|
|
if (oldItem.deepEquals(newItem)) {
|
2019-03-16 14:38:29 +01:00
|
|
|
//If items are equal - update timestamp only
|
2019-09-17 18:44:33 +02:00
|
|
|
return Collections.singletonList(StatusBaseViewHolder.Key.KEY_CREATED);
|
2019-04-08 15:40:16 +02:00
|
|
|
} else
|
2019-03-16 14:38:29 +01:00
|
|
|
// If items are different - update a whole view holder
|
|
|
|
return null;
|
2018-05-27 10:22:12 +02:00
|
|
|
}
|
|
|
|
};
|
2019-03-16 14:38:29 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
startUpdateTimestamp();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start to update adapter every minute to refresh timestamp
|
|
|
|
* If setting absoluteTimeView is false
|
|
|
|
* Auto dispose observable on pause
|
|
|
|
*/
|
|
|
|
private void startUpdateTimestamp() {
|
|
|
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
|
|
|
boolean useAbsoluteTime = preferences.getBoolean("absoluteTimeView", false);
|
|
|
|
if (!useAbsoluteTime) {
|
|
|
|
Observable.interval(1, TimeUnit.MINUTES)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_PAUSE)))
|
|
|
|
.subscribe(
|
|
|
|
interval -> updateAdapter()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-04-08 15:40:16 +02:00
|
|
|
@Override
|
|
|
|
public void onReselect() {
|
|
|
|
jumpToTop();
|
|
|
|
}
|
2019-05-15 12:43:16 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void refreshContent() {
|
|
|
|
if (isAdded())
|
|
|
|
onRefresh();
|
|
|
|
else
|
|
|
|
isNeedRefresh = true;
|
|
|
|
}
|
2017-01-07 23:24:02 +01:00
|
|
|
}
|