org.telegram.messenger.MessagesStorage Java Examples

The following examples show how to use org.telegram.messenger.MessagesStorage. 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: ContactsActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void askForPermissons(boolean alert) {
    Activity activity = getParentActivity();
    if (activity == null || !UserConfig.getInstance(currentAccount).syncContacts || activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
        return;
    }
    if (alert && askAboutContacts) {
        AlertDialog.Builder builder = AlertsCreator.createContactsPermissionDialog(activity, new MessagesStorage.IntCallback() {
            @Override
            public void run(int param) {
                askAboutContacts = param != 0;
                MessagesController.getGlobalNotificationsSettings().edit().putBoolean("askAboutContacts", askAboutContacts).commit();
                askForPermissons(false);
            }
        });
        showDialog(builder.create());
        return;
    }
    ArrayList<String> permissons = new ArrayList<>();
    permissons.add(Manifest.permission.READ_CONTACTS);
    permissons.add(Manifest.permission.WRITE_CONTACTS);
    permissons.add(Manifest.permission.GET_ACCOUNTS);
    String[] items = permissons.toArray(new String[permissons.size()]);
    activity.requestPermissions(items, 1);
}
 
Example #2
Source File: DialogsSearchAdapter.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void clearRecentSearch()
{
    recentSearchObjectsById = new LongSparseArray<>();
    recentSearchObjects = new ArrayList<>();
    notifyDataSetChanged();
    MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() ->
    {
        try
        {
            MessagesStorage.getInstance(currentAccount).getDatabase().executeFast("DELETE FROM search_recent WHERE 1").stepThis().dispose();
        }
        catch (Exception e)
        {
            FileLog.e(e);
        }
    });
}
 
Example #3
Source File: BaseLocationAdapter.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void searchBotUser()
{
    if (searchingUser)
    {
        return;
    }
    searchingUser = true;
    TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
    req.username = MessagesController.getInstance(currentAccount).venueSearchBot;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) ->
    {
        if (response != null)
        {
            AndroidUtilities.runOnUIThread(() ->
            {
                TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
                MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                MessagesController.getInstance(currentAccount).putChats(res.chats, false);
                MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
                Location coord = lastSearchLocation;
                lastSearchLocation = null;
                searchPlacesWithQuery(lastSearchQuery, coord, false);
            });
        }
    });
}
 
Example #4
Source File: ContactsActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void askForPermissons(boolean alert) {
    Activity activity = getParentActivity();
    if (activity == null || !UserConfig.getInstance(currentAccount).syncContacts || activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
        return;
    }
    if (alert && askAboutContacts) {
        AlertDialog.Builder builder = AlertsCreator.createContactsPermissionDialog(activity, new MessagesStorage.IntCallback() {
            @Override
            public void run(int param) {
                askAboutContacts = param != 0;
                MessagesController.getGlobalNotificationsSettings().edit().putBoolean("askAboutContacts", askAboutContacts).commit();
                askForPermissons(false);
            }
        });
        showDialog(builder.create());
        return;
    }
    ArrayList<String> permissons = new ArrayList<>();
    permissons.add(Manifest.permission.READ_CONTACTS);
    permissons.add(Manifest.permission.WRITE_CONTACTS);
    permissons.add(Manifest.permission.GET_ACCOUNTS);
    String[] items = permissons.toArray(new String[permissons.size()]);
    activity.requestPermissions(items, 1);
}
 
