From fdaf4555c5d1551c9a6914a3a8279f84e7ed1ea8 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Fri, 21 Nov 2014 22:36:21 +0300 Subject: [PATCH] Bug fixes --- TMessagesProj/build.gradle | 20 +-- .../telegram/android/AndroidUtilities.java | 2 +- .../org/telegram/android/MessageObject.java | 4 +- .../android/NotificationsController.java | 9 +- .../telegram/ui/Adapters/ContactsAdapter.java | 2 +- .../ui/Adapters/ContactsSearchAdapter.java | 5 +- .../org/telegram/ui/Cells/ChatActionCell.java | 2 +- .../org/telegram/ui/Cells/DialogCell.java | 10 +- .../java/org/telegram/ui/Cells/UserCell.java | 4 +- .../org/telegram/ui/GroupCreateActivity.java | 8 +- .../org/telegram/ui/LastSeenActivity.java | 6 + .../java/org/telegram/ui/Views/CheckBox.java | 138 +++++++++++++++--- .../java/org/telegram/ui/Views/Switch.java | 1 - TMessagesProj/src/main/res/values/strings.xml | 2 +- 14 files changed, 168 insertions(+), 45 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 24c5e8949..2a1bb4c7f 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -65,16 +65,16 @@ android { jni.srcDirs = [] //disable automatic ndk-build call } - sourceSets { - debug { - manifest.srcFile 'config/debug/AndroidManifest.xml' - } - release { - manifest.srcFile 'config/release/AndroidManifest.xml' - } - foss { - manifest.srcFile 'config/foss/AndroidManifest.xml' - } + sourceSets.debug { + manifest.srcFile 'config/debug/AndroidManifest.xml' + } + + sourceSets.release { + manifest.srcFile 'config/release/AndroidManifest.xml' + } + + sourceSets.foss { + manifest.srcFile 'config/foss/AndroidManifest.xml' } defaultConfig { diff --git a/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java b/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java index 91ac10b6c..9e8afe33f 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java +++ b/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java @@ -346,7 +346,7 @@ public class AndroidUtilities { } else if (encryptedChat.ttl == 60 * 60 * 24 * 7) { numberPicker.setValue(20); } else if (encryptedChat.ttl == 0) { - numberPicker.setValue(5); + numberPicker.setValue(0); } numberPicker.setFormatter(new NumberPicker.Formatter() { @Override diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessageObject.java b/TMessagesProj/src/main/java/org/telegram/android/MessageObject.java index 953bdb110..d3cc37878 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MessageObject.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MessageObject.java @@ -345,7 +345,9 @@ public class MessageObject { int dateMonth = rightNow.get(Calendar.MONTH); dateKey = String.format("%d_%02d_%02d", dateYear, dateMonth, dateDay); - generateLayout(); + if (preview != 0) { + generateLayout(); + } generateThumbs(false, preview); } diff --git a/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java b/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java index e63e291d8..4b23d7ef0 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java @@ -424,6 +424,12 @@ public class NotificationsController { mBuilder.setPriority(NotificationCompat.PRIORITY_MAX); } + mBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE); + mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); + /*Bundle bundle = new Bundle(); + bundle.putString(NotificationCompat.EXTRA_PEOPLE, ); + mBuilder.setExtras()*/ + String lastMessage = null; String lastMessageFull = null; if (pushMessages.size() == 1) { @@ -627,7 +633,8 @@ public class NotificationsController { .setContentText(text) .setGroupSummary(false) .setContentIntent(contentIntent) - .extend(new NotificationCompat.WearableExtender().addAction(action)); + .extend(new NotificationCompat.WearableExtender().addAction(action)) + .setCategory(NotificationCompat.CATEGORY_MESSAGE); notificationManager.notify(notificationId, builder.build()); wearNoticationsIds.put(dialog_id, notificationId); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsAdapter.java index 5cf62fbff..99915e3eb 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsAdapter.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsAdapter.java @@ -220,7 +220,7 @@ public class ContactsAdapter extends BaseSectionsAdapter { TLRPC.User user = MessagesController.getInstance().getUser(arr.get(position).user_id); ((UserCell)convertView).setData(user, null, null, 0); if (checkedMap != null) { - ((UserCell) convertView).setChecked(checkedMap.containsKey(user.id)); + ((UserCell) convertView).setChecked(checkedMap.containsKey(user.id), false); } if (ignoreUsers != null) { if (ignoreUsers.containsKey(user.id)) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsSearchAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsSearchAdapter.java index f2ae0178e..8d5fe7023 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsSearchAdapter.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsSearchAdapter.java @@ -215,6 +215,9 @@ public class ContactsSearchAdapter extends BaseContactsSearchAdapter { if (view == null) { if (useUserCell) { view = new UserCell(mContext, 1); + if (checkedMap != null) { + ((UserCell) view).setChecked(false, false); + } } else { view = new ProfileSearchCell(mContext); } @@ -244,7 +247,7 @@ public class ContactsSearchAdapter extends BaseContactsSearchAdapter { if (useUserCell) { ((UserCell) view).setData(user, name, username, 0); if (checkedMap != null) { - ((UserCell) view).setChecked(checkedMap.containsKey(user.id)); + ((UserCell) view).setChecked(checkedMap.containsKey(user.id), false); } } else { ((ProfileSearchCell) view).setData(user, null, null, name, username); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatActionCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatActionCell.java index 2f12ebf40..c7e20f198 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatActionCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatActionCell.java @@ -228,7 +228,7 @@ public class ChatActionCell extends BaseCell { setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), textHeight + AndroidUtilities.dp(14)); return; } - int width = MeasureSpec.getSize(widthMeasureSpec); + int width = Math.max(AndroidUtilities.dp(30), MeasureSpec.getSize(widthMeasureSpec)); if (width != previousWidth) { previousWidth = width; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java index decbc68ea..ebbe032f1 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java @@ -328,7 +328,12 @@ public class DialogCell extends BaseCell { messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("%s: %s", name, message.messageText)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20)); } else { if (message.messageOwner.message != null) { - messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("%s: %s", name, message.messageOwner.message.replace("\n", " ").replace("<", "<").replace(">", ">"))), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20)); + String mess = message.messageOwner.message; + if (mess.length() > 150) { + mess = mess.substring(0, 150); + } + mess = mess.replace("\n", " "); + messageString = Emoji.replaceEmoji(Html.fromHtml(String.format("%s: %s", name, mess.replace("<", "<").replace(">", ">"))), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20)); } } } else { @@ -505,10 +510,11 @@ public class DialogCell extends BaseCell { if (messageString == null) { messageString = ""; } - String mess = messageString.toString().replace("\n", " "); + String mess = messageString.toString(); if (mess.length() > 150) { mess = mess.substring(0, 150); } + mess = mess.replace("\n", " "); messageString = Emoji.replaceEmoji(mess, messagePaint.getFontMetricsInt(), AndroidUtilities.dp(17)); } messageWidth = Math.max(AndroidUtilities.dp(12), messageWidth); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/UserCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/UserCell.java index 1492ccf90..4d49a33a2 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/UserCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/UserCell.java @@ -142,11 +142,11 @@ public class UserCell extends FrameLayout { update(0); } - public void setChecked(boolean checked) { + public void setChecked(boolean checked, boolean animated) { if (checkBox.getVisibility() != VISIBLE) { checkBox.setVisibility(VISIBLE); } - checkBox.setChecked(checked); + checkBox.setChecked(checked, animated); } @Override diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java index c03c0af83..7a3193837 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java @@ -120,7 +120,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen isBroadcast = args.getBoolean("broadcast", false); isAlwaysShare = args.getBoolean("isAlwaysShare", false); isNeverShare = args.getBoolean("isNeverShare", false); - maxCount = !isBroadcast ? MessagesController.getInstance().maxGroupCount : MessagesController.getInstance().maxBroadcastCount; + maxCount = !isBroadcast ? MessagesController.getInstance().maxGroupCount - 1 : MessagesController.getInstance().maxBroadcastCount; } @Override @@ -391,7 +391,9 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen return; } + boolean check = true; if (selectedContacts.containsKey(user.id)) { + check = false; try { XImageSpan span = selectedContacts.get(user.id); selectedContacts.remove(user.id); @@ -441,7 +443,9 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen listView.setVerticalScrollBarEnabled(false); emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts)); } else { - listView.invalidateViews(); + if (view instanceof UserCell) { + ((UserCell) view).setChecked(check, true); + } } } }); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LastSeenActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LastSeenActivity.java index 7ba77bdb8..653e39fde 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LastSeenActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LastSeenActivity.java @@ -193,8 +193,14 @@ public class LastSeenActivity extends BaseFragment implements NotificationCenter public void didSelectUsers(ArrayList ids) { if (i == neverShareRow) { currentMinus = ids; + for (Integer id : currentMinus) { + currentPlus.remove(id); + } } else { currentPlus = ids; + for (Integer id : currentPlus) { + currentMinus.remove(id); + } } doneButton.setVisibility(View.VISIBLE); listAdapter.notifyDataSetChanged(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/CheckBox.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/CheckBox.java index c407daac5..9a27adba8 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/CheckBox.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/CheckBox.java @@ -9,50 +9,146 @@ package org.telegram.ui.Views; import android.content.Context; +import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffXfermode; import android.graphics.drawable.Drawable; -import android.widget.CompoundButton; +import android.view.View; +import org.telegram.android.AndroidUtilities; import org.telegram.messenger.R; +import org.telegram.ui.AnimationCompat.ObjectAnimatorProxy; -public class CheckBox extends CompoundButton { +public class CheckBox extends View { - private Paint paint; - private Drawable checkDrawable; + private static Drawable checkDrawable; + private static Paint paint; + private static Paint eraser; + private static Paint eraser2; + private static Paint checkPaint; + + private Bitmap drawBitmap; + private Bitmap checkBitmap; + private Canvas bitmapCanvas; + private Canvas checkCanvas; + + private float progress; + private ObjectAnimatorProxy checkAnimator; + private boolean isCheckAnimation = true; + + private boolean attachedToWindow; + private boolean isChecked = false; + + private final static float progressBounceDiff = 0.2f; public CheckBox(Context context) { super(context); + if (checkDrawable == null) { + checkDrawable = context.getResources().getDrawable(R.drawable.round_check2); + paint = new Paint(Paint.ANTI_ALIAS_FLAG); + paint.setColor(0xff5ec245); + eraser = new Paint(Paint.ANTI_ALIAS_FLAG); + eraser.setColor(0); + eraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); + eraser2 = new Paint(Paint.ANTI_ALIAS_FLAG); + eraser2.setColor(0); + eraser2.setStyle(Paint.Style.STROKE); + eraser2.setStrokeWidth(AndroidUtilities.dp(28)); + eraser2.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); + } + drawBitmap = Bitmap.createBitmap(AndroidUtilities.dp(22), AndroidUtilities.dp(22), Bitmap.Config.ARGB_4444); + bitmapCanvas = new Canvas(drawBitmap); + checkBitmap = Bitmap.createBitmap(AndroidUtilities.dp(22), AndroidUtilities.dp(22), Bitmap.Config.ARGB_4444); + checkCanvas = new Canvas(checkBitmap); + } - paint = new Paint(Paint.ANTI_ALIAS_FLAG); - paint.setColor(0xff5ec245); + public void setProgress(float value) { + progress = value; + invalidate(); + } - checkDrawable = context.getResources().getDrawable(R.drawable.round_check2); + public float getProgress() { + return progress; + } + + private void cancelCheckAnimator() { + if (checkAnimator != null) { + checkAnimator.cancel(); + } + } + + private void animateToCheckedState(boolean newCheckedState) { + isCheckAnimation = newCheckedState; + checkAnimator = ObjectAnimatorProxy.ofFloatProxy(this, "progress", newCheckedState ? 1 : 0); + checkAnimator.setDuration(300); + checkAnimator.start(); } @Override - public void setChecked(boolean checked) { - super.setChecked(checked); + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + attachedToWindow = true; + } - checked = isChecked(); + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + attachedToWindow = false; + } + + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + } + + public void setChecked(boolean checked, boolean animated) { + isChecked = checked; invalidate(); - /*if (attachedToWindow && wasLayout) { - animateThumbToCheckedState(checked); + if (attachedToWindow && animated) { + animateToCheckedState(checked); } else { - cancelPositionAnimator(); - setThumbPosition(checked ? 1 : 0); - }*/ + cancelCheckAnimator(); + setProgress(checked ? 1.0f : 0.0f); + } + } + + public boolean isChecked() { + return isChecked; } @Override protected void onDraw(Canvas canvas) { - if (isChecked()) { - canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, getMeasuredWidth() / 2, paint); - int x = (getMeasuredWidth() - checkDrawable.getIntrinsicWidth()) / 2; - int y = (getMeasuredHeight() - checkDrawable.getIntrinsicHeight()) / 2; - checkDrawable.setBounds(x, y, x + checkDrawable.getIntrinsicWidth(), y + checkDrawable.getIntrinsicHeight()); - checkDrawable.draw(canvas); + if (progress != 0) { + drawBitmap.eraseColor(0); + float rad = getMeasuredWidth() / 2; + + float roundProgress = progress >= 0.5f ? 1.0f : progress / 0.5f; + float checkProgress = progress < 0.5f ? 0.0f : (progress - 0.5f) / 0.5f; + + float roundProgressCheckState = isCheckAnimation ? progress : (1.0f - progress); + if (roundProgressCheckState < progressBounceDiff) { + rad -= AndroidUtilities.dp(2) * roundProgressCheckState / progressBounceDiff; + } else if (roundProgressCheckState < progressBounceDiff * 2) { + rad -= AndroidUtilities.dp(2) - AndroidUtilities.dp(2) * (roundProgressCheckState - progressBounceDiff) / progressBounceDiff; + } + bitmapCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, rad, paint); + bitmapCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, rad * (1 - roundProgress), eraser); + canvas.drawBitmap(drawBitmap, 0, 0, null); + + checkBitmap.eraseColor(0); + int w = checkDrawable.getIntrinsicWidth(); + int h = checkDrawable.getIntrinsicHeight(); + int x = (getMeasuredWidth() - w) / 2; + int y = (getMeasuredHeight() - h) / 2; + + checkDrawable.setBounds(x, y, x + w, y + h); + checkDrawable.draw(checkCanvas); + checkCanvas.drawCircle(getMeasuredWidth() / 2 - AndroidUtilities.dp(2.5f), getMeasuredHeight() / 2 + AndroidUtilities.dp(4), ((getMeasuredWidth() + AndroidUtilities.dp(6)) / 2) * (1 - checkProgress), eraser2); + + canvas.drawBitmap(checkBitmap, 0, 0, null); } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/Switch.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/Switch.java index b1bb9aa0a..1a10e4334 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/Switch.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/Switch.java @@ -90,7 +90,6 @@ public class Switch extends CompoundButton { private ObjectAnimatorProxy mPositionAnimator; - @SuppressWarnings("hiding") private final Rect mTempRect = new Rect(); public Switch(Context context) { diff --git a/TMessagesProj/src/main/res/values/strings.xml b/TMessagesProj/src/main/res/values/strings.xml index 6006908e2..d38745b32 100644 --- a/TMessagesProj/src/main/res/values/strings.xml +++ b/TMessagesProj/src/main/res/values/strings.xml @@ -137,7 +137,7 @@ %1$s removed you from the group %2$s %1$s has left the group %2$s %1$s joined Telegram! - %1$s,\nWe detected a login into your account from a new device on %2$s\n\nDevice: %3$s\nLocation: %4$s\n\nIf this wasn\'t you, you can go to Settings - Terminate all sessions.\n\nSincerely,\nThe Telegram Team + %1$s,\nWe detected a login into your account from a new device on %2$s\n\nDevice: %3$s\nLocation: %4$s\n\nIf this wasn\'t you, you can go to Settings - Privacy and Security - Terminate all other sessions.\n\nSincerely,\nThe Telegram Team %1$s updated profile photo Reply Reply to %1$s