Skip to content

Commit

Permalink
修复名称过长末尾变为...时找不到撤回消息的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonQS committed Jun 24, 2018
1 parent 9af4b24 commit d7da484
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 38 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ log_wx
alipay/
libs/

*.properties

# Java compiled classes #
*.class

Expand Down
17 changes: 0 additions & 17 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,6 @@
android:resource="@xml/provider_paths" />
</provider>

<!-- alipay sdk begin -->

<activity
android:name="com.alipay.sdk.app.H5PayActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:exported="false"
android:screenOrientation="behind"
android:windowSoftInputMode="adjustResize|stateHidden"></activity>
<activity
android:name="com.alipay.sdk.app.H5AuthActivity"
android:configChanges="orientation|keyboardHidden|navigation"
android:exported="false"
android:screenOrientation="behind"
android:windowSoftInputMode="adjustResize|stateHidden"></activity>

<!-- alipay sdk end -->

</application>


Expand Down
33 changes: 23 additions & 10 deletions app/src/main/java/com/qsboy/antirecall/access/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import java.util.ArrayList;
import java.util.List;

import static com.qsboy.antirecall.ui.App.addedMessage;
import static com.qsboy.antirecall.utils.ImageHelper.searchImageFile;

public abstract class Client {

static String added = "";
AccessibilityNodeInfo titleNode;
AccessibilityNodeInfo chatGroupViewNode;
AccessibilityNodeInfo redPegNode;
Expand Down Expand Up @@ -164,10 +164,11 @@ private void onOtherMsg() {
addMsg(false);
}

// TODO: 23/06/2018 撤回的地方名字太长会用...表示 需要模糊搜索
// TODO: 如果有 qq 表情的话(非常规 ascii) 把它转义成 斜杠+描述 的形式
public void addMsg(boolean force) {
String temp = title + " - " + subName + " : " + message;
if (added.equals(temp))
if (addedMessage.equals(temp))
return;
// 不添加"撤回了一条消息"
if (RECALL.equals(message))
Expand All @@ -179,9 +180,8 @@ public void addMsg(boolean force) {
return;
}
}
added = temp;
Log.e(TAG, "Add message: " + added);
dao.addMessage(title, subName, message);
addedMessage = temp;
Log.e(TAG, "Add Msg: " + addedMessage + " " + dao.addMessage(title, subName, message));
}

private class Recalls {
Expand Down Expand Up @@ -263,8 +263,11 @@ private void findRecallByContext(ArrayList<Integer> prevList, ArrayList<Integer>
int prevPos = -1;
int nextPos = -1;
int distance = unknownRecalls + 5;
for (Integer p : prevList) {
for (Integer n : nextList) {
// 先找新消息
for (int i = prevList.size() - 1; i >= 0; i--) {
Integer p = prevList.get(i);
for (int i1 = nextList.size() - 1; i1 >= 0; i1--) {
Integer n = nextList.get(i1);
if (n - p == unknownRecalls + 1) {
// 如果上下文的距离刚好就是撤回的数量 那就直接拿来找
distance = n - p;
Expand All @@ -273,13 +276,15 @@ private void findRecallByContext(ArrayList<Integer> prevList, ArrayList<Integer>
break;
} else
// 如果上下文之间漏加了或者多加了 那就取最近的一对
if (n - p < distance) {
if (n - p < distance && n - p > 2) {
// 找到距离最近的
distance = n - p;
prevPos = p;
nextPos = n;
}
}
if (nextPos - prevPos == unknownRecalls + 1)
break;
}
Log.i(TAG, "findRecallByContext: [ " + prevPos + " - " + nextPos + " ]");

Expand All @@ -291,6 +296,8 @@ private void findRecallByContext(ArrayList<Integer> prevList, ArrayList<Integer>
SparseArray<Messages> map = new SparseArray<>();
for (int i = 0, j = 0, k = 0; k < 10; k++) {
// Log.d(TAG, "findRecallByContext: [" + i + " " + j + "] - " + " [" + (prevPos + i) + " " + (nextPos - j) + "] - " + subName);
if (prevPos + i >= nextPos || nextPos - j <= prevPos)
break;
Messages msgPrev = findNext(prevPos + i, entries.get(topPos + i + 1).subName);
Messages msgNext = findPrev(nextPos - j, entries.get(botPos - j - 1).subName);
Log.i(TAG, "findRecallByContext: \n" +
Expand Down Expand Up @@ -354,7 +361,10 @@ private Messages findNext(int prevPos, String subName) {
}
if ((messages = dao.queryById(title, prevPos)) == null)
continue;
if (!messages.getSubName().equals(subName))
if (subName.endsWith("...")) {
if (!subName.contains(messages.getSubName().substring(0, messages.getSubName().length() - 4)))
continue;
} else if (!messages.getSubName().equals(subName))
continue;
break;
}
Expand Down Expand Up @@ -386,7 +396,10 @@ private Messages findPrev(int nextPos, String subName) {
if ((messages = dao.queryById(title, nextPos)) == null)
continue;
// 判断撤回人名字是否一致
if (!messages.getSubName().equals(subName))
if (subName.endsWith("...")) {
if (!subName.contains(messages.getSubName().substring(0, messages.getSubName().length() - 4)))
continue;
} else if (!messages.getSubName().equals(subName))
continue;
// 找到了
break;
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/com/qsboy/antirecall/db/Dao.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,29 @@ public int getMaxID(String name) {
if (!cursor.moveToFirst()) {
return 0;
}
return cursor.getInt(0);
int maxID = cursor.getInt(0);
Log.i(TAG, "getMaxID: " + maxID);
return maxID;
}

/**
* @param name 联系人名字
* @param subName 群昵称
* @param message 消息记录
*/
public void addMessage(String name, String subName, String message) {
this.addMessage(name, subName, message, new Date().getTime());
public long addMessage(String name, String subName, String message) {
return this.addMessage(name, subName, message, new Date().getTime());
}

public void addMessage(String name, String subName, String message, long time) {
public long addMessage(String name, String subName, String message, long time) {
if (subName == null || subName.equals(""))
subName = name;
createTableIfNotExists(name);
ContentValues values = new ContentValues();
values.put(Column_SubName, subName);
values.put(Column_Message, message);
values.put(Column_Time, time);
db.insert(getSafeName(name), null, values);
return db.insert(getSafeName(name), null, values);
}

public void addRecall(Messages messages) {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/qsboy/antirecall/ui/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

public class App extends Application {

public static final int LaunchDelayTime = 1000;
public static final int LaunchDelayTime = 750;
public static String addedMessage = "";

public static final int THEME_RED = 1;
public static final int THEME_GREEN = 2;
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/qsboy/antirecall/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class MainActivity extends AppCompatActivity {
private List<Fragment> fragmentList = new ArrayList<>();

// TODO: 03/06/2018 顶部加filter
// TODO: 20/06/2018 请求白名单

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -167,4 +168,9 @@ public void prepareDataForTest() {
Log.i(TAG, "prepareDataForTest: tvTime: " + (out.getTime() - in.getTime()));
}

private void addData() {
Dao dao = Dao.getInstance(this, Dao.DB_NAME_QQ);
dao.addMessage("编程团老年人水群", "ryuujo", " ", Calendar.getInstance().getTime().getTime());

}
}
20 changes: 20 additions & 0 deletions app/src/main/java/com/qsboy/antirecall/ui/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.qsboy.antirecall.ui;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
Expand All @@ -17,6 +18,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.StrictMode;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.graphics.drawable.VectorDrawableCompat;
Expand Down Expand Up @@ -192,6 +194,24 @@ public void error() {
}
startActivity(intent);
}
// public static void shareFile(Context context, Uri uri) {
// File file = new File("\sdcard\android123.cwj"); //附件文件地址
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
builder.detectFileUriExposure();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("subject", ""); //
intent.putExtra("body", ""); // 正文
// intent.putExtra(Intent.EXTRA_STREAM, uri); // 添加附件,附件为file对象
// if (uri.toString().endsWith(".gz")) {
// intent.setType("application/x-gzip"); // 如果是gz使用gzip的mime
// } else if (uri.toString().endsWith(".txt")) {
// intent.setType("text/plain"); // 纯文本则用text/plain的mime
// } else {
intent.setType("application/octet-stream"); // 其他的均使用流当做二进制数据来发送
// }
startActivity(intent); // 调用系统的mail客户端进行发送
// }
});

view.findViewById(R.id.btn_donate).setOnClickListener(v -> {
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/com/qsboy/antirecall/utils/XToastPro.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ private XToastPro(Context context) {

public static XToastPro build(Context context, String text) {
XToastPro toast = new XToastPro(context);
if (ll == null) {
Log.e(TAG, "build: is null");
if (ll == null)
ll = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.toast_pro, null);
} else Log.w(TAG, "build: not null");
FrameLayout item = (FrameLayout) LayoutInflater.from(context).inflate(R.layout.toast_pro_item, null);
ImageView iv = item.findViewById(R.id.toast_iv);
TextView tv = item.findViewById(R.id.toast_tv);
Expand Down

0 comments on commit d7da484

Please sign in to comment.