1
0
mirror of https://github.com/NekoX-Dev/NekoX.git synced 2024-11-04 22:51:40 +01:00

unread count

This commit is contained in:
Riko Sakurauchi 2019-06-17 11:39:43 +08:00
parent ac92d9984d
commit d626d91dc6
No known key found for this signature in database
GPG Key ID: 25AC0345B92902AF
2 changed files with 83 additions and 5 deletions

View File

@ -11,7 +11,9 @@ import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.GridLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import androidx.recyclerview.widget.RecyclerView;
@ -273,13 +275,24 @@ public class FilterPopup {
popupLayout.setBackgroundDrawable(shadowDrawable);
LinearLayout linearLayout = new LinearLayout(parentActivity);
GridLayout gridLayout = new GridLayout(parentActivity);
RelativeLayout cascadeLayout = new RelativeLayout(parentActivity) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(gridLayout.getMeasuredWidth(), getMeasuredHeight());
}
};
cascadeLayout.addView(gridLayout, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
cascadeLayout.addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
ScrollView scrollView;
if (Build.VERSION.SDK_INT >= 21) {
scrollView = new ScrollView(parentActivity, null, 0, R.style.scrollbarShapeStyle) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(linearLayout.getMeasuredWidth(), getMeasuredHeight());
setMeasuredDimension(cascadeLayout.getMeasuredWidth(), getMeasuredHeight());
}
};
} else {
@ -288,21 +301,27 @@ public class FilterPopup {
scrollView.setClipToPadding(false);
popupLayout.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
linearLayout.setMinimumWidth(AndroidUtilities.dp(200));
gridLayout.setColumnCount(2);
gridLayout.setMinimumWidth(AndroidUtilities.dp(200));
linearLayout.setOrientation(LinearLayout.VERTICAL);
for (int a = 0, N = items.size(); a < N; a++) {
ActionBarMenuSubItem cell = new ActionBarMenuSubItem(parentActivity);
cell.setText(items.get(a).toString());
linearLayout.addView(cell);
ActionBarMenuSubItem cell2 = new ActionBarMenuSubItem(parentActivity);
linearLayout.addView(cell2);
gridLayout.addView(cell);
UnreadCountBadgeView badge = new UnreadCountBadgeView(parentActivity, "2333");
gridLayout.addView(badge);
final int i = a;
cell.setOnClickListener(v1 -> {
cell2.setOnClickListener(v1 -> {
dialogsActivity.updateDialogsType(options.get(i));
if (scrimPopupWindow != null) {
scrimPopupWindow.dismiss();
}
});
}
scrollView.addView(linearLayout, LayoutHelper.createScroll(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
scrollView.addView(cascadeLayout, LayoutHelper.createScroll(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
scrimPopupWindow = new ActionBarPopupWindow(popupLayout, LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT) {
@Override
public void dismiss() {

View File

@ -0,0 +1,59 @@
package tw.nekomimi.nekogram;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.text.Layout;
import android.text.StaticLayout;
import android.view.View;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.LocaleController;
import org.telegram.ui.ActionBar.Theme;
public class UnreadCountBadgeView extends View {
public String countString;
private RectF rect = new RectF();
StaticLayout countLayout;
int countWidth;
public UnreadCountBadgeView(Context context, String countString) {
super(context);
this.countString = countString;
countWidth = Math.max(AndroidUtilities.dp(12), (int) Math.ceil(Theme.dialogs_countTextPaint.measureText(countString)));
countLayout = new StaticLayout(countString, Theme.dialogs_countTextPaint, countWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = Theme.dialogs_countPaint;
// Paint paint = dialogMuted || currentDialogFolderId != 0 ? Theme.dialogs_countGrayPaint : Theme.dialogs_countPaint;
paint.setAlpha(255);
Theme.dialogs_countTextPaint.setAlpha(255);
int countLeft = AndroidUtilities.dp(5.5f);
int countTop = AndroidUtilities.dp(12.5f);
int x = 0;
rect.set(x, countTop, x + countWidth + AndroidUtilities.dp(11), countTop + AndroidUtilities.dp(23));
canvas.drawRoundRect(rect, 11.5f * AndroidUtilities.density, 11.5f * AndroidUtilities.density, paint);
if (countLayout != null) {
canvas.save();
canvas.translate(countLeft, countTop + AndroidUtilities.dp(4));
countLayout.draw(canvas);
canvas.restore();
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(
countWidth + AndroidUtilities.dp(29),
AndroidUtilities.dp(48)
);
}
}