2017-01-23 06:19:30 +01:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
2017-04-10 02:12:31 +02:00
|
|
|
* This file is a part of Tusky.
|
2017-01-23 06:19:30 +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-23 06:19:30 +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-23 06:19:30 +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-23 06:19:30 +01:00
|
|
|
|
2017-05-05 00:55:34 +02:00
|
|
|
package com.keylesspalace.tusky.fragment;
|
2017-01-23 06:19:30 +01:00
|
|
|
|
|
|
|
import android.content.Context;
|
2018-12-27 09:48:24 +01:00
|
|
|
import android.content.Intent;
|
2017-06-26 11:15:47 +02:00
|
|
|
import android.content.SharedPreferences;
|
2017-01-23 06:19:30 +01:00
|
|
|
import android.os.Bundle;
|
2018-05-08 19:15:10 +02:00
|
|
|
import android.text.TextUtils;
|
2017-05-23 21:34:31 +02:00
|
|
|
import android.util.Log;
|
2017-01-23 06:19:30 +01:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
2019-09-08 10:30:59 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.arch.core.util.Function;
|
|
|
|
import androidx.core.util.Pair;
|
|
|
|
import androidx.lifecycle.Lifecycle;
|
2019-10-22 21:18:20 +02:00
|
|
|
import androidx.preference.PreferenceManager;
|
2019-09-08 10:30:59 +02:00
|
|
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import androidx.recyclerview.widget.SimpleItemAnimator;
|
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
|
|
|
2019-03-04 19:24:27 +01:00
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
2018-12-27 09:48:24 +01:00
|
|
|
import com.keylesspalace.tusky.AccountListActivity;
|
|
|
|
import com.keylesspalace.tusky.BaseActivity;
|
2017-07-12 21:54:52 +02:00
|
|
|
import com.keylesspalace.tusky.BuildConfig;
|
|
|
|
import com.keylesspalace.tusky.R;
|
2018-04-28 16:17:01 +02:00
|
|
|
import com.keylesspalace.tusky.ViewThreadActivity;
|
2017-05-05 00:55:34 +02:00
|
|
|
import com.keylesspalace.tusky.adapter.ThreadAdapter;
|
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-03-04 19:24:27 +01:00
|
|
|
import com.keylesspalace.tusky.appstore.EventHub;
|
2018-05-27 10:22:12 +02:00
|
|
|
import com.keylesspalace.tusky.appstore.FavoriteEvent;
|
|
|
|
import com.keylesspalace.tusky.appstore.ReblogEvent;
|
|
|
|
import com.keylesspalace.tusky.appstore.StatusComposedEvent;
|
|
|
|
import com.keylesspalace.tusky.appstore.StatusDeletedEvent;
|
2018-03-27 19:47:00 +02:00
|
|
|
import com.keylesspalace.tusky.di.Injectable;
|
2019-07-08 12:57:53 +02: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-05-05 00:55:34 +02:00
|
|
|
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
2018-05-27 10:22:12 +02:00
|
|
|
import com.keylesspalace.tusky.network.MastodonApi;
|
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;
|
2019-03-04 19:24:27 +01:00
|
|
|
import com.keylesspalace.tusky.util.ListStatusAccessibilityDelegate;
|
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;
|
2017-07-12 21:54:52 +02:00
|
|
|
import com.keylesspalace.tusky.util.ViewDataUtils;
|
2017-05-29 12:14:09 +02:00
|
|
|
import com.keylesspalace.tusky.view.ConversationLineItemDecoration;
|
2017-07-12 21:54:52 +02:00
|
|
|
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
|
|
|
|
2019-07-08 12:57:53 +02:00
|
|
|
import java.util.ArrayList;
|
2017-07-12 21:54:52 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
2017-01-23 06:19:30 +01:00
|
|
|
|
2018-03-27 19:47:00 +02:00
|
|
|
import javax.inject.Inject;
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
2017-03-09 00:27:37 +01:00
|
|
|
|
2018-12-17 15:25:35 +01:00
|
|
|
import static com.uber.autodispose.AutoDispose.autoDisposable;
|
|
|
|
import static com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider.from;
|
2018-05-27 10:22:12 +02:00
|
|
|
|
2018-04-28 16:17:01 +02:00
|
|
|
public final class ViewThreadFragment extends SFragment implements
|
2018-03-27 19:47:00 +02:00
|
|
|
SwipeRefreshLayout.OnRefreshListener, StatusActionListener, Injectable {
|
2017-03-15 21:38:19 +01:00
|
|
|
private static final String TAG = "ViewThreadFragment";
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
@Inject
|
|
|
|
public MastodonApi mastodonApi;
|
|
|
|
@Inject
|
|
|
|
public EventHub eventHub;
|
2018-03-27 19:47:00 +02:00
|
|
|
|
2017-04-15 12:28:22 +02:00
|
|
|
private SwipeRefreshLayout swipeRefreshLayout;
|
2017-01-23 06:19:30 +01:00
|
|
|
private RecyclerView recyclerView;
|
|
|
|
private ThreadAdapter adapter;
|
2017-03-03 01:25:35 +01:00
|
|
|
private String thisThreadsStatusId;
|
2017-11-30 20:12:09 +01:00
|
|
|
private boolean alwaysShowSensitiveMedia;
|
2019-07-28 19:59:52 +02:00
|
|
|
private boolean alwaysOpenSpoiler;
|
2017-01-23 06:19:30 +01:00
|
|
|
|
2017-10-18 00:20:26 +02:00
|
|
|
private int statusIndex = 0;
|
2017-07-12 21:54:52 +02:00
|
|
|
|
2018-04-28 16:17:01 +02:00
|
|
|
private final PairedList<Status, StatusViewData.Concrete> statuses =
|
2017-11-30 20:12:09 +01:00
|
|
|
new PairedList<>(new Function<Status, StatusViewData.Concrete>() {
|
|
|
|
@Override
|
|
|
|
public StatusViewData.Concrete apply(Status input) {
|
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(
|
|
|
|
input,
|
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-30 20:12:09 +01:00
|
|
|
}
|
|
|
|
});
|
2017-07-12 21:54:52 +02:00
|
|
|
|
2017-01-23 06:19:30 +01:00
|
|
|
public static ViewThreadFragment newInstance(String id) {
|
2019-06-02 21:23:18 +02:00
|
|
|
Bundle arguments = new Bundle(1);
|
2017-01-23 06:19:30 +01:00
|
|
|
ViewThreadFragment fragment = new ViewThreadFragment();
|
|
|
|
arguments.putString("id", id);
|
|
|
|
fragment.setArguments(arguments);
|
|
|
|
return fragment;
|
|
|
|
}
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2018-07-08 19:21:19 +02:00
|
|
|
thisThreadsStatusId = getArguments().getString("id");
|
2019-12-30 21:37:20 +01:00
|
|
|
SharedPreferences preferences =
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(getActivity());
|
2020-12-23 19:13:37 +01:00
|
|
|
|
2019-12-30 21:37:20 +01:00
|
|
|
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),
|
2021-02-06 08:14:51 +01:00
|
|
|
preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false),
|
|
|
|
preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
|
2019-12-30 21:37:20 +01:00
|
|
|
);
|
|
|
|
adapter = new ThreadAdapter(statusDisplayOptions, this);
|
2018-05-27 10:22:12 +02:00
|
|
|
}
|
|
|
|
|
2017-01-23 06:19:30 +01:00
|
|
|
@Override
|
2017-11-30 20:12:09 +01:00
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
2017-11-06 16:19:15 +01:00
|
|
|
@Nullable Bundle savedInstanceState) {
|
2017-01-23 06:19:30 +01:00
|
|
|
View rootView = inflater.inflate(R.layout.fragment_view_thread, container, false);
|
|
|
|
|
|
|
|
Context context = getContext();
|
2019-02-12 19:22:37 +01:00
|
|
|
swipeRefreshLayout = rootView.findViewById(R.id.swipeRefreshLayout);
|
2017-04-15 12:28:22 +02:00
|
|
|
swipeRefreshLayout.setOnRefreshListener(this);
|
2018-12-17 15:25:35 +01:00
|
|
|
swipeRefreshLayout.setColorSchemeResources(R.color.tusky_blue);
|
2017-04-15 12:28:22 +02:00
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
recyclerView = rootView.findViewById(R.id.recyclerView);
|
2017-01-23 06:19:30 +01:00
|
|
|
recyclerView.setHasFixedSize(true);
|
|
|
|
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
|
|
|
|
recyclerView.setLayoutManager(layoutManager);
|
2019-03-04 19:24:27 +01:00
|
|
|
recyclerView.setAccessibilityDelegateCompat(
|
2019-04-07 16:32:58 +02:00
|
|
|
new ListStatusAccessibilityDelegate(recyclerView, this, statuses::getPairedItemOrNull));
|
2017-01-23 06:19:30 +01:00
|
|
|
DividerItemDecoration divider = new DividerItemDecoration(
|
|
|
|
context, layoutManager.getOrientation());
|
|
|
|
recyclerView.addItemDecoration(divider);
|
2017-11-30 20:12:09 +01:00
|
|
|
|
2019-06-02 21:23:18 +02:00
|
|
|
recyclerView.addItemDecoration(new ConversationLineItemDecoration(context));
|
2018-11-12 21:09:39 +01:00
|
|
|
alwaysShowSensitiveMedia = accountManager.getActiveAccount().getAlwaysShowSensitiveMedia();
|
2019-07-28 19:59:52 +02:00
|
|
|
alwaysOpenSpoiler = accountManager.getActiveAccount().getAlwaysOpenSpoiler();
|
2019-07-08 12:57:53 +02:00
|
|
|
reloadFilters(false);
|
2019-06-02 21:23:18 +02:00
|
|
|
|
2017-01-23 06:19:30 +01:00
|
|
|
recyclerView.setAdapter(adapter);
|
|
|
|
|
2017-07-21 03:17:36 +02:00
|
|
|
statuses.clear();
|
2017-01-23 06:19:30 +01:00
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
|
2017-06-06 23:15:29 +02:00
|
|
|
|
2017-01-23 06:19:30 +01:00
|
|
|
return rootView;
|
|
|
|
}
|
|
|
|
|
2017-06-06 23:15:29 +02:00
|
|
|
|
2017-05-03 22:28:46 +02:00
|
|
|
@Override
|
|
|
|
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
onRefresh();
|
2018-07-12 21:21:53 +02:00
|
|
|
|
|
|
|
eventHub.getEvents()
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
|
|
|
.subscribe(event -> {
|
|
|
|
if (event instanceof FavoriteEvent) {
|
|
|
|
handleFavEvent((FavoriteEvent) event);
|
|
|
|
} else if (event instanceof ReblogEvent) {
|
|
|
|
handleReblogEvent((ReblogEvent) event);
|
2019-11-19 10:15:32 +01:00
|
|
|
} else if (event instanceof BookmarkEvent) {
|
|
|
|
handleBookmarkEvent((BookmarkEvent) event);
|
2018-07-12 21:21:53 +02:00
|
|
|
} else if (event instanceof BlockEvent) {
|
|
|
|
removeAllByAccountId(((BlockEvent) event).getAccountId());
|
|
|
|
} else if (event instanceof StatusComposedEvent) {
|
|
|
|
handleStatusComposedEvent((StatusComposedEvent) event);
|
|
|
|
} else if (event instanceof StatusDeletedEvent) {
|
|
|
|
handleStatusDeletedEvent((StatusDeletedEvent) event);
|
|
|
|
}
|
|
|
|
});
|
2017-05-03 22:28:46 +02:00
|
|
|
}
|
|
|
|
|
2018-04-28 16:17:01 +02:00
|
|
|
public void onRevealPressed() {
|
|
|
|
boolean allExpanded = allExpanded();
|
|
|
|
for (int i = 0; i < statuses.size(); i++) {
|
|
|
|
StatusViewData.Concrete newViewData =
|
|
|
|
new StatusViewData.Concrete.Builder(statuses.getPairedItem(i))
|
|
|
|
.setIsExpanded(!allExpanded)
|
|
|
|
.createStatusViewData();
|
|
|
|
statuses.setPairedItem(i, newViewData);
|
|
|
|
}
|
|
|
|
adapter.setStatuses(statuses.getPairedCopy());
|
2020-01-29 19:16:12 +01:00
|
|
|
updateRevealIcon();
|
2018-04-28 16:17:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean allExpanded() {
|
|
|
|
boolean allExpanded = true;
|
|
|
|
for (int i = 0; i < statuses.size(); i++) {
|
|
|
|
if (!statuses.getPairedItem(i).isExpanded()) {
|
|
|
|
allExpanded = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return allExpanded;
|
|
|
|
}
|
|
|
|
|
2017-06-30 08:31:58 +02:00
|
|
|
@Override
|
|
|
|
public void onRefresh() {
|
|
|
|
sendStatusRequest(thisThreadsStatusId);
|
|
|
|
sendThreadRequest(thisThreadsStatusId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReply(int position) {
|
2017-07-12 21:54:52 +02:00
|
|
|
super.reply(statuses.get(position));
|
2017-06-30 08:31:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-07-12 21:54:52 +02:00
|
|
|
public void onReblog(final boolean reblog, final int position) {
|
|
|
|
final Status status = statuses.get(position);
|
2018-12-27 09:48:24 +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
|
|
|
timelineCases.reblog(statuses.get(position), reblog)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this)))
|
|
|
|
.subscribe(
|
|
|
|
(newStatus) -> updateStatus(position, newStatus),
|
2019-11-19 10:15:32 +01:00
|
|
|
(t) -> Log.d(TAG,
|
2019-06-02 21:23:18 +02:00
|
|
|
"Failed to reblog status: " + status.getId(), t)
|
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-30 08:31:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-07-12 21:54:52 +02:00
|
|
|
public void onFavourite(final boolean favourite, final int position) {
|
|
|
|
final Status status = statuses.get(position);
|
2018-12-27 09:48:24 +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
|
|
|
timelineCases.favourite(statuses.get(position), favourite)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this)))
|
|
|
|
.subscribe(
|
|
|
|
(newStatus) -> updateStatus(position, newStatus),
|
2019-11-19 10:15:32 +01:00
|
|
|
(t) -> Log.d(TAG,
|
2019-06-02 21:23:18 +02:00
|
|
|
"Failed to favourite status: " + status.getId(), t)
|
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-30 08:31:58 +02:00
|
|
|
}
|
|
|
|
|
2019-11-19 10:15:32 +01:00
|
|
|
@Override
|
|
|
|
public void onBookmark(final boolean bookmark, final int position) {
|
|
|
|
final Status status = statuses.get(position);
|
|
|
|
|
|
|
|
timelineCases.bookmark(statuses.get(position), bookmark)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this)))
|
|
|
|
.subscribe(
|
|
|
|
(newStatus) -> updateStatus(position, newStatus),
|
|
|
|
(t) -> Log.d(TAG,
|
|
|
|
"Failed to bookmark status: " + status.getId(), t)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-12-27 09:48:24 +01:00
|
|
|
private void updateStatus(int position, Status status) {
|
2019-03-04 19:24:27 +01:00
|
|
|
if (position >= 0 && position < statuses.size()) {
|
2018-05-27 10:22:12 +02:00
|
|
|
|
2019-02-16 15:53:56 +01:00
|
|
|
Status actionableStatus = status.getActionableStatus();
|
|
|
|
|
2019-02-16 14:35:06 +01:00
|
|
|
StatusViewData.Concrete viewData = new StatusViewData.Builder(statuses.getPairedItem(position))
|
2019-02-16 15:53:56 +01:00
|
|
|
.setReblogged(actionableStatus.getReblogged())
|
|
|
|
.setReblogsCount(actionableStatus.getReblogsCount())
|
|
|
|
.setFavourited(actionableStatus.getFavourited())
|
2019-11-19 10:15:32 +01:00
|
|
|
.setBookmarked(actionableStatus.getBookmarked())
|
2019-02-16 15:53:56 +01:00
|
|
|
.setFavouritesCount(actionableStatus.getFavouritesCount())
|
2019-02-16 14:35:06 +01:00
|
|
|
.createStatusViewData();
|
|
|
|
statuses.setPairedItem(position, viewData);
|
|
|
|
|
|
|
|
adapter.setItem(position, viewData, true);
|
2018-05-27 10:22:12 +02:00
|
|
|
|
2018-12-27 09:48:24 +01:00
|
|
|
}
|
2018-05-27 10:22:12 +02:00
|
|
|
}
|
|
|
|
|
2017-06-30 08:31:58 +02:00
|
|
|
@Override
|
2019-02-12 19:22:37 +01:00
|
|
|
public void onMore(@NonNull View view, int position) {
|
2017-07-14 03:31:31 +02:00
|
|
|
super.more(statuses.get(position), view, position);
|
2017-06-30 08:31:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-12 19:22:37 +01:00
|
|
|
public void onViewMedia(int position, int attachmentIndex, @NonNull View view) {
|
2018-05-10 20:13:25 +02:00
|
|
|
Status status = statuses.get(position);
|
|
|
|
super.viewMedia(attachmentIndex, status, view);
|
2017-06-30 08:31:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onViewThread(int position) {
|
2017-07-12 21:54:52 +02:00
|
|
|
Status status = statuses.get(position);
|
2018-03-03 13:24:03 +01:00
|
|
|
if (thisThreadsStatusId.equals(status.getId())) {
|
2017-06-30 08:31:58 +02:00
|
|
|
// If already viewing this thread, don't reopen it.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.viewThread(status);
|
|
|
|
}
|
|
|
|
|
2017-06-28 10:10:56 +02:00
|
|
|
@Override
|
|
|
|
public void onOpenReblog(int position) {
|
|
|
|
// there should be no reblogs in the thread but let's implement it to be sure
|
2017-07-12 21:54:52 +02:00
|
|
|
super.openReblog(statuses.get(position));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onExpandedChange(boolean expanded, int position) {
|
2017-11-06 16:19:15 +01:00
|
|
|
StatusViewData.Concrete newViewData =
|
|
|
|
new StatusViewData.Builder(statuses.getPairedItem(position))
|
|
|
|
.setIsExpanded(expanded)
|
|
|
|
.createStatusViewData();
|
2017-07-12 21:54:52 +02:00
|
|
|
statuses.setPairedItem(position, newViewData);
|
2020-02-14 19:04:14 +01:00
|
|
|
adapter.setItem(position, newViewData, true);
|
2018-04-28 16:17:01 +02:00
|
|
|
updateRevealIcon();
|
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.Concrete newViewData =
|
|
|
|
new StatusViewData.Builder(statuses.getPairedItem(position))
|
|
|
|
.setIsShowingSensitiveContent(isShowing)
|
|
|
|
.createStatusViewData();
|
2017-07-12 21:54:52 +02:00
|
|
|
statuses.setPairedItem(position, newViewData);
|
2019-09-08 10:30:59 +02:00
|
|
|
adapter.setItem(position, newViewData, true);
|
2017-06-28 10:10:56 +02:00
|
|
|
}
|
|
|
|
|
2017-11-03 22:17:31 +01:00
|
|
|
@Override
|
2018-12-27 09:48:24 +01:00
|
|
|
public void onLoadMore(int position) {
|
2017-11-03 22:17:31 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-27 09:48:24 +01:00
|
|
|
@Override
|
|
|
|
public void onShowReblogs(int position) {
|
|
|
|
String statusId = statuses.get(position).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).getId();
|
|
|
|
Intent intent = AccountListActivity.newIntent(getContext(), AccountListActivity.Type.FAVOURITED, statusId);
|
|
|
|
((BaseActivity) getActivity()).startActivityWithSlideInAnimation(intent);
|
|
|
|
}
|
|
|
|
|
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.Concrete status = statuses.getPairedItem(position);
|
|
|
|
if (status == null) {
|
|
|
|
// 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 null instead at position: %d of %d",
|
|
|
|
position,
|
|
|
|
statuses.size() - 1
|
|
|
|
));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusViewData.Concrete updatedStatus = new StatusViewData.Builder(status)
|
|
|
|
.setCollapsed(isCollapsed)
|
|
|
|
.createStatusViewData();
|
|
|
|
statuses.setPairedItem(position, updatedStatus);
|
|
|
|
recyclerView.post(() -> adapter.setItem(position, updatedStatus, true));
|
|
|
|
}
|
|
|
|
|
2017-06-30 08:31:58 +02:00
|
|
|
@Override
|
|
|
|
public void onViewTag(String tag) {
|
|
|
|
super.viewTag(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onViewAccount(String id) {
|
|
|
|
super.viewAccount(id);
|
|
|
|
}
|
|
|
|
|
2017-07-12 21:54:52 +02:00
|
|
|
@Override
|
|
|
|
public void removeItem(int position) {
|
2017-11-06 16:19:15 +01:00
|
|
|
if (position == statusIndex) {
|
2017-10-24 23:33:05 +02:00
|
|
|
//the status got removed, close the activity
|
|
|
|
getActivity().finish();
|
|
|
|
}
|
2017-07-12 21:54:52 +02:00
|
|
|
statuses.remove(position);
|
|
|
|
adapter.setStatuses(statuses.getPairedCopy());
|
|
|
|
}
|
|
|
|
|
2019-04-22 10:11:00 +02:00
|
|
|
public void onVoteInPoll(int position, @NonNull List<Integer> choices) {
|
|
|
|
final Status status = statuses.get(position).getActionableStatus();
|
|
|
|
|
|
|
|
setVoteForPoll(position, status.getPoll().votedCopy(choices));
|
|
|
|
|
|
|
|
timelineCases.voteInPoll(status, choices)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this)))
|
|
|
|
.subscribe(
|
|
|
|
(newPoll) -> setVoteForPoll(position, newPoll),
|
|
|
|
(t) -> Log.d(TAG,
|
|
|
|
"Failed to vote in poll: " + status.getId(), t)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setVoteForPoll(int position, Poll newPoll) {
|
|
|
|
|
|
|
|
StatusViewData.Concrete viewData = statuses.getPairedItem(position);
|
|
|
|
|
|
|
|
StatusViewData.Concrete newViewData = new StatusViewData.Builder(viewData)
|
|
|
|
.setPoll(newPoll)
|
|
|
|
.createStatusViewData();
|
|
|
|
statuses.setPairedItem(position, newViewData);
|
|
|
|
adapter.setItem(position, newViewData, true);
|
|
|
|
}
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
private void removeAllByAccountId(String accountId) {
|
2017-07-12 21:54:52 +02:00
|
|
|
Status status = null;
|
|
|
|
if (!statuses.isEmpty()) {
|
|
|
|
status = statuses.get(statusIndex);
|
|
|
|
}
|
|
|
|
// using iterator to safely remove items while iterating
|
|
|
|
Iterator<Status> iterator = statuses.iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Status s = iterator.next();
|
2019-06-22 08:05:24 +02:00
|
|
|
if (s.getAccount().getId().equals(accountId) || s.getActionableStatus().getAccount().getId().equals(accountId)) {
|
2017-07-12 21:54:52 +02:00
|
|
|
iterator.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
statusIndex = statuses.indexOf(status);
|
2017-11-06 16:19:15 +01:00
|
|
|
if (statusIndex == -1) {
|
2017-10-24 23:33:05 +02:00
|
|
|
//the status got removed, close the activity
|
|
|
|
getActivity().finish();
|
|
|
|
return;
|
|
|
|
}
|
2017-08-03 06:29:31 +02:00
|
|
|
adapter.setDetailedStatusPosition(statusIndex);
|
2017-07-12 21:54:52 +02:00
|
|
|
adapter.setStatuses(statuses.getPairedCopy());
|
|
|
|
}
|
|
|
|
|
2017-05-03 22:28:46 +02:00
|
|
|
private void sendStatusRequest(final String id) {
|
2021-01-31 19:34:33 +01:00
|
|
|
mastodonApi.status(id)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
|
|
|
.subscribe(
|
|
|
|
status -> {
|
|
|
|
int position = setStatus(status);
|
|
|
|
recyclerView.scrollToPosition(position);
|
|
|
|
},
|
|
|
|
throwable -> onThreadRequestFailure(id, throwable)
|
|
|
|
);
|
2017-01-23 06:19:30 +01:00
|
|
|
}
|
|
|
|
|
2017-02-27 01:14:50 +01:00
|
|
|
private void sendThreadRequest(final String id) {
|
2021-01-31 19:34:33 +01:00
|
|
|
mastodonApi.statusContext(id)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
|
|
|
.subscribe(
|
|
|
|
context -> {
|
|
|
|
swipeRefreshLayout.setRefreshing(false);
|
|
|
|
setContext(context.getAncestors(), context.getDescendants());
|
|
|
|
},
|
|
|
|
throwable -> onThreadRequestFailure(id, throwable)
|
|
|
|
);
|
2017-01-23 06:19:30 +01:00
|
|
|
}
|
|
|
|
|
2021-01-31 19:34:33 +01:00
|
|
|
private void onThreadRequestFailure(final String id, final Throwable throwable) {
|
2017-03-15 20:27:49 +01:00
|
|
|
View view = getView();
|
2017-04-15 12:28:22 +02:00
|
|
|
swipeRefreshLayout.setRefreshing(false);
|
2017-03-15 20:27:49 +01:00
|
|
|
if (view != null) {
|
2017-04-06 09:09:49 +02:00
|
|
|
Snackbar.make(view, R.string.error_generic, Snackbar.LENGTH_LONG)
|
2018-04-28 16:17:01 +02:00
|
|
|
.setAction(R.string.action_retry, v -> {
|
|
|
|
sendThreadRequest(id);
|
|
|
|
sendStatusRequest(id);
|
2017-03-15 20:27:49 +01:00
|
|
|
})
|
|
|
|
.show();
|
2017-03-15 21:38:19 +01:00
|
|
|
} else {
|
2021-01-31 19:34:33 +01:00
|
|
|
Log.e(TAG, "Network request failed", throwable);
|
2017-03-15 20:27:49 +01:00
|
|
|
}
|
2017-01-23 06:19:30 +01:00
|
|
|
}
|
2017-07-12 21:54:52 +02:00
|
|
|
|
2017-10-18 00:20:26 +02:00
|
|
|
private int setStatus(Status status) {
|
2017-07-12 21:54:52 +02:00
|
|
|
if (statuses.size() > 0
|
|
|
|
&& statusIndex < statuses.size()
|
|
|
|
&& statuses.get(statusIndex).equals(status)) {
|
|
|
|
// Do not add this status on refresh, it's already in there.
|
|
|
|
statuses.set(statusIndex, status);
|
|
|
|
return statusIndex;
|
|
|
|
}
|
|
|
|
int i = statusIndex;
|
|
|
|
statuses.add(i, status);
|
2017-08-03 06:29:31 +02:00
|
|
|
adapter.setDetailedStatusPosition(i);
|
2019-06-02 21:23:18 +02:00
|
|
|
adapter.addItem(i, statuses.getPairedItem(i));
|
2018-04-28 16:17:01 +02:00
|
|
|
updateRevealIcon();
|
2017-07-12 21:54:52 +02:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2019-07-08 12:57:53 +02:00
|
|
|
private void setContext(List<Status> unfilteredAncestors, List<Status> unfilteredDescendants) {
|
2017-07-12 21:54:52 +02:00
|
|
|
Status mainStatus = null;
|
|
|
|
|
|
|
|
// In case of refresh, remove old ancestors and descendants first. We'll remove all blindly,
|
|
|
|
// as we have no guarantee on their order to be the same as before
|
|
|
|
int oldSize = statuses.size();
|
|
|
|
if (oldSize > 1) {
|
|
|
|
mainStatus = statuses.get(statusIndex);
|
|
|
|
statuses.clear();
|
|
|
|
adapter.clearItems();
|
|
|
|
}
|
|
|
|
|
2019-07-08 12:57:53 +02:00
|
|
|
ArrayList<Status> ancestors = new ArrayList<>();
|
|
|
|
for (Status status : unfilteredAncestors)
|
|
|
|
if (!shouldFilterStatus(status))
|
|
|
|
ancestors.add(status);
|
|
|
|
|
2017-07-12 21:54:52 +02:00
|
|
|
// Insert newly fetched ancestors
|
|
|
|
statusIndex = ancestors.size();
|
2017-08-03 06:29:31 +02:00
|
|
|
adapter.setDetailedStatusPosition(statusIndex);
|
2017-07-12 21:54:52 +02:00
|
|
|
statuses.addAll(0, ancestors);
|
2017-11-06 16:19:15 +01:00
|
|
|
List<StatusViewData.Concrete> ancestorsViewDatas = statuses.getPairedCopy().subList(0, statusIndex);
|
2017-07-12 21:54:52 +02:00
|
|
|
if (BuildConfig.DEBUG && ancestors.size() != ancestorsViewDatas.size()) {
|
|
|
|
String error = String.format(Locale.getDefault(),
|
|
|
|
"Incorrectly got statusViewData sublist." +
|
|
|
|
" ancestors.size == %d ancestorsViewDatas.size == %d," +
|
|
|
|
" statuses.size == %d",
|
|
|
|
ancestors.size(), ancestorsViewDatas.size(), statuses.size());
|
|
|
|
throw new AssertionError(error);
|
|
|
|
}
|
|
|
|
adapter.addAll(0, ancestorsViewDatas);
|
|
|
|
|
|
|
|
if (mainStatus != null) {
|
|
|
|
// In case we needed to delete everything (which is way easier than deleting
|
|
|
|
// everything except one), re-insert the remaining status here.
|
2019-07-08 12:57:53 +02:00
|
|
|
// Not filtering the main status, since the user explicitly chose to be here
|
2017-07-12 21:54:52 +02:00
|
|
|
statuses.add(statusIndex, mainStatus);
|
2017-11-06 16:19:15 +01:00
|
|
|
StatusViewData.Concrete viewData = statuses.getPairedItem(statusIndex);
|
2017-11-30 20:12:09 +01:00
|
|
|
|
2017-10-27 13:20:17 +02:00
|
|
|
adapter.addItem(statusIndex, viewData);
|
2017-07-12 21:54:52 +02:00
|
|
|
}
|
|
|
|
|
2019-07-08 12:57:53 +02:00
|
|
|
ArrayList<Status> descendants = new ArrayList<>();
|
|
|
|
for (Status status : unfilteredDescendants)
|
|
|
|
if (!shouldFilterStatus(status))
|
|
|
|
descendants.add(status);
|
|
|
|
|
2017-07-12 21:54:52 +02:00
|
|
|
// Insert newly fetched descendants
|
|
|
|
statuses.addAll(descendants);
|
2017-11-06 16:19:15 +01:00
|
|
|
List<StatusViewData.Concrete> descendantsViewData;
|
|
|
|
descendantsViewData = statuses.getPairedCopy()
|
|
|
|
.subList(statuses.size() - descendants.size(), statuses.size());
|
2017-07-12 21:54:52 +02:00
|
|
|
if (BuildConfig.DEBUG && descendants.size() != descendantsViewData.size()) {
|
|
|
|
String error = String.format(Locale.getDefault(),
|
|
|
|
"Incorrectly got statusViewData sublist." +
|
|
|
|
" descendants.size == %d descendantsViewData.size == %d," +
|
|
|
|
" statuses.size == %d",
|
|
|
|
descendants.size(), descendantsViewData.size(), statuses.size());
|
|
|
|
throw new AssertionError(error);
|
|
|
|
}
|
|
|
|
adapter.addAll(descendantsViewData);
|
2018-04-28 16:17:01 +02:00
|
|
|
updateRevealIcon();
|
2017-07-12 21:54:52 +02:00
|
|
|
}
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
private void handleFavEvent(FavoriteEvent event) {
|
|
|
|
Pair<Integer, Status> posAndStatus = findStatusAndPos(event.getStatusId());
|
|
|
|
if (posAndStatus == null) return;
|
2019-06-02 21:23:18 +02:00
|
|
|
|
2018-12-27 09:48:24 +01:00
|
|
|
boolean favourite = event.getFavourite();
|
|
|
|
posAndStatus.second.setFavourited(favourite);
|
|
|
|
|
|
|
|
if (posAndStatus.second.getReblog() != null) {
|
|
|
|
posAndStatus.second.getReblog().setFavourited(favourite);
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusViewData.Concrete viewdata = statuses.getPairedItem(posAndStatus.first);
|
|
|
|
|
|
|
|
StatusViewData.Builder viewDataBuilder = new StatusViewData.Builder((viewdata));
|
|
|
|
viewDataBuilder.setFavourited(favourite);
|
|
|
|
|
|
|
|
StatusViewData.Concrete newViewData = viewDataBuilder.createStatusViewData();
|
|
|
|
|
|
|
|
statuses.setPairedItem(posAndStatus.first, newViewData);
|
|
|
|
adapter.setItem(posAndStatus.first, newViewData, true);
|
2018-05-27 10:22:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleReblogEvent(ReblogEvent event) {
|
|
|
|
Pair<Integer, Status> posAndStatus = findStatusAndPos(event.getStatusId());
|
|
|
|
if (posAndStatus == null) return;
|
2019-06-02 21:23:18 +02:00
|
|
|
|
2018-12-27 09:48:24 +01:00
|
|
|
boolean reblog = event.getReblog();
|
|
|
|
posAndStatus.second.setReblogged(reblog);
|
|
|
|
|
|
|
|
if (posAndStatus.second.getReblog() != null) {
|
|
|
|
posAndStatus.second.getReblog().setReblogged(reblog);
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusViewData.Concrete viewdata = statuses.getPairedItem(posAndStatus.first);
|
|
|
|
|
|
|
|
StatusViewData.Builder viewDataBuilder = new StatusViewData.Builder((viewdata));
|
|
|
|
viewDataBuilder.setReblogged(reblog);
|
|
|
|
|
|
|
|
StatusViewData.Concrete newViewData = viewDataBuilder.createStatusViewData();
|
|
|
|
|
|
|
|
statuses.setPairedItem(posAndStatus.first, newViewData);
|
|
|
|
adapter.setItem(posAndStatus.first, newViewData, true);
|
2018-05-27 10:22:12 +02:00
|
|
|
}
|
|
|
|
|
2019-11-19 10:15:32 +01:00
|
|
|
private void handleBookmarkEvent(BookmarkEvent event) {
|
|
|
|
Pair<Integer, Status> posAndStatus = findStatusAndPos(event.getStatusId());
|
|
|
|
if (posAndStatus == null) return;
|
|
|
|
|
|
|
|
boolean bookmark = event.getBookmark();
|
|
|
|
posAndStatus.second.setBookmarked(bookmark);
|
|
|
|
|
|
|
|
if (posAndStatus.second.getReblog() != null) {
|
|
|
|
posAndStatus.second.getReblog().setBookmarked(bookmark);
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusViewData.Concrete viewdata = statuses.getPairedItem(posAndStatus.first);
|
|
|
|
|
|
|
|
StatusViewData.Builder viewDataBuilder = new StatusViewData.Builder((viewdata));
|
|
|
|
viewDataBuilder.setBookmarked(bookmark);
|
|
|
|
|
|
|
|
StatusViewData.Concrete newViewData = viewDataBuilder.createStatusViewData();
|
|
|
|
|
|
|
|
statuses.setPairedItem(posAndStatus.first, newViewData);
|
|
|
|
adapter.setItem(posAndStatus.first, newViewData, true);
|
|
|
|
}
|
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
private void handleStatusComposedEvent(StatusComposedEvent event) {
|
|
|
|
Status eventStatus = event.getStatus();
|
|
|
|
if (eventStatus.getInReplyToId() == null) return;
|
|
|
|
|
2018-07-08 19:21:19 +02:00
|
|
|
if (eventStatus.getInReplyToId().equals(thisThreadsStatusId)) {
|
2018-05-27 10:22:12 +02:00
|
|
|
insertStatus(eventStatus, statuses.size());
|
|
|
|
} else {
|
|
|
|
// If new status is a reply to some status in the thread, insert new status after it
|
|
|
|
// We only check statuses below main status, ones on top don't belong to this thread
|
|
|
|
for (int i = statusIndex; i < statuses.size(); i++) {
|
|
|
|
Status status = statuses.get(i);
|
|
|
|
if (eventStatus.getInReplyToId().equals(status.getId())) {
|
|
|
|
insertStatus(eventStatus, i + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void insertStatus(Status status, int at) {
|
|
|
|
statuses.add(at, status);
|
|
|
|
adapter.addItem(at, statuses.getPairedItem(at));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleStatusDeletedEvent(StatusDeletedEvent event) {
|
|
|
|
Pair<Integer, Status> posAndStatus = findStatusAndPos(event.getStatusId());
|
|
|
|
if (posAndStatus == null) return;
|
|
|
|
|
|
|
|
@SuppressWarnings("ConstantConditions")
|
|
|
|
int pos = posAndStatus.first;
|
|
|
|
statuses.remove(pos);
|
|
|
|
adapter.removeItem(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
private Pair<Integer, Status> findStatusAndPos(@NonNull String statusId) {
|
|
|
|
for (int i = 0; i < statuses.size(); i++) {
|
|
|
|
if (statusId.equals(statuses.get(i).getId())) {
|
|
|
|
return new Pair<>(i, statuses.get(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-04-28 16:17:01 +02:00
|
|
|
private void updateRevealIcon() {
|
|
|
|
ViewThreadActivity activity = ((ViewThreadActivity) getActivity());
|
|
|
|
if (activity == null) return;
|
|
|
|
|
|
|
|
boolean hasAnyWarnings = false;
|
|
|
|
// Statuses are updated from the main thread so nothing should change while iterating
|
|
|
|
for (int i = 0; i < statuses.size(); i++) {
|
2018-05-08 19:15:10 +02:00
|
|
|
if (!TextUtils.isEmpty(statuses.get(i).getSpoilerText())) {
|
2018-04-28 16:17:01 +02:00
|
|
|
hasAnyWarnings = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!hasAnyWarnings) {
|
2018-05-27 10:22:12 +02:00
|
|
|
activity.setRevealButtonState(ViewThreadActivity.REVEAL_BUTTON_HIDDEN);
|
|
|
|
return;
|
2018-04-28 16:17:01 +02:00
|
|
|
}
|
|
|
|
activity.setRevealButtonState(allExpanded() ? ViewThreadActivity.REVEAL_BUTTON_HIDE :
|
|
|
|
ViewThreadActivity.REVEAL_BUTTON_REVEAL);
|
|
|
|
}
|
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 filter.getContext().contains(Filter.THREAD);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void refreshAfterApplyingFilters() {
|
|
|
|
onRefresh();
|
|
|
|
}
|
2017-01-23 06:19:30 +01:00
|
|
|
}
|