Java Code Examples for org.telegram.SQLite.SQLiteCursor

The following examples show how to use org.telegram.SQLite.SQLiteCursor. These examples are extracted from open source projects. 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
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
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
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 Project: Telegram   Source File: SearchAdapterHelper.java    License: 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;
}