Update to 2.4.0

This commit is contained in:
DrKLO 2015-02-01 21:51:02 +03:00
parent 2fcef37b9e
commit dff666fca1
227 changed files with 10202 additions and 3920 deletions

View File

@ -82,7 +82,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
versionCode 416
versionName "2.3.3"
versionCode 423
versionName "2.4.0"
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -149,6 +149,7 @@
<service android:name="org.telegram.android.NotificationsService" android:enabled="true"/>
<service android:name="org.telegram.android.NotificationRepeat" android:exported="false"/>
<service android:name="org.telegram.android.NotificationDelay" android:exported="false"/>
<service android:name="org.telegram.android.VideoEncodingService" android:enabled="true"/>
<receiver android:name="org.telegram.android.AppStartReceiver" android:enabled="true">

View File

@ -27,33 +27,49 @@ import org.telegram.messenger.TLRPC;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.Utilities;
public class ImageReceiver {
private TLObject last_path = null;
private String last_httpUrl = null;
private String last_filter = null;
private Drawable last_placeholder = null;
private TLRPC.FileLocation last_placeholderLocation = null;
private int last_size = 0;
private String currentPath = null;
private boolean isPlaceholder = false;
private Drawable currentImage = null;
private Integer tag = null;
private View parentView = null;
private int imageX = 0, imageY = 0, imageW = 0, imageH = 0;
public class ImageReceiver implements NotificationCenter.NotificationCenterDelegate {
public static interface ImageReceiverDelegate {
public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb);
}
private View parentView;
private Integer tag;
private Integer thumbTag;
private MessageObject parentMessageObject;
private boolean canceledLoading;
private TLObject currentImageLocation;
private String currentKey;
private String currentThumbKey;
private String currentHttpUrl;
private String currentFilter;
private String currentThumbFilter;
private TLRPC.FileLocation currentThumbLocation;
private int currentSize;
private boolean currentCacheOnly;
private BitmapDrawable currentImage;
private BitmapDrawable currentThumb;
private Drawable staticThumb;
private boolean needsQualityThumb;
private boolean shouldGenerateQualityThumb;
private int imageX, imageY, imageW, imageH;
private Rect drawRegion = new Rect();
private boolean isVisible = true;
private boolean isAspectFit = false;
private boolean lastCacheOnly = false;
private boolean forcePreview = false;
private int roundRadius = 0;
private BitmapShader bitmapShader = null;
private Paint roundPaint = null;
private RectF roundRect = null;
private RectF bitmapRect = null;
private Matrix shaderMatrix = null;
private boolean isAspectFit;
private boolean forcePreview;
private int roundRadius;
private BitmapShader bitmapShader;
private Paint roundPaint;
private RectF roundRect;
private RectF bitmapRect;
private Matrix shaderMatrix;
private int alpha = 255;
private boolean isPressed;
private boolean disableRecycle;
private ImageReceiverDelegate delegate;
public ImageReceiver() {
@ -63,38 +79,64 @@ public class ImageReceiver {
parentView = view;
}
public void setImage(TLObject path, String filter, Drawable placeholder, boolean cacheOnly) {
setImage(path, null, filter, placeholder, null, 0, cacheOnly);
public void cancelLoadImage() {
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, 0);
canceledLoading = true;
}
public void setImage(TLObject path, String filter, Drawable placeholder, int size, boolean cacheOnly) {
setImage(path, null, filter, placeholder, null, size, cacheOnly);
public void setImage(TLObject path, String filter, Drawable thumb, boolean cacheOnly) {
setImage(path, null, filter, thumb, null, null, 0, cacheOnly);
}
public void setImage(String path, String filter, Drawable placeholder, int size) {
setImage(null, path, filter, placeholder, null, size, true);
public void setImage(TLObject path, String filter, Drawable thumb, int size, boolean cacheOnly) {
setImage(path, null, filter, thumb, null, null, size, cacheOnly);
}
public void setImage(TLObject fileLocation, String httpUrl, String filter, Drawable placeholder, TLRPC.FileLocation placeholderLocation, int size, boolean cacheOnly) {
if ((fileLocation == null && httpUrl == null) || (fileLocation != null && !(fileLocation instanceof TLRPC.TL_fileLocation) && !(fileLocation instanceof TLRPC.TL_fileEncryptedLocation) && !(fileLocation instanceof TLRPC.TL_document))) {
recycleBitmap(null);
currentPath = null;
isPlaceholder = true;
last_path = null;
last_httpUrl = null;
last_filter = null;
lastCacheOnly = false;
bitmapShader = null;
last_placeholder = placeholder;
last_placeholderLocation = placeholderLocation;
last_size = 0;
public void setImage(String httpUrl, String filter, Drawable thumb, int size) {
setImage(null, httpUrl, filter, thumb, null, null, size, true);
}
public void setImage(TLObject fileLocation, String filter, TLRPC.FileLocation thumbLocation, String thumbFilter, boolean cacheOnly) {
setImage(fileLocation, null, filter, null, thumbLocation, thumbFilter, 0, cacheOnly);
}
public void setImage(TLObject fileLocation, String filter, TLRPC.FileLocation thumbLocation, String thumbFilter, int size, boolean cacheOnly) {
setImage(fileLocation, null, filter, null, thumbLocation, thumbFilter, size, cacheOnly);
}
public void setImage(TLObject fileLocation, String httpUrl, String filter, Drawable thumb, TLRPC.FileLocation thumbLocation, String thumbFilter, int size, boolean cacheOnly) {
if ((fileLocation == null && httpUrl == null && thumbLocation == null)
|| (fileLocation != null && !(fileLocation instanceof TLRPC.TL_fileLocation)
&& !(fileLocation instanceof TLRPC.TL_fileEncryptedLocation)
&& !(fileLocation instanceof TLRPC.TL_document))) {
recycleBitmap(null, false);
recycleBitmap(null, true);
currentKey = null;
currentThumbKey = null;
currentThumbFilter = null;
currentImageLocation = null;
currentHttpUrl = null;
currentFilter = null;
currentCacheOnly = false;
staticThumb = thumb;
currentThumbLocation = null;
currentSize = 0;
currentImage = null;
ImageLoader.getInstance().cancelLoadingForImageView(this);
bitmapShader = null;
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, 0);
if (parentView != null) {
parentView.invalidate();
}
if (delegate != null) {
delegate.didSetImage(this, currentImage != null || currentThumb != null || staticThumb != null, currentImage == null);
}
return;
}
if (!(thumbLocation instanceof TLRPC.TL_fileLocation)) {
thumbLocation = null;
}
String key = null;
if (fileLocation != null) {
if (fileLocation instanceof TLRPC.FileLocation) {
@ -104,80 +146,61 @@ public class ImageReceiver {
TLRPC.Document location = (TLRPC.Document) fileLocation;
key = location.dc_id + "_" + location.id;
}
} else {
} else if (httpUrl != null) {
key = Utilities.MD5(httpUrl);
}
if (key != null) {
if (filter != null) {
key += "@" + filter;
}
boolean sameFile = false;
BitmapDrawable img = null;
if (currentPath != null) {
if (currentPath.equals(key)) {
sameFile = true;
if (currentImage != null) {
}
if (currentKey != null && key != null && currentKey.equals(key)) {
if (delegate != null) {
delegate.didSetImage(this, currentImage != null || currentThumb != null || staticThumb != null, currentImage == null);
}
if (!canceledLoading && !forcePreview) {
return;
} else {
img = ImageLoader.getInstance().getImageFromMemory(fileLocation, httpUrl, filter, this);
}
} else {
img = ImageLoader.getInstance().getImageFromMemory(fileLocation, httpUrl, filter, this);
recycleBitmap(img);
}
}
img = ImageLoader.getInstance().getImageFromMemory(fileLocation, httpUrl, filter, this);
currentPath = key;
last_path = fileLocation;
last_httpUrl = httpUrl;
last_filter = filter;
if (!sameFile) {
last_placeholder = placeholder;
last_placeholderLocation = placeholderLocation;
}
last_size = size;
lastCacheOnly = cacheOnly;
bitmapShader = null;
if (img == null) {
isPlaceholder = true;
if (!sameFile && last_placeholderLocation != null && last_placeholder == null) {
last_placeholder = ImageLoader.getInstance().getImageFromMemory(last_placeholderLocation, null, null, null);
if (last_placeholder != null) {
try {
Bitmap bitmap = ((BitmapDrawable) last_placeholder).getBitmap();
bitmap = bitmap.copy(bitmap.getConfig(), true);
Utilities.blurBitmap(bitmap, 1);
last_placeholder = new BitmapDrawable(bitmap);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
}
ImageLoader.getInstance().loadImage(fileLocation, httpUrl, this, size, cacheOnly);
if (parentView != null) {
parentView.invalidate();
}
} else {
setImageBitmap(img, currentPath);
}
}
public void setImageBitmap(BitmapDrawable bitmap, String imgKey) {
if (currentPath == null || !imgKey.equals(currentPath)) {
return;
String thumbKey = null;
if (thumbLocation != null) {
thumbKey = thumbLocation.volume_id + "_" + thumbLocation.local_id;
if (thumbFilter != null) {
thumbKey += "@" + thumbFilter;
}
isPlaceholder = false;
ImageLoader.getInstance().incrementUseCount(currentPath);
currentImage = bitmap;
if (roundRadius != 0) {
bitmapShader = new BitmapShader(bitmap.getBitmap(), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
roundPaint.setShader(bitmapShader);
bitmapRect.set(0, 0, bitmap.getBitmap().getWidth(), bitmap.getBitmap().getHeight());
}
recycleBitmap(key, false);
recycleBitmap(thumbKey, true);
currentThumbKey = thumbKey;
currentKey = key;
currentImageLocation = fileLocation;
currentHttpUrl = httpUrl;
currentFilter = filter;
currentThumbFilter = thumbFilter;
currentSize = size;
currentCacheOnly = cacheOnly;
currentThumbLocation = thumbLocation;
staticThumb = thumb;
bitmapShader = null;
if (delegate != null) {
delegate.didSetImage(this, currentImage != null || currentThumb != null || staticThumb != null, currentImage == null);
}
ImageLoader.getInstance().loadImageForImageReceiver(this);
if (parentView != null) {
parentView.invalidate();
}
}
public void setDelegate(ImageReceiverDelegate delegate) {
this.delegate = delegate;
}
public void setPressed(boolean value) {
isPressed = value;
}
@ -195,62 +218,50 @@ public class ImageReceiver {
}
public void setImageBitmap(Drawable bitmap) {
ImageLoader.getInstance().cancelLoadingForImageView(this);
recycleBitmap(null);
last_placeholder = bitmap;
isPlaceholder = true;
last_placeholderLocation = null;
currentPath = null;
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, 0);
recycleBitmap(null, false);
recycleBitmap(null, true);
staticThumb = bitmap;
currentThumbLocation = null;
currentKey = null;
currentThumbKey = null;
currentImage = null;
last_path = null;
last_httpUrl = null;
last_filter = null;
currentThumbFilter = null;
currentImageLocation = null;
currentHttpUrl = null;
currentFilter = null;
currentSize = 0;
currentCacheOnly = false;
bitmapShader = null;
last_size = 0;
lastCacheOnly = false;
if (delegate != null) {
delegate.didSetImage(this, currentImage != null || currentThumb != null || staticThumb != null, currentImage == null);
}
if (parentView != null) {
parentView.invalidate();
}
}
public void clearImage() {
recycleBitmap(null);
}
private void recycleBitmap(BitmapDrawable newBitmap) {
if (currentImage == null || isPlaceholder || disableRecycle) {
return;
}
if (currentImage instanceof BitmapDrawable) {
if (currentImage != newBitmap) {
if (currentPath != null) {
Bitmap bitmap = ((BitmapDrawable) currentImage).getBitmap();
boolean canDelete = ImageLoader.getInstance().decrementUseCount(currentPath);
if (!ImageLoader.getInstance().isInCache(currentPath)) {
if (ImageLoader.getInstance().runtimeHack != null) {
ImageLoader.getInstance().runtimeHack.trackAlloc(bitmap.getRowBytes() * bitmap.getHeight());
}
if (canDelete) {
currentImage = null;
bitmap.recycle();
}
} else {
currentImage = null;
}
currentPath = null;
}
}
recycleBitmap(null, false);
recycleBitmap(null, true);
if (needsQualityThumb) {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageThumbGenerated);
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, 0);
}
}
public boolean draw(Canvas canvas) {
try {
Drawable bitmapDrawable = currentImage;
if (forcePreview || bitmapDrawable == null && last_placeholder != null && last_placeholder instanceof BitmapDrawable) {
bitmapDrawable = last_placeholder;
BitmapDrawable bitmapDrawable = null;
if (!forcePreview && currentImage != null) {
bitmapDrawable = currentImage;
} else if (staticThumb instanceof BitmapDrawable) {
bitmapDrawable = (BitmapDrawable) staticThumb;
} else if (currentThumb != null) {
bitmapDrawable = currentThumb;
}
if (bitmapDrawable != null) {
Paint paint = ((BitmapDrawable) bitmapDrawable).getPaint();
Paint paint = bitmapDrawable.getPaint();
boolean hasFilter = paint != null && paint.getColorFilter() != null;
if (hasFilter && !isPressed) {
bitmapDrawable.setColorFilter(null);
@ -285,11 +296,14 @@ public class ImageReceiver {
bitmapDrawable.setAlpha(alpha);
bitmapDrawable.draw(canvas);
} catch (Exception e) {
if (currentPath != null) {
ImageLoader.getInstance().removeImage(currentPath);
currentPath = null;
if (bitmapDrawable == currentImage && currentKey != null) {
ImageLoader.getInstance().removeImage(currentKey);
currentKey = null;
} else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
ImageLoader.getInstance().removeImage(currentThumbKey);
currentThumbKey = null;
}
setImage(last_path, last_httpUrl, last_filter, last_placeholder, last_placeholderLocation, last_size, lastCacheOnly);
setImage(currentImageLocation, currentHttpUrl, currentFilter, currentThumb, currentThumbLocation, currentThumbFilter, currentSize, currentCacheOnly);
FileLog.e("tmessages", e);
}
canvas.restore();
@ -311,11 +325,14 @@ public class ImageReceiver {
bitmapDrawable.setAlpha(alpha);
bitmapDrawable.draw(canvas);
} catch (Exception e) {
if (currentPath != null) {
ImageLoader.getInstance().removeImage(currentPath);
currentPath = null;
if (bitmapDrawable == currentImage && currentKey != null) {
ImageLoader.getInstance().removeImage(currentKey);
currentKey = null;
} else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
ImageLoader.getInstance().removeImage(currentThumbKey);
currentThumbKey = null;
}
setImage(last_path, last_httpUrl, last_filter, last_placeholder, last_placeholderLocation, last_size, lastCacheOnly);
setImage(currentImageLocation, currentHttpUrl, currentFilter, currentThumb, currentThumbLocation, currentThumbFilter, currentSize, currentCacheOnly);
FileLog.e("tmessages", e);
}
}
@ -329,11 +346,14 @@ public class ImageReceiver {
bitmapDrawable.setAlpha(alpha);
bitmapDrawable.draw(canvas);
} catch (Exception e) {
if (currentPath != null) {
ImageLoader.getInstance().removeImage(currentPath);
currentPath = null;
if (bitmapDrawable == currentImage && currentKey != null) {
ImageLoader.getInstance().removeImage(currentKey);
currentKey = null;
} else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
ImageLoader.getInstance().removeImage(currentThumbKey);
currentThumbKey = null;
}
setImage(last_path, last_httpUrl, last_filter, last_placeholder, last_placeholderLocation, last_size, lastCacheOnly);
setImage(currentImageLocation, currentHttpUrl, currentFilter, currentThumb, currentThumbLocation, currentThumbFilter, currentSize, currentCacheOnly);
FileLog.e("tmessages", e);
}
}
@ -341,19 +361,14 @@ public class ImageReceiver {
}
}
return true;
} else if (last_placeholder != null) {
} else if (staticThumb != null) {
drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
last_placeholder.setBounds(drawRegion);
staticThumb.setBounds(drawRegion);
if (isVisible) {
try {
last_placeholder.setAlpha(alpha);
last_placeholder.draw(canvas);
staticThumb.setAlpha(alpha);
staticThumb.draw(canvas);
} catch (Exception e) {
if (currentPath != null) {
ImageLoader.getInstance().removeImage(currentPath);
currentPath = null;
}
setImage(last_path, last_httpUrl, last_filter, last_placeholder, last_placeholderLocation, last_size, lastCacheOnly);
FileLog.e("tmessages", e);
}
}
@ -366,10 +381,12 @@ public class ImageReceiver {
}
public Bitmap getBitmap() {
if (currentImage != null && currentImage instanceof BitmapDrawable) {
return ((BitmapDrawable)currentImage).getBitmap();
} else if (isPlaceholder && last_placeholder != null && last_placeholder instanceof BitmapDrawable) {
return ((BitmapDrawable)last_placeholder).getBitmap();
if (currentImage != null) {
return currentImage.getBitmap();
} else if (currentThumb != null) {
return currentThumb.getBitmap();
} else if (staticThumb instanceof BitmapDrawable) {
return ((BitmapDrawable) staticThumb).getBitmap();
}
return null;
}
@ -393,7 +410,7 @@ public class ImageReceiver {
}
public boolean hasImage() {
return currentImage != null || last_placeholder != null || currentPath != null || last_httpUrl != null;
return currentImage != null || currentThumb != null || currentKey != null || currentHttpUrl != null || staticThumb != null;
}
public void setAspectFit(boolean value) {
@ -404,14 +421,6 @@ public class ImageReceiver {
parentView = view;
}
protected Integer getTag() {
return tag;
}
protected void setTag(Integer tag) {
this.tag = tag;
}
public void setImageCoords(int x, int y, int width, int height) {
imageX = x;
imageY = y;
@ -444,17 +453,49 @@ public class ImageReceiver {
}
public String getFilter() {
return last_filter;
return currentFilter;
}
public String getThumbFilter() {
return currentThumbFilter;
}
public String getKey() {
return currentPath;
return currentKey;
}
public String getThumbKey() {
return currentThumbKey;
}
public int getSize() {
return currentSize;
}
public TLObject getImageLocation() {
return currentImageLocation;
}
public TLRPC.FileLocation getThumbLocation() {
return currentThumbLocation;
}
public String getHttpImageLocation() {
return currentHttpUrl;
}
public boolean getCacheOnly() {
return currentCacheOnly;
}
public void setForcePreview(boolean value) {
forcePreview = value;
}
public boolean isForcePreview() {
return forcePreview;
}
public void setRoundRadius(int value) {
roundRadius = value;
if (roundRadius != 0) {
@ -475,4 +516,146 @@ public class ImageReceiver {
public int getRoundRadius() {
return roundRadius;
}
public void setParentMessageObject(MessageObject messageObject) {
parentMessageObject = messageObject;
}
public MessageObject getParentMessageObject() {
return parentMessageObject;
}
public void setNeedsQualityThumb(boolean value) {
needsQualityThumb = value;
if (needsQualityThumb) {
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageThumbGenerated);
} else {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageThumbGenerated);
}
}
public boolean isNeedsQualityThumb() {
return needsQualityThumb;
}
public void setShouldGenerateQualityThumb(boolean value) {
shouldGenerateQualityThumb = value;
}
public boolean isShouldGenerateQualityThumb() {
return shouldGenerateQualityThumb;
}
protected Integer getTag(boolean thumb) {
if (thumb) {
return thumbTag;
} else {
return tag;
}
}
protected void setTag(Integer value, boolean thumb) {
if (thumb) {
thumbTag = value;
} else {
tag = value;
}
}
protected void setImageBitmapByKey(BitmapDrawable bitmap, String key, boolean thumb) {
if (bitmap == null || key == null) {
return;
}
if (!thumb) {
if (currentKey == null || !key.equals(currentKey)) {
return;
}
ImageLoader.getInstance().incrementUseCount(currentKey);
currentImage = bitmap;
if (roundRadius != 0 && bitmap instanceof BitmapDrawable) {
Bitmap object = bitmap.getBitmap();
bitmapShader = new BitmapShader(object, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
roundPaint.setShader(bitmapShader);
bitmapRect.set(0, 0, object.getWidth(), object.getHeight());
}
if (parentView != null) {
parentView.invalidate();
}
} else if (currentThumb == null && (currentImage == null || forcePreview)) {
if (currentThumbKey == null || !key.equals(currentThumbKey)) {
return;
}
ImageLoader.getInstance().incrementUseCount(currentThumbKey);
currentThumb = bitmap;
if (!(staticThumb instanceof BitmapDrawable) && parentView != null) {
parentView.invalidate();
}
}
if (delegate != null) {
delegate.didSetImage(this, currentImage != null || currentThumb != null || staticThumb != null, currentImage == null);
}
}
private void recycleBitmap(String newKey, boolean thumb) {
String key;
BitmapDrawable image;
if (thumb) {
if (currentThumb == null) {
return;
}
key = currentThumbKey;
image = currentThumb;
} else {
if (currentImage == null) {
return;
}
key = currentKey;
image = currentImage;
}
BitmapDrawable newBitmap = null;
if (newKey != null) {
newBitmap = ImageLoader.getInstance().getImageFromMemory(newKey);
}
if (key == null || image == null || image == newBitmap || disableRecycle) {
return;
}
Bitmap bitmap = image.getBitmap();
boolean canDelete = ImageLoader.getInstance().decrementUseCount(key);
if (!ImageLoader.getInstance().isInCache(key)) {
if (ImageLoader.getInstance().runtimeHack != null) {
ImageLoader.getInstance().runtimeHack.trackAlloc(bitmap.getRowBytes() * bitmap.getHeight());
}
if (canDelete) {
bitmap.recycle();
ImageLoader.getInstance().callGC();
}
}
if (thumb) {
currentThumb = null;
currentThumbKey = null;
} else {
currentImage = null;
currentKey = null;
}
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.messageThumbGenerated) {
String key = (String) args[1];
if (currentThumbKey != null && currentThumbKey.equals(key)) {
if (currentThumb == null) {
ImageLoader.getInstance().incrementUseCount(currentThumbKey);
}
currentThumb = (BitmapDrawable) args[0];
if (staticThumb instanceof BitmapDrawable) {
staticThumb = null;
}
if (parentView != null) {
parentView.invalidate();
}
}
}
}
}

View File

@ -58,17 +58,19 @@ public class LocaleController {
public static FastDateFormat chatDate;
public static FastDateFormat chatFullDate;
private HashMap<String, PluralRules> allRules = new HashMap<String, PluralRules>();
private HashMap<String, PluralRules> allRules = new HashMap<>();
private Locale currentLocale;
private Locale systemDefaultLocale;
private PluralRules currentPluralRules;
private LocaleInfo currentLocaleInfo;
private LocaleInfo defaultLocalInfo;
private HashMap<String, String> localeValues = new HashMap<String, String>();
private HashMap<String, String> localeValues = new HashMap<>();
private String languageOverride;
private boolean changingConfiguration = false;
private HashMap<String, String> translitChars;
private class TimeZoneChangedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
@ -110,10 +112,10 @@ public class LocaleController {
}
}
public ArrayList<LocaleInfo> sortedLanguages = new ArrayList<LocaleController.LocaleInfo>();
public HashMap<String, LocaleInfo> languagesDict = new HashMap<String, LocaleInfo>();
public ArrayList<LocaleInfo> sortedLanguages = new ArrayList<>();
public HashMap<String, LocaleInfo> languagesDict = new HashMap<>();
private ArrayList<LocaleInfo> otherLanguages = new ArrayList<LocaleInfo>();
private ArrayList<LocaleInfo> otherLanguages = new ArrayList<>();
private static volatile LocaleController Instance = null;
public static LocaleController getInstance() {
@ -442,7 +444,7 @@ public class LocaleController {
private HashMap<String, String> getLocaleFileStrings(File file) {
try {
HashMap<String, String> stringMap = new HashMap<String, String>();
HashMap<String, String> stringMap = new HashMap<>();
XmlPullParser parser = Xml.newPullParser();
parser.setInput(new FileInputStream(file), "UTF-8");
int eventType = parser.getEventType();
@ -818,6 +820,542 @@ public class LocaleController {
}
}
public String getTranslitString(String src) {
if (translitChars == null) {
translitChars = new HashMap<>(520);
translitChars.put("ȼ", "c");
translitChars.put("", "n");
translitChars.put("ɖ", "d");
translitChars.put("ỿ", "y");
translitChars.put("", "o");
translitChars.put("ø", "o");
translitChars.put("", "a");
translitChars.put("ʯ", "h");
translitChars.put("ŷ", "y");
translitChars.put("ʞ", "k");
translitChars.put("", "u");
translitChars.put("", "aa");
translitChars.put("ij", "ij");
translitChars.put("", "l");
translitChars.put("ɪ", "i");
translitChars.put("", "b");
translitChars.put("ʀ", "r");
translitChars.put("ě", "e");
translitChars.put("", "ffi");
translitChars.put("ơ", "o");
translitChars.put("", "r");
translitChars.put("", "o");
translitChars.put("ǐ", "i");
translitChars.put("", "p");
translitChars.put("ý", "y");
translitChars.put("", "e");
translitChars.put("", "o");
translitChars.put("", "a");
translitChars.put("ʙ", "b");
translitChars.put("", "e");
translitChars.put("ƈ", "c");
translitChars.put("ɦ", "h");
translitChars.put("", "b");
translitChars.put("", "s");
translitChars.put("đ", "d");
translitChars.put("", "o");
translitChars.put("ɟ", "j");
translitChars.put("", "a");
translitChars.put("ɏ", "y");
translitChars.put("л", "l");
translitChars.put("ʌ", "v");
translitChars.put("", "p");
translitChars.put("", "fi");
translitChars.put("", "k");
translitChars.put("", "d");
translitChars.put("", "l");
translitChars.put("ė", "e");
translitChars.put("ё", "yo");
translitChars.put("", "k");
translitChars.put("ċ", "c");
translitChars.put("ʁ", "r");
translitChars.put("ƕ", "hv");
translitChars.put("ƀ", "b");
translitChars.put("", "o");
translitChars.put("ȣ", "ou");
translitChars.put("ǰ", "j");
translitChars.put("", "g");
translitChars.put("", "n");
translitChars.put("ɉ", "j");
translitChars.put("ǧ", "g");
translitChars.put("dz", "dz");
translitChars.put("ź", "z");
translitChars.put("", "au");
translitChars.put("ǖ", "u");
translitChars.put("", "g");
translitChars.put("ȯ", "o");
translitChars.put("ɐ", "a");
translitChars.put("ą", "a");
translitChars.put("õ", "o");
translitChars.put("ɻ", "r");
translitChars.put("", "o");
translitChars.put("ǟ", "a");
translitChars.put("ȴ", "l");
translitChars.put("ʂ", "s");
translitChars.put("", "fl");
translitChars.put("ȉ", "i");
translitChars.put("", "e");
translitChars.put("", "n");
translitChars.put("ï", "i");
translitChars.put("ñ", "n");
translitChars.put("", "i");
translitChars.put("ʇ", "t");
translitChars.put("", "z");
translitChars.put("", "y");
translitChars.put("ȳ", "y");
translitChars.put("", "s");
translitChars.put("ɽ", "r");
translitChars.put("ĝ", "g");
translitChars.put("в", "v");
translitChars.put("", "u");
translitChars.put("", "k");
translitChars.put("", "et");
translitChars.put("ī", "i");
translitChars.put("ť", "t");
translitChars.put("", "c");
translitChars.put("ʟ", "l");
translitChars.put("", "av");
translitChars.put("û", "u");
translitChars.put("æ", "ae");
translitChars.put("и", "i");
translitChars.put("ă", "a");
translitChars.put("ǘ", "u");
translitChars.put("", "s");
translitChars.put("", "r");
translitChars.put("", "a");
translitChars.put("ƃ", "b");
translitChars.put("", "h");
translitChars.put("", "s");
translitChars.put("", "e");
translitChars.put("ʜ", "h");
translitChars.put("", "x");
translitChars.put("", "k");
translitChars.put("", "d");
translitChars.put("ƣ", "oi");
translitChars.put("", "p");
translitChars.put("ħ", "h");
translitChars.put("", "v");
translitChars.put("", "w");
translitChars.put("ǹ", "n");
translitChars.put("ɯ", "m");
translitChars.put("ɡ", "g");
translitChars.put("ɴ", "n");
translitChars.put("", "p");
translitChars.put("", "v");
translitChars.put("ū", "u");
translitChars.put("", "b");
translitChars.put("", "p");
translitChars.put("ь", "");
translitChars.put("å", "a");
translitChars.put("ɕ", "c");
translitChars.put("", "o");
translitChars.put("", "a");
translitChars.put("ƒ", "f");
translitChars.put("ǣ", "ae");
translitChars.put("", "vy");
translitChars.put("", "ff");
translitChars.put("", "r");
translitChars.put("ô", "o");
translitChars.put("ǿ", "o");
translitChars.put("", "u");
translitChars.put("ȥ", "z");
translitChars.put("", "f");
translitChars.put("", "d");
translitChars.put("ȇ", "e");
translitChars.put("ȕ", "u");
translitChars.put("п", "p");
translitChars.put("ȵ", "n");
translitChars.put("ʠ", "q");
translitChars.put("", "a");
translitChars.put("ǩ", "k");
translitChars.put("ĩ", "i");
translitChars.put("", "u");
translitChars.put("ŧ", "t");
translitChars.put("ɾ", "r");
translitChars.put("ƙ", "k");
translitChars.put("", "t");
translitChars.put("", "q");
translitChars.put("", "a");
translitChars.put("н", "n");
translitChars.put("ʄ", "j");
translitChars.put("ƚ", "l");
translitChars.put("", "f");
translitChars.put("д", "d");
translitChars.put("", "s");
translitChars.put("", "r");
translitChars.put("", "v");
translitChars.put("ɵ", "o");
translitChars.put("", "c");
translitChars.put("", "u");
translitChars.put("", "z");
translitChars.put("", "u");
translitChars.put("ň", "n");
translitChars.put("ʍ", "w");
translitChars.put("", "a");
translitChars.put("lj", "lj");
translitChars.put("ɓ", "b");
translitChars.put("ɼ", "r");
translitChars.put("ò", "o");
translitChars.put("", "w");
translitChars.put("ɗ", "d");
translitChars.put("", "ay");
translitChars.put("ư", "u");
translitChars.put("", "b");
translitChars.put("ǜ", "u");
translitChars.put("", "e");
translitChars.put("ǡ", "a");
translitChars.put("ɥ", "h");
translitChars.put("", "o");
translitChars.put("ǔ", "u");
translitChars.put("ʎ", "y");
translitChars.put("ȱ", "o");
translitChars.put("", "e");
translitChars.put("ế", "e");
translitChars.put("ĭ", "i");
translitChars.put("", "e");
translitChars.put("", "t");
translitChars.put("", "d");
translitChars.put("", "h");
translitChars.put("", "s");
translitChars.put("ë", "e");
translitChars.put("", "m");
translitChars.put("ö", "o");
translitChars.put("é", "e");
translitChars.put("ı", "i");
translitChars.put("ď", "d");
translitChars.put("", "m");
translitChars.put("", "y");
translitChars.put("я", "ya");
translitChars.put("ŵ", "w");
translitChars.put("", "e");
translitChars.put("", "u");
translitChars.put("ƶ", "z");
translitChars.put("ĵ", "j");
translitChars.put("", "d");
translitChars.put("ŭ", "u");
translitChars.put("ʝ", "j");
translitChars.put("ж", "zh");
translitChars.put("ê", "e");
translitChars.put("ǚ", "u");
translitChars.put("ġ", "g");
translitChars.put("", "r");
translitChars.put("ƞ", "n");
translitChars.put("ъ", "");
translitChars.put("", "e");
translitChars.put("", "s");
translitChars.put("", "d");
translitChars.put("ķ", "k");
translitChars.put("", "ae");
translitChars.put("ɘ", "e");
translitChars.put("", "o");
translitChars.put("ḿ", "m");
translitChars.put("", "f");
translitChars.put("а", "a");
translitChars.put("", "a");
translitChars.put("", "oo");
translitChars.put("", "m");
translitChars.put("", "p");
translitChars.put("ц", "ts");
translitChars.put("", "u");
translitChars.put("", "k");
translitChars.put("", "h");
translitChars.put("ţ", "t");
translitChars.put("", "p");
translitChars.put("", "m");
translitChars.put("á", "a");
translitChars.put("", "n");
translitChars.put("", "v");
translitChars.put("è", "e");
translitChars.put("", "z");
translitChars.put("", "d");
translitChars.put("", "p");
translitChars.put("м", "m");
translitChars.put("ɫ", "l");
translitChars.put("", "z");
translitChars.put("ɱ", "m");
translitChars.put("", "r");
translitChars.put("", "v");
translitChars.put("ũ", "u");
translitChars.put("ß", "ss");
translitChars.put("т", "t");
translitChars.put("ĥ", "h");
translitChars.put("", "t");
translitChars.put("ʐ", "z");
translitChars.put("", "r");
translitChars.put("ɲ", "n");
translitChars.put("à", "a");
translitChars.put("", "y");
translitChars.put("", "y");
translitChars.put("", "oe");
translitChars.put("ы", "i");
translitChars.put("", "x");
translitChars.put("ȗ", "u");
translitChars.put("", "j");
translitChars.put("", "a");
translitChars.put("ʑ", "z");
translitChars.put("", "s");
translitChars.put("", "i");
translitChars.put("", "ao");
translitChars.put("ɀ", "z");
translitChars.put("ÿ", "y");
translitChars.put("ǝ", "e");
translitChars.put("ǭ", "o");
translitChars.put("", "d");
translitChars.put("", "l");
translitChars.put("ù", "u");
translitChars.put("", "a");
translitChars.put("", "b");
translitChars.put("", "u");
translitChars.put("к", "k");
translitChars.put("", "a");
translitChars.put("", "t");
translitChars.put("ƴ", "y");
translitChars.put("", "t");
translitChars.put("з", "z");
translitChars.put("", "l");
translitChars.put("ȷ", "j");
translitChars.put("", "z");
translitChars.put("", "h");
translitChars.put("", "w");
translitChars.put("", "k");
translitChars.put("", "o");
translitChars.put("î", "i");
translitChars.put("ģ", "g");
translitChars.put("ȅ", "e");
translitChars.put("ȧ", "a");
translitChars.put("", "a");
translitChars.put("щ", "sch");
translitChars.put("ɋ", "q");
translitChars.put("", "t");
translitChars.put("", "um");
translitChars.put("", "c");
translitChars.put("", "x");
translitChars.put("", "u");
translitChars.put("", "i");
translitChars.put("", "r");
translitChars.put("ś", "s");
translitChars.put("", "o");
translitChars.put("", "y");
translitChars.put("", "s");
translitChars.put("nj", "nj");
translitChars.put("ȁ", "a");
translitChars.put("", "t");
translitChars.put("ĺ", "l");
translitChars.put("ž", "z");
translitChars.put("", "th");
translitChars.put("ƌ", "d");
translitChars.put("ș", "s");
translitChars.put("š", "s");
translitChars.put("", "u");
translitChars.put("", "e");
translitChars.put("", "s");
translitChars.put("ɇ", "e");
translitChars.put("", "u");
translitChars.put("", "o");
translitChars.put("ȿ", "s");
translitChars.put("", "v");
translitChars.put("", "is");
translitChars.put("", "o");
translitChars.put("ɛ", "e");
translitChars.put("ǻ", "a");
translitChars.put("", "ffl");
translitChars.put("", "o");
translitChars.put("ȋ", "i");
translitChars.put("", "ue");
translitChars.put("ȡ", "d");
translitChars.put("", "z");
translitChars.put("", "w");
translitChars.put("", "a");
translitChars.put("", "t");
translitChars.put("ğ", "g");
translitChars.put("ɳ", "n");
translitChars.put("ʛ", "g");
translitChars.put("", "u");
translitChars.put("ф", "f");
translitChars.put("", "a");
translitChars.put("", "n");
translitChars.put("ɨ", "i");
translitChars.put("", "r");
translitChars.put("ǎ", "a");
translitChars.put("ſ", "s");
translitChars.put("у", "u");
translitChars.put("ȫ", "o");
translitChars.put("ɿ", "r");
translitChars.put("ƭ", "t");
translitChars.put("", "i");
translitChars.put("ǽ", "ae");
translitChars.put("", "v");
translitChars.put("ɶ", "oe");
translitChars.put("", "m");
translitChars.put("ż", "z");
translitChars.put("ĕ", "e");
translitChars.put("", "av");
translitChars.put("", "o");
translitChars.put("", "e");
translitChars.put("ɬ", "l");
translitChars.put("", "i");
translitChars.put("", "d");
translitChars.put("", "st");
translitChars.put("", "l");
translitChars.put("ŕ", "r");
translitChars.put("", "ou");
translitChars.put("ʈ", "t");
translitChars.put("ā", "a");
translitChars.put("э", "e");
translitChars.put("", "e");
translitChars.put("", "o");
translitChars.put("ç", "c");
translitChars.put("", "s");
translitChars.put("", "a");
translitChars.put("ų", "u");
translitChars.put("", "a");
translitChars.put("ǥ", "g");
translitChars.put("р", "r");
translitChars.put("", "k");
translitChars.put("", "z");
translitChars.put("ŝ", "s");
translitChars.put("", "e");
translitChars.put("ɠ", "g");
translitChars.put("", "l");
translitChars.put("", "f");
translitChars.put("", "x");
translitChars.put("х", "h");
translitChars.put("ǒ", "o");
translitChars.put("ę", "e");
translitChars.put("", "o");
translitChars.put("ƫ", "t");
translitChars.put("ǫ", "o");
translitChars.put("", "i");
translitChars.put("", "n");
translitChars.put("ć", "c");
translitChars.put("", "g");
translitChars.put("", "w");
translitChars.put("", "d");
translitChars.put("", "l");
translitChars.put("ч", "ch");
translitChars.put("œ", "oe");
translitChars.put("", "r");
translitChars.put("ļ", "l");
translitChars.put("ȑ", "r");
translitChars.put("ȭ", "o");
translitChars.put("", "n");
translitChars.put("", "ae");
translitChars.put("ŀ", "l");
translitChars.put("ä", "a");
translitChars.put("ƥ", "p");
translitChars.put("", "o");
translitChars.put("į", "i");
translitChars.put("ȓ", "r");
translitChars.put("dž", "dz");
translitChars.put("", "g");
translitChars.put("", "u");
translitChars.put("ō", "o");
translitChars.put("ľ", "l");
translitChars.put("", "w");
translitChars.put("ț", "t");
translitChars.put("ń", "n");
translitChars.put("ɍ", "r");
translitChars.put("ȃ", "a");
translitChars.put("ü", "u");
translitChars.put("", "l");
translitChars.put("", "o");
translitChars.put("", "o");
translitChars.put("", "b");
translitChars.put("ɹ", "r");
translitChars.put("", "r");
translitChars.put("ʏ", "y");
translitChars.put("", "f");
translitChars.put("", "h");
translitChars.put("ŏ", "o");
translitChars.put("ú", "u");
translitChars.put("", "r");
translitChars.put("ʮ", "h");
translitChars.put("ó", "o");
translitChars.put("ů", "u");
translitChars.put("", "o");
translitChars.put("", "p");
translitChars.put("", "i");
translitChars.put("", "u");
translitChars.put("ã", "a");
translitChars.put("", "i");
translitChars.put("", "t");
translitChars.put("", "e");
translitChars.put("", "u");
translitChars.put("í", "i");
translitChars.put("ɔ", "o");
translitChars.put("с", "s");
translitChars.put("й", "i");
translitChars.put("ɺ", "r");
translitChars.put("ɢ", "g");
translitChars.put("ř", "r");
translitChars.put("", "h");
translitChars.put("ű", "u");
translitChars.put("ȍ", "o");
translitChars.put("ш", "sh");
translitChars.put("", "l");
translitChars.put("", "h");
translitChars.put("ȶ", "t");
translitChars.put("ņ", "n");
translitChars.put("", "e");
translitChars.put("ì", "i");
translitChars.put("", "w");
translitChars.put("б", "b");
translitChars.put("ē", "e");
translitChars.put("", "e");
translitChars.put("ł", "l");
translitChars.put("", "o");
translitChars.put("ɭ", "l");
translitChars.put("", "y");
translitChars.put("", "j");
translitChars.put("", "k");
translitChars.put("ṿ", "v");
translitChars.put("ȩ", "e");
translitChars.put("â", "a");
translitChars.put("ş", "s");
translitChars.put("ŗ", "r");
translitChars.put("ʋ", "v");
translitChars.put("", "a");
translitChars.put("", "c");
translitChars.put("", "e");
translitChars.put("ɰ", "m");
translitChars.put("е", "e");
translitChars.put("", "w");
translitChars.put("ȏ", "o");
translitChars.put("č", "c");
translitChars.put("ǵ", "g");
translitChars.put("ĉ", "c");
translitChars.put("ю", "yu");
translitChars.put("", "o");
translitChars.put("", "k");
translitChars.put("", "q");
translitChars.put("г", "g");
translitChars.put("", "o");
translitChars.put("", "s");
translitChars.put("", "o");
translitChars.put("ȟ", "h");
translitChars.put("ő", "o");
translitChars.put("", "tz");
translitChars.put("", "e");
translitChars.put("о", "o");
}
StringBuilder dst = new StringBuilder(src.length());
int len = src.length();
for (int a = 0; a < len; a++) {
String ch = src.substring(a, a + 1);
String tch = translitChars.get(ch);
if (tch != null) {
dst.append(tch);
} else {
dst.append(ch);
}
}
return dst.toString();
}
abstract public static class PluralRules {
abstract int quantityForNumber(int n);

View File

@ -14,7 +14,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Static library version of {@link android.util.LruCache}. Used to write apps
@ -41,8 +40,8 @@ public class LruCache {
throw new IllegalArgumentException("maxSize <= 0");
}
this.maxSize = maxSize;
this.map = new LinkedHashMap<String, BitmapDrawable>(0, 0.75f, true);
this.mapFilters = new LinkedHashMap<String, ArrayList<String>>();
this.map = new LinkedHashMap<>(0, 0.75f, true);
this.mapFilters = new LinkedHashMap<>();
}
/**
@ -69,7 +68,7 @@ public class LruCache {
public ArrayList<String> getFilterKeys(String key) {
ArrayList<String> arr = mapFilters.get(key);
if (arr != null) {
return new ArrayList<String>(arr);
return new ArrayList<>(arr);
}
return null;
}
@ -98,14 +97,17 @@ public class LruCache {
if (args.length > 1) {
ArrayList<String> arr = mapFilters.get(args[0]);
if (arr == null) {
arr = new ArrayList<String>();
arr = new ArrayList<>();
mapFilters.put(args[0], arr);
}
if (!arr.contains(args[1])) {
arr.add(args[1]);
}
}
if (previous != null) {
entryRemoved(false, key, previous, value);
ImageLoader.getInstance().callGC();
}
trimToSize(maxSize, key);
@ -137,15 +139,16 @@ public class LruCache {
if (args.length > 1) {
ArrayList<String> arr = mapFilters.get(args[0]);
if (arr != null) {
arr.remove(key);
arr.remove(args[1]);
if (arr.isEmpty()) {
mapFilters.remove(args[1]);
mapFilters.remove(args[0]);
}
}
}
entryRemoved(true, key, value, null);
}
ImageLoader.getInstance().callGC();
}
}
@ -172,14 +175,15 @@ public class LruCache {
if (args.length > 1) {
ArrayList<String> arr = mapFilters.get(args[0]);
if (arr != null) {
arr.remove(key);
arr.remove(args[1]);
if (arr.isEmpty()) {
mapFilters.remove(args[1]);
mapFilters.remove(args[0]);
}
}
}
entryRemoved(false, key, previous, null);
ImageLoader.getInstance().callGC();
}
return previous;

View File

@ -122,6 +122,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public String bucketName;
public PhotoEntry coverPhoto;
public ArrayList<PhotoEntry> photos = new ArrayList<>();
public HashMap<Integer, PhotoEntry> photosByIds = new HashMap<>();
public AlbumEntry(int bucketId, String bucketName, PhotoEntry coverPhoto) {
this.bucketId = bucketId;
@ -131,6 +132,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public void addPhoto(PhotoEntry photoEntry) {
photos.add(photoEntry);
photosByIds.put(photoEntry.imageId, photoEntry);
}
}
@ -140,6 +142,8 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public long dateTaken;
public String path;
public int orientation;
public String thumbPath;
public String imagePath;
public PhotoEntry(int bucketId, int imageId, long dateTaken, String path, int orientation) {
this.bucketId = bucketId;
@ -1095,11 +1099,11 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
@Override
public void onSensorChanged(SensorEvent event) {
if (audioTrackPlayer == null && audioPlayer == null || isPaused || (useFrontSpeaker == (event.values[0] == 0))) {
if (proximitySensor != null && audioTrackPlayer == null && audioPlayer == null || isPaused || (useFrontSpeaker == (event.values[0] < proximitySensor.getMaximumRange() / 10))) {
return;
}
ignoreProximity = true;
useFrontSpeaker = event.values[0] == 0;
useFrontSpeaker = event.values[0] < proximitySensor.getMaximumRange() / 10;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioRouteChanged, useFrontSpeaker);
MessageObject currentMessageObject = playingMessageObject;
float progress = playingMessageObject.audioProgress;
@ -2450,12 +2454,16 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
decoder.start();
final int TIMEOUT_USEC = 2500;
ByteBuffer[] decoderInputBuffers = decoder.getInputBuffers();
ByteBuffer[] encoderOutputBuffers = encoder.getOutputBuffers();
ByteBuffer[] decoderInputBuffers = null;
ByteBuffer[] encoderOutputBuffers = null;
ByteBuffer[] encoderInputBuffers = null;
if (Build.VERSION.SDK_INT < 21) {
decoderInputBuffers = decoder.getInputBuffers();
encoderOutputBuffers = encoder.getOutputBuffers();
if (Build.VERSION.SDK_INT < 18) {
encoderInputBuffers = encoder.getInputBuffers();
}
}
checkConversionCanceled();
@ -2467,7 +2475,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
if (index == videoIndex) {
int inputBufIndex = decoder.dequeueInputBuffer(TIMEOUT_USEC);
if (inputBufIndex >= 0) {
ByteBuffer inputBuf = decoderInputBuffers[inputBufIndex];
ByteBuffer inputBuf = null;
if (Build.VERSION.SDK_INT < 21) {
inputBuf = decoderInputBuffers[inputBufIndex];
} else {
inputBuf = decoder.getInputBuffer(inputBufIndex);
}
int chunkSize = extractor.readSampleData(inputBuf, 0);
if (chunkSize < 0) {
decoder.queueInputBuffer(inputBufIndex, 0, 0, 0L, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
@ -2497,7 +2510,9 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
if (encoderStatus == MediaCodec.INFO_TRY_AGAIN_LATER) {
encoderOutputAvailable = false;
} else if (encoderStatus == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
if (Build.VERSION.SDK_INT < 21) {
encoderOutputBuffers = encoder.getOutputBuffers();
}
} else if (encoderStatus == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
MediaFormat newFormat = encoder.getOutputFormat();
if (videoTrackIndex == -5) {
@ -2506,7 +2521,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} else if (encoderStatus < 0) {
throw new RuntimeException("unexpected result from encoder.dequeueOutputBuffer: " + encoderStatus);
} else {
ByteBuffer encodedData = encoderOutputBuffers[encoderStatus];
ByteBuffer encodedData = null;
if (Build.VERSION.SDK_INT < 21) {
encodedData = encoderOutputBuffers[encoderStatus];
} else {
encodedData = encoder.getOutputBuffer(encoderStatus);
}
if (encodedData == null) {
throw new RuntimeException("encoderOutputBuffer " + encoderStatus + " was null");
}

View File

@ -8,7 +8,6 @@
package org.telegram.android;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.text.Layout;
import android.text.Spannable;
@ -42,12 +41,11 @@ public class MessageObject {
public CharSequence messageText;
public int type;
public int contentType;
public ArrayList<PhotoObject> photoThumbs;
public Bitmap imagePreview;
public String dateKey;
public boolean deleted = false;
public float audioProgress;
public int audioProgressSec;
public ArrayList<TLRPC.PhotoSize> photoThumbs;
private static TextPaint textPaint;
public int lastLineWidth;
@ -66,11 +64,7 @@ public class MessageObject {
public ArrayList<TextLayoutBlock> textLayoutBlocks;
public MessageObject(TLRPC.Message message, AbstractMap<Integer, TLRPC.User> users) {
this(message, users, 1);
}
public MessageObject(TLRPC.Message message, AbstractMap<Integer, TLRPC.User> users, int preview) {
public MessageObject(TLRPC.Message message, AbstractMap<Integer, TLRPC.User> users, boolean generateLayout) {
if (textPaint == null) {
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
textPaint.setColor(0xff000000);
@ -319,6 +313,9 @@ public class MessageObject {
type = 8;
} else if (message.media.document.mime_type.equals("image/webp") && isSticker()) {
type = 13;
if (messageOwner.media.document.thumb != null && messageOwner.media.document.thumb.location != null) {
messageOwner.media.document.thumb.location.ext = "webp";
}
} else {
type = 9;
}
@ -355,37 +352,25 @@ public class MessageObject {
int dateMonth = rightNow.get(Calendar.MONTH);
dateKey = String.format("%d_%02d_%02d", dateYear, dateMonth, dateDay);
if (preview != 0) {
if (generateLayout) {
generateLayout();
}
generateThumbs(false, preview);
generateThumbs(false);
}
public CharSequence replaceWithLink(CharSequence source, String param, TLRPC.User user) {
String name = ContactsController.formatName(user.first_name, user.last_name);
int start = TextUtils.indexOf(source, param);
URLSpanNoUnderline span = new URLSpanNoUnderline("" + user.id);
SpannableStringBuilder builder = new SpannableStringBuilder(TextUtils.replace(source, new String[]{param}, new String[]{name}));
builder.setSpan(span, start, start + name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return builder;
}
public void generateThumbs(boolean update, int preview) {
public void generateThumbs(boolean update) {
if (messageOwner instanceof TLRPC.TL_messageService) {
if (messageOwner.action instanceof TLRPC.TL_messageActionChatEditPhoto) {
if (!update) {
photoThumbs = new ArrayList<>();
for (TLRPC.PhotoSize size : messageOwner.action.photo.sizes) {
photoThumbs.add(new PhotoObject(size, preview, isSecretMedia()));
}
photoThumbs = new ArrayList<>(messageOwner.action.photo.sizes);
} else if (photoThumbs != null && !photoThumbs.isEmpty()) {
for (PhotoObject photoObject : photoThumbs) {
for (TLRPC.PhotoSize photoObject : photoThumbs) {
for (TLRPC.PhotoSize size : messageOwner.action.photo.sizes) {
if (size instanceof TLRPC.TL_photoSizeEmpty) {
continue;
}
if (size.type.equals(photoObject.photoOwner.type)) {
photoObject.photoOwner.location = size.location;
if (size.type.equals(photoObject.type)) {
photoObject.location = size.location;
break;
}
}
@ -395,22 +380,15 @@ public class MessageObject {
} else if (messageOwner.media != null && !(messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
if (!update) {
photoThumbs = new ArrayList<>();
for (TLRPC.PhotoSize size : messageOwner.media.photo.sizes) {
PhotoObject obj = new PhotoObject(size, preview, isSecretMedia());
photoThumbs.add(obj);
if (imagePreview == null && obj.image != null) {
imagePreview = obj.image;
}
}
photoThumbs = new ArrayList<>(messageOwner.media.photo.sizes);
} else if (photoThumbs != null && !photoThumbs.isEmpty()) {
for (PhotoObject photoObject : photoThumbs) {
for (TLRPC.PhotoSize photoObject : photoThumbs) {
for (TLRPC.PhotoSize size : messageOwner.media.photo.sizes) {
if (size instanceof TLRPC.TL_photoSizeEmpty) {
continue;
}
if (size.type.equals(photoObject.photoOwner.type)) {
photoObject.photoOwner.location = size.location;
if (size.type.equals(photoObject.type)) {
photoObject.location = size.location;
break;
}
}
@ -419,36 +397,34 @@ public class MessageObject {
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
if (!update) {
photoThumbs = new ArrayList<>();
PhotoObject obj = new PhotoObject(messageOwner.media.video.thumb, preview, isSecretMedia());
photoThumbs.add(obj);
if (imagePreview == null && obj.image != null) {
imagePreview = obj.image;
}
photoThumbs.add(messageOwner.media.video.thumb);
} else if (photoThumbs != null && !photoThumbs.isEmpty() && messageOwner.media.video.thumb != null) {
PhotoObject photoObject = photoThumbs.get(0);
photoObject.photoOwner.location = messageOwner.media.video.thumb.location;
TLRPC.PhotoSize photoObject = photoThumbs.get(0);
photoObject.location = messageOwner.media.video.thumb.location;
}
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
if (!(messageOwner.media.document.thumb instanceof TLRPC.TL_photoSizeEmpty)) {
if (!update) {
photoThumbs = new ArrayList<>();
if (type == 13) {
messageOwner.media.document.thumb.location.ext = "webp";
}
PhotoObject obj = new PhotoObject(messageOwner.media.document.thumb, preview, isSecretMedia());
photoThumbs.add(obj);
if (imagePreview == null && obj.image != null) {
imagePreview = obj.image;
}
photoThumbs.add(messageOwner.media.document.thumb);
} else if (photoThumbs != null && !photoThumbs.isEmpty() && messageOwner.media.document.thumb != null) {
PhotoObject photoObject = photoThumbs.get(0);
photoObject.photoOwner.location = messageOwner.media.document.thumb.location;
TLRPC.PhotoSize photoObject = photoThumbs.get(0);
photoObject.location = messageOwner.media.document.thumb.location;
}
}
}
}
}
public CharSequence replaceWithLink(CharSequence source, String param, TLRPC.User user) {
String name = ContactsController.formatName(user.first_name, user.last_name);
int start = TextUtils.indexOf(source, param);
URLSpanNoUnderline span = new URLSpanNoUnderline("" + user.id);
SpannableStringBuilder builder = new SpannableStringBuilder(TextUtils.replace(source, new String[]{param}, new String[]{name}));
builder.setSpan(span, start, start + name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return builder;
}
public String getFileName() {
if (messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
return FileLoader.getAttachFileName(messageOwner.media.video);
@ -468,6 +444,19 @@ public class MessageObject {
return "";
}
public int getFileType() {
if (messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
return FileLoader.MEDIA_DIR_VIDEO;
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
return FileLoader.MEDIA_DIR_DOCUMENT;
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaAudio) {
return FileLoader.MEDIA_DIR_AUDIO;
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
return FileLoader.MEDIA_DIR_IMAGE;
}
return FileLoader.MEDIA_DIR_CACHE;
}
private boolean containsUrls(CharSequence message) {
if (message == null || message.length() < 3 || message.length() > 1024 * 20) {
return false;
@ -787,9 +776,9 @@ public class MessageObject {
return "";
}
public boolean isSticker() {
if (messageOwner.media != null && messageOwner.media.document != null) {
for (TLRPC.DocumentAttribute attribute : messageOwner.media.document.attributes) {
public static boolean isStickerMessage(TLRPC.Message message) {
if (message.media != null && message.media.document != null) {
for (TLRPC.DocumentAttribute attribute : message.media.document.attributes) {
if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
return true;
}
@ -797,4 +786,8 @@ public class MessageObject {
}
return false;
}
public boolean isSticker() {
return isStickerMessage(messageOwner);
}
}

View File

@ -314,9 +314,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
sendingTypings.clear();
loadingFullUsers.clear();
loadedFullUsers.clear();
loadingFullUsers.clear();
loadedFullUsers.clear();
reloadingMessages.clear();
loadingFullChats.clear();
loadedFullChats.clear();
updatesStartWaitTime = 0;
currentDeletingTaskTime = 0;
@ -568,6 +568,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
TLRPC.messages_Messages messagesRes = (TLRPC.messages_Messages) response;
ImageLoader.saveMessagesThumbs(messagesRes.messages);
MessagesStorage.getInstance().putMessages(messagesRes, dialog_id);
final ArrayList<MessageObject> objects = new ArrayList<>();
@ -578,7 +579,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
for (TLRPC.User u : messagesRes.users) {
usersLocal.put(u.id, u);
}
objects.add(new MessageObject(message, usersLocal, 2));
objects.add(new MessageObject(message, usersLocal, true));
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
@ -898,151 +899,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
});
}
public void processLoadedMedia(final TLRPC.messages_Messages res, final long uid, int offset, int count, int max_id, final boolean fromCache, final int classGuid) {
int lower_part = (int)uid;
if (fromCache && res.messages.isEmpty() && lower_part != 0) {
loadMedia(uid, offset, count, max_id, false, classGuid);
} else {
if (!fromCache) {
MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, true, true);
MessagesStorage.getInstance().putMedia(uid, res.messages);
}
final HashMap<Integer, TLRPC.User> usersLocal = new HashMap<>();
for (TLRPC.User u : res.users) {
usersLocal.put(u.id, u);
}
final ArrayList<MessageObject> objects = new ArrayList<>();
for (TLRPC.Message message : res.messages) {
objects.add(new MessageObject(message, usersLocal));
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
int totalCount;
if (res instanceof TLRPC.TL_messages_messagesSlice) {
totalCount = res.count;
} else {
totalCount = res.messages.size();
}
putUsers(res.users, fromCache);
for (TLRPC.Chat chat : res.chats) {
putChat(chat, fromCache);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.mediaDidLoaded, uid, totalCount, objects, fromCache, classGuid);
}
});
}
}
public void loadMedia(final long uid, final int offset, final int count, final int max_id, final boolean fromCache, final int classGuid) {
int lower_part = (int)uid;
if (fromCache || lower_part == 0) {
MessagesStorage.getInstance().loadMedia(uid, offset, count, max_id, classGuid);
} else {
TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
req.offset = offset;
req.limit = count;
req.max_id = max_id;
req.filter = new TLRPC.TL_inputMessagesFilterPhotoVideo();
req.q = "";
if (uid < 0) {
req.peer = new TLRPC.TL_inputPeerChat();
req.peer.chat_id = -lower_part;
} else {
TLRPC.User user = getUser(lower_part);
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
req.peer = new TLRPC.TL_inputPeerForeign();
req.peer.access_hash = user.access_hash;
} else {
req.peer = new TLRPC.TL_inputPeerContact();
}
req.peer.user_id = lower_part;
}
long reqId = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
final TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
processLoadedMedia(res, uid, offset, count, max_id, false, classGuid);
}
}
});
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
}
}
public void processLoadedMediaCount(final int count, final long uid, final int classGuid, final boolean fromCache) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
int lower_part = (int)uid;
if (fromCache && count == -1 && lower_part != 0) {
getMediaCount(uid, classGuid, false);
} else {
if (!fromCache) {
MessagesStorage.getInstance().putMediaCount(uid, count);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.mediaCountDidLoaded, uid, (fromCache && count == -1 ? 0 : count), fromCache);
}
}
});
}
public void getMediaCount(final long uid, final int classGuid, boolean fromCache) {
int lower_part = (int)uid;
if (fromCache || lower_part == 0) {
MessagesStorage.getInstance().getMediaCount(uid, classGuid);
} else {
TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
req.offset = 0;
req.limit = 1;
req.max_id = 0;
req.filter = new TLRPC.TL_inputMessagesFilterPhotoVideo();
req.q = "";
if (uid < 0) {
req.peer = new TLRPC.TL_inputPeerChat();
req.peer.chat_id = -lower_part;
} else {
TLRPC.User user = getUser(lower_part);
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
req.peer = new TLRPC.TL_inputPeerForeign();
req.peer.access_hash = user.access_hash;
} else {
req.peer = new TLRPC.TL_inputPeerContact();
}
req.peer.user_id = lower_part;
}
long reqId = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
final TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, true, true);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
putUsers(res.users, false);
for (TLRPC.Chat chat : res.chats) {
putChat(chat, false);
}
}
});
if (res instanceof TLRPC.TL_messages_messagesSlice) {
processLoadedMediaCount(res.count, uid, classGuid, false);
} else {
processLoadedMediaCount(res.messages.size(), uid, classGuid, false);
}
}
}
});
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
}
}
public void uploadAndApplyUserAvatar(TLRPC.PhotoSize bigPhoto) {
if (bigPhoto != null) {
uploadingAvatar = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
@ -1470,6 +1326,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void run() {
int lower_id = (int)dialog_id;
int high_id = (int)(dialog_id >> 32);
if (!isCache) {
ImageLoader.saveMessagesThumbs(messagesRes.messages);
}
if (!isCache && allowCache) {
MessagesStorage.getInstance().putMessages(messagesRes, dialog_id);
}
@ -1490,7 +1349,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
ArrayList<Integer> messagesToReload = null;
for (TLRPC.Message message : messagesRes.messages) {
message.dialog_id = dialog_id;
objects.add(new MessageObject(message, usersLocal, 2));
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) {
@ -1553,7 +1412,13 @@ public class MessagesController implements NotificationCenter.NotificationCenter
dialog_id = -dialog.peer.chat_id;
}
if (dialog.notify_settings.mute_until != 0) {
if (dialog.notify_settings.mute_until > ConnectionsManager.getInstance().getCurrentTime() + 60 * 60 * 24 * 365) {
editor.putInt("notify2_" + dialog_id, 2);
dialog.notify_settings.mute_until = Integer.MAX_VALUE;
} else {
editor.putInt("notify2_" + dialog_id, 3);
editor.putInt("notifyuntil_" + dialog_id, dialog.notify_settings.mute_until);
}
}
}
}
@ -1592,7 +1457,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
for (TLRPC.Message m : dialogsRes.messages) {
new_dialogMessage.put(m.id, new MessageObject(m, usersLocal, 0));
new_dialogMessage.put(m.id, new MessageObject(m, usersLocal, false));
}
for (TLRPC.TL_dialog d : dialogsRes.dialogs) {
if (d.last_message_date == 0) {
@ -1701,6 +1566,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
int new_totalDialogsCount;
if (!isCache) {
ImageLoader.saveMessagesThumbs(dialogsRes.messages);
MessagesStorage.getInstance().putDialogs(dialogsRes);
}
@ -1716,7 +1582,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
for (TLRPC.Message m : dialogsRes.messages) {
new_dialogMessage.put(m.id, new MessageObject(m, usersLocal, 0));
new_dialogMessage.put(m.id, new MessageObject(m, usersLocal, false));
}
for (TLRPC.TL_dialog d : dialogsRes.dialogs) {
if (d.last_message_date == 0) {
@ -1990,7 +1856,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
newMsg.date = ConnectionsManager.getInstance().getCurrentTime();
newMsg.random_id = 0;
UserConfig.saveConfig(false);
MessageObject newMsgObj = new MessageObject(newMsg, users);
MessageObject newMsgObj = new MessageObject(newMsg, users, true);
newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
ArrayList<MessageObject> objArr = new ArrayList<>();
@ -2034,7 +1900,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
putUsers(res.users, false);
putChats(res.chats, false);
final ArrayList<MessageObject> messagesObj = new ArrayList<>();
messagesObj.add(new MessageObject(res.message, users));
messagesObj.add(new MessageObject(res.message, users, true));
TLRPC.Chat chat = res.chats.get(0);
updateInterfaceWithMessages(-chat.id, messagesObj);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatDidCreated, chat.id);
@ -2081,7 +1947,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
putUsers(res.users, false);
putChats(res.chats, false);
final ArrayList<MessageObject> messagesObj = new ArrayList<>();
messagesObj.add(new MessageObject(res.message, users));
messagesObj.add(new MessageObject(res.message, users, true));
TLRPC.Chat chat = res.chats.get(0);
updateInterfaceWithMessages(-chat.id, messagesObj);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_CHAT_MEMBERS);
@ -2163,7 +2029,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
putChats(res.chats, false);
if (user.id != UserConfig.getClientUserId()) {
final ArrayList<MessageObject> messagesObj = new ArrayList<>();
messagesObj.add(new MessageObject(res.message, users));
messagesObj.add(new MessageObject(res.message, users, true));
TLRPC.Chat chat = res.chats.get(0);
updateInterfaceWithMessages(-chat.id, messagesObj);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_CHAT_MEMBERS);
@ -2247,7 +2113,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
putUsers(res.users, false);
putChats(res.chats, false);
final ArrayList<MessageObject> messagesObj = new ArrayList<>();
messagesObj.add(new MessageObject(res.message, users));
messagesObj.add(new MessageObject(res.message, users, true));
TLRPC.Chat chat = res.chats.get(0);
updateInterfaceWithMessages(-chat.id, messagesObj);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
@ -2291,13 +2157,17 @@ public class MessagesController implements NotificationCenter.NotificationCenter
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));
messagesObj.add(new MessageObject(res.message, users, true));
TLRPC.Chat chat = res.chats.get(0);
updateInterfaceWithMessages(-chat.id, messagesObj);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
@ -2305,8 +2175,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
});
final ArrayList<TLRPC.Message> messages = new ArrayList<>();
messages.add(res.message);
MessagesStorage.getInstance().putMessages(messages, true, true, false, 0);
processNewDifferenceParams(res.seq, res.pts, -1);
}
@ -2616,9 +2484,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
ImageLoader.saveMessagesThumbs(res.new_messages);
final ArrayList<MessageObject> pushMessages = new ArrayList<>();
for (TLRPC.Message message : res.new_messages) {
MessageObject obj = new MessageObject(message, usersDict, 2);
MessageObject obj = new MessageObject(message, usersDict, true);
long dialog_id = obj.messageOwner.dialog_id;
if (dialog_id == 0) {
@ -2763,7 +2633,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
message.media = new TLRPC.TL_messageMediaEmpty();
MessagesStorage.lastSeqValue = updates.seq;
MessagesStorage.lastPtsValue = updates.pts;
final MessageObject obj = new MessageObject(message, null);
final MessageObject obj = new MessageObject(message, null, true);
final ArrayList<MessageObject> objArr = new ArrayList<>();
objArr.add(obj);
ArrayList<TLRPC.Message> arr = new ArrayList<>();
@ -2834,7 +2704,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
MessagesStorage.lastSeqValue = updates.seq;
MessagesStorage.lastPtsValue = updates.pts;
MessagesStorage.lastDateValue = updates.date;
final MessageObject obj = new MessageObject(message, null);
final MessageObject obj = new MessageObject(message, null, true);
final ArrayList<MessageObject> objArr = new ArrayList<>();
objArr.add(obj);
ArrayList<TLRPC.Message> arr = new ArrayList<>();
@ -2976,6 +2846,29 @@ public class MessagesController implements NotificationCenter.NotificationCenter
MessagesStorage.getInstance().saveDiffParams(MessagesStorage.lastSeqValue, MessagesStorage.lastPtsValue, MessagesStorage.lastDateValue, MessagesStorage.lastQtsValue);
}
private boolean isNotifySettingsMuted(TLRPC.PeerNotifySettings settings) {
return settings instanceof TLRPC.TL_peerNotifySettings && settings.mute_until > ConnectionsManager.getInstance().getCurrentTime();
}
public boolean isDialogMuted(long dialog_id) {
TLRPC.TL_dialog dialog = dialogs_dict.get(dialog_id);
if (dialog != null) {
return isNotifySettingsMuted(dialog.notify_settings);
} else {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
int mute_type = preferences.getInt("notify2_" + dialog_id, 0);
if (mute_type == 2) {
return true;
} else if (mute_type == 3) {
int mute_until = preferences.getInt("notifyuntil_" + dialog_id, 0);
if (mute_until >= ConnectionsManager.getInstance().getCurrentTime()) {
return true;
}
}
}
return false;
}
public boolean processUpdateArray(ArrayList<TLRPC.Update> updates, final ArrayList<TLRPC.User> usersArr, final ArrayList<TLRPC.Chat> chatsArr) {
if (updates.isEmpty()) {
return true;
@ -3043,7 +2936,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
messagesArr.add(upd.message);
MessageObject obj = new MessageObject(upd.message, usersDict, 2);
ImageLoader.saveMessageThumbs(upd.message);
MessageObject obj = new MessageObject(upd.message, usersDict, true);
if (obj.type == 11) {
interfaceUpdateMask |= UPDATE_MASK_CHAT_AVATAR;
} else if (obj.type == 10) {
@ -3134,7 +3028,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
newMessage.dialog_id = update.user_id;
messagesArr.add(newMessage);
MessageObject obj = new MessageObject(newMessage, usersDict);
MessageObject obj = new MessageObject(newMessage, usersDict, true);
ArrayList<MessageObject> arr = messages.get(newMessage.dialog_id);
if (arr == null) {
arr = new ArrayList<>();
@ -3178,7 +3072,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
newMessage.dialog_id = 777000;
messagesArr.add(newMessage);
MessageObject obj = new MessageObject(newMessage, usersDict);
MessageObject obj = new MessageObject(newMessage, usersDict, true);
ArrayList<MessageObject> arr = messages.get(newMessage.dialog_id);
if (arr == null) {
arr = new ArrayList<>();
@ -3200,8 +3094,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
messages.put(uid, arr);
}
for (TLRPC.Message message : decryptedMessages) {
ImageLoader.saveMessageThumbs(message);
messagesArr.add(message);
MessageObject obj = new MessageObject(message, usersDict, 2);
MessageObject obj = new MessageObject(message, usersDict, true);
arr.add(obj);
pushMessages.add(obj);
}
@ -3287,7 +3182,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
newMessage.message = ((TLRPC.TL_updateServiceNotification)update).message;
messagesArr.add(newMessage);
MessageObject obj = new MessageObject(newMessage, usersDict);
MessageObject obj = new MessageObject(newMessage, usersDict, true);
ArrayList<MessageObject> arr = messages.get(newMessage.dialog_id);
if (arr == null) {
arr = new ArrayList<>();
@ -3370,6 +3265,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
toDbUser.status = update.status;
dbUsersStatus.add(toDbUser);
if (update.user_id == UserConfig.getClientUserId()) {
NotificationsController.getInstance().setLastOnlineFromOtherDevice(update.status.expires);
}
} else if (update instanceof TLRPC.TL_updateUserName) {
if (currentUser != null) {
currentUser.first_name = update.first_name;
@ -3405,15 +3303,38 @@ public class MessagesController implements NotificationCenter.NotificationCenter
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
editor = preferences.edit();
}
int dialog_id = update.peer.peer.user_id;
long dialog_id = update.peer.peer.user_id;
if (dialog_id == 0) {
dialog_id = -update.peer.peer.chat_id;
}
if (update.notify_settings.mute_until != 0) {
editor.putInt("notify2_" + dialog_id, 2);
} else {
editor.remove("notify2_" + dialog_id);
TLRPC.TL_dialog dialog = dialogs_dict.get(dialog_id);
if (dialog != null) {
dialog.notify_settings = update.notify_settings;
}
if (update.notify_settings.mute_until > ConnectionsManager.getInstance().getCurrentTime()) {
int until = 0;
if (update.notify_settings.mute_until > ConnectionsManager.getInstance().getCurrentTime() + 60 * 60 * 24 * 365) {
editor.putInt("notify2_" + dialog_id, 2);
if (dialog != null) {
dialog.notify_settings.mute_until = Integer.MAX_VALUE;
}
} else {
until = update.notify_settings.mute_until;
editor.putInt("notify2_" + dialog_id, 3);
editor.putInt("notifyuntil_" + dialog_id, update.notify_settings.mute_until);
if (dialog != null) {
dialog.notify_settings.mute_until = until;
}
}
MessagesStorage.getInstance().setDialogFlags(dialog_id, ((long)until << 32) | 1);
} else {
if (dialog != null) {
dialog.notify_settings.mute_until = 0;
}
editor.remove("notify2_" + dialog_id);
MessagesStorage.getInstance().setDialogFlags(dialog_id, 0);
}
}/* else if (update.peer instanceof TLRPC.TL_notifyChats) { disable global settings sync
if (editor == null) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);

View File

@ -17,6 +17,7 @@ import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.SQLite.SQLiteCursor;
import org.telegram.SQLite.SQLiteDatabase;
import org.telegram.SQLite.SQLitePreparedStatement;
import org.telegram.android.query.SharedMediaQuery;
import org.telegram.messenger.BuffersStorage;
import org.telegram.messenger.ByteBufferDesc;
import org.telegram.messenger.ConnectionsManager;
@ -109,8 +110,6 @@ public class MessagesStorage {
database.executeFast("CREATE TABLE chat_settings(uid INTEGER PRIMARY KEY, participants BLOB)").stepThis().dispose();
database.executeFast("CREATE TABLE contacts(uid INTEGER PRIMARY KEY, mutual INTEGER)").stepThis().dispose();
database.executeFast("CREATE TABLE pending_read(uid INTEGER PRIMARY KEY, max_id INTEGER)").stepThis().dispose();
database.executeFast("CREATE TABLE media(mid INTEGER PRIMARY KEY, uid INTEGER, date INTEGER, data BLOB)").stepThis().dispose();
database.executeFast("CREATE TABLE media_counts(uid INTEGER PRIMARY KEY, count INTEGER)").stepThis().dispose();
database.executeFast("CREATE TABLE wallpapers(uid INTEGER PRIMARY KEY, data BLOB)").stepThis().dispose();
database.executeFast("CREATE TABLE randoms(random_id INTEGER, mid INTEGER, PRIMARY KEY (random_id, mid))").stepThis().dispose();
database.executeFast("CREATE TABLE enc_tasks_v2(mid INTEGER PRIMARY KEY, date INTEGER)").stepThis().dispose();
@ -123,9 +122,6 @@ public class MessagesStorage {
database.executeFast("CREATE TABLE messages_seq(mid INTEGER PRIMARY KEY, seq_in INTEGER, seq_out INTEGER);").stepThis().dispose();
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 secret_holes(uid INTEGER, seq_in INTEGER, seq_out INTEGER, data BLOB, PRIMARY KEY (uid, seq_in, seq_out));").stepThis().dispose();
//database.executeFast("CREATE TABLE attach_data(uid INTEGER, id INTEGER, data BLOB, PRIMARY KEY (uid, id))").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();
@ -134,6 +130,8 @@ public class MessagesStorage {
//database.executeFast("CREATE TABLE messages_holes(uid INTEGER, start INTEGER, end INTEGER, PRIMARY KEY(uid, start));").stepThis().dispose();
//database.executeFast("CREATE INDEX IF NOT EXISTS type_uid_end_messages_holes ON messages_holes(uid, end);").stepThis().dispose();
//database.executeFast("CREATE TABLE secret_holes(uid INTEGER, seq_in INTEGER, seq_out INTEGER, data BLOB, PRIMARY KEY (uid, seq_in, seq_out));").stepThis().dispose();
//database.executeFast("CREATE TABLE attach_data(uid INTEGER, id INTEGER, data BLOB, PRIMARY KEY (uid, id))").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS type_date_idx_download_queue ON download_queue(type, date);").stepThis().dispose();
@ -146,10 +144,6 @@ public class MessagesStorage {
database.executeFast("CREATE INDEX IF NOT EXISTS last_mid_idx_dialogs ON dialogs(last_mid);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS unread_count_idx_dialogs ON dialogs(unread_count);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_idx_media ON media(uid, mid);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_media ON media(mid);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS uid_date_mid_idx_media ON media(uid, date, mid);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_idx_messages ON messages(uid, mid);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS uid_date_mid_idx_messages ON messages(uid, date, mid);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS mid_out_idx_messages ON messages(mid, out);").stepThis().dispose();
@ -158,7 +152,17 @@ public class MessagesStorage {
database.executeFast("CREATE INDEX IF NOT EXISTS seq_idx_messages_seq ON messages_seq(seq_in, seq_out);").stepThis().dispose();
database.executeFast("PRAGMA user_version = 12").stepThis().dispose();
//shared media
database.executeFast("CREATE TABLE media_v2(mid INTEGER PRIMARY KEY, uid INTEGER, date INTEGER, type INTEGER, data BLOB)").stepThis().dispose();
database.executeFast("CREATE TABLE media_counts_v2(uid INTEGER, type INTEGER, count INTEGER, PRIMARY KEY(uid, type))").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_type_date_idx_media ON media_v2(uid, mid, type, date);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_media ON media_v2(mid);").stepThis().dispose();
//kev-value
database.executeFast("CREATE TABLE keyvalue(id TEXT PRIMARY KEY, value TEXT)").stepThis().dispose();
//version
database.executeFast("PRAGMA user_version = 13").stepThis().dispose();
} else {
try {
SQLiteCursor cursor = database.queryFinalized("SELECT seq, pts, date, qts, lsv, sg, pbytes FROM params WHERE id = 1");
@ -189,7 +193,7 @@ public class MessagesStorage {
}
}
int version = database.executeInt("PRAGMA user_version");
if (version < 12) {
if (version < 13) {
updateDbToLastVersion(version);
}
}
@ -208,9 +212,6 @@ public class MessagesStorage {
if (version < 4) {
database.executeFast("CREATE TABLE IF NOT EXISTS user_photos(uid INTEGER, id INTEGER, data BLOB, PRIMARY KEY (uid, id))").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_media ON media(mid);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS uid_date_mid_idx_media ON media(uid, date, mid);").stepThis().dispose();
database.executeFast("DROP INDEX IF EXISTS read_state_out_idx_messages;").stepThis().dispose();
database.executeFast("DROP INDEX IF EXISTS ttl_idx_messages;").stepThis().dispose();
database.executeFast("DROP INDEX IF EXISTS date_idx_messages;").stepThis().dispose();
@ -350,6 +351,23 @@ public class MessagesStorage {
database.executeFast("PRAGMA user_version = 12").stepThis().dispose();
version = 12;
}
if (version == 12 && version < 13) {
database.executeFast("DROP INDEX IF EXISTS uid_mid_idx_media;").stepThis().dispose();
database.executeFast("DROP INDEX IF EXISTS mid_idx_media;").stepThis().dispose();
database.executeFast("DROP INDEX IF EXISTS uid_date_mid_idx_media;").stepThis().dispose();
database.executeFast("DROP TABLE IF EXISTS media;").stepThis().dispose();
database.executeFast("DROP TABLE IF EXISTS media_counts;").stepThis().dispose();
database.executeFast("CREATE TABLE IF NOT EXISTS media_v2(mid INTEGER PRIMARY KEY, uid INTEGER, date INTEGER, type INTEGER, data BLOB)").stepThis().dispose();
database.executeFast("CREATE TABLE IF NOT EXISTS media_counts_v2(uid INTEGER, type INTEGER, count INTEGER, PRIMARY KEY(uid, type))").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS uid_mid_type_date_idx_media ON media_v2(uid, mid, type, date);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_media ON media_v2(mid);").stepThis().dispose();
database.executeFast("CREATE TABLE IF NOT EXISTS keyvalue(id TEXT PRIMARY KEY, value TEXT)").stepThis().dispose();
database.executeFast("PRAGMA user_version = 13").stepThis().dispose();
version = 13;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@ -445,7 +463,7 @@ public class MessagesStorage {
});
}
public void setDialogFlags(final long did, final int flags) {
public void setDialogFlags(final long did, final long flags) {
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
@ -821,9 +839,9 @@ public class MessagesStorage {
}
}
database.executeFast("UPDATE dialogs SET unread_count = 0 WHERE did = " + did).stepThis().dispose();
database.executeFast("DELETE FROM media_counts WHERE uid = " + did).stepThis().dispose();
database.executeFast("DELETE FROM messages WHERE uid = " + did).stepThis().dispose();
database.executeFast("DELETE FROM media WHERE uid = " + did).stepThis().dispose();
database.executeFast("DELETE FROM media_counts_v2 WHERE uid = " + did).stepThis().dispose();
database.executeFast("DELETE FROM media_v2 WHERE uid = " + did).stepThis().dispose();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@ -1479,149 +1497,6 @@ public class MessagesStorage {
});
}
public void putMediaCount(final long uid, final int count) {
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO media_counts VALUES(?, ?)");
state2.requery();
state2.bindLong(1, uid);
state2.bindInteger(2, count);
state2.step();
state2.dispose();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
}
public void getMediaCount(final long uid, final int classGuid) {
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
int count = -1;
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT count FROM media_counts WHERE uid = %d LIMIT 1", uid));
if (cursor.next()) {
count = cursor.intValue(0);
}
cursor.dispose();
int lower_part = (int)uid;
if (count == -1 && lower_part == 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT COUNT(mid) FROM media WHERE uid = %d LIMIT 1", uid));
if (cursor.next()) {
count = cursor.intValue(0);
}
cursor.dispose();
if (count != -1) {
putMediaCount(uid, count);
}
}
MessagesController.getInstance().processLoadedMediaCount(count, uid, classGuid, true);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
}
public void loadMedia(final long uid, final int offset, final int count, final int max_id, final int classGuid) {
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
TLRPC.TL_messages_messages res = new TLRPC.TL_messages_messages();
try {
ArrayList<Integer> loadedUsers = new ArrayList<>();
ArrayList<Integer> fromUser = new ArrayList<>();
SQLiteCursor cursor;
if ((int)uid != 0) {
if (max_id != 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, mid FROM media WHERE uid = %d AND mid < %d ORDER BY date DESC, mid DESC LIMIT %d", uid, max_id, count));
} else {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, mid FROM media WHERE uid = %d ORDER BY date DESC, mid DESC LIMIT %d,%d", uid, offset, count));
}
} else {
if (max_id != 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.data, m.mid, r.random_id FROM media as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.mid > %d ORDER BY m.mid ASC LIMIT %d", uid, max_id, count));
} else {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.data, m.mid, r.random_id FROM media as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d ORDER BY m.mid ASC LIMIT %d,%d", uid, offset, count));
}
}
while (cursor.next()) {
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Message message = (TLRPC.Message)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
message.id = cursor.intValue(1);
message.dialog_id = uid;
if ((int)uid == 0) {
message.random_id = cursor.longValue(2);
}
res.messages.add(message);
fromUser.add(message.from_id);
}
buffersStorage.reuseFreeBuffer(data);
}
cursor.dispose();
StringBuilder usersToLoad = new StringBuilder();
for (int uid : fromUser) {
if (!loadedUsers.contains(uid)) {
if (usersToLoad.length() != 0) {
usersToLoad.append(",");
}
usersToLoad.append(uid);
loadedUsers.add(uid);
}
}
if (usersToLoad.length() != 0) {
getUsersInternal(usersToLoad.toString(), res.users);
}
} catch (Exception e) {
res.messages.clear();
res.chats.clear();
res.users.clear();
FileLog.e("tmessages", e);
} finally {
MessagesController.getInstance().processLoadedMedia(res, uid, offset, count, max_id, true, classGuid);
}
}
});
}
public void putMedia(final long uid, final ArrayList<TLRPC.Message> messages) {
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
database.beginTransaction();
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO media VALUES(?, ?, ?, ?)");
for (TLRPC.Message message : messages) {
if (message.media instanceof TLRPC.TL_messageMediaVideo || message.media instanceof TLRPC.TL_messageMediaPhoto) {
state2.requery();
ByteBufferDesc data = buffersStorage.getFreeBuffer(message.getObjectSize());
message.serializeToStream(data);
state2.bindInteger(1, message.id);
state2.bindLong(2, uid);
state2.bindInteger(3, message.date);
state2.bindByteBuffer(4, data.buffer);
state2.step();
buffersStorage.reuseFreeBuffer(data);
}
}
state2.dispose();
database.commitTransaction();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
}
public void getUnsentMessages(final int count) {
storageQueue.postRunnable(new Runnable() {
@Override
@ -2105,10 +1980,11 @@ public class MessagesStorage {
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
SQLitePreparedStatement state = null;
try {
String id = Utilities.MD5(path);
if (id != null) {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO sent_files_v2 VALUES(?, ?, ?)");
state = database.executeFast("REPLACE INTO sent_files_v2 VALUES(?, ?, ?)");
state.requery();
ByteBufferDesc data = buffersStorage.getFreeBuffer(file.getObjectSize());
file.serializeToStream(data);
@ -2116,11 +1992,14 @@ public class MessagesStorage {
state.bindInteger(2, type);
state.bindByteBuffer(3, data.buffer);
state.step();
state.dispose();
buffersStorage.reuseFreeBuffer(data);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
} finally {
if (state != null) {
state.dispose();
}
}
}
});
@ -2439,7 +2318,7 @@ public class MessagesStorage {
state.dispose();
}
private void getUsersInternal(String usersToLoad, ArrayList<TLRPC.User> result) throws Exception {
public void getUsersInternal(String usersToLoad, ArrayList<TLRPC.User> result) throws Exception {
if (usersToLoad == null || usersToLoad.length() == 0 || result == null) {
return;
}
@ -2464,7 +2343,7 @@ public class MessagesStorage {
cursor.dispose();
}
private void getChatsInternal(String chatsToLoad, ArrayList<TLRPC.Chat> result) throws Exception {
public void getChatsInternal(String chatsToLoad, ArrayList<TLRPC.Chat> result) throws Exception {
if (chatsToLoad == null || chatsToLoad.length() == 0 || result == null) {
return;
}
@ -2486,7 +2365,7 @@ public class MessagesStorage {
cursor.dispose();
}
private void getEncryptedChatsInternal(String chatsToLoad, ArrayList<TLRPC.EncryptedChat> result, ArrayList<Integer> usersToLoad) throws Exception {
public void getEncryptedChatsInternal(String chatsToLoad, ArrayList<TLRPC.EncryptedChat> result, ArrayList<Integer> usersToLoad) throws Exception {
if (chatsToLoad == null || chatsToLoad.length() == 0 || result == null) {
return;
}
@ -2633,15 +2512,6 @@ public class MessagesStorage {
});
}
private boolean canAddMessageToMedia(TLRPC.Message message) {
if (message instanceof TLRPC.TL_message_secret && message.media instanceof TLRPC.TL_messageMediaPhoto && message.ttl != 0 && message.ttl <= 60) {
return false;
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto || message.media instanceof TLRPC.TL_messageMediaVideo) {
return true;
}
return false;
}
private int getMessageMediaType(TLRPC.Message message) {
if (message instanceof TLRPC.TL_message_secret && (
message.media instanceof TLRPC.TL_messageMediaPhoto && message.ttl != 0 && message.ttl <= 60 ||
@ -2661,13 +2531,14 @@ public class MessagesStorage {
}
HashMap<Long, TLRPC.Message> messagesMap = new HashMap<>();
HashMap<Long, Integer> messagesCounts = new HashMap<>();
HashMap<Long, Integer> mediaCounts = new HashMap<>();
HashMap<Integer, HashMap<Long, Integer>> mediaCounts = new HashMap<>();
HashMap<Integer, Integer> mediaTypes = new HashMap<>();
HashMap<Integer, Long> messagesIdsMap = new HashMap<>();
HashMap<Integer, Long> messagesMediaIdsMap = new HashMap<>();
StringBuilder messageIds = new StringBuilder();
StringBuilder messageMediaIds = new StringBuilder();
SQLitePreparedStatement state = database.executeFast("REPLACE INTO messages VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)");
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO media VALUES(?, ?, ?, ?)");
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(?, ?, ?, ?)");
@ -2689,12 +2560,39 @@ public class MessagesStorage {
messagesIdsMap.put(message.id, dialog_id);
}
if (canAddMessageToMedia(message)) {
if (SharedMediaQuery.canAddMessageToMedia(message)) {
if (messageMediaIds.length() > 0) {
messageMediaIds.append(",");
}
messageMediaIds.append(message.id);
messagesMediaIdsMap.put(message.id, dialog_id);
mediaTypes.put(message.id, SharedMediaQuery.getMediaType(message));
}
}
if (messageMediaIds.length() > 0) {
SQLiteCursor cursor = database.queryFinalized("SELECT mid FROM media_v2 WHERE mid IN(" + messageMediaIds.toString() + ")");
while (cursor.next()) {
int mid = cursor.intValue(0);
messagesMediaIdsMap.remove(mid);
}
cursor.dispose();
for (HashMap.Entry<Integer, Long> entry : messagesMediaIdsMap.entrySet()) {
Integer type = mediaTypes.get(entry.getKey());
HashMap<Long, Integer> counts = mediaCounts.get(type);
Integer count;
if (counts == null) {
counts = new HashMap<>();
count = 0;
mediaCounts.put(type, counts);
} else {
count = counts.get(entry.getValue());
}
if (count == null) {
count = 0;
}
count++;
counts.put(entry.getValue(), count);
}
}
@ -2715,23 +2613,6 @@ public class MessagesStorage {
}
}
if (messageMediaIds.length() > 0) {
SQLiteCursor cursor = database.queryFinalized("SELECT mid FROM media WHERE mid IN(" + messageMediaIds.toString() + ")");
while (cursor.next()) {
int mid = cursor.intValue(0);
messagesMediaIdsMap.remove(mid);
}
cursor.dispose();
for (Long dialog_id : messagesMediaIdsMap.values()) {
Integer count = mediaCounts.get(dialog_id);
if (count == null) {
count = 0;
}
count++;
mediaCounts.put(dialog_id, count);
}
}
int downloadMediaMask = 0;
for (TLRPC.Message message : messages) {
fixUnsupportedMedia(message);
@ -2784,12 +2665,13 @@ public class MessagesStorage {
state3.step();
}
if (canAddMessageToMedia(message)) {
if (SharedMediaQuery.canAddMessageToMedia(message)) {
state2.requery();
state2.bindInteger(1, messageId);
state2.bindLong(2, dialog_id);
state2.bindInteger(3, message.date);
state2.bindByteBuffer(4, data.buffer);
state2.bindInteger(4, SharedMediaQuery.getMediaType(message));
state2.bindByteBuffer(5, data.buffer);
state2.step();
}
buffersStorage.reuseFreeBuffer(data);
@ -2883,32 +2765,36 @@ public class MessagesStorage {
state.step();
}
state.dispose();
if (withTransaction) {
database.commitTransaction();
}
MessagesController.getInstance().processDialogsUpdateRead(messagesCounts);
if (!mediaCounts.isEmpty()) {
state = database.executeFast("REPLACE INTO media_counts VALUES(?, ?)");
for (HashMap.Entry<Long, Integer> pair : mediaCounts.entrySet()) {
state = database.executeFast("REPLACE INTO media_counts_v2 VALUES(?, ?, ?)");
for (HashMap.Entry<Integer, HashMap<Long, Integer>> counts : mediaCounts.entrySet()) {
Integer type = counts.getKey();
for (HashMap.Entry<Long, Integer> pair : counts.getValue().entrySet()) {
long uid = pair.getKey();
int lower_part = (int) uid;
int count = -1;
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT count FROM media_counts WHERE uid = %d LIMIT 1", uid));
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT count FROM media_counts_v2 WHERE uid = %d AND type = %d LIMIT 1", uid, type));
if (cursor.next()) {
count = cursor.intValue(0);
}
cursor.dispose();
if (count != -1) {
state.requery();
count += pair.getValue();
state.bindLong(1, uid);
state.bindInteger(2, count);
state.bindInteger(2, type);
state.bindInteger(3, count);
state.step();
}
cursor.dispose();
}
}
state.dispose();
}
if (withTransaction) {
database.commitTransaction();
}
MessagesController.getInstance().processDialogsUpdateRead(messagesCounts);
if (downloadMediaMask != 0) {
final int downloadMediaMaskFinal = downloadMediaMask;
@ -3078,6 +2964,12 @@ public class MessagesStorage {
state.bindInteger(2, oldId);
state.step();
} catch (Exception e) {
try {
database.executeFast(String.format(Locale.US, "DELETE FROM messages WHERE mid = %d", oldId)).stepThis().dispose();
database.executeFast(String.format(Locale.US, "DELETE FROM messages_seq WHERE mid = %d", oldId)).stepThis().dispose();
} catch (Exception e2) {
FileLog.e("tmessages", e2);
}
FileLog.e("tmessages", e);
} finally {
if (state != null) {
@ -3087,11 +2979,16 @@ public class MessagesStorage {
}
try {
state = database.executeFast("UPDATE media SET mid = ? WHERE mid = ?");
state = database.executeFast("UPDATE media_v2 SET mid = ? WHERE mid = ?");
state.bindInteger(1, newId);
state.bindInteger(2, oldId);
state.step();
} catch (Exception e) {
try {
database.executeFast(String.format(Locale.US, "DELETE FROM media_v2 WHERE mid = %d", oldId)).stepThis().dispose();
} catch (Exception e2) {
FileLog.e("tmessages", e2);
}
FileLog.e("tmessages", e);
} finally {
if (state != null) {
@ -3352,8 +3249,8 @@ public class MessagesStorage {
FileLoader.getInstance().deleteFiles(filesToDelete);
database.executeFast(String.format(Locale.US, "DELETE FROM messages WHERE mid IN(%s)", ids)).stepThis().dispose();
database.executeFast(String.format(Locale.US, "DELETE FROM messages_seq WHERE mid IN(%s)", ids)).stepThis().dispose();
database.executeFast(String.format(Locale.US, "DELETE FROM media WHERE mid IN(%s)", ids)).stepThis().dispose();
database.executeFast("DELETE FROM media_counts WHERE 1").stepThis().dispose();
database.executeFast(String.format(Locale.US, "DELETE FROM media_v2 WHERE mid IN(%s)", ids)).stepThis().dispose();
database.executeFast("DELETE FROM media_counts_v2 WHERE 1").stepThis().dispose();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@ -3521,7 +3418,7 @@ public class MessagesStorage {
database.beginTransaction();
if (!messages.messages.isEmpty()) {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO messages VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)");
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO media VALUES(?, ?, ?, ?)");
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO media_v2 VALUES(?, ?, ?, ?, ?)");
for (TLRPC.Message message : messages.messages) {
fixUnsupportedMedia(message);
state.requery();
@ -3538,12 +3435,13 @@ public class MessagesStorage {
state.bindInteger(9, 0);
state.step();
if (message.media instanceof TLRPC.TL_messageMediaVideo || message.media instanceof TLRPC.TL_messageMediaPhoto) {
if (SharedMediaQuery.canAddMessageToMedia(message)) {
state2.requery();
state2.bindInteger(1, message.id);
state2.bindLong(2, dialog_id);
state2.bindInteger(3, message.date);
state2.bindByteBuffer(4, data.buffer);
state2.bindInteger(4, SharedMediaQuery.getMediaType(message));
state2.bindByteBuffer(5, data.buffer);
state2.step();
}
buffersStorage.reuseFreeBuffer(data);
@ -3573,13 +3471,22 @@ public class MessagesStorage {
usersToLoad.add(UserConfig.getClientUserId());
ArrayList<Integer> chatsToLoad = new ArrayList<>();
ArrayList<Integer> encryptedToLoad = new ArrayList<>();
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state FROM dialogs as d LEFT JOIN messages as m ON d.last_mid = m.mid ORDER BY d.date DESC LIMIT %d,%d", offset, count));
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT d.did, d.last_mid, d.unread_count, d.date, m.data, m.read_state, m.mid, m.send_state, s.flags FROM dialogs as d LEFT JOIN messages as m ON d.last_mid = m.mid LEFT JOIN dialog_settings as s ON d.did = s.did ORDER BY d.date DESC LIMIT %d,%d", offset, count));
while (cursor.next()) {
TLRPC.TL_dialog dialog = new TLRPC.TL_dialog();
dialog.id = cursor.longValue(0);
dialog.top_message = cursor.intValue(1);
dialog.unread_count = cursor.intValue(2);
dialog.last_message_date = cursor.intValue(3);
long flags = cursor.longValue(8);
int low_flags = (int)flags;
dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
if ((low_flags & 1) != 0) {
dialog.notify_settings.mute_until = (int)(flags >> 32);
if (dialog.notify_settings.mute_until == 0) {
dialog.notify_settings.mute_until = Integer.MAX_VALUE;
}
}
dialogs.dialogs.add(dialog);
ByteBufferDesc data = buffersStorage.getFreeBuffer(cursor.byteArrayLength(4));
@ -3680,7 +3587,7 @@ public class MessagesStorage {
if (!dialogs.dialogs.isEmpty()) {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO messages VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)");
SQLitePreparedStatement state2 = database.executeFast("REPLACE INTO dialogs(did, date, unread_count, last_mid) VALUES(?, ?, ?, ?)");
SQLitePreparedStatement state3 = database.executeFast("REPLACE INTO media VALUES(?, ?, ?, ?)");
SQLitePreparedStatement state3 = database.executeFast("REPLACE INTO media_v2 VALUES(?, ?, ?, ?, ?)");
SQLitePreparedStatement state4 = database.executeFast("REPLACE INTO dialog_settings VALUES(?, ?)");
for (TLRPC.TL_dialog dialog : dialogs.dialogs) {
@ -3717,12 +3624,13 @@ public class MessagesStorage {
state4.bindInteger(2, dialog.notify_settings.mute_until != 0 ? 1 : 0);
state4.step();
if (message.media instanceof TLRPC.TL_messageMediaVideo || message.media instanceof TLRPC.TL_messageMediaPhoto) {
if (SharedMediaQuery.canAddMessageToMedia(message)) {
state3.requery();
state3.bindLong(1, message.id);
state3.bindInteger(2, uid);
state3.bindInteger(3, message.date);
state3.bindByteBuffer(4, data.buffer);
state3.bindInteger(4, SharedMediaQuery.getMediaType(message));
state3.bindByteBuffer(5, data.buffer);
state3.step();
}
buffersStorage.reuseFreeBuffer(data);

View File

@ -52,6 +52,8 @@ public class NotificationCenter {
public static final int httpFileDidLoaded = totalEvents++;
public static final int httpFileDidFailedLoad = totalEvents++;
public static final int messageThumbGenerated = totalEvents++;
public static final int wallpapersDidLoaded = totalEvents++;
public static final int closeOtherAppActivities = totalEvents++;
public static final int didUpdatedConnectionState = totalEvents++;
@ -70,16 +72,16 @@ public class NotificationCenter {
public static final int FileNewChunkAvailable = totalEvents++;
public static final int FilePreparingFailed = totalEvents++;
public final static int audioProgressDidChanged = totalEvents++;
public final static int audioDidReset = totalEvents++;
public final static int recordProgressChanged = totalEvents++;
public final static int recordStarted = totalEvents++;
public final static int recordStartError = totalEvents++;
public final static int recordStopped = totalEvents++;
public final static int screenshotTook = totalEvents++;
public final static int albumsDidLoaded = totalEvents++;
public final static int audioDidSent = totalEvents++;
public final static int audioDidStarted = totalEvents++;
public static final int audioProgressDidChanged = totalEvents++;
public static final int audioDidReset = totalEvents++;
public static final int recordProgressChanged = totalEvents++;
public static final int recordStarted = totalEvents++;
public static final int recordStartError = totalEvents++;
public static final int recordStopped = totalEvents++;
public static final int screenshotTook = totalEvents++;
public static final int albumsDidLoaded = totalEvents++;
public static final int audioDidSent = totalEvents++;
public static final int audioDidStarted = totalEvents++;
public static final int audioRouteChanged = totalEvents++;
final private HashMap<Integer, ArrayList<Object>> observers = new HashMap<>();

View File

@ -0,0 +1,29 @@
/*
* 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.android;
import android.app.IntentService;
import android.content.Intent;
public class NotificationDelay extends IntentService {
public NotificationDelay() {
super("NotificationDelay");
}
@Override
protected void onHandleIntent(Intent intent) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
NotificationsController.getInstance().notificationDelayReached();
}
});
}
}

View File

@ -31,6 +31,8 @@ import org.json.JSONObject;
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.ApplicationLoader;
@ -57,6 +59,7 @@ public class NotificationsController {
private int total_unread_count = 0;
private int personal_count = 0;
private boolean notifyCheck = false;
private int lastOnlineFromOtherDevice = 0;
private static volatile NotificationsController Instance = null;
public static NotificationsController getInstance() {
@ -256,6 +259,27 @@ public class NotificationsController {
}
}
private void scheduleNotificationDelay(boolean onlineReason) {
try {
FileLog.e("tmessages", "delay notification start");
AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext.getSystemService(Context.ALARM_SERVICE);
PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationDelay.class), 0);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
if (onlineReason) {
alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 3 * 1000, pintent);
} else {
alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 500, pintent);
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
protected void notificationDelayReached() {
FileLog.e("tmessages", "delay reached");
showOrUpdateNotification(true);
}
protected void repeatNotificationMaybe() {
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
if (hour >= 11 && hour <= 22) {
@ -266,6 +290,15 @@ public class NotificationsController {
}
}
public void setLastOnlineFromOtherDevice(final int time) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
lastOnlineFromOtherDevice = time;
}
});
}
private void showOrUpdateNotification(boolean notifyAboutLast) {
if (!UserConfig.isClientActivated() || pushMessages.isEmpty()) {
dismissNotification();
@ -307,6 +340,12 @@ public class NotificationsController {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
int notify_override = preferences.getInt("notify2_" + dialog_id, 0);
if (notify_override == 3) {
int mute_until = preferences.getInt("notifyuntil_" + dialog_id, 0);
if (mute_until >= ConnectionsManager.getInstance().getCurrentTime()) {
notify_override = 2;
}
}
if (!notifyAboutLast || notify_override == 2 || (!preferences.getBoolean("EnableAll", true) || chat_id != 0 && !preferences.getBoolean("EnableGroup", true)) && notify_override == 0) {
notifyDisabled = true;
}
@ -490,7 +529,7 @@ public class NotificationsController {
}
if (photoPath != null) {
BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50", null);
BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50");
if (img != null) {
mBuilder.setLargeIcon(img.getBitmap());
}
@ -773,6 +812,12 @@ public class NotificationsController {
popup = (int)dialog_id == 0 ? 0 : preferences.getInt(isChat ? "popupGroup" : "popupAll", 0);
if (value == null) {
int notify_override = preferences.getInt("notify2_" + dialog_id, 0);
if (notify_override == 3) {
int mute_until = preferences.getInt("notifyuntil_" + dialog_id, 0);
if (mute_until >= ConnectionsManager.getInstance().getCurrentTime()) {
notify_override = 2;
}
}
value = !(notify_override == 2 || (!preferences.getBoolean("EnableAll", true) || isChat && !preferences.getBoolean("EnableGroup", true)) && notify_override == 0);
settingsCache.put(dialog_id, value);
}
@ -808,6 +853,12 @@ public class NotificationsController {
long dialog_id = entry.getKey();
int notify_override = preferences.getInt("notify2_" + dialog_id, 0);
if (notify_override == 3) {
int mute_until = preferences.getInt("notifyuntil_" + dialog_id, 0);
if (mute_until >= ConnectionsManager.getInstance().getCurrentTime()) {
notify_override = 2;
}
}
boolean canAddValue = !(notify_override == 2 || (!preferences.getBoolean("EnableAll", true) || ((int)dialog_id < 0) && !preferences.getBoolean("EnableGroup", true)) && notify_override == 0);
Integer currentCount = pushDialogs.get(dialog_id);
@ -842,6 +893,14 @@ public class NotificationsController {
pushDialogs.put(dialog_id, newCount);
}
}
/*if (old_unread_count != total_unread_count) { TODO
if (lastOnlineFromOtherDevice > ConnectionsManager.getInstance().getCurrentTime()) {
showOrUpdateNotification(false);
scheduleNotificationDelay(true);
} else {
showOrUpdateNotification(notifyCheck);
}
}*/
if (old_unread_count != total_unread_count) {
showOrUpdateNotification(notifyCheck);
}
@ -869,6 +928,12 @@ public class NotificationsController {
Boolean value = settingsCache.get(dialog_id);
if (value == null) {
int notify_override = preferences.getInt("notify2_" + dialog_id, 0);
if (notify_override == 3) {
int mute_until = preferences.getInt("notifyuntil_" + dialog_id, 0);
if (mute_until >= ConnectionsManager.getInstance().getCurrentTime()) {
notify_override = 2;
}
}
value = !(notify_override == 2 || (!preferences.getBoolean("EnableAll", true) || ((int) dialog_id < 0) && !preferences.getBoolean("EnableGroup", true)) && notify_override == 0);
settingsCache.put(dialog_id, value);
}
@ -884,7 +949,7 @@ public class NotificationsController {
if (pushMessagesDict.containsKey(message.id)) {
continue;
}
MessageObject messageObject = new MessageObject(message, null, 0);
MessageObject messageObject = new MessageObject(message, null, false);
if (isPersonalMessage(messageObject)) {
personal_count++;
}
@ -892,6 +957,12 @@ public class NotificationsController {
Boolean value = settingsCache.get(dialog_id);
if (value == null) {
int notify_override = preferences.getInt("notify2_" + dialog_id, 0);
if (notify_override == 3) {
int mute_until = preferences.getInt("notifyuntil_" + dialog_id, 0);
if (mute_until >= ConnectionsManager.getInstance().getCurrentTime()) {
notify_override = 2;
}
}
value = !(notify_override == 2 || (!preferences.getBoolean("EnableAll", true) || ((int) dialog_id < 0) && !preferences.getBoolean("EnableGroup", true)) && notify_override == 0);
settingsCache.put(dialog_id, value);
}
@ -957,4 +1028,49 @@ public class NotificationsController {
return messageObject.messageOwner.to_id != null && messageObject.messageOwner.to_id.chat_id == 0
&& (messageObject.messageOwner.action == null || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionEmpty);
}
public static void updateServerNotificationsSettings(long dialog_id) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.notificationsSettingsUpdated);
if ((int)dialog_id == 0) {
return;
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
TLRPC.TL_account_updateNotifySettings req = new TLRPC.TL_account_updateNotifySettings();
req.settings = new TLRPC.TL_inputPeerNotifySettings();
req.settings.sound = "default";
req.settings.events_mask = 0;
int mute_type = preferences.getInt("notify2_" + dialog_id, 0);
if (mute_type == 3) {
req.settings.mute_until = preferences.getInt("notifyuntil_" + dialog_id, 0);
} else {
req.settings.mute_until = mute_type != 2 ? 0 : Integer.MAX_VALUE;
}
req.settings.show_previews = preferences.getBoolean("preview_" + dialog_id, true);
req.peer = new TLRPC.TL_inputNotifyPeer();
if ((int)dialog_id < 0) {
((TLRPC.TL_inputNotifyPeer)req.peer).peer = new TLRPC.TL_inputPeerChat();
((TLRPC.TL_inputNotifyPeer)req.peer).peer.chat_id = -(int)dialog_id;
} else {
TLRPC.User user = MessagesController.getInstance().getUser((int)dialog_id);
if (user == null) {
return;
}
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
((TLRPC.TL_inputNotifyPeer)req.peer).peer = new TLRPC.TL_inputPeerForeign();
((TLRPC.TL_inputNotifyPeer)req.peer).peer.access_hash = user.access_hash;
} else {
((TLRPC.TL_inputNotifyPeer)req.peer).peer = new TLRPC.TL_inputPeerContact();
}
((TLRPC.TL_inputNotifyPeer)req.peer).peer.user_id = (int)dialog_id;
}
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
}
});
}
}

View File

@ -1,86 +0,0 @@
/*
* This is the source code of Telegram for Android v. 1.3.2.
* 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.
*/
package org.telegram.android;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.Utilities;
import java.nio.ByteBuffer;
import java.util.ArrayList;
public class PhotoObject {
public TLRPC.PhotoSize photoOwner;
public Bitmap image;
public PhotoObject(TLRPC.PhotoSize photo, int preview, boolean secret) {
photoOwner = photo;
if (preview != 0 && photo instanceof TLRPC.TL_photoCachedSize) {
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
opts.inDither = false;
opts.outWidth = photo.w;
opts.outHeight = photo.h;
try {
if (photo.location.ext != null) {
ByteBuffer buffer = ByteBuffer.allocateDirect(photo.bytes.length);
buffer.put(photo.bytes);
image = Utilities.loadWebpImage(buffer, buffer.limit(), null);
} else {
image = BitmapFactory.decodeByteArray(photoOwner.bytes, 0, photoOwner.bytes.length, opts);
}
if (image != null) {
if (preview == 2) {
if (secret) {
Utilities.blurBitmap(image, 7);
Utilities.blurBitmap(image, 7);
Utilities.blurBitmap(image, 7);
} else {
if (photo.location.ext != null) {
Utilities.blurBitmap(image, 1);
} else {
Utilities.blurBitmap(image, 3);
}
}
}
if (ImageLoader.getInstance().runtimeHack != null) {
ImageLoader.getInstance().runtimeHack.trackFree(image.getRowBytes() * image.getHeight());
}
}
} catch (Throwable throwable) {
FileLog.e("tmessages", throwable);
}
}
}
public static PhotoObject getClosestImageWithSize(ArrayList<PhotoObject> arr, int side) {
if (arr == null) {
return null;
}
int lastSide = 0;
PhotoObject closestObject = null;
for (PhotoObject obj : arr) {
if (obj == null || obj.photoOwner == null) {
continue;
}
int currentSide = obj.photoOwner.w >= obj.photoOwner.h ? obj.photoOwner.w : obj.photoOwner.h;
if (closestObject == null || closestObject.photoOwner instanceof TLRPC.TL_photoCachedSize || currentSide <= side && lastSide < currentSide) {
closestObject = obj;
lastSide = currentSide;
}
}
return closestObject;
}
}

View File

@ -478,7 +478,7 @@ public class SecretChatHelper {
reqSend.action.ttl_seconds = encryptedChat.ttl;
message = createServiceSecretMessage(encryptedChat, reqSend.action);
MessageObject newMsgObj = new MessageObject(message, null);
MessageObject newMsgObj = new MessageObject(message, null, false);
newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENDING;
ArrayList<MessageObject> objArr = new ArrayList<>();
objArr.add(newMsgObj);
@ -514,7 +514,7 @@ public class SecretChatHelper {
reqSend.action.random_ids = random_ids;
message = createServiceSecretMessage(encryptedChat, reqSend.action);
MessageObject newMsgObj = new MessageObject(message, null);
MessageObject newMsgObj = new MessageObject(message, null, false);
newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENDING;
ArrayList<MessageObject> objArr = new ArrayList<>();
objArr.add(newMsgObj);
@ -547,7 +547,7 @@ public class SecretChatHelper {
arr.add(newMsg);
MessagesStorage.getInstance().putMessages(arr, false, true, false, 0);
MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.photo, 3);
//MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.photo, 3);
} else if (newMsg.media instanceof TLRPC.TL_messageMediaVideo && newMsg.media.video != null) {
TLRPC.Video video = newMsg.media.video;
newMsg.media.video = new TLRPC.TL_videoEncrypted();
@ -578,7 +578,7 @@ public class SecretChatHelper {
arr.add(newMsg);
MessagesStorage.getInstance().putMessages(arr, false, true, false, 0);
MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.video, 5);
//MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.video, 5);
} else if (newMsg.media instanceof TLRPC.TL_messageMediaDocument && newMsg.media.document != null) {
TLRPC.Document document = newMsg.media.document;
newMsg.media.document = new TLRPC.TL_documentEncrypted();
@ -605,7 +605,7 @@ public class SecretChatHelper {
arr.add(newMsg);
MessagesStorage.getInstance().putMessages(arr, false, true, false, 0);
MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.document, 4);
//MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.document, 4);
} else if (newMsg.media instanceof TLRPC.TL_messageMediaAudio && newMsg.media.audio != null) {
TLRPC.Audio audio = newMsg.media.audio;
newMsg.media.audio = new TLRPC.TL_audioEncrypted();
@ -656,7 +656,8 @@ public class SecretChatHelper {
TLObject toEncryptObject = null;
if (AndroidUtilities.getPeerLayerVersion(chat.layer) >= 17) {
TLRPC.TL_decryptedMessageLayer layer = new TLRPC.TL_decryptedMessageLayer();
layer.layer = Math.min(17, AndroidUtilities.getPeerLayerVersion(chat.layer));
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))];
Utilities.random.nextBytes(layer.random_bytes);
@ -698,6 +699,7 @@ public class SecretChatHelper {
toEncryptObject = req;
}
int len = toEncryptObject.getObjectSize();
ByteBufferDesc toEncrypt = BuffersStorage.getInstance().getFreeBuffer(4 + len);
toEncrypt.writeInt32(len);

View File

@ -301,7 +301,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
public void run() {
if (message.documentLocation.thumb.location instanceof TLRPC.TL_fileLocationUnavailable) {
try {
Bitmap bitmap = ImageLoader.loadBitmap(cacheFile.getAbsolutePath(), null, 90, 90);
Bitmap bitmap = ImageLoader.loadBitmap(cacheFile.getAbsolutePath(), null, 90, 90, true);
if (bitmap != null) {
message.documentLocation.thumb = ImageLoader.scaleAndSaveImage(bitmap, 90, 90, 55, message.sendEncryptedRequest != null);
}
@ -753,7 +753,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
}
MessageObject newMsgObj = new MessageObject(newMsg, null, 2);
MessageObject newMsgObj = new MessageObject(newMsg, null, true);
newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENDING;
ArrayList<MessageObject> objArr = new ArrayList<>();
@ -1302,7 +1302,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
if (isBroadcast) {
for (TLRPC.Message message : sentMessages) {
ArrayList<MessageObject> arr = new ArrayList<>();
MessageObject messageObject = new MessageObject(message, null, 0);
MessageObject messageObject = new MessageObject(message, null, false);
arr.add(messageObject);
MessagesController.getInstance().updateInterfaceWithMessages(messageObject.getDialogId(), arr, isBroadcast);
}
@ -1369,7 +1369,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName + ".jpg");
File cacheFile2 = null;
if (sentMessage.media.photo.sizes.size() == 1 || size.w > 80 || size.h > 80) {
if (sentMessage.media.photo.sizes.size() == 1 || size.w > 90 || size.h > 90) {
cacheFile2 = FileLoader.getPathToAttach(size);
} else {
cacheFile2 = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName2 + ".jpg");
@ -1431,6 +1431,8 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
ImageLoader.getInstance().replaceImageInCache(fileName, fileName2);
size2.location = size.location;
}
} else if (MessageObject.isStickerMessage(sentMessage) && size2.location != null) {
size.location = size2.location;
}
newMsg.media.document.dc_id = sentMessage.media.document.dc_id;
@ -1501,7 +1503,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
MessagesController.getInstance().putChats(chats, true);
MessagesController.getInstance().putEncryptedChats(encryptedChats, true);
for (TLRPC.Message message : messages) {
MessageObject messageObject = new MessageObject(message, null, 0);
MessageObject messageObject = new MessageObject(message, null, false);
retrySendMessage(messageObject, true);
}
}
@ -1509,9 +1511,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
public TLRPC.TL_photo generatePhotoSizes(String path, Uri imageUri) {
Bitmap bitmap = ImageLoader.loadBitmap(path, imageUri, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
Bitmap bitmap = ImageLoader.loadBitmap(path, imageUri, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), true);
if (bitmap == null && AndroidUtilities.getPhotoSize() != 800) {
bitmap = ImageLoader.loadBitmap(path, imageUri, 800, 800);
bitmap = ImageLoader.loadBitmap(path, imageUri, 800, 800, true);
}
ArrayList<TLRPC.PhotoSize> sizes = new ArrayList<>();
TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(bitmap, 90, 90, 55, true);
@ -1578,10 +1580,13 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
originalPath += "" + f.length();
}
TLRPC.TL_document document = (TLRPC.TL_document)MessagesStorage.getInstance().getSentFile(originalPath, !isEncrypted ? 1 : 4);
if (document == null && !path.equals(originalPath)) {
TLRPC.TL_document document = null;
if (!isEncrypted) {
document = (TLRPC.TL_document) MessagesStorage.getInstance().getSentFile(originalPath, !isEncrypted ? 1 : 4);
if (document == null && !path.equals(originalPath) && !isEncrypted) {
document = (TLRPC.TL_document) MessagesStorage.getInstance().getSentFile(path + f.length(), !isEncrypted ? 1 : 4);
}
}
if (document == null) {
document = new TLRPC.TL_document();
document.id = 0;
@ -1603,7 +1608,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
if (document.mime_type.equals("image/gif")) {
try {
Bitmap bitmap = ImageLoader.loadBitmap(f.getAbsolutePath(), null, 90, 90);
Bitmap bitmap = ImageLoader.loadBitmap(f.getAbsolutePath(), null, 90, 90, true);
if (bitmap != null) {
document.thumb = ImageLoader.scaleAndSaveImage(bitmap, 90, 90, 55, isEncrypted);
}
@ -1727,7 +1732,10 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
boolean isEncrypted = (int)dialog_id == 0;
for (final MediaController.SearchImage searchImage : photos) {
if (searchImage.type == 1) {
TLRPC.TL_document document = (TLRPC.TL_document)MessagesStorage.getInstance().getSentFile(searchImage.imageUrl, !isEncrypted ? 1 : 4);
TLRPC.TL_document document = null;
if (!isEncrypted) {
document = (TLRPC.TL_document) MessagesStorage.getInstance().getSentFile(searchImage.imageUrl, !isEncrypted ? 1 : 4);
}
String md5 = Utilities.MD5(searchImage.imageUrl) + "." + ImageLoader.getHttpUrlExtension(searchImage.imageUrl);
File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), md5);
if (document == null) {
@ -1753,7 +1761,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
if (thumbFile != null) {
try {
Bitmap bitmap = ImageLoader.loadBitmap(thumbFile.getAbsolutePath(), null, 90, 90);
Bitmap bitmap = ImageLoader.loadBitmap(thumbFile.getAbsolutePath(), null, 90, 90, true);
if (bitmap != null) {
document.thumb = ImageLoader.scaleAndSaveImage(bitmap, 90, 90, 55, isEncrypted);
}
@ -1781,7 +1789,10 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
});
} else {
boolean needDownloadHttp = true;
TLRPC.TL_photo photo = (TLRPC.TL_photo) MessagesStorage.getInstance().getSentFile(searchImage.imageUrl, !isEncrypted ? 0 : 3);
TLRPC.TL_photo photo = null;
if (!isEncrypted) {
photo = (TLRPC.TL_photo) MessagesStorage.getInstance().getSentFile(searchImage.imageUrl, !isEncrypted ? 0 : 3);
}
if (photo == null) {
String md5 = Utilities.MD5(searchImage.imageUrl) + "." + ImageLoader.getHttpUrlExtension(searchImage.imageUrl);
File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), md5);
@ -1891,10 +1902,13 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
} else {
originalPath = null;
}
TLRPC.TL_photo photo = (TLRPC.TL_photo)MessagesStorage.getInstance().getSentFile(originalPath, !isEncrypted ? 0 : 3);
TLRPC.TL_photo photo = null;
if (!isEncrypted) {
photo = (TLRPC.TL_photo) MessagesStorage.getInstance().getSentFile(originalPath, !isEncrypted ? 0 : 3);
if (photo == null && uri != null) {
photo = (TLRPC.TL_photo) MessagesStorage.getInstance().getSentFile(Utilities.getPath(uri), !isEncrypted ? 0 : 3);
}
}
if (photo == null) {
photo = SendMessagesHelper.getInstance().generatePhotoSizes(path, uri);
}
@ -1935,7 +1949,10 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
if (videoEditedInfo != null) {
originalPath += duration + "_" + videoEditedInfo.startTime + "_" + videoEditedInfo.endTime;
}
TLRPC.TL_video video = (TLRPC.TL_video)MessagesStorage.getInstance().getSentFile(originalPath, !isEncrypted ? 2 : 5);
TLRPC.TL_video video = null;
if (!isEncrypted) {
video = (TLRPC.TL_video) MessagesStorage.getInstance().getSentFile(originalPath, !isEncrypted ? 2 : 5);
}
if (video == null) {
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Video.Thumbnails.MINI_KIND);
TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(thumb, 90, 90, 55, isEncrypted);

View File

@ -0,0 +1,398 @@
/*
* 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.android.query;
import org.telegram.SQLite.SQLiteCursor;
import org.telegram.SQLite.SQLitePreparedStatement;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.ImageLoader;
import org.telegram.android.MessageObject;
import org.telegram.android.MessagesController;
import org.telegram.android.MessagesStorage;
import org.telegram.android.NotificationCenter;
import org.telegram.messenger.ByteBufferDesc;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.TLClassStore;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
public class SharedMediaQuery {
public final static int MEDIA_PHOTOVIDEO = 0;
public final static int MEDIA_FILE = 1;
public final static int MEDIA_AUDIO = 2;
public static void loadMedia(final long uid, final int offset, final int count, final int max_id, final int type, final boolean fromCache, final int classGuid) {
int lower_part = (int)uid;
if (fromCache || lower_part == 0) {
loadMediaDatabase(uid, offset, count, max_id, type, classGuid);
} else {
TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
req.offset = offset;
req.limit = count;
req.max_id = max_id;
if (type == MEDIA_PHOTOVIDEO) {
req.filter = new TLRPC.TL_inputMessagesFilterPhotoVideo();
} else if (type == MEDIA_FILE) {
req.filter = new TLRPC.TL_inputMessagesFilterDocument();
} else if (type == MEDIA_AUDIO) {
req.filter = new TLRPC.TL_inputMessagesFilterAudio();
}
req.q = "";
if (uid < 0) {
req.peer = new TLRPC.TL_inputPeerChat();
req.peer.chat_id = -lower_part;
} else {
TLRPC.User user = MessagesController.getInstance().getUser(lower_part);
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
req.peer = new TLRPC.TL_inputPeerForeign();
req.peer.access_hash = user.access_hash;
} else {
req.peer = new TLRPC.TL_inputPeerContact();
}
req.peer.user_id = lower_part;
}
long reqId = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
final TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
processLoadedMedia(res, uid, offset, count, max_id, type, false, classGuid);
}
}
});
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
}
}
public static void getMediaCount(final long uid, final int type, final int classGuid, boolean fromCache) {
int lower_part = (int)uid;
if (fromCache || lower_part == 0) {
getMediaCountDatabase(uid, type, classGuid);
} else {
TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
req.offset = 0;
req.limit = 1;
req.max_id = 0;
if (type == MEDIA_PHOTOVIDEO) {
req.filter = new TLRPC.TL_inputMessagesFilterPhotoVideo();
} else if (type == MEDIA_FILE) {
req.filter = new TLRPC.TL_inputMessagesFilterDocument();
} else if (type == MEDIA_AUDIO) {
req.filter = new TLRPC.TL_inputMessagesFilterAudio();
}
req.q = "";
if (uid < 0) {
req.peer = new TLRPC.TL_inputPeerChat();
req.peer.chat_id = -lower_part;
} else {
TLRPC.User user = MessagesController.getInstance().getUser(lower_part);
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
req.peer = new TLRPC.TL_inputPeerForeign();
req.peer.access_hash = user.access_hash;
} else {
req.peer = new TLRPC.TL_inputPeerContact();
}
req.peer.user_id = lower_part;
}
long reqId = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
final TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, true, true);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
MessagesController.getInstance().putUsers(res.users, false);
MessagesController.getInstance().putChats(res.chats, false);
}
});
if (res instanceof TLRPC.TL_messages_messagesSlice) {
processLoadedMediaCount(res.count, uid, type, classGuid, false);
} else {
processLoadedMediaCount(res.messages.size(), uid, type, classGuid, false);
}
}
}
});
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
}
}
public static int getMediaType(TLRPC.Message message) {
if (message == null) {
return -1;
}
if (message.media instanceof TLRPC.TL_messageMediaPhoto || message.media instanceof TLRPC.TL_messageMediaVideo) {
return SharedMediaQuery.MEDIA_PHOTOVIDEO;
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
if (MessageObject.isStickerMessage(message)) {
return -1;
} else {
return SharedMediaQuery.MEDIA_FILE;
}
} else if (message.media instanceof TLRPC.TL_messageMediaAudio) {
return SharedMediaQuery.MEDIA_AUDIO;
}
return -1;
}
public static boolean canAddMessageToMedia(TLRPC.Message message) {
if (message instanceof TLRPC.TL_message_secret && message.media instanceof TLRPC.TL_messageMediaPhoto && message.ttl != 0 && message.ttl <= 60) {
return false;
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto || message.media instanceof TLRPC.TL_messageMediaVideo || message.media instanceof TLRPC.TL_messageMediaDocument || message.media instanceof TLRPC.TL_messageMediaAudio) {
return true;
}
return false;
}
private static void processLoadedMedia(final TLRPC.messages_Messages res, final long uid, int offset, int count, int max_id, final int type, final boolean fromCache, final int classGuid) {
int lower_part = (int)uid;
if (fromCache && res.messages.isEmpty() && lower_part != 0) {
loadMedia(uid, offset, count, max_id, type, false, classGuid);
} else {
if (!fromCache) {
ImageLoader.saveMessagesThumbs(res.messages);
MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, true, true);
putMediaDatabase(uid, type, res.messages);
}
final HashMap<Integer, TLRPC.User> usersLocal = new HashMap<>();
for (TLRPC.User u : res.users) {
usersLocal.put(u.id, u);
}
final ArrayList<MessageObject> objects = new ArrayList<>();
for (TLRPC.Message message : res.messages) {
objects.add(new MessageObject(message, usersLocal, false));
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
int totalCount;
if (res instanceof TLRPC.TL_messages_messagesSlice) {
totalCount = res.count;
} else {
totalCount = res.messages.size();
}
MessagesController.getInstance().putUsers(res.users, fromCache);
MessagesController.getInstance().putChats(res.chats, fromCache);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.mediaDidLoaded, uid, totalCount, objects, fromCache, classGuid, type);
}
});
}
}
private static void processLoadedMediaCount(final int count, final long uid, final int type, final int classGuid, final boolean fromCache) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
int lower_part = (int)uid;
if (fromCache && count == -1 && lower_part != 0) {
getMediaCount(uid, type, classGuid, false);
} else {
if (!fromCache) {
putMediaCountDatabase(uid, type, count);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.mediaCountDidLoaded, uid, (fromCache && count == -1 ? 0 : count), fromCache, type);
}
}
});
}
private static void putMediaCountDatabase(final long uid, final int type, final int count) {
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
try {
SQLitePreparedStatement state2 = MessagesStorage.getInstance().getDatabase().executeFast("REPLACE INTO media_counts_v2 VALUES(?, ?, ?)");
state2.requery();
state2.bindLong(1, uid);
state2.bindInteger(2, type);
state2.bindInteger(3, count);
state2.step();
state2.dispose();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
}
private static void getMediaCountDatabase(final long uid, final int type, final int classGuid) {
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
try {
int count = -1;
SQLiteCursor cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT count FROM media_counts_v2 WHERE uid = %d AND type = %d LIMIT 1", uid, type));
if (cursor.next()) {
count = cursor.intValue(0);
}
cursor.dispose();
int lower_part = (int)uid;
if (count == -1 && lower_part == 0) {
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT COUNT(mid) FROM media_v2 WHERE uid = %d AND type = %d LIMIT 1", uid, type));
if (cursor.next()) {
count = cursor.intValue(0);
}
cursor.dispose();
/*cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, send_state, date FROM messages WHERE uid = %d ORDER BY mid ASC LIMIT %d", uid, 1000));
ArrayList<TLRPC.Message> photos = new ArrayList<>();
ArrayList<TLRPC.Message> docs = new ArrayList<>();
while (cursor.next()) {
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(cursor.byteArrayLength(1));
if (data != null && cursor.byteBufferValue(1, data.buffer) != 0) {
TLRPC.Message message = (TLRPC.Message) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
MessageObject.setIsUnread(message, cursor.intValue(0) != 1);
message.date = cursor.intValue(2);
message.send_state = cursor.intValue(1);
message.dialog_id = uid;
if (message.ttl > 60 && message.media instanceof TLRPC.TL_messageMediaPhoto || message.media instanceof TLRPC.TL_messageMediaVideo) {
photos.add(message);
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
docs.add(message);
}
}
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
}
cursor.dispose();
if (!photos.isEmpty() || !docs.isEmpty()) {
MessagesStorage.getInstance().getDatabase().beginTransaction();
if (!photos.isEmpty()) {
putMediaDatabaseInternal(uid, MEDIA_PHOTOVIDEO, photos);
}
if (docs.isEmpty()) {
putMediaDatabaseInternal(uid, MEDIA_FILE, docs);
}
MessagesStorage.getInstance().getDatabase().commitTransaction();
}*/
if (count != -1) {
putMediaCountDatabase(uid, type, count);
}
}
processLoadedMediaCount(count, uid, type, classGuid, true);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
}
private static void loadMediaDatabase(final long uid, final int offset, final int count, final int max_id, final int type, final int classGuid) {
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
TLRPC.TL_messages_messages res = new TLRPC.TL_messages_messages();
try {
ArrayList<Integer> loadedUsers = new ArrayList<>();
ArrayList<Integer> fromUser = new ArrayList<>();
SQLiteCursor cursor;
if ((int)uid != 0) {
if (max_id != 0) {
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, mid FROM media_v2 WHERE uid = %d AND mid < %d AND type = %d ORDER BY date DESC, mid DESC LIMIT %d", uid, max_id, type, count));
} else {
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, mid FROM media_v2 WHERE uid = %d AND type = %d ORDER BY date DESC, mid DESC LIMIT %d,%d", uid, type, offset, count));
}
} else {
if (max_id != 0) {
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT m.data, m.mid, r.random_id FROM media_v2 as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.mid > %d AND type = %d ORDER BY m.mid ASC LIMIT %d", uid, max_id, type, count));
} else {
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT m.data, m.mid, r.random_id FROM media_v2 as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND type = %d ORDER BY m.mid ASC LIMIT %d,%d", uid, type, offset, count));
}
}
while (cursor.next()) {
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Message message = (TLRPC.Message) TLClassStore.Instance().TLdeserialize(data, data.readInt32());
message.id = cursor.intValue(1);
message.dialog_id = uid;
if ((int)uid == 0) {
message.random_id = cursor.longValue(2);
}
res.messages.add(message);
fromUser.add(message.from_id);
}
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
}
cursor.dispose();
StringBuilder usersToLoad = new StringBuilder();
for (int uid : fromUser) {
if (!loadedUsers.contains(uid)) {
if (usersToLoad.length() != 0) {
usersToLoad.append(",");
}
usersToLoad.append(uid);
loadedUsers.add(uid);
}
}
if (usersToLoad.length() != 0) {
MessagesStorage.getInstance().getUsersInternal(usersToLoad.toString(), res.users);
}
} catch (Exception e) {
res.messages.clear();
res.chats.clear();
res.users.clear();
FileLog.e("tmessages", e);
} finally {
processLoadedMedia(res, uid, offset, count, max_id, type, true, classGuid);
}
}
});
}
private static void putMediaDatabaseInternal(final long uid, final int type, final ArrayList<TLRPC.Message> messages) {
try {
MessagesStorage.getInstance().getDatabase().beginTransaction();
SQLitePreparedStatement state2 = MessagesStorage.getInstance().getDatabase().executeFast("REPLACE INTO media_v2 VALUES(?, ?, ?, ?, ?)");
for (TLRPC.Message message : messages) {
if (canAddMessageToMedia(message)) {
state2.requery();
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(message.getObjectSize());
message.serializeToStream(data);
state2.bindInteger(1, message.id);
state2.bindLong(2, uid);
state2.bindInteger(3, message.date);
state2.bindInteger(4, type);
state2.bindByteBuffer(5, data.buffer);
state2.step();
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
}
}
state2.dispose();
MessagesStorage.getInstance().getDatabase().commitTransaction();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
private static void putMediaDatabase(final long uid, final int type, final ArrayList<TLRPC.Message> messages) {
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
putMediaDatabaseInternal(uid, type, messages);
}
});
}
}

View File

@ -14,6 +14,7 @@ import android.content.pm.PackageInfo;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.PowerManager;
import android.util.Base64;
import org.telegram.android.AndroidUtilities;
@ -81,6 +82,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
private volatile long nextCallToken = 1;
private PowerManager.WakeLock wakeLock = null;
private static volatile ConnectionsManager Instance = null;
public static ConnectionsManager getInstance() {
ConnectionsManager localInstance = Instance;
@ -213,6 +216,14 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
Utilities.stageQueue.postRunnable(stageRunnable, 1000);
try {
PowerManager pm = (PowerManager)ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
wakeLock.setReferenceCounted(false);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
public int getConnectionState() {
@ -456,7 +467,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
} else {
Datacenter datacenter = new Datacenter();
datacenter.datacenterId = 1;
datacenter.addAddressAndPort("173.240.5.253", 443);
datacenter.addAddressAndPort("149.154.175.10", 443);
datacenters.put(datacenter.datacenterId, datacenter);
datacenter = new Datacenter();
@ -566,25 +577,33 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
while (requestQueue.size() != 0) {
RPCRequest request = requestQueue.get(0);
requestQueue.remove(0);
for (int a = 0; a < requestQueue.size(); a++) {
RPCRequest request = requestQueue.get(a);
if ((request.flags & RPCRequest.RPCRequestClassWithoutLogin) != 0) {
continue;
}
requestQueue.remove(a);
if (request.completionBlock != null) {
TLRPC.TL_error implicitError = new TLRPC.TL_error();
implicitError.code = -1000;
implicitError.text = "";
request.completionBlock.run(null, implicitError);
}
a--;
}
while (runningRequests.size() != 0) {
RPCRequest request = runningRequests.get(0);
runningRequests.remove(0);
for (int a = 0; a < runningRequests.size(); a++) {
RPCRequest request = runningRequests.get(a);
if ((request.flags & RPCRequest.RPCRequestClassWithoutLogin) != 0) {
continue;
}
runningRequests.remove(a);
if (request.completionBlock != null) {
TLRPC.TL_error implicitError = new TLRPC.TL_error();
implicitError.code = -1000;
implicitError.text = "";
request.completionBlock.run(null, implicitError);
}
a--;
}
pingIdToDate.clear();
quickAckIdToRequestIds.clear();
@ -2140,6 +2159,15 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
} else {
if (resultContainer.result instanceof TLRPC.updates_Difference) {
pushMessagesReceived = true;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (wakeLock.isHeld()) {
FileLog.e("tmessages", "release wakelock");
wakeLock.release();
}
}
});
}
if (request.rawRequest instanceof TLRPC.TL_auth_checkPassword) {
UserConfig.setWaitingForPasswordEnter(false);
@ -2337,9 +2365,25 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (paused) {
pushMessagesReceived = false;
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
FileLog.e("tmessages", "acquire wakelock");
wakeLock.acquire(20000);
}
});
resumeNetworkInternal();
} else {
pushMessagesReceived = true;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (wakeLock.isHeld()) {
FileLog.e("tmessages", "release wakelock");
wakeLock.release();
}
}
});
MessagesController.getInstance().processUpdates((TLRPC.Updates) message, false);
}
} else {
@ -2444,7 +2488,25 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
});
} else if ((connection.transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
FileLog.e("tmessages", "call connection closed");
FileLog.e("tmessages", "push connection closed");
if (BuildVars.DEBUG_VERSION) {
try {
ConnectivityManager cm = (ConnectivityManager)ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] networkInfos = cm.getAllNetworkInfo();
for (int a = 0; a < 2; a++) {
if (a >= networkInfos.length) {
break;
}
NetworkInfo info = networkInfos[a];
FileLog.e("tmessages", "Network: " + info.getTypeName() + " status: " + info.getState() + " info: " + info.getExtraInfo() + " object: " + info.getDetailedState() + " other: " + info);
}
if (networkInfos.length == 0) {
FileLog.e("tmessages", "no network available");
}
} catch (Exception e) {
FileLog.e("tmessages", "NETWORK STATE GET ERROR", e);
}
}
sendingPushPing = false;
lastPushPingTime = System.currentTimeMillis() - 60000 * 3 + 4000;
}
@ -2456,7 +2518,10 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (datacenter.authKey != null) {
if ((connection.transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
sendingPushPing = false;
lastPushPingTime = System.currentTimeMillis() - 60000 * 3 + 4000;
//lastPushPingTime = System.currentTimeMillis() - 60000 * 3 + 4000; //TODO check this
//FileLog.e("tmessages", "schedule push ping in 4 seconds");
lastPushPingTime = System.currentTimeMillis();
generatePing(datacenter, true);
} else {
if (paused && lastPauseTime != 0) {
lastPauseTime = System.currentTimeMillis();
@ -2541,6 +2606,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
} else {
if (datacenter.authKeyId == 0 || keyId != datacenter.authKeyId) {
FileLog.e("tmessages", "Error: invalid auth key id " + connection);
datacenter.switchTo443Port();
connection.suspendConnection(true);
connection.connect();
return;
@ -2581,6 +2647,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (!Utilities.arraysEquals(messageKey, 0, realMessageKeyFull, realMessageKeyFull.length - 16)) {
FileLog.e("tmessages", "***** Error: invalid message key");
datacenter.switchTo443Port();
connection.suspendConnection(true);
connection.connect();
return;

View File

@ -115,6 +115,16 @@ public class Datacenter {
readCurrentAddressAndPortNum();
}
public void switchTo443Port() {
for (int a = 0; a < addresses.size(); a++) {
if (ports.get(addresses.get(a)) == 443) {
currentAddressNum = a;
currentPortNum = 0;
break;
}
}
}
public String getCurrentAddress() {
if (addresses.isEmpty()) {
return null;

View File

@ -55,7 +55,7 @@ public class FileLoadOperation {
private boolean isForceRequest = false;
public static interface FileLoadOperationDelegate {
public abstract void didFinishLoadingFile(FileLoadOperation operation, File finalFile, File tempFile);
public abstract void didFinishLoadingFile(FileLoadOperation operation, File finalFile);
public abstract void didFailedLoadingFile(FileLoadOperation operation, int state);
public abstract void didChangedLoadProgress(FileLoadOperation operation, float progress);
}
@ -341,9 +341,11 @@ public class FileLoadOperation {
cacheIvTemp.delete();
}
if (cacheFileTemp != null) {
cacheFileTemp.renameTo(cacheFileFinal);
if (!cacheFileTemp.renameTo(cacheFileFinal)) {
cacheFileFinal = cacheFileTemp;
}
delegate.didFinishLoadingFile(FileLoadOperation.this, cacheFileFinal, cacheFileTemp);
}
delegate.didFinishLoadingFile(FileLoadOperation.this, cacheFileFinal);
}
private void processRequestResult(RequestInfo requestInfo, TLRPC.TL_error error) {
@ -373,7 +375,8 @@ public class FileLoadOperation {
fiv.seek(0);
fiv.write(iv);
}
downloadedBytes += requestInfo.response.bytes.limit();
int currentBytesSize = requestInfo.response.bytes.limit();
downloadedBytes += currentBytesSize;
if (totalBytesCount > 0 && state == stateDownloading) {
delegate.didChangedLoadProgress(FileLoadOperation.this, Math.min(1.0f, (float)downloadedBytes / (float)totalBytesCount));
}
@ -390,11 +393,15 @@ public class FileLoadOperation {
}
}
if (currentBytesSize != downloadChunkSize) {
onFinishLoadingFile();
} else {
if (totalBytesCount != downloadedBytes && downloadedBytes % downloadChunkSize == 0 || totalBytesCount > 0 && totalBytesCount > downloadedBytes) {
startDownloadRequest();
} else {
onFinishLoadingFile();
}
}
} catch (Exception e) {
cleanup();
delegate.didFailedLoadingFile(FileLoadOperation.this, 0);

View File

@ -23,7 +23,7 @@ public class FileLoader {
public abstract void fileUploadProgressChanged(String location, float progress, boolean isEncrypted);
public abstract void fileDidUploaded(String location, TLRPC.InputFile inputFile, TLRPC.InputEncryptedFile inputEncryptedFile);
public abstract void fileDidFailedUpload(String location, boolean isEncrypted);
public abstract void fileDidLoaded(String location, File finalFile, File tempFile);
public abstract void fileDidLoaded(String location, File finalFile, int type);
public abstract void fileDidFailedLoad(String location, int state);
public abstract void fileLoadProgressChanged(String location, float progress);
}
@ -395,53 +395,50 @@ public class FileLoader {
File tempDir = getDirectory(MEDIA_DIR_CACHE);
File storeDir = tempDir;
int type = MEDIA_DIR_CACHE;
if (video != null) {
operation = new FileLoadOperation(video);
if (!cacheOnly) {
storeDir = getDirectory(MEDIA_DIR_VIDEO);
}
type = MEDIA_DIR_VIDEO;
} else if (location != null) {
operation = new FileLoadOperation(location, locationSize);
if (!cacheOnly) {
storeDir = getDirectory(MEDIA_DIR_IMAGE);
}
type = MEDIA_DIR_IMAGE;
} else if (document != null) {
operation = new FileLoadOperation(document);
if (!cacheOnly) {
storeDir = getDirectory(MEDIA_DIR_DOCUMENT);
}
type = MEDIA_DIR_DOCUMENT;
} else if (audio != null) {
operation = new FileLoadOperation(audio);
if (!cacheOnly) {
storeDir = getDirectory(MEDIA_DIR_AUDIO);
type = MEDIA_DIR_AUDIO;
}
if (!cacheOnly) {
storeDir = getDirectory(type);
}
operation.setPaths(storeDir, tempDir);
final String arg1 = fileName;
final String finalFileName = fileName;
final int finalType = type;
loadOperationPaths.put(fileName, operation);
operation.setDelegate(new FileLoadOperation.FileLoadOperationDelegate() {
@Override
public void didFinishLoadingFile(FileLoadOperation operation, File finalFile, File tempFile) {
public void didFinishLoadingFile(FileLoadOperation operation, File finalFile) {
if (delegate != null) {
delegate.fileDidLoaded(arg1, finalFile, tempFile);
delegate.fileDidLoaded(finalFileName, finalFile, finalType);
}
checkDownloadQueue(audio, location, arg1);
checkDownloadQueue(audio, location, finalFileName);
}
@Override
public void didFailedLoadingFile(FileLoadOperation operation, int canceled) {
checkDownloadQueue(audio, location, arg1);
checkDownloadQueue(audio, location, finalFileName);
if (delegate != null) {
delegate.fileDidFailedLoad(arg1, canceled);
delegate.fileDidFailedLoad(finalFileName, canceled);
}
}
@Override
public void didChangedLoadProgress(FileLoadOperation operation, float progress) {
if (delegate != null) {
delegate.fileLoadProgressChanged(arg1, progress);
delegate.fileLoadProgressChanged(finalFileName, progress);
}
}
});
@ -641,7 +638,7 @@ public class FileLoader {
continue;
}
int currentSide = obj.w >= obj.h ? obj.w : obj.h;
if (closestObject == null || closestObject instanceof TLRPC.TL_photoCachedSize || currentSide <= side && lastSide < currentSide) {
if (closestObject == null || obj instanceof TLRPC.TL_photoCachedSize || currentSide <= side && lastSide < currentSide) {
closestObject = obj;
lastSide = currentSide;
}

View File

@ -160,6 +160,26 @@ public class FileLog {
}
}
public static void w(final String tag, final String message) {
if (!BuildVars.DEBUG_VERSION) {
return;
}
Log.w(tag, message);
if (getInstance().streamWriter != null) {
getInstance().logQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
getInstance().streamWriter.write(getInstance().dateFormat.format(System.currentTimeMillis()) + " W/" + tag + ": " + message + "\n");
getInstance().streamWriter.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
public static void cleanupLogs() {
ArrayList<Uri> uris = new ArrayList<Uri>();
File sdCard = ApplicationLoader.applicationContext.getExternalFilesDir(null);

View File

@ -299,6 +299,9 @@ public class TcpConnection extends ConnectionContext {
if (canReuse) {
BuffersStorage.getInstance().reuseFreeBuffer(buff);
}
if (BuildConfig.DEBUG) {
FileLog.e("tmessages", TcpConnection.this + " disconnected, don't send data");
}
return;
}

View File

@ -48,6 +48,7 @@ public class ActionBar extends FrameLayout {
private boolean allowOverlayTitle;
private CharSequence lastTitle;
private boolean showingOverlayTitle;
private boolean castShadows = true;
protected boolean isSearchFieldVisible;
protected int itemsBackgroundResourceId;
@ -485,6 +486,14 @@ public class ActionBar extends FrameLayout {
}
}
public void setCastShadows(boolean value) {
castShadows = value;
}
public boolean getCastShadows() {
return castShadows;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);

View File

@ -68,8 +68,10 @@ public class ActionBarLayout extends FrameLayout {
continue;
}
if (view instanceof ActionBar && view.getVisibility() == VISIBLE) {
if (((ActionBar) view).getCastShadows()) {
actionBarHeight = view.getMeasuredHeight();
wasActionBar = true;
}
break;
}
}
@ -597,7 +599,7 @@ public class ActionBarLayout extends FrameLayout {
if (useAlphaAnimations && fragmentsStack.size() == 1) {
presentFragmentInternalRemoveOld(removeLast, currentFragment);
ArrayList<Object> animators = new ArrayList<Object>();
ArrayList<Object> animators = new ArrayList<>();
animators.add(ObjectAnimatorProxy.ofFloat(this, "alpha", 0.0f, 1.0f));
if (backgroundView != null) {
backgroundView.setVisibility(VISIBLE);
@ -783,7 +785,7 @@ public class ActionBarLayout extends FrameLayout {
}
};
ArrayList<Object> animators = new ArrayList<Object>();
ArrayList<Object> animators = new ArrayList<>();
animators.add(ObjectAnimatorProxy.ofFloat(this, "alpha", 1.0f, 0.0f));
if (backgroundView != null) {
animators.add(ObjectAnimatorProxy.ofFloat(backgroundView, "alpha", 1.0f, 0.0f));

View File

@ -14,7 +14,6 @@ import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import org.telegram.android.AndroidUtilities;
@ -78,11 +77,10 @@ public class ActionBarMenu extends LinearLayout {
public ActionBarMenuItem addItem(int id, int icon, int backgroundResource, Drawable drawable, int width) {
ActionBarMenuItem menuItem = new ActionBarMenuItem(getContext(), this, backgroundResource);
menuItem.setTag(id);
menuItem.setScaleType(ImageView.ScaleType.CENTER);
if (drawable != null) {
menuItem.setImageDrawable(drawable);
menuItem.iconView.setImageDrawable(drawable);
} else {
menuItem.setImageResource(icon);
menuItem.iconView.setImageResource(icon);
}
addView(menuItem);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)menuItem.getLayoutParams();

View File

@ -34,10 +34,11 @@ import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.messenger.R;
import org.telegram.ui.AnimationCompat.ViewProxy;
import org.telegram.ui.Components.FrameLayoutFixed;
import java.lang.reflect.Field;
public class ActionBarMenuItem extends ImageView {
public class ActionBarMenuItem extends FrameLayoutFixed {
public static class ActionBarMenuItemSearchListener {
public void onSearchExpand() { }
@ -51,6 +52,7 @@ public class ActionBarMenuItem extends ImageView {
private ActionBarPopupWindow popupWindow;
private EditText searchField;
private ImageView clearButton;
protected ImageView iconView;
private FrameLayout searchContainer;
private boolean isSearchField = false;
private ActionBarMenuItemSearchListener listener;
@ -61,11 +63,20 @@ public class ActionBarMenuItem extends ImageView {
private boolean showFromBottom;
private int menuHeight = AndroidUtilities.dp(16);
private boolean needOffset = Build.VERSION.SDK_INT >= 21;
private int subMenuOpenSide = 0;
public ActionBarMenuItem(Context context, ActionBarMenu menu, int background) {
super(context);
setBackgroundResource(background);
parentMenu = menu;
iconView = new ImageView(context);
iconView.setScaleType(ImageView.ScaleType.CENTER);
addView(iconView);
LayoutParams layoutParams = (LayoutParams) iconView.getLayoutParams();
layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = LayoutParams.MATCH_PARENT;
iconView.setLayoutParams(layoutParams);
}
@Override
@ -145,6 +156,10 @@ public class ActionBarMenuItem extends ImageView {
needOffset = Build.VERSION.SDK_INT >= 21 && value;
}
public void setSubMenuOpenSide(int side) {
subMenuOpenSide = side;
}
public TextView addSubItem(int id, String text, int icon) {
if (popupLayout == null) {
rect = new Rect();
@ -256,6 +271,7 @@ public class ActionBarMenuItem extends ImageView {
}
popupWindow.setFocusable(true);
if (popupLayout.getMeasuredWidth() == 0) {
if (subMenuOpenSide == 0) {
if (showFromBottom) {
popupWindow.showAsDropDown(this, -popupLayout.getMeasuredWidth() + getMeasuredWidth(), getOffsetY());
popupWindow.update(this, -popupLayout.getMeasuredWidth() + getMeasuredWidth(), getOffsetY(), -1, -1);
@ -264,11 +280,19 @@ public class ActionBarMenuItem extends ImageView {
popupWindow.update(this, parentMenu.parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), getOffsetY(), -1, -1);
}
} else {
popupWindow.showAsDropDown(this, -AndroidUtilities.dp(8), getOffsetY());
popupWindow.update(this, -AndroidUtilities.dp(8), getOffsetY(), -1, -1);
}
} else {
if (subMenuOpenSide == 0) {
if (showFromBottom) {
popupWindow.showAsDropDown(this, -popupLayout.getMeasuredWidth() + getMeasuredWidth(), getOffsetY());
} else {
popupWindow.showAsDropDown(this, parentMenu.parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), getOffsetY());
}
} else {
popupWindow.showAsDropDown(this, -AndroidUtilities.dp(8), getOffsetY());
}
}
}
@ -427,7 +451,7 @@ public class ActionBarMenuItem extends ImageView {
clearButton = new ImageView(getContext());
clearButton.setImageResource(R.drawable.ic_close_white);
clearButton.setScaleType(ScaleType.CENTER);
clearButton.setScaleType(ImageView.ScaleType.CENTER);
clearButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@ -459,11 +483,15 @@ public class ActionBarMenuItem extends ImageView {
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (popupWindow != null && popupWindow.isShowing()) {
if (subMenuOpenSide == 0) {
if (showFromBottom) {
popupWindow.update(this, -popupLayout.getMeasuredWidth() + getMeasuredWidth(), getOffsetY(), -1, -1);
} else {
popupWindow.update(this, parentMenu.parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), getOffsetY(), -1, -1);
}
} else {
popupWindow.update(this, -AndroidUtilities.dp(8), getOffsetY(), -1, -1);
}
}
}

View File

@ -99,12 +99,21 @@ public class ContactsSearchAdapter extends BaseContactsSearchAdapter {
Utilities.searchQueue.postRunnable(new Runnable() {
@Override
public void run() {
String q = query.trim().toLowerCase();
if (q.length() == 0) {
String search1 = query.trim().toLowerCase();
if (search1.length() == 0) {
updateSearchResults(new ArrayList<TLRPC.User>(), new ArrayList<CharSequence>());
return;
}
long time = System.currentTimeMillis();
String search2 = LocaleController.getInstance().getTranslitString(search1);
if (search1.equals(search2) || search2.length() == 0) {
search2 = null;
}
String search[] = new String[1 + (search2 != null ? 1 : 0)];
search[0] = search1;
if (search2 != null) {
search[1] = search2;
}
ArrayList<TLRPC.User> resultArray = new ArrayList<>();
ArrayList<CharSequence> resultArrayNames = new ArrayList<>();
@ -117,6 +126,7 @@ public class ContactsSearchAdapter extends BaseContactsSearchAdapter {
String name = ContactsController.formatName(user.first_name, user.last_name).toLowerCase();
int found = 0;
for (String q : search) {
if (name.startsWith(q) || name.contains(" " + q)) {
found = 1;
} else if (user.username != null && user.username.startsWith(q)) {
@ -130,6 +140,8 @@ public class ContactsSearchAdapter extends BaseContactsSearchAdapter {
resultArrayNames.add(Utilities.generateSearchName("@" + user.username, null, "@" + q));
}
resultArray.add(user);
break;
}
}
}

View File

@ -112,7 +112,7 @@ public class DialogsAdapter extends BaseFragmentAdapter {
}
}
MessageObject message = MessagesController.getInstance().dialogMessage.get(dialog.top_message);
((DialogCell) view).setDialog(dialog.id, message, true, dialog.last_message_date, dialog.unread_count);
((DialogCell) view).setDialog(dialog.id, message, true, dialog.last_message_date, dialog.unread_count, MessagesController.getInstance().isDialogMuted(dialog.id));
}
return view;

View File

@ -134,7 +134,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
searchResultMessages.clear();
}
for (TLRPC.Message message : res.messages) {
searchResultMessages.add(new MessageObject(message, null, 0));
searchResultMessages.add(new MessageObject(message, null, false));
}
messagesSearchEndReached = res.messages.size() != 20;
notifyDataSetChanged();
@ -155,12 +155,21 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
@Override
public void run() {
try {
String q = query.trim().toLowerCase();
if (q.length() == 0) {
String search1 = query.trim().toLowerCase();
if (search1.length() == 0) {
lastSearchId = -1;
updateSearchResults(new ArrayList<TLObject>(), new ArrayList<CharSequence>(), new ArrayList<TLRPC.User>(), lastSearchId);
return;
}
String search2 = LocaleController.getInstance().getTranslitString(search1);
if (search1.equals(search2) || search2.length() == 0) {
search2 = null;
}
String search[] = new String[1 + (search2 != null ? 1 : 0)];
search[0] = search1;
if (search2 != null) {
search[1] = search2;
}
ArrayList<Integer> usersToLoad = new ArrayList<>();
ArrayList<Integer> chatsToLoad = new ArrayList<>();
@ -212,6 +221,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
username = name.substring(usernamePos + 3);
}
int found = 0;
for (String q : search) {
if (name.startsWith(q) || name.contains(" " + q)) {
found = 1;
} else if (username != null && username.startsWith(q)) {
@ -236,6 +246,8 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
}
}
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
break;
}
}
}
cursor.dispose();
@ -245,7 +257,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, name FROM chats WHERE uid IN(%s)", TextUtils.join(",", chatsToLoad)));
while (cursor.next()) {
String name = cursor.stringValue(1);
String[] args = name.split(" ");
for (String q : search) {
if (name.startsWith(q) || name.contains(" " + q)) {
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
@ -262,6 +274,8 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
resultCount++;
}
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
break;
}
}
}
cursor.dispose();
@ -278,6 +292,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
username = name.substring(usernamePos + 2);
}
int found = 0;
for (String q : search) {
if (name.startsWith(q) || name.contains(" " + q)) {
found = 1;
} else if (username != null && username.startsWith(q)) {
@ -322,6 +337,8 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
}
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data2);
break;
}
}
}
cursor.dispose();
@ -367,6 +384,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
username = name.substring(usernamePos + 3);
}
int found = 0;
for (String q : search) {
if (name.startsWith(q) || name.contains(" " + q)) {
found = 1;
} else if (username != null && username.startsWith(q)) {
@ -389,6 +407,8 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
}
}
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
break;
}
}
}
cursor.dispose();
@ -598,7 +618,7 @@ public class DialogsSearchAdapter extends BaseContactsSearchAdapter {
}
((DialogCell) view).useSeparator = (i != getCount() - 1);
MessageObject messageObject = (MessageObject)getItem(i);
((DialogCell) view).setDialog(messageObject.getDialogId(), messageObject, false, messageObject.messageOwner.date, 0);
((DialogCell) view).setDialog(messageObject.getDialogId(), messageObject, false, messageObject.messageOwner.date, 0, false);
} else if (type == 3) {
if (view == null) {
view = new LoadingCell(mContext);

View File

@ -25,7 +25,7 @@ import org.telegram.android.AndroidUtilities;
import org.telegram.android.ImageReceiver;
import org.telegram.android.MessageObject;
import org.telegram.android.MessagesController;
import org.telegram.android.PhotoObject;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
@ -105,13 +105,9 @@ public class ChatActionCell extends BaseCell {
if (currentMessageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
imageReceiver.setImage(currentMessageObject.messageOwner.action.newUserPhoto.photo_small, "50_50", avatarDrawable, false);
} else {
PhotoObject photo = PhotoObject.getClosestImageWithSize(currentMessageObject.photoThumbs, AndroidUtilities.dp(64));
TLRPC.PhotoSize photo = FileLoader.getClosestPhotoSizeWithSize(currentMessageObject.photoThumbs, AndroidUtilities.dp(64));
if (photo != null) {
if (photo.image != null) {
imageReceiver.setImageBitmap(photo.image);
} else {
imageReceiver.setImage(photo.photoOwner.location, "50_50", avatarDrawable, false);
}
imageReceiver.setImage(photo.location, "50_50", avatarDrawable, false);
} else {
imageReceiver.setImageBitmap(avatarDrawable);
}

View File

@ -33,7 +33,6 @@ import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.Utilities;
import org.telegram.android.MessageObject;
import org.telegram.android.PhotoObject;
import org.telegram.ui.Components.RadialProgress;
import org.telegram.ui.PhotoViewer;
import org.telegram.ui.Components.GifDrawable;
@ -67,8 +66,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
private int photoWidth;
private int photoHeight;
private PhotoObject currentPhotoObject;
private PhotoObject currentPhotoObjectThumb;
private TLRPC.PhotoSize currentPhotoObject;
private TLRPC.PhotoSize currentPhotoObjectThumb;
private String currentUrl;
private String currentPhotoFilter;
private ImageReceiver photoImage;
@ -339,11 +338,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
cancelLoading = false;
radialProgress.setProgress(0, false);
if (currentMessageObject.type == 1) {
if (currentMessageObject.imagePreview != null) {
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, new BitmapDrawable(currentMessageObject.imagePreview), currentPhotoObject.photoOwner.size, false);
} else {
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, null, currentPhotoObject.photoOwner.size, false);
}
photoImage.setImage(currentPhotoObject.location, currentPhotoFilter, currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null, currentPhotoFilter, currentPhotoObject.size, false);
} else if (currentMessageObject.type == 8 || currentMessageObject.type == 9) {
FileLoader.getInstance().loadFile(currentMessageObject.messageOwner.media.document, true, false);
lastDownloadedGifMessage = currentMessageObject;
@ -361,7 +356,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
} else {
cancelLoading = true;
if (currentMessageObject.type == 1) {
ImageLoader.getInstance().cancelLoadingForImageView(photoImage);
photoImage.cancelLoadImage();
} else if (currentMessageObject.type == 8 || currentMessageObject.type == 9) {
FileLoader.getInstance().cancelLoadFile(currentMessageObject.messageOwner.media.document);
if (lastDownloadedGifMessage != null && lastDownloadedGifMessage.messageOwner.id == currentMessageObject.messageOwner.id) {
@ -402,7 +397,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
if (!url.equals(currentUrl)) {
return true;
}
} else if (currentPhotoObject == null || currentPhotoObject.photoOwner.location instanceof TLRPC.TL_fileLocationUnavailable) {
} else if (currentPhotoObject == null || currentPhotoObject.location instanceof TLRPC.TL_fileLocationUnavailable) {
return true;
} else if (currentMessageObject != null && photoNotSet) {
File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
@ -429,6 +424,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
photoNotSet = false;
drawBackground = true;
photoImage.setForcePreview(messageObject.isSecretPhoto());
if (messageObject.type == 9) {
String name = messageObject.getDocumentName();
if (name == null || name.length() == 0) {
@ -499,23 +495,21 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
nameLayout = null;
updateSecretTimeText();
}
if (messageObject.type == 9) {
if (messageObject.type == 9) { //doc
photoWidth = AndroidUtilities.dp(86);
photoHeight = AndroidUtilities.dp(86);
backgroundWidth = photoWidth + Math.max(nameWidth, infoWidth) + AndroidUtilities.dp(68);
currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
photoImage.setNeedsQualityThumb(true);
photoImage.setShouldGenerateQualityThumb(true);
photoImage.setParentMessageObject(messageObject);
if (currentPhotoObject != null) {
if (currentPhotoObject.image != null) {
photoImage.setImageBitmap(currentPhotoObject.image);
} else {
currentPhotoFilter = String.format(Locale.US, "%d_%d_b", photoWidth, photoHeight);
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, null, 0, false);
}
photoImage.setImage(null, null, null, null, currentPhotoObject.location, currentPhotoFilter, 0, true);
} else {
photoImage.setImageBitmap((BitmapDrawable) null);
}
} else if (messageObject.type == 4) {
} else if (messageObject.type == 4) { //geo
photoWidth = AndroidUtilities.dp(100);
photoHeight = AndroidUtilities.dp(100);
backgroundWidth = photoWidth + AndroidUtilities.dp(12);
@ -523,8 +517,11 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
double lat = messageObject.messageOwner.media.geo.lat;
double lon = messageObject.messageOwner.media.geo._long;
currentUrl = String.format(Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false", lat, lon, Math.min(2, (int)Math.ceil(AndroidUtilities.density)), lat, lon);
photoImage.setNeedsQualityThumb(false);
photoImage.setShouldGenerateQualityThumb(false);
photoImage.setParentMessageObject(null);
photoImage.setImage(currentUrl, null, null, 0);
} else if (messageObject.type == 13) {
} else if (messageObject.type == 13) { //webp
drawBackground = false;
for (TLRPC.DocumentAttribute attribute : messageObject.messageOwner.media.document.attributes) {
if (attribute instanceof TLRPC.TL_documentAttributeImageSize) {
@ -548,20 +545,26 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
photoWidth = (int)maxWidth;
}
backgroundWidth = photoWidth + AndroidUtilities.dp(12);
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 80);
photoImage.setNeedsQualityThumb(false);
photoImage.setShouldGenerateQualityThumb(false);
photoImage.setParentMessageObject(null);
if (currentMessageObject.messageOwner.attachPath != null && currentMessageObject.messageOwner.attachPath.length() > 0) {
File f = new File(currentMessageObject.messageOwner.attachPath);
if (f.exists()) {
photoImage.setImage(null, currentMessageObject.messageOwner.attachPath,
String.format(Locale.US, "%d_%d", photoWidth, photoHeight),
messageObject.imagePreview != null ? new BitmapDrawable(messageObject.imagePreview) : null,
null,
currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null,
"b1",
currentMessageObject.messageOwner.media.document.size, true);
}
} else if (currentMessageObject.messageOwner.media.document.id != 0) {
photoImage.setImage(currentMessageObject.messageOwner.media.document, null,
String.format(Locale.US, "%d_%d", photoWidth, photoHeight),
messageObject.imagePreview != null ? new BitmapDrawable(messageObject.imagePreview) : null,
messageObject.messageOwner.media.document.thumb.location,
null,
currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null,
"b1",
currentMessageObject.messageOwner.media.document.size, true);
}
} else {
@ -579,23 +582,38 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
photoHeight = AndroidUtilities.getPhotoSize();
}
currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
if (messageObject.type == 1) {
currentPhotoObjectThumb = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, 80);
photoImage.setNeedsQualityThumb(false);
photoImage.setShouldGenerateQualityThumb(false);
photoImage.setParentMessageObject(null);
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 80);
} else if (messageObject.type == 3) {
photoImage.setNeedsQualityThumb(true);
photoImage.setShouldGenerateQualityThumb(true);
photoImage.setParentMessageObject(messageObject);
} else if (messageObject.type == 8) {
photoImage.setNeedsQualityThumb(true);
photoImage.setShouldGenerateQualityThumb(true);
photoImage.setParentMessageObject(messageObject);
}
//8 - gif, 1 - photo, 3 - video
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
if (currentPhotoObject != null) {
boolean noSize = false;
if (currentMessageObject.type == 3 || currentMessageObject.type == 8) {
noSize = true;
}
float scale = (float) currentPhotoObject.photoOwner.w / (float) photoWidth;
float scale = (float) currentPhotoObject.w / (float) photoWidth;
if (!noSize && currentPhotoObject.photoOwner.size == 0) {
currentPhotoObject.photoOwner.size = -1;
if (!noSize && currentPhotoObject.size == 0) {
currentPhotoObject.size = -1;
}
int w = (int) (currentPhotoObject.photoOwner.w / scale);
int h = (int) (currentPhotoObject.photoOwner.h / scale);
int w = (int) (currentPhotoObject.w / scale);
int h = (int) (currentPhotoObject.h / scale);
if (w == 0) {
if (messageObject.type == 3) {
w = infoWidth + infoOffset + AndroidUtilities.dp(16);
@ -613,9 +631,9 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
w = (int) (w / scale2);
} else if (h < AndroidUtilities.dp(120)) {
h = AndroidUtilities.dp(120);
float hScale = (float) currentPhotoObject.photoOwner.h / h;
if (currentPhotoObject.photoOwner.w / hScale < photoWidth) {
w = (int) (currentPhotoObject.photoOwner.w / hScale);
float hScale = (float) currentPhotoObject.h / h;
if (currentPhotoObject.w / hScale < photoWidth) {
w = (int) (currentPhotoObject.w / hScale);
}
}
int timeWidthTotal = timeWidth + AndroidUtilities.dp(14 + (currentMessageObject.isOut() ? 20 : 0));
@ -634,49 +652,50 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
photoWidth = w;
photoHeight = h;
backgroundWidth = w + AndroidUtilities.dp(12);
currentPhotoFilter = String.format(Locale.US, "%d_%d", (int) (w / AndroidUtilities.density), (int) (h / AndroidUtilities.density));
if (messageObject.photoThumbs.size() > 1 || messageObject.type == 3 || messageObject.type == 8) {
if (messageObject.isSecretPhoto()) {
currentPhotoFilter += "_b2";
} else {
currentPhotoFilter += "_b";
}
}
if (currentPhotoObject.image != null) {
photoImage.setImageBitmap(currentPhotoObject.image);
} else {
boolean photoExist = true;
String fileName = FileLoader.getAttachFileName(currentPhotoObject.photoOwner);
String fileName = FileLoader.getAttachFileName(currentPhotoObject);
if (messageObject.type == 1) {
boolean photoExist = true;
File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
if (!cacheFile.exists()) {
photoExist = false;
} else {
MediaController.getInstance().removeLoadingFileObserver(this);
}
}
if (photoExist || MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO) || FileLoader.getInstance().isLoadingFile(fileName)) {
if (allowedToSetPhoto || ImageLoader.getInstance().getImageFromMemory(currentPhotoObject.photoOwner.location, null, currentPhotoFilter, null) != null) {
if (allowedToSetPhoto || ImageLoader.getInstance().getImageFromMemory(currentPhotoObject.location, null, currentPhotoFilter) != null) {
allowedToSetPhoto = true;
if (messageObject.imagePreview != null) {
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, new BitmapDrawable(messageObject.imagePreview), noSize ? 0 : currentPhotoObject.photoOwner.size, false);
photoImage.setImage(currentPhotoObject.location, currentPhotoFilter, currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null, currentPhotoFilter, noSize ? 0 : currentPhotoObject.size, false);
} else if (currentPhotoObjectThumb != null) {
photoImage.setImage(null, null, currentPhotoObjectThumb.location, currentPhotoFilter, 0, false);
} else {
photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, null, noSize ? 0 : currentPhotoObject.photoOwner.size, false);
}
} else {
photoImage.setImageBitmap(messageObject.imagePreview);
photoImage.setImageBitmap((Drawable) null);
}
} else {
photoNotSet = true;
if (messageObject.imagePreview != null) {
photoImage.setImageBitmap(messageObject.imagePreview);
} else if (currentPhotoObjectThumb != null) {
photoImage.setImage(currentPhotoObjectThumb.photoOwner.location, currentPhotoFilter, null, 0, true);
if (currentPhotoObjectThumb != null) {
photoImage.setImage(null, null, currentPhotoObjectThumb.location, currentPhotoFilter, 0, false);
} else {
photoImage.setImageBitmap((Drawable) null);
}
}
} else {
photoImage.setImage(null, null, currentPhotoObject.location, currentPhotoFilter, 0, false);
}
} else {
photoImage.setImageBitmap((Bitmap)null);
}
}
photoImage.setForcePreview(messageObject.isSecretPhoto());
invalidate();
}
@ -694,7 +713,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
if (currentPhotoObject == null) {
return;
}
fileName = FileLoader.getAttachFileName(currentPhotoObject.photoOwner);
fileName = FileLoader.getAttachFileName(currentPhotoObject);
cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
} else if (currentMessageObject.type == 8 || currentMessageObject.type == 3 || currentMessageObject.type == 9) {
if (currentMessageObject.messageOwner.attachPath != null && currentMessageObject.messageOwner.attachPath.length() != 0) {

View File

@ -50,6 +50,7 @@ public class DialogCell extends BaseCell {
private static Drawable countDrawable;
private static Drawable groupDrawable;
private static Drawable broadcastDrawable;
private static Drawable muteDrawable;
private static Paint linePaint;
@ -58,6 +59,7 @@ public class DialogCell extends BaseCell {
private int lastMessageDate;
private int unreadCount;
private boolean lastUnreadState;
private boolean dialogMuted;
private MessageObject message;
private ImageReceiver avatarImage;
@ -76,6 +78,7 @@ public class DialogCell extends BaseCell {
private boolean drawNameLock;
private boolean drawNameGroup;
private boolean drawNameBroadcast;
private int nameMuteLeft;
private int nameLockLeft;
private int nameLockTop;
@ -151,6 +154,7 @@ public class DialogCell extends BaseCell {
countDrawable = getResources().getDrawable(R.drawable.dialogs_badge);
groupDrawable = getResources().getDrawable(R.drawable.list_group);
broadcastDrawable = getResources().getDrawable(R.drawable.list_broadcast);
muteDrawable = getResources().getDrawable(R.drawable.mute_grey);
}
}
@ -162,12 +166,13 @@ public class DialogCell extends BaseCell {
avatarDrawable = new AvatarDrawable();
}
public void setDialog(long dialog_id, MessageObject messageObject, boolean usePrintStrings, int date, int unread) {
public void setDialog(long dialog_id, MessageObject messageObject, boolean usePrintStrings, int date, int unread, boolean muted) {
currentDialogId = dialog_id;
message = messageObject;
allowPrintStrings = usePrintStrings;
lastMessageDate = date;
unreadCount = unread;
dialogMuted = muted;
lastUnreadState = messageObject != null && messageObject.isUnread();
update(0);
}
@ -463,6 +468,14 @@ public class DialogCell extends BaseCell {
}
}
if (dialogMuted) {
int w = AndroidUtilities.dp(6) + muteDrawable.getIntrinsicWidth();
nameWidth -= w;
if (LocaleController.isRTL) {
nameLeft += w;
}
}
nameWidth = Math.max(AndroidUtilities.dp(12), nameWidth);
CharSequence nameStringFinal = TextUtils.ellipsize(nameString.replace("\n", " "), currentNamePaint, nameWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END);
try {
@ -536,6 +549,9 @@ public class DialogCell extends BaseCell {
nameLeft += (nameWidth - widthpx);
}
}
if (dialogMuted) {
nameMuteLeft = (nameLeft - AndroidUtilities.dp(6) - muteDrawable.getIntrinsicWidth());
}
}
if (messageLayout != null && messageLayout.getLineCount() > 0) {
left = messageLayout.getLineLeft(0);
@ -555,6 +571,9 @@ public class DialogCell extends BaseCell {
nameLeft -= (nameWidth - widthpx);
}
}
if (dialogMuted) {
nameMuteLeft = (int) (nameLeft + left + AndroidUtilities.dp(6));
}
}
if (messageLayout != null && messageLayout.getLineCount() > 0) {
left = messageLayout.getLineRight(0);
@ -710,6 +729,11 @@ public class DialogCell extends BaseCell {
}
}
if (dialogMuted) {
setDrawableBounds(muteDrawable, nameMuteLeft, AndroidUtilities.dp(16.5f));
muteDrawable.draw(canvas);
}
if (drawError) {
setDrawableBounds(errorDrawable, errorLeft, errorTop);
errorDrawable.draw(canvas);

View File

@ -0,0 +1,59 @@
/*
* 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.util.TypedValue;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.ui.Components.FrameLayoutFixed;
public class PhotoEditToolCell extends FrameLayoutFixed {
private ImageView iconImage;
private TextView nameTextView;
private TextView valueTextView;
public PhotoEditToolCell(Context context) {
super(context);
iconImage = new ImageView(context);
iconImage.setScaleType(ImageView.ScaleType.CENTER);
addView(iconImage);
LayoutParams layoutParams = (LayoutParams) iconImage.getLayoutParams();
layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = LayoutParams.MATCH_PARENT;
layoutParams.bottomMargin = AndroidUtilities.dp(20);
iconImage.setLayoutParams(layoutParams);
nameTextView = new TextView(context);
nameTextView.setGravity(Gravity.CENTER);
nameTextView.setTextColor(0xffffffff);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
addView(nameTextView);
layoutParams = (LayoutParams) nameTextView.getLayoutParams();
layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = AndroidUtilities.dp(20);
layoutParams.gravity = Gravity.LEFT | Gravity.BOTTOM;
nameTextView.setLayoutParams(layoutParams);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(80), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(60), MeasureSpec.EXACTLY));
}
public void setIconAndText(int resId, String text) {
iconImage.setImageResource(resId);
nameTextView.setText(text);
}
}

View File

@ -11,6 +11,7 @@ package org.telegram.ui.Cells;
import android.content.Context;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.ImageView;
import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.R;
@ -22,6 +23,7 @@ public class PhotoPickerPhotoCell extends FrameLayout {
public BackupImageView photoImage;
public FrameLayout checkFrame;
public CheckBox checkBox;
public ImageView editedImage;
public int itemWidth;
public PhotoPickerPhotoCell(Context context) {
@ -55,6 +57,16 @@ public class PhotoPickerPhotoCell extends FrameLayout {
layoutParams.topMargin = AndroidUtilities.dp(6);
layoutParams.rightMargin = AndroidUtilities.dp(6);
checkBox.setLayoutParams(layoutParams);
editedImage = new ImageView(context);
editedImage.setImageResource(R.drawable.photo_edit);
editedImage.setScaleType(ImageView.ScaleType.CENTER);
addView(editedImage);
layoutParams = (LayoutParams) editedImage.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(42);
layoutParams.height = AndroidUtilities.dp(42);
layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
editedImage.setLayoutParams(layoutParams);
}
@Override

View File

@ -0,0 +1,381 @@
/*
* 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.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.ImageLoader;
import org.telegram.android.ImageReceiver;
import org.telegram.android.LocaleController;
import org.telegram.android.MediaController;
import org.telegram.android.MessageObject;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.Components.CheckBox;
import org.telegram.ui.Components.LineProgressView;
import java.io.File;
import java.util.Date;
public class SharedDocumentCell extends FrameLayout implements MediaController.FileDownloadProgressListener {
private ImageView placeholderImabeView;
private BackupImageView thumbImageView;
private TextView nameTextView;
private TextView extTextView;
private TextView dateTextView;
private ImageView statusImageView;
private LineProgressView progressView;
private CheckBox checkBox;
private boolean needDivider;
private static Paint paint;
private int TAG;
private MessageObject message;
private boolean loading;
private boolean loaded;
private int icons[] = {
R.drawable.media_doc_blue,
R.drawable.media_doc_green,
R.drawable.media_doc_red,
R.drawable.media_doc_yellow
};
public SharedDocumentCell(Context context) {
super(context);
if (paint == null) {
paint = new Paint();
paint.setColor(0xffd9d9d9);
paint.setStrokeWidth(1);
}
TAG = MediaController.getInstance().generateObserverTag();
placeholderImabeView = new ImageView(context);
addView(placeholderImabeView);
LayoutParams layoutParams = (LayoutParams) placeholderImabeView.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(40);
layoutParams.height = AndroidUtilities.dp(40);
layoutParams.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(12);
layoutParams.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(12) : 0;
layoutParams.topMargin = AndroidUtilities.dp(8);
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
placeholderImabeView.setLayoutParams(layoutParams);
extTextView = new TextView(context);
extTextView.setTextColor(0xffffffff);
extTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
extTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
extTextView.setLines(1);
extTextView.setMaxLines(1);
extTextView.setSingleLine(true);
extTextView.setGravity(Gravity.CENTER);
extTextView.setEllipsize(TextUtils.TruncateAt.END);
addView(extTextView);
layoutParams = (LayoutParams) extTextView.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(32);
layoutParams.height = LayoutParams.WRAP_CONTENT;
layoutParams.topMargin = AndroidUtilities.dp(22);
layoutParams.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(16);
layoutParams.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(16) : 0;
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
extTextView.setLayoutParams(layoutParams);
thumbImageView = new BackupImageView(context);
thumbImageView.imageReceiver.setDelegate(new ImageReceiver.ImageReceiverDelegate() {
@Override
public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb) {
extTextView.setVisibility(set ? GONE : VISIBLE);
placeholderImabeView.setVisibility(set ? GONE : VISIBLE);
}
});
addView(thumbImageView);
layoutParams = (LayoutParams) thumbImageView.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(40);
layoutParams.height = AndroidUtilities.dp(40);
layoutParams.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(12);
layoutParams.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(12) : 0;
layoutParams.topMargin = AndroidUtilities.dp(8);
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
thumbImageView.setLayoutParams(layoutParams);
nameTextView = new TextView(context);
nameTextView.setTextColor(0xff222222);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
nameTextView.setLines(1);
nameTextView.setMaxLines(1);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
addView(nameTextView);
layoutParams = (LayoutParams) nameTextView.getLayoutParams();
layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = LayoutParams.WRAP_CONTENT;
layoutParams.topMargin = AndroidUtilities.dp(5);
layoutParams.leftMargin = LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(72);
layoutParams.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(72) : AndroidUtilities.dp(8);
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
nameTextView.setLayoutParams(layoutParams);
statusImageView = new ImageView(context);
statusImageView.setVisibility(GONE);
addView(statusImageView);
layoutParams = (LayoutParams) statusImageView.getLayoutParams();
layoutParams.width = LayoutParams.WRAP_CONTENT;
layoutParams.height = LayoutParams.WRAP_CONTENT;
layoutParams.topMargin = AndroidUtilities.dp(35);
layoutParams.leftMargin = LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(72);
layoutParams.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(72) : AndroidUtilities.dp(8);
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
statusImageView.setLayoutParams(layoutParams);
dateTextView = new TextView(context);
dateTextView.setTextColor(0xff999999);
dateTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
dateTextView.setLines(1);
dateTextView.setMaxLines(1);
dateTextView.setSingleLine(true);
dateTextView.setEllipsize(TextUtils.TruncateAt.END);
dateTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
addView(dateTextView);
layoutParams = (LayoutParams) dateTextView.getLayoutParams();
layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = LayoutParams.WRAP_CONTENT;
layoutParams.topMargin = AndroidUtilities.dp(30);
layoutParams.leftMargin = LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(72);
layoutParams.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(72) : AndroidUtilities.dp(8);
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
dateTextView.setLayoutParams(layoutParams);
progressView = new LineProgressView(context);
addView(progressView);
layoutParams = (LayoutParams) progressView.getLayoutParams();
layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = AndroidUtilities.dp(2);
layoutParams.topMargin = AndroidUtilities.dp(54);
layoutParams.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(72);
layoutParams.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(72) : 0;
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
progressView.setLayoutParams(layoutParams);
checkBox = new CheckBox(context, R.drawable.round_check2);
checkBox.setVisibility(GONE);
addView(checkBox);
layoutParams = (LayoutParams) checkBox.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(22);
layoutParams.height = AndroidUtilities.dp(22);
layoutParams.topMargin = AndroidUtilities.dp(30);
layoutParams.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(34);
layoutParams.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(34) : 0;
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
checkBox.setLayoutParams(layoutParams);
}
private int getThumbForNameOrMime(String name, String mime) {
if (name != null && name.length() != 0) {
int color = -1;
if (name.contains(".doc") || name.contains(".txt") || name.contains(".psd")) {
color = 0;
} else if (name.contains(".xls") || name.contains(".csv")) {
color = 1;
} else if (name.contains(".pdf") || name.contains(".ppt") || name.contains(".key")) {
color = 2;
} else if (name.contains(".zip") || name.contains(".rar") || name.contains(".ai") || name.contains(".mp3") || name.contains(".mov") || name.contains(".avi")) {
color = 3;
}
if (color == -1) {
int idx;
String ext = (idx = name.lastIndexOf(".")) == -1 ? "" : name.substring(idx + 1);
if (ext.length() != 0) {
color = ext.charAt(0) % icons.length;
} else {
color = name.charAt(0) % icons.length;
}
}
return icons[color];
}
return icons[0];
}
public void setTextAndValueAndTypeAndThumb(String text, String value, String type, String thumb, int resId) {
nameTextView.setText(text);
dateTextView.setText(value);
if (type != null) {
extTextView.setVisibility(VISIBLE);
extTextView.setText(type);
} else {
extTextView.setVisibility(GONE);
}
if (resId == 0) {
placeholderImabeView.setImageResource(getThumbForNameOrMime(text, type));
placeholderImabeView.setVisibility(VISIBLE);
} else {
placeholderImabeView.setVisibility(GONE);
}
if (thumb != null || resId != 0) {
if (thumb != null) {
thumbImageView.setImage(thumb, "40_40", null);
} else {
thumbImageView.setImageResource(resId);
}
thumbImageView.setVisibility(VISIBLE);
} else {
thumbImageView.setVisibility(GONE);
}
}
public void setChecked(boolean checked, boolean animated) {
if (checkBox.getVisibility() != VISIBLE) {
checkBox.setVisibility(VISIBLE);
}
checkBox.setChecked(checked, animated);
}
public void setDocument(MessageObject document, boolean divider) {
needDivider = divider;
message = document;
loaded = false;
loading = false;
int idx = -1;
String name = FileLoader.getDocumentFileName(document.messageOwner.media.document);
placeholderImabeView.setVisibility(VISIBLE);
extTextView.setVisibility(VISIBLE);
placeholderImabeView.setImageResource(getThumbForNameOrMime(name, document.messageOwner.media.document.mime_type));
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.setImageBitmap(null);
} else {
thumbImageView.setVisibility(VISIBLE);
thumbImageView.setImage(document.messageOwner.media.document.thumb.location, "40_40", (Drawable) null);
}
long date = (long) document.messageOwner.date * 1000;
dateTextView.setText(String.format("%s, %s", Utilities.formatFileSize(document.messageOwner.media.document.size), LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.formatterYear.format(new Date(date)), LocaleController.formatterDay.format(new Date(date)))));
setWillNotDraw(!needDivider);
progressView.setProgress(0, false);
updateFileExistIcon();
}
public void updateFileExistIcon() {
if (message != null) {
String fileName = null;
File cacheFile = null;
if (message.messageOwner.attachPath == null || message.messageOwner.attachPath.length() == 0 || !(new File(message.messageOwner.attachPath).exists())) {
cacheFile = FileLoader.getPathToMessage(message.messageOwner);
if (!cacheFile.exists()) {
fileName = FileLoader.getAttachFileName(message.messageOwner.media.document);
}
}
loaded = false;
if (fileName == null) {
statusImageView.setVisibility(GONE);
dateTextView.setPadding(0, 0, 0, 0);
loading = false;
loaded = true;
MediaController.getInstance().removeLoadingFileObserver(this);
} else {
MediaController.getInstance().addLoadingFileObserver(fileName, this);
loading = FileLoader.getInstance().isLoadingFile(fileName);
statusImageView.setVisibility(VISIBLE);
statusImageView.setImageResource(loading ? R.drawable.media_doc_pause : R.drawable.media_doc_load);
dateTextView.setPadding(LocaleController.isRTL ? 0 : AndroidUtilities.dp(14), 0, LocaleController.isRTL ? AndroidUtilities.dp(14) : 0, 0);
if (loading) {
progressView.setVisibility(VISIBLE);
Float progress = ImageLoader.getInstance().getFileProgress(fileName);
if (progress == null) {
progress = 0.0f;
}
progressView.setProgress(progress, false);
} else {
progressView.setVisibility(GONE);
}
}
} else {
loading = false;
loaded = true;
progressView.setVisibility(GONE);
progressView.setProgress(0, false);
statusImageView.setVisibility(GONE);
dateTextView.setPadding(0, 0, 0, 0);
MediaController.getInstance().removeLoadingFileObserver(this);
}
}
public MessageObject getDocument() {
return message;
}
public boolean isLoaded() {
return loaded;
}
public boolean isLoading() {
return loading;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(56) + (needDivider ? 1 : 0), MeasureSpec.EXACTLY));
}
@Override
protected void onDraw(Canvas canvas) {
if (needDivider) {
canvas.drawLine(AndroidUtilities.dp(72), getHeight() - 1, getWidth() - getPaddingRight(), getHeight() - 1, paint);
}
}
@Override
public void onFailedDownload(String name) {
updateFileExistIcon();
}
@Override
public void onSuccessDownload(String name) {
progressView.setProgress(1, true);
updateFileExistIcon();
}
@Override
public void onProgressDownload(String fileName, float progress) {
progressView.setProgress(progress, true);
}
@Override
public void onProgressUpload(String fileName, float progress, boolean isEncrypted) {
}
@Override
public int getObserverTag() {
return TAG;
}
}

View File

@ -1,142 +0,0 @@
/*
* This is the source code of Telegram for Android v. 1.7.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.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.messenger.R;
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.Components.CheckBox;
public class TextDetailDocumentsCell extends FrameLayout {
private TextView textView;
private TextView valueTextView;
private TextView typeTextView;
private BackupImageView imageView;
private CheckBox checkBox;
public TextDetailDocumentsCell(Context context) {
super(context);
textView = new TextView(context);
textView.setTextColor(0xff212121);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
textView.setLines(1);
textView.setMaxLines(1);
textView.setSingleLine(true);
textView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
addView(textView);
LayoutParams layoutParams = (LayoutParams) textView.getLayoutParams();
layoutParams.width = LayoutParams.WRAP_CONTENT;
layoutParams.height = LayoutParams.WRAP_CONTENT;
layoutParams.topMargin = AndroidUtilities.dp(10);
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 71);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 71 : 16);
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
textView.setLayoutParams(layoutParams);
valueTextView = new TextView(context);
valueTextView.setTextColor(0xff8a8a8a);
valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
valueTextView.setLines(1);
valueTextView.setMaxLines(1);
valueTextView.setSingleLine(true);
valueTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
addView(valueTextView);
layoutParams = (LayoutParams) valueTextView.getLayoutParams();
layoutParams.width = LayoutParams.WRAP_CONTENT;
layoutParams.height = LayoutParams.WRAP_CONTENT;
layoutParams.topMargin = AndroidUtilities.dp(35);
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 71);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 71 : 16);
layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT;
valueTextView.setLayoutParams(layoutParams);
typeTextView = new TextView(context);
typeTextView.setBackgroundColor(0xff757575);
typeTextView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
typeTextView.setGravity(Gravity.CENTER);
typeTextView.setSingleLine(true);
typeTextView.setTextColor(0xffd1d1d1);
typeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
typeTextView.setTypeface(Typeface.DEFAULT_BOLD);
addView(typeTextView);
layoutParams = (LayoutParams) typeTextView.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(40);
layoutParams.height = AndroidUtilities.dp(40);
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 16);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 0);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL;
typeTextView.setLayoutParams(layoutParams);
imageView = new BackupImageView(context);
addView(imageView);
layoutParams = (LayoutParams) imageView.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(40);
layoutParams.height = AndroidUtilities.dp(40);
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 16);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 0);
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL;
imageView.setLayoutParams(layoutParams);
checkBox = new CheckBox(context, R.drawable.round_check2);
checkBox.setVisibility(GONE);
addView(checkBox);
layoutParams = (LayoutParams) checkBox.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(22);
layoutParams.height = AndroidUtilities.dp(22);
layoutParams.topMargin = AndroidUtilities.dp(34);
layoutParams.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(38);
layoutParams.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(38) : 0;
layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
checkBox.setLayoutParams(layoutParams);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(64), MeasureSpec.EXACTLY));
}
public void setTextAndValueAndTypeAndThumb(String text, String value, String type, String thumb, int resId) {
textView.setText(text);
valueTextView.setText(value);
if (type != null) {
typeTextView.setVisibility(VISIBLE);
typeTextView.setText(type);
} else {
typeTextView.setVisibility(GONE);
}
if (thumb != null || resId != 0) {
if (thumb != null) {
imageView.setImage(thumb, "40_40", null);
} else {
imageView.setImageResource(resId);
}
imageView.setVisibility(VISIBLE);
} else {
imageView.setVisibility(GONE);
}
}
public void setChecked(boolean checked, boolean animated) {
if (checkBox.getVisibility() != VISIBLE) {
checkBox.setVisibility(VISIBLE);
}
checkBox.setChecked(checked, animated);
}
}

View File

@ -134,6 +134,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private RecyclerListView stickersListView;
private StickersAdapter stickersAdapter;
private View stickersPanel;
private TextView muteItem;
private boolean allowStickersPanel;
private AnimatorSetProxy runningAnimation;
@ -213,6 +214,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private final static int clear_history = 11;
private final static int delete_chat = 12;
private final static int share_contact = 13;
private final static int mute = 14;
AdapterView.OnItemLongClickListener onItemLongClickListener = new AdapterView.OnItemLongClickListener() {
@Override
@ -446,6 +448,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidStarted);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateMessageMedia);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.replaceMessagesObjects);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.notificationsSettingsUpdated);
super.onFragmentCreate();
@ -505,6 +508,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidStarted);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateMessageMedia);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.replaceMessagesObjects);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.notificationsSettingsUpdated);
if (AndroidUtilities.isTablet()) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.openedChatChanged, dialog_id, true);
}
@ -770,6 +774,58 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
} else if (id == mute) {
boolean muted = MessagesController.getInstance().isDialogMuted(dialog_id);
if (!muted) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("Notifications", R.string.Notifications));
CharSequence[] items = new CharSequence[]{
LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 1)),
LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 8)),
LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Days", 2))
};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
int untilTime = ConnectionsManager.getInstance().getCurrentTime();
if (i == 0) {
untilTime += 60 * 60;
} else if (i == 1) {
untilTime += 60 * 60 * 8;
} else if (i == 2) {
untilTime += 60 * 60 * 48;
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("notify2_" + dialog_id, 3);
editor.putInt("notifyuntil_" + dialog_id, untilTime);
long flags = ((long)untilTime << 32) | 1;
MessagesStorage.getInstance().setDialogFlags(dialog_id, flags);
editor.commit();
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
if (dialog != null) {
dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
dialog.notify_settings.mute_until = untilTime;
}
NotificationsController.updateServerNotificationsSettings(dialog_id);
}
}
);
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("notify2_" + dialog_id, 0);
MessagesStorage.getInstance().setDialogFlags(dialog_id, 0);
editor.commit();
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
if (dialog != null) {
dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
}
NotificationsController.updateServerNotificationsSettings(dialog_id);
}
}
}
});
@ -861,6 +917,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
nameTextView.setGravity(Gravity.LEFT);
nameTextView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
avatarContainer.addView(nameTextView);
layoutParams2 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams();
@ -888,14 +945,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
layoutParams2.gravity = Gravity.BOTTOM;
onlineTextView.setLayoutParams(layoutParams2);
updateTitle();
updateSubtitle();
if (currentEncryptedChat != null) {
nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_header, 0, 0, 0);
nameTextView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
}
ActionBarMenu menu = actionBar.createMenu();
headerItem = menu.addItem(0, R.drawable.ic_ab_other);
@ -911,11 +960,16 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else {
headerItem.addSubItem(delete_chat, LocaleController.getString("DeleteChatUser", R.string.DeleteChatUser), 0);
}
muteItem = headerItem.addSubItem(mute, null, 0);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) headerItem.getLayoutParams();
layoutParams.rightMargin = AndroidUtilities.dp(-48);
headerItem.setLayoutParams(layoutParams);
updateTitle();
updateSubtitle();
updateTitleIcons();
attachItem = menu.addItem(chat_menu_attach, R.drawable.ic_ab_other);
attachItem.addSubItem(attach_photo, LocaleController.getString("ChatTakePhoto", R.string.ChatTakePhoto), R.drawable.ic_attach_photo);
attachItem.addSubItem(attach_gallery, LocaleController.getString("ChatGallery", R.string.ChatGallery), R.drawable.ic_attach_gallery);
@ -1730,13 +1784,35 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (currentUser.id / 1000 != 777 && currentUser.id / 1000 != 333 && ContactsController.getInstance().contactsDict.get(currentUser.id) == null && (ContactsController.getInstance().contactsDict.size() != 0 || !ContactsController.getInstance().isLoadingContacts())) {
if (currentUser.phone != null && currentUser.phone.length() != 0) {
nameTextView.setText(PhoneFormat.getInstance().format("+" + currentUser.phone));
} else {
if (currentUser instanceof TLRPC.TL_userDeleted) {
nameTextView.setText(LocaleController.getString("HiddenName", R.string.HiddenName));
} else {
nameTextView.setText(ContactsController.formatName(currentUser.first_name, currentUser.last_name));
}
}
} else {
nameTextView.setText(ContactsController.formatName(currentUser.first_name, currentUser.last_name));
}
}
TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
if (dialog != null && dialog.notify_settings != null) {
} else {
nameTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.mute_blue, 0);
}
}
private void updateTitleIcons() {
int leftIcon = currentEncryptedChat != null ? R.drawable.ic_lock_header : 0;
int rightIcon = MessagesController.getInstance().isDialogMuted(dialog_id) ? R.drawable.mute_fixed : 0;
nameTextView.setCompoundDrawablesWithIntrinsicBounds(leftIcon, 0, rightIcon, 0);
if (rightIcon != 0) {
muteItem.setText(LocaleController.getString("UnmuteNotifications", R.string.UnmuteNotifications));
} else {
muteItem.setText(LocaleController.getString("MuteNotifications", R.string.MuteNotifications));
}
}
private void updateSubtitle() {
@ -2076,7 +2152,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
TLRPC.Message dateMsg = new TLRPC.Message();
dateMsg.message = LocaleController.formatDateChat(obj.messageOwner.date);
dateMsg.id = 0;
MessageObject dateObj = new MessageObject(dateMsg, null);
MessageObject dateObj = new MessageObject(dateMsg, null, false);
dateObj.type = 10;
dateObj.contentType = 4;
if (load_type == 1) {
@ -2099,7 +2175,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
TLRPC.Message dateMsg = new TLRPC.Message();
dateMsg.message = "";
dateMsg.id = 0;
MessageObject dateObj = new MessageObject(dateMsg, null);
MessageObject dateObj = new MessageObject(dateMsg, null, false);
dateObj.contentType = dateObj.type = 6;
boolean dateAdded = true;
if (a != messArr.size() - 1) {
@ -2395,7 +2471,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
TLRPC.Message dateMsg = new TLRPC.Message();
dateMsg.message = LocaleController.formatDateChat(obj.messageOwner.date);
dateMsg.id = 0;
MessageObject dateObj = new MessageObject(dateMsg, null);
MessageObject dateObj = new MessageObject(dateMsg, null, false);
dateObj.type = 10;
dateObj.contentType = 4;
messages.add(0, dateObj);
@ -2534,7 +2610,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
TLRPC.Message newMsgObj = (TLRPC.Message)args[2];
if (newMsgObj != null) {
obj.messageOwner.media = newMsgObj.media;
obj.generateThumbs(true, 1);
obj.generateThumbs(true);
}
messagesDict.remove(msgId);
messagesDict.put(newMsgId, obj);
@ -2691,7 +2767,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (existMessageObject != null) {
existMessageObject.messageOwner.media = messageObject.messageOwner.media;
existMessageObject.messageOwner.attachPath = messageObject.messageOwner.attachPath;
existMessageObject.generateThumbs(false, 1);
existMessageObject.generateThumbs(false);
}
updateVisibleRows();
} else if (id == NotificationCenter.replaceMessagesObjects) {
@ -2713,6 +2789,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
chatAdapter.notifyDataSetChanged();
}
}
} else if (id == NotificationCenter.notificationsSettingsUpdated) {
updateTitleIcons();
}
}
@ -2746,8 +2824,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left) ||
currentUser != null && (currentUser instanceof TLRPC.TL_userDeleted || currentUser instanceof TLRPC.TL_userEmpty || userBlocked)) {
bottomOverlayChat.setVisibility(View.VISIBLE);
muteItem.setVisibility(View.GONE);
chatActivityEnterView.setFieldFocused(false);
} else {
muteItem.setVisibility(View.VISIBLE);
bottomOverlayChat.setVisibility(View.GONE);
}
}
@ -2925,6 +3005,13 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else {
selectedMessagesCountTextView.setTextSize(20);
}
if (AndroidUtilities.isTablet()) {
if (AndroidUtilities.isSmallTablet() && getParentActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
} else {
actionBar.setBackButtonImage(R.drawable.ic_close_white);
}
}
int padding = (AndroidUtilities.getCurrentActionBarHeight() - AndroidUtilities.dp(48)) / 2;
avatarContainer.setPadding(avatarContainer.getPaddingLeft(), padding, avatarContainer.getPaddingRight(), padding);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)avatarContainer.getLayoutParams();
@ -3007,10 +3094,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else if (type == 3) {
items = new CharSequence[]{LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Delete", R.string.Delete)};
} else if (type == 4) {
items = new CharSequence[]{LocaleController.getString(selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument ? "SaveToDownloads" : "SaveToGallery",
selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument ? R.string.SaveToDownloads : R.string.SaveToGallery), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
items = new CharSequence[]{LocaleController.getString(selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument ? "ShareFile" : "SaveToGallery",
selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument ? R.string.ShareFile : R.string.SaveToGallery), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
} else if (type == 5) {
items = new CharSequence[]{LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile), LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
items = new CharSequence[]{LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile), LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("Delete", R.string.Delete)};
}
} else {
if (type == 2) {
@ -3018,8 +3105,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else if (type == 3) {
items = new CharSequence[]{LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Delete", R.string.Delete)};
} else if (type == 4) {
items = new CharSequence[]{LocaleController.getString(selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument ? "SaveToDownloads" : "SaveToGallery",
selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument ? R.string.SaveToDownloads : R.string.SaveToGallery), LocaleController.getString("Delete", R.string.Delete)};
items = new CharSequence[]{LocaleController.getString(selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument ? "ShareFile" : "SaveToGallery",
selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument ? R.string.ShareFile : R.string.SaveToGallery), LocaleController.getString("Delete", R.string.Delete)};
} else if (type == 5) {
items = new CharSequence[]{LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile), LocaleController.getString("Delete", R.string.Delete)};
}
@ -3206,7 +3293,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else if (selectedObject.type == 1) {
MediaController.saveFile(path, getParentActivity(), 0, null);
} else if (selectedObject.type == 8 || selectedObject.type == 9) {
MediaController.saveFile(path, getParentActivity(), 2, selectedObject.getDocumentName());
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(selectedObject.messageOwner.media.document.mime_type);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
getParentActivity().startActivity(Intent.createChooser(intent, ""));
}
} else if (option == 5) {
File locFile = null;

View File

@ -32,11 +32,11 @@ public class AvatarDrawable extends Drawable {
private static TextPaint namePaint;
private static int[] arrColors = {0xffe56555, 0xfff28c48, 0xffeec764, 0xff76c84d, 0xff5fbed5, 0xff549cdd, 0xff8e85ee, 0xfff2749a};
private static int[] arrColorsProfiles = {0xffd86f65, 0xfff69d61, 0xfffabb3c, 0xff67b35d, 0xff56a2bb, 0xff5c98cd, 0xff8c79d2, 0xfff37fa6};
private static int[] arrColorsProfilesBack = {0xffca6056, 0xfff18944, 0xfff2b02c, 0xff56a14c, 0xff4492ac, 0xff4c84b6, 0xff7d6ac4, 0xffe66b94};
private static int[] arrColorsProfilesText = {0xfff9cbc5, 0xfffdddc8, 0xfffce5bb, 0xffc0edba, 0xffb8e2f0, 0xffb3d7f7, 0xffcdc4ed, 0xfffed1e0};
private static int[] arrColorsNames = {0xffca5650, 0xffd87b29, 0xffc7a21c, 0xff50b232, 0xff42b1a8, 0xff4e92cc, 0xff4e92cc, 0xffdb5b9d};
private static int[] arrColorsButtons = {R.drawable.bar_selector_red, R.drawable.bar_selector_orange, R.drawable.bar_selector_yellow,
R.drawable.bar_selector_green, R.drawable.bar_selector_cyan, R.drawable.bar_selector_blue, R.drawable.bar_selector_violet, R.drawable.bar_selector_pink};
private static int[] arrColorsProfilesBack = {0xffca6056, 0xfff18944, 0xff7d6ac4, 0xff56a14c, 0xff4492ac, 0xff4c84b6, 0xff7d6ac4, 0xff4c84b6};
private static int[] arrColorsProfilesText = {0xfff9cbc5, 0xfffdddc8, 0xffcdc4ed, 0xffc0edba, 0xffb8e2f0, 0xffb3d7f7, 0xffcdc4ed, 0xffb3d7f7};
private static int[] arrColorsNames = {0xffca5650, 0xffd87b29, 0xff4e92cc, 0xff50b232, 0xff42b1a8, 0xff4e92cc, 0xff4e92cc, 0xff4e92cc};
private static int[] arrColorsButtons = {R.drawable.bar_selector_red, R.drawable.bar_selector_orange, R.drawable.bar_selector_violet,
R.drawable.bar_selector_green, R.drawable.bar_selector_cyan, R.drawable.bar_selector_blue, R.drawable.bar_selector_violet, R.drawable.bar_selector_blue};

View File

@ -29,7 +29,7 @@ import org.telegram.ui.ActionBar.BaseFragment;
import java.io.File;
public class AvatarUpdater implements NotificationCenter.NotificationCenterDelegate, PhotoCropActivity.PhotoCropActivityDelegate {
public class AvatarUpdater implements NotificationCenter.NotificationCenterDelegate, PhotoCropActivity.PhotoEditActivityDelegate {
public String currentPicturePath;
private TLRPC.PhotoSize smallPhoto;
private TLRPC.PhotoSize bigPhoto;
@ -94,7 +94,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
activity.presentFragment(photoCropActivity);
} catch (Exception e) {
FileLog.e("tmessages", e);
Bitmap bitmap = ImageLoader.loadBitmap(path, uri, 800, 800);
Bitmap bitmap = ImageLoader.loadBitmap(path, uri, 800, 800, true);
processBitmap(bitmap);
}
}
@ -137,7 +137,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
}
@Override
public void didFinishCrop(Bitmap bitmap) {
public void didFinishEdit(Bitmap bitmap, Bundle args) {
processBitmap(bitmap);
}

View File

@ -18,6 +18,7 @@ import android.view.View;
import org.telegram.android.ImageReceiver;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
public class BackupImageView extends View {
@ -43,34 +44,35 @@ public class BackupImageView extends View {
imageReceiver = new ImageReceiver(this);
}
public void setImage(TLObject path, String filter, Drawable placeholder) {
setImage(path, null, filter, placeholder, null, 0);
public void setImage(TLObject path, String filter, Drawable thumb) {
setImage(path, null, filter, thumb, null, null, null, 0);
}
public void setImage(TLObject path, String filter, Bitmap placeholderBitmap) {
setImage(path, null, filter, null, placeholderBitmap, 0);
public void setImage(TLObject path, String filter, Bitmap thumb) {
setImage(path, null, filter, null, thumb, null, null, 0);
}
public void setImage(TLObject path, String filter, Drawable placeholder, int size) {
setImage(path, null, filter, placeholder, null, size);
public void setImage(TLObject path, String filter, Drawable thumb, int size) {
setImage(path, null, filter, thumb, null, null, null, size);
}
public void setImage(TLObject path, String filter, Bitmap placeholderBitmap, int size) {
setImage(path, null, filter, null, placeholderBitmap, size);
public void setImage(TLObject path, String filter, Bitmap thumb, int size) {
setImage(path, null, filter, null, thumb, null, null, size);
}
public void setImage(String path, String filter, Drawable placeholder) {
setImage(null, path, filter, placeholder, null, 0);
public void setImage(TLObject path, String filter, TLRPC.FileLocation thumb, int size) {
setImage(path, null, filter, null, null, thumb, null, size);
}
public void setImage(TLObject path, String httpUrl, String filter, Drawable placeholder, Bitmap placeholderBitmap, int size) {
Drawable placeholderDrawable = null;
if (placeholderBitmap != null) {
placeholderDrawable = new BitmapDrawable(null, placeholderBitmap);
} else if (placeholder != null) {
placeholderDrawable = placeholder;
public void setImage(String path, String filter, Drawable thumb) {
setImage(null, path, filter, thumb, null, null, null, 0);
}
imageReceiver.setImage(path, httpUrl, filter, placeholderDrawable, null, size, false);
public void setImage(TLObject path, String httpUrl, String filter, Drawable thumb, Bitmap thumbBitmap, TLRPC.FileLocation thumbLocation, String thumbFilter, int size) {
if (thumbBitmap != null) {
thumb = new BitmapDrawable(null, thumbBitmap);
}
imageReceiver.setImage(path, httpUrl, filter, thumb, thumbLocation, thumbFilter, size, false);
}
public void setImageBitmap(Bitmap bitmap) {

View File

@ -0,0 +1,98 @@
/*
* 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.Components;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import org.telegram.android.AndroidUtilities;
public class LineProgressView extends View {
private long lastUpdateTime = 0;
private float currentProgress = 0;
private float animationProgressStart = 0;
private long currentProgressTime = 0;
private float animatedProgressValue = 0;
private float animatedAlphaValue = 1.0f;
private static DecelerateInterpolator decelerateInterpolator = null;
private static Paint progressPaint = null;
public LineProgressView(Context context) {
super(context);
if (decelerateInterpolator == null) {
decelerateInterpolator = new DecelerateInterpolator();
progressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
progressPaint.setStyle(Paint.Style.STROKE);
progressPaint.setStrokeCap(Paint.Cap.ROUND);
progressPaint.setStrokeWidth(AndroidUtilities.dp(2));
progressPaint.setColor(0xff36a2ee);
}
}
private void updateAnimation() {
long newTime = System.currentTimeMillis();
long dt = newTime - lastUpdateTime;
lastUpdateTime = newTime;
if (animatedProgressValue != 1 && animatedProgressValue != currentProgress) {
float progressDiff = currentProgress - animationProgressStart;
if (progressDiff > 0) {
currentProgressTime += dt;
if (currentProgressTime >= 300) {
animatedProgressValue = currentProgress;
animationProgressStart = currentProgress;
currentProgressTime = 0;
} else {
animatedProgressValue = animationProgressStart + progressDiff * decelerateInterpolator.getInterpolation(currentProgressTime / 300.0f);
}
}
invalidate();
}
if (animatedProgressValue >= 1 && animatedProgressValue == 1 && animatedAlphaValue != 0) {
animatedAlphaValue -= dt / 200.0f;
if (animatedAlphaValue <= 0) {
animatedAlphaValue = 0.0f;
}
invalidate();
}
}
public void setProgressColor(int color) {
progressPaint.setColor(color);
}
public void setProgress(float value, boolean animated) {
if (!animated) {
animatedProgressValue = value;
animationProgressStart = value;
} else {
animationProgressStart = animatedProgressValue;
}
if (value != 1) {
animatedAlphaValue = 1;
}
currentProgress = value;
currentProgressTime = 0;
lastUpdateTime = System.currentTimeMillis();
invalidate();
}
public void onDraw(Canvas canvas) {
progressPaint.setAlpha((int)(255 * animatedAlphaValue));
canvas.drawRect(0, 0, getWidth() * animatedProgressValue, getHeight(), progressPaint);
updateAnimation();
}
}

View File

@ -289,7 +289,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, ContactsController.getInstance().getInviteText());
getParentActivity().startActivity(intent);
getParentActivity().startActivity(Intent.createChooser(intent, ""));
} catch (Exception e) {
FileLog.e("tmessages", e);
}

View File

@ -36,11 +36,10 @@ import org.telegram.messenger.Utilities;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.ActionBarMenuItem;
import org.telegram.ui.AnimationCompat.AnimatorSetProxy;
import org.telegram.ui.AnimationCompat.ObjectAnimatorProxy;
import org.telegram.ui.Cells.TextDetailDocumentsCell;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Cells.SharedDocumentCell;
import java.io.BufferedReader;
import java.io.File;
@ -63,13 +62,13 @@ public class DocumentSelectActivity extends BaseFragment {
private TextView emptyView;
private File currentDir;
private ArrayList<ListItem> items = new ArrayList<ListItem>();
private ArrayList<ListItem> items = new ArrayList<>();
private boolean receiverRegistered = false;
private ArrayList<HistoryEntry> history = new ArrayList<HistoryEntry>();
private ArrayList<HistoryEntry> history = new ArrayList<>();
private long sizeLimit = 1024 * 1024 * 1024;
private DocumentSelectActivityDelegate delegate;
private HashMap<String, ListItem> selectedFiles = new HashMap<String, ListItem>();
private ArrayList<View> actionModeViews = new ArrayList<View>();
private HashMap<String, ListItem> selectedFiles = new HashMap<>();
private ArrayList<View> actionModeViews = new ArrayList<>();
private boolean scrolling;
private final static int done = 3;
@ -152,27 +151,19 @@ public class DocumentSelectActivity extends BaseFragment {
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == 1) {
if (delegate != null) {
delegate.startDocumentSelectActivity();
}
finishFragment(false);
} else if (id == -2) {
selectedFiles.clear();
actionBar.hideActionMode();
listView.invalidateViews();
} else if (id == done) {
if (delegate != null) {
ArrayList<String> files = new ArrayList<String>();
ArrayList<String> files = new ArrayList<>();
files.addAll(selectedFiles.keySet());
delegate.didSelectFiles(DocumentSelectActivity.this, files);
}
}
}
});
ActionBarMenu menu = actionBar.createMenu();
final ActionBarMenuItem item = menu.addItem(1, R.drawable.ic_ab_other);
selectedFiles.clear();
actionModeViews.clear();
@ -254,7 +245,7 @@ public class DocumentSelectActivity extends BaseFragment {
selectedMessagesCountTextView.setText(String.format("%d", selectedFiles.size()));
if (Build.VERSION.SDK_INT >= 11) {
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
ArrayList<Object> animators = new ArrayList<Object>();
ArrayList<Object> animators = new ArrayList<>();
for (int a = 0; a < actionModeViews.size(); a++) {
View view2 = actionModeViews.get(a);
AndroidUtilities.clearDrawableAnimation(view2);
@ -269,8 +260,8 @@ public class DocumentSelectActivity extends BaseFragment {
animatorSet.start();
}
scrolling = false;
if (view instanceof TextDetailDocumentsCell) {
((TextDetailDocumentsCell) view).setChecked(true, true);
if (view instanceof SharedDocumentCell) {
((SharedDocumentCell) view).setChecked(true, true);
}
actionBar.showActionMode();
}
@ -287,6 +278,12 @@ public class DocumentSelectActivity extends BaseFragment {
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) {
@ -295,16 +292,18 @@ public class DocumentSelectActivity extends BaseFragment {
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;
}
history.add(he);
actionBar.setTitle(item.title);
listView.setSelection(0);
} else {
@ -333,12 +332,12 @@ public class DocumentSelectActivity extends BaseFragment {
selectedMessagesCountTextView.setText(String.format("%d", selectedFiles.size()));
}
scrolling = false;
if (view instanceof TextDetailDocumentsCell) {
((TextDetailDocumentsCell) view).setChecked(selectedFiles.containsKey(item.file.toString()), true);
if (view instanceof SharedDocumentCell) {
((SharedDocumentCell) view).setChecked(selectedFiles.containsKey(item.file.toString()), true);
}
} else {
if (delegate != null) {
ArrayList<String> files = new ArrayList<String>();
ArrayList<String> files = new ArrayList<>();
files.add(file.getAbsolutePath());
delegate.didSelectFiles(DocumentSelectActivity.this, files);
}
@ -465,7 +464,16 @@ public class DocumentSelectActivity extends BaseFragment {
}
ListItem item = new ListItem();
item.title = "..";
if (history.size() > 0) {
HistoryEntry entry = history.get(history.size() - 1);
if (entry.dir == null) {
item.subtitle = LocaleController.getString("Folder", R.string.Folder);
} else {
item.subtitle = entry.dir.toString();
}
} else {
item.subtitle = LocaleController.getString("Folder", R.string.Folder);
}
item.icon = R.drawable.ic_directory;
item.file = null;
items.add(0, item);
@ -499,8 +507,8 @@ public class DocumentSelectActivity extends BaseFragment {
try {
BufferedReader reader = new BufferedReader(new FileReader("/proc/mounts"));
String line;
HashMap<String, ArrayList<String>> aliases = new HashMap<String, ArrayList<String>>();
ArrayList<String> result = new ArrayList<String>();
HashMap<String, ArrayList<String>> aliases = new HashMap<>();
ArrayList<String> result = new ArrayList<>();
String extDevice = null;
while ((line = reader.readLine()) != null) {
if ((!line.contains("/mnt") && !line.contains("/storage") && !line.contains("/sdcard")) || line.contains("asec") || line.contains("tmpfs") || line.contains("none")) {
@ -560,6 +568,13 @@ public class DocumentSelectActivity extends BaseFragment {
FileLog.e("tmessages", e);
}
fs = new ListItem();
fs.title = LocaleController.getString("Gallery", R.string.Gallery);
fs.subtitle = LocaleController.getString("GalleryInfo", R.string.GalleryInfo);
fs.icon = R.drawable.ic_storage_gallery;
fs.file = null;
items.add(fs);
AndroidUtilities.clearDrawableAnimation(listView);
scrolling = true;
listAdapter.notifyDataSetChanged();
@ -608,15 +623,15 @@ public class DocumentSelectActivity extends BaseFragment {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = new TextDetailDocumentsCell(mContext);
convertView = new SharedDocumentCell(mContext);
}
TextDetailDocumentsCell textDetailCell = (TextDetailDocumentsCell) convertView;
SharedDocumentCell textDetailCell = (SharedDocumentCell) convertView;
ListItem item = items.get(position);
if (item.icon != 0) {
((TextDetailDocumentsCell) convertView).setTextAndValueAndTypeAndThumb(item.title, item.subtitle, null, null, item.icon);
((SharedDocumentCell) convertView).setTextAndValueAndTypeAndThumb(item.title, item.subtitle, null, null, item.icon);
} else {
String type = item.ext.toUpperCase().substring(0, Math.min(item.ext.length(), 4));
((TextDetailDocumentsCell) convertView).setTextAndValueAndTypeAndThumb(item.title, item.subtitle, type, item.thumb, 0);
((SharedDocumentCell) convertView).setTextAndValueAndTypeAndThumb(item.title, item.subtitle, type, item.thumb, 0);
}
if (item.file != null && actionBar.isActionModeShowed()) {
textDetailCell.setChecked(selectedFiles.containsKey(item.file.toString()), !scrolling);

View File

@ -8,10 +8,13 @@
package org.telegram.ui;
import android.animation.ObjectAnimator;
import android.animation.StateListAnimator;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.database.DataSetObserver;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
@ -114,7 +117,13 @@ public class IntroActivity extends Activity {
}
viewPager = (ViewPager)findViewById(R.id.intro_view_pager);
TextView startMessagingButton = (TextView) findViewById(R.id.start_messaging_button);
startMessagingButton.setText(LocaleController.getString("StartMessaging", R.string.StartMessaging));
startMessagingButton.setText(LocaleController.getString("StartMessaging", R.string.StartMessaging).toUpperCase());
if (Build.VERSION.SDK_INT >= 21) {
StateListAnimator animator = new StateListAnimator();
animator.addState(new int[] {android.R.attr.state_pressed}, ObjectAnimator.ofFloat(startMessagingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
animator.addState(new int[] {}, ObjectAnimator.ofFloat(startMessagingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
startMessagingButton.setStateListAnimator(animator);
}
topImage1 = (ImageView)findViewById(R.id.icon_image1);
topImage2 = (ImageView)findViewById(R.id.icon_image2);
bottomPages = (ViewGroup)findViewById(R.id.bottom_pages);

View File

@ -276,7 +276,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, ContactsController.getInstance().getInviteText());
startActivity(intent);
startActivity(Intent.createChooser(intent, ""));
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@ -735,6 +735,14 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
} else if (showDialogsList) {
if (!AndroidUtilities.isTablet()) {
actionBarLayout.removeAllFragments();
} else {
if (!layersActionBarLayout.fragmentsStack.isEmpty()) {
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) {
layersActionBarLayout.removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0));
a--;
}
layersActionBarLayout.closeLastFragment(false);
}
}
pushOpened = false;
isNew = false;

View File

@ -843,7 +843,7 @@ public class LoginActivity extends BaseFragment {
needShowAlert(LocaleController.getString("CodeExpired", R.string.CodeExpired));
} else if (error.text.startsWith("FLOOD_WAIT")) {
needShowAlert(LocaleController.getString("FloodWait", R.string.FloodWait));
} else {
} else if (error.code != -1000) {
needShowAlert(error.text);
}
}

View File

@ -8,9 +8,12 @@
package org.telegram.ui;
import android.animation.ObjectAnimator;
import android.animation.StateListAnimator;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.res.Configuration;
import android.graphics.Outline;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
@ -18,6 +21,7 @@ import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.ViewTreeObserver;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.AbsListView;
@ -102,6 +106,8 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.openedChatChanged);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.notificationsSettingsUpdated);
if (getArguments() != null) {
onlySelect = arguments.getBoolean("onlySelect", false);
serverOnly = arguments.getBoolean("serverOnly", false);
@ -126,6 +132,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.contactsDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.appDidLogout);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.openedChatChanged);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.notificationsSettingsUpdated);
delegate = null;
}
@ -275,6 +282,19 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
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);
@ -595,6 +615,10 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
}
updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG);
}
} else if (id == NotificationCenter.notificationsSettingsUpdated) {
if (messagesListView != null) {
updateVisibleRows(0);
}
}
}

View File

@ -281,7 +281,9 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
ArrayList<String> photos = new ArrayList<>();
for (HashMap.Entry<Integer, MediaController.PhotoEntry> entry : selectedPhotos.entrySet()) {
MediaController.PhotoEntry photoEntry = entry.getValue();
if (photoEntry.path != null) {
if (photoEntry.imagePath != null) {
photos.add(photoEntry.imagePath);
} else if (photoEntry.path != null) {
photos.add(photoEntry.path);
}
}

View File

@ -35,8 +35,8 @@ import java.io.File;
public class PhotoCropActivity extends BaseFragment {
public interface PhotoCropActivityDelegate {
public abstract void didFinishCrop(Bitmap bitmap);
public interface PhotoEditActivityDelegate {
public abstract void didFinishEdit(Bitmap bitmap, Bundle args);
}
private class PhotoCropView extends FrameLayout {
@ -44,12 +44,14 @@ public class PhotoCropActivity extends BaseFragment {
Paint rectPaint = null;
Paint circlePaint = null;
Paint halfPaint = null;
float rectSize = 600;
float rectSizeX = 600;
float rectSizeY = 600;
float rectX = -1, rectY = -1;
int draggingState = 0;
float oldX = 0, oldY = 0;
int bitmapWidth, bitmapHeight, bitmapX, bitmapY;
int viewWidth, viewHeight;
boolean freeform;
public PhotoCropView(Context context) {
super(context);
@ -68,14 +70,14 @@ public class PhotoCropActivity extends BaseFragment {
private void init() {
rectPaint = new Paint();
rectPaint.setColor(0xfffafafa);
rectPaint.setColor(0x3ffafafa);
rectPaint.setStrokeWidth(AndroidUtilities.dp(2));
rectPaint.setStyle(Paint.Style.STROKE);
circlePaint = new Paint();
circlePaint.setColor(0x7fffffff);
circlePaint.setColor(0xffffffff);
halfPaint = new Paint();
halfPaint.setColor(0x3f000000);
setBackgroundColor(0xff000000);
halfPaint.setColor(0xc8000000);
setBackgroundColor(0xff333333);
setOnTouchListener(new OnTouchListener() {
@Override
@ -86,13 +88,13 @@ public class PhotoCropActivity extends BaseFragment {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
if (rectX - cornerSide < x && rectX + cornerSide > x && rectY - cornerSide < y && rectY + cornerSide > y) {
draggingState = 1;
} else if (rectX - cornerSide + rectSize < x && rectX + cornerSide + rectSize > x && rectY - cornerSide < y && rectY + cornerSide > y) {
} else if (rectX - cornerSide + rectSizeX < x && rectX + cornerSide + rectSizeX > x && rectY - cornerSide < y && rectY + cornerSide > y) {
draggingState = 2;
} else if (rectX - cornerSide < x && rectX + cornerSide > x && rectY - cornerSide + rectSize < y && rectY + cornerSide + rectSize > y) {
} else if (rectX - cornerSide < x && rectX + cornerSide > x && rectY - cornerSide + rectSizeY < y && rectY + cornerSide + rectSizeY > y) {
draggingState = 3;
} else if (rectX - cornerSide + rectSize < x && rectX + cornerSide + rectSize > x && rectY - cornerSide + rectSize < y && rectY + cornerSide + rectSize > y) {
} else if (rectX - cornerSide + rectSizeX < x && rectX + cornerSide + rectSizeX > x && rectY - cornerSide + rectSizeY < y && rectY + cornerSide + rectSizeY > y) {
draggingState = 4;
} else if (rectX < x && rectX + rectSize > x && rectY < y && rectY + rectSize > y) {
} else if (rectX < x && rectX + rectSizeX > x && rectY < y && rectY + rectSizeY > y) {
draggingState = 5;
} else {
draggingState = 0;
@ -113,61 +115,115 @@ public class PhotoCropActivity extends BaseFragment {
if (rectX < bitmapX) {
rectX = bitmapX;
} else if (rectX + rectSize > bitmapX + bitmapWidth) {
rectX = bitmapX + bitmapWidth - rectSize;
} else if (rectX + rectSizeX > bitmapX + bitmapWidth) {
rectX = bitmapX + bitmapWidth - rectSizeX;
}
if (rectY < bitmapY) {
rectY = bitmapY;
} else if (rectY + rectSize > bitmapY + bitmapHeight) {
rectY = bitmapY + bitmapHeight - rectSize;
} else if (rectY + rectSizeY > bitmapY + bitmapHeight) {
rectY = bitmapY + bitmapHeight - rectSizeY;
}
} else if (draggingState == 1) {
if (rectSize - diffX < 160) {
diffX = rectSize - 160;
} else {
if (draggingState == 1) {
if (rectSizeX - diffX < 160) {
diffX = rectSizeX - 160;
}
if (rectX + diffX < bitmapX) {
diffX = bitmapX - rectX;
}
if (!freeform) {
if (rectY + diffX < bitmapY) {
diffX = bitmapY - rectY;
}
rectX += diffX;
rectY += diffX;
rectSize -= diffX;
rectSizeX -= diffX;
rectSizeY -= diffX;
} else {
if (rectSizeY - diffY < 160) {
diffY = rectSizeY - 160;
}
if (rectY + diffY < bitmapY) {
diffY = bitmapY - rectY;
}
rectX += diffX;
rectY += diffY;
rectSizeX -= diffX;
rectSizeY -= diffY;
}
} else if (draggingState == 2) {
if (rectSize + diffX < 160) {
diffX = -(rectSize - 160);
if (rectSizeX + diffX < 160) {
diffX = -(rectSizeX - 160);
}
if (rectX + rectSize + diffX > bitmapX + bitmapWidth) {
diffX = bitmapX + bitmapWidth - rectX - rectSize;
if (rectX + rectSizeX + diffX > bitmapX + bitmapWidth) {
diffX = bitmapX + bitmapWidth - rectX - rectSizeX;
}
if (!freeform) {
if (rectY - diffX < bitmapY) {
diffX = rectY - bitmapY;
}
rectY -= diffX;
rectSize += diffX;
rectSizeX += diffX;
rectSizeY += diffX;
} else {
if (rectSizeY - diffY < 160) {
diffY = rectSizeY - 160;
}
if (rectY + diffY < bitmapY) {
diffY = bitmapY - rectY;
}
rectY += diffY;
rectSizeX += diffX;
rectSizeY -= diffY;
}
} else if (draggingState == 3) {
if (rectSize - diffX < 160) {
diffX = rectSize - 160;
if (rectSizeX - diffX < 160) {
diffX = rectSizeX - 160;
}
if (rectX + diffX < bitmapX) {
diffX = bitmapX - rectX;
}
if (rectY + rectSize - diffX > bitmapY + bitmapHeight) {
diffX = rectY + rectSize - bitmapY - bitmapHeight;
if (!freeform) {
if (rectY + rectSizeX - diffX > bitmapY + bitmapHeight) {
diffX = rectY + rectSizeX - bitmapY - bitmapHeight;
}
rectX += diffX;
rectSize -= diffX;
rectSizeX -= diffX;
rectSizeY -= diffX;
} else {
if (rectY + rectSizeY + diffY > bitmapY + bitmapHeight) {
diffY = bitmapY + bitmapHeight - rectY - rectSizeY;
}
rectX += diffX;
rectSizeX -= diffX;
rectSizeY += diffY;
if (rectSizeY < 160) {
rectSizeY = 160;
}
}
} else if (draggingState == 4) {
if (rectX + rectSize + diffX > bitmapX + bitmapWidth) {
diffX = bitmapX + bitmapWidth - rectX - rectSize;
if (rectX + rectSizeX + diffX > bitmapX + bitmapWidth) {
diffX = bitmapX + bitmapWidth - rectX - rectSizeX;
}
if (rectY + rectSize + diffX > bitmapY + bitmapHeight) {
diffX = bitmapY + bitmapHeight - rectY - rectSize;
if (!freeform) {
if (rectY + rectSizeX + diffX > bitmapY + bitmapHeight) {
diffX = bitmapY + bitmapHeight - rectY - rectSizeX;
}
rectSizeX += diffX;
rectSizeY += diffX;
} else {
if (rectY + rectSizeY + diffY > bitmapY + bitmapHeight) {
diffY = bitmapY + bitmapHeight - rectY - rectSizeY;
}
rectSizeX += diffX;
rectSizeY += diffY;
}
if (rectSizeX < 160) {
rectSizeX = 160;
}
if (rectSizeY < 160) {
rectSizeY = 160;
}
rectSize += diffX;
if (rectSize < 160) {
rectSize = 160;
}
}
@ -186,7 +242,8 @@ public class PhotoCropActivity extends BaseFragment {
}
float percX = (rectX - bitmapX) / bitmapWidth;
float percY = (rectY - bitmapY) / bitmapHeight;
float percSize = rectSize / bitmapWidth;
float percSizeX = rectSizeX / bitmapWidth;
float percSizeY = rectSizeY / bitmapHeight;
float w = imageToCrop.getWidth();
float h = imageToCrop.getHeight();
float scaleX = viewWidth / w;
@ -198,23 +255,33 @@ public class PhotoCropActivity extends BaseFragment {
bitmapWidth = viewWidth;
bitmapHeight = (int)Math.ceil(h * scaleX);
}
bitmapX = (viewWidth - bitmapWidth) / 2;
bitmapY = (viewHeight - bitmapHeight) / 2;
bitmapX = (viewWidth - bitmapWidth) / 2 + AndroidUtilities.dp(14);
bitmapY = (viewHeight - bitmapHeight) / 2 + AndroidUtilities.dp(14);
if (rectX == -1 && rectY == -1) {
if (freeform) {
rectY = bitmapY;
rectX = bitmapX;
rectSizeX = bitmapWidth;
rectSizeY = bitmapHeight;
} else {
if (bitmapWidth > bitmapHeight) {
rectY = bitmapY;
rectX = (viewWidth - bitmapHeight) / 2;
rectSize = bitmapHeight;
rectX = (viewWidth - bitmapHeight) / 2 + AndroidUtilities.dp(14);
rectSizeX = bitmapHeight;
rectSizeY = bitmapHeight;
} else {
rectX = bitmapX;
rectY = (viewHeight - bitmapWidth) / 2;
rectSize = bitmapWidth;
rectY = (viewHeight - bitmapWidth) / 2 + AndroidUtilities.dp(14);
rectSizeX = bitmapWidth;
rectSizeY = bitmapWidth;
}
}
} else {
rectX = percX * bitmapWidth + bitmapX;
rectY = percY * bitmapHeight + bitmapY;
rectSize = percSize * bitmapWidth;
rectSizeX = percSizeX * bitmapWidth;
rectSizeY = percSizeY * bitmapHeight;
}
invalidate();
}
@ -222,31 +289,33 @@ public class PhotoCropActivity extends BaseFragment {
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
viewWidth = right - left;
viewHeight = bottom - top;
viewWidth = right - left - AndroidUtilities.dp(28);
viewHeight = bottom - top - AndroidUtilities.dp(28);
updateBitmapSize();
}
public Bitmap getBitmap() {
float percX = (rectX - bitmapX) / bitmapWidth;
float percY = (rectY - bitmapY) / bitmapHeight;
float percSize = rectSize / bitmapWidth;
float percSizeX = rectSizeX / bitmapWidth;
float percSizeY = rectSizeY / bitmapWidth;
int x = (int)(percX * imageToCrop.getWidth());
int y = (int)(percY * imageToCrop.getHeight());
int size = (int)(percSize * imageToCrop.getWidth());
if (x + size > imageToCrop.getWidth()) {
size = imageToCrop.getWidth() - x;
int sizeX = (int)(percSizeX * imageToCrop.getWidth());
int sizeY = (int)(percSizeY * imageToCrop.getWidth());
if (x + sizeX > imageToCrop.getWidth()) {
sizeX = imageToCrop.getWidth() - x;
}
if (y + size > imageToCrop.getHeight()) {
size = imageToCrop.getHeight() - y;
if (y + sizeY > imageToCrop.getHeight()) {
sizeY = imageToCrop.getHeight() - y;
}
try {
return Bitmap.createBitmap(imageToCrop, x, y, size, size);
return Bitmap.createBitmap(imageToCrop, x, y, sizeX, sizeY);
} catch (Throwable e) {
FileLog.e("tmessags", e);
System.gc();
try {
return Bitmap.createBitmap(imageToCrop, x, y, size, size);
return Bitmap.createBitmap(imageToCrop, x, y, sizeX, sizeY);
} catch (Throwable e2) {
FileLog.e("tmessages", e2);
}
@ -261,26 +330,39 @@ public class PhotoCropActivity extends BaseFragment {
drawable.draw(canvas);
}
canvas.drawRect(bitmapX, bitmapY, bitmapX + bitmapWidth, rectY, halfPaint);
canvas.drawRect(bitmapX, rectY, rectX, rectY + rectSize, halfPaint);
canvas.drawRect(rectX + rectSize, rectY, bitmapX + bitmapWidth, rectY + rectSize, halfPaint);
canvas.drawRect(bitmapX, rectY + rectSize, bitmapX + bitmapWidth, bitmapY + bitmapHeight, halfPaint);
canvas.drawRect(bitmapX, rectY, rectX, rectY + rectSizeY, halfPaint);
canvas.drawRect(rectX + rectSizeX, rectY, bitmapX + bitmapWidth, rectY + rectSizeY, halfPaint);
canvas.drawRect(bitmapX, rectY + rectSizeY, bitmapX + bitmapWidth, bitmapY + bitmapHeight, halfPaint);
canvas.drawRect(rectX, rectY, rectX + rectSize, rectY + rectSize, rectPaint);
canvas.drawRect(rectX, rectY, rectX + rectSizeX, rectY + rectSizeY, rectPaint);
int side = AndroidUtilities.dp(7);
canvas.drawRect(rectX - side, rectY - side, rectX + side, rectY + side, circlePaint);
canvas.drawRect(rectX + rectSize - side, rectY - side, rectX + rectSize + side, rectY + side, circlePaint);
canvas.drawRect(rectX - side, rectY + rectSize - side, rectX + side, rectY + rectSize + side, circlePaint);
canvas.drawRect(rectX + rectSize - side, rectY + rectSize - side, rectX + rectSize + side, rectY + rectSize + side, circlePaint);
int side = AndroidUtilities.dp(1);
canvas.drawRect(rectX + side, rectY + side, rectX + side + AndroidUtilities.dp(20), rectY + side * 3, circlePaint);
canvas.drawRect(rectX + side, rectY + side, rectX + side * 3, rectY + side + AndroidUtilities.dp(20), circlePaint);
canvas.drawRect(rectX + rectSizeX - side - AndroidUtilities.dp(20), rectY + side, rectX + rectSizeX - side, rectY + side * 3, circlePaint);
canvas.drawRect(rectX + rectSizeX - side * 3, rectY + side, rectX + rectSizeX - side, rectY + side + AndroidUtilities.dp(20), circlePaint);
canvas.drawRect(rectX + side, rectY + rectSizeY - side - AndroidUtilities.dp(20), rectX + side * 3, rectY + rectSizeY - side, circlePaint);
canvas.drawRect(rectX + side, rectY + rectSizeY - side * 3, rectX + side + AndroidUtilities.dp(20), rectY + rectSizeY - side, circlePaint);
canvas.drawRect(rectX + rectSizeX - side - AndroidUtilities.dp(20), rectY + rectSizeY - side * 3, rectX + rectSizeX - side, rectY + rectSizeY - side, circlePaint);
canvas.drawRect(rectX + rectSizeX - side * 3, rectY + rectSizeY - side - AndroidUtilities.dp(20), rectX + rectSizeX - side, rectY + rectSizeY - side, circlePaint);
for (int a = 1; a < 3; a++) {
canvas.drawRect(rectX + rectSizeX / 3 * a, rectY + side, rectX + side + rectSizeX / 3 * a, rectY + rectSizeY - side, circlePaint);
canvas.drawRect(rectX + side, rectY + rectSizeY / 3 * a, rectX - side + rectSizeX, rectY + rectSizeY / 3 * a + side, circlePaint);
}
}
}
private Bitmap imageToCrop;
private BitmapDrawable drawable;
private PhotoCropActivityDelegate delegate = null;
private PhotoEditActivityDelegate delegate = null;
private PhotoCropView view;
private boolean sameBitmap = false;
private boolean doneButtonPressed = false;
private String bitmapKey;
private final static int done_button = 1;
@ -288,9 +370,19 @@ public class PhotoCropActivity extends BaseFragment {
super(args);
}
public PhotoCropActivity(Bundle args, Bitmap bitmap, String key) {
super(args);
imageToCrop = bitmap;
bitmapKey = key;
if (imageToCrop != null && key != null) {
ImageLoader.getInstance().incrementUseCount(key);
}
}
@Override
public boolean onFragmentCreate() {
swipeBackEnabled = false;
if (imageToCrop == null) {
String photoPath = getArguments().getString("photoPath");
Uri photoUri = getArguments().getParcelable("photoUri");
if (photoPath == null && photoUri == null) {
@ -308,10 +400,11 @@ public class PhotoCropActivity extends BaseFragment {
} else {
size = Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
}
imageToCrop = ImageLoader.loadBitmap(photoPath, photoUri, size, size);
imageToCrop = ImageLoader.loadBitmap(photoPath, photoUri, size, size, true);
if (imageToCrop == null) {
return false;
}
}
drawable = new BitmapDrawable(imageToCrop);
super.onFragmentCreate();
return true;
@ -321,7 +414,12 @@ public class PhotoCropActivity extends BaseFragment {
public void onFragmentDestroy() {
super.onFragmentDestroy();
drawable = null;
if (imageToCrop != null && !sameBitmap) {
if (bitmapKey != null) {
if (ImageLoader.getInstance().decrementUseCount(bitmapKey) && !ImageLoader.getInstance().isInCache(bitmapKey)) {
bitmapKey = null;
}
}
if (bitmapKey == null && imageToCrop != null && !sameBitmap) {
imageToCrop.recycle();
imageToCrop = null;
}
@ -330,6 +428,8 @@ public class PhotoCropActivity extends BaseFragment {
@Override
public View createView(LayoutInflater inflater, ViewGroup container) {
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));
@ -344,7 +444,7 @@ public class PhotoCropActivity extends BaseFragment {
if (bitmap == imageToCrop) {
sameBitmap = true;
}
delegate.didFinishCrop(bitmap);
delegate.didFinishEdit(bitmap, getArguments());
doneButtonPressed = true;
}
finishFragment();
@ -356,6 +456,7 @@ public class PhotoCropActivity extends BaseFragment {
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();
@ -366,7 +467,7 @@ public class PhotoCropActivity extends BaseFragment {
return fragmentView;
}
public void setDelegate(PhotoCropActivityDelegate delegate) {
public void setDelegate(PhotoEditActivityDelegate delegate) {
this.delegate = delegate;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,7 @@ import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.util.Base64;
import android.view.Gravity;
import android.view.LayoutInflater;
@ -32,6 +33,7 @@ import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONObject;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.ImageLoader;
import org.telegram.android.LocaleController;
import org.telegram.android.MediaController;
import org.telegram.android.MessagesStorage;
@ -45,6 +47,7 @@ import org.telegram.android.volley.toolbox.JsonObjectRequest;
import org.telegram.android.volley.toolbox.Volley;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
@ -65,7 +68,7 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class PhotoPickerActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, PhotoViewer.PhotoViewerProvider {
public class PhotoPickerActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, PhotoViewer.PhotoViewerProvider, PhotoCropActivity.PhotoEditActivityDelegate {
public static interface PhotoPickerActivityDelegate {
public abstract void selectedPhotosChanged();
@ -85,7 +88,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
private boolean searching;
private String nextSearchBingString;
private boolean giffySearchEndReached = true;
private boolean giphySearchEndReached = true;
private String lastSearchString;
private boolean loadingRecent;
@ -184,7 +187,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
searchResultKeys.clear();
lastSearchString = null;
nextSearchBingString = null;
giffySearchEndReached = true;
giphySearchEndReached = true;
searching = false;
requestQueue.cancelAll("search");
if (type == 0) {
@ -204,11 +207,11 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
searchResult.clear();
searchResultKeys.clear();
nextSearchBingString = null;
giffySearchEndReached = true;
giphySearchEndReached = true;
if (type == 0) {
searchBingImages(editText.getText().toString(), 0, 53);
} else if (type == 1) {
searchGiffyImages(editText.getText().toString(), 0, 53);
searchGiphyImages(editText.getText().toString(), 0, 53);
}
lastSearchString = editText.getText().toString();
if (lastSearchString.length() == 0) {
@ -320,8 +323,8 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2 && !searching) {
if (type == 0 && nextSearchBingString != null) {
searchBingImages(lastSearchString, searchResult.size(), 54);
} else if (type == 1 && !giffySearchEndReached) {
searchGiffyImages(searchItem.getSearchField().getText().toString(), searchResult.size(), 54);
} else if (type == 1 && !giphySearchEndReached) {
searchGiphyImages(searchItem.getSearchField().getText().toString(), searchResult.size(), 54);
}
}
}
@ -615,6 +618,20 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
}
@Override
public void didFinishEdit(Bitmap bitmap, Bundle args) {
TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(bitmap, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 80, false, 101, 101);
if (size != null) {
int id = args.getInt("id");
MediaController.PhotoEntry entry = selectedAlbum.photosByIds.get(id);
entry.imagePath = FileLoader.getPathToAttach(size, true).toString();
selectedPhotos.put(entry.imageId, entry);
listAdapter.notifyDataSetChanged();
photoPickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
delegate.selectedPhotosChanged();
}
}
private void updateSearchInterface() {
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
@ -630,7 +647,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
}
private void searchGiffyImages(String query, int offset, final int count) {
private void searchGiphyImages(String query, int offset, final int count) {
if (searching) {
searching = false;
requestQueue.cancelAll("search");
@ -647,7 +664,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
try {
JSONObject pagination = response.getJSONObject("pagination");
int total_count = pagination.getInt("total_count");
giffySearchEndReached = searchResult.size() + result.length() >= total_count;
giphySearchEndReached = searchResult.size() + result.length() >= total_count;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@ -678,7 +695,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
}
if (!added) {
giffySearchEndReached = true;
giphySearchEndReached = true;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
@ -691,7 +708,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override
public void onErrorResponse(VolleyError error) {
FileLog.e("tmessages", "Error: " + error.getMessage());
giffySearchEndReached = true;
giphySearchEndReached = true;
searching = false;
updateSearchInterface();
}
@ -884,7 +901,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
} else if (type == 0) {
return searchResult.size() + (nextSearchBingString == null ? 0 : 1);
} else if (type == 1) {
return searchResult.size() + (giffySearchEndReached ? 0 : 1);
return searchResult.size() + (giphySearchEndReached ? 0 : 1);
}
}
return selectedAlbum.photos.size();
@ -920,9 +937,11 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get((Integer) ((View) v.getParent()).getTag());
if (selectedPhotos.containsKey(photoEntry.imageId)) {
selectedPhotos.remove(photoEntry.imageId);
photoEntry.imagePath = null;
} else {
selectedPhotos.put(photoEntry.imageId, photoEntry);
}
((PhotoPickerPhotoCell) v.getParent()).editedImage.setVisibility(photoEntry.imagePath != null ? View.VISIBLE : View.GONE);
((PhotoPickerPhotoCell) v.getParent()).checkBox.setChecked(selectedPhotos.containsKey(photoEntry.imageId), true);
} else {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
@ -937,6 +956,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
} else {
selectedWebPhotos.put(photoEntry.id, photoEntry);
}
((PhotoPickerPhotoCell) v.getParent()).editedImage.setVisibility(View.GONE);
((PhotoPickerPhotoCell) v.getParent()).checkBox.setChecked(selectedWebPhotos.containsKey(photoEntry.id), true);
}
photoPickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
@ -958,6 +978,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
imageView.setImageResource(R.drawable.nophotos);
}
cell.checkBox.setChecked(selectedPhotos.containsKey(photoEntry.imageId), false);
cell.editedImage.setVisibility(photoEntry.imagePath != null ? View.VISIBLE : View.GONE);
showing = PhotoViewer.getInstance().isShowingImage(photoEntry.path);
} else {
MediaController.SearchImage photoEntry = null;
@ -972,6 +993,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
imageView.setImageResource(R.drawable.nophotos);
}
cell.checkBox.setChecked(selectedWebPhotos.containsKey(photoEntry.id), false);
cell.editedImage.setVisibility(View.GONE);
showing = PhotoViewer.getInstance().isShowingImage(photoEntry.thumbUrl);
}
imageView.imageReceiver.setVisible(!showing, false);

View File

@ -34,11 +34,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.ScaleAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Scroller;
@ -48,6 +44,7 @@ import org.telegram.android.AndroidUtilities;
import org.telegram.android.ContactsController;
import org.telegram.android.ImageLoader;
import org.telegram.android.MessagesStorage;
import org.telegram.android.query.SharedMediaQuery;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLoader;
@ -108,7 +105,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private PhotoPickerBottomLayout pickerView;
private ImageView shareButton;
private RadialProgressView radialProgressViews[] = new RadialProgressView[3];
private GifDrawable gifDrawable = null;
private GifDrawable gifDrawable;
private ActionBarMenuItem editItem;
private AnimatorSetProxy currentActionBarAnimation;
private boolean canShowBottom = true;
private int animationInProgress = 0;
@ -117,7 +116,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private PlaceProviderObject showAfterAnimation;
private PlaceProviderObject hideAfterAnimation;
private boolean disableShowCheck = false;
private Animation.AnimationListener animationListener;
private ImageReceiver leftImage = new ImageReceiver();
private ImageReceiver centerImage = new ImageReceiver();
@ -189,6 +187,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private final static int gallery_menu_save = 1;
private final static int gallery_menu_showall = 2;
private final static int gallery_menu_send = 3;
private final static int gallery_menu_edit = 4;
private final static int PAGE_SPACING = AndroidUtilities.dp(30);
@ -340,13 +339,21 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
public static interface PhotoViewerProvider {
public PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index);
public Bitmap getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index);
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index);
public void willHidePhotoViewer();
public boolean isPhotoChecked(int index);
public void setPhotoChecked(int index);
public void cancelButtonPressed();
public void sendButtonPressed(int index);
public int getSelectedCount();
}
@ -373,14 +380,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
setWillNotDraw(false);
}
@Override
protected void onAnimationEnd() {
super.onAnimationEnd();
if (getInstance().animationListener != null) {
getInstance().animationListener.onAnimationEnd(null);
}
}
@Override
protected void onDraw(Canvas canvas) {
getInstance().onDraw(canvas);
@ -388,6 +387,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
private static volatile PhotoViewer Instance = null;
public static PhotoViewer getInstance() {
PhotoViewer localInstance = Instance;
if (localInstance == null) {
@ -489,13 +489,13 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
long uid = (Long) args[0];
if (uid == currentDialogId) {
if ((int) currentDialogId != 0 && (Boolean) args[2]) {
MessagesController.getInstance().getMediaCount(currentDialogId, classGuid, false);
SharedMediaQuery.getMediaCount(currentDialogId, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, false);
}
totalImagesCount = (Integer) args[1];
if (needSearchImageInArr && isFirstLoading) {
isFirstLoading = false;
loadingMoreImages = true;
MessagesController.getInstance().loadMedia(currentDialogId, 0, 100, 0, true, classGuid);
SharedMediaQuery.loadMedia(currentDialogId, 0, 100, 0, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
} else if (!imagesArr.isEmpty()) {
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, (totalImagesCount - imagesArr.size()) + currentIndex + 1, totalImagesCount));
}
@ -548,7 +548,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
} else {
if (!cacheEndReached || !arr.isEmpty() && added != 0) {
loadingMoreImages = true;
MessagesController.getInstance().loadMedia(currentDialogId, 0, 100, imagesArrTemp.get(0).messageOwner.id, true, classGuid);
SharedMediaQuery.loadMedia(currentDialogId, 0, 100, imagesArrTemp.get(0).messageOwner.id, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
}
}
} else {
@ -652,6 +652,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (opennedFromMedia) {
closePhoto(true);
} else if (currentDialogId != 0) {
disableShowCheck = true;
closePhoto(false);
Bundle args2 = new Bundle();
args2.putLong("dialog_id", currentDialogId);
@ -690,6 +691,21 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
}
}*/
} else if (id == gallery_menu_edit) {
Bundle args = new Bundle();
Bitmap bitmap = centerImage.getBitmap();
String key = centerImage.getKey();
if (bitmap == null) {
args.putString("photoPath", currentPathObject);
}
MediaController.PhotoEntry object = (MediaController.PhotoEntry) imagesArrLocals.get(currentIndex);
args.putInt("id", object.imageId);
args.putBoolean("freeformCrop", true);
args.putBoolean("onlyCrop", true);
PhotoEditorActivity fragment = new PhotoEditorActivity(args, bitmap, key);
fragment.setDelegate((PhotoCropActivity.PhotoEditActivityDelegate) placeProvider);
((LaunchActivity) parentActivity).presentFragment(fragment, false, true);
closePhoto(false);
}
}
@ -716,6 +732,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
menuItem.addSubItem(gallery_menu_save, LocaleController.getString("SaveToGallery", R.string.SaveToGallery), 0);
menuItem.addSubItem(gallery_menu_showall, LocaleController.getString("ShowAllMedia", R.string.ShowAllMedia), 0);
editItem = menu.addItemWithWidth(gallery_menu_edit, R.drawable.photo_edit, AndroidUtilities.dp(56));
bottomLayout = new FrameLayout(containerView.getContext());
containerView.addView(bottomLayout);
layoutParams = (FrameLayout.LayoutParams) bottomLayout.getLayoutParams();
@ -764,7 +782,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
intent.setType("image/jpeg");
}
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
parentActivity.startActivity(intent);
parentActivity.startActivity(Intent.createChooser(intent, ""));
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
@ -895,6 +914,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
dateTextView.setLayoutParams(layoutParams);
pickerView = new PhotoPickerBottomLayout(parentActivity);
pickerView.setBackgroundColor(0x7f000000);
containerView.addView(pickerView);
pickerView.cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -963,13 +983,14 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private void toggleCheckImageView(boolean show) {
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
animatorSet.playTogether(
ObjectAnimatorProxy.ofFloat(checkImageView, "alpha", show ? 1.0f : 0.0f)
ObjectAnimatorProxy.ofFloat(checkImageView, "alpha", show ? 1.0f : 0.0f),
ObjectAnimatorProxy.ofFloat(pickerView, "alpha", show ? 1.0f : 0.0f)
);
animatorSet.setDuration(200);
animatorSet.start();
}
private void toggleActionBar(boolean show, boolean animated) {
private void toggleActionBar(boolean show, final boolean animated) {
if (show) {
actionBar.setVisibility(View.VISIBLE);
if (canShowBottom) {
@ -981,25 +1002,28 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
bottomLayout.setEnabled(show);
if (animated) {
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
animatorSet.playTogether(
currentActionBarAnimation = new AnimatorSetProxy();
currentActionBarAnimation.playTogether(
ObjectAnimatorProxy.ofFloat(actionBar, "alpha", show ? 1.0f : 0.0f),
ObjectAnimatorProxy.ofFloat(bottomLayout, "alpha", show ? 1.0f : 0.0f)
);
if (!show) {
animatorSet.addListener(new AnimatorListenerAdapterProxy() {
currentActionBarAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Object animation) {
if (currentActionBarAnimation.equals(animation)) {
actionBar.setVisibility(View.GONE);
if (canShowBottom) {
bottomLayout.setVisibility(View.GONE);
}
currentActionBarAnimation = null;
}
}
});
}
animatorSet.setDuration(200);
animatorSet.start();
currentActionBarAnimation.setDuration(200);
currentActionBarAnimation.start();
} else {
ViewProxy.setAlpha(actionBar, show ? 1.0f : 0.0f);
ViewProxy.setAlpha(bottomLayout, show ? 1.0f : 0.0f);
@ -1075,7 +1099,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (message.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
return message.messageOwner.action.newUserPhoto.photo_big;
} else {
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.action.photo.sizes, AndroidUtilities.getPhotoSize());
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.photoThumbs, AndroidUtilities.getPhotoSize());
if (sizeFull != null) {
size[0] = sizeFull.size;
if (size[0] == 0) {
@ -1087,7 +1111,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
}
} else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && message.messageOwner.media.photo != null) {
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, AndroidUtilities.getPhotoSize());
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.photoThumbs, AndroidUtilities.getPhotoSize());
if (sizeFull != null) {
size[0] = sizeFull.size;
if (size[0] == 0) {
@ -1138,7 +1162,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
location.secret = sizeFull.secret;
return location;
} else {
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.action.photo.sizes, AndroidUtilities.getPhotoSize());
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.photoThumbs, AndroidUtilities.getPhotoSize());
if (sizeFull != null) {
TLRPC.TL_inputFileLocation location = new TLRPC.TL_inputFileLocation();
location.local_id = sizeFull.location.local_id;
@ -1149,7 +1173,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
}
} else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, AndroidUtilities.getPhotoSize());
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.photoThumbs, AndroidUtilities.getPhotoSize());
if (sizeFull != null) {
TLRPC.TL_inputFileLocation location = new TLRPC.TL_inputFileLocation();
location.local_id = sizeFull.location.local_id;
@ -1206,9 +1230,12 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
menuItem.setVisibility(View.VISIBLE);
bottomLayout.setVisibility(View.VISIBLE);
ViewProxy.setAlpha(checkImageView, 1.0f);
ViewProxy.setAlpha(pickerView, 1.0f);
checkImageView.clearAnimation();
pickerView.clearAnimation();
checkImageView.setVisibility(View.GONE);
pickerView.setVisibility(View.GONE);
editItem.setVisibility(View.GONE);
for (int a = 0; a < 3; a++) {
if (radialProgressViews[a] != null) {
radialProgressViews[a].setBackgroundState(-1, false);
@ -1284,17 +1311,26 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
bottomLayout.setVisibility(View.GONE);
shareButton.setVisibility(View.VISIBLE);
canShowBottom = false;
//editItem.setVisibility(imagesArrLocals.get(index) instanceof MediaController.PhotoEntry ? View.VISIBLE : View.GONE);
updateSelectedCount();
}
if (currentDialogId != 0 && totalImagesCount == 0) {
MessagesController.getInstance().getMediaCount(currentDialogId, classGuid, true);
SharedMediaQuery.getMediaCount(currentDialogId, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
} else if (avatarsUserId != 0) {
MessagesController.getInstance().loadUserPhotos(avatarsUserId, 0, 80, 0, true, classGuid);
}
}
public void setImageIndex(int index, boolean init) {
private void setImages() {
if (animationInProgress == 0) {
setIndexToImage(centerImage, currentIndex);
setIndexToImage(rightImage, currentIndex + 1);
setIndexToImage(leftImage, currentIndex - 1);
}
}
private void setImageIndex(int index, boolean init) {
if (currentIndex == index) {
return;
}
@ -1332,7 +1368,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (totalImagesCount != 0 && !needSearchImageInArr) {
if (imagesArr.size() < totalImagesCount && !loadingMoreImages && currentIndex < 5) {
MessageObject lastMessage = imagesArr.get(0);
MessagesController.getInstance().loadMedia(currentDialogId, 0, 100, lastMessage.messageOwner.id, !cacheEndReached, classGuid);
SharedMediaQuery.loadMedia(currentDialogId, 0, 100, lastMessage.messageOwner.id, SharedMediaQuery.MEDIA_PHOTOVIDEO, !cacheEndReached, classGuid);
loadingMoreImages = true;
}
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, (totalImagesCount - imagesArr.size()) + currentIndex + 1, totalImagesCount));
@ -1427,9 +1463,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
if (prevIndex == -1) {
setIndexToImage(centerImage, currentIndex);
setIndexToImage(rightImage, currentIndex + 1);
setIndexToImage(leftImage, currentIndex - 1);
setImages();
for (int a = 0; a < 3; a++) {
checkProgress(a, false);
@ -1553,6 +1587,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private void setIndexToImage(ImageReceiver imageReceiver, int index) {
if (!imagesArrLocals.isEmpty()) {
imageReceiver.setParentMessageObject(null);
if (index >= 0 && index < imagesArrLocals.size()) {
Object object = imagesArrLocals.get(index);
int size = (int) (AndroidUtilities.getPhotoSize() / AndroidUtilities.density);
@ -1584,33 +1619,38 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (!imagesArr.isEmpty()) {
messageObject = imagesArr.get(index);
}
imageReceiver.setParentMessageObject(messageObject);
if (messageObject != null) {
imageReceiver.setShouldGenerateQualityThumb(true);
}
if (messageObject != null && messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
if (messageObject.imagePreview != null) {
imageReceiver.setImageBitmap(messageObject.imagePreview);
} else if (messageObject.messageOwner.media.video.thumb != null) {
imageReceiver.setNeedsQualityThumb(true);
if (messageObject.messageOwner.media.video.thumb != null) {
Bitmap placeHolder = null;
if (currentThumb != null && imageReceiver == centerImage) {
placeHolder = currentThumb;
}
imageReceiver.setImage(fileLocation, null, placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, 0, true);
TLRPC.PhotoSize thumbLocation = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 100);
imageReceiver.setImage(null, null, null, placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, thumbLocation.location, "b", 0, true);
} else {
imageReceiver.setImageBitmap(parentActivity.getResources().getDrawable(R.drawable.photoview_placeholder));
}
} else {
imageReceiver.setNeedsQualityThumb(false);
Bitmap placeHolder = null;
if (messageObject != null) {
placeHolder = messageObject.imagePreview;
}
if (currentThumb != null && imageReceiver == centerImage) {
placeHolder = currentThumb;
}
if (size[0] == 0) {
size[0] = -1;
}
imageReceiver.setImage(fileLocation, null, placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, size[0], avatarsUserId != 0);
TLRPC.PhotoSize thumbLocation = messageObject != null ? FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 100) : null;
imageReceiver.setImage(fileLocation, null, null, placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, thumbLocation != null ? thumbLocation.location : null, "b", size[0], avatarsUserId != 0);
}
} else {
imageReceiver.setNeedsQualityThumb(false);
imageReceiver.setParentMessageObject(null);
if (size[0] == 0) {
imageReceiver.setImageBitmap((Bitmap) null);
} else {
@ -1776,6 +1816,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
@Override
public void run() {
animationInProgress = 0;
setImages();
transitionAnimationStartTime = 0;
containerView.invalidate();
animatingImageView.setVisibility(View.GONE);
@ -1948,48 +1989,36 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
transitionAnimationStartTime = System.currentTimeMillis();
animatorSet.start();
} else {
AnimationSet animationSet = new AnimationSet(true);
AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);
animation.setDuration(150);
animation.setFillAfter(false);
animationSet.addAnimation(animation);
ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.9f, 1.0f, 0.9f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(150);
scaleAnimation.setFillAfter(false);
animationSet.addAnimation(scaleAnimation);
animationSet.setDuration(150);
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
animatorSet.playTogether(
ObjectAnimatorProxy.ofFloat(containerView, "scaleX", 0.9f),
ObjectAnimatorProxy.ofFloat(containerView, "scaleY", 0.9f),
ObjectAnimatorProxy.ofInt(backgroundDrawable, "alpha", 0),
ObjectAnimatorProxy.ofFloat(containerView, "alpha", 0.0f)
);
animationInProgress = 2;
animationEndRunnable = new Runnable() {
@Override
public void run() {
if (animationListener != null) {
animationInProgress = 0;
onPhotoClosed(object);
animationListener = null;
}
ViewProxy.setScaleX(containerView, 1.0f);
ViewProxy.setScaleY(containerView, 1.0f);
containerView.clearAnimation();
}
};
animationSet.setAnimationListener(animationListener = new Animation.AnimationListener() {
animatorSet.setDuration(200);
animatorSet.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
public void onAnimationEnd(Object animation) {
if (animationEndRunnable != null) {
animationEndRunnable.run();
animationEndRunnable = null;
}
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
transitionAnimationStartTime = System.currentTimeMillis();
containerView.startAnimation(animationSet);
animatorSet.start();
}
}
@ -2121,8 +2150,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
}
} else if (ev.getActionMasked() == MotionEvent.ACTION_MOVE) {
discardTap = true;
if (canZoom && ev.getPointerCount() == 2 && !draggingDown && zooming && !changingPage) {
discardTap = true;
scale = (float) Math.hypot(ev.getX(1) - ev.getX(0), ev.getY(1) - ev.getY(0)) / pinchStartDistance * pinchStartScale;
translationX = (pinchCenterX - containerView.getWidth() / 2) - ((pinchCenterX - containerView.getWidth() / 2) - pinchStartX) * (scale / pinchStartScale);
translationY = (pinchCenterY - containerView.getHeight() / 2) - ((pinchCenterY - containerView.getHeight() / 2) - pinchStartY) * (scale / pinchStartScale);
@ -2134,6 +2163,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
float dx = Math.abs(ev.getX() - moveStartX);
float dy = Math.abs(ev.getY() - dragY);
if (dx > AndroidUtilities.dp(3) || dy > AndroidUtilities.dp(3)) {
discardTap = true;
}
if (canDragDown && !draggingDown && scale == 1 && dy >= AndroidUtilities.dp(30) && dy / 2 > dx) {
draggingDown = true;
moving = false;
@ -2141,6 +2173,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (isActionBarVisible && canShowBottom) {
toggleActionBar(false, true);
} else if (checkImageView.getVisibility() == View.VISIBLE) {
toggleActionBar(false, true);
toggleCheckImageView(false);
}
return true;
@ -2221,6 +2254,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
closePhoto(true);
} else {
if (checkImageView.getVisibility() == View.VISIBLE) {
toggleActionBar(true, true);
toggleCheckImageView(true);
}
animateTo(1, 0, 0);

View File

@ -13,6 +13,7 @@ import android.app.KeyguardManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.PowerManager;
import android.text.TextUtils;
@ -45,7 +46,6 @@ import org.telegram.android.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.android.MessageObject;
import org.telegram.android.PhotoObject;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.Components.AvatarDrawable;
@ -524,7 +524,8 @@ public class PopupNotificationActivity extends Activity implements NotificationC
imageView.imageReceiver.setAspectFit(true);
if (messageObject.type == 1) {
PhotoObject currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 100);
boolean photoSet = false;
if (currentPhotoObject != null) {
boolean photoExist = true;
@ -535,11 +536,11 @@ public class PopupNotificationActivity extends Activity implements NotificationC
}
}
if (photoExist || MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO)) {
imageView.setImage(currentPhotoObject.photoOwner.location, "100_100", messageObject.imagePreview, currentPhotoObject.photoOwner.size);
imageView.setImage(currentPhotoObject.location, "100_100", thumb.location, currentPhotoObject.size);
photoSet = true;
} else {
if (messageObject.imagePreview != null) {
imageView.setImageBitmap(messageObject.imagePreview);
if (thumb != null) {
imageView.setImage(thumb.location, null, (Drawable) null);
photoSet = true;
}
}

View File

@ -8,12 +8,15 @@
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.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Outline;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@ -24,6 +27,7 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.ViewTreeObserver;
import android.widget.AbsListView;
import android.widget.AdapterView;
@ -38,6 +42,7 @@ import org.telegram.android.LocaleController;
import org.telegram.android.MessagesStorage;
import org.telegram.android.SecretChatHelper;
import org.telegram.android.SendMessagesHelper;
import org.telegram.android.query.SharedMediaQuery;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.TLRPC;
@ -170,14 +175,12 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
}
}
NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatInfoDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
sortedUsers = new ArrayList<>();
updateOnlineCount();
if (chat_id > 0) {
MessagesController.getInstance().getMediaCount(-chat_id, classGuid, true);
SharedMediaQuery.getMediaCount(-chat_id, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
}
avatarUpdater = new AvatarUpdater();
@ -196,6 +199,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaCountDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
updateRowsIds();
return true;
@ -206,6 +210,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
super.onFragmentDestroy();
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mediaCountDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
if (user_id != 0) {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.contactsDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.encryptedChatCreated);
@ -214,7 +219,6 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
MessagesController.getInstance().cancelLoadFullUser(user_id);
} else if (chat_id != 0) {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatInfoDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
avatarUpdater.clear();
}
}
@ -547,21 +551,36 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
});
}
if (dialog_id != 0) {
MessagesController.getInstance().getMediaCount(dialog_id, classGuid, true);
SharedMediaQuery.getMediaCount(dialog_id, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
} else {
MessagesController.getInstance().getMediaCount(user_id, classGuid, true);
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_user_states);
writeButton.setImageResource(R.drawable.floating_message);
writeButton.setPadding(0, AndroidUtilities.dp(3), 0, 0);
} else if (chat_id != 0) {
writeButton.setImageResource(R.drawable.floating_group_states);
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;
@ -580,6 +599,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
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);
@ -814,6 +834,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().removeObserver(ProfileActivity.this, NotificationCenter.closeChats);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
TLRPC.EncryptedChat encryptedChat = (TLRPC.EncryptedChat) args[0];
Bundle args2 = new Bundle();
@ -1082,7 +1103,11 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
AvatarDrawable avatarDrawable = new AvatarDrawable(user);
avatarImage.setImage(photo, "50_50", avatarDrawable);
if (user instanceof TLRPC.TL_userDeleted) {
nameTextView.setText(LocaleController.getString("HiddenName", R.string.HiddenName));
} else {
nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
}
onlineTextView.setText(LocaleController.formatUserStatus(user));
avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
@ -1166,6 +1191,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
if (dialog_id != 0) {
Bundle args = new Bundle();
args.putBoolean("scrollToTopOnResume", true);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
int lower_part = (int)dialog_id;
if (lower_part != 0) {

View File

@ -30,14 +30,13 @@ import android.widget.ListView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.MessagesController;
import org.telegram.android.MessagesStorage;
import org.telegram.android.NotificationsController;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.android.LocaleController;
import org.telegram.android.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.Cells.TextColorCell;
@ -162,18 +161,23 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
LocaleController.getString("Disabled", R.string.Disabled)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
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();
}
if (i == settingsNotificationsRow) {
updateServerNotificationsSettings();
}
NotificationsController.updateServerNotificationsSettings(dialog_id);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
@ -298,45 +302,6 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
return fragmentView;
}
public void updateServerNotificationsSettings() {
if ((int)dialog_id == 0) {
return;
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
TLRPC.TL_account_updateNotifySettings req = new TLRPC.TL_account_updateNotifySettings();
req.settings = new TLRPC.TL_inputPeerNotifySettings();
req.settings.sound = "default";
req.settings.events_mask = 0;
req.settings.mute_until = preferences.getInt("notify2_" + dialog_id, 0) != 2 ? 0 : Integer.MAX_VALUE;
req.settings.show_previews = preferences.getBoolean("preview_" + dialog_id, true);
req.peer = new TLRPC.TL_inputNotifyPeer();
if ((int)dialog_id < 0) {
((TLRPC.TL_inputNotifyPeer)req.peer).peer = new TLRPC.TL_inputPeerChat();
((TLRPC.TL_inputNotifyPeer)req.peer).peer.chat_id = -(int)dialog_id;
} else {
TLRPC.User user = MessagesController.getInstance().getUser((int)dialog_id);
if (user == null) {
return;
}
if (user instanceof TLRPC.TL_userForeign || user instanceof TLRPC.TL_userRequest) {
((TLRPC.TL_inputNotifyPeer)req.peer).peer = new TLRPC.TL_inputPeerForeign();
((TLRPC.TL_inputNotifyPeer)req.peer).peer.access_hash = user.access_hash;
} else {
((TLRPC.TL_inputNotifyPeer)req.peer).peer = new TLRPC.TL_inputPeerContact();
}
((TLRPC.TL_inputNotifyPeer)req.peer).peer.user_id = (int)dialog_id;
}
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
}
});
}
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
@ -451,6 +416,19 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi
textCell.setTextAndValue(LocaleController.getString("Notifications", R.string.Notifications), LocaleController.getString("Enabled", R.string.Enabled), true);
} else if (value == 2) {
textCell.setTextAndValue(LocaleController.getString("Notifications", R.string.Notifications), LocaleController.getString("Disabled", R.string.Disabled), true);
} else if (value == 3) {
int delta = preferences.getInt("notifyuntil_" + dialog_id, 0) - ConnectionsManager.getInstance().getCurrentTime();
String val;
if (delta <= 0) {
val = LocaleController.getString("Enabled", R.string.Enabled);
} else if (delta < 60 * 60) {
val = LocaleController.formatString("WillUnmuteIn", R.string.WillUnmuteIn, LocaleController.formatPluralString("Minutes", delta / 60));
} else if (delta < 60 * 60 * 24) {
val = LocaleController.formatString("WillUnmuteIn", R.string.WillUnmuteIn, LocaleController.formatPluralString("Hours", (int) Math.ceil(delta / 60.0f / 60)));
} else {
val = LocaleController.formatString("WillUnmuteIn", R.string.WillUnmuteIn, LocaleController.formatPluralString("Days", (int) Math.ceil(delta / 60.0f / 60 / 24)));
}
textCell.setTextAndValue(LocaleController.getString("Notifications", R.string.Notifications), val, true);
}
} else if (i == settingsSoundRow) {
String value = preferences.getString("sound_" + dialog_id, LocaleController.getString("Default", R.string.Default));

View File

@ -256,12 +256,12 @@ public class SecretPhotoViewer implements NotificationCenter.NotificationCenterD
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesDeleted);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didCreatedNewDeleteTask);
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(messageObject.messageOwner.media.photo.sizes, AndroidUtilities.getPhotoSize());
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
int size = sizeFull.size;
if (size == 0) {
size = -1;
}
BitmapDrawable drawable = ImageLoader.getInstance().getImageFromMemory(sizeFull.location, null, null, null);
BitmapDrawable drawable = ImageLoader.getInstance().getImageFromMemory(sizeFull.location, null, null);
if (drawable == null) {
File file = FileLoader.getPathToAttach(sizeFull);
Bitmap bitmap = null;

View File

@ -8,6 +8,8 @@
package org.telegram.ui;
import android.animation.ObjectAnimator;
import android.animation.StateListAnimator;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
@ -18,7 +20,9 @@ import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Outline;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.text.Spannable;
@ -31,6 +35,7 @@ import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.ViewTreeObserver;
import android.widget.AbsListView;
import android.widget.AdapterView;
@ -596,7 +601,21 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
frameLayout.addView(actionBar);
writeButton = new ImageView(getParentActivity());
writeButton.setImageResource(R.drawable.floating_group_states);
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;

View File

@ -225,7 +225,7 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
Utilities.addMediaToGallery(currentPicturePath);
try {
Point screenSize = AndroidUtilities.getRealScreenSize();
Bitmap bitmap = ImageLoader.loadBitmap(currentPicturePath, null, screenSize.x, screenSize.y);
Bitmap bitmap = ImageLoader.loadBitmap(currentPicturePath, null, screenSize.x, screenSize.y, true);
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg");
FileOutputStream stream = new FileOutputStream(toFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream);
@ -242,7 +242,7 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
}
try {
Point screenSize = AndroidUtilities.getRealScreenSize();
Bitmap bitmap = ImageLoader.loadBitmap(null, data.getData(), screenSize.x, screenSize.y);
Bitmap bitmap = ImageLoader.loadBitmap(null, data.getData(), screenSize.x, screenSize.y, true);
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg");
FileOutputStream stream = new FileOutputStream(toFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 227 B

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 373 B

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 B

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1022 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 951 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

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