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;
ArrayList<Integer> bolds = new ArrayList<>();
while ((start = str.indexOf("<b>")) != -1) {
int end = str.indexOf("</b>") - 3;
str = str.replaceFirst("<b>", "").replaceFirst("</b>", "");
bolds.add(start);
bolds.add(end);
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<>();
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 spannableStringBuilder = new SpannableStringBuilder(stringBuilder);
for (int a = 0; a < bolds.size() / 2; a++) {
spannableStringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
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);
}
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(str);
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);
}
return stringBuilder;
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,12 +1471,21 @@ 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 (message.media.bytes.length == 0 || message.media.bytes.length == 1 && message.media.bytes[0] < TLRPC.LAYER) {
if (messagesToReload == null) {
messagesToReload = new ArrayList<>();
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);
}
messagesToReload.add(message.id);
}
}
}
@ -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);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
MessagesController.getInstance().deleteDialog(-chat_id, 0, false);
}
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);
}
}
});
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);
MessagesStorage.lastDateValue = updates.date;
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,67 +571,74 @@ 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;
}
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);
if (newMsgObj == null) {
continue;
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--;
}
final int oldId = newMsgObj.id;
final ArrayList<TLRPC.Message> sentMessages = new ArrayList<>();
sentMessages.add(message);
newMsgObj.id = message.id;
processSentMessage(newMsgObj, message, null);
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
MessagesStorage.getInstance().updateMessageStateAndId(newMsgObj.random_id, oldId, newMsgObj.id, 0, false);
MessagesStorage.getInstance().putMessages(sentMessages, true, false, false, 0);
AndroidUtilities.runOnUIThread(new Runnable() {
}
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);
newMsgObj.id = message.id;
processSentMessage(newMsgObj, message, null);
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, newMsgObj.id, newMsgObj);
processSentMessage(oldId);
removeFromSendingMessages(oldId);
MessagesStorage.getInstance().updateMessageStateAndId(newMsgObj.random_id, oldId, newMsgObj.id, 0, false);
MessagesStorage.getInstance().putMessages(sentMessages, true, false, false, 0);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, newMsgObj.id, newMsgObj, false);
processSentMessage(oldId);
removeFromSendingMessages(oldId);
}
});
if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) {
stopVideoService(newMsgObj.attachPath);
}
}
});
if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) {
stopVideoService(newMsgObj.attachPath);
}
}
});
}
}
} else {
for (final TLRPC.Message newMsgObj : newMsgObjArr) {
MessagesStorage.getInstance().markMessageAsSendError(newMsgObj.id);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageSendError, newMsgObj.id);
processSentMessage(newMsgObj.id);
if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) {
stopVideoService(newMsgObj.attachPath);
}
removeFromSendingMessages(newMsgObj.id);
}
for (final TLRPC.Message newMsgObj : newMsgObjArr) {
MessagesStorage.getInstance().markMessageAsSendError(newMsgObj.id);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageSendError, newMsgObj.id);
processSentMessage(newMsgObj.id);
if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) {
stopVideoService(newMsgObj.attachPath);
}
});
}
removeFromSendingMessages(newMsgObj.id);
}
});
}
}
}, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassCanCompress, ConnectionsManager.DEFAULT_DATACENTER_ID);
@ -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();
}
newMsg.media = new TLRPC.TL_messageMediaEmpty();
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,82 +1457,82 @@ 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;
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;
}
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);
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;
}
}
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
MessagesStorage.getInstance().updateMessageStateAndId(newMsgObj.random_id, oldId, (isBroadcast ? oldId : newMsgObj.id), 0, false);
MessagesStorage.getInstance().putMessages(sentMessages, true, false, isBroadcast, 0);
if (isBroadcast) {
ArrayList<TLRPC.Message> currentMessage = new ArrayList<>();
currentMessage.add(newMsgObj);
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
MessagesStorage.getInstance().putMessages(currentMessage, true, false, false, 0);
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (!isSentError) {
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
MessagesStorage.getInstance().updateMessageStateAndId(newMsgObj.random_id, oldId, (isBroadcast ? oldId : newMsgObj.id), 0, false);
MessagesStorage.getInstance().putMessages(sentMessages, true, false, isBroadcast, 0);
if (isBroadcast) {
ArrayList<TLRPC.Message> currentMessage = new ArrayList<>();
currentMessage.add(newMsgObj);
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
if (isBroadcast) {
for (TLRPC.Message message : sentMessages) {
ArrayList<MessageObject> arr = new ArrayList<>();
MessageObject messageObject = new MessageObject(message, null, false);
arr.add(messageObject);
MessagesController.getInstance().updateInterfaceWithMessages(messageObject.getDialogId(), arr, isBroadcast);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, (isBroadcast ? oldId : newMsgObj.id), newMsgObj);
processSentMessage(oldId);
removeFromSendingMessages(oldId);
MessagesStorage.getInstance().putMessages(currentMessage, true, false, false, 0);
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
newMsgObj.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
if (isBroadcast) {
for (TLRPC.Message message : sentMessages) {
ArrayList<MessageObject> arr = new ArrayList<>();
MessageObject messageObject = new MessageObject(message, null, false);
arr.add(messageObject);
MessagesController.getInstance().updateInterfaceWithMessages(messageObject.getDialogId(), arr, isBroadcast);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, oldId, (isBroadcast ? oldId : newMsgObj.id), newMsgObj, mediaUpdated);
processSentMessage(oldId);
removeFromSendingMessages(oldId);
}
});
if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) {
stopVideoService(attachPath);
}
});
if (newMsgObj.media instanceof TLRPC.TL_messageMediaVideo) {
stopVideoService(attachPath);
}
}
});
});
}
} 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);
} else {
x = AndroidUtilities.dp(72);
}
if (backButtonImageView != null && backButtonImageView.getVisibility() == VISIBLE) {
x = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 80 : 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,131 +64,124 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("BlockedUsers", R.string.BlockedUsers));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == block_user) {
Bundle args = new Bundle();
args.putBoolean("onlyUsers", true);
args.putBoolean("destroyAfterSelect", true);
args.putBoolean("returnAsResult", true);
ContactsActivity fragment = new ContactsActivity(args);
fragment.setDelegate(BlockedUsersActivity.this);
presentFragment(fragment);
}
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));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == block_user) {
Bundle args = new Bundle();
args.putBoolean("onlyUsers", true);
args.putBoolean("destroyAfterSelect", true);
args.putBoolean("returnAsResult", true);
ContactsActivity fragment = new ContactsActivity(args);
fragment.setDelegate(BlockedUsersActivity.this);
presentFragment(fragment);
}
});
}
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItem(block_user, R.drawable.plus);
ActionBarMenu menu = actionBar.createMenu();
menu.addItem(block_user, R.drawable.plus);
fragmentView = new FrameLayout(getParentActivity());
FrameLayout frameLayout = (FrameLayout) fragmentView;
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
emptyTextView = new TextView(getParentActivity());
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setVisibility(View.INVISIBLE);
emptyTextView.setText(LocaleController.getString("NoBlocked", R.string.NoBlocked));
frameLayout.addView(emptyTextView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP;
emptyTextView.setLayoutParams(layoutParams);
emptyTextView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
emptyTextView = new TextView(context);
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setVisibility(View.INVISIBLE);
emptyTextView.setText(LocaleController.getString("NoBlocked", R.string.NoBlocked));
frameLayout.addView(emptyTextView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP;
emptyTextView.setLayoutParams(layoutParams);
emptyTextView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
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(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 = new ListView(context);
listView.setEmptyView(emptyTextView);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setAdapter(listViewAdapter = new ListAdapter(context));
if (Build.VERSION.SDK_INT >= 11) {
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
}
frameLayout.addView(listView);
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i < MessagesController.getInstance().blockedUsers.size()) {
Bundle args = new Bundle();
args.putInt("user_id", MessagesController.getInstance().blockedUsers.get(i));
presentFragment(new ProfileActivity(args));
}
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i < 0 || i >= MessagesController.getInstance().blockedUsers.size() || getParentActivity() == null) {
return true;
}
});
selectedUserId = MessagesController.getInstance().blockedUsers.get(i);
progressView = new FrameLayout(getParentActivity());
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());
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 = new ListView(getParentActivity());
listView.setEmptyView(emptyTextView);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setAdapter(listViewAdapter = new ListAdapter(getParentActivity()));
if (Build.VERSION.SDK_INT >= 11) {
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
}
frameLayout.addView(listView);
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i < MessagesController.getInstance().blockedUsers.size()) {
Bundle args = new Bundle();
args.putInt("user_id", MessagesController.getInstance().blockedUsers.get(i));
presentFragment(new ProfileActivity(args));
}
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i < 0 || i >= MessagesController.getInstance().blockedUsers.size() || getParentActivity() == null) {
return true;
}
selectedUserId = MessagesController.getInstance().blockedUsers.get(i);
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items = new CharSequence[] {LocaleController.getString("Unblock", R.string.Unblock)};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
MessagesController.getInstance().unblockUser(selectedUserId);
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items = new CharSequence[]{LocaleController.getString("Unblock", R.string.Unblock)};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
MessagesController.getInstance().unblockUser(selectedUserId);
}
});
showAlertDialog(builder);
}
});
showAlertDialog(builder);
return true;
}
});
if (MessagesController.getInstance().loadingBlockedUsers) {
progressView.setVisibility(View.VISIBLE);
emptyTextView.setVisibility(View.GONE);
listView.setEmptyView(null);
} else {
progressView.setVisibility(View.GONE);
listView.setEmptyView(emptyTextView);
return true;
}
});
if (MessagesController.getInstance().loadingBlockedUsers) {
progressView.setVisibility(View.VISIBLE);
emptyTextView.setVisibility(View.GONE);
listView.setEmptyView(null);
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
progressView.setVisibility(View.GONE);
listView.setEmptyView(emptyTextView);
}
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 {
resetPressedLink();
}
} else {
resetPressedLink();
}
} 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 {
pressedLink = null;
resetPressedLink();
}
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
resetPressedLink();
}
} else {
pressedLink = null;
resetPressedLink();
}
return super.onTouchEvent(event);
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,19 +665,121 @@ public class ChatMessageCell extends ChatBaseCell {
textY = AndroidUtilities.dp(10) + namesOffset;
}
for (int a = firstVisibleBlockNum; a <= lastVisibleBlockNum; a++) {
if (a >= currentMessageObject.textLayoutBlocks.size()) {
break;
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);
if (pressedLink != null && a == linkBlockNum) {
canvas.drawPath(urlPath, urlPaint);
}
try {
block.textLayout.draw(canvas);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
canvas.restore();
}
MessageObject.TextLayoutBlock block = currentMessageObject.textLayoutBlocks.get(a);
canvas.save();
canvas.translate(textX - (int)Math.ceil(block.textXOffset), textY + block.textYOffset);
try {
block.textLayout.draw(canvas);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
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();
}
}
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

@ -36,7 +36,7 @@ import org.telegram.ui.Components.LineProgressView;
import java.io.File;
import java.util.Date;
public class SharedDocumentCell extends FrameLayout implements MediaController.FileDownloadProgressListener {
public class SharedDocumentCell extends FrameLayout implements MediaController.FileDownloadProgressListener {
private ImageView placeholderImabeView;
private BackupImageView thumbImageView;
@ -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,85 +56,78 @@ public class ChangeChatNameActivity extends BaseFragment {
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("EditName", R.string.EditName));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
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));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (firstNameField.getText().length() != 0) {
saveName();
finishFragment();
} else if (id == done_button) {
if (firstNameField.getText().length() != 0) {
saveName();
finishFragment();
}
}
}
});
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
TLRPC.Chat currentChat = MessagesController.getInstance().getChat(chat_id);
TLRPC.Chat currentChat = MessagesController.getInstance().getChat(chat_id);
fragmentView = new LinearLayout(getParentActivity());
fragmentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
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() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
firstNameField = new EditText(context);
firstNameField.setText(currentChat.title);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
firstNameField.setTextColor(0xff212121);
firstNameField.setMaxLines(3);
firstNameField.setPadding(0, 0, 0, 0);
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
firstNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
AndroidUtilities.clearCursorDrawable(firstNameField);
firstNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
doneButton.performClick();
return true;
}
});
firstNameField = new EditText(getParentActivity());
firstNameField.setText(currentChat.title);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
firstNameField.setTextColor(0xff212121);
firstNameField.setMaxLines(3);
firstNameField.setPadding(0, 0, 0, 0);
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
firstNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
AndroidUtilities.clearCursorDrawable(firstNameField);
firstNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
doneButton.performClick();
return true;
}
return false;
}
});
((LinearLayout) fragmentView).addView(firstNameField);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)firstNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(24);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
firstNameField.setLayoutParams(layoutParams);
if (chat_id > 0) {
firstNameField.setHint(LocaleController.getString("GroupName", R.string.GroupName));
} else {
firstNameField.setHint(LocaleController.getString("EnterListName", R.string.EnterListName));
return false;
}
firstNameField.setSelection(firstNameField.length());
});
((LinearLayout) fragmentView).addView(firstNameField);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) firstNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(24);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
firstNameField.setLayoutParams(layoutParams);
if (chat_id > 0) {
firstNameField.setHint(LocaleController.getString("GroupName", R.string.GroupName));
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
firstNameField.setHint(LocaleController.getString("EnterListName", R.string.EnterListName));
}
firstNameField.setSelection(firstNameField.length());
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,117 +49,111 @@ public class ChangeNameActivity extends BaseFragment {
private final static int done_button = 1;
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("EditName", R.string.EditName));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
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));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (firstNameField.getText().length() != 0) {
saveName();
finishFragment();
} else if (id == done_button) {
if (firstNameField.getText().length() != 0) {
saveName();
finishFragment();
}
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
if (user == null) {
user = UserConfig.getCurrentUser();
}
});
fragmentView = new LinearLayout(getParentActivity());
fragmentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
if (user == null) {
user = UserConfig.getCurrentUser();
}
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() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
firstNameField = new EditText(context);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
firstNameField.setTextColor(0xff212121);
firstNameField.setMaxLines(1);
firstNameField.setLines(1);
firstNameField.setSingleLine(true);
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
firstNameField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName));
AndroidUtilities.clearCursorDrawable(firstNameField);
((LinearLayout) fragmentView).addView(firstNameField);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) firstNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(24);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
firstNameField.setLayoutParams(layoutParams);
firstNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_NEXT) {
lastNameField.requestFocus();
lastNameField.setSelection(lastNameField.length());
return true;
}
});
firstNameField = new EditText(getParentActivity());
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
firstNameField.setTextColor(0xff212121);
firstNameField.setMaxLines(1);
firstNameField.setLines(1);
firstNameField.setSingleLine(true);
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
firstNameField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName));
AndroidUtilities.clearCursorDrawable(firstNameField);
((LinearLayout) fragmentView).addView(firstNameField);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)firstNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(24);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
firstNameField.setLayoutParams(layoutParams);
firstNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_NEXT) {
lastNameField.requestFocus();
lastNameField.setSelection(lastNameField.length());
return true;
}
return false;
}
});
lastNameField = new EditText(getParentActivity());
lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
lastNameField.setHintTextColor(0xff979797);
lastNameField.setTextColor(0xff212121);
lastNameField.setMaxLines(1);
lastNameField.setLines(1);
lastNameField.setSingleLine(true);
lastNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
lastNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
lastNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName));
AndroidUtilities.clearCursorDrawable(lastNameField);
((LinearLayout) fragmentView).addView(lastNameField);
layoutParams = (LinearLayout.LayoutParams)lastNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(16);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
lastNameField.setLayoutParams(layoutParams);
lastNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE) {
doneButton.performClick();
return true;
}
return false;
}
});
if (user != null) {
firstNameField.setText(user.first_name);
firstNameField.setSelection(firstNameField.length());
lastNameField.setText(user.last_name);
return false;
}
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
});
lastNameField = new EditText(context);
lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
lastNameField.setHintTextColor(0xff979797);
lastNameField.setTextColor(0xff212121);
lastNameField.setMaxLines(1);
lastNameField.setLines(1);
lastNameField.setSingleLine(true);
lastNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
lastNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
lastNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName));
AndroidUtilities.clearCursorDrawable(lastNameField);
((LinearLayout) fragmentView).addView(lastNameField);
layoutParams = (LinearLayout.LayoutParams) lastNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(16);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
lastNameField.setLayoutParams(layoutParams);
lastNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE) {
doneButton.performClick();
return true;
}
return false;
}
});
if (user != null) {
firstNameField.setText(user.first_name);
firstNameField.setSelection(firstNameField.length());
lastNameField.setText(user.last_name);
}
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,80 +100,74 @@ public class ChangePhoneActivity extends BaseFragment {
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == done_button) {
views[currentViewNum].onNextPressed();
} else if (id == -1) {
finishFragment();
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() {
@Override
public void onItemClick(int id) {
if (id == done_button) {
views[currentViewNum].onNextPressed();
} else if (id == -1) {
finishFragment();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
fragmentView = new ScrollView(context);
ScrollView scrollView = (ScrollView) fragmentView;
scrollView.setFillViewport(true);
FrameLayout frameLayout = new FrameLayout(context);
scrollView.addView(frameLayout);
ScrollView.LayoutParams layoutParams = (ScrollView.LayoutParams) frameLayout.getLayoutParams();
layoutParams.width = ScrollView.LayoutParams.MATCH_PARENT;
layoutParams.height = ScrollView.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
frameLayout.setLayoutParams(layoutParams);
views[0] = new PhoneView(context);
views[0].setVisibility(View.VISIBLE);
frameLayout.addView(views[0]);
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) views[0].getLayoutParams();
layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams1.leftMargin = AndroidUtilities.dp(16);
layoutParams1.rightMargin = AndroidUtilities.dp(16);
layoutParams1.topMargin = AndroidUtilities.dp(30);
layoutParams1.gravity = Gravity.TOP | Gravity.LEFT;
views[0].setLayoutParams(layoutParams1);
views[1] = new LoginActivitySmsView(context);
views[1].setVisibility(View.GONE);
frameLayout.addView(views[1]);
layoutParams1 = (FrameLayout.LayoutParams) views[1].getLayoutParams();
layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams1.leftMargin = AndroidUtilities.dp(16);
layoutParams1.rightMargin = AndroidUtilities.dp(16);
layoutParams1.topMargin = AndroidUtilities.dp(30);
layoutParams1.gravity = Gravity.TOP | Gravity.LEFT;
views[1].setLayoutParams(layoutParams1);
try {
if (views[0] == null || views[1] == null) {
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);
}
}
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
fragmentView = new ScrollView(getParentActivity());
ScrollView scrollView = (ScrollView) fragmentView;
scrollView.setFillViewport(true);
FrameLayout frameLayout = new FrameLayout(getParentActivity());
scrollView.addView(frameLayout);
ScrollView.LayoutParams layoutParams = (ScrollView.LayoutParams) frameLayout.getLayoutParams();
layoutParams.width = ScrollView.LayoutParams.MATCH_PARENT;
layoutParams.height = ScrollView.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
frameLayout.setLayoutParams(layoutParams);
views[0] = new PhoneView(getParentActivity());
views[0].setVisibility(View.VISIBLE);
frameLayout.addView(views[0]);
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) views[0].getLayoutParams();
layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams1.leftMargin = AndroidUtilities.dp(16);
layoutParams1.rightMargin = AndroidUtilities.dp(16);
layoutParams1.topMargin = AndroidUtilities.dp(30);
layoutParams1.gravity = Gravity.TOP | Gravity.LEFT;
views[0].setLayoutParams(layoutParams1);
views[1] = new LoginActivitySmsView(getParentActivity());
views[1].setVisibility(View.GONE);
frameLayout.addView(views[1]);
layoutParams1 = (FrameLayout.LayoutParams) views[1].getLayoutParams();
layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams1.leftMargin = AndroidUtilities.dp(16);
layoutParams1.rightMargin = AndroidUtilities.dp(16);
layoutParams1.topMargin = AndroidUtilities.dp(30);
layoutParams1.gravity = Gravity.TOP | Gravity.LEFT;
views[1].setLayoutParams(layoutParams1);
try {
if (views[0] == null || views[1] == null) {
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);
}
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
actionBar.setTitle(views[0].getHeaderName());
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
actionBar.setTitle(views[0].getHeaderName());
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,129 +35,122 @@ import org.telegram.ui.ActionBar.BaseFragment;
public class ChangePhoneHelpActivity extends BaseFragment {
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
TLRPC.User user = UserConfig.getCurrentUser();
String value;
if (user != null && user.phone != null && user.phone.length() != 0) {
value = PhoneFormat.getInstance().format("+" + user.phone);
} else {
value = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
}
actionBar.setTitle(value);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
fragmentView = new RelativeLayout(getParentActivity());
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
RelativeLayout relativeLayout = (RelativeLayout) fragmentView;
ScrollView scrollView = new ScrollView(getParentActivity());
relativeLayout.addView(scrollView);
RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) scrollView.getLayoutParams();
layoutParams3.width = RelativeLayout.LayoutParams.MATCH_PARENT;
layoutParams3.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
layoutParams3.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
scrollView.setLayoutParams(layoutParams3);
LinearLayout linearLayout = new LinearLayout(getParentActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setPadding(0, AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20));
scrollView.addView(linearLayout);
ScrollView.LayoutParams layoutParams = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
layoutParams.width = ScrollView.LayoutParams.MATCH_PARENT;
layoutParams.height = ScrollView.LayoutParams.WRAP_CONTENT;
linearLayout.setLayoutParams(layoutParams);
ImageView imageView = new ImageView(getParentActivity());
imageView.setImageResource(R.drawable.phone_change);
linearLayout.addView(imageView);
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.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)));
} catch (Exception e) {
FileLog.e("tmessages", e);
textView.setText(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp));
}
linearLayout.addView(textView);
layoutParams2 = (LinearLayout.LayoutParams)textView.getLayoutParams();
layoutParams2.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
layoutParams2.leftMargin = AndroidUtilities.dp(20);
layoutParams2.rightMargin = AndroidUtilities.dp(20);
layoutParams2.topMargin = AndroidUtilities.dp(56);
textView.setLayoutParams(layoutParams2);
textView = new TextView(getParentActivity());
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setTextColor(0xff4d83b3);
textView.setText(LocaleController.getString("PhoneNumberChange", R.string.PhoneNumberChange));
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.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
layoutParams2.leftMargin = AndroidUtilities.dp(20);
layoutParams2.rightMargin = AndroidUtilities.dp(20);
layoutParams2.topMargin = AndroidUtilities.dp(46);
textView.setLayoutParams(layoutParams2);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("PhoneNumberAlert", R.string.PhoneNumberAlert));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
presentFragment(new ChangePhoneActivity(), true);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
});
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
TLRPC.User user = UserConfig.getCurrentUser();
String value;
if (user != null && user.phone != null && user.phone.length() != 0) {
value = PhoneFormat.getInstance().format("+" + user.phone);
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
value = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
}
actionBar.setTitle(value);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
fragmentView = new RelativeLayout(context);
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
RelativeLayout relativeLayout = (RelativeLayout) fragmentView;
ScrollView scrollView = new ScrollView(context);
relativeLayout.addView(scrollView);
RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) scrollView.getLayoutParams();
layoutParams3.width = RelativeLayout.LayoutParams.MATCH_PARENT;
layoutParams3.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
layoutParams3.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
scrollView.setLayoutParams(layoutParams3);
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setPadding(0, AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20));
scrollView.addView(linearLayout);
ScrollView.LayoutParams layoutParams = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
layoutParams.width = ScrollView.LayoutParams.MATCH_PARENT;
layoutParams.height = ScrollView.LayoutParams.WRAP_CONTENT;
linearLayout.setLayoutParams(layoutParams);
ImageView imageView = new ImageView(context);
imageView.setImageResource(R.drawable.phone_change);
linearLayout.addView(imageView);
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(context);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setTextColor(0xff212121);
try {
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.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
layoutParams2.leftMargin = AndroidUtilities.dp(20);
layoutParams2.rightMargin = AndroidUtilities.dp(20);
layoutParams2.topMargin = AndroidUtilities.dp(56);
textView.setLayoutParams(layoutParams2);
textView = new TextView(context);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setTextColor(0xff4d83b3);
textView.setText(LocaleController.getString("PhoneNumberChange", R.string.PhoneNumberChange));
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.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
layoutParams2.leftMargin = AndroidUtilities.dp(20);
layoutParams2.rightMargin = AndroidUtilities.dp(20);
layoutParams2.topMargin = AndroidUtilities.dp(46);
textView.setLayoutParams(layoutParams2);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("PhoneNumberAlert", R.string.PhoneNumberAlert));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
presentFragment(new ChangePhoneActivity(), true);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
});
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,130 +62,124 @@ public class ChangeUsernameActivity extends BaseFragment {
private final static int done_button = 1;
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("Username", R.string.Username));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
saveName();
}
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));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
saveName();
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
if (user == null) {
user = UserConfig.getCurrentUser();
}
});
fragmentView = new LinearLayout(getParentActivity());
fragmentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
if (user == null) {
user = UserConfig.getCurrentUser();
}
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() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
firstNameField = new EditText(context);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
firstNameField.setTextColor(0xff212121);
firstNameField.setMaxLines(1);
firstNameField.setLines(1);
firstNameField.setPadding(0, 0, 0, 0);
firstNameField.setSingleLine(true);
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
firstNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
firstNameField.setHint(LocaleController.getString("UsernamePlaceholder", R.string.UsernamePlaceholder));
AndroidUtilities.clearCursorDrawable(firstNameField);
firstNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
doneButton.performClick();
return true;
}
});
firstNameField = new EditText(getParentActivity());
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
firstNameField.setTextColor(0xff212121);
firstNameField.setMaxLines(1);
firstNameField.setLines(1);
firstNameField.setPadding(0, 0, 0, 0);
firstNameField.setSingleLine(true);
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
firstNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
firstNameField.setHint(LocaleController.getString("UsernamePlaceholder", R.string.UsernamePlaceholder));
AndroidUtilities.clearCursorDrawable(firstNameField);
firstNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
doneButton.performClick();
return true;
}
return false;
}
});
((LinearLayout) fragmentView).addView(firstNameField);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)firstNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(24);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
firstNameField.setLayoutParams(layoutParams);
if (user != null && user.username != null && user.username.length() > 0) {
firstNameField.setText(user.username);
firstNameField.setSelection(firstNameField.length());
return false;
}
});
checkTextView = new TextView(getParentActivity());
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.topMargin = AndroidUtilities.dp(12);
layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
checkTextView.setLayoutParams(layoutParams);
((LinearLayout) fragmentView).addView(firstNameField);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) firstNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(24);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
firstNameField.setLayoutParams(layoutParams);
TextView helpTextView = new TextView(getParentActivity());
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)));
((LinearLayout) fragmentView).addView(helpTextView);
layoutParams = (LinearLayout.LayoutParams)helpTextView.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(10);
layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
helpTextView.setLayoutParams(layoutParams);
firstNameField.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
checkUserName(firstNameField.getText().toString(), false);
}
@Override
public void afterTextChanged(Editable editable) {
}
});
checkTextView.setVisibility(View.GONE);
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
if (user != null && user.username != null && user.username.length() > 0) {
firstNameField.setText(user.username);
firstNameField.setSelection(firstNameField.length());
}
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.topMargin = AndroidUtilities.dp(12);
layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
checkTextView.setLayoutParams(layoutParams);
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(AndroidUtilities.replaceTags(LocaleController.getString("UsernameHelp", R.string.UsernameHelp)));
((LinearLayout) fragmentView).addView(helpTextView);
layoutParams = (LinearLayout.LayoutParams) helpTextView.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(10);
layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
helpTextView.setLayoutParams(layoutParams);
firstNameField.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
checkUserName(firstNameField.getText().toString(), false);
}
@Override
public void afterTextChanged(Editable editable) {
}
});
checkTextView.setVisibility(View.GONE);
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,12 +90,22 @@ 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();
}
imageReceiver.clearImage();
}
@Override

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 (!forceShowSendButton) {
openKeyboard();
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) {
topView.setVisibility(GONE);
LayoutParams layoutParams2 = (LayoutParams) textFieldContainer.getLayoutParams();
layoutParams2.topMargin = AndroidUtilities.dp(2);
textFieldContainer.setLayoutParams(layoutParams2);
if (animation == currentTopViewAnimation) {
topView.setVisibility(GONE);
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,198 +74,186 @@ 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) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (addContact) {
actionBar.setTitle(LocaleController.getString("AddContactTitle", R.string.AddContactTitle));
} else {
actionBar.setTitle(LocaleController.getString("EditName", R.string.EditName));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (addContact) {
actionBar.setTitle(LocaleController.getString("AddContactTitle", R.string.AddContactTitle));
} else {
actionBar.setTitle(LocaleController.getString("EditName", R.string.EditName));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (firstNameField.getText().length() != 0) {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
user.first_name = firstNameField.getText().toString();
user.last_name = lastNameField.getText().toString();
ContactsController.getInstance().addContact(user);
finishFragment();
} else if (id == done_button) {
if (firstNameField.getText().length() != 0) {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
user.first_name = firstNameField.getText().toString();
user.last_name = lastNameField.getText().toString();
ContactsController.getInstance().addContact(user);
finishFragment();
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_NAME);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_NAME);
}
}
});
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
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.setOrientation(LinearLayout.VERTICAL);
((ScrollView) fragmentView).addView(linearLayout);
ScrollView.LayoutParams layoutParams2 = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
layoutParams2.width = ScrollView.LayoutParams.MATCH_PARENT;
layoutParams2.height = ScrollView.LayoutParams.WRAP_CONTENT;
linearLayout.setLayoutParams(layoutParams2);
linearLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
((ScrollView) fragmentView).addView(linearLayout);
ScrollView.LayoutParams layoutParams2 = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
layoutParams2.width = ScrollView.LayoutParams.MATCH_PARENT;
layoutParams2.height = ScrollView.LayoutParams.WRAP_CONTENT;
linearLayout.setLayoutParams(layoutParams2);
linearLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
FrameLayout frameLayout = new FrameLayout(context);
linearLayout.addView(frameLayout);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(24);
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
frameLayout.setLayoutParams(layoutParams);
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;
layoutParams3.width = AndroidUtilities.dp(60);
layoutParams3.height = AndroidUtilities.dp(60);
avatarImage.setLayoutParams(layoutParams3);
nameTextView = new TextView(context);
nameTextView.setTextColor(0xff212121);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
nameTextView.setLines(1);
nameTextView.setMaxLines(1);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
frameLayout.addView(nameTextView);
layoutParams3 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
layoutParams3.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams3.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams3.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 80);
layoutParams3.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 80 : 0);
layoutParams3.topMargin = AndroidUtilities.dp(3);
layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
nameTextView.setLayoutParams(layoutParams3);
onlineTextView = new TextView(context);
onlineTextView.setTextColor(0xff999999);
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
onlineTextView.setLines(1);
onlineTextView.setMaxLines(1);
onlineTextView.setSingleLine(true);
onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
onlineTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
frameLayout.addView(onlineTextView);
layoutParams3 = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams();
layoutParams3.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams3.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams3.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 80);
layoutParams3.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 80 : 0);
layoutParams3.topMargin = AndroidUtilities.dp(32);
layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
onlineTextView.setLayoutParams(layoutParams3);
firstNameField = new EditText(context);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
firstNameField.setTextColor(0xff212121);
firstNameField.setMaxLines(1);
firstNameField.setLines(1);
firstNameField.setSingleLine(true);
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
firstNameField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName));
AndroidUtilities.clearCursorDrawable(firstNameField);
linearLayout.addView(firstNameField);
layoutParams = (LinearLayout.LayoutParams) firstNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(24);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
firstNameField.setLayoutParams(layoutParams);
firstNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_NEXT) {
lastNameField.requestFocus();
lastNameField.setSelection(lastNameField.length());
return true;
}
});
FrameLayout frameLayout = new FrameLayout(getParentActivity());
linearLayout.addView(frameLayout);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(24);
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
frameLayout.setLayoutParams(layoutParams);
avatarImage = new BackupImageView(getParentActivity());
avatarImage.imageReceiver.setRoundRadius(AndroidUtilities.dp(30));
avatarImage.processDetach = false;
frameLayout.addView(avatarImage);
FrameLayout.LayoutParams layoutParams3 = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
layoutParams3.width = AndroidUtilities.dp(60);
layoutParams3.height = AndroidUtilities.dp(60);
avatarImage.setLayoutParams(layoutParams3);
nameTextView = new TextView(getParentActivity());
nameTextView.setTextColor(0xff212121);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
nameTextView.setLines(1);
nameTextView.setMaxLines(1);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
frameLayout.addView(nameTextView);
layoutParams3 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
layoutParams3.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams3.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams3.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 80);
layoutParams3.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 80 : 0);
layoutParams3.topMargin = AndroidUtilities.dp(3);
layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
nameTextView.setLayoutParams(layoutParams3);
onlineTextView = new TextView(getParentActivity());
onlineTextView.setTextColor(0xff999999);
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
onlineTextView.setLines(1);
onlineTextView.setMaxLines(1);
onlineTextView.setSingleLine(true);
onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
onlineTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
frameLayout.addView(onlineTextView);
layoutParams3 = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams();
layoutParams3.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams3.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams3.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 80);
layoutParams3.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 80 : 0);
layoutParams3.topMargin = AndroidUtilities.dp(32);
layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
onlineTextView.setLayoutParams(layoutParams3);
firstNameField = new EditText(getParentActivity());
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(0xff979797);
firstNameField.setTextColor(0xff212121);
firstNameField.setMaxLines(1);
firstNameField.setLines(1);
firstNameField.setSingleLine(true);
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
firstNameField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName));
AndroidUtilities.clearCursorDrawable(firstNameField);
linearLayout.addView(firstNameField);
layoutParams = (LinearLayout.LayoutParams) firstNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(24);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
firstNameField.setLayoutParams(layoutParams);
firstNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_NEXT) {
lastNameField.requestFocus();
lastNameField.setSelection(lastNameField.length());
return true;
}
return false;
}
});
lastNameField = new EditText(getParentActivity());
lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
lastNameField.setHintTextColor(0xff979797);
lastNameField.setTextColor(0xff212121);
lastNameField.setMaxLines(1);
lastNameField.setLines(1);
lastNameField.setSingleLine(true);
lastNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
lastNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
lastNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName));
AndroidUtilities.clearCursorDrawable(lastNameField);
linearLayout.addView(lastNameField);
layoutParams = (LinearLayout.LayoutParams) lastNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(16);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
lastNameField.setLayoutParams(layoutParams);
lastNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE) {
doneButton.performClick();
return true;
}
return false;
}
});
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user != null) {
if (user.phone == null) {
if (phone != null) {
user.phone = PhoneFormat.stripExceptNumbers(phone);
}
}
firstNameField.setText(user.first_name);
firstNameField.setSelection(firstNameField.length());
lastNameField.setText(user.last_name);
return false;
}
});
updateAvatarLayout();
} else {
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
lastNameField = new EditText(context);
lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
lastNameField.setHintTextColor(0xff979797);
lastNameField.setTextColor(0xff212121);
lastNameField.setMaxLines(1);
lastNameField.setLines(1);
lastNameField.setSingleLine(true);
lastNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
lastNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
lastNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName));
AndroidUtilities.clearCursorDrawable(lastNameField);
linearLayout.addView(lastNameField);
layoutParams = (LinearLayout.LayoutParams) lastNameField.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(16);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.rightMargin = AndroidUtilities.dp(24);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
lastNameField.setLayoutParams(layoutParams);
lastNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE) {
doneButton.performClick();
return true;
}
return false;
}
});
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user != null) {
if (user.phone == null) {
if (phone != null) {
user.phone = PhoneFormat.stripExceptNumbers(phone);
}
}
firstNameField.setText(user.first_name);
firstNameField.setSelection(firstNameField.length());
lastNameField.setText(user.last_name);
}
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,286 +117,281 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
searching = false;
searchWas = false;
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (destroyAfterSelect) {
if (returnAsResult) {
actionBar.setTitle(LocaleController.getString("SelectContact", R.string.SelectContact));
} else {
if (createSecretChat) {
actionBar.setTitle(LocaleController.getString("NewSecretChat", R.string.NewSecretChat));
} else {
actionBar.setTitle(LocaleController.getString("NewMessageTitle", R.string.NewMessageTitle));
}
}
searching = false;
searchWas = false;
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (destroyAfterSelect) {
if (returnAsResult) {
actionBar.setTitle(LocaleController.getString("SelectContact", R.string.SelectContact));
} else {
actionBar.setTitle(LocaleController.getString("Contacts", R.string.Contacts));
if (createSecretChat) {
actionBar.setTitle(LocaleController.getString("NewSecretChat", R.string.NewSecretChat));
} else {
actionBar.setTitle(LocaleController.getString("NewMessageTitle", R.string.NewMessageTitle));
}
}
} else {
actionBar.setTitle(LocaleController.getString("Contacts", R.string.Contacts));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
searching = true;
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
@Override
public boolean onSearchCollapse() {
searchListViewAdapter.searchDialogs(null);
searching = false;
searchWas = false;
listView.setAdapter(listViewAdapter);
listViewAdapter.notifyDataSetChanged();
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
}
listView.setFastScrollEnabled(true);
listView.setVerticalScrollBarEnabled(false);
emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
return true;
}
@Override
public void onTextChanged(EditText editText) {
if (searchListViewAdapter == null) {
return;
}
String text = editText.getText().toString();
if (text.length() != 0) {
searchWas = true;
if (listView != null) {
listView.setAdapter(searchListViewAdapter);
searchListViewAdapter.notifyDataSetChanged();
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(false);
}
listView.setFastScrollEnabled(false);
listView.setVerticalScrollBarEnabled(true);
}
if (emptyTextView != null) {
emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
}
}
});
searchListViewAdapter.searchDialogs(text);
}
});
item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
ActionBarMenu menu = actionBar.createMenu();
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
searching = true;
}
searchListViewAdapter = new SearchAdapter(context, ignoreUsers, allowUsernameSearch);
listViewAdapter = new ContactsAdapter(context, onlyUsers, needPhonebook, ignoreUsers);
@Override
public boolean onSearchCollapse() {
searchListViewAdapter.searchDialogs(null);
searching = false;
searchWas = false;
listView.setAdapter(listViewAdapter);
listViewAdapter.notifyDataSetChanged();
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
}
listView.setFastScrollEnabled(true);
listView.setVerticalScrollBarEnabled(false);
emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
return true;
}
fragmentView = new FrameLayout(context);
@Override
public void onTextChanged(EditText editText) {
if (searchListViewAdapter == null) {
LinearLayout emptyTextLayout = new LinearLayout(context);
emptyTextLayout.setVisibility(View.INVISIBLE);
emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
((FrameLayout) fragmentView).addView(emptyTextLayout);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP;
emptyTextLayout.setLayoutParams(layoutParams);
emptyTextLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
emptyTextView = new TextView(context);
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
emptyTextLayout.addView(emptyTextView);
LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.weight = 0.5f;
emptyTextView.setLayoutParams(layoutParams1);
FrameLayout frameLayout = new FrameLayout(context);
emptyTextLayout.addView(frameLayout);
layoutParams1 = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.weight = 0.5f;
frameLayout.setLayoutParams(layoutParams1);
listView = new LetterSectionsListView(context);
listView.setEmptyView(emptyTextLayout);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setFastScrollEnabled(true);
listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
listView.setAdapter(listViewAdapter);
if (Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
}
((FrameLayout) fragmentView).addView(listView);
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (searching && searchWas) {
TLRPC.User user = searchListViewAdapter.getItem(i);
if (user == null) {
return;
}
String text = editText.getText().toString();
if (text.length() != 0) {
searchWas = true;
if (listView != null) {
listView.setAdapter(searchListViewAdapter);
searchListViewAdapter.notifyDataSetChanged();
if(android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(false);
}
listView.setFastScrollEnabled(false);
listView.setVerticalScrollBarEnabled(true);
}
if (emptyTextView != null) {
emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
}
if (searchListViewAdapter.isGlobalSearch(i)) {
ArrayList<TLRPC.User> users = new ArrayList<>();
users.add(user);
MessagesController.getInstance().putUsers(users, false);
MessagesStorage.getInstance().putUsersAndChats(users, null, false, true);
}
searchListViewAdapter.searchDialogs(text);
}
});
item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
searchListViewAdapter = new SearchAdapter(getParentActivity(), ignoreUsers, allowUsernameSearch);
listViewAdapter = new ContactsAdapter(getParentActivity(), onlyUsers, needPhonebook, ignoreUsers);
fragmentView = new FrameLayout(getParentActivity());
LinearLayout emptyTextLayout = new LinearLayout(getParentActivity());
emptyTextLayout.setVisibility(View.INVISIBLE);
emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
((FrameLayout) fragmentView).addView(emptyTextLayout);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP;
emptyTextLayout.setLayoutParams(layoutParams);
emptyTextLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
emptyTextView = new TextView(getParentActivity());
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
emptyTextLayout.addView(emptyTextView);
LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.weight = 0.5f;
emptyTextView.setLayoutParams(layoutParams1);
FrameLayout frameLayout = new FrameLayout(getParentActivity());
emptyTextLayout.addView(frameLayout);
layoutParams1 = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.weight = 0.5f;
frameLayout.setLayoutParams(layoutParams1);
listView = new LetterSectionsListView(getParentActivity());
listView.setEmptyView(emptyTextLayout);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setFastScrollEnabled(true);
listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
listView.setAdapter(listViewAdapter);
if (Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
}
((FrameLayout) fragmentView).addView(listView);
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (searching && searchWas) {
TLRPC.User user = searchListViewAdapter.getItem(i);
if (user == null) {
if (returnAsResult) {
if (ignoreUsers != null && ignoreUsers.containsKey(user.id)) {
return;
}
if (searchListViewAdapter.isGlobalSearch(i)) {
ArrayList<TLRPC.User> users = new ArrayList<>();
users.add(user);
MessagesController.getInstance().putUsers(users, false);
MessagesStorage.getInstance().putUsersAndChats(users, null, false, true);
}
if (returnAsResult) {
if (ignoreUsers != null && ignoreUsers.containsKey(user.id)) {
return;
}
didSelectResult(user, true, null);
didSelectResult(user, true, null);
} else {
if (createSecretChat) {
creatingChat = true;
SecretChatHelper.getInstance().startSecretChat(getParentActivity(), user);
} else {
if (createSecretChat) {
creatingChat = true;
SecretChatHelper.getInstance().startSecretChat(getParentActivity(), user);
} else {
Bundle args = new Bundle();
args.putInt("user_id", user.id);
presentFragment(new ChatActivity(args), true);
}
}
} else {
int section = listViewAdapter.getSectionForPosition(i);
int row = listViewAdapter.getPositionInSectionForPosition(i);
if (row < 0 || section < 0) {
return;
}
if (!onlyUsers && section == 0) {
if (needPhonebook) {
if (row == 0) {
try {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, ContactsController.getInstance().getInviteText());
getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("InviteFriends", R.string.InviteFriends)), 500);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
} else {
if (row == 0) {
if (!MessagesController.isFeatureEnabled("chat_create", ContactsActivity.this)) {
return;
}
presentFragment(new GroupCreateActivity(), false);
} else if (row == 1) {
Bundle args = new Bundle();
args.putInt("user_id", user.id);
presentFragment(new ChatActivity(args), true);
args.putBoolean("onlyUsers", true);
args.putBoolean("destroyAfterSelect", true);
args.putBoolean("createSecretChat", true);
presentFragment(new ContactsActivity(args), false);
} else if (row == 2) {
if (!MessagesController.isFeatureEnabled("broadcast_create", ContactsActivity.this)) {
return;
}
Bundle args = new Bundle();
args.putBoolean("broadcast", true);
presentFragment(new GroupCreateActivity(args), false);
}
}
} else {
int section = listViewAdapter.getSectionForPosition(i);
int row = listViewAdapter.getPositionInSectionForPosition(i);
if (row < 0 || section < 0) {
return;
}
if (!onlyUsers && section == 0) {
if (needPhonebook) {
if (row == 0) {
Object item = listViewAdapter.getItem(section, row);
if (item instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) item;
if (returnAsResult) {
if (ignoreUsers != null && ignoreUsers.containsKey(user.id)) {
return;
}
didSelectResult(user, true, null);
} else {
if (createSecretChat) {
creatingChat = true;
SecretChatHelper.getInstance().startSecretChat(getParentActivity(), user);
} else {
Bundle args = new Bundle();
args.putInt("user_id", user.id);
presentFragment(new ChatActivity(args), true);
}
}
} else if (item instanceof ContactsController.Contact) {
ContactsController.Contact contact = (ContactsController.Contact) item;
String usePhone = null;
if (!contact.phones.isEmpty()) {
usePhone = contact.phones.get(0);
}
if (usePhone == null || getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("InviteUser", R.string.InviteUser));
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
final String arg1 = usePhone;
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
try {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, ContactsController.getInstance().getInviteText());
getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("InviteFriends", R.string.InviteFriends)), 500);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", arg1, null));
intent.putExtra("sms_body", LocaleController.getString("InviteText", R.string.InviteText));
getParentActivity().startActivityForResult(intent, 500);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
} else {
if (row == 0) {
if (!MessagesController.isFeatureEnabled("chat_create", ContactsActivity.this)) {
return;
}
presentFragment(new GroupCreateActivity(), false);
} else if (row == 1) {
Bundle args = new Bundle();
args.putBoolean("onlyUsers", true);
args.putBoolean("destroyAfterSelect", true);
args.putBoolean("createSecretChat", true);
presentFragment(new ContactsActivity(args), false);
} else if (row == 2) {
if (!MessagesController.isFeatureEnabled("broadcast_create", ContactsActivity.this)) {
return;
}
Bundle args = new Bundle();
args.putBoolean("broadcast", true);
presentFragment(new GroupCreateActivity(args), false);
}
}
} else {
Object item = listViewAdapter.getItem(section, row);
if (item instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) item;
if (returnAsResult) {
if (ignoreUsers != null && ignoreUsers.containsKey(user.id)) {
return;
}
didSelectResult(user, true, null);
} else {
if (createSecretChat) {
creatingChat = true;
SecretChatHelper.getInstance().startSecretChat(getParentActivity(), user);
} else {
Bundle args = new Bundle();
args.putInt("user_id", user.id);
presentFragment(new ChatActivity(args), true);
}
}
} else if (item instanceof ContactsController.Contact) {
ContactsController.Contact contact = (ContactsController.Contact) item;
String usePhone = null;
if (!contact.phones.isEmpty()) {
usePhone = contact.phones.get(0);
}
if (usePhone == null || getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("InviteUser", R.string.InviteUser));
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
final String arg1 = usePhone;
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", arg1, null));
intent.putExtra("sms_body", LocaleController.getString("InviteText", R.string.InviteText));
getParentActivity().startActivityForResult(intent, 500);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
}
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (absListView.isFastScrollEnabled()) {
AndroidUtilities.clearDrawableAnimation(absListView);
}
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (absListView.isFastScrollEnabled()) {
AndroidUtilities.clearDrawableAnimation(absListView);
}
}
});
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,174 +61,168 @@ public class CountrySelectActivity extends BaseFragment {
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
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));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
searching = true;
}
@Override
public boolean onSearchCollapse() {
searchListViewAdapter.search(null);
searching = false;
searchWas = false;
listView.setAdapter(listViewAdapter);
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
}
listView.setFastScrollEnabled(true);
listView.setVerticalScrollBarEnabled(false);
emptyTextView.setText(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
return true;
}
@Override
public void onTextChanged(EditText editText) {
String text = editText.getText().toString();
searchListViewAdapter.search(text);
if (text.length() != 0) {
searchWas = true;
if (listView != null) {
listView.setAdapter(searchListViewAdapter);
if(android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(false);
}
listView.setFastScrollEnabled(false);
listView.setVerticalScrollBarEnabled(true);
}
if (emptyTextView != null) {
}
}
}
});
item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
searching = false;
searchWas = false;
listViewAdapter = new CountryAdapter(getParentActivity());
searchListViewAdapter = new CountrySearchAdapter(getParentActivity(), listViewAdapter.getCountries());
fragmentView = new FrameLayout(getParentActivity());
LinearLayout emptyTextLayout = new LinearLayout(getParentActivity());
emptyTextLayout.setVisibility(View.INVISIBLE);
emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
((FrameLayout) fragmentView).addView(emptyTextLayout);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP;
emptyTextLayout.setLayoutParams(layoutParams);
emptyTextLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
emptyTextView = new TextView(getParentActivity());
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
emptyTextLayout.addView(emptyTextView);
LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.weight = 0.5f;
emptyTextView.setLayoutParams(layoutParams1);
FrameLayout frameLayout = new FrameLayout(getParentActivity());
emptyTextLayout.addView(frameLayout);
layoutParams1 = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.weight = 0.5f;
frameLayout.setLayoutParams(layoutParams1);
listView = new LetterSectionsListView(getParentActivity());
listView.setEmptyView(emptyTextLayout);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setFastScrollEnabled(true);
listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
listView.setAdapter(listViewAdapter);
if (Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
}
((FrameLayout) fragmentView).addView(listView);
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Country country = null;
if (searching && searchWas) {
country = searchListViewAdapter.getItem(i);
} else {
int section = listViewAdapter.getSectionForPosition(i);
int row = listViewAdapter.getPositionInSectionForPosition(i);
if (row < 0 || section < 0) {
return;
}
country = listViewAdapter.getItem(section, row);
}
if (i < 0) {
return;
}
if (country != null && delegate != null) {
delegate.didSelectCountry(country.name);
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (absListView.isFastScrollEnabled()) {
AndroidUtilities.clearDrawableAnimation(absListView);
}
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
});
ActionBarMenu menu = actionBar.createMenu();
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
searching = true;
}
@Override
public boolean onSearchCollapse() {
searchListViewAdapter.search(null);
searching = false;
searchWas = false;
listView.setAdapter(listViewAdapter);
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
}
listView.setFastScrollEnabled(true);
listView.setVerticalScrollBarEnabled(false);
emptyTextView.setText(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
return true;
}
@Override
public void onTextChanged(EditText editText) {
String text = editText.getText().toString();
searchListViewAdapter.search(text);
if (text.length() != 0) {
searchWas = true;
if (listView != null) {
listView.setAdapter(searchListViewAdapter);
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(false);
}
listView.setFastScrollEnabled(false);
listView.setVerticalScrollBarEnabled(true);
}
if (emptyTextView != null) {
}
}
}
});
item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
searching = false;
searchWas = false;
listViewAdapter = new CountryAdapter(context);
searchListViewAdapter = new CountrySearchAdapter(context, listViewAdapter.getCountries());
fragmentView = new FrameLayout(context);
LinearLayout emptyTextLayout = new LinearLayout(context);
emptyTextLayout.setVisibility(View.INVISIBLE);
emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
((FrameLayout) fragmentView).addView(emptyTextLayout);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP;
emptyTextLayout.setLayoutParams(layoutParams);
emptyTextLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
emptyTextView = new TextView(context);
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
emptyTextLayout.addView(emptyTextView);
LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.weight = 0.5f;
emptyTextView.setLayoutParams(layoutParams1);
FrameLayout frameLayout = new FrameLayout(context);
emptyTextLayout.addView(frameLayout);
layoutParams1 = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.weight = 0.5f;
frameLayout.setLayoutParams(layoutParams1);
listView = new LetterSectionsListView(context);
listView.setEmptyView(emptyTextLayout);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setFastScrollEnabled(true);
listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
listView.setAdapter(listViewAdapter);
if (Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
}
((FrameLayout) fragmentView).addView(listView);
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Country country = null;
if (searching && searchWas) {
country = searchListViewAdapter.getItem(i);
} else {
int section = listViewAdapter.getSectionForPosition(i);
int row = listViewAdapter.getPositionInSectionForPosition(i);
if (row < 0 || section < 0) {
return;
}
country = listViewAdapter.getItem(section, row);
}
if (i < 0) {
return;
}
if (country != null && delegate != null) {
delegate.didSelectCountry(country.name);
}
finishFragment();
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (absListView.isFastScrollEnabled()) {
AndroidUtilities.clearDrawableAnimation(absListView);
}
}
});
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,217 +142,211 @@ 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));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == -2) {
selectedFiles.clear();
actionBar.hideActionMode();
listView.invalidateViews();
} else if (id == done) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("SelectFile", R.string.SelectFile));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == -2) {
selectedFiles.clear();
actionBar.hideActionMode();
listView.invalidateViews();
} else if (id == done) {
if (delegate != null) {
ArrayList<String> files = new ArrayList<>();
files.addAll(selectedFiles.keySet());
delegate.didSelectFiles(DocumentSelectActivity.this, files);
}
}
}
});
selectedFiles.clear();
actionModeViews.clear();
final ActionBarMenu actionMode = actionBar.createActionMode();
actionModeViews.add(actionMode.addItem(-2, R.drawable.ic_ab_back_grey, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
selectedMessagesCountTextView = new TextView(actionMode.getContext());
selectedMessagesCountTextView.setTextSize(18);
selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
selectedMessagesCountTextView.setTextColor(0xff737373);
selectedMessagesCountTextView.setSingleLine(true);
selectedMessagesCountTextView.setLines(1);
selectedMessagesCountTextView.setEllipsize(TextUtils.TruncateAt.END);
selectedMessagesCountTextView.setPadding(AndroidUtilities.dp(11), 0, 0, AndroidUtilities.dp(2));
selectedMessagesCountTextView.setGravity(Gravity.CENTER_VERTICAL);
selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
actionMode.addView(selectedMessagesCountTextView);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) selectedMessagesCountTextView.getLayoutParams();
layoutParams.weight = 1;
layoutParams.width = 0;
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
selectedMessagesCountTextView.setLayoutParams(layoutParams);
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(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.setEmptyView(emptyView);
listView.setAdapter(listAdapter);
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
scrolling = scrollState != SCROLL_STATE_IDLE;
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int i, long id) {
if (actionBar.isActionModeShowed() || i < 0 || i >= items.size()) {
return false;
}
ListItem item = items.get(i);
File file = item.file;
if (file != null && !file.isDirectory()) {
if (!file.canRead()) {
showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
return false;
}
if (sizeLimit != 0) {
if (file.length() > sizeLimit) {
showErrorBox(LocaleController.formatString("FileUploadLimit", R.string.FileUploadLimit, Utilities.formatFileSize(sizeLimit)));
return false;
}
}
if (file.length() == 0) {
return false;
}
selectedFiles.put(file.toString(), item);
selectedMessagesCountTextView.setText(String.format("%d", selectedFiles.size()));
if (Build.VERSION.SDK_INT >= 11) {
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
ArrayList<Object> animators = new ArrayList<>();
for (int a = 0; a < actionModeViews.size(); a++) {
View view2 = actionModeViews.get(a);
AndroidUtilities.clearDrawableAnimation(view2);
if (a < 1) {
animators.add(ObjectAnimatorProxy.ofFloat(view2, "translationX", -AndroidUtilities.dp(56), 0));
} else {
animators.add(ObjectAnimatorProxy.ofFloat(view2, "scaleY", 0.1f, 1.0f));
}
}
animatorSet.playTogether(animators);
animatorSet.setDuration(250);
animatorSet.start();
}
scrolling = false;
if (view instanceof SharedDocumentCell) {
((SharedDocumentCell) view).setChecked(true, true);
}
actionBar.showActionMode();
}
return true;
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i < 0 || i >= items.size()) {
return;
}
ListItem item = items.get(i);
File file = item.file;
if (file == null) {
if (item.icon == R.drawable.ic_storage_gallery) {
if (delegate != null) {
delegate.startDocumentSelectActivity();
}
finishFragment(false);
} else {
HistoryEntry he = history.remove(history.size() - 1);
actionBar.setTitle(he.title);
if (he.dir != null) {
listFiles(he.dir);
} else {
listRoots();
}
listView.setSelectionFromTop(he.scrollItem, he.scrollOffset);
}
} else if (file.isDirectory()) {
HistoryEntry he = new HistoryEntry();
he.scrollItem = listView.getFirstVisiblePosition();
he.scrollOffset = listView.getChildAt(0).getTop();
he.dir = currentDir;
he.title = actionBar.getTitle().toString();
history.add(he);
if (!listFiles(file)) {
history.remove(he);
return;
}
actionBar.setTitle(item.title);
listView.setSelection(0);
} else {
if (!file.canRead()) {
showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
return;
}
if (sizeLimit != 0) {
if (file.length() > sizeLimit) {
showErrorBox(LocaleController.formatString("FileUploadLimit", R.string.FileUploadLimit, Utilities.formatFileSize(sizeLimit)));
return;
}
}
if (file.length() == 0) {
return;
}
if (actionBar.isActionModeShowed()) {
if (selectedFiles.containsKey(file.toString())) {
selectedFiles.remove(file.toString());
} else {
selectedFiles.put(file.toString(), item);
}
if (selectedFiles.isEmpty()) {
actionBar.hideActionMode();
} else {
selectedMessagesCountTextView.setText(String.format("%d", selectedFiles.size()));
}
scrolling = false;
if (view instanceof SharedDocumentCell) {
((SharedDocumentCell) view).setChecked(selectedFiles.containsKey(item.file.toString()), true);
}
} else {
if (delegate != null) {
ArrayList<String> files = new ArrayList<>();
files.addAll(selectedFiles.keySet());
files.add(file.getAbsolutePath());
delegate.didSelectFiles(DocumentSelectActivity.this, files);
}
}
}
});
selectedFiles.clear();
actionModeViews.clear();
final ActionBarMenu actionMode = actionBar.createActionMode();
actionModeViews.add(actionMode.addItem(-2, R.drawable.ic_ab_back_grey, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
selectedMessagesCountTextView = new TextView(actionMode.getContext());
selectedMessagesCountTextView.setTextSize(18);
selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
selectedMessagesCountTextView.setTextColor(0xff737373);
selectedMessagesCountTextView.setSingleLine(true);
selectedMessagesCountTextView.setLines(1);
selectedMessagesCountTextView.setEllipsize(TextUtils.TruncateAt.END);
selectedMessagesCountTextView.setPadding(AndroidUtilities.dp(11), 0, 0, AndroidUtilities.dp(2));
selectedMessagesCountTextView.setGravity(Gravity.CENTER_VERTICAL);
selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
actionMode.addView(selectedMessagesCountTextView);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)selectedMessagesCountTextView.getLayoutParams();
layoutParams.weight = 1;
layoutParams.width = 0;
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
selectedMessagesCountTextView.setLayoutParams(layoutParams);
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);
emptyView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
listView = (ListView)fragmentView.findViewById(R.id.listView);
listView.setEmptyView(emptyView);
listView.setAdapter(listAdapter);
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
scrolling = scrollState != SCROLL_STATE_IDLE;
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int i, long id) {
if (actionBar.isActionModeShowed() || i < 0 || i >= items.size()) {
return false;
}
ListItem item = items.get(i);
File file = item.file;
if (file != null && !file.isDirectory()) {
if (!file.canRead()) {
showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
return false;
}
if (sizeLimit != 0) {
if (file.length() > sizeLimit) {
showErrorBox(LocaleController.formatString("FileUploadLimit", R.string.FileUploadLimit, Utilities.formatFileSize(sizeLimit)));
return false;
}
}
if (file.length() == 0) {
return false;
}
selectedFiles.put(file.toString(), item);
selectedMessagesCountTextView.setText(String.format("%d", selectedFiles.size()));
if (Build.VERSION.SDK_INT >= 11) {
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
ArrayList<Object> animators = new ArrayList<>();
for (int a = 0; a < actionModeViews.size(); a++) {
View view2 = actionModeViews.get(a);
AndroidUtilities.clearDrawableAnimation(view2);
if (a < 1) {
animators.add(ObjectAnimatorProxy.ofFloat(view2, "translationX", -AndroidUtilities.dp(56), 0));
} else {
animators.add(ObjectAnimatorProxy.ofFloat(view2, "scaleY", 0.1f, 1.0f));
}
}
animatorSet.playTogether(animators);
animatorSet.setDuration(250);
animatorSet.start();
}
scrolling = false;
if (view instanceof SharedDocumentCell) {
((SharedDocumentCell) view).setChecked(true, true);
}
actionBar.showActionMode();
}
return true;
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i < 0 || i >= items.size()) {
return;
}
ListItem item = items.get(i);
File file = item.file;
if (file == null) {
if (item.icon == R.drawable.ic_storage_gallery) {
if (delegate != null) {
delegate.startDocumentSelectActivity();
}
finishFragment(false);
} else {
HistoryEntry he = history.remove(history.size() - 1);
actionBar.setTitle(he.title);
if (he.dir != null) {
listFiles(he.dir);
} else {
listRoots();
}
listView.setSelectionFromTop(he.scrollItem, he.scrollOffset);
}
} else if (file.isDirectory()) {
HistoryEntry he = new HistoryEntry();
he.scrollItem = listView.getFirstVisiblePosition();
he.scrollOffset = listView.getChildAt(0).getTop();
he.dir = currentDir;
he.title = actionBar.getTitle().toString();
history.add(he);
if (!listFiles(file)) {
history.remove(he);
return;
}
actionBar.setTitle(item.title);
listView.setSelection(0);
} else {
if (!file.canRead()) {
showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
return;
}
if (sizeLimit != 0) {
if (file.length() > sizeLimit) {
showErrorBox(LocaleController.formatString("FileUploadLimit", R.string.FileUploadLimit, Utilities.formatFileSize(sizeLimit)));
return;
}
}
if (file.length() == 0) {
return;
}
if (actionBar.isActionModeShowed()) {
if (selectedFiles.containsKey(file.toString())) {
selectedFiles.remove(file.toString());
} else {
selectedFiles.put(file.toString(), item);
}
if (selectedFiles.isEmpty()) {
actionBar.hideActionMode();
} else {
selectedMessagesCountTextView.setText(String.format("%d", selectedFiles.size()));
}
scrolling = false;
if (view instanceof SharedDocumentCell) {
((SharedDocumentCell) view).setChecked(selectedFiles.containsKey(item.file.toString()), true);
}
} else {
if (delegate != null) {
ArrayList<String> files = new ArrayList<>();
files.add(file.getAbsolutePath());
delegate.didSelectFiles(DocumentSelectActivity.this, files);
}
}
}
}
});
listRoots();
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
});
listRoots();
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,337 +141,331 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
searching = false;
searchWas = false;
public View createView(Context context, LayoutInflater inflater) {
searching = false;
searchWas = false;
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (isAlwaysShare) {
actionBar.setTitle(LocaleController.getString("AlwaysShareWithTitle", R.string.AlwaysShareWithTitle));
} else if (isNeverShare) {
actionBar.setTitle(LocaleController.getString("NeverShareWithTitle", R.string.NeverShareWithTitle));
} else {
actionBar.setTitle(isBroadcast ? LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList) : LocaleController.getString("NewGroup", R.string.NewGroup));
actionBar.setSubtitle(LocaleController.formatString("MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));
}
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (isAlwaysShare) {
actionBar.setTitle(LocaleController.getString("AlwaysShareWithTitle", R.string.AlwaysShareWithTitle));
} else if (isNeverShare) {
actionBar.setTitle(LocaleController.getString("NeverShareWithTitle", R.string.NeverShareWithTitle));
} else {
actionBar.setTitle(isBroadcast ? LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList) : LocaleController.getString("NewGroup", R.string.NewGroup));
actionBar.setSubtitle(LocaleController.formatString("MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (selectedContacts.isEmpty()) {
return;
}
ArrayList<Integer> result = new ArrayList<>();
result.addAll(selectedContacts.keySet());
if (isAlwaysShare || isNeverShare) {
if (delegate != null) {
delegate.didSelectUsers(result);
}
finishFragment();
} else {
Bundle args = new Bundle();
args.putIntegerArrayList("result", result);
args.putBoolean("broadcast", isBroadcast);
presentFragment(new GroupCreateFinalActivity(args));
}
}
}
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
searchListViewAdapter = new SearchAdapter(getParentActivity(), null, false);
searchListViewAdapter.setCheckedMap(selectedContacts);
searchListViewAdapter.setUseUserCell(true);
listViewAdapter = new ContactsAdapter(getParentActivity(), true, false, null);
listViewAdapter.setCheckedMap(selectedContacts);
fragmentView = new LinearLayout(getParentActivity());
LinearLayout linearLayout = (LinearLayout) fragmentView;
linearLayout.setOrientation(LinearLayout.VERTICAL);
FrameLayout frameLayout = new FrameLayout(getParentActivity());
linearLayout.addView(frameLayout);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.TOP;
frameLayout.setLayoutParams(layoutParams);
userSelectEditText = new EditText(getParentActivity());
userSelectEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
userSelectEditText.setHintTextColor(0xff979797);
userSelectEditText.setTextColor(0xff212121);
userSelectEditText.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
userSelectEditText.setMinimumHeight(AndroidUtilities.dp(54));
userSelectEditText.setSingleLine(false);
userSelectEditText.setLines(2);
userSelectEditText.setMaxLines(2);
userSelectEditText.setVerticalScrollBarEnabled(true);
userSelectEditText.setHorizontalScrollBarEnabled(false);
userSelectEditText.setPadding(0, 0, 0, 0);
userSelectEditText.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
userSelectEditText.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
AndroidUtilities.clearCursorDrawable(userSelectEditText);
frameLayout.addView(userSelectEditText);
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) userSelectEditText.getLayoutParams();
layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams1.leftMargin = AndroidUtilities.dp(10);
layoutParams1.rightMargin = AndroidUtilities.dp(10);
layoutParams1.gravity = Gravity.TOP;
userSelectEditText.setLayoutParams(layoutParams1);
if (isAlwaysShare) {
userSelectEditText.setHint(LocaleController.getString("AlwaysShareWithPlaceholder", R.string.AlwaysShareWithPlaceholder));
} else if (isNeverShare) {
userSelectEditText.setHint(LocaleController.getString("NeverShareWithPlaceholder", R.string.NeverShareWithPlaceholder));
} else {
userSelectEditText.setHint(LocaleController.getString("SendMessageTo", R.string.SendMessageTo));
}
if (Build.VERSION.SDK_INT >= 11) {
userSelectEditText.setTextIsSelectable(false);
}
userSelectEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
if (!ignoreChange) {
beforeChangeIndex = userSelectEditText.getSelectionStart();
changeString = new SpannableString(charSequence);
}
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
if (!ignoreChange) {
boolean search = false;
int afterChangeIndex = userSelectEditText.getSelectionEnd();
if (editable.toString().length() < changeString.toString().length()) {
String deletedString = "";
try {
deletedString = changeString.toString().substring(afterChangeIndex, beforeChangeIndex);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (deletedString.length() > 0) {
if (searching && searchWas) {
search = true;
}
Spannable span = userSelectEditText.getText();
for (int a = 0; a < allSpans.size(); a++) {
XImageSpan sp = allSpans.get(a);
if (span.getSpanStart(sp) == -1) {
allSpans.remove(sp);
selectedContacts.remove(sp.uid);
}
}
if (!isAlwaysShare && !isNeverShare) {
actionBar.setSubtitle(LocaleController.formatString("MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));
}
listView.invalidateViews();
} else {
search = true;
}
} else {
search = true;
}
if (search) {
String text = userSelectEditText.getText().toString().replace("<", "");
if (text.length() != 0) {
searching = true;
searchWas = true;
if (listView != null) {
listView.setAdapter(searchListViewAdapter);
searchListViewAdapter.notifyDataSetChanged();
if(android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(false);
}
listView.setFastScrollEnabled(false);
listView.setVerticalScrollBarEnabled(true);
}
if (emptyTextView != null) {
emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
}
searchListViewAdapter.searchDialogs(text);
} else {
searchListViewAdapter.searchDialogs(null);
searching = false;
searchWas = false;
listView.setAdapter(listViewAdapter);
listViewAdapter.notifyDataSetChanged();
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
}
listView.setFastScrollEnabled(true);
listView.setVerticalScrollBarEnabled(false);
emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
}
}
}
}
});
LinearLayout emptyTextLayout = new LinearLayout(getParentActivity());
emptyTextLayout.setVisibility(View.INVISIBLE);
emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.addView(emptyTextLayout);
layoutParams = (LinearLayout.LayoutParams) emptyTextLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
emptyTextLayout.setLayoutParams(layoutParams);
emptyTextLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
emptyTextView = new TextView(getParentActivity());
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
emptyTextLayout.addView(emptyTextView);
layoutParams = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.weight = 0.5f;
emptyTextView.setLayoutParams(layoutParams);
FrameLayout frameLayout2 = new FrameLayout(getParentActivity());
emptyTextLayout.addView(frameLayout2);
layoutParams = (LinearLayout.LayoutParams) frameLayout2.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.weight = 0.5f;
frameLayout2.setLayoutParams(layoutParams);
listView = new LetterSectionsListView(getParentActivity());
listView.setEmptyView(emptyTextLayout);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setFastScrollEnabled(true);
listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
listView.setAdapter(listViewAdapter);
if (Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
}
linearLayout.addView(listView);
layoutParams = (LinearLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
TLRPC.User user = null;
if (searching && searchWas) {
user = searchListViewAdapter.getItem(i);
} else {
int section = listViewAdapter.getSectionForPosition(i);
int row = listViewAdapter.getPositionInSectionForPosition(i);
if (row < 0 || section < 0) {
return;
}
user = (TLRPC.User) listViewAdapter.getItem(section, row);
}
if (user == null) {
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (selectedContacts.isEmpty()) {
return;
}
ArrayList<Integer> result = new ArrayList<>();
result.addAll(selectedContacts.keySet());
if (isAlwaysShare || isNeverShare) {
if (delegate != null) {
delegate.didSelectUsers(result);
}
finishFragment();
} else {
Bundle args = new Bundle();
args.putIntegerArrayList("result", result);
args.putBoolean("broadcast", isBroadcast);
presentFragment(new GroupCreateFinalActivity(args));
}
}
}
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
boolean check = true;
if (selectedContacts.containsKey(user.id)) {
check = false;
searchListViewAdapter = new SearchAdapter(context, null, false);
searchListViewAdapter.setCheckedMap(selectedContacts);
searchListViewAdapter.setUseUserCell(true);
listViewAdapter = new ContactsAdapter(context, true, false, null);
listViewAdapter.setCheckedMap(selectedContacts);
fragmentView = new LinearLayout(context);
LinearLayout linearLayout = (LinearLayout) fragmentView;
linearLayout.setOrientation(LinearLayout.VERTICAL);
FrameLayout frameLayout = new FrameLayout(context);
linearLayout.addView(frameLayout);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.TOP;
frameLayout.setLayoutParams(layoutParams);
userSelectEditText = new EditText(context);
userSelectEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
userSelectEditText.setHintTextColor(0xff979797);
userSelectEditText.setTextColor(0xff212121);
userSelectEditText.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
userSelectEditText.setMinimumHeight(AndroidUtilities.dp(54));
userSelectEditText.setSingleLine(false);
userSelectEditText.setLines(2);
userSelectEditText.setMaxLines(2);
userSelectEditText.setVerticalScrollBarEnabled(true);
userSelectEditText.setHorizontalScrollBarEnabled(false);
userSelectEditText.setPadding(0, 0, 0, 0);
userSelectEditText.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
userSelectEditText.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
AndroidUtilities.clearCursorDrawable(userSelectEditText);
frameLayout.addView(userSelectEditText);
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) userSelectEditText.getLayoutParams();
layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams1.leftMargin = AndroidUtilities.dp(10);
layoutParams1.rightMargin = AndroidUtilities.dp(10);
layoutParams1.gravity = Gravity.TOP;
userSelectEditText.setLayoutParams(layoutParams1);
if (isAlwaysShare) {
userSelectEditText.setHint(LocaleController.getString("AlwaysShareWithPlaceholder", R.string.AlwaysShareWithPlaceholder));
} else if (isNeverShare) {
userSelectEditText.setHint(LocaleController.getString("NeverShareWithPlaceholder", R.string.NeverShareWithPlaceholder));
} else {
userSelectEditText.setHint(LocaleController.getString("SendMessageTo", R.string.SendMessageTo));
}
if (Build.VERSION.SDK_INT >= 11) {
userSelectEditText.setTextIsSelectable(false);
}
userSelectEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
if (!ignoreChange) {
beforeChangeIndex = userSelectEditText.getSelectionStart();
changeString = new SpannableString(charSequence);
}
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
if (!ignoreChange) {
boolean search = false;
int afterChangeIndex = userSelectEditText.getSelectionEnd();
if (editable.toString().length() < changeString.toString().length()) {
String deletedString = "";
try {
XImageSpan span = selectedContacts.get(user.id);
selectedContacts.remove(user.id);
SpannableStringBuilder text = new SpannableStringBuilder(userSelectEditText.getText());
text.delete(text.getSpanStart(span), text.getSpanEnd(span));
allSpans.remove(span);
ignoreChange = true;
userSelectEditText.setText(text);
userSelectEditText.setSelection(text.length());
ignoreChange = false;
deletedString = changeString.toString().substring(afterChangeIndex, beforeChangeIndex);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (deletedString.length() > 0) {
if (searching && searchWas) {
search = true;
}
Spannable span = userSelectEditText.getText();
for (int a = 0; a < allSpans.size(); a++) {
XImageSpan sp = allSpans.get(a);
if (span.getSpanStart(sp) == -1) {
allSpans.remove(sp);
selectedContacts.remove(sp.uid);
}
}
if (!isAlwaysShare && !isNeverShare) {
actionBar.setSubtitle(LocaleController.formatString("MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));
}
listView.invalidateViews();
} else {
search = true;
}
} else {
if (selectedContacts.size() == maxCount) {
return;
}
ignoreChange = true;
XImageSpan span = createAndPutChipForUser(user);
span.uid = user.id;
ignoreChange = false;
search = true;
}
if (!isAlwaysShare && !isNeverShare) {
actionBar.setSubtitle(LocaleController.formatString("MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));
}
if (searching || searchWas) {
ignoreChange = true;
SpannableStringBuilder ssb = new SpannableStringBuilder("");
for (ImageSpan sp : allSpans) {
ssb.append("<<");
ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
}
userSelectEditText.setText(ssb);
userSelectEditText.setSelection(ssb.length());
ignoreChange = false;
searchListViewAdapter.searchDialogs(null);
searching = false;
searchWas = false;
listView.setAdapter(listViewAdapter);
listViewAdapter.notifyDataSetChanged();
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
}
listView.setFastScrollEnabled(true);
listView.setVerticalScrollBarEnabled(false);
emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
} else {
if (view instanceof UserCell) {
((UserCell) view).setChecked(check, true);
if (search) {
String text = userSelectEditText.getText().toString().replace("<", "");
if (text.length() != 0) {
searching = true;
searchWas = true;
if (listView != null) {
listView.setAdapter(searchListViewAdapter);
searchListViewAdapter.notifyDataSetChanged();
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(false);
}
listView.setFastScrollEnabled(false);
listView.setVerticalScrollBarEnabled(true);
}
if (emptyTextView != null) {
emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
}
searchListViewAdapter.searchDialogs(text);
} else {
searchListViewAdapter.searchDialogs(null);
searching = false;
searchWas = false;
listView.setAdapter(listViewAdapter);
listViewAdapter.notifyDataSetChanged();
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
}
listView.setFastScrollEnabled(true);
listView.setVerticalScrollBarEnabled(false);
emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
}
}
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL) {
AndroidUtilities.hideKeyboard(userSelectEditText);
}
if (listViewAdapter != null) {
listViewAdapter.setIsScrolling(i != SCROLL_STATE_IDLE);
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (absListView.isFastScrollEnabled()) {
AndroidUtilities.clearDrawableAnimation(absListView);
}
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
});
LinearLayout emptyTextLayout = new LinearLayout(context);
emptyTextLayout.setVisibility(View.INVISIBLE);
emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.addView(emptyTextLayout);
layoutParams = (LinearLayout.LayoutParams) emptyTextLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
emptyTextLayout.setLayoutParams(layoutParams);
emptyTextLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
emptyTextView = new TextView(context);
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
emptyTextLayout.addView(emptyTextView);
layoutParams = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.weight = 0.5f;
emptyTextView.setLayoutParams(layoutParams);
FrameLayout frameLayout2 = new FrameLayout(context);
emptyTextLayout.addView(frameLayout2);
layoutParams = (LinearLayout.LayoutParams) frameLayout2.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.weight = 0.5f;
frameLayout2.setLayoutParams(layoutParams);
listView = new LetterSectionsListView(context);
listView.setEmptyView(emptyTextLayout);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setFastScrollEnabled(true);
listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
listView.setAdapter(listViewAdapter);
if (Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
}
linearLayout.addView(listView);
layoutParams = (LinearLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
TLRPC.User user = null;
if (searching && searchWas) {
user = searchListViewAdapter.getItem(i);
} else {
int section = listViewAdapter.getSectionForPosition(i);
int row = listViewAdapter.getPositionInSectionForPosition(i);
if (row < 0 || section < 0) {
return;
}
user = (TLRPC.User) listViewAdapter.getItem(section, row);
}
if (user == null) {
return;
}
boolean check = true;
if (selectedContacts.containsKey(user.id)) {
check = false;
try {
XImageSpan span = selectedContacts.get(user.id);
selectedContacts.remove(user.id);
SpannableStringBuilder text = new SpannableStringBuilder(userSelectEditText.getText());
text.delete(text.getSpanStart(span), text.getSpanEnd(span));
allSpans.remove(span);
ignoreChange = true;
userSelectEditText.setText(text);
userSelectEditText.setSelection(text.length());
ignoreChange = false;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else {
if (selectedContacts.size() == maxCount) {
return;
}
ignoreChange = true;
XImageSpan span = createAndPutChipForUser(user);
span.uid = user.id;
ignoreChange = false;
}
if (!isAlwaysShare && !isNeverShare) {
actionBar.setSubtitle(LocaleController.formatString("MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));
}
if (searching || searchWas) {
ignoreChange = true;
SpannableStringBuilder ssb = new SpannableStringBuilder("");
for (ImageSpan sp : allSpans) {
ssb.append("<<");
ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
}
userSelectEditText.setText(ssb);
userSelectEditText.setSelection(ssb.length());
ignoreChange = false;
searchListViewAdapter.searchDialogs(null);
searching = false;
searchWas = false;
listView.setAdapter(listViewAdapter);
listViewAdapter.notifyDataSetChanged();
if (android.os.Build.VERSION.SDK_INT >= 11) {
listView.setFastScrollAlwaysVisible(true);
}
listView.setFastScrollEnabled(true);
listView.setVerticalScrollBarEnabled(false);
emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
} else {
if (view instanceof UserCell) {
((UserCell) view).setChecked(check, true);
}
}
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL) {
AndroidUtilities.hideKeyboard(userSelectEditText);
}
if (listViewAdapter != null) {
listViewAdapter.setIsScrolling(i != SCROLL_STATE_IDLE);
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (absListView.isFastScrollEnabled()) {
AndroidUtilities.clearDrawableAnimation(absListView);
}
}
});
return fragmentView;
}

View file

@ -138,191 +138,185 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (isBroadcast) {
actionBar.setTitle(LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList));
} else {
actionBar.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup));
}
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (isBroadcast) {
actionBar.setTitle(LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList));
} else {
actionBar.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (donePressed) {
return;
}
if (nameTextView.getText().length() == 0) {
return;
}
donePressed = true;
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (donePressed) {
return;
}
if (nameTextView.getText().length() == 0) {
return;
}
donePressed = true;
if (isBroadcast) {
MessagesController.getInstance().createChat(nameTextView.getText().toString(), selectedContacts, uploadedAvatar, isBroadcast);
if (isBroadcast) {
MessagesController.getInstance().createChat(nameTextView.getText().toString(), selectedContacts, isBroadcast);
} else {
if (avatarUpdater.uploadingAvatar != null) {
createAfterUpload = true;
} else {
if (avatarUpdater.uploadingAvatar != null) {
createAfterUpload = true;
} else {
progressDialog = new ProgressDialog(getParentActivity());
progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
progressDialog = new ProgressDialog(getParentActivity());
progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
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
public void onClick(DialogInterface dialog, int which) {
ConnectionsManager.getInstance().cancelRpc(reqId, true);
donePressed = false;
try {
dialog.dismiss();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ConnectionsManager.getInstance().cancelRpc(reqId, true);
donePressed = false;
try {
dialog.dismiss();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
});
progressDialog.show();
}
}
});
progressDialog.show();
}
}
}
});
}
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
fragmentView = new LinearLayout(getParentActivity());
LinearLayout linearLayout = (LinearLayout) fragmentView;
linearLayout.setOrientation(LinearLayout.VERTICAL);
fragmentView = new LinearLayout(context);
LinearLayout linearLayout = (LinearLayout) fragmentView;
linearLayout.setOrientation(LinearLayout.VERTICAL);
FrameLayout frameLayout = new FrameLayoutFixed(getParentActivity());
linearLayout.addView(frameLayout);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
frameLayout.setLayoutParams(layoutParams);
FrameLayout frameLayout = new FrameLayoutFixed(context);
linearLayout.addView(frameLayout);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
frameLayout.setLayoutParams(layoutParams);
avatarImage = new BackupImageView(getParentActivity());
avatarImage.imageReceiver.setRoundRadius(AndroidUtilities.dp(32));
avatarDrawable.setInfo(5, null, null, isBroadcast);
avatarImage.setImageDrawable(avatarDrawable);
frameLayout.addView(avatarImage);
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
layoutParams1.width = AndroidUtilities.dp(64);
layoutParams1.height = AndroidUtilities.dp(64);
layoutParams1.topMargin = AndroidUtilities.dp(12);
layoutParams1.bottomMargin = AndroidUtilities.dp(12);
layoutParams1.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(16);
layoutParams1.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(16) : 0;
layoutParams1.gravity = Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
avatarImage.setLayoutParams(layoutParams1);
if (!isBroadcast) {
avatarDrawable.setDrawPhoto(true);
avatarImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
avatarImage = new BackupImageView(context);
avatarImage.setRoundRadius(AndroidUtilities.dp(32));
avatarDrawable.setInfo(5, null, null, isBroadcast);
avatarImage.setImageDrawable(avatarDrawable);
frameLayout.addView(avatarImage);
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
layoutParams1.width = AndroidUtilities.dp(64);
layoutParams1.height = AndroidUtilities.dp(64);
layoutParams1.topMargin = AndroidUtilities.dp(12);
layoutParams1.bottomMargin = AndroidUtilities.dp(12);
layoutParams1.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(16);
layoutParams1.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(16) : 0;
layoutParams1.gravity = Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
avatarImage.setLayoutParams(layoutParams1);
if (!isBroadcast) {
avatarDrawable.setDrawPhoto(true);
avatarImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items;
CharSequence[] items;
if (avatar != null) {
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto)};
} else {
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley)};
}
if (avatar != null) {
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto)};
} else {
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley)};
}
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
avatarUpdater.openCamera();
} else if (i == 1) {
avatarUpdater.openGallery();
} else if (i == 2) {
avatar = null;
uploadedAvatar = null;
avatarImage.setImage(avatar, "50_50", avatarDrawable);
}
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
avatarUpdater.openCamera();
} else if (i == 1) {
avatarUpdater.openGallery();
} else if (i == 2) {
avatar = null;
uploadedAvatar = null;
avatarImage.setImage(avatar, "50_50", avatarDrawable);
}
});
showAlertDialog(builder);
}
});
}
nameTextView = new EditText(getParentActivity());
nameTextView.setHint(isBroadcast ? LocaleController.getString("EnterListName", R.string.EnterListName) : LocaleController.getString("EnterGroupNamePlaceholder", R.string.EnterGroupNamePlaceholder));
if (nameToSet != null) {
nameTextView.setText(nameToSet);
nameToSet = null;
}
nameTextView.setMaxLines(4);
nameTextView.setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
nameTextView.setHintTextColor(0xff979797);
nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
nameTextView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
nameTextView.setPadding(0, 0, 0, AndroidUtilities.dp(8));
AndroidUtilities.clearCursorDrawable(nameTextView);
nameTextView.setTextColor(0xff212121);
frameLayout.addView(nameTextView);
layoutParams1 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams1.leftMargin = LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(96);
layoutParams1.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(96) : AndroidUtilities.dp(16);
layoutParams1.gravity = Gravity.CENTER_VERTICAL;
nameTextView.setLayoutParams(layoutParams1);
if (!isBroadcast) {
nameTextView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null, null, isBroadcast);
avatarImage.invalidate();
}
});
}
GreySectionCell sectionCell = new GreySectionCell(getParentActivity());
sectionCell.setText(LocaleController.formatPluralString("Members", selectedContacts.size()));
linearLayout.addView(sectionCell);
listView = new ListView(getParentActivity());
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
listView.setAdapter(listAdapter = new ListAdapter(getParentActivity()));
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);
}
}
});
showAlertDialog(builder);
}
});
}
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);
nameToSet = null;
}
nameTextView.setMaxLines(4);
nameTextView.setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
nameTextView.setHintTextColor(0xff979797);
nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
nameTextView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
nameTextView.setPadding(0, 0, 0, AndroidUtilities.dp(8));
AndroidUtilities.clearCursorDrawable(nameTextView);
nameTextView.setTextColor(0xff212121);
frameLayout.addView(nameTextView);
layoutParams1 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams1.leftMargin = LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(96);
layoutParams1.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(96) : AndroidUtilities.dp(16);
layoutParams1.gravity = Gravity.CENTER_VERTICAL;
nameTextView.setLayoutParams(layoutParams1);
if (!isBroadcast) {
nameTextView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null, null, isBroadcast);
avatarImage.invalidate();
}
});
}
GreySectionCell sectionCell = new GreySectionCell(context);
sectionCell.setText(LocaleController.formatPluralString("Members", selectedContacts.size()));
linearLayout.addView(sectionCell);
listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
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);
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,45 +44,39 @@ public class IdenticonActivity extends BaseFragment {
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey));
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));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
});
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);
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)));
}
});
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
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);
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(AndroidUtilities.replaceTags(LocaleController.formatString("EncryptionKeyDescription", R.string.EncryptionKeyDescription, user.first_name, user.first_name)));
}
fragmentView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
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,192 +52,186 @@ public class LanguageSelectActivity extends BaseFragment {
public ArrayList<LocaleController.LocaleInfo> searchResult;
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
searching = false;
searchWas = false;
public View createView(Context context, LayoutInflater inflater) {
searching = false;
searchWas = false;
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("Language", R.string.Language));
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("Language", R.string.Language));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
searching = true;
}
@Override
public boolean onSearchCollapse() {
search(null);
searching = false;
searchWas = false;
if (listView != null) {
emptyTextView.setVisibility(View.GONE);
listView.setAdapter(listAdapter);
}
return true;
}
@Override
public void onTextChanged(EditText editText) {
String text = editText.getText().toString();
search(text);
if (text.length() != 0) {
searchWas = true;
if (listView != null) {
listView.setAdapter(searchListViewAdapter);
}
}
}
});
item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
listAdapter = new ListAdapter(getParentActivity());
searchListViewAdapter = new SearchAdapter(getParentActivity());
fragmentView = new FrameLayout(getParentActivity());
LinearLayout emptyTextLayout = new LinearLayout(getParentActivity());
emptyTextLayout.setVisibility(View.INVISIBLE);
emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
((FrameLayout) fragmentView).addView(emptyTextLayout);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP;
emptyTextLayout.setLayoutParams(layoutParams);
emptyTextLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
emptyTextView = new TextView(getParentActivity());
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
emptyTextLayout.addView(emptyTextView);
LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.weight = 0.5f;
emptyTextView.setLayoutParams(layoutParams1);
FrameLayout frameLayout = new FrameLayout(getParentActivity());
emptyTextLayout.addView(frameLayout);
layoutParams1 = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.weight = 0.5f;
frameLayout.setLayoutParams(layoutParams1);
listView = new ListView(getParentActivity());
listView.setEmptyView(emptyTextLayout);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setAdapter(listAdapter);
((FrameLayout) fragmentView).addView(listView);
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
LocaleController.LocaleInfo localeInfo = null;
if (searching && searchWas) {
if (i >= 0 && i < searchResult.size()) {
localeInfo = searchResult.get(i);
}
} else {
if (i >= 0 && i < LocaleController.getInstance().sortedLanguages.size()) {
localeInfo = LocaleController.getInstance().sortedLanguages.get(i);
}
}
if (localeInfo != null) {
LocaleController.getInstance().applyLanguage(localeInfo, true);
parentLayout.rebuildAllFragmentViews(false);
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
});
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
LocaleController.LocaleInfo localeInfo = null;
if (searching && searchWas) {
if (i >= 0 && i < searchResult.size()) {
localeInfo = searchResult.get(i);
}
} else {
if (i >= 0 && i < LocaleController.getInstance().sortedLanguages.size()) {
localeInfo = LocaleController.getInstance().sortedLanguages.get(i);
}
ActionBarMenu menu = actionBar.createMenu();
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
searching = true;
}
@Override
public boolean onSearchCollapse() {
search(null);
searching = false;
searchWas = false;
if (listView != null) {
emptyTextView.setVisibility(View.GONE);
listView.setAdapter(listAdapter);
}
return true;
}
@Override
public void onTextChanged(EditText editText) {
String text = editText.getText().toString();
search(text);
if (text.length() != 0) {
searchWas = true;
if (listView != null) {
listView.setAdapter(searchListViewAdapter);
}
if (localeInfo == null || localeInfo.pathToFile == null || getParentActivity() == null) {
return false;
}
}
});
item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
listAdapter = new ListAdapter(context);
searchListViewAdapter = new SearchAdapter(context);
fragmentView = new FrameLayout(context);
LinearLayout emptyTextLayout = new LinearLayout(context);
emptyTextLayout.setVisibility(View.INVISIBLE);
emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
((FrameLayout) fragmentView).addView(emptyTextLayout);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP;
emptyTextLayout.setLayoutParams(layoutParams);
emptyTextLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
emptyTextView = new TextView(context);
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
emptyTextLayout.addView(emptyTextView);
LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.weight = 0.5f;
emptyTextView.setLayoutParams(layoutParams1);
FrameLayout frameLayout = new FrameLayout(context);
emptyTextLayout.addView(frameLayout);
layoutParams1 = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
layoutParams1.weight = 0.5f;
frameLayout.setLayoutParams(layoutParams1);
listView = new ListView(context);
listView.setEmptyView(emptyTextLayout);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setAdapter(listAdapter);
((FrameLayout) fragmentView).addView(listView);
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
LocaleController.LocaleInfo localeInfo = null;
if (searching && searchWas) {
if (i >= 0 && i < searchResult.size()) {
localeInfo = searchResult.get(i);
}
final LocaleController.LocaleInfo finalLocaleInfo = localeInfo;
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("DeleteLocalization", R.string.DeleteLocalization));
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (LocaleController.getInstance().deleteLanguage(finalLocaleInfo)) {
if (searchResult != null) {
searchResult.remove(finalLocaleInfo);
}
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
if (searchListViewAdapter != null) {
searchListViewAdapter.notifyDataSetChanged();
}
} else {
if (i >= 0 && i < LocaleController.getInstance().sortedLanguages.size()) {
localeInfo = LocaleController.getInstance().sortedLanguages.get(i);
}
}
if (localeInfo != null) {
LocaleController.getInstance().applyLanguage(localeInfo, true);
parentLayout.rebuildAllFragmentViews(false);
}
finishFragment();
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
LocaleController.LocaleInfo localeInfo = null;
if (searching && searchWas) {
if (i >= 0 && i < searchResult.size()) {
localeInfo = searchResult.get(i);
}
} else {
if (i >= 0 && i < LocaleController.getInstance().sortedLanguages.size()) {
localeInfo = LocaleController.getInstance().sortedLanguages.get(i);
}
}
if (localeInfo == null || localeInfo.pathToFile == null || getParentActivity() == null) {
return false;
}
final LocaleController.LocaleInfo finalLocaleInfo = localeInfo;
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("DeleteLocalization", R.string.DeleteLocalization));
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (LocaleController.getInstance().deleteLanguage(finalLocaleInfo)) {
if (searchResult != null) {
searchResult.remove(finalLocaleInfo);
}
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
if (searchListViewAdapter != null) {
searchListViewAdapter.notifyDataSetChanged();
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
return true;
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
return true;
}
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
return fragmentView;
}

