From 21e8f388251c36dbd06cf3b732e26f3d3805fa0e Mon Sep 17 00:00:00 2001 From: Adamantcheese Date: Wed, 17 Apr 2019 19:20:24 -0700 Subject: [PATCH 1/2] Add thread folders --- .../chan/core/settings/ChanSettings.java | 2 ++ .../ui/controller/ImageViewerController.java | 21 +++++++++++++--- .../controller/MediaSettingsController.java | 25 ++++++++++++++++++- Clover/app/src/main/res/values/strings.xml | 6 +++-- 4 files changed, 48 insertions(+), 6 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 cb1624c079..c33294d468 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 @@ -133,6 +133,7 @@ public String getKey() { public static final BooleanSetting neverHideToolbar; public static final BooleanSetting controllerSwipeable; public static final BooleanSetting saveBoardFolder; + public static final BooleanSetting saveThreadFolder; public static final BooleanSetting videoDefaultMuted; public static final BooleanSetting videoAutoLoop; @@ -214,6 +215,7 @@ public String getKey() { neverHideToolbar = new BooleanSetting(p, "preference_never_hide_toolbar", false); controllerSwipeable = new BooleanSetting(p, "preference_controller_swipeable", true); saveBoardFolder = new BooleanSetting(p, "preference_save_subboard", false); + saveThreadFolder = new BooleanSetting(p, "preference_save_subthread", false); videoDefaultMuted = new BooleanSetting(p, "preference_video_default_muted", true); videoAutoLoop = new BooleanSetting(p, "preference_video_loop", true); diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/ImageViewerController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/ImageViewerController.java index a4f3a7e15b..800a012fd4 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/ImageViewerController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/ImageViewerController.java @@ -222,9 +222,24 @@ private void saveShare(boolean share, PostImage postImage) { ImageSaveTask task = new ImageSaveTask(postImage); task.setShare(share); if (ChanSettings.saveBoardFolder.get()) { - task.setSubFolder(presenter.getLoadable().site.name() + - File.separator + - presenter.getLoadable().boardCode); + String subFolderName = + presenter.getLoadable().site.name() + + File.separator + + presenter.getLoadable().boardCode; + if (ChanSettings.saveThreadFolder.get()) { + //save to op no appended with the first 50 characters of the subject + //should be unique and perfectly understandable title wise + subFolderName = subFolderName + + File.separator + + presenter.getLoadable().no + + "_" + + presenter.getLoadable().title + .toLowerCase() + .replaceAll(" ", "_") + .replaceAll("[^a-z0-9_]", "") + .substring(0, 50); + } + task.setSubFolder(subFolderName); } ImageSaver.getInstance().startDownloadTask(context, task); } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/MediaSettingsController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/MediaSettingsController.java index ea561c4d8f..4547d26a81 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/MediaSettingsController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/MediaSettingsController.java @@ -37,6 +37,8 @@ public class MediaSettingsController extends SettingsController { // Special setting views + private BooleanSettingView boardFolderSetting; + private BooleanSettingView threadFolderSetting; private LinkSettingView saveLocation; private ListSettingView imageAutoLoadView; private ListSettingView videoAutoLoadView; @@ -60,6 +62,8 @@ public void onCreate() { buildPreferences(); onPreferenceChange(imageAutoLoadView); + + threadFolderSetting.setEnabled(ChanSettings.saveBoardFolder.get()); } @Override @@ -75,6 +79,8 @@ public void onPreferenceChange(SettingView item) { if (item == imageAutoLoadView) { updateVideoLoadModes(); + } else if (item == boardFolderSetting) { + updateThreadFolderSetting(); } } @@ -91,11 +97,16 @@ private void populatePreferences() { setupSaveLocationSetting(media); - media.add(new BooleanSettingView(this, + boardFolderSetting = (BooleanSettingView) media.add(new BooleanSettingView(this, ChanSettings.saveBoardFolder, R.string.setting_save_board_folder, R.string.setting_save_board_folder_description)); + threadFolderSetting = (BooleanSettingView) media.add(new BooleanSettingView(this, + ChanSettings.saveThreadFolder, + R.string.setting_save_thread_folder, + R.string.setting_save_thread_folder_description)); + media.add(new BooleanSettingView(this, ChanSettings.saveOriginalFilename, R.string.setting_save_original_filename, @@ -206,4 +217,16 @@ private void setupSaveLocationSetting(SettingsGroup media) { private void updateSaveLocationSetting() { saveLocation.setDescription(ChanSettings.saveLocation.get()); } + + private void updateThreadFolderSetting() { + if (ChanSettings.saveBoardFolder.get()) { + threadFolderSetting.setEnabled(true); + } else if (!ChanSettings.saveBoardFolder.get()) { + if (ChanSettings.saveThreadFolder.get()) { + threadFolderSetting.onClick(threadFolderSetting.view); + } + threadFolderSetting.setEnabled(false); + ChanSettings.saveThreadFolder.set(false); + } + } } diff --git a/Clover/app/src/main/res/values/strings.xml b/Clover/app/src/main/res/values/strings.xml index 71002459aa..cc1eb8ff42 100644 --- a/Clover/app/src/main/res/values/strings.xml +++ b/Clover/app/src/main/res/values/strings.xml @@ -500,8 +500,10 @@ Crash reports do not collect any personally identifiable information." Media - Save images in a board folder - Create a folder for each board to store images in + Save images in board folders + Create a folder for each board when saving + Save images in thread folders + Create a folder for each thread when saving Save original filename "Save the image with the filename the site assigned. From 8a55c67327a69f110d76fbd011415ee331add78f Mon Sep 17 00:00:00 2001 From: Adamantcheese Date: Wed, 17 Apr 2019 23:07:26 -0700 Subject: [PATCH 2/2] Fix crash when saving with thread folders --- .../floens/chan/ui/controller/ImageViewerController.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/ImageViewerController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/ImageViewerController.java index 800a012fd4..fe8ad47b14 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/ImageViewerController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/ImageViewerController.java @@ -232,12 +232,13 @@ private void saveShare(boolean share, PostImage postImage) { subFolderName = subFolderName + File.separator + presenter.getLoadable().no + - "_" + - presenter.getLoadable().title + "_"; + String tempTitle = presenter.getLoadable().title .toLowerCase() .replaceAll(" ", "_") - .replaceAll("[^a-z0-9_]", "") - .substring(0, 50); + .replaceAll("[^a-z0-9_]", ""); + tempTitle = tempTitle.substring(0, Math.min(tempTitle.length(), 50)); + subFolderName = subFolderName + tempTitle; } task.setSubFolder(subFolderName); }