update to 2.7.0

This commit is contained in:
DrKLO 2015-04-09 21:00:14 +03:00
parent 525676eb1b
commit b820e126d2
123 changed files with 12466 additions and 9380 deletions

View File

@ -82,7 +82,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
versionCode 479
versionName "2.6.1"
versionCode 492
versionName "2.7.0"
}
}

View File

@ -104,7 +104,7 @@ include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_PRELINK_MODULE := false
LOCAL_STATIC_LIBRARIES := webp sqlite
LOCAL_MODULE := tmessages.6
LOCAL_MODULE := tmessages.7
LOCAL_CFLAGS := -w -std=gnu99 -O2 -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64
LOCAL_CFLAGS += -Drestrict='' -D__EMX__ -DOPUS_BUILD -DFIXED_POINT -DUSE_ALLOCA -DHAVE_LRINT -DHAVE_LRINTF -fno-math-errno
LOCAL_CFLAGS += -DANDROID_NDK -DDISABLE_IMPORTGL -fno-strict-aliasing -fprefetch-loop-arrays -DAVOID_TABLES -DANDROID_TILE_BASED_DECODE -DANDROID_ARMV6_IDCT -ffast-math

View File

@ -419,6 +419,11 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_calcCDT(JNIEnv *env, jclass
free(cdfsMin);
}
JNIEXPORT int Java_org_telegram_messenger_Utilities_pinBitmap(JNIEnv *env, jclass class, jobject bitmap) {
unsigned char *pixels;
return AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0 ? 1 : 0;
}
JNIEXPORT void Java_org_telegram_messenger_Utilities_loadBitmap(JNIEnv *env, jclass class, jstring path, jobject bitmap, int scale, int width, int height, int stride) {
AndroidBitmapInfo info;

View File

@ -14,6 +14,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Typeface;
@ -23,6 +24,7 @@ import android.os.Environment;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.DisplayMetrics;
import android.util.StateSet;
import android.view.Display;
@ -43,6 +45,10 @@ import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.AnimationCompat.AnimatorListenerAdapterProxy;
import org.telegram.ui.AnimationCompat.AnimatorSetProxy;
import org.telegram.ui.AnimationCompat.ObjectAnimatorProxy;
import org.telegram.ui.AnimationCompat.ViewProxy;
import org.telegram.ui.Components.ForegroundDetector;
import org.telegram.ui.Components.NumberPicker;
import org.telegram.ui.Components.TypefaceSpan;
@ -538,21 +544,51 @@ public class AndroidUtilities {
}
}
public static Spannable replaceBold(String str) {
int start;
public static Spannable replaceTags(String str) {
try {
int start = -1;
int startColor = -1;
int end = -1;
StringBuilder stringBuilder = new StringBuilder(str);
while ((start = stringBuilder.indexOf("<br>")) != -1) {
stringBuilder.replace(start, start + 4, "\n");
}
while ((start = stringBuilder.indexOf("<br/>")) != -1) {
stringBuilder.replace(start, start + 5, "\n");
}
ArrayList<Integer> bolds = new ArrayList<>();
while ((start = str.indexOf("<b>")) != -1) {
int end = str.indexOf("</b>") - 3;
str = str.replaceFirst("<b>", "").replaceFirst("</b>", "");
ArrayList<Integer> colors = new ArrayList<>();
while ((start = stringBuilder.indexOf("<b>")) != -1 || (startColor = stringBuilder.indexOf("<c")) != -1) {
if (start != -1) {
stringBuilder.replace(start, start + 3, "");
end = stringBuilder.indexOf("</b>");
stringBuilder.replace(end, end + 4, "");
bolds.add(start);
bolds.add(end);
} else if (startColor != -1) {
stringBuilder.replace(startColor, startColor + 2, "");
end = stringBuilder.indexOf(">", startColor);
int color = Color.parseColor(stringBuilder.substring(startColor, end));
stringBuilder.replace(startColor, end + 1, "");
end = stringBuilder.indexOf("</c>");
stringBuilder.replace(end, end + 4, "");
colors.add(startColor);
colors.add(end);
colors.add(color);
}
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(str);
}
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(stringBuilder);
for (int a = 0; a < bolds.size() / 2; a++) {
TypefaceSpan span = new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
stringBuilder.setSpan(span, bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
spannableStringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return stringBuilder;
for (int a = 0; a < colors.size() / 3; a++) {
spannableStringBuilder.setSpan(new ForegroundColorSpan(colors.get(a * 3 + 2)), colors.get(a * 3), colors.get(a * 3 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return spannableStringBuilder;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return new SpannableStringBuilder(str);
}
public static boolean needShowPasscode(boolean reset) {
@ -569,6 +605,61 @@ public class AndroidUtilities {
(UserConfig.appLocked || UserConfig.autoLockIn != 0 && UserConfig.lastPauseTime != 0 && !UserConfig.appLocked && (UserConfig.lastPauseTime + UserConfig.autoLockIn) <= ConnectionsManager.getInstance().getCurrentTime());
}
public static void shakeTextView(final TextView textView, final float x, final int num) {
if (num == 6) {
ViewProxy.setTranslationX(textView, 0);
textView.clearAnimation();
return;
}
AnimatorSetProxy animatorSetProxy = new AnimatorSetProxy();
animatorSetProxy.playTogether(ObjectAnimatorProxy.ofFloat(textView, "translationX", AndroidUtilities.dp(x)));
animatorSetProxy.setDuration(50);
animatorSetProxy.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Object animation) {
shakeTextView(textView, num == 5 ? 0 : -x, num + 1);
}
});
animatorSetProxy.start();
}
/*public static String ellipsize(String text, int maxLines, int maxWidth, TextPaint paint) {
if (text == null || paint == null) {
return null;
}
int count;
int offset = 0;
StringBuilder result = null;
TextView
for (int a = 0; a < maxLines; a++) {
count = paint.breakText(text, true, maxWidth, null);
if (a != maxLines - 1) {
if (result == null) {
result = new StringBuilder(count * maxLines + 1);
}
boolean foundSpace = false;
for (int c = count - 1; c >= offset; c--) {
if (text.charAt(c) == ' ') {
foundSpace = true;
result.append(text.substring(offset, c - 1));
offset = c - 1;
}
}
if (!foundSpace) {
offset = count;
}
text = text.substring(0, offset);
} else if (maxLines == 1) {
return text.substring(0, count);
} else {
result.append(text.substring(0, count));
}
}
return result.toString();
}*/
/*public static void turnOffHardwareAcceleration(Window window) {
if (window == null || Build.MODEL == null || Build.VERSION.SDK_INT < 11) {
return;

View File

@ -645,9 +645,13 @@ public class ImageLoader {
} else {
opts.inPreferredConfig = Bitmap.Config.RGB_565;
}
//if (Build.VERSION.SDK_INT < 21) {
// opts.inPurgeable = true;
//}
opts.inDither = false;
if (mediaId != null) {
image = MediaStore.Images.Thumbnails.getThumbnail(ApplicationLoader.applicationContext.getContentResolver(), mediaId, MediaStore.Images.Thumbnails.MINI_KIND, null);
image = MediaStore.Images.Thumbnails.getThumbnail(ApplicationLoader.applicationContext.getContentResolver(), mediaId, MediaStore.Images.Thumbnails.MINI_KIND, opts);
}
if (image == null) {
if (isWebp) {
@ -1981,6 +1985,15 @@ public class ImageLoader {
}
}
}
} else if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
if (message.media.webpage.photo != null) {
for (TLRPC.PhotoSize size : message.media.webpage.photo.sizes) {
if (size instanceof TLRPC.TL_photoCachedSize) {
photoSize = size;
break;
}
}
}
}
if (photoSize != null && photoSize.bytes != null && photoSize.bytes.length != 0) {
if (photoSize.location instanceof TLRPC.TL_fileLocationUnavailable) {
@ -2018,6 +2031,13 @@ public class ImageLoader {
message.media.video.thumb = newPhotoSize;
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
message.media.document.thumb = newPhotoSize;
} else if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
for (int a = 0; a < message.media.webpage.photo.sizes.size(); a++) {
if (message.media.webpage.photo.sizes.get(a) instanceof TLRPC.TL_photoCachedSize) {
message.media.webpage.photo.sizes.set(a, newPhotoSize);
break;
}
}
}
}
}

View File

@ -68,7 +68,6 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
private Matrix shaderMatrix;
private int alpha = 255;
private boolean isPressed;
private boolean disableRecycle;
private int orientation;
private boolean centerRotation;
private ImageReceiverDelegate delegate;
@ -224,10 +223,6 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
setImageBitmap(bitmap != null ? new BitmapDrawable(null, bitmap) : null);
}
public void setDisableRecycle(boolean value) {
disableRecycle = value;
}
public void setImageBitmap(Drawable bitmap) {
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, 0);
recycleBitmap(null, false);
@ -497,10 +492,18 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
return imageX;
}
public int getImageX2() {
return imageX + imageW;
}
public int getImageY() {
return imageY;
}
public int getImageY2() {
return imageY + imageH;
}
public int getImageWidth() {
return imageW;
}
@ -682,7 +685,7 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
if (newKey != null) {
newBitmap = ImageLoader.getInstance().getImageFromMemory(newKey);
}
if (key == null || image == null || image == newBitmap || disableRecycle) {
if (key == null || image == null || image == newBitmap) {
return;
}
Bitmap bitmap = image.getBitmap();

View File

@ -1105,8 +1105,16 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
if (proximitySensor != null && audioTrackPlayer == null && audioPlayer == null || isPaused || (useFrontSpeaker == (event.values[0] < proximitySensor.getMaximumRange() / 10))) {
return;
}
boolean newValue = event.values[0] < proximitySensor.getMaximumRange() / 10;
try {
if (newValue && NotificationsController.getInstance().audioManager.isWiredHeadsetOn()) {
return;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
ignoreProximity = true;
useFrontSpeaker = event.values[0] < proximitySensor.getMaximumRange() / 10;
useFrontSpeaker = newValue;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioRouteChanged, useFrontSpeaker);
MessageObject currentMessageObject = playingMessageObject;
float progress = playingMessageObject.audioProgress;

View File

@ -41,6 +41,7 @@ public class MessageObject {
public TLRPC.Message messageOwner;
public CharSequence messageText;
public CharSequence linkDescription;
public MessageObject replyMessageObject;
public int type;
public int contentType;
@ -273,7 +274,7 @@ public class MessageObject {
messageText = LocaleController.formatString("YouCreatedBroadcastList", R.string.YouCreatedBroadcastList);
}
}
} else if (message.media != null && !(message.media instanceof TLRPC.TL_messageMediaEmpty)) {
} else if (!isMediaEmpty()) {
if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
messageText = LocaleController.getString("AttachPhoto", R.string.AttachPhoto);
} else if (message.media instanceof TLRPC.TL_messageMediaVideo) {
@ -309,22 +310,22 @@ public class MessageObject {
messageText = Emoji.replaceEmoji(messageText, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20));
if (message instanceof TLRPC.TL_message || message instanceof TLRPC.TL_messageForwarded_old2) {
if (message.media == null || message.media instanceof TLRPC.TL_messageMediaEmpty) {
if (isMediaEmpty()) {
contentType = type = 0;
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaPhoto) {
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
contentType = type = 1;
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaGeo) {
} else if (message.media instanceof TLRPC.TL_messageMediaGeo) {
contentType = 1;
type = 4;
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaVideo) {
} else if (message.media instanceof TLRPC.TL_messageMediaVideo) {
contentType = 1;
type = 3;
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaContact) {
} else if (message.media instanceof TLRPC.TL_messageMediaContact) {
contentType = 3;
type = 12;
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaUnsupported) {
} else if (message.media instanceof TLRPC.TL_messageMediaUnsupported) {
contentType = type = 0;
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaDocument) {
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
contentType = 1;
if (message.media.document.mime_type != null) {
if (message.media.document.mime_type.equals("image/gif") && message.media.document.thumb != null && !(message.media.document.thumb instanceof TLRPC.TL_photoSizeEmpty)) {
@ -340,7 +341,7 @@ public class MessageObject {
} else {
type = 9;
}
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaAudio) {
} else if (message.media instanceof TLRPC.TL_messageMediaAudio) {
contentType = type = 2;
}
} else if (message instanceof TLRPC.TL_messageService) {
@ -433,6 +434,24 @@ public class MessageObject {
photoObject.location = messageOwner.media.document.thumb.location;
}
}
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
if (messageOwner.media.webpage.photo != null) {
if (!update || photoThumbs == null) {
photoThumbs = new ArrayList<>(messageOwner.media.webpage.photo.sizes);
} else if (photoThumbs != null && !photoThumbs.isEmpty()) {
for (TLRPC.PhotoSize photoObject : photoThumbs) {
for (TLRPC.PhotoSize size : messageOwner.media.webpage.photo.sizes) {
if (size instanceof TLRPC.TL_photoSizeEmpty) {
continue;
}
if (size.type.equals(photoObject.type)) {
photoObject.location = size.location;
break;
}
}
}
}
}
}
}
}
@ -538,11 +557,24 @@ public class MessageObject {
return false;
}
public void generateLinkDescription() {
if (linkDescription != null) {
return;
}
if (messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageOwner.media.webpage instanceof TLRPC.TL_webPage && messageOwner.media.webpage.description != null) {
linkDescription = Spannable.Factory.getInstance().newSpannable(messageOwner.media.webpage.description);
if (containsUrls(linkDescription)) {
Linkify.addLinks((Spannable) linkDescription, Linkify.WEB_URLS);
}
}
}
private void generateLayout() {
if (type != 0 || messageOwner.to_id == null || messageText == null || messageText.length() == 0) {
return;
}
generateLinkDescription();
textLayoutBlocks = new ArrayList<>();
if (messageText instanceof Spannable && containsUrls(messageText)) {
@ -781,7 +813,7 @@ public class MessageObject {
}
public boolean isSending() {
return messageOwner.send_state == MESSAGE_SEND_STATE_SENDING;
return messageOwner.send_state == MESSAGE_SEND_STATE_SENDING && messageOwner.id < 0;
}
public boolean isSendError() {
@ -789,7 +821,7 @@ public class MessageObject {
}
public boolean isSent() {
return messageOwner.send_state == MESSAGE_SEND_STATE_SENT;
return messageOwner.send_state == MESSAGE_SEND_STATE_SENT || messageOwner.id > 0;
}
public String getSecretTimeString() {
@ -944,4 +976,12 @@ public class MessageObject {
public boolean isReply() {
return !(replyMessageObject != null && replyMessageObject.messageOwner instanceof TLRPC.TL_messageEmpty) && messageOwner.reply_to_msg_id != 0 && (messageOwner.flags & TLRPC.MESSAGE_FLAG_REPLY) != 0;
}
public boolean isMediaEmpty() {
return isMediaEmpty(messageOwner);
}
public static boolean isMediaEmpty(TLRPC.Message message) {
return message == null || message.media == null || message.media instanceof TLRPC.TL_messageMediaEmpty || message.media instanceof TLRPC.TL_messageMediaWebPage;
}
}

View File

@ -13,7 +13,6 @@ import android.app.AlertDialog;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.text.Html;
import android.util.Base64;
import android.util.SparseArray;
@ -179,7 +178,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
public void updateConfig(final TLRPC.TL_config config) {
AndroidUtilities.runOnUIThread(new Runnable() {
AndroidUtilities.runOnUIThread(new Runnable() { //TODO use new config params
@Override
public void run() {
maxBroadcastCount = config.broadcast_size_max;
@ -1307,12 +1306,12 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (label.length() != 0) {
if (count > 1) {
if (arr.size() > 2) {
newPrintingStrings.put(key, Html.fromHtml(String.format("%s %s", label, LocaleController.formatPluralString("AndMoreTyping", arr.size() - 2))));
newPrintingStrings.put(key, String.format("%s %s", label, LocaleController.formatPluralString("AndMoreTyping", arr.size() - 2)));
} else {
newPrintingStrings.put(key, Html.fromHtml(String.format("%s %s", label, LocaleController.getString("AreTyping", R.string.AreTyping))));
newPrintingStrings.put(key, String.format("%s %s", label, LocaleController.getString("AreTyping", R.string.AreTyping)));
}
} else {
newPrintingStrings.put(key, Html.fromHtml(String.format("%s %s", label, LocaleController.getString("IsTyping", R.string.IsTyping))));
newPrintingStrings.put(key, String.format("%s %s", label, LocaleController.getString("IsTyping", R.string.IsTyping)));
}
}
}
@ -1472,13 +1471,22 @@ public class MessagesController implements NotificationCenter.NotificationCenter
for (TLRPC.Message message : messagesRes.messages) {
message.dialog_id = dialog_id;
objects.add(new MessageObject(message, usersLocal, true));
if (isCache && message.media instanceof TLRPC.TL_messageMediaUnsupported) {
if (isCache) {
if (message.media instanceof TLRPC.TL_messageMediaUnsupported) {
if (message.media.bytes.length == 0 || message.media.bytes.length == 1 && message.media.bytes[0] < TLRPC.LAYER) {
if (messagesToReload == null) {
messagesToReload = new ArrayList<>();
}
messagesToReload.add(message.id);
}
} else if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
if (message.media.webpage instanceof TLRPC.TL_webPagePending && message.media.webpage.date <= ConnectionsManager.getInstance().getCurrentTime()) {
if (messagesToReload == null) {
messagesToReload = new ArrayList<>();
}
messagesToReload.add(message.id);
}
}
}
}
if (messagesToReload != null) {
@ -1941,7 +1949,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
public long createChat(String title, ArrayList<Integer> selectedContacts, final TLRPC.InputFile uploadedAvatar, boolean isBroadcast) {
public long createChat(String title, ArrayList<Integer> selectedContacts, boolean isBroadcast) {
if (isBroadcast) {
TLRPC.TL_chat chat = new TLRPC.TL_chat();
chat.id = UserConfig.lastBroadcastId;
@ -2015,35 +2023,21 @@ public class MessagesController implements NotificationCenter.NotificationCenter
});
return;
}
final TLRPC.messages_StatedMessage res = (TLRPC.messages_StatedMessage) response;
MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, true, true);
final TLRPC.Updates updates = (TLRPC.Updates) response;
processUpdates(updates, false);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
putUsers(res.users, false);
putChats(res.chats, false);
final ArrayList<MessageObject> messagesObj = new ArrayList<>();
messagesObj.add(new MessageObject(res.message, users, true));
TLRPC.Chat chat = res.chats.get(0);
updateInterfaceWithMessages(-chat.id, messagesObj);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatDidCreated, chat.id);
if (uploadedAvatar != null) {
changeChatAvatar(chat.id, uploadedAvatar);
putUsers(updates.users, false);
putChats(updates.chats, false);
TLRPC.Chat chat = null;
if (updates.chats != null && !updates.chats.isEmpty()) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatDidCreated, updates.chats.get(0).id);
} else {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatDidFailCreate);
}
}
});
final ArrayList<TLRPC.Message> messages = new ArrayList<>();
messages.add(res.message);
MessagesStorage.getInstance().putMessages(messages, true, true, false, 0);
if (res instanceof TLRPC.TL_messages_statedMessage) {
MessagesController.getInstance().processNewDifferenceParams(-1, res.pts, res.message.date, res.pts_count);
} else if (res instanceof TLRPC.TL_messages_statedMessageLink) {
MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, res.message.date, res.pts_count);
}
}
});
}
@ -2066,48 +2060,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (error != null) {
return;
}
final TLRPC.messages_StatedMessage res = (TLRPC.messages_StatedMessage) response;
MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, true, true);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
putUsers(res.users, false);
putChats(res.chats, false);
final ArrayList<MessageObject> messagesObj = new ArrayList<>();
messagesObj.add(new MessageObject(res.message, users, true));
TLRPC.Chat chat = res.chats.get(0);
updateInterfaceWithMessages(-chat.id, messagesObj);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_CHAT_MEMBERS);
if (info != null) {
for (TLRPC.TL_chatParticipant p : info.participants) {
if (p.user_id == user.id) {
return;
}
}
TLRPC.TL_chatParticipant newPart = new TLRPC.TL_chatParticipant();
newPart.user_id = user.id;
newPart.inviter_id = UserConfig.getClientUserId();
newPart.date = ConnectionsManager.getInstance().getCurrentTime();
info.participants.add(0, newPart);
MessagesStorage.getInstance().updateChatInfo(info.chat_id, info, true);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatInfoDidLoaded, info.chat_id, info);
}
}
});
final ArrayList<TLRPC.Message> messages = new ArrayList<>();
messages.add(res.message);
MessagesStorage.getInstance().putMessages(messages, true, true, false, 0);
if (res instanceof TLRPC.TL_messages_statedMessage) {
MessagesController.getInstance().processNewDifferenceParams(-1, res.pts, res.message.date, res.pts_count);
} else if (res instanceof TLRPC.TL_messages_statedMessageLink) {
MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, res.message.date, res.pts_count);
}
processUpdates((TLRPC.Updates) response, false);
}
});
} else {
@ -2150,57 +2103,15 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (error != null) {
return;
}
final TLRPC.messages_StatedMessage res = (TLRPC.messages_StatedMessage) response;
final TLRPC.Updates updates = (TLRPC.Updates) response;
processUpdates(updates, false);
if (user.id == UserConfig.getClientUserId()) {
res.chats = null;
}
MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, true, true);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
putUsers(res.users, false);
putChats(res.chats, false);
if (user.id != UserConfig.getClientUserId()) {
final ArrayList<MessageObject> messagesObj = new ArrayList<>();
messagesObj.add(new MessageObject(res.message, users, true));
TLRPC.Chat chat = res.chats.get(0);
updateInterfaceWithMessages(-chat.id, messagesObj);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_CHAT_MEMBERS);
}
boolean changed = false;
if (info != null) {
for (int a = 0; a < info.participants.size(); a++) {
TLRPC.TL_chatParticipant p = info.participants.get(a);
if (p.user_id == user.id) {
info.participants.remove(a);
changed = true;
break;
}
}
if (changed) {
MessagesStorage.getInstance().updateChatInfo(chat_id, info, true);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatInfoDidLoaded, info.chat_id, info);
} else {
MessagesStorage.getInstance().updateChatInfo(chat_id, user.id, true, 0, 0);
}
} else {
MessagesStorage.getInstance().updateChatInfo(chat_id, user.id, true, 0, 0);
}
MessagesController.getInstance().deleteDialog(-chat_id, 0, false);
}
});
if (user.id != UserConfig.getClientUserId()) {
final ArrayList<TLRPC.Message> messages = new ArrayList<>();
messages.add(res.message);
MessagesStorage.getInstance().putMessages(messages, true, true, false, 0);
}
if (res instanceof TLRPC.TL_messages_statedMessage) {
MessagesController.getInstance().processNewDifferenceParams(-1, res.pts, res.message.date, res.pts_count);
} else if (res instanceof TLRPC.TL_messages_statedMessageLink) {
MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, res.message.date, res.pts_count);
}
}
});
@ -2243,32 +2154,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (error != null) {
return;
}
final TLRPC.messages_StatedMessage res = (TLRPC.messages_StatedMessage) response;
MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, true, true);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
putUsers(res.users, false);
putChats(res.chats, false);
final ArrayList<MessageObject> messagesObj = new ArrayList<>();
messagesObj.add(new MessageObject(res.message, users, true));
TLRPC.Chat chat = res.chats.get(0);
updateInterfaceWithMessages(-chat.id, messagesObj);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_CHAT_NAME);
}
});
final ArrayList<TLRPC.Message> messages = new ArrayList<>();
messages.add(res.message);
MessagesStorage.getInstance().putMessages(messages, true, true, false, 0);
if (res instanceof TLRPC.TL_messages_statedMessage) {
MessagesController.getInstance().processNewDifferenceParams(-1, res.pts, res.message.date, res.pts_count);
} else if (res instanceof TLRPC.TL_messages_statedMessageLink) {
MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, res.message.date, res.pts_count);
}
processUpdates((TLRPC.Updates) response, false);
}
});
} else {
@ -2298,34 +2184,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (error != null) {
return;
}
final TLRPC.messages_StatedMessage res = (TLRPC.messages_StatedMessage) response;
MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, true, true);
final ArrayList<TLRPC.Message> messages = new ArrayList<>();
messages.add(res.message);
ImageLoader.saveMessagesThumbs(messages);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
putUsers(res.users, false);
putChats(res.chats, false);
final ArrayList<MessageObject> messagesObj = new ArrayList<>();
messagesObj.add(new MessageObject(res.message, users, true));
TLRPC.Chat chat = res.chats.get(0);
updateInterfaceWithMessages(-chat.id, messagesObj);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_CHAT_AVATAR);
}
});
MessagesStorage.getInstance().putMessages(messages, true, true, false, 0);
if (res instanceof TLRPC.TL_messages_statedMessage) {
MessagesController.getInstance().processNewDifferenceParams(-1, res.pts, res.message.date, res.pts_count);
} else if (res instanceof TLRPC.TL_messages_statedMessageLink) {
MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, res.message.date, res.pts_count);
}
processUpdates((TLRPC.Updates) response, false);
}
});
}
@ -2617,6 +2476,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
req.pts = MessagesStorage.lastPtsValue;
req.date = MessagesStorage.lastDateValue;
req.qts = MessagesStorage.lastQtsValue;
if (req.date == 0) {
req.date = ConnectionsManager.getInstance().getCurrentTime();
}
FileLog.e("tmessages", "start getDifference with date = " + MessagesStorage.lastDateValue + " pts = " + MessagesStorage.lastPtsValue + " seq = " + MessagesStorage.lastSeqValue);
if (ConnectionsManager.getInstance().getConnectionState() == 0) {
ConnectionsManager.getInstance().setConnectionState(3);
@ -2681,7 +2543,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
Integer oldId = entry.getKey();
SendMessagesHelper.getInstance().processSentMessage(oldId);
Integer newId = entry.getValue();
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, newId, null);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, newId, null, false);
}
}
});
@ -2860,9 +2722,18 @@ public class MessagesController implements NotificationCenter.NotificationCenter
TLRPC.User user = getUser(updates.user_id);
TLRPC.User user2 = null;
if (user == null) {
user = MessagesStorage.getInstance().getUserSync(updates.user_id);
putUser(user, true);
}
boolean needFwdUser = false;
if (updates.fwd_from_id != 0) {
user2 = getUser(updates.fwd_from_id);
if (user2 == null) {
user2 = MessagesStorage.getInstance().getUserSync(updates.fwd_from_id);
putUser(user2, true);
}
needFwdUser = true;
}
@ -2870,7 +2741,12 @@ public class MessagesController implements NotificationCenter.NotificationCenter
if (updates instanceof TLRPC.TL_updateShortMessage) {
missingData = user == null || needFwdUser && user2 == null;
} else {
missingData = getChat(updates.chat_id) == null || user == null || needFwdUser && user2 == null;
TLRPC.Chat chat = getChat(updates.chat_id);
if (chat == null) {
chat = MessagesStorage.getInstance().getChatSync(updates.chat_id);
putChat(chat, true);
}
missingData = chat == null || user == null || needFwdUser && user2 == null;
}
if (user != null && user.status != null && user.status.expires <= 0) {
onlinePrivacy.put(user.id, ConnectionsManager.getInstance().getCurrentTime());
@ -3036,7 +2912,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
if (processUpdate) {
processUpdateArray(updates.updates, updates.users, updates.chats);
if (updates.date != 0) {
MessagesStorage.lastDateValue = updates.date;
}
if (updates.seq != 0) {
MessagesStorage.lastSeqValue = updates.seq;
}
@ -3113,6 +2991,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
long currentTime = System.currentTimeMillis();
final HashMap<Long, ArrayList<MessageObject>> messages = new HashMap<>();
final HashMap<Long, TLRPC.WebPage> webPages = new HashMap<>();
final ArrayList<MessageObject> pushMessages = new ArrayList<>();
final ArrayList<TLRPC.Message> messagesArr = new ArrayList<>();
final HashMap<Integer, Integer> markAsReadMessagesInbox = new HashMap<>();
@ -3305,6 +3184,12 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else if (update instanceof TLRPC.TL_updateActivation) {
//DEPRECATED
} else if (update instanceof TLRPC.TL_updateNewAuthorization) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.newSessionReceived);
}
});
TLRPC.TL_messageService newMessage = new TLRPC.TL_messageService();
newMessage.action = new TLRPC.TL_messageActionLoginUnknownLocation();
newMessage.action.title = update.device;
@ -3438,6 +3323,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
pushMessages.add(obj);
} else if (update instanceof TLRPC.TL_updatePrivacy) {
updatesOnMainThread.add(update);
} else if (update instanceof TLRPC.TL_updateWebPage) {
webPages.put(update.webpage.id, update.webpage);
}
}
if (!messages.isEmpty()) {
@ -3612,6 +3499,10 @@ public class MessagesController implements NotificationCenter.NotificationCenter
MessagesStorage.getInstance().updateUsers(dbUsers, false, true, true);
}
if (!webPages.isEmpty()) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didReceivedWebpagesInUpdates, webPages);
}
if (!messages.isEmpty()) {
for (HashMap.Entry<Long, ArrayList<MessageObject>> entry : messages.entrySet()) {
Long key = entry.getKey();
@ -3701,6 +3592,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
});
if (!webPages.isEmpty()) {
MessagesStorage.getInstance().putWebPages(webPages);
}
if (!markAsReadMessagesInbox.isEmpty() || !markAsReadMessagesOutbox.isEmpty() || !markAsReadEncrypted.isEmpty()) {
if (!markAsReadMessagesInbox.isEmpty() || !markAsReadMessagesOutbox.isEmpty()) {
MessagesStorage.getInstance().updateDialogsWithReadedMessages(markAsReadMessagesInbox, true);

View File

@ -123,6 +123,7 @@ public class MessagesStorage {
database.executeFast("CREATE TABLE web_recent_v3(id TEXT, type INTEGER, image_url TEXT, thumb_url TEXT, local_url TEXT, width INTEGER, height INTEGER, size INTEGER, date INTEGER, PRIMARY KEY (id, type));").stepThis().dispose();
database.executeFast("CREATE TABLE stickers(id INTEGER PRIMARY KEY, data BLOB, date INTEGER);").stepThis().dispose();
database.executeFast("CREATE TABLE hashtag_recent_v2(id TEXT PRIMARY KEY, date INTEGER);").stepThis().dispose();
database.executeFast("CREATE TABLE webpage_pending(id INTEGER, mid INTEGER, PRIMARY KEY (id, mid));").stepThis().dispose();
database.executeFast("CREATE TABLE user_contacts_v6(uid INTEGER PRIMARY KEY, fname TEXT, sname TEXT)").stepThis().dispose();
database.executeFast("CREATE TABLE user_phones_v6(uid INTEGER, phone TEXT, sphone TEXT, deleted INTEGER, PRIMARY KEY (uid, phone))").stepThis().dispose();
@ -163,7 +164,7 @@ public class MessagesStorage {
database.executeFast("CREATE TABLE keyvalue(id TEXT PRIMARY KEY, value TEXT)").stepThis().dispose();
//version
database.executeFast("PRAGMA user_version = 15").stepThis().dispose();
database.executeFast("PRAGMA user_version = 16").stepThis().dispose();
} else {
try {
SQLiteCursor cursor = database.queryFinalized("SELECT seq, pts, date, qts, lsv, sg, pbytes FROM params WHERE id = 1");
@ -194,7 +195,7 @@ public class MessagesStorage {
}
}
int version = database.executeInt("PRAGMA user_version");
if (version < 15) {
if (version < 16) {
updateDbToLastVersion(version);
}
}
@ -379,6 +380,11 @@ public class MessagesStorage {
database.executeFast("PRAGMA user_version = 15").stepThis().dispose();
version = 15;
}
if (version == 15 && version < 16) {
database.executeFast("CREATE TABLE IF NOT EXISTS webpage_pending(id INTEGER, mid INTEGER, PRIMARY KEY (id, mid));").stepThis().dispose();
database.executeFast("PRAGMA user_version = 16").stepThis().dispose();
version = 16;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@ -2660,6 +2666,79 @@ public class MessagesStorage {
return -1;
}
public void putWebPages(final HashMap<Long, TLRPC.WebPage> webPages) {
if (webPages == null || webPages.isEmpty()) {
return;
}
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
String ids = TextUtils.join(",", webPages.keySet());
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT mid FROM webpage_pending WHERE id IN (%s)", ids));
ArrayList<Integer> mids = new ArrayList<>();
while (cursor.next()) {
mids.add(cursor.intValue(0));
}
cursor.dispose();
if (mids.isEmpty()) {
return;
}
final ArrayList<TLRPC.Message> messages = new ArrayList<>();
cursor = database.queryFinalized(String.format(Locale.US, "SELECT mid, data FROM messages WHERE mid IN (%s)", TextUtils.join(",", mids)));
while (cursor.next()) {
int mid = cursor.intValue(0);
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(1));
if (data != null && cursor.byteBufferValue(1, data.buffer) != 0) {
TLRPC.Message message = (TLRPC.Message)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
message.id = mid;
message.media.webpage = webPages.get(message.media.webpage.id);
messages.add(message);
}
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
database.executeFast(String.format(Locale.US, "DELETE FROM webpage_pending WHERE id IN (%s)", ids)).stepThis().dispose();
if (messages.isEmpty()) {
return;
}
database.beginTransaction();
SQLitePreparedStatement state = database.executeFast("UPDATE messages SET data = ? WHERE mid = ?");
for (TLRPC.Message message : messages) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(message.getObjectSize());
message.serializeToStream(data);
state.requery();
state.bindByteBuffer(1, data.buffer);
state.bindInteger(2, message.id);
state.step();
buffersStorage.reuseFreeBuffer(data);
}
state.dispose();
database.commitTransaction();
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didReceivedWebpages, messages);
}
});
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
}
private void putMessagesInternal(final ArrayList<TLRPC.Message> messages, final boolean withTransaction, final boolean isBroadcast, final int downloadMask) {
try {
if (withTransaction) {
@ -2677,6 +2756,7 @@ public class MessagesStorage {
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO media_v2 VALUES(?, ?, ?, ?, ?)");
SQLitePreparedStatement state3 = database.executeFast("REPLACE INTO randoms VALUES(?, ?)");
SQLitePreparedStatement state4 = database.executeFast("REPLACE INTO download_queue VALUES(?, ?, ?, ?)");
SQLitePreparedStatement state5 = database.executeFast("REPLACE INTO webpage_pending VALUES(?, ?)");
for (TLRPC.Message message : messages) {
long dialog_id = message.dialog_id;
@ -2810,15 +2890,23 @@ public class MessagesStorage {
state2.bindByteBuffer(5, data.buffer);
state2.step();
}
if (message.media instanceof TLRPC.TL_messageMediaWebPage && message.media.webpage instanceof TLRPC.TL_webPagePending) {
state5.requery();
state5.bindLong(1, message.media.webpage.id);
state5.bindInteger(2, message.id);
state5.step();
}
buffersStorage.reuseFreeBuffer(data);
if (downloadMask != 0) {
if (message.date >= ConnectionsManager.getInstance().getCurrentTime() - 60 * 60 * 24 && downloadMask != 0) {
if (message.media instanceof TLRPC.TL_messageMediaAudio || message.media instanceof TLRPC.TL_messageMediaPhoto || message.media instanceof TLRPC.TL_messageMediaVideo || message.media instanceof TLRPC.TL_messageMediaDocument) {
int type = 0;
long id = 0;
TLObject object = null;
if (message.media instanceof TLRPC.TL_messageMediaAudio) {
if ((downloadMask & MediaController.AUTODOWNLOAD_MASK_AUDIO) != 0) {
if ((downloadMask & MediaController.AUTODOWNLOAD_MASK_AUDIO) != 0 && message.media.audio.size < 1024 * 1024 * 5) {
id = message.media.audio.id;
type = MediaController.AUTODOWNLOAD_MASK_AUDIO;
object = message.media.audio;
@ -2864,6 +2952,7 @@ public class MessagesStorage {
state2.dispose();
state3.dispose();
state4.dispose();
state5.dispose();
state = database.executeFast("REPLACE INTO dialogs(did, date, unread_count, last_mid) VALUES(?, ?, ?, ?)");
for (HashMap.Entry<Long, TLRPC.Message> pair : messagesMap.entrySet()) {
@ -3543,11 +3632,19 @@ public class MessagesStorage {
}
private void fixUnsupportedMedia(TLRPC.Message message) {
if (message != null && message.media instanceof TLRPC.TL_messageMediaUnsupported && message.media.bytes != null) {
if (message == null) {
return;
}
boolean ok = false;
if (message.media instanceof TLRPC.TL_messageMediaUnsupported_old) {
if (message.media.bytes.length == 0) {
message.media.bytes = new byte[1];
message.media.bytes[0] = TLRPC.LAYER;
}
} else if (message.media instanceof TLRPC.TL_messageMediaUnsupported) {
message.media = new TLRPC.TL_messageMediaUnsupported_old();
message.media.bytes = new byte[1];
message.media.bytes[0] = TLRPC.LAYER;
}
}
@ -3802,6 +3899,42 @@ public class MessagesStorage {
});
}
public TLRPC.User getUserSync(final int user_id) {
final Semaphore semaphore = new Semaphore(0);
final TLRPC.User[] user = new TLRPC.User[1];
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
user[0] = getUser(user_id);
semaphore.release();
}
});
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return user[0];
}
public TLRPC.Chat getChatSync(final int user_id) {
final Semaphore semaphore = new Semaphore(0);
final TLRPC.Chat[] chat = new TLRPC.Chat[1];
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
chat[0] = getChat(user_id);
semaphore.release();
}
});
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return chat[0];
}
public TLRPC.User getUser(final int user_id) {
TLRPC.User user = null;
try {

View File

@ -23,7 +23,7 @@ import java.util.zip.ZipFile;
public class NativeLoader {
private final static int LIB_VERSION = 6;
private final static int LIB_VERSION = 7;
private final static String LIB_NAME = "tmessages." + LIB_VERSION;
private final static String LIB_SO_NAME = "lib" + LIB_NAME + ".so";
private final static String LOCALE_LIB_SO_NAME = "lib" + LIB_NAME + "loc.so";

View File

@ -49,9 +49,13 @@ public class NotificationCenter {
public static final int recentImagesDidLoaded = totalEvents++;
public static final int replaceMessagesObjects = totalEvents++;
public static final int didSetPasscode = totalEvents++;
public static final int didSetTwoStepPassword = totalEvents++;
public static final int screenStateChanged = totalEvents++;
public static final int appSwitchedToForeground = totalEvents++;
public static final int didLoadedReplyMessages = totalEvents++;
public static final int newSessionReceived = totalEvents++;
public static final int didReceivedWebpages = totalEvents++;
public static final int didReceivedWebpagesInUpdates = totalEvents++;
public static final int httpFileDidLoaded = totalEvents++;
public static final int httpFileDidFailedLoad = totalEvents++;
@ -64,7 +68,6 @@ public class NotificationCenter {
public static final int didReceiveSmsCode = totalEvents++;
public static final int emojiDidLoaded = totalEvents++;
public static final int appDidLogout = totalEvents++;
public static final int needPasswordEnter = totalEvents++;
public static final int FileDidUpload = totalEvents++;
public static final int FileDidFailUpload = totalEvents++;

View File

@ -71,7 +71,7 @@ public class NotificationsController {
private long lastSoundPlay;
private MediaPlayer mediaPlayerIn;
private MediaPlayer mediaPlayerOut;
private AudioManager audioManager;
protected AudioManager audioManager;
private static volatile NotificationsController Instance = null;
public static NotificationsController getInstance() {
@ -171,7 +171,7 @@ public class NotificationsController {
msg = LocaleController.formatString("NotificationUnrecognizedDevice", R.string.NotificationUnrecognizedDevice, UserConfig.getCurrentUser().first_name, date, messageObject.messageOwner.action.title, messageObject.messageOwner.action.address);
}
} else {
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty) {
if (messageObject.isMediaEmpty()) {
if (!shortMessage) {
if (messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, ContactsController.formatName(user.first_name, user.last_name), messageObject.messageOwner.message);
@ -236,7 +236,7 @@ public class NotificationsController {
msg = messageObject.messageText.toString();
}
} else {
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty) {
if (messageObject.isMediaEmpty()) {
if (!shortMessage && messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) {
msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, ContactsController.formatName(user.first_name, user.last_name), chat.title, messageObject.messageOwner.message);
} else {
@ -868,7 +868,7 @@ public class NotificationsController {
AssetFileDescriptor assetFileDescriptor = ApplicationLoader.applicationContext.getResources().openRawResourceFd(R.raw.sound_in);
if (assetFileDescriptor != null) {
mediaPlayerIn = new MediaPlayer();
mediaPlayerIn.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
mediaPlayerIn.setAudioStreamType(AudioManager.STREAM_SYSTEM);
mediaPlayerIn.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
mediaPlayerIn.setLooping(false);
assetFileDescriptor.close();
@ -938,7 +938,7 @@ public class NotificationsController {
AssetFileDescriptor assetFileDescriptor = ApplicationLoader.applicationContext.getResources().openRawResourceFd(R.raw.sound_out);
if (assetFileDescriptor != null) {
mediaPlayerOut = new MediaPlayer();
mediaPlayerOut.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
mediaPlayerOut.setAudioStreamType(AudioManager.STREAM_SYSTEM);
mediaPlayerOut.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
mediaPlayerOut.setLooping(false);
assetFileDescriptor.close();

View File

@ -119,7 +119,7 @@ public class SecretChatHelper {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
reqSend.random_bytes = new byte[15];
Utilities.random.nextBytes(reqSend.random_bytes);
}
@ -224,7 +224,7 @@ public class SecretChatHelper {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
reqSend.random_bytes = new byte[15];
Utilities.random.nextBytes(reqSend.random_bytes);
}
@ -252,7 +252,7 @@ public class SecretChatHelper {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
reqSend.random_bytes = new byte[15];
Utilities.random.nextBytes(reqSend.random_bytes);
}
@ -283,7 +283,7 @@ public class SecretChatHelper {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
reqSend.random_bytes = new byte[15];
Utilities.random.nextBytes(reqSend.random_bytes);
}
@ -312,7 +312,7 @@ public class SecretChatHelper {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
reqSend.random_bytes = new byte[15];
Utilities.random.nextBytes(reqSend.random_bytes);
}
@ -343,7 +343,7 @@ public class SecretChatHelper {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
reqSend.random_bytes = new byte[15];
Utilities.random.nextBytes(reqSend.random_bytes);
}
@ -375,7 +375,7 @@ public class SecretChatHelper {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
reqSend.random_bytes = new byte[15];
Utilities.random.nextBytes(reqSend.random_bytes);
}
@ -406,7 +406,7 @@ public class SecretChatHelper {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
reqSend.random_bytes = new byte[15];
Utilities.random.nextBytes(reqSend.random_bytes);
}
@ -436,7 +436,7 @@ public class SecretChatHelper {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
reqSend.random_bytes = new byte[15];
Utilities.random.nextBytes(reqSend.random_bytes);
}
@ -464,7 +464,7 @@ public class SecretChatHelper {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
reqSend.random_bytes = new byte[15];
Utilities.random.nextBytes(reqSend.random_bytes);
}
@ -500,7 +500,7 @@ public class SecretChatHelper {
reqSend = new TLRPC.TL_decryptedMessageService();
} else {
reqSend = new TLRPC.TL_decryptedMessageService_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
reqSend.random_bytes = new byte[15];
Utilities.random.nextBytes(reqSend.random_bytes);
}
@ -659,7 +659,7 @@ public class SecretChatHelper {
int myLayer = Math.max(17, AndroidUtilities.getMyLayerVersion(chat.layer));
layer.layer = Math.min(myLayer, AndroidUtilities.getPeerLayerVersion(chat.layer));
layer.message = req;
layer.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
layer.random_bytes = new byte[15];
Utilities.random.nextBytes(layer.random_bytes);
toEncryptObject = layer;
@ -795,7 +795,7 @@ public class SecretChatHelper {
@Override
public void run() {
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, newMsgObj.id, newMsgObj.id, newMsgObj);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, newMsgObj.id, newMsgObj.id, newMsgObj, false);
SendMessagesHelper.getInstance().processSentMessage(newMsgObj.id);
if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) {
SendMessagesHelper.getInstance().stopVideoService(attachPath);
@ -1104,10 +1104,7 @@ public class SecretChatHelper {
}
byte[] salt = new byte[256];
for (int a = 0; a < 256; a++) {
salt[a] = (byte) (Utilities.random.nextDouble() * 256);
}
Utilities.random.nextBytes(salt);
BigInteger p = new BigInteger(1, MessagesStorage.secretPBytes);
BigInteger g_b = BigInteger.valueOf(MessagesStorage.secretG);
g_b = g_b.modPow(new BigInteger(1, salt), p);
@ -1409,9 +1406,7 @@ public class SecretChatHelper {
return;
}
final byte[] salt = new byte[256];
for (int a = 0; a < 256; a++) {
salt[a] = (byte) (Utilities.random.nextDouble() * 256);
}
Utilities.random.nextBytes(salt);
BigInteger i_g_a = BigInteger.valueOf(MessagesStorage.secretG);
i_g_a = i_g_a.modPow(new BigInteger(1, salt), new BigInteger(1, MessagesStorage.secretPBytes));

View File

@ -447,7 +447,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
if (messageObject == null) {
return;
}
if (messageObject.messageOwner.media != null && !(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
if (messageObject.messageOwner.media != null && !(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty) && !(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage)) {
if (messageObject.messageOwner.media.photo instanceof TLRPC.TL_photo) {
sendMessage((TLRPC.TL_photo) messageObject.messageOwner.media.photo, null, null, did, messageObject.replyMessageObject);
} else if (messageObject.messageOwner.media.audio instanceof TLRPC.TL_audio) {
@ -471,14 +471,18 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
sendMessage(messageObject, did);
}
} else if (messageObject.messageOwner.message != null) {
sendMessage(messageObject.messageOwner.message, did, messageObject.replyMessageObject);
TLRPC.WebPage webPage = null;
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
webPage = messageObject.messageOwner.media.webpage;
}
sendMessage(messageObject.messageOwner.message, did, messageObject.replyMessageObject, webPage, true);
} else {
sendMessage(messageObject, did);
}
}
public void sendMessage(TLRPC.User user, long peer, MessageObject reply_to_msg) {
sendMessage(null, null, null, null, null, null, user, null, null, null, peer, false, null, reply_to_msg);
sendMessage(null, null, null, null, null, null, user, null, null, null, peer, false, null, reply_to_msg, null, true);
}
public void sendMessage(ArrayList<MessageObject> messages, long peer) {
@ -567,26 +571,32 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
req.id = ids;
final ArrayList<TLRPC.Message> newMsgObjArr = arr;
final HashMap<Long, TLRPC.Message> messagesByRandomIdsFinal = messagesByRandomIds;
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
final TLRPC.messages_StatedMessages res = (TLRPC.messages_StatedMessages) response;
if (newMsgObjArr.size() != res.messages.size()) {
MessagesController.getInstance().getDifference();
return;
HashMap<Integer, Long> newMessagesByIds = new HashMap<>();
TLRPC.Updates updates = (TLRPC.Updates) response;
for (int a = 0; a < updates.updates.size(); a++) {
TLRPC.Update update = updates.updates.get(a);
if (update instanceof TLRPC.TL_updateMessageID) {
newMessagesByIds.put(update.id, update.random_id);
updates.updates.remove(a);
a--;
}
if (res instanceof TLRPC.TL_messages_statedMessages) {
MessagesController.getInstance().processNewDifferenceParams(-1, res.pts, -1, res.pts_count);
} else if (res instanceof TLRPC.TL_messages_statedMessagesLinks) {
MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, -1, res.pts_count);
}
for (int a = 0; a < res.messages.size(); a++) {
TLRPC.Message message = res.messages.get(a);
final TLRPC.Message newMsgObj = newMsgObjArr.get(a);
for (TLRPC.Update update : updates.updates) {
if (update instanceof TLRPC.TL_updateNewMessage) {
MessagesController.getInstance().processNewDifferenceParams(-1, update.pts, -1, update.pts_count);
TLRPC.Message message = ((TLRPC.TL_updateNewMessage) update).message;
Long random_id = newMessagesByIds.get(message.id);
if (random_id != null) {
final TLRPC.Message newMsgObj = messagesByRandomIdsFinal.get(random_id);
if (newMsgObj == null) {
continue;
}
newMsgObjArr.remove(newMsgObj);
final int oldId = newMsgObj.id;
final ArrayList<TLRPC.Message> sentMessages = new ArrayList<>();
sentMessages.add(message);
@ -601,7 +611,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
@Override
public void run() {
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, newMsgObj.id, newMsgObj);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, newMsgObj.id, newMsgObj, false);
processSentMessage(oldId);
removeFromSendingMessages(oldId);
}
@ -612,7 +622,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
});
}
} else {
}
}
}
for (final TLRPC.Message newMsgObj : newMsgObjArr) {
MessagesStorage.getInstance().markMessageAsSendError(newMsgObj.id);
AndroidUtilities.runOnUIThread(new Runnable() {
@ -629,7 +641,6 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
});
}
}
}
}, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassCanCompress, ConnectionsManager.DEFAULT_DATACENTER_ID);
if (a != messages.size() - 1) {
@ -644,38 +655,38 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
public void sendMessage(MessageObject message) {
sendMessage(null, null, null, null, null, message, null, null, null, null, message.getDialogId(), true, message.messageOwner.attachPath, null);
sendMessage(null, null, null, null, null, message, null, null, null, null, message.getDialogId(), true, message.messageOwner.attachPath, null, null, true);
}
public void sendMessage(MessageObject message, long peer) {
sendMessage(null, null, null, null, null, message, null, null, null, null, peer, false, message.messageOwner.attachPath, null);
sendMessage(null, null, null, null, null, message, null, null, null, null, peer, false, message.messageOwner.attachPath, null, null, true);
}
public void sendMessage(TLRPC.TL_document document, String originalPath, String path, long peer, MessageObject reply_to_msg) {
sendMessage(null, null, null, null, null, null, null, document, null, originalPath, peer, false, path, reply_to_msg);
sendMessage(null, null, null, null, null, null, null, document, null, originalPath, peer, false, path, reply_to_msg, null, true);
}
public void sendMessage(String message, long peer, MessageObject reply_to_msg) {
sendMessage(message, null, null, null, null, null, null, null, null, null, peer, false, null, reply_to_msg);
public void sendMessage(String message, long peer, MessageObject reply_to_msg, TLRPC.WebPage webPage, boolean searchLinks) {
sendMessage(message, null, null, null, null, null, null, null, null, null, peer, false, null, reply_to_msg, webPage, searchLinks);
}
public void sendMessage(double lat, double lon, long peer, MessageObject reply_to_msg) {
sendMessage(null, lat, lon, null, null, null, null, null, null, null, peer, false, null, reply_to_msg);
sendMessage(null, lat, lon, null, null, null, null, null, null, null, peer, false, null, reply_to_msg, null, true);
}
public void sendMessage(TLRPC.TL_photo photo, String originalPath, String path, long peer, MessageObject reply_to_msg) {
sendMessage(null, null, null, photo, null, null, null, null, null, originalPath, peer, false, path, reply_to_msg);
sendMessage(null, null, null, photo, null, null, null, null, null, originalPath, peer, false, path, reply_to_msg, null, true);
}
public void sendMessage(TLRPC.TL_video video, String originalPath, String path, long peer, MessageObject reply_to_msg) {
sendMessage(null, null, null, null, video, null, null, null, null, originalPath, peer, false, path, reply_to_msg);
sendMessage(null, null, null, null, video, null, null, null, null, originalPath, peer, false, path, reply_to_msg, null, true);
}
public void sendMessage(TLRPC.TL_audio audio, String path, long peer, MessageObject reply_to_msg) {
sendMessage(null, null, null, null, null, null, null, null, audio, null, peer, false, path, reply_to_msg);
sendMessage(null, null, null, null, null, null, null, null, audio, null, peer, false, path, reply_to_msg, null, true);
}
private void sendMessage(String message, Double lat, Double lon, TLRPC.TL_photo photo, TLRPC.TL_video video, MessageObject msgObj, TLRPC.User user, TLRPC.TL_document document, TLRPC.TL_audio audio, String originalPath, long peer, boolean retry, String path, MessageObject reply_to_msg) {
private void sendMessage(String message, Double lat, Double lon, TLRPC.TL_photo photo, TLRPC.TL_video video, MessageObject msgObj, TLRPC.User user, TLRPC.TL_document document, TLRPC.TL_audio audio, String originalPath, long peer, boolean retry, String path, MessageObject reply_to_msg, TLRPC.WebPage webPage, boolean searchLinks) {
if (peer == 0) {
return;
}
@ -741,7 +752,12 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
} else {
newMsg = new TLRPC.TL_message();
}
if (encryptedChat != null || webPage == null) {
newMsg.media = new TLRPC.TL_messageMediaEmpty();
} else {
newMsg.media = new TLRPC.TL_messageMediaWebPage();
newMsg.media.webpage = webPage;
}
type = 0;
newMsg.message = message;
} else if (lat != null && lon != null) {
@ -860,6 +876,8 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
if (lower_id != 0) {
if (high_id == 1) {
if (currentChatInfo == null) {
MessagesStorage.getInstance().markMessageAsSendError(newMsg.id);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageSendError, newMsg.id);
processSentMessage(newMsg.id);
return;
}
@ -932,9 +950,14 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
if (encryptedChat == null) {
if (sendToPeers != null) {
TLRPC.TL_messages_sendBroadcast reqSend = new TLRPC.TL_messages_sendBroadcast();
ArrayList<Long> random_ids = new ArrayList<>();
for (int a = 0; a < sendToPeers.size(); a++) {
random_ids.add(Utilities.random.nextLong());
}
reqSend.message = message;
reqSend.contacts = sendToPeers;
reqSend.media = new TLRPC.TL_inputMediaEmpty();
reqSend.random_id = random_ids;
performSendMessageRequest(reqSend, newMsgObj.messageOwner, null);
} else {
TLRPC.TL_messages_sendMessage reqSend = new TLRPC.TL_messages_sendMessage();
@ -942,8 +965,12 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
reqSend.peer = sendToPeer;
reqSend.random_id = newMsg.random_id;
if (reply_to_msg != null) {
reqSend.flags |= 1;
reqSend.reply_to_msg_id = reply_to_msg.getId();
}
if (!searchLinks) {
reqSend.flags |= 2;
}
performSendMessageRequest(reqSend, newMsgObj.messageOwner, null);
}
} else {
@ -953,7 +980,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
reqSend.ttl = newMsg.ttl;
} else {
reqSend = new TLRPC.TL_decryptedMessage_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
reqSend.random_bytes = new byte[15];
Utilities.random.nextBytes(reqSend.random_bytes);
}
reqSend.random_id = newMsg.random_id;
@ -1065,8 +1092,13 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
if (sendToPeers != null) {
TLRPC.TL_messages_sendBroadcast request = new TLRPC.TL_messages_sendBroadcast();
ArrayList<Long> random_ids = new ArrayList<>();
for (int a = 0; a < sendToPeers.size(); a++) {
random_ids.add(Utilities.random.nextLong());
}
request.contacts = sendToPeers;
request.media = inputMedia;
request.random_id = random_ids;
request.message = "";
if (delayedMessage != null) {
delayedMessage.sendRequest = request;
@ -1078,6 +1110,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
request.random_id = newMsg.random_id;
request.media = inputMedia;
if (reply_to_msg != null) {
request.flags |= 1;
request.reply_to_msg_id = reply_to_msg.getId();
}
if (delayedMessage != null) {
@ -1121,7 +1154,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
reqSend.ttl = newMsg.ttl;
} else {
reqSend = new TLRPC.TL_decryptedMessage_old();
reqSend.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
reqSend.random_bytes = new byte[15];
Utilities.random.nextBytes(reqSend.random_bytes);
}
reqSend.random_id = newMsg.random_id;
@ -1424,47 +1457,43 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
boolean isSentError = false;
if (error == null) {
final int oldId = newMsgObj.id;
final boolean isBroadcast = req instanceof TLRPC.TL_messages_sendBroadcast;
final ArrayList<TLRPC.Message> sentMessages = new ArrayList<>();
final String attachPath = newMsgObj.attachPath;
final boolean mediaUpdated = response instanceof TLRPC.messages_SentMessage && !(((TLRPC.messages_SentMessage) response).media instanceof TLRPC.TL_messageMediaEmpty);
if (response instanceof TLRPC.messages_SentMessage) {
TLRPC.messages_SentMessage res = (TLRPC.messages_SentMessage) response;
newMsgObj.id = res.id;
newMsgObj.local_id = newMsgObj.id = res.id;
newMsgObj.date = res.date;
newMsgObj.media = res.media;
if (res instanceof TLRPC.TL_messages_sentMessage) {
MessagesController.getInstance().processNewDifferenceParams(-1, res.pts, res.date, res.pts_count);
} else if (res instanceof TLRPC.TL_messages_sentMessageLink) {
MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, res.date, res.pts_count);
}
} else if (response instanceof TLRPC.messages_StatedMessage) {
TLRPC.messages_StatedMessage res = (TLRPC.messages_StatedMessage) response;
sentMessages.add(res.message);
newMsgObj.id = res.message.id;
processSentMessage(newMsgObj, res.message, originalPath);
if (res instanceof TLRPC.TL_messages_statedMessage) {
MessagesController.getInstance().processNewDifferenceParams(-1, res.pts, res.message.date, res.pts_count);
} else if (res instanceof TLRPC.TL_messages_statedMessageLink) {
MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, res.message.date, res.pts_count);
}
} else if (response instanceof TLRPC.messages_StatedMessages) {
TLRPC.messages_StatedMessages res = (TLRPC.messages_StatedMessages) response;
if (!res.messages.isEmpty()) {
sentMessages.addAll(res.messages);
TLRPC.Message message = res.messages.get(0);
if (!isBroadcast) {
newMsgObj.id = message.id;
}
processSentMessage(newMsgObj, message, originalPath);
}
if (res instanceof TLRPC.TL_messages_statedMessages) {
MessagesController.getInstance().processNewDifferenceParams(-1, res.pts, -1, res.pts_count);
} else if (res instanceof TLRPC.TL_messages_statedMessagesLinks) {
MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, -1, res.pts_count);
sentMessages.add(newMsgObj);
} else if (response instanceof TLRPC.Updates) {
TLRPC.TL_updateNewMessage newMessage = null;
for (TLRPC.Update update : ((TLRPC.Updates) response).updates) {
if (update instanceof TLRPC.TL_updateNewMessage) {
newMessage = (TLRPC.TL_updateNewMessage) update;
break;
}
}
if (newMessage != null) {
sentMessages.add(newMessage.message);
newMsgObj.id = newMessage.message.id;
processSentMessage(newMsgObj, newMessage.message, originalPath);
MessagesController.getInstance().processNewDifferenceParams(-1, newMessage.pts, -1, newMessage.pts_count);
} else {
isSentError = true;
}
}
if (!isSentError) {
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
@ -1489,7 +1518,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, (isBroadcast ? oldId : newMsgObj.id), newMsgObj);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, (isBroadcast ? oldId : newMsgObj.id), newMsgObj, mediaUpdated);
processSentMessage(oldId);
removeFromSendingMessages(oldId);
}
@ -1499,7 +1528,11 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
}
});
}
} else {
isSentError = true;
}
if (isSentError) {
MessagesStorage.getInstance().markMessageAsSendError(newMsgObj.id);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override

View File

@ -31,7 +31,7 @@ public class WearReplyReceiver extends BroadcastReceiver {
if (dialog_id == 0 || max_id == 0) {
return;
}
SendMessagesHelper.getInstance().sendMessage(text.toString(), dialog_id, null);
SendMessagesHelper.getInstance().sendMessage(text.toString(), dialog_id, null, null, true);
MessagesController.getInstance().markDialogAsRead(dialog_id, max_id, max_id, 0, 0, true, false);
}
}

View File

@ -1037,11 +1037,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
for (int i = 0; i < runningRequests.size(); i++) {
RPCRequest request = runningRequests.get(i);
if (UserConfig.waitingForPasswordEnter && (request.flags & RPCRequest.RPCRequestClassWithoutLogin) == 0) {
FileLog.e("tmessages", "skip request " + request.rawRequest + ", need password enter");
continue;
}
int datacenterId = request.runningDatacenterId;
if (datacenterId == DEFAULT_DATACENTER_ID) {
if (movingToDatacenterId != DEFAULT_DATACENTER_ID) {
@ -1244,11 +1239,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
continue;
}
if (UserConfig.waitingForPasswordEnter && (request.flags & RPCRequest.RPCRequestClassWithoutLogin) == 0) {
FileLog.e("tmessages", "skip request " + request.rawRequest + ", need password enter");
continue;
}
int datacenterId = request.runningDatacenterId;
if (datacenterId == DEFAULT_DATACENTER_ID) {
if (movingToDatacenterId != DEFAULT_DATACENTER_ID && (request.flags & RPCRequest.RPCRequestClassEnableUnauthorized) == 0) {
@ -2183,10 +2173,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
});
}
if (request.rawRequest instanceof TLRPC.TL_auth_checkPassword) {
UserConfig.setWaitingForPasswordEnter(false);
UserConfig.saveConfig(false);
}
request.completionBlock.run(resultContainer.result, null);
}
}
@ -2194,7 +2180,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (implicitError != null && implicitError.code == 401) {
isError = true;
if (implicitError.text != null && implicitError.text.contains("SESSION_PASSWORD_NEEDED")) {
UserConfig.setWaitingForPasswordEnter(true);
/*UserConfig.setWaitingForPasswordEnter(true); TODO
UserConfig.saveConfig(false);
if (UserConfig.isClientActivated()) {
discardResponse = true;
@ -2204,7 +2190,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
NotificationCenter.getInstance().postNotificationName(NotificationCenter.needPasswordEnter);
}
});
}
}*/
} else if (datacenter.datacenterId == currentDatacenterId || datacenter.datacenterId == movingToDatacenterId) {
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0 && UserConfig.isClientActivated()) {
UserConfig.clearConfig();

View File

@ -63,7 +63,7 @@ public class RPCRequest {
boolean initRequest = false;
ArrayList<Long> respondsToMessageIds = new ArrayList<Long>();
ArrayList<Long> respondsToMessageIds = new ArrayList<>();
public void addRespondMessageId(long messageId) {
respondsToMessageIds.add(messageId);

View File

@ -124,8 +124,6 @@ public class TLClassStore {
classStore.put(TLRPC.TL_boolTrue.constructor, TLRPC.TL_boolTrue.class);
classStore.put(TLRPC.TL_boolFalse.constructor, TLRPC.TL_boolFalse.class);
classStore.put(TLRPC.TL_auth_exportedAuthorization.constructor, TLRPC.TL_auth_exportedAuthorization.class);
classStore.put(TLRPC.TL_messages_statedMessagesLinks.constructor, TLRPC.TL_messages_statedMessagesLinks.class);
classStore.put(TLRPC.TL_messages_statedMessages.constructor, TLRPC.TL_messages_statedMessages.class);
classStore.put(TLRPC.TL_inputNotifyChats.constructor, TLRPC.TL_inputNotifyChats.class);
classStore.put(TLRPC.TL_inputNotifyPeer.constructor, TLRPC.TL_inputNotifyPeer.class);
classStore.put(TLRPC.TL_inputNotifyUsers.constructor, TLRPC.TL_inputNotifyUsers.class);
@ -322,8 +320,6 @@ public class TLClassStore {
classStore.put(TLRPC.TL_contactFound.constructor, TLRPC.TL_contactFound.class);
classStore.put(TLRPC.TL_inputFileBig.constructor, TLRPC.TL_inputFileBig.class);
classStore.put(TLRPC.TL_inputFile.constructor, TLRPC.TL_inputFile.class);
classStore.put(TLRPC.TL_messages_statedMessageLink.constructor, TLRPC.TL_messages_statedMessageLink.class);
classStore.put(TLRPC.TL_messages_statedMessage.constructor, TLRPC.TL_messages_statedMessage.class);
classStore.put(TLRPC.TL_userFull.constructor, TLRPC.TL_userFull.class);
classStore.put(TLRPC.TL_updates_state.constructor, TLRPC.TL_updates_state.class);
classStore.put(TLRPC.TL_resPQ.constructor, TLRPC.TL_resPQ.class);
@ -377,6 +373,17 @@ public class TLClassStore {
classStore.put(TLRPC.TL_contactLinkHasPhone.constructor, TLRPC.TL_contactLinkHasPhone.class);
classStore.put(TLRPC.TL_contactLinkContact.constructor, TLRPC.TL_contactLinkContact.class);
classStore.put(TLRPC.TL_messages_affectedMessages.constructor, TLRPC.TL_messages_affectedMessages.class);
classStore.put(TLRPC.TL_updateWebPage.constructor, TLRPC.TL_updateWebPage.class);
classStore.put(TLRPC.TL_webPagePending.constructor, TLRPC.TL_webPagePending.class);
classStore.put(TLRPC.TL_webPageEmpty.constructor, TLRPC.TL_webPageEmpty.class);
classStore.put(TLRPC.TL_webPage.constructor, TLRPC.TL_webPage.class);
classStore.put(TLRPC.TL_messageMediaWebPage.constructor, TLRPC.TL_messageMediaWebPage.class);
classStore.put(TLRPC.TL_authorization.constructor, TLRPC.TL_authorization.class);
classStore.put(TLRPC.TL_account_authorizations.constructor, TLRPC.TL_account_authorizations.class);
classStore.put(TLRPC.TL_account_passwordSettings.constructor, TLRPC.TL_account_passwordSettings.class);
classStore.put(TLRPC.TL_account_passwordInputSettings.constructor, TLRPC.TL_account_passwordInputSettings.class);
classStore.put(TLRPC.TL_auth_passwordRecovery.constructor, TLRPC.TL_auth_passwordRecovery.class);
classStore.put(TLRPC.TL_messages_getWebPagePreview.constructor, TLRPC.TL_messages_getWebPagePreview.class);
classStore.put(TLRPC.TL_messageMediaUnsupported_old.constructor, TLRPC.TL_messageMediaUnsupported_old.class);
classStore.put(TLRPC.TL_userSelf_old2.constructor, TLRPC.TL_userSelf_old2.class);

File diff suppressed because it is too large Load Diff

View File

@ -30,7 +30,6 @@ public class UserConfig {
private final static Object sync = new Object();
public static boolean saveIncomingPhotos = false;
public static int contactsVersion = 1;
public static boolean waitingForPasswordEnter = false;
public static String passcodeHash = "";
public static boolean appLocked = false;
public static int passcodeType = 0;
@ -67,7 +66,6 @@ public class UserConfig {
editor.putInt("lastBroadcastId", lastBroadcastId);
editor.putBoolean("registeredForInternalPush", registeredForInternalPush);
editor.putBoolean("blockedUsersLoaded", blockedUsersLoaded);
editor.putBoolean("waitingForPasswordEnter", waitingForPasswordEnter);
editor.putString("passcodeHash1", passcodeHash);
editor.putBoolean("appLocked", appLocked);
editor.putInt("passcodeType", passcodeType);
@ -101,18 +99,6 @@ public class UserConfig {
}
}
public static boolean isWaitingForPasswordEnter() {
synchronized (sync) {
return waitingForPasswordEnter;
}
}
public static void setWaitingForPasswordEnter(boolean value) {
synchronized (sync) {
waitingForPasswordEnter = value;
}
}
public static int getClientUserId() {
synchronized (sync) {
return currentUser != null ? currentUser.id : 0;
@ -208,7 +194,6 @@ public class UserConfig {
lastBroadcastId = preferences.getInt("lastBroadcastId", -1);
registeredForInternalPush = preferences.getBoolean("registeredForInternalPush", false);
blockedUsersLoaded = preferences.getBoolean("blockedUsersLoaded", false);
waitingForPasswordEnter = preferences.getBoolean("waitingForPasswordEnter", false);
passcodeHash = preferences.getString("passcodeHash1", "");
appLocked = preferences.getBoolean("appLocked", false);
passcodeType = preferences.getInt("passcodeType", 0);
@ -231,7 +216,6 @@ public class UserConfig {
currentUser = null;
registeredForInternalPush = false;
registeredForPush = false;
waitingForPasswordEnter = false;
contactsHash = "";
importHash = "";
lastSendMessageId = -210000;

View File

@ -21,7 +21,6 @@ import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.util.Base64;
@ -29,6 +28,8 @@ import net.hockeyapp.android.CrashManager;
import net.hockeyapp.android.CrashManagerListener;
import net.hockeyapp.android.UpdateManager;
import org.telegram.android.AndroidUtilities;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@ -108,6 +109,7 @@ public class Utilities {
public native static long doPQNative(long _what);
public native static void loadBitmap(String path, Bitmap bitmap, int scale, int width, int height, int stride);
public native static int pinBitmap(Bitmap bitmap);
public native static void blurBitmap(Object bitmap, int radius);
public native static void calcCDT(ByteBuffer hsvBuffer, int width, int height, ByteBuffer buffer);
public native static Bitmap loadWebpImage(ByteBuffer buffer, int len, BitmapFactory.Options options);
@ -145,6 +147,9 @@ public class Utilities {
}
public static String bytesToHex(byte[] bytes) {
if (bytes == null) {
return "";
}
char[] hexChars = new char[bytes.length * 2];
int v;
for (int j = 0; j < bytes.length; j++) {
@ -156,6 +161,9 @@ public class Utilities {
}
public static byte[] hexToBytes(String hex) {
if (hex == null) {
return null;
}
int len = hex.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
@ -685,7 +693,7 @@ public class Utilities {
builder.append(" ");
}
query.trim();
builder.append(Html.fromHtml("<font color=\"#4d83b3\">" + query + "</font>"));
builder.append(AndroidUtilities.replaceTags("<c#ff4d83b3>" + query + "</c>"));
lastIndex = end;
}

View File

@ -1,629 +0,0 @@
/*
* This is the source code of Telegram for Android v. 2.0.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.
*/
package org.telegram.ui;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.ContactsController;
import org.telegram.android.LocaleController;
import org.telegram.android.MessagesController;
import org.telegram.android.MessagesStorage;
import org.telegram.android.NotificationCenter;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.Cells.HeaderCell;
import org.telegram.ui.Cells.TextFieldCell;
import org.telegram.ui.Cells.TextInfoPrivacyCell;
import org.telegram.ui.Cells.TextSettingsCell;
import java.util.ArrayList;
public class AccountPasswordActivity extends BaseFragment {
private ListAdapter listAdapter;
private TextFieldCell oldPasswordCell;
private TextFieldCell newPasswordCell;
private TextFieldCell verifyPasswordCell;
private TextFieldCell hintPasswordCell;
private View doneButton;
private ProgressDialog progressDialog;
private int type;
private boolean hasPassword;
private boolean loading;
private byte[] new_salt;
private String hint;
private byte[] current_salt;
private int changePasswordSectionRow;
private int oldPasswordRow;
private int newPasswordRow;
private int verifyPasswordRow;
private int hintRow;
private int passwordDetailRow;
private int deleteAccountSection;
private int deleteAccountRow;
private int deleteAccountDetailRow;
private int rowCount;
private final static int done_button = 1;
public AccountPasswordActivity(int type) {
super();
this.type = type;
}
@Override
public boolean onFragmentCreate() {
super.onFragmentCreate();
getCurrentPassword();
return true;
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
if (type == 0) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
}
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("Password", R.string.Password));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
doneWithPassword();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
doneButton.setVisibility(loading ? View.GONE : View.VISIBLE);
if (type == 0) {
oldPasswordCell = new TextFieldCell(getParentActivity());
oldPasswordCell.setFieldTitleAndHint(LocaleController.getString("OldPassword", R.string.OldPassword), LocaleController.getString("EnterOldPassword", R.string.EnterOldPassword), AndroidUtilities.dp(10), true);
oldPasswordCell.setBackgroundColor(0xffffffff);
newPasswordCell = new TextFieldCell(getParentActivity());
newPasswordCell.setFieldTitleAndHint(LocaleController.getString("NewPassword", R.string.NewPassword), LocaleController.getString("EnterNewPassword", R.string.EnterNewPassword), 0, true);
newPasswordCell.setBackgroundColor(0xffffffff);
verifyPasswordCell = new TextFieldCell(getParentActivity());
verifyPasswordCell.setFieldTitleAndHint(null, LocaleController.getString("VerifyNewPassword", R.string.VerifyNewPassword), AndroidUtilities.dp(10), true);
verifyPasswordCell.setBackgroundColor(0xffffffff);
hintPasswordCell = new TextFieldCell(getParentActivity());
hintPasswordCell.setFieldTitleAndHint(LocaleController.getString("PasswordHint", R.string.PasswordHint), LocaleController.getString("EnterHint", R.string.EnterHint), AndroidUtilities.dp(22), false);
hintPasswordCell.setBackgroundColor(0xffffffff);
if (hint != null) {
hintPasswordCell.setFieldText(hint);
}
} else if (type == 1) {
oldPasswordCell = new TextFieldCell(getParentActivity());
oldPasswordCell.setFieldTitleAndHint(null, LocaleController.getString("EnterYourPassword", R.string.EnterYourPassword), AndroidUtilities.dp(22), true);
oldPasswordCell.setBackgroundColor(0xffffffff);
}
listAdapter = new ListAdapter(getParentActivity());
fragmentView = new FrameLayout(getParentActivity());
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xfff0f0f0);
FrameLayout progressView = new FrameLayout(getParentActivity());
frameLayout.addView(progressView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
progressView.setLayoutParams(layoutParams);
ProgressBar progressBar = new ProgressBar(getParentActivity());
progressView.addView(progressBar);
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.CENTER;
progressView.setLayoutParams(layoutParams);
ListView listView = new ListView(getParentActivity());
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
listView.setDrawSelectorOnTop(true);
listView.setEmptyView(progressView);
frameLayout.addView(listView);
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP;
listView.setLayoutParams(layoutParams);
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
if (i == deleteAccountRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSureDeleteAccount", R.string.AreYouSureDeleteAccount));
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) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSureDeleteAccount2", R.string.AreYouSureDeleteAccount2));
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) {
TLRPC.TL_account_deleteAccount req = new TLRPC.TL_account_deleteAccount();
req.reason = "Forgot password";
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.clear().commit();
MessagesController.getInstance().unregistedPush();
MessagesController.getInstance().logOut();
UserConfig.clearConfig();
NotificationCenter.getInstance().postNotificationName(NotificationCenter.appDidLogout);
MessagesStorage.getInstance().cleanUp(false);
MessagesController.getInstance().cleanUp();
ContactsController.getInstance().deleteAllAppAccounts();
}
});
}
}
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassWithoutLogin);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
}
});
updateRows();
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
@Override
public void onResume() {
super.onResume();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
private void updateRows() {
rowCount = 0;
if (!loading) {
if (type == 0) {
changePasswordSectionRow = rowCount++;
oldPasswordRow = hasPassword ? rowCount++ : -1;
newPasswordRow = rowCount++;
verifyPasswordRow = rowCount++;
hintRow = rowCount++;
passwordDetailRow = rowCount++;
deleteAccountSection = -1;
deleteAccountRow = -1;
deleteAccountDetailRow = -1;
} else if (type == 1) {
changePasswordSectionRow = rowCount++;
oldPasswordRow = rowCount++;
passwordDetailRow = rowCount++;
deleteAccountSection = rowCount++;
deleteAccountDetailRow = rowCount++;
verifyPasswordRow = -1;
newPasswordRow = -1;
hintRow = -1;
deleteAccountRow = -1;
}
doneButton.setVisibility(View.VISIBLE);
}
listAdapter.notifyDataSetChanged();
}
private void ShowAlert(final String text) {
if (text == null || getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(text);
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showAlertDialog(builder);
}
private void needShowProgress() {
if (getParentActivity() == null || getParentActivity().isFinishing() || progressDialog != null) {
return;
}
progressDialog = new ProgressDialog(getParentActivity());
progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
progressDialog.show();
}
private void needHideProgress() {
if (progressDialog == null) {
return;
}
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
progressDialog = null;
}
private void getCurrentPassword() {
loading = true;
TLRPC.TL_account_getPassword req = new TLRPC.TL_account_getPassword();
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(final TLObject response, final TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
loading = false;
TLRPC.account_Password res = (TLRPC.account_Password) response;
if (res instanceof TLRPC.TL_account_noPassword) {
hasPassword = false;
new_salt = res.new_salt;
hint = null;
current_salt = null;
} else if (res instanceof TLRPC.TL_account_password) {
hasPassword = true;
new_salt = res.new_salt;
hint = res.hint;
current_salt = res.current_salt;
} else {
new_salt = null;
hint = null;
current_salt = null;
}
if (new_salt != null) {
byte[] salt = new byte[new_salt.length + 16];
Utilities.random.nextBytes(salt);
System.arraycopy(new_salt, 0, salt, 0, new_salt.length);
new_salt = salt;
}
if (type == 0 && hintPasswordCell != null && hint != null) {
hintPasswordCell.setFieldText(hint);
}
updateRows();
}
});
}
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassWithoutLogin);
}
private void doneWithPassword() {
if (type == 0) {
String oldPassword = oldPasswordCell.getFieldText();
String newPassword = newPasswordCell.getFieldText();
String verifyPasswrod = verifyPasswordCell.getFieldText();
String hint = hintPasswordCell.getFieldText();
if (hasPassword) {
if (oldPassword.length() == 0) {
ShowAlert(LocaleController.getString("PasswordOldIncorrect", R.string.PasswordOldIncorrect));
return;
}
}
if (newPassword.length() == 0) {
ShowAlert(LocaleController.getString("PasswordNewIncorrect", R.string.PasswordNewIncorrect));
return;
}
if (!newPassword.equals(verifyPasswrod)) {
ShowAlert(LocaleController.getString("PasswordDoNotMatch", R.string.PasswordDoNotMatch));
return;
}
if (hint.toLowerCase().contains(newPassword.toLowerCase())) {
ShowAlert(LocaleController.getString("HintIncorrect", R.string.HintIncorrect));
return;
}
byte[] oldPasswordBytes = null;
byte[] newPasswordBytes = null;
try {
oldPasswordBytes = oldPassword.getBytes("UTF-8");
newPasswordBytes = newPassword.getBytes("UTF-8");
} catch (Exception e) {
FileLog.e("tmessages", e);
}
TLRPC.TL_account_setPassword req = new TLRPC.TL_account_setPassword();
req.hint = hintPasswordCell.getFieldText();
if (req.hint == null) {
req.hint = "";
}
if (hasPassword) {
byte[] hash = new byte[current_salt.length * 2 + oldPasswordBytes.length];
System.arraycopy(current_salt, 0, hash, 0, current_salt.length);
System.arraycopy(oldPasswordBytes, 0, hash, oldPasswordBytes.length, oldPasswordBytes.length);
System.arraycopy(current_salt, 0, hash, hash.length - current_salt.length, current_salt.length);
req.current_password_hash = Utilities.computeSHA256(hash, 0, hash.length);
} else {
req.current_password_hash = new byte[0];
}
needShowProgress();
byte[] hash = new byte[new_salt.length * 2 + newPasswordBytes.length];
System.arraycopy(new_salt, 0, hash, 0, new_salt.length);
System.arraycopy(newPasswordBytes, 0, hash, newPasswordBytes.length, newPasswordBytes.length);
System.arraycopy(new_salt, 0, hash, hash.length - new_salt.length, new_salt.length);
req.new_password_hash = Utilities.computeSHA256(hash, 0, hash.length);
req.new_salt = new_salt;
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(final TLObject response, final TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
needHideProgress();
if (error == null) {
UserConfig.registeredForPush = false;
UserConfig.registeredForInternalPush = false;
UserConfig.saveConfig(false);
MessagesController.getInstance().registerForPush(UserConfig.pushString);
ConnectionsManager.getInstance().initPushConnection();
finishFragment();
} else {
if (error.text.contains("PASSWORD_HASH_INVALID")) {
ShowAlert(LocaleController.getString("PasswordOldIncorrect", R.string.PasswordOldIncorrect));
} else if (error.text.contains("NEW_PASSWORD_BAD")) {
ShowAlert(LocaleController.getString("PasswordNewIncorrect", R.string.PasswordNewIncorrect));
} else if (error.text.startsWith("FLOOD_WAIT")) {
ShowAlert(LocaleController.getString("FloodWait", R.string.FloodWait));
} else {
ShowAlert(error.text);
}
}
}
});
}
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
} else if (type == 1) {
String oldPassword = oldPasswordCell.getFieldText();
if (oldPassword.length() == 0) {
ShowAlert(LocaleController.getString("PasswordIncorrect", R.string.PasswordIncorrect));
return;
}
byte[] oldPasswordBytes = null;
try {
oldPasswordBytes = oldPassword.getBytes("UTF-8");
} catch (Exception e) {
FileLog.e("tmessages", e);
}
needShowProgress();
byte[] hash = new byte[current_salt.length * 2 + oldPasswordBytes.length];
System.arraycopy(current_salt, 0, hash, 0, current_salt.length);
System.arraycopy(oldPasswordBytes, 0, hash, oldPasswordBytes.length, oldPasswordBytes.length);
System.arraycopy(current_salt, 0, hash, hash.length - current_salt.length, current_salt.length);
TLRPC.TL_auth_checkPassword req = new TLRPC.TL_auth_checkPassword();
req.password_hash = Utilities.computeSHA256(hash, 0, hash.length);
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(final TLObject response, final TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
needHideProgress();
if (error == null) {
if (UserConfig.isClientActivated()) {
presentFragment(new MessagesActivity(null), true);
UserConfig.registeredForPush = false;
UserConfig.registeredForInternalPush = false;
UserConfig.saveConfig(false);
MessagesController.getInstance().registerForPush(UserConfig.pushString);
ConnectionsManager.getInstance().initPushConnection();
} else {
TLRPC.TL_auth_authorization res = (TLRPC.TL_auth_authorization)response;
UserConfig.clearConfig();
MessagesController.getInstance().cleanUp();
UserConfig.setCurrentUser(res.user);
UserConfig.saveConfig(true);
MessagesStorage.getInstance().cleanUp(true);
ArrayList<TLRPC.User> users = new ArrayList<>();
users.add(res.user);
MessagesStorage.getInstance().putUsersAndChats(users, null, true, true);
MessagesController.getInstance().putUser(res.user, false);
ContactsController.getInstance().checkAppAccount();
MessagesController.getInstance().getBlockedUsers(true);
presentFragment(new MessagesActivity(null), true);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.mainUserInfoChanged);
ConnectionsManager.getInstance().initPushConnection();
}
} else {
if (error.text.contains("PASSWORD_HASH_INVALID")) {
ShowAlert(LocaleController.getString("PasswordOldIncorrect", R.string.PasswordOldIncorrect));
} else if (error.text.startsWith("FLOOD_WAIT")) {
ShowAlert(LocaleController.getString("FloodWait", R.string.FloodWait));
} else {
ShowAlert(error.text);
}
}
}
});
}
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassWithoutLogin);
}
}
private class ListAdapter extends BaseFragmentAdapter {
private Context mContext;
public ListAdapter(Context context) {
mContext = context;
}
@Override
public boolean areAllItemsEnabled() {
return false;
}
@Override
public boolean isEnabled(int i) {
return i == deleteAccountRow;
}
@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 viewType = getItemViewType(i);
if (viewType == 0) {
if (view == null) {
view = new TextInfoPrivacyCell(mContext);
}
if (i == passwordDetailRow) {
if (type == 0) {
((TextInfoPrivacyCell) view).setText(LocaleController.getString("PasswordImportant", R.string.PasswordImportant));
} else if (type == 1) {
((TextInfoPrivacyCell) view).setText(hint == null || hint.length() == 0 ? "" : LocaleController.formatString("PasswordHintDetail", R.string.PasswordHintDetail, hint));
}
((TextInfoPrivacyCell) view).setTextColor(0xffcf3030);
if (deleteAccountDetailRow != -1) {
view.setBackgroundResource(R.drawable.greydivider);
} else {
view.setBackgroundResource(R.drawable.greydivider_bottom);
}
} else if (i == deleteAccountDetailRow) {
((TextInfoPrivacyCell) view).setText(LocaleController.getString("DeleteAccountImportant", R.string.DeleteAccountImportant));
((TextInfoPrivacyCell) view).setTextColor(0xffcf3030);
view.setBackgroundResource(R.drawable.greydivider_bottom);
}
} else if (viewType == 1) {
if (view == null) {
view = new HeaderCell(mContext);
view.setBackgroundColor(0xffffffff);
}
if (i == changePasswordSectionRow) {
if (type == 0) {
((HeaderCell) view).setText(LocaleController.getString("ChangePassword", R.string.ChangePassword));
} else if (type == 1) {
((HeaderCell) view).setText(LocaleController.getString("EnterPassword", R.string.EnterPassword));
}
} else if (i == deleteAccountSection) {
((HeaderCell) view).setText(LocaleController.getString("PasswordDeleteAccountTitle", R.string.PasswordDeleteAccountTitle));
}
} else if (viewType == 2) {
return newPasswordCell;
} else if (viewType == 3) {
return oldPasswordCell;
} else if (viewType == 4) {
return verifyPasswordCell;
} else if (viewType == 5) {
return hintPasswordCell;
} else if (viewType == 6) {
if (view == null) {
view = new TextSettingsCell(mContext);
view.setBackgroundColor(0xffffffff);
}
TextSettingsCell textCell = (TextSettingsCell) view;
if (i == deleteAccountRow) {
textCell.setText(LocaleController.getString("PasswordDeleteAccount", R.string.PasswordDeleteAccount), false);
}
}
return view;
}
@Override
public int getItemViewType(int i) {
if (i == passwordDetailRow || i == deleteAccountDetailRow) {
return 0;
} else if (i == changePasswordSectionRow || i == deleteAccountSection) {
return 1;
} else if (i == newPasswordRow) {
return 2;
} else if (i == oldPasswordRow) {
return 3;
} else if (i == verifyPasswordRow) {
return 4;
} else if (i == hintRow) {
return 5;
} else if (i == deleteAccountRow) {
return 6;
}
return 0;
}
@Override
public int getViewTypeCount() {
return 7;
}
@Override
public boolean isEmpty() {
return rowCount == 0;
}
}
}

View File

@ -121,18 +121,10 @@ public class ActionBar extends FrameLayout {
}
int x = 0;
if (backButtonImageView != null) {
if (AndroidUtilities.isTablet()) {
x = AndroidUtilities.dp(80);
if (backButtonImageView != null && backButtonImageView.getVisibility() == VISIBLE) {
x = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 80 : 72);
} else {
x = AndroidUtilities.dp(72);
}
} else {
if (AndroidUtilities.isTablet()) {
x = AndroidUtilities.dp(26);
} else {
x = AndroidUtilities.dp(18);
}
x = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 26 : 18);
}
if (menu != null) {
@ -202,17 +194,31 @@ public class ActionBar extends FrameLayout {
}
public void setBackButtonDrawable(Drawable drawable) {
boolean reposition = false;
if (backButtonImageView == null) {
createBackButtonImage();
} else {
reposition = true;
}
backButtonImageView.setVisibility(drawable == null ? GONE : VISIBLE);
backButtonImageView.setImageDrawable(drawable);
if (reposition) {
positionTitle(getMeasuredWidth(), getMeasuredHeight());
}
}
public void setBackButtonImage(int resource) {
boolean reposition = false;
if (backButtonImageView == null) {
createBackButtonImage();
} else {
reposition = true;
}
backButtonImageView.setVisibility(resource == 0 ? GONE : VISIBLE);
backButtonImageView.setImageResource(resource);
if (reposition) {
positionTitle(getMeasuredWidth(), getMeasuredHeight());
}
}
private void createSubtitleTextView() {
@ -234,7 +240,7 @@ public class ActionBar extends FrameLayout {
createSubtitleTextView();
}
if (subTitleTextView != null) {
subTitleTextView.setVisibility(value != null && !isSearchFieldVisible ? VISIBLE : GONE);
subTitleTextView.setVisibility(value != null && !isSearchFieldVisible ? VISIBLE : INVISIBLE);
subTitleTextView.setText(value);
positionTitle(getMeasuredWidth(), getMeasuredHeight());
}
@ -276,7 +282,7 @@ public class ActionBar extends FrameLayout {
}
if (titleTextView != null) {
lastTitle = value;
titleTextView.setVisibility(value != null && !isSearchFieldVisible ? VISIBLE : GONE);
titleTextView.setVisibility(value != null && !isSearchFieldVisible ? VISIBLE : INVISIBLE);
titleTextView.setText(value);
positionTitle(getMeasuredWidth(), getMeasuredHeight());
}
@ -344,7 +350,7 @@ public class ActionBar extends FrameLayout {
layoutParams.width = LayoutParams.FILL_PARENT;
layoutParams.gravity = Gravity.RIGHT;
actionMode.setLayoutParams(layoutParams);
actionMode.setVisibility(GONE);
actionMode.setVisibility(INVISIBLE);
if (occupyStatusBar) {
actionModeTop = new View(getContext());
@ -355,7 +361,7 @@ public class ActionBar extends FrameLayout {
layoutParams.width = LayoutParams.FILL_PARENT;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
actionModeTop.setLayoutParams(layoutParams);
actionModeTop.setVisibility(GONE);
actionModeTop.setVisibility(INVISIBLE);
}
return actionMode;
@ -381,9 +387,9 @@ public class ActionBar extends FrameLayout {
if (actionMode == null) {
return;
}
actionMode.setVisibility(GONE);
actionMode.setVisibility(INVISIBLE);
if (occupyStatusBar && actionModeTop != null) {
actionModeTop.setVisibility(GONE);
actionModeTop.setVisibility(INVISIBLE);
}
if (titleFrameLayout != null) {
titleFrameLayout.setVisibility(VISIBLE);
@ -400,10 +406,10 @@ public class ActionBar extends FrameLayout {
protected void onSearchFieldVisibilityChanged(boolean visible) {
isSearchFieldVisible = visible;
if (titleTextView != null) {
titleTextView.setVisibility(visible ? GONE : VISIBLE);
titleTextView.setVisibility(visible ? INVISIBLE : VISIBLE);
}
if (subTitleTextView != null) {
subTitleTextView.setVisibility(visible ? GONE : VISIBLE);
subTitleTextView.setVisibility(visible ? INVISIBLE : VISIBLE);
}
Drawable drawable = backButtonImageView.getDrawable();
if (drawable != null && drawable instanceof MenuDrawable) {
@ -460,7 +466,7 @@ public class ActionBar extends FrameLayout {
createTitleTextView();
}
if (titleTextView != null) {
titleTextView.setVisibility(textToSet != null && !isSearchFieldVisible ? VISIBLE : GONE);
titleTextView.setVisibility(textToSet != null && !isSearchFieldVisible ? VISIBLE : INVISIBLE);
titleTextView.setText(textToSet);
positionTitle(getMeasuredWidth(), getMeasuredHeight());
}

View File

@ -303,7 +303,7 @@ public class ActionBarLayout extends FrameLayout {
}
}
}
containerViewBack.setVisibility(View.GONE);
containerViewBack.setVisibility(View.INVISIBLE);
//AndroidUtilities.unlockOrientation(parentActivity);
startedTracking = false;
animationInProgress = false;
@ -321,7 +321,15 @@ public class ActionBarLayout extends FrameLayout {
beginTrackingSent = false;
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
View fragmentView = lastFragment.createView(parentActivity.getLayoutInflater());
View fragmentView = lastFragment.fragmentView;
if (fragmentView == null) {
fragmentView = lastFragment.createView(parentActivity, parentActivity.getLayoutInflater());
} else {
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
@ -342,7 +350,7 @@ public class ActionBarLayout extends FrameLayout {
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
fragmentView.setLayoutParams(layoutParams);
if (fragmentView.getBackground() == null) {
if (!lastFragment.hasOwnBackground && fragmentView.getBackground() == null) {
fragmentView.setBackgroundColor(0xffffffff);
}
lastFragment.onResume();
@ -372,7 +380,7 @@ public class ActionBarLayout extends FrameLayout {
int dx = Math.max(0, (int) (ev.getX() - startedTrackingX));
int dy = Math.abs((int) ev.getY() - startedTrackingY);
velocityTracker.addMovement(ev);
if (maybeStartTracking && !startedTracking && dx >= AndroidUtilities.dp(10) && Math.abs(dx) / 3 > dy) {
if (maybeStartTracking && !startedTracking && dx >= AndroidUtilities.getPixelsInCM(0.3f, true) && Math.abs(dx) / 3 > dy) {
prepareForMoving(ev);
} else if (startedTracking) {
if (!beginTrackingSent) {
@ -531,7 +539,7 @@ public class ActionBarLayout extends FrameLayout {
}
}
}
containerViewBack.setVisibility(View.GONE);
containerViewBack.setVisibility(View.INVISIBLE);
}
public boolean presentFragment(BaseFragment fragment) {
@ -555,7 +563,15 @@ public class ActionBarLayout extends FrameLayout {
final BaseFragment currentFragment = !fragmentsStack.isEmpty() ? fragmentsStack.get(fragmentsStack.size() - 1) : null;
fragment.setParentLayout(this);
View fragmentView = fragment.createView(parentActivity.getLayoutInflater());
View fragmentView = fragment.fragmentView;
if (fragmentView == null) {
fragmentView = fragment.createView(parentActivity, parentActivity.getLayoutInflater());
} else {
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
if (fragment.needAddActionBar() && fragment.actionBar != null) {
if (removeActionBarExtraHeight) {
fragment.actionBar.setOccupyStatusBar(false);
@ -576,7 +592,7 @@ public class ActionBarLayout extends FrameLayout {
fragmentsStack.add(fragment);
fragment.onResume();
currentActionBar = fragment.actionBar;
if (fragmentView.getBackground() == null) {
if (!fragment.hasOwnBackground && fragmentView.getBackground() == null) {
fragmentView.setBackgroundColor(0xffffffff);
}
@ -707,7 +723,7 @@ public class ActionBarLayout extends FrameLayout {
fragment.onFragmentDestroy();
fragment.setParentLayout(null);
fragmentsStack.remove(fragment);
containerViewBack.setVisibility(View.GONE);
containerViewBack.setVisibility(View.INVISIBLE);
bringChildToFront(containerView);
}
@ -733,7 +749,15 @@ public class ActionBarLayout extends FrameLayout {
containerView.setVisibility(View.VISIBLE);
previousFragment.setParentLayout(this);
View fragmentView = previousFragment.createView(parentActivity.getLayoutInflater());
View fragmentView = previousFragment.fragmentView;
if (fragmentView == null) {
fragmentView = previousFragment.createView(parentActivity, parentActivity.getLayoutInflater());
} else {
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
if (previousFragment.needAddActionBar() && previousFragment.actionBar != null) {
if (removeActionBarExtraHeight) {
previousFragment.actionBar.setOccupyStatusBar(false);
@ -752,7 +776,7 @@ public class ActionBarLayout extends FrameLayout {
fragmentView.setLayoutParams(layoutParams);
previousFragment.onResume();
currentActionBar = previousFragment.actionBar;
if (fragmentView.getBackground() == null) {
if (!previousFragment.hasOwnBackground && fragmentView.getBackground() == null) {
fragmentView.setBackgroundColor(0xffffffff);
}
@ -804,9 +828,9 @@ public class ActionBarLayout extends FrameLayout {
@Override
public void run() {
removeFragmentFromStack(currentFragment);
setVisibility(GONE);
setVisibility(INVISIBLE);
if (backgroundView != null) {
backgroundView.setVisibility(GONE);
backgroundView.setVisibility(INVISIBLE);
}
if (drawerLayoutContainer != null) {
drawerLayoutContainer.setAllowOpenDrawer(true, false);
@ -843,9 +867,9 @@ public class ActionBarLayout extends FrameLayout {
currentAnimation.start();
} else {
removeFragmentFromStack(currentFragment);
setVisibility(GONE);
setVisibility(INVISIBLE);
if (backgroundView != null) {
backgroundView.setVisibility(GONE);
backgroundView.setVisibility(INVISIBLE);
}
}
}
@ -857,7 +881,15 @@ public class ActionBarLayout extends FrameLayout {
}
BaseFragment previousFragment = fragmentsStack.get(fragmentsStack.size() - 1);
previousFragment.setParentLayout(this);
View fragmentView = previousFragment.createView(parentActivity.getLayoutInflater());
View fragmentView = previousFragment.fragmentView;
if (fragmentView == null) {
fragmentView = previousFragment.createView(parentActivity, parentActivity.getLayoutInflater());
} else {
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
if (previousFragment.needAddActionBar() && previousFragment.actionBar != null) {
if (removeActionBarExtraHeight) {
previousFragment.actionBar.setOccupyStatusBar(false);
@ -876,7 +908,7 @@ public class ActionBarLayout extends FrameLayout {
fragmentView.setLayoutParams(layoutParams);
previousFragment.onResume();
currentActionBar = previousFragment.actionBar;
if (fragmentView.getBackground() == null) {
if (!previousFragment.hasOwnBackground && fragmentView.getBackground() == null) {
fragmentView.setBackgroundColor(0xffffffff);
}
}

View File

@ -10,6 +10,7 @@ package org.telegram.ui.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
@ -31,6 +32,7 @@ public class BaseFragment {
protected int classGuid = 0;
protected Bundle arguments;
protected boolean swipeBackEnabled = true;
protected boolean hasOwnBackground = false;
public BaseFragment() {
classGuid = ConnectionsManager.getInstance().generateClassGuid();
@ -41,7 +43,7 @@ public class BaseFragment {
classGuid = ConnectionsManager.getInstance().generateClassGuid();
}
public View createView(LayoutInflater inflater) {
public View createView(Context context, LayoutInflater inflater) {
return null;
}
@ -201,9 +203,9 @@ public class BaseFragment {
return true;
}
public void showAlertDialog(AlertDialog.Builder builder) {
public AlertDialog showAlertDialog(AlertDialog.Builder builder) {
if (parentLayout == null || parentLayout.checkTransitionAnimation() || parentLayout.animationInProgress || parentLayout.startedTracking) {
return;
return null;
}
try {
if (visibleDialog != null) {
@ -223,9 +225,11 @@ public class BaseFragment {
onDialogDismiss();
}
});
return visibleDialog;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return null;
}
protected void onDialogDismiss() {

View File

@ -301,7 +301,7 @@ public class DrawerLayoutContainer extends FrameLayout {
float dx = (int) (ev.getX() - startedTrackingX);
float dy = Math.abs((int) ev.getY() - startedTrackingY);
velocityTracker.addMovement(ev);
if (maybeStartTracking && !startedTracking && (dx > 0 && dx / 3.0f > Math.abs(dy) || dx < 0 && Math.abs(dx) >= Math.abs(dy) && Math.abs(dx) >= AndroidUtilities.dp(10))) {
if (maybeStartTracking && !startedTracking && (dx > 0 && dx / 3.0f > Math.abs(dy) && Math.abs(dx) >= AndroidUtilities.getPixelsInCM(0.2f, true) || dx < 0 && Math.abs(dx) >= Math.abs(dy) && Math.abs(dx) >= AndroidUtilities.getPixelsInCM(0.3f, true))) {
prepareForDrawerOpen(ev);
startedTrackingX = (int) ev.getX();
requestDisallowInterceptTouchEvent(true);

View File

@ -73,7 +73,7 @@ public class CountrySearchAdapter extends BaseFragmentAdapter {
return;
}
long time = System.currentTimeMillis();
ArrayList<Country> resultArray = new ArrayList<Country>();
ArrayList<Country> resultArray = new ArrayList<>();
String n = query.substring(0, 1);
ArrayList<Country> arr = countries.get(n.toUpperCase());

View File

@ -9,7 +9,6 @@
package org.telegram.ui.Adapters;
import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
@ -348,7 +347,7 @@ public class DialogsSearchAdapter extends BaseSearchAdapter {
user.status.expires = cursor.intValue(7);
}
if (found == 1) {
dialogSearchResult.name = Html.fromHtml("<font color=\"#00a60e\">" + ContactsController.formatName(user.first_name, user.last_name) + "</font>");
dialogSearchResult.name = AndroidUtilities.replaceTags("<c#ff00a60e>" + ContactsController.formatName(user.first_name, user.last_name) + "</c>");
} else {
dialogSearchResult.name = Utilities.generateSearchName("@" + user.username, null, "@" + q);
}
@ -534,6 +533,7 @@ public class DialogsSearchAdapter extends BaseSearchAdapter {
notifyDataSetChanged();
return;
}
searchResultMessages.clear();
searchResultHashtags.clear();
for (HashtagObject hashtagObject : hashtags) {
searchResultHashtags.add(hashtagObject.hashtag);
@ -670,10 +670,11 @@ public class DialogsSearchAdapter extends BaseSearchAdapter {
((ProfileSearchCell) view).useSeparator = (i != getCount() - 1 && i != localCount - 1 && i != localCount + globalCount - 1);
Object obj = getItem(i);
if (obj instanceof TLRPC.User) {
user = MessagesController.getInstance().getUser(((TLRPC.User) obj).id);
/*user = MessagesController.getInstance().getUser(((TLRPC.User) obj).id);
if (user == null) {
user = (TLRPC.User) obj;
}
}*/
user = (TLRPC.User) obj;
} else if (obj instanceof TLRPC.Chat) {
chat = MessagesController.getInstance().getChat(((TLRPC.Chat) obj).id);
} else if (obj instanceof TLRPC.EncryptedChat) {
@ -697,7 +698,7 @@ public class DialogsSearchAdapter extends BaseSearchAdapter {
foundUserName = foundUserName.substring(1);
}
try {
username = Html.fromHtml(String.format("<font color=\"#4d83b3\">@%s</font>%s", user.username.substring(0, foundUserName.length()), user.username.substring(foundUserName.length())));
username = AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>@%s</c>%s", user.username.substring(0, foundUserName.length()), user.username.substring(foundUserName.length())));
} catch (Exception e) {
username = user.username;
FileLog.e("tmessages", e);

View File

@ -9,7 +9,6 @@
package org.telegram.ui.Adapters;
import android.content.Context;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
@ -257,7 +256,7 @@ public class SearchAdapter extends BaseSearchAdapter {
foundUserName = foundUserName.substring(1);
}
try {
username = Html.fromHtml(String.format("<font color=\"#4d83b3\">@%s</font>%s", user.username.substring(0, foundUserName.length()), user.username.substring(foundUserName.length())));
username = AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>@%s</c>%s", user.username.substring(0, foundUserName.length()), user.username.substring(foundUserName.length())));
} catch (Exception e) {
username = user.username;
FileLog.e("tmessages", e);

View File

@ -64,8 +64,7 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("BlockedUsers", R.string.BlockedUsers));
@ -89,10 +88,10 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe
ActionBarMenu menu = actionBar.createMenu();
menu.addItem(block_user, R.drawable.plus);
fragmentView = new FrameLayout(getParentActivity());
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
emptyTextView = new TextView(getParentActivity());
emptyTextView = new TextView(context);
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
@ -111,14 +110,14 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe
}
});
progressView = new FrameLayout(getParentActivity());
progressView = new FrameLayout(context);
frameLayout.addView(progressView);
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
progressView.setLayoutParams(layoutParams);
ProgressBar progressBar = new ProgressBar(getParentActivity());
ProgressBar progressBar = new ProgressBar(context);
progressView.addView(progressBar);
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
@ -126,12 +125,12 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe
layoutParams.gravity = Gravity.CENTER;
progressView.setLayoutParams(layoutParams);
listView = new ListView(getParentActivity());
listView = new ListView(context);
listView.setEmptyView(emptyTextView);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setAdapter(listViewAdapter = new ListAdapter(getParentActivity()));
listView.setAdapter(listViewAdapter = new ListAdapter(context));
if (Build.VERSION.SDK_INT >= 11) {
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
}
@ -161,7 +160,7 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe
selectedUserId = MessagesController.getInstance().blockedUsers.get(i);
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items = new CharSequence[] {LocaleController.getString("Unblock", R.string.Unblock)};
CharSequence[] items = new CharSequence[]{LocaleController.getString("Unblock", R.string.Unblock)};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
@ -184,12 +183,6 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe
progressView.setVisibility(View.GONE);
listView.setEmptyView(emptyTextView);
}
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -14,7 +14,6 @@ import android.content.res.Configuration;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
@ -83,9 +82,9 @@ public class ChatBaseCell extends BaseCell {
private static TextPaint timeMediaPaint;
private static TextPaint namePaint;
private static TextPaint forwardNamePaint;
private static TextPaint replyNamePaint;
private static TextPaint replyTextPaint;
private static Paint replyLinePaint;
protected static TextPaint replyNamePaint;
protected static TextPaint replyTextPaint;
protected static Paint replyLinePaint;
protected int backgroundWidth = 100;
@ -191,6 +190,7 @@ public class ChatBaseCell extends BaseCell {
replyTextPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
replyTextPaint.setTextSize(AndroidUtilities.dp(14));
replyTextPaint.linkColor = 0xff316f9f;
replyLinePaint = new Paint();
}
@ -362,7 +362,7 @@ public class ChatBaseCell extends BaseCell {
forwardedNameWidth = getMaxNameWidth();
CharSequence str = TextUtils.ellipsize(currentForwardNameString.replace("\n", " "), forwardNamePaint, forwardedNameWidth - AndroidUtilities.dp(40), TextUtils.TruncateAt.END);
str = Html.fromHtml(String.format("%s<br>%s <b>%s</b>", LocaleController.getString("ForwardedMessage", R.string.ForwardedMessage), LocaleController.getString("From", R.string.From), str));
str = AndroidUtilities.replaceTags(String.format("%s\n%s <b>%s</b>", LocaleController.getString("ForwardedMessage", R.string.ForwardedMessage), LocaleController.getString("From", R.string.From), str));
forwardedNameLayout = new StaticLayout(str, forwardNamePaint, forwardedNameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (forwardedNameLayout.getLineCount() > 1) {
forwardedNameWidth = Math.max((int) Math.ceil(forwardedNameLayout.getLineWidth(0)), (int) Math.ceil(forwardedNameLayout.getLineWidth(1)));

View File

@ -9,35 +9,128 @@
package org.telegram.ui.Cells;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.Browser;
import android.text.Layout;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.ClickableSpan;
import android.view.MotionEvent;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.ImageReceiver;
import org.telegram.android.MediaController;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
import org.telegram.android.MessageObject;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.ui.Components.StaticLayoutEx;
import org.telegram.ui.Components.URLSpanNoUnderline;
import java.util.Locale;
public class ChatMessageCell extends ChatBaseCell {
private int textX, textY;
private int totalHeight = 0;
private ClickableSpan pressedLink;
private int linkBlockNum;
private MyPath urlPath = new MyPath();
private boolean linkPreviewPressed;
private static Paint urlPaint;
private int lastVisibleBlockNum = 0;
private int firstVisibleBlockNum = 0;
private int totalVisibleBlocksCount = 0;
private ImageReceiver linkImageView;
private boolean isSmallImage;
private boolean drawLinkImageView;
private boolean hasLinkPreview;
private int linkPreviewHeight;
private boolean isInstagram;
private int smallImageX;
private int descriptionY;
private int durationWidth;
private StaticLayout siteNameLayout;
private StaticLayout titleLayout;
private StaticLayout descriptionLayout;
private StaticLayout durationLayout;
private StaticLayout authorLayout;
private static TextPaint durationPaint;
private TLRPC.PhotoSize currentPhotoObject;
private TLRPC.PhotoSize currentPhotoObjectThumb;
private boolean imageCleared;
private static Drawable igvideoDrawable;
private class MyPath extends Path {
private StaticLayout currentLayout;
private int currentLine;
private float lastTop = -1;
public void setCurrentLayout(StaticLayout layout, int start) {
currentLayout = layout;
currentLine = layout.getLineForOffset(start);
lastTop = -1;
}
@Override
public void addRect(float left, float top, float right, float bottom, Direction dir) {
if (lastTop == -1) {
lastTop = top;
} else if (lastTop != top) {
lastTop = top;
currentLine++;
}
float lineRight = currentLayout.getLineRight(currentLine);
float lineLeft = currentLayout.getLineLeft(currentLine);
if (left >= lineRight) {
return;
}
if (right > lineRight) {
right = lineRight;
}
if (left < lineLeft) {
left = lineLeft;
}
super.addRect(left, top, right, bottom, dir);
}
}
public ChatMessageCell(Context context) {
super(context);
drawForwardedName = true;
linkImageView = new ImageReceiver(this);
if (urlPaint == null) {
urlPaint = new Paint();
urlPaint.setColor(0x33316f9f);
}
}
private void resetPressedLink() {
if (pressedLink != null) {
pressedLink = null;
}
linkPreviewPressed = false;
invalidate();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean result = false;
if (currentMessageObject != null && currentMessageObject.textLayoutBlocks != null && !currentMessageObject.textLayoutBlocks.isEmpty() && currentMessageObject.messageText instanceof Spannable && !isPressed) {
if (event.getAction() == MotionEvent.ACTION_DOWN || pressedLink != null && event.getAction() == MotionEvent.ACTION_UP) {
if (event.getAction() == MotionEvent.ACTION_DOWN || (linkPreviewPressed || pressedLink != null) && event.getAction() == MotionEvent.ACTION_UP) {
int x = (int)event.getX();
int y = (int)event.getY();
if (x >= textX && y >= textY && x <= textX + currentMessageObject.textWidth && y <= textY + currentMessageObject.textHeight) {
@ -55,11 +148,19 @@ public class ChatMessageCell extends ChatBaseCell {
if (left <= x && left + block.textLayout.getLineWidth(line) >= x) {
Spannable buffer = (Spannable)currentMessageObject.messageText;
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
if (link.length != 0) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
resetPressedLink();
pressedLink = link[0];
return true;
linkBlockNum = blockNum;
try {
int start = buffer.getSpanStart(pressedLink) - block.charactersOffset;
urlPath.setCurrentLayout(block.textLayout, start);
block.textLayout.getSelectionPath(start, buffer.getSpanEnd(pressedLink) - block.charactersOffset, urlPath);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
result = true;
} else {
if (link[0] == pressedLink) {
try {
@ -76,30 +177,98 @@ public class ChatMessageCell extends ChatBaseCell {
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return true;
resetPressedLink();
result = true;
}
}
} else {
pressedLink = null;
resetPressedLink();
}
} else {
pressedLink = null;
resetPressedLink();
}
} catch (Exception e) {
pressedLink = null;
resetPressedLink();
FileLog.e("tmessages", e);
}
} else {
pressedLink = null;
resetPressedLink();
}
} else if (hasLinkPreview && x >= textX && x <= textX + backgroundWidth && y >= textY + currentMessageObject.textHeight && y <= textY + currentMessageObject.textHeight + linkPreviewHeight + AndroidUtilities.dp(8)) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
resetPressedLink();
if (drawLinkImageView && linkImageView.isInsideImage(x, y)) {
linkPreviewPressed = true;
result = true;
} else {
if (descriptionLayout != null && y >= descriptionY) {
try {
x -= textX + AndroidUtilities.dp(10);
y -= descriptionY;
final int line = descriptionLayout.getLineForVertical(y);
final int off = descriptionLayout.getOffsetForHorizontal(line, x);
final float left = descriptionLayout.getLineLeft(line);
if (left <= x && left + descriptionLayout.getLineWidth(line) >= x) {
Spannable buffer = (Spannable) currentMessageObject.linkDescription;
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
if (link.length != 0) {
resetPressedLink();
pressedLink = link[0];
linkPreviewPressed = true;
linkBlockNum = -10;
result = true;
try {
int start = buffer.getSpanStart(pressedLink);
urlPath.setCurrentLayout(descriptionLayout, start);
descriptionLayout.getSelectionPath(start, buffer.getSpanEnd(pressedLink), urlPath);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else {
pressedLink = null;
}
resetPressedLink();
}
} else {
pressedLink = null;
resetPressedLink();
}
return super.onTouchEvent(event);
} catch (Exception e) {
resetPressedLink();
FileLog.e("tmessages", e);
}
}
}
} else if (linkPreviewPressed) {
try {
if (pressedLink != null) {
pressedLink.onClick(this);
} else {
Uri uri = Uri.parse(currentMessageObject.messageOwner.media.webpage.url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, getContext().getPackageName());
getContext().startActivity(intent);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
resetPressedLink();
result = true;
}
} else {
resetPressedLink();
}
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
resetPressedLink();
}
} else {
resetPressedLink();
}
if (result && event.getAction() == MotionEvent.ACTION_DOWN) {
startCheckLongPress();
}
if (event.getAction() != MotionEvent.ACTION_DOWN && event.getAction() != MotionEvent.ACTION_MOVE) {
cancelCheckLongPress();
}
return result || super.onTouchEvent(event);
}
public void setVisiblePart(int position, int height) {
@ -137,6 +306,51 @@ public class ChatMessageCell extends ChatBaseCell {
return left1 <= right2;
}
private StaticLayout generateStaticLayout(CharSequence text, TextPaint paint, int maxWidth, int smallWidth, int linesCount, int maxLines) {
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text);
int addedChars = 0;
StaticLayout layout = new StaticLayout(text, paint, smallWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
for (int a = 0; a < linesCount; a++) {
int pos = layout.getLineEnd(a);
if (pos == text.length()) {
break;
}
pos--;
if (stringBuilder.charAt(pos + addedChars) == ' ') {
stringBuilder.replace(pos + addedChars, pos + addedChars + 1, "\n");
} else {
stringBuilder.insert(pos + addedChars, "\n");
addedChars++;
}
if (a == layout.getLineCount() - 1 || a == maxLines - 1) {
break;
}
}
return StaticLayoutEx.createStaticLayout(stringBuilder, paint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, AndroidUtilities.dp(1), false, TextUtils.TruncateAt.END, maxWidth, maxLines);
}
@Override
protected boolean isUserDataChanged() {
if (imageCleared || !hasLinkPreview && currentMessageObject.messageOwner.media != null && currentMessageObject.messageOwner.media.webpage instanceof TLRPC.TL_webPage) {
return true;
}
//suppress warning
return super.isUserDataChanged();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (linkImageView != null) {
linkImageView.clearImage();
if (currentPhotoObject != null) {
imageCleared = true;
currentPhotoObject = null;
currentPhotoObjectThumb = null;
}
}
}
@Override
public void setMessageObject(MessageObject messageObject) {
if (currentMessageObject != messageObject || isUserDataChanged()) {
@ -144,7 +358,21 @@ public class ChatMessageCell extends ChatBaseCell {
firstVisibleBlockNum = 0;
lastVisibleBlockNum = 0;
}
pressedLink = null;
drawLinkImageView = false;
hasLinkPreview = false;
resetPressedLink();
linkPreviewPressed = false;
linkPreviewHeight = 0;
smallImageX = 0;
isInstagram = false;
durationLayout = null;
descriptionLayout = null;
titleLayout = null;
siteNameLayout = null;
authorLayout = null;
currentPhotoObject = null;
imageCleared = false;
currentPhotoObjectThumb = null;
int maxWidth;
if (AndroidUtilities.isTablet()) {
@ -182,7 +410,215 @@ public class ChatMessageCell extends ChatBaseCell {
timeMore += AndroidUtilities.dp(20.5f);
}
if (maxWidth - messageObject.lastLineWidth < timeMore) {
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageObject.messageOwner.media.webpage instanceof TLRPC.TL_webPage) {
int linkPreviewMaxWidth;
if (AndroidUtilities.isTablet()) {
if (currentMessageObject.messageOwner.to_id.chat_id != 0 && !currentMessageObject.isOut()) {
linkPreviewMaxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(122);
} else {
linkPreviewMaxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(80);
}
} else {
if (currentMessageObject.messageOwner.to_id.chat_id != 0 && !currentMessageObject.isOut()) {
linkPreviewMaxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(122);
} else {
linkPreviewMaxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(80);
}
}
int additinalWidth = AndroidUtilities.dp(10);
int restLinesCount = 3;
int additionalHeight = 0;
linkPreviewMaxWidth -= additinalWidth;
hasLinkPreview = true;
TLRPC.TL_webPage webPage = (TLRPC.TL_webPage) messageObject.messageOwner.media.webpage;
if (currentMessageObject.photoThumbs == null && webPage.photo != null) {
currentMessageObject.generateThumbs(true);
}
if (MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO)) {
isSmallImage = webPage.description != null && webPage.type != null && (webPage.type.equals("app") || webPage.type.equals("profile") || webPage.type.equals("article")) && currentMessageObject.photoThumbs != null;
}
if (webPage.site_name != null) {
try {
int width = (int) Math.ceil(replyNamePaint.measureText(webPage.site_name));
siteNameLayout = new StaticLayout(webPage.site_name, replyNamePaint, Math.min(width, linkPreviewMaxWidth), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
int height = siteNameLayout.getLineBottom(siteNameLayout.getLineCount() - 1);
linkPreviewHeight += height;
totalHeight += height;
additionalHeight += height;
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
if (webPage.title != null) {
try {
if (linkPreviewHeight != 0) {
linkPreviewHeight += AndroidUtilities.dp(2);
totalHeight += AndroidUtilities.dp(2);
}
int restLines = 0;
if (!isSmallImage || webPage.description == null) {
titleLayout = StaticLayoutEx.createStaticLayout(webPage.title, replyNamePaint, linkPreviewMaxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, AndroidUtilities.dp(1), false, TextUtils.TruncateAt.END, linkPreviewMaxWidth, 2);
} else {
restLines = restLinesCount;
titleLayout = generateStaticLayout(webPage.title, replyNamePaint, linkPreviewMaxWidth, linkPreviewMaxWidth - AndroidUtilities.dp(48 + 2), restLinesCount, 2);
restLinesCount -= titleLayout.getLineCount();
}
int height = titleLayout.getLineBottom(titleLayout.getLineCount() - 1);
linkPreviewHeight += height;
totalHeight += height;
for (int a = 0; a < titleLayout.getLineCount(); a++) {
int width = (int) Math.ceil(titleLayout.getLineWidth(a));
if (a < restLines) {
smallImageX = Math.max(smallImageX, width);
width += AndroidUtilities.dp(48 + 2);
}
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
if (webPage.author != null) {
try {
if (linkPreviewHeight != 0) {
linkPreviewHeight += AndroidUtilities.dp(2);
totalHeight += AndroidUtilities.dp(2);
}
int width = Math.min((int) Math.ceil(replyNamePaint.measureText(webPage.author)), linkPreviewMaxWidth);
if (restLinesCount == 3 && (!isSmallImage || webPage.description == null)) {
authorLayout = new StaticLayout(webPage.author, replyNamePaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
} else {
authorLayout = generateStaticLayout(webPage.author, replyNamePaint, width, linkPreviewMaxWidth - AndroidUtilities.dp(48 + 2), restLinesCount, 1);
restLinesCount -= authorLayout.getLineCount();
}
int height = authorLayout.getLineBottom(authorLayout.getLineCount() - 1);
linkPreviewHeight += height;
totalHeight += height;
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
if (webPage.description != null) {
try {
currentMessageObject.generateLinkDescription();
if (linkPreviewHeight != 0) {
linkPreviewHeight += AndroidUtilities.dp(2);
totalHeight += AndroidUtilities.dp(2);
}
int restLines = 0;
if (restLinesCount == 3 && !isSmallImage) {
descriptionLayout = StaticLayoutEx.createStaticLayout(messageObject.linkDescription, replyTextPaint, linkPreviewMaxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, AndroidUtilities.dp(1), false, TextUtils.TruncateAt.END, linkPreviewMaxWidth, 6);
} else {
restLines = restLinesCount;
descriptionLayout = generateStaticLayout(messageObject.linkDescription, replyTextPaint, linkPreviewMaxWidth, linkPreviewMaxWidth - AndroidUtilities.dp(48 + 2), restLinesCount, 6);
}
int height = descriptionLayout.getLineBottom(descriptionLayout.getLineCount() - 1);
linkPreviewHeight += height;
totalHeight += height;
for (int a = 0; a < descriptionLayout.getLineCount(); a++) {
int width = (int) Math.ceil(descriptionLayout.getLineWidth(a));
if (a < restLines) {
smallImageX = Math.max(smallImageX, width);
width += AndroidUtilities.dp(48 + 2);
}
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
if (webPage.photo != null && MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO)) {
boolean smallImage = webPage.type != null && (webPage.type.equals("app") || webPage.type.equals("profile") || webPage.type.equals("article"));
if (smallImage && descriptionLayout != null && descriptionLayout.getLineCount() == 1) {
smallImage = false;
isSmallImage = false;
}
int maxPhotoWidth = smallImage ? AndroidUtilities.dp(48) : linkPreviewMaxWidth;
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, maxPhotoWidth);
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 80);
if (currentPhotoObjectThumb == currentPhotoObject) {
currentPhotoObjectThumb = null;
}
if (currentPhotoObject != null) {
if (linkPreviewHeight != 0) {
linkPreviewHeight += AndroidUtilities.dp(2);
totalHeight += AndroidUtilities.dp(2);
}
maxChildWidth = Math.max(maxChildWidth, maxPhotoWidth + additinalWidth);
currentPhotoObject.size = -1;
if (currentPhotoObjectThumb != null) {
currentPhotoObjectThumb.size = -1;
}
int width;
int height;
if (smallImage) {
width = height = maxPhotoWidth;
} else {
width = currentPhotoObject.w;
height = currentPhotoObject.h;
float scale = width / (float) maxPhotoWidth;
width /= scale;
height /= scale;
if (height > AndroidUtilities.displaySize.y / 3) {
height = AndroidUtilities.displaySize.y / 3;
}
}
if (isSmallImage) {
if (AndroidUtilities.dp(50) + additionalHeight > linkPreviewHeight) {
totalHeight += AndroidUtilities.dp(50) + additionalHeight - linkPreviewHeight + AndroidUtilities.dp(8);
linkPreviewHeight = AndroidUtilities.dp(50) + additionalHeight;
}
linkPreviewHeight -= AndroidUtilities.dp(8);
} else {
totalHeight += height + AndroidUtilities.dp(12);
linkPreviewHeight += height;
}
linkImageView.setImageCoords(0, 0, width, height);
linkImageView.setImage(currentPhotoObject.location, String.format(Locale.US, "%d_%d", width, height), currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null, String.format(Locale.US, "%d_%d_b", width, height), 0, false);
drawLinkImageView = true;
if (webPage.site_name != null) {
if (webPage.site_name.toLowerCase().equals("instagram") && webPage.type != null && webPage.type.equals("video")) {
isInstagram = true;
if (igvideoDrawable == null) {
igvideoDrawable = getResources().getDrawable(R.drawable.igvideo);
}
}
}
}
if (webPage.duration != 0) {
if (durationPaint == null) {
durationPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
durationPaint.setTextSize(AndroidUtilities.dp(12));
durationPaint.setColor(0xffffffff);
}
int minutes = webPage.duration / 60;
int seconds = webPage.duration - minutes * 60;
String str = String.format("%d:%02d", minutes, seconds);
durationWidth = (int) Math.ceil(durationPaint.measureText(str));
durationLayout = new StaticLayout(str, durationPaint, durationWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
}
} else {
linkPreviewHeight -= AndroidUtilities.dp(6);
totalHeight += AndroidUtilities.dp(4);
}
}
if (hasLinkPreview || maxWidth - messageObject.lastLineWidth < timeMore) {
totalHeight += AndroidUtilities.dp(14);
backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth) + AndroidUtilities.dp(29);
} else {
@ -217,7 +653,7 @@ public class ChatMessageCell extends ChatBaseCell {
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (currentMessageObject == null || currentMessageObject.textLayoutBlocks == null || currentMessageObject.textLayoutBlocks.isEmpty() || firstVisibleBlockNum < 0) {
if (currentMessageObject == null || currentMessageObject.textLayoutBlocks == null || currentMessageObject.textLayoutBlocks.isEmpty()) {
return;
}
@ -229,13 +665,17 @@ public class ChatMessageCell extends ChatBaseCell {
textY = AndroidUtilities.dp(10) + namesOffset;
}
if (firstVisibleBlockNum >= 0) {
for (int a = firstVisibleBlockNum; a <= lastVisibleBlockNum; a++) {
if (a >= currentMessageObject.textLayoutBlocks.size()) {
break;
}
MessageObject.TextLayoutBlock block = currentMessageObject.textLayoutBlocks.get(a);
canvas.save();
canvas.translate(textX - (int)Math.ceil(block.textXOffset), textY + block.textYOffset);
canvas.translate(textX - (int) Math.ceil(block.textXOffset), textY + block.textYOffset);
if (pressedLink != null && a == linkBlockNum) {
canvas.drawPath(urlPath, urlPaint);
}
try {
block.textLayout.draw(canvas);
} catch (Exception e) {
@ -244,4 +684,102 @@ public class ChatMessageCell extends ChatBaseCell {
canvas.restore();
}
}
if (hasLinkPreview) {
int startY = textY + currentMessageObject.textHeight + AndroidUtilities.dp(8);
int linkPreviewY = startY;
int smallImageStartY = 0;
replyLinePaint.setColor(currentMessageObject.isOut() ? 0xff8dc97a : 0xff6c9fd2);
canvas.drawRect(textX, linkPreviewY - AndroidUtilities.dp(3), textX + AndroidUtilities.dp(2), linkPreviewY + linkPreviewHeight + AndroidUtilities.dp(3), replyLinePaint);
if (siteNameLayout != null) {
replyNamePaint.setColor(currentMessageObject.isOut() ? 0xff70b15c : 0xff4b91cf);
canvas.save();
canvas.translate(textX + AndroidUtilities.dp(10), linkPreviewY - AndroidUtilities.dp(3));
siteNameLayout.draw(canvas);
canvas.restore();
linkPreviewY += siteNameLayout.getLineBottom(siteNameLayout.getLineCount() - 1);
}
if (titleLayout != null) {
if (linkPreviewY != startY) {
linkPreviewY += AndroidUtilities.dp(2);
}
replyNamePaint.setColor(0xff000000);
smallImageStartY = linkPreviewY - AndroidUtilities.dp(1);
canvas.save();
canvas.translate(textX + AndroidUtilities.dp(10), linkPreviewY - AndroidUtilities.dp(3));
titleLayout.draw(canvas);
canvas.restore();
linkPreviewY += titleLayout.getLineBottom(titleLayout.getLineCount() - 1);
}
if (authorLayout != null) {
if (linkPreviewY != startY) {
linkPreviewY += AndroidUtilities.dp(2);
}
if (smallImageStartY == 0) {
smallImageStartY = linkPreviewY - AndroidUtilities.dp(1);
}
replyNamePaint.setColor(0xff000000);
canvas.save();
canvas.translate(textX + AndroidUtilities.dp(10), linkPreviewY - AndroidUtilities.dp(3));
authorLayout.draw(canvas);
canvas.restore();
linkPreviewY += authorLayout.getLineBottom(authorLayout.getLineCount() - 1);
}
if (descriptionLayout != null) {
if (linkPreviewY != startY) {
linkPreviewY += AndroidUtilities.dp(2);
}
if (smallImageStartY == 0) {
smallImageStartY = linkPreviewY - AndroidUtilities.dp(1);
}
replyTextPaint.setColor(0xff000000);
descriptionY = linkPreviewY - AndroidUtilities.dp(3);
canvas.save();
canvas.translate(textX + AndroidUtilities.dp(10), descriptionY);
if (pressedLink != null && linkBlockNum == -10) {
canvas.drawPath(urlPath, urlPaint);
}
descriptionLayout.draw(canvas);
canvas.restore();
linkPreviewY += descriptionLayout.getLineBottom(descriptionLayout.getLineCount() - 1);
}
if (drawLinkImageView) {
if (linkPreviewY != startY) {
linkPreviewY += AndroidUtilities.dp(2);
}
if (isSmallImage) {
linkImageView.setImageCoords(textX + smallImageX + AndroidUtilities.dp(12), smallImageStartY, linkImageView.getImageWidth(), linkImageView.getImageHeight());
} else {
linkImageView.setImageCoords(textX + AndroidUtilities.dp(10), linkPreviewY, linkImageView.getImageWidth(), linkImageView.getImageHeight());
}
linkImageView.draw(canvas);
if (isInstagram && igvideoDrawable != null) {
int x = linkImageView.getImageX() + linkImageView.getImageWidth() - igvideoDrawable.getIntrinsicWidth() - AndroidUtilities.dp(4);
int y = linkImageView.getImageY() + AndroidUtilities.dp(4);
igvideoDrawable.setBounds(x, y, x + igvideoDrawable.getIntrinsicWidth(), y + igvideoDrawable.getIntrinsicHeight());
igvideoDrawable.draw(canvas);
}
if (durationLayout != null) {
int x = linkImageView.getImageX() + linkImageView.getImageWidth() - AndroidUtilities.dp(8) - durationWidth;
int y = linkImageView.getImageY() + linkImageView.getImageHeight() - AndroidUtilities.dp(19);
mediaBackgroundDrawable.setBounds(x - AndroidUtilities.dp(4), y - AndroidUtilities.dp(1.5f), x + durationWidth + AndroidUtilities.dp(4), y + AndroidUtilities.dp(14.5f));
mediaBackgroundDrawable.draw(canvas);
canvas.save();
canvas.translate(x, y);
durationLayout.draw(canvas);
canvas.restore();
}
}
}
}
}

View File

@ -12,7 +12,6 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
@ -132,6 +131,7 @@ public class DialogCell extends BaseCell {
messagePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
messagePaint.setTextSize(AndroidUtilities.dp(16));
messagePaint.setColor(0xff8f8f8f);
messagePaint.linkColor = 0xff8f8f8f;
linePaint = new Paint();
linePaint.setColor(0xffdcdcdc);
@ -341,9 +341,9 @@ public class DialogCell extends BaseCell {
}
}
checkMessage = false;
if (message.messageOwner.media != null && !(message.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
if (message.messageOwner.media != null && !message.isMediaEmpty()) {
currentMessagePaint = messagePrintingPaint;
messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=#4d83b3>%s:</font> <font color=#4d83b3>%s</font>", name, message.messageText)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>%s:</c> <c#ff4d83b3>%s</c>", name, message.messageText)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
} else {
if (message.messageOwner.message != null) {
String mess = message.messageOwner.message;
@ -351,12 +351,12 @@ public class DialogCell extends BaseCell {
mess = mess.substring(0, 150);
}
mess = mess.replace("\n", " ");
messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("<font color=#4d83b3>%s:</font> <font color=#808080>%s</font>", name, mess.replace("<", "&lt;").replace(">", "&gt;"))), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>%s:</c> <c#ff808080>%s</c>", name, mess.replace("<", "&lt;").replace(">", "&gt;"))), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
}
}
} else {
messageString = message.messageText;
if (message.messageOwner.media != null && !(message.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
if (message.messageOwner.media != null && !message.isMediaEmpty()) {
currentMessagePaint = messagePrintingPaint;
}
}
@ -370,7 +370,7 @@ public class DialogCell extends BaseCell {
drawCount = false;
}
if (message.isOut() && message.isOut()) {
if (message.isOut()) {
if (message.isSending()) {
drawCheck1 = false;
drawCheck2 = false;

View File

@ -58,7 +58,7 @@ public class DrawerProfileCell extends FrameLayout {
shadowView.setLayoutParams(layoutParams);
avatarImageView = new BackupImageView(context);
avatarImageView.imageReceiver.setRoundRadius(AndroidUtilities.dp(32));
avatarImageView.getImageReceiver().setRoundRadius(AndroidUtilities.dp(32));
addView(avatarImageView);
layoutParams = (LayoutParams) avatarImageView.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(64);

View File

@ -37,7 +37,7 @@ public class MentionCell extends LinearLayout {
avatarDrawable.setSmallStyle(true);
imageView = new BackupImageView(context);
imageView.imageReceiver.setRoundRadius(AndroidUtilities.dp(14));
imageView.setRoundRadius(AndroidUtilities.dp(14));
addView(imageView);
LayoutParams layoutParams = (LayoutParams) imageView.getLayoutParams();
layoutParams.leftMargin = AndroidUtilities.dp(12);

View File

@ -117,7 +117,7 @@ public class PhotoPickerAlbumsCell extends FrameLayoutFixed {
for (int a = 0; a < 4; a++) {
albumViews[a] = new AlbumView(context);
addView(albumViews[a]);
albumViews[a].setVisibility(GONE);
albumViews[a].setVisibility(INVISIBLE);
albumViews[a].setTag(a);
albumViews[a].setOnClickListener(new OnClickListener() {
@Override
@ -132,7 +132,7 @@ public class PhotoPickerAlbumsCell extends FrameLayoutFixed {
public void setAlbumsCount(int count) {
for (int a = 0; a < albumViews.length; a++) {
albumViews[a].setVisibility(a < count ? VISIBLE : GONE);
albumViews[a].setVisibility(a < count ? VISIBLE : INVISIBLE);
}
albumsCount = count;
}
@ -156,7 +156,7 @@ public class PhotoPickerAlbumsCell extends FrameLayoutFixed {
albumView.nameTextView.setText(albumEntry.bucketName);
albumView.countTextView.setText(String.format("%d", albumEntry.photos.size()));
} else {
albumViews[a].setVisibility(GONE);
albumViews[a].setVisibility(INVISIBLE);
}
}

View File

@ -30,6 +30,7 @@ import org.telegram.messenger.UserConfig;
import org.telegram.ui.Components.AvatarDrawable;
public class ProfileSearchCell extends BaseCell {
private static TextPaint namePaint;
private static TextPaint nameEncryptedPaint;
private static TextPaint onlinePaint;

View File

@ -0,0 +1,205 @@
/*
* This is the source code of Telegram for Android v. 2.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-2015.
*/
package org.telegram.ui.Cells;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import java.util.Locale;
public class SessionCell extends FrameLayout {
private TextView nameTextView;
private TextView onlineTextView;
private TextView detailTextView;
private TextView detailExTextView;
boolean needDivider;
private static Paint paint;
public SessionCell(Context context) {
super(context);
if (paint == null) {
paint = new Paint();
paint.setColor(0xffd9d9d9);
paint.setStrokeWidth(1);
}
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setWeightSum(1);
addView(linearLayout);
LayoutParams layoutParams = (LayoutParams) linearLayout.getLayoutParams();
layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = AndroidUtilities.dp(30);
layoutParams.leftMargin = AndroidUtilities.dp(17);
layoutParams.rightMargin = AndroidUtilities.dp(17);
layoutParams.topMargin = AndroidUtilities.dp(11);
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
linearLayout.setLayoutParams(layoutParams);
nameTextView = new TextView(context);
nameTextView.setTextColor(0xff212121);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
nameTextView.setLines(1);
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
nameTextView.setMaxLines(1);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
onlineTextView = new TextView(context);
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
onlineTextView.setGravity((LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP);
if (LocaleController.isRTL) {
linearLayout.addView(onlineTextView);
linearLayout.addView(nameTextView);
} else {
linearLayout.addView(nameTextView);
linearLayout.addView(onlineTextView);
}
LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) nameTextView.getLayoutParams();
layoutParams2.width = 0;
layoutParams2.height = LayoutParams.MATCH_PARENT;
layoutParams2.weight = 1;
if (LocaleController.isRTL) {
layoutParams2.leftMargin = AndroidUtilities.dp(10);
} else {
layoutParams2.rightMargin = AndroidUtilities.dp(10);
}
layoutParams2.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
nameTextView.setLayoutParams(layoutParams2);
layoutParams2 = (LinearLayout.LayoutParams) onlineTextView.getLayoutParams();
layoutParams2.width = LayoutParams.WRAP_CONTENT;
layoutParams2.height = LayoutParams.MATCH_PARENT;
layoutParams2.topMargin = AndroidUtilities.dp(2);
layoutParams2.gravity = (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP;
onlineTextView.setLayoutParams(layoutParams2);
detailTextView = new TextView(context);
detailTextView.setTextColor(0xff212121);
detailTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
detailTextView.setLines(1);
detailTextView.setMaxLines(1);
detailTextView.setSingleLine(true);
detailTextView.setEllipsize(TextUtils.TruncateAt.END);
detailTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
addView(detailTextView);
layoutParams = (LayoutParams) detailTextView.getLayoutParams();
layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(17);
layoutParams.rightMargin = AndroidUtilities.dp(17);
layoutParams.topMargin = AndroidUtilities.dp(36);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
detailTextView.setLayoutParams(layoutParams);
detailExTextView = new TextView(context);
detailExTextView.setTextColor(0xff999999);
detailExTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
detailExTextView.setLines(1);
detailExTextView.setMaxLines(1);
detailExTextView.setSingleLine(true);
detailExTextView.setEllipsize(TextUtils.TruncateAt.END);
detailExTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
addView(detailExTextView);
layoutParams = (LayoutParams) detailExTextView.getLayoutParams();
layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(17);
layoutParams.rightMargin = AndroidUtilities.dp(17);
layoutParams.topMargin = AndroidUtilities.dp(59);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
detailExTextView.setLayoutParams(layoutParams);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(90) + (needDivider ? 1 : 0), MeasureSpec.EXACTLY));
}
public void setSession(TLRPC.TL_authorization session, boolean divider) {
needDivider = divider;
nameTextView.setText(String.format(Locale.US, "%s %s", session.app_name, session.app_version));
if ((session.flags & 1) != 0) {
onlineTextView.setText(LocaleController.getString("Online", R.string.Online));
onlineTextView.setTextColor(0xff2f8cc9);
} else {
onlineTextView.setText(LocaleController.stringForMessageListDate(session.date_active));
onlineTextView.setTextColor(0xff999999);
}
StringBuilder stringBuilder = new StringBuilder();
if (session.ip.length() != 0) {
stringBuilder.append(session.ip);
}
if (session.country.length() != 0) {
if (stringBuilder.length() != 0) {
stringBuilder.append(" ");
}
stringBuilder.append("");
stringBuilder.append(session.country);
}
detailExTextView.setText(stringBuilder);
stringBuilder = new StringBuilder();
if (session.device_model.length() != 0) {
stringBuilder.append(session.device_model);
}
if (session.system_version.length() != 0 || session.platform.length() != 0) {
if (stringBuilder.length() != 0) {
stringBuilder.append(", ");
}
if (session.platform.length() != 0) {
stringBuilder.append(session.platform);
}
if (session.system_version.length() != 0) {
if (session.platform.length() != 0) {
stringBuilder.append(" ");
}
stringBuilder.append(session.system_version);
}
}
if ((session.flags & 2) == 0) {
if (stringBuilder.length() != 0) {
stringBuilder.append(", ");
}
stringBuilder.append(LocaleController.getString("UnofficialApp", R.string.UnofficialApp));
stringBuilder.append(" (ID: ");
stringBuilder.append(session.api_id);
stringBuilder.append(")");
}
detailTextView.setText(stringBuilder);
}
@Override
protected void onDraw(Canvas canvas) {
if (needDivider) {
canvas.drawLine(getPaddingLeft(), getHeight() - 1, getWidth() - getPaddingRight(), getHeight() - 1, paint);
}
}
}

View File

@ -106,11 +106,11 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
extTextView.setLayoutParams(layoutParams);
thumbImageView = new BackupImageView(context);
thumbImageView.imageReceiver.setDelegate(new ImageReceiver.ImageReceiverDelegate() {
thumbImageView.getImageReceiver().setDelegate(new ImageReceiver.ImageReceiverDelegate() {
@Override
public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb) {
extTextView.setVisibility(set ? GONE : VISIBLE);
placeholderImabeView.setVisibility(set ? GONE : VISIBLE);
extTextView.setVisibility(set ? INVISIBLE : VISIBLE);
placeholderImabeView.setVisibility(set ? INVISIBLE : VISIBLE);
}
});
addView(thumbImageView);
@ -143,7 +143,7 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
nameTextView.setLayoutParams(layoutParams);
statusImageView = new ImageView(context);
statusImageView.setVisibility(GONE);
statusImageView.setVisibility(INVISIBLE);
addView(statusImageView);
layoutParams = (LayoutParams) statusImageView.getLayoutParams();
layoutParams.width = LayoutParams.WRAP_CONTENT;
@ -184,7 +184,7 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
progressView.setLayoutParams(layoutParams);
checkBox = new CheckBox(context, R.drawable.round_check2);
checkBox.setVisibility(GONE);
checkBox.setVisibility(INVISIBLE);
addView(checkBox);
layoutParams = (LayoutParams) checkBox.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(22);
@ -229,13 +229,13 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
extTextView.setVisibility(VISIBLE);
extTextView.setText(type);
} else {
extTextView.setVisibility(GONE);
extTextView.setVisibility(INVISIBLE);
}
if (resId == 0) {
placeholderImabeView.setImageResource(getThumbForNameOrMime(text, type));
placeholderImabeView.setVisibility(VISIBLE);
} else {
placeholderImabeView.setVisibility(GONE);
placeholderImabeView.setVisibility(INVISIBLE);
}
if (thumb != null || resId != 0) {
if (thumb != null) {
@ -245,7 +245,7 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
}
thumbImageView.setVisibility(VISIBLE);
} else {
thumbImageView.setVisibility(GONE);
thumbImageView.setVisibility(INVISIBLE);
}
}
@ -277,7 +277,7 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
nameTextView.setText(name);
extTextView.setText((idx = name.lastIndexOf(".")) == -1 ? "" : name.substring(idx + 1).toLowerCase());
if (document.messageOwner.media.document.thumb instanceof TLRPC.TL_photoSizeEmpty) {
thumbImageView.setVisibility(GONE);
thumbImageView.setVisibility(INVISIBLE);
thumbImageView.setImageBitmap(null);
} else {
thumbImageView.setVisibility(VISIBLE);
@ -291,7 +291,7 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
dateTextView.setText("");
placeholderImabeView.setVisibility(VISIBLE);
extTextView.setVisibility(VISIBLE);
thumbImageView.setVisibility(GONE);
thumbImageView.setVisibility(INVISIBLE);
thumbImageView.setImageBitmap(null);
}
@ -312,7 +312,7 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
}
loaded = false;
if (fileName == null) {
statusImageView.setVisibility(GONE);
statusImageView.setVisibility(INVISIBLE);
dateTextView.setPadding(0, 0, 0, 0);
loading = false;
loaded = true;
@ -331,15 +331,15 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.
}
progressView.setProgress(progress, false);
} else {
progressView.setVisibility(GONE);
progressView.setVisibility(INVISIBLE);
}
}
} else {
loading = false;
loaded = true;
progressView.setVisibility(GONE);
progressView.setVisibility(INVISIBLE);
progressView.setProgress(0, false);
statusImageView.setVisibility(GONE);
statusImageView.setVisibility(INVISIBLE);
dateTextView.setPadding(0, 0, 0, 0);
MediaController.getInstance().removeLoadingFileObserver(this);
}

View File

@ -55,8 +55,8 @@ public class SharedPhotoVideoCell extends FrameLayoutFixed {
super(context);
imageView = new BackupImageView(context);
imageView.imageReceiver.setNeedsQualityThumb(true);
imageView.imageReceiver.setShouldGenerateQualityThumb(true);
imageView.getImageReceiver().setNeedsQualityThumb(true);
imageView.getImageReceiver().setShouldGenerateQualityThumb(true);
addView(imageView);
LayoutParams layoutParams = (LayoutParams) imageView.getLayoutParams();
layoutParams.width = LayoutParams.MATCH_PARENT;
@ -105,7 +105,7 @@ public class SharedPhotoVideoCell extends FrameLayoutFixed {
selector.setLayoutParams(layoutParams);
checkBox = new CheckBox(context, R.drawable.round_check2);
checkBox.setVisibility(GONE);
checkBox.setVisibility(INVISIBLE);
addView(checkBox);
layoutParams = (LayoutParams) checkBox.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(22);
@ -134,7 +134,7 @@ public class SharedPhotoVideoCell extends FrameLayoutFixed {
for (int a = 0; a < 6; a++) {
photoVideoViews[a] = new PhotoVideoView(context);
addView(photoVideoViews[a]);
photoVideoViews[a].setVisibility(GONE);
photoVideoViews[a].setVisibility(INVISIBLE);
photoVideoViews[a].setTag(a);
photoVideoViews[a].setOnClickListener(new OnClickListener() {
@Override
@ -164,7 +164,7 @@ public class SharedPhotoVideoCell extends FrameLayoutFixed {
public void setItemsCount(int count) {
for (int a = 0; a < photoVideoViews.length; a++) {
photoVideoViews[a].setVisibility(a < count ? VISIBLE : GONE);
photoVideoViews[a].setVisibility(a < count ? VISIBLE : INVISIBLE);
}
itemsCount = count;
}
@ -202,8 +202,8 @@ public class SharedPhotoVideoCell extends FrameLayoutFixed {
photoVideoViews[a].setVisibility(VISIBLE);
PhotoVideoView photoVideoView = photoVideoViews[a];
photoVideoView.imageView.imageReceiver.setParentMessageObject(messageObject);
photoVideoView.imageView.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(messageObject), false);
photoVideoView.imageView.getImageReceiver().setParentMessageObject(messageObject);
photoVideoView.imageView.getImageReceiver().setVisible(!PhotoViewer.getInstance().isShowingImage(messageObject), false);
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVideo && messageObject.messageOwner.media.video != null) {
photoVideoView.videoInfoContainer.setVisibility(VISIBLE);
int duration = messageObject.messageOwner.media.video.duration;
@ -217,15 +217,15 @@ public class SharedPhotoVideoCell extends FrameLayoutFixed {
photoVideoView.imageView.setImageResource(R.drawable.photo_placeholder_in);
}
} else if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && messageObject.messageOwner.media.photo != null && !messageObject.photoThumbs.isEmpty()) {
photoVideoView.videoInfoContainer.setVisibility(GONE);
photoVideoView.videoInfoContainer.setVisibility(INVISIBLE);
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 80);
photoVideoView.imageView.setImage(null, null, null, ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.photo_placeholder_in), null, photoSize.location, "b", 0);
} else {
photoVideoView.videoInfoContainer.setVisibility(GONE);
photoVideoView.videoInfoContainer.setVisibility(INVISIBLE);
photoVideoView.imageView.setImageResource(R.drawable.photo_placeholder_in);
}
} else {
photoVideoViews[a].setVisibility(GONE);
photoVideoViews[a].setVisibility(INVISIBLE);
messageObjects[a] = null;
}
}

View File

@ -26,9 +26,7 @@ public class StickerCell extends FrameLayoutFixed {
super(context);
imageView = new BackupImageView(context);
imageView.imageReceiver.setAspectFit(true);
imageView.imageReceiver.setDisableRecycle(true);
imageView.processDetach = false;
imageView.setAspectFit(true);
addView(imageView);
LayoutParams layoutParams = (LayoutParams) imageView.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(66);
@ -45,8 +43,8 @@ public class StickerCell extends FrameLayoutFixed {
@Override
public void setPressed(boolean pressed) {
if (imageView.imageReceiver.getPressed() != pressed) {
imageView.imageReceiver.setPressed(pressed);
if (imageView.getImageReceiver().getPressed() != pressed) {
imageView.getImageReceiver().setPressed(pressed);
imageView.invalidate();
}
super.setPressed(pressed);

View File

@ -97,32 +97,32 @@ public class TextCell extends FrameLayout {
public void setText(String text) {
textView.setText(text);
imageView.setVisibility(GONE);
valueTextView.setVisibility(GONE);
valueImageView.setVisibility(GONE);
imageView.setVisibility(INVISIBLE);
valueTextView.setVisibility(INVISIBLE);
valueImageView.setVisibility(INVISIBLE);
}
public void setTextAndIcon(String text, int resId) {
textView.setText(text);
imageView.setImageResource(resId);
imageView.setVisibility(VISIBLE);
valueTextView.setVisibility(GONE);
valueImageView.setVisibility(GONE);
valueTextView.setVisibility(INVISIBLE);
valueImageView.setVisibility(INVISIBLE);
}
public void setTextAndValue(String text, String value) {
textView.setText(text);
valueTextView.setText(value);
valueTextView.setVisibility(VISIBLE);
imageView.setVisibility(GONE);
valueImageView.setVisibility(GONE);
imageView.setVisibility(INVISIBLE);
valueImageView.setVisibility(INVISIBLE);
}
public void setTextAndValueDrawable(String text, Drawable drawable) {
textView.setText(text);
valueImageView.setVisibility(VISIBLE);
valueImageView.setImageDrawable(drawable);
valueTextView.setVisibility(GONE);
imageView.setVisibility(GONE);
valueTextView.setVisibility(INVISIBLE);
imageView.setVisibility(INVISIBLE);
}
}

View File

@ -82,7 +82,7 @@ public class TextDetailCell extends FrameLayout {
public void setTextAndValue(String text, String value) {
textView.setText(text);
valueTextView.setText(value);
imageView.setVisibility(GONE);
imageView.setVisibility(INVISIBLE);
}
public void setTextAndValueAndIcon(String text, String value, int resId) {

View File

@ -1,104 +0,0 @@
/*
* This is the source code of Telegram for Android v. 2.0.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.
*/
package org.telegram.ui.Cells;
import android.content.Context;
import android.graphics.Typeface;
import android.text.InputType;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
public class TextFieldCell extends LinearLayout {
private TextView textView;
private EditText editText;
public TextFieldCell(Context context) {
super(context);
setOrientation(VERTICAL);
textView = new TextView(context);
textView.setTextColor(0xff505050);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
addView(textView);
LayoutParams layoutParams = (LayoutParams) textView.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(17);
layoutParams.height = LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(17);
layoutParams.rightMargin = AndroidUtilities.dp(17);
layoutParams.width = LayoutParams.MATCH_PARENT;
textView.setLayoutParams(layoutParams);
editText = new EditText(context);
editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
editText.setHintTextColor(0xffbebebe);
editText.setTextColor(0xff212121);
editText.setMaxLines(1);
editText.setLines(1);
editText.setSingleLine(true);
editText.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
AndroidUtilities.clearCursorDrawable(editText);
addView(editText);
layoutParams = (LayoutParams) editText.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(10);
layoutParams.bottomMargin = AndroidUtilities.dp(17);
layoutParams.height = AndroidUtilities.dp(30);
layoutParams.leftMargin = AndroidUtilities.dp(17);
layoutParams.rightMargin = AndroidUtilities.dp(17);
layoutParams.width = LayoutParams.MATCH_PARENT;
editText.setLayoutParams(layoutParams);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE) {
textView.clearFocus();
AndroidUtilities.hideKeyboard(textView);
return true;
}
return false;
}
});
}
public void setFieldText(String text) {
editText.setText(text);
}
public String getFieldText() {
return editText.getText().toString();
}
public void setFieldTitleAndHint(String title, String hint, int bottom, boolean password) {
editText.setHint(hint);
LayoutParams layoutParams = (LayoutParams) editText.getLayoutParams();
layoutParams.bottomMargin = bottom;
editText.setLayoutParams(layoutParams);
if (password) {
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
editText.setTypeface(Typeface.DEFAULT);
} else {
editText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
}
if (title != null) {
textView.setText(title);
textView.setVisibility(VISIBLE);
} else {
textView.setVisibility(GONE);
}
}
}

View File

@ -25,10 +25,10 @@ public class TextInfoPrivacyCell extends FrameLayout {
super(context);
textView = new TextView(context);
textView.setTextColor(0xffa3a3a3);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
textView.setTextColor(0xff808080);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
textView.setPadding(0, AndroidUtilities.dp(6), 0, AndroidUtilities.dp(16));
textView.setPadding(0, AndroidUtilities.dp(10), 0, AndroidUtilities.dp(17));
addView(textView);
LayoutParams layoutParams = (LayoutParams) textView.getLayoutParams();
layoutParams.width = LayoutParams.WRAP_CONTENT;

View File

@ -74,7 +74,7 @@ public class TextSettingsCell extends FrameLayout {
valueImageView = new ImageView(context);
valueImageView.setScaleType(ImageView.ScaleType.CENTER);
valueImageView.setVisibility(GONE);
valueImageView.setVisibility(INVISIBLE);
addView(valueImageView);
layoutParams = (LayoutParams) valueImageView.getLayoutParams();
layoutParams.width = LayoutParams.WRAP_CONTENT;
@ -109,20 +109,20 @@ public class TextSettingsCell extends FrameLayout {
public void setText(String text, boolean divider) {
textView.setText(text);
valueTextView.setVisibility(GONE);
valueImageView.setVisibility(GONE);
valueTextView.setVisibility(INVISIBLE);
valueImageView.setVisibility(INVISIBLE);
needDivider = divider;
setWillNotDraw(!divider);
}
public void setTextAndValue(String text, String value, boolean divider) {
textView.setText(text);
valueImageView.setVisibility(GONE);
valueImageView.setVisibility(INVISIBLE);
if (value != null) {
valueTextView.setText(value);
valueTextView.setVisibility(VISIBLE);
} else {
valueTextView.setVisibility(GONE);
valueTextView.setVisibility(INVISIBLE);
}
needDivider = divider;
setWillNotDraw(!divider);
@ -130,12 +130,12 @@ public class TextSettingsCell extends FrameLayout {
public void setTextAndIcon(String text, int resId, boolean divider) {
textView.setText(text);
valueTextView.setVisibility(GONE);
valueTextView.setVisibility(INVISIBLE);
if (resId != 0) {
valueImageView.setVisibility(VISIBLE);
valueImageView.setImageResource(resId);
} else {
valueImageView.setVisibility(GONE);
valueImageView.setVisibility(INVISIBLE);
}
needDivider = divider;
setWillNotDraw(!divider);

View File

@ -54,7 +54,7 @@ public class UserCell extends FrameLayout {
super(context);
avatarImageView = new BackupImageView(context);
avatarImageView.imageReceiver.setRoundRadius(AndroidUtilities.dp(24));
avatarImageView.setRoundRadius(AndroidUtilities.dp(24));
addView(avatarImageView);
LayoutParams layoutParams = (LayoutParams) avatarImageView.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(48);
@ -113,7 +113,7 @@ public class UserCell extends FrameLayout {
imageView.setLayoutParams(layoutParams);
checkBox = new CheckBox(context, R.drawable.round_check2);
checkBox.setVisibility(GONE);
checkBox.setVisibility(INVISIBLE);
addView(checkBox);
layoutParams = (LayoutParams) checkBox.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(22);
@ -228,7 +228,7 @@ public class UserCell extends FrameLayout {
}
}
imageView.setVisibility(currentDrawable == 0 ? GONE : VISIBLE);
imageView.setVisibility(currentDrawable == 0 ? INVISIBLE : VISIBLE);
imageView.setImageResource(currentDrawable);
avatarImageView.setImage(photo, "50_50", avatarDrawable);
}

View File

@ -9,6 +9,7 @@
package org.telegram.ui;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.InputType;
@ -55,9 +56,7 @@ public class ChangeChatNameActivity extends BaseFragment {
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("EditName", R.string.EditName));
@ -80,7 +79,7 @@ public class ChangeChatNameActivity extends BaseFragment {
TLRPC.Chat currentChat = MessagesController.getInstance().getChat(chat_id);
fragmentView = new LinearLayout(getParentActivity());
fragmentView = new LinearLayout(context);
fragmentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@ -90,7 +89,7 @@ public class ChangeChatNameActivity extends BaseFragment {
}
});
firstNameField = new EditText(getParentActivity());
firstNameField = new EditText(context);
firstNameField.setText(currentChat.title);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
@ -114,7 +113,7 @@ public class ChangeChatNameActivity extends BaseFragment {
});
((LinearLayout) fragmentView).addView(firstNameField);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)firstNameField.getLayoutParams();
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) firstNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(24);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
@ -128,12 +127,7 @@ public class ChangeChatNameActivity extends BaseFragment {
firstNameField.setHint(LocaleController.getString("EnterListName", R.string.EnterListName));
}
firstNameField.setSelection(firstNameField.length());
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -9,6 +9,7 @@
package org.telegram.ui;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.InputType;
import android.util.TypedValue;
@ -48,8 +49,7 @@ public class ChangeNameActivity extends BaseFragment {
private final static int done_button = 1;
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("EditName", R.string.EditName));
@ -75,7 +75,7 @@ public class ChangeNameActivity extends BaseFragment {
user = UserConfig.getCurrentUser();
}
fragmentView = new LinearLayout(getParentActivity());
fragmentView = new LinearLayout(context);
fragmentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@ -85,7 +85,7 @@ public class ChangeNameActivity extends BaseFragment {
}
});
firstNameField = new EditText(getParentActivity());
firstNameField = new EditText(context);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
firstNameField.setTextColor(0xff212121);
@ -98,7 +98,7 @@ public class ChangeNameActivity extends BaseFragment {
firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName));
AndroidUtilities.clearCursorDrawable(firstNameField);
((LinearLayout) fragmentView).addView(firstNameField);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)firstNameField.getLayoutParams();
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) firstNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(24);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
@ -117,7 +117,7 @@ public class ChangeNameActivity extends BaseFragment {
}
});
lastNameField = new EditText(getParentActivity());
lastNameField = new EditText(context);
lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
lastNameField.setHintTextColor(0xff979797);
lastNameField.setTextColor(0xff212121);
@ -130,7 +130,7 @@ public class ChangeNameActivity extends BaseFragment {
lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName));
AndroidUtilities.clearCursorDrawable(lastNameField);
((LinearLayout) fragmentView).addView(lastNameField);
layoutParams = (LinearLayout.LayoutParams)lastNameField.getLayoutParams();
layoutParams = (LinearLayout.LayoutParams) lastNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(16);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
@ -153,12 +153,7 @@ public class ChangeNameActivity extends BaseFragment {
firstNameField.setSelection(firstNameField.length());
lastNameField.setText(user.last_name);
}
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -25,7 +25,6 @@ import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.inputmethod.EditorInfo;
@ -101,8 +100,7 @@ public class ChangePhoneActivity extends BaseFragment {
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@ -119,11 +117,11 @@ public class ChangePhoneActivity extends BaseFragment {
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
fragmentView = new ScrollView(getParentActivity());
fragmentView = new ScrollView(context);
ScrollView scrollView = (ScrollView) fragmentView;
scrollView.setFillViewport(true);
FrameLayout frameLayout = new FrameLayout(getParentActivity());
FrameLayout frameLayout = new FrameLayout(context);
scrollView.addView(frameLayout);
ScrollView.LayoutParams layoutParams = (ScrollView.LayoutParams) frameLayout.getLayoutParams();
layoutParams.width = ScrollView.LayoutParams.MATCH_PARENT;
@ -131,7 +129,7 @@ public class ChangePhoneActivity extends BaseFragment {
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
frameLayout.setLayoutParams(layoutParams);
views[0] = new PhoneView(getParentActivity());
views[0] = new PhoneView(context);
views[0].setVisibility(View.VISIBLE);
frameLayout.addView(views[0]);
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) views[0].getLayoutParams();
@ -143,7 +141,7 @@ public class ChangePhoneActivity extends BaseFragment {
layoutParams1.gravity = Gravity.TOP | Gravity.LEFT;
views[0].setLayoutParams(layoutParams1);
views[1] = new LoginActivitySmsView(getParentActivity());
views[1] = new LoginActivitySmsView(context);
views[1].setVisibility(View.GONE);
frameLayout.addView(views[1]);
layoutParams1 = (FrameLayout.LayoutParams) views[1].getLayoutParams();
@ -157,10 +155,10 @@ public class ChangePhoneActivity extends BaseFragment {
try {
if (views[0] == null || views[1] == null) {
FrameLayout parent = (FrameLayout)((ScrollView) fragmentView).getChildAt(0);
FrameLayout parent = (FrameLayout) ((ScrollView) fragmentView).getChildAt(0);
for (int a = 0; a < views.length; a++) {
if (views[a] == null) {
views[a] = (SlideView)parent.getChildAt(a);
views[a] = (SlideView) parent.getChildAt(a);
}
}
}
@ -169,12 +167,7 @@ public class ChangePhoneActivity extends BaseFragment {
}
actionBar.setTitle(views[0].getHeaderName());
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -9,13 +9,13 @@
package org.telegram.ui;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
@ -35,8 +35,7 @@ import org.telegram.ui.ActionBar.BaseFragment;
public class ChangePhoneHelpActivity extends BaseFragment {
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
@ -58,7 +57,7 @@ public class ChangePhoneHelpActivity extends BaseFragment {
}
});
fragmentView = new RelativeLayout(getParentActivity());
fragmentView = new RelativeLayout(context);
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
@ -68,7 +67,7 @@ public class ChangePhoneHelpActivity extends BaseFragment {
RelativeLayout relativeLayout = (RelativeLayout) fragmentView;
ScrollView scrollView = new ScrollView(getParentActivity());
ScrollView scrollView = new ScrollView(context);
relativeLayout.addView(scrollView);
RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) scrollView.getLayoutParams();
layoutParams3.width = RelativeLayout.LayoutParams.MATCH_PARENT;
@ -76,7 +75,7 @@ public class ChangePhoneHelpActivity extends BaseFragment {
layoutParams3.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
scrollView.setLayoutParams(layoutParams3);
LinearLayout linearLayout = new LinearLayout(getParentActivity());
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setPadding(0, AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20));
scrollView.addView(linearLayout);
@ -85,28 +84,28 @@ public class ChangePhoneHelpActivity extends BaseFragment {
layoutParams.height = ScrollView.LayoutParams.WRAP_CONTENT;
linearLayout.setLayoutParams(layoutParams);
ImageView imageView = new ImageView(getParentActivity());
ImageView imageView = new ImageView(context);
imageView.setImageResource(R.drawable.phone_change);
linearLayout.addView(imageView);
LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams)imageView.getLayoutParams();
LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams();
layoutParams2.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
imageView.setLayoutParams(layoutParams2);
TextView textView = new TextView(getParentActivity());
TextView textView = new TextView(context);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setTextColor(0xff212121);
try {
textView.setText(AndroidUtilities.replaceBold(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp)));
textView.setText(AndroidUtilities.replaceTags(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp)));
} catch (Exception e) {
FileLog.e("tmessages", e);
textView.setText(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp));
}
linearLayout.addView(textView);
layoutParams2 = (LinearLayout.LayoutParams)textView.getLayoutParams();
layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
layoutParams2.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
@ -115,7 +114,7 @@ public class ChangePhoneHelpActivity extends BaseFragment {
layoutParams2.topMargin = AndroidUtilities.dp(56);
textView.setLayoutParams(layoutParams2);
textView = new TextView(getParentActivity());
textView = new TextView(context);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setTextColor(0xff4d83b3);
@ -123,7 +122,7 @@ public class ChangePhoneHelpActivity extends BaseFragment {
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setPadding(0, AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10));
linearLayout.addView(textView);
layoutParams2 = (LinearLayout.LayoutParams)textView.getLayoutParams();
layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
layoutParams2.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
@ -152,12 +151,6 @@ public class ChangePhoneHelpActivity extends BaseFragment {
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
}

View File

@ -11,6 +11,7 @@ package org.telegram.ui;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.text.Editable;
@ -61,8 +62,7 @@ public class ChangeUsernameActivity extends BaseFragment {
private final static int done_button = 1;
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("Username", R.string.Username));
@ -85,7 +85,7 @@ public class ChangeUsernameActivity extends BaseFragment {
user = UserConfig.getCurrentUser();
}
fragmentView = new LinearLayout(getParentActivity());
fragmentView = new LinearLayout(context);
fragmentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@ -95,7 +95,7 @@ public class ChangeUsernameActivity extends BaseFragment {
}
});
firstNameField = new EditText(getParentActivity());
firstNameField = new EditText(context);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
firstNameField.setTextColor(0xff212121);
@ -120,7 +120,7 @@ public class ChangeUsernameActivity extends BaseFragment {
});
((LinearLayout) fragmentView).addView(firstNameField);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)firstNameField.getLayoutParams();
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) firstNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(24);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
@ -133,11 +133,11 @@ public class ChangeUsernameActivity extends BaseFragment {
firstNameField.setSelection(firstNameField.length());
}
checkTextView = new TextView(getParentActivity());
checkTextView = new TextView(context);
checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
checkTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
((LinearLayout) fragmentView).addView(checkTextView);
layoutParams = (LinearLayout.LayoutParams)checkTextView.getLayoutParams();
layoutParams = (LinearLayout.LayoutParams) checkTextView.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(12);
layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
@ -146,13 +146,13 @@ public class ChangeUsernameActivity extends BaseFragment {
layoutParams.rightMargin = AndroidUtilities.dp(24);
checkTextView.setLayoutParams(layoutParams);
TextView helpTextView = new TextView(getParentActivity());
TextView helpTextView = new TextView(context);
helpTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
helpTextView.setTextColor(0xff6d6d72);
helpTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
helpTextView.setText(Html.fromHtml(LocaleController.getString("UsernameHelp", R.string.UsernameHelp)));
helpTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("UsernameHelp", R.string.UsernameHelp)));
((LinearLayout) fragmentView).addView(helpTextView);
layoutParams = (LinearLayout.LayoutParams)helpTextView.getLayoutParams();
layoutParams = (LinearLayout.LayoutParams) helpTextView.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(10);
layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
@ -179,12 +179,7 @@ public class ChangeUsernameActivity extends BaseFragment {
});
checkTextView.setVisibility(View.GONE);
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

File diff suppressed because it is too large Load Diff

View File

@ -35,6 +35,7 @@ import java.io.File;
import java.util.ArrayList;
public class AvatarUpdater implements NotificationCenter.NotificationCenterDelegate, PhotoCropActivity.PhotoEditActivityDelegate {
public String currentPicturePath;
private TLRPC.PhotoSize smallPhoto;
private TLRPC.PhotoSize bigPhoto;

View File

@ -20,10 +20,9 @@ import org.telegram.android.ImageReceiver;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
public class BackupImageView extends View {
public ImageReceiver imageReceiver;
public boolean processDetach = true;
private ImageReceiver imageReceiver;
public BackupImageView(Context context) {
super(context);
@ -91,13 +90,23 @@ public class BackupImageView extends View {
imageReceiver.setImageBitmap(drawable);
}
public void setRoundRadius(int value) {
imageReceiver.setRoundRadius(value);
}
public void setAspectFit(boolean value) {
imageReceiver.setAspectFit(value);
}
public ImageReceiver getImageReceiver() {
return imageReceiver;
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (processDetach) {
imageReceiver.clearImage();
}
}
@Override
protected void onDraw(Canvas canvas) {

View File

@ -61,7 +61,7 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
public interface ChatActivityEnterViewDelegate {
void onMessageSend(String message);
void needSendTyping();
void onTextChanged(CharSequence text);
void onTextChanged(CharSequence text, boolean bigChange);
void onAttachButtonHidden();
void onAttachButtonShow();
void onWindowSizeChanged(int size);
@ -104,11 +104,15 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
private long dialog_id;
private boolean ignoreTextChange;
private MessageObject replyingMessageObject;
private TLRPC.WebPage messageWebPage;
private boolean messageWebPageSearch;
private ChatActivityEnterViewDelegate delegate;
private float topViewAnimation;
private boolean topViewShowed;
private boolean needShowTopView;
private boolean allowShowTopView;
private AnimatorSetProxy currentTopViewAnimation;
public ChatActivityEnterView(Activity context, SizeNotifierRelativeLayout parent, BaseFragment fragment, boolean isChat) {
super(context);
@ -234,12 +238,15 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
String message = getTrimmedString(charSequence.toString());
checkSendButton(true);
if (delegate != null) {
delegate.onTextChanged(charSequence);
if (before > count || count > 1) {
messageWebPageSearch = true;
}
delegate.onTextChanged(charSequence, before > count || count > 1);
}
if (message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) {
@ -499,6 +506,7 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
}
public void setTopViewAnimation(float progress) {
topViewAnimation = progress;
LayoutParams layoutParams2 = (LayoutParams) textFieldContainer.getLayoutParams();
layoutParams2.topMargin = AndroidUtilities.dp(2) + (int) (topView.getLayoutParams().height * progress);
textFieldContainer.setLayoutParams(layoutParams2);
@ -514,75 +522,85 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
}
public void showTopView(boolean animated) {
if (topView == null) {
if (topView == null || topViewShowed) {
return;
}
needShowTopView = true;
topViewShowed = true;
if (allowShowTopView) {
topView.setVisibility(VISIBLE);
float resumeValue = 0.0f;
if (currentTopViewAnimation != null) {
resumeValue = topViewAnimation;
currentTopViewAnimation.cancel();
currentTopViewAnimation = null;
}
if (animated) {
if (keyboardVisible || emojiPopup != null && emojiPopup.isShowing()) {
AnimatorSetProxy animatorSetProxy = new AnimatorSetProxy();
animatorSetProxy.playTogether(
ObjectAnimatorProxy.ofFloat(ChatActivityEnterView.this, "topViewAnimation", 0.0f, 1.0f)
currentTopViewAnimation = new AnimatorSetProxy();
currentTopViewAnimation.playTogether(
ObjectAnimatorProxy.ofFloat(ChatActivityEnterView.this, "topViewAnimation", 1.0f)
);
animatorSetProxy.addListener(new AnimatorListenerAdapterProxy() {
currentTopViewAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Object animation) {
LayoutParams layoutParams2 = (LayoutParams) textFieldContainer.getLayoutParams();
layoutParams2.topMargin = AndroidUtilities.dp(2) + topView.getLayoutParams().height;
textFieldContainer.setLayoutParams(layoutParams2);
if (animation == currentTopViewAnimation) {
setTopViewAnimation(1.0f);
if (!forceShowSendButton) {
openKeyboard();
}
currentTopViewAnimation = null;
}
}
});
animatorSetProxy.setDuration(200);
animatorSetProxy.start();
currentTopViewAnimation.setDuration(200);
currentTopViewAnimation.start();
} else {
LayoutParams layoutParams2 = (LayoutParams) textFieldContainer.getLayoutParams();
layoutParams2.topMargin = AndroidUtilities.dp(2) + topView.getLayoutParams().height;
textFieldContainer.setLayoutParams(layoutParams2);
setTopViewAnimation(1.0f);
if (!forceShowSendButton) {
openKeyboard();
}
}
} else {
LayoutParams layoutParams2 = (LayoutParams) textFieldContainer.getLayoutParams();
layoutParams2.topMargin = AndroidUtilities.dp(2) + topView.getLayoutParams().height;
textFieldContainer.setLayoutParams(layoutParams2);
setTopViewAnimation(1.0f);
}
}
}
public void hideTopView(boolean animated) {
if (topView == null) {
public void hideTopView(final boolean animated) {
if (topView == null || !topViewShowed) {
return;
}
topViewShowed = false;
needShowTopView = false;
if (allowShowTopView) {
float resumeValue = 1.0f;
if (currentTopViewAnimation != null) {
resumeValue = topViewAnimation;
currentTopViewAnimation.cancel();
currentTopViewAnimation = null;
}
if (animated) {
AnimatorSetProxy animatorSetProxy = new AnimatorSetProxy();
animatorSetProxy.playTogether(
ObjectAnimatorProxy.ofFloat(ChatActivityEnterView.this, "topViewAnimation", 1.0f, 0.0f)
currentTopViewAnimation = new AnimatorSetProxy();
currentTopViewAnimation.playTogether(
ObjectAnimatorProxy.ofFloat(ChatActivityEnterView.this, "topViewAnimation", resumeValue, 0.0f)
);
animatorSetProxy.addListener(new AnimatorListenerAdapterProxy() {
currentTopViewAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Object animation) {
if (animation == currentTopViewAnimation) {
topView.setVisibility(GONE);
LayoutParams layoutParams2 = (LayoutParams) textFieldContainer.getLayoutParams();
layoutParams2.topMargin = AndroidUtilities.dp(2);
textFieldContainer.setLayoutParams(layoutParams2);
setTopViewAnimation(0.0f);
currentTopViewAnimation = null;
}
}
});
animatorSetProxy.setDuration(200);
animatorSetProxy.start();
currentTopViewAnimation.setDuration(200);
currentTopViewAnimation.start();
} else {
topView.setVisibility(GONE);
LayoutParams layoutParams2 = (LayoutParams) textFieldContainer.getLayoutParams();
layoutParams2.topMargin = AndroidUtilities.dp(2);
textFieldContainer.setLayoutParams(layoutParams2);
setTopViewAnimation(0.0f);
}
}
}
@ -601,9 +619,7 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
allowShowTopView = false;
if (needShowTopView) {
topView.setVisibility(View.GONE);
LayoutParams layoutParams2 = (LayoutParams) textFieldContainer.getLayoutParams();
layoutParams2.topMargin = AndroidUtilities.dp(2);
textFieldContainer.setLayoutParams(layoutParams2);
setTopViewAnimation(0.0f);
}
}
} else {
@ -611,9 +627,7 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
allowShowTopView = true;
if (needShowTopView) {
topView.setVisibility(View.VISIBLE);
LayoutParams layoutParams2 = (LayoutParams) textFieldContainer.getLayoutParams();
layoutParams2.topMargin = AndroidUtilities.dp(2) + topView.getLayoutParams().height;
textFieldContainer.setLayoutParams(layoutParams2);
setTopViewAnimation(1.0f);
}
}
}
@ -651,6 +665,11 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
replyingMessageObject = messageObject;
}
public void setWebPage(TLRPC.WebPage webPage, boolean searchWebPages) {
messageWebPage = webPage;
messageWebPageSearch = searchWebPages;
}
private void sendMessage() {
if (parentFragment != null) {
String action = null;
@ -689,7 +708,7 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
int count = (int) Math.ceil(text.length() / 4096.0f);
for (int a = 0; a < count; a++) {
String mess = text.substring(a * 4096, Math.min((a + 1) * 4096, text.length()));
SendMessagesHelper.getInstance().sendMessage(mess, dialog_id, replyingMessageObject);
SendMessagesHelper.getInstance().sendMessage(mess, dialog_id, replyingMessageObject, messageWebPage, messageWebPageSearch);
}
return true;
}
@ -1107,7 +1126,7 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
messageEditText.setSelection(messageEditText.getText().length());
ignoreTextChange = false;
if (delegate != null) {
delegate.onTextChanged(messageEditText.getText());
delegate.onTextChanged(messageEditText.getText(), true);
}
}

View File

@ -22,6 +22,7 @@ import org.telegram.messenger.FileLog;
import org.telegram.ui.AnimationCompat.ViewProxy;
public class ClippingImageView extends View {
private int clipBottom;
private int clipLeft;
private int clipRight;
@ -79,7 +80,7 @@ public class ClippingImageView extends View {
}
public void onDraw(Canvas canvas) {
if (getVisibility() == GONE || getVisibility() == INVISIBLE) {
if (getVisibility() != VISIBLE) {
return;
}
if (bmp != null) {

View File

@ -31,7 +31,8 @@ import org.telegram.messenger.R;
import java.util.ArrayList;
public class EmojiView extends LinearLayout {
private ArrayList<EmojiGridAdapter> adapters = new ArrayList<EmojiGridAdapter>();
private ArrayList<EmojiGridAdapter> adapters = new ArrayList<>();
private int[] icons = {
R.drawable.ic_emoji_recent,
R.drawable.ic_emoji_smile,
@ -42,7 +43,7 @@ public class EmojiView extends LinearLayout {
private Listener listener;
private ViewPager pager;
private FrameLayout recentsWrap;
private ArrayList<GridView> views = new ArrayList<GridView>();
private ArrayList<GridView> views = new ArrayList<>();
public EmojiView(Context paramContext) {
super(paramContext);
@ -63,7 +64,7 @@ public class EmojiView extends LinearLayout {
if (this.pager.getCurrentItem() == 0) {
return;
}
ArrayList<Long> localArrayList = new ArrayList<Long>();
ArrayList<Long> localArrayList = new ArrayList<>();
long[] currentRecent = Emoji.data[0];
boolean was = false;
for (long aCurrentRecent : currentRecent) {
@ -161,7 +162,7 @@ public class EmojiView extends LinearLayout {
}
private void saveRecents() {
ArrayList<Long> localArrayList = new ArrayList<Long>();
ArrayList<Long> localArrayList = new ArrayList<>();
long[] arrayOfLong = Emoji.data[0];
int i = arrayOfLong.length;
for (int j = 0; ; j++) {

View File

@ -19,7 +19,8 @@ import org.telegram.messenger.FileLog;
import java.util.ArrayList;
public class FrameLayoutFixed extends FrameLayout {
private final ArrayList<View> mMatchParentChildren = new ArrayList<View>(1);
private final ArrayList<View> mMatchParentChildren = new ArrayList<>(1);
public FrameLayoutFixed(Context context) {
super(context);
@ -110,7 +111,7 @@ public class FrameLayoutFixed extends FrameLayout {
}
setMeasuredDimension(resolveSizeAndStateFixed(maxWidth, widthMeasureSpec, childState),
resolveSizeAndStateFixed(maxHeight, heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT));
resolveSizeAndStateFixed(maxHeight, heightMeasureSpec, childState << 16));
count = mMatchParentChildren.size();
if (count > 1) {

View File

@ -14,6 +14,7 @@ import android.graphics.Paint;
import org.telegram.android.AndroidUtilities;
public class ProgressView {
private Paint innerPaint;
private Paint outerPaint;

View File

@ -33,14 +33,17 @@ public class SizeNotifierRelativeLayout extends RelativeLayout {
public SizeNotifierRelativeLayout(Context context) {
super(context);
setWillNotDraw(false);
}
public SizeNotifierRelativeLayout(android.content.Context context, android.util.AttributeSet attrs) {
super(context, attrs);
setWillNotDraw(false);
}
public SizeNotifierRelativeLayout(android.content.Context context, android.util.AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setWillNotDraw(false);
}
public void setBackgroundImage(int resourceId) {

View File

@ -49,4 +49,8 @@ public class SlideView extends LinearLayout {
public void restoreStateParams(Bundle bundle) {
}
public boolean needBackButton() {
return false;
}
}

View File

@ -0,0 +1,119 @@
/*
* This is the source code of Telegram for Android v. 2.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-2015.
*/
package org.telegram.ui.Components;
import android.os.Build;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextDirectionHeuristic;
import android.text.TextDirectionHeuristics;
import android.text.TextPaint;
import android.text.TextUtils;
import org.telegram.messenger.FileLog;
import java.lang.reflect.Constructor;
public class StaticLayoutEx {
private static final String TEXT_DIR_CLASS = "android.text.TextDirectionHeuristic";
private static final String TEXT_DIRS_CLASS = "android.text.TextDirectionHeuristics";
private static final String TEXT_DIR_FIRSTSTRONG_LTR = "FIRSTSTRONG_LTR";
private static boolean initialized;
private static Constructor<StaticLayout> sConstructor;
private static Object[] sConstructorArgs;
private static Object sTextDirection;
public static void init() {
if (initialized) {
return;
}
try {
final Class<?> textDirClass;
if (Build.VERSION.SDK_INT >= 18) {
textDirClass = TextDirectionHeuristic.class;
sTextDirection = TextDirectionHeuristics.FIRSTSTRONG_LTR;
} else {
ClassLoader loader = StaticLayoutEx.class.getClassLoader();
textDirClass = loader.loadClass(TEXT_DIR_CLASS);
Class<?> textDirsClass = loader.loadClass(TEXT_DIRS_CLASS);
sTextDirection = textDirsClass.getField(TEXT_DIR_FIRSTSTRONG_LTR).get(textDirsClass);
}
final Class<?>[] signature = new Class[]{
CharSequence.class,
int.class,
int.class,
TextPaint.class,
int.class,
Layout.Alignment.class,
textDirClass,
float.class,
float.class,
boolean.class,
TextUtils.TruncateAt.class,
int.class,
int.class
};
sConstructor = StaticLayout.class.getDeclaredConstructor(signature);
sConstructor.setAccessible(true);
sConstructorArgs = new Object[signature.length];
initialized = true;
} catch (Throwable e) {
FileLog.e("tmessages", e);
}
}
public static StaticLayout createStaticLayout(CharSequence source, TextPaint paint, int width, Layout.Alignment align, float spacingmult, float spacingadd, boolean includepad, TextUtils.TruncateAt ellipsize, int ellipsisWidth, int maxLines) {
return createStaticLayout(source, 0, source.length(), paint, width, align, spacingmult, spacingadd, includepad, ellipsize, ellipsisWidth, maxLines);
}
public static StaticLayout createStaticLayout(CharSequence source, int bufstart, int bufend, TextPaint paint, int outerWidth, Layout.Alignment align, float spacingMult, float spacingAdd, boolean includePad, TextUtils.TruncateAt ellipsize, int ellipsisWidth, int maxLines) {
if (Build.VERSION.SDK_INT >= 14) {
init();
try {
sConstructorArgs[0] = source;
sConstructorArgs[1] = bufstart;
sConstructorArgs[2] = bufend;
sConstructorArgs[3] = paint;
sConstructorArgs[4] = outerWidth;
sConstructorArgs[5] = align;
sConstructorArgs[6] = sTextDirection;
sConstructorArgs[7] = spacingMult;
sConstructorArgs[8] = spacingAdd;
sConstructorArgs[9] = includePad;
sConstructorArgs[10] = ellipsize;
sConstructorArgs[11] = ellipsisWidth;
sConstructorArgs[12] = maxLines;
return sConstructor.newInstance(sConstructorArgs);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
try {
if (maxLines == 1) {
return new StaticLayout(source, bufstart, bufend, paint, outerWidth, align, spacingMult, spacingAdd, includePad, ellipsize, ellipsisWidth);
} else {
StaticLayout layout = new StaticLayout(source, paint, outerWidth, align, spacingMult, spacingAdd, includePad);
if (layout.getLineCount() <= maxLines) {
return layout;
} else {
int off = layout.getOffsetForHorizontal(maxLines - 1, layout.getLineWidth(maxLines - 1));
return new StaticLayout(source.subSequence(0, off), paint, outerWidth, align, spacingMult, spacingAdd, includePad);
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return null;
}
}

View File

@ -29,6 +29,7 @@ import java.util.ArrayList;
@TargetApi(10)
public class VideoTimelineView extends View {
private long videoLength = 0;
private float progressLeft = 0;
private float progressRight = 1;
@ -39,7 +40,7 @@ public class VideoTimelineView extends View {
private float pressDx = 0;
private MediaMetadataRetriever mediaMetadataRetriever = null;
private VideoTimelineViewDelegate delegate = null;
private ArrayList<Bitmap> frames = new ArrayList<Bitmap>();
private ArrayList<Bitmap> frames = new ArrayList<>();
private AsyncTask<Integer, Integer, Bitmap> currentTask = null;
private static final Object sync = new Object();
private long frameTimeOffset = 0;

View File

@ -9,6 +9,7 @@
package org.telegram.ui;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.InputType;
@ -19,7 +20,6 @@ import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.FrameLayout;
@ -74,15 +74,11 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
if (avatarImage != null) {
avatarImage.setImageDrawable(null);
}
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (addContact) {
@ -111,9 +107,9 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
fragmentView = new ScrollView(getParentActivity());
fragmentView = new ScrollView(context);
LinearLayout linearLayout = new LinearLayout(getParentActivity());
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
((ScrollView) fragmentView).addView(linearLayout);
ScrollView.LayoutParams layoutParams2 = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
@ -127,7 +123,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
}
});
FrameLayout frameLayout = new FrameLayout(getParentActivity());
FrameLayout frameLayout = new FrameLayout(context);
linearLayout.addView(frameLayout);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(24);
@ -137,9 +133,8 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
frameLayout.setLayoutParams(layoutParams);
avatarImage = new BackupImageView(getParentActivity());
avatarImage.imageReceiver.setRoundRadius(AndroidUtilities.dp(30));
avatarImage.processDetach = false;
avatarImage = new BackupImageView(context);
avatarImage.setRoundRadius(AndroidUtilities.dp(30));
frameLayout.addView(avatarImage);
FrameLayout.LayoutParams layoutParams3 = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
@ -147,7 +142,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
layoutParams3.height = AndroidUtilities.dp(60);
avatarImage.setLayoutParams(layoutParams3);
nameTextView = new TextView(getParentActivity());
nameTextView = new TextView(context);
nameTextView.setTextColor(0xff212121);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
nameTextView.setLines(1);
@ -166,7 +161,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
nameTextView.setLayoutParams(layoutParams3);
onlineTextView = new TextView(getParentActivity());
onlineTextView = new TextView(context);
onlineTextView.setTextColor(0xff999999);
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
onlineTextView.setLines(1);
@ -184,7 +179,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
onlineTextView.setLayoutParams(layoutParams3);
firstNameField = new EditText(getParentActivity());
firstNameField = new EditText(context);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
firstNameField.setTextColor(0xff212121);
@ -216,7 +211,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
}
});
lastNameField = new EditText(getParentActivity());
lastNameField = new EditText(context);
lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
lastNameField.setHintTextColor(0xff979797);
lastNameField.setTextColor(0xff212121);
@ -259,13 +254,6 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
lastNameField.setText(user.last_name);
}
updateAvatarLayout();
} else {
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
@ -299,6 +287,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
@Override
public void onResume() {
super.onResume();
updateAvatarLayout();
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true);
if (!animations) {

View File

@ -9,6 +9,7 @@
package org.telegram.ui;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
@ -116,8 +117,8 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
searching = false;
searchWas = false;
@ -180,7 +181,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
if (listView != null) {
listView.setAdapter(searchListViewAdapter);
searchListViewAdapter.notifyDataSetChanged();
if(android.os.Build.VERSION.SDK_INT >= 11) {
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(false);
}
listView.setFastScrollEnabled(false);
@ -195,12 +196,12 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
});
item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
searchListViewAdapter = new SearchAdapter(getParentActivity(), ignoreUsers, allowUsernameSearch);
listViewAdapter = new ContactsAdapter(getParentActivity(), onlyUsers, needPhonebook, ignoreUsers);
searchListViewAdapter = new SearchAdapter(context, ignoreUsers, allowUsernameSearch);
listViewAdapter = new ContactsAdapter(context, onlyUsers, needPhonebook, ignoreUsers);
fragmentView = new FrameLayout(getParentActivity());
fragmentView = new FrameLayout(context);
LinearLayout emptyTextLayout = new LinearLayout(getParentActivity());
LinearLayout emptyTextLayout = new LinearLayout(context);
emptyTextLayout.setVisibility(View.INVISIBLE);
emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
((FrameLayout) fragmentView).addView(emptyTextLayout);
@ -216,7 +217,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
}
});
emptyTextView = new TextView(getParentActivity());
emptyTextView = new TextView(context);
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
emptyTextView.setGravity(Gravity.CENTER);
@ -228,7 +229,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
layoutParams1.weight = 0.5f;
emptyTextView.setLayoutParams(layoutParams1);
FrameLayout frameLayout = new FrameLayout(getParentActivity());
FrameLayout frameLayout = new FrameLayout(context);
emptyTextLayout.addView(frameLayout);
layoutParams1 = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
@ -236,7 +237,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
layoutParams1.weight = 0.5f;
frameLayout.setLayoutParams(layoutParams1);
listView = new LetterSectionsListView(getParentActivity());
listView = new LetterSectionsListView(context);
listView.setEmptyView(emptyTextLayout);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
@ -390,12 +391,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
}
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -8,12 +8,12 @@
package org.telegram.ui;
import android.content.Context;
import android.os.Build;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.EditText;
@ -61,8 +61,7 @@ public class CountrySelectActivity extends BaseFragment {
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
@ -108,7 +107,7 @@ public class CountrySelectActivity extends BaseFragment {
searchWas = true;
if (listView != null) {
listView.setAdapter(searchListViewAdapter);
if(android.os.Build.VERSION.SDK_INT >= 11) {
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(false);
}
listView.setFastScrollEnabled(false);
@ -125,12 +124,12 @@ public class CountrySelectActivity extends BaseFragment {
searching = false;
searchWas = false;
listViewAdapter = new CountryAdapter(getParentActivity());
searchListViewAdapter = new CountrySearchAdapter(getParentActivity(), listViewAdapter.getCountries());
listViewAdapter = new CountryAdapter(context);
searchListViewAdapter = new CountrySearchAdapter(context, listViewAdapter.getCountries());
fragmentView = new FrameLayout(getParentActivity());
fragmentView = new FrameLayout(context);
LinearLayout emptyTextLayout = new LinearLayout(getParentActivity());
LinearLayout emptyTextLayout = new LinearLayout(context);
emptyTextLayout.setVisibility(View.INVISIBLE);
emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
((FrameLayout) fragmentView).addView(emptyTextLayout);
@ -146,7 +145,7 @@ public class CountrySelectActivity extends BaseFragment {
}
});
emptyTextView = new TextView(getParentActivity());
emptyTextView = new TextView(context);
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
@ -158,7 +157,7 @@ public class CountrySelectActivity extends BaseFragment {
layoutParams1.weight = 0.5f;
emptyTextView.setLayoutParams(layoutParams1);
FrameLayout frameLayout = new FrameLayout(getParentActivity());
FrameLayout frameLayout = new FrameLayout(context);
emptyTextLayout.addView(frameLayout);
layoutParams1 = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
@ -166,7 +165,7 @@ public class CountrySelectActivity extends BaseFragment {
layoutParams1.weight = 0.5f;
frameLayout.setLayoutParams(layoutParams1);
listView = new LetterSectionsListView(getParentActivity());
listView = new LetterSectionsListView(context);
listView.setEmptyView(emptyTextLayout);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
@ -223,12 +222,7 @@ public class CountrySelectActivity extends BaseFragment {
}
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -125,7 +125,7 @@ public class DocumentSelectActivity extends BaseFragment {
}
@Override
public View createView(LayoutInflater inflater) {
public View createView(Context context, LayoutInflater inflater) {
if (!receiverRegistered) {
receiverRegistered = true;
IntentFilter filter = new IntentFilter();
@ -142,7 +142,6 @@ public class DocumentSelectActivity extends BaseFragment {
getParentActivity().registerReceiver(receiver, filter);
}
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("SelectFile", R.string.SelectFile));
@ -186,7 +185,7 @@ public class DocumentSelectActivity extends BaseFragment {
}
});
actionMode.addView(selectedMessagesCountTextView);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)selectedMessagesCountTextView.getLayoutParams();
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) selectedMessagesCountTextView.getLayoutParams();
layoutParams.weight = 1;
layoutParams.width = 0;
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
@ -195,15 +194,15 @@ public class DocumentSelectActivity extends BaseFragment {
actionModeViews.add(actionMode.addItem(done, R.drawable.ic_ab_done_gray, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
fragmentView = inflater.inflate(R.layout.document_select_layout, null, false);
listAdapter = new ListAdapter(getParentActivity());
emptyView = (TextView)fragmentView.findViewById(R.id.searchEmptyView);
listAdapter = new ListAdapter(context);
emptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
emptyView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
listView = (ListView)fragmentView.findViewById(R.id.listView);
listView = (ListView) fragmentView.findViewById(R.id.listView);
listView.setEmptyView(emptyView);
listView.setAdapter(listAdapter);
@ -347,12 +346,7 @@ public class DocumentSelectActivity extends BaseFragment {
});
listRoots();
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -9,6 +9,7 @@
package org.telegram.ui;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
@ -28,7 +29,6 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AbsListView;
import android.widget.AdapterView;
@ -141,8 +141,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
searching = false;
searchWas = false;
@ -185,17 +184,17 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
searchListViewAdapter = new SearchAdapter(getParentActivity(), null, false);
searchListViewAdapter = new SearchAdapter(context, null, false);
searchListViewAdapter.setCheckedMap(selectedContacts);
searchListViewAdapter.setUseUserCell(true);
listViewAdapter = new ContactsAdapter(getParentActivity(), true, false, null);
listViewAdapter = new ContactsAdapter(context, true, false, null);
listViewAdapter.setCheckedMap(selectedContacts);
fragmentView = new LinearLayout(getParentActivity());
fragmentView = new LinearLayout(context);
LinearLayout linearLayout = (LinearLayout) fragmentView;
linearLayout.setOrientation(LinearLayout.VERTICAL);
FrameLayout frameLayout = new FrameLayout(getParentActivity());
FrameLayout frameLayout = new FrameLayout(context);
linearLayout.addView(frameLayout);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
@ -203,7 +202,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
layoutParams.gravity = Gravity.TOP;
frameLayout.setLayoutParams(layoutParams);
userSelectEditText = new EditText(getParentActivity());
userSelectEditText = new EditText(context);
userSelectEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
userSelectEditText.setHintTextColor(0xff979797);
userSelectEditText.setTextColor(0xff212121);
@ -293,7 +292,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
if (listView != null) {
listView.setAdapter(searchListViewAdapter);
searchListViewAdapter.notifyDataSetChanged();
if(android.os.Build.VERSION.SDK_INT >= 11) {
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(false);
}
listView.setFastScrollEnabled(false);
@ -321,7 +320,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
}
});
LinearLayout emptyTextLayout = new LinearLayout(getParentActivity());
LinearLayout emptyTextLayout = new LinearLayout(context);
emptyTextLayout.setVisibility(View.INVISIBLE);
emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.addView(emptyTextLayout);
@ -336,7 +335,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
}
});
emptyTextView = new TextView(getParentActivity());
emptyTextView = new TextView(context);
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
@ -348,7 +347,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
layoutParams.weight = 0.5f;
emptyTextView.setLayoutParams(layoutParams);
FrameLayout frameLayout2 = new FrameLayout(getParentActivity());
FrameLayout frameLayout2 = new FrameLayout(context);
emptyTextLayout.addView(frameLayout2);
layoutParams = (LinearLayout.LayoutParams) frameLayout2.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
@ -356,7 +355,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
layoutParams.weight = 0.5f;
frameLayout2.setLayoutParams(layoutParams);
listView = new LetterSectionsListView(getParentActivity());
listView = new LetterSectionsListView(context);
listView.setEmptyView(emptyTextLayout);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
@ -466,12 +465,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
}
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -138,8 +138,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (isBroadcast) {
@ -163,7 +162,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
donePressed = true;
if (isBroadcast) {
MessagesController.getInstance().createChat(nameTextView.getText().toString(), selectedContacts, uploadedAvatar, isBroadcast);
MessagesController.getInstance().createChat(nameTextView.getText().toString(), selectedContacts, isBroadcast);
} else {
if (avatarUpdater.uploadingAvatar != null) {
createAfterUpload = true;
@ -173,7 +172,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
final long reqId = MessagesController.getInstance().createChat(nameTextView.getText().toString(), selectedContacts, uploadedAvatar, isBroadcast);
final long reqId = MessagesController.getInstance().createChat(nameTextView.getText().toString(), selectedContacts, isBroadcast);
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() {
@Override
@ -197,11 +196,11 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
fragmentView = new LinearLayout(getParentActivity());
fragmentView = new LinearLayout(context);
LinearLayout linearLayout = (LinearLayout) fragmentView;
linearLayout.setOrientation(LinearLayout.VERTICAL);
FrameLayout frameLayout = new FrameLayoutFixed(getParentActivity());
FrameLayout frameLayout = new FrameLayoutFixed(context);
linearLayout.addView(frameLayout);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
@ -209,8 +208,8 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
frameLayout.setLayoutParams(layoutParams);
avatarImage = new BackupImageView(getParentActivity());
avatarImage.imageReceiver.setRoundRadius(AndroidUtilities.dp(32));
avatarImage = new BackupImageView(context);
avatarImage.setRoundRadius(AndroidUtilities.dp(32));
avatarDrawable.setInfo(5, null, null, isBroadcast);
avatarImage.setImageDrawable(avatarDrawable);
frameLayout.addView(avatarImage);
@ -260,7 +259,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
});
}
nameTextView = new EditText(getParentActivity());
nameTextView = new EditText(context);
nameTextView.setHint(isBroadcast ? LocaleController.getString("EnterListName", R.string.EnterListName) : LocaleController.getString("EnterGroupNamePlaceholder", R.string.EnterGroupNamePlaceholder));
if (nameToSet != null) {
nameTextView.setText(nameToSet);
@ -303,26 +302,21 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
});
}
GreySectionCell sectionCell = new GreySectionCell(getParentActivity());
GreySectionCell sectionCell = new GreySectionCell(context);
sectionCell.setText(LocaleController.formatPluralString("Members", selectedContacts.size()));
linearLayout.addView(sectionCell);
listView = new ListView(getParentActivity());
listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
listView.setAdapter(listAdapter = new ListAdapter(getParentActivity()));
listView.setAdapter(listAdapter = new ListAdapter(context));
linearLayout.addView(listView);
layoutParams = (LinearLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
@ -336,7 +330,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
avatarImage.setImage(avatar, "50_50", avatarDrawable);
if (createAfterUpload) {
FileLog.e("tmessages", "avatar did uploaded");
MessagesController.getInstance().createChat(nameTextView.getText().toString(), selectedContacts, uploadedAvatar, false);
MessagesController.getInstance().createChat(nameTextView.getText().toString(), selectedContacts, false);
}
}
});
@ -402,10 +396,14 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
FileLog.e("tmessages", e);
}
}
int chat_id = (Integer)args[0];
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
Bundle args2 = new Bundle();
args2.putInt("chat_id", (Integer)args[0]);
args2.putInt("chat_id", chat_id);
presentFragment(new ChatActivity(args2), true);
if (uploadedAvatar != null) {
MessagesController.getInstance().changeChatAvatar(chat_id, uploadedAvatar);
}
}
});
}

View File

@ -10,18 +10,17 @@ package org.telegram.ui;
import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.TLRPC;
@ -45,8 +44,7 @@ public class IdenticonActivity extends BaseFragment {
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey));
@ -62,14 +60,14 @@ public class IdenticonActivity extends BaseFragment {
fragmentView = inflater.inflate(R.layout.identicon_layout, null, false);
ImageView identiconView = (ImageView) fragmentView.findViewById(R.id.identicon_view);
TextView textView = (TextView)fragmentView.findViewById(R.id.identicon_text);
TextView textView = (TextView) fragmentView.findViewById(R.id.identicon_text);
TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(chat_id);
if (encryptedChat != null) {
IdenticonDrawable drawable = new IdenticonDrawable();
identiconView.setImageDrawable(drawable);
drawable.setEncryptedChat(encryptedChat);
TLRPC.User user = MessagesController.getInstance().getUser(encryptedChat.user_id);
textView.setText(Html.fromHtml(LocaleController.formatString("EncryptionKeyDescription", R.string.EncryptionKeyDescription, user.first_name, user.first_name)));
textView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("EncryptionKeyDescription", R.string.EncryptionKeyDescription, user.first_name, user.first_name)));
}
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@ -78,12 +76,7 @@ public class IdenticonActivity extends BaseFragment {
return true;
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -19,7 +19,6 @@ import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
@ -255,7 +254,7 @@ public class IntroActivity extends Activity {
container.addView(view, 0);
headerTextView.setText(getString(titles[position]));
messageTextView.setText(Html.fromHtml(getString(messages[position])));
messageTextView.setText(AndroidUtilities.replaceTags(getString(messages[position])));
return view;
}

View File

@ -52,8 +52,7 @@ public class LanguageSelectActivity extends BaseFragment {
public ArrayList<LocaleController.LocaleInfo> searchResult;
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
searching = false;
searchWas = false;
@ -104,12 +103,12 @@ public class LanguageSelectActivity extends BaseFragment {
});
item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
listAdapter = new ListAdapter(getParentActivity());
searchListViewAdapter = new SearchAdapter(getParentActivity());
listAdapter = new ListAdapter(context);
searchListViewAdapter = new SearchAdapter(context);
fragmentView = new FrameLayout(getParentActivity());
fragmentView = new FrameLayout(context);
LinearLayout emptyTextLayout = new LinearLayout(getParentActivity());
LinearLayout emptyTextLayout = new LinearLayout(context);
emptyTextLayout.setVisibility(View.INVISIBLE);
emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
((FrameLayout) fragmentView).addView(emptyTextLayout);
@ -125,7 +124,7 @@ public class LanguageSelectActivity extends BaseFragment {
}
});
emptyTextView = new TextView(getParentActivity());
emptyTextView = new TextView(context);
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
@ -137,7 +136,7 @@ public class LanguageSelectActivity extends BaseFragment {
layoutParams1.weight = 0.5f;
emptyTextView.setLayoutParams(layoutParams1);
FrameLayout frameLayout = new FrameLayout(getParentActivity());
FrameLayout frameLayout = new FrameLayout(context);
emptyTextLayout.addView(frameLayout);
layoutParams1 = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
@ -145,7 +144,7 @@ public class LanguageSelectActivity extends BaseFragment {
layoutParams1.weight = 0.5f;
frameLayout.setLayoutParams(layoutParams1);
listView = new ListView(getParentActivity());
listView = new ListView(context);
listView.setEmptyView(emptyTextLayout);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
@ -232,12 +231,7 @@ public class LanguageSelectActivity extends BaseFragment {
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -99,8 +99,7 @@ public class LastSeenActivity extends BaseFragment implements NotificationCenter
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("PrivacyLastSeen", R.string.PrivacyLastSeen));
@ -142,13 +141,13 @@ public class LastSeenActivity extends BaseFragment implements NotificationCenter
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
doneButton.setVisibility(View.GONE);
listAdapter = new ListAdapter(getParentActivity());
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(getParentActivity());
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xfff0f0f0);
ListView listView = new ListView(getParentActivity());
ListView listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
@ -237,12 +236,7 @@ public class LastSeenActivity extends BaseFragment implements NotificationCenter
}
}
});
} else {
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -75,8 +75,7 @@ public class LastSeenUsersActivity extends BaseFragment implements NotificationC
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (isAlwaysShare) {
@ -116,10 +115,10 @@ public class LastSeenUsersActivity extends BaseFragment implements NotificationC
ActionBarMenu menu = actionBar.createMenu();
menu.addItem(block_user, R.drawable.plus);
fragmentView = new FrameLayout(getParentActivity());
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
TextView emptyTextView = new TextView(getParentActivity());
TextView emptyTextView = new TextView(context);
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
@ -138,12 +137,12 @@ public class LastSeenUsersActivity extends BaseFragment implements NotificationC
}
});
listView = new ListView(getParentActivity());
listView = new ListView(context);
listView.setEmptyView(emptyTextView);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setAdapter(listViewAdapter = new ListAdapter(getParentActivity()));
listView.setAdapter(listViewAdapter = new ListAdapter(context));
if (Build.VERSION.SDK_INT >= 11) {
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
}
@ -173,12 +172,12 @@ public class LastSeenUsersActivity extends BaseFragment implements NotificationC
selectedUserId = uidArray.get(i);
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items = new CharSequence[] {LocaleController.getString("Delete", R.string.Delete)};
CharSequence[] items = new CharSequence[]{LocaleController.getString("Delete", R.string.Delete)};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
uidArray.remove((Integer)selectedUserId);
uidArray.remove((Integer) selectedUserId);
listViewAdapter.notifyDataSetChanged();
if (delegate != null) {
delegate.didUpdatedUserList(uidArray, false);
@ -190,12 +189,7 @@ public class LastSeenUsersActivity extends BaseFragment implements NotificationC
return true;
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -104,7 +104,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
protected void onCreate(Bundle savedInstanceState) {
ApplicationLoader.postInitApplication();
if (!UserConfig.isClientActivated() && !UserConfig.isWaitingForPasswordEnter()) {
if (!UserConfig.isClientActivated()) {
Intent intent = getIntent();
if (intent != null && intent.getAction() != null && (Intent.ACTION_SEND.equals(intent.getAction()) || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE))) {
super.onCreate(savedInstanceState);
@ -205,7 +205,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
int viewX = location[0];
int viewY = location[1];
if (x > viewX && x < viewX + layersActionBarLayout.getWidth() && y > viewY && y < viewY + layersActionBarLayout.getHeight()) {
if (layersActionBarLayout.checkTransitionAnimation() || x > viewX && x < viewX + layersActionBarLayout.getWidth() && y > viewY && y < viewY + layersActionBarLayout.getHeight()) {
return false;
} else {
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
@ -335,7 +335,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
NotificationCenter.getInstance().addObserver(this, NotificationCenter.mainUserInfoChanged);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeOtherAppActivities);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didUpdatedConnectionState);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.needPasswordEnter);
if (Build.VERSION.SDK_INT < 14) {
NotificationCenter.getInstance().addObserver(this, NotificationCenter.screenStateChanged);
} else {
@ -343,18 +342,13 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
if (actionBarLayout.fragmentsStack.isEmpty()) {
if (!UserConfig.isClientActivated() && !UserConfig.isWaitingForPasswordEnter()) {
if (!UserConfig.isClientActivated()) {
actionBarLayout.addFragmentToStack(new LoginActivity());
drawerLayoutContainer.setAllowOpenDrawer(false, false);
} else {
if (UserConfig.isWaitingForPasswordEnter()) {
actionBarLayout.addFragmentToStack(new AccountPasswordActivity(1));
drawerLayoutContainer.setAllowOpenDrawer(false, false);
} else {
actionBarLayout.addFragmentToStack(new MessagesActivity(null));
drawerLayoutContainer.setAllowOpenDrawer(true, false);
}
}
try {
if (savedInstanceState != null) {
@ -411,7 +405,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
} else {
allowOpen = actionBarLayout.fragmentsStack.size() <= 1;
}
if (actionBarLayout.fragmentsStack.size() == 1 && (actionBarLayout.fragmentsStack.get(0) instanceof LoginActivity || actionBarLayout.fragmentsStack.get(0) instanceof AccountPasswordActivity)) {
if (actionBarLayout.fragmentsStack.size() == 1 && actionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) {
allowOpen = false;
}
drawerLayoutContainer.setAllowOpenDrawer(allowOpen, false);
@ -476,7 +470,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
documentsUrisArray = null;
contactsToSend = null;
if (UserConfig.isClientActivated() && !UserConfig.isWaitingForPasswordEnter() && (flags & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) {
if (UserConfig.isClientActivated() && (flags & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) {
if (intent != null && intent.getAction() != null && !restore) {
if (Intent.ACTION_SEND.equals(intent.getAction())) {
boolean error = false;
@ -864,38 +858,28 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
if (!pushOpened && !isNew) {
if (AndroidUtilities.isTablet()) {
if (!UserConfig.isClientActivated() && !UserConfig.isWaitingForPasswordEnter()) {
if (!UserConfig.isClientActivated()) {
if (layersActionBarLayout.fragmentsStack.isEmpty()) {
layersActionBarLayout.addFragmentToStack(new LoginActivity());
drawerLayoutContainer.setAllowOpenDrawer(false, false);
}
} else {
if (actionBarLayout.fragmentsStack.isEmpty()) {
if (UserConfig.isWaitingForPasswordEnter()) {
layersActionBarLayout.addFragmentToStack(new AccountPasswordActivity(1));
drawerLayoutContainer.setAllowOpenDrawer(false, false);
} else {
actionBarLayout.addFragmentToStack(new MessagesActivity(null));
drawerLayoutContainer.setAllowOpenDrawer(true, false);
}
}
}
} else {
if (actionBarLayout.fragmentsStack.isEmpty()) {
if (!UserConfig.isClientActivated() && !UserConfig.isWaitingForPasswordEnter()) {
if (!UserConfig.isClientActivated()) {
actionBarLayout.addFragmentToStack(new LoginActivity());
drawerLayoutContainer.setAllowOpenDrawer(false, false);
} else {
if (UserConfig.isWaitingForPasswordEnter()) {
actionBarLayout.addFragmentToStack(new AccountPasswordActivity(1));
drawerLayoutContainer.setAllowOpenDrawer(false, false);
} else {
actionBarLayout.addFragmentToStack(new MessagesActivity(null));
drawerLayoutContainer.setAllowOpenDrawer(true, false);
}
}
}
}
actionBarLayout.showLastFragment();
if (AndroidUtilities.isTablet()) {
layersActionBarLayout.showLastFragment();
@ -1001,7 +985,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mainUserInfoChanged);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeOtherAppActivities);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didUpdatedConnectionState);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.needPasswordEnter);
if (Build.VERSION.SDK_INT < 14) {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.screenStateChanged);
} else {
@ -1218,28 +1201,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
} else if (id == NotificationCenter.mainUserInfoChanged) {
drawerLayoutAdapter.notifyDataSetChanged();
} else if (id == NotificationCenter.needPasswordEnter) {
if (AndroidUtilities.isTablet()) {
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
a--;
}
for (int a = 0; a < actionBarLayout.fragmentsStack.size() - 1; a++) {
actionBarLayout.removeFragmentFromStack(actionBarLayout.fragmentsStack.get(0));
a--;
}
rightActionBarLayout.closeLastFragment(false);
actionBarLayout.closeLastFragment(false);
layersActionBarLayout.presentFragment(new AccountPasswordActivity(1), false, true, true);
drawerLayoutContainer.setAllowOpenDrawer(false, false);
} else {
for (int a = 0; a < actionBarLayout.fragmentsStack.size() - 1; a++) {
actionBarLayout.removeFragmentFromStack(actionBarLayout.fragmentsStack.get(0));
a--;
}
actionBarLayout.presentFragment(new AccountPasswordActivity(1), true);
drawerLayoutContainer.setAllowOpenDrawer(false, false);
}
} else if (id == NotificationCenter.screenStateChanged) {
if (!ApplicationLoader.mainInterfacePaused) {
if (!ApplicationLoader.isScreenOn) {
@ -1452,7 +1413,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
@Override
public boolean needPresentFragment(BaseFragment fragment, boolean removeLast, boolean forceWithoutAnimation, ActionBarLayout layout) {
if (AndroidUtilities.isTablet()) {
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof AccountPasswordActivity) && !(fragment instanceof LoginActivity) && layersActionBarLayout.getVisibility() != View.VISIBLE, true);
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity) && layersActionBarLayout.getVisibility() != View.VISIBLE, true);
if (fragment instanceof MessagesActivity) {
MessagesActivity messagesActivity = (MessagesActivity)fragment;
if (messagesActivity.isMainDialogList() && layout != actionBarLayout) {
@ -1521,7 +1482,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
} else if (layout != layersActionBarLayout) {
layersActionBarLayout.setVisibility(View.VISIBLE);
drawerLayoutContainer.setAllowOpenDrawer(false, true);
if (fragment instanceof LoginActivity || fragment instanceof AccountPasswordActivity) {
if (fragment instanceof LoginActivity) {
backgroundTablet.setVisibility(View.VISIBLE);
shadowTabletSide.setVisibility(View.GONE);
shadowTablet.setBackgroundColor(0x00000000);
@ -1533,7 +1494,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
return true;
} else {
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity) && !(fragment instanceof AccountPasswordActivity), false);
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity), false);
return true;
}
}
@ -1541,7 +1502,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
@Override
public boolean needAddFragmentToStack(BaseFragment fragment, ActionBarLayout layout) {
if (AndroidUtilities.isTablet()) {
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity) && !(fragment instanceof AccountPasswordActivity) && layersActionBarLayout.getVisibility() != View.VISIBLE, true);
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity) && layersActionBarLayout.getVisibility() != View.VISIBLE, true);
if (fragment instanceof MessagesActivity) {
MessagesActivity messagesActivity = (MessagesActivity)fragment;
if (messagesActivity.isMainDialogList() && layout != actionBarLayout) {
@ -1586,7 +1547,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
} else if (layout != layersActionBarLayout) {
layersActionBarLayout.setVisibility(View.VISIBLE);
drawerLayoutContainer.setAllowOpenDrawer(false, true);
if (fragment instanceof LoginActivity || fragment instanceof AccountPasswordActivity) {
if (fragment instanceof LoginActivity) {
backgroundTablet.setVisibility(View.VISIBLE);
shadowTabletSide.setVisibility(View.GONE);
shadowTablet.setBackgroundColor(0x00000000);
@ -1598,7 +1559,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
return true;
} else {
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity) && !(fragment instanceof AccountPasswordActivity), false);
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity), false);
return true;
}
}

View File

@ -13,7 +13,6 @@ import android.location.Location;
import android.location.LocationManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.google.android.gms.maps.CameraUpdate;
@ -47,6 +46,7 @@ import org.telegram.ui.ActionBar.BaseFragment;
import java.util.List;
public class LocationActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
private GoogleMap googleMap;
private TextView distanceTextView;
private Marker userMarker;
@ -88,14 +88,10 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
if (mapView != null) {
mapView.onDestroy();
}
if (avatarImageView != null) {
avatarImageView.setImageDrawable(null);
}
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (messageObject != null) {
@ -147,13 +143,12 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
fragmentView = inflater.inflate(R.layout.location_attach_layout, null, false);
}
avatarImageView = (BackupImageView)fragmentView.findViewById(R.id.location_avatar_view);
avatarImageView = (BackupImageView) fragmentView.findViewById(R.id.location_avatar_view);
if (avatarImageView != null) {
avatarImageView.processDetach = false;
avatarImageView.imageReceiver.setRoundRadius(AndroidUtilities.dp(32));
avatarImageView.setRoundRadius(AndroidUtilities.dp(32));
}
nameTextView = (TextView)fragmentView.findViewById(R.id.location_name_label);
distanceTextView = (TextView)fragmentView.findViewById(R.id.location_distance_label);
nameTextView = (TextView) fragmentView.findViewById(R.id.location_name_label);
distanceTextView = (TextView) fragmentView.findViewById(R.id.location_distance_label);
View bottomView = fragmentView.findViewById(R.id.location_bottom_view);
TextView sendButton = (TextView) fragmentView.findViewById(R.id.location_send_button);
if (sendButton != null) {
@ -161,10 +156,10 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
sendButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
}
mapView = (MapView)fragmentView.findViewById(R.id.map_view);
mapView = (MapView) fragmentView.findViewById(R.id.map_view);
mapView.onCreate(null);
try {
MapsInitializer.initialize(getParentActivity());
MapsInitializer.initialize(context);
googleMap = mapView.getMap();
} catch (Exception e) {
FileLog.e("tmessages", e);
@ -233,7 +228,6 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
}
if (messageObject != null) {
updateUserData();
userLocation = new Location("network");
userLocation.setLatitude(messageObject.messageOwner.media.geo.lat);
userLocation.setLongitude(messageObject.messageOwner.media.geo._long);
@ -246,12 +240,7 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
positionMarker(myLocation);
}
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
@ -297,7 +286,7 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
if (userLocation != null && distanceTextView != null) {
float distance = location.distanceTo(userLocation);
if (distance < 1000) {
distanceTextView.setText(String.format("%d %s", (int)(distance), LocaleController.getString("MetersAway", R.string.MetersAway)));
distanceTextView.setText(String.format("%d %s", (int) (distance), LocaleController.getString("MetersAway", R.string.MetersAway)));
} else {
distanceTextView.setText(String.format("%.2f %s", distance / 1000.0f, LocaleController.getString("KMetersAway", R.string.KMetersAway)));
}
@ -326,7 +315,7 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.updateInterfaces) {
int mask = (Integer)args[0];
int mask = (Integer) args[0];
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
updateUserData();
}
@ -353,6 +342,7 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
if (mapView != null) {
mapView.onResume();
}
updateUserData();
}
@Override

View File

@ -216,8 +216,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle("");
actionBar.setAllowOverlayTitle(false);
@ -288,7 +287,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
fragment.setDelegate(new MessagesActivity.MessagesActivityDelegate() {
@Override
public void didSelectDialog(MessagesActivity fragment, long did, boolean param) {
int lower_part = (int)did;
int lower_part = (int) did;
if (lower_part != 0) {
Bundle args = new Bundle();
args.putBoolean("scrollToTopOnResume", true);
@ -312,7 +311,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
ChatActivity chatActivity = new ChatActivity(args);
presentFragment(chatActivity, true);
chatActivity.showReplyForMessageObjectOrForward(true, null, fmessages, false);
chatActivity.showReplyPanel(true, null, fmessages, null, false, false);
if (!AndroidUtilities.isTablet()) {
removeSelfFromStack();
@ -372,7 +371,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
searchItem.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
searchItem.setVisibility(View.GONE);
dropDownContainer = new ActionBarMenuItem(getParentActivity(), menu, R.drawable.bar_selector);
dropDownContainer = new ActionBarMenuItem(context, menu, R.drawable.bar_selector);
dropDownContainer.setSubMenuOpenSide(1);
dropDownContainer.addSubItem(shared_media_item, LocaleController.getString("SharedMediaTitle", R.string.SharedMediaTitle), 0);
dropDownContainer.addSubItem(files_item, LocaleController.getString("DocumentsTitle", R.string.DocumentsTitle), 0);
@ -391,7 +390,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
}
});
dropDown = new TextView(getParentActivity());
dropDown = new TextView(context);
dropDown.setGravity(Gravity.LEFT);
dropDown.setSingleLine(true);
dropDown.setLines(1);
@ -429,7 +428,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
}
});
actionMode.addView(selectedMessagesCountTextView);
LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams)selectedMessagesCountTextView.getLayoutParams();
LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) selectedMessagesCountTextView.getLayoutParams();
layoutParams1.weight = 1;
layoutParams1.width = 0;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
@ -440,14 +439,14 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
}
actionModeViews.add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
photoVideoAdapter = new SharedPhotoVideoAdapter(getParentActivity());
documentsAdapter = new SharedDocumentsAdapter(getParentActivity());
documentsSearchAdapter = new DocumentsSearchAdapter(getParentActivity());
photoVideoAdapter = new SharedPhotoVideoAdapter(context);
documentsAdapter = new SharedDocumentsAdapter(context);
documentsSearchAdapter = new DocumentsSearchAdapter(context);
FrameLayout frameLayout;
fragmentView = frameLayout = new FrameLayout(getParentActivity());
fragmentView = frameLayout = new FrameLayout(context);
listView = new SectionsListView(getParentActivity());
listView = new SectionsListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setDrawSelectorOnTop(true);
@ -509,10 +508,10 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
});
for (int a = 0; a < 6; a++) {
cellCache.add(new SharedPhotoVideoCell(getParentActivity()));
cellCache.add(new SharedPhotoVideoCell(context));
}
emptyView = new LinearLayout(getParentActivity());
emptyView = new LinearLayout(context);
emptyView.setOrientation(LinearLayout.VERTICAL);
emptyView.setGravity(Gravity.CENTER);
emptyView.setVisibility(View.GONE);
@ -529,14 +528,14 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
}
});
emptyImageView = new ImageView(getParentActivity());
emptyImageView = new ImageView(context);
emptyView.addView(emptyImageView);
layoutParams1 = (LinearLayout.LayoutParams) emptyImageView.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams1.height = LinearLayout.LayoutParams.WRAP_CONTENT;
emptyImageView.setLayoutParams(layoutParams1);
emptyTextView = new TextView(getParentActivity());
emptyTextView = new TextView(context);
emptyTextView.setTextColor(0xff8a8a8a);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
@ -549,7 +548,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
layoutParams1.gravity = Gravity.CENTER;
emptyTextView.setLayoutParams(layoutParams1);
progressView = new LinearLayout(getParentActivity());
progressView = new LinearLayout(context);
progressView.setGravity(Gravity.CENTER);
progressView.setOrientation(LinearLayout.VERTICAL);
progressView.setVisibility(View.GONE);
@ -560,7 +559,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
progressView.setLayoutParams(layoutParams);
ProgressBar progressBar = new ProgressBar(getParentActivity());
ProgressBar progressBar = new ProgressBar(context);
progressView.addView(progressBar);
layoutParams1 = (LinearLayout.LayoutParams) progressBar.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.WRAP_CONTENT;
@ -568,12 +567,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
progressBar.setLayoutParams(layoutParams1);
switchToCurrentSelectedMode();
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
@ -742,7 +736,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
object.viewX = coords[0];
object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = imageView.imageReceiver;
object.imageReceiver = imageView.getImageReceiver();
object.thumb = object.imageReceiver.getBitmap();
return object;
}

View File

@ -11,6 +11,7 @@ package org.telegram.ui;
import android.animation.ObjectAnimator;
import android.animation.StateListAnimator;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Configuration;
import android.graphics.Outline;
@ -155,8 +156,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
searching = false;
searchWas = false;
@ -276,7 +276,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
fragmentView = inflater.inflate(R.layout.messages_list, null, false);
if (searchString == null) {
dialogsAdapter = new DialogsAdapter(getParentActivity(), serverOnly);
dialogsAdapter = new DialogsAdapter(context, serverOnly);
if (AndroidUtilities.isTablet() && openedDialogId != 0) {
dialogsAdapter.setOpenedDialogId(openedDialogId);
}
@ -287,7 +287,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
} else if (!onlySelect) {
type = 1;
}
dialogsSearchAdapter = new DialogsSearchAdapter(getParentActivity(), type);
dialogsSearchAdapter = new DialogsSearchAdapter(context, type);
dialogsSearchAdapter.setDelegate(new DialogsSearchAdapter.MessagesActivitySearchAdapterDelegate() {
@Override
public void searchStateChanged(boolean search) {
@ -299,7 +299,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
}
});
messagesListView = (ListView)fragmentView.findViewById(R.id.messages_list_view);
messagesListView = (ListView) fragmentView.findViewById(R.id.messages_list_view);
if (dialogsAdapter != null) {
messagesListView.setAdapter(dialogsAdapter);
}
@ -324,15 +324,15 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
});
TextView textView = (TextView)fragmentView.findViewById(R.id.list_empty_view_text1);
TextView textView = (TextView) fragmentView.findViewById(R.id.list_empty_view_text1);
textView.setText(LocaleController.getString("NoChats", R.string.NoChats));
textView = (TextView)fragmentView.findViewById(R.id.list_empty_view_text2);
textView = (TextView) fragmentView.findViewById(R.id.list_empty_view_text2);
String help = LocaleController.getString("NoChatsHelp", R.string.NoChatsHelp);
if (AndroidUtilities.isTablet() && !AndroidUtilities.isSmallTablet()) {
help = help.replace("\n", " ");
}
textView.setText(help);
textView = (TextView)fragmentView.findViewById(R.id.search_empty_text);
textView = (TextView) fragmentView.findViewById(R.id.search_empty_text);
textView.setText(LocaleController.getString("NoResult", R.string.NoResult));
floatingButton = (ImageView) fragmentView.findViewById(R.id.floating_button);
@ -340,8 +340,8 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
floatingButton.setScaleType(ImageView.ScaleType.CENTER);
if (Build.VERSION.SDK_INT >= 21) {
StateListAnimator animator = new StateListAnimator();
animator.addState(new int[] {android.R.attr.state_pressed}, ObjectAnimator.ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
animator.addState(new int[] {}, ObjectAnimator.ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
animator.addState(new int[]{android.R.attr.state_pressed}, ObjectAnimator.ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
animator.addState(new int[]{}, ObjectAnimator.ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
floatingButton.setStateListAnimator(animator);
floatingButton.setOutlineProvider(new ViewOutlineProvider() {
@Override
@ -350,7 +350,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
}
});
}
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)floatingButton.getLayoutParams();
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) floatingButton.getLayoutParams();
layoutParams.leftMargin = LocaleController.isRTL ? AndroidUtilities.dp(14) : 0;
layoutParams.rightMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(14);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM;
@ -395,7 +395,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
dialog_id = ((TLRPC.User) obj).id;
if (dialogsSearchAdapter.isGlobalSearch(i)) {
ArrayList<TLRPC.User> users = new ArrayList<>();
users.add((TLRPC.User)obj);
users.add((TLRPC.User) obj);
MessagesController.getInstance().putUsers(users, false);
MessagesStorage.getInstance().putUsersAndChats(users, null, false, true);
}
@ -406,9 +406,9 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
dialog_id = AndroidUtilities.makeBroadcastId(((TLRPC.Chat) obj).id);
}
} else if (obj instanceof TLRPC.EncryptedChat) {
dialog_id = ((long)((TLRPC.EncryptedChat) obj).id) << 32;
dialog_id = ((long) ((TLRPC.EncryptedChat) obj).id) << 32;
} else if (obj instanceof MessageObject) {
MessageObject messageObject = (MessageObject)obj;
MessageObject messageObject = (MessageObject) obj;
dialog_id = messageObject.getDialogId();
message_id = messageObject.getId();
dialogsSearchAdapter.addHashtagsFromMessage(dialogsSearchAdapter.getLastSearchString());
@ -425,8 +425,8 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
didSelectResult(dialog_id, true, false);
} else {
Bundle args = new Bundle();
int lower_part = (int)dialog_id;
int high_id = (int)(dialog_id >> 32);
int lower_part = (int) dialog_id;
int high_id = (int) (dialog_id >> 32);
if (lower_part != 0) {
if (high_id == 1) {
args.putInt("chat_id", lower_part);
@ -509,8 +509,8 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
int lower_id = (int)selectedDialog;
int high_id = (int)(selectedDialog >> 32);
int lower_id = (int) selectedDialog;
int high_id = (int) (selectedDialog >> 32);
final boolean isChat = lower_id < 0 && high_id != 1;
builder.setItems(new CharSequence[]{LocaleController.getString("ClearHistory", R.string.ClearHistory),
@ -531,14 +531,17 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
MessagesController.getInstance().deleteDialog(selectedDialog, 0, which == 0);
if (which != 0) {
if (isChat) {
MessagesController.getInstance().deleteUserFromChat((int) -selectedDialog, MessagesController.getInstance().getUser(UserConfig.getClientUserId()), null);
} else {
MessagesController.getInstance().deleteDialog(selectedDialog, 0, false);
}
if (AndroidUtilities.isTablet()) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats, selectedDialog);
}
} else {
MessagesController.getInstance().deleteDialog(selectedDialog, 0, true);
}
}
});
@ -602,12 +605,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
if (searchString != null) {
actionBar.openSearchField(searchString);
}
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -156,8 +156,7 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds));
@ -170,10 +169,10 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
}
});
fragmentView = new FrameLayout(getParentActivity());
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
listView = new ListView(getParentActivity());
listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
@ -182,7 +181,7 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setAdapter(new ListAdapter(getParentActivity()));
listView.setAdapter(new ListAdapter(context));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
@ -363,9 +362,9 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
return;
}
LayoutInflater li = (LayoutInflater)getParentActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater li = (LayoutInflater) getParentActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.settings_color_dialog_layout, null, false);
final ColorPickerView colorPickerView = (ColorPickerView)view.findViewById(R.id.color_picker);
final ColorPickerView colorPickerView = (ColorPickerView) view.findViewById(R.id.color_picker);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (i == messageLedRow) {
@ -409,7 +408,7 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
} else if (i == messagePopupNotificationRow || i == groupPopupNotificationRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("PopupNotification", R.string.PopupNotification));
builder.setItems(new CharSequence[] {
builder.setItems(new CharSequence[]{
LocaleController.getString("NoPopup", R.string.NoPopup),
LocaleController.getString("OnlyWhenScreenOn", R.string.OnlyWhenScreenOn),
LocaleController.getString("OnlyWhenScreenOff", R.string.OnlyWhenScreenOff),
@ -435,7 +434,7 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
} else if (i == messageVibrateRow || i == groupVibrateRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("Vibrate", R.string.Vibrate));
builder.setItems(new CharSequence[] {
builder.setItems(new CharSequence[]{
LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled),
LocaleController.getString("Default", R.string.Default),
LocaleController.getString("Short", R.string.Short),
@ -472,7 +471,7 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
} else if (i == messagePriorityRow || i == groupPriorityRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority));
builder.setItems(new CharSequence[] {
builder.setItems(new CharSequence[]{
LocaleController.getString("NotificationsPriorityDefault", R.string.NotificationsPriorityDefault),
LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh),
LocaleController.getString("NotificationsPriorityMax", R.string.NotificationsPriorityMax)
@ -495,7 +494,7 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
} else if (i == repeatRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("RepeatNotifications", R.string.RepeatNotifications));
builder.setItems(new CharSequence[] {
builder.setItems(new CharSequence[]{
LocaleController.getString("RepeatDisabled", R.string.RepeatDisabled),
LocaleController.formatPluralString("Minutes", 5),
LocaleController.formatPluralString("Minutes", 10),
@ -535,12 +534,7 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
}
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
@ -577,7 +571,7 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
Ringtone rng = RingtoneManager.getRingtone(getParentActivity(), ringtone);
if (rng != null) {
if(ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
name = LocaleController.getString("Default", R.string.Default);
name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
} else {
name = rng.getTitle(getParentActivity());
}
@ -724,9 +718,9 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
textCell.setMultilineDetail(false);
String value = null;
if (i == messageSoundRow) {
value = preferences.getString("GlobalSound", LocaleController.getString("Default", R.string.Default));
value = preferences.getString("GlobalSound", LocaleController.getString("SoundDefault", R.string.SoundDefault));
} else if (i == groupSoundRow) {
value = preferences.getString("GroupSound", LocaleController.getString("Default", R.string.Default));
value = preferences.getString("GroupSound", LocaleController.getString("SoundDefault", R.string.SoundDefault));
}
if (value.equals("NoSound")) {
value = LocaleController.getString("NoSound", R.string.NoSound);

View File

@ -55,9 +55,6 @@ import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.ActionBarMenuItem;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.AnimationCompat.AnimatorListenerAdapterProxy;
import org.telegram.ui.AnimationCompat.AnimatorSetProxy;
import org.telegram.ui.AnimationCompat.ObjectAnimatorProxy;
import org.telegram.ui.Cells.TextCheckCell;
import org.telegram.ui.Cells.TextInfoPrivacyCell;
import org.telegram.ui.Cells.TextSettingsCell;
@ -111,8 +108,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
if (type != 3) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
}
@ -138,17 +134,21 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
}
});
fragmentView = new FrameLayout(getParentActivity());
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
if (type != 0) {
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
titleTextView = new TextView(getParentActivity());
titleTextView = new TextView(context);
titleTextView.setTextColor(0xff757575);
if (type == 1) {
if (UserConfig.passcodeHash.length() != 0) {
titleTextView.setText(LocaleController.getString("EnterNewPasscode", R.string.EnterNewPasscode));
} else {
titleTextView.setText(LocaleController.getString("EnterNewFirstPasscode", R.string.EnterNewFirstPasscode));
}
} else {
titleTextView.setText(LocaleController.getString("EnterCurrentPasscode", R.string.EnterCurrentPasscode));
}
@ -162,7 +162,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
layoutParams.topMargin = AndroidUtilities.dp(38);
titleTextView.setLayoutParams(layoutParams);
passwordEditText = new EditText(getParentActivity());
passwordEditText = new EditText(context);
passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
passwordEditText.setTextColor(0xff000000);
passwordEditText.setMaxLines(1);
@ -251,7 +251,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
}
if (type == 1) {
dropDownContainer = new ActionBarMenuItem(getParentActivity(), menu, R.drawable.bar_selector);
dropDownContainer = new ActionBarMenuItem(context, menu, R.drawable.bar_selector);
dropDownContainer.setSubMenuOpenSide(1);
dropDownContainer.addSubItem(pin_item, LocaleController.getString("PasscodePIN", R.string.PasscodePIN), 0);
dropDownContainer.addSubItem(password_item, LocaleController.getString("PasscodePassword", R.string.PasscodePassword), 0);
@ -270,7 +270,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
}
});
dropDown = new TextView(getParentActivity());
dropDown = new TextView(context);
dropDown.setGravity(Gravity.LEFT);
dropDown.setSingleLine(true);
dropDown.setLines(1);
@ -297,7 +297,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
} else {
actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
frameLayout.setBackgroundColor(0xfff0f0f0);
listView = new ListView(getParentActivity());
listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
@ -308,7 +308,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP;
listView.setLayoutParams(layoutParams);
listView.setAdapter(listAdapter = new ListAdapter(getParentActivity()));
listView.setAdapter(listAdapter = new ListAdapter(context));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
@ -396,12 +396,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
}
});
}
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
@ -526,7 +521,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
} catch (Exception e) {
FileLog.e("tmessages", e);
}
shakeTextView(2, 0);
AndroidUtilities.shakeTextView(titleTextView, 2, 0);
passwordEditText.setText("");
return;
}
@ -550,23 +545,6 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
}
}
private void shakeTextView(final float x, final int num) {
if (num == 6) {
titleTextView.clearAnimation();
return;
}
AnimatorSetProxy animatorSetProxy = new AnimatorSetProxy();
animatorSetProxy.playTogether(ObjectAnimatorProxy.ofFloat(titleTextView, "translationX", AndroidUtilities.dp(x)));
animatorSetProxy.setDuration(50);
animatorSetProxy.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Object animation) {
shakeTextView(num == 5 ? 0 : -x, num + 1);
}
});
animatorSetProxy.start();
}
private void onPasscodeError() {
if (getParentActivity() == null) {
return;
@ -575,7 +553,7 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
if (v != null) {
v.vibrate(200);
}
shakeTextView(2, 0);
AndroidUtilities.shakeTextView(titleTextView, 2, 0);
}
private void fixLayoutInternal() {

View File

@ -95,8 +95,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
@SuppressWarnings("unchecked")
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackgroundColor(0xff333333);
actionBar.setItemsBackground(R.drawable.bar_selector_picker);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
@ -123,12 +122,12 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
ActionBarMenu menu = actionBar.createMenu();
menu.addItem(1, R.drawable.ic_ab_other);
fragmentView = new FrameLayout(getParentActivity());
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xff000000);
listView = new ListView(getParentActivity());
listView = new ListView(context);
listView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), AndroidUtilities.dp(4));
listView.setClipToPadding(false);
listView.setHorizontalScrollBarEnabled(false);
@ -144,10 +143,10 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.bottomMargin = AndroidUtilities.dp(48);
listView.setLayoutParams(layoutParams);
listView.setAdapter(listAdapter = new ListAdapter(getParentActivity()));
listView.setAdapter(listAdapter = new ListAdapter(context));
AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);
emptyView = new TextView(getParentActivity());
emptyView = new TextView(context);
emptyView.setTextColor(0xff808080);
emptyView.setTextSize(20);
emptyView.setGravity(Gravity.CENTER);
@ -166,7 +165,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
}
});
progressView = new FrameLayout(getParentActivity());
progressView = new FrameLayout(context);
progressView.setVisibility(View.GONE);
frameLayout.addView(progressView);
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
@ -175,7 +174,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
layoutParams.bottomMargin = AndroidUtilities.dp(48);
progressView.setLayoutParams(layoutParams);
ProgressBar progressBar = new ProgressBar(getParentActivity());
ProgressBar progressBar = new ProgressBar(context);
progressView.addView(progressBar);
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
@ -183,7 +182,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
layoutParams.gravity = Gravity.CENTER;
progressView.setLayoutParams(layoutParams);
photoPickerBottomLayout = new PhotoPickerBottomLayout(getParentActivity());
photoPickerBottomLayout = new PhotoPickerBottomLayout(context);
frameLayout.addView(photoPickerBottomLayout);
layoutParams = (FrameLayout.LayoutParams) photoPickerBottomLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
@ -212,12 +211,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
listView.setEmptyView(emptyView);
}
photoPickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -19,7 +19,6 @@ import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import org.telegram.android.AndroidUtilities;
@ -432,8 +431,7 @@ public class PhotoCropActivity extends BaseFragment {
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackgroundColor(0xff333333);
actionBar.setItemsBackground(R.drawable.bar_selector_picker);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
@ -461,15 +459,10 @@ public class PhotoCropActivity extends BaseFragment {
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
fragmentView = view = new PhotoCropView(getParentActivity());
fragmentView = view = new PhotoCropView(context);
((PhotoCropView) fragmentView).freeform = getArguments().getBoolean("freeform", false);
fragmentView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -142,8 +142,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@SuppressWarnings("unchecked")
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackgroundColor(0xff333333);
actionBar.setItemsBackground(R.drawable.bar_selector_picker);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
@ -239,12 +238,12 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
}
fragmentView = new FrameLayout(getParentActivity());
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xff000000);
listView = new GridView(getParentActivity());
listView = new GridView(context);
listView.setPadding(AndroidUtilities.dp(4), AndroidUtilities.dp(4), AndroidUtilities.dp(4), AndroidUtilities.dp(4));
listView.setClipToPadding(false);
listView.setDrawSelectorOnTop(true);
@ -261,7 +260,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
listView.setLayoutParams(layoutParams);
listView.setAdapter(listAdapter = new ListAdapter(getParentActivity()));
listView.setAdapter(listAdapter = new ListAdapter(context));
AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
@ -311,7 +310,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
});
}
emptyView = new TextView(getParentActivity());
emptyView = new TextView(context);
emptyView.setTextColor(0xff808080);
emptyView.setTextSize(20);
emptyView.setGravity(Gravity.CENTER);
@ -359,7 +358,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
});
progressView = new FrameLayout(getParentActivity());
progressView = new FrameLayout(context);
progressView.setVisibility(View.GONE);
frameLayout.addView(progressView);
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
@ -368,7 +367,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
progressView.setLayoutParams(layoutParams);
ProgressBar progressBar = new ProgressBar(getParentActivity());
ProgressBar progressBar = new ProgressBar(context);
progressView.addView(progressBar);
layoutParams = (FrameLayout.LayoutParams) progressBar.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
@ -379,7 +378,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
updateSearchInterface();
}
photoPickerBottomLayout = new PhotoPickerBottomLayout(getParentActivity());
photoPickerBottomLayout = new PhotoPickerBottomLayout(context);
frameLayout.addView(photoPickerBottomLayout);
layoutParams = (FrameLayout.LayoutParams) photoPickerBottomLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
@ -405,12 +404,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
listView.setEmptyView(emptyView);
photoPickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
@ -488,7 +482,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
object.viewX = coords[0];
object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = cell.photoImage.imageReceiver;
object.imageReceiver = cell.photoImage.getImageReceiver();
object.thumb = object.imageReceiver.getBitmap();
cell.checkBox.setVisibility(View.GONE);
return object;
@ -534,7 +528,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
public Bitmap getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
PhotoPickerPhotoCell cell = getCellForIndex(index);
if (cell != null) {
return cell.photoImage.imageReceiver.getBitmap();
return cell.photoImage.getImageReceiver().getBitmap();
}
return null;
}
@ -1057,7 +1051,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
cell.checkBox.setChecked(selectedWebPhotos.containsKey(photoEntry.id), false);
showing = PhotoViewer.getInstance().isShowingImage(photoEntry.thumbUrl);
}
imageView.imageReceiver.setVisible(!showing, false);
imageView.getImageReceiver().setVisible(!showing, false);
cell.checkBox.setVisibility(singlePhoto || showing ? View.GONE : View.VISIBLE);
} else if (viewType == 1) {
if (view == null) {

View File

@ -207,7 +207,7 @@ public class PopupNotificationActivity extends Activity implements NotificationC
}
@Override
public void onTextChanged(CharSequence text) {
public void onTextChanged(CharSequence text, boolean big) {
}
@ -264,8 +264,7 @@ public class PopupNotificationActivity extends Activity implements NotificationC
avatarContainer.setLayoutParams(layoutParams2);
avatarImageView = new BackupImageView(this);
avatarImageView.imageReceiver.setRoundRadius(AndroidUtilities.dp(21));
avatarImageView.processDetach = false;
avatarImageView.setRoundRadius(AndroidUtilities.dp(21));
avatarContainer.addView(avatarImageView);
layoutParams2 = (FrameLayout.LayoutParams) avatarImageView.getLayoutParams();
layoutParams2.width = AndroidUtilities.dp(42);
@ -549,7 +548,7 @@ public class PopupNotificationActivity extends Activity implements NotificationC
TextView messageText = (TextView)view.findViewById(R.id.message_text);
BackupImageView imageView = (BackupImageView) view.findViewById(R.id.message_image);
imageView.imageReceiver.setAspectFit(true);
imageView.setAspectFit(true);
if (messageObject.type == 1) {
TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
@ -986,6 +985,7 @@ public class PopupNotificationActivity extends Activity implements NotificationC
}
ConnectionsManager.getInstance().setAppPaused(false, false);
fixLayout();
checkAndUpdateAvatar();
wakeLock.acquire(7000);
}

View File

@ -19,12 +19,10 @@ import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.Toast;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.ContactsController;
import org.telegram.android.LocaleController;
import org.telegram.android.MessagesController;
import org.telegram.android.NotificationCenter;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
@ -51,10 +49,10 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
private int lastSeenRow;
private int lastSeenDetailRow;
private int securitySectionRow;
private int terminateSessionsRow;
private int sessionsRow;
private int passwordRow;
private int passcodeRow;
private int terminateSessionsDetailRow;
private int sessionsDetailRow;
private int deleteAccountSectionRow;
private int deleteAccountRow;
private int deleteAccountDetailRow;
@ -73,12 +71,12 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
lastSeenDetailRow = rowCount++;
securitySectionRow = rowCount++;
passcodeRow = rowCount++;
terminateSessionsRow = rowCount++;
terminateSessionsDetailRow = rowCount++;
passwordRow = rowCount++;
sessionsRow = rowCount++;
sessionsDetailRow = rowCount++;
deleteAccountSectionRow = rowCount++;
deleteAccountRow = rowCount++;
deleteAccountDetailRow = rowCount++;
passwordRow = -1;
NotificationCenter.getInstance().addObserver(this, NotificationCenter.privacyRulesUpdated);
@ -92,8 +90,7 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("PrivacySettings", R.string.PrivacySettings));
@ -106,13 +103,13 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
}
});
listAdapter = new ListAdapter(getParentActivity());
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(getParentActivity());
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xfff0f0f0);
ListView listView = new ListView(getParentActivity());
ListView listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
@ -129,53 +126,15 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
if (i == blockedRow) {
presentFragment(new BlockedUsersActivity());
} else if (i == terminateSessionsRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSureSessions", R.string.AreYouSureSessions));
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) {
TLRPC.TL_auth_resetAuthorizations req = new TLRPC.TL_auth_resetAuthorizations();
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(final TLObject response, final TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (getParentActivity() == null) {
return;
}
if (error == null && response instanceof TLRPC.TL_boolTrue) {
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions), Toast.LENGTH_SHORT);
toast.show();
} else {
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("UnknownError", R.string.UnknownError), Toast.LENGTH_SHORT);
toast.show();
}
}
});
UserConfig.registeredForPush = false;
UserConfig.registeredForInternalPush = false;
UserConfig.saveConfig(false);
MessagesController.getInstance().registerForPush(UserConfig.pushString);
ConnectionsManager.getInstance().initPushConnection();
}
});
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == sessionsRow) {
presentFragment(new SessionsActivity());
} else if (i == deleteAccountRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("DeleteAccountTitle", R.string.DeleteAccountTitle));
builder.setItems(new CharSequence[] {
builder.setItems(new CharSequence[]{
LocaleController.formatPluralString("Months", 1),
LocaleController.formatPluralString("Months", 3),
LocaleController.formatPluralString("Months", 6),
@ -228,7 +187,7 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
} else if (i == lastSeenRow) {
presentFragment(new LastSeenActivity());
} else if (i == passwordRow) {
presentFragment(new AccountPasswordActivity(0));
presentFragment(new TwoStepVerificationActivity(0));
} else if (i == passcodeRow) {
if (UserConfig.passcodeHash.length() > 0) {
presentFragment(new PasscodeActivity(2));
@ -238,12 +197,7 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
}
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
@ -327,7 +281,7 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
@Override
public boolean isEnabled(int i) {
return i == passcodeRow || i == passwordRow || i == blockedRow || i == terminateSessionsRow || i == lastSeenRow && !ContactsController.getInstance().getLoadingLastSeenInfo() || i == deleteAccountRow && !ContactsController.getInstance().getLoadingDeleteInfo();
return i == passcodeRow || i == passwordRow || i == blockedRow || i == sessionsRow || i == lastSeenRow && !ContactsController.getInstance().getLoadingLastSeenInfo() || i == deleteAccountRow && !ContactsController.getInstance().getLoadingDeleteInfo();
}
@Override
@ -361,10 +315,10 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
TextSettingsCell textCell = (TextSettingsCell) view;
if (i == blockedRow) {
textCell.setText(LocaleController.getString("BlockedUsers", R.string.BlockedUsers), true);
} else if (i == terminateSessionsRow) {
textCell.setText(LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions), false);
} else if (i == sessionsRow) {
textCell.setText(LocaleController.getString("SessionsTitle", R.string.SessionsTitle), false);
} else if (i == passwordRow) {
textCell.setText(LocaleController.getString("Password", R.string.Password), true);
textCell.setText(LocaleController.getString("TwoStepVerification", R.string.TwoStepVerification), true);
} else if (i == passcodeRow) {
textCell.setText(LocaleController.getString("Passcode", R.string.Passcode), true);
} else if (i == lastSeenRow) {
@ -401,8 +355,8 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
} else if (i == lastSeenDetailRow) {
((TextInfoPrivacyCell) view).setText(LocaleController.getString("LastSeenHelp", R.string.LastSeenHelp));
view.setBackgroundResource(R.drawable.greydivider);
} else if (i == terminateSessionsDetailRow) {
((TextInfoPrivacyCell) view).setText(LocaleController.getString("ClearOtherSessionsHelp", R.string.ClearOtherSessionsHelp));
} else if (i == sessionsDetailRow) {
((TextInfoPrivacyCell) view).setText(LocaleController.getString("SessionsInfo", R.string.SessionsInfo));
view.setBackgroundResource(R.drawable.greydivider);
}
} else if (type == 2) {
@ -423,9 +377,9 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
@Override
public int getItemViewType(int i) {
if (i == lastSeenRow || i == blockedRow || i == deleteAccountRow || i == terminateSessionsRow || i == passwordRow || i == passcodeRow) {
if (i == lastSeenRow || i == blockedRow || i == deleteAccountRow || i == sessionsRow || i == passwordRow || i == passcodeRow) {
return 0;
} else if (i == deleteAccountDetailRow || i == lastSeenDetailRow || i == terminateSessionsDetailRow) {
} else if (i == deleteAccountDetailRow || i == lastSeenDetailRow || i == sessionsDetailRow) {
return 1;
} else if (i == securitySectionRow || i == deleteAccountSectionRow || i == privacySectionRow) {
return 2;

View File

@ -20,7 +20,6 @@ import android.graphics.Outline;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
@ -208,9 +207,6 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
if (avatarImage != null) {
avatarImage.setImageDrawable(null);
}
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mediaCountDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
@ -227,8 +223,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackgroundColor(AvatarDrawable.getProfileBackColorForId(user_id != 0 ? 5 : chat_id));
actionBar.setItemsBackground(AvatarDrawable.getButtonColorForId(user_id != 0 ? 5 : chat_id));
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
@ -344,14 +339,13 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
createActionBarMenu();
listAdapter = new ListAdapter(getParentActivity());
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(getParentActivity());
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
avatarImage = new BackupImageView(getParentActivity());
avatarImage.imageReceiver.setRoundRadius(AndroidUtilities.dp(30));
avatarImage.processDetach = false;
avatarImage = new BackupImageView(context);
avatarImage.setRoundRadius(AndroidUtilities.dp(30));
actionBar.addView(avatarImage);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
@ -380,7 +374,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
}
});
nameTextView = new TextView(getParentActivity());
nameTextView = new TextView(context);
nameTextView.setTextColor(0xffffffff);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
nameTextView.setLines(1);
@ -399,7 +393,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
nameTextView.setLayoutParams(layoutParams);
onlineTextView = new TextView(getParentActivity());
onlineTextView = new TextView(context);
onlineTextView.setTextColor(AvatarDrawable.getProfileTextColorForId(user_id != 0 ? 5 : chat_id));
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
onlineTextView.setLines(1);
@ -417,7 +411,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
onlineTextView.setLayoutParams(layoutParams);
listView = new ListView(getParentActivity());
listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
@ -446,7 +440,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
presentFragment(new MediaActivity(args));
} else if (i == settingsKeyRow) {
Bundle args = new Bundle();
args.putInt("chat_id", (int)(dialog_id >> 32));
args.putInt("chat_id", (int) (dialog_id >> 32));
presentFragment(new IdenticonActivity(args));
} else if (i == settingsTimerRow) {
if (getParentActivity() == null) {
@ -481,7 +475,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setItems(new CharSequence[] {LocaleController.getString("Call", R.string.Call), LocaleController.getString("Copy", R.string.Copy)}, new DialogInterface.OnClickListener() {
builder.setItems(new CharSequence[]{LocaleController.getString("Call", R.string.Call), LocaleController.getString("Copy", R.string.Copy)}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
@ -493,11 +487,11 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
FileLog.e("tmessages", e);
}
} else if (i == 1) {
if(Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText("+" + user.phone);
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("label", "+" + user.phone);
clipboard.setPrimaryClip(clip);
}
@ -562,7 +556,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
frameLayout.addView(actionBar);
if (user_id != 0 || chat_id >= 0 && !currentChat.left) {
writeButton = new ImageView(getParentActivity());
writeButton = new ImageView(context);
writeButton.setBackgroundResource(R.drawable.floating_user_states);
writeButton.setScaleType(ImageView.ScaleType.CENTER);
if (user_id != 0) {
@ -574,8 +568,8 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
frameLayout.addView(writeButton);
if (Build.VERSION.SDK_INT >= 21) {
StateListAnimator animator = new StateListAnimator();
animator.addState(new int[] {android.R.attr.state_pressed}, ObjectAnimator.ofFloat(writeButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
animator.addState(new int[] {}, ObjectAnimator.ofFloat(writeButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
animator.addState(new int[]{android.R.attr.state_pressed}, ObjectAnimator.ofFloat(writeButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
animator.addState(new int[]{}, ObjectAnimator.ofFloat(writeButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
writeButton.setStateListAnimator(animator);
writeButton.setOutlineProvider(new ViewOutlineProvider() {
@Override
@ -648,13 +642,6 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
}
});
updateProfileData();
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
@ -733,7 +720,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
}
}
avatarImage.imageReceiver.setRoundRadius(AndroidUtilities.dp(avatarSize / 2));
avatarImage.setRoundRadius(AndroidUtilities.dp(avatarSize / 2));
layoutParams = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(avatarSize);
layoutParams.height = AndroidUtilities.dp(avatarSize);
@ -889,6 +876,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
updateProfileData();
fixLayout();
}
@ -924,11 +912,11 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
object.viewX = coords[0];
object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
object.parentView = avatarImage;
object.imageReceiver = avatarImage.imageReceiver;
object.imageReceiver = avatarImage.getImageReceiver();
object.user_id = user_id;
object.thumb = object.imageReceiver.getBitmap();
object.size = -1;
object.radius = avatarImage.imageReceiver.getRoundRadius();
object.radius = avatarImage.getImageReceiver().getRoundRadius();
return object;
}
return null;
@ -944,7 +932,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
@Override
public void willHidePhotoViewer() {
avatarImage.imageReceiver.setVisible(true, true);
avatarImage.getImageReceiver().setVisible(true, true);
}
@Override
@ -1044,7 +1032,6 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
MessagesController.getInstance().deleteUserFromChat(chat_id, MessagesController.getInstance().getUser(UserConfig.getClientUserId()), info);
MessagesController.getInstance().deleteDialog(-chat_id, 0, false);
finishFragment();
}
}
@ -1123,7 +1110,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
}
onlineTextView.setText(LocaleController.formatUserStatus(user));
avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
avatarImage.getImageReceiver().setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
} else if (chat_id != 0) {
TLRPC.Chat chat = MessagesController.getInstance().getChat(chat_id);
if (chat != null) {
@ -1137,7 +1124,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
}
if (count != 0 && onlineCount > 1) {
onlineTextView.setText(Html.fromHtml(String.format("%s, %s", LocaleController.formatPluralString("Members", count), LocaleController.formatPluralString("Online", onlineCount))));
onlineTextView.setText(String.format("%s, %s", LocaleController.formatPluralString("Members", count), LocaleController.formatPluralString("Online", onlineCount)));
} else {
onlineTextView.setText(LocaleController.formatPluralString("Members", count));
}
@ -1150,7 +1137,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
}
avatarImage.setImage(photo, "50_50", new AvatarDrawable(chat, true));
avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
avatarImage.getImageReceiver().setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
}
}

View File

@ -85,8 +85,7 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds));
@ -99,10 +98,10 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
}
});
fragmentView = new FrameLayout(getParentActivity());
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
listView = new ListView(getParentActivity());
listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
@ -112,14 +111,14 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setAdapter(new ListAdapter(getParentActivity()));
listView.setAdapter(new ListAdapter(context));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
if (i == settingsVibrateRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("Vibrate", R.string.Vibrate));
builder.setItems(new CharSequence[] {
builder.setItems(new CharSequence[]{
LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled),
LocaleController.getString("SettingsDefault", R.string.SettingsDefault),
LocaleController.getString("SystemDefault", R.string.SystemDefault),
@ -155,7 +154,7 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setItems(new CharSequence[] {
builder.setItems(new CharSequence[]{
LocaleController.getString("Default", R.string.Default),
LocaleController.getString("Enabled", R.string.Enabled),
LocaleController.getString("NotificationsDisabled", R.string.NotificationsDisabled)
@ -216,15 +215,15 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
return;
}
LayoutInflater li = (LayoutInflater)getParentActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater li = (LayoutInflater) getParentActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.settings_color_dialog_layout, null, false);
final ColorPickerView colorPickerView = (ColorPickerView)view.findViewById(R.id.color_picker);
final ColorPickerView colorPickerView = (ColorPickerView) view.findViewById(R.id.color_picker);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (preferences.contains("color_" + dialog_id)) {
colorPickerView.setOldCenterColor(preferences.getInt("color_" + dialog_id, 0xff00ff00));
} else {
if ((int)dialog_id < 0) {
if ((int) dialog_id < 0) {
colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
} else {
colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00));
@ -268,7 +267,7 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
} else if (i == settingsPriorityRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority));
builder.setItems(new CharSequence[] {
builder.setItems(new CharSequence[]{
LocaleController.getString("SettingsDefault", R.string.SettingsDefault),
LocaleController.getString("NotificationsPriorityDefault", R.string.NotificationsPriorityDefault),
LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh),
@ -293,12 +292,7 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
}
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
@ -314,7 +308,7 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
Ringtone rng = RingtoneManager.getRingtone(ApplicationLoader.applicationContext, ringtone);
if (rng != null) {
if(ringtone.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
name = LocaleController.getString("Default", R.string.Default);
name = LocaleController.getString("SoundDefault", R.string.SoundDefault);
} else {
name = rng.getTitle(getParentActivity());
}
@ -437,7 +431,7 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
}
}
} else if (i == settingsSoundRow) {
String value = preferences.getString("sound_" + dialog_id, LocaleController.getString("Default", R.string.Default));
String value = preferences.getString("sound_" + dialog_id, LocaleController.getString("SoundDefault", R.string.SoundDefault));
if (value.equals("NoSound")) {
value = LocaleController.getString("NoSound", R.string.NoSound);
}

View File

@ -0,0 +1,475 @@
/*
* This is the source code of Telegram for Android v. 2.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-2015.
*/
package org.telegram.ui;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Build;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.android.MessagesController;
import org.telegram.android.NotificationCenter;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.Cells.HeaderCell;
import org.telegram.ui.Cells.SessionCell;
import org.telegram.ui.Cells.TextInfoPrivacyCell;
import org.telegram.ui.Cells.TextSettingsCell;
import java.util.ArrayList;
public class SessionsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
private ListAdapter listAdapter;
private ArrayList<TLRPC.TL_authorization> sessions = new ArrayList<>();
private TLRPC.TL_authorization currentSession = null;
private boolean loading;
private LinearLayout emptyLayout;
private int currentSessionSectionRow;
private int currentSessionRow;
private int terminateAllSessionsRow;
private int terminateAllSessionsDetailRow;
private int otherSessionsSectionRow;
private int otherSessionsStartRow;
private int otherSessionsEndRow;
private int otherSessionsTerminateDetail;
private int noOtherSessionsRow;
private int rowCount;
@Override
public boolean onFragmentCreate() {
super.onFragmentCreate();
updateRows();
loadSessions(false);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.newSessionReceived);
return true;
}
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.newSessionReceived);
}
@Override
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("SessionsTitle", R.string.SessionsTitle));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xfff0f0f0);
emptyLayout = new LinearLayout(context);
emptyLayout.setOrientation(LinearLayout.VERTICAL);
emptyLayout.setGravity(Gravity.CENTER);
emptyLayout.setBackgroundResource(R.drawable.greydivider_bottom);
emptyLayout.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AndroidUtilities.displaySize.y - AndroidUtilities.getCurrentActionBarHeight()));
ImageView imageView = new ImageView(context);
imageView.setImageResource(R.drawable.devices);
emptyLayout.addView(imageView);
LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams();
layoutParams2.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.height = LinearLayout.LayoutParams.WRAP_CONTENT;
imageView.setLayoutParams(layoutParams2);
TextView textView = new TextView(context);
textView.setTextColor(0xff8a8a8a);
textView.setGravity(Gravity.CENTER);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setText(LocaleController.getString("NoOtherSessions", R.string.NoOtherSessions));
emptyLayout.addView(textView);
layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
layoutParams2.topMargin = AndroidUtilities.dp(16);
layoutParams2.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER;
textView.setLayoutParams(layoutParams2);
textView = new TextView(context);
textView.setTextColor(0xff8a8a8a);
textView.setGravity(Gravity.CENTER);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
textView.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0);
textView.setText(LocaleController.getString("NoOtherSessionsInfo", R.string.NoOtherSessionsInfo));
emptyLayout.addView(textView);
layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
layoutParams2.topMargin = AndroidUtilities.dp(14);
layoutParams2.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER;
textView.setLayoutParams(layoutParams2);
FrameLayout progressView = new FrameLayout(context);
frameLayout.addView(progressView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
progressView.setLayoutParams(layoutParams);
progressView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
ProgressBar progressBar = new ProgressBar(context);
progressView.addView(progressBar);
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.CENTER;
progressView.setLayoutParams(layoutParams);
ListView listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
listView.setDrawSelectorOnTop(true);
listView.setEmptyView(progressView);
frameLayout.addView(listView);
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP;
listView.setLayoutParams(layoutParams);
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
if (i == terminateAllSessionsRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSureSessions", R.string.AreYouSureSessions));
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) {
TLRPC.TL_auth_resetAuthorizations req = new TLRPC.TL_auth_resetAuthorizations();
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(final TLObject response, final TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (getParentActivity() == null) {
return;
}
if (error == null && response instanceof TLRPC.TL_boolTrue) {
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions), Toast.LENGTH_SHORT);
toast.show();
} else {
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("UnknownError", R.string.UnknownError), Toast.LENGTH_SHORT);
toast.show();
}
finishFragment();
}
});
UserConfig.registeredForPush = false;
UserConfig.registeredForInternalPush = false;
UserConfig.saveConfig(false);
MessagesController.getInstance().registerForPush(UserConfig.pushString);
ConnectionsManager.getInstance().initPushConnection();
}
});
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i >= otherSessionsStartRow && i < otherSessionsEndRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("TerminateSessionQuestion", R.string.TerminateSessionQuestion));
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 option) {
final ProgressDialog progressDialog = new ProgressDialog(getParentActivity());
progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
progressDialog.show();
final TLRPC.TL_authorization authorization = sessions.get(i - otherSessionsStartRow);
TLRPC.TL_account_resetAuthorization req = new TLRPC.TL_account_resetAuthorization();
req.hash = authorization.hash;
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(final TLObject response, final TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (error == null) {
sessions.remove(authorization);
updateRows();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
}
});
}
});
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
}
});
return fragmentView;
}
@Override
public void onResume() {
super.onResume();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.newSessionReceived) {
loadSessions(true);
}
}
private void loadSessions(boolean silent) {
if (loading) {
return;
}
if (!silent) {
loading = true;
}
TLRPC.TL_account_getAuthorizations req = new TLRPC.TL_account_getAuthorizations();
long reqId = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(final TLObject response, final TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
loading = false;
if (error == null) {
sessions.clear();
TLRPC.TL_account_authorizations res = (TLRPC.TL_account_authorizations) response;
for (TLRPC.TL_authorization authorization : res.authorizations) {
if ((authorization.flags & 1) != 0) {
currentSession = authorization;
} else {
sessions.add(authorization);
}
}
updateRows();
}
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
});
}
});
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
}
private void updateRows() {
rowCount = 0;
if (currentSession != null) {
currentSessionSectionRow = rowCount++;
currentSessionRow = rowCount++;
} else {
currentSessionRow = -1;
currentSessionSectionRow = -1;
}
if (sessions.isEmpty()) {
noOtherSessionsRow = -1;
terminateAllSessionsRow = -1;
terminateAllSessionsDetailRow = -1;
otherSessionsSectionRow = -1;
otherSessionsStartRow = -1;
otherSessionsEndRow = -1;
otherSessionsTerminateDetail = -1;
} else {
noOtherSessionsRow = -1;
terminateAllSessionsRow = rowCount++;
terminateAllSessionsDetailRow = rowCount++;
otherSessionsSectionRow = rowCount++;
otherSessionsStartRow = otherSessionsSectionRow + 1;
otherSessionsEndRow = otherSessionsStartRow + sessions.size();
rowCount += sessions.size();
otherSessionsTerminateDetail = rowCount++;
}
}
private class ListAdapter extends BaseFragmentAdapter {
private Context mContext;
public ListAdapter(Context context) {
mContext = context;
}
@Override
public boolean areAllItemsEnabled() {
return false;
}
@Override
public boolean isEnabled(int i) {
return i == terminateAllSessionsRow || i >= otherSessionsStartRow && i < otherSessionsEndRow;
}
@Override
public int getCount() {
return loading ? 0 : 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) {
view = new TextSettingsCell(mContext);
view.setBackgroundColor(0xffffffff);
}
TextSettingsCell textCell = (TextSettingsCell) view;
if (i == terminateAllSessionsRow) {
textCell.setTextColor(0xffdb5151);
textCell.setText(LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions), false);
}
} else if (type == 1) {
if (view == null) {
view = new TextInfoPrivacyCell(mContext);
}
if (i == terminateAllSessionsDetailRow) {
((TextInfoPrivacyCell) view).setText(LocaleController.getString("ClearOtherSessionsHelp", R.string.ClearOtherSessionsHelp));
view.setBackgroundResource(R.drawable.greydivider);
} else if (i == otherSessionsTerminateDetail) {
((TextInfoPrivacyCell) view).setText(LocaleController.getString("TerminateSessionInfo", R.string.TerminateSessionInfo));
view.setBackgroundResource(R.drawable.greydivider_bottom);
}
} else if (type == 2) {
if (view == null) {
view = new HeaderCell(mContext);
view.setBackgroundColor(0xffffffff);
}
if (i == currentSessionSectionRow) {
((HeaderCell) view).setText(LocaleController.getString("CurrentSession", R.string.CurrentSession));
} else if (i == otherSessionsSectionRow) {
((HeaderCell) view).setText(LocaleController.getString("OtherSessions", R.string.OtherSessions));
}
} else if (type == 3) {
ViewGroup.LayoutParams layoutParams = emptyLayout.getLayoutParams();
if (layoutParams != null) {
layoutParams.height = Math.max(AndroidUtilities.dp(220), AndroidUtilities.displaySize.y - AndroidUtilities.getCurrentActionBarHeight() - AndroidUtilities.dp(128) - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0));
emptyLayout.setLayoutParams(layoutParams);
}
return emptyLayout;
} else if (type == 4) {
if (view == null) {
view = new SessionCell(mContext);
view.setBackgroundColor(0xffffffff);
}
if (i == currentSessionRow) {
((SessionCell) view).setSession(currentSession, !sessions.isEmpty());
} else {
((SessionCell) view).setSession(sessions.get(i - otherSessionsStartRow), i != otherSessionsEndRow - 1);
}
}
return view;
}
@Override
public int getItemViewType(int i) {
if (i == terminateAllSessionsRow) {
return 0;
} else if (i == terminateAllSessionsDetailRow || i == otherSessionsTerminateDetail) {
return 1;
} else if (i == currentSessionSectionRow || i == otherSessionsSectionRow) {
return 2;
} else if (i == noOtherSessionsRow) {
return 3;
} else if (i == currentSessionRow || i >= otherSessionsStartRow && i < otherSessionsEndRow) {
return 4;
}
return 0;
}
@Override
public int getViewTypeCount() {
return 5;
}
@Override
public boolean isEmpty() {
return loading;
}
}
}

View File

@ -268,8 +268,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackgroundColor(AvatarDrawable.getProfileBackColorForId(5));
actionBar.setItemsBackground(AvatarDrawable.getButtonColorForId(5));
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
@ -316,14 +315,13 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
item.addSubItem(edit_name, LocaleController.getString("EditName", R.string.EditName), 0);
item.addSubItem(logout, LocaleController.getString("LogOut", R.string.LogOut), 0);
listAdapter = new ListAdapter(getParentActivity());
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(getParentActivity());
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
avatarImage = new BackupImageView(getParentActivity());
avatarImage.imageReceiver.setRoundRadius(AndroidUtilities.dp(30));
avatarImage.processDetach = false;
avatarImage = new BackupImageView(context);
avatarImage.setRoundRadius(AndroidUtilities.dp(30));
actionBar.addView(avatarImage);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
@ -344,7 +342,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
});
nameTextView = new TextView(getParentActivity());
nameTextView = new TextView(context);
nameTextView.setTextColor(0xffffffff);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
nameTextView.setLines(1);
@ -363,7 +361,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
nameTextView.setLayoutParams(layoutParams);
onlineTextView = new TextView(getParentActivity());
onlineTextView = new TextView(context);
onlineTextView.setTextColor(AvatarDrawable.getProfileTextColorForId(5));
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
onlineTextView.setLines(1);
@ -381,7 +379,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
onlineTextView.setLayoutParams(layoutParams);
listView = new ListView(getParentActivity());
listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
@ -506,7 +504,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("SortBy", R.string.SortBy));
builder.setItems(new CharSequence[] {
builder.setItems(new CharSequence[]{
LocaleController.getString("Default", R.string.Default),
LocaleController.getString("SortFirstName", R.string.SortFirstName),
LocaleController.getString("SortLastName", R.string.SortLastName)
@ -603,14 +601,14 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
frameLayout.addView(actionBar);
writeButton = new ImageView(getParentActivity());
writeButton = new ImageView(context);
writeButton.setBackgroundResource(R.drawable.floating_user_states);
writeButton.setImageResource(R.drawable.floating_camera);
writeButton.setScaleType(ImageView.ScaleType.CENTER);
if (Build.VERSION.SDK_INT >= 21) {
StateListAnimator animator = new StateListAnimator();
animator.addState(new int[] {android.R.attr.state_pressed}, ObjectAnimator.ofFloat(writeButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
animator.addState(new int[] {}, ObjectAnimator.ofFloat(writeButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
animator.addState(new int[]{android.R.attr.state_pressed}, ObjectAnimator.ofFloat(writeButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
animator.addState(new int[]{}, ObjectAnimator.ofFloat(writeButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
writeButton.setStateListAnimator(animator);
writeButton.setOutlineProvider(new ViewOutlineProvider() {
@Override
@ -646,10 +644,10 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
boolean fullMenu = false;
if (user.photo != null && user.photo.photo_big != null && !(user.photo instanceof TLRPC.TL_userProfilePhotoEmpty)) {
items = new CharSequence[] {LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto)};
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto)};
fullMenu = true;
} else {
items = new CharSequence[] {LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley)};
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley)};
}
final boolean full = fullMenu;
@ -694,13 +692,6 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
});
updateUserData();
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}
@ -729,11 +720,11 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
object.viewX = coords[0];
object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
object.parentView = avatarImage;
object.imageReceiver = avatarImage.imageReceiver;
object.imageReceiver = avatarImage.getImageReceiver();
object.user_id = UserConfig.getClientUserId();
object.thumb = object.imageReceiver.getBitmap();
object.size = -1;
object.radius = avatarImage.imageReceiver.getRoundRadius();
object.radius = avatarImage.getImageReceiver().getRoundRadius();
return object;
}
}
@ -750,7 +741,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
@Override
public void willHidePhotoViewer() {
avatarImage.imageReceiver.setVisible(true, true);
avatarImage.getImageReceiver().setVisible(true, true);
}
@Override
@ -888,6 +879,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
updateUserData();
fixLayout();
}
@ -927,7 +919,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
writeButton.clearAnimation();
}
avatarImage.imageReceiver.setRoundRadius(AndroidUtilities.dp(avatarSize / 2));
avatarImage.setRoundRadius(AndroidUtilities.dp(avatarSize / 2));
layoutParams = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(avatarSize);
layoutParams.height = AndroidUtilities.dp(avatarSize);
@ -982,12 +974,12 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
avatarDrawable.setColor(0xff5c98cd);
if (avatarImage != null) {
avatarImage.setImage(photo, "50_50", avatarDrawable);
avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
avatarImage.getImageReceiver().setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
onlineTextView.setText(LocaleController.getString("Online", R.string.Online));
avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
avatarImage.getImageReceiver().setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,7 @@ package org.telegram.ui;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.SurfaceTexture;
@ -22,7 +23,6 @@ import android.view.LayoutInflater;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.CheckBox;
import android.widget.CompoundButton;
@ -224,8 +224,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackgroundColor(0xff333333);
actionBar.setItemsBackground(R.drawable.bar_selector_white);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
@ -401,12 +400,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
updateVideoOriginalInfo();
updateVideoEditedInfo();
} else {
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

View File

@ -101,8 +101,7 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("ChatBackground", R.string.ChatBackground));
@ -159,11 +158,11 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
fragmentView = inflater.inflate(R.layout.settings_wallpapers_layout, null, false);
listAdapter = new ListAdapter(getParentActivity());
listAdapter = new ListAdapter(context);
progressBar = (ProgressBar)fragmentView.findViewById(R.id.action_progress);
backgroundImage = (ImageView)fragmentView.findViewById(R.id.background_image);
listView = (HorizontalListView)fragmentView.findViewById(R.id.listView);
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
@ -174,7 +173,7 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
}
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)};
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
@ -209,12 +208,7 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
});
processSelectedBackground();
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
return fragmentView;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 990 B

Some files were not shown because too many files have changed in this diff Show More