From f1881efdc10fe1c92585dc206ba2c721889b7b31 Mon Sep 17 00:00:00 2001 From: Floens Date: Mon, 24 Aug 2015 22:05:46 +0200 Subject: [PATCH] Add option to show filenames on posts --- .../chan/core/settings/ChanSettings.java | 2 + .../org/floens/chan/ui/cell/PostCell.java | 46 ++++++++++++------- .../AdvancedSettingsController.java | 4 +- Clover/app/src/main/res/values/strings.xml | 1 + 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java b/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java index 8bf7c249..25c5521b 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java +++ b/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java @@ -89,6 +89,7 @@ public class ChanSettings { public static final BooleanSetting volumeKeysScrolling; public static final BooleanSetting postFullDate; public static final BooleanSetting postFileInfo; + public static final BooleanSetting postFilename; public static final BooleanSetting watchEnabled; public static final BooleanSetting watchCountdown; @@ -152,6 +153,7 @@ public class ChanSettings { volumeKeysScrolling = new BooleanSetting(p, "preference_volume_key_scrolling", false); postFullDate = new BooleanSetting(p, "preference_post_full_date", false); postFileInfo = new BooleanSetting(p, "preference_post_file_info", true); + postFilename = new BooleanSetting(p, "preference_post_filename", false); watchEnabled = new BooleanSetting(p, "preference_watch_enabled", false, new Setting.SettingCallback() { @Override diff --git a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java index d71a8c85..604abb47 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java @@ -38,6 +38,7 @@ import android.text.style.BackgroundColorSpan; import android.text.style.ClickableSpan; import android.text.style.ForegroundColorSpan; import android.text.style.StyleSpan; +import android.text.style.UnderlineSpan; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; @@ -314,15 +315,14 @@ public class PostCell extends LinearLayout implements PostCellInterface, PostLin thumbnailView.setUrl(null, 0, 0); } - CharSequence[] titleParts = new CharSequence[post.subjectSpan == null ? 2 : 4]; - int titlePartsCount = 0; + List titleParts = new ArrayList<>(5); if (post.subjectSpan != null) { - titleParts[titlePartsCount++] = post.subjectSpan; - titleParts[titlePartsCount++] = "\n"; + titleParts.add(post.subjectSpan); + titleParts.add("\n"); } - titleParts[titlePartsCount++] = post.nameTripcodeIdCapcodeSpan; + titleParts.add(post.nameTripcodeIdCapcodeSpan); CharSequence time; if (ChanSettings.postFullDate.get()) { @@ -338,24 +338,38 @@ public class PostCell extends LinearLayout implements PostCellInterface, PostLin Resources.getSystem().updateConfiguration(c, null); } - String fileInfo = ""; - if (ChanSettings.postFileInfo.get() && post.hasImage) { - PostImage image = post.image; - fileInfo = "\n" + image.extension.toUpperCase() + " " + - AndroidUtils.getReadableFileSize(image.size, false) + " " + - image.imageWidth + "x" + image.imageHeight; - } - String noText = "No." + post.no; - SpannableString date = new SpannableString(noText + " " + time + fileInfo); + SpannableString date = new SpannableString(noText + " " + time); date.setSpan(new ForegroundColorSpan(theme.detailsColor), 0, date.length(), 0); date.setSpan(new AbsoluteSizeSpan(detailsSizePx), 0, date.length(), 0); + titleParts.add(date); if (ChanSettings.tapNoReply.get()) { date.setSpan(new NoClickableSpan(), 0, noText.length(), 0); } - titleParts[titlePartsCount] = date; - title.setText(TextUtils.concat(titleParts)); + if (post.hasImage) { + PostImage image = post.image; + + boolean postFileName = ChanSettings.postFilename.get(); + if (postFileName) { + SpannableString fileInfo = new SpannableString("\n" + image.filename + "." + image.extension); + fileInfo.setSpan(new ForegroundColorSpan(theme.detailsColor), 0, fileInfo.length(), 0); + fileInfo.setSpan(new AbsoluteSizeSpan(detailsSizePx), 0, fileInfo.length(), 0); + fileInfo.setSpan(new UnderlineSpan(), 0, fileInfo.length(), 0); + titleParts.add(fileInfo); + } + + if (ChanSettings.postFileInfo.get()) { + SpannableString fileInfo = new SpannableString((postFileName ? " " : "\n") + image.extension.toUpperCase() + " " + + AndroidUtils.getReadableFileSize(image.size, false) + " " + + image.imageWidth + "x" + image.imageHeight); + fileInfo.setSpan(new ForegroundColorSpan(theme.detailsColor), 0, fileInfo.length(), 0); + fileInfo.setSpan(new AbsoluteSizeSpan(detailsSizePx), 0, fileInfo.length(), 0); + titleParts.add(fileInfo); + } + } + + title.setText(TextUtils.concat(titleParts.toArray(new CharSequence[titleParts.size()]))); iconsSpannable = new SpannableString(""); diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/AdvancedSettingsController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/AdvancedSettingsController.java index 98b930e0..23ca274c 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/AdvancedSettingsController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/AdvancedSettingsController.java @@ -48,6 +48,7 @@ public class AdvancedSettingsController extends SettingsController { private SettingView forcePhoneLayoutSetting; private SettingView postFullDate; private SettingView postFileInfo; + private SettingView postFilename; private SettingView anonymize; private SettingView anonymizeIds; private SettingView tapNoReply; @@ -87,7 +88,7 @@ public class AdvancedSettingsController extends SettingsController { needRestart = true; } - if (item == postFullDate || item == postFileInfo || item == anonymize || item == anonymizeIds || item == tapNoReply) { + if (item == postFullDate || item == postFileInfo || item == anonymize || item == anonymizeIds || item == tapNoReply || item == postFilename) { EventBus.getDefault().post(new RefreshUIMessage("postui")); } } @@ -129,6 +130,7 @@ public class AdvancedSettingsController extends SettingsController { settings.add(new BooleanSettingView(this, ChanSettings.volumeKeysScrolling, string(R.string.setting_volume_key_scrolling), null)); postFullDate = settings.add(new BooleanSettingView(this, ChanSettings.postFullDate, string(R.string.setting_post_full_date), null)); postFileInfo = settings.add(new BooleanSettingView(this, ChanSettings.postFileInfo, string(R.string.setting_post_file_info), null)); + postFilename = settings.add(new BooleanSettingView(this, ChanSettings.postFilename, string(R.string.setting_post_filename), null)); groups.add(settings); diff --git a/Clover/app/src/main/res/values/strings.xml b/Clover/app/src/main/res/values/strings.xml index 5a59889e..b71d13b1 100644 --- a/Clover/app/src/main/res/values/strings.xml +++ b/Clover/app/src/main/res/values/strings.xml @@ -346,6 +346,7 @@ along with this program. If not, see . Volume keys scroll content Show the full date on posts Show file info on posts + Show filename on posts HTTP Proxy Enable proxy