Example #5
Source File: AlertsCreator.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public static boolean checkSlowMode(Context context, int currentAccount, long did, boolean few) {
    int lowerId = (int) did;
    if (lowerId < 0) {
        TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lowerId);
        if (chat != null && chat.slowmode_enabled && !ChatObject.hasAdminRights(chat)) {
            if (!few) {
                TLRPC.ChatFull chatFull = MessagesController.getInstance(currentAccount).getChatFull(chat.id);
                if (chatFull == null) {
                    chatFull = MessagesStorage.getInstance(currentAccount).loadChatInfo(chat.id, new CountDownLatch(1), false, false);
                }
                if (chatFull != null && chatFull.slowmode_next_send_date >= ConnectionsManager.getInstance(currentAccount).getCurrentTime()) {
                    few = true;
                }
            }
            if (few) {
                AlertsCreator.createSimpleAlert(context, chat.title, LocaleController.getString("SlowmodeSendError", R.string.SlowmodeSendError)).show();
                return true;
            }
        }
    }
    return false;
}
 
Example #6
Source File: ProfileActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private TLRPC.Chat getChat(int chatId)
{
    TLRPC.Chat[] chat = new TLRPC.Chat[] { MessagesController.getInstance(currentAccount).getChat(chatId) };
    if (chat[0] == null)
    {
        final CountDownLatch countDownLatch = new CountDownLatch(1);
        MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() ->
        {
            chat[0] = MessagesStorage.getInstance(currentAccount).getChat(chatId);
            countDownLatch.countDown();
        });
        try
        {
            countDownLatch.await();
        }
        catch (Exception e)
        {
            FileLog.e(e);
        }
    }

    return chat[0];
}
 
Example #7
Source File: BaseLocationAdapter.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void searchBotUser() {
    if (searchingUser) {
        return;
    }
    searchingUser = true;
    TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
    req.username = MessagesController.getInstance(currentAccount).venueSearchBot;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
        if (response != null) {
            AndroidUtilities.runOnUIThread(() -> {
                TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
                MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                MessagesController.getInstance(currentAccount).putChats(res.chats, false);
                MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
                Location coord = lastSearchLocation;
                lastSearchLocation = null;
                searchPlacesWithQuery(lastSearchQuery, coord, false);
            });
        }
    });
}
 
Example #8
Source File: PhotoPickerActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void searchBotUser(boolean gif) {
    if (searchingUser) {
        return;
    }
    searchingUser = true;
    TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
    req.username = gif ? MessagesController.getInstance(currentAccount).gifSearchBot : MessagesController.getInstance(currentAccount).imageSearchBot;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
        if (response != null) {
            AndroidUtilities.runOnUIThread(() -> {
                TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
                MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                MessagesController.getInstance(currentAccount).putChats(res.chats, false);
                MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
                String str = lastSearchImageString;
                lastSearchImageString = null;
                searchImages(gif, str, "", false);
            });
        }
    });
}
 
Example #9
Source File: FilterTabsView.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void setIsEditing(boolean value) {
    isEditing = value;
    editingForwardAnimation = true;
    listView.invalidateViews();
    invalidate();
    if (!isEditing && orderChanged) {
        MessagesStorage.getInstance(UserConfig.selectedAccount).saveDialogFiltersOrder();
        TLRPC.TL_messages_updateDialogFiltersOrder req = new TLRPC.TL_messages_updateDialogFiltersOrder();
        ArrayList<MessagesController.DialogFilter> filters = MessagesController.getInstance(UserConfig.selectedAccount).dialogFilters;
        for (int a = 0, N = filters.size(); a < N; a++) {
            MessagesController.DialogFilter filter = filters.get(a);
            req.order.add(filters.get(a).id);
        }
        ConnectionsManager.getInstance(UserConfig.selectedAccount).sendRequest(req, (response, error) -> {

        });
        orderChanged = false;
    }
}
 
Example #10
Source File: WallpapersListActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void searchBotUser() {
    if (searchingUser) {
        return;
    }
    searchingUser = true;
    TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
    req.username = MessagesController.getInstance(currentAccount).imageSearchBot;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
        if (response != null) {
            AndroidUtilities.runOnUIThread(() -> {
                TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
                MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                MessagesController.getInstance(currentAccount).putChats(res.chats, false);
                MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
                String str = lastSearchImageString;
                lastSearchImageString = null;
                searchImages(str, "", false);
            });
        }
    });
}
 
