Search in sources :

Example 26 with SerializedData

use of org.telegram.tgnet.SerializedData in project Telegram-FOSS by Telegram-FOSS-Team.

the class SharedConfig method saveConfig.

public static void saveConfig() {
    synchronized (sync) {
        try {
            SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putBoolean("saveIncomingPhotos", saveIncomingPhotos);
            editor.putString("passcodeHash1", passcodeHash);
            editor.putString("passcodeSalt", passcodeSalt.length > 0 ? Base64.encodeToString(passcodeSalt, Base64.DEFAULT) : "");
            editor.putBoolean("appLocked", appLocked);
            editor.putInt("passcodeType", passcodeType);
            editor.putLong("passcodeRetryInMs", passcodeRetryInMs);
            editor.putLong("lastUptimeMillis", lastUptimeMillis);
            editor.putInt("badPasscodeTries", badPasscodeTries);
            editor.putInt("autoLockIn", autoLockIn);
            editor.putInt("lastPauseTime", lastPauseTime);
            editor.putString("lastUpdateVersion2", lastUpdateVersion);
            editor.putBoolean("useFingerprint", useFingerprint);
            editor.putBoolean("allowScreenCapture", allowScreenCapture);
            editor.putString("pushString2", pushString);
            editor.putBoolean("pushStatSent", pushStatSent);
            editor.putString("pushAuthKey", pushAuthKey != null ? Base64.encodeToString(pushAuthKey, Base64.DEFAULT) : "");
            editor.putInt("lastLocalId", lastLocalId);
            editor.putString("passportConfigJson", passportConfigJson);
            editor.putInt("passportConfigHash", passportConfigHash);
            editor.putBoolean("sortContactsByName", sortContactsByName);
            editor.putBoolean("sortFilesByName", sortFilesByName);
            editor.putInt("textSelectionHintShows", textSelectionHintShows);
            editor.putInt("scheduledOrNoSoundHintShows", scheduledOrNoSoundHintShows);
            editor.putBoolean("forwardingOptionsHintShown", forwardingOptionsHintShown);
            editor.putInt("lockRecordAudioVideoHint", lockRecordAudioVideoHint);
            editor.putString("storageCacheDir", !TextUtils.isEmpty(storageCacheDir) ? storageCacheDir : "");
            if (pendingAppUpdate != null) {
                try {
                    SerializedData data = new SerializedData(pendingAppUpdate.getObjectSize());
                    pendingAppUpdate.serializeToStream(data);
                    String str = Base64.encodeToString(data.toByteArray(), Base64.DEFAULT);
                    editor.putString("appUpdate", str);
                    editor.putInt("appUpdateBuild", pendingAppUpdateBuildVersion);
                    data.cleanup();
                } catch (Exception ignore) {
                }
            } else {
                editor.remove("appUpdate");
            }
            editor.putLong("appUpdateCheckTime", lastUpdateCheckTime);
            editor.commit();
        } catch (Exception e) {
            FileLog.e(e);
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) SerializedData(org.telegram.tgnet.SerializedData)

Example 27 with SerializedData

use of org.telegram.tgnet.SerializedData in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatAttachAlertPollLayout method onMenuItemClick.

@Override
void onMenuItemClick(int id) {
    if (id == done_button) {
        if (quizPoll && parentAlert.doneItem.getAlpha() != 1.0f) {
            int checksCount = 0;
            for (int a = 0; a < answersChecks.length; a++) {
                if (!TextUtils.isEmpty(getFixedString(answers[a])) && answersChecks[a]) {
                    checksCount++;
                }
            }
            if (checksCount <= 0) {
                showQuizHint();
            }
            return;
        }
        TLRPC.TL_messageMediaPoll poll = new TLRPC.TL_messageMediaPoll();
        poll.poll = new TLRPC.TL_poll();
        poll.poll.multiple_choice = multipleChoise;
        poll.poll.quiz = quizPoll;
        poll.poll.public_voters = !anonymousPoll;
        poll.poll.question = getFixedString(questionString).toString();
        SerializedData serializedData = new SerializedData(10);
        for (int a = 0; a < answers.length; a++) {
            if (TextUtils.isEmpty(getFixedString(answers[a]))) {
                continue;
            }
            TLRPC.TL_pollAnswer answer = new TLRPC.TL_pollAnswer();
            answer.text = getFixedString(answers[a]).toString();
            answer.option = new byte[1];
            answer.option[0] = (byte) (48 + poll.poll.answers.size());
            poll.poll.answers.add(answer);
            if ((multipleChoise || quizPoll) && answersChecks[a]) {
                serializedData.writeByte(answer.option[0]);
            }
        }
        HashMap<String, String> params = new HashMap<>();
        params.put("answers", Utilities.bytesToHex(serializedData.toByteArray()));
        poll.results = new TLRPC.TL_pollResults();
        CharSequence solution = getFixedString(solutionString);
        if (solution != null) {
            poll.results.solution = solution.toString();
            CharSequence[] message = new CharSequence[] { solution };
            ArrayList<TLRPC.MessageEntity> entities = MediaDataController.getInstance(parentAlert.currentAccount).getEntities(message, true);
            if (entities != null && !entities.isEmpty()) {
                poll.results.solution_entities = entities;
            }
            if (!TextUtils.isEmpty(poll.results.solution)) {
                poll.results.flags |= 16;
            }
        }
        ChatActivity chatActivity = (ChatActivity) parentAlert.baseFragment;
        if (chatActivity.isInScheduleMode()) {
            AlertsCreator.createScheduleDatePickerDialog(chatActivity.getParentActivity(), chatActivity.getDialogId(), (notify, scheduleDate) -> {
                delegate.sendPoll(poll, params, notify, scheduleDate);
                parentAlert.dismiss();
            });
        } else {
            delegate.sendPoll(poll, params, true, 0);
            parentAlert.dismiss();
        }
    }
}
Also used : ChatActivity(org.telegram.ui.ChatActivity) HashMap(java.util.HashMap) SerializedData(org.telegram.tgnet.SerializedData) TLRPC(org.telegram.tgnet.TLRPC)

Example 28 with SerializedData

use of org.telegram.tgnet.SerializedData in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatThemeController method requestAllChatThemes.

public static void requestAllChatThemes(final ResultCallback<List<EmojiThemes>> callback, boolean withDefault) {
    if (themesHash == 0 || lastReloadTimeMs == 0) {
        init();
    }
    boolean needReload = System.currentTimeMillis() - lastReloadTimeMs > reloadTimeoutMs;
    if (allChatThemes == null || allChatThemes.isEmpty() || needReload) {
        TLRPC.TL_account_getChatThemes request = new TLRPC.TL_account_getChatThemes();
        request.hash = themesHash;
        ConnectionsManager.getInstance(UserConfig.selectedAccount).sendRequest(request, (response, error) -> chatThemeQueue.postRunnable(() -> {
            boolean isError = false;
            final List<EmojiThemes> chatThemes;
            if (response instanceof TLRPC.TL_account_themes) {
                TLRPC.TL_account_themes resp = (TLRPC.TL_account_themes) response;
                themesHash = resp.hash;
                lastReloadTimeMs = System.currentTimeMillis();
                SharedPreferences.Editor editor = getSharedPreferences().edit();
                editor.clear();
                editor.putLong("hash", themesHash);
                editor.putLong("lastReload", lastReloadTimeMs);
                editor.putInt("count", resp.themes.size());
                chatThemes = new ArrayList<>(resp.themes.size());
                for (int i = 0; i < resp.themes.size(); ++i) {
                    TLRPC.TL_theme tlChatTheme = resp.themes.get(i);
                    Emoji.preloadEmoji(tlChatTheme.emoticon);
                    SerializedData data = new SerializedData(tlChatTheme.getObjectSize());
                    tlChatTheme.serializeToStream(data);
                    editor.putString("theme_" + i, Utilities.bytesToHex(data.toByteArray()));
                    EmojiThemes chatTheme = new EmojiThemes(tlChatTheme, false);
                    chatTheme.preloadWallpaper();
                    chatThemes.add(chatTheme);
                }
                editor.apply();
            } else if (response instanceof TLRPC.TL_account_themesNotModified) {
                chatThemes = getAllChatThemesFromPrefs();
            } else {
                chatThemes = null;
                isError = true;
                AndroidUtilities.runOnUIThread(() -> callback.onError(error));
            }
            if (!isError) {
                if (withDefault && !chatThemes.get(0).showAsDefaultStub) {
                    chatThemes.add(0, EmojiThemes.createChatThemesDefault());
                }
                for (EmojiThemes theme : chatThemes) {
                    theme.initColors();
                }
                AndroidUtilities.runOnUIThread(() -> {
                    allChatThemes = new ArrayList<>(chatThemes);
                    callback.onComplete(chatThemes);
                });
            }
        }));
    } else {
        List<EmojiThemes> chatThemes = new ArrayList<>(allChatThemes);
        if (withDefault && !chatThemes.get(0).showAsDefaultStub) {
            chatThemes.add(0, EmojiThemes.createChatThemesDefault());
        }
        for (EmojiThemes theme : chatThemes) {
            theme.initColors();
        }
        callback.onComplete(chatThemes);
    }
}
Also used : ArrayList(java.util.ArrayList) SerializedData(org.telegram.tgnet.SerializedData) TLRPC(org.telegram.tgnet.TLRPC) EmojiThemes(org.telegram.ui.ActionBar.EmojiThemes) ArrayList(java.util.ArrayList) List(java.util.List)

Example 29 with SerializedData

use of org.telegram.tgnet.SerializedData in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatThemeController method getAllChatThemesFromPrefs.

private static List<EmojiThemes> getAllChatThemesFromPrefs() {
    SharedPreferences preferences = getSharedPreferences();
    int count = preferences.getInt("count", 0);
    List<EmojiThemes> themes = new ArrayList<>(count);
    for (int i = 0; i < count; ++i) {
        String value = preferences.getString("theme_" + i, "");
        SerializedData serializedData = new SerializedData(Utilities.hexToBytes(value));
        try {
            TLRPC.TL_theme chatTheme = TLRPC.Theme.TLdeserialize(serializedData, serializedData.readInt32(true), true);
            if (chatTheme != null) {
                themes.add(new EmojiThemes(chatTheme, false));
            }
        } catch (Throwable e) {
            FileLog.e(e);
        }
    }
    return themes;
}
Also used : EmojiThemes(org.telegram.ui.ActionBar.EmojiThemes) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) SerializedData(org.telegram.tgnet.SerializedData) TLRPC(org.telegram.tgnet.TLRPC)

Aggregations

SerializedData (org.telegram.tgnet.SerializedData)29 SharedPreferences (android.content.SharedPreferences)17 TLRPC (org.telegram.tgnet.TLRPC)17 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)5 Point (org.telegram.ui.Components.Point)5 SuppressLint (android.annotation.SuppressLint)4 Paint (android.graphics.Paint)3 TextPaint (android.text.TextPaint)3 TLObject (org.telegram.tgnet.TLObject)3 Bitmap (android.graphics.Bitmap)2 BitmapFactory (android.graphics.BitmapFactory)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 Uri (android.net.Uri)2 SpannableString (android.text.SpannableString)2 View (android.view.View)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 List (java.util.List)2 EmojiThemes (org.telegram.ui.ActionBar.EmojiThemes)2