mirror of https://github.com/kurisufriend/Clover
organized all settings we have into different sections. the advanced settings screen is not gone. the strings have also been organized. removed the https setting (it was already always https since the site reorganisation).refactor-toolbar
parent
0876aed5fc
commit
145a9099a9
@ -0,0 +1,61 @@ |
||||
/* |
||||
* 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.core.presenter; |
||||
|
||||
import org.floens.chan.core.database.DatabaseManager; |
||||
import org.floens.chan.core.settings.ChanSettings; |
||||
|
||||
import javax.inject.Inject; |
||||
|
||||
public class SettingsPresenter { |
||||
private Callback callback; |
||||
|
||||
private DatabaseManager databaseManager; |
||||
|
||||
@Inject |
||||
public SettingsPresenter(DatabaseManager databaseManager) { |
||||
this.databaseManager = databaseManager; |
||||
} |
||||
|
||||
public void create(Callback callback) { |
||||
this.callback = callback; |
||||
} |
||||
|
||||
public void destroy() { |
||||
|
||||
} |
||||
|
||||
public void show() { |
||||
long siteCount = databaseManager.runTask( |
||||
databaseManager.getDatabaseSiteManager().getCount()); |
||||
long filterCount = databaseManager.runTask( |
||||
databaseManager.getDatabaseFilterManager().getCount()); |
||||
|
||||
callback.setSiteCount((int) siteCount); |
||||
callback.setFiltersCount((int) filterCount); |
||||
callback.setWatchEnabled(ChanSettings.watchEnabled.get()); |
||||
} |
||||
|
||||
public interface Callback { |
||||
void setSiteCount(int count); |
||||
|
||||
void setFiltersCount(int count); |
||||
|
||||
void setWatchEnabled(boolean enabled); |
||||
} |
||||
} |
@ -1,116 +0,0 @@ |
||||
/* |
||||
* 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.controller; |
||||
|
||||
import android.content.Context; |
||||
import android.widget.LinearLayout; |
||||
|
||||
import org.floens.chan.R; |
||||
import org.floens.chan.core.settings.ChanSettings; |
||||
import org.floens.chan.ui.activity.StartActivity; |
||||
import org.floens.chan.ui.helper.RefreshUIMessage; |
||||
import org.floens.chan.ui.settings.BooleanSettingView; |
||||
import org.floens.chan.ui.settings.IntegerSettingView; |
||||
import org.floens.chan.ui.settings.SettingView; |
||||
import org.floens.chan.ui.settings.SettingsController; |
||||
import org.floens.chan.ui.settings.SettingsGroup; |
||||
import org.floens.chan.ui.settings.StringSettingView; |
||||
|
||||
import de.greenrobot.event.EventBus; |
||||
|
||||
public class AdvancedSettingsController extends SettingsController { |
||||
private static final String TAG = "AdvancedSettingsController"; |
||||
|
||||
private boolean needRestart; |
||||
private SettingView newCaptcha; |
||||
private SettingView enableReplyFab; |
||||
private SettingView neverHideToolbar; |
||||
private SettingView controllersSwipeable; |
||||
|
||||
public AdvancedSettingsController(Context context) { |
||||
super(context); |
||||
} |
||||
|
||||
@Override |
||||
public void onCreate() { |
||||
super.onCreate(); |
||||
|
||||
navigation.setTitle(R.string.settings_screen_advanced); |
||||
|
||||
view = inflateRes(R.layout.settings_layout); |
||||
content = view.findViewById(R.id.scrollview_content); |
||||
|
||||
populatePreferences(); |
||||
|
||||
buildPreferences(); |
||||
|
||||
ChanSettings.settingsOpenCounter.set(5); |
||||
} |
||||
|
||||
@Override |
||||
public void onDestroy() { |
||||
super.onDestroy(); |
||||
|
||||
if (needRestart) { |
||||
((StartActivity) context).restart(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onPreferenceChange(SettingView item) { |
||||
super.onPreferenceChange(item); |
||||
|
||||
if (item == enableReplyFab || item == newCaptcha || item == neverHideToolbar || item == controllersSwipeable) { |
||||
needRestart = true; |
||||
} else { |
||||
EventBus.getDefault().post(new RefreshUIMessage("postui")); |
||||
} |
||||
} |
||||
|
||||
private void populatePreferences() { |
||||
SettingsGroup settings = new SettingsGroup(R.string.settings_group_advanced); |
||||
|
||||
newCaptcha = settings.add(new BooleanSettingView(this, ChanSettings.postNewCaptcha, R.string.setting_use_new_captcha, R.string.setting_use_new_captcha_description)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.saveOriginalFilename, R.string.setting_save_original_filename, 0)); |
||||
controllersSwipeable = settings.add(new BooleanSettingView(this, ChanSettings.controllerSwipeable, R.string.setting_controller_swipeable, 0)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.shareUrl, R.string.setting_share_url, R.string.setting_share_url_description)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.networkHttps, R.string.setting_network_https, R.string.setting_network_https_description)); |
||||
enableReplyFab = settings.add(new BooleanSettingView(this, ChanSettings.enableReplyFab, R.string.setting_enable_reply_fab, R.string.setting_enable_reply_fab_description)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.anonymize, R.string.setting_anonymize, 0)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.anonymizeIds, R.string.setting_anonymize_ids, 0)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.showAnonymousName, R.string.setting_show_anonymous_name, 0)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.revealImageSpoilers, R.string.settings_reveal_image_spoilers, 0)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.revealTextSpoilers, R.string.settings_reveal_text_spoilers, R.string.settings_reveal_text_spoilers_description)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.repliesButtonsBottom, R.string.setting_buttons_bottom, 0)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.confirmExit, R.string.setting_confirm_exit, 0)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.tapNoReply, R.string.setting_tap_no_rely, 0)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.volumeKeysScrolling, R.string.setting_volume_key_scrolling, 0)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.postFullDate, R.string.setting_post_full_date, 0)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.postFileInfo, R.string.setting_post_file_info, 0)); |
||||
settings.add(new BooleanSettingView(this, ChanSettings.postFilename, R.string.setting_post_filename, 0)); |
||||
neverHideToolbar = settings.add(new BooleanSettingView(this, ChanSettings.neverHideToolbar, R.string.setting_never_hide_toolbar, 0)); |
||||
|
||||
groups.add(settings); |
||||
|
||||
SettingsGroup proxy = new SettingsGroup(R.string.settings_group_proxy); |
||||
proxy.add(new BooleanSettingView(this, ChanSettings.proxyEnabled, R.string.setting_proxy_enabled, 0)); |
||||
proxy.add(new StringSettingView(this, ChanSettings.proxyAddress, R.string.setting_proxy_address, R.string.setting_proxy_address)); |
||||
proxy.add(new IntegerSettingView(this, ChanSettings.proxyPort, R.string.setting_proxy_port, R.string.setting_proxy_port)); |
||||
groups.add(proxy); |
||||
} |
||||
} |
@ -0,0 +1,169 @@ |
||||
/* |
||||
* 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.controller; |
||||
|
||||
import android.content.Context; |
||||
|
||||
import org.floens.chan.R; |
||||
import org.floens.chan.core.settings.ChanSettings; |
||||
import org.floens.chan.ui.settings.BooleanSettingView; |
||||
import org.floens.chan.ui.settings.LinkSettingView; |
||||
import org.floens.chan.ui.settings.ListSettingView; |
||||
import org.floens.chan.ui.settings.SettingsController; |
||||
import org.floens.chan.ui.settings.SettingsGroup; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import static org.floens.chan.ui.theme.ThemeHelper.theme; |
||||
import static org.floens.chan.utils.AndroidUtils.getString; |
||||
|
||||
public class AppearanceSettingsController extends SettingsController { |
||||
public AppearanceSettingsController(Context context) { |
||||
super(context); |
||||
} |
||||
|
||||
@Override |
||||
public void onCreate() { |
||||
super.onCreate(); |
||||
|
||||
navigation.setTitle(R.string.settings_screen_appearance); |
||||
|
||||
setupLayout(); |
||||
|
||||
populatePreferences(); |
||||
|
||||
buildPreferences(); |
||||
} |
||||
|
||||
private void populatePreferences() { |
||||
// Appearance group
|
||||
{ |
||||
SettingsGroup appearance = new SettingsGroup(R.string.settings_group_appearance); |
||||
|
||||
appearance.add(new LinkSettingView(this, |
||||
getString(R.string.setting_theme), theme().displayName, |
||||
v -> navigationController.pushController( |
||||
new ThemeSettingsController(context)))); |
||||
|
||||
groups.add(appearance); |
||||
} |
||||
|
||||
// Layout group
|
||||
{ |
||||
SettingsGroup layout = new SettingsGroup(R.string.settings_group_layout); |
||||
|
||||
setupLayoutModeSetting(layout); |
||||
|
||||
setupGridColumnsSetting(layout); |
||||
|
||||
requiresRestart.add(layout.add(new BooleanSettingView(this, |
||||
ChanSettings.neverHideToolbar, |
||||
R.string.setting_never_hide_toolbar, 0))); |
||||
|
||||
requiresRestart.add(layout.add(new BooleanSettingView(this, |
||||
ChanSettings.enableReplyFab, |
||||
R.string.setting_enable_reply_fab, |
||||
R.string.setting_enable_reply_fab_description))); |
||||
|
||||
groups.add(layout); |
||||
} |
||||
|
||||
// Post group
|
||||
{ |
||||
SettingsGroup post = new SettingsGroup(R.string.settings_group_post); |
||||
|
||||
setupFontSizeSetting(post); |
||||
|
||||
requiresUiRefresh.add(post.add(new BooleanSettingView(this, |
||||
ChanSettings.fontCondensed, |
||||
R.string.setting_font_condensed, |
||||
R.string.setting_font_condensed_description))); |
||||
|
||||
requiresUiRefresh.add(post.add(new BooleanSettingView(this, |
||||
ChanSettings.postFullDate, |
||||
R.string.setting_post_full_date, 0))); |
||||
|
||||
requiresUiRefresh.add(post.add(new BooleanSettingView(this, |
||||
ChanSettings.postFileInfo, |
||||
R.string.setting_post_file_info, 0))); |
||||
|
||||
requiresUiRefresh.add(post.add(new BooleanSettingView(this, |
||||
ChanSettings.postFilename, |
||||
R.string.setting_post_filename, 0))); |
||||
|
||||
groups.add(post); |
||||
} |
||||
} |
||||
|
||||
private void setupLayoutModeSetting(SettingsGroup layout) { |
||||
List<ListSettingView.Item> layoutModes = new ArrayList<>(); |
||||
for (ChanSettings.LayoutMode mode : ChanSettings.LayoutMode.values()) { |
||||
int name = 0; |
||||
switch (mode) { |
||||
case AUTO: |
||||
name = R.string.setting_layout_mode_auto; |
||||
break; |
||||
case PHONE: |
||||
name = R.string.setting_layout_mode_phone; |
||||
break; |
||||
case SLIDE: |
||||
name = R.string.setting_layout_mode_slide; |
||||
break; |
||||
case SPLIT: |
||||
name = R.string.setting_layout_mode_split; |
||||
break; |
||||
} |
||||
layoutModes.add(new ListSettingView.Item<>(getString(name), mode)); |
||||
} |
||||
|
||||
requiresRestart.add(layout.add(new ListSettingView<>(this, |
||||
ChanSettings.layoutMode, |
||||
R.string.setting_layout_mode, layoutModes))); |
||||
} |
||||
|
||||
private void setupGridColumnsSetting(SettingsGroup layout) { |
||||
List<ListSettingView.Item> gridColumns = new ArrayList<>(); |
||||
gridColumns.add(new ListSettingView.Item<>( |
||||
getString(R.string.setting_board_grid_span_count_default), 0)); |
||||
for (int columns = 2; columns <= 5; columns++) { |
||||
gridColumns.add(new ListSettingView.Item<>( |
||||
context.getString(R.string.setting_board_grid_span_count_item, columns), |
||||
columns)); |
||||
} |
||||
requiresUiRefresh.add(layout.add(new ListSettingView<>(this, |
||||
ChanSettings.boardGridSpanCount, |
||||
R.string.setting_board_grid_span_count, gridColumns))); |
||||
} |
||||
|
||||
private void setupFontSizeSetting(SettingsGroup post) { |
||||
List<ListSettingView.Item> fontSizes = new ArrayList<>(); |
||||
for (int size = 10; size <= 19; size++) { |
||||
String name = size + (String.valueOf(size) |
||||
.equals(ChanSettings.fontSize.getDefault()) ? |
||||
" " + getString(R.string.setting_font_size_default) : |
||||
""); |
||||
fontSizes.add(new ListSettingView.Item<>(name, String.valueOf(size))); |
||||
} |
||||
|
||||
requiresUiRefresh.add(post.add(new ListSettingView<>(this, |
||||
ChanSettings.fontSize, |
||||
R.string.setting_font_size, |
||||
fontSizes.toArray(new ListSettingView.Item[fontSizes.size()])))); |
||||
} |
||||
} |
@ -0,0 +1,170 @@ |
||||
/* |
||||
* 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.controller; |
||||
|
||||
import android.content.Context; |
||||
import android.view.View; |
||||
import android.widget.Toast; |
||||
|
||||
import org.floens.chan.R; |
||||
import org.floens.chan.core.database.DatabaseManager; |
||||
import org.floens.chan.core.settings.ChanSettings; |
||||
import org.floens.chan.ui.helper.RefreshUIMessage; |
||||
import org.floens.chan.ui.settings.BooleanSettingView; |
||||
import org.floens.chan.ui.settings.IntegerSettingView; |
||||
import org.floens.chan.ui.settings.LinkSettingView; |
||||
import org.floens.chan.ui.settings.SettingsController; |
||||
import org.floens.chan.ui.settings.SettingsGroup; |
||||
import org.floens.chan.ui.settings.StringSettingView; |
||||
|
||||
import de.greenrobot.event.EventBus; |
||||
|
||||
import static org.floens.chan.Chan.injector; |
||||
|
||||
public class BehaviourSettingsController extends SettingsController { |
||||
public BehaviourSettingsController(Context context) { |
||||
super(context); |
||||
} |
||||
|
||||
@Override |
||||
public void onCreate() { |
||||
super.onCreate(); |
||||
|
||||
navigation.setTitle(R.string.settings_screen_behaviour); |
||||
|
||||
setupLayout(); |
||||
|
||||
populatePreferences(); |
||||
|
||||
buildPreferences(); |
||||
} |
||||
|
||||
private void populatePreferences() { |
||||
// General group
|
||||
{ |
||||
SettingsGroup general = new SettingsGroup(R.string.settings_group_general); |
||||
|
||||
general.add(new BooleanSettingView(this, |
||||
ChanSettings.autoRefreshThread, |
||||
R.string.setting_auto_refresh_thread, 0)); |
||||
|
||||
general.add(new BooleanSettingView(this, ChanSettings.confirmExit, |
||||
R.string.setting_confirm_exit, 0)); |
||||
|
||||
requiresRestart.add(general.add(new BooleanSettingView(this, |
||||
ChanSettings.controllerSwipeable, |
||||
R.string.setting_controller_swipeable, 0))); |
||||
|
||||
setupClearThreadHidesSetting(general); |
||||
|
||||
groups.add(general); |
||||
} |
||||
|
||||
// Reply group
|
||||
{ |
||||
SettingsGroup reply = new SettingsGroup(R.string.settings_group_reply); |
||||
|
||||
reply.add(new BooleanSettingView(this, |
||||
ChanSettings.postNewCaptcha, |
||||
R.string.setting_use_new_captcha, |
||||
R.string.setting_use_new_captcha_description)); |
||||
|
||||
reply.add(new BooleanSettingView(this, ChanSettings.postPinThread, |
||||
R.string.setting_post_pin, 0)); |
||||
|
||||
reply.add(new StringSettingView(this, ChanSettings.postDefaultName, |
||||
R.string.setting_post_default_name, R.string.setting_post_default_name)); |
||||
|
||||
groups.add(reply); |
||||
} |
||||
|
||||
// Post group
|
||||
{ |
||||
SettingsGroup post = new SettingsGroup(R.string.settings_group_post); |
||||
|
||||
requiresUiRefresh.add(post.add(new BooleanSettingView(this, |
||||
ChanSettings.textOnly, |
||||
R.string.setting_text_only, R.string.setting_text_only_description))); |
||||
|
||||
requiresUiRefresh.add(post.add(new BooleanSettingView(this, |
||||
ChanSettings.revealTextSpoilers, |
||||
R.string.settings_reveal_text_spoilers, |
||||
R.string.settings_reveal_text_spoilers_description))); |
||||
|
||||
requiresUiRefresh.add(post.add(new BooleanSettingView(this, |
||||
ChanSettings.anonymize, |
||||
R.string.setting_anonymize, 0))); |
||||
|
||||
requiresUiRefresh.add(post.add(new BooleanSettingView(this, |
||||
ChanSettings.anonymizeIds, |
||||
R.string.setting_anonymize_ids, 0))); |
||||
|
||||
requiresUiRefresh.add(post.add(new BooleanSettingView(this, |
||||
ChanSettings.showAnonymousName, |
||||
R.string.setting_show_anonymous_name, 0))); |
||||
|
||||
post.add(new BooleanSettingView(this, |
||||
ChanSettings.repliesButtonsBottom, |
||||
R.string.setting_buttons_bottom, 0)); |
||||
|
||||
post.add(new BooleanSettingView(this, |
||||
ChanSettings.volumeKeysScrolling, |
||||
R.string.setting_volume_key_scrolling, 0)); |
||||
|
||||
post.add(new BooleanSettingView(this, |
||||
ChanSettings.tapNoReply, |
||||
R.string.setting_tap_no_rely, 0)); |
||||
|
||||
post.add(new BooleanSettingView(this, |
||||
ChanSettings.openLinkConfirmation, |
||||
R.string.setting_open_link_confirmation, 0)); |
||||
|
||||
groups.add(post); |
||||
} |
||||
|
||||
// Proxy group
|
||||
{ |
||||
SettingsGroup proxy = new SettingsGroup(R.string.settings_group_proxy); |
||||
|
||||
proxy.add(new BooleanSettingView(this, ChanSettings.proxyEnabled, |
||||
R.string.setting_proxy_enabled, 0)); |
||||
|
||||
proxy.add(new StringSettingView(this, ChanSettings.proxyAddress, |
||||
R.string.setting_proxy_address, R.string.setting_proxy_address)); |
||||
|
||||
proxy.add(new IntegerSettingView(this, ChanSettings.proxyPort, |
||||
R.string.setting_proxy_port, R.string.setting_proxy_port)); |
||||
|
||||
groups.add(proxy); |
||||
} |
||||
} |
||||
|
||||
private void setupClearThreadHidesSetting(SettingsGroup post) { |
||||
post.add(new LinkSettingView(this, R.string.setting_clear_thread_hides, 0, new View.OnClickListener() { |
||||
@Override |
||||
public void onClick(View v) { |
||||
// TODO: don't do this here.
|
||||
DatabaseManager databaseManager = injector().instance(DatabaseManager.class); |
||||
databaseManager.clearAllThreadHides(); |
||||
Toast.makeText(context, R.string.setting_cleared_thread_hides, Toast.LENGTH_LONG) |
||||
.show(); |
||||
EventBus.getDefault().post(new RefreshUIMessage("clearhides")); |
||||
} |
||||
})); |
||||
} |
||||
} |
@ -0,0 +1,194 @@ |
||||
/* |
||||
* 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.controller; |
||||
|
||||
import android.content.Context; |
||||
|
||||
import org.floens.chan.R; |
||||
import org.floens.chan.core.settings.ChanSettings; |
||||
import org.floens.chan.ui.settings.BooleanSettingView; |
||||
import org.floens.chan.ui.settings.LinkSettingView; |
||||
import org.floens.chan.ui.settings.ListSettingView; |
||||
import org.floens.chan.ui.settings.SettingView; |
||||
import org.floens.chan.ui.settings.SettingsController; |
||||
import org.floens.chan.ui.settings.SettingsGroup; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import de.greenrobot.event.EventBus; |
||||
|
||||
import static org.floens.chan.utils.AndroidUtils.getString; |
||||
|
||||
public class MediaSettingsController extends SettingsController { |
||||
// Special setting views
|
||||
private LinkSettingView saveLocation; |
||||
private ListSettingView<ChanSettings.MediaAutoLoadMode> imageAutoLoadView; |
||||
private ListSettingView<ChanSettings.MediaAutoLoadMode> videoAutoLoadView; |
||||
|
||||
public MediaSettingsController(Context context) { |
||||
super(context); |
||||
} |
||||
|
||||
@Override |
||||
public void onCreate() { |
||||
super.onCreate(); |
||||
|
||||
EventBus.getDefault().register(this); |
||||
|
||||
navigation.setTitle(R.string.settings_screen_media); |
||||
|
||||
setupLayout(); |
||||
|
||||
populatePreferences(); |
||||
|
||||
buildPreferences(); |
||||
|
||||
onPreferenceChange(imageAutoLoadView); |
||||
} |
||||
|
||||
@Override |
||||
public void onDestroy() { |
||||
super.onDestroy(); |
||||
|
||||
EventBus.getDefault().unregister(this); |
||||
} |
||||
|
||||
@Override |
||||
public void onPreferenceChange(SettingView item) { |
||||
super.onPreferenceChange(item); |
||||
|
||||
if (item == imageAutoLoadView) { |
||||
updateVideoLoadModes(); |
||||
} |
||||
} |
||||
|
||||
public void onEvent(ChanSettings.SettingChanged setting) { |
||||
if (setting.setting == ChanSettings.saveLocation) { |
||||
updateSaveLocationSetting(); |
||||
} |
||||
} |
||||
|
||||
private void populatePreferences() { |
||||
// Media group
|
||||
{ |
||||
SettingsGroup media = new SettingsGroup(R.string.settings_group_media); |
||||
|
||||
setupSaveLocationSetting(media); |
||||
|
||||
media.add(new BooleanSettingView(this, |
||||
ChanSettings.saveBoardFolder, |
||||
R.string.setting_save_board_folder, |
||||
R.string.setting_save_board_folder_description)); |
||||
|
||||
media.add(new BooleanSettingView(this, |
||||
ChanSettings.saveOriginalFilename, |
||||
R.string.setting_save_original_filename, 0)); |
||||
|
||||
media.add(new BooleanSettingView(this, ChanSettings.videoOpenExternal, |
||||
R.string.setting_video_open_external, |
||||
R.string.setting_video_open_external_description)); |
||||
|
||||
media.add(new BooleanSettingView(this, |
||||
ChanSettings.shareUrl, |
||||
R.string.setting_share_url, R.string.setting_share_url_description)); |
||||
|
||||
media.add(new BooleanSettingView(this, |
||||
ChanSettings.revealImageSpoilers, |
||||
R.string.settings_reveal_image_spoilers, 0)); |
||||
|
||||
groups.add(media); |
||||
} |
||||
|
||||
// Loading group
|
||||
{ |
||||
SettingsGroup loading = new SettingsGroup(R.string.settings_group_media_loading); |
||||
|
||||
setupMediaLoadTypesSetting(loading); |
||||
|
||||
groups.add(loading); |
||||
} |
||||
} |
||||
|
||||
private void setupMediaLoadTypesSetting(SettingsGroup loading) { |
||||
List<ListSettingView.Item> imageAutoLoadTypes = new ArrayList<>(); |
||||
List<ListSettingView.Item> videoAutoLoadTypes = new ArrayList<>(); |
||||
for (ChanSettings.MediaAutoLoadMode mode : ChanSettings.MediaAutoLoadMode.values()) { |
||||
int name = 0; |
||||
switch (mode) { |
||||
case ALL: |
||||
name = R.string.setting_image_auto_load_all; |
||||
break; |
||||
case WIFI: |
||||
name = R.string.setting_image_auto_load_wifi; |
||||
break; |
||||
case NONE: |
||||
name = R.string.setting_image_auto_load_none; |
||||
break; |
||||
} |
||||
|
||||
imageAutoLoadTypes.add(new ListSettingView.Item<>(getString(name), mode)); |
||||
videoAutoLoadTypes.add(new ListSettingView.Item<>(getString(name), mode)); |
||||
} |
||||
|
||||
imageAutoLoadView = new ListSettingView<>(this, |
||||
ChanSettings.imageAutoLoadNetwork, R.string.setting_image_auto_load, |
||||
imageAutoLoadTypes); |
||||
loading.add(imageAutoLoadView); |
||||
|
||||
videoAutoLoadView = new ListSettingView<>(this, |
||||
ChanSettings.videoAutoLoadNetwork, R.string.setting_video_auto_load, |
||||
videoAutoLoadTypes); |
||||
loading.add(videoAutoLoadView); |
||||
|
||||
updateVideoLoadModes(); |
||||
} |
||||
|
||||
private void updateVideoLoadModes() { |
||||
ChanSettings.MediaAutoLoadMode currentImageLoadMode = ChanSettings.imageAutoLoadNetwork.get(); |
||||
ChanSettings.MediaAutoLoadMode[] modes = ChanSettings.MediaAutoLoadMode.values(); |
||||
boolean enabled = false; |
||||
boolean resetVideoMode = false; |
||||
for (int i = 0; i < modes.length; i++) { |
||||
if (modes[i].getName().equals(currentImageLoadMode.getName())) { |
||||
enabled = true; |
||||
if (resetVideoMode) { |
||||
ChanSettings.videoAutoLoadNetwork.set(modes[i]); |
||||
videoAutoLoadView.updateSelection(); |
||||
onPreferenceChange(videoAutoLoadView); |
||||
} |
||||
} |
||||
videoAutoLoadView.items.get(i).enabled = enabled; |
||||
if (!enabled && ChanSettings.videoAutoLoadNetwork.get().getName() |
||||
.equals(modes[i].getName())) { |
||||
resetVideoMode = true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void setupSaveLocationSetting(SettingsGroup media) { |
||||
saveLocation = (LinkSettingView) media.add(new LinkSettingView(this, |
||||
R.string.save_location_screen, 0, |
||||
v -> navigationController.pushController(new SaveLocationController(context)))); |
||||
updateSaveLocationSetting(); |
||||
} |
||||
|
||||
private void updateSaveLocationSetting() { |
||||
saveLocation.setDescription(ChanSettings.saveLocation.get()); |
||||
} |
||||
} |
Loading…
Reference in new issue