Add OptionsSetting that wraps an enum

multisite
Floens 9 years ago
parent 74f1bf3186
commit 7014fc6a8b
  1. 4
      Clover/app/src/main/java/org/floens/chan/Chan.java
  2. 38
      Clover/app/src/main/java/org/floens/chan/chan/ChanUrls.java
  3. 8
      Clover/app/src/main/java/org/floens/chan/core/presenter/ImageViewerPresenter.java
  4. 4
      Clover/app/src/main/java/org/floens/chan/core/settings/BooleanSetting.java
  5. 82
      Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java
  6. 4
      Clover/app/src/main/java/org/floens/chan/core/settings/CounterSetting.java
  7. 7
      Clover/app/src/main/java/org/floens/chan/core/settings/IntegerSetting.java
  8. 22
      Clover/app/src/main/java/org/floens/chan/core/settings/OptionSettingItem.java
  9. 62
      Clover/app/src/main/java/org/floens/chan/core/settings/OptionsSetting.java
  10. 22
      Clover/app/src/main/java/org/floens/chan/core/settings/Setting.java
  11. 4
      Clover/app/src/main/java/org/floens/chan/core/settings/StringSetting.java
  12. 5
      Clover/app/src/main/java/org/floens/chan/ui/adapter/PostAdapter.java
  13. 2
      Clover/app/src/main/java/org/floens/chan/ui/cell/CardPostCell.java
  14. 4
      Clover/app/src/main/java/org/floens/chan/ui/cell/PostCell.java
  15. 23
      Clover/app/src/main/java/org/floens/chan/ui/cell/PostCellInterface.java
  16. 6
      Clover/app/src/main/java/org/floens/chan/ui/cell/PostStubCell.java
  17. 17
      Clover/app/src/main/java/org/floens/chan/ui/controller/BrowseController.java
  18. 16
      Clover/app/src/main/java/org/floens/chan/ui/controller/MainSettingsController.java
  19. 2
      Clover/app/src/main/java/org/floens/chan/ui/controller/PostRepliesController.java
  20. 3
      Clover/app/src/main/java/org/floens/chan/ui/controller/ThemeSettingsController.java
  21. 3
      Clover/app/src/main/java/org/floens/chan/ui/controller/ViewThreadController.java
  22. 3
      Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadLayout.java
  23. 6
      Clover/app/src/main/java/org/floens/chan/ui/layout/ThreadListLayout.java