View file

@ -99,150 +99,144 @@ public class LastSeenActivity extends BaseFragment implements NotificationCenter
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("PrivacyLastSeen", R.string.PrivacyLastSeen));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (getParentActivity() == null) {
return;
}
if (currentType != 0) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean showed = preferences.getBoolean("privacyAlertShowed", false);
if (!showed) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("CustomHelp", R.string.CustomHelp));
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) {
applyCurrentPrivacySettings();
preferences.edit().putBoolean("privacyAlertShowed", true).commit();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
return;
}
}
applyCurrentPrivacySettings();
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));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (getParentActivity() == null) {
return;
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
doneButton.setVisibility(View.GONE);
listAdapter = new ListAdapter(getParentActivity());
fragmentView = new FrameLayout(getParentActivity());
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xfff0f0f0);
ListView listView = new ListView(getParentActivity());
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
listView.setDrawSelectorOnTop(true);
frameLayout.addView(listView);
FrameLayout.LayoutParams 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 == nobodyRow || i == everybodyRow || i == myContactsRow) {
int newType = currentType;
if (i == nobodyRow) {
newType = 1;
} else if (i == everybodyRow) {
newType = 0;
} else if (i == myContactsRow) {
newType = 2;
}
if (newType == currentType) {
if (currentType != 0) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean showed = preferences.getBoolean("privacyAlertShowed", false);
if (!showed) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("CustomHelp", R.string.CustomHelp));
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) {
applyCurrentPrivacySettings();
preferences.edit().putBoolean("privacyAlertShowed", true).commit();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
return;
}
doneButton.setVisibility(View.VISIBLE);
currentType = newType;
updateRows();
} else if (i == neverShareRow || i == alwaysShareRow) {
ArrayList<Integer> createFromArray = null;
if (i == neverShareRow) {
createFromArray = currentMinus;
} else {
createFromArray = currentPlus;
}
if (createFromArray.isEmpty()) {
Bundle args = new Bundle();
args.putBoolean(i == neverShareRow ? "isNeverShare" : "isAlwaysShare", true);
GroupCreateActivity fragment = new GroupCreateActivity(args);
fragment.setDelegate(new GroupCreateActivity.GroupCreateActivityDelegate() {
@Override
public void didSelectUsers(ArrayList<Integer> ids) {
if (i == neverShareRow) {
currentMinus = ids;
}
applyCurrentPrivacySettings();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
doneButton.setVisibility(View.GONE);
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xfff0f0f0);
ListView listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
listView.setDrawSelectorOnTop(true);
frameLayout.addView(listView);
FrameLayout.LayoutParams 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 == nobodyRow || i == everybodyRow || i == myContactsRow) {
int newType = currentType;
if (i == nobodyRow) {
newType = 1;
} else if (i == everybodyRow) {
newType = 0;
} else if (i == myContactsRow) {
newType = 2;
}
if (newType == currentType) {
return;
}
doneButton.setVisibility(View.VISIBLE);
currentType = newType;
updateRows();
} else if (i == neverShareRow || i == alwaysShareRow) {
ArrayList<Integer> createFromArray = null;
if (i == neverShareRow) {
createFromArray = currentMinus;
} else {
createFromArray = currentPlus;
}
if (createFromArray.isEmpty()) {
Bundle args = new Bundle();
args.putBoolean(i == neverShareRow ? "isNeverShare" : "isAlwaysShare", true);
GroupCreateActivity fragment = new GroupCreateActivity(args);
fragment.setDelegate(new GroupCreateActivity.GroupCreateActivityDelegate() {
@Override
public void didSelectUsers(ArrayList<Integer> ids) {
if (i == neverShareRow) {
currentMinus = ids;
for (Integer id : currentMinus) {
currentPlus.remove(id);
}
} else {
currentPlus = ids;
for (Integer id : currentPlus) {
currentMinus.remove(id);
}
}
doneButton.setVisibility(View.VISIBLE);
listAdapter.notifyDataSetChanged();
}
});
presentFragment(fragment);
} else {
LastSeenUsersActivity fragment = new LastSeenUsersActivity(createFromArray, i == alwaysShareRow);
fragment.setDelegate(new LastSeenUsersActivity.LastSeenUsersActivityDelegate() {
@Override
public void didUpdatedUserList(ArrayList<Integer> ids, boolean added) {
if (i == neverShareRow) {
currentMinus = ids;
if (added) {
for (Integer id : currentMinus) {
currentPlus.remove(id);
}
} else {
currentPlus = ids;
}
} else {
currentPlus = ids;
if (added) {
for (Integer id : currentPlus) {
currentMinus.remove(id);
}
}
doneButton.setVisibility(View.VISIBLE);
listAdapter.notifyDataSetChanged();
}
});
presentFragment(fragment);
} else {
LastSeenUsersActivity fragment = new LastSeenUsersActivity(createFromArray, i == alwaysShareRow);
fragment.setDelegate(new LastSeenUsersActivity.LastSeenUsersActivityDelegate() {
@Override
public void didUpdatedUserList(ArrayList<Integer> ids, boolean added) {
if (i == neverShareRow) {
currentMinus = ids;
if (added) {
for (Integer id : currentMinus) {
currentPlus.remove(id);
}
}
} else {
currentPlus = ids;
if (added) {
for (Integer id : currentPlus) {
currentMinus.remove(id);
}
}
}
doneButton.setVisibility(View.VISIBLE);
listAdapter.notifyDataSetChanged();
}
});
presentFragment(fragment);
}
doneButton.setVisibility(View.VISIBLE);
listAdapter.notifyDataSetChanged();
}
});
presentFragment(fragment);
}
}
});
} else {
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
});
return fragmentView;
}