Example #11
Source File: DialogsSearchAdapter.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void putRecentSearch(final long did, TLObject object) {
    RecentSearchObject recentSearchObject = recentSearchObjectsById.get(did);
    if (recentSearchObject == null) {
        recentSearchObject = new RecentSearchObject();
        recentSearchObjectsById.put(did, recentSearchObject);
    } else {
        recentSearchObjects.remove(recentSearchObject);
    }
    recentSearchObjects.add(0, recentSearchObject);
    recentSearchObject.did = did;
    recentSearchObject.object = object;
    recentSearchObject.date = (int) (System.currentTimeMillis() / 1000);
    notifyDataSetChanged();
    MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() -> {
        try {
            SQLitePreparedStatement state = MessagesStorage.getInstance(currentAccount).getDatabase().executeFast("REPLACE INTO search_recent VALUES(?, ?)");
            state.requery();
            state.bindLong(1, did);
            state.bindInteger(2, (int) (System.currentTimeMillis() / 1000));
            state.step();
            state.dispose();
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
 
Example #12
Source File: DialogsSearchAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void removeRecentSearch(long did) {
    RecentSearchObject object = recentSearchObjectsById.get(did);
    if (object == null) {
        return;
    }
    recentSearchObjectsById.remove(did);
    recentSearchObjects.remove(object);
    notifyDataSetChanged();
    MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() -> {
        try {
            MessagesStorage.getInstance(currentAccount).getDatabase().executeFast("DELETE FROM search_recent WHERE did = " + did).stepThis().dispose();
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
 
Example #13
Source File: ChatEditActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onFragmentCreate() {
    currentChat = MessagesController.getInstance(currentAccount).getChat(chatId);
    if (currentChat == null) {
        currentChat = MessagesStorage.getInstance(currentAccount).getChatSync(chatId);
        if (currentChat != null) {
            MessagesController.getInstance(currentAccount).putChat(currentChat, true);
        } else {
            return false;
        }
        if (info == null) {
            info = MessagesStorage.getInstance(currentAccount).loadChatInfo(chatId, new CountDownLatch(1), false, false);
            if (info == null) {
                return false;
            }
        }
    }

    isChannel = ChatObject.isChannel(currentChat) && !currentChat.megagroup;
    imageUpdater.parentFragment = this;
    imageUpdater.delegate = this;
    signMessages = currentChat.signatures;
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.chatInfoDidLoad);
    return super.onFragmentCreate();
}
 
Example #14
Source File: DialogsSearchAdapter.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void clearRecentSearch()
{
    recentSearchObjectsById = new LongSparseArray<>();
    recentSearchObjects = new ArrayList<>();
    notifyDataSetChanged();
    MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() ->
    {
        try
        {
            MessagesStorage.getInstance(currentAccount).getDatabase().executeFast("DELETE FROM search_recent WHERE 1").stepThis().dispose();
        }
        catch (Exception e)
        {
            FileLog.e(e);
        }
    });
}
 
Example #15
Source File: ProfileActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private TLRPC.Chat getChat(int chatId)
{
    TLRPC.Chat[] chat = new TLRPC.Chat[] { MessagesController.getInstance(currentAccount).getChat(chatId) };
    if (chat[0] == null)
    {
        final CountDownLatch countDownLatch = new CountDownLatch(1);
        MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() ->
        {
            chat[0] = MessagesStorage.getInstance(currentAccount).getChat(chatId);
            countDownLatch.countDown();
        });
        try
        {
            countDownLatch.await();
        }
        catch (Exception e)
        {
            FileLog.e(e);
        }
    }

    return chat[0];
}
 
Example #16
Source File: LoginActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void onAuthSuccess(TLRPC.TL_auth_authorization res)
{
    ConnectionsManager.getInstance(currentAccount).setUserId(res.user.id);
    UserConfig.getInstance(currentAccount).clearConfig();
    MessagesController.getInstance(currentAccount).cleanup();
    UserConfig.getInstance(currentAccount).syncContacts = syncContacts;
    UserConfig.getInstance(currentAccount).setCurrentUser(res.user);
    UserConfig.getInstance(currentAccount).saveConfig(true);
    MessagesStorage.getInstance(currentAccount).cleanup(true);
    ArrayList<TLRPC.User> users = new ArrayList<>();
    users.add(res.user);
    MessagesStorage.getInstance(currentAccount).putUsersAndChats(users, null, true, true);
    MessagesController.getInstance(currentAccount).putUser(res.user, false);
    ContactsController.getInstance(currentAccount).checkAppAccount();
    MessagesController.getInstance(currentAccount).getBlockedUsers(true);
    MessagesController.getInstance(currentAccount).checkProxyInfo(true);
    ConnectionsManager.getInstance(currentAccount).updateDcSettings();
    needFinishActivity();
}
 
Example #17
Source File: PhotoPickerActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void searchBotUser(boolean gif) {
    if (searchingUser) {
        return;
    }
    searchingUser = true;
    TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
    req.username = gif ? MessagesController.getInstance(currentAccount).gifSearchBot : MessagesController.getInstance(currentAccount).imageSearchBot;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
        if (response != null) {
            AndroidUtilities.runOnUIThread(() -> {
                TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
                MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                MessagesController.getInstance(currentAccount).putChats(res.chats, false);
                MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
                String str = lastSearchImageString;
                lastSearchImageString = null;
                searchImages(gif, str, "", false);
            });
        }
    });
}
 
Example #18
Source File: ChatEditActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onFragmentCreate() {
    currentChat = MessagesController.getInstance(currentAccount).getChat(chatId);
    if (currentChat == null) {
        currentChat = MessagesStorage.getInstance(currentAccount).getChatSync(chatId);
        if (currentChat != null) {
            MessagesController.getInstance(currentAccount).putChat(currentChat, true);
        } else {
            return false;
        }
        if (info == null) {
            info = MessagesStorage.getInstance(currentAccount).loadChatInfo(chatId, new CountDownLatch(1), false, false);
            if (info == null) {
                return false;
            }
        }
    }

    isChannel = ChatObject.isChannel(currentChat) && !currentChat.megagroup;
    imageUpdater.parentFragment = this;
    imageUpdater.delegate = this;
    signMessages = currentChat.signatures;
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.chatInfoDidLoad);
    return super.onFragmentCreate();
}
 
