2013-10-25 15:19:00 +00:00
|
|
|
/*
|
2013-12-20 19:25:49 +00:00
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
2013-10-25 15:19:00 +00:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.AlertDialog;
|
2014-02-28 22:28:25 +00:00
|
|
|
import android.app.ProgressDialog;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2014-05-16 23:05:49 +00:00
|
|
|
import android.content.pm.PackageInfo;
|
2014-11-11 22:16:17 +00:00
|
|
|
import android.content.res.Configuration;
|
2013-12-20 19:25:49 +00:00
|
|
|
import android.net.Uri;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.os.Bundle;
|
2014-04-02 17:36:57 +00:00
|
|
|
import android.text.Html;
|
2014-04-03 21:18:54 +00:00
|
|
|
import android.text.Spannable;
|
2014-04-02 17:36:57 +00:00
|
|
|
import android.text.method.LinkMovementMethod;
|
2014-02-28 22:28:25 +00:00
|
|
|
import android.util.Base64;
|
2014-11-11 22:16:17 +00:00
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.Gravity;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.LayoutInflater;
|
2014-04-03 21:18:54 +00:00
|
|
|
import android.view.MotionEvent;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2014-11-11 22:16:17 +00:00
|
|
|
import android.view.ViewTreeObserver;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.widget.AdapterView;
|
2014-11-11 22:16:17 +00:00
|
|
|
import android.widget.FrameLayout;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.TextView;
|
2014-02-04 18:36:55 +00:00
|
|
|
import android.widget.Toast;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
|
|
|
import org.telegram.android.ContactsController;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.PhoneFormat.PhoneFormat;
|
2014-08-22 14:24:33 +00:00
|
|
|
import org.telegram.android.MediaController;
|
2014-03-22 23:20:13 +00:00
|
|
|
import org.telegram.messenger.BuildVars;
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.LocaleController;
|
2014-09-25 03:54:35 +00:00
|
|
|
import org.telegram.messenger.FileLoader;
|
2014-02-28 22:28:25 +00:00
|
|
|
import org.telegram.messenger.SerializedData;
|
|
|
|
import org.telegram.messenger.TLClassStore;
|
|
|
|
import org.telegram.messenger.TLObject;
|
|
|
|
import org.telegram.messenger.TLRPC;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.ConnectionsManager;
|
2013-12-20 19:25:49 +00:00
|
|
|
import org.telegram.messenger.FileLog;
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.MessagesController;
|
|
|
|
import org.telegram.android.MessagesStorage;
|
2014-08-22 14:24:33 +00:00
|
|
|
import org.telegram.android.NotificationCenter;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.RPCRequest;
|
|
|
|
import org.telegram.messenger.UserConfig;
|
2014-08-22 14:24:33 +00:00
|
|
|
import org.telegram.android.MessageObject;
|
2014-06-20 00:18:13 +00:00
|
|
|
import org.telegram.ui.Adapters.BaseFragmentAdapter;
|
2014-11-12 10:41:46 +00:00
|
|
|
import org.telegram.ui.Cells.TextInfoCell;
|
2014-11-11 22:16:17 +00:00
|
|
|
import org.telegram.ui.Cells.EmptyCell;
|
|
|
|
import org.telegram.ui.Cells.HeaderCell;
|
|
|
|
import org.telegram.ui.Cells.ShadowSectionCell;
|
|
|
|
import org.telegram.ui.Cells.TextCheckCell;
|
|
|
|
import org.telegram.ui.Cells.TextDetailSettingsCell;
|
|
|
|
import org.telegram.ui.Cells.TextSettingsCell;
|
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.Views.ActionBar.ActionBarMenuItem;
|
2014-11-06 21:34:47 +00:00
|
|
|
import org.telegram.ui.Views.AvatarDrawable;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.ui.Views.AvatarUpdater;
|
|
|
|
import org.telegram.ui.Views.BackupImageView;
|
2014-06-03 23:31:48 +00:00
|
|
|
import org.telegram.ui.Views.ActionBar.BaseFragment;
|
2014-10-14 20:36:15 +00:00
|
|
|
import org.telegram.ui.Views.NumberPicker;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
2014-05-16 23:05:49 +00:00
|
|
|
import java.util.Locale;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
public class SettingsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, PhotoViewer.PhotoViewerProvider {
|
2014-11-11 22:16:17 +00:00
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
private ListView listView;
|
|
|
|
private ListAdapter listAdapter;
|
2014-11-11 22:16:17 +00:00
|
|
|
private BackupImageView avatarImage;
|
|
|
|
private TextView nameTextView;
|
|
|
|
private TextView onlineTextView;
|
|
|
|
private ImageView writeButton;
|
2013-10-25 15:19:00 +00:00
|
|
|
private AvatarUpdater avatarUpdater = new AvatarUpdater();
|
|
|
|
|
2014-11-11 22:16:17 +00:00
|
|
|
private int emptyRow;
|
2014-03-22 22:31:55 +00:00
|
|
|
private int numberSectionRow;
|
|
|
|
private int numberRow;
|
2014-10-17 18:29:13 +00:00
|
|
|
private int usernameRow;
|
2014-03-22 22:31:55 +00:00
|
|
|
private int settingsSectionRow;
|
2014-11-11 22:16:17 +00:00
|
|
|
private int settingsSectionRow2;
|
2014-03-22 22:31:55 +00:00
|
|
|
private int enableAnimationsRow;
|
|
|
|
private int notificationRow;
|
|
|
|
private int blockedRow;
|
|
|
|
private int backgroundRow;
|
2014-11-11 22:16:17 +00:00
|
|
|
private int languageRow;
|
2014-03-22 22:31:55 +00:00
|
|
|
private int terminateSessionsRow;
|
2014-08-22 14:24:33 +00:00
|
|
|
private int mediaDownloadSection;
|
2014-11-11 22:16:17 +00:00
|
|
|
private int mediaDownloadSection2;
|
2014-08-22 14:24:33 +00:00
|
|
|
private int mobileDownloadRow;
|
|
|
|
private int wifiDownloadRow;
|
|
|
|
private int roamingDownloadRow;
|
2014-09-30 22:36:18 +00:00
|
|
|
private int saveToGalleryRow;
|
2014-11-11 22:16:17 +00:00
|
|
|
private int messagesSectionRow;
|
|
|
|
private int messagesSectionRow2;
|
|
|
|
private int textSizeRow;
|
|
|
|
private int sendByEnterRow;
|
|
|
|
private int supportSectionRow;
|
|
|
|
private int supportSectionRow2;
|
|
|
|
private int askQuestionRow;
|
2014-04-02 17:36:57 +00:00
|
|
|
private int telegramFaqRow;
|
2014-11-11 22:16:17 +00:00
|
|
|
private int sendLogsRow;
|
|
|
|
private int clearLogsRow;
|
|
|
|
private int switchBackendButtonRow;
|
2014-05-16 23:05:49 +00:00
|
|
|
private int versionRow;
|
2014-05-24 22:47:05 +00:00
|
|
|
private int contactsSectionRow;
|
|
|
|
private int contactsReimportRow;
|
|
|
|
private int contactsSortRow;
|
2014-05-16 23:05:49 +00:00
|
|
|
private int rowCount;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-11-11 22:16:17 +00:00
|
|
|
private final static int edit_name = 1;
|
|
|
|
private final static int logout = 2;
|
|
|
|
|
2014-04-03 21:18:54 +00:00
|
|
|
private static class LinkMovementMethodMy extends LinkMovementMethod {
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
|
|
|
|
try {
|
|
|
|
return super.onTouchEvent(widget, buffer, event);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
super.onFragmentCreate();
|
|
|
|
avatarUpdater.parentFragment = this;
|
|
|
|
avatarUpdater.delegate = new AvatarUpdater.AvatarUpdaterDelegate() {
|
|
|
|
@Override
|
2013-12-20 19:25:49 +00:00
|
|
|
public void didUploadedPhoto(TLRPC.InputFile file, TLRPC.PhotoSize small, TLRPC.PhotoSize big) {
|
2013-10-25 15:19:00 +00:00
|
|
|
TLRPC.TL_photos_uploadProfilePhoto req = new TLRPC.TL_photos_uploadProfilePhoto();
|
|
|
|
req.caption = "";
|
|
|
|
req.crop = new TLRPC.TL_inputPhotoCropAuto();
|
|
|
|
req.file = file;
|
|
|
|
req.geo_point = new TLRPC.TL_inputGeoPointEmpty();
|
2014-03-22 22:31:55 +00:00
|
|
|
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
public void run(TLObject response, TLRPC.TL_error error) {
|
2014-02-04 18:36:55 +00:00
|
|
|
if (error == null) {
|
2014-08-22 14:24:33 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
|
2014-02-04 18:36:55 +00:00
|
|
|
if (user == null) {
|
2014-06-13 10:42:21 +00:00
|
|
|
user = UserConfig.getCurrentUser();
|
2014-02-04 18:36:55 +00:00
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
MessagesController.getInstance().putUser(user, false);
|
2014-02-04 18:36:55 +00:00
|
|
|
} else {
|
2014-06-13 10:42:21 +00:00
|
|
|
UserConfig.setCurrentUser(user);
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo)response;
|
|
|
|
ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
|
2014-10-01 19:55:24 +00:00
|
|
|
TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 100);
|
|
|
|
TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 1000);
|
2014-02-04 18:36:55 +00:00
|
|
|
user.photo = new TLRPC.TL_userProfilePhoto();
|
|
|
|
user.photo.photo_id = photo.photo.id;
|
|
|
|
if (smallSize != null) {
|
|
|
|
user.photo.photo_small = smallSize.location;
|
|
|
|
}
|
|
|
|
if (bigSize != null) {
|
|
|
|
user.photo.photo_big = bigSize.location;
|
|
|
|
} else if (smallSize != null) {
|
|
|
|
user.photo.photo_small = smallSize.location;
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesStorage.getInstance().clearUserPhotos(user.id);
|
2014-02-04 18:36:55 +00:00
|
|
|
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
|
|
|
|
users.add(user);
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesStorage.getInstance().putUsersAndChats(users, null, false, true);
|
2014-11-06 21:34:47 +00:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
2014-02-04 18:36:55 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_ALL);
|
2014-02-04 18:36:55 +00:00
|
|
|
UserConfig.saveConfig(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-07-02 22:39:05 +00:00
|
|
|
});
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
};
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
rowCount = 0;
|
2014-11-11 22:16:17 +00:00
|
|
|
emptyRow = rowCount++;
|
2013-10-25 15:19:00 +00:00
|
|
|
numberSectionRow = rowCount++;
|
|
|
|
numberRow = rowCount++;
|
2014-10-17 18:29:13 +00:00
|
|
|
usernameRow = rowCount++;
|
2013-10-25 15:19:00 +00:00
|
|
|
settingsSectionRow = rowCount++;
|
2014-11-11 22:16:17 +00:00
|
|
|
settingsSectionRow2 = rowCount++;
|
2013-10-25 15:19:00 +00:00
|
|
|
enableAnimationsRow = rowCount++;
|
|
|
|
notificationRow = rowCount++;
|
|
|
|
blockedRow = rowCount++;
|
|
|
|
backgroundRow = rowCount++;
|
2014-11-11 22:16:17 +00:00
|
|
|
languageRow = rowCount++;
|
2014-02-04 18:36:55 +00:00
|
|
|
terminateSessionsRow = rowCount++;
|
2014-08-22 14:24:33 +00:00
|
|
|
mediaDownloadSection = rowCount++;
|
2014-11-11 22:16:17 +00:00
|
|
|
mediaDownloadSection2 = rowCount++;
|
2014-08-22 14:24:33 +00:00
|
|
|
mobileDownloadRow = rowCount++;
|
|
|
|
wifiDownloadRow = rowCount++;
|
|
|
|
roamingDownloadRow = rowCount++;
|
2014-09-30 22:36:18 +00:00
|
|
|
saveToGalleryRow = rowCount++;
|
2014-02-04 18:36:55 +00:00
|
|
|
messagesSectionRow = rowCount++;
|
2014-11-11 22:16:17 +00:00
|
|
|
messagesSectionRow2 = rowCount++;
|
2014-02-04 18:36:55 +00:00
|
|
|
textSizeRow = rowCount++;
|
|
|
|
sendByEnterRow = rowCount++;
|
2013-10-25 15:19:00 +00:00
|
|
|
supportSectionRow = rowCount++;
|
2014-11-11 22:16:17 +00:00
|
|
|
supportSectionRow2 = rowCount++;
|
|
|
|
askQuestionRow = rowCount++;
|
|
|
|
telegramFaqRow = rowCount++;
|
2014-03-22 23:20:13 +00:00
|
|
|
if (BuildVars.DEBUG_VERSION) {
|
2013-12-20 19:25:49 +00:00
|
|
|
sendLogsRow = rowCount++;
|
2014-02-28 22:28:25 +00:00
|
|
|
clearLogsRow = rowCount++;
|
2014-03-25 23:38:23 +00:00
|
|
|
switchBackendButtonRow = rowCount++;
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
2014-05-16 23:05:49 +00:00
|
|
|
versionRow = rowCount++;
|
2014-11-11 22:16:17 +00:00
|
|
|
//contactsSectionRow = rowCount++;
|
|
|
|
//contactsReimportRow = rowCount++;
|
|
|
|
//contactsSortRow = rowCount++;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-10-17 18:29:13 +00:00
|
|
|
MessagesController.getInstance().loadFullUser(UserConfig.getCurrentUser(), classGuid);
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2014-10-17 18:29:13 +00:00
|
|
|
MessagesController.getInstance().cancelLoadFullUser(UserConfig.getClientUserId());
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
|
2013-10-25 15:19:00 +00:00
|
|
|
avatarUpdater.clear();
|
|
|
|
}
|
|
|
|
|
2014-11-11 22:16:17 +00:00
|
|
|
@Override
|
|
|
|
public boolean needAddActionBar() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
2014-06-03 23:31:48 +00:00
|
|
|
public View createView(LayoutInflater inflater, ViewGroup container) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (fragmentView == null) {
|
2014-11-11 22:16:17 +00:00
|
|
|
actionBar.setBackgroundColor(AvatarDrawable.getProfileBackColorForId(5));
|
|
|
|
actionBar.setItemsBackground(AvatarDrawable.getButtonColorForId(5));
|
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
actionBar.setBackOverlay(R.layout.updating_state_layout);
|
|
|
|
actionBar.setExtraHeight(AndroidUtilities.dp(88));
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
2014-06-03 23:31:48 +00:00
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
|
|
|
finishFragment();
|
2014-11-11 22:16:17 +00:00
|
|
|
} else if (id == edit_name) {
|
|
|
|
presentFragment(new SettingsChangeNameActivity());
|
|
|
|
} else if (id == logout) {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureLogout", R.string.AreYouSureLogout));
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.clear().commit();
|
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.appDidLogout);
|
|
|
|
MessagesController.getInstance().unregistedPush();
|
|
|
|
MessagesController.getInstance().logOut();
|
|
|
|
UserConfig.clearConfig();
|
|
|
|
MessagesStorage.getInstance().cleanUp(false);
|
|
|
|
MessagesController.getInstance().cleanUp();
|
|
|
|
ContactsController.getInstance().deleteAllAppAccounts();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
showAlertDialog(builder);
|
2014-06-03 23:31:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-11-11 22:16:17 +00:00
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
|
|
|
menu.clearItems();
|
|
|
|
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
|
|
|
|
item.addSubItem(edit_name, LocaleController.getString("EditName", R.string.EditName), 0);
|
|
|
|
item.addSubItem(logout, LocaleController.getString("LogOut", R.string.LogOut), 0);
|
2014-06-03 23:31:48 +00:00
|
|
|
|
|
|
|
listAdapter = new ListAdapter(getParentActivity());
|
2014-11-11 22:16:17 +00:00
|
|
|
|
|
|
|
fragmentView = new FrameLayout(getParentActivity());
|
|
|
|
FrameLayout frameLayout = (FrameLayout) fragmentView;
|
|
|
|
frameLayout.addView(actionBar);
|
|
|
|
|
|
|
|
avatarImage = new BackupImageView(getParentActivity());
|
|
|
|
avatarImage.imageReceiver.setRoundRadius(AndroidUtilities.dp(30));
|
|
|
|
avatarImage.processDetach = false;
|
|
|
|
actionBar.addView(avatarImage);
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
|
|
|
|
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
|
|
|
|
layoutParams.width = AndroidUtilities.dp(60);
|
|
|
|
layoutParams.height = AndroidUtilities.dp(60);
|
|
|
|
layoutParams.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(17);
|
|
|
|
layoutParams.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(17) : 0;
|
|
|
|
layoutParams.bottomMargin = AndroidUtilities.dp(22);
|
|
|
|
avatarImage.setLayoutParams(layoutParams);
|
|
|
|
avatarImage.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
|
|
|
|
if (user.photo != null && user.photo.photo_big != null) {
|
|
|
|
PhotoViewer.getInstance().setParentActivity(getParentActivity());
|
|
|
|
PhotoViewer.getInstance().openPhoto(user.photo.photo_big, SettingsActivity.this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
nameTextView = new TextView(getParentActivity());
|
|
|
|
nameTextView.setTextColor(0xffffffff);
|
|
|
|
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
|
|
|
nameTextView.setLines(1);
|
|
|
|
nameTextView.setMaxLines(1);
|
|
|
|
nameTextView.setSingleLine(true);
|
|
|
|
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
|
|
|
|
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
actionBar.addView(nameTextView);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
|
|
|
|
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
|
|
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
|
|
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 97);
|
|
|
|
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 97 : 16);
|
|
|
|
layoutParams.bottomMargin = AndroidUtilities.dp(51);
|
|
|
|
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
|
|
|
|
nameTextView.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
onlineTextView = new TextView(getParentActivity());
|
|
|
|
onlineTextView.setTextColor(AvatarDrawable.getProfileTextColorForId(5));
|
|
|
|
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
onlineTextView.setLines(1);
|
|
|
|
onlineTextView.setMaxLines(1);
|
|
|
|
onlineTextView.setSingleLine(true);
|
|
|
|
onlineTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
|
|
|
|
actionBar.addView(onlineTextView);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams();
|
|
|
|
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
|
|
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
|
|
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 97);
|
|
|
|
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 97 : 16);
|
|
|
|
layoutParams.bottomMargin = AndroidUtilities.dp(30);
|
|
|
|
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
|
|
|
|
onlineTextView.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
listView = new ListView(getParentActivity());
|
|
|
|
listView.setDivider(null);
|
|
|
|
listView.setDividerHeight(0);
|
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
|
|
|
AndroidUtilities.setListViewEdgeEffectColor(listView, AvatarDrawable.getProfileBackColorForId(5));
|
|
|
|
frameLayout.addView(listView);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
|
|
|
|
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.gravity = Gravity.TOP;
|
|
|
|
listView.setLayoutParams(layoutParams);
|
2013-10-25 15:19:00 +00:00
|
|
|
listView.setAdapter(listAdapter);
|
|
|
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
2014-05-24 22:47:05 +00:00
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (i == textSizeRow) {
|
2014-06-14 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-03-22 22:31:55 +00:00
|
|
|
builder.setTitle(LocaleController.getString("TextSize", R.string.TextSize));
|
2014-10-14 20:36:15 +00:00
|
|
|
final NumberPicker numberPicker = new NumberPicker(getParentActivity());
|
|
|
|
numberPicker.setMinValue(12);
|
|
|
|
numberPicker.setMaxValue(30);
|
|
|
|
numberPicker.setValue(MessagesController.getInstance().fontSize);
|
|
|
|
builder.setView(numberPicker);
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() {
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2014-02-04 18:36:55 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
2014-10-14 20:36:15 +00:00
|
|
|
editor.putInt("fons_size", numberPicker.getValue());
|
|
|
|
MessagesController.getInstance().fontSize = numberPicker.getValue();
|
2013-10-25 15:19:00 +00:00
|
|
|
editor.commit();
|
|
|
|
if (listView != null) {
|
|
|
|
listView.invalidateViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == enableAnimationsRow) {
|
2014-02-04 18:36:55 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
boolean animations = preferences.getBoolean("view_animations", true);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("view_animations", !animations);
|
|
|
|
editor.commit();
|
|
|
|
if (listView != null) {
|
|
|
|
listView.invalidateViews();
|
|
|
|
}
|
|
|
|
} else if (i == notificationRow) {
|
2014-06-03 23:31:48 +00:00
|
|
|
presentFragment(new SettingsNotificationsActivity());
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == blockedRow) {
|
2014-07-19 23:31:49 +00:00
|
|
|
presentFragment(new SettingsBlockedUsersActivity());
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == backgroundRow) {
|
2014-06-03 23:31:48 +00:00
|
|
|
presentFragment(new SettingsWallpapersActivity());
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == askQuestionRow) {
|
2014-06-14 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
final TextView message = new TextView(getParentActivity());
|
2014-04-02 17:36:57 +00:00
|
|
|
message.setText(Html.fromHtml(LocaleController.getString("AskAQuestionInfo", R.string.AskAQuestionInfo)));
|
|
|
|
message.setTextSize(18);
|
2014-07-02 22:39:05 +00:00
|
|
|
message.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(5), AndroidUtilities.dp(8), AndroidUtilities.dp(6));
|
2014-04-03 21:18:54 +00:00
|
|
|
message.setMovementMethod(new LinkMovementMethodMy());
|
2014-02-28 22:28:25 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-04-02 17:36:57 +00:00
|
|
|
builder.setView(message);
|
|
|
|
builder.setPositiveButton(LocaleController.getString("AskButton", R.string.AskButton), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
performAskAQuestion();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2013-12-20 19:25:49 +00:00
|
|
|
} else if (i == sendLogsRow) {
|
|
|
|
sendLogs();
|
2014-02-28 22:28:25 +00:00
|
|
|
} else if (i == clearLogsRow) {
|
|
|
|
FileLog.cleanupLogs();
|
2014-02-04 18:36:55 +00:00
|
|
|
} else if (i == sendByEnterRow) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
boolean send = preferences.getBoolean("send_by_enter", false);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("send_by_enter", !send);
|
|
|
|
editor.commit();
|
|
|
|
if (listView != null) {
|
|
|
|
listView.invalidateViews();
|
|
|
|
}
|
2014-09-30 22:36:18 +00:00
|
|
|
} else if (i == saveToGalleryRow) {
|
|
|
|
MediaController.getInstance().toggleSaveToGallery();
|
|
|
|
if (listView != null) {
|
|
|
|
listView.invalidateViews();
|
|
|
|
}
|
2014-02-04 18:36:55 +00:00
|
|
|
} else if (i == terminateSessionsRow) {
|
2014-06-14 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-07-10 21:15:39 +00:00
|
|
|
builder.setMessage(LocaleController.getString("AreYouSureSessions", R.string.AreYouSureSessions));
|
2014-03-22 22:31:55 +00:00
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
2014-02-04 18:36:55 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
TLRPC.TL_auth_resetAuthorizations req = new TLRPC.TL_auth_resetAuthorizations();
|
2014-03-22 22:31:55 +00:00
|
|
|
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
2014-02-04 18:36:55 +00:00
|
|
|
@Override
|
2014-06-14 08:36:01 +00:00
|
|
|
public void run(final TLObject response, final TLRPC.TL_error error) {
|
2014-11-06 21:34:47 +00:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
2014-06-14 08:36:01 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (error == null && response instanceof TLRPC.TL_boolTrue) {
|
|
|
|
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions), Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
} else {
|
|
|
|
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("UnknownError", R.string.UnknownError), Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-02-04 18:36:55 +00:00
|
|
|
UserConfig.registeredForPush = false;
|
2014-06-14 08:36:01 +00:00
|
|
|
UserConfig.registeredForInternalPush = false;
|
|
|
|
UserConfig.saveConfig(false);
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().registerForPush(UserConfig.pushString);
|
2014-06-14 08:36:01 +00:00
|
|
|
ConnectionsManager.getInstance().initPushConnection();
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
2014-07-02 22:39:05 +00:00
|
|
|
});
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
|
|
|
});
|
2014-03-22 22:31:55 +00:00
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2014-03-25 00:25:32 +00:00
|
|
|
} else if (i == languageRow) {
|
2014-06-03 23:31:48 +00:00
|
|
|
presentFragment(new LanguageSelectActivity());
|
2014-03-25 23:38:23 +00:00
|
|
|
} else if (i == switchBackendButtonRow) {
|
2014-06-14 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-03-25 23:38:23 +00:00
|
|
|
builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure));
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
ConnectionsManager.getInstance().switchBackend();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2014-04-02 17:36:57 +00:00
|
|
|
} else if (i == telegramFaqRow) {
|
|
|
|
try {
|
|
|
|
Intent pickIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl)));
|
2014-06-03 23:31:48 +00:00
|
|
|
getParentActivity().startActivity(pickIntent);
|
2014-04-02 17:36:57 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-05-24 22:47:05 +00:00
|
|
|
} else if (i == contactsReimportRow) {
|
|
|
|
|
|
|
|
} else if (i == contactsSortRow) {
|
2014-06-14 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-05-24 22:47:05 +00:00
|
|
|
builder.setTitle(LocaleController.getString("SortBy", R.string.SortBy));
|
|
|
|
builder.setItems(new CharSequence[] {
|
|
|
|
LocaleController.getString("Default", R.string.Default),
|
|
|
|
LocaleController.getString("SortFirstName", R.string.SortFirstName),
|
|
|
|
LocaleController.getString("SortLastName", R.string.SortLastName)
|
|
|
|
}, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("sortContactsBy", which);
|
|
|
|
editor.commit();
|
|
|
|
if (listView != null) {
|
|
|
|
listView.invalidateViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (i == wifiDownloadRow || i == mobileDownloadRow || i == roamingDownloadRow) {
|
2014-06-14 08:36:01 +00:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2014-08-22 14:24:33 +00:00
|
|
|
|
|
|
|
int mask = 0;
|
|
|
|
if (i == mobileDownloadRow) {
|
|
|
|
builder.setTitle(LocaleController.getString("WhenUsingMobileData", R.string.WhenUsingMobileData));
|
|
|
|
mask = MediaController.getInstance().mobileDataDownloadMask;
|
|
|
|
} else if (i == wifiDownloadRow) {
|
|
|
|
builder.setTitle(LocaleController.getString("WhenConnectedOnWiFi", R.string.WhenConnectedOnWiFi));
|
|
|
|
mask = MediaController.getInstance().wifiDownloadMask;
|
|
|
|
} else if (i == roamingDownloadRow) {
|
|
|
|
builder.setTitle(LocaleController.getString("WhenRoaming", R.string.WhenRoaming));
|
|
|
|
mask = MediaController.getInstance().roamingDownloadMask;
|
|
|
|
}
|
|
|
|
builder.setMultiChoiceItems(
|
2014-11-11 22:16:17 +00:00
|
|
|
new CharSequence[]{LocaleController.getString("AttachPhoto", R.string.AttachPhoto), LocaleController.getString("AttachAudio", R.string.AttachAudio), LocaleController.getString("AttachVideo", R.string.AttachVideo), LocaleController.getString("AttachDocument", R.string.AttachDocument)},
|
2014-08-22 14:24:33 +00:00
|
|
|
new boolean[]{(mask & MediaController.AUTODOWNLOAD_MASK_PHOTO) != 0, (mask & MediaController.AUTODOWNLOAD_MASK_AUDIO) != 0, (mask & MediaController.AUTODOWNLOAD_MASK_VIDEO) != 0, (mask & MediaController.AUTODOWNLOAD_MASK_DOCUMENT) != 0},
|
|
|
|
new DialogInterface.OnMultiChoiceClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
|
|
|
int mask = 0;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
if (i == mobileDownloadRow) {
|
|
|
|
mask = MediaController.getInstance().mobileDataDownloadMask;
|
|
|
|
} else if (i == wifiDownloadRow) {
|
|
|
|
mask = MediaController.getInstance().wifiDownloadMask;
|
|
|
|
} else if (i == roamingDownloadRow) {
|
|
|
|
mask = MediaController.getInstance().roamingDownloadMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
int maskDiff = 0;
|
|
|
|
if (which == 0) {
|
|
|
|
maskDiff = MediaController.AUTODOWNLOAD_MASK_PHOTO;
|
|
|
|
} else if (which == 1) {
|
|
|
|
maskDiff = MediaController.AUTODOWNLOAD_MASK_AUDIO;
|
|
|
|
} else if (which == 2) {
|
|
|
|
maskDiff = MediaController.AUTODOWNLOAD_MASK_VIDEO;
|
|
|
|
} else if (which == 3) {
|
|
|
|
maskDiff = MediaController.AUTODOWNLOAD_MASK_DOCUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isChecked) {
|
|
|
|
mask |= maskDiff;
|
|
|
|
} else {
|
|
|
|
mask &= ~maskDiff;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == mobileDownloadRow) {
|
|
|
|
editor.putInt("mobileDataDownloadMask", mask);
|
|
|
|
mask = MediaController.getInstance().mobileDataDownloadMask = mask;
|
|
|
|
} else if (i == wifiDownloadRow) {
|
|
|
|
editor.putInt("wifiDownloadMask", mask);
|
|
|
|
MediaController.getInstance().wifiDownloadMask = mask;
|
|
|
|
} else if (i == roamingDownloadRow) {
|
|
|
|
editor.putInt("roamingDownloadMask", mask);
|
|
|
|
MediaController.getInstance().roamingDownloadMask = mask;
|
|
|
|
}
|
|
|
|
editor.commit();
|
|
|
|
if (listView != null) {
|
|
|
|
listView.invalidateViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), null);
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2014-10-17 18:29:13 +00:00
|
|
|
} else if (i == usernameRow) {
|
|
|
|
presentFragment(new SettingsChangeUsernameActivity());
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-11-11 22:16:17 +00:00
|
|
|
|
|
|
|
writeButton = new ImageView(getParentActivity());
|
|
|
|
writeButton.setImageResource(R.drawable.floating_group_states);
|
|
|
|
frameLayout.addView(writeButton);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) writeButton.getLayoutParams();
|
|
|
|
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
|
|
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
|
|
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 0);
|
|
|
|
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 16);
|
|
|
|
layoutParams.gravity = (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT);
|
|
|
|
writeButton.setLayoutParams(layoutParams);
|
|
|
|
writeButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
|
|
|
|
CharSequence[] items;
|
|
|
|
|
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
|
|
|
|
if (user == null) {
|
|
|
|
user = UserConfig.getCurrentUser();
|
|
|
|
}
|
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean fullMenu = false;
|
|
|
|
if (user.photo != null && user.photo.photo_big != null && !(user.photo instanceof TLRPC.TL_userProfilePhotoEmpty)) {
|
|
|
|
items = new CharSequence[] {LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto)};
|
|
|
|
fullMenu = true;
|
|
|
|
} else {
|
|
|
|
items = new CharSequence[] {LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley)};
|
|
|
|
}
|
|
|
|
|
|
|
|
final boolean full = fullMenu;
|
|
|
|
builder.setItems(items, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
if (i == 0) {
|
|
|
|
avatarUpdater.openCamera();
|
|
|
|
} else if (i == 1) {
|
|
|
|
avatarUpdater.openGallery();
|
|
|
|
} else if (i == 3) {
|
|
|
|
MessagesController.getInstance().deleteUserPhoto(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
showAlertDialog(builder);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
updateUserData();
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
2014-08-22 14:24:33 +00:00
|
|
|
@Override
|
|
|
|
protected void onDialogDismiss() {
|
|
|
|
MediaController.getInstance().checkAutodownloadSettings();
|
|
|
|
}
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
@Override
|
2014-06-12 01:13:15 +00:00
|
|
|
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
2014-06-10 23:05:54 +00:00
|
|
|
if (fileLocation == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
|
2014-06-10 23:05:54 +00:00
|
|
|
if (user != null && user.photo != null && user.photo.photo_big != null) {
|
|
|
|
TLRPC.FileLocation photoBig = user.photo.photo_big;
|
|
|
|
if (photoBig.local_id == fileLocation.local_id && photoBig.volume_id == fileLocation.volume_id && photoBig.dc_id == fileLocation.dc_id) {
|
2014-11-11 22:16:17 +00:00
|
|
|
int coords[] = new int[2];
|
|
|
|
avatarImage.getLocationInWindow(coords);
|
|
|
|
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
|
|
|
|
object.viewX = coords[0];
|
|
|
|
object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
|
|
|
|
object.parentView = avatarImage;
|
|
|
|
object.imageReceiver = avatarImage.imageReceiver;
|
|
|
|
object.user_id = UserConfig.getClientUserId();
|
|
|
|
object.thumb = object.imageReceiver.getBitmap();
|
|
|
|
object.size = -1;
|
|
|
|
return object;
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-06-11 00:22:42 +00:00
|
|
|
@Override
|
2014-06-12 01:13:15 +00:00
|
|
|
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) { }
|
2014-06-11 00:22:42 +00:00
|
|
|
|
2014-06-12 01:13:15 +00:00
|
|
|
@Override
|
|
|
|
public void willHidePhotoViewer() { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPhotoChecked(int index) { return false; }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setPhotoChecked(int index) { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void cancelButtonPressed() { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendButtonPressed(int index) { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSelectedCount() { return 0; }
|
2014-06-11 00:22:42 +00:00
|
|
|
|
2014-04-02 17:36:57 +00:00
|
|
|
public void performAskAQuestion() {
|
|
|
|
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
int uid = preferences.getInt("support_id", 0);
|
|
|
|
TLRPC.User supportUser = null;
|
|
|
|
if (uid != 0) {
|
2014-08-22 14:24:33 +00:00
|
|
|
supportUser = MessagesController.getInstance().getUser(uid);
|
2014-04-02 17:36:57 +00:00
|
|
|
if (supportUser == null) {
|
|
|
|
String userString = preferences.getString("support_user", null);
|
|
|
|
if (userString != null) {
|
|
|
|
try {
|
|
|
|
byte[] datacentersBytes = Base64.decode(userString, Base64.DEFAULT);
|
|
|
|
if (datacentersBytes != null) {
|
|
|
|
SerializedData data = new SerializedData(datacentersBytes);
|
|
|
|
supportUser = (TLRPC.User)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
2014-07-02 22:39:05 +00:00
|
|
|
if (supportUser != null && supportUser.id == 333000) {
|
|
|
|
supportUser = null;
|
|
|
|
}
|
2014-04-02 17:36:57 +00:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
supportUser = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (supportUser == null) {
|
2014-06-03 23:31:48 +00:00
|
|
|
final ProgressDialog progressDialog = new ProgressDialog(getParentActivity());
|
|
|
|
progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
|
2014-04-02 17:36:57 +00:00
|
|
|
progressDialog.setCanceledOnTouchOutside(false);
|
|
|
|
progressDialog.setCancelable(false);
|
|
|
|
progressDialog.show();
|
|
|
|
TLRPC.TL_help_getSupport req = new TLRPC.TL_help_getSupport();
|
|
|
|
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
|
|
|
@Override
|
|
|
|
public void run(TLObject response, TLRPC.TL_error error) {
|
|
|
|
if (error == null) {
|
|
|
|
|
|
|
|
final TLRPC.TL_help_support res = (TLRPC.TL_help_support)response;
|
2014-11-06 21:34:47 +00:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
2014-04-02 17:36:57 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("support_id", res.user.id);
|
|
|
|
SerializedData data = new SerializedData();
|
|
|
|
res.user.serializeToStream(data);
|
|
|
|
editor.putString("support_user", Base64.encodeToString(data.toByteArray(), Base64.DEFAULT));
|
|
|
|
editor.commit();
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-07-26 22:28:33 +00:00
|
|
|
ArrayList<TLRPC.User> users = new ArrayList<TLRPC.User>();
|
|
|
|
users.add(res.user);
|
|
|
|
MessagesStorage.getInstance().putUsersAndChats(users, null, true, true);
|
2014-08-22 14:24:33 +00:00
|
|
|
MessagesController.getInstance().putUser(res.user, false);
|
2014-06-03 23:31:48 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", res.user.id);
|
|
|
|
presentFragment(new ChatActivity(args));
|
2014-04-02 17:36:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2014-11-06 21:34:47 +00:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
2014-04-02 17:36:57 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-07-02 22:39:05 +00:00
|
|
|
});
|
2014-04-02 17:36:57 +00:00
|
|
|
} else {
|
2014-08-22 14:24:33 +00:00
|
|
|
MessagesController.getInstance().putUser(supportUser, true);
|
2014-06-03 23:31:48 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", supportUser.id);
|
|
|
|
presentFragment(new ChatActivity(args));
|
2014-04-02 17:36:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
2014-03-26 20:16:28 +00:00
|
|
|
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
|
2014-02-28 22:28:25 +00:00
|
|
|
avatarUpdater.onActivityResult(requestCode, resultCode, data);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-26 20:16:28 +00:00
|
|
|
@Override
|
|
|
|
public void saveSelfArgs(Bundle args) {
|
|
|
|
if (avatarUpdater != null && avatarUpdater.currentPicturePath != null) {
|
|
|
|
args.putString("path", avatarUpdater.currentPicturePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void restoreSelfArgs(Bundle args) {
|
|
|
|
if (avatarUpdater != null) {
|
|
|
|
avatarUpdater.currentPicturePath = args.getString("path");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
2014-08-22 14:24:33 +00:00
|
|
|
if (id == NotificationCenter.updateInterfaces) {
|
2014-02-04 18:36:55 +00:00
|
|
|
int mask = (Integer)args[0];
|
|
|
|
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
2014-11-11 22:16:17 +00:00
|
|
|
updateUserData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
fixLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
fixLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fixLayout() {
|
|
|
|
if (fragmentView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fragmentView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreDraw() {
|
|
|
|
if (fragmentView != null) {
|
|
|
|
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) listView.getLayoutParams();
|
|
|
|
layoutParams.topMargin = actionBar.getHeight();
|
|
|
|
listView.setLayoutParams(layoutParams);
|
|
|
|
layoutParams = (ViewGroup.MarginLayoutParams) writeButton.getLayoutParams();
|
|
|
|
layoutParams.topMargin = actionBar.getHeight() - AndroidUtilities.dp(29.5f);
|
|
|
|
writeButton.setLayoutParams(layoutParams);
|
|
|
|
fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
2014-11-11 22:16:17 +00:00
|
|
|
return false;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-11-11 22:16:17 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateUserData() {
|
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
|
|
|
|
TLRPC.FileLocation photo = null;
|
|
|
|
TLRPC.FileLocation photoBig = null;
|
|
|
|
if (user.photo != null) {
|
|
|
|
photo = user.photo.photo_small;
|
|
|
|
photoBig = user.photo.photo_big;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-11-11 22:16:17 +00:00
|
|
|
avatarImage.setImage(photo, "50_50", new AvatarDrawable(user, true));
|
|
|
|
avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
|
|
|
|
|
|
|
|
nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
|
|
|
|
onlineTextView.setText(LocaleController.formatUserStatus(user));
|
|
|
|
|
|
|
|
avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
private void sendLogs() {
|
|
|
|
try {
|
|
|
|
ArrayList<Uri> uris = new ArrayList<Uri>();
|
|
|
|
File sdCard = ApplicationLoader.applicationContext.getExternalFilesDir(null);
|
|
|
|
File dir = new File (sdCard.getAbsolutePath() + "/logs");
|
|
|
|
File[] files = dir.listFiles();
|
|
|
|
for (File file : files) {
|
|
|
|
uris.add(Uri.fromFile(file));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uris.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Intent i = new Intent(Intent.ACTION_SEND_MULTIPLE);
|
|
|
|
i.setType("message/rfc822") ;
|
2014-03-22 23:20:13 +00:00
|
|
|
i.putExtra(Intent.EXTRA_EMAIL, new String[]{BuildVars.SEND_LOGS_EMAIL});
|
2013-12-20 19:25:49 +00:00
|
|
|
i.putExtra(Intent.EXTRA_SUBJECT, "last logs");
|
|
|
|
i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
|
2014-06-03 23:31:48 +00:00
|
|
|
getParentActivity().startActivity(Intent.createChooser(i, "Select email application."));
|
2013-12-20 19:25:49 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 00:18:13 +00:00
|
|
|
private class ListAdapter extends BaseFragmentAdapter {
|
2013-10-25 15:19:00 +00:00
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areAllItemsEnabled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled(int i) {
|
2014-02-04 18:36:55 +00:00
|
|
|
return i == textSizeRow || i == enableAnimationsRow || i == blockedRow || i == notificationRow || i == backgroundRow ||
|
2014-08-22 14:24:33 +00:00
|
|
|
i == askQuestionRow || i == sendLogsRow || i == sendByEnterRow || i == terminateSessionsRow || i == wifiDownloadRow ||
|
2014-10-17 18:29:13 +00:00
|
|
|
i == mobileDownloadRow || i == clearLogsRow || i == roamingDownloadRow || i == languageRow || i == usernameRow ||
|
2014-09-30 22:36:18 +00:00
|
|
|
i == switchBackendButtonRow || i == telegramFaqRow || i == contactsSortRow || i == contactsReimportRow || i == saveToGalleryRow;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
return rowCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int i) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int i) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasStableIds() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
|
|
|
int type = getItemViewType(i);
|
|
|
|
if (type == 0) {
|
|
|
|
if (view == null) {
|
2014-11-11 22:16:17 +00:00
|
|
|
view = new EmptyCell(mContext, 16);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (type == 1) {
|
|
|
|
if (view == null) {
|
2014-11-11 22:16:17 +00:00
|
|
|
view = new ShadowSectionCell(mContext);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (type == 2) {
|
|
|
|
if (view == null) {
|
2014-11-11 22:16:17 +00:00
|
|
|
view = new TextSettingsCell(mContext);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-11-11 22:16:17 +00:00
|
|
|
TextSettingsCell textCell = (TextSettingsCell) view;
|
|
|
|
if (i == textSizeRow) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
int size = preferences.getInt("fons_size", AndroidUtilities.isTablet() ? 18 : 16);
|
|
|
|
textCell.setTextAndValue(LocaleController.getString("TextSize", R.string.TextSize), String.format("%d", size), true);
|
|
|
|
} else if (i == languageRow) {
|
|
|
|
textCell.setTextAndValue(LocaleController.getString("Language", R.string.Language), LocaleController.getCurrentLanguageName(), true);
|
|
|
|
} else if (i == contactsSortRow) {
|
|
|
|
String value;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
int sort = preferences.getInt("sortContactsBy", 0);
|
|
|
|
if (sort == 0) {
|
|
|
|
value = LocaleController.getString("Default", R.string.Default);
|
|
|
|
} else if (sort == 1) {
|
|
|
|
value = LocaleController.getString("FirstName", R.string.SortFirstName);
|
|
|
|
} else {
|
|
|
|
value = LocaleController.getString("LastName", R.string.SortLastName);
|
|
|
|
}
|
|
|
|
textCell.setTextAndValue(LocaleController.getString("SortBy", R.string.SortBy), value, true);
|
|
|
|
} else if (i == notificationRow) {
|
|
|
|
textCell.setText(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds), true);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == blockedRow) {
|
2014-11-11 22:16:17 +00:00
|
|
|
textCell.setText(LocaleController.getString("BlockedUsers", R.string.BlockedUsers), true);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == backgroundRow) {
|
2014-11-11 22:16:17 +00:00
|
|
|
textCell.setText(LocaleController.getString("ChatBackground", R.string.ChatBackground), true);
|
2013-12-20 19:25:49 +00:00
|
|
|
} else if (i == sendLogsRow) {
|
2014-11-11 22:16:17 +00:00
|
|
|
textCell.setText("Send Logs", true);
|
2014-02-28 22:28:25 +00:00
|
|
|
} else if (i == clearLogsRow) {
|
2014-11-11 22:16:17 +00:00
|
|
|
textCell.setText("Clear Logs", true);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == askQuestionRow) {
|
2014-11-11 22:16:17 +00:00
|
|
|
textCell.setText(LocaleController.getString("AskAQuestion", R.string.AskAQuestion), true);
|
2014-02-04 18:36:55 +00:00
|
|
|
} else if (i == terminateSessionsRow) {
|
2014-11-11 22:16:17 +00:00
|
|
|
textCell.setText(LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions), false);
|
2014-03-25 23:38:23 +00:00
|
|
|
} else if (i == switchBackendButtonRow) {
|
2014-11-11 22:16:17 +00:00
|
|
|
textCell.setText("Switch Backend", true);
|
2014-04-02 17:36:57 +00:00
|
|
|
} else if (i == telegramFaqRow) {
|
2014-11-11 22:16:17 +00:00
|
|
|
textCell.setText(LocaleController.getString("TelegramFAQ", R.string.TelegramFaq), true);
|
2014-05-24 22:47:05 +00:00
|
|
|
} else if (i == contactsReimportRow) {
|
2014-11-11 22:16:17 +00:00
|
|
|
textCell.setText(LocaleController.getString("ImportContacts", R.string.ImportContacts), true);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (type == 3) {
|
|
|
|
if (view == null) {
|
2014-11-11 22:16:17 +00:00
|
|
|
view = new TextCheckCell(mContext);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-11-11 22:16:17 +00:00
|
|
|
TextCheckCell textCell = (TextCheckCell) view;
|
|
|
|
|
2014-02-04 18:36:55 +00:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (i == enableAnimationsRow) {
|
2014-11-11 22:16:17 +00:00
|
|
|
textCell.setTextAndCheck(LocaleController.getString("EnableAnimations", R.string.EnableAnimations), preferences.getBoolean("view_animations", true), true);
|
2014-02-04 18:36:55 +00:00
|
|
|
} else if (i == sendByEnterRow) {
|
2014-11-11 22:16:17 +00:00
|
|
|
textCell.setTextAndCheck(LocaleController.getString("SendByEnter", R.string.SendByEnter), preferences.getBoolean("send_by_enter", false), false);
|
2014-09-30 22:36:18 +00:00
|
|
|
} else if (i == saveToGalleryRow) {
|
2014-11-11 22:16:17 +00:00
|
|
|
textCell.setTextAndCheck(LocaleController.getString("SaveToGallerySettings", R.string.SaveToGallerySettings), MediaController.getInstance().canSaveToGallery(), false);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (type == 4) {
|
|
|
|
if (view == null) {
|
2014-11-11 22:16:17 +00:00
|
|
|
view = new HeaderCell(mContext);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-11-11 22:16:17 +00:00
|
|
|
if (i == settingsSectionRow2) {
|
|
|
|
((HeaderCell) view).setText(LocaleController.getString("SETTINGS", R.string.SETTINGS));
|
|
|
|
} else if (i == supportSectionRow2) {
|
|
|
|
((HeaderCell) view).setText(LocaleController.getString("Support", R.string.Support));
|
|
|
|
} else if (i == messagesSectionRow2) {
|
|
|
|
((HeaderCell) view).setText(LocaleController.getString("MessagesSettings", R.string.MessagesSettings));
|
|
|
|
} else if (i == mediaDownloadSection2) {
|
|
|
|
((HeaderCell) view).setText(LocaleController.getString("AutomaticMediaDownload", R.string.AutomaticMediaDownload));
|
|
|
|
} else if (i == numberSectionRow) {
|
|
|
|
((HeaderCell) view).setText(LocaleController.getString("Info", R.string.Info));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-11-11 22:16:17 +00:00
|
|
|
} else if (type == 5) {
|
2014-05-16 23:05:49 +00:00
|
|
|
if (view == null) {
|
2014-11-12 10:41:46 +00:00
|
|
|
view = new TextInfoCell(mContext);
|
2014-05-16 23:05:49 +00:00
|
|
|
try {
|
|
|
|
PackageInfo pInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
|
2014-11-12 10:41:46 +00:00
|
|
|
((TextInfoCell) view).setText(String.format(Locale.US, "Telegram for Android v%s (%d)", pInfo.versionName, pInfo.versionCode));
|
2014-05-16 23:05:49 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
2014-11-11 22:16:17 +00:00
|
|
|
} else if (type == 6) {
|
2014-08-22 14:24:33 +00:00
|
|
|
if (view == null) {
|
2014-11-11 22:16:17 +00:00
|
|
|
view = new TextDetailSettingsCell(mContext);
|
2014-08-22 14:24:33 +00:00
|
|
|
}
|
2014-11-11 22:16:17 +00:00
|
|
|
TextDetailSettingsCell textCell = (TextDetailSettingsCell) view;
|
2014-08-22 14:24:33 +00:00
|
|
|
|
2014-11-11 22:16:17 +00:00
|
|
|
if (i == mobileDownloadRow || i == wifiDownloadRow || i == roamingDownloadRow) {
|
|
|
|
int mask = 0;
|
|
|
|
String value;
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
if (i == mobileDownloadRow) {
|
|
|
|
value = LocaleController.getString("WhenUsingMobileData", R.string.WhenUsingMobileData);
|
|
|
|
mask = MediaController.getInstance().mobileDataDownloadMask;
|
|
|
|
} else if (i == wifiDownloadRow) {
|
|
|
|
value = LocaleController.getString("WhenConnectedOnWiFi", R.string.WhenConnectedOnWiFi);
|
|
|
|
mask = MediaController.getInstance().wifiDownloadMask;
|
|
|
|
} else {
|
|
|
|
value = LocaleController.getString("WhenRoaming", R.string.WhenRoaming);
|
|
|
|
mask = MediaController.getInstance().roamingDownloadMask;
|
2014-08-22 14:24:33 +00:00
|
|
|
}
|
2014-11-11 22:16:17 +00:00
|
|
|
String text = "";
|
|
|
|
if ((mask & MediaController.AUTODOWNLOAD_MASK_PHOTO) != 0) {
|
|
|
|
text += LocaleController.getString("AttachPhoto", R.string.AttachPhoto);
|
2014-08-22 14:24:33 +00:00
|
|
|
}
|
2014-11-11 22:16:17 +00:00
|
|
|
if ((mask & MediaController.AUTODOWNLOAD_MASK_AUDIO) != 0) {
|
|
|
|
if (text.length() != 0) {
|
|
|
|
text += ", ";
|
|
|
|
}
|
|
|
|
text += LocaleController.getString("AttachAudio", R.string.AttachAudio);
|
2014-08-22 14:24:33 +00:00
|
|
|
}
|
2014-11-11 22:16:17 +00:00
|
|
|
if ((mask & MediaController.AUTODOWNLOAD_MASK_VIDEO) != 0) {
|
|
|
|
if (text.length() != 0) {
|
|
|
|
text += ", ";
|
|
|
|
}
|
|
|
|
text += LocaleController.getString("AttachVideo", R.string.AttachVideo);
|
|
|
|
}
|
|
|
|
if ((mask & MediaController.AUTODOWNLOAD_MASK_DOCUMENT) != 0) {
|
|
|
|
if (text.length() != 0) {
|
|
|
|
text += ", ";
|
|
|
|
}
|
|
|
|
text += LocaleController.getString("AttachDocument", R.string.AttachDocument);
|
|
|
|
}
|
|
|
|
if (text.length() == 0) {
|
|
|
|
text = LocaleController.getString("NoMediaAutoDownload", R.string.NoMediaAutoDownload);
|
|
|
|
}
|
|
|
|
textCell.setTextAndValue(value, text, true);
|
|
|
|
} else if (i == numberRow) {
|
|
|
|
TLRPC.User user = UserConfig.getCurrentUser();
|
|
|
|
String value;
|
|
|
|
if (user != null && user.phone != null && user.phone.length() != 0) {
|
|
|
|
value = PhoneFormat.getInstance().format("+" + user.phone);
|
|
|
|
} else {
|
|
|
|
value = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
|
|
|
|
}
|
|
|
|
textCell.setTextAndValue(value, LocaleController.getString("Phone", R.string.Phone), true);
|
|
|
|
} else if (i == usernameRow) {
|
|
|
|
TLRPC.User user = UserConfig.getCurrentUser();
|
|
|
|
String value;
|
|
|
|
if (user != null && user.username != null && user.username.length() != 0) {
|
|
|
|
value = "@" + user.username;
|
|
|
|
} else {
|
|
|
|
value = LocaleController.getString("UsernameEmpty", R.string.UsernameEmpty);
|
|
|
|
}
|
|
|
|
textCell.setTextAndValue(value, LocaleController.getString("Username", R.string.Username), false);
|
2014-08-22 14:24:33 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int i) {
|
2014-11-11 22:16:17 +00:00
|
|
|
if (i == emptyRow) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return 0;
|
2014-11-11 22:16:17 +00:00
|
|
|
} if (i == settingsSectionRow || i == supportSectionRow || i == messagesSectionRow || i == mediaDownloadSection || i == contactsSectionRow) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return 1;
|
2014-09-30 22:36:18 +00:00
|
|
|
} else if (i == enableAnimationsRow || i == sendByEnterRow || i == saveToGalleryRow) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return 3;
|
2014-11-11 22:16:17 +00:00
|
|
|
} else if (i == notificationRow || i == blockedRow || i == backgroundRow || i == askQuestionRow || i == sendLogsRow || i == terminateSessionsRow || i == clearLogsRow || i == switchBackendButtonRow || i == telegramFaqRow || i == contactsReimportRow || i == textSizeRow || i == languageRow || i == contactsSortRow) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return 2;
|
2014-05-16 23:05:49 +00:00
|
|
|
} else if (i == versionRow) {
|
2014-11-11 22:16:17 +00:00
|
|
|
return 5;
|
|
|
|
} else if (i == wifiDownloadRow || i == mobileDownloadRow || i == roamingDownloadRow || i == numberRow || i == usernameRow) {
|
2014-05-16 23:05:49 +00:00
|
|
|
return 6;
|
2014-11-11 22:16:17 +00:00
|
|
|
} else if (i == settingsSectionRow2 || i == messagesSectionRow2 || i == supportSectionRow2 || i == numberSectionRow || i == mediaDownloadSection2) {
|
|
|
|
return 4;
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
2014-11-11 22:16:17 +00:00
|
|
|
return 7;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEmpty() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|