View file

@ -75,127 +75,121 @@ public class LastSeenUsersActivity extends BaseFragment implements NotificationC
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (isAlwaysShare) {
actionBar.setTitle(LocaleController.getString("AlwaysShareWithTitle", R.string.AlwaysShareWithTitle));
} else {
actionBar.setTitle(LocaleController.getString("NeverShareWithTitle", R.string.NeverShareWithTitle));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == block_user) {
Bundle args = new Bundle();
args.putBoolean(isAlwaysShare ? "isAlwaysShare" : "isNeverShare", true);
GroupCreateActivity fragment = new GroupCreateActivity(args);
fragment.setDelegate(new GroupCreateActivity.GroupCreateActivityDelegate() {
@Override
public void didSelectUsers(ArrayList<Integer> ids) {
for (Integer id : ids) {
if (uidArray.contains(id)) {
continue;
}
uidArray.add(id);
}
listViewAdapter.notifyDataSetChanged();
if (delegate != null) {
delegate.didUpdatedUserList(uidArray, true);
}
}
});
presentFragment(fragment);
}
}
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItem(block_user, R.drawable.plus);
fragmentView = new FrameLayout(getParentActivity());
FrameLayout frameLayout = (FrameLayout) fragmentView;
TextView emptyTextView = new TextView(getParentActivity());
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setVisibility(View.INVISIBLE);
emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
frameLayout.addView(emptyTextView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP;
emptyTextView.setLayoutParams(layoutParams);
emptyTextView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
listView = new ListView(getParentActivity());
listView.setEmptyView(emptyTextView);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setAdapter(listViewAdapter = new ListAdapter(getParentActivity()));
if (Build.VERSION.SDK_INT >= 11) {
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
}
frameLayout.addView(listView);
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i < uidArray.size()) {
Bundle args = new Bundle();
args.putInt("user_id", uidArray.get(i));
presentFragment(new ProfileActivity(args));
}
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i < 0 || i >= uidArray.size() || getParentActivity() == null) {
return true;
}
selectedUserId = uidArray.get(i);
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items = new CharSequence[] {LocaleController.getString("Delete", R.string.Delete)};
builder.setItems(items, new DialogInterface.OnClickListener() {
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (isAlwaysShare) {
actionBar.setTitle(LocaleController.getString("AlwaysShareWithTitle", R.string.AlwaysShareWithTitle));
} else {
actionBar.setTitle(LocaleController.getString("NeverShareWithTitle", R.string.NeverShareWithTitle));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == block_user) {
Bundle args = new Bundle();
args.putBoolean(isAlwaysShare ? "isAlwaysShare" : "isNeverShare", true);
GroupCreateActivity fragment = new GroupCreateActivity(args);
fragment.setDelegate(new GroupCreateActivity.GroupCreateActivityDelegate() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
uidArray.remove((Integer)selectedUserId);
listViewAdapter.notifyDataSetChanged();
if (delegate != null) {
delegate.didUpdatedUserList(uidArray, false);
public void didSelectUsers(ArrayList<Integer> ids) {
for (Integer id : ids) {
if (uidArray.contains(id)) {
continue;
}
uidArray.add(id);
}
listViewAdapter.notifyDataSetChanged();
if (delegate != null) {
delegate.didUpdatedUserList(uidArray, true);
}
}
});
showAlertDialog(builder);
presentFragment(fragment);
}
}
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItem(block_user, R.drawable.plus);
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
TextView emptyTextView = new TextView(context);
emptyTextView.setTextColor(0xff808080);
emptyTextView.setTextSize(20);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setVisibility(View.INVISIBLE);
emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
frameLayout.addView(emptyTextView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP;
emptyTextView.setLayoutParams(layoutParams);
emptyTextView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
listView = new ListView(context);
listView.setEmptyView(emptyTextView);
listView.setVerticalScrollBarEnabled(false);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setAdapter(listViewAdapter = new ListAdapter(context));
if (Build.VERSION.SDK_INT >= 11) {
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
}
frameLayout.addView(listView);
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i < uidArray.size()) {
Bundle args = new Bundle();
args.putInt("user_id", uidArray.get(i));
presentFragment(new ProfileActivity(args));
}
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i < 0 || i >= uidArray.size() || getParentActivity() == null) {
return true;
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
selectedUserId = uidArray.get(i);
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
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);
listViewAdapter.notifyDataSetChanged();
if (delegate != null) {
delegate.didUpdatedUserList(uidArray, false);
}
}
}
});
showAlertDialog(builder);
return true;
}
}
});
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,17 +342,12 @@ 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);
}
actionBarLayout.addFragmentToStack(new MessagesActivity(null));
drawerLayoutContainer.setAllowOpenDrawer(true, false);
}
try {
@ -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,35 +858,25 @@ 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);
}
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.addFragmentToStack(new MessagesActivity(null));
drawerLayoutContainer.setAllowOpenDrawer(true, false);
}
}
}
@ -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,170 +88,159 @@ 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) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (messageObject != null) {
actionBar.setTitle(LocaleController.getString("ChatLocation", R.string.ChatLocation));
} else {
actionBar.setTitle(LocaleController.getString("ShareLocation", R.string.ShareLocation));
}
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (messageObject != null) {
actionBar.setTitle(LocaleController.getString("ChatLocation", R.string.ChatLocation));
} else {
actionBar.setTitle(LocaleController.getString("ShareLocation", R.string.ShareLocation));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == map_list_menu_map) {
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == map_list_menu_map) {
if (googleMap != null) {
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
} else if (id == map_list_menu_satellite) {
if (googleMap != null) {
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
}
} else if (id == map_list_menu_hybrid) {
if (googleMap != null) {
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
}
} else if (id == map_to_my_location) {
if (myLocation != null) {
LatLng latLng = new LatLng(myLocation.getLatitude(), myLocation.getLongitude());
if (googleMap != null) {
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
} else if (id == map_list_menu_satellite) {
if (googleMap != null) {
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
}
} else if (id == map_list_menu_hybrid) {
if (googleMap != null) {
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
}
} else if (id == map_to_my_location) {
if (myLocation != null) {
LatLng latLng = new LatLng(myLocation.getLatitude(), myLocation.getLongitude());
if (googleMap != null) {
CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8);
googleMap.animateCamera(position);
}
CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8);
googleMap.animateCamera(position);
}
}
}
}
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItem(map_to_my_location, R.drawable.ic_ab_location);
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
item.addSubItem(map_list_menu_map, LocaleController.getString("Map", R.string.Map), 0);
item.addSubItem(map_list_menu_satellite, LocaleController.getString("Satellite", R.string.Satellite), 0);
item.addSubItem(map_list_menu_hybrid, LocaleController.getString("Hybrid", R.string.Hybrid), 0);
if (messageObject != null) {
fragmentView = inflater.inflate(R.layout.location_view_layout, null, false);
} else {
fragmentView = inflater.inflate(R.layout.location_attach_layout, null, false);
}
avatarImageView = (BackupImageView) fragmentView.findViewById(R.id.location_avatar_view);
if (avatarImageView != null) {
avatarImageView.setRoundRadius(AndroidUtilities.dp(32));
}
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) {
sendButton.setText(LocaleController.getString("SendLocation", R.string.SendLocation).toUpperCase());
sendButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
}
mapView = (MapView) fragmentView.findViewById(R.id.map_view);
mapView.onCreate(null);
try {
MapsInitializer.initialize(context);
googleMap = mapView.getMap();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (googleMap != null) {
googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(false);
googleMap.getUiSettings().setZoomControlsEnabled(false);
googleMap.getUiSettings().setCompassEnabled(false);
googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(Location location) {
positionMarker(location);
}
});
myLocation = getLastLocation();
ActionBarMenu menu = actionBar.createMenu();
menu.addItem(map_to_my_location, R.drawable.ic_ab_location);
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
item.addSubItem(map_list_menu_map, LocaleController.getString("Map", R.string.Map), 0);
item.addSubItem(map_list_menu_satellite, LocaleController.getString("Satellite", R.string.Satellite), 0);
item.addSubItem(map_list_menu_hybrid, LocaleController.getString("Hybrid", R.string.Hybrid), 0);
if (messageObject != null) {
fragmentView = inflater.inflate(R.layout.location_view_layout, null, false);
} else {
fragmentView = inflater.inflate(R.layout.location_attach_layout, null, false);
}
avatarImageView = (BackupImageView)fragmentView.findViewById(R.id.location_avatar_view);
if (avatarImageView != null) {
avatarImageView.processDetach = false;
avatarImageView.imageReceiver.setRoundRadius(AndroidUtilities.dp(32));
}
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) {
sendButton.setText(LocaleController.getString("SendLocation", R.string.SendLocation).toUpperCase());
sendButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
}
userLocation = new Location("network");
userLocation.setLatitude(20.659322);
userLocation.setLongitude(-11.406250);
LatLng latLng = new LatLng(20.659322, -11.406250);
userMarker = googleMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)).draggable(true));
mapView = (MapView)fragmentView.findViewById(R.id.map_view);
mapView.onCreate(null);
try {
MapsInitializer.initialize(getParentActivity());
googleMap = mapView.getMap();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (googleMap != null) {
googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(false);
googleMap.getUiSettings().setZoomControlsEnabled(false);
googleMap.getUiSettings().setCompassEnabled(false);
googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onMyLocationChange(Location location) {
positionMarker(location);
public void onClick(View view) {
if (delegate != null) {
delegate.didSelectLocation(userLocation.getLatitude(), userLocation.getLongitude());
}
finishFragment();
}
});
myLocation = getLastLocation();
if (sendButton != null) {
userLocation = new Location("network");
userLocation.setLatitude(20.659322);
userLocation.setLongitude(-11.406250);
LatLng latLng = new LatLng(20.659322, -11.406250);
userMarker = googleMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)).draggable(true));
googleMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {
@Override
public void onMarkerDragStart(Marker marker) {
}
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (delegate != null) {
delegate.didSelectLocation(userLocation.getLatitude(), userLocation.getLongitude());
}
finishFragment();
}
});
@Override
public void onMarkerDrag(Marker marker) {
userLocationMoved = true;
}
googleMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {
@Override
public void onMarkerDragStart(Marker marker) {
}
@Override
public void onMarkerDrag(Marker marker) {
userLocationMoved = true;
}
@Override
public void onMarkerDragEnd(Marker marker) {
LatLng latLng = marker.getPosition();
userLocation.setLatitude(latLng.latitude);
userLocation.setLongitude(latLng.longitude);
}
});
}
if (bottomView != null) {
bottomView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (userLocation != null) {
LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());
CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8);
googleMap.animateCamera(position);
}
}
});
}
if (messageObject != null) {
updateUserData();
userLocation = new Location("network");
userLocation.setLatitude(messageObject.messageOwner.media.geo.lat);
userLocation.setLongitude(messageObject.messageOwner.media.geo._long);
LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());
userMarker = googleMap.addMarker(new MarkerOptions().position(latLng).
icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)));
CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8);
googleMap.moveCamera(position);
}
positionMarker(myLocation);
@Override
public void onMarkerDragEnd(Marker marker) {
LatLng latLng = marker.getPosition();
userLocation.setLatitude(latLng.latitude);
userLocation.setLongitude(latLng.longitude);
}
});
}
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
if (bottomView != null) {
bottomView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (userLocation != null) {
LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());
CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8);
googleMap.animateCamera(position);
}
}
});
}
if (messageObject != null) {
userLocation = new Location("network");
userLocation.setLatitude(messageObject.messageOwner.media.geo.lat);
userLocation.setLongitude(messageObject.messageOwner.media.geo._long);
LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude());
userMarker = googleMap.addMarker(new MarkerOptions().position(latLng).
icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)));
CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 8);
googleMap.moveCamera(position);
}
positionMarker(myLocation);
}
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,364 +216,358 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle("");
actionBar.setAllowOverlayTitle(false);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (Build.VERSION.SDK_INT < 11 && listView != null) {
listView.setAdapter(null);
listView = null;
photoVideoAdapter = null;
documentsAdapter = null;
}
finishFragment();
} else if (id == -2) {
selectedFiles.clear();
actionBar.hideActionMode();
listView.invalidateViews();
} else if (id == shared_media_item) {
if (selectedMode == 0) {
return;
}
selectedMode = 0;
switchToCurrentSelectedMode();
} else if (id == files_item) {
if (selectedMode == 1) {
return;
}
selectedMode = 1;
switchToCurrentSelectedMode();
} else if (id == delete) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.formatString("AreYouSureDeleteMessages", R.string.AreYouSureDeleteMessages, LocaleController.formatPluralString("items", selectedFiles.size())));
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) {
ArrayList<Integer> ids = new ArrayList<>(selectedFiles.keySet());
ArrayList<Long> random_ids = null;
TLRPC.EncryptedChat currentEncryptedChat = null;
if ((int) dialog_id == 0) {
currentEncryptedChat = MessagesController.getInstance().getEncryptedChat((int) (dialog_id >> 32));
}
if (currentEncryptedChat != null) {
random_ids = new ArrayList<>();
for (HashMap.Entry<Integer, MessageObject> entry : selectedFiles.entrySet()) {
MessageObject msg = entry.getValue();
if (msg.messageOwner.random_id != 0 && msg.type != 10) {
random_ids.add(msg.messageOwner.random_id);
}
}
}
MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat);
actionBar.hideActionMode();
selectedFiles.clear();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (id == forward) {
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putBoolean("serverOnly", true);
MessagesActivity fragment = new MessagesActivity(args);
fragment.setDelegate(new MessagesActivity.MessagesActivityDelegate() {
@Override
public void didSelectDialog(MessagesActivity fragment, long did, boolean param) {
int lower_part = (int)did;
if (lower_part != 0) {
Bundle args = new Bundle();
args.putBoolean("scrollToTopOnResume", true);
if (lower_part > 0) {
args.putInt("user_id", lower_part);
} else if (lower_part < 0) {
args.putInt("chat_id", -lower_part);
}
ArrayList<MessageObject> fmessages = new ArrayList<>();
ArrayList<Integer> ids = new ArrayList<>(selectedFiles.keySet());
Collections.sort(ids);
for (Integer id : ids) {
if (id > 0) {
fmessages.add(selectedFiles.get(id));
}
}
selectedFiles.clear();
actionBar.hideActionMode();
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
ChatActivity chatActivity = new ChatActivity(args);
presentFragment(chatActivity, true);
chatActivity.showReplyForMessageObjectOrForward(true, null, fmessages, false);
if (!AndroidUtilities.isTablet()) {
removeSelfFromStack();
Activity parentActivity = getParentActivity();
if (parentActivity == null) {
parentActivity = chatActivity.getParentActivity();
}
if (parentActivity != null) {
parentActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}
}
} else {
fragment.finishFragment();
}
}
});
presentFragment(fragment);
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle("");
actionBar.setAllowOverlayTitle(false);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (Build.VERSION.SDK_INT < 11 && listView != null) {
listView.setAdapter(null);
listView = null;
photoVideoAdapter = null;
documentsAdapter = null;
}
}
});
selectedFiles.clear();
actionModeViews.clear();
final ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
dropDownContainer.setVisibility(View.GONE);
searching = true;
}
@Override
public boolean onSearchCollapse() {
dropDownContainer.setVisibility(View.VISIBLE);
documentsSearchAdapter.searchDocuments(null);
searching = false;
searchWas = false;
finishFragment();
} else if (id == -2) {
selectedFiles.clear();
actionBar.hideActionMode();
listView.invalidateViews();
} else if (id == shared_media_item) {
if (selectedMode == 0) {
return;
}
selectedMode = 0;
switchToCurrentSelectedMode();
return true;
}
@Override
public void onTextChanged(EditText editText) {
if (documentsSearchAdapter == null) {
} else if (id == files_item) {
if (selectedMode == 1) {
return;
}
String text = editText.getText().toString();
if (text.length() != 0) {
searchWas = true;
switchToCurrentSelectedMode();
}
documentsSearchAdapter.searchDocuments(text);
}
});
searchItem.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
searchItem.setVisibility(View.GONE);
dropDownContainer = new ActionBarMenuItem(getParentActivity(), 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);
actionBar.addView(dropDownContainer);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.rightMargin = AndroidUtilities.dp(40);
layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64) : AndroidUtilities.dp(56);
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
dropDownContainer.setLayoutParams(layoutParams);
dropDownContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dropDownContainer.toggleSubMenu();
}
});
dropDown = new TextView(getParentActivity());
dropDown.setGravity(Gravity.LEFT);
dropDown.setSingleLine(true);
dropDown.setLines(1);
dropDown.setMaxLines(1);
dropDown.setEllipsize(TextUtils.TruncateAt.END);
dropDown.setTextColor(0xffffffff);
dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
dropDownContainer.addView(dropDown);
layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(16);
layoutParams.gravity = Gravity.CENTER_VERTICAL;
dropDown.setLayoutParams(layoutParams);
final ActionBarMenu actionMode = actionBar.createActionMode();
actionModeViews.add(actionMode.addItem(-2, R.drawable.ic_ab_back_grey, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
selectedMessagesCountTextView = new TextView(actionMode.getContext());
selectedMessagesCountTextView.setTextSize(18);
selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
selectedMessagesCountTextView.setTextColor(0xff737373);
selectedMessagesCountTextView.setSingleLine(true);
selectedMessagesCountTextView.setLines(1);
selectedMessagesCountTextView.setEllipsize(TextUtils.TruncateAt.END);
selectedMessagesCountTextView.setPadding(AndroidUtilities.dp(11), 0, 0, AndroidUtilities.dp(2));
selectedMessagesCountTextView.setGravity(Gravity.CENTER_VERTICAL);
selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
actionMode.addView(selectedMessagesCountTextView);
LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams)selectedMessagesCountTextView.getLayoutParams();
layoutParams1.weight = 1;
layoutParams1.width = 0;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
selectedMessagesCountTextView.setLayoutParams(layoutParams1);
if ((int) dialog_id != 0) {
actionModeViews.add(actionMode.addItem(forward, R.drawable.ic_ab_fwd_forward, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
}
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());
FrameLayout frameLayout;
fragmentView = frameLayout = new FrameLayout(getParentActivity());
listView = new SectionsListView(getParentActivity());
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setDrawSelectorOnTop(true);
listView.setClipToPadding(false);
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.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
if (selectedMode == 1 && view instanceof SharedDocumentCell) {
SharedDocumentCell cell = (SharedDocumentCell) view;
MessageObject message = cell.getDocument();
MediaActivity.this.onItemClick(i, view, message, 0);
}
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
scrolling = scrollState != SCROLL_STATE_IDLE;
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (searching && searchWas) {
selectedMode = 1;
switchToCurrentSelectedMode();
} else if (id == delete) {
if (getParentActivity() == null) {
return;
}
if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2 && !sharedMediaData[selectedMode].loading && !sharedMediaData[selectedMode].endReached) {
sharedMediaData[selectedMode].loading = true;
int type;
if (selectedMode == 0) {
type = SharedMediaQuery.MEDIA_PHOTOVIDEO;
} else if (selectedMode == 1) {
type = SharedMediaQuery.MEDIA_FILE;
} else {
type = SharedMediaQuery.MEDIA_AUDIO;
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.formatString("AreYouSureDeleteMessages", R.string.AreYouSureDeleteMessages, LocaleController.formatPluralString("items", selectedFiles.size())));
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) {
ArrayList<Integer> ids = new ArrayList<>(selectedFiles.keySet());
ArrayList<Long> random_ids = null;
TLRPC.EncryptedChat currentEncryptedChat = null;
if ((int) dialog_id == 0) {
currentEncryptedChat = MessagesController.getInstance().getEncryptedChat((int) (dialog_id >> 32));
}
if (currentEncryptedChat != null) {
random_ids = new ArrayList<>();
for (HashMap.Entry<Integer, MessageObject> entry : selectedFiles.entrySet()) {
MessageObject msg = entry.getValue();
if (msg.messageOwner.random_id != 0 && msg.type != 10) {
random_ids.add(msg.messageOwner.random_id);
}
}
}
MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat);
actionBar.hideActionMode();
selectedFiles.clear();
}
SharedMediaQuery.loadMedia(dialog_id, 0, 50, sharedMediaData[selectedMode].max_id, type, !sharedMediaData[selectedMode].cacheEndReached, classGuid);
}
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int i, long id) {
if (selectedMode == 1 && view instanceof SharedDocumentCell) {
SharedDocumentCell cell = (SharedDocumentCell) view;
MessageObject message = cell.getDocument();
return MediaActivity.this.onItemLongClick(message, view, 0);
}
return false;
}
});
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (id == forward) {
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putBoolean("serverOnly", true);
MessagesActivity fragment = new MessagesActivity(args);
fragment.setDelegate(new MessagesActivity.MessagesActivityDelegate() {
@Override
public void didSelectDialog(MessagesActivity fragment, long did, boolean param) {
int lower_part = (int) did;
if (lower_part != 0) {
Bundle args = new Bundle();
args.putBoolean("scrollToTopOnResume", true);
if (lower_part > 0) {
args.putInt("user_id", lower_part);
} else if (lower_part < 0) {
args.putInt("chat_id", -lower_part);
}
for (int a = 0; a < 6; a++) {
cellCache.add(new SharedPhotoVideoCell(getParentActivity()));
ArrayList<MessageObject> fmessages = new ArrayList<>();
ArrayList<Integer> ids = new ArrayList<>(selectedFiles.keySet());
Collections.sort(ids);
for (Integer id : ids) {
if (id > 0) {
fmessages.add(selectedFiles.get(id));
}
}
selectedFiles.clear();
actionBar.hideActionMode();
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
ChatActivity chatActivity = new ChatActivity(args);
presentFragment(chatActivity, true);
chatActivity.showReplyPanel(true, null, fmessages, null, false, false);
if (!AndroidUtilities.isTablet()) {
removeSelfFromStack();
Activity parentActivity = getParentActivity();
if (parentActivity == null) {
parentActivity = chatActivity.getParentActivity();
}
if (parentActivity != null) {
parentActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}
}
} else {
fragment.finishFragment();
}
}
});
presentFragment(fragment);
}
}
});
selectedFiles.clear();
actionModeViews.clear();
final ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
dropDownContainer.setVisibility(View.GONE);
searching = true;
}
emptyView = new LinearLayout(getParentActivity());
emptyView.setOrientation(LinearLayout.VERTICAL);
emptyView.setGravity(Gravity.CENTER);
emptyView.setVisibility(View.GONE);
emptyView.setBackgroundColor(0xfff0f0f0);
frameLayout.addView(emptyView);
layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
emptyView.setLayoutParams(layoutParams);
emptyView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
@Override
public boolean onSearchCollapse() {
dropDownContainer.setVisibility(View.VISIBLE);
documentsSearchAdapter.searchDocuments(null);
searching = false;
searchWas = false;
switchToCurrentSelectedMode();
emptyImageView = new ImageView(getParentActivity());
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.setTextColor(0xff8a8a8a);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
emptyTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), AndroidUtilities.dp(128));
emptyView.addView(emptyTextView);
layoutParams1 = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
layoutParams1.topMargin = AndroidUtilities.dp(24);
layoutParams1.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams1.gravity = Gravity.CENTER;
emptyTextView.setLayoutParams(layoutParams1);
progressView = new LinearLayout(getParentActivity());
progressView.setGravity(Gravity.CENTER);
progressView.setOrientation(LinearLayout.VERTICAL);
progressView.setVisibility(View.GONE);
progressView.setBackgroundColor(0xfff0f0f0);
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());
progressView.addView(progressBar);
layoutParams1 = (LinearLayout.LayoutParams) progressBar.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams1.height = LinearLayout.LayoutParams.WRAP_CONTENT;
progressBar.setLayoutParams(layoutParams1);
switchToCurrentSelectedMode();
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
return true;
}
@Override
public void onTextChanged(EditText editText) {
if (documentsSearchAdapter == null) {
return;
}
String text = editText.getText().toString();
if (text.length() != 0) {
searchWas = true;
switchToCurrentSelectedMode();
}
documentsSearchAdapter.searchDocuments(text);
}
});
searchItem.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
searchItem.setVisibility(View.GONE);
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);
actionBar.addView(dropDownContainer);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.rightMargin = AndroidUtilities.dp(40);
layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64) : AndroidUtilities.dp(56);
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
dropDownContainer.setLayoutParams(layoutParams);
dropDownContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dropDownContainer.toggleSubMenu();
}
});
dropDown = new TextView(context);
dropDown.setGravity(Gravity.LEFT);
dropDown.setSingleLine(true);
dropDown.setLines(1);
dropDown.setMaxLines(1);
dropDown.setEllipsize(TextUtils.TruncateAt.END);
dropDown.setTextColor(0xffffffff);
dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
dropDownContainer.addView(dropDown);
layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(16);
layoutParams.gravity = Gravity.CENTER_VERTICAL;
dropDown.setLayoutParams(layoutParams);
final ActionBarMenu actionMode = actionBar.createActionMode();
actionModeViews.add(actionMode.addItem(-2, R.drawable.ic_ab_back_grey, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
selectedMessagesCountTextView = new TextView(actionMode.getContext());
selectedMessagesCountTextView.setTextSize(18);
selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
selectedMessagesCountTextView.setTextColor(0xff737373);
selectedMessagesCountTextView.setSingleLine(true);
selectedMessagesCountTextView.setLines(1);
selectedMessagesCountTextView.setEllipsize(TextUtils.TruncateAt.END);
selectedMessagesCountTextView.setPadding(AndroidUtilities.dp(11), 0, 0, AndroidUtilities.dp(2));
selectedMessagesCountTextView.setGravity(Gravity.CENTER_VERTICAL);
selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
actionMode.addView(selectedMessagesCountTextView);
LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) selectedMessagesCountTextView.getLayoutParams();
layoutParams1.weight = 1;
layoutParams1.width = 0;
layoutParams1.height = LinearLayout.LayoutParams.MATCH_PARENT;
selectedMessagesCountTextView.setLayoutParams(layoutParams1);
if ((int) dialog_id != 0) {
actionModeViews.add(actionMode.addItem(forward, R.drawable.ic_ab_fwd_forward, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
}
actionModeViews.add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
photoVideoAdapter = new SharedPhotoVideoAdapter(context);
documentsAdapter = new SharedDocumentsAdapter(context);
documentsSearchAdapter = new DocumentsSearchAdapter(context);
FrameLayout frameLayout;
fragmentView = frameLayout = new FrameLayout(context);
listView = new SectionsListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setDrawSelectorOnTop(true);
listView.setClipToPadding(false);
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.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
if (selectedMode == 1 && view instanceof SharedDocumentCell) {
SharedDocumentCell cell = (SharedDocumentCell) view;
MessageObject message = cell.getDocument();
MediaActivity.this.onItemClick(i, view, message, 0);
}
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
scrolling = scrollState != SCROLL_STATE_IDLE;
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (searching && searchWas) {
return;
}
if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2 && !sharedMediaData[selectedMode].loading && !sharedMediaData[selectedMode].endReached) {
sharedMediaData[selectedMode].loading = true;
int type;
if (selectedMode == 0) {
type = SharedMediaQuery.MEDIA_PHOTOVIDEO;
} else if (selectedMode == 1) {
type = SharedMediaQuery.MEDIA_FILE;
} else {
type = SharedMediaQuery.MEDIA_AUDIO;
}
SharedMediaQuery.loadMedia(dialog_id, 0, 50, sharedMediaData[selectedMode].max_id, type, !sharedMediaData[selectedMode].cacheEndReached, classGuid);
}
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int i, long id) {
if (selectedMode == 1 && view instanceof SharedDocumentCell) {
SharedDocumentCell cell = (SharedDocumentCell) view;
MessageObject message = cell.getDocument();
return MediaActivity.this.onItemLongClick(message, view, 0);
}
return false;
}
});
for (int a = 0; a < 6; a++) {
cellCache.add(new SharedPhotoVideoCell(context));
}
emptyView = new LinearLayout(context);
emptyView.setOrientation(LinearLayout.VERTICAL);
emptyView.setGravity(Gravity.CENTER);
emptyView.setVisibility(View.GONE);
emptyView.setBackgroundColor(0xfff0f0f0);
frameLayout.addView(emptyView);
layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
emptyView.setLayoutParams(layoutParams);
emptyView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
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(context);
emptyTextView.setTextColor(0xff8a8a8a);
emptyTextView.setGravity(Gravity.CENTER);
emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
emptyTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), AndroidUtilities.dp(128));
emptyView.addView(emptyTextView);
layoutParams1 = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
layoutParams1.topMargin = AndroidUtilities.dp(24);
layoutParams1.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams1.gravity = Gravity.CENTER;
emptyTextView.setLayoutParams(layoutParams1);
progressView = new LinearLayout(context);
progressView.setGravity(Gravity.CENTER);
progressView.setOrientation(LinearLayout.VERTICAL);
progressView.setVisibility(View.GONE);
progressView.setBackgroundColor(0xfff0f0f0);
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(context);
progressView.addView(progressBar);
layoutParams1 = (LinearLayout.LayoutParams) progressBar.getLayoutParams();
layoutParams1.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams1.height = LinearLayout.LayoutParams.WRAP_CONTENT;
progressBar.setLayoutParams(layoutParams1);
switchToCurrentSelectedMode();
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,459 +156,456 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
searching = false;
searchWas = false;
public View createView(Context context, LayoutInflater inflater) {
searching = false;
searchWas = false;
ActionBarMenu menu = actionBar.createMenu();
if (!onlySelect && searchString == null) {
passcodeItem = menu.addItem(passcode_menu_item, R.drawable.lock_close);
ActionBarMenu menu = actionBar.createMenu();
if (!onlySelect && searchString == null) {
passcodeItem = menu.addItem(passcode_menu_item, R.drawable.lock_close);
updatePasscodeButton();
}
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
searching = true;
if (messagesListView != null) {
if (searchString != null) {
messagesListView.setEmptyView(progressView);
searchEmptyView.setVisibility(View.INVISIBLE);
} else {
messagesListView.setEmptyView(searchEmptyView);
progressView.setVisibility(View.INVISIBLE);
}
emptyView.setVisibility(View.INVISIBLE);
if (!onlySelect) {
floatingButton.setVisibility(View.GONE);
}
}
updatePasscodeButton();
}
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
searching = true;
if (messagesListView != null) {
if (searchString != null) {
messagesListView.setEmptyView(progressView);
searchEmptyView.setVisibility(View.INVISIBLE);
} else {
messagesListView.setEmptyView(searchEmptyView);
progressView.setVisibility(View.INVISIBLE);
}
emptyView.setVisibility(View.INVISIBLE);
if (!onlySelect) {
floatingButton.setVisibility(View.GONE);
}
}
updatePasscodeButton();
}
@Override
public boolean onSearchCollapse() {
if (searchString != null) {
finishFragment();
return false;
}
searching = false;
searchWas = false;
if (messagesListView != null) {
if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) {
searchEmptyView.setVisibility(View.INVISIBLE);
emptyView.setVisibility(View.INVISIBLE);
progressView.setVisibility(View.VISIBLE);
messagesListView.setEmptyView(progressView);
} else {
messagesListView.setEmptyView(emptyView);
searchEmptyView.setVisibility(View.INVISIBLE);
progressView.setVisibility(View.INVISIBLE);
}
if (!onlySelect) {
floatingButton.setVisibility(View.VISIBLE);
floatingHidden = true;
ViewProxy.setTranslationY(floatingButton, AndroidUtilities.dp(100));
hideFloatingButton(false);
}
if (messagesListView.getAdapter() != dialogsAdapter) {
messagesListView.setAdapter(dialogsAdapter);
dialogsAdapter.notifyDataSetChanged();
}
}
if (dialogsSearchAdapter != null) {
dialogsSearchAdapter.searchDialogs(null, false);
}
updatePasscodeButton();
return true;
}
@Override
public void onTextChanged(EditText editText) {
String text = editText.getText().toString();
if (text.length() != 0) {
searchWas = true;
if (dialogsSearchAdapter != null) {
messagesListView.setAdapter(dialogsSearchAdapter);
dialogsSearchAdapter.notifyDataSetChanged();
}
if (searchEmptyView != null && messagesListView.getEmptyView() == emptyView) {
messagesListView.setEmptyView(searchEmptyView);
emptyView.setVisibility(View.INVISIBLE);
progressView.setVisibility(View.INVISIBLE);
}
}
if (dialogsSearchAdapter != null) {
dialogsSearchAdapter.searchDialogs(text, serverOnly);
}
}
});
item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
if (onlySelect) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle(LocaleController.getString("SelectChat", R.string.SelectChat));
} else {
@Override
public boolean onSearchCollapse() {
if (searchString != null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
} else {
actionBar.setBackButtonDrawable(new MenuDrawable());
finishFragment();
return false;
}
actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
}
actionBar.setAllowOverlayTitle(true);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (onlySelect) {
finishFragment();
} else if (parentLayout != null) {
parentLayout.getDrawerLayoutContainer().openDrawer(false);
}
} else if (id == passcode_menu_item) {
UserConfig.appLocked = !UserConfig.appLocked;
UserConfig.saveConfig(false);
updatePasscodeButton();
}
}
});
fragmentView = inflater.inflate(R.layout.messages_list, null, false);
if (searchString == null) {
dialogsAdapter = new DialogsAdapter(getParentActivity(), serverOnly);
if (AndroidUtilities.isTablet() && openedDialogId != 0) {
dialogsAdapter.setOpenedDialogId(openedDialogId);
}
}
int type = 0;
if (searchString != null) {
type = 2;
} else if (!onlySelect) {
type = 1;
}
dialogsSearchAdapter = new DialogsSearchAdapter(getParentActivity(), type);
dialogsSearchAdapter.setDelegate(new DialogsSearchAdapter.MessagesActivitySearchAdapterDelegate() {
@Override
public void searchStateChanged(boolean search) {
if (searching && searchWas && messagesListView != null) {
progressView.setVisibility(search ? View.VISIBLE : View.INVISIBLE);
searchEmptyView.setVisibility(search ? View.INVISIBLE : View.VISIBLE);
messagesListView.setEmptyView(search ? progressView : searchEmptyView);
}
}
});
messagesListView = (ListView)fragmentView.findViewById(R.id.messages_list_view);
if (dialogsAdapter != null) {
messagesListView.setAdapter(dialogsAdapter);
}
if (Build.VERSION.SDK_INT >= 11) {
messagesListView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
}
progressView = fragmentView.findViewById(R.id.progressLayout);
searchEmptyView = fragmentView.findViewById(R.id.search_empty_view);
searchEmptyView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
emptyView = fragmentView.findViewById(R.id.list_empty_view);
emptyView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
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);
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.setText(LocaleController.getString("NoResult", R.string.NoResult));
floatingButton = (ImageView) fragmentView.findViewById(R.id.floating_button);
floatingButton.setVisibility(onlySelect ? View.GONE : View.VISIBLE);
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));
floatingButton.setStateListAnimator(animator);
floatingButton.setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
}
});
}
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;
floatingButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
args.putBoolean("destroyAfterSelect", true);
presentFragment(new ContactsActivity(args));
}
});
if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) {
searchEmptyView.setVisibility(View.INVISIBLE);
emptyView.setVisibility(View.INVISIBLE);
progressView.setVisibility(View.VISIBLE);
messagesListView.setEmptyView(progressView);
} else {
messagesListView.setEmptyView(emptyView);
searchEmptyView.setVisibility(View.INVISIBLE);
progressView.setVisibility(View.INVISIBLE);
}
messagesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (messagesListView == null || messagesListView.getAdapter() == null) {
return;
}
long dialog_id = 0;
int message_id = 0;
BaseFragmentAdapter adapter = (BaseFragmentAdapter) messagesListView.getAdapter();
if (adapter == dialogsAdapter) {
TLRPC.TL_dialog dialog = dialogsAdapter.getItem(i);
if (dialog == null) {
return;
}
dialog_id = dialog.id;
} else if (adapter == dialogsSearchAdapter) {
Object obj = dialogsSearchAdapter.getItem(i);
if (obj instanceof TLRPC.User) {
dialog_id = ((TLRPC.User) obj).id;
if (dialogsSearchAdapter.isGlobalSearch(i)) {
ArrayList<TLRPC.User> users = new ArrayList<>();
users.add((TLRPC.User)obj);
MessagesController.getInstance().putUsers(users, false);
MessagesStorage.getInstance().putUsersAndChats(users, null, false, true);
}
} else if (obj instanceof TLRPC.Chat) {
if (((TLRPC.Chat) obj).id > 0) {
dialog_id = -((TLRPC.Chat) obj).id;
} else {
dialog_id = AndroidUtilities.makeBroadcastId(((TLRPC.Chat) obj).id);
}
} else if (obj instanceof TLRPC.EncryptedChat) {
dialog_id = ((long)((TLRPC.EncryptedChat) obj).id) << 32;
} else if (obj instanceof MessageObject) {
MessageObject messageObject = (MessageObject)obj;
dialog_id = messageObject.getDialogId();
message_id = messageObject.getId();
dialogsSearchAdapter.addHashtagsFromMessage(dialogsSearchAdapter.getLastSearchString());
} else if (obj instanceof String) {
actionBar.openSearchField((String) obj);
}
}
if (dialog_id == 0) {
return;
}
if (onlySelect) {
didSelectResult(dialog_id, true, false);
searching = false;
searchWas = false;
if (messagesListView != null) {
if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) {
searchEmptyView.setVisibility(View.INVISIBLE);
emptyView.setVisibility(View.INVISIBLE);
progressView.setVisibility(View.VISIBLE);
messagesListView.setEmptyView(progressView);
} else {
Bundle args = new Bundle();
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);
} else {
if (lower_part > 0) {
args.putInt("user_id", lower_part);
} else if (lower_part < 0) {
args.putInt("chat_id", -lower_part);
}
}
} else {
args.putInt("enc_id", high_id);
}
if (message_id != 0) {
args.putInt("message_id", message_id);
} else {
if (actionBar != null) {
actionBar.closeSearchField();
}
}
if (AndroidUtilities.isTablet()) {
if (openedDialogId == dialog_id) {
return;
}
if (dialogsAdapter != null) {
dialogsAdapter.setOpenedDialogId(openedDialogId = dialog_id);
updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG);
}
}
if (searchString != null) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
presentFragment(new ChatActivity(args));
} else {
presentFragment(new ChatActivity(args));
}
messagesListView.setEmptyView(emptyView);
searchEmptyView.setVisibility(View.INVISIBLE);
progressView.setVisibility(View.INVISIBLE);
}
if (!onlySelect) {
floatingButton.setVisibility(View.VISIBLE);
floatingHidden = true;
ViewProxy.setTranslationY(floatingButton, AndroidUtilities.dp(100));
hideFloatingButton(false);
}
if (messagesListView.getAdapter() != dialogsAdapter) {
messagesListView.setAdapter(dialogsAdapter);
dialogsAdapter.notifyDataSetChanged();
}
}
});
messagesListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
if (onlySelect || searching && searchWas || getParentActivity() == null) {
if (searchWas && searching) {
BaseFragmentAdapter adapter = (BaseFragmentAdapter) messagesListView.getAdapter();
if (adapter == dialogsSearchAdapter) {
Object item = adapter.getItem(i);
if (item instanceof String) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch));
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogsSearchAdapter.clearRecentHashtags();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
return true;
}
}
}
return false;
}
TLRPC.TL_dialog dialog;
if (serverOnly) {
if (i >= MessagesController.getInstance().dialogsServerOnly.size()) {
return false;
}
dialog = MessagesController.getInstance().dialogsServerOnly.get(i);
} else {
if (i >= MessagesController.getInstance().dialogs.size()) {
return false;
}
dialog = MessagesController.getInstance().dialogs.get(i);
}
selectedDialog = dialog.id;
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);
final boolean isChat = lower_id < 0 && high_id != 1;
builder.setItems(new CharSequence[]{LocaleController.getString("ClearHistory", R.string.ClearHistory),
isChat ? LocaleController.getString("DeleteChat", R.string.DeleteChat) : LocaleController.getString("Delete", R.string.Delete)}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, final int which) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
if (which == 0) {
builder.setMessage(LocaleController.getString("AreYouSureClearHistory", R.string.AreYouSureClearHistory));
} else {
if (isChat) {
builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
} else {
builder.setMessage(LocaleController.getString("AreYouSureDeleteThisChat", R.string.AreYouSureDeleteThisChat));
}
}
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);
}
if (AndroidUtilities.isTablet()) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats, selectedDialog);
}
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
return true;
if (dialogsSearchAdapter != null) {
dialogsSearchAdapter.searchDialogs(null, false);
}
});
messagesListView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (searching && searchWas) {
if (visibleItemCount > 0 && absListView.getLastVisiblePosition() == totalItemCount - 1 && !dialogsSearchAdapter.isMessagesSearchEndReached()) {
dialogsSearchAdapter.loadMoreSearchMessages();
}
return;
}
if (visibleItemCount > 0) {
if (absListView.getLastVisiblePosition() == MessagesController.getInstance().dialogs.size() && !serverOnly || absListView.getLastVisiblePosition() == MessagesController.getInstance().dialogsServerOnly.size() && serverOnly) {
MessagesController.getInstance().loadDialogs(MessagesController.getInstance().dialogs.size(), MessagesController.getInstance().dialogsServerOnly.size(), 100, true);
}
}
if (floatingButton.getVisibility() != View.GONE) {
final View topChild = absListView.getChildAt(0);
int firstViewTop = 0;
if (topChild != null) {
firstViewTop = topChild.getTop();
}
boolean goingDown;
boolean changed = true;
if (prevPosition == firstVisibleItem) {
final int topDelta = prevTop - firstViewTop;
goingDown = firstViewTop < prevTop;
changed = Math.abs(topDelta) > 1;
} else {
goingDown = firstVisibleItem > prevPosition;
}
if (changed && scrollUpdated) {
hideFloatingButton(goingDown);
}
prevPosition = firstVisibleItem;
prevTop = firstViewTop;
scrollUpdated = true;
}
}
});
if (searchString != null) {
actionBar.openSearchField(searchString);
updatePasscodeButton();
return true;
}
@Override
public void onTextChanged(EditText editText) {
String text = editText.getText().toString();
if (text.length() != 0) {
searchWas = true;
if (dialogsSearchAdapter != null) {
messagesListView.setAdapter(dialogsSearchAdapter);
dialogsSearchAdapter.notifyDataSetChanged();
}
if (searchEmptyView != null && messagesListView.getEmptyView() == emptyView) {
messagesListView.setEmptyView(searchEmptyView);
emptyView.setVisibility(View.INVISIBLE);
progressView.setVisibility(View.INVISIBLE);
}
}
if (dialogsSearchAdapter != null) {
dialogsSearchAdapter.searchDialogs(text, serverOnly);
}
}
});
item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
if (onlySelect) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle(LocaleController.getString("SelectChat", R.string.SelectChat));
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
if (searchString != null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
} else {
actionBar.setBackButtonDrawable(new MenuDrawable());
}
actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
}
actionBar.setAllowOverlayTitle(true);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (onlySelect) {
finishFragment();
} else if (parentLayout != null) {
parentLayout.getDrawerLayoutContainer().openDrawer(false);
}
} else if (id == passcode_menu_item) {
UserConfig.appLocked = !UserConfig.appLocked;
UserConfig.saveConfig(false);
updatePasscodeButton();
}
}
});
fragmentView = inflater.inflate(R.layout.messages_list, null, false);
if (searchString == null) {
dialogsAdapter = new DialogsAdapter(context, serverOnly);
if (AndroidUtilities.isTablet() && openedDialogId != 0) {
dialogsAdapter.setOpenedDialogId(openedDialogId);
}
}
int type = 0;
if (searchString != null) {
type = 2;
} else if (!onlySelect) {
type = 1;
}
dialogsSearchAdapter = new DialogsSearchAdapter(context, type);
dialogsSearchAdapter.setDelegate(new DialogsSearchAdapter.MessagesActivitySearchAdapterDelegate() {
@Override
public void searchStateChanged(boolean search) {
if (searching && searchWas && messagesListView != null) {
progressView.setVisibility(search ? View.VISIBLE : View.INVISIBLE);
searchEmptyView.setVisibility(search ? View.INVISIBLE : View.VISIBLE);
messagesListView.setEmptyView(search ? progressView : searchEmptyView);
}
}
});
messagesListView = (ListView) fragmentView.findViewById(R.id.messages_list_view);
if (dialogsAdapter != null) {
messagesListView.setAdapter(dialogsAdapter);
}
if (Build.VERSION.SDK_INT >= 11) {
messagesListView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
}
progressView = fragmentView.findViewById(R.id.progressLayout);
searchEmptyView = fragmentView.findViewById(R.id.search_empty_view);
searchEmptyView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
emptyView = fragmentView.findViewById(R.id.list_empty_view);
emptyView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
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);
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.setText(LocaleController.getString("NoResult", R.string.NoResult));
floatingButton = (ImageView) fragmentView.findViewById(R.id.floating_button);
floatingButton.setVisibility(onlySelect ? View.GONE : View.VISIBLE);
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));
floatingButton.setStateListAnimator(animator);
floatingButton.setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
}
});
}
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;
floatingButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
args.putBoolean("destroyAfterSelect", true);
presentFragment(new ContactsActivity(args));
}
});
if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) {
searchEmptyView.setVisibility(View.INVISIBLE);
emptyView.setVisibility(View.INVISIBLE);
progressView.setVisibility(View.VISIBLE);
messagesListView.setEmptyView(progressView);
} else {
messagesListView.setEmptyView(emptyView);
searchEmptyView.setVisibility(View.INVISIBLE);
progressView.setVisibility(View.INVISIBLE);
}
messagesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (messagesListView == null || messagesListView.getAdapter() == null) {
return;
}
long dialog_id = 0;
int message_id = 0;
BaseFragmentAdapter adapter = (BaseFragmentAdapter) messagesListView.getAdapter();
if (adapter == dialogsAdapter) {
TLRPC.TL_dialog dialog = dialogsAdapter.getItem(i);
if (dialog == null) {
return;
}
dialog_id = dialog.id;
} else if (adapter == dialogsSearchAdapter) {
Object obj = dialogsSearchAdapter.getItem(i);
if (obj instanceof TLRPC.User) {
dialog_id = ((TLRPC.User) obj).id;
if (dialogsSearchAdapter.isGlobalSearch(i)) {
ArrayList<TLRPC.User> users = new ArrayList<>();
users.add((TLRPC.User) obj);
MessagesController.getInstance().putUsers(users, false);
MessagesStorage.getInstance().putUsersAndChats(users, null, false, true);
}
} else if (obj instanceof TLRPC.Chat) {
if (((TLRPC.Chat) obj).id > 0) {
dialog_id = -((TLRPC.Chat) obj).id;
} else {
dialog_id = AndroidUtilities.makeBroadcastId(((TLRPC.Chat) obj).id);
}
} else if (obj instanceof TLRPC.EncryptedChat) {
dialog_id = ((long) ((TLRPC.EncryptedChat) obj).id) << 32;
} else if (obj instanceof MessageObject) {
MessageObject messageObject = (MessageObject) obj;
dialog_id = messageObject.getDialogId();
message_id = messageObject.getId();
dialogsSearchAdapter.addHashtagsFromMessage(dialogsSearchAdapter.getLastSearchString());
} else if (obj instanceof String) {
actionBar.openSearchField((String) obj);
}
}
if (dialog_id == 0) {
return;
}
if (onlySelect) {
didSelectResult(dialog_id, true, false);
} else {
Bundle args = new Bundle();
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);
} else {
if (lower_part > 0) {
args.putInt("user_id", lower_part);
} else if (lower_part < 0) {
args.putInt("chat_id", -lower_part);
}
}
} else {
args.putInt("enc_id", high_id);
}
if (message_id != 0) {
args.putInt("message_id", message_id);
} else {
if (actionBar != null) {
actionBar.closeSearchField();
}
}
if (AndroidUtilities.isTablet()) {
if (openedDialogId == dialog_id) {
return;
}
if (dialogsAdapter != null) {
dialogsAdapter.setOpenedDialogId(openedDialogId = dialog_id);
updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG);
}
}
if (searchString != null) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
presentFragment(new ChatActivity(args));
} else {
presentFragment(new ChatActivity(args));
}
}
}
});
messagesListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
if (onlySelect || searching && searchWas || getParentActivity() == null) {
if (searchWas && searching) {
BaseFragmentAdapter adapter = (BaseFragmentAdapter) messagesListView.getAdapter();
if (adapter == dialogsSearchAdapter) {
Object item = adapter.getItem(i);
if (item instanceof String) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch));
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogsSearchAdapter.clearRecentHashtags();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
return true;
}
}
}
return false;
}
TLRPC.TL_dialog dialog;
if (serverOnly) {
if (i >= MessagesController.getInstance().dialogsServerOnly.size()) {
return false;
}
dialog = MessagesController.getInstance().dialogsServerOnly.get(i);
} else {
if (i >= MessagesController.getInstance().dialogs.size()) {
return false;
}
dialog = MessagesController.getInstance().dialogs.get(i);
}
selectedDialog = dialog.id;
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);
final boolean isChat = lower_id < 0 && high_id != 1;
builder.setItems(new CharSequence[]{LocaleController.getString("ClearHistory", R.string.ClearHistory),
isChat ? LocaleController.getString("DeleteChat", R.string.DeleteChat) : LocaleController.getString("Delete", R.string.Delete)}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, final int which) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
if (which == 0) {
builder.setMessage(LocaleController.getString("AreYouSureClearHistory", R.string.AreYouSureClearHistory));
} else {
if (isChat) {
builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
} else {
builder.setMessage(LocaleController.getString("AreYouSureDeleteThisChat", R.string.AreYouSureDeleteThisChat));
}
}
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
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);
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
return true;
}
});
messagesListView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (searching && searchWas) {
if (visibleItemCount > 0 && absListView.getLastVisiblePosition() == totalItemCount - 1 && !dialogsSearchAdapter.isMessagesSearchEndReached()) {
dialogsSearchAdapter.loadMoreSearchMessages();
}
return;
}
if (visibleItemCount > 0) {
if (absListView.getLastVisiblePosition() == MessagesController.getInstance().dialogs.size() && !serverOnly || absListView.getLastVisiblePosition() == MessagesController.getInstance().dialogsServerOnly.size() && serverOnly) {
MessagesController.getInstance().loadDialogs(MessagesController.getInstance().dialogs.size(), MessagesController.getInstance().dialogsServerOnly.size(), 100, true);
}
}
if (floatingButton.getVisibility() != View.GONE) {
final View topChild = absListView.getChildAt(0);
int firstViewTop = 0;
if (topChild != null) {
firstViewTop = topChild.getTop();
}
boolean goingDown;
boolean changed = true;
if (prevPosition == firstVisibleItem) {
final int topDelta = prevTop - firstViewTop;
goingDown = firstViewTop < prevTop;
changed = Math.abs(topDelta) > 1;
} else {
goingDown = firstVisibleItem > prevPosition;
}
if (changed && scrollUpdated) {
hideFloatingButton(goingDown);
}
prevPosition = firstVisibleItem;
prevTop = firstViewTop;
scrollUpdated = true;
}
}
});
if (searchString != null) {
actionBar.openSearchField(searchString);
}
return fragmentView;
}

