make the unread count a bit more accurate

refactor-toolbar
Floens 7 years ago
parent d70a655bf6
commit a91cc5155c
  1. 13
      Clover/app/src/main/java/org/floens/chan/ui/adapter/DrawerAdapter.java
  2. 4
      Clover/app/src/main/java/org/floens/chan/ui/drawable/ArrowMenuDrawable.java
  3. 37
      Clover/app/src/main/java/org/floens/chan/ui/helper/PinHelper.java

@ -31,6 +31,7 @@ import org.floens.chan.R;
import org.floens.chan.core.manager.WatchManager;
import org.floens.chan.core.model.orm.Pin;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.ui.helper.PinHelper;
import org.floens.chan.ui.helper.PostHelper;
import org.floens.chan.ui.view.ThumbnailView;
import org.floens.chan.utils.AndroidUtils;
@ -248,17 +249,7 @@ public class DrawerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.image.setUrl(pin.thumbnailUrl, dp(40), dp(40));
if (ChanSettings.watchEnabled.get()) {
String count;
if (pin.isError) {
count = "E";
} else {
int c = pin.getNewPostCount();
if (c > 999) {
count = "1k+";
} else {
count = Integer.toString(c);
}
}
String count = PinHelper.getShortUnreadCount(pin.getNewPostCount());
holder.watchCountText.setVisibility(View.VISIBLE);
holder.watchCountText.setText(count);

@ -26,6 +26,8 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import org.floens.chan.ui.helper.PinHelper;
import static org.floens.chan.utils.AndroidUtils.dp;
public class ArrowMenuDrawable extends Drawable {
@ -199,7 +201,7 @@ public class ArrowMenuDrawable extends Drawable {
}
public void setBadge(int count, boolean red) {
String text = count == 0 ? null : (count > 999 ? "1k+" : String.valueOf(count));
String text = count == 0 ? null : (PinHelper.getShortUnreadCount(count));
if (badgeRed != red || !TextUtils.equals(text, badgeText)) {
badgeText = text;
badgeRed = red;

@ -0,0 +1,37 @@
/*
* Clover - 4chan browser https://github.com/Floens/Clover/
* Copyright (C) 2014 Floens
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.floens.chan.ui.helper;
public class PinHelper {
public static String getShortUnreadCount(int value) {
String count;
if (value < 1000) {
count = String.valueOf(value);
} else {
int k = value / 1000;
if (k < 10) {
count = k + "k+";
} else if (k < 100) {
count = k + "k";
} else {
count = ":D";
}
}
return count;
}
}
Loading…
Cancel
Save