1
0
mirror of https://github.com/NekoX-Dev/NekoX.git synced 2024-11-23 03:45:42 +01:00

update to 2.3.6

This commit is contained in:
DrKLO 2013-10-27 02:34:39 +04:00
parent c824df619a
commit 27b74b537e
8 changed files with 196 additions and 98 deletions

View File

@ -141,7 +141,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
void setTimeDifference(int diff) {
boolean store = Math.abs(diff - timeDifference) > 25;
timeDifference = diff;
//_timeOffsetFromUTC = _timeDifference + (int)[[NSTimeZone localTimeZone] secondsFromGMT];
if (store) {
saveSession();
}
@ -596,18 +595,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
datacenter.connection.datacenterId = datacenter.datacenterId;
}
datacenter.connection.connect();
/*if (it == currentDatacenterId) {
boolean isConnecting = datacenter.connection.channelToken != 0;
if (isConnecting) {
_isWaitingForFirstData = true;
}
if (_isConnecting != isConnecting)
{
_isConnecting = isConnecting;
[self dispatchConnectingState];
}
}*/
}
}
for (int it : downloadTransportsToResume) {
@ -1092,7 +1079,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
for (int num : unauthorizedDatacenterIds) {
if (num != currentDatacenterId && num != movingToDatacenterId && UserConfig.clientUserId != 0/* && unavailableDatacenterIds.get(num) == null*/) {
if (num != currentDatacenterId && num != movingToDatacenterId && UserConfig.clientUserId != 0) {
boolean notFound = true;
for (Action actor : actionQueue) {
if (actor instanceof ExportAuthorizationAction) {
@ -1205,7 +1192,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
currentSize += protoMessage.bytes;
// || currentMessages.size() == 5
if (currentSize >= 3 * 1024 || a == messagesToSend.size() - 1) {
ArrayList<Integer> quickAckId = new ArrayList<Integer>();
byte[] transportData = createConnectionData(currentMessages, sessionId, quickAckId, connection);
@ -1450,8 +1436,9 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
saveSession();
//if (sessionId == datacenter.authSessionId && [datacenter.datacenterId isEqualToValue:currentDatacenterId])
// [TGTelegraphInstance stateUpdateRequired];
if (sessionId == datacenter.authSessionId && datacenter.datacenterId == currentDatacenterId && UserConfig.clientActivated) {
MessagesController.Instance.getDifference();
}
arr.add(newSession.unique_id);
}
} else if (message instanceof TLRPC.TL_msg_container) {
@ -1894,20 +1881,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
@Override
public void tcpConnectionConnected(TcpConnection connection) {
/*int requestClass = [transport transportRequestClass];
if ([transport datacenter].datacenterId == _currentDatacenterId && requestClass & TGRequestClassGeneric)
{
if (_isConnecting)
{
_isConnecting = false;
_isWaitingForFirstData = true;
[self dispatchConnectingState];
}
if (!_isReady)
return;
}*/
Datacenter datacenter = datacenterWithId(connection.datacenterId);
if (datacenter.authKey != null) {
processRequestQueue(connection.transportRequestClass, connection.datacenterId);

View File

@ -402,18 +402,6 @@ public class Emoji {
if(bmps[info.page] == null) {
loadPageAsync(info.page);
}
/*drawables.add(new WeakReference<EmojiDrawable>(ed));
try {
for (int a = 0; a < drawables.size(); a++) {
WeakReference<EmojiDrawable> it = drawables.get(a);
if (it.get() == null) {
drawables.remove(a);
a--;
}
}
} catch(Throwable x) {
x.printStackTrace();
}*/
return ed;
}
@ -507,7 +495,8 @@ public class Emoji {
s = Spannable.Factory.getInstance().newSpannable(cs);
}
long buf = 0;
for (int i = 0; i < cs.length(); i++){
int emojiCount = 0;
for (int i = 0; i < cs.length(); i++) {
char c = cs.charAt(i);
if (c == 0xD83C || c == 0xD83D || (buf != 0 && (buf & 0xFFFFFFFF00000000L) == 0 && (c >= 0xDDE6 && c <= 0xDDFA))) {
buf <<= 16;
@ -518,6 +507,7 @@ public class Emoji {
Drawable d = Emoji.getEmojiDrawable(buf);
if (d != null){
EmojiSpan span = new EmojiSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM);
emojiCount++;
if (c>= 0xDDE6 && c <= 0xDDFA) {
s.setSpan(span, i - 3, i + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
@ -535,6 +525,7 @@ public class Emoji {
Drawable d = Emoji.getEmojiDrawable(buf);
if(d != null) {
EmojiSpan span = new EmojiSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM);
emojiCount++;
s.setSpan(span, i - 1, i + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
buf = 0;
@ -544,9 +535,13 @@ public class Emoji {
Drawable d = Emoji.getEmojiDrawable(c);
if(d != null){
EmojiSpan span = new EmojiSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM);
emojiCount++;
s.setSpan(span, i, i + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
if (emojiCount >= 50) {
break;
}
}
return s;
}

View File

@ -19,10 +19,10 @@ import java.security.NoSuchAlgorithmException;
import java.util.Locale;
public class FileUploadOperation {
private final int uploadChunkSize = 1024 * 32;
private int uploadChunkSize = 1024 * 32;
private String uploadingFilePath;
public int state = 0;
private byte[] readBuffer = new byte[uploadChunkSize];
private byte[] readBuffer;
public FileUploadOperationDelegate delegate;
private long requestToken = 0;
private int currentPartNum = 0;
@ -103,6 +103,9 @@ public class FileUploadOperation {
File cacheFile = new File(uploadingFilePath);
stream = new FileInputStream(cacheFile);
totalFileSize = cacheFile.length();
uploadChunkSize = (int)Math.max(32, Math.ceil(totalFileSize / (1024.0f * 3000))) * 1024;
readBuffer = new byte[uploadChunkSize];
}
int readed = stream.read(readBuffer);
int toAdd = 0;

View File

@ -25,7 +25,6 @@ import android.util.Log;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import org.json.JSONObject;
import org.telegram.TL.TLRPC;
import org.telegram.ui.ApplicationLoader;
import org.telegram.ui.LaunchActivity;
@ -118,8 +117,6 @@ public class GcmBroadcastReceiver extends BroadcastReceiver {
int chat_id = 0;
int user_id = 0;
TLRPC.User user = null;
TLRPC.Chat chat = null;
String custom = extras.getString("custom");
try {
if (custom != null) {
@ -171,7 +168,6 @@ public class GcmBroadcastReceiver extends BroadcastReceiver {
}
boolean needVibrate;
boolean needPreview = true;
String choosenSoundPath = null;
if (chat_id != 0) {
@ -192,6 +188,8 @@ public class GcmBroadcastReceiver extends BroadcastReceiver {
} else if (chatSound != null) {
choosenSoundPath = chatSound;
}
} else {
choosenSoundPath = globalSound;
}
intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
@ -205,11 +203,9 @@ public class GcmBroadcastReceiver extends BroadcastReceiver {
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg)
.setAutoCancel(true);
.setAutoCancel(true)
.setTicker(msg);
if (needPreview) {
mBuilder.setTicker(msg);
}
if (needVibrate) {
mBuilder.setVibrate(new long[]{0, 100, 0, 100});
}

View File

@ -11,11 +11,15 @@ package org.telegram.messenger;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.database.Cursor;
@ -27,6 +31,8 @@ import android.os.Build;
import android.os.Vibrator;
import android.provider.BaseColumns;
import android.provider.ContactsContract;
import android.provider.Settings;
import android.support.v4.app.NotificationCompat;
import android.text.Html;
import android.util.Log;
import android.util.SparseArray;
@ -38,6 +44,7 @@ import org.telegram.TL.TLObject;
import org.telegram.TL.TLRPC;
import org.telegram.objects.MessageObject;
import org.telegram.ui.ApplicationLoader;
import org.telegram.ui.LaunchActivity;
import java.io.File;
import java.io.FileInputStream;
@ -4100,61 +4107,182 @@ public class MessagesController implements NotificationCenter.NotificationCenter
return;
}
boolean inAppSounds = preferences.getBoolean("EnableInAppSounds", true);
boolean inAppVibrate = preferences.getBoolean("EnableInAppVibrate", true);
boolean inAppPreview = preferences.getBoolean("EnableInAppPreview", true);
if (ApplicationLoader.lastPauseTime == 0) {
boolean inAppSounds = preferences.getBoolean("EnableInAppSounds", true);
boolean inAppVibrate = preferences.getBoolean("EnableInAppVibrate", true);
boolean inAppPreview = preferences.getBoolean("EnableInAppPreview", true);
if ((inAppSounds || inAppVibrate || inAppPreview) && ApplicationLoader.lastPauseTime == 0) {
long dialog_id = messageObject.messageOwner.dialog_id;
int user_id = messageObject.messageOwner.from_id;
int chat_id = 0;
if (dialog_id == 0) {
if (messageObject.messageOwner.to_id.chat_id != 0) {
dialog_id = -messageObject.messageOwner.to_id.chat_id;
chat_id = messageObject.messageOwner.to_id.chat_id;
} else if (messageObject.messageOwner.to_id.user_id != 0) {
if (messageObject.messageOwner.to_id.user_id == UserConfig.clientUserId) {
dialog_id = messageObject.messageOwner.from_id;
} else {
dialog_id = messageObject.messageOwner.to_id.user_id;
if (inAppSounds || inAppVibrate || inAppPreview) {
long dialog_id = messageObject.messageOwner.dialog_id;
int user_id = messageObject.messageOwner.from_id;
int chat_id = 0;
if (dialog_id == 0) {
if (messageObject.messageOwner.to_id.chat_id != 0) {
dialog_id = -messageObject.messageOwner.to_id.chat_id;
chat_id = messageObject.messageOwner.to_id.chat_id;
} else if (messageObject.messageOwner.to_id.user_id != 0) {
if (messageObject.messageOwner.to_id.user_id == UserConfig.clientUserId) {
dialog_id = messageObject.messageOwner.from_id;
} else {
dialog_id = messageObject.messageOwner.to_id.user_id;
}
}
} else {
TLRPC.EncryptedChat chat = encryptedChats.get((int)(dialog_id >> 32));
if (chat == null) {
return;
}
}
} else {
TLRPC.EncryptedChat chat = encryptedChats.get((int)(dialog_id >> 32));
if (chat == null) {
if (dialog_id == 0) {
return;
}
TLRPC.User user = users.get(user_id);
if (user == null) {
return;
}
TLRPC.Chat chat;
if (chat_id != 0) {
chat = chats.get(chat_id);
if (chat == null) {
return;
}
}
String key = "notify_" + dialog_id;
boolean value = preferences.getBoolean(key, true);
if (!value) {
return;
}
if (inAppPreview) {
NotificationCenter.Instance.postNotificationName(701, messageObject);
}
if (inAppVibrate) {
Vibrator v = (Vibrator)Utilities.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(100);
}
if (inAppSounds) {
playNotificationSound();
}
}
} else {
long dialog_id = messageObject.messageOwner.dialog_id;
int chat_id = messageObject.messageOwner.to_id.chat_id;
int user_id = messageObject.messageOwner.to_id.user_id;
if (dialog_id == 0) {
return;
if (chat_id != 0) {
dialog_id = -chat_id;
} else if (user_id != 0) {
dialog_id = user_id;
}
}
TLRPC.User user = users.get(user_id);
if (user == null) {
return;
if ((int)dialog_id != 0) {
return; //temporary disable notifications for normal chats
}
TLRPC.Chat chat;
if (chat_id != 0) {
chat = chats.get(chat_id);
if (chat == null) {
if (dialog_id != 0) {
String key = "notify_" + dialog_id;
boolean value = preferences.getBoolean(key, true);
if (!value) {
return;
}
}
String key = "notify_" + dialog_id;
boolean value = preferences.getBoolean(key, true);
if (!value) {
boolean groupEnabled = preferences.getBoolean("EnableGroup", true);
if (chat_id != 0 && !globalEnabled) {
return;
}
if (inAppPreview) {
NotificationCenter.Instance.postNotificationName(701, messageObject);
boolean globalVibrate = preferences.getBoolean("EnableVibrateAll", true);
boolean groupVibrate = preferences.getBoolean("EnableVibrateGroup", true);
String defaultPath = null;
Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
if (defaultUri != null) {
defaultPath = defaultUri.getPath();
}
if (inAppVibrate) {
Vibrator v = (Vibrator)Utilities.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(100);
String globalSound = preferences.getString("GlobalSoundPath", defaultPath);
String chatSound = preferences.getString("GroupSoundPath", defaultPath);
String userSoundPath = null;
String chatSoundPath = null;
NotificationManager mNotificationManager = (NotificationManager)Utilities.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(Utilities.applicationContext, LaunchActivity.class);
String msg;
if ((int)dialog_id != 0) {
if (chat_id != 0) {
intent.putExtra("chatId", chat_id);
}
if (user_id != 0) {
intent.putExtra("userId", user_id);
}
msg = messageObject.messageOwner.message;
} else {
msg = Utilities.applicationContext.getString(R.string.YouHaveNewMessage);
}
if (inAppSounds) {
playNotificationSound();
boolean needVibrate = false;
if (user_id != 0) {
userSoundPath = preferences.getString("sound_path_" + user_id, null);
needVibrate = globalVibrate;
}
if (chat_id != 0) {
chatSoundPath = preferences.getString("sound_chat_path_" + chat_id, null);
needVibrate = groupVibrate;
}
String choosenSoundPath = null;
if (user_id != 0) {
if (userSoundPath != null) {
choosenSoundPath = userSoundPath;
} else if (globalSound != null) {
choosenSoundPath = globalSound;
}
} else if (chat_id != 0) {
if (chatSoundPath != null) {
choosenSoundPath = chatSoundPath;
} else if (chatSound != null) {
choosenSoundPath = chatSound;
}
} else {
choosenSoundPath = globalSound;
}
intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(Utilities.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(Utilities.applicationContext)
.setContentTitle(Utilities.applicationContext.getString(R.string.AppName))
.setSmallIcon(R.drawable.notification)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg)
.setAutoCancel(true)
.setTicker(msg);
if (needVibrate) {
mBuilder.setVibrate(new long[]{0, 100, 0, 100});
}
if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) {
if (choosenSoundPath.equals(defaultPath)) {
mBuilder.setSound(defaultUri);
} else {
mBuilder.setSound(Uri.parse(choosenSoundPath));
}
}
mBuilder.setContentIntent(contentIntent);
mNotificationManager.cancel(1);
Notification notification = mBuilder.build();
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 1000;
notification.ledOffMS = 1000;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
mNotificationManager.notify(1, notification);
}
}

View File

@ -104,9 +104,6 @@ public class TcpConnection extends PyroClientAdapter {
}
public void suspendConnection(boolean task) {
if (ConnectionsManager.DEBUG_VERSION) {
Log.d("tmessages", "suspend connnection " + this);
}
if (task) {
selector.scheduleTask(new Runnable() {
@Override
@ -118,6 +115,9 @@ public class TcpConnection extends PyroClientAdapter {
if (connectionState == TcpConnectionState.TcpConnectionStageIdle || connectionState == TcpConnectionState.TcpConnectionStageSuspended) {
return;
}
if (ConnectionsManager.DEBUG_VERSION) {
Log.d("tmessages", "suspend connnection " + this);
}
connectionState = TcpConnectionState.TcpConnectionStageSuspended;
if (client != null) {
client.dropConnection();
@ -130,9 +130,12 @@ public class TcpConnection extends PyroClientAdapter {
reconnectTimer.cancel();
reconnectTimer = null;
}
if (connectionState == TcpConnectionState.TcpConnectionStageIdle) {
if (connectionState == TcpConnectionState.TcpConnectionStageIdle || connectionState == TcpConnectionState.TcpConnectionStageSuspended) {
return;
}
if (ConnectionsManager.DEBUG_VERSION) {
Log.d("tmessages", "suspend connnection " + this);
}
connectionState = TcpConnectionState.TcpConnectionStageSuspended;
if (client != null) {
client.dropConnection();

View File

@ -2165,14 +2165,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
Intent pickIntent = new Intent();
pickIntent.setType("video/*");
pickIntent.setAction(Intent.ACTION_GET_CONTENT);
pickIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 1024 * 1024 * 100);
pickIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 1024 * 1024 * 1000);
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
File video = Utilities.generateVideoPath();
if (video != null) {
if(android.os.Build.VERSION.SDK_INT > 10) {
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video));
}
takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 1024 * 1024 * 100);
takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 1024 * 1024 * 1000);
currentPicturePath = video.getAbsolutePath();
}
Intent chooserIntent = Intent.createChooser(pickIntent, "");

View File

@ -198,7 +198,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
((ApplicationActivity)parentActivity).presentFragment(fragment, "key_" + dialog_id, false);
} else if (i == 4 && dialog_id != 0 && currentEncryptedChat instanceof TLRPC.TL_encryptedChat) {
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setTitle(getStringEntry(R.string.TextSize));
builder.setTitle(getStringEntry(R.string.MessageLifetime));
builder.setItems(new CharSequence[]{
getStringEntry(R.string.ShortMessageLifetimeForever),
getStringEntry(R.string.ShortMessageLifetime2s),