Support filter emoticon

This commit is contained in:
NekoInverter 2020-04-26 14:50:44 +08:00 committed by 世界
parent 21dc1f60bc
commit b2bd9cc0bc
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
4 changed files with 34 additions and 10 deletions

View File

@ -375,6 +375,7 @@ public class MessagesController extends BaseController implements NotificationCe
public ArrayList<Integer> neverShow = new ArrayList<>();
public LongSparseArray<Integer> pinnedDialogs = new LongSparseArray<>();
public ArrayList<TLRPC.Dialog> dialogs = new ArrayList<>();
public String emoticon;
}
private DialogFilter sortingDialogFilter;

View File

@ -304,7 +304,7 @@ public class MessagesStorage extends BaseController {
database.executeFast("CREATE INDEX IF NOT EXISTS folder_id_idx_dialogs ON dialogs(folder_id);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS flags_idx_dialogs ON dialogs(flags);").stepThis().dispose();
database.executeFast("CREATE TABLE dialog_filter(id INTEGER PRIMARY KEY, ord INTEGER, unread_count INTEGER, flags INTEGER, title TEXT)").stepThis().dispose();
database.executeFast("CREATE TABLE dialog_filter_neko(id INTEGER PRIMARY KEY, ord INTEGER, unread_count INTEGER, flags INTEGER, title TEXT, emoticon TEXT)").stepThis().dispose();
database.executeFast("CREATE TABLE dialog_filter_ep(id INTEGER, peer INTEGER, PRIMARY KEY (id, peer))").stepThis().dispose();
database.executeFast("CREATE TABLE dialog_filter_pin_v2(id INTEGER, peer INTEGER, pin INTEGER, PRIMARY KEY (id, peer))").stepThis().dispose();
@ -420,6 +420,11 @@ public class MessagesStorage extends BaseController {
FileLog.e(e2);
}
}
try {
database.executeFast("CREATE TABLE IF NOT EXISTS dialog_filter_neko(id INTEGER PRIMARY KEY, ord INTEGER, unread_count INTEGER, flags INTEGER, title TEXT, emoticon TEXT)").stepThis().dispose();
} catch (Exception e) {
FileLog.e(e);
}
if (version < LAST_DB_VERSION) {
updateDbToLastVersion(version);
}
@ -1593,7 +1598,7 @@ public class MessagesStorage extends BaseController {
usersToLoad.add(getUserConfig().getClientUserId());
SQLiteCursor filtersCursor = database.queryFinalized("SELECT id, ord, unread_count, flags, title FROM dialog_filter WHERE 1");
SQLiteCursor filtersCursor = database.queryFinalized("SELECT id, ord, unread_count, flags, title, emoticon FROM dialog_filter_neko WHERE 1");
boolean updateCounters = false;
while (filtersCursor.next()) {
@ -1603,6 +1608,7 @@ public class MessagesStorage extends BaseController {
filter.pendingUnreadCount = filter.unreadCount = -1;//filtersCursor.intValue(2);
filter.flags = filtersCursor.intValue(3);
filter.name = filtersCursor.stringValue(4);
filter.emoticon = filtersCursor.stringValue(5);
dialogFilters.add(filter);
dialogFiltersMap.put(filter.id, filter);
filtersById.put(filter.id, filter);
@ -2063,12 +2069,17 @@ public class MessagesStorage extends BaseController {
dialogFiltersMap.put(filter.id, filter);
}
SQLitePreparedStatement state = database.executeFast("REPLACE INTO dialog_filter VALUES(?, ?, ?, ?, ?)");
SQLitePreparedStatement state = database.executeFast("REPLACE INTO dialog_filter_neko VALUES(?, ?, ?, ?, ?, ?)");
state.bindInteger(1, filter.id);
state.bindInteger(2, filter.order);
state.bindInteger(3, filter.unreadCount);
state.bindInteger(4, filter.flags);
state.bindString(5, filter.name);
if (filter.emoticon != null) {
state.bindString(6, filter.emoticon);
} else {
state.bindNull(6);
}
state.step();
state.dispose();
if (peers) {
@ -2169,6 +2180,10 @@ public class MessagesStorage extends BaseController {
changed = true;
filter.name = newFilter.title;
}
if (!TextUtils.equals(filter.emoticon, newFilter.emoticon)) {
changed = true;
filter.emoticon = newFilter.emoticon;
}
if (filter.flags != newFlags) {
filter.flags = newFlags;
changed = true;
@ -2315,6 +2330,7 @@ public class MessagesStorage extends BaseController {
filter.id = newFilter.id;
filter.flags = newFlags;
filter.name = newFilter.title;
filter.emoticon = newFilter.emoticon;
filter.pendingUnreadCount = -1;
for (int c = 0; c < 2; c++) {
if (c == 0) {
@ -2477,7 +2493,7 @@ public class MessagesStorage extends BaseController {
try {
dialogFilters.remove(filter);
dialogFiltersMap.remove(filter.id);
database.executeFast("DELETE FROM dialog_filter WHERE id = " + filter.id).stepThis().dispose();
database.executeFast("DELETE FROM dialog_filter_neko WHERE id = " + filter.id).stepThis().dispose();
database.executeFast("DELETE FROM dialog_filter_ep WHERE id = " + filter.id).stepThis().dispose();
database.executeFast("DELETE FROM dialog_filter_pin_v2 WHERE id = " + filter.id).stepThis().dispose();
} catch (Exception e) {
@ -2507,7 +2523,7 @@ public class MessagesStorage extends BaseController {
public void saveDialogFiltersOrderInternal() {
try {
SQLitePreparedStatement state = database.executeFast("UPDATE dialog_filter SET ord = ?, flags = ? WHERE id = ?");
SQLitePreparedStatement state = database.executeFast("UPDATE dialog_filter_neko SET ord = ?, flags = ? WHERE id = ?");
for (int a = 0, N = dialogFilters.size(); a < N ;a++) {
MessagesController.DialogFilter filter = dialogFilters.get(a);
state.requery();

View File

@ -3000,7 +3000,18 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
filterTabsView.removeTabs();
if (!NekoConfig.hideAllTab) filterTabsView.addTab(Integer.MAX_VALUE, LocaleController.getString("FilterAllChats", R.string.FilterAllChats));
for (int a = 0, N = filters.size(); a < N; a++) {
filterTabsView.addTab(a, filters.get(a).name);
MessagesController.DialogFilter dialogFilter = filters.get(a);
switch (NekoConfig.tabsTitleType) {
case NekoConfig.TITLE_TYPE_TEXT:
filterTabsView.addTab(a, dialogFilter.name);
break;
case NekoConfig.TITLE_TYPE_ICON:
filterTabsView.addTab(a, dialogFilter.emoticon != null ? dialogFilter.emoticon : "📂");
break;
case NekoConfig.TITLE_TYPE_MIX:
filterTabsView.addTab(a, dialogFilter.emoticon != null ? dialogFilter.emoticon + " " + dialogFilter.name : "📂 " + dialogFilter.name);
break;
}
}
id = filterTabsView.getCurrentTabId();
if (id >= 0) {

View File

@ -96,8 +96,4 @@
<string name="TabTitleTypeText">Titles</string>
<string name="TabTitleTypeIcon">Emoticons</string>
<string name="TabTitleTypeMix">Emoticons with titles</string>
<string name="ConfirmAVMessage">Confirm sending video/voice message</string>
<string name="AskBeforeCalling">Ask before calling</string>
<string name="ConfirmCall">Confirm calling</string>
<string name="CallTo">Call to **%1$s**?</string>
</resources>