org.telegram.SQLite.SQLiteCursor Java Examples

The following examples show how to use org.telegram.SQLite.SQLiteCursor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchAdapterHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public boolean loadRecentHashtags() {
    if (hashtagsLoadedFromDb) {
        return true;
    }
    MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() -> {
        try {
            SQLiteCursor cursor = MessagesStorage.getInstance(currentAccount).getDatabase().queryFinalized("SELECT id, date FROM hashtag_recent_v2 WHERE 1");
            final ArrayList<HashtagObject> arrayList = new ArrayList<>();
            final HashMap<String, HashtagObject> hashMap = new HashMap<>();
            while (cursor.next()) {
                HashtagObject hashtagObject = new HashtagObject();
                hashtagObject.hashtag = cursor.stringValue(0);
                hashtagObject.date = cursor.intValue(1);
                arrayList.add(hashtagObject);
                hashMap.put(hashtagObject.hashtag, hashtagObject);
            }
            cursor.dispose();
            Collections.sort(arrayList, (lhs, rhs) -> {
                if (lhs.date < rhs.date) {
                    return 1;
                } else if (lhs.date > rhs.date) {
                    return -1;
                } else {
                    return 0;
                }
            });
            AndroidUtilities.runOnUIThread(() -> setHashtags(arrayList, hashMap));
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
    return false;
}
 
Example #2
Source File: SearchAdapterHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public boolean loadRecentHashtags() {
    if (hashtagsLoadedFromDb) {
        return true;
    }
    MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() -> {
        try {
            SQLiteCursor cursor = MessagesStorage.getInstance(currentAccount).getDatabase().queryFinalized("SELECT id, date FROM hashtag_recent_v2 WHERE 1");
            final ArrayList<HashtagObject> arrayList = new ArrayList<>();
            final HashMap<String, HashtagObject> hashMap = new HashMap<>();
            while (cursor.next()) {
                HashtagObject hashtagObject = new HashtagObject();
                hashtagObject.hashtag = cursor.stringValue(0);
                hashtagObject.date = cursor.intValue(1);
                arrayList.add(hashtagObject);
                hashMap.put(hashtagObject.hashtag, hashtagObject);
            }
            cursor.dispose();
            Collections.sort(arrayList, (lhs, rhs) -> {
                if (lhs.date < rhs.date) {
                    return 1;
                } else if (lhs.date > rhs.date) {
                    return -1;
                } else {
                    return 0;
                }
            });
            AndroidUtilities.runOnUIThread(() -> setHashtags(arrayList, hashMap));
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
    return false;
}
 
Example #3
Source File: SearchAdapterHelper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public boolean loadRecentHashtags() {
    if (hashtagsLoadedFromDb) {
        return true;
    }
    MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() -> {
        try {
            SQLiteCursor cursor = MessagesStorage.getInstance(currentAccount).getDatabase().queryFinalized("SELECT id, date FROM hashtag_recent_v2 WHERE 1");
            final ArrayList<HashtagObject> arrayList = new ArrayList<>();
            final HashMap<String, HashtagObject> hashMap = new HashMap<>();
            while (cursor.next()) {
                HashtagObject hashtagObject = new HashtagObject();
                hashtagObject.hashtag = cursor.stringValue(0);
                hashtagObject.date = cursor.intValue(1);
                arrayList.add(hashtagObject);
                hashMap.put(hashtagObject.hashtag, hashtagObject);
            }
            cursor.dispose();
            Collections.sort(arrayList, (lhs, rhs) -> {
                if (lhs.date < rhs.date) {
                    return 1;
                } else if (lhs.date > rhs.date) {
                    return -1;
                } else {
                    return 0;
                }
            });
            AndroidUtilities.runOnUIThread(() -> setHashtags(arrayList, hashMap));
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
    return false;
}
 
Example #4
Source File: SearchAdapterHelper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public boolean loadRecentHashtags() {
    if (hashtagsLoadedFromDb) {
        return true;
    }
    MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() -> {
        try {
            SQLiteCursor cursor = MessagesStorage.getInstance(currentAccount).getDatabase().queryFinalized("SELECT id, date FROM hashtag_recent_v2 WHERE 1");
            final ArrayList<HashtagObject> arrayList = new ArrayList<>();
            final HashMap<String, HashtagObject> hashMap = new HashMap<>();
            while (cursor.next()) {
                HashtagObject hashtagObject = new HashtagObject();
                hashtagObject.hashtag = cursor.stringValue(0);
                hashtagObject.date = cursor.intValue(1);
                arrayList.add(hashtagObject);
                hashMap.put(hashtagObject.hashtag, hashtagObject);
            }
            cursor.dispose();
            Collections.sort(arrayList, (lhs, rhs) -> {
                if (lhs.date < rhs.date) {
                    return 1;
                } else if (lhs.date > rhs.date) {
                    return -1;
                } else {
                    return 0;
                }
            });
            AndroidUtilities.runOnUIThread(() -> setHashtags(arrayList, hashMap));
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
    return false;
}