mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-17 04:00:48 +01:00
fixed parcelable tweet loader gap handling
fixed last character lost in quote comment merged 'load more automatically' into 'media preview' option
This commit is contained in:
parent
bd0198a623
commit
5aa3385b1b
@ -157,8 +157,6 @@ public interface SharedPreferenceConstants {
|
||||
String KEY_GZIP_COMPRESSING = "gzip_compressing";
|
||||
@Preference(type = BOOLEAN)
|
||||
String KEY_IGNORE_SSL_ERROR = "ignore_ssl_error";
|
||||
@Preference(type = BOOLEAN)
|
||||
String KEY_LOAD_MORE_AUTOMATICALLY = "load_more_automatically";
|
||||
@Preference(type = STRING)
|
||||
String KEY_QUOTE_FORMAT = "quote_format";
|
||||
@Preference(type = BOOLEAN)
|
||||
|
@ -58,7 +58,6 @@ abstract class BaseUserListsListFragment extends BasePullToRefreshListFragment i
|
||||
private final ArrayList<ParcelableUserList> mData = new ArrayList<>();
|
||||
private ParcelableUserList mSelectedUserList;
|
||||
private long mCursor = -1;
|
||||
private boolean mLoadMoreAutomatically;
|
||||
|
||||
private AsyncTwitterWrapper mTwitterWrapper;
|
||||
private MultiSelectManager mMultiSelectManager;
|
||||
@ -206,7 +205,6 @@ abstract class BaseUserListsListFragment extends BasePullToRefreshListFragment i
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mLoadMoreAutomatically = mPreferences.getBoolean(KEY_LOAD_MORE_AUTOMATICALLY, false);
|
||||
configBaseCardAdapter(getActivity(), mAdapter);
|
||||
}
|
||||
|
||||
@ -216,7 +214,6 @@ abstract class BaseUserListsListFragment extends BasePullToRefreshListFragment i
|
||||
|
||||
@Override
|
||||
protected void onReachedBottom() {
|
||||
if (!mLoadMoreAutomatically) return;
|
||||
loadMoreUserLists();
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,6 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
||||
|
||||
private ParcelableDirectMessage mSelectedDirectMessage;
|
||||
private boolean mLoaderInitialized;
|
||||
private boolean mLoadMoreAutomatically;
|
||||
private String mImageUri;
|
||||
|
||||
|
||||
@ -543,7 +542,6 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
|
||||
ScaleType.CENTER_CROP.name());
|
||||
mAdapter.setImagePreviewScaleType(previewScaleType);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
mLoadMoreAutomatically = mPreferences.getBoolean(KEY_LOAD_MORE_AUTOMATICALLY, false);
|
||||
updateAddImageButton();
|
||||
}
|
||||
|
||||
|
@ -635,7 +635,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
|
||||
final int idx = status.quote_text_unescaped.lastIndexOf(" twitter.com");
|
||||
final Spanned quote_text = Html.fromHtml(status.quote_text_html);
|
||||
quoteTextView.setText(idx > 0 ? quote_text.subSequence(0, idx - 1) : quote_text);
|
||||
quoteTextView.setText(idx > 0 ? quote_text.subSequence(0, idx) : quote_text);
|
||||
final SpannableString originalTweetLink = SpannableString.valueOf("Original tweet");
|
||||
originalTweetLink.setSpan(new URLSpan(LinkCreator.getTwitterStatusLink(status.user_screen_name, status.quote_id).toString()),
|
||||
0, originalTweetLink.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
@ -1221,6 +1221,10 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
}
|
||||
|
||||
public boolean isDetailMediaExpanded() {
|
||||
if (mDisplayMediaPreview) {
|
||||
final ParcelableStatus status = mStatus;
|
||||
return status != null && (mSensitiveContentEnabled || !status.is_possibly_sensitive);
|
||||
}
|
||||
return mDetailMediaExpanded;
|
||||
}
|
||||
|
||||
|
@ -68,9 +68,10 @@ public abstract class ParcelableStatusesLoader extends AsyncTaskLoader<List<Parc
|
||||
protected boolean deleteStatus(final List<ParcelableStatus> statuses, final long status_id) {
|
||||
if (statuses == null || statuses.isEmpty()) return false;
|
||||
boolean result = false;
|
||||
for (final ParcelableStatus status : statuses.toArray(new ParcelableStatus[statuses.size()])) {
|
||||
if (status.id == status_id) {
|
||||
result |= statuses.remove(status);
|
||||
for (int i = statuses.size() - 1; i >= 0; i--) {
|
||||
if (statuses.get(i).id == status_id) {
|
||||
statuses.remove(i);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -26,6 +26,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.mariotaku.jsonserializer.JSONFileIO;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
@ -85,11 +86,14 @@ public abstract class TwitterAPIStatusesLoader extends ParcelableStatusesLoader
|
||||
}
|
||||
}
|
||||
if (!isFromUser()) return data;
|
||||
final Twitter twitter = getTwitter();
|
||||
if (twitter == null) return null;
|
||||
final List<Status> statuses;
|
||||
final boolean truncated;
|
||||
final Context context = getContext();
|
||||
final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
||||
final int loadItemLimit = prefs.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT);
|
||||
final boolean noItemsBefore = data == null || data.isEmpty();
|
||||
try {
|
||||
final Paging paging = new Paging();
|
||||
paging.setCount(loadItemLimit);
|
||||
@ -100,23 +104,41 @@ public abstract class TwitterAPIStatusesLoader extends ParcelableStatusesLoader
|
||||
paging.setSinceId(mSinceId - 1);
|
||||
}
|
||||
statuses = new ArrayList<>();
|
||||
final Twitter twitter = getTwitter();
|
||||
if (twitter == null) {
|
||||
throw new TwitterException("Account is null");
|
||||
}
|
||||
truncated = truncateStatuses(getStatuses(twitter, paging), statuses, mSinceId);
|
||||
} catch (final TwitterException e) {
|
||||
// mHandler.post(new ShowErrorRunnable(e));
|
||||
Log.w(LOGTAG, e);
|
||||
return new CopyOnWriteArrayList<>(data);
|
||||
}
|
||||
final long minStatusId = statuses.isEmpty() ? -1 : Collections.min(statuses).getId();
|
||||
final boolean insertGap = minStatusId > 0 && statuses.size() > 1 && !data.isEmpty() && !truncated;
|
||||
for (final Status status : statuses) {
|
||||
|
||||
final long[] statusIds = new long[statuses.size()];
|
||||
long minId = -1;
|
||||
int minIdx = -1;
|
||||
int rowsDeleted = 0;
|
||||
for (int i = 0, j = statuses.size(); i < j; i++) {
|
||||
final twitter4j.Status status = statuses.get(i);
|
||||
final long id = status.getId();
|
||||
final boolean deleted = deleteStatus(data, id);
|
||||
data.add(new ParcelableStatus(status, mAccountId, minStatusId == id && insertGap && !deleted));
|
||||
if (minId == -1 || id < minId) {
|
||||
minId = id;
|
||||
minIdx = i;
|
||||
}
|
||||
statusIds[i] = id;
|
||||
|
||||
if (deleteStatus(data, status.getId())) {
|
||||
rowsDeleted++;
|
||||
}
|
||||
}
|
||||
|
||||
// Insert a gap.
|
||||
final boolean deletedOldGap = rowsDeleted > 0 && ArrayUtils.contains(statusIds, mMaxId);
|
||||
final boolean noRowsDeleted = rowsDeleted == 0;
|
||||
final boolean insertGap = minId > 0 && (noRowsDeleted || deletedOldGap) && !truncated
|
||||
&& !noItemsBefore && statuses.size() > 1;
|
||||
for (int i = 0, j = statuses.size(); i < j; i++) {
|
||||
final Status status = statuses.get(i);
|
||||
data.add(new ParcelableStatus(status, mAccountId, insertGap && minIdx == i));
|
||||
}
|
||||
|
||||
final ParcelableStatus[] array = data.toArray(new ParcelableStatus[data.size()]);
|
||||
for (int i = 0, size = array.length; i < size; i++) {
|
||||
final ParcelableStatus status = array[i];
|
||||
|
@ -183,10 +183,10 @@ public class StatusViewHolder extends RecyclerView.ViewHolder implements Constan
|
||||
final int idx = status.quote_text_unescaped.lastIndexOf(" twitter.com");
|
||||
if (adapter.getLinkHighlightingStyle() == VALUE_LINK_HIGHLIGHT_OPTION_CODE_NONE) {
|
||||
final String text = status.quote_text_unescaped;
|
||||
quoteTextView.setText(idx > 0 ? text.substring(0, idx - 1) : text);
|
||||
quoteTextView.setText(idx > 0 ? text.substring(0, idx ) : text);
|
||||
} else {
|
||||
final Spanned text = Html.fromHtml(status.quote_text_html);
|
||||
quoteTextView.setText(idx > 0 ? text.subSequence(0, idx - 1) : text);
|
||||
quoteTextView.setText(idx > 0 ? text.subSequence(0, idx ) : text);
|
||||
linkify.applyAllLinks(quoteTextView, status.account_id, getLayoutPosition(),
|
||||
status.is_possibly_sensitive, adapter.getLinkHighlightingStyle());
|
||||
quoteTextView.setMovementMethod(null);
|
||||
@ -373,10 +373,10 @@ public class StatusViewHolder extends RecyclerView.ViewHolder implements Constan
|
||||
final String quote_text_unescaped = cursor.getString(indices.quote_text_unescaped);
|
||||
final int idx = quote_text_unescaped.lastIndexOf(" twitter.com");
|
||||
if (adapter.getLinkHighlightingStyle() == VALUE_LINK_HIGHLIGHT_OPTION_CODE_NONE) {
|
||||
quoteTextView.setText(idx > 0 ? quote_text_unescaped.substring(0, idx - 1) : quote_text_unescaped);
|
||||
quoteTextView.setText(idx > 0 ? quote_text_unescaped.substring(0, idx ) : quote_text_unescaped);
|
||||
} else {
|
||||
final Spanned text = Html.fromHtml(cursor.getString(indices.quote_text_html));
|
||||
quoteTextView.setText(idx > 0 ? text.subSequence(0, idx - 1) : text);
|
||||
quoteTextView.setText(idx > 0 ? text.subSequence(0, idx ) : text);
|
||||
linkify.applyAllLinks(quoteTextView, account_id, getLayoutPosition(),
|
||||
cursor.getShort(indices.is_possibly_sensitive) == 1,
|
||||
adapter.getLinkHighlightingStyle());
|
||||
@ -574,7 +574,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder implements Constan
|
||||
timeView.setTextSize(textSize * 0.85f);
|
||||
replyRetweetView.setTextSize(textSize * 0.75f);
|
||||
replyCountView.setTextSize(textSize);
|
||||
replyCountView.setTextSize(textSize);
|
||||
retweetCountView.setTextSize(textSize);
|
||||
favoriteCountView.setTextSize(textSize);
|
||||
}
|
||||
|
||||
|
@ -1,23 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@id/reply"
|
||||
android:icon="@drawable/ic_action_reply"
|
||||
android:title="@string/reply"/>
|
||||
<item
|
||||
android:id="@id/retweet"
|
||||
android:icon="@drawable/ic_action_retweet"
|
||||
android:title="@string/retweet"/>
|
||||
<item
|
||||
android:id="@id/quote"
|
||||
android:icon="@drawable/ic_action_quote"
|
||||
android:title="@string/quote"/>
|
||||
<item
|
||||
android:id="@id/favorite"
|
||||
android:icon="@drawable/ic_action_star"
|
||||
android:title="@string/favorite"/>
|
||||
<item
|
||||
android:id="@id/share"
|
||||
android:icon="@drawable/ic_action_share"
|
||||
|
@ -61,12 +61,6 @@
|
||||
android:summary="@string/share_format_summary"
|
||||
android:title="@string/share_format"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="load_more_automatically"
|
||||
android:summary="@string/load_more_automatically_summary"
|
||||
android:title="@string/load_more_automatically"/>
|
||||
|
||||
<org.mariotaku.twidere.preference.SeekBarDialogPreference
|
||||
android:defaultValue="20"
|
||||
android:key="load_item_limit"
|
||||
|
Loading…
x
Reference in New Issue
Block a user