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;
|
|
|
|
import android.graphics.Typeface;
|
2013-12-20 19:25:49 +00:00
|
|
|
import android.net.Uri;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.os.Bundle;
|
2013-12-20 19:25:49 +00:00
|
|
|
import android.support.v7.app.ActionBar;
|
2014-02-04 18:36:55 +00:00
|
|
|
import android.support.v7.app.ActionBarActivity;
|
2014-02-28 22:28:25 +00:00
|
|
|
import android.util.Base64;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.LayoutInflater;
|
2013-12-20 19:25:49 +00:00
|
|
|
import android.view.MenuItem;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.BaseAdapter;
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
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
|
|
|
|
|
|
|
import org.telegram.PhoneFormat.PhoneFormat;
|
2014-03-22 23:20:13 +00:00
|
|
|
import org.telegram.messenger.BuildVars;
|
2014-03-22 22:31:55 +00:00
|
|
|
import org.telegram.messenger.LocaleController;
|
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;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.MessagesController;
|
2014-02-04 18:36:55 +00:00
|
|
|
import org.telegram.messenger.MessagesStorage;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.NotificationCenter;
|
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.RPCRequest;
|
|
|
|
import org.telegram.messenger.UserConfig;
|
|
|
|
import org.telegram.messenger.Utilities;
|
2014-02-04 18:36:55 +00:00
|
|
|
import org.telegram.objects.PhotoObject;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.ui.Views.AvatarUpdater;
|
|
|
|
import org.telegram.ui.Views.BackupImageView;
|
|
|
|
import org.telegram.ui.Views.BaseFragment;
|
|
|
|
import org.telegram.ui.Views.OnSwipeTouchListener;
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
public class SettingsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
|
|
|
private ListView listView;
|
|
|
|
private ListAdapter listAdapter;
|
|
|
|
private AvatarUpdater avatarUpdater = new AvatarUpdater();
|
|
|
|
|
2014-03-22 22:31:55 +00:00
|
|
|
private int profileRow;
|
|
|
|
private int numberSectionRow;
|
|
|
|
private int numberRow;
|
|
|
|
private int settingsSectionRow;
|
|
|
|
private int textSizeRow;
|
|
|
|
private int enableAnimationsRow;
|
|
|
|
private int notificationRow;
|
|
|
|
private int blockedRow;
|
|
|
|
private int backgroundRow;
|
|
|
|
private int supportSectionRow;
|
|
|
|
private int askQuestionRow;
|
|
|
|
private int logoutRow;
|
|
|
|
private int sendLogsRow;
|
|
|
|
private int clearLogsRow;
|
|
|
|
private int rowCount;
|
|
|
|
private int messagesSectionRow;
|
|
|
|
private int sendByEnterRow;
|
|
|
|
private int terminateSessionsRow;
|
|
|
|
private int photoDownloadSection;
|
|
|
|
private int photoDownloadChatRow;
|
|
|
|
private int photoDownloadPrivateRow;
|
|
|
|
private int audioDownloadSection;
|
|
|
|
private int audioDownloadChatRow;
|
|
|
|
private int audioDownloadPrivateRow;
|
2014-03-25 00:25:32 +00:00
|
|
|
private int languageRow;
|
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-03-22 22:31:55 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().users.get(UserConfig.clientUserId);
|
2014-02-04 18:36:55 +00:00
|
|
|
if (user == null) {
|
|
|
|
user = UserConfig.currentUser;
|
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().users.put(user.id, user);
|
2014-02-04 18:36:55 +00:00
|
|
|
} else {
|
|
|
|
UserConfig.currentUser = user;
|
|
|
|
}
|
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo)response;
|
|
|
|
ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
|
|
|
|
TLRPC.PhotoSize smallSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 100, 100);
|
|
|
|
TLRPC.PhotoSize bigSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 1000, 1000);
|
|
|
|
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-02-04 18:36:55 +00:00
|
|
|
Utilities.RunOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.updateInterfaces, MessagesController.UPDATE_MASK_ALL);
|
2014-02-04 18:36:55 +00:00
|
|
|
UserConfig.saveConfig(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}, null, true, RPCRequest.RPCRequestClassGeneric);
|
|
|
|
}
|
|
|
|
};
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
rowCount = 0;
|
|
|
|
profileRow = rowCount++;
|
|
|
|
numberSectionRow = rowCount++;
|
|
|
|
numberRow = rowCount++;
|
|
|
|
settingsSectionRow = rowCount++;
|
|
|
|
enableAnimationsRow = rowCount++;
|
2014-03-25 00:25:32 +00:00
|
|
|
languageRow = rowCount++;
|
2013-10-25 15:19:00 +00:00
|
|
|
notificationRow = rowCount++;
|
|
|
|
blockedRow = rowCount++;
|
|
|
|
backgroundRow = rowCount++;
|
2014-02-04 18:36:55 +00:00
|
|
|
terminateSessionsRow = rowCount++;
|
|
|
|
photoDownloadSection = rowCount++;
|
|
|
|
photoDownloadChatRow = rowCount++;
|
|
|
|
photoDownloadPrivateRow = rowCount++;
|
2014-03-22 22:31:55 +00:00
|
|
|
audioDownloadSection = rowCount++;
|
|
|
|
audioDownloadChatRow = rowCount++;
|
|
|
|
audioDownloadPrivateRow = rowCount++;
|
2014-02-04 18:36:55 +00:00
|
|
|
messagesSectionRow = rowCount++;
|
|
|
|
textSizeRow = rowCount++;
|
|
|
|
sendByEnterRow = rowCount++;
|
2013-10-25 15:19:00 +00:00
|
|
|
supportSectionRow = 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++;
|
2013-12-20 19:25:49 +00:00
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
askQuestionRow = rowCount++;
|
|
|
|
logoutRow = rowCount++;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, MessagesController.updateInterfaces);
|
2013-10-25 15:19:00 +00:00
|
|
|
avatarUpdater.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
if (fragmentView == null) {
|
|
|
|
fragmentView = inflater.inflate(R.layout.settings_layout, container, false);
|
|
|
|
listAdapter = new ListAdapter(parentActivity);
|
|
|
|
listView = (ListView)fragmentView.findViewById(R.id.listView);
|
|
|
|
listView.setAdapter(listAdapter);
|
|
|
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
|
if (i == textSizeRow) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
2014-03-22 22:31:55 +00:00
|
|
|
builder.setTitle(LocaleController.getString("TextSize", R.string.TextSize));
|
2014-03-25 00:25:32 +00:00
|
|
|
builder.setItems(new CharSequence[]{String.format("%d", 12), String.format("%d", 13), String.format("%d", 14), String.format("%d", 15), String.format("%d", 16), String.format("%d", 17), String.format("%d", 18), String.format("%d", 19), String.format("%d", 20), String.format("%d", 21), String.format("%d", 22), String.format("%d", 23), String.format("%d", 24)}, 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();
|
2013-12-20 19:25:49 +00:00
|
|
|
editor.putInt("fons_size", 12 + which);
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().fontSize = 12 + which;
|
2013-10-25 15:19:00 +00:00
|
|
|
editor.commit();
|
|
|
|
if (listView != null) {
|
|
|
|
listView.invalidateViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-03-22 22:31:55 +00:00
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2013-10-25 15:19:00 +00:00
|
|
|
builder.show().setCanceledOnTouchOutside(true);
|
|
|
|
} 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-03-04 20:04:57 +00:00
|
|
|
((LaunchActivity)parentActivity).presentFragment(new SettingsNotificationsActivity(), "settings_notifications", false);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == blockedRow) {
|
2014-03-04 20:04:57 +00:00
|
|
|
((LaunchActivity)parentActivity).presentFragment(new SettingsBlockedUsers(), "settings_blocked", false);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == backgroundRow) {
|
2014-03-04 20:04:57 +00:00
|
|
|
((LaunchActivity)parentActivity).presentFragment(new SettingsWallpapersActivity(), "settings_wallpapers", false);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == askQuestionRow) {
|
2014-02-28 22:28:25 +00:00
|
|
|
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-03-22 22:31:55 +00:00
|
|
|
supportUser = MessagesController.getInstance().users.get(uid);
|
2014-02-28 22:28:25 +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());
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
supportUser = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (supportUser == null) {
|
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final ProgressDialog progressDialog = new ProgressDialog(parentActivity);
|
|
|
|
progressDialog.setMessage(parentActivity.getString(R.string.Loading));
|
|
|
|
progressDialog.setCanceledOnTouchOutside(false);
|
|
|
|
progressDialog.setCancelable(false);
|
|
|
|
progressDialog.show();
|
|
|
|
TLRPC.TL_help_getSupport req = new TLRPC.TL_help_getSupport();
|
2014-03-22 22:31:55 +00:00
|
|
|
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
2014-02-28 22:28:25 +00:00
|
|
|
@Override
|
|
|
|
public void run(TLObject response, TLRPC.TL_error error) {
|
|
|
|
if (error == null) {
|
|
|
|
|
|
|
|
final TLRPC.TL_help_support res = (TLRPC.TL_help_support)response;
|
|
|
|
Utilities.RunOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-03-10 09:27:49 +00:00
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-28 22:28:25 +00:00
|
|
|
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-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().users.put(res.user.id, res.user);
|
2014-02-28 22:28:25 +00:00
|
|
|
ChatActivity fragment = new ChatActivity();
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putInt("user_id", res.user.id);
|
|
|
|
fragment.setArguments(bundle);
|
2014-03-04 20:04:57 +00:00
|
|
|
((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), false);
|
2014-02-28 22:28:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Utilities.RunOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
progressDialog.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, null, true, RPCRequest.RPCRequestClassGeneric);
|
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().users.putIfAbsent(supportUser.id, supportUser);
|
2014-02-28 22:28:25 +00:00
|
|
|
ChatActivity fragment = new ChatActivity();
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putInt("user_id", supportUser.id);
|
|
|
|
fragment.setArguments(bundle);
|
2014-03-04 20:04:57 +00:00
|
|
|
((LaunchActivity)parentActivity).presentFragment(fragment, "chat" + Math.random(), false);
|
2014-02-28 22:28:25 +00:00
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
} else if (i == terminateSessionsRow) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
2014-03-22 22:31:55 +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() {
|
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
|
|
|
|
public void run(TLObject response, TLRPC.TL_error error) {
|
|
|
|
ActionBarActivity inflaterActivity = parentActivity;
|
|
|
|
if (inflaterActivity == null) {
|
|
|
|
inflaterActivity = (ActionBarActivity)getActivity();
|
|
|
|
}
|
|
|
|
if (inflaterActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (error == null && response instanceof TLRPC.TL_boolTrue) {
|
|
|
|
Toast toast = Toast.makeText(inflaterActivity, R.string.TerminateAllSessions, Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
} else {
|
|
|
|
Toast toast = Toast.makeText(inflaterActivity, R.string.UnknownError, Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
UserConfig.registeredForPush = false;
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().registerForPush(UserConfig.pushString);
|
2014-02-04 18:36:55 +00:00
|
|
|
}
|
|
|
|
}, null, true, RPCRequest.RPCRequestClassGeneric);
|
|
|
|
}
|
|
|
|
});
|
2014-03-22 22:31:55 +00:00
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2014-02-04 18:36:55 +00:00
|
|
|
builder.show().setCanceledOnTouchOutside(true);
|
|
|
|
} else if (i == photoDownloadChatRow) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
boolean value = preferences.getBoolean("photo_download_chat", true);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("photo_download_chat", !value);
|
|
|
|
editor.commit();
|
|
|
|
if (listView != null) {
|
|
|
|
listView.invalidateViews();
|
|
|
|
}
|
|
|
|
} else if (i == photoDownloadPrivateRow) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
boolean value = preferences.getBoolean("photo_download_user", true);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("photo_download_user", !value);
|
|
|
|
editor.commit();
|
|
|
|
if (listView != null) {
|
|
|
|
listView.invalidateViews();
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
} else if (i == audioDownloadChatRow) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
boolean value = preferences.getBoolean("audio_download_chat", true);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("audio_download_chat", !value);
|
|
|
|
editor.commit();
|
|
|
|
if (listView != null) {
|
|
|
|
listView.invalidateViews();
|
|
|
|
}
|
|
|
|
} else if (i == audioDownloadPrivateRow) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
boolean value = preferences.getBoolean("audio_download_user", true);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putBoolean("audio_download_user", !value);
|
|
|
|
editor.commit();
|
|
|
|
if (listView != null) {
|
|
|
|
listView.invalidateViews();
|
|
|
|
}
|
2014-03-25 00:25:32 +00:00
|
|
|
} else if (i == languageRow) {
|
|
|
|
((LaunchActivity)parentActivity).presentFragment(new LanguageSelectActivity(), "settings_wallpapers", false);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
// else if (i == 6) {
|
|
|
|
// UserConfig.saveIncomingPhotos = !UserConfig.saveIncomingPhotos;
|
|
|
|
// listView.invalidateViews();
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
listView.setOnTouchListener(new OnSwipeTouchListener() {
|
|
|
|
public void onSwipeRight() {
|
|
|
|
finishFragment(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
2014-02-28 22:28:25 +00:00
|
|
|
avatarUpdater.onActivityResult(requestCode, resultCode, data);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
|
|
|
if (id == MessagesController.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) {
|
|
|
|
if (listView != null) {
|
|
|
|
listView.invalidateViews();
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void applySelfActionBar() {
|
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ActionBar actionBar = parentActivity.getSupportActionBar();
|
|
|
|
actionBar.setDisplayShowTitleEnabled(true);
|
|
|
|
actionBar.setDisplayShowHomeEnabled(false);
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
actionBar.setDisplayUseLogoEnabled(false);
|
|
|
|
actionBar.setDisplayShowCustomEnabled(false);
|
|
|
|
actionBar.setSubtitle(null);
|
|
|
|
actionBar.setCustomView(null);
|
2014-03-22 22:31:55 +00:00
|
|
|
actionBar.setTitle(LocaleController.getString("Settings", R.string.Settings));
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
TextView title = (TextView)parentActivity.findViewById(R.id.action_bar_title);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (title == null) {
|
|
|
|
final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android");
|
|
|
|
title = (TextView)parentActivity.findViewById(subtitleId);
|
|
|
|
}
|
|
|
|
if (title != null) {
|
|
|
|
title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
|
|
|
title.setCompoundDrawablePadding(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-02-28 22:28:25 +00:00
|
|
|
startActivity(Intent.createChooser(i, "Select email application."));
|
2013-12-20 19:25:49 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
if (isFinish) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
if (getActivity() == null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!firstStart && listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
firstStart = false;
|
2014-03-04 20:04:57 +00:00
|
|
|
((LaunchActivity)parentActivity).showActionBar();
|
|
|
|
((LaunchActivity)parentActivity).updateActionBar();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-12-20 19:25:49 +00:00
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2013-10-25 15:19:00 +00:00
|
|
|
int itemId = item.getItemId();
|
|
|
|
switch (itemId) {
|
|
|
|
case android.R.id.home:
|
|
|
|
finishFragment();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private class ListAdapter extends BaseAdapter {
|
|
|
|
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 ||
|
|
|
|
i == askQuestionRow || i == sendLogsRow || i == sendByEnterRow || i == terminateSessionsRow || i == photoDownloadPrivateRow ||
|
2014-03-25 00:25:32 +00:00
|
|
|
i == photoDownloadChatRow || i == clearLogsRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow || i == languageRow;
|
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) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
view = li.inflate(R.layout.settings_name_layout, viewGroup, false);
|
|
|
|
|
|
|
|
ImageButton button = (ImageButton)view.findViewById(R.id.settings_edit_name);
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2014-03-04 20:04:57 +00:00
|
|
|
((LaunchActivity)parentActivity).presentFragment(new SettingsChangeNameActivity(), "change_name", false);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final ImageButton button2 = (ImageButton)view.findViewById(R.id.settings_change_avatar_button);
|
|
|
|
button2.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
|
|
|
|
|
|
|
CharSequence[] items;
|
|
|
|
|
2014-03-22 22:31:55 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().users.get(UserConfig.clientUserId);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (user == null) {
|
|
|
|
user = UserConfig.currentUser;
|
|
|
|
}
|
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-20 19:25:49 +00:00
|
|
|
boolean fullMenu = false;
|
2013-10-25 15:19:00 +00:00
|
|
|
if (user.photo != null && user.photo.photo_big != null && !(user.photo instanceof TLRPC.TL_userProfilePhotoEmpty)) {
|
2014-03-22 22:31:55 +00:00
|
|
|
items = new CharSequence[] {LocaleController.getString("OpenPhoto", R.string.OpenPhoto), LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto)};
|
2013-12-20 19:25:49 +00:00
|
|
|
fullMenu = true;
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
2014-03-22 22:31:55 +00:00
|
|
|
items = new CharSequence[] {LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley)};
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2013-12-20 19:25:49 +00:00
|
|
|
final boolean full = fullMenu;
|
2013-10-25 15:19:00 +00:00
|
|
|
builder.setItems(items, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
2013-12-20 19:25:49 +00:00
|
|
|
if (i == 0 && full) {
|
2014-03-22 22:31:55 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().users.get(UserConfig.clientUserId);
|
2013-12-20 19:25:49 +00:00
|
|
|
if (user != null && user.photo != null && user.photo.photo_big != null) {
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().addToMemCache(56, user.id);
|
|
|
|
NotificationCenter.getInstance().addToMemCache(53, user.photo.photo_big);
|
2013-12-20 19:25:49 +00:00
|
|
|
Intent intent = new Intent(parentActivity, GalleryImageViewer.class);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
} else if (i == 0 && !full || i == 1 && full) {
|
2013-10-25 15:19:00 +00:00
|
|
|
avatarUpdater.openCamera();
|
2013-12-20 19:25:49 +00:00
|
|
|
} else if (i == 1 && !full || i == 2 && full) {
|
2013-10-25 15:19:00 +00:00
|
|
|
avatarUpdater.openGallery();
|
2013-12-20 19:25:49 +00:00
|
|
|
} else if (i == 3) {
|
2013-10-25 15:19:00 +00:00
|
|
|
TLRPC.TL_photos_updateProfilePhoto req = new TLRPC.TL_photos_updateProfilePhoto();
|
|
|
|
req.id = new TLRPC.TL_inputPhotoEmpty();
|
|
|
|
req.crop = new TLRPC.TL_inputPhotoCropAuto();
|
|
|
|
UserConfig.currentUser.photo = new TLRPC.TL_userProfilePhotoEmpty();
|
2014-03-22 22:31:55 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().users.get(UserConfig.clientUserId);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (user == null) {
|
|
|
|
user = UserConfig.currentUser;
|
|
|
|
}
|
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (user != null) {
|
|
|
|
user.photo = UserConfig.currentUser.photo;
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.updateInterfaces, MessagesController.UPDATE_MASK_ALL);
|
|
|
|
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-03-22 22:31:55 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().users.get(UserConfig.clientUserId);
|
2014-02-04 18:36:55 +00:00
|
|
|
if (user == null) {
|
|
|
|
user = UserConfig.currentUser;
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().users.put(user.id, user);
|
2014-02-04 18:36:55 +00:00
|
|
|
} else {
|
|
|
|
UserConfig.currentUser = user;
|
|
|
|
}
|
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
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-02-04 18:36:55 +00:00
|
|
|
user.photo = (TLRPC.UserProfilePhoto)response;
|
|
|
|
Utilities.RunOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.updateInterfaces, MessagesController.UPDATE_MASK_ALL);
|
2014-02-04 18:36:55 +00:00
|
|
|
UserConfig.saveConfig(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}, null, true, RPCRequest.RPCRequestClassGeneric);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.show().setCanceledOnTouchOutside(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-03-25 00:25:32 +00:00
|
|
|
TextView textView = (TextView)view.findViewById(R.id.settings_online);
|
|
|
|
textView.setText(LocaleController.getString("Online", R.string.Online));
|
|
|
|
|
|
|
|
textView = (TextView)view.findViewById(R.id.settings_name);
|
2013-12-20 19:25:49 +00:00
|
|
|
Typeface typeface = Utilities.getTypeface("fonts/rmedium.ttf");
|
|
|
|
textView.setTypeface(typeface);
|
2014-03-22 22:31:55 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().users.get(UserConfig.clientUserId);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (user == null) {
|
|
|
|
user = UserConfig.currentUser;
|
|
|
|
}
|
|
|
|
if (user != null) {
|
|
|
|
textView.setText(Utilities.formatName(user.first_name, user.last_name));
|
|
|
|
BackupImageView avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image);
|
|
|
|
TLRPC.FileLocation photo = null;
|
|
|
|
if (user.photo != null) {
|
|
|
|
photo = user.photo.photo_small;
|
|
|
|
}
|
|
|
|
avatarImage.setImage(photo, null, Utilities.getUserAvatarForId(user.id));
|
|
|
|
}
|
|
|
|
return view;
|
|
|
|
} else if (type == 1) {
|
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
view = li.inflate(R.layout.settings_section_layout, viewGroup, false);
|
|
|
|
}
|
|
|
|
TextView textView = (TextView)view.findViewById(R.id.settings_section_text);
|
|
|
|
if (i == numberSectionRow) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("YourPhoneNumber", R.string.YourPhoneNumber));
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == settingsSectionRow) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("SETTINGS", R.string.SETTINGS));
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == supportSectionRow) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("Support", R.string.Support));
|
2014-02-04 18:36:55 +00:00
|
|
|
} else if (i == messagesSectionRow) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("MessagesSettings", R.string.MessagesSettings));
|
2014-02-04 18:36:55 +00:00
|
|
|
} else if (i == photoDownloadSection) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("AutomaticPhotoDownload", R.string.AutomaticPhotoDownload));
|
|
|
|
} else if (i == audioDownloadSection) {
|
|
|
|
textView.setText(LocaleController.getString("AutomaticAudioDownload", R.string.AutomaticAudioDownload));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (type == 2) {
|
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
view = li.inflate(R.layout.settings_row_button_layout, viewGroup, false);
|
|
|
|
}
|
|
|
|
TextView textView = (TextView)view.findViewById(R.id.settings_row_text);
|
|
|
|
View divider = view.findViewById(R.id.settings_row_divider);
|
|
|
|
if (i == numberRow) {
|
|
|
|
TLRPC.User user = UserConfig.currentUser;
|
|
|
|
if (user != null && user.phone != null && user.phone.length() != 0) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(PhoneFormat.getInstance().format("+" + user.phone));
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
textView.setText("Unknown");
|
|
|
|
}
|
|
|
|
divider.setVisibility(View.INVISIBLE);
|
|
|
|
} else if (i == notificationRow) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds));
|
2013-10-25 15:19:00 +00:00
|
|
|
divider.setVisibility(View.VISIBLE);
|
|
|
|
} else if (i == blockedRow) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("BlockedUsers", R.string.BlockedUsers));
|
2013-10-25 15:19:00 +00:00
|
|
|
divider.setVisibility(backgroundRow != 0 ? View.VISIBLE : View.INVISIBLE);
|
|
|
|
} else if (i == backgroundRow) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("ChatBackground", R.string.ChatBackground));
|
2014-02-04 18:36:55 +00:00
|
|
|
divider.setVisibility(View.VISIBLE);
|
2013-12-20 19:25:49 +00:00
|
|
|
} else if (i == sendLogsRow) {
|
|
|
|
textView.setText("Send Logs");
|
|
|
|
divider.setVisibility(View.VISIBLE);
|
2014-02-28 22:28:25 +00:00
|
|
|
} else if (i == clearLogsRow) {
|
|
|
|
textView.setText("Clear Logs");
|
|
|
|
divider.setVisibility(View.VISIBLE);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (i == askQuestionRow) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("AskAQuestion", R.string.AskAQuestion));
|
2013-10-25 15:19:00 +00:00
|
|
|
divider.setVisibility(View.INVISIBLE);
|
2014-02-04 18:36:55 +00:00
|
|
|
} else if (i == terminateSessionsRow) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions));
|
2014-02-04 18:36:55 +00:00
|
|
|
divider.setVisibility(View.INVISIBLE);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else if (type == 3) {
|
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
view = li.inflate(R.layout.settings_row_check_layout, viewGroup, false);
|
|
|
|
}
|
|
|
|
TextView textView = (TextView)view.findViewById(R.id.settings_row_text);
|
|
|
|
View divider = view.findViewById(R.id.settings_row_divider);
|
2014-02-04 18:36:55 +00:00
|
|
|
ImageView checkButton = (ImageView)view.findViewById(R.id.settings_row_check_button);
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
2013-10-25 15:19:00 +00:00
|
|
|
if (i == enableAnimationsRow) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("EnableAnimations", R.string.EnableAnimations));
|
2013-10-25 15:19:00 +00:00
|
|
|
divider.setVisibility(View.VISIBLE);
|
2014-02-04 18:36:55 +00:00
|
|
|
boolean enabled = preferences.getBoolean("view_animations", true);
|
|
|
|
if (enabled) {
|
|
|
|
checkButton.setImageResource(R.drawable.btn_check_on);
|
|
|
|
} else {
|
|
|
|
checkButton.setImageResource(R.drawable.btn_check_off);
|
|
|
|
}
|
|
|
|
} else if (i == sendByEnterRow) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("SendByEnter", R.string.SendByEnter));
|
2014-02-04 18:36:55 +00:00
|
|
|
divider.setVisibility(View.INVISIBLE);
|
|
|
|
boolean enabled = preferences.getBoolean("send_by_enter", false);
|
|
|
|
if (enabled) {
|
|
|
|
checkButton.setImageResource(R.drawable.btn_check_on);
|
|
|
|
} else {
|
|
|
|
checkButton.setImageResource(R.drawable.btn_check_off);
|
|
|
|
}
|
|
|
|
} else if (i == photoDownloadChatRow) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("AutomaticPhotoDownloadGroups", R.string.AutomaticPhotoDownloadGroups));
|
2014-02-04 18:36:55 +00:00
|
|
|
divider.setVisibility(View.VISIBLE);
|
|
|
|
boolean enabled = preferences.getBoolean("photo_download_chat", true);
|
|
|
|
if (enabled) {
|
|
|
|
checkButton.setImageResource(R.drawable.btn_check_on);
|
|
|
|
} else {
|
|
|
|
checkButton.setImageResource(R.drawable.btn_check_off);
|
|
|
|
}
|
|
|
|
} else if (i == photoDownloadPrivateRow) {
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("AutomaticPhotoDownloadPrivateChats", R.string.AutomaticPhotoDownloadPrivateChats));
|
2014-02-04 18:36:55 +00:00
|
|
|
divider.setVisibility(View.INVISIBLE);
|
|
|
|
boolean enabled = preferences.getBoolean("photo_download_user", true);
|
|
|
|
if (enabled) {
|
2013-10-25 15:19:00 +00:00
|
|
|
checkButton.setImageResource(R.drawable.btn_check_on);
|
|
|
|
} else {
|
|
|
|
checkButton.setImageResource(R.drawable.btn_check_off);
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
} else if (i == audioDownloadChatRow) {
|
|
|
|
textView.setText(LocaleController.getString("AutomaticPhotoDownloadGroups", R.string.AutomaticPhotoDownloadGroups));
|
|
|
|
divider.setVisibility(View.VISIBLE);
|
|
|
|
boolean enabled = preferences.getBoolean("audio_download_chat", true);
|
|
|
|
if (enabled) {
|
|
|
|
checkButton.setImageResource(R.drawable.btn_check_on);
|
|
|
|
} else {
|
|
|
|
checkButton.setImageResource(R.drawable.btn_check_off);
|
|
|
|
}
|
|
|
|
} else if (i == audioDownloadPrivateRow) {
|
|
|
|
textView.setText(LocaleController.getString("AutomaticPhotoDownloadPrivateChats", R.string.AutomaticPhotoDownloadPrivateChats));
|
|
|
|
divider.setVisibility(View.INVISIBLE);
|
|
|
|
boolean enabled = preferences.getBoolean("audio_download_user", true);
|
|
|
|
if (enabled) {
|
|
|
|
checkButton.setImageResource(R.drawable.btn_check_on);
|
|
|
|
} else {
|
|
|
|
checkButton.setImageResource(R.drawable.btn_check_off);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
// if (i == 7) {
|
2014-03-22 22:31:55 +00:00
|
|
|
// textView.setText(LocaleController.getString(R.string.SaveIncomingPhotos));
|
2013-10-25 15:19:00 +00:00
|
|
|
// divider.setVisibility(View.INVISIBLE);
|
|
|
|
//
|
|
|
|
// ImageView checkButton = (ImageView)view.findViewById(R.id.settings_row_check_button);
|
|
|
|
// if (UserConfig.saveIncomingPhotos) {
|
|
|
|
// checkButton.setImageResource(R.drawable.btn_check_on);
|
|
|
|
// } else {
|
|
|
|
// checkButton.setImageResource(R.drawable.btn_check_off);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
} else if (type == 4) {
|
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
view = li.inflate(R.layout.settings_logout_button, viewGroup, false);
|
|
|
|
TextView textView = (TextView)view.findViewById(R.id.settings_row_text);
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("LogOut", R.string.LogOut));
|
2013-10-25 15:19:00 +00:00
|
|
|
textView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
2014-03-22 22:31:55 +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() {
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
2014-03-22 22:31:55 +00:00
|
|
|
NotificationCenter.getInstance().postNotificationName(1234);
|
|
|
|
MessagesController.getInstance().unregistedPush();
|
2013-10-25 15:19:00 +00:00
|
|
|
listView.setAdapter(null);
|
|
|
|
UserConfig.clearConfig();
|
|
|
|
}
|
|
|
|
});
|
2014-03-22 22:31:55 +00:00
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2013-10-25 15:19:00 +00:00
|
|
|
builder.show().setCanceledOnTouchOutside(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (type == 5) {
|
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
view = li.inflate(R.layout.user_profile_leftright_row_layout, viewGroup, false);
|
|
|
|
}
|
|
|
|
TextView textView = (TextView)view.findViewById(R.id.settings_row_text);
|
|
|
|
TextView detailTextView = (TextView)view.findViewById(R.id.settings_row_text_detail);
|
|
|
|
View divider = view.findViewById(R.id.settings_row_divider);
|
|
|
|
if (i == textSizeRow) {
|
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
|
|
|
int size = preferences.getInt("fons_size", 16);
|
|
|
|
detailTextView.setText(String.format("%d", size));
|
2014-03-22 22:31:55 +00:00
|
|
|
textView.setText(LocaleController.getString("TextSize", R.string.TextSize));
|
2013-10-25 15:19:00 +00:00
|
|
|
divider.setVisibility(View.VISIBLE);
|
2014-03-25 00:25:32 +00:00
|
|
|
} else if (i == languageRow) {
|
|
|
|
detailTextView.setText(LocaleController.getCurrentLanguageName());
|
|
|
|
textView.setText(LocaleController.getString("Language", R.string.Language));
|
|
|
|
divider.setVisibility(View.VISIBLE);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int i) {
|
|
|
|
if (i == profileRow) {
|
|
|
|
return 0;
|
2014-03-22 22:31:55 +00:00
|
|
|
} else if (i == numberSectionRow || i == settingsSectionRow || i == supportSectionRow || i == messagesSectionRow || i == photoDownloadSection || i == audioDownloadSection) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return 1;
|
2014-03-25 00:25:32 +00:00
|
|
|
} else if (i == textSizeRow || i == languageRow) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return 5;
|
2014-03-22 22:31:55 +00:00
|
|
|
} else if (i == enableAnimationsRow || i == sendByEnterRow || i == photoDownloadChatRow || i == photoDownloadPrivateRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return 3;
|
2014-02-28 22:28:25 +00:00
|
|
|
} else if (i == numberRow || i == notificationRow || i == blockedRow || i == backgroundRow || i == askQuestionRow || i == sendLogsRow || i == terminateSessionsRow || i == clearLogsRow) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return 2;
|
|
|
|
} else if (i == logoutRow) {
|
|
|
|
return 4;
|
|
|
|
} else {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEmpty() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|