2015-01-26 17:09:02 +01:00
|
|
|
/*
|
|
|
|
* Twidere - Twitter client for Android
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.mariotaku.twidere.adapter;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.support.v7.widget.RecyclerView.Adapter;
|
|
|
|
import android.support.v7.widget.RecyclerView.ViewHolder;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
2015-03-11 15:15:32 +01:00
|
|
|
import org.mariotaku.twidere.Constants;
|
2015-01-26 17:09:02 +01:00
|
|
|
import org.mariotaku.twidere.R;
|
2015-03-11 15:15:32 +01:00
|
|
|
import org.mariotaku.twidere.adapter.iface.IContentCardAdapter;
|
2015-01-26 17:09:02 +01:00
|
|
|
import org.mariotaku.twidere.app.TwidereApplication;
|
|
|
|
import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages.ConversationEntries;
|
2015-03-11 15:15:32 +01:00
|
|
|
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
2015-01-26 17:09:02 +01:00
|
|
|
import org.mariotaku.twidere.util.ImageLoaderWrapper;
|
2015-03-11 15:15:32 +01:00
|
|
|
import org.mariotaku.twidere.util.ImageLoadingHandler;
|
2015-01-26 17:09:02 +01:00
|
|
|
import org.mariotaku.twidere.util.MultiSelectManager;
|
|
|
|
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
2015-03-11 15:15:32 +01:00
|
|
|
import org.mariotaku.twidere.util.Utils;
|
2015-01-26 17:09:02 +01:00
|
|
|
import org.mariotaku.twidere.view.holder.MessageEntryViewHolder;
|
|
|
|
|
2015-03-11 15:15:32 +01:00
|
|
|
public class MessageEntriesAdapter extends Adapter<ViewHolder> implements Constants, IContentCardAdapter, OnClickListener {
|
2015-01-26 17:09:02 +01:00
|
|
|
|
|
|
|
private final Context mContext;
|
|
|
|
private final LayoutInflater mInflater;
|
|
|
|
private final ImageLoaderWrapper mImageLoader;
|
|
|
|
private final MultiSelectManager mMultiSelectManager;
|
|
|
|
private final boolean mNicknameOnly;
|
2015-03-11 15:15:32 +01:00
|
|
|
private final int mTextSize;
|
|
|
|
private final int mProfileImageStyle;
|
|
|
|
private final int mMediaPreviewStyle;
|
2015-01-26 17:09:02 +01:00
|
|
|
private Cursor mCursor;
|
|
|
|
private MessageEntriesAdapterListener mListener;
|
|
|
|
|
|
|
|
public Context getContext() {
|
|
|
|
return mContext;
|
|
|
|
}
|
|
|
|
|
2015-03-11 15:15:32 +01:00
|
|
|
@Override
|
|
|
|
public ImageLoadingHandler getImageLoadingHandler() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getProfileImageStyle() {
|
|
|
|
return mProfileImageStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMediaPreviewStyle() {
|
|
|
|
return mMediaPreviewStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AsyncTwitterWrapper getTwitterWrapper() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getTextSize() {
|
|
|
|
return mTextSize;
|
|
|
|
}
|
|
|
|
|
2015-01-26 17:09:02 +01:00
|
|
|
public ImageLoaderWrapper getImageLoader() {
|
|
|
|
return mImageLoader;
|
|
|
|
}
|
|
|
|
|
2015-03-11 15:15:32 +01:00
|
|
|
@Override
|
|
|
|
public boolean isGapItem(int position) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onGapClick(ViewHolder holder, int position) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-26 17:09:02 +01:00
|
|
|
public boolean isNicknameOnly() {
|
|
|
|
return mNicknameOnly;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
final View view = mInflater.inflate(R.layout.list_item_message_entry, parent, false);
|
|
|
|
return new MessageEntryViewHolder(this, view);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
|
|
|
final Cursor c = mCursor;
|
|
|
|
c.moveToPosition(position);
|
|
|
|
((MessageEntryViewHolder) holder).displayMessage(c);
|
|
|
|
}
|
|
|
|
|
2015-03-11 15:15:32 +01:00
|
|
|
@Override
|
|
|
|
public void onItemActionClick(ViewHolder holder, int id, int position) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onItemMenuClick(ViewHolder holder, View menuView, int position) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-26 17:09:02 +01:00
|
|
|
public void onMessageClick(int position) {
|
|
|
|
if (mListener == null) return;
|
|
|
|
mListener.onEntryClick(position, getEntry(position));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCursor(Cursor cursor) {
|
|
|
|
mCursor = cursor;
|
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
final Cursor c = mCursor;
|
|
|
|
if (c == null) return 0;
|
|
|
|
return c.getCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
public MessageEntriesAdapter(final Context context) {
|
|
|
|
mContext = context;
|
|
|
|
mInflater = LayoutInflater.from(context);
|
|
|
|
final TwidereApplication app = TwidereApplication.getInstance(context);
|
|
|
|
mMultiSelectManager = app.getMultiSelectManager();
|
|
|
|
mImageLoader = app.getImageLoaderWrapper();
|
2015-03-11 15:15:32 +01:00
|
|
|
final SharedPreferencesWrapper preferences = SharedPreferencesWrapper.getInstance(context,
|
|
|
|
SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
|
|
|
mProfileImageStyle = Utils.getProfileImageStyle(preferences.getString(KEY_PROFILE_IMAGE_STYLE, null));
|
|
|
|
mMediaPreviewStyle = Utils.getMediaPreviewStyle(preferences.getString(KEY_MEDIA_PREVIEW_STYLE, null));
|
|
|
|
mTextSize = preferences.getInt(KEY_TEXT_SIZE, context.getResources().getInteger(R.integer.default_text_size));
|
|
|
|
mNicknameOnly = preferences.getBoolean(KEY_NICKNAME_ONLY, false);
|
2015-01-26 17:09:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class DirectMessageEntry {
|
|
|
|
|
|
|
|
public final long account_id, conversation_id;
|
|
|
|
public final String screen_name, name;
|
|
|
|
|
|
|
|
DirectMessageEntry(Cursor cursor) {
|
|
|
|
account_id = cursor.getLong(ConversationEntries.IDX_ACCOUNT_ID);
|
|
|
|
conversation_id = cursor.getLong(ConversationEntries.IDX_CONVERSATION_ID);
|
|
|
|
screen_name = cursor.getString(ConversationEntries.IDX_SCREEN_NAME);
|
|
|
|
name = cursor.getString(ConversationEntries.IDX_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public DirectMessageEntry getEntry(final int position) {
|
|
|
|
final Cursor c = mCursor;
|
|
|
|
if (c == null || c.isClosed() || !c.moveToPosition(position)) return null;
|
|
|
|
return new DirectMessageEntry(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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.profile_image: {
|
|
|
|
// if (mContext instanceof Activity) {
|
|
|
|
// final long account_id = getAccountId(position);
|
|
|
|
// final long user_id = getConversationId(position);
|
|
|
|
// final String screen_name = getScreenName(position);
|
|
|
|
// openUserProfile(mContext, account_id, user_id, screen_name, null);
|
|
|
|
// }
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setListener(MessageEntriesAdapterListener listener) {
|
|
|
|
mListener = listener;
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface MessageEntriesAdapterListener {
|
|
|
|
public void onEntryClick(int position, DirectMessageEntry entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|