View file

@ -156,391 +156,385 @@ public class NotificationsSettingsActivity extends BaseFragment implements Notif
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
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));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
});
}
});
fragmentView = new FrameLayout(getParentActivity());
FrameLayout frameLayout = (FrameLayout) fragmentView;
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
listView = new ListView(getParentActivity());
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
frameLayout.addView(listView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setAdapter(new ListAdapter(getParentActivity()));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
boolean enabled = false;
if (i == messageAlertRow || i == groupAlertRow) {
listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
frameLayout.addView(listView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setAdapter(new ListAdapter(context));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
boolean enabled = false;
if (i == messageAlertRow || i == groupAlertRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (i == messageAlertRow) {
enabled = preferences.getBoolean("EnableAll", true);
editor.putBoolean("EnableAll", !enabled);
} else if (i == groupAlertRow) {
enabled = preferences.getBoolean("EnableGroup", true);
editor.putBoolean("EnableGroup", !enabled);
}
editor.commit();
updateServerNotificationsSettings(i == groupAlertRow);
} else if (i == messagePreviewRow || i == groupPreviewRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (i == messagePreviewRow) {
enabled = preferences.getBoolean("EnablePreviewAll", true);
editor.putBoolean("EnablePreviewAll", !enabled);
} else if (i == groupPreviewRow) {
enabled = preferences.getBoolean("EnablePreviewGroup", true);
editor.putBoolean("EnablePreviewGroup", !enabled);
}
editor.commit();
updateServerNotificationsSettings(i == groupPreviewRow);
} else if (i == messageSoundRow || i == groupSoundRow) {
try {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (i == messageAlertRow) {
enabled = preferences.getBoolean("EnableAll", true);
editor.putBoolean("EnableAll", !enabled);
} else if (i == groupAlertRow) {
enabled = preferences.getBoolean("EnableGroup", true);
editor.putBoolean("EnableGroup", !enabled);
}
editor.commit();
updateServerNotificationsSettings(i == groupAlertRow);
} else if (i == messagePreviewRow || i == groupPreviewRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (i == messagePreviewRow) {
enabled = preferences.getBoolean("EnablePreviewAll", true);
editor.putBoolean("EnablePreviewAll", !enabled);
} else if (i == groupPreviewRow) {
enabled = preferences.getBoolean("EnablePreviewGroup", true);
editor.putBoolean("EnablePreviewGroup", !enabled);
}
editor.commit();
updateServerNotificationsSettings(i == groupPreviewRow);
} else if (i == messageSoundRow || i == groupSoundRow) {
try {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
Uri currentSound = null;
Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
Uri currentSound = null;
String defaultPath = null;
Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
if (defaultUri != null) {
defaultPath = defaultUri.getPath();
}
String defaultPath = null;
Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
if (defaultUri != null) {
defaultPath = defaultUri.getPath();
}
if (i == messageSoundRow) {
String path = preferences.getString("GlobalSoundPath", defaultPath);
if (path != null && !path.equals("NoSound")) {
if (path.equals(defaultPath)) {
currentSound = defaultUri;
} else {
currentSound = Uri.parse(path);
}
}
} else if (i == groupSoundRow) {
String path = preferences.getString("GroupSoundPath", defaultPath);
if (path != null && !path.equals("NoSound")) {
if (path.equals(defaultPath)) {
currentSound = defaultUri;
} else {
currentSound = Uri.parse(path);
}
if (i == messageSoundRow) {
String path = preferences.getString("GlobalSoundPath", defaultPath);
if (path != null && !path.equals("NoSound")) {
if (path.equals(defaultPath)) {
currentSound = defaultUri;
} else {
currentSound = Uri.parse(path);
}
}
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
startActivityForResult(tmpIntent, i);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else if (i == resetNotificationsRow) {
if (reseting) {
return;
}
reseting = true;
TLRPC.TL_account_resetNotifySettings req = new TLRPC.TL_account_resetNotifySettings();
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
MessagesController.getInstance().enableJoined = true;
reseting = false;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.clear();
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
if (getParentActivity() != null) {
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("ResetNotificationsText", R.string.ResetNotificationsText), Toast.LENGTH_SHORT);
toast.show();
}
}
});
} else if (i == groupSoundRow) {
String path = preferences.getString("GroupSoundPath", defaultPath);
if (path != null && !path.equals("NoSound")) {
if (path.equals(defaultPath)) {
currentSound = defaultUri;
} else {
currentSound = Uri.parse(path);
}
}
});
} else if (i == inappSoundRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnableInAppSounds", true);
editor.putBoolean("EnableInAppSounds", !enabled);
editor.commit();
} else if (i == inappVibrateRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnableInAppVibrate", true);
editor.putBoolean("EnableInAppVibrate", !enabled);
editor.commit();
} else if (i == inappPreviewRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnableInAppPreview", true);
editor.putBoolean("EnableInAppPreview", !enabled);
editor.commit();
} else if (i == inchatSoundRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnableInChatSound", true);
editor.putBoolean("EnableInChatSound", !enabled);
editor.commit();
NotificationsController.getInstance().setInChatSoundEnabled(!enabled);
} else if (i == inappPriorityRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnableInAppPriority", false);
editor.putBoolean("EnableInAppPriority", !enabled);
editor.commit();
} else if (i == contactJoinedRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnableContactJoined", true);
MessagesController.getInstance().enableJoined = !enabled;
editor.putBoolean("EnableContactJoined", !enabled);
editor.commit();
} else if (i == pebbleAlertRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnablePebbleNotifications", false);
editor.putBoolean("EnablePebbleNotifications", !enabled);
editor.commit();
} else if (i == badgeNumberRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("badgeNumber", true);
editor.putBoolean("badgeNumber", !enabled);
editor.commit();
NotificationsController.getInstance().setBadgeEnabled(!enabled);
} else if (i == notificationsServiceRow) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
enabled = preferences.getBoolean("pushService", true);
if (!enabled) {
final SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("pushService", !enabled);
editor.commit();
ApplicationLoader.startPushService();
} else {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("NotificationsServiceDisableInfo", R.string.NotificationsServiceDisableInfo));
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
}
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
startActivityForResult(tmpIntent, i);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else if (i == resetNotificationsRow) {
if (reseting) {
return;
}
reseting = true;
TLRPC.TL_account_resetNotifySettings req = new TLRPC.TL_account_resetNotifySettings();
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ApplicationLoader.stopPushService();
final SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("pushService", false);
public void run() {
MessagesController.getInstance().enableJoined = true;
reseting = false;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.clear();
editor.commit();
listView.invalidateViews();
if (listView != null) {
listView.invalidateViews();
}
if (getParentActivity() != null) {
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("ResetNotificationsText", R.string.ResetNotificationsText), Toast.LENGTH_SHORT);
toast.show();
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
} else if (i == messageLedRow || i == groupLedRow) {
});
} else if (i == inappSoundRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnableInAppSounds", true);
editor.putBoolean("EnableInAppSounds", !enabled);
editor.commit();
} else if (i == inappVibrateRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnableInAppVibrate", true);
editor.putBoolean("EnableInAppVibrate", !enabled);
editor.commit();
} else if (i == inappPreviewRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnableInAppPreview", true);
editor.putBoolean("EnableInAppPreview", !enabled);
editor.commit();
} else if (i == inchatSoundRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnableInChatSound", true);
editor.putBoolean("EnableInChatSound", !enabled);
editor.commit();
NotificationsController.getInstance().setInChatSoundEnabled(!enabled);
} else if (i == inappPriorityRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnableInAppPriority", false);
editor.putBoolean("EnableInAppPriority", !enabled);
editor.commit();
} else if (i == contactJoinedRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnableContactJoined", true);
MessagesController.getInstance().enableJoined = !enabled;
editor.putBoolean("EnableContactJoined", !enabled);
editor.commit();
} else if (i == pebbleAlertRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("EnablePebbleNotifications", false);
editor.putBoolean("EnablePebbleNotifications", !enabled);
editor.commit();
} else if (i == badgeNumberRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
enabled = preferences.getBoolean("badgeNumber", true);
editor.putBoolean("badgeNumber", !enabled);
editor.commit();
NotificationsController.getInstance().setBadgeEnabled(!enabled);
} else if (i == notificationsServiceRow) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
enabled = preferences.getBoolean("pushService", true);
if (!enabled) {
final SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("pushService", !enabled);
editor.commit();
ApplicationLoader.startPushService();
} else {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("NotificationsServiceDisableInfo", R.string.NotificationsServiceDisableInfo));
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) {
ApplicationLoader.stopPushService();
final SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("pushService", false);
editor.commit();
listView.invalidateViews();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
} else if (i == messageLedRow || i == groupLedRow) {
if (getParentActivity() == null) {
return;
}
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);
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);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (i == messageLedRow) {
colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00));
} else if (i == groupLedRow) {
colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (i == messageLedRow) {
colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00));
} else if (i == groupLedRow) {
colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
builder.setView(view);
builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (i == messageLedRow) {
editor.putInt("MessagesLed", colorPickerView.getColor());
} else if (i == groupLedRow) {
editor.putInt("GroupLed", colorPickerView.getColor());
}
editor.commit();
listView.invalidateViews();
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
builder.setView(view);
builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (i == messageLedRow) {
editor.putInt("MessagesLed", colorPickerView.getColor());
} else if (i == groupLedRow) {
editor.putInt("GroupLed", colorPickerView.getColor());
}
editor.commit();
});
builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (i == messageLedRow) {
editor.putInt("MessagesLed", 0);
} else if (i == groupLedRow) {
editor.putInt("GroupLed", 0);
}
editor.commit();
listView.invalidateViews();
}
});
showAlertDialog(builder);
} 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[]{
LocaleController.getString("NoPopup", R.string.NoPopup),
LocaleController.getString("OnlyWhenScreenOn", R.string.OnlyWhenScreenOn),
LocaleController.getString("OnlyWhenScreenOff", R.string.OnlyWhenScreenOff),
LocaleController.getString("AlwaysShowPopup", R.string.AlwaysShowPopup)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (i == messagePopupNotificationRow) {
editor.putInt("popupAll", which);
} else if (i == groupPopupNotificationRow) {
editor.putInt("popupGroup", which);
}
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
});
builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (i == messageLedRow) {
editor.putInt("MessagesLed", 0);
} else if (i == groupLedRow) {
editor.putInt("GroupLed", 0);
}
editor.commit();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} 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[]{
LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled),
LocaleController.getString("Default", R.string.Default),
LocaleController.getString("Short", R.string.Short),
LocaleController.getString("Long", R.string.Long),
LocaleController.getString("OnlyIfSilent", R.string.OnlyIfSilent)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
String param = "vibrate_messages";
if (i == groupVibrateRow) {
param = "vibrate_group";
}
if (which == 0) {
editor.putInt(param, 2);
} else if (which == 1) {
editor.putInt(param, 0);
} else if (which == 2) {
editor.putInt(param, 1);
} else if (which == 3) {
editor.putInt(param, 3);
} else if (which == 4) {
editor.putInt(param, 4);
}
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
});
showAlertDialog(builder);
} 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[] {
LocaleController.getString("NoPopup", R.string.NoPopup),
LocaleController.getString("OnlyWhenScreenOn", R.string.OnlyWhenScreenOn),
LocaleController.getString("OnlyWhenScreenOff", R.string.OnlyWhenScreenOff),
LocaleController.getString("AlwaysShowPopup", R.string.AlwaysShowPopup)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (i == messagePopupNotificationRow) {
editor.putInt("popupAll", which);
} else if (i == groupPopupNotificationRow) {
editor.putInt("popupGroup", which);
}
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} 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[]{
LocaleController.getString("NotificationsPriorityDefault", R.string.NotificationsPriorityDefault),
LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh),
LocaleController.getString("NotificationsPriorityMax", R.string.NotificationsPriorityMax)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (i == messagePriorityRow) {
preferences.edit().putInt("priority_messages", which).commit();
} else if (i == groupPriorityRow) {
preferences.edit().putInt("priority_group", which).commit();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} 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[] {
LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled),
LocaleController.getString("Default", R.string.Default),
LocaleController.getString("Short", R.string.Short),
LocaleController.getString("Long", R.string.Long),
LocaleController.getString("OnlyIfSilent", R.string.OnlyIfSilent)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
String param = "vibrate_messages";
if (i == groupVibrateRow) {
param = "vibrate_group";
}
if (which == 0) {
editor.putInt(param, 2);
} else if (which == 1) {
editor.putInt(param, 0);
} else if (which == 2) {
editor.putInt(param, 1);
} else if (which == 3) {
editor.putInt(param, 3);
} else if (which == 4) {
editor.putInt(param, 4);
}
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
if (listView != null) {
listView.invalidateViews();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} 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[] {
LocaleController.getString("NotificationsPriorityDefault", R.string.NotificationsPriorityDefault),
LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh),
LocaleController.getString("NotificationsPriorityMax", R.string.NotificationsPriorityMax)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (i == messagePriorityRow) {
preferences.edit().putInt("priority_messages", which).commit();
} else if (i == groupPriorityRow) {
preferences.edit().putInt("priority_group", which).commit();
}
if (listView != null) {
listView.invalidateViews();
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == repeatRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("RepeatNotifications", R.string.RepeatNotifications));
builder.setItems(new CharSequence[]{
LocaleController.getString("RepeatDisabled", R.string.RepeatDisabled),
LocaleController.formatPluralString("Minutes", 5),
LocaleController.formatPluralString("Minutes", 10),
LocaleController.formatPluralString("Minutes", 30),
LocaleController.formatPluralString("Hours", 1),
LocaleController.formatPluralString("Hours", 2),
LocaleController.formatPluralString("Hours", 4)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int minutes = 0;
if (which == 1) {
minutes = 5;
} else if (which == 2) {
minutes = 10;
} else if (which == 3) {
minutes = 30;
} else if (which == 4) {
minutes = 60;
} else if (which == 5) {
minutes = 60 * 2;
} else if (which == 6) {
minutes = 60 * 4;
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == repeatRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("RepeatNotifications", R.string.RepeatNotifications));
builder.setItems(new CharSequence[] {
LocaleController.getString("RepeatDisabled", R.string.RepeatDisabled),
LocaleController.formatPluralString("Minutes", 5),
LocaleController.formatPluralString("Minutes", 10),
LocaleController.formatPluralString("Minutes", 30),
LocaleController.formatPluralString("Hours", 1),
LocaleController.formatPluralString("Hours", 2),
LocaleController.formatPluralString("Hours", 4)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int minutes = 0;
if (which == 1) {
minutes = 5;
} else if (which == 2) {
minutes = 10;
} else if (which == 3) {
minutes = 30;
} else if (which == 4) {
minutes = 60;
} else if (which == 5) {
minutes = 60 * 2;
} else if (which == 6) {
minutes = 60 * 4;
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
preferences.edit().putInt("repeat_messages", minutes).commit();
if (listView != null) {
listView.invalidateViews();
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
preferences.edit().putInt("repeat_messages", minutes).commit();
if (listView != null) {
listView.invalidateViews();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(!enabled);
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(!enabled);
}
});
} 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,297 +108,295 @@ public class PasscodeActivity extends BaseFragment implements NotificationCenter
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
if (type != 3) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
public View createView(Context context, LayoutInflater inflater) {
if (type != 3) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
}
actionBar.setAllowOverlayTitle(false);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (passwordEditText.getImeOptions() == EditorInfo.IME_ACTION_NEXT) {
processNext();
} else if (passwordEditText.getImeOptions() == EditorInfo.IME_ACTION_DONE) {
processDone();
}
} else if (id == pin_item) {
currentPasswordType = 0;
updateDropDownTextView();
} else if (id == password_item) {
currentPasswordType = 1;
updateDropDownTextView();
}
}
actionBar.setAllowOverlayTitle(false);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
});
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(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));
}
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
frameLayout.addView(titleTextView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
layoutParams.topMargin = AndroidUtilities.dp(38);
titleTextView.setLayoutParams(layoutParams);
passwordEditText = new EditText(context);
passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
passwordEditText.setTextColor(0xff000000);
passwordEditText.setMaxLines(1);
passwordEditText.setLines(1);
passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
passwordEditText.setSingleLine(true);
if (type == 1) {
passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
} else {
passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
}
passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
passwordEditText.setTypeface(Typeface.DEFAULT);
AndroidUtilities.clearCursorDrawable(passwordEditText);
frameLayout.addView(passwordEditText);
layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(90);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(40);
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
layoutParams.rightMargin = AndroidUtilities.dp(40);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
passwordEditText.setLayoutParams(layoutParams);
passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (passwordEditText.getImeOptions() == EditorInfo.IME_ACTION_NEXT) {
processNext();
} else if (passwordEditText.getImeOptions() == EditorInfo.IME_ACTION_DONE) {
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_NEXT) {
processNext();
return true;
} else if (i == EditorInfo.IME_ACTION_DONE) {
processDone();
return true;
}
return false;
}
});
passwordEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (passwordEditText.length() == 4) {
if (type == 2 && UserConfig.passcodeType == 0) {
processDone();
} else if (type == 1 && currentPasswordType == 0) {
if (passwordEditText.getImeOptions() == EditorInfo.IME_ACTION_NEXT) {
processNext();
} else if (passwordEditText.getImeOptions() == EditorInfo.IME_ACTION_DONE) {
processDone();
}
}
} else if (id == pin_item) {
currentPasswordType = 0;
updateDropDownTextView();
} else if (id == password_item) {
currentPasswordType = 1;
updateDropDownTextView();
}
}
});
if (android.os.Build.VERSION.SDK_INT < 11) {
passwordEditText.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
menu.clear();
}
});
} else {
passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
fragmentView = new FrameLayout(getParentActivity());
FrameLayout frameLayout = (FrameLayout) fragmentView;
public void onDestroyActionMode(ActionMode mode) {
}
if (type != 0) {
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}
titleTextView = new TextView(getParentActivity());
titleTextView.setTextColor(0xff757575);
if (type == 1) {
titleTextView.setText(LocaleController.getString("EnterNewPasscode", R.string.EnterNewPasscode));
} else {
titleTextView.setText(LocaleController.getString("EnterCurrentPasscode", R.string.EnterCurrentPasscode));
}
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
frameLayout.addView(titleTextView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
layoutParams.topMargin = AndroidUtilities.dp(38);
titleTextView.setLayoutParams(layoutParams);
passwordEditText = new EditText(getParentActivity());
passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
passwordEditText.setTextColor(0xff000000);
passwordEditText.setMaxLines(1);
passwordEditText.setLines(1);
passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
passwordEditText.setSingleLine(true);
if (type == 1) {
passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
} else {
passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
}
passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
passwordEditText.setTypeface(Typeface.DEFAULT);
AndroidUtilities.clearCursorDrawable(passwordEditText);
frameLayout.addView(passwordEditText);
layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(90);
layoutParams.height = AndroidUtilities.dp(36);
layoutParams.leftMargin = AndroidUtilities.dp(40);
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
layoutParams.rightMargin = AndroidUtilities.dp(40);
layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
passwordEditText.setLayoutParams(layoutParams);
passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_NEXT) {
processNext();
return true;
} else if (i == EditorInfo.IME_ACTION_DONE) {
processDone();
return true;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
});
passwordEditText.addTextChangedListener(new TextWatcher() {
}
if (type == 1) {
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);
actionBar.addView(dropDownContainer);
layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.rightMargin = AndroidUtilities.dp(40);
layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64) : AndroidUtilities.dp(56);
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
dropDownContainer.setLayoutParams(layoutParams);
dropDownContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (passwordEditText.length() == 4) {
if (type == 2 && UserConfig.passcodeType == 0) {
processDone();
} else if (type == 1 && currentPasswordType == 0) {
if (passwordEditText.getImeOptions() == EditorInfo.IME_ACTION_NEXT) {
processNext();
} else if (passwordEditText.getImeOptions() == EditorInfo.IME_ACTION_DONE) {
processDone();
}
}
}
public void onClick(View view) {
dropDownContainer.toggleSubMenu();
}
});
if (android.os.Build.VERSION.SDK_INT < 11) {
passwordEditText.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
menu.clear();
}
});
} else {
passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
public void onDestroyActionMode(ActionMode mode) {
}
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
});
}
if (type == 1) {
dropDownContainer = new ActionBarMenuItem(getParentActivity(), 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);
actionBar.addView(dropDownContainer);
layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.rightMargin = AndroidUtilities.dp(40);
layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64) : AndroidUtilities.dp(56);
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
dropDownContainer.setLayoutParams(layoutParams);
dropDownContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dropDownContainer.toggleSubMenu();
}
});
dropDown = new TextView(getParentActivity());
dropDown.setGravity(Gravity.LEFT);
dropDown.setSingleLine(true);
dropDown.setLines(1);
dropDown.setMaxLines(1);
dropDown.setEllipsize(TextUtils.TruncateAt.END);
dropDown.setTextColor(0xffffffff);
dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
dropDownContainer.addView(dropDown);
layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(16);
layoutParams.gravity = Gravity.CENTER_VERTICAL;
layoutParams.bottomMargin = AndroidUtilities.dp(1);
dropDown.setLayoutParams(layoutParams);
} else {
actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
}
updateDropDownTextView();
dropDown = new TextView(context);
dropDown.setGravity(Gravity.LEFT);
dropDown.setSingleLine(true);
dropDown.setLines(1);
dropDown.setMaxLines(1);
dropDown.setEllipsize(TextUtils.TruncateAt.END);
dropDown.setTextColor(0xffffffff);
dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
dropDownContainer.addView(dropDown);
layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(16);
layoutParams.gravity = Gravity.CENTER_VERTICAL;
layoutParams.bottomMargin = AndroidUtilities.dp(1);
dropDown.setLayoutParams(layoutParams);
} else {
actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
frameLayout.setBackgroundColor(0xfff0f0f0);
listView = new ListView(getParentActivity());
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
listView.setDrawSelectorOnTop(true);
frameLayout.addView(listView);
FrameLayout.LayoutParams 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 = new ListAdapter(getParentActivity()));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
if (i == changePasscodeRow) {
presentFragment(new PasscodeActivity(1));
} else if (i == passcodeRow) {
TextCheckCell cell = (TextCheckCell) view;
if (UserConfig.passcodeHash.length() != 0) {
UserConfig.passcodeHash = "";
UserConfig.appLocked = false;
UserConfig.saveConfig(false);
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View child = listView.getChildAt(a);
if (child instanceof TextSettingsCell) {
TextSettingsCell textCell = (TextSettingsCell) child;
textCell.setTextColor(0xffc6c6c6);
break;
}
}
cell.setChecked(UserConfig.passcodeHash.length() != 0);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didSetPasscode);
} else {
presentFragment(new PasscodeActivity(1));
}
} else if (i == autoLockRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AutoLock", R.string.AutoLock));
final NumberPicker numberPicker = new NumberPicker(getParentActivity());
numberPicker.setMinValue(0);
numberPicker.setMaxValue(4);
if (UserConfig.autoLockIn == 0) {
numberPicker.setValue(0);
} else if (UserConfig.autoLockIn == 60) {
numberPicker.setValue(1);
} else if (UserConfig.autoLockIn == 60 * 5) {
numberPicker.setValue(2);
} else if (UserConfig.autoLockIn == 60 * 60) {
numberPicker.setValue(3);
} else if (UserConfig.autoLockIn == 60 * 60 * 5) {
numberPicker.setValue(4);
}
numberPicker.setFormatter(new NumberPicker.Formatter() {
@Override
public String format(int value) {
if (value == 0) {
return LocaleController.getString("Disabled", R.string.Disabled);
} else if (value == 1) {
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", 1));
} else if (value == 2) {
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", 5));
} else if (value == 3) {
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Hours", 1));
} else if (value == 4) {
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Hours", 5));
}
return "";
}
});
builder.setView(numberPicker);
builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
which = numberPicker.getValue();
if (which == 0) {
UserConfig.autoLockIn = 0;
} else if (which == 1) {
UserConfig.autoLockIn = 60;
} else if (which == 2) {
UserConfig.autoLockIn = 60 * 5;
} else if (which == 3) {
UserConfig.autoLockIn = 60 * 60;
} else if (which == 4) {
UserConfig.autoLockIn = 60 * 60 * 5;
}
listView.invalidateViews();
UserConfig.saveConfig(false);
}
});
showAlertDialog(builder);
}
}
});
}
updateDropDownTextView();
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
frameLayout.setBackgroundColor(0xfff0f0f0);
listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
listView.setDrawSelectorOnTop(true);
frameLayout.addView(listView);
FrameLayout.LayoutParams 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 = new ListAdapter(context));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
if (i == changePasscodeRow) {
presentFragment(new PasscodeActivity(1));
} else if (i == passcodeRow) {
TextCheckCell cell = (TextCheckCell) view;
if (UserConfig.passcodeHash.length() != 0) {
UserConfig.passcodeHash = "";
UserConfig.appLocked = false;
UserConfig.saveConfig(false);
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View child = listView.getChildAt(a);
if (child instanceof TextSettingsCell) {
TextSettingsCell textCell = (TextSettingsCell) child;
textCell.setTextColor(0xffc6c6c6);
break;
}
}
cell.setChecked(UserConfig.passcodeHash.length() != 0);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didSetPasscode);
} else {
presentFragment(new PasscodeActivity(1));
}
} else if (i == autoLockRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AutoLock", R.string.AutoLock));
final NumberPicker numberPicker = new NumberPicker(getParentActivity());
numberPicker.setMinValue(0);
numberPicker.setMaxValue(4);
if (UserConfig.autoLockIn == 0) {
numberPicker.setValue(0);
} else if (UserConfig.autoLockIn == 60) {
numberPicker.setValue(1);
} else if (UserConfig.autoLockIn == 60 * 5) {
numberPicker.setValue(2);
} else if (UserConfig.autoLockIn == 60 * 60) {
numberPicker.setValue(3);
} else if (UserConfig.autoLockIn == 60 * 60 * 5) {
numberPicker.setValue(4);
}
numberPicker.setFormatter(new NumberPicker.Formatter() {
@Override
public String format(int value) {
if (value == 0) {
return LocaleController.getString("Disabled", R.string.Disabled);
} else if (value == 1) {
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", 1));
} else if (value == 2) {
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", 5));
} else if (value == 3) {
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Hours", 1));
} else if (value == 4) {
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Hours", 5));
}
return "";
}
});
builder.setView(numberPicker);
builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
which = numberPicker.getValue();
if (which == 0) {
UserConfig.autoLockIn = 0;
} else if (which == 1) {
UserConfig.autoLockIn = 60;
} else if (which == 2) {
UserConfig.autoLockIn = 60 * 5;
} else if (which == 3) {
UserConfig.autoLockIn = 60 * 60;
} else if (which == 4) {
UserConfig.autoLockIn = 60 * 60 * 5;
}
listView.invalidateViews();
UserConfig.saveConfig(false);
}
});
showAlertDialog(builder);
}
}
});
}
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,129 +95,123 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
@SuppressWarnings("unchecked")
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackgroundColor(0xff333333);
actionBar.setItemsBackground(R.drawable.bar_selector_picker);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle(LocaleController.getString("Gallery", R.string.Gallery));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (Build.VERSION.SDK_INT < 11) {
listView.setAdapter(null);
listView = null;
listAdapter = null;
}
finishFragment();
} else if (id == 1) {
if (delegate != null) {
finishFragment(false);
delegate.startPhotoSelectActivity();
}
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackgroundColor(0xff333333);
actionBar.setItemsBackground(R.drawable.bar_selector_picker);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle(LocaleController.getString("Gallery", R.string.Gallery));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (Build.VERSION.SDK_INT < 11) {
listView.setAdapter(null);
listView = null;
listAdapter = null;
}
finishFragment();
} else if (id == 1) {
if (delegate != null) {
finishFragment(false);
delegate.startPhotoSelectActivity();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItem(1, R.drawable.ic_ab_other);
fragmentView = new FrameLayout(getParentActivity());
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xff000000);
listView = new ListView(getParentActivity());
listView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), AndroidUtilities.dp(4));
listView.setClipToPadding(false);
listView.setHorizontalScrollBarEnabled(false);
listView.setVerticalScrollBarEnabled(false);
listView.setSelector(new ColorDrawable(0));
listView.setDividerHeight(0);
listView.setDivider(null);
listView.setDrawingCacheEnabled(false);
listView.setScrollingCacheEnabled(false);
frameLayout.addView(listView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.bottomMargin = AndroidUtilities.dp(48);
listView.setLayoutParams(layoutParams);
listView.setAdapter(listAdapter = new ListAdapter(getParentActivity()));
AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);
emptyView = new TextView(getParentActivity());
emptyView.setTextColor(0xff808080);
emptyView.setTextSize(20);
emptyView.setGravity(Gravity.CENTER);
emptyView.setVisibility(View.GONE);
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
frameLayout.addView(emptyView);
layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.bottomMargin = AndroidUtilities.dp(48);
emptyView.setLayoutParams(layoutParams);
emptyView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
progressView = new FrameLayout(getParentActivity());
progressView.setVisibility(View.GONE);
frameLayout.addView(progressView);
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.bottomMargin = AndroidUtilities.dp(48);
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);
photoPickerBottomLayout = new PhotoPickerBottomLayout(getParentActivity());
frameLayout.addView(photoPickerBottomLayout);
layoutParams = (FrameLayout.LayoutParams) photoPickerBottomLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = AndroidUtilities.dp(48);
layoutParams.gravity = Gravity.BOTTOM;
photoPickerBottomLayout.setLayoutParams(layoutParams);
photoPickerBottomLayout.cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finishFragment();
}
});
photoPickerBottomLayout.doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendSelectedPhotos();
finishFragment();
}
});
if (loading && (albumsSorted == null || albumsSorted != null && albumsSorted.isEmpty())) {
progressView.setVisibility(View.VISIBLE);
listView.setEmptyView(null);
} else {
progressView.setVisibility(View.GONE);
listView.setEmptyView(emptyView);
}
photoPickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItem(1, R.drawable.ic_ab_other);
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xff000000);
listView = new ListView(context);
listView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), AndroidUtilities.dp(4));
listView.setClipToPadding(false);
listView.setHorizontalScrollBarEnabled(false);
listView.setVerticalScrollBarEnabled(false);
listView.setSelector(new ColorDrawable(0));
listView.setDividerHeight(0);
listView.setDivider(null);
listView.setDrawingCacheEnabled(false);
listView.setScrollingCacheEnabled(false);
frameLayout.addView(listView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.bottomMargin = AndroidUtilities.dp(48);
listView.setLayoutParams(layoutParams);
listView.setAdapter(listAdapter = new ListAdapter(context));
AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);
emptyView = new TextView(context);
emptyView.setTextColor(0xff808080);
emptyView.setTextSize(20);
emptyView.setGravity(Gravity.CENTER);
emptyView.setVisibility(View.GONE);
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
frameLayout.addView(emptyView);
layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.bottomMargin = AndroidUtilities.dp(48);
emptyView.setLayoutParams(layoutParams);
emptyView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
progressView = new FrameLayout(context);
progressView.setVisibility(View.GONE);
frameLayout.addView(progressView);
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.bottomMargin = AndroidUtilities.dp(48);
progressView.setLayoutParams(layoutParams);
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);
photoPickerBottomLayout = new PhotoPickerBottomLayout(context);
frameLayout.addView(photoPickerBottomLayout);
layoutParams = (FrameLayout.LayoutParams) photoPickerBottomLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = AndroidUtilities.dp(48);
layoutParams.gravity = Gravity.BOTTOM;
photoPickerBottomLayout.setLayoutParams(layoutParams);
photoPickerBottomLayout.cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finishFragment();
}
});
photoPickerBottomLayout.doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendSelectedPhotos();
finishFragment();
}
});
if (loading && (albumsSorted == null || albumsSorted != null && albumsSorted.isEmpty())) {
progressView.setVisibility(View.VISIBLE);
listView.setEmptyView(null);
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
progressView.setVisibility(View.GONE);
listView.setEmptyView(emptyView);
}
photoPickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
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,44 +431,38 @@ public class PhotoCropActivity extends BaseFragment {
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackgroundColor(0xff333333);
actionBar.setItemsBackground(R.drawable.bar_selector_picker);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("CropImage", R.string.CropImage));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (delegate != null && !doneButtonPressed) {
Bitmap bitmap = view.getBitmap();
if (bitmap == imageToCrop) {
sameBitmap = true;
}
delegate.didFinishEdit(bitmap, getArguments());
doneButtonPressed = true;
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackgroundColor(0xff333333);
actionBar.setItemsBackground(R.drawable.bar_selector_picker);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("CropImage", R.string.CropImage));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (delegate != null && !doneButtonPressed) {
Bitmap bitmap = view.getBitmap();
if (bitmap == imageToCrop) {
sameBitmap = true;
}
finishFragment();
delegate.didFinishEdit(bitmap, getArguments());
doneButtonPressed = true;
}
finishFragment();
}
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
fragmentView = view = new PhotoCropView(getParentActivity());
((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);
}
}
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
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));
return fragmentView;
}