Example #19
Source File: BaseLocationAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void searchBotUser() {
    if (searchingUser) {
        return;
    }
    searchingUser = true;
    TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
    req.username = MessagesController.getInstance(currentAccount).venueSearchBot;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
        if (response != null) {
            AndroidUtilities.runOnUIThread(() -> {
                TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
                MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                MessagesController.getInstance(currentAccount).putChats(res.chats, false);
                MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
                Location coord = lastSearchLocation;
                lastSearchLocation = null;
                searchPlacesWithQuery(lastSearchQuery, coord, false);
            });
        }
    });
}
 
Example #20
Source File: LoginActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void onAuthSuccess(TLRPC.TL_auth_authorization res)
{
    ConnectionsManager.getInstance(currentAccount).setUserId(res.user.id);
    UserConfig.getInstance(currentAccount).clearConfig();
    MessagesController.getInstance(currentAccount).cleanup();
    UserConfig.getInstance(currentAccount).syncContacts = syncContacts;
    UserConfig.getInstance(currentAccount).setCurrentUser(res.user);
    UserConfig.getInstance(currentAccount).saveConfig(true);
    MessagesStorage.getInstance(currentAccount).cleanup(true);
    ArrayList<TLRPC.User> users = new ArrayList<>();
    users.add(res.user);
    MessagesStorage.getInstance(currentAccount).putUsersAndChats(users, null, true, true);
    MessagesController.getInstance(currentAccount).putUser(res.user, false);
    ContactsController.getInstance(currentAccount).checkAppAccount();
    MessagesController.getInstance(currentAccount).getBlockedUsers(true);
    MessagesController.getInstance(currentAccount).checkProxyInfo(true);
    ConnectionsManager.getInstance(currentAccount).updateDcSettings();
    needFinishActivity();
}
 
