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);
}
}
}
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();
}
}
}
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);
}
}
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;
}
Aggregations