Skip to content

Commit

Permalink
Resolves #683
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamantcheese committed Aug 3, 2019
1 parent 31873ce commit 0bdddef
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.floens.chan.BuildConfig;
import org.floens.chan.R;
import org.floens.chan.core.manager.WatchManager;
import org.floens.chan.core.model.orm.Board;
import org.floens.chan.core.update.UpdateManager;
import org.floens.chan.ui.adapter.PostsFilter;
import org.floens.chan.utils.AndroidUtils;
Expand Down Expand Up @@ -134,6 +135,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;

Expand Down Expand Up @@ -217,6 +219,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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,25 @@ 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 +
"_";
String tempTitle = presenter.getLoadable().title
.toLowerCase()
.replaceAll(" ", "_")
.replaceAll("[^a-z0-9_]", "");
tempTitle = tempTitle.substring(0, Math.min(tempTitle.length(), 50));
subFolderName = subFolderName + tempTitle;
}
task.setSubFolder(subFolderName);
}
ImageSaver.getInstance().startDownloadTask(context, task);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

public class MediaSettingsController extends SettingsController {
// Special setting views
private BooleanSettingView boardFolderSetting;
private BooleanSettingView threadFolderSetting;
private LinkSettingView saveLocation;
private ListSettingView<ChanSettings.MediaAutoLoadMode> imageAutoLoadView;
private ListSettingView<ChanSettings.MediaAutoLoadMode> videoAutoLoadView;
Expand All @@ -60,6 +62,8 @@ public void onCreate() {
buildPreferences();

onPreferenceChange(imageAutoLoadView);

threadFolderSetting.setEnabled(ChanSettings.saveBoardFolder.get());
}

@Override
Expand All @@ -75,6 +79,8 @@ public void onPreferenceChange(SettingView item) {

if (item == imageAutoLoadView) {
updateVideoLoadModes();
} else if (item == boardFolderSetting) {
updateThreadFolderSetting();
}
}

Expand All @@ -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,
Expand Down Expand Up @@ -132,9 +143,9 @@ private void populatePreferences() {
setupMediaLoadTypesSetting(loading);

loading.add(new BooleanSettingView(this,
ChanSettings.videoAutoLoop,
R.string.setting_video_auto_loop,
R.string.setting_video_auto_loop_description));
ChanSettings.videoAutoLoop,
R.string.setting_video_auto_loop,
R.string.setting_video_auto_loop_description));

groups.add(loading);
}
Expand Down Expand Up @@ -203,6 +214,18 @@ private void setupSaveLocationSetting(SettingsGroup media) {
updateSaveLocationSetting();
}

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);
}
}

private void updateSaveLocationSetting() {
saveLocation.setDescription(ChanSettings.saveLocation.get());
}
Expand Down
6 changes: 4 additions & 2 deletions Clover/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,10 @@ Crash reports do not collect any personally identifiable information."
<!-- Media general group -->
<string name="settings_group_media">Media</string>

<string name="setting_save_board_folder">Save images in a board folder</string>
<string name="setting_save_board_folder_description">Create a folder for each board to store images in</string>
<string name="setting_save_board_folder">Save images in board folders</string>
<string name="setting_save_board_folder_description">Create a folder for each board when saving</string>
<string name="setting_save_thread_folder">Save images in thread folders</string>
<string name="setting_save_thread_folder_description">Create a folder for each thread when saving</string>
<string name="setting_save_original_filename">Save original filename</string>
<string name="setting_save_original_filename_description">
"Save the image with the filename the site assigned.
Expand Down

0 comments on commit 0bdddef

Please sign in to comment.