Commit 1eeb12f6 authored by DrKLO's avatar DrKLO

Icon for group chats in messages list

(DEBUG) Option in settings to switch to test datacenters
Update some images
parent d4854101
......@@ -82,7 +82,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 211
versionName "1.4.8"
versionCode 212
versionName "1.4.9"
}
}
......@@ -53,8 +53,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
public int currentDatacenterId;
public int movingToDatacenterId;
private long lastOutgoingMessageId = 0;
private int useDifferentBackend = 0;
private final int SESSION_VERSION = 2;
private int isTestBackend = 0;
public int timeDifference = 0;
public int currentPingTime;
private int lastDestroySessionRequestTime;
......@@ -228,7 +227,30 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
}
void loadSession() {
public void switchBackend() {
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
if (isTestBackend == 0) {
isTestBackend = 1;
} else {
isTestBackend = 0;
}
datacenters.clear();
fillDatacenters();
saveSession();
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
UserConfig.clearConfig();
System.exit(0);
}
});
}
});
}
private void loadSession() {
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
......@@ -236,10 +258,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (configFile.exists()) {
try {
SerializedData data = new SerializedData(configFile);
int datacenterSetId = data.readInt32();
isTestBackend = data.readInt32();
int version = data.readInt32();
if (datacenterSetId == useDifferentBackend && version == SESSION_VERSION) {
sessionsToDestroy.clear();
int count = data.readInt32();
for (int a = 0; a < count; a++) {
......@@ -252,16 +272,12 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
datacenters.put(datacenter.datacenterId, datacenter);
}
currentDatacenterId = data.readInt32();
} else {
UserConfig.clearConfig();
}
} catch (Exception e) {
UserConfig.clearConfig();
}
} else {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("dataconfig", Context.MODE_PRIVATE);
int datacenterSetId = preferences.getInt("datacenterSetId", 0);
if (datacenterSetId == useDifferentBackend) {
isTestBackend = preferences.getInt("datacenterSetId", 0);
currentDatacenterId = preferences.getInt("currentDatacenterId", 0);
timeDifference = preferences.getInt("timeDifference", 0);
lastDcUpdateTime = preferences.getInt("lastDcUpdateTime", 0);
......@@ -299,7 +315,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
FileLog.e("tmessages", e);
}
}
}
if (currentDatacenterId != 0 && UserConfig.clientActivated) {
Datacenter datacenter = datacenterWithId(currentDatacenterId);
......@@ -310,8 +325,24 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
}
fillDatacenters();
for (Datacenter datacenter : datacenters.values()) {
datacenter.authSessionId = getNewSessionId();
}
if (datacenters.size() != 0 && currentDatacenterId == 0) {
currentDatacenterId = 1;
saveSession();
}
movingToDatacenterId = DEFAULT_DATACENTER_ID;
}
});
}
private void fillDatacenters() {
if (datacenters.size() == 0) {
if (useDifferentBackend == 0) {
if (isTestBackend == 0) {
Datacenter datacenter = new Datacenter();
datacenter.datacenterId = 1;
datacenter.addAddressAndPort("173.240.5.1", 443);
......@@ -373,28 +404,16 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
datacenter.addAddressAndPort("116.51.22.2", 443);
datacenters.put(datacenter.datacenterId, datacenter);
}
for (Datacenter datacenter : datacenters.values()) {
datacenter.authSessionId = getNewSessionId();
}
if (datacenters.size() != 0 && currentDatacenterId == 0) {
currentDatacenterId = 1;
saveSession();
}
movingToDatacenterId = DEFAULT_DATACENTER_ID;
}
});
}
void saveSession() {
private void saveSession() {
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("dataconfig", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("datacenterSetId", useDifferentBackend);
editor.putInt("datacenterSetId", isTestBackend);
Datacenter currentDatacenter = datacenterWithId(currentDatacenterId);
if (currentDatacenter != null) {
editor.putInt("currentDatacenterId", currentDatacenterId);
......
......@@ -22,7 +22,6 @@ import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.ContactsController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
......@@ -296,28 +295,17 @@ public class ChatOrUserCell extends BaseCell {
if (chat != null) {
nameString2 = chat.title;
} else if (user != null) {
if (user.id / 1000 != 333 && ContactsController.getInstance().contactsDict.get(user.id) == null) {
if (ContactsController.getInstance().contactsDict.size() == 0 && ContactsController.getInstance().loadingContacts) {
nameString2 = Utilities.formatName(user.first_name, user.last_name);
} else {
if (user.phone != null && user.phone.length() != 0) {
nameString2 = PhoneFormat.getInstance().format("+" + user.phone);
} else {
nameString2 = Utilities.formatName(user.first_name, user.last_name);
}
}
} else {
nameString2 = Utilities.formatName(user.first_name, user.last_name);
}
}
nameString = nameString2.replace("\n", " ");
}
if (nameString.length() == 0) {
if (user.phone != null && user.phone.length() != 0) {
nameString = PhoneFormat.getInstance().format("+" + user.phone);
}
} else {
nameString = LocaleController.getString("HiddenName", R.string.HiddenName);
}
}
if (encryptedChat != null) {
currentNamePaint = nameEncryptedPaint;
} else {
......
......@@ -47,6 +47,7 @@ public class DialogCell extends BaseCell {
private static Drawable errorDrawable;
private static Drawable lockDrawable;
private static Drawable countDrawable;
private static Drawable groupDrawable;
private TLRPC.TL_dialog currentDialog;
private ImageReceiver avatarImage;
......@@ -127,6 +128,10 @@ public class DialogCell extends BaseCell {
countDrawable = getResources().getDrawable(R.drawable.dialogs_badge);
}
if (groupDrawable == null) {
groupDrawable = getResources().getDrawable(R.drawable.grouplist);
}
if (avatarImage == null) {
avatarImage = new ImageReceiver();
avatarImage.parentView = new WeakReference<View>(this);
......@@ -260,6 +265,9 @@ public class DialogCell extends BaseCell {
if (cellLayout.drawNameLock) {
setDrawableBounds(lockDrawable, cellLayout.nameLockLeft, cellLayout.nameLockTop);
lockDrawable.draw(canvas);
} else if (cellLayout.drawNameGroup) {
setDrawableBounds(groupDrawable, cellLayout.nameLockLeft, cellLayout.nameLockTop);
groupDrawable.draw(canvas);
}
canvas.save();
......@@ -313,8 +321,9 @@ public class DialogCell extends BaseCell {
private int nameWidth;
private StaticLayout nameLayout;
private boolean drawNameLock;
private boolean drawNameGroup;
private int nameLockLeft;
private int nameLockTop = Utilities.dp(13);
private int nameLockTop;
private int timeLeft;
private int timeTop = Utilities.dp(13);
......@@ -359,6 +368,8 @@ public class DialogCell extends BaseCell {
if (encryptedChat != null) {
drawNameLock = true;
drawNameGroup = false;
nameLockTop = Utilities.dp(13);
if (!LocaleController.isRTL) {
nameLockLeft = Utilities.dp(77);
nameLeft = Utilities.dp(81) + lockDrawable.getIntrinsicWidth();
......@@ -368,12 +379,25 @@ public class DialogCell extends BaseCell {
}
} else {
drawNameLock = false;
if (chat != null) {
drawNameGroup = true;
nameLockTop = Utilities.dp(14);
if (!LocaleController.isRTL) {
nameLockLeft = Utilities.dp(77);
nameLeft = Utilities.dp(81) + groupDrawable.getIntrinsicWidth();
} else {
nameLockLeft = width - Utilities.dp(77) - groupDrawable.getIntrinsicWidth();
nameLeft = Utilities.dp(14);
}
} else {
drawNameGroup = false;
if (!LocaleController.isRTL) {
nameLeft = Utilities.dp(77);
} else {
nameLeft = Utilities.dp(14);
}
}
}
if (message == null) {
if (printingString != null) {
......@@ -547,6 +571,8 @@ public class DialogCell extends BaseCell {
}
if (drawNameLock) {
nameWidth -= Utilities.dp(4) + lockDrawable.getIntrinsicWidth();
} else if (drawNameGroup) {
nameWidth -= Utilities.dp(4) + groupDrawable.getIntrinsicWidth();
}
if (drawClock) {
int w = clockDrawable.getIntrinsicWidth() + Utilities.dp(2);
......
......@@ -263,11 +263,8 @@ public class LanguageSelectActivity extends BaseFragment {
searching = false;
searchWas = false;
if (listView != null) {
listView.setEmptyView(emptyTextView);
emptyTextView.setVisibility(View.GONE);
}
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
listView.setAdapter(listAdapter);
}
((LaunchActivity)parentActivity).fixBackButton();
return true;
......
......@@ -77,6 +77,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
private int logoutRow;
private int sendLogsRow;
private int clearLogsRow;
private int switchBackendButtonRow;
private int rowCount;
private int messagesSectionRow;
private int sendByEnterRow;
......@@ -175,6 +176,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
if (BuildVars.DEBUG_VERSION) {
sendLogsRow = rowCount++;
clearLogsRow = rowCount++;
switchBackendButtonRow = rowCount++;
}
askQuestionRow = rowCount++;
logoutRow = rowCount++;
......@@ -408,6 +410,18 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
} else if (i == languageRow) {
((LaunchActivity)parentActivity).presentFragment(new LanguageSelectActivity(), "settings_wallpapers", false);
} else if (i == switchBackendButtonRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
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);
builder.show().setCanceledOnTouchOutside(true);
}
// else if (i == 6) {
// UserConfig.saveIncomingPhotos = !UserConfig.saveIncomingPhotos;
......@@ -542,7 +556,8 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
public boolean isEnabled(int i) {
return i == textSizeRow || i == enableAnimationsRow || i == blockedRow || i == notificationRow || i == backgroundRow ||
i == askQuestionRow || i == sendLogsRow || i == sendByEnterRow || i == terminateSessionsRow || i == photoDownloadPrivateRow ||
i == photoDownloadChatRow || i == clearLogsRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow || i == languageRow;
i == photoDownloadChatRow || i == clearLogsRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow || i == languageRow ||
i == switchBackendButtonRow;
}
@Override
......@@ -748,6 +763,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
} else if (i == terminateSessionsRow) {
textView.setText(LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions));
divider.setVisibility(View.INVISIBLE);
} else if (i == switchBackendButtonRow) {
textView.setText("Switch Backend");
divider.setVisibility(View.VISIBLE);
}
} else if (type == 3) {
if (view == null) {
......@@ -883,7 +901,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
return 5;
} else if (i == enableAnimationsRow || i == sendByEnterRow || i == photoDownloadChatRow || i == photoDownloadPrivateRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow) {
return 3;
} else if (i == numberRow || i == notificationRow || i == blockedRow || i == backgroundRow || i == askQuestionRow || i == sendLogsRow || i == terminateSessionsRow || i == clearLogsRow) {
} else if (i == numberRow || i == notificationRow || i == blockedRow || i == backgroundRow || i == askQuestionRow || i == sendLogsRow || i == terminateSessionsRow || i == clearLogsRow || i == switchBackendButtonRow) {
return 2;
} else if (i == logoutRow) {
return 4;
......
......@@ -37,15 +37,15 @@
android:id="@+id/chat_photo_image"/>
<org.telegram.ui.Views.FrameLayoutFixed
android:layout_height="40dp"
android:layout_width="40dp"
android:layout_height="44dp"
android:layout_width="44dp"
android:id="@+id/chat_view_action_layout"
android:layout_gravity="center"
android:visibility="visible">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_width="44dp"
android:layout_height="44dp"
android:scaleType="centerInside"
android:id="@+id/chat_view_action_cancel_button"
android:src="@drawable/photo_download_states"
......
......@@ -27,15 +27,15 @@
android:id="@+id/chat_photo_image"/>
<org.telegram.ui.Views.FrameLayoutFixed
android:layout_height="40dp"
android:layout_width="40dp"
android:layout_height="44dp"
android:layout_width="44dp"
android:id="@+id/chat_view_action_layout"
android:layout_gravity="center"
android:visibility="visible">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_width="44dp"
android:layout_height="44dp"
android:scaleType="centerInside"
android:id="@+id/chat_view_action_cancel_button"
android:src="@drawable/photo_download_states"
......
......@@ -151,7 +151,7 @@
android:layout_marginTop="2dp"
android:maxLines="4"
android:minHeight="48dp"
android:textSize="18dp"
android:textSize="18sp"
android:textColorHint="#909090"
android:ems="10"
android:imeOptions="flagNoExtractUi"
......
......@@ -27,15 +27,15 @@
android:id="@+id/chat_photo_image"/>
<org.telegram.ui.Views.FrameLayoutFixed
android:layout_height="40dp"
android:layout_width="40dp"
android:layout_height="44dp"
android:layout_width="44dp"
android:id="@+id/chat_view_action_layout"
android:layout_gravity="center"
android:visibility="visible">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_width="44dp"
android:layout_height="44dp"
android:scaleType="centerInside"
android:id="@+id/chat_view_action_cancel_button"
android:src="@drawable/photo_download_cancel_states"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment