Commit 92e1b050 authored by DrKLO's avatar DrKLO

Improved back swipe, new photo viewer(not finished, disabed) bug fixes

parent cdb39ac3
...@@ -82,7 +82,7 @@ android { ...@@ -82,7 +82,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 8 minSdkVersion 8
targetSdkVersion 19 targetSdkVersion 19
versionCode 238 versionCode 240
versionName "1.4.15" versionName "1.4.15"
} }
} }
...@@ -1603,7 +1603,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ...@@ -1603,7 +1603,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
} }
} }
@SuppressWarnings("unused")
ByteBufferDesc createConnectionData(ArrayList<NetworkMessage> messages, ArrayList<Integer> quickAckId, TcpConnection connection) { ByteBufferDesc createConnectionData(ArrayList<NetworkMessage> messages, ArrayList<Integer> quickAckId, TcpConnection connection) {
Datacenter datacenter = datacenterWithId(connection.getDatacenterId()); Datacenter datacenter = datacenterWithId(connection.getDatacenterId());
if (datacenter.authKey == null) { if (datacenter.authKey == null) {
......
...@@ -433,7 +433,12 @@ public class ContactsController { ...@@ -433,7 +433,12 @@ public class ContactsController {
FileLog.e("tmessages", "detected account deletion!"); FileLog.e("tmessages", "detected account deletion!");
currentAccount = new Account(UserConfig.currentUser.phone, "org.telegram.account"); currentAccount = new Account(UserConfig.currentUser.phone, "org.telegram.account");
am.addAccountExplicitly(currentAccount, "", null); am.addAccountExplicitly(currentAccount, "", null);
performWriteContactsToPhoneBookInternal(); Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
performWriteContactsToPhoneBook();
}
});
} }
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -1149,7 +1154,7 @@ public class ContactsController { ...@@ -1149,7 +1154,7 @@ public class ContactsController {
sortedUsersSectionsArray = sortedSectionsArray; sortedUsersSectionsArray = sortedSectionsArray;
} }
private void performWriteContactsToPhoneBookInternal() { private void performWriteContactsToPhoneBookInternal(ArrayList<TLRPC.TL_contact> contactsArray) {
try { try {
Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, currentAccount.name).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, currentAccount.type).build(); Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, currentAccount.name).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, currentAccount.type).build();
Cursor c1 = ApplicationLoader.applicationContext.getContentResolver().query(rawContactUri, new String[]{BaseColumns._ID, ContactsContract.RawContacts.SYNC2}, null, null, null); Cursor c1 = ApplicationLoader.applicationContext.getContentResolver().query(rawContactUri, new String[]{BaseColumns._ID, ContactsContract.RawContacts.SYNC2}, null, null, null);
...@@ -1160,7 +1165,7 @@ public class ContactsController { ...@@ -1160,7 +1165,7 @@ public class ContactsController {
} }
c1.close(); c1.close();
for (TLRPC.TL_contact u : contacts) { for (TLRPC.TL_contact u : contactsArray) {
if (!bookContacts.containsKey(u.user_id)) { if (!bookContacts.containsKey(u.user_id)) {
TLRPC.User user = MessagesController.getInstance().users.get(u.user_id); TLRPC.User user = MessagesController.getInstance().users.get(u.user_id);
addContactToPhoneBook(user, false); addContactToPhoneBook(user, false);
...@@ -1173,10 +1178,12 @@ public class ContactsController { ...@@ -1173,10 +1178,12 @@ public class ContactsController {
} }
private void performWriteContactsToPhoneBook() { private void performWriteContactsToPhoneBook() {
final ArrayList<TLRPC.TL_contact> contactsArray = new ArrayList<TLRPC.TL_contact>();
contactsArray.addAll(contacts);
Utilities.globalQueue.postRunnable(new Runnable() { Utilities.globalQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
performWriteContactsToPhoneBookInternal(); performWriteContactsToPhoneBookInternal(contactsArray);
} }
}); });
} }
......
...@@ -11,9 +11,10 @@ package org.telegram.messenger; ...@@ -11,9 +11,10 @@ package org.telegram.messenger;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.util.Log;
public class DispatchQueue extends Thread { public class DispatchQueue extends Thread {
public Handler handler; public volatile Handler handler = null;
private final Object handlerSyncObject = new Object(); private final Object handlerSyncObject = new Object();
public DispatchQueue(final String threadName) { public DispatchQueue(final String threadName) {
...@@ -47,12 +48,14 @@ public class DispatchQueue extends Thread { ...@@ -47,12 +48,14 @@ public class DispatchQueue extends Thread {
public void postRunnable(Runnable runnable, int delay) { public void postRunnable(Runnable runnable, int delay) {
if (handler == null) { if (handler == null) {
try { synchronized (handlerSyncObject) {
synchronized (handlerSyncObject) { if (handler == null) {
handlerSyncObject.wait(); try {
handlerSyncObject.wait();
} catch (Throwable t) {
t.printStackTrace();
}
} }
} catch (Throwable t) {
t.printStackTrace();
} }
} }
...@@ -67,8 +70,8 @@ public class DispatchQueue extends Thread { ...@@ -67,8 +70,8 @@ public class DispatchQueue extends Thread {
public void run() { public void run() {
Looper.prepare(); Looper.prepare();
handler = new Handler();
synchronized (handlerSyncObject) { synchronized (handlerSyncObject) {
handler = new Handler();
handlerSyncObject.notify(); handlerSyncObject.notify();
} }
Looper.loop(); Looper.loop();
......
...@@ -3403,7 +3403,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -3403,7 +3403,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
ConnectionsManager.getInstance().connectionState = 0; ConnectionsManager.getInstance().connectionState = 0;
processUpdatesQueue(true); processUpdatesQueue(true);
} else if (res instanceof TLRPC.TL_updates_differenceSlice) { } else if (res instanceof TLRPC.TL_updates_differenceSlice) {
//MessagesStorage.lastSeqValue = res.intermediate_state.seq;
MessagesStorage.lastDateValue = res.intermediate_state.date; MessagesStorage.lastDateValue = res.intermediate_state.date;
MessagesStorage.lastPtsValue = res.intermediate_state.pts; MessagesStorage.lastPtsValue = res.intermediate_state.pts;
MessagesStorage.lastQtsValue = res.intermediate_state.qts; MessagesStorage.lastQtsValue = res.intermediate_state.qts;
...@@ -3424,8 +3423,14 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -3424,8 +3423,14 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}); });
} else { } else {
gettingDifference = false; gettingDifference = false;
getDifference(); ConnectionsManager.getInstance().connectionState = 0;
FileLog.e("tmessages", "get difference error, don't know what to do :("); final int stateCopy = ConnectionsManager.getInstance().connectionState;
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(703, stateCopy);
}
});
} }
} }
}, null, true, RPCRequest.RPCRequestClassGeneric); }, null, true, RPCRequest.RPCRequestClassGeneric);
......
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
package org.telegram.messenger; package org.telegram.messenger;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.Html; import android.text.Html;
import android.util.SparseArray; import android.util.SparseArray;
...@@ -40,8 +38,6 @@ public class MessagesStorage { ...@@ -40,8 +38,6 @@ public class MessagesStorage {
public static final int wallpapersDidLoaded = 171; public static final int wallpapersDidLoaded = 171;
private boolean appliedDialogFix = false;
private static volatile MessagesStorage Instance = null; private static volatile MessagesStorage Instance = null;
public static MessagesStorage getInstance() { public static MessagesStorage getInstance() {
MessagesStorage localInstance = Instance; MessagesStorage localInstance = Instance;
...@@ -66,22 +62,10 @@ public class MessagesStorage { ...@@ -66,22 +62,10 @@ public class MessagesStorage {
cacheFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache4.db"); cacheFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache4.db");
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("dbconfig", Context.MODE_PRIVATE);
appliedDialogFix = preferences.getBoolean("appliedDialogFix", false);
boolean createTable = false; boolean createTable = false;
//cacheFile.delete(); //cacheFile.delete();
if (!cacheFile.exists()) { if (!cacheFile.exists()) {
createTable = true; createTable = true;
try {
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("appliedDialogFix", true);
appliedDialogFix = true;
editor.commit();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} }
try { try {
database = new SQLiteDatabase(cacheFile.getPath()); database = new SQLiteDatabase(cacheFile.getPath());
...@@ -202,66 +186,11 @@ public class MessagesStorage { ...@@ -202,66 +186,11 @@ public class MessagesStorage {
cacheFile.delete(); cacheFile.delete();
cacheFile = null; cacheFile = null;
} }
try {
File old = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache.db");
if (old.exists()) {
old.delete();
}
old = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache2.db");
if (old.exists()) {
old.delete();
}
old = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache3.db");
if (old.exists()) {
old.delete();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
openDatabase(); openDatabase();
} }
}); });
} }
public void applyDialogsFix() { //server bug on 20.02.2014
if (!appliedDialogFix) {
try {
SQLiteCursor cursor = database.queryFinalized("SELECT d.did, m.data FROM dialogs as d LEFT JOIN messages as m ON d.last_mid = m.mid WHERE m.mid < 0 AND m.date >= 1392930900 AND m.date <= 1392935700");
String dids = "";
while (cursor.next()) {
long did = cursor.longValue(0);
byte[] messageData = cursor.byteArrayValue(1);
if (messageData != null) {
SerializedData data = new SerializedData(messageData);
TLRPC.Message message = (TLRPC.Message)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (message != null) {
if (message.action != null && message.action instanceof TLRPC.TL_messageActionUserJoined) {
if (dids.length() != 0) {
dids += ",";
}
dids += "" + did;
}
}
}
}
cursor.dispose();
if (dids.length() != 0) {
database.executeFast("DELETE FROM dialogs WHERE did IN(" + dids + ")").stepThis().dispose();
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("dbconfig", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("appliedDialogFix", true);
appliedDialogFix = true;
editor.commit();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
}
public void saveSecretParams(final int lsv, final int sg, final byte[] pbytes) { public void saveSecretParams(final int lsv, final int sg, final byte[] pbytes) {
storageQueue.postRunnable(new Runnable() { storageQueue.postRunnable(new Runnable() {
@Override @Override
......
...@@ -90,6 +90,10 @@ public class TcpConnection extends ConnectionContext { ...@@ -90,6 +90,10 @@ public class TcpConnection extends ConnectionContext {
connectionState = TcpConnectionState.TcpConnectionStageConnecting; connectionState = TcpConnectionState.TcpConnectionStageConnecting;
try { try {
Datacenter datacenter = ConnectionsManager.getInstance().datacenterWithId(datacenterId);
hostAddress = datacenter.getCurrentAddress();
hostPort = datacenter.getCurrentPort();
if(android.os.Build.VERSION.SDK_INT < 11) { if(android.os.Build.VERSION.SDK_INT < 11) {
if (!ConnectionsManager.isNetworkOnline() && !tryWithNoNetworkAnyway) { if (!ConnectionsManager.isNetworkOnline() && !tryWithNoNetworkAnyway) {
handleConnectionError(null); handleConnectionError(null);
...@@ -108,9 +112,7 @@ public class TcpConnection extends ConnectionContext { ...@@ -108,9 +112,7 @@ public class TcpConnection extends ConnectionContext {
} catch (Exception e2) { } catch (Exception e2) {
FileLog.e("tmessages", e2); FileLog.e("tmessages", e2);
} }
Datacenter datacenter = ConnectionsManager.getInstance().datacenterWithId(datacenterId);
hostAddress = datacenter.getCurrentAddress();
hostPort = datacenter.getCurrentPort();
FileLog.d("tmessages", String.format(TcpConnection.this + " Connecting (%s:%d)", hostAddress, hostPort)); FileLog.d("tmessages", String.format(TcpConnection.this + " Connecting (%s:%d)", hostAddress, hostPort));
firstPacket = true; firstPacket = true;
if (restOfTheData != null) { if (restOfTheData != null) {
...@@ -292,6 +294,7 @@ public class TcpConnection extends ConnectionContext { ...@@ -292,6 +294,7 @@ public class TcpConnection extends ConnectionContext {
} }
if (client == null || client.isDisconnected()) { if (client == null || client.isDisconnected()) {
BuffersStorage.getInstance().reuseFreeBuffer(buff);
return; return;
} }
......
...@@ -39,7 +39,7 @@ import java.util.Locale; ...@@ -39,7 +39,7 @@ import java.util.Locale;
public class ChatMediaCell extends ChatBaseCell implements MediaController.FileDownloadProgressListener { public class ChatMediaCell extends ChatBaseCell implements MediaController.FileDownloadProgressListener {
public static interface ChatMediaCellDelegate { public static interface ChatMediaCellDelegate {
public abstract void didPressedImage(ChatBaseCell cell); public abstract void didPressedImage(ChatMediaCell cell, ImageReceiver imageReceiver);
} }
private static Drawable placeholderInDrawable; private static Drawable placeholderInDrawable;
...@@ -196,7 +196,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -196,7 +196,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
if (currentMessageObject.type == 1) { if (currentMessageObject.type == 1) {
if (buttonState == -1) { if (buttonState == -1) {
if (mediaDelegate != null) { if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this); mediaDelegate.didPressedImage(this, photoImage);
} }
} else if (buttonState == 0) { } else if (buttonState == 0) {
didPressedButton(); didPressedButton();
...@@ -217,7 +217,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -217,7 +217,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
} }
} else if (currentMessageObject.type == 4) { } else if (currentMessageObject.type == 4) {
if (mediaDelegate != null) { if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this); mediaDelegate.didPressedImage(this, photoImage);
} }
} }
} }
...@@ -271,7 +271,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -271,7 +271,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
} }
} else if (buttonState == 3) { } else if (buttonState == 3) {
if (mediaDelegate != null) { if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this); mediaDelegate.didPressedImage(this, photoImage);
} }
} }
} }
...@@ -545,6 +545,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD ...@@ -545,6 +545,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
canvas.restore(); canvas.restore();
} else { } else {
photoImage.draw(canvas, photoImage.imageX, photoImage.imageY, photoWidth, photoHeight); photoImage.draw(canvas, photoImage.imageX, photoImage.imageY, photoWidth, photoHeight);
drawTime = photoImage.getVisible();
} }
if (progressVisible) { if (progressVisible) {
......
...@@ -191,7 +191,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen ...@@ -191,7 +191,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
} }
} }
}); });
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
return true; return true;
} }
...@@ -269,7 +269,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen ...@@ -269,7 +269,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} }
} }
}); });
...@@ -585,7 +585,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen ...@@ -585,7 +585,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
processPhotoMenu(action); processPhotoMenu(action);
} }
}); });
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} }
}); });
} else { } else {
...@@ -709,7 +709,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen ...@@ -709,7 +709,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} }
}); });
} }
......
...@@ -307,7 +307,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter ...@@ -307,7 +307,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} }
} }
} }
...@@ -346,7 +346,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter ...@@ -346,7 +346,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
} }
}); });
builder.setNegativeButton(R.string.Cancel, null); builder.setNegativeButton(R.string.Cancel, null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} else { } else {
if (delegate != null) { if (delegate != null) {
delegate.didSelectContact(user); delegate.didSelectContact(user);
......
...@@ -200,7 +200,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati ...@@ -200,7 +200,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
} }
} }
}); });
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} }
}); });
......
...@@ -93,6 +93,12 @@ public class IdenticonActivity extends BaseFragment { ...@@ -93,6 +93,12 @@ public class IdenticonActivity extends BaseFragment {
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override @Override
public boolean onPreDraw() { public boolean onPreDraw() {
if (fragmentView != null) {
fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
}
if (getParentActivity() == null) {
return true;
}
LinearLayout layout = (LinearLayout)fragmentView; LinearLayout layout = (LinearLayout)fragmentView;
WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE); WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
int rotation = manager.getDefaultDisplay().getRotation(); int rotation = manager.getDefaultDisplay().getRotation();
...@@ -104,8 +110,6 @@ public class IdenticonActivity extends BaseFragment { ...@@ -104,8 +110,6 @@ public class IdenticonActivity extends BaseFragment {
} }
fragmentView.setPadding(fragmentView.getPaddingLeft(), 0, fragmentView.getPaddingRight(), fragmentView.getPaddingBottom()); fragmentView.setPadding(fragmentView.getPaddingLeft(), 0, fragmentView.getPaddingRight(), fragmentView.getPaddingBottom());
fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
return false; return false;
} }
}); });
......
...@@ -166,7 +166,7 @@ public class LanguageSelectActivity extends BaseFragment { ...@@ -166,7 +166,7 @@ public class LanguageSelectActivity extends BaseFragment {
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
return true; return true;
} }
}); });
......
...@@ -168,6 +168,8 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen ...@@ -168,6 +168,8 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
} }
handleIntent(getIntent(), false, savedInstanceState != null); handleIntent(getIntent(), false, savedInstanceState != null);
PhotoViewer.getInstance().setParentActivity(this);
} }
private void handleIntent(Intent intent, boolean isNew, boolean restore) { private void handleIntent(Intent intent, boolean isNew, boolean restore) {
...@@ -744,4 +746,22 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen ...@@ -744,4 +746,22 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
} }
@Override
public void onBackPressed() {
if (PhotoViewer.getInstance().isVisible()) {
PhotoViewer.getInstance().closePhoto();
} else {
super.onBackPressed();
}
}
@Override
public boolean onPreIme() {
if (PhotoViewer.getInstance().isVisible()) {
PhotoViewer.getInstance().closePhoto();
return true;
}
return super.onPreIme();
}
} }
...@@ -215,7 +215,7 @@ public class LoginActivity extends BaseFragment implements SlideView.SlideViewDe ...@@ -215,7 +215,7 @@ public class LoginActivity extends BaseFragment implements SlideView.SlideViewDe
builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(text); builder.setMessage(text);
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} }
}); });
} }
......
...@@ -337,7 +337,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter ...@@ -337,7 +337,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
}); });
} }
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
return true; return true;
} }
}); });
...@@ -487,7 +487,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter ...@@ -487,7 +487,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
} }
}); });
builder.setNegativeButton(R.string.Cancel, null); builder.setNegativeButton(R.string.Cancel, null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} else { } else {
if (delegate != null) { if (delegate != null) {
delegate.didSelectDialog(MessagesActivity.this, dialog_id); delegate.didSelectDialog(MessagesActivity.this, dialog_id);
......
This diff is collapsed.
...@@ -254,7 +254,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -254,7 +254,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} else if (i == enableAnimationsRow) { } else if (i == enableAnimationsRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true); boolean animations = preferences.getBoolean("view_animations", true);
...@@ -286,7 +286,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -286,7 +286,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} else if (i == sendLogsRow) { } else if (i == sendLogsRow) {
sendLogs(); sendLogs();
} else if (i == clearLogsRow) { } else if (i == clearLogsRow) {
...@@ -325,7 +325,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -325,7 +325,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} else if (i == languageRow) { } else if (i == languageRow) {
presentFragment(new LanguageSelectActivity()); presentFragment(new LanguageSelectActivity());
} else if (i == switchBackendButtonRow) { } else if (i == switchBackendButtonRow) {
...@@ -339,7 +339,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -339,7 +339,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} else if (i == telegramFaqRow) { } else if (i == telegramFaqRow) {
try { try {
Intent pickIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl))); Intent pickIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl)));
...@@ -369,7 +369,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -369,7 +369,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} else if (i == photoDownloadChatRow || i == photoDownloadPrivateRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow) { } else if (i == photoDownloadChatRow || i == photoDownloadPrivateRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
...@@ -398,7 +398,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -398,7 +398,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} }
} }
}); });
...@@ -547,7 +547,6 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -547,7 +547,6 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
showActionBar();
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }
...@@ -696,7 +695,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -696,7 +695,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
} }
} }
}); });
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} }
}); });
} }
...@@ -844,12 +843,14 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -844,12 +843,14 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
NotificationCenter.getInstance().postNotificationName(1234); NotificationCenter.getInstance().postNotificationName(1234);
MessagesController.getInstance().unregistedPush(); MessagesController.getInstance().unregistedPush();
listView.setAdapter(null); MessagesStorage.getInstance().cleanUp();
MessagesController.getInstance().cleanUp();
ConnectionsManager.getInstance().cleanUp();
UserConfig.clearConfig(); UserConfig.clearConfig();
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} }
}); });
} }
......
...@@ -151,7 +151,7 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe ...@@ -151,7 +151,7 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
} }
} }
}); });
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
return true; return true;
} }
......
...@@ -279,7 +279,7 @@ public class SettingsNotificationsActivity extends BaseFragment { ...@@ -279,7 +279,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} }
} }
} }
......
...@@ -96,62 +96,15 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica ...@@ -96,62 +96,15 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
@Override @Override
public View createView(LayoutInflater inflater, ViewGroup container) { public View createView(LayoutInflater inflater, ViewGroup container) {
if (fragmentView == null) { if (fragmentView == null) {
fragmentView = inflater.inflate(R.layout.settings_wallpapers_layout, container, false); actionBarLayer.setCustomView(R.layout.settings_do_action_layout);
listAdapter = new ListAdapter(getParentActivity()); Button cancelButton = (Button)actionBarLayer.findViewById(R.id.cancel_button);
progressBar = (ProgressBar)fragmentView.findViewById(R.id.action_progress);
backgroundImage = (ImageView)fragmentView.findViewById(R.id.background_image);
listView = (HorizontalListView)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 == 0) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items = new CharSequence[] {LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("Cancel", R.string.Cancel)};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File image = Utilities.generatePicturePath();
if (image != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
currentPicturePath = image.getAbsolutePath();
}
getParentActivity().startActivityForResult(takePictureIntent, 10);
} else if (i == 1) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
getParentActivity().startActivityForResult(photoPickerIntent, 11);
}
}
});
builder.show().setCanceledOnTouchOutside(true);
} else {
TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
selectedBackground = wallPaper.id;
listAdapter.notifyDataSetChanged();
processSelectedBackground();
}
}
});
TextView textView = (TextView)fragmentView.findViewById(R.id.done_button_text);
textView.setText(LocaleController.getString("Set", R.string.Set));
Button cancelButton = (Button)fragmentView.findViewById(R.id.cancel_button);
cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel));
cancelButton.setOnClickListener(new View.OnClickListener() { cancelButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
finishFragment(); finishFragment();
} }
}); });
doneButton = actionBarLayer.findViewById(R.id.done_button);
doneButton = fragmentView.findViewById(R.id.done_button);
doneButton.setOnClickListener(new View.OnClickListener() { doneButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
...@@ -190,6 +143,53 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica ...@@ -190,6 +143,53 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
} }
}); });
cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel));
TextView textView = (TextView)doneButton.findViewById(R.id.done_button_text);
textView.setText(LocaleController.getString("Set", R.string.Set));
fragmentView = inflater.inflate(R.layout.settings_wallpapers_layout, container, false);
listAdapter = new ListAdapter(getParentActivity());
progressBar = (ProgressBar)fragmentView.findViewById(R.id.action_progress);
backgroundImage = (ImageView)fragmentView.findViewById(R.id.background_image);
listView = (HorizontalListView)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 == 0) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items = new CharSequence[] {LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("Cancel", R.string.Cancel)};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File image = Utilities.generatePicturePath();
if (image != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
currentPicturePath = image.getAbsolutePath();
}
getParentActivity().startActivityForResult(takePictureIntent, 10);
} else if (i == 1) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
getParentActivity().startActivityForResult(photoPickerIntent, 11);
}
}
});
showAlertDialog(builder);
} else {
TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
selectedBackground = wallPaper.id;
listAdapter.notifyDataSetChanged();
processSelectedBackground();
}
}
});
processSelectedBackground(); processSelectedBackground();
} else { } else {
ViewGroup parent = (ViewGroup)fragmentView.getParent(); ViewGroup parent = (ViewGroup)fragmentView.getParent();
...@@ -428,7 +428,6 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica ...@@ -428,7 +428,6 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }
hideActionBar();
processSelectedBackground(); processSelectedBackground();
fixLayout(); fixLayout();
} }
......
...@@ -194,7 +194,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen ...@@ -194,7 +194,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} }
} }
}); });
...@@ -222,7 +222,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen ...@@ -222,7 +222,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} }
}); });
if (dialog_id == 0) { if (dialog_id == 0) {
...@@ -268,7 +268,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen ...@@ -268,7 +268,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} else if (i == settingsSoundRow) { } else if (i == settingsSoundRow) {
try { try {
Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
...@@ -351,7 +351,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen ...@@ -351,7 +351,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
} }
}); });
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} }
} }
}); });
...@@ -633,7 +633,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen ...@@ -633,7 +633,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
} }
} }
}); });
builder.show().setCanceledOnTouchOutside(true); showAlertDialog(builder);
} }
}); });
} }
......
...@@ -32,6 +32,7 @@ public class ActionBar extends FrameLayout { ...@@ -32,6 +32,7 @@ public class ActionBar extends FrameLayout {
private View currentBackOverlay; private View currentBackOverlay;
private View shadowView = null; private View shadowView = null;
private int currentBackOverlayWidth; private int currentBackOverlayWidth;
protected int itemsBackgroundResourceId;
public ActionBar(Context context) { public ActionBar(Context context) {
super(context); super(context);
...@@ -139,7 +140,6 @@ public class ActionBar extends FrameLayout { ...@@ -139,7 +140,6 @@ public class ActionBar extends FrameLayout {
layoutParams.width = LayoutParams.MATCH_PARENT; layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = LayoutParams.MATCH_PARENT; layoutParams.height = LayoutParams.MATCH_PARENT;
layer.setLayoutParams(layoutParams); layer.setLayoutParams(layoutParams);
currentLayer.setBackgroundDrawable(getBackground());
shadowView.setX(-Utilities.dp(2)); shadowView.setX(-Utilities.dp(2));
shadowView.setVisibility(VISIBLE); shadowView.setVisibility(VISIBLE);
} }
...@@ -148,7 +148,6 @@ public class ActionBar extends FrameLayout { ...@@ -148,7 +148,6 @@ public class ActionBar extends FrameLayout {
if (currentLayer == null) { if (currentLayer == null) {
return; return;
} }
currentLayer.setBackgroundDrawable(null);
currentLayer.setX(0); currentLayer.setX(0);
if (!backAnimation) { if (!backAnimation) {
removeView(currentLayer); removeView(currentLayer);
...@@ -206,4 +205,8 @@ public class ActionBar extends FrameLayout { ...@@ -206,4 +205,8 @@ public class ActionBar extends FrameLayout {
currentLayer.onMenuButtonPressed(); currentLayer.onMenuButtonPressed();
} }
} }
public void setItemsBackground(int resourceId) {
itemsBackgroundResourceId = resourceId;
}
} }
...@@ -37,7 +37,7 @@ public class ActionBarLayer extends FrameLayout { ...@@ -37,7 +37,7 @@ public class ActionBarLayer extends FrameLayout {
private TextView subTitleTextView; private TextView subTitleTextView;
private ActionBarMenu menu; private ActionBarMenu menu;
private ActionBarMenu actionMode; private ActionBarMenu actionMode;
private ActionBar parentActionBar; protected ActionBar parentActionBar;
private boolean oldUseLogo; private boolean oldUseLogo;
private boolean oldUseBack; private boolean oldUseBack;
private boolean isBackLayoutHidden = false; private boolean isBackLayoutHidden = false;
...@@ -53,8 +53,8 @@ public class ActionBarLayer extends FrameLayout { ...@@ -53,8 +53,8 @@ public class ActionBarLayer extends FrameLayout {
layoutParams.width = LayoutParams.WRAP_CONTENT; layoutParams.width = LayoutParams.WRAP_CONTENT;
layoutParams.height = LayoutParams.FILL_PARENT; layoutParams.height = LayoutParams.FILL_PARENT;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT; layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
backButtonFrameLayout.setBackgroundResource(R.drawable.bar_selector);
backButtonFrameLayout.setLayoutParams(layoutParams); backButtonFrameLayout.setLayoutParams(layoutParams);
backButtonFrameLayout.setBackgroundResource(actionBar.itemsBackgroundResourceId);
backButtonFrameLayout.setPadding(0, 0, Utilities.dp(4), 0); backButtonFrameLayout.setPadding(0, 0, Utilities.dp(4), 0);
backButtonFrameLayout.setOnClickListener(new OnClickListener() { backButtonFrameLayout.setOnClickListener(new OnClickListener() {
@Override @Override
...@@ -432,6 +432,16 @@ public class ActionBarLayer extends FrameLayout { ...@@ -432,6 +432,16 @@ public class ActionBarLayer extends FrameLayout {
super.onMeasure(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec);
} }
@Override
public void setAlpha(float alpha) {
if (menu != null) {
menu.setAlpha(alpha);
}
if (backButtonFrameLayout != null) {
backButtonFrameLayout.setAlpha(alpha);
}
}
public void onMenuButtonPressed() { public void onMenuButtonPressed() {
if (menu != null) { if (menu != null) {
menu.onMenuButtonPressed(); menu.onMenuButtonPressed();
......
...@@ -16,7 +16,6 @@ import android.widget.FrameLayout; ...@@ -16,7 +16,6 @@ import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
public class ActionBarMenu extends LinearLayout { public class ActionBarMenu extends LinearLayout {
...@@ -50,7 +49,7 @@ public class ActionBarMenu extends LinearLayout { ...@@ -50,7 +49,7 @@ public class ActionBarMenu extends LinearLayout {
addView(view); addView(view);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)view.getLayoutParams(); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)view.getLayoutParams();
layoutParams.height = FrameLayout.LayoutParams.FILL_PARENT; layoutParams.height = FrameLayout.LayoutParams.FILL_PARENT;
view.setBackgroundResource(R.drawable.bar_selector); view.setBackgroundResource(parentActionBar.itemsBackgroundResourceId);
view.setLayoutParams(layoutParams); view.setLayoutParams(layoutParams);
view.setOnClickListener(new OnClickListener() { view.setOnClickListener(new OnClickListener() {
@Override @Override
......
...@@ -48,7 +48,7 @@ public class ActionBarMenuItem extends ImageView { ...@@ -48,7 +48,7 @@ public class ActionBarMenuItem extends ImageView {
public ActionBarMenuItem(Context context, ActionBarMenu menu, ActionBar actionBar) { public ActionBarMenuItem(Context context, ActionBarMenu menu, ActionBar actionBar) {
super(context); super(context);
setBackgroundResource(R.drawable.bar_selector); setBackgroundResource(actionBar.itemsBackgroundResourceId);
parentMenu = menu; parentMenu = menu;
parentActionBar = actionBar; parentActionBar = actionBar;
} }
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
package org.telegram.ui.Views.ActionBar; package org.telegram.ui.Views.ActionBar;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -15,6 +17,8 @@ import android.view.View; ...@@ -15,6 +17,8 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import org.telegram.messenger.ConnectionsManager; import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
public class BaseFragment { public class BaseFragment {
private boolean isFinished = false; private boolean isFinished = false;
...@@ -23,6 +27,7 @@ public class BaseFragment { ...@@ -23,6 +27,7 @@ public class BaseFragment {
protected ActionBarLayer actionBarLayer; protected ActionBarLayer actionBarLayer;
protected int classGuid = 0; protected int classGuid = 0;
protected Bundle arguments; protected Bundle arguments;
private AlertDialog visibleDialog = null;
public BaseFragment() { public BaseFragment() {
classGuid = ConnectionsManager.getInstance().generateClassGuid(); classGuid = ConnectionsManager.getInstance().generateClassGuid();
...@@ -54,9 +59,9 @@ public class BaseFragment { ...@@ -54,9 +59,9 @@ public class BaseFragment {
if (parentActivity != null) { if (parentActivity != null) {
if (actionBarLayer != null) { if (actionBarLayer != null) {
actionBarLayer.onDestroy(); actionBarLayer.onDestroy();
actionBarLayer = null;
} }
actionBarLayer = parentActivity.getInternalActionBar().createLayer(); actionBarLayer = parentActivity.getInternalActionBar().createLayer();
actionBarLayer.setBackgroundResource(R.color.header);
} }
} }
} }
...@@ -96,6 +101,14 @@ public class BaseFragment { ...@@ -96,6 +101,14 @@ public class BaseFragment {
actionBarLayer.onPause(); actionBarLayer.onPause();
actionBarLayer.closeSearchField(); actionBarLayer.closeSearchField();
} }
try {
if (visibleDialog != null && visibleDialog.isShowing()) {
visibleDialog.dismiss();
visibleDialog = null;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} }
public void onConfigurationChanged(android.content.res.Configuration newConfig) { public void onConfigurationChanged(android.content.res.Configuration newConfig) {
...@@ -156,7 +169,17 @@ public class BaseFragment { ...@@ -156,7 +169,17 @@ public class BaseFragment {
} }
public void onBeginSlide() { public void onBeginSlide() {
try {
if (visibleDialog != null && visibleDialog.isShowing()) {
visibleDialog.dismiss();
visibleDialog = null;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (actionBarLayer != null) {
actionBarLayer.onPause();
}
} }
public void onOpenAnimationEnd() { public void onOpenAnimationEnd() {
...@@ -166,4 +189,22 @@ public class BaseFragment { ...@@ -166,4 +189,22 @@ public class BaseFragment {
public void onLowMemory() { public void onLowMemory() {
} }
protected void showAlertDialog(AlertDialog.Builder builder) {
if (parentActivity == null || parentActivity.checkTransitionAnimation() || parentActivity.animationInProgress || parentActivity.startedTracking) {
return;
}
if (visibleDialog != null && visibleDialog.isShowing()) {
visibleDialog.dismiss();
visibleDialog = null;
}
visibleDialog = builder.show();
visibleDialog.setCanceledOnTouchOutside(true);
visibleDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
visibleDialog = null;
}
});
}
} }
...@@ -10,6 +10,7 @@ package org.telegram.ui.Views; ...@@ -10,6 +10,7 @@ package org.telegram.ui.Views;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.database.DataSetObserver; import android.database.DataSetObserver;
import android.graphics.Rect; import android.graphics.Rect;
...@@ -139,6 +140,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> { ...@@ -139,6 +140,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
@SuppressLint("DrawAllocation")
@Override @Override
protected synchronized void onLayout(boolean changed, int left, int top, int right, int bottom) { protected synchronized void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom); super.onLayout(changed, left, top, right, bottom);
...@@ -308,6 +310,12 @@ public class HorizontalListView extends AdapterView<ListAdapter> { ...@@ -308,6 +310,12 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
return handled; return handled;
} }
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
requestDisallowInterceptTouchEvent(true);
return super.onInterceptTouchEvent(ev);
}
protected boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, protected boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) { float velocityY) {
synchronized(HorizontalListView.this){ synchronized(HorizontalListView.this){
......
...@@ -10,6 +10,7 @@ package org.telegram.ui.Views; ...@@ -10,6 +10,7 @@ package org.telegram.ui.Views;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
...@@ -34,6 +35,8 @@ public class ImageReceiver { ...@@ -34,6 +35,8 @@ public class ImageReceiver {
public Integer TAG = null; public Integer TAG = null;
public WeakReference<View> parentView = null; public WeakReference<View> parentView = null;
public int imageX = 0, imageY = 0, imageW = 0, imageH = 0; public int imageX = 0, imageY = 0, imageW = 0, imageH = 0;
public Rect drawRegion = new Rect();
private boolean isVisible = true;
private boolean selfSetting = false; private boolean selfSetting = false;
public void setImage(TLRPC.FileLocation path, String filter, Drawable placeholder) { public void setImage(TLRPC.FileLocation path, String filter, Drawable placeholder) {
...@@ -172,6 +175,9 @@ public class ImageReceiver { ...@@ -172,6 +175,9 @@ public class ImageReceiver {
} }
public void draw(Canvas canvas, int x, int y, int w, int h) { public void draw(Canvas canvas, int x, int y, int w, int h) {
if (!isVisible) {
return;
}
try { try {
if (currentImage != null) { if (currentImage != null) {
int bitmapW = currentImage.getIntrinsicWidth(); int bitmapW = currentImage.getIntrinsicWidth();
...@@ -179,27 +185,29 @@ public class ImageReceiver { ...@@ -179,27 +185,29 @@ public class ImageReceiver {
float scaleW = bitmapW / (float)w; float scaleW = bitmapW / (float)w;
float scaleH = bitmapH / (float)h; float scaleH = bitmapH / (float)h;
if (Math.abs(scaleW - scaleH) > 0.05f) { if (Math.abs(scaleW - scaleH) > 0.00001f) {
canvas.save(); canvas.save();
canvas.clipRect(x, y, x + w, y + h); canvas.clipRect(x, y, x + w, y + h);
if (bitmapW / scaleH > w) { if (bitmapW / scaleH > w) {
bitmapW /= scaleH; bitmapW /= scaleH;
currentImage.setBounds(x - (bitmapW - w) / 2, y, x + (bitmapW + w) / 2, y + h); drawRegion.set(x - (bitmapW - w) / 2, y, x + (bitmapW + w) / 2, y + h);
} else { } else {
bitmapH /= scaleW; bitmapH /= scaleW;
currentImage.setBounds(x, y - (bitmapH - h) / 2, x + w, y + (bitmapH + h) / 2); drawRegion.set(x, y - (bitmapH - h) / 2, x + w, y + (bitmapH + h) / 2);
} }
currentImage.setBounds(drawRegion);
currentImage.draw(canvas); currentImage.draw(canvas);
canvas.restore(); canvas.restore();
} else { } else {
currentImage.setBounds(x, y, x + w, y + h); drawRegion.set(x, y, x + w, y + h);
currentImage.setBounds(drawRegion);
currentImage.draw(canvas); currentImage.draw(canvas);
} }
} else if (last_placeholder != null) { } else if (last_placeholder != null) {
last_placeholder.setBounds(x, y, x + w, y + h); drawRegion.set(x, y, x + w, y + h);
last_placeholder.setBounds(drawRegion);
last_placeholder.draw(canvas); last_placeholder.draw(canvas);
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -211,4 +219,28 @@ public class ImageReceiver { ...@@ -211,4 +219,28 @@ public class ImageReceiver {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
} }
public Bitmap getBitmap() {
if (currentImage != null && currentImage instanceof BitmapDrawable) {
return ((BitmapDrawable)currentImage).getBitmap();
} else if (isPlaceholder && last_placeholder != null && last_placeholder instanceof BitmapDrawable) {
return ((BitmapDrawable)last_placeholder).getBitmap();
}
return null;
}
public void setVisible(boolean value) {
if (isVisible == value) {
return;
}
isVisible = value;
View parent = parentView.get();
if (parent != null) {
parent.invalidate();
}
}
public boolean getVisible() {
return isVisible;
}
} }
<!--
~ This is the source code of Telegram for Android v. 1.4.x.
~ 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-2014.
-->
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#40ffffff" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle">
<solid android:color="#40ffffff" />
</shape>
</item>
<item android:state_selected="true">
<shape android:shape="rectangle">
<solid android:color="#40ffffff" />
</shape>
</item>
<item android:drawable="@drawable/transparent" />
</selector>
\ No newline at end of file
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:scaleType="centerCrop" android:scaleType="centerCrop"
android:id="@+id/background_image" android:id="@+id/background_image"/>
android:layout_marginBottom="48dp"/>
<ProgressBar <ProgressBar
android:background="#99000000" android:background="#99000000"
...@@ -27,56 +26,6 @@ ...@@ -27,56 +26,6 @@
android:id="@+id/listView" android:id="@+id/listView"
android:clipToPadding="false" android:clipToPadding="false"
android:paddingLeft="40dp" android:paddingLeft="40dp"
android:paddingRight="40dp" android:paddingRight="40dp"/>
android:layout_marginBottom="48dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:layout_gravity="bottom">
<Button
android:textSize="12dp"
android:textColor="#111111"
android:id="@+id/cancel_button"
android:background="@drawable/list_selector"
android:paddingLeft="3dp"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:textAllCaps="true"
android:layout_weight="1.0"
android:textStyle="bold"/>
<View
android:layout_gravity="center_vertical"
android:background="#c9c9c9"
android:layout_width="1px"
android:layout_height="28dp" />
<FrameLayout
android:id="@+id/done_button"
android:background="@drawable/list_selector"
android:paddingRight="3dp"
android:clickable="true"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0">
<TextView
android:textSize="12dp"
android:textColor="#111111"
android:gravity="center"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:id="@+id/done_button_text"
android:drawableLeft="@drawable/ic_ab_done_gray"
android:drawablePadding="8dp"
android:textStyle="bold"/>
</FrameLayout>
</LinearLayout>
</FrameLayout> </FrameLayout>
\ No newline at end of file
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