Example #21
Source File: WallpapersListActivity.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onFragmentCreate() {
    if (currentType == TYPE_ALL) {
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.wallpapersDidLoad);
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didSetNewWallpapper);
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.wallpapersNeedReload);
        MessagesStorage.getInstance(currentAccount).getWallpapers();
    } else {
        for (int a = 0; a < defaultColors.length; a++) {
            wallPapers.add(new ColorWallpaper(Theme.COLOR_BACKGROUND_SLUG, defaultColors[a], 0, 45));
        }
        if (currentType == TYPE_COLOR && patterns.isEmpty()) {
            NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.wallpapersDidLoad);
            MessagesStorage.getInstance(currentAccount).getWallpapers();
        }
    }
    return super.onFragmentCreate();
}
 
Example #22
Source File: DialogsSearchAdapter.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void putRecentSearch(final long did, TLObject object)
{
    RecentSearchObject recentSearchObject = recentSearchObjectsById.get(did);
    if (recentSearchObject == null)
    {
        recentSearchObject = new RecentSearchObject();
        recentSearchObjectsById.put(did, recentSearchObject);
    }
    else
    {
        recentSearchObjects.remove(recentSearchObject);
    }
    recentSearchObjects.add(0, recentSearchObject);
    recentSearchObject.did = did;
    recentSearchObject.object = object;
    recentSearchObject.date = (int) (System.currentTimeMillis() / 1000);
    notifyDataSetChanged();
    MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() ->
    {
        try
        {
            SQLitePreparedStatement state = MessagesStorage.getInstance(currentAccount).getDatabase().executeFast("REPLACE INTO search_recent VALUES(?, ?)");
            state.requery();
            state.bindLong(1, did);
            state.bindInteger(2, (int) (System.currentTimeMillis() / 1000));
            state.step();
            state.dispose();
        }
        catch (Exception e)
        {
            FileLog.e(e);
        }
    });
}
 
Example #23
Source File: DialogsSearchAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void clearRecentSearch() {
    recentSearchObjectsById = new LongSparseArray<>();
    recentSearchObjects = new ArrayList<>();
    notifyDataSetChanged();
    MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() -> {
        try {
            MessagesStorage.getInstance(currentAccount).getDatabase().executeFast("DELETE FROM search_recent WHERE 1").stepThis().dispose();
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
 
Example #24
Source File: SearchAdapterHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void putRecentHashtags(final ArrayList<HashtagObject> arrayList) {
    MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() -> {
        try {
            MessagesStorage.getInstance(currentAccount).getDatabase().beginTransaction();
            SQLitePreparedStatement state = MessagesStorage.getInstance(currentAccount).getDatabase().executeFast("REPLACE INTO hashtag_recent_v2 VALUES(?, ?)");
            for (int a = 0; a < arrayList.size(); a++) {
                if (a == 100) {
                    break;
                }
                HashtagObject hashtagObject = arrayList.get(a);
                state.requery();
                state.bindString(1, hashtagObject.hashtag);
                state.bindInteger(2, hashtagObject.date);
                state.step();
            }
            state.dispose();
            MessagesStorage.getInstance(currentAccount).getDatabase().commitTransaction();
            if (arrayList.size() >= 100) {
                MessagesStorage.getInstance(currentAccount).getDatabase().beginTransaction();
                for (int a = 100; a < arrayList.size(); a++) {
                    MessagesStorage.getInstance(currentAccount).getDatabase().executeFast("DELETE FROM hashtag_recent_v2 WHERE id = '" + arrayList.get(a).hashtag + "'").stepThis().dispose();
                }
                MessagesStorage.getInstance(currentAccount).getDatabase().commitTransaction();
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
 
Example #25
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 #26
Source File: DialogsSearchAdapter.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void clearRecentSearch() {
    recentSearchObjectsById = new LongSparseArray<>();
    recentSearchObjects = new ArrayList<>();
    notifyDataSetChanged();
    MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() -> {
        try {
            MessagesStorage.getInstance(currentAccount).getDatabase().executeFast("DELETE FROM search_recent WHERE 1").stepThis().dispose();
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
 
Example #27
Source File: PhotoPickerActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onFragmentCreate() {
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.closeChats);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recentImagesDidLoaded);
    if (selectedAlbum == null) {
        if (recentImages.isEmpty()) {
            MessagesStorage.getInstance(currentAccount).loadWebRecent(type);
            loadingRecent = true;
        }
    }
    return super.onFragmentCreate();
}
 
Example #28
Source File: WallpapersActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onFragmentCreate() {
    super.onFragmentCreate();

    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.FileDidFailedLoad);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.FileDidLoaded);
    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.wallpapersDidLoaded);

    SharedPreferences preferences = MessagesController.getGlobalMainSettings();
    selectedBackground = preferences.getInt("selectedBackground", 1000001);
    overrideThemeWallpaper = preferences.getBoolean("overrideThemeWallpaper", false);
    selectedColor = preferences.getInt("selectedColor", 0);
    MessagesStorage.getInstance(currentAccount).getWallpapers();
    return true;
}
 
Example #29
Source File: GroupStickersActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void saveStickerSet() {
    if (info == null || info.stickerset != null && selectedStickerSet != null && selectedStickerSet.set.id == info.stickerset.id || info.stickerset == null && selectedStickerSet == null) {
        finishFragment();
        return;
    }
    showEditDoneProgress(true);
    TLRPC.TL_channels_setStickers req = new TLRPC.TL_channels_setStickers();
    req.channel = MessagesController.getInstance(currentAccount).getInputChannel(chatId);
    if (selectedStickerSet == null) {
        req.stickerset = new TLRPC.TL_inputStickerSetEmpty();
    } else {
        MessagesController.getEmojiSettings(currentAccount).edit().remove("group_hide_stickers_" + info.id).commit();
        req.stickerset = new TLRPC.TL_inputStickerSetID();
        req.stickerset.id = selectedStickerSet.set.id;
        req.stickerset.access_hash = selectedStickerSet.set.access_hash;
    }
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        if (error == null) {
            if (selectedStickerSet == null) {
                info.stickerset = null;
            } else {
                info.stickerset = selectedStickerSet.set;
                MediaDataController.getInstance(currentAccount).putGroupStickerSet(selectedStickerSet);
            }
            if (info.stickerset == null) {
                info.flags |= 256;
            } else {
                info.flags = info.flags &~ 256;
            }
            MessagesStorage.getInstance(currentAccount).updateChatInfo(info, false);
            NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.chatInfoDidLoad, info, 0, true, null);
            finishFragment();
        } else {
            Toast.makeText(getParentActivity(), LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text, Toast.LENGTH_SHORT).show();
            donePressed = false;
            showEditDoneProgress(false);
        }
    }));
}
 
Example #30
Source File: SearchAdapterHelper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void clearRecentHashtags() {
    hashtags = new ArrayList<>();
    hashtagsByText = new HashMap<>();
    MessagesStorage.getInstance(currentAccount).getStorageQueue().postRunnable(() -> {
        try {
            MessagesStorage.getInstance(currentAccount).getDatabase().executeFast("DELETE FROM hashtag_recent_v2 WHERE 1").stepThis().dispose();
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}