@ -28,7 +28,6 @@ import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import org.floens.chan.chan.ChanUrls;
import org.floens.chan.core.cache.FileCache;
import org.floens.chan.core.database.DatabaseManager;
import org.floens.chan.core.http.ReplyManager;
@ -36,7 +35,6 @@ import org.floens.chan.core.manager.BoardManager;
import org.floens.chan.core.manager.WatchManager;
import org.floens.chan.core.net.BitmapLruImageCache;
import org.floens.chan.core.net.ProxiedHurlStack;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.utils.AndroidUtils;
import org.floens.chan.utils.Logger;
import org.floens.chan.utils.Time;
@ -112,8 +110,6 @@ public class Chan extends Application {
AndroidUtils.init();
ChanUrls.loadScheme(ChanSettings.networkHttps.get());
userAgent = createUserAgent();
File cacheDir = getExternalCacheDir() != null ? getExternalCacheDir() : getCacheDir();

@ -17,25 +17,21 @@
*/
package org.floens.chan.chan;
import org.floens.chan.core.settings.ChanSettings;
import java.util.Locale;
public class ChanUrls {
private static String scheme;
public static void loadScheme(boolean useHttps) {
scheme = useHttps ? "https" : "http";
}
public static String getCatalogUrl(String board) {
return scheme + "://a.4cdn.org/" + board + "/catalog.json";
return scheme() + "://a.4cdn.org/" + board + "/catalog.json";
}
public static String getPageUrl(String board, int pageNumber) {
return scheme + "://a.4cdn.org/" + board + "/" + (pageNumber + 1) + ".json";
return scheme() + "://a.4cdn.org/" + board + "/" + (pageNumber + 1) + ".json";
}
public static String getThreadUrl(String board, int no) {
return scheme + "://a.4cdn.org/" + board + "/thread/" + no + ".json";
return scheme() + "://a.4cdn.org/" + board + "/thread/" + no + ".json";
}
public static String getCaptchaSiteKey() {
@ -43,27 +39,27 @@ public class ChanUrls {
}
public static String getImageUrl(String board, String code, String extension) {
return scheme + "://i.4cdn.org/" + board + "/" + code + "." + extension;
return scheme() + "://i.4cdn.org/" + board + "/" + code + "." + extension;
}
public static String getThumbnailUrl(String board, String code) {
return scheme + "://t.4cdn.org/" + board + "/" + code + "s.jpg";
return scheme() + "://t.4cdn.org/" + board + "/" + code + "s.jpg";
}
public static String getSpoilerUrl() {
return scheme + "://s.4cdn.org/image/spoiler.png";
return scheme() + "://s.4cdn.org/image/spoiler.png";
}
public static String getCustomSpoilerUrl(String board, int value) {
return scheme + "://s.4cdn.org/image/spoiler-" + board + value + ".png";
return scheme() + "://s.4cdn.org/image/spoiler-" + board + value + ".png";
}
public static String getCountryFlagUrl(String countryCode) {
return scheme + "://s.4cdn.org/image/country/" + countryCode.toLowerCase(Locale.ENGLISH) + ".gif";
return scheme() + "://s.4cdn.org/image/country/" + countryCode.toLowerCase(Locale.ENGLISH) + ".gif";
}
public static String getBoardsUrl() {
return scheme + "://a.4cdn.org/boards.json";
return scheme() + "://a.4cdn.org/boards.json";
}
public static String getReplyUrl(String board) {
@ -75,19 +71,19 @@ public class ChanUrls {
}
public static String getBoardUrlDesktop(String board) {
return scheme + "://boards.4chan.org/" + board + "/";
return scheme() + "://boards.4chan.org/" + board + "/";
}
public static String getThreadUrlDesktop(String board, int no) {
return scheme + "://boards.4chan.org/" + board + "/thread/" + no;
return scheme() + "://boards.4chan.org/" + board + "/thread/" + no;
}
public static String getThreadUrlDesktop(String board, int no, int postNo) {
return scheme + "://boards.4chan.org/" + board + "/thread/" + no + "#p" + postNo;
return scheme() + "://boards.4chan.org/" + board + "/thread/" + no + "#p" + postNo;
}
public static String getCatalogUrlDesktop(String board) {
return scheme + "://boards.4chan.org/" + board + "/catalog";
return scheme() + "://boards.4chan.org/" + board + "/catalog";
}
public static String getPassUrl() {
@ -105,4 +101,8 @@ public class ChanUrls {
public static String getReportUrl(String board, int no) {
return "https://sys.4chan.org/" + board + "/imgboard.php?mode=report&no=" + no;
}
private static String scheme() {
return ChanSettings.networkHttps.get() ? "https" : "http";
}
}

@ -271,12 +271,12 @@ public class ImageViewerPresenter implements MultiImageView.Callback, ViewPager.
return imageAutoLoad(postImage) && shouldLoadForNetworkType(ChanSettings.videoAutoLoadNetwork.get());
}
private boolean shouldLoadForNetworkType(String networkType) {
if (networkType.equals(ChanSettings.MediaAutoLoadMode.NONE.name)) {
private boolean shouldLoadForNetworkType(ChanSettings.MediaAutoLoadMode networkType) {
if (networkType == ChanSettings.MediaAutoLoadMode.NONE) {
return false;
} else if (networkType.equals(ChanSettings.MediaAutoLoadMode.WIFI.name)) {
} else if (networkType == ChanSettings.MediaAutoLoadMode.WIFI) {
return isConnected(ConnectivityManager.TYPE_WIFI);
} else if (networkType.equals(ChanSettings.MediaAutoLoadMode.ALL.name)) {
} else if (networkType == ChanSettings.MediaAutoLoadMode.ALL) {
return true;
}

@ -27,10 +27,6 @@ public class BooleanSetting extends Setting<Boolean> {
super(sharedPreferences, key, def);
}
public BooleanSetting(SharedPreferences sharedPreferences, String key, Boolean def, SettingCallback<Boolean> callback) {
super(sharedPreferences, key, def, callback);
}
@Override
public Boolean get() {
if (hasCached) {

@ -23,10 +23,8 @@ import android.text.TextUtils;
import org.floens.chan.Chan;
import org.floens.chan.R;
import org.floens.chan.chan.ChanUrls;
import org.floens.chan.core.manager.WatchManager;
import org.floens.chan.ui.adapter.PostsFilter;
import org.floens.chan.ui.cell.PostCellInterface;
import org.floens.chan.utils.AndroidUtils;
import java.io.File;
@ -34,7 +32,7 @@ import java.net.InetSocketAddress;
import java.net.Proxy;
public class ChanSettings {
public enum MediaAutoLoadMode {
public enum MediaAutoLoadMode implements OptionSettingItem {
// ALways auto load, either wifi or mobile
ALL("all"),
// Only auto load if on wifi
@ -42,19 +40,31 @@ public class ChanSettings {
// Never auto load
NONE("none");
public String name;
String name;
MediaAutoLoadMode(String name) {
this.name = name;
}
public static MediaAutoLoadMode find(String name) {
for (MediaAutoLoadMode mode : MediaAutoLoadMode.values()) {
if (mode.name.equals(name)) {
return mode;
}
}
return null;
@Override
public String getName() {
return name;
}
}
public enum PostViewMode implements OptionSettingItem {
LIST("list"),
CARD("grid");
String name;
PostViewMode(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
}
@ -66,11 +76,11 @@ public class ChanSettings {
public static final BooleanSetting openLinkConfirmation;
public static final BooleanSetting autoRefreshThread;
// public static final BooleanSetting imageAutoLoad;
public static final StringSetting imageAutoLoadNetwork;
public static final StringSetting videoAutoLoadNetwork;
public static final OptionsSetting<MediaAutoLoadMode> imageAutoLoadNetwork;
public static final OptionsSetting<MediaAutoLoadMode> videoAutoLoadNetwork;
public static final BooleanSetting videoOpenExternal;
public static final BooleanSetting videoErrorIgnore;
public static final StringSetting boardViewMode;
public static final OptionsSetting<PostViewMode> boardViewMode;
public static final IntegerSetting boardGridSpanCount;
public static final StringSetting boardOrder;
@ -125,6 +135,22 @@ public class ChanSettings {
public static final CounterSetting replyOpenCounter;
public static final CounterSetting threadOpenCounter;
public enum TestOptions implements OptionSettingItem {
ONE("one"),
TWO("two"),
THREE("three");
String name;
TestOptions(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
static {
SharedPreferences p = AndroidUtils.getPreferences();
@ -137,11 +163,11 @@ public class ChanSettings {
openLinkConfirmation = new BooleanSetting(p, "preference_open_link_confirmation", false);
autoRefreshThread = new BooleanSetting(p, "preference_auto_refresh_thread", true);
// imageAutoLoad = new BooleanSetting(p, "preference_image_auto_load", true);
imageAutoLoadNetwork = new StringSetting(p, "preference_image_auto_load_network", MediaAutoLoadMode.WIFI.name);
videoAutoLoadNetwork = new StringSetting(p, "preference_video_auto_load_network", MediaAutoLoadMode.WIFI.name);
imageAutoLoadNetwork = new OptionsSetting<>(p, "preference_image_auto_load_network", MediaAutoLoadMode.values(), MediaAutoLoadMode.WIFI);
videoAutoLoadNetwork = new OptionsSetting<>(p, "preference_video_auto_load_network", MediaAutoLoadMode.values(), MediaAutoLoadMode.WIFI);
videoOpenExternal = new BooleanSetting(p, "preference_video_external", false);
videoErrorIgnore = new BooleanSetting(p, "preference_video_error_ignore", false);
boardViewMode = new StringSetting(p, "preference_board_view_mode", PostCellInterface.PostViewMode.LIST.name); // "list" or "grid"
boardViewMode = new OptionsSetting<>(p, "preference_board_view_mode", PostViewMode.values(), PostViewMode.LIST);
boardGridSpanCount = new IntegerSetting(p, "preference_board_grid_span_count", 0);
boardOrder = new StringSetting(p, "preference_board_order", PostsFilter.Order.BUMP.name);
@ -154,12 +180,7 @@ public class ChanSettings {
saveLocation = new StringSetting(p, "preference_image_save_location", Environment.getExternalStorageDirectory() + File.separator + "Clover");
saveOriginalFilename = new BooleanSetting(p, "preference_image_save_original", false);
shareUrl = new BooleanSetting(p, "preference_image_share_url", false);
networkHttps = new BooleanSetting(p, "preference_network_https", true, new Setting.SettingCallback<Boolean>() {
@Override
public void onValueChange(Setting setting, Boolean value) {
ChanUrls.loadScheme(value);
}
});
networkHttps = new BooleanSetting(p, "preference_network_https", true);
forcePhoneLayout = new BooleanSetting(p, "preference_force_phone_layout", false);
enableReplyFab = new BooleanSetting(p, "preference_enable_reply_fab", true);
anonymize = new BooleanSetting(p, "preference_anonymize", false);
@ -175,14 +196,16 @@ public class ChanSettings {
neverHideToolbar = new BooleanSetting(p, "preference_never_hide_toolbar", false);
controllerSwipeable = new BooleanSetting(p, "preference_controller_swipeable", true);
watchEnabled = new BooleanSetting(p, "preference_watch_enabled", false, new Setting.SettingCallback<Boolean>() {
watchEnabled = new BooleanSetting(p, "preference_watch_enabled", false);
watchEnabled.addCallback(new Setting.SettingCallback<Boolean>() {
@Override
public void onValueChange(Setting setting, Boolean value) {
Chan.getWatchManager().onWatchEnabledChanged(value);
}
});
watchCountdown = new BooleanSetting(p, "preference_watch_countdown", false);
watchBackground = new BooleanSetting(p, "preference_watch_background_enabled", false, new Setting.SettingCallback<Boolean>() {
watchBackground = new BooleanSetting(p, "preference_watch_background_enabled", false);
watchBackground.addCallback(new Setting.SettingCallback<Boolean>() {
@Override
public void onValueChange(Setting setting, Boolean value) {
Chan.getWatchManager().onBackgroundWatchingChanged(value);
@ -202,19 +225,22 @@ public class ChanSettings {
previousVersion = new IntegerSetting(p, "preference_previous_version", 0);
proxyEnabled = new BooleanSetting(p, "preference_proxy_enabled", false, new Setting.SettingCallback<Boolean>() {
proxyEnabled = new BooleanSetting(p, "preference_proxy_enabled", false);
proxyEnabled.addCallback(new Setting.SettingCallback<Boolean>() {
@Override
public void onValueChange(Setting setting, Boolean value) {
loadProxy();
}
});
proxyAddress = new StringSetting(p, "preference_proxy_address", "", new Setting.SettingCallback<String>() {
proxyAddress = new StringSetting(p, "preference_proxy_address", "");
proxyAddress.addCallback(new Setting.SettingCallback<String>() {
@Override
public void onValueChange(Setting setting, String value) {
loadProxy();
}
});
proxyPort = new IntegerSetting(p, "preference_proxy_port", 80, new Setting.SettingCallback<Integer>() {
proxyPort = new IntegerSetting(p, "preference_proxy_port", 80);
proxyPort.addCallback(new Setting.SettingCallback<Integer>() {
@Override
public void onValueChange(Setting setting, Integer value) {
loadProxy();

@ -24,10 +24,6 @@ public class CounterSetting extends IntegerSetting {
super(sharedPreferences, key, 0);
}
public CounterSetting(SharedPreferences sharedPreferences, String key, SettingCallback<Integer> callback) {
super(sharedPreferences, key, 0, callback);
}
public int increase() {
set(get() + 1);
return get();

@ -19,9 +19,6 @@ package org.floens.chan.core.settings;
import android.content.SharedPreferences;
/**
* Created by Zetsubou on 02.07.2015
*/
public class IntegerSetting extends Setting<Integer> {
private boolean hasCached = false;
private Integer cached;
@ -30,10 +27,6 @@ public class IntegerSetting extends Setting<Integer> {
super(sharedPreferences, key, def);
}
public IntegerSetting(SharedPreferences sharedPreferences, String key, Integer def, SettingCallback<Integer> callback) {
super(sharedPreferences, key, def, callback);
}
@Override
public Integer get() {
if (hasCached) {

@ -0,0 +1,22 @@
/*
* 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.settings;
public interface OptionSettingItem {
String getName();
}

@ -0,0 +1,62 @@
/*
* 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.settings;
import android.content.SharedPreferences;
public class OptionsSetting<T extends OptionSettingItem> extends Setting<T> {
private boolean hasCached = false;
private T cached;
private T[] items;
public OptionsSetting(SharedPreferences sharedPreferences, String key, T[] items, T def) {
super(sharedPreferences, key, def);
this.items = items;
}
@Override
public T get() {
if (hasCached) {
return cached;
} else {
String itemName = sharedPreferences.getString(key, def.getName());
T selectedItem = null;
for (T item : items) {
if (item.getName().equals(itemName)) {
selectedItem = item;
}
}
if (selectedItem == null) {
selectedItem = def;
}
cached = selectedItem;
hasCached = true;
return cached;
}
}
@Override
public void set(T value) {
if (!value.equals(get())) {
sharedPreferences.edit().putString(key, value.getName()).apply();
cached = value;
onValueChanged();
}
}
}

@ -19,21 +19,19 @@ package org.floens.chan.core.settings;
import android.content.SharedPreferences;
import java.util.ArrayList;
import java.util.List;
public abstract class Setting<T> {
protected final SharedPreferences sharedPreferences;
protected final String key;
protected final T def;
private SettingCallback<T> callback;
private List<SettingCallback<T>> callbacks = new ArrayList<>();
public Setting(SharedPreferences sharedPreferences, String key, T def) {
this(sharedPreferences, key, def, null);
}
public Setting(SharedPreferences sharedPreferences, String key, T def, SettingCallback<T> callback) {
this.sharedPreferences = sharedPreferences;
this.key = key;
this.def = def;
this.callback = callback;
}
public abstract T get();
@ -44,9 +42,17 @@ public abstract class Setting<T> {
return def;
}
public void addCallback(SettingCallback<T> callback) {
this.callbacks.add(callback);
}
public void removeCallback(SettingCallback<T> callback) {
this.callbacks.remove(callback);
}
protected final void onValueChanged() {
if (callback != null) {
callback.onValueChange(this, get());
for (int i = 0; i < callbacks.size(); i++) {
callbacks.get(i).onValueChange(this, get());
}
}

@ -27,10 +27,6 @@ public class StringSetting extends Setting<String> {
super(sharedPreferences, key, def);
}
public StringSetting(SharedPreferences sharedPreferences, String key, String def, SettingCallback<String> callback) {
super(sharedPreferences, key, def, callback);
}
@Override
public String get() {
if (hasCached) {

@ -26,6 +26,7 @@ import org.floens.chan.R;
import org.floens.chan.core.model.ChanThread;
import org.floens.chan.core.model.Loadable;
import org.floens.chan.core.model.Post;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.ui.cell.PostCellInterface;
import org.floens.chan.ui.cell.ThreadStatusCell;
@ -54,7 +55,7 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private int lastSeenIndicatorPosition = -1;
private boolean bound;
private PostCellInterface.PostViewMode postViewMode;
private ChanSettings.PostViewMode postViewMode;
public PostAdapter(RecyclerView recyclerView, PostAdapterCallback postAdapterCallback, PostCellInterface.PostCellCallback postCellCallback, ThreadStatusCell.Callback statusCellCallback) {
this.recyclerView = recyclerView;
@ -266,7 +267,7 @@ public class PostAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
notifyDataSetChanged();
}
public void setPostViewMode(PostCellInterface.PostViewMode postViewMode) {
public void setPostViewMode(ChanSettings.PostViewMode postViewMode) {
this.postViewMode = postViewMode;
}

@ -146,7 +146,7 @@ public class CardPostCell extends CardView implements PostCellInterface, View.On
}
public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback,
boolean highlighted, boolean selected, int markedNo, boolean showDivider, PostCellInterface.PostViewMode postViewMode) {
boolean highlighted, boolean selected, int markedNo, boolean showDivider, ChanSettings.PostViewMode postViewMode) {
if (this.post == post) {
return;
}

@ -72,9 +72,7 @@ import org.floens.chan.utils.AndroidUtils;
import org.floens.chan.utils.Time;
import java.text.BreakIterator;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static android.text.TextUtils.isEmpty;
@ -254,7 +252,7 @@ public class PostCell extends LinearLayout implements PostCellInterface {
}
public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback,
boolean highlighted, boolean selected, int markedNo, boolean showDivider, PostCellInterface.PostViewMode postViewMode) {
boolean highlighted, boolean selected, int markedNo, boolean showDivider, ChanSettings.PostViewMode postViewMode) {
if (this.post == post && this.highlighted == highlighted && this.selected == selected && this.markedNo == markedNo && this.showDivider == showDivider) {
return;
}

@ -20,6 +20,7 @@ package org.floens.chan.ui.cell;
import org.floens.chan.core.model.Loadable;
import org.floens.chan.core.model.Post;
import org.floens.chan.core.model.PostLinkable;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.ui.theme.Theme;
import org.floens.chan.ui.view.FloatingMenuItem;
import org.floens.chan.ui.view.ThumbnailView;
@ -27,32 +28,12 @@ import org.floens.chan.ui.view.ThumbnailView;
import java.util.List;
public interface PostCellInterface {
void setPost(Theme theme, Post post, PostCellCallback callback, boolean highlighted, boolean selected, int markedNo, boolean showDivider, PostCellInterface.PostViewMode postViewMode);
void setPost(Theme theme, Post post, PostCellCallback callback, boolean highlighted, boolean selected, int markedNo, boolean showDivider, ChanSettings.PostViewMode postViewMode);
Post getPost();
ThumbnailView getThumbnailView();
enum PostViewMode {
LIST("list"),
CARD("grid");
public String name;
PostViewMode(String name) {
this.name = name;
}
public static PostViewMode find(String name) {
for (PostViewMode mode : PostViewMode.values()) {
if (mode.name.equals(name)) {
return mode;
}
}
return null;
}
}
interface PostCellCallback {
Loadable getLoadable();

@ -48,7 +48,7 @@ public class PostStubCell extends RelativeLayout implements PostCellInterface, V
private boolean bound;
private Theme theme;
private Post post;
private PostViewMode postViewMode;
private ChanSettings.PostViewMode postViewMode;
private boolean showDivider;
private PostCellInterface.PostCellCallback callback;
@ -139,7 +139,7 @@ public class PostStubCell extends RelativeLayout implements PostCellInterface, V
}
public void setPost(Theme theme, final Post post, PostCellInterface.PostCellCallback callback,
boolean highlighted, boolean selected, int markedNo, boolean showDivider, PostCellInterface.PostViewMode postViewMode) {
boolean highlighted, boolean selected, int markedNo, boolean showDivider, ChanSettings.PostViewMode postViewMode) {
if (this.post == post) {
return;
}
@ -191,7 +191,7 @@ public class PostStubCell extends RelativeLayout implements PostCellInterface, V
title.setText(titleText);
}
divider.setVisibility(postViewMode == PostViewMode.CARD ? GONE :
divider.setVisibility(postViewMode == ChanSettings.PostViewMode.CARD ? GONE :
(showDivider ? VISIBLE : GONE));
}

@ -38,7 +38,6 @@ import org.floens.chan.core.model.Pin;
import org.floens.chan.core.presenter.ThreadPresenter;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.ui.adapter.PostsFilter;
import org.floens.chan.ui.cell.PostCellInterface;
import org.floens.chan.ui.layout.ThreadLayout;
import org.floens.chan.ui.toolbar.ToolbarMenu;
import org.floens.chan.ui.toolbar.ToolbarMenuItem;
@ -62,7 +61,7 @@ public class BrowseController extends ThreadController implements ToolbarMenuIte
private final DatabaseManager databaseManager;
private PostCellInterface.PostViewMode postViewMode;
private ChanSettings.PostViewMode postViewMode;
private PostsFilter.Order order;
private List<FloatingMenuItem> boardItems;
@ -80,7 +79,7 @@ public class BrowseController extends ThreadController implements ToolbarMenuIte
public void onCreate() {
super.onCreate();
postViewMode = PostCellInterface.PostViewMode.find(ChanSettings.boardViewMode.get());
postViewMode = ChanSettings.boardViewMode.get();
order = PostsFilter.Order.find(ChanSettings.boardOrder.get());
threadLayout.setPostViewMode(postViewMode);
threadLayout.getPresenter().setOrder(order);
@ -104,7 +103,7 @@ public class BrowseController extends ThreadController implements ToolbarMenuIte
items.add(new FloatingMenuItem(REPLY_ID, R.string.action_reply));
}
items.add(new FloatingMenuItem(SHARE_ID, R.string.action_share));
viewModeMenuItem = new FloatingMenuItem(VIEW_MODE_ID, postViewMode == PostCellInterface.PostViewMode.LIST ?
viewModeMenuItem = new FloatingMenuItem(VIEW_MODE_ID, postViewMode == ChanSettings.PostViewMode.LIST ?
R.string.action_switch_catalog : R.string.action_switch_board);
items.add(viewModeMenuItem);
items.add(new FloatingMenuItem(ORDER_ID, R.string.action_order));
@ -146,16 +145,16 @@ public class BrowseController extends ThreadController implements ToolbarMenuIte
break;
case VIEW_MODE_ID:
if (postViewMode == PostCellInterface.PostViewMode.LIST) {
postViewMode = PostCellInterface.PostViewMode.CARD;
if (postViewMode == ChanSettings.PostViewMode.LIST) {
postViewMode = ChanSettings.PostViewMode.CARD;
} else {
postViewMode = PostCellInterface.PostViewMode.LIST;
postViewMode = ChanSettings.PostViewMode.LIST;
}
ChanSettings.boardViewMode.set(postViewMode.name);
ChanSettings.boardViewMode.set(postViewMode);
viewModeMenuItem.setText(context.getString(
postViewMode == PostCellInterface.PostViewMode.LIST ? R.string.action_switch_catalog : R.string.action_switch_board));
postViewMode == ChanSettings.PostViewMode.LIST ? R.string.action_switch_catalog : R.string.action_switch_board));
threadLayout.setPostViewMode(postViewMode);

@ -56,8 +56,8 @@ import static org.floens.chan.utils.AndroidUtils.getString;
public class MainSettingsController extends SettingsController implements ToolbarMenuItem.ToolbarMenuItemCallback, WatchSettingsController.WatchSettingControllerListener, PassSettingsController.PassSettingControllerListener {
private static final int ADVANCED_SETTINGS = 1;
private ListSettingView<String> imageAutoLoadView;
private ListSettingView<String> videoAutoLoadView;
private ListSettingView<ChanSettings.MediaAutoLoadMode> imageAutoLoadView;
private ListSettingView<ChanSettings.MediaAutoLoadMode> videoAutoLoadView;
private LinkSettingView watchLink;
private LinkSettingView passLink;
@ -225,8 +225,8 @@ public class MainSettingsController extends SettingsController implements Toolba
break;
}
imageAutoLoadTypes.add(new ListSettingView.Item<>(getString(name), mode.name));
videoAutoLoadTypes.add(new ListSettingView.Item<>(getString(name), mode.name));
imageAutoLoadTypes.add(new ListSettingView.Item<ChanSettings.MediaAutoLoadMode>(getString(name), mode));
videoAutoLoadTypes.add(new ListSettingView.Item<ChanSettings.MediaAutoLoadMode>(getString(name), mode));
}
imageAutoLoadView = new ListSettingView<>(this, ChanSettings.imageAutoLoadNetwork, R.string.setting_image_auto_load, imageAutoLoadTypes);
@ -354,21 +354,21 @@ public class MainSettingsController extends SettingsController implements Toolba
}
private void updateVideoLoadModes() {
String currentImageLoadMode = ChanSettings.imageAutoLoadNetwork.get();
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].name.equals(currentImageLoadMode)) {
if (modes[i].getName().equals(currentImageLoadMode.getName())) {
enabled = true;
if (resetVideoMode) {
ChanSettings.videoAutoLoadNetwork.set(modes[i].name);
ChanSettings.videoAutoLoadNetwork.set(modes[i]);
videoAutoLoadView.updateSelection();
onPreferenceChange(videoAutoLoadView);
}
}
videoAutoLoadView.items.get(i).enabled = enabled;
if (!enabled && ChanSettings.videoAutoLoadNetwork.get().equals(modes[i].name)) {
if (!enabled && ChanSettings.videoAutoLoadNetwork.get().getName().equals(modes[i].getName())) {
resetVideoMode = true;
}
}

@ -191,7 +191,7 @@ public class PostRepliesController extends Controller {
final Post p = getItem(position);
boolean showDivider = position < getCount() - 1;
postCell.setPost(null, p, presenter, false, false, data.forPost.no, showDivider, PostCellInterface.PostViewMode.LIST);
postCell.setPost(null, p, presenter, false, false, data.forPost.no, showDivider, ChanSettings.PostViewMode.LIST);
return (View) postCell;
}

@ -45,7 +45,6 @@ import org.floens.chan.core.model.PostLinkable;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.ui.activity.StartActivity;
import org.floens.chan.ui.cell.PostCell;
import org.floens.chan.ui.cell.PostCellInterface;
import org.floens.chan.ui.theme.Theme;
import org.floens.chan.ui.theme.ThemeHelper;
import org.floens.chan.ui.toolbar.NavigationItem;
@ -316,7 +315,7 @@ public class ThemeSettingsController extends Controller implements View.OnClickL
themeContext.getResources().getDimensionPixelSize(R.dimen.toolbar_height)));
PostCell postCell = (PostCell) LayoutInflater.from(themeContext).inflate(R.layout.cell_post, null);
postCell.setPost(theme, post, DUMMY_POST_CALLBACK, false, false, -1, true, PostCellInterface.PostViewMode.LIST);
postCell.setPost(theme, post, DUMMY_POST_CALLBACK, false, false, -1, true, ChanSettings.PostViewMode.LIST);
linearLayout.addView(postCell, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
return linearLayout;

@ -32,7 +32,6 @@ import org.floens.chan.core.model.Loadable;
import org.floens.chan.core.model.Pin;
import org.floens.chan.core.presenter.ThreadPresenter;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.ui.cell.PostCellInterface;
import org.floens.chan.ui.helper.HintPopup;
import org.floens.chan.ui.layout.ThreadLayout;
import org.floens.chan.ui.toolbar.ToolbarMenu;
@ -73,7 +72,7 @@ public class ViewThreadController extends ThreadController implements ThreadLayo
public void onCreate() {
super.onCreate();
threadLayout.setPostViewMode(PostCellInterface.PostViewMode.LIST);
threadLayout.setPostViewMode(ChanSettings.PostViewMode.LIST);
view.setBackgroundColor(getAttrColor(context, R.attr.backcolor));

@ -60,7 +60,6 @@ import org.floens.chan.core.model.ThreadHide;
import org.floens.chan.core.presenter.ThreadPresenter;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.ui.adapter.PostsFilter;
import org.floens.chan.ui.cell.PostCellInterface;
import org.floens.chan.ui.helper.PostPopupHelper;
import org.floens.chan.ui.toolbar.Toolbar;
import org.floens.chan.ui.view.HidingFloatingActionButton;
@ -188,7 +187,7 @@ public class ThreadLayout extends CoordinatorLayout implements ThreadPresenter.T
presenter.requestData();
}
public void setPostViewMode(PostCellInterface.PostViewMode postViewMode) {
public void setPostViewMode(ChanSettings.PostViewMode postViewMode) {
threadListLayout.setPostViewMode(postViewMode);
}

@ -70,7 +70,7 @@ public class ThreadListLayout extends FrameLayout implements ReplyLayout.ReplyLa
private ThreadListLayoutPresenterCallback callback;
private ThreadListLayoutCallback threadListLayoutCallback;
private boolean replyOpen;
private PostCellInterface.PostViewMode postViewMode;
private ChanSettings.PostViewMode postViewMode;
private int spanCount = 2;
private int background;
private boolean searchOpen;
@ -140,12 +140,12 @@ public class ThreadListLayout extends FrameLayout implements ReplyLayout.ReplyLa
spanCount = Math.max(1, Math.round(getMeasuredWidth() / cardWidth));
}
if (postViewMode == PostCellInterface.PostViewMode.CARD) {
if (postViewMode == ChanSettings.PostViewMode.CARD) {
((GridLayoutManager) layoutManager).setSpanCount(spanCount);
}
}
public void setPostViewMode(PostCellInterface.PostViewMode postViewMode) {
public void setPostViewMode(ChanSettings.PostViewMode postViewMode) {
if (this.postViewMode != postViewMode) {
this.postViewMode = postViewMode;

Loading…
Cancel
Save