mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-22 21:58:53 +01:00
Use ListView for QK Reply
Fixes height and dismissal issues
This commit is contained in:
@@ -65,7 +65,7 @@ public abstract class RecyclerCursorAdapter<VH extends RecyclerView.ViewHolder,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return mCursor == null ? 0 : mCursor.getColumnCount();
|
return mCursor == null ? 0 : mCursor.getCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract DataType getItem(int position);
|
protected abstract DataType getItem(int position);
|
||||||
|
|||||||
@@ -9,28 +9,24 @@ import android.database.Cursor;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.widget.ListView;
|
||||||
|
|
||||||
import com.moez.QKSMS.R;
|
import com.moez.QKSMS.R;
|
||||||
|
import com.moez.QKSMS.common.utils.KeyboardUtils;
|
||||||
import com.moez.QKSMS.data.Conversation;
|
import com.moez.QKSMS.data.Conversation;
|
||||||
import com.moez.QKSMS.data.ConversationLegacy;
|
import com.moez.QKSMS.data.ConversationLegacy;
|
||||||
import com.moez.QKSMS.data.Message;
|
import com.moez.QKSMS.data.Message;
|
||||||
import com.moez.QKSMS.interfaces.ActivityLauncher;
|
import com.moez.QKSMS.interfaces.ActivityLauncher;
|
||||||
import com.moez.QKSMS.service.CopyUnreadMessageTextService;
|
import com.moez.QKSMS.service.CopyUnreadMessageTextService;
|
||||||
import com.moez.QKSMS.service.DeleteUnreadMessageService;
|
import com.moez.QKSMS.service.DeleteUnreadMessageService;
|
||||||
import com.moez.QKSMS.common.utils.CursorUtils;
|
|
||||||
import com.moez.QKSMS.common.utils.KeyboardUtils;
|
|
||||||
import com.moez.QKSMS.transaction.SmsHelper;
|
import com.moez.QKSMS.transaction.SmsHelper;
|
||||||
import com.moez.QKSMS.ui.MainActivity;
|
import com.moez.QKSMS.ui.MainActivity;
|
||||||
import com.moez.QKSMS.ui.base.QKPopupActivity;
|
import com.moez.QKSMS.ui.base.QKPopupActivity;
|
||||||
import com.moez.QKSMS.ui.messagelist.MessageColumns;
|
import com.moez.QKSMS.ui.messagelist.MessageColumns;
|
||||||
import com.moez.QKSMS.ui.messagelist.MessageListAdapter;
|
|
||||||
import com.moez.QKSMS.ui.view.ComposeView;
|
import com.moez.QKSMS.ui.view.ComposeView;
|
||||||
import com.moez.QKSMS.ui.view.MessageListRecyclerView;
|
|
||||||
import com.moez.QKSMS.ui.view.WrappingLinearLayoutManager;
|
|
||||||
import com.moez.QKSMS.ui.welcome.DemoConversationCursorLoader;
|
import com.moez.QKSMS.ui.welcome.DemoConversationCursorLoader;
|
||||||
|
|
||||||
public class QKReplyActivity extends QKPopupActivity implements DialogInterface.OnDismissListener,
|
public class QKReplyActivity extends QKPopupActivity implements DialogInterface.OnDismissListener,
|
||||||
@@ -52,9 +48,8 @@ public class QKReplyActivity extends QKPopupActivity implements DialogInterface.
|
|||||||
private Cursor mCursor;
|
private Cursor mCursor;
|
||||||
private boolean mShowUnreadOnly = true;
|
private boolean mShowUnreadOnly = true;
|
||||||
|
|
||||||
private MessageListRecyclerView mRecyclerView;
|
private ListView mListView;
|
||||||
private WrappingLinearLayoutManager mLayoutManager;
|
private QKReplyAdapter mAdapter;
|
||||||
private MessageListAdapter mAdapter;
|
|
||||||
private ComposeView mComposeView;
|
private ComposeView mComposeView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,21 +75,10 @@ public class QKReplyActivity extends QKPopupActivity implements DialogInterface.
|
|||||||
mComposeView.setLabel("QKReply");
|
mComposeView.setLabel("QKReply");
|
||||||
mComposeView.refresh();
|
mComposeView.refresh();
|
||||||
|
|
||||||
mLayoutManager = new WrappingLinearLayoutManager(this);
|
mAdapter = new QKReplyAdapter(this);
|
||||||
mLayoutManager.setStackFromEnd(true);
|
|
||||||
mAdapter = new MessageListAdapter(this);
|
|
||||||
mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
|
|
||||||
@Override
|
|
||||||
public void onChanged() {
|
|
||||||
LinearLayoutManager manager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
|
|
||||||
int position = CursorUtils.isValid(mCursor) && mCursor.getCount() > 0 ? mCursor.getCount() - 1 : 0;
|
|
||||||
manager.smoothScrollToPosition(mRecyclerView, null, position);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mRecyclerView = (MessageListRecyclerView) findViewById(R.id.popup_messages);
|
mListView = (ListView) findViewById(R.id.popup_messages);
|
||||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
mListView.setAdapter(mAdapter);
|
||||||
mRecyclerView.setAdapter(mAdapter);
|
|
||||||
|
|
||||||
// Disable the compose view for the welcome screen (so that they can't send texts to nobody)
|
// Disable the compose view for the welcome screen (so that they can't send texts to nobody)
|
||||||
if (extras.getLong(EXTRA_THREAD_ID) == DemoConversationCursorLoader.THREAD_ID_WELCOME_SCREEN) {
|
if (extras.getLong(EXTRA_THREAD_ID) == DemoConversationCursorLoader.THREAD_ID_WELCOME_SCREEN) {
|
||||||
@@ -278,8 +262,6 @@ public class QKReplyActivity extends QKPopupActivity implements DialogInterface.
|
|||||||
mAdapter.changeCursor(data);
|
mAdapter.changeCursor(data);
|
||||||
}
|
}
|
||||||
mCursor = data;
|
mCursor = data;
|
||||||
|
|
||||||
mRecyclerView.scrollToPosition(CursorUtils.isValid(mCursor) && mCursor.getCount() > 0 ? mCursor.getCount() - 1 : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLoaderReset(Loader<Cursor> loader) {
|
public void onLoaderReset(Loader<Cursor> loader) {
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.moez.QKSMS.ui.popup;
|
||||||
|
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
|
import com.moez.QKSMS.ui.base.QKActivity;
|
||||||
|
import com.moez.QKSMS.ui.messagelist.MessageListAdapter;
|
||||||
|
import com.moez.QKSMS.ui.messagelist.MessageListViewHolder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ArrayAdapter wrapper of MessageListAdapter to allow regular ListView usage in QKReplyActivity
|
||||||
|
* RecyclerView in variable-height windows causes a lot of issues
|
||||||
|
*/
|
||||||
|
public class QKReplyAdapter extends ArrayAdapter {
|
||||||
|
|
||||||
|
private MessageListAdapter mMessageListAdapter;
|
||||||
|
|
||||||
|
public QKReplyAdapter(QKActivity context) {
|
||||||
|
super(context, 0);
|
||||||
|
mMessageListAdapter = new MessageListAdapter(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
MessageListViewHolder holder;
|
||||||
|
|
||||||
|
if (convertView == null) {
|
||||||
|
holder = mMessageListAdapter.onCreateViewHolder(parent, getItemViewType(position));
|
||||||
|
convertView = holder.itemView;
|
||||||
|
convertView.setTag(holder);
|
||||||
|
} else {
|
||||||
|
holder = (MessageListViewHolder) convertView.getTag();
|
||||||
|
}
|
||||||
|
|
||||||
|
mMessageListAdapter.bindViewHolder(holder, position);
|
||||||
|
return holder.itemView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return mMessageListAdapter != null ? mMessageListAdapter.getCount() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
return mMessageListAdapter.getItemViewType(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getViewTypeCount() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeCursor(Cursor cursor) {
|
||||||
|
mMessageListAdapter.changeCursor(cursor);
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:foreground="@drawable/ab_shadow">
|
android:foreground="@drawable/ab_shadow">
|
||||||
|
|
||||||
<com.moez.QKSMS.ui.view.MessageListRecyclerView
|
<ListView
|
||||||
android:id="@+id/popup_messages"
|
android:id="@+id/popup_messages"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
Reference in New Issue
Block a user