View file

@ -142,275 +142,269 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@SuppressWarnings("unchecked")
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackgroundColor(0xff333333);
actionBar.setItemsBackground(R.drawable.bar_selector_picker);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
if (selectedAlbum != null) {
actionBar.setTitle(selectedAlbum.bucketName);
} else if (type == 0) {
actionBar.setTitle(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
} else if (type == 1) {
actionBar.setTitle(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (Build.VERSION.SDK_INT < 11) {
listView.setAdapter(null);
listView = null;
listAdapter = null;
}
finishFragment();
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackgroundColor(0xff333333);
actionBar.setItemsBackground(R.drawable.bar_selector_picker);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
if (selectedAlbum != null) {
actionBar.setTitle(selectedAlbum.bucketName);
} else if (type == 0) {
actionBar.setTitle(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
} else if (type == 1) {
actionBar.setTitle(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (Build.VERSION.SDK_INT < 11) {
listView.setAdapter(null);
listView = null;
listAdapter = null;
}
finishFragment();
}
});
}
});
if (selectedAlbum == null) {
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
if (selectedAlbum == null) {
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
}
}
@Override
public boolean onSearchCollapse() {
finishFragment();
return false;
}
@Override
public boolean onSearchCollapse() {
finishFragment();
return false;
}
@Override
public void onTextChanged(EditText editText) {
if (editText.getText().length() == 0) {
searchResult.clear();
searchResultKeys.clear();
lastSearchString = null;
nextSearchBingString = null;
giphySearchEndReached = true;
searching = false;
requestQueue.cancelAll("search");
if (type == 0) {
emptyView.setText(LocaleController.getString("NoRecentPhotos", R.string.NoRecentPhotos));
} else if (type == 1) {
emptyView.setText(LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
}
updateSearchInterface();
}
}
@Override
public void onSearchPressed(EditText editText) {
if (editText.getText().toString().length() == 0) {
return;
}
@Override
public void onTextChanged(EditText editText) {
if (editText.getText().length() == 0) {
searchResult.clear();
searchResultKeys.clear();
lastSearchString = null;
nextSearchBingString = null;
giphySearchEndReached = true;
searching = false;
requestQueue.cancelAll("search");
if (type == 0) {
searchBingImages(editText.getText().toString(), 0, 53);
emptyView.setText(LocaleController.getString("NoRecentPhotos", R.string.NoRecentPhotos));
} else if (type == 1) {
searchGiphyImages(editText.getText().toString(), 0, 53);
}
lastSearchString = editText.getText().toString();
if (lastSearchString.length() == 0) {
lastSearchString = null;
if (type == 0) {
emptyView.setText(LocaleController.getString("NoRecentPhotos", R.string.NoRecentPhotos));
} else if (type == 1) {
emptyView.setText(LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
}
} else {
emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
emptyView.setText(LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
}
updateSearchInterface();
}
});
}
if (selectedAlbum == null) {
if (type == 0) {
searchItem.getSearchField().setHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
} else if (type == 1) {
searchItem.getSearchField().setHint(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
}
}
fragmentView = new FrameLayout(getParentActivity());
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xff000000);
listView = new GridView(getParentActivity());
listView.setPadding(AndroidUtilities.dp(4), AndroidUtilities.dp(4), AndroidUtilities.dp(4), AndroidUtilities.dp(4));
listView.setClipToPadding(false);
listView.setDrawSelectorOnTop(true);
listView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
listView.setHorizontalScrollBarEnabled(false);
listView.setVerticalScrollBarEnabled(false);
listView.setNumColumns(GridView.AUTO_FIT);
listView.setVerticalSpacing(AndroidUtilities.dp(4));
listView.setHorizontalSpacing(AndroidUtilities.dp(4));
listView.setSelector(R.drawable.list_selector);
frameLayout.addView(listView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
listView.setLayoutParams(layoutParams);
listView.setAdapter(listAdapter = new ListAdapter(getParentActivity()));
AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
ArrayList<Object> arrayList = null;
if (selectedAlbum != null) {
arrayList = (ArrayList) selectedAlbum.photos;
} else {
if (searchResult.isEmpty() && lastSearchString == null) {
arrayList = (ArrayList) recentImages;
} else {
arrayList = (ArrayList) searchResult;
}
}
if (i < 0 || i >= arrayList.size()) {
public void onSearchPressed(EditText editText) {
if (editText.getText().toString().length() == 0) {
return;
}
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().openPhotoForSelect(arrayList, i, singlePhoto ? 1 : 0, PhotoPickerActivity.this);
searchResult.clear();
searchResultKeys.clear();
nextSearchBingString = null;
giphySearchEndReached = true;
if (type == 0) {
searchBingImages(editText.getText().toString(), 0, 53);
} else if (type == 1) {
searchGiphyImages(editText.getText().toString(), 0, 53);
}
lastSearchString = editText.getText().toString();
if (lastSearchString.length() == 0) {
lastSearchString = null;
if (type == 0) {
emptyView.setText(LocaleController.getString("NoRecentPhotos", R.string.NoRecentPhotos));
} else if (type == 1) {
emptyView.setText(LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
}
} else {
emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
}
updateSearchInterface();
}
});
}
if (selectedAlbum == null) {
if (type == 0) {
searchItem.getSearchField().setHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
} else if (type == 1) {
searchItem.getSearchField().setHint(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
}
}
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xff000000);
listView = new GridView(context);
listView.setPadding(AndroidUtilities.dp(4), AndroidUtilities.dp(4), AndroidUtilities.dp(4), AndroidUtilities.dp(4));
listView.setClipToPadding(false);
listView.setDrawSelectorOnTop(true);
listView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
listView.setHorizontalScrollBarEnabled(false);
listView.setVerticalScrollBarEnabled(false);
listView.setNumColumns(GridView.AUTO_FIT);
listView.setVerticalSpacing(AndroidUtilities.dp(4));
listView.setHorizontalSpacing(AndroidUtilities.dp(4));
listView.setSelector(R.drawable.list_selector);
frameLayout.addView(listView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
listView.setLayoutParams(layoutParams);
listView.setAdapter(listAdapter = new ListAdapter(context));
AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
ArrayList<Object> arrayList = null;
if (selectedAlbum != null) {
arrayList = (ArrayList) selectedAlbum.photos;
} else {
if (searchResult.isEmpty() && lastSearchString == null) {
arrayList = (ArrayList) recentImages;
} else {
arrayList = (ArrayList) searchResult;
}
}
if (i < 0 || i >= arrayList.size()) {
return;
}
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().openPhotoForSelect(arrayList, i, singlePhoto ? 1 : 0, PhotoPickerActivity.this);
}
});
if (selectedAlbum == null) {
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (searchResult.isEmpty() && lastSearchString == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch));
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
recentImages.clear();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
MessagesStorage.getInstance().clearWebRecent(type);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
return true;
}
return false;
}
});
}
emptyView = new TextView(context);
emptyView.setTextColor(0xff808080);
emptyView.setTextSize(20);
emptyView.setGravity(Gravity.CENTER);
emptyView.setVisibility(View.GONE);
if (selectedAlbum != null) {
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
} else {
if (type == 0) {
emptyView.setText(LocaleController.getString("NoRecentPhotos", R.string.NoRecentPhotos));
} else if (type == 1) {
emptyView.setText(LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
}
}
frameLayout.addView(emptyView);
layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
emptyView.setLayoutParams(layoutParams);
emptyView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
if (selectedAlbum == null) {
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2 && !searching) {
if (type == 0 && nextSearchBingString != null) {
searchBingImages(lastSearchString, searchResult.size(), 54);
} else if (type == 1 && !giphySearchEndReached) {
searchGiphyImages(searchItem.getSearchField().getText().toString(), searchResult.size(), 54);
}
}
}
});
if (selectedAlbum == null) {
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (searchResult.isEmpty() && lastSearchString == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch));
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
recentImages.clear();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
MessagesStorage.getInstance().clearWebRecent(type);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
return true;
}
return false;
}
});
}
emptyView = new TextView(getParentActivity());
emptyView.setTextColor(0xff808080);
emptyView.setTextSize(20);
emptyView.setGravity(Gravity.CENTER);
emptyView.setVisibility(View.GONE);
if (selectedAlbum != null) {
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
} else {
if (type == 0) {
emptyView.setText(LocaleController.getString("NoRecentPhotos", R.string.NoRecentPhotos));
} else if (type == 1) {
emptyView.setText(LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
}
}
frameLayout.addView(emptyView);
layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
progressView = new FrameLayout(context);
progressView.setVisibility(View.GONE);
frameLayout.addView(progressView);
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
emptyView.setLayoutParams(layoutParams);
emptyView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
progressView.setLayoutParams(layoutParams);
if (selectedAlbum == null) {
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
ProgressBar progressBar = new ProgressBar(context);
progressView.addView(progressBar);
layoutParams = (FrameLayout.LayoutParams) progressBar.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.CENTER;
progressBar.setLayoutParams(layoutParams);
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2 && !searching) {
if (type == 0 && nextSearchBingString != null) {
searchBingImages(lastSearchString, searchResult.size(), 54);
} else if (type == 1 && !giphySearchEndReached) {
searchGiphyImages(searchItem.getSearchField().getText().toString(), searchResult.size(), 54);
}
}
}
});
progressView = new FrameLayout(getParentActivity());
progressView.setVisibility(View.GONE);
frameLayout.addView(progressView);
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
progressView.setLayoutParams(layoutParams);
ProgressBar progressBar = new ProgressBar(getParentActivity());
progressView.addView(progressBar);
layoutParams = (FrameLayout.LayoutParams) progressBar.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.gravity = Gravity.CENTER;
progressBar.setLayoutParams(layoutParams);
updateSearchInterface();
}
photoPickerBottomLayout = new PhotoPickerBottomLayout(getParentActivity());
frameLayout.addView(photoPickerBottomLayout);
layoutParams = (FrameLayout.LayoutParams) photoPickerBottomLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = AndroidUtilities.dp(48);
layoutParams.gravity = Gravity.BOTTOM;
photoPickerBottomLayout.setLayoutParams(layoutParams);
photoPickerBottomLayout.cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
delegate.actionButtonPressed(true);
finishFragment();
}
});
photoPickerBottomLayout.doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendSelectedPhotos();
}
});
if (singlePhoto) {
photoPickerBottomLayout.setVisibility(View.GONE);
}
listView.setEmptyView(emptyView);
photoPickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
updateSearchInterface();
}
photoPickerBottomLayout = new PhotoPickerBottomLayout(context);
frameLayout.addView(photoPickerBottomLayout);
layoutParams = (FrameLayout.LayoutParams) photoPickerBottomLayout.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = AndroidUtilities.dp(48);
layoutParams.gravity = Gravity.BOTTOM;
photoPickerBottomLayout.setLayoutParams(layoutParams);
photoPickerBottomLayout.cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
delegate.actionButtonPressed(true);
finishFragment();
}
});
photoPickerBottomLayout.doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendSelectedPhotos();
}
});
if (singlePhoto) {
photoPickerBottomLayout.setVisibility(View.GONE);
}
listView.setEmptyView(emptyView);
photoPickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
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,158 +90,114 @@ public class PrivacySettingsActivity extends BaseFragment implements Notificatio
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("PrivacySettings", R.string.PrivacySettings));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
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));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
});
listAdapter = new ListAdapter(getParentActivity());
fragmentView = new FrameLayout(getParentActivity());
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xfff0f0f0);
ListView listView = new ListView(getParentActivity());
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
listView.setDrawSelectorOnTop(true);
frameLayout.addView(listView);
FrameLayout.LayoutParams 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 == 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 == deleteAccountRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("DeleteAccountTitle", R.string.DeleteAccountTitle));
builder.setItems(new CharSequence[] {
LocaleController.formatPluralString("Months", 1),
LocaleController.formatPluralString("Months", 3),
LocaleController.formatPluralString("Months", 6),
LocaleController.formatPluralString("Years", 1)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int value = 0;
if (which == 0) {
value = 30;
} else if (which == 1) {
value = 90;
} else if (which == 2) {
value = 182;
} else if (which == 3) {
value = 365;
}
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_account_setAccountTTL req = new TLRPC.TL_account_setAccountTTL();
req.ttl = new TLRPC.TL_accountDaysTTL();
req.ttl.days = value;
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 (response instanceof TLRPC.TL_boolTrue) {
ContactsController.getInstance().setDeleteAccountTTL(req.ttl.days);
listAdapter.notifyDataSetChanged();
}
}
});
}
});
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == lastSeenRow) {
presentFragment(new LastSeenActivity());
} else if (i == passwordRow) {
presentFragment(new AccountPasswordActivity(0));
} else if (i == passcodeRow) {
if (UserConfig.passcodeHash.length() > 0) {
presentFragment(new PasscodeActivity(2));
} else {
presentFragment(new PasscodeActivity(0));
}
}
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
});
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(0xfff0f0f0);
ListView listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
listView.setDrawSelectorOnTop(true);
frameLayout.addView(listView);
FrameLayout.LayoutParams 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 == blockedRow) {
presentFragment(new BlockedUsersActivity());
} 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[]{
LocaleController.formatPluralString("Months", 1),
LocaleController.formatPluralString("Months", 3),
LocaleController.formatPluralString("Months", 6),
LocaleController.formatPluralString("Years", 1)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int value = 0;
if (which == 0) {
value = 30;
} else if (which == 1) {
value = 90;
} else if (which == 2) {
value = 182;
} else if (which == 3) {
value = 365;
}
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_account_setAccountTTL req = new TLRPC.TL_account_setAccountTTL();
req.ttl = new TLRPC.TL_accountDaysTTL();
req.ttl.days = value;
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 (response instanceof TLRPC.TL_boolTrue) {
ContactsController.getInstance().setDeleteAccountTTL(req.ttl.days);
listAdapter.notifyDataSetChanged();
}
}
});
}
});
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == lastSeenRow) {
presentFragment(new LastSeenActivity());
} else if (i == passwordRow) {
presentFragment(new TwoStepVerificationActivity(0));
} else if (i == passcodeRow) {
if (UserConfig.passcodeHash.length() > 0) {
presentFragment(new PasscodeActivity(2));
} else {
presentFragment(new PasscodeActivity(0));
}
}
}
});
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,434 +223,425 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
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);
actionBar.setExtraHeight(AndroidUtilities.dp(88), false);
if (AndroidUtilities.isTablet()) {
actionBar.setOccupyStatusBar(false);
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);
actionBar.setExtraHeight(AndroidUtilities.dp(88), false);
if (AndroidUtilities.isTablet()) {
actionBar.setOccupyStatusBar(false);
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(final int id) {
if (getParentActivity() == null) {
return;
}
if (id == -1) {
finishFragment();
} else if (id == block_contact) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
if (!userBlocked) {
builder.setMessage(LocaleController.getString("AreYouSureBlockContact", R.string.AreYouSureBlockContact));
} else {
builder.setMessage(LocaleController.getString("AreYouSureUnblockContact", R.string.AreYouSureUnblockContact));
}
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) {
if (!userBlocked) {
MessagesController.getInstance().blockUser(user_id);
} else {
MessagesController.getInstance().unblockUser(user_id);
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (id == add_contact) {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
Bundle args = new Bundle();
args.putInt("user_id", user.id);
presentFragment(new ContactAddActivity(args));
} else if (id == share_contact) {
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putBoolean("serverOnly", true);
MessagesActivity fragment = new MessagesActivity(args);
fragment.setDelegate(ProfileActivity.this);
presentFragment(fragment);
} else if (id == edit_contact) {
Bundle args = new Bundle();
args.putInt("user_id", user_id);
presentFragment(new ContactAddActivity(args));
} else if (id == delete_contact) {
final TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null || getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSureDeleteContact", R.string.AreYouSureDeleteContact));
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) {
ArrayList<TLRPC.User> arrayList = new ArrayList<>();
arrayList.add(user);
ContactsController.getInstance().deleteContact(arrayList);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (id == add_member) {
Bundle args = new Bundle();
args.putBoolean("onlyUsers", true);
args.putBoolean("destroyAfterSelect", true);
args.putBoolean("returnAsResult", true);
//args.putBoolean("allowUsernameSearch", false);
if (chat_id > 0) {
args.putString("selectAlertString", LocaleController.getString("AddToTheGroup", R.string.AddToTheGroup));
}
ContactsActivity fragment = new ContactsActivity(args);
fragment.setDelegate(new ContactsActivity.ContactsActivityDelegate() {
@Override
public void didSelectContact(TLRPC.User user, String param) {
MessagesController.getInstance().addUserToChat(chat_id, user, info, param != null ? Utilities.parseInt(param) : 0);
}
});
if (info != null) {
HashMap<Integer, TLRPC.User> users = new HashMap<>();
for (TLRPC.TL_chatParticipant p : info.participants) {
users.put(p.user_id, null);
}
fragment.setIgnoreUsers(users);
}
presentFragment(fragment);
} else if (id == leave_group) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
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) {
kickUser(null);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (id == edit_name) {
Bundle args = new Bundle();
args.putInt("chat_id", chat_id);
presentFragment(new ChangeChatNameActivity(args));
}
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(final int id) {
});
createActionBarMenu();
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
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;
layoutParams.width = AndroidUtilities.dp(60);
layoutParams.height = AndroidUtilities.dp(60);
layoutParams.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(17);
layoutParams.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(17) : 0;
layoutParams.bottomMargin = AndroidUtilities.dp(22);
avatarImage.setLayoutParams(layoutParams);
avatarImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (user_id != 0) {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user.photo != null && user.photo.photo_big != null) {
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().openPhoto(user.photo.photo_big, ProfileActivity.this);
}
} else if (chat_id != 0) {
TLRPC.Chat chat = MessagesController.getInstance().getChat(chat_id);
if (chat.photo != null && chat.photo.photo_big != null) {
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().openPhoto(chat.photo.photo_big, ProfileActivity.this);
}
}
}
});
nameTextView = new TextView(context);
nameTextView.setTextColor(0xffffffff);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
nameTextView.setLines(1);
nameTextView.setMaxLines(1);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
actionBar.addView(nameTextView);
layoutParams = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 97);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 97 : 16);
layoutParams.bottomMargin = AndroidUtilities.dp(51);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
nameTextView.setLayoutParams(layoutParams);
onlineTextView = new TextView(context);
onlineTextView.setTextColor(AvatarDrawable.getProfileTextColorForId(user_id != 0 ? 5 : chat_id));
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
onlineTextView.setLines(1);
onlineTextView.setMaxLines(1);
onlineTextView.setSingleLine(true);
onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
onlineTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
actionBar.addView(onlineTextView);
layoutParams = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 97);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 97 : 16);
layoutParams.bottomMargin = AndroidUtilities.dp(30);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
onlineTextView.setLayoutParams(layoutParams);
listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
AndroidUtilities.setListViewEdgeEffectColor(listView, AvatarDrawable.getProfileBackColorForId(user_id != 0 ? 5 : chat_id));
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 (getParentActivity() == null) {
return;
}
if (i == sharedMediaRow) {
Bundle args = new Bundle();
if (user_id != 0) {
args.putLong("dialog_id", dialog_id != 0 ? dialog_id : user_id);
} else {
args.putLong("dialog_id", -chat_id);
}
presentFragment(new MediaActivity(args));
} else if (i == settingsKeyRow) {
Bundle args = new Bundle();
args.putInt("chat_id", (int) (dialog_id >> 32));
presentFragment(new IdenticonActivity(args));
} else if (i == settingsTimerRow) {
if (getParentActivity() == null) {
return;
}
if (id == -1) {
finishFragment();
} else if (id == block_contact) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
if (!userBlocked) {
builder.setMessage(LocaleController.getString("AreYouSureBlockContact", R.string.AreYouSureBlockContact));
} else {
builder.setMessage(LocaleController.getString("AreYouSureUnblockContact", R.string.AreYouSureUnblockContact));
showAlertDialog(AndroidUtilities.buildTTLAlert(getParentActivity(), currentEncryptedChat));
} else if (i == settingsNotificationsRow) {
Bundle args = new Bundle();
if (user_id != 0) {
args.putLong("dialog_id", dialog_id == 0 ? user_id : dialog_id);
} else if (chat_id != 0) {
args.putLong("dialog_id", -chat_id);
}
presentFragment(new ProfileNotificationsActivity(args));
} else if (i == startSecretChatRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSureSecretChat", R.string.AreYouSureSecretChat));
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) {
creatingChat = true;
SecretChatHelper.getInstance().startSecretChat(getParentActivity(), MessagesController.getInstance().getUser(user_id));
}
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) {
if (!userBlocked) {
MessagesController.getInstance().blockUser(user_id);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == phoneRow) {
final TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null || user.phone == null || user.phone.length() == 0 || getParentActivity() == null) {
return;
}
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() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
try {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+" + user.phone));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getParentActivity().startActivityForResult(intent, 500);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else if (i == 1) {
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 {
MessagesController.getInstance().unblockUser(user_id);
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);
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (id == add_contact) {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
Bundle args = new Bundle();
args.putInt("user_id", user.id);
presentFragment(new ContactAddActivity(args));
} else if (id == share_contact) {
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putBoolean("serverOnly", true);
MessagesActivity fragment = new MessagesActivity(args);
fragment.setDelegate(ProfileActivity.this);
presentFragment(fragment);
} else if (id == edit_contact) {
Bundle args = new Bundle();
args.putInt("user_id", user_id);
presentFragment(new ContactAddActivity(args));
} else if (id == delete_contact) {
final TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null || getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSureDeleteContact", R.string.AreYouSureDeleteContact));
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) {
ArrayList<TLRPC.User> arrayList = new ArrayList<>();
arrayList.add(user);
ContactsController.getInstance().deleteContact(arrayList);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (id == add_member) {
Bundle args = new Bundle();
args.putBoolean("onlyUsers", true);
args.putBoolean("destroyAfterSelect", true);
args.putBoolean("returnAsResult", true);
//args.putBoolean("allowUsernameSearch", false);
if (chat_id > 0) {
args.putString("selectAlertString", LocaleController.getString("AddToTheGroup", R.string.AddToTheGroup));
}
ContactsActivity fragment = new ContactsActivity(args);
fragment.setDelegate(new ContactsActivity.ContactsActivityDelegate() {
@Override
public void didSelectContact(TLRPC.User user, String param) {
MessagesController.getInstance().addUserToChat(chat_id, user, info, param != null ? Utilities.parseInt(param) : 0);
}
});
if (info != null) {
HashMap<Integer, TLRPC.User> users = new HashMap<>();
for (TLRPC.TL_chatParticipant p : info.participants) {
users.put(p.user_id, null);
}
fragment.setIgnoreUsers(users);
}
presentFragment(fragment);
} else if (id == leave_group) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit));
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) {
kickUser(null);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (id == edit_name) {
Bundle args = new Bundle();
args.putInt("chat_id", chat_id);
presentFragment(new ChangeChatNameActivity(args));
}
}
});
createActionBarMenu();
listAdapter = new ListAdapter(getParentActivity());
fragmentView = new FrameLayout(getParentActivity());
FrameLayout frameLayout = (FrameLayout) fragmentView;
avatarImage = new BackupImageView(getParentActivity());
avatarImage.imageReceiver.setRoundRadius(AndroidUtilities.dp(30));
avatarImage.processDetach = false;
actionBar.addView(avatarImage);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
layoutParams.width = AndroidUtilities.dp(60);
layoutParams.height = AndroidUtilities.dp(60);
layoutParams.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(17);
layoutParams.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(17) : 0;
layoutParams.bottomMargin = AndroidUtilities.dp(22);
avatarImage.setLayoutParams(layoutParams);
avatarImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (user_id != 0) {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user.photo != null && user.photo.photo_big != null) {
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().openPhoto(user.photo.photo_big, ProfileActivity.this);
}
} else if (chat_id != 0) {
TLRPC.Chat chat = MessagesController.getInstance().getChat(chat_id);
if (chat.photo != null && chat.photo.photo_big != null) {
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().openPhoto(chat.photo.photo_big, ProfileActivity.this);
}
}
}
});
nameTextView = new TextView(getParentActivity());
nameTextView.setTextColor(0xffffffff);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
nameTextView.setLines(1);
nameTextView.setMaxLines(1);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
actionBar.addView(nameTextView);
layoutParams = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 97);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 97 : 16);
layoutParams.bottomMargin = AndroidUtilities.dp(51);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
nameTextView.setLayoutParams(layoutParams);
onlineTextView = new TextView(getParentActivity());
onlineTextView.setTextColor(AvatarDrawable.getProfileTextColorForId(user_id != 0 ? 5 : chat_id));
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
onlineTextView.setLines(1);
onlineTextView.setMaxLines(1);
onlineTextView.setSingleLine(true);
onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
onlineTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
actionBar.addView(onlineTextView);
layoutParams = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 97);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 97 : 16);
layoutParams.bottomMargin = AndroidUtilities.dp(30);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
onlineTextView.setLayoutParams(layoutParams);
listView = new ListView(getParentActivity());
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
AndroidUtilities.setListViewEdgeEffectColor(listView, AvatarDrawable.getProfileBackColorForId(user_id != 0 ? 5 : chat_id));
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 (getParentActivity() == null) {
});
showAlertDialog(builder);
} else if (i > emptyRowChat2 && i < membersEndRow) {
int user_id = info.participants.get(sortedUsers.get(i - emptyRowChat2 - 1)).user_id;
if (user_id == UserConfig.getClientUserId()) {
return;
}
if (i == sharedMediaRow) {
Bundle args = new Bundle();
if (user_id != 0) {
args.putLong("dialog_id", dialog_id != 0 ? dialog_id : user_id);
} else {
args.putLong("dialog_id", -chat_id);
}
presentFragment(new MediaActivity(args));
} else if (i == settingsKeyRow) {
Bundle args = new Bundle();
args.putInt("chat_id", (int)(dialog_id >> 32));
presentFragment(new IdenticonActivity(args));
} else if (i == settingsTimerRow) {
Bundle args = new Bundle();
args.putInt("user_id", user_id);
presentFragment(new ProfileActivity(args));
}
}
});
if (chat_id != 0) {
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i > emptyRowChat2 && i < membersEndRow) {
if (getParentActivity() == null) {
return;
}
showAlertDialog(AndroidUtilities.buildTTLAlert(getParentActivity(), currentEncryptedChat));
} else if (i == settingsNotificationsRow) {
Bundle args = new Bundle();
if (user_id != 0) {
args.putLong("dialog_id", dialog_id == 0 ? user_id : dialog_id);
} else if (chat_id != 0) {
args.putLong("dialog_id", -chat_id);
}
presentFragment(new ProfileNotificationsActivity(args));
} else if (i == startSecretChatRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSureSecretChat", R.string.AreYouSureSecretChat));
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) {
creatingChat = true;
SecretChatHelper.getInstance().startSecretChat(getParentActivity(), MessagesController.getInstance().getUser(user_id));
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == phoneRow) {
final TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null || user.phone == null || user.phone.length() == 0 || getParentActivity() == null) {
return;
return false;
}
TLRPC.TL_chatParticipant user = info.participants.get(sortedUsers.get(i - emptyRowChat2 - 1));
if (user.user_id == UserConfig.getClientUserId()) {
return false;
}
if (info.admin_id != UserConfig.getClientUserId() && user.inviter_id != UserConfig.getClientUserId()) {
return false;
}
selectedUser = user;
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() {
CharSequence[] items = new CharSequence[]{chat_id > 0 ? LocaleController.getString("KickFromGroup", R.string.KickFromGroup) : LocaleController.getString("KickFromBroadcast", R.string.KickFromBroadcast)};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
try {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+" + user.phone));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getParentActivity().startActivityForResult(intent, 500);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else if (i == 1) {
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.ClipData clip = android.content.ClipData.newPlainText("label", "+" + user.phone);
clipboard.setPrimaryClip(clip);
}
kickUser(selectedUser);
}
}
});
showAlertDialog(builder);
} else if (i > emptyRowChat2 && i < membersEndRow) {
int user_id = info.participants.get(sortedUsers.get(i - emptyRowChat2 - 1)).user_id;
if (user_id == UserConfig.getClientUserId()) {
return true;
}
return false;
}
});
}
if (dialog_id != 0) {
SharedMediaQuery.getMediaCount(dialog_id, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
} else {
SharedMediaQuery.getMediaCount(user_id, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
}
frameLayout.addView(actionBar);
if (user_id != 0 || chat_id >= 0 && !currentChat.left) {
writeButton = new ImageView(context);
writeButton.setBackgroundResource(R.drawable.floating_user_states);
writeButton.setScaleType(ImageView.ScaleType.CENTER);
if (user_id != 0) {
writeButton.setImageResource(R.drawable.floating_message);
writeButton.setPadding(0, AndroidUtilities.dp(3), 0, 0);
} else if (chat_id != 0) {
writeButton.setImageResource(R.drawable.floating_camera);
}
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));
writeButton.setStateListAnimator(animator);
writeButton.setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
}
});
}
layoutParams = (FrameLayout.LayoutParams) writeButton.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 0);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 16);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT);
writeButton.setLayoutParams(layoutParams);
writeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getParentActivity() == null) {
return;
}
if (user_id != 0) {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null || user instanceof TLRPC.TL_userEmpty) {
return;
}
NotificationCenter.getInstance().removeObserver(ProfileActivity.this, NotificationCenter.closeChats);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
Bundle args = new Bundle();
args.putInt("user_id", user_id);
presentFragment(new ProfileActivity(args));
presentFragment(new ChatActivity(args), true);
} else if (chat_id != 0) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items;
TLRPC.Chat chat = MessagesController.getInstance().getChat(chat_id);
if (chat.photo == null || chat.photo.photo_big == null || chat.photo instanceof TLRPC.TL_chatPhotoEmpty) {
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley)};
} else {
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto)};
}
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
int action = 0;
if (i == 0) {
avatarUpdater.openCamera();
} else if (i == 1) {
avatarUpdater.openGallery();
} else if (i == 2) {
MessagesController.getInstance().changeChatAvatar(chat_id, null);
}
}
});
showAlertDialog(builder);
}
}
});
if (chat_id != 0) {
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i > emptyRowChat2 && i < membersEndRow) {
if (getParentActivity() == null) {
return false;
}
TLRPC.TL_chatParticipant user = info.participants.get(sortedUsers.get(i - emptyRowChat2 - 1));
if (user.user_id == UserConfig.getClientUserId()) {
return false;
}
if (info.admin_id != UserConfig.getClientUserId() && user.inviter_id != UserConfig.getClientUserId()) {
return false;
}
selectedUser = user;
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items = new CharSequence[]{chat_id > 0 ? LocaleController.getString("KickFromGroup", R.string.KickFromGroup) : LocaleController.getString("KickFromBroadcast", R.string.KickFromBroadcast)};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
kickUser(selectedUser);
}
}
});
showAlertDialog(builder);
return true;
}
return false;
}
});
}
if (dialog_id != 0) {
SharedMediaQuery.getMediaCount(dialog_id, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
} else {
SharedMediaQuery.getMediaCount(user_id, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
}
frameLayout.addView(actionBar);
if (user_id != 0 || chat_id >= 0 && !currentChat.left) {
writeButton = new ImageView(getParentActivity());
writeButton.setBackgroundResource(R.drawable.floating_user_states);
writeButton.setScaleType(ImageView.ScaleType.CENTER);
if (user_id != 0) {
writeButton.setImageResource(R.drawable.floating_message);
writeButton.setPadding(0, AndroidUtilities.dp(3), 0, 0);
} else if (chat_id != 0) {
writeButton.setImageResource(R.drawable.floating_camera);
}
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));
writeButton.setStateListAnimator(animator);
writeButton.setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
}
});
}
layoutParams = (FrameLayout.LayoutParams) writeButton.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 0);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 16);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT);
writeButton.setLayoutParams(layoutParams);
writeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getParentActivity() == null) {
return;
}
if (user_id != 0) {
TLRPC.User user = MessagesController.getInstance().getUser(user_id);
if (user == null || user instanceof TLRPC.TL_userEmpty) {
return;
}
NotificationCenter.getInstance().removeObserver(ProfileActivity.this, NotificationCenter.closeChats);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
Bundle args = new Bundle();
args.putInt("user_id", user_id);
presentFragment(new ChatActivity(args), true);
} else if (chat_id != 0) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items;
TLRPC.Chat chat = MessagesController.getInstance().getChat(chat_id);
if (chat.photo == null || chat.photo.photo_big == null || chat.photo instanceof TLRPC.TL_chatPhotoEmpty) {
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley)};
} else {
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto)};
}
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
int action = 0;
if (i == 0) {
avatarUpdater.openCamera();
} else if (i == 1) {
avatarUpdater.openGallery();
} else if (i == 2) {
MessagesController.getInstance().changeChatAvatar(chat_id, null);
}
}
});
showAlertDialog(builder);
}
}
});
}
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
checkListViewScroll();
}
});
updateProfileData();
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
checkListViewScroll();
}
});
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,220 +85,214 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
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));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
});
fragmentView = new FrameLayout(getParentActivity());
FrameLayout frameLayout = (FrameLayout) fragmentView;
listView = new ListView(getParentActivity());
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
AndroidUtilities.setListViewEdgeEffectColor(listView, AvatarDrawable.getProfileBackColorForId(5));
frameLayout.addView(listView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
listView.setAdapter(new ListAdapter(getParentActivity()));
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[] {
LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled),
LocaleController.getString("SettingsDefault", R.string.SettingsDefault),
LocaleController.getString("SystemDefault", R.string.SystemDefault),
LocaleController.getString("Short", R.string.Short),
LocaleController.getString("Long", R.string.Long)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (which == 0) {
editor.putInt("vibrate_" + dialog_id, 2);
} else if (which == 1) {
editor.putInt("vibrate_" + dialog_id, 0);
} else if (which == 2) {
editor.putInt("vibrate_" + dialog_id, 4);
} else if (which == 3) {
editor.putInt("vibrate_" + dialog_id, 1);
} else if (which == 4) {
editor.putInt("vibrate_" + dialog_id, 3);
}
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == settingsNotificationsRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setItems(new CharSequence[] {
LocaleController.getString("Default", R.string.Default),
LocaleController.getString("Enabled", R.string.Enabled),
LocaleController.getString("NotificationsDisabled", R.string.NotificationsDisabled)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("notify2_" + dialog_id, which);
MessagesStorage.getInstance().setDialogFlags(dialog_id, which == 2 ? 1 : 0);
editor.commit();
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
if (dialog != null) {
dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
if (which == 2) {
dialog.notify_settings.mute_until = Integer.MAX_VALUE;
}
}
if (listView != null) {
listView.invalidateViews();
}
NotificationsController.updateServerNotificationsSettings(dialog_id);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == settingsSoundRow) {
try {
Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
Uri currentSound = null;
String defaultPath = null;
Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
if (defaultUri != null) {
defaultPath = defaultUri.getPath();
}
String path = preferences.getString("sound_path_" + dialog_id, defaultPath);
if (path != null && !path.equals("NoSound")) {
if (path.equals(defaultPath)) {
currentSound = defaultUri;
} else {
currentSound = Uri.parse(path);
}
}
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
startActivityForResult(tmpIntent, 12);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else if (i == settingsLedRow) {
if (getParentActivity() == null) {
return;
}
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);
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) {
colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
} else {
colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00));
}
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
builder.setView(view);
builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("color_" + dialog_id, colorPickerView.getColor());
editor.commit();
listView.invalidateViews();
}
});
builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("color_" + dialog_id, 0);
editor.commit();
listView.invalidateViews();
}
});
builder.setNegativeButton(LocaleController.getString("Default", R.string.Default), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.remove("color_" + dialog_id);
editor.commit();
listView.invalidateViews();
}
});
showAlertDialog(builder);
} else if (i == settingsPriorityRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority));
builder.setItems(new CharSequence[] {
LocaleController.getString("SettingsDefault", R.string.SettingsDefault),
LocaleController.getString("NotificationsPriorityDefault", R.string.NotificationsPriorityDefault),
LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh),
LocaleController.getString("NotificationsPriorityMax", R.string.NotificationsPriorityMax)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
which = 3;
} else {
which--;
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
preferences.edit().putInt("priority_" + dialog_id, which).commit();
if (listView != null) {
listView.invalidateViews();
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
}
});
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
});
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
AndroidUtilities.setListViewEdgeEffectColor(listView, AvatarDrawable.getProfileBackColorForId(5));
frameLayout.addView(listView);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
listView.setLayoutParams(layoutParams);
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[]{
LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled),
LocaleController.getString("SettingsDefault", R.string.SettingsDefault),
LocaleController.getString("SystemDefault", R.string.SystemDefault),
LocaleController.getString("Short", R.string.Short),
LocaleController.getString("Long", R.string.Long)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (which == 0) {
editor.putInt("vibrate_" + dialog_id, 2);
} else if (which == 1) {
editor.putInt("vibrate_" + dialog_id, 0);
} else if (which == 2) {
editor.putInt("vibrate_" + dialog_id, 4);
} else if (which == 3) {
editor.putInt("vibrate_" + dialog_id, 1);
} else if (which == 4) {
editor.putInt("vibrate_" + dialog_id, 3);
}
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == settingsNotificationsRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setItems(new CharSequence[]{
LocaleController.getString("Default", R.string.Default),
LocaleController.getString("Enabled", R.string.Enabled),
LocaleController.getString("NotificationsDisabled", R.string.NotificationsDisabled)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("notify2_" + dialog_id, which);
MessagesStorage.getInstance().setDialogFlags(dialog_id, which == 2 ? 1 : 0);
editor.commit();
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
if (dialog != null) {
dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
if (which == 2) {
dialog.notify_settings.mute_until = Integer.MAX_VALUE;
}
}
if (listView != null) {
listView.invalidateViews();
}
NotificationsController.updateServerNotificationsSettings(dialog_id);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == settingsSoundRow) {
try {
Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
Uri currentSound = null;
String defaultPath = null;
Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
if (defaultUri != null) {
defaultPath = defaultUri.getPath();
}
String path = preferences.getString("sound_path_" + dialog_id, defaultPath);
if (path != null && !path.equals("NoSound")) {
if (path.equals(defaultPath)) {
currentSound = defaultUri;
} else {
currentSound = Uri.parse(path);
}
}
tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
startActivityForResult(tmpIntent, 12);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else if (i == settingsLedRow) {
if (getParentActivity() == null) {
return;
}
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);
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) {
colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00));
} else {
colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00));
}
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor));
builder.setView(view);
builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("color_" + dialog_id, colorPickerView.getColor());
editor.commit();
listView.invalidateViews();
}
});
builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("color_" + dialog_id, 0);
editor.commit();
listView.invalidateViews();
}
});
builder.setNegativeButton(LocaleController.getString("Default", R.string.Default), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.remove("color_" + dialog_id);
editor.commit();
listView.invalidateViews();
}
});
showAlertDialog(builder);
} else if (i == settingsPriorityRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority));
builder.setItems(new CharSequence[]{
LocaleController.getString("SettingsDefault", R.string.SettingsDefault),
LocaleController.getString("NotificationsPriorityDefault", R.string.NotificationsPriorityDefault),
LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh),
LocaleController.getString("NotificationsPriorityMax", R.string.NotificationsPriorityMax)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
which = 3;
} else {
which--;
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
preferences.edit().putInt("priority_" + dialog_id, which).commit();
if (listView != null) {
listView.invalidateViews();
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
}
});
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,439 +268,430 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackgroundColor(AvatarDrawable.getProfileBackColorForId(5));
actionBar.setItemsBackground(AvatarDrawable.getButtonColorForId(5));
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setExtraHeight(AndroidUtilities.dp(88), false);
if (AndroidUtilities.isTablet()) {
actionBar.setOccupyStatusBar(false);
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackgroundColor(AvatarDrawable.getProfileBackColorForId(5));
actionBar.setItemsBackground(AvatarDrawable.getButtonColorForId(5));
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setExtraHeight(AndroidUtilities.dp(88), false);
if (AndroidUtilities.isTablet()) {
actionBar.setOccupyStatusBar(false);
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == edit_name) {
presentFragment(new ChangeNameActivity());
} else if (id == logout) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSureLogout", R.string.AreYouSureLogout));
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) {
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();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == edit_name) {
presentFragment(new ChangeNameActivity());
} else if (id == logout) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSureLogout", R.string.AreYouSureLogout));
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) {
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();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
});
ActionBarMenu menu = actionBar.createMenu();
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
item.addSubItem(edit_name, LocaleController.getString("EditName", R.string.EditName), 0);
item.addSubItem(logout, LocaleController.getString("LogOut", R.string.LogOut), 0);
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
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;
layoutParams.width = AndroidUtilities.dp(60);
layoutParams.height = AndroidUtilities.dp(60);
layoutParams.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(17);
layoutParams.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(17) : 0;
layoutParams.bottomMargin = AndroidUtilities.dp(22);
avatarImage.setLayoutParams(layoutParams);
avatarImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
if (user.photo != null && user.photo.photo_big != null) {
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().openPhoto(user.photo.photo_big, SettingsActivity.this);
}
});
ActionBarMenu menu = actionBar.createMenu();
ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
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());
fragmentView = new FrameLayout(getParentActivity());
FrameLayout frameLayout = (FrameLayout) fragmentView;
avatarImage = new BackupImageView(getParentActivity());
avatarImage.imageReceiver.setRoundRadius(AndroidUtilities.dp(30));
avatarImage.processDetach = false;
actionBar.addView(avatarImage);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
layoutParams.width = AndroidUtilities.dp(60);
layoutParams.height = AndroidUtilities.dp(60);
layoutParams.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(17);
layoutParams.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(17) : 0;
layoutParams.bottomMargin = AndroidUtilities.dp(22);
avatarImage.setLayoutParams(layoutParams);
avatarImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
if (user.photo != null && user.photo.photo_big != null) {
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().openPhoto(user.photo.photo_big, SettingsActivity.this);
}
}
});
nameTextView = new TextView(getParentActivity());
nameTextView.setTextColor(0xffffffff);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
nameTextView.setLines(1);
nameTextView.setMaxLines(1);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
actionBar.addView(nameTextView);
layoutParams = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 97);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 97 : 16);
layoutParams.bottomMargin = AndroidUtilities.dp(51);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
nameTextView.setLayoutParams(layoutParams);
onlineTextView = new TextView(getParentActivity());
onlineTextView.setTextColor(AvatarDrawable.getProfileTextColorForId(5));
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
onlineTextView.setLines(1);
onlineTextView.setMaxLines(1);
onlineTextView.setSingleLine(true);
onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
onlineTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
actionBar.addView(onlineTextView);
layoutParams = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 97);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 97 : 16);
layoutParams.bottomMargin = AndroidUtilities.dp(30);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
onlineTextView.setLayoutParams(layoutParams);
listView = new ListView(getParentActivity());
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
AndroidUtilities.setListViewEdgeEffectColor(listView, AvatarDrawable.getProfileBackColorForId(5));
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 == textSizeRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("TextSize", R.string.TextSize));
final NumberPicker numberPicker = new NumberPicker(getParentActivity());
numberPicker.setMinValue(12);
numberPicker.setMaxValue(30);
numberPicker.setValue(MessagesController.getInstance().fontSize);
builder.setView(numberPicker);
builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("fons_size", numberPicker.getValue());
MessagesController.getInstance().fontSize = numberPicker.getValue();
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
}
});
showAlertDialog(builder);
} else if (i == enableAnimationsRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("view_animations", !animations);
editor.commit();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(!animations);
}
} else if (i == notificationRow) {
presentFragment(new NotificationsSettingsActivity());
} else if (i == backgroundRow) {
presentFragment(new WallpapersActivity());
} else if (i == askQuestionRow) {
if (getParentActivity() == null) {
return;
}
final TextView message = new TextView(getParentActivity());
message.setText(Html.fromHtml(LocaleController.getString("AskAQuestionInfo", R.string.AskAQuestionInfo)));
message.setTextSize(18);
message.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(5), AndroidUtilities.dp(8), AndroidUtilities.dp(6));
message.setMovementMethod(new LinkMovementMethodMy());
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setView(message);
builder.setPositiveButton(LocaleController.getString("AskButton", R.string.AskButton), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
performAskAQuestion();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == sendLogsRow) {
sendLogs();
} else if (i == clearLogsRow) {
FileLog.cleanupLogs();
} else if (i == sendByEnterRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean send = preferences.getBoolean("send_by_enter", false);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("send_by_enter", !send);
editor.commit();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(!send);
}
} else if (i == saveToGalleryRow) {
MediaController.getInstance().toggleSaveToGallery();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(MediaController.getInstance().canSaveToGallery());
}
} else if (i == privacyRow) {
presentFragment(new PrivacySettingsActivity());
} else if (i == languageRow) {
presentFragment(new LanguageSelectActivity());
} else if (i == switchBackendButtonRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure));
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ConnectionsManager.getInstance().switchBackend();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == telegramFaqRow) {
try {
Intent pickIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl)));
getParentActivity().startActivityForResult(pickIntent, 500);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else if (i == contactsReimportRow) {
} else if (i == contactsSortRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("SortBy", R.string.SortBy));
builder.setItems(new CharSequence[] {
LocaleController.getString("Default", R.string.Default),
LocaleController.getString("SortFirstName", R.string.SortFirstName),
LocaleController.getString("SortLastName", R.string.SortLastName)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("sortContactsBy", which);
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == wifiDownloadRow || i == mobileDownloadRow || i == roamingDownloadRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
int mask = 0;
if (i == mobileDownloadRow) {
builder.setTitle(LocaleController.getString("WhenUsingMobileData", R.string.WhenUsingMobileData));
mask = MediaController.getInstance().mobileDataDownloadMask;
} else if (i == wifiDownloadRow) {
builder.setTitle(LocaleController.getString("WhenConnectedOnWiFi", R.string.WhenConnectedOnWiFi));
mask = MediaController.getInstance().wifiDownloadMask;
} else if (i == roamingDownloadRow) {
builder.setTitle(LocaleController.getString("WhenRoaming", R.string.WhenRoaming));
mask = MediaController.getInstance().roamingDownloadMask;
}
builder.setMultiChoiceItems(
new CharSequence[]{LocaleController.getString("AttachPhoto", R.string.AttachPhoto), LocaleController.getString("AttachAudio", R.string.AttachAudio), LocaleController.getString("AttachVideo", R.string.AttachVideo), LocaleController.getString("AttachDocument", R.string.AttachDocument)},
new boolean[]{(mask & MediaController.AUTODOWNLOAD_MASK_PHOTO) != 0, (mask & MediaController.AUTODOWNLOAD_MASK_AUDIO) != 0, (mask & MediaController.AUTODOWNLOAD_MASK_VIDEO) != 0, (mask & MediaController.AUTODOWNLOAD_MASK_DOCUMENT) != 0},
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
int mask = 0;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (i == mobileDownloadRow) {
mask = MediaController.getInstance().mobileDataDownloadMask;
} else if (i == wifiDownloadRow) {
mask = MediaController.getInstance().wifiDownloadMask;
} else if (i == roamingDownloadRow) {
mask = MediaController.getInstance().roamingDownloadMask;
}
int maskDiff = 0;
if (which == 0) {
maskDiff = MediaController.AUTODOWNLOAD_MASK_PHOTO;
} else if (which == 1) {
maskDiff = MediaController.AUTODOWNLOAD_MASK_AUDIO;
} else if (which == 2) {
maskDiff = MediaController.AUTODOWNLOAD_MASK_VIDEO;
} else if (which == 3) {
maskDiff = MediaController.AUTODOWNLOAD_MASK_DOCUMENT;
}
if (isChecked) {
mask |= maskDiff;
} else {
mask &= ~maskDiff;
}
if (i == mobileDownloadRow) {
editor.putInt("mobileDataDownloadMask", mask);
mask = MediaController.getInstance().mobileDataDownloadMask = mask;
} else if (i == wifiDownloadRow) {
editor.putInt("wifiDownloadMask", mask);
MediaController.getInstance().wifiDownloadMask = mask;
} else if (i == roamingDownloadRow) {
editor.putInt("roamingDownloadMask", mask);
MediaController.getInstance().roamingDownloadMask = mask;
}
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
}
});
builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), null);
showAlertDialog(builder);
} else if (i == usernameRow) {
presentFragment(new ChangeUsernameActivity());
} else if (i == numberRow) {
presentFragment(new ChangePhoneHelpActivity());
}
}
});
frameLayout.addView(actionBar);
writeButton = new ImageView(getParentActivity());
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));
writeButton.setStateListAnimator(animator);
writeButton.setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
}
});
}
frameLayout.addView(writeButton);
layoutParams = (FrameLayout.LayoutParams) writeButton.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 0);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 16);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT);
writeButton.setLayoutParams(layoutParams);
writeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
});
nameTextView = new TextView(context);
nameTextView.setTextColor(0xffffffff);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
nameTextView.setLines(1);
nameTextView.setMaxLines(1);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
actionBar.addView(nameTextView);
layoutParams = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 97);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 97 : 16);
layoutParams.bottomMargin = AndroidUtilities.dp(51);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
nameTextView.setLayoutParams(layoutParams);
onlineTextView = new TextView(context);
onlineTextView.setTextColor(AvatarDrawable.getProfileTextColorForId(5));
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
onlineTextView.setLines(1);
onlineTextView.setMaxLines(1);
onlineTextView.setSingleLine(true);
onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
onlineTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
actionBar.addView(onlineTextView);
layoutParams = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 97);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 97 : 16);
layoutParams.bottomMargin = AndroidUtilities.dp(30);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
onlineTextView.setLayoutParams(layoutParams);
listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
AndroidUtilities.setListViewEdgeEffectColor(listView, AvatarDrawable.getProfileBackColorForId(5));
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 == textSizeRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("TextSize", R.string.TextSize));
final NumberPicker numberPicker = new NumberPicker(getParentActivity());
numberPicker.setMinValue(12);
numberPicker.setMaxValue(30);
numberPicker.setValue(MessagesController.getInstance().fontSize);
builder.setView(numberPicker);
builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("fons_size", numberPicker.getValue());
MessagesController.getInstance().fontSize = numberPicker.getValue();
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
}
});
showAlertDialog(builder);
} else if (i == enableAnimationsRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean animations = preferences.getBoolean("view_animations", true);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("view_animations", !animations);
editor.commit();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(!animations);
}
} else if (i == notificationRow) {
presentFragment(new NotificationsSettingsActivity());
} else if (i == backgroundRow) {
presentFragment(new WallpapersActivity());
} else if (i == askQuestionRow) {
if (getParentActivity() == null) {
return;
}
final TextView message = new TextView(getParentActivity());
message.setText(Html.fromHtml(LocaleController.getString("AskAQuestionInfo", R.string.AskAQuestionInfo)));
message.setTextSize(18);
message.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(5), AndroidUtilities.dp(8), AndroidUtilities.dp(6));
message.setMovementMethod(new LinkMovementMethodMy());
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setView(message);
builder.setPositiveButton(LocaleController.getString("AskButton", R.string.AskButton), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
performAskAQuestion();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == sendLogsRow) {
sendLogs();
} else if (i == clearLogsRow) {
FileLog.cleanupLogs();
} else if (i == sendByEnterRow) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean send = preferences.getBoolean("send_by_enter", false);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("send_by_enter", !send);
editor.commit();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(!send);
}
} else if (i == saveToGalleryRow) {
MediaController.getInstance().toggleSaveToGallery();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(MediaController.getInstance().canSaveToGallery());
}
} else if (i == privacyRow) {
presentFragment(new PrivacySettingsActivity());
} else if (i == languageRow) {
presentFragment(new LanguageSelectActivity());
} else if (i == switchBackendButtonRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure));
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ConnectionsManager.getInstance().switchBackend();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == telegramFaqRow) {
try {
Intent pickIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl)));
getParentActivity().startActivityForResult(pickIntent, 500);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else if (i == contactsReimportRow) {
} else if (i == contactsSortRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("SortBy", R.string.SortBy));
builder.setItems(new CharSequence[]{
LocaleController.getString("Default", R.string.Default),
LocaleController.getString("SortFirstName", R.string.SortFirstName),
LocaleController.getString("SortLastName", R.string.SortLastName)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("sortContactsBy", which);
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (i == wifiDownloadRow || i == mobileDownloadRow || i == roamingDownloadRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items;
int mask = 0;
if (i == mobileDownloadRow) {
builder.setTitle(LocaleController.getString("WhenUsingMobileData", R.string.WhenUsingMobileData));
mask = MediaController.getInstance().mobileDataDownloadMask;
} else if (i == wifiDownloadRow) {
builder.setTitle(LocaleController.getString("WhenConnectedOnWiFi", R.string.WhenConnectedOnWiFi));
mask = MediaController.getInstance().wifiDownloadMask;
} else if (i == roamingDownloadRow) {
builder.setTitle(LocaleController.getString("WhenRoaming", R.string.WhenRoaming));
mask = MediaController.getInstance().roamingDownloadMask;
}
builder.setMultiChoiceItems(
new CharSequence[]{LocaleController.getString("AttachPhoto", R.string.AttachPhoto), LocaleController.getString("AttachAudio", R.string.AttachAudio), LocaleController.getString("AttachVideo", R.string.AttachVideo), LocaleController.getString("AttachDocument", R.string.AttachDocument)},
new boolean[]{(mask & MediaController.AUTODOWNLOAD_MASK_PHOTO) != 0, (mask & MediaController.AUTODOWNLOAD_MASK_AUDIO) != 0, (mask & MediaController.AUTODOWNLOAD_MASK_VIDEO) != 0, (mask & MediaController.AUTODOWNLOAD_MASK_DOCUMENT) != 0},
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
int mask = 0;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (i == mobileDownloadRow) {
mask = MediaController.getInstance().mobileDataDownloadMask;
} else if (i == wifiDownloadRow) {
mask = MediaController.getInstance().wifiDownloadMask;
} else if (i == roamingDownloadRow) {
mask = MediaController.getInstance().roamingDownloadMask;
}
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
if (user == null) {
user = UserConfig.getCurrentUser();
}
if (user == null) {
return;
}
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)};
fullMenu = true;
} else {
items = new CharSequence[] {LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley)};
}
int maskDiff = 0;
if (which == 0) {
maskDiff = MediaController.AUTODOWNLOAD_MASK_PHOTO;
} else if (which == 1) {
maskDiff = MediaController.AUTODOWNLOAD_MASK_AUDIO;
} else if (which == 2) {
maskDiff = MediaController.AUTODOWNLOAD_MASK_VIDEO;
} else if (which == 3) {
maskDiff = MediaController.AUTODOWNLOAD_MASK_DOCUMENT;
}
final boolean full = fullMenu;
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
avatarUpdater.openCamera();
} else if (i == 1) {
avatarUpdater.openGallery();
} else if (i == 2) {
MessagesController.getInstance().deleteUserPhoto(null);
}
}
});
if (isChecked) {
mask |= maskDiff;
} else {
mask &= ~maskDiff;
}
if (i == mobileDownloadRow) {
editor.putInt("mobileDataDownloadMask", mask);
mask = MediaController.getInstance().mobileDataDownloadMask = mask;
} else if (i == wifiDownloadRow) {
editor.putInt("wifiDownloadMask", mask);
MediaController.getInstance().wifiDownloadMask = mask;
} else if (i == roamingDownloadRow) {
editor.putInt("roamingDownloadMask", mask);
MediaController.getInstance().roamingDownloadMask = mask;
}
editor.commit();
if (listView != null) {
listView.invalidateViews();
}
}
});
builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), null);
showAlertDialog(builder);
} else if (i == usernameRow) {
presentFragment(new ChangeUsernameActivity());
} else if (i == numberRow) {
presentFragment(new ChangePhoneHelpActivity());
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (totalItemCount == 0) {
return;
}
int height = 0;
View child = view.getChildAt(0);
if (child != null) {
if (firstVisibleItem == 0) {
height = AndroidUtilities.dp(88) + (child.getTop() < 0 ? child.getTop() : 0);
}
if (actionBar.getExtraHeight() != height) {
actionBar.setExtraHeight(height, true);
needLayout();
}
}
}
});
updateUserData();
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
});
frameLayout.addView(actionBar);
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));
writeButton.setStateListAnimator(animator);
writeButton.setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
}
});
}
frameLayout.addView(writeButton);
layoutParams = (FrameLayout.LayoutParams) writeButton.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 0);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 16);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT);
writeButton.setLayoutParams(layoutParams);
writeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items;
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
if (user == null) {
user = UserConfig.getCurrentUser();
}
if (user == null) {
return;
}
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)};
fullMenu = true;
} else {
items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley)};
}
final boolean full = fullMenu;
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
avatarUpdater.openCamera();
} else if (i == 1) {
avatarUpdater.openGallery();
} else if (i == 2) {
MessagesController.getInstance().deleteUserPhoto(null);
}
}
});
showAlertDialog(builder);
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (totalItemCount == 0) {
return;
}
int height = 0;
View child = view.getChildAt(0);
if (child != null) {
if (firstVisibleItem == 0) {
height = AndroidUtilities.dp(88) + (child.getTop() < 0 ? child.getTop() : 0);
}
if (actionBar.getExtraHeight() != height) {
actionBar.setExtraHeight(height, true);
needLayout();
}
}
}
});
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,189 +224,183 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackgroundColor(0xff333333);
actionBar.setItemsBackground(R.drawable.bar_selector_white);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle(LocaleController.getString("EditVideo", R.string.EditVideo));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == 1) {
synchronized (sync) {
if (videoPlayer != null) {
try {
videoPlayer.stop();
videoPlayer.release();
videoPlayer = null;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
public View createView(Context context, LayoutInflater inflater) {
actionBar.setBackgroundColor(0xff333333);
actionBar.setItemsBackground(R.drawable.bar_selector_white);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle(LocaleController.getString("EditVideo", R.string.EditVideo));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == 1) {
synchronized (sync) {
if (videoPlayer != null) {
try {
videoPlayer.stop();
videoPlayer.release();
videoPlayer = null;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
if (delegate != null) {
if (compressVideo.getVisibility() == View.GONE || compressVideo.getVisibility() == View.VISIBLE && !compressVideo.isChecked()) {
delegate.didFinishEditVideo(videoPath, startTime, endTime, originalWidth, originalHeight, rotationValue, originalWidth, originalHeight, bitrate, estimatedSize, esimatedDuration);
} else {
delegate.didFinishEditVideo(videoPath, startTime, endTime, resultWidth, resultHeight, rotationValue, originalWidth, originalHeight, bitrate, estimatedSize, esimatedDuration);
}
}
finishFragment();
}
if (delegate != null) {
if (compressVideo.getVisibility() == View.GONE || compressVideo.getVisibility() == View.VISIBLE && !compressVideo.isChecked()) {
delegate.didFinishEditVideo(videoPath, startTime, endTime, originalWidth, originalHeight, rotationValue, originalWidth, originalHeight, bitrate, estimatedSize, esimatedDuration);
} else {
delegate.didFinishEditVideo(videoPath, startTime, endTime, resultWidth, resultHeight, rotationValue, originalWidth, originalHeight, bitrate, estimatedSize, esimatedDuration);
}
}
finishFragment();
}
});
}
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(1, R.drawable.ic_done, AndroidUtilities.dp(56));
ActionBarMenu menu = actionBar.createMenu();
menu.addItemWithWidth(1, R.drawable.ic_done, AndroidUtilities.dp(56));
fragmentView = inflater.inflate(R.layout.video_editor_layout, null, false);
originalSizeTextView = (TextView) fragmentView.findViewById(R.id.original_size);
editedSizeTextView = (TextView) fragmentView.findViewById(R.id.edited_size);
videoContainerView = fragmentView.findViewById(R.id.video_container);
textContainerView = fragmentView.findViewById(R.id.info_container);
controlView = fragmentView.findViewById(R.id.control_layout);
compressVideo = (CheckBox) fragmentView.findViewById(R.id.compress_video);
compressVideo.setText(LocaleController.getString("CompressVideo", R.string.CompressVideo));
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
compressVideo.setVisibility(originalHeight != resultHeight || originalWidth != resultWidth ? View.VISIBLE : View.GONE);
compressVideo.setChecked(preferences.getBoolean("compress_video", true));
compressVideo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("compress_video", isChecked);
editor.commit();
updateVideoEditedInfo();
}
});
fragmentView = inflater.inflate(R.layout.video_editor_layout, null, false);
originalSizeTextView = (TextView) fragmentView.findViewById(R.id.original_size);
editedSizeTextView = (TextView) fragmentView.findViewById(R.id.edited_size);
videoContainerView = fragmentView.findViewById(R.id.video_container);
textContainerView = fragmentView.findViewById(R.id.info_container);
controlView = fragmentView.findViewById(R.id.control_layout);
compressVideo = (CheckBox) fragmentView.findViewById(R.id.compress_video);
compressVideo.setText(LocaleController.getString("CompressVideo", R.string.CompressVideo));
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
compressVideo.setVisibility(originalHeight != resultHeight || originalWidth != resultWidth ? View.VISIBLE : View.GONE);
compressVideo.setChecked(preferences.getBoolean("compress_video", true));
compressVideo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("compress_video", isChecked);
editor.commit();
updateVideoEditedInfo();
}
});
if (Build.VERSION.SDK_INT < 18) {
try {
MediaCodecInfo codecInfo = MediaController.selectCodec(MediaController.MIME_TYPE);
if (codecInfo == null) {
if (Build.VERSION.SDK_INT < 18) {
try {
MediaCodecInfo codecInfo = MediaController.selectCodec(MediaController.MIME_TYPE);
if (codecInfo == null) {
compressVideo.setVisibility(View.GONE);
} else {
String name = codecInfo.getName();
if (name.equals("OMX.google.h264.encoder") ||
name.equals("OMX.ST.VFM.H264Enc") ||
name.equals("OMX.Exynos.avc.enc") ||
name.equals("OMX.MARVELL.VIDEO.HW.CODA7542ENCODER") ||
name.equals("OMX.MARVELL.VIDEO.H264ENCODER") ||
name.equals("OMX.k3.video.encoder.avc") || //fix this later
name.equals("OMX.TI.DUCATI1.VIDEO.H264E")) { //fix this later
compressVideo.setVisibility(View.GONE);
} else {
String name = codecInfo.getName();
if (name.equals("OMX.google.h264.encoder") ||
name.equals("OMX.ST.VFM.H264Enc") ||
name.equals("OMX.Exynos.avc.enc") ||
name.equals("OMX.MARVELL.VIDEO.HW.CODA7542ENCODER") ||
name.equals("OMX.MARVELL.VIDEO.H264ENCODER") ||
name.equals("OMX.k3.video.encoder.avc") || //fix this later
name.equals("OMX.TI.DUCATI1.VIDEO.H264E")) { //fix this later
if (MediaController.selectColorFormat(codecInfo, MediaController.MIME_TYPE) == 0) {
compressVideo.setVisibility(View.GONE);
} else {
if (MediaController.selectColorFormat(codecInfo, MediaController.MIME_TYPE) == 0) {
compressVideo.setVisibility(View.GONE);
}
}
}
} catch (Exception e) {
compressVideo.setVisibility(View.GONE);
FileLog.e("tmessages", e);
}
}
TextView titleTextView = (TextView) fragmentView.findViewById(R.id.original_title);
titleTextView.setText(LocaleController.getString("OriginalVideo", R.string.OriginalVideo));
titleTextView = (TextView) fragmentView.findViewById(R.id.edited_title);
titleTextView.setText(LocaleController.getString("EditedVideo", R.string.EditedVideo));
videoTimelineView = (VideoTimelineView) fragmentView.findViewById(R.id.video_timeline_view);
videoTimelineView.setVideoPath(videoPath);
videoTimelineView.setDelegate(new VideoTimelineView.VideoTimelineViewDelegate() {
@Override
public void onLeftProgressChanged(float progress) {
if (videoPlayer == null || !playerPrepared) {
return;
}
try {
if (videoPlayer.isPlaying()) {
videoPlayer.pause();
playButton.setImageResource(R.drawable.video_play);
}
videoPlayer.setOnSeekCompleteListener(null);
videoPlayer.seekTo((int) (videoDuration * progress));
} catch (Exception e) {
FileLog.e("tmessages", e);
}
needSeek = true;
videoSeekBarView.setProgress(videoTimelineView.getLeftProgress());
updateVideoEditedInfo();
}
@Override
public void onRifhtProgressChanged(float progress) {
if (videoPlayer == null || !playerPrepared) {
return;
}
try {
if (videoPlayer.isPlaying()) {
videoPlayer.pause();
playButton.setImageResource(R.drawable.video_play);
}
videoPlayer.setOnSeekCompleteListener(null);
videoPlayer.seekTo((int) (videoDuration * progress));
} catch (Exception e) {
FileLog.e("tmessages", e);
}
needSeek = true;
videoSeekBarView.setProgress(videoTimelineView.getLeftProgress());
updateVideoEditedInfo();
}
});
videoSeekBarView = (VideoSeekBarView) fragmentView.findViewById(R.id.video_seekbar);
videoSeekBarView.delegate = new VideoSeekBarView.SeekBarDelegate() {
@Override
public void onSeekBarDrag(float progress) {
if (progress < videoTimelineView.getLeftProgress()) {
progress = videoTimelineView.getLeftProgress();
videoSeekBarView.setProgress(progress);
} else if (progress > videoTimelineView.getRightProgress()) {
progress = videoTimelineView.getRightProgress();
videoSeekBarView.setProgress(progress);
}
if (videoPlayer == null || !playerPrepared) {
return;
}
if (videoPlayer.isPlaying()) {
try {
videoPlayer.seekTo((int) (videoDuration * progress));
lastProgress = progress;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else {
lastProgress = progress;
needSeek = true;
}
}
};
playButton = (ImageView) fragmentView.findViewById(R.id.play_button);
playButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
play();
}
});
textureView = (TextureView) fragmentView.findViewById(R.id.video_view);
textureView.setSurfaceTextureListener(this);
updateVideoOriginalInfo();
updateVideoEditedInfo();
} else {
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
} catch (Exception e) {
compressVideo.setVisibility(View.GONE);
FileLog.e("tmessages", e);
}
}
TextView titleTextView = (TextView) fragmentView.findViewById(R.id.original_title);
titleTextView.setText(LocaleController.getString("OriginalVideo", R.string.OriginalVideo));
titleTextView = (TextView) fragmentView.findViewById(R.id.edited_title);
titleTextView.setText(LocaleController.getString("EditedVideo", R.string.EditedVideo));
videoTimelineView = (VideoTimelineView) fragmentView.findViewById(R.id.video_timeline_view);
videoTimelineView.setVideoPath(videoPath);
videoTimelineView.setDelegate(new VideoTimelineView.VideoTimelineViewDelegate() {
@Override
public void onLeftProgressChanged(float progress) {
if (videoPlayer == null || !playerPrepared) {
return;
}
try {
if (videoPlayer.isPlaying()) {
videoPlayer.pause();
playButton.setImageResource(R.drawable.video_play);
}
videoPlayer.setOnSeekCompleteListener(null);
videoPlayer.seekTo((int) (videoDuration * progress));
} catch (Exception e) {
FileLog.e("tmessages", e);
}
needSeek = true;
videoSeekBarView.setProgress(videoTimelineView.getLeftProgress());
updateVideoEditedInfo();
}
@Override
public void onRifhtProgressChanged(float progress) {
if (videoPlayer == null || !playerPrepared) {
return;
}
try {
if (videoPlayer.isPlaying()) {
videoPlayer.pause();
playButton.setImageResource(R.drawable.video_play);
}
videoPlayer.setOnSeekCompleteListener(null);
videoPlayer.seekTo((int) (videoDuration * progress));
} catch (Exception e) {
FileLog.e("tmessages", e);
}
needSeek = true;
videoSeekBarView.setProgress(videoTimelineView.getLeftProgress());
updateVideoEditedInfo();
}
});
videoSeekBarView = (VideoSeekBarView) fragmentView.findViewById(R.id.video_seekbar);
videoSeekBarView.delegate = new VideoSeekBarView.SeekBarDelegate() {
@Override
public void onSeekBarDrag(float progress) {
if (progress < videoTimelineView.getLeftProgress()) {
progress = videoTimelineView.getLeftProgress();
videoSeekBarView.setProgress(progress);
} else if (progress > videoTimelineView.getRightProgress()) {
progress = videoTimelineView.getRightProgress();
videoSeekBarView.setProgress(progress);
}
if (videoPlayer == null || !playerPrepared) {
return;
}
if (videoPlayer.isPlaying()) {
try {
videoPlayer.seekTo((int) (videoDuration * progress));
lastProgress = progress;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else {
lastProgress = progress;
needSeek = true;
}
}
};
playButton = (ImageView) fragmentView.findViewById(R.id.play_button);
playButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
play();
}
});
textureView = (TextureView) fragmentView.findViewById(R.id.video_view);
textureView.setSurfaceTextureListener(this);
updateVideoOriginalInfo();
updateVideoEditedInfo();
return fragmentView;
}

View file

@ -101,120 +101,114 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
}
@Override
public View createView(LayoutInflater inflater) {
if (fragmentView == null) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("ChatBackground", R.string.ChatBackground));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
boolean done;
TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground);
if (wallPaper != null && wallPaper.id != 1000001 && wallPaper instanceof TLRPC.TL_wallPaper) {
int width = AndroidUtilities.displaySize.x;
int height = AndroidUtilities.displaySize.y;
if (width > height) {
int temp = width;
width = height;
height = temp;
}
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, Math.min(width, height));
String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
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));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
boolean done;
TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground);
if (wallPaper != null && wallPaper.id != 1000001 && wallPaper instanceof TLRPC.TL_wallPaper) {
int width = AndroidUtilities.displaySize.x;
int height = AndroidUtilities.displaySize.y;
if (width > height) {
int temp = width;
width = height;
height = temp;
}
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, Math.min(width, height));
String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
try {
done = Utilities.copyFile(f, toFile);
} catch (Exception e) {
done = false;
FileLog.e("tmessages", e);
}
} else {
if (selectedBackground == -1) {
File fromFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg");
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
done = fromFile.renameTo(toFile);
} else {
done = true;
}
}
if (done) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("selectedBackground", selectedBackground);
editor.putInt("selectedColor", selectedColor);
editor.commit();
ApplicationLoader.reloadWallpaper();
}
finishFragment();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
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(context);
progressBar = (ProgressBar) fragmentView.findViewById(R.id.action_progress);
backgroundImage = (ImageView) fragmentView.findViewById(R.id.background_image);
listView = (HorizontalListView) fragmentView.findViewById(R.id.listView);
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i == 0) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items = new CharSequence[]{LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("Cancel", R.string.Cancel)};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
try {
done = Utilities.copyFile(f, toFile);
if (i == 0) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File image = Utilities.generatePicturePath();
if (image != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
currentPicturePath = image.getAbsolutePath();
}
startActivityForResult(takePictureIntent, 10);
} else if (i == 1) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 11);
}
} catch (Exception e) {
done = false;
FileLog.e("tmessages", e);
}
} else {
if (selectedBackground == -1) {
File fromFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg");
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
done = fromFile.renameTo(toFile);
} else {
done = true;
}
}
if (done) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("selectedBackground", selectedBackground);
editor.putInt("selectedColor", selectedColor);
editor.commit();
ApplicationLoader.reloadWallpaper();
}
finishFragment();
}
});
showAlertDialog(builder);
} else {
TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
selectedBackground = wallPaper.id;
listAdapter.notifyDataSetChanged();
processSelectedBackground();
}
});
ActionBarMenu menu = actionBar.createMenu();
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());
progressBar = (ProgressBar)fragmentView.findViewById(R.id.action_progress);
backgroundImage = (ImageView)fragmentView.findViewById(R.id.background_image);
listView = (HorizontalListView)fragmentView.findViewById(R.id.listView);
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (i == 0) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items = new CharSequence[] {LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("Cancel", R.string.Cancel)};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
try {
if (i == 0) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File image = Utilities.generatePicturePath();
if (image != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
currentPicturePath = image.getAbsolutePath();
}
startActivityForResult(takePictureIntent, 10);
} else if (i == 1) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 11);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
showAlertDialog(builder);
} else {
TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
selectedBackground = wallPaper.id;
listAdapter.notifyDataSetChanged();
processSelectedBackground();
}
}
});
processSelectedBackground();
} else {
ViewGroup parent = (ViewGroup)fragmentView.getParent();
if (parent != null) {
parent.removeView(fragmentView);
}
}
});
processSelectedBackground();
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