Skip to content

Commit

Permalink
长按删除单条日志记录
Browse files Browse the repository at this point in the history
  • Loading branch information
pppscn committed Mar 4, 2021
1 parent 8403a5e commit 02d4845
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 237 deletions.
Binary file modified app/release/SmsForwarder_release_20210304_1.4.0.apk
Binary file not shown.
59 changes: 47 additions & 12 deletions app/src/main/java/com/idormy/sms/forwarder/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
Expand All @@ -44,13 +45,25 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
private List<LogVo> logVos = new ArrayList<>();
private LogAdapter adapter;
private ReFlashListView listView;
//SIM卡信息
//private Map<String, Map> SimInfo = new HashMap();

@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "oncreate");
super.onCreate(savedInstanceState);

//检查权限是否获取
checkPermission();

//获取本机号码(注意:这里获取的不一定是卡槽1的)
TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String Line1Number = mTelephonyMgr.getLine1Number();
Log.d(TAG, "Line1Number: " + Line1Number);

//获取SIM卡信息
getSimInfo(Line1Number);
//MyApplication appContext = ((MyApplication) getApplicationContext());
//appContext.setSimInfo(SimInfo);

setContentView(R.layout.activity_main);
LogUtil.init(this);
// 先拿到数据并放在适配器上
Expand All @@ -67,18 +80,40 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
}
});

//检查权限是否获取
checkPermission();
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
//定义AlertDialog.Builder对象,当长按列表项的时候弹出确认删除对话框
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage("确定删除?");
builder.setTitle("提示");

//添加AlertDialog.Builder对象的setPositiveButton()方法
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Long id = logVos.get(position - 1).getId();
Log.d(TAG, "id = " + id);
LogUtil.delLog(id, null);
initTLogs(); //初始化数据
showList(logVos);
Toast.makeText(getBaseContext(), "删除列表项", Toast.LENGTH_SHORT).show();
}
});

//获取本机号码(注意:这里获取的不一定是卡槽1的)
TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String Line1Number = mTelephonyMgr.getLine1Number();
Log.d(TAG, "Line1Number: " + Line1Number);
//添加AlertDialog.Builder对象的setNegativeButton()方法
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {

//获取SIM卡信息
getSimInfo(Line1Number);
//MyApplication appContext = ((MyApplication) getApplicationContext());
//appContext.setSimInfo(SimInfo);
@Override
public void onClick(DialogInterface dialog, int which) {

}
});

builder.create().show();
return true;
}
});
}

// 初始化数据
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/java/com/idormy/sms/forwarder/MyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ public static String getChannelName(Context ctx) {
return channelName;
}

public Map<String, Map> getSimInfo() {
return SimInfo;
}

public void setSimInfo(Map<String, Map> info) {
SimInfo = info;
}

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
Expand Down
149 changes: 75 additions & 74 deletions app/src/main/java/com/idormy/sms/forwarder/model/RuleModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,101 @@
import java.util.Map;

public class RuleModel {
private String TAG = "RuleModel";
private Long id;
public static final String FILED_TRANSPOND_ALL = "transpond_all";
public static final String FILED_PHONE_NUM = "phone_num";
public static final String FILED_MSG_CONTENT = "msg_content";
public static final String FILED_MULTI_MATCH="multi_match";
public static final String FILED_MULTI_MATCH = "multi_match";
public static final Map<String, String> FILED_MAP = new HashMap<String, String>();
static{
FILED_MAP.put("transpond_all", "转发全部");
FILED_MAP.put("phone_num", "手机号");
FILED_MAP.put("msg_content", "内容");
FILED_MAP.put("multi_match", "多重匹配");
}
private String filed;

public static final String CHECK_IS = "is";
public static final String CHECK_CONTAIN = "contain";
public static final String CHECK_START_WITH = "startwith";
public static final String CHECK_END_WITH = "endwith";
public static final String CHECK_NOT_IS = "notis";
public static final Map<String, String> CHECK_MAP = new HashMap<String, String>();

static {
FILED_MAP.put("transpond_all", "转发全部");
FILED_MAP.put("phone_num", "手机号");
FILED_MAP.put("msg_content", "内容");
FILED_MAP.put("multi_match", "多重匹配");
}

static {
CHECK_MAP.put("is", "是");
CHECK_MAP.put("contain", "包含");
CHECK_MAP.put("startwith", "开头是");
CHECK_MAP.put("endwith", "结尾是");
CHECK_MAP.put("notis", "不是");
}

private String TAG = "RuleModel";
private Long id;
private String filed;
private String check;

private String value;

private Long senderId;
private Long time;

public static String getRuleMatch(String filed, String check, String value) {
switch (filed) {
case FILED_TRANSPOND_ALL:
return "全部转发到 ";
default:
return "当 " + FILED_MAP.get(filed) + " " + CHECK_MAP.get(check) + " " + value + " 转发到 ";

}

}

public static String getRuleFiledFromCheckId(int id) {
switch (id) {
case R.id.btnContent:
return FILED_MSG_CONTENT;
case R.id.btnPhone:
return FILED_PHONE_NUM;
case R.id.btnMultiMatch:
return FILED_MULTI_MATCH;
default:
return FILED_TRANSPOND_ALL;
}
}

public static String getRuleCheckFromCheckId(int id) {
switch (id) {
case R.id.btnContain:
return CHECK_CONTAIN;
case R.id.btnStartWith:
return CHECK_START_WITH;
case R.id.btnEndWith:
return CHECK_END_WITH;
case R.id.btnNotIs:
return CHECK_NOT_IS;
default:
return CHECK_IS;
}
}

//字段分支
public boolean checkMsg(SmsVo msg) throws Exception {

//检查这一行和上一行合并的结果是否命中
boolean mixChecked=false;
if(msg!=null){
boolean mixChecked = false;
if (msg != null) {
//先检查规则是否命中
switch (this.filed){
switch (this.filed) {
case FILED_TRANSPOND_ALL:
mixChecked= true;
mixChecked = true;
break;
case FILED_PHONE_NUM:
mixChecked= checkValue(msg.getMobile());
mixChecked = checkValue(msg.getMobile());
break;
case FILED_MSG_CONTENT:
mixChecked= checkValue(msg.getContent());
mixChecked = checkValue(msg.getContent());
break;
case FILED_MULTI_MATCH:
mixChecked= RuleLineUtils.checkRuleLines(msg,this.value);
mixChecked = RuleLineUtils.checkRuleLines(msg, this.value);
break;
default:
break;
Expand All @@ -73,63 +113,52 @@ public boolean checkMsg(SmsVo msg) throws Exception {
}


Log.i(TAG, "rule:"+this+" checkMsg:"+msg+" checked:"+mixChecked);
Log.i(TAG, "rule:" + this + " checkMsg:" + msg + " checked:" + mixChecked);
return mixChecked;

}

//内容分支
public boolean checkValue(String msgValue){
boolean checked=false;
public boolean checkValue(String msgValue) {
boolean checked = false;

if(this.value!=null){
switch (this.check){
if (this.value != null) {
switch (this.check) {
case CHECK_IS:
checked=this.value.equals(msgValue);
checked = this.value.equals(msgValue);
break;
case CHECK_CONTAIN:
if(msgValue!=null){
checked=msgValue.contains(this.value);
if (msgValue != null) {
checked = msgValue.contains(this.value);
}
break;
case CHECK_START_WITH:
if(msgValue!=null){
checked=msgValue.startsWith(this.value);
if (msgValue != null) {
checked = msgValue.startsWith(this.value);
}
break;
case CHECK_END_WITH:
if(msgValue!=null){
checked=msgValue.endsWith(this.value);
if (msgValue != null) {
checked = msgValue.endsWith(this.value);
}
break;
default:
break;
}
}

Log.i(TAG, "checkValue "+msgValue+" "+this.check+" "+this.value+" checked:"+checked);
Log.i(TAG, "checkValue " + msgValue + " " + this.check + " " + this.value + " checked:" + checked);

return checked;

}


public String getRuleMatch() {
switch (filed){
case FILED_TRANSPOND_ALL:
return "全部转发到 ";
default:
return "当 "+FILED_MAP.get(filed)+" "+CHECK_MAP.get(check)+" "+value+" 转发到 ";
}

}
public static String getRuleMatch(String filed, String check, String value) {
switch (filed) {
case FILED_TRANSPOND_ALL:
return "全部转发到 ";
default:
return "当 " + FILED_MAP.get(filed) + " " + CHECK_MAP.get(check) + " " + value + " 转发到 ";

}

}
Expand All @@ -138,8 +167,8 @@ public Long getRuleSenderId() {
return senderId;
}

public int getRuleFiledCheckId(){
switch (filed){
public int getRuleFiledCheckId() {
switch (filed) {
case FILED_MSG_CONTENT:
return R.id.btnContent;
case FILED_PHONE_NUM:
Expand All @@ -151,21 +180,8 @@ public int getRuleFiledCheckId(){
}
}

public static String getRuleFiledFromCheckId(int id){
switch (id){
case R.id.btnContent:
return FILED_MSG_CONTENT;
case R.id.btnPhone:
return FILED_PHONE_NUM;
case R.id.btnMultiMatch:
return FILED_MULTI_MATCH;
default:
return FILED_TRANSPOND_ALL;
}
}

public int getRuleCheckCheckId(){
switch (check){
public int getRuleCheckCheckId() {
switch (check) {
case CHECK_CONTAIN:
return R.id.btnContain;
case CHECK_START_WITH:
Expand All @@ -179,21 +195,6 @@ public int getRuleCheckCheckId(){
}
}

public static String getRuleCheckFromCheckId(int id){
switch (id){
case R.id.btnContain:
return CHECK_CONTAIN;
case R.id.btnStartWith:
return CHECK_START_WITH;
case R.id.btnEndWith:
return CHECK_END_WITH;
case R.id.btnNotIs:
return CHECK_NOT_IS;
default:
return CHECK_IS;
}
}

public Long getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import com.idormy.sms.forwarder.R;

public class LogVo {
private Long id;
private String from;
private String content;
private String simInfo;
private String rule;
private int senderImageId;
private String time;

public LogVo(String from, String content, String simInfo, String time, String rule, int senderImageId) {
public LogVo(Long id, String from, String content, String simInfo, String time, String rule, int senderImageId) {
this.id = id;
this.from = from;
this.content = content;
this.simInfo = simInfo;
Expand All @@ -23,6 +25,10 @@ public LogVo() {

}

public Long getId() {
return id;
}

public String getFrom() {
return from;
}
Expand Down
Loading

0 comments on commit 02d4845

Please sign in to comment.