reorganize settings

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
Floens 8 years ago
parent 0876aed5fc
commit 145a9099a9
  1. 4
      Clover/app/src/main/java/org/floens/chan/core/database/DatabaseFilterManager.java
  2. 4
      Clover/app/src/main/java/org/floens/chan/core/database/DatabaseSiteManager.java
  3. 61
      Clover/app/src/main/java/org/floens/chan/core/presenter/SettingsPresenter.java
  4. 6
      Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java
  5. 2
      Clover/app/src/main/java/org/floens/chan/ui/activity/StartActivity.java
  6. 116
      Clover/app/src/main/java/org/floens/chan/ui/controller/AdvancedSettingsController.java
  7. 169
      Clover/app/src/main/java/org/floens/chan/ui/controller/AppearanceSettingsController.java
  8. 170
      Clover/app/src/main/java/org/floens/chan/ui/controller/BehaviourSettingsController.java
  9. 409
      Clover/app/src/main/java/org/floens/chan/ui/controller/MainSettingsController.java
  10. 194
      Clover/app/src/main/java/org/floens/chan/ui/controller/MediaSettingsController.java
  11. 2
      Clover/app/src/main/java/org/floens/chan/ui/controller/SiteSetupController.java
  12. 8
      Clover/app/src/main/java/org/floens/chan/ui/controller/WatchSettingsController.java
  13. 34
      Clover/app/src/main/java/org/floens/chan/ui/settings/SettingsController.java
  14. 252
      Clover/app/src/main/res/values/strings.xml

@ -71,4 +71,8 @@ public class DatabaseFilterManager {
} }
}; };
} }
public Callable<Long> getCount() {
return () -> helper.filterDao.countOf();
}
} }

@ -41,6 +41,10 @@ public class DatabaseSiteManager {
}; };
} }
public Callable<Long> getCount() {
return () -> helper.siteDao.countOf();
}
public Callable<SiteModel> add(final SiteModel site) { public Callable<SiteModel> add(final SiteModel site) {
return new Callable<SiteModel>() { return new Callable<SiteModel>() {
@Override @Override

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

@ -115,7 +115,6 @@ public class ChanSettings {
public static final StringSetting saveLocation; public static final StringSetting saveLocation;
public static final BooleanSetting saveOriginalFilename; public static final BooleanSetting saveOriginalFilename;
public static final BooleanSetting shareUrl; public static final BooleanSetting shareUrl;
public static final BooleanSetting networkHttps;
public static final BooleanSetting enableReplyFab; public static final BooleanSetting enableReplyFab;
public static final BooleanSetting anonymize; public static final BooleanSetting anonymize;
public static final BooleanSetting anonymizeIds; public static final BooleanSetting anonymizeIds;
@ -150,7 +149,6 @@ public class ChanSettings {
public static final StringSetting proxyAddress; public static final StringSetting proxyAddress;
public static final IntegerSetting proxyPort; public static final IntegerSetting proxyPort;
public static final CounterSetting settingsOpenCounter;
public static final CounterSetting historyOpenCounter; public static final CounterSetting historyOpenCounter;
public static final CounterSetting replyOpenCounter; public static final CounterSetting replyOpenCounter;
public static final CounterSetting threadOpenCounter; public static final CounterSetting threadOpenCounter;
@ -192,7 +190,6 @@ public class ChanSettings {
EventBus.getDefault().post(new SettingChanged<>(saveLocation))); EventBus.getDefault().post(new SettingChanged<>(saveLocation)));
saveOriginalFilename = new BooleanSetting(p, "preference_image_save_original", false); saveOriginalFilename = new BooleanSetting(p, "preference_image_save_original", false);
shareUrl = new BooleanSetting(p, "preference_image_share_url", false); shareUrl = new BooleanSetting(p, "preference_image_share_url", false);
networkHttps = new BooleanSetting(p, "preference_network_https", true);
enableReplyFab = new BooleanSetting(p, "preference_enable_reply_fab", true); enableReplyFab = new BooleanSetting(p, "preference_enable_reply_fab", true);
anonymize = new BooleanSetting(p, "preference_anonymize", false); anonymize = new BooleanSetting(p, "preference_anonymize", false);
anonymizeIds = new BooleanSetting(p, "preference_anonymize_ids", false); anonymizeIds = new BooleanSetting(p, "preference_anonymize_ids", false);
@ -236,7 +233,6 @@ public class ChanSettings {
proxyPort.addCallback((setting, value) -> loadProxy()); proxyPort.addCallback((setting, value) -> loadProxy());
loadProxy(); loadProxy();
settingsOpenCounter = new CounterSetting(p, "counter_settings_open");
historyOpenCounter = new CounterSetting(p, "counter_history_open"); historyOpenCounter = new CounterSetting(p, "counter_history_open");
replyOpenCounter = new CounterSetting(p, "counter_reply_open"); replyOpenCounter = new CounterSetting(p, "counter_reply_open");
threadOpenCounter = new CounterSetting(p, "counter_thread_open"); threadOpenCounter = new CounterSetting(p, "counter_thread_open");
@ -250,6 +246,8 @@ public class ChanSettings {
// preference_pass_enabled default false // preference_pass_enabled default false
// preference_autoplay false // preference_autoplay false
// preference_watch_background_timeout "60" the old timeout background setting in minutes // preference_watch_background_timeout "60" the old timeout background setting in minutes
// preference_network_https true
// counter_settings_open
} }
public static ThemeColor getThemeAndColor() { public static ThemeColor getThemeAndColor() {

@ -433,7 +433,7 @@ public class StartActivity extends AppCompatActivity implements NfcAdapter.Creat
if (!stackTop().onBack()) { if (!stackTop().onBack()) {
if (ChanSettings.confirmExit.get()) { if (ChanSettings.confirmExit.get()) {
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setTitle(R.string.setting_confirm_exit_title) .setTitle(R.string.action_confirm_exit_title)
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.exit, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.exit, new DialogInterface.OnClickListener() {
@Override @Override

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

@ -23,61 +23,32 @@ import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.widget.ImageView;
import android.widget.Toast; import android.widget.Toast;
import org.floens.chan.R; import org.floens.chan.R;
import org.floens.chan.core.database.DatabaseManager; import org.floens.chan.core.presenter.SettingsPresenter;
import org.floens.chan.core.settings.ChanSettings; import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.ui.activity.StartActivity; import org.floens.chan.ui.activity.StartActivity;
import org.floens.chan.ui.helper.HintPopup;
import org.floens.chan.ui.helper.RefreshUIMessage;
import org.floens.chan.ui.settings.BooleanSettingView;
import org.floens.chan.ui.settings.LinkSettingView; 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.SettingView;
import org.floens.chan.ui.settings.SettingsController; import org.floens.chan.ui.settings.SettingsController;
import org.floens.chan.ui.settings.SettingsGroup; import org.floens.chan.ui.settings.SettingsGroup;
import org.floens.chan.ui.settings.StringSettingView;
import org.floens.chan.ui.toolbar.ToolbarMenu;
import org.floens.chan.ui.toolbar.ToolbarMenuItem;
import org.floens.chan.ui.view.FloatingMenuItem;
import org.floens.chan.utils.AndroidUtils; import org.floens.chan.utils.AndroidUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import de.greenrobot.event.EventBus;
import static org.floens.chan.Chan.inject; import static org.floens.chan.Chan.inject;
import static org.floens.chan.ui.theme.ThemeHelper.theme;
import static org.floens.chan.utils.AndroidUtils.getString; import static org.floens.chan.utils.AndroidUtils.getString;
public class MainSettingsController extends SettingsController implements ToolbarMenuItem.ToolbarMenuItemCallback, WatchSettingsController.WatchSettingControllerListener { public class MainSettingsController extends SettingsController implements SettingsPresenter.Callback {
private static final int ADVANCED_SETTINGS = 1; @Inject
private ListSettingView<ChanSettings.MediaAutoLoadMode> imageAutoLoadView; private SettingsPresenter presenter;
private ListSettingView<ChanSettings.MediaAutoLoadMode> videoAutoLoadView;
private LinkSettingView saveLocation;
private LinkSettingView watchLink; private LinkSettingView watchLink;
private int clickCount; private int clickCount;
private SettingView developerView; private SettingView developerView;
private SettingView fontView; private LinkSettingView sitesSetting;
private SettingView layoutModeView; private LinkSettingView filtersSetting;
private SettingView fontCondensed;
private SettingView textOnly;
private SettingView gridColumnsView;
private ToolbarMenuItem overflow;
private ChanSettings.LayoutMode previousLayoutMode;
private HintPopup advancedSettingsHint;
@Inject
DatabaseManager databaseManager;
public MainSettingsController(Context context) { public MainSettingsController(Context context) {
super(context); super(context);
@ -88,263 +59,128 @@ public class MainSettingsController extends SettingsController implements Toolba
super.onCreate(); super.onCreate();
inject(this); inject(this);
EventBus.getDefault().register(this);
navigation.setTitle(R.string.settings_screen); navigation.setTitle(R.string.settings_screen);
navigation.menu = new ToolbarMenu(context);
overflow = navigation.createOverflow(context, this, Collections.singletonList(
new FloatingMenuItem(ADVANCED_SETTINGS, R.string.settings_screen_advanced)
));
view = inflateRes(R.layout.settings_layout); setupLayout();
content = view.findViewById(R.id.scrollview_content);
previousLayoutMode = ChanSettings.layoutMode.get();
populatePreferences(); populatePreferences();
onWatchEnabledChanged(ChanSettings.watchEnabled.get());
buildPreferences(); buildPreferences();
onPreferenceChange(imageAutoLoadView);
if (!ChanSettings.developer.get()) { if (!ChanSettings.developer.get()) {
developerView.view.setVisibility(View.GONE); developerView.view.setVisibility(View.GONE);
} }
if (ChanSettings.settingsOpenCounter.increase() == 3) { presenter.create(this);
ImageView view = overflow.getView();
view.startAnimation(android.view.animation.AnimationUtils.loadAnimation(context, R.anim.menu_overflow_shake));
advancedSettingsHint = HintPopup.show(context, view, R.string.settings_advanced_hint);
}
}
@Override
public void onHide() {
super.onHide();
if (advancedSettingsHint != null) {
advancedSettingsHint.dismiss();
advancedSettingsHint = null;
}
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
EventBus.getDefault().unregister(this); presenter.destroy();
if (previousLayoutMode != ChanSettings.layoutMode.get()) {
((StartActivity) context).restart();
}
}
public void onEvent(ChanSettings.SettingChanged setting) {
if (setting.setting == ChanSettings.saveLocation) {
setSaveLocationDescription();
}
} }
@Override @Override
public void onMenuItemClicked(ToolbarMenuItem item) { public void onShow() {
super.onShow();
presenter.show();
} }
@Override @Override
public void onSubMenuItemClicked(ToolbarMenuItem parent, FloatingMenuItem item) { public void setFiltersCount(int count) {
if (((Integer) item.getId()) == ADVANCED_SETTINGS) { String filters = context.getResources().getQuantityString(R.plurals.filter, count, count);
navigationController.pushController(new AdvancedSettingsController(context)); filtersSetting.setDescription(filters);
}
} }
@Override @Override
public void onPreferenceChange(SettingView item) { public void setSiteCount(int count) {
super.onPreferenceChange(item); String sites = context.getResources().getQuantityString(R.plurals.site, count, count);
sitesSetting.setDescription(sites);
if (item == imageAutoLoadView) {
updateVideoLoadModes();
} else if (item == fontView || item == fontCondensed) {
EventBus.getDefault().post(new RefreshUIMessage("font"));
} else if (item == gridColumnsView) {
EventBus.getDefault().post(new RefreshUIMessage("gridcolumns"));
} else if (item == textOnly) {
EventBus.getDefault().post(new RefreshUIMessage("textonly"));
}
} }
@Override @Override
public void onWatchEnabledChanged(boolean enabled) { public void setWatchEnabled(boolean enabled) {
watchLink.setDescription(enabled ? R.string.setting_watch_summary_enabled : R.string.setting_watch_summary_disabled); watchLink.setDescription(enabled ?
R.string.setting_watch_summary_enabled : R.string.setting_watch_summary_disabled);
} }
private void populatePreferences() { private void populatePreferences() {
// General group // General group
SettingsGroup general = new SettingsGroup(R.string.settings_group_general); {
SettingsGroup general = new SettingsGroup(R.string.settings_group_settings);
watchLink = (LinkSettingView) general.add(new LinkSettingView(this, R.string.settings_watch, 0, new View.OnClickListener() {
@Override watchLink = (LinkSettingView) general.add(new LinkSettingView(this,
public void onClick(View v) { R.string.settings_watch, 0,
navigationController.pushController(new WatchSettingsController(context)); v -> navigationController.pushController(
} new WatchSettingsController(context))));
}));
sitesSetting = (LinkSettingView) general.add(new LinkSettingView(this,
groups.add(general); R.string.settings_sites, 0,
v -> navigationController.pushController(
SettingsGroup appearance = new SettingsGroup(R.string.settings_group_appearance); new SitesSetupController(context))));
appearance.add(new LinkSettingView(this, getString(R.string.settings_screen_theme), theme().displayName, new View.OnClickListener() { general.add(new LinkSettingView(this,
@Override R.string.settings_appearance, R.string.settings_appearance_description,
public void onClick(View v) { v -> navigationController.pushController(
navigationController.pushController(new ThemeSettingsController(context)); new AppearanceSettingsController(context))));
}
})); general.add(new LinkSettingView(this,
R.string.settings_behaviour, R.string.settings_behaviour_description,
List<ListSettingView.Item> layoutModes = new ArrayList<>(); v -> navigationController.pushController(
for (ChanSettings.LayoutMode mode : ChanSettings.LayoutMode.values()) { new BehaviourSettingsController(context))));
int name = 0;
switch (mode) { general.add(new LinkSettingView(this,
case AUTO: R.string.settings_media, R.string.settings_media_description,
name = R.string.setting_layout_mode_auto; v -> navigationController.pushController(
break; new MediaSettingsController(context))));
case PHONE:
name = R.string.setting_layout_mode_phone; filtersSetting = (LinkSettingView) general.add(new LinkSettingView(this,
break; R.string.settings_filters, 0,
case SLIDE: v -> navigationController.pushController(new FiltersController(context))));
name = R.string.setting_layout_mode_slide;
break; groups.add(general);
case SPLIT:
name = R.string.setting_layout_mode_split;
break;
}
layoutModes.add(new ListSettingView.Item<>(getString(name), mode));
}
layoutModeView = new ListSettingView<>(this, ChanSettings.layoutMode, R.string.setting_layout_mode, layoutModes);
appearance.add(layoutModeView);
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)));
} }
fontView = appearance.add(new ListSettingView<>(this, ChanSettings.fontSize, R.string.setting_font_size, fontSizes.toArray(new ListSettingView.Item[fontSizes.size()]))); setupAboutGroup();
fontCondensed = appearance.add(new BooleanSettingView(this, ChanSettings.fontCondensed, R.string.setting_font_condensed, R.string.setting_font_condensed_description)); }
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));
}
gridColumnsView = appearance.add(new ListSettingView<>(this, ChanSettings.boardGridSpanCount, R.string.setting_board_grid_span_count, gridColumns));
groups.add(appearance);
// Browsing group
SettingsGroup browsing = new SettingsGroup(R.string.settings_group_browsing);
browsing.add(new LinkSettingView(this, R.string.filters_screen, 0, new View.OnClickListener() {
@Override
public void onClick(View v) {
navigationController.pushController(new FiltersController(context));
}
}));
saveLocation = (LinkSettingView) browsing.add(new LinkSettingView(this, R.string.save_location_screen, 0, new View.OnClickListener() {
@Override
public void onClick(View v) {
navigationController.pushController(new SaveLocationController(context));
}
}));
setSaveLocationDescription();
browsing.add(new BooleanSettingView(this, ChanSettings.saveBoardFolder, R.string.setting_save_board_folder, R.string.setting_save_board_folder_description));
browsing.add(new BooleanSettingView(this, ChanSettings.openLinkConfirmation, R.string.setting_open_link_confirmation, 0));
browsing.add(new BooleanSettingView(this, ChanSettings.autoRefreshThread, R.string.setting_auto_refresh_thread, 0));
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);
browsing.add(imageAutoLoadView);
videoAutoLoadView = new ListSettingView<>(this, ChanSettings.videoAutoLoadNetwork, R.string.setting_video_auto_load, videoAutoLoadTypes);
browsing.add(videoAutoLoadView);
updateVideoLoadModes();
browsing.add(new BooleanSettingView(this, ChanSettings.videoOpenExternal, R.string.setting_video_open_external, R.string.setting_video_open_external_description));
textOnly = new BooleanSettingView(this, ChanSettings.textOnly, R.string.setting_text_only, R.string.setting_text_only_description);
browsing.add(textOnly);
browsing.add(new LinkSettingView(this, R.string.setting_clear_thread_hides, 0, new View.OnClickListener() {
@Override
public void onClick(View v) {
databaseManager.clearAllThreadHides();
Toast.makeText(context, R.string.setting_cleared_thread_hides, Toast.LENGTH_LONG).show();
EventBus.getDefault().post(new RefreshUIMessage("clearhides"));
}
}));
groups.add(browsing); private void setupAboutGroup() {
SettingsGroup about = new SettingsGroup(R.string.settings_group_about);
// Posting group final String version = setupVersionSetting(about);
SettingsGroup posting = new SettingsGroup(R.string.settings_group_posting);
posting.add(new BooleanSettingView(this, ChanSettings.postPinThread, R.string.setting_post_pin, 0)); setupUpdateSetting(about);
posting.add(new StringSettingView(this, ChanSettings.postDefaultName, R.string.setting_post_default_name, R.string.setting_post_default_name));
groups.add(posting); setupExtraAboutSettings(about, version);
// About group about.add(new LinkSettingView(this,
SettingsGroup about = new SettingsGroup(R.string.settings_group_about); R.string.settings_about_license, R.string.settings_about_license_description,
String version = ""; v -> navigationController.pushController(
try { new LicensesController(context,
version = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; getString(R.string.settings_about_license),
} catch (PackageManager.NameNotFoundException e) { "file:///android_asset/html/license.html"))));
e.printStackTrace();
}
final String finalVersion = version;
String userVersion = version + " " + getString(R.string.app_flavor_name); about.add(new LinkSettingView(this,
about.add(new LinkSettingView(this, getString(R.string.app_name), userVersion, new View.OnClickListener() { R.string.settings_about_licenses, R.string.settings_about_licenses_description,
@Override v -> navigationController.pushController(
public void onClick(View v) { new LicensesController(context,
if ((++clickCount) % 5 == 0) { getString(R.string.settings_about_licenses),
boolean developer = !ChanSettings.developer.get(); "file:///android_asset/html/licenses.html"))));
ChanSettings.developer.set(developer); developerView = about.add(new LinkSettingView(this,
R.string.settings_developer, 0,
v -> navigationController.pushController(
new DeveloperSettingsController(context))));
Toast.makeText(context, (developer ? "Enabled" : "Disabled") + " developer options", Toast.LENGTH_LONG).show(); groups.add(about);
}
developerView.view.setVisibility(developer ? View.VISIBLE : View.GONE); private void setupExtraAboutSettings(SettingsGroup about, String version) {
} int extraAbouts = context.getResources()
} .getIdentifier("extra_abouts", "array", context.getPackageName());
}));
if (((StartActivity) context).getVersionHandler().isUpdatingAvailable()) {
about.add(new LinkSettingView(this, R.string.settings_update_check, 0, new View.OnClickListener() {
@Override
public void onClick(View v) {
((StartActivity) context).getVersionHandler().manualUpdateCheck();
}
}));
}
int extraAbouts = context.getResources().getIdentifier("extra_abouts", "array", context.getPackageName());
if (extraAbouts != 0) { if (extraAbouts != 0) {
String[] abouts = context.getResources().getStringArray(extraAbouts); String[] abouts = context.getResources().getStringArray(extraAbouts);
if (abouts.length % 3 == 0) { if (abouts.length % 3 == 0) {
@ -360,7 +196,7 @@ public class MainSettingsController extends SettingsController implements Toolba
} }
final String finalAboutLink = aboutLink; final String finalAboutLink = aboutLink;
about.add(new LinkSettingView(this, aboutName, aboutDescription, new View.OnClickListener() { View.OnClickListener clickListener = new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (finalAboutLink != null) { if (finalAboutLink != null) {
@ -370,7 +206,7 @@ public class MainSettingsController extends SettingsController implements Toolba
intent.setData(Uri.parse("mailto:")); intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email[0]}); intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email[0]});
String subject = email[1]; String subject = email[1];
subject = subject.replace("__VERSION__", finalVersion); subject = subject.replace("__VERSION__", version);
intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_SUBJECT, subject);
AndroidUtils.openIntent(intent); AndroidUtils.openIntent(intent);
} else { } else {
@ -378,59 +214,48 @@ public class MainSettingsController extends SettingsController implements Toolba
} }
} }
} }
})); };
about.add(new LinkSettingView(this,
aboutName, aboutDescription,
clickListener));
} }
} }
} }
}
about.add(new LinkSettingView(this, R.string.settings_about_license, R.string.settings_about_license_description, new View.OnClickListener() { private String setupVersionSetting(SettingsGroup about) {
@Override String version = "";
public void onClick(View v) { try {
navigationController.pushController(new LicensesController(context, version = context.getPackageManager()
getString(R.string.settings_about_license), "file:///android_asset/html/license.html")); .getPackageInfo(context.getPackageName(), 0).versionName;
} } catch (PackageManager.NameNotFoundException ignored) {
})); }
about.add(new LinkSettingView(this, R.string.settings_about_licenses, R.string.settings_about_licenses_description, new View.OnClickListener() { String userVersion = version + " " + getString(R.string.app_flavor_name);
@Override about.add(new LinkSettingView(this,
public void onClick(View v) { getString(R.string.app_name), userVersion,
navigationController.pushController(new LicensesController(context, v -> {
getString(R.string.settings_about_licenses), "file:///android_asset/html/licenses.html")); if ((++clickCount) % 5 == 0) {
} boolean developer = !ChanSettings.developer.get();
}));
developerView = about.add(new LinkSettingView(this, R.string.settings_developer, 0, new View.OnClickListener() { ChanSettings.developer.set(developer);
@Override
public void onClick(View v) {
navigationController.pushController(new DeveloperSettingsController(context));
}
}));
groups.add(about); Toast.makeText(context, (developer ? "Enabled" : "Disabled") +
} " developer options", Toast.LENGTH_LONG).show();
developerView.view.setVisibility(developer ? View.VISIBLE : View.GONE);
}
}));
private void setSaveLocationDescription() { return version;
saveLocation.setDescription(ChanSettings.saveLocation.get());
} }
private void updateVideoLoadModes() { private void setupUpdateSetting(SettingsGroup about) {
ChanSettings.MediaAutoLoadMode currentImageLoadMode = ChanSettings.imageAutoLoadNetwork.get(); if (((StartActivity) context).getVersionHandler().isUpdatingAvailable()) {
ChanSettings.MediaAutoLoadMode[] modes = ChanSettings.MediaAutoLoadMode.values(); about.add(new LinkSettingView(this,
boolean enabled = false; R.string.settings_update_check, 0,
boolean resetVideoMode = false; v -> ((StartActivity) context).getVersionHandler().manualUpdateCheck()));
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;
}
} }
} }
} }

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

@ -87,7 +87,7 @@ public class SiteSetupController extends SettingsController implements SiteSetup
public void setIsLoggedIn(boolean isLoggedIn) { public void setIsLoggedIn(boolean isLoggedIn) {
String text = context.getString(isLoggedIn ? String text = context.getString(isLoggedIn ?
R.string.setup_site_login_description_enabled : R.string.setup_site_login_description_enabled :
R.string.setup_site_login_description_enabled); R.string.setup_site_login_description_disabled);
loginLink.setDescription(text); loginLink.setDescription(text);
} }

@ -20,7 +20,6 @@ package org.floens.chan.ui.controller;
import android.content.Context; import android.content.Context;
import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.SwitchCompat;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.LinearLayout;
import org.floens.chan.R; import org.floens.chan.R;
import org.floens.chan.core.settings.ChanSettings; import org.floens.chan.core.settings.ChanSettings;
@ -81,9 +80,6 @@ public class WatchSettingsController extends SettingsController implements Compo
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
ChanSettings.watchEnabled.set(isChecked); ChanSettings.watchEnabled.set(isChecked);
if (previousSiblingController instanceof WatchSettingControllerListener) {
((WatchSettingControllerListener) previousSiblingController).onWatchEnabledChanged(isChecked);
}
crossfadeView.toggle(isChecked, true); crossfadeView.toggle(isChecked, true);
} }
@ -142,8 +138,4 @@ public class WatchSettingsController extends SettingsController implements Compo
groups.add(settings); groups.add(settings);
} }
public interface WatchSettingControllerListener {
void onWatchEnabledChanged(boolean enabled);
}
} }

@ -27,18 +27,28 @@ import android.widget.TextView;
import org.floens.chan.R; import org.floens.chan.R;
import org.floens.chan.controller.Controller; import org.floens.chan.controller.Controller;
import org.floens.chan.ui.activity.StartActivity;
import org.floens.chan.ui.helper.RefreshUIMessage;
import org.floens.chan.utils.AndroidUtils; import org.floens.chan.utils.AndroidUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.greenrobot.event.EventBus;
import static org.floens.chan.utils.AndroidUtils.dp; import static org.floens.chan.utils.AndroidUtils.dp;
public class SettingsController extends Controller implements AndroidUtils.OnMeasuredCallback { public class SettingsController extends Controller implements AndroidUtils.OnMeasuredCallback {
protected LinearLayout content; protected LinearLayout content;
protected List<SettingsGroup> groups = new ArrayList<>(); protected List<SettingsGroup> groups = new ArrayList<>();
private boolean built = false; protected List<SettingView> requiresUiRefresh = new ArrayList<>();
// Very user unfriendly.
@Deprecated
protected List<SettingView> requiresRestart = new ArrayList<>();
private boolean needRestart = false;
public SettingsController(Context context) { public SettingsController(Context context) {
super(context); super(context);
@ -51,6 +61,15 @@ public class SettingsController extends Controller implements AndroidUtils.OnMea
AndroidUtils.waitForLayout(view, this); AndroidUtils.waitForLayout(view, this);
} }
@Override
public void onDestroy() {
super.onDestroy();
if (needRestart) {
((StartActivity) context).restart();
}
}
@Override @Override
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
@ -70,6 +89,12 @@ public class SettingsController extends Controller implements AndroidUtils.OnMea
|| (item instanceof LinkSettingView)) { || (item instanceof LinkSettingView)) {
setDescriptionText(item.view, item.getTopDescription(), item.getBottomDescription()); setDescriptionText(item.view, item.getTopDescription(), item.getBottomDescription());
} }
if (requiresUiRefresh.contains(item)) {
EventBus.getDefault().post(new RefreshUIMessage("unknown"));
} else if (requiresRestart.contains(item)) {
needRestart = true;
}
} }
private void setMargins() { private void setMargins() {
@ -107,6 +132,11 @@ public class SettingsController extends Controller implements AndroidUtils.OnMea
} }
} }
protected void setupLayout() {
view = inflateRes(R.layout.settings_layout);
content = view.findViewById(R.id.scrollview_content);
}
protected void buildPreferences() { protected void buildPreferences() {
LayoutInflater inf = LayoutInflater.from(context); LayoutInflater inf = LayoutInflater.from(context);
boolean firstGroup = true; boolean firstGroup = true;
@ -149,8 +179,6 @@ public class SettingsController extends Controller implements AndroidUtils.OnMea
} }
} }
} }
built = true;
} }
private void setDescriptionText(View view, String topText, String bottomText) { private void setDescriptionText(View view, String topText, String bottomText) {

@ -101,6 +101,16 @@ Re-enable this permission in the app settings if you permanently disabled it."</
<item quantity="other">%d bookmarks</item> <item quantity="other">%d bookmarks</item>
</plurals> </plurals>
<plurals name="filter">
<item quantity="one">%d filter</item>
<item quantity="other">%d filters</item>
</plurals>
<plurals name="site">
<item quantity="one">%d site</item>
<item quantity="other">%d sites</item>
</plurals>
<string name="card_stats">%1$dR %2$dI</string> <string name="card_stats">%1$dR %2$dI</string>
<string name="action_view_album">View album</string> <string name="action_view_album">View album</string>
@ -137,6 +147,8 @@ Re-enable this permission in the app settings if you permanently disabled it."</
<string name="open_thread_confirmation">Open this thread?</string> <string name="open_thread_confirmation">Open this thread?</string>
<string name="open_link_failed">No applications found to open link</string> <string name="open_link_failed">No applications found to open link</string>
<string name="action_confirm_exit_title">Confirm exit</string>
<string name="thumbnail_load_failed_network">Error</string> <string name="thumbnail_load_failed_network">Error</string>
<string name="thumbnail_load_failed_server">404</string> <string name="thumbnail_load_failed_server">404</string>
<string name="image_preview_failed">Failed to show image</string> <string name="image_preview_failed">Failed to show image</string>
@ -357,32 +369,152 @@ Re-enable this permission in the app settings if you permanently disabled it."</
<string name="drawer_sites">Sites</string> <string name="drawer_sites">Sites</string>
<string name="drawer_history">History</string> <string name="drawer_history">History</string>
<!-- Main settings -->
<string name="settings_screen">Settings</string> <string name="settings_screen">Settings</string>
<string name="settings_group_general">General</string>
<!-- Main "Settings" group -->
<string name="settings_group_settings">Settings</string>
<string name="settings_watch">Thread watcher</string> <string name="settings_watch">Thread watcher</string>
<string name="settings_pass">4chan pass</string> <string name="settings_sites">Sites</string>
<string name="settings_advanced_hint">Try the advanced settings!</string> <string name="settings_appearance">Appearance</string>
<string name="settings_appearance_description">Theme, layout, fonts, etc.</string>
<string name="settings_behaviour">Behaviour</string>
<string name="settings_behaviour_description">Thread refresh, captcha, etc.</string>
<string name="settings_media">Media</string>
<string name="settings_media_description">Save location, auto loading, etc.</string>
<string name="settings_filters">Filters</string>
<!-- Thread watcher -->
<string name="setting_watch_summary_enabled">Watching pinned threads</string>
<string name="setting_watch_summary_disabled">Off</string>
<string name="settings_group_appearance">Appearance</string> <string name="settings_screen_watch">Thread watcher settings</string>
<string name="settings_group_watch">Settings</string>
<string name="setting_watch_info">To watch pins for new posts, turn the thread watcher on.</string>
<string name="setting_watch_enable_background">Enable in the background</string>
<string name="setting_watch_enable_background_description">Watch pins when Clover is in the background</string>
<string name="setting_watch_background_timeout">Background update interval</string>
<string name="setting_watch_background_timeout_description">The time between updates in the background</string>
<string name="setting_watch_notify_mode">Notify about</string>
<string-array name="setting_watch_notify_modes">
<item>All posts</item>
<item>Only posts quoting you</item>
</string-array>
<string name="setting_watch_sound">Notification sound</string>
<string-array name="setting_watch_sounds">
<item>All posts</item>
<item>Only posts quoting you</item>
</string-array>
<string name="setting_watch_peek">Heads-up notification on mentions</string>
<string name="setting_watch_peek_description">Show a heads-up notification on mentions</string>
<string name="setting_watch_led">Notification light</string>
<string-array name="setting_watch_leds">
<item>None</item>
<item>White</item>
<item>Red</item>
<item>Yellow</item>
<item>Green</item>
<item>Cyan</item>
<item>Blue</item>
<item>Purple</item>
</string-array>
<!-- Main About group -->
<string name="settings_group_about">About</string>
<string name="settings_update_check">Check for updates</string>
<string name="settings_about_license">Released under the GNU GPLv3 license</string>
<string name="settings_about_license_description">Tap to see license</string>
<string name="settings_about_licenses">Open Source Licenses</string>
<string name="settings_about_licenses_description">Legal information about licenses</string>
<string name="settings_developer">Developer settings</string>
<string name="settings_group_browsing">Browsing</string>
<!-- Appearance -->
<string name="settings_screen_appearance">Appearance</string>
<string name="settings_group_appearance">Appearance</string>
<string name="setting_theme">Theme</string> <string name="setting_theme">Theme</string>
<string name="setting_theme_explanation">Swipe to change the theme.\nTap the toolbar menu to change its color.\n</string>
<string name="setting_theme_accent">Click here to change the FAB color</string> <!-- Appearance layout group -->
<string name="settings_group_layout">Layout</string>
<string name="setting_layout_mode">Layout mode</string> <string name="setting_layout_mode">Layout mode</string>
<string name="setting_layout_mode_auto">Auto</string> <string name="setting_layout_mode_auto">Auto</string>
<string name="setting_layout_mode_phone">Phone layout</string> <string name="setting_layout_mode_phone">Phone layout</string>
<string name="setting_layout_mode_slide">Slide mode</string> <string name="setting_layout_mode_slide">Slide mode</string>
<string name="setting_layout_mode_split">Split mode</string> <string name="setting_layout_mode_split">Split mode</string>
<string name="setting_board_grid_span_count">Catalog mode columns</string>
<string name="setting_board_grid_span_count_default">Auto</string>
<string name="setting_board_grid_span_count_item">%1$d columns</string>
<string name="setting_never_hide_toolbar">Never hide the toolbar</string>
<string name="setting_enable_reply_fab">Enable the reply FAB</string>
<string name="setting_enable_reply_fab_description">Disabling replaces it with a menu option</string>
<!-- Appearance post group -->
<string name="settings_group_post">Post</string>
<string name="setting_font_size">Font size</string> <string name="setting_font_size">Font size</string>
<string name="setting_font_size_default">(default)</string> <string name="setting_font_size_default">(default)</string>
<string name="setting_font_condensed">Use condensed font</string> <string name="setting_font_condensed">Use condensed font</string>
<string name="setting_font_condensed_description">Use a condensed font for the posts</string> <string name="setting_font_condensed_description">Use a condensed font for the posts</string>
<string name="setting_board_grid_span_count">Catalog mode columns</string> <string name="setting_post_full_date">Show the full date on posts</string>
<string name="setting_board_grid_span_count_default">Auto</string> <string name="setting_post_file_info">Show file info on posts</string>
<string name="setting_board_grid_span_count_item">%1$d columns</string> <string name="setting_post_filename">Show filename on posts</string>
<string name="setting_open_link_confirmation">Ask before opening links</string>
<!-- Behaviour -->
<string name="settings_screen_behaviour">Behaviour</string>
<!-- Behaviour general group -->
<string name="settings_group_general">General</string>
<string name="setting_auto_refresh_thread">Auto refresh threads</string> <string name="setting_auto_refresh_thread">Auto refresh threads</string>
<string name="setting_confirm_exit">Confirm before exit</string>
<string name="setting_controller_swipeable">Allow screens to be swiped away</string>
<string name="setting_clear_thread_hides">Clear all thread hides</string>
<string name="setting_cleared_thread_hides">Cleared all thread hides</string>
<!-- Behaviour reply group -->
<string name="settings_group_reply">Reply</string>
<string name="setting_use_new_captcha">Use the new captcha</string>
<string name="setting_use_new_captcha_description">Enable to use the newer recaptcha for thread replies.</string>
<string name="setting_post_pin">Pin thread on post</string>
<string name="setting_post_default_name">Default post name</string>
<!-- Behaviour post group -->
<string name="setting_text_only">Text only mode</string>
<string name="setting_text_only_description">Hide images when in board and thread view</string>
<string name="settings_reveal_text_spoilers">Reveal text spoilers</string>
<string name="settings_reveal_text_spoilers_description">Makes the spoiler text appear clicked</string>
<string name="setting_anonymize">Make everyone Anonymous</string>
<string name="setting_anonymize_ids">Hide IDs</string>
<string name="setting_show_anonymous_name">Show Anonymous username</string>
<string name="setting_buttons_bottom">Reply buttons on the bottom</string>
<string name="setting_volume_key_scrolling">Volume keys scroll content</string>
<string name="setting_tap_no_rely">Tap the post number to reply</string>
<string name="setting_open_link_confirmation">Ask before opening links</string>
<!-- Behaviour proxy group -->
<string name="settings_group_proxy">HTTP Proxy</string>
<string name="setting_proxy_enabled">Enable proxy</string>
<string name="setting_proxy_address">Proxy server address</string>
<string name="setting_proxy_port">Proxy server port</string>
<!-- Media -->
<string name="settings_screen_media">Media</string>
<!-- 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_original_filename">Save original filename</string>
<string name="setting_video_open_external">Open videos external</string>
<string name="setting_video_open_external_description">Open videos in an external media player</string>
<string name="setting_share_url">Share url to image</string>
<string name="setting_share_url_description">Share the url to the image instead of the image itself</string>
<string name="settings_reveal_image_spoilers">Reveal image spoilers</string>
<!-- Media loading group -->
<string name="settings_group_media_loading">Media loading</string>
<string name="setting_image_auto_load">Auto load images</string> <string name="setting_image_auto_load">Auto load images</string>
<string name="setting_image_auto_load_all">Always</string> <string name="setting_image_auto_load_all">Always</string>
@ -390,32 +522,9 @@ Re-enable this permission in the app settings if you permanently disabled it."</
<string name="setting_image_auto_load_none">Never</string> <string name="setting_image_auto_load_none">Never</string>
<string name="setting_video_auto_load">Auto load videos</string> <string name="setting_video_auto_load">Auto load videos</string>
<string name="setting_video_auto_load_description">Depends on auto load images</string>
<string name="setting_video_open_external">Open videos external</string>
<string name="setting_video_open_external_description">Open videos in an external media player</string>
<string name="setting_text_only">Text only mode</string>
<string name="setting_text_only_description">Hide images when in board and thread view</string>
<string name="setting_clear_thread_hides">Clear all thread hides</string>
<string name="setting_cleared_thread_hides">Cleared all thread hides</string>
<string name="settings_group_posting">Posting</string>
<string name="setting_post_default_name">Default post name</string>
<string name="setting_post_pin">Pin thread on post</string>
<string name="settings_group_about">About</string> <!-- Save location settings -->
<string name="settings_update_check">Check for updates</string>
<string name="settings_about_license">Released under the GNU GPLv3 license</string>
<string name="settings_about_license_description">Tap to see license</string>
<string name="settings_about_licenses">Open Source Licenses</string>
<string name="settings_about_licenses_description">Legal information about licenses</string>
<string name="settings_developer">Developer settings</string>
<string name="settings_open_logs">View logs</string>
<string name="settings_logs_screen">Logs</string>
<string name="settings_logs_copy">Copy</string>
<string name="settings_logs_copied_to_clipboard">Copied to clipboard</string>
<string name="settings_screen_advanced">Advanced settings</string>
<string name="settings_group_advanced">Advanced settings</string>
<string name="save_location_screen">Save location</string> <string name="save_location_screen">Save location</string>
<string name="save_location_storage_permission_required_title">Storage permission required</string> <string name="save_location_storage_permission_required_title">Storage permission required</string>
<string name="save_location_storage_permission_required"> <string name="save_location_storage_permission_required">
@ -425,71 +534,18 @@ Re-enable this permission in the app settings if you permanently disabled it."</
<string name="setting_save_folder">File save folder</string> <string name="setting_save_folder">File save folder</string>
<string name="setting_save_folder_error_create_folder">Error creating save folder</string> <string name="setting_save_folder_error_create_folder">Error creating save folder</string>
<string name="setting_folder_pick_ok">Choose</string> <string name="setting_folder_pick_ok">Choose</string>
<string name="setting_use_new_captcha">Use the new captcha</string>
<string name="setting_use_new_captcha_description">Enable to use the newer recaptcha for thread replies.</string>
<string name="setting_save_original_filename">Save original filename</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_share_url">Share url to image</string>
<string name="setting_share_url_description">Share the url to the image instead of the image itself</string>
<string name="setting_network_https">Use HTTPS</string>
<string name="setting_network_https_description">Use HTTPS for all network requests</string>
<string name="setting_enable_reply_fab">Enable the reply FAB</string>
<string name="setting_enable_reply_fab_description">Disabling replaces it with a menu option</string>
<string name="setting_anonymize">Make everyone Anonymous</string>
<string name="setting_anonymize_ids">Hide IDs</string>
<string name="setting_show_anonymous_name">Show Anonymous username</string>
<string name="settings_reveal_image_spoilers">Reveal image spoilers</string>
<string name="settings_reveal_text_spoilers">Reveal text spoilers</string>
<string name="settings_reveal_text_spoilers_description">Makes the spoiler text appear clicked</string>
<string name="setting_buttons_bottom">Reply buttons on the bottom</string>
<string name="setting_confirm_exit">Confirm before exit</string>
<string name="setting_confirm_exit_title">Confirm exit</string>
<string name="setting_tap_no_rely">Tap the post number to reply</string>
<string name="setting_volume_key_scrolling">Volume keys scroll content</string>
<string name="setting_post_full_date">Show the full date on posts</string>
<string name="setting_post_file_info">Show file info on posts</string>
<string name="setting_post_filename">Show filename on posts</string>
<string name="setting_never_hide_toolbar">Never hide the toolbar</string>
<string name="setting_controller_swipeable">Allow screens to be swiped away</string>
<string name="settings_group_proxy">HTTP Proxy</string>
<string name="setting_proxy_enabled">Enable proxy</string>
<string name="setting_proxy_address">Proxy server address</string>
<string name="setting_proxy_port">Proxy server port</string>
<string name="settings_screen_watch">Watcher settings</string> <!-- Theme settings -->
<string name="settings_group_watch">Watcher settings</string> <string name="setting_theme_explanation">Swipe to change the theme.\nTap the toolbar menu to change its color.\n</string>
<string name="setting_watch_info">To watch pins for new posts, turn the thread watcher on.</string> <string name="setting_theme_accent">Click here to change the FAB color</string>
<string name="setting_watch_summary_enabled">Watching pinned threads</string>
<string name="setting_watch_summary_disabled">Off</string> <!-- Developer settings -->
<string name="setting_watch_enable_background">Enable in the background</string> <string name="settings_open_logs">View logs</string>
<string name="setting_watch_enable_background_description">Watch pins when Clover is in the background</string> <string name="settings_logs_screen">Logs</string>
<string name="setting_watch_background_timeout">Background update interval</string> <string name="settings_logs_copy">Copy</string>
<string name="setting_watch_background_timeout_description">The time between updates in the background</string> <string name="settings_logs_copied_to_clipboard">Copied to clipboard</string>
<string name="setting_watch_notify_mode">Notify about</string>
<string-array name="setting_watch_notify_modes">
<item>All posts</item>
<item>Only posts quoting you</item>
</string-array>
<string name="setting_watch_sound">Notification sound</string>
<string-array name="setting_watch_sounds">
<item>All posts</item>
<item>Only posts quoting you</item>
</string-array>
<string name="setting_watch_peek">Heads-up notification on mentions</string>
<string name="setting_watch_peek_description">Show a heads-up notification on mentions</string>
<string name="setting_watch_led">Notification light</string>
<string-array name="setting_watch_leds">
<item>None</item>
<item>White</item>
<item>Red</item>
<item>Yellow</item>
<item>Green</item>
<item>Cyan</item>
<item>Blue</item>
<item>Purple</item>
</string-array>
<string name="settings_screen_pass">4chan pass</string> <string name="settings_screen_pass">4chan pass</string>
<string name="setting_pass_token">Token</string> <string name="setting_pass_token">Token</string>

Loading…
Cancel
Save