mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-17 04:00:48 +01:00
updated RestFu
fixing memory leak
This commit is contained in:
parent
d742d2b697
commit
d443558495
@ -43,7 +43,7 @@ dependencies {
|
||||
compile 'com.android.support:support-v4:23.1.1'
|
||||
compile 'com.bluelinelabs:logansquare:1.3.4'
|
||||
compile 'org.apache.commons:commons-lang3:3.4'
|
||||
compile 'com.github.mariotaku.RestFu:library:0.9.12'
|
||||
compile 'com.github.mariotaku.RestFu:library:0.9.13'
|
||||
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.2'
|
||||
compile 'com.github.mariotaku.SQLiteQB:library:0.9.3'
|
||||
compile 'com.github.mariotaku.ObjectCursor:core:0.9.3'
|
||||
|
@ -20,6 +20,8 @@
|
||||
package org.mariotaku.twidere.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
@ -39,9 +41,12 @@ import org.mariotaku.twidere.api.twitter.model.User;
|
||||
import org.mariotaku.twidere.api.twitter.model.UserMentionEntity;
|
||||
import org.mariotaku.twidere.common.R;
|
||||
import org.mariotaku.twidere.model.ConsumerKeyType;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Filters;
|
||||
import org.mariotaku.twidere.util.collection.LongSparseMap;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
@ -255,4 +260,72 @@ public class TwitterContentUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFiltered(final SQLiteDatabase database, final long user_id, final String text_plain,
|
||||
final String text_html, final String source, final long retweeted_by_id, final long quotedUserId) {
|
||||
return isFiltered(database, user_id, text_plain, text_html, source, retweeted_by_id, quotedUserId, true);
|
||||
}
|
||||
|
||||
public static boolean isFiltered(final SQLiteDatabase database, final long userId,
|
||||
final String textPlain, final String textHtml, final String source,
|
||||
final long retweetedById, final long quotedUserId, final boolean filterRts) {
|
||||
if (database == null) return false;
|
||||
if (textPlain == null && textHtml == null && userId <= 0 && source == null) return false;
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final List<String> selection_args = new ArrayList<>();
|
||||
builder.append("SELECT NULL WHERE");
|
||||
if (textPlain != null) {
|
||||
selection_args.add(textPlain);
|
||||
builder.append("(SELECT 1 IN (SELECT ? LIKE '%'||" + Filters.Keywords.TABLE_NAME + "." + Filters.VALUE
|
||||
+ "||'%' FROM " + Filters.Keywords.TABLE_NAME + "))");
|
||||
}
|
||||
if (textHtml != null) {
|
||||
if (!selection_args.isEmpty()) {
|
||||
builder.append(" OR ");
|
||||
}
|
||||
selection_args.add(textHtml);
|
||||
builder.append("(SELECT 1 IN (SELECT ? LIKE '%<a href=\"%'||" + Filters.Links.TABLE_NAME + "."
|
||||
+ Filters.VALUE + "||'%\">%' FROM " + Filters.Links.TABLE_NAME + "))");
|
||||
}
|
||||
if (userId > 0) {
|
||||
if (!selection_args.isEmpty()) {
|
||||
builder.append(" OR ");
|
||||
}
|
||||
builder.append("(SELECT ").append(userId).append(" IN (SELECT ").append(Filters.Users.USER_ID).append(" FROM ").append(Filters.Users.TABLE_NAME).append("))");
|
||||
}
|
||||
if (retweetedById > 0) {
|
||||
if (!selection_args.isEmpty()) {
|
||||
builder.append(" OR ");
|
||||
}
|
||||
builder.append("(SELECT ").append(retweetedById).append(" IN (SELECT ").append(Filters.Users.USER_ID).append(" FROM ").append(Filters.Users.TABLE_NAME).append("))");
|
||||
}
|
||||
if (quotedUserId > 0) {
|
||||
if (!selection_args.isEmpty()) {
|
||||
builder.append(" OR ");
|
||||
}
|
||||
builder.append("(SELECT ").append(quotedUserId).append(" IN (SELECT ").append(Filters.Users.USER_ID).append(" FROM ").append(Filters.Users.TABLE_NAME).append("))");
|
||||
}
|
||||
if (source != null) {
|
||||
if (!selection_args.isEmpty()) {
|
||||
builder.append(" OR ");
|
||||
}
|
||||
selection_args.add(source);
|
||||
builder.append("(SELECT 1 IN (SELECT ? LIKE '%>'||" + Filters.Sources.TABLE_NAME + "." + Filters.VALUE
|
||||
+ "||'</a>%' FROM " + Filters.Sources.TABLE_NAME + "))");
|
||||
}
|
||||
final Cursor cur = database.rawQuery(builder.toString(),
|
||||
selection_args.toArray(new String[selection_args.size()]));
|
||||
if (cur == null) return false;
|
||||
try {
|
||||
return cur.getCount() > 0;
|
||||
} finally {
|
||||
cur.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFiltered(final SQLiteDatabase database, final ParcelableStatus status,
|
||||
final boolean filter_rts) {
|
||||
if (database == null || status == null) return false;
|
||||
return isFiltered(database, status.user_id, status.text_plain, status.text_html, status.source,
|
||||
status.retweeted_by_user_id, status.quoted_user_id, filter_rts);
|
||||
}
|
||||
}
|
||||
|
@ -108,8 +108,8 @@ dependencies {
|
||||
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
|
||||
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.2'
|
||||
compile 'com.github.mariotaku:PickNCrop:0.9.2'
|
||||
compile 'com.github.mariotaku.RestFu:library:0.9.12'
|
||||
compile 'com.github.mariotaku.RestFu:okhttp:0.9.12'
|
||||
compile 'com.github.mariotaku.RestFu:library:0.9.13'
|
||||
compile 'com.github.mariotaku.RestFu:okhttp:0.9.13'
|
||||
compile 'com.github.mariotaku:InetAddressJni:0.9.1'
|
||||
compile 'com.diogobernardino:williamchart:2.1'
|
||||
compile 'com.lnikkila:extendedtouchview:0.1.0'
|
||||
|
@ -76,7 +76,8 @@ public class DraftsAdapter extends SimpleCursorAdapter implements Constants {
|
||||
if (actionType == Drafts.ACTION_UPDATE_STATUS) {
|
||||
final ParcelableMedia[] media = ParcelableMedia.fromMediaUpdates(mediaUpdates);
|
||||
holder.media_preview_container.setVisibility(View.VISIBLE);
|
||||
holder.media_preview_container.displayMedia(media, mImageLoader, -1L, null, mMediaLoadingHandler);
|
||||
holder.media_preview_container.displayMedia(media, mImageLoader, -1, -1, null,
|
||||
mMediaLoadingHandler);
|
||||
} else {
|
||||
holder.media_preview_container.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ import android.os.Bundle;
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.mariotaku.twidere.Constants;
|
||||
@ -33,17 +32,21 @@ import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.adapter.iface.IDirectMessagesAdapter;
|
||||
import org.mariotaku.twidere.model.ParcelableDirectMessage;
|
||||
import org.mariotaku.twidere.model.ParcelableDirectMessageCursorIndices;
|
||||
import org.mariotaku.twidere.model.ParcelableMedia;
|
||||
import org.mariotaku.twidere.util.DirectMessageOnLinkClickHandler;
|
||||
import org.mariotaku.twidere.util.MediaLoadingHandler;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.TwidereLinkify;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.view.CardMediaContainer;
|
||||
import org.mariotaku.twidere.view.ShapedImageView;
|
||||
import org.mariotaku.twidere.view.holder.IncomingMessageViewHolder;
|
||||
import org.mariotaku.twidere.view.holder.MessageViewHolder;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class MessageConversationAdapter extends BaseRecyclerViewAdapter<ViewHolder> implements Constants,
|
||||
IDirectMessagesAdapter, OnClickListener {
|
||||
IDirectMessagesAdapter {
|
||||
|
||||
private static final int ITEM_VIEW_TYPE_MESSAGE_OUTGOING = 1;
|
||||
private static final int ITEM_VIEW_TYPE_MESSAGE_INCOMING = 2;
|
||||
@ -61,6 +64,7 @@ public class MessageConversationAdapter extends BaseRecyclerViewAdapter<ViewHold
|
||||
private Cursor mCursor;
|
||||
private ParcelableDirectMessageCursorIndices mIndices;
|
||||
private TwidereLinkify mLinkify;
|
||||
private CardMediaContainer.OnMediaClickListener mEventListener;
|
||||
|
||||
public MessageConversationAdapter(final Context context) {
|
||||
super(context);
|
||||
@ -71,7 +75,9 @@ public class MessageConversationAdapter extends BaseRecyclerViewAdapter<ViewHold
|
||||
mMediaPreviewStyle = Utils.getMediaPreviewStyle(mPreferences.getString(KEY_MEDIA_PREVIEW_STYLE, null));
|
||||
mMediaLoadingHandler = new MediaLoadingHandler(R.id.media_preview_progress);
|
||||
mIncomingMessageColor = ThemeUtils.getUserAccentColor(context);
|
||||
mOutgoingMessageColor = ThemeUtils.getCardBackgroundColor(context, ThemeUtils.getThemeBackgroundOption(context), ThemeUtils.getUserThemeBackgroundAlpha(context));
|
||||
mOutgoingMessageColor = ThemeUtils.getCardBackgroundColor(context,
|
||||
ThemeUtils.getThemeBackgroundOption(context), ThemeUtils.getUserThemeBackgroundAlpha(context));
|
||||
mEventListener = new EventListener(this);
|
||||
}
|
||||
|
||||
public MediaLoadingHandler getMediaLoadingHandler() {
|
||||
@ -162,22 +168,6 @@ public class MessageConversationAdapter extends BaseRecyclerViewAdapter<ViewHold
|
||||
return Utils.findDirectMessageInDatabases(getContext(), account_id, message_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(final View view) {
|
||||
if (mMultiSelectManager.isActive()) return;
|
||||
final Object tag = view.getTag();
|
||||
final int position = tag instanceof Integer ? (Integer) tag : -1;
|
||||
if (position == -1) return;
|
||||
switch (view.getId()) {
|
||||
case R.id.media_preview: {
|
||||
final ParcelableDirectMessage message = getDirectMessage(position);
|
||||
if (message == null || message.media == null) return;
|
||||
final Bundle options = Utils.createMediaViewerActivityOption(view);
|
||||
Utils.openMedia(getContext(), message, null, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getMediaPreviewStyle() {
|
||||
return mMediaPreviewStyle;
|
||||
@ -192,4 +182,26 @@ public class MessageConversationAdapter extends BaseRecyclerViewAdapter<ViewHold
|
||||
mCursor = cursor;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public CardMediaContainer.OnMediaClickListener getOnMediaClickListener() {
|
||||
return mEventListener;
|
||||
}
|
||||
|
||||
static class EventListener implements CardMediaContainer.OnMediaClickListener {
|
||||
|
||||
private final WeakReference<MessageConversationAdapter> adapterRef;
|
||||
|
||||
public EventListener(MessageConversationAdapter adapter) {
|
||||
this.adapterRef = new WeakReference<>(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaClick(View view, ParcelableMedia media, long accountId, long extraId) {
|
||||
final MessageConversationAdapter adapter = adapterRef.get();
|
||||
final Bundle options = Utils.createMediaViewerActivityOption(view);
|
||||
Utils.openMedia(adapter.getContext(), adapter.getDirectMessage((int) extraId), media,
|
||||
options);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ public class StaggeredGridParcelableStatusesAdapter extends AbsParcelableStatuse
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaClick(View view, ParcelableMedia media, long accountId) {
|
||||
public void onMediaClick(View view, ParcelableMedia media, long accountId, long extraId) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,6 +7,7 @@ import org.mariotaku.twidere.model.ParcelableMedia;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.util.MediaLoadingHandler;
|
||||
import org.mariotaku.twidere.util.TwidereLinkify;
|
||||
import org.mariotaku.twidere.view.CardMediaContainer;
|
||||
import org.mariotaku.twidere.view.CardMediaContainer.PreviewStyle;
|
||||
import org.mariotaku.twidere.view.holder.GapViewHolder;
|
||||
import org.mariotaku.twidere.view.holder.iface.IStatusViewHolder;
|
||||
|
@ -450,7 +450,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaClick(View view, ParcelableMedia media, long accountId) {
|
||||
public void onMediaClick(View view, ParcelableMedia media, long accountId, long extraId) {
|
||||
final ParcelableStatus status = mStatusAdapter.getStatus();
|
||||
if (status == null) return;
|
||||
final Bundle options = Utils.createMediaViewerActivityOption(view);
|
||||
@ -1056,8 +1056,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||
mediaPreviewContainer.setVisibility(View.VISIBLE);
|
||||
mediaPreview.setVisibility(View.VISIBLE);
|
||||
mediaPreviewLoad.setVisibility(View.GONE);
|
||||
mediaPreview.displayMedia(media, loader, status.account_id,
|
||||
adapter.getFragment(), adapter.getMediaLoadingHandler());
|
||||
mediaPreview.displayMedia(media, loader, status.account_id, -1, adapter.getFragment(),
|
||||
adapter.getMediaLoadingHandler());
|
||||
} else {
|
||||
mediaPreviewContainer.setVisibility(View.VISIBLE);
|
||||
mediaPreview.setVisibility(View.GONE);
|
||||
|
@ -30,7 +30,7 @@ import org.mariotaku.twidere.api.twitter.model.ResponseList;
|
||||
import org.mariotaku.twidere.api.twitter.model.Status;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.util.DataStoreUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.TwitterContentUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -63,7 +63,7 @@ public class MediaTimelineLoader extends TwitterAPIStatusesLoader {
|
||||
@Override
|
||||
protected boolean shouldFilterStatus(final SQLiteDatabase database, final ParcelableStatus status) {
|
||||
final long retweetUserId = status.is_retweet ? status.user_id : -1;
|
||||
return !mIsMyTimeline && Utils.isFiltered(database, retweetUserId, status.text_plain,
|
||||
return !mIsMyTimeline && TwitterContentUtils.isFiltered(database, retweetUserId, status.text_plain,
|
||||
status.text_html, status.source, -1, status.quoted_user_id);
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import org.mariotaku.twidere.api.twitter.model.Paging;
|
||||
import org.mariotaku.twidere.api.twitter.model.ResponseList;
|
||||
import org.mariotaku.twidere.api.twitter.model.Status;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.TwitterContentUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -50,7 +50,7 @@ public class RetweetsOfMeLoader extends TwitterAPIStatusesLoader {
|
||||
|
||||
@Override
|
||||
protected boolean shouldFilterStatus(final SQLiteDatabase database, final ParcelableStatus status) {
|
||||
return Utils.isFiltered(database, -1, status.text_plain, status.text_html, status.source,
|
||||
return TwitterContentUtils.isFiltered(database, -1, status.text_plain, status.text_html, status.source,
|
||||
status.retweeted_by_user_id, status.quoted_user_id);
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import org.mariotaku.twidere.api.twitter.model.Paging;
|
||||
import org.mariotaku.twidere.api.twitter.model.SearchQuery;
|
||||
import org.mariotaku.twidere.api.twitter.model.Status;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.TwitterContentUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -66,7 +66,7 @@ public class TweetSearchLoader extends TwitterAPIStatusesLoader {
|
||||
|
||||
@Override
|
||||
protected boolean shouldFilterStatus(final SQLiteDatabase database, final ParcelableStatus status) {
|
||||
return Utils.isFiltered(database, status, true);
|
||||
return TwitterContentUtils.isFiltered(database, status, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +32,7 @@ import org.mariotaku.twidere.api.twitter.model.ResponseList;
|
||||
import org.mariotaku.twidere.api.twitter.model.Status;
|
||||
import org.mariotaku.twidere.api.twitter.Twitter;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.TwitterContentUtils;
|
||||
|
||||
public class UserListTimelineLoader extends TwitterAPIStatusesLoader {
|
||||
|
||||
@ -67,7 +67,7 @@ public class UserListTimelineLoader extends TwitterAPIStatusesLoader {
|
||||
|
||||
@Override
|
||||
protected boolean shouldFilterStatus(final SQLiteDatabase database, final ParcelableStatus status) {
|
||||
return Utils.isFiltered(database, status, true);
|
||||
return TwitterContentUtils.isFiltered(database, status, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ import org.mariotaku.twidere.api.twitter.model.ResponseList;
|
||||
import org.mariotaku.twidere.api.twitter.model.Status;
|
||||
import org.mariotaku.twidere.model.ParcelableStatus;
|
||||
import org.mariotaku.twidere.util.DataStoreUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.TwitterContentUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -64,7 +64,7 @@ public class UserTimelineLoader extends TwitterAPIStatusesLoader {
|
||||
@Override
|
||||
protected boolean shouldFilterStatus(final SQLiteDatabase database, final ParcelableStatus status) {
|
||||
final long retweetUserId = status.is_retweet ? status.user_id : -1;
|
||||
return !mIsMyTimeline && Utils.isFiltered(database, retweetUserId, status.text_plain,
|
||||
return !mIsMyTimeline && TwitterContentUtils.isFiltered(database, retweetUserId, status.text_plain,
|
||||
status.text_html, status.source, -1, status.quoted_user_id);
|
||||
}
|
||||
}
|
||||
|
@ -1741,75 +1741,6 @@ public final class Utils implements Constants {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFiltered(final SQLiteDatabase database, final long user_id, final String text_plain,
|
||||
final String text_html, final String source, final long retweeted_by_id, final long quotedUserId) {
|
||||
return isFiltered(database, user_id, text_plain, text_html, source, retweeted_by_id, quotedUserId, true);
|
||||
}
|
||||
|
||||
public static boolean isFiltered(final SQLiteDatabase database, final long userId,
|
||||
final String textPlain, final String textHtml, final String source,
|
||||
final long retweetedById, final long quotedUserId, final boolean filterRts) {
|
||||
if (database == null) return false;
|
||||
if (textPlain == null && textHtml == null && userId <= 0 && source == null) return false;
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final List<String> selection_args = new ArrayList<>();
|
||||
builder.append("SELECT NULL WHERE");
|
||||
if (textPlain != null) {
|
||||
selection_args.add(textPlain);
|
||||
builder.append("(SELECT 1 IN (SELECT ? LIKE '%'||" + Filters.Keywords.TABLE_NAME + "." + Filters.VALUE
|
||||
+ "||'%' FROM " + Filters.Keywords.TABLE_NAME + "))");
|
||||
}
|
||||
if (textHtml != null) {
|
||||
if (!selection_args.isEmpty()) {
|
||||
builder.append(" OR ");
|
||||
}
|
||||
selection_args.add(textHtml);
|
||||
builder.append("(SELECT 1 IN (SELECT ? LIKE '%<a href=\"%'||" + Filters.Links.TABLE_NAME + "."
|
||||
+ Filters.VALUE + "||'%\">%' FROM " + Filters.Links.TABLE_NAME + "))");
|
||||
}
|
||||
if (userId > 0) {
|
||||
if (!selection_args.isEmpty()) {
|
||||
builder.append(" OR ");
|
||||
}
|
||||
builder.append("(SELECT ").append(userId).append(" IN (SELECT ").append(Users.USER_ID).append(" FROM ").append(Users.TABLE_NAME).append("))");
|
||||
}
|
||||
if (retweetedById > 0) {
|
||||
if (!selection_args.isEmpty()) {
|
||||
builder.append(" OR ");
|
||||
}
|
||||
builder.append("(SELECT ").append(retweetedById).append(" IN (SELECT ").append(Users.USER_ID).append(" FROM ").append(Users.TABLE_NAME).append("))");
|
||||
}
|
||||
if (quotedUserId > 0) {
|
||||
if (!selection_args.isEmpty()) {
|
||||
builder.append(" OR ");
|
||||
}
|
||||
builder.append("(SELECT ").append(quotedUserId).append(" IN (SELECT ").append(Users.USER_ID).append(" FROM ").append(Users.TABLE_NAME).append("))");
|
||||
}
|
||||
if (source != null) {
|
||||
if (!selection_args.isEmpty()) {
|
||||
builder.append(" OR ");
|
||||
}
|
||||
selection_args.add(source);
|
||||
builder.append("(SELECT 1 IN (SELECT ? LIKE '%>'||" + Filters.Sources.TABLE_NAME + "." + Filters.VALUE
|
||||
+ "||'</a>%' FROM " + Filters.Sources.TABLE_NAME + "))");
|
||||
}
|
||||
final Cursor cur = database.rawQuery(builder.toString(),
|
||||
selection_args.toArray(new String[selection_args.size()]));
|
||||
if (cur == null) return false;
|
||||
try {
|
||||
return cur.getCount() > 0;
|
||||
} finally {
|
||||
cur.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFiltered(final SQLiteDatabase database, final ParcelableStatus status,
|
||||
final boolean filter_rts) {
|
||||
if (database == null || status == null) return false;
|
||||
return isFiltered(database, status.user_id, status.text_plain, status.text_html, status.source,
|
||||
status.retweeted_by_user_id, status.quoted_user_id, filter_rts);
|
||||
}
|
||||
|
||||
public static boolean isMyAccount(final Context context, final long accountId) {
|
||||
if (context == null) return false;
|
||||
final ContentResolver resolver = context.getContentResolver();
|
||||
@ -3275,23 +3206,6 @@ public final class Utils implements Constants {
|
||||
}
|
||||
}
|
||||
|
||||
private static class ImageGridClickListener implements View.OnClickListener {
|
||||
private final OnMediaClickListener mListener;
|
||||
private final long mAccountId;
|
||||
|
||||
ImageGridClickListener(final OnMediaClickListener listener, final long accountId) {
|
||||
mListener = listener;
|
||||
mAccountId = accountId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
if (mListener == null) return;
|
||||
mListener.onMediaClick(v, (ParcelableMedia) v.getTag(), mAccountId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Notifications to Pebble smartwatches
|
||||
*
|
||||
|
@ -40,6 +40,7 @@ import org.mariotaku.twidere.util.MediaLoadingHandler;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 14/12/17.
|
||||
@ -87,15 +88,16 @@ public class CardMediaContainer extends ViewGroup implements Constants {
|
||||
|
||||
public void displayMedia(@Nullable final ParcelableMedia[] mediaArray,
|
||||
@NonNull final MediaLoaderWrapper loader,
|
||||
final long accountId,
|
||||
final long accountId, final long extraId,
|
||||
final OnMediaClickListener mediaClickListener,
|
||||
final MediaLoadingHandler loadingHandler) {
|
||||
displayMedia(mediaArray, loader, accountId, false, mediaClickListener, loadingHandler);
|
||||
displayMedia(mediaArray, loader, accountId, extraId, false, mediaClickListener,
|
||||
loadingHandler);
|
||||
}
|
||||
|
||||
public void displayMedia(@Nullable final ParcelableMedia[] mediaArray,
|
||||
@NonNull final MediaLoaderWrapper loader,
|
||||
final long accountId, boolean withCredentials,
|
||||
final long accountId, final long extraId, boolean withCredentials,
|
||||
final OnMediaClickListener mediaClickListener,
|
||||
final MediaLoadingHandler loadingHandler) {
|
||||
if (mediaArray == null || mMediaPreviewStyle == VALUE_MEDIA_PREVIEW_STYLE_CODE_NONE) {
|
||||
@ -106,7 +108,8 @@ public class CardMediaContainer extends ViewGroup implements Constants {
|
||||
}
|
||||
return;
|
||||
}
|
||||
final View.OnClickListener clickListener = new ImageGridClickListener(mediaClickListener, accountId);
|
||||
final View.OnClickListener clickListener = new ImageGridClickListener(mediaClickListener,
|
||||
accountId, extraId);
|
||||
for (int i = 0, j = getChildCount(), k = mediaArray.length; i < j; i++) {
|
||||
final View child = getChildAt(i);
|
||||
child.setOnClickListener(clickListener);
|
||||
@ -288,22 +291,26 @@ public class CardMediaContainer extends ViewGroup implements Constants {
|
||||
}
|
||||
|
||||
public interface OnMediaClickListener {
|
||||
void onMediaClick(View view, ParcelableMedia media, long accountId);
|
||||
void onMediaClick(View view, ParcelableMedia media, long accountId, long id);
|
||||
}
|
||||
|
||||
private static class ImageGridClickListener implements View.OnClickListener {
|
||||
private final OnMediaClickListener mListener;
|
||||
private final WeakReference<OnMediaClickListener> mListenerRef;
|
||||
private final long mAccountId;
|
||||
private final long mExtraId;
|
||||
|
||||
ImageGridClickListener(final OnMediaClickListener listener, final long accountId) {
|
||||
mListener = listener;
|
||||
ImageGridClickListener(final OnMediaClickListener listener, final long accountId,
|
||||
final long extraId) {
|
||||
mListenerRef = new WeakReference<>(listener);
|
||||
mAccountId = accountId;
|
||||
mExtraId = extraId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
if (mListener == null) return;
|
||||
mListener.onMediaClick(v, (ParcelableMedia) v.getTag(), mAccountId);
|
||||
final OnMediaClickListener listener = mListenerRef.get();
|
||||
if (listener == null) return;
|
||||
listener.onMediaClick(v, (ParcelableMedia) v.getTag(), mAccountId, mExtraId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
import android.text.Spanned;
|
||||
import android.view.View;
|
||||
@ -42,9 +41,8 @@ import org.mariotaku.twidere.util.TwidereColorUtils;
|
||||
import org.mariotaku.twidere.util.TwidereLinkify;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.view.CardMediaContainer;
|
||||
import org.mariotaku.twidere.view.CardMediaContainer.OnMediaClickListener;
|
||||
|
||||
public class MessageViewHolder extends ViewHolder implements OnMediaClickListener {
|
||||
public class MessageViewHolder extends ViewHolder {
|
||||
|
||||
public final CardMediaContainer mediaContainer;
|
||||
public final TextView textView, time;
|
||||
@ -87,13 +85,8 @@ public class MessageViewHolder extends ViewHolder implements OnMediaClickListene
|
||||
textView.setText(linkify.applyAllLinks(text, accountId, false));
|
||||
time.setText(Utils.formatToLongTimeString(context, timestamp));
|
||||
mediaContainer.setVisibility(media != null && media.length > 0 ? View.VISIBLE : View.GONE);
|
||||
mediaContainer.displayMedia(media, loader, accountId, true, this, adapter.getMediaLoadingHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaClick(View view, ParcelableMedia media, long accountId) {
|
||||
final Bundle options = Utils.createMediaViewerActivityOption(view);
|
||||
Utils.openMedia(adapter.getContext(), adapter.getDirectMessage(getAdapterPosition()), media, options);
|
||||
mediaContainer.displayMedia(media, loader, accountId, getLayoutPosition(), true,
|
||||
adapter.getOnMediaClickListener(), adapter.getMediaLoadingHandler());
|
||||
}
|
||||
|
||||
public void setMessageColor(int color) {
|
||||
|
@ -269,7 +269,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, IStatusVi
|
||||
final boolean hasMedia = !ArrayUtils.isEmpty(media);
|
||||
if (hasMedia && (adapter.isSensitiveContentEnabled() || !status.is_possibly_sensitive)) {
|
||||
mediaPreview.setVisibility(View.VISIBLE);
|
||||
mediaPreview.displayMedia(media, loader, status.account_id, this,
|
||||
mediaPreview.displayMedia(media, loader, status.account_id, -1, this,
|
||||
adapter.getMediaLoadingHandler());
|
||||
} else {
|
||||
mediaPreview.setVisibility(View.GONE);
|
||||
@ -342,7 +342,7 @@ public class StatusViewHolder extends ViewHolder implements Constants, IStatusVi
|
||||
|
||||
|
||||
@Override
|
||||
public void onMediaClick(View view, ParcelableMedia media, long accountId) {
|
||||
public void onMediaClick(View view, ParcelableMedia media, long accountId, long extraId) {
|
||||
if (statusClickListener == null) return;
|
||||
final int position = getLayoutPosition();
|
||||
statusClickListener.onMediaClick(this, view, media, position);
|
||||
|
@ -45,7 +45,7 @@ public interface IStatusViewHolder extends CardMediaContainer.OnMediaClickListen
|
||||
ImageView getProfileTypeView();
|
||||
|
||||
@Override
|
||||
void onMediaClick(View view, ParcelableMedia media, long accountId);
|
||||
void onMediaClick(View view, ParcelableMedia media, long accountId, long extraId);
|
||||
|
||||
void setStatusClickListener(StatusClickListener listener);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user