Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

统一黑白名单,支持规则优先级、搜索、多选管理 #84

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,25 @@

import android.database.Cursor;
import android.graphics.Typeface;
import androidx.recyclerview.widget.RecyclerView;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.crossbowffs.nekosms.R;
import com.crossbowffs.nekosms.data.SmsMessageData;
import com.crossbowffs.nekosms.loader.BlockedSmsLoader;
import com.crossbowffs.nekosms.widget.RecyclerCursorAdapter;

/* package */ class BlockedMessagesAdapter extends RecyclerCursorAdapter<BlockedMessagesAdapter.BlockedSmsItemHolder> {
public class BlockedSmsItemHolder extends RecyclerView.ViewHolder {
public final TextView mSenderTextView;
public final TextView mTimeSentTextView;
public final TextView mBodyTextView;
public SmsMessageData mMessageData;

public BlockedSmsItemHolder(View itemView) {
super(itemView);
import java.util.Set;

mSenderTextView = (TextView)itemView.findViewById(R.id.blocked_message_sender_textview);
mTimeSentTextView = (TextView)itemView.findViewById(R.id.blocked_message_time_sent_textview);
mBodyTextView = (TextView)itemView.findViewById(R.id.blocked_message_body_textview);
}
}
/* package */ class BlockedMessagesAdapter extends RecyclerCursorAdapter<BlockedMessagesAdapter.BlockedSmsItemHolder> {

private final BlockedMessagesFragment mFragment;
private OnItemClickListener onItemClickListener;

public BlockedMessagesAdapter(BlockedMessagesFragment fragment) {
mFragment = fragment;
Expand All @@ -48,33 +39,74 @@ protected int[] onBindColumns(Cursor cursor) {
}

@Override
public void onBindViewHolder(BlockedSmsItemHolder holder, Cursor cursor) {
public void onBindViewHolder(BlockedSmsItemHolder holder,Cursor cursor) {
Set<Long> selectedMsgIds = mFragment.getSelectedMsgIds();
final SmsMessageData messageData = BlockedSmsLoader.get().getData(cursor, getColumns(), holder.mMessageData);
holder.mMessageData = messageData;

int subid = messageData.getSubId();
String sender = messageData.getSender();
long timeSent = messageData.getTimeSent();
String body = messageData.getBody();
CharSequence timeSentString = DateUtils.getRelativeTimeSpanString(mFragment.getContext(), timeSent);

holder.mSenderTextView.setText(sender);
holder.mSenderTextView.setText(sender+" (SIM "+subid+")");
holder.mTimeSentTextView.setText(timeSentString);
holder.mBodyTextView.setText(body);
if (messageData.isRead()) {
holder.mSenderTextView.setTypeface(null, Typeface.NORMAL);
holder.mTimeSentTextView.setTypeface(null, Typeface.NORMAL);
holder.mBodyTextView.setTypeface(null, Typeface.NORMAL);
} else {
holder.mSenderTextView.setTypeface(null, Typeface.BOLD);
holder.mTimeSentTextView.setTypeface(null, Typeface.BOLD);
holder.mBodyTextView.setTypeface(null, Typeface.BOLD);
holder.mSenderTextView.setTypeface(null, Typeface.BOLD_ITALIC);
holder.mTimeSentTextView.setTypeface(null, Typeface.BOLD_ITALIC);
holder.mBodyTextView.setTypeface(null, Typeface.BOLD_ITALIC);
}

if (selectedMsgIds.contains(messageData.getId())) {
holder.itemView.setAlpha(0.2f);
} else {
holder.itemView.setAlpha(1.0f);
}

if (onItemClickListener != null) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onItemClickListener.onItemClick(v, messageData);
}
});
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
//return: true:不继续传递事件,告诉系统此事件已被处理;false:继续传递事件,上级可继续处理
return onItemClickListener.onItemLongClick(v, messageData);
}
});
}
}

public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}

public interface OnItemClickListener {
void onItemClick(View view, SmsMessageData messageData);
boolean onItemLongClick(View view, SmsMessageData messageData);
}

public class BlockedSmsItemHolder extends RecyclerView.ViewHolder {
public final TextView mSenderTextView;
public final TextView mTimeSentTextView;
public final TextView mBodyTextView;
public SmsMessageData mMessageData;

holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mFragment.showMessageDetailsDialog(messageData);
}
});
public BlockedSmsItemHolder(View itemView) {
super(itemView);
mSenderTextView = (TextView) itemView.findViewById(R.id.blocked_message_sender_textview);
mTimeSentTextView = (TextView) itemView.findViewById(R.id.blocked_message_time_sent_textview);
mBodyTextView = (TextView) itemView.findViewById(R.id.blocked_message_body_textview);
}
}

}
Loading