Add option to select with network type videos should load on

Still depends on the image network type, so the other options are greyed out where appropiate.
For example when you select the image network type to "wifi only", you then can't select the video network type to "all".
The video mode will be set to a lower type automatically when the image mode is changed to something lower.
multisite
Floens 10 years ago
parent 0566c89093
commit db39d68efa
  1. 29
      Clover/app/src/main/java/org/floens/chan/core/presenter/ImageViewerPresenter.java
  2. 15
      Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java
  3. 39
      Clover/app/src/main/java/org/floens/chan/ui/controller/MainSettingsController.java
  4. 42
      Clover/app/src/main/java/org/floens/chan/ui/settings/ListSettingView.java
  5. 23
      Clover/app/src/main/java/org/floens/chan/ui/view/FloatingMenu.java
  6. 25
      Clover/app/src/main/java/org/floens/chan/ui/view/FloatingMenuItem.java

@ -264,25 +264,24 @@ public class ImageViewerPresenter implements MultiImageView.Callback, ViewPager.
private boolean imageAutoLoad(PostImage postImage) {
// Auto load the image when it is cached
if (Chan.getFileCache().exists(postImage.imageUrl)) {
return true;
} else {
String autoLoadMode = ChanSettings.imageAutoLoadNetwork.get();
if (autoLoadMode.equals(ChanSettings.ImageAutoLoadMode.NONE.name)) {
return false;
} else if (autoLoadMode.equals(ChanSettings.ImageAutoLoadMode.WIFI.name)) {
return isConnected(ConnectivityManager.TYPE_WIFI);
} else if (autoLoadMode.equals(ChanSettings.ImageAutoLoadMode.ALL.name)) {
return true;
}
return Chan.getFileCache().exists(postImage.imageUrl) || shouldLoadForNetworkType(ChanSettings.imageAutoLoadNetwork.get());
}
private boolean videoAutoLoad(PostImage postImage) {
return imageAutoLoad(postImage) && shouldLoadForNetworkType(ChanSettings.videoAutoLoadNetwork.get());
}
// Not connected or unrecognized
private boolean shouldLoadForNetworkType(String networkType) {
if (networkType.equals(ChanSettings.MediaAutoLoadMode.NONE.name)) {
return false;
} else if (networkType.equals(ChanSettings.MediaAutoLoadMode.WIFI.name)) {
return isConnected(ConnectivityManager.TYPE_WIFI);
} else if (networkType.equals(ChanSettings.MediaAutoLoadMode.ALL.name)) {
return true;
}
}
private boolean videoAutoLoad(PostImage postImage) {
return imageAutoLoad(postImage) && ChanSettings.videoAutoLoad.get();
// Not connected or unrecognized
return false;
}
private void setTitle(PostImage postImage, int position) {

@ -32,7 +32,7 @@ import java.net.InetSocketAddress;
import java.net.Proxy;
public class ChanSettings {
public enum ImageAutoLoadMode {
public enum MediaAutoLoadMode {
// ALways auto load, either wifi or mobile
ALL("all"),
// Only auto load if on wifi
@ -42,12 +42,12 @@ public class ChanSettings {
public String name;
ImageAutoLoadMode(String name) {
MediaAutoLoadMode(String name) {
this.name = name;
}
public static ImageAutoLoadMode find(String name) {
for (ImageAutoLoadMode mode : ImageAutoLoadMode.values()) {
public static MediaAutoLoadMode find(String name) {
for (MediaAutoLoadMode mode : MediaAutoLoadMode.values()) {
if (mode.name.equals(name)) {
return mode;
}
@ -65,7 +65,7 @@ public class ChanSettings {
public static final BooleanSetting autoRefreshThread;
// public static final BooleanSetting imageAutoLoad;
public static final StringSetting imageAutoLoadNetwork;
public static final BooleanSetting videoAutoLoad;
public static final StringSetting videoAutoLoadNetwork;
public static final BooleanSetting videoOpenExternal;
public static final BooleanSetting videoErrorIgnore;
public static final StringSetting boardViewMode;
@ -132,8 +132,8 @@ public class ChanSettings {
openLinkConfirmation = new BooleanSetting(p, "preference_open_link_confirmation", true);
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", ImageAutoLoadMode.WIFI.name);
videoAutoLoad = new BooleanSetting(p, "preference_autoplay", false);
imageAutoLoadNetwork = new StringSetting(p, "preference_image_auto_load_network", MediaAutoLoadMode.WIFI.name);
videoAutoLoadNetwork = new StringSetting(p, "preference_video_auto_load_network", MediaAutoLoadMode.WIFI.name);
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"
@ -223,6 +223,7 @@ public class ChanSettings {
// preference_board_view_mode default "list"
// preference_board_editor_filler default false
// preference_pass_enabled default false
// preference_autoplay false
}
public static boolean passLoggedIn() {

@ -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 SettingView imageAutoLoadView;
private SettingView videoAutoLoadView;
private ListSettingView imageAutoLoadView;
private ListSettingView videoAutoLoadView;
private LinkSettingView watchLink;
private LinkSettingView passLink;
@ -132,7 +132,7 @@ public class MainSettingsController extends SettingsController implements Toolba
super.onPreferenceChange(item);
if (item == imageAutoLoadView) {
videoAutoLoadView.setEnabled(!ChanSettings.imageAutoLoadNetwork.get().equals(ChanSettings.ImageAutoLoadMode.NONE.name));
updateVideoLoadModes();
} else if (item == fontView || item == fontCondensed) {
EventBus.getDefault().post(new RefreshUIMessage("font"));
}
@ -200,7 +200,8 @@ public class MainSettingsController extends SettingsController implements Toolba
browsing.add(new BooleanSettingView(this, ChanSettings.autoRefreshThread, R.string.setting_auto_refresh_thread, 0));
List<ListSettingView.Item> imageAutoLoadTypes = new ArrayList<>();
for (ChanSettings.ImageAutoLoadMode mode : ChanSettings.ImageAutoLoadMode.values()) {
List<ListSettingView.Item> videoAutoLoadTypes = new ArrayList<>();
for (ChanSettings.MediaAutoLoadMode mode : ChanSettings.MediaAutoLoadMode.values()) {
int name = 0;
switch (mode) {
case ALL:
@ -215,10 +216,15 @@ public class MainSettingsController extends SettingsController implements Toolba
}
imageAutoLoadTypes.add(new ListSettingView.Item(getString(name), mode.name));
videoAutoLoadTypes.add(new ListSettingView.Item(getString(name), mode.name));
}
imageAutoLoadView = browsing.add(new ListSettingView(this, ChanSettings.imageAutoLoadNetwork, R.string.setting_image_auto_load, imageAutoLoadTypes.toArray(new ListSettingView.Item[imageAutoLoadTypes.size()])));
videoAutoLoadView = browsing.add(new BooleanSettingView(this, ChanSettings.videoAutoLoad, R.string.setting_video_auto_load, R.string.setting_video_auto_load_description));
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));
browsing.add(new LinkSettingView(this, R.string.setting_clear_thread_hides, 0, new View.OnClickListener() {
@Override
@ -335,4 +341,25 @@ public class MainSettingsController extends SettingsController implements Toolba
groups.add(about);
}
private void updateVideoLoadModes() {
String 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)) {
enabled = true;
if (resetVideoMode) {
ChanSettings.videoAutoLoadNetwork.set(modes[i].name);
videoAutoLoadView.updateSelection();
onPreferenceChange(videoAutoLoadView);
}
}
videoAutoLoadView.items.get(i).enabled = enabled;
if (!enabled && ChanSettings.videoAutoLoadNetwork.get().equals(modes[i].name)) {
resetVideoMode = true;
}
}
}
}

@ -26,12 +26,13 @@ import org.floens.chan.ui.view.FloatingMenu;
import org.floens.chan.ui.view.FloatingMenuItem;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.floens.chan.utils.AndroidUtils.dp;
public class ListSettingView extends SettingView implements FloatingMenu.FloatingMenuCallback, View.OnClickListener {
public final Item[] items;
public final List<Item> items;
private Setting<String> setting;
@ -46,28 +47,36 @@ public class ListSettingView extends SettingView implements FloatingMenu.Floatin
this.setting = setting;
items = new Item[itemNames.length];
items = new ArrayList<>(itemNames.length);
for (int i = 0; i < itemNames.length; i++) {
items[i] = new Item(itemNames[i], keys[i]);
items.add(i, new Item(itemNames[i], keys[i]));
}
selectItem();
updateSelection();
}
public ListSettingView(SettingsController settingsController, Setting<String> setting, int name, Item[] items) {
this(settingsController, setting, getString(name), items);
}
public ListSettingView(SettingsController settingsController, Setting<String> setting, int name, List<Item> items) {
this(settingsController, setting, getString(name), items);
}
public ListSettingView(SettingsController settingsController, Setting<String> setting, String name, Item[] items) {
this(settingsController, setting, name, Arrays.asList(items));
}
public ListSettingView(SettingsController settingsController, Setting<String> setting, String name, List<Item> items) {
super(settingsController, name);
this.setting = setting;
this.items = items;
selectItem();
updateSelection();
}
public String getBottomDescription() {
return items[selected].name;
return items.get(selected).name;
}
public Setting<String> getSetting() {
@ -92,10 +101,9 @@ public class ListSettingView extends SettingView implements FloatingMenu.Floatin
@Override
public void onClick(View v) {
List<FloatingMenuItem> menuItems = new ArrayList<>(2);
List<FloatingMenuItem> menuItems = new ArrayList<>(items.size());
for (Item item : items) {
menuItems.add(new FloatingMenuItem(item.key, item.name));
menuItems.add(new FloatingMenuItem(item.key, item.name, item.enabled));
}
FloatingMenu menu = new FloatingMenu(v.getContext());
@ -110,7 +118,7 @@ public class ListSettingView extends SettingView implements FloatingMenu.Floatin
public void onFloatingMenuItemClicked(FloatingMenu menu, FloatingMenuItem item) {
String selectedKey = (String) item.getId();
setting.set(selectedKey);
selectItem();
updateSelection();
settingsController.onPreferenceChange(this);
}
@ -118,10 +126,10 @@ public class ListSettingView extends SettingView implements FloatingMenu.Floatin
public void onFloatingMenuDismissed(FloatingMenu menu) {
}
private void selectItem() {
public void updateSelection() {
String selectedKey = setting.get();
for (int i = 0; i < items.length; i++) {
if (items[i].key.equals(selectedKey)) {
for (int i = 0; i < items.size(); i++) {
if (items.get(i).key.equals(selectedKey)) {
selected = i;
break;
}
@ -131,10 +139,18 @@ public class ListSettingView extends SettingView implements FloatingMenu.Floatin
public static class Item {
public final String name;
public final String key;
public boolean enabled;
public Item(String name, String key) {
this.name = name;
this.key = key;
enabled = true;
}
public Item(String name, String key, boolean enabled) {
this.name = name;
this.key = key;
this.enabled = enabled;
}
}
}

@ -34,10 +34,10 @@ import org.floens.chan.R;
import org.floens.chan.utils.AndroidUtils;
import org.floens.chan.utils.Logger;
import java.util.ArrayList;
import java.util.List;
import static org.floens.chan.utils.AndroidUtils.dp;
import static org.floens.chan.utils.AndroidUtils.getAttrColor;
public class FloatingMenu {
public static final int POPUP_WIDTH_AUTO = -1;
@ -118,10 +118,8 @@ public class FloatingMenu {
popupWindow.setContentWidth(popupWidth);
}
List<String> stringItems = new ArrayList<>(items.size());
int selectedPosition = 0;
for (int i = 0; i < items.size(); i++) {
stringItems.add(items.get(i).getText());
if (items.get(i) == selectedItem) {
selectedPosition = i;
}
@ -130,15 +128,18 @@ public class FloatingMenu {
if (adapter != null) {
popupWindow.setAdapter(adapter);
} else {
popupWindow.setAdapter(new FloatingMenuArrayAdapter(context, R.layout.toolbar_menu_item, stringItems));
popupWindow.setAdapter(new FloatingMenuArrayAdapter(context, R.layout.toolbar_menu_item, items));
}
popupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position >= 0 && position < items.size()) {
callback.onFloatingMenuItemClicked(FloatingMenu.this, items.get(position));
popupWindow.dismiss();
FloatingMenuItem item = items.get(position);
if (item.isEnabled()) {
callback.onFloatingMenuItemClicked(FloatingMenu.this, item);
popupWindow.dismiss();
}
} else {
callback.onFloatingMenuItemClicked(FloatingMenu.this, null);
}
@ -193,8 +194,8 @@ public class FloatingMenu {
void onFloatingMenuDismissed(FloatingMenu menu);
}
private static class FloatingMenuArrayAdapter extends ArrayAdapter<String> {
public FloatingMenuArrayAdapter(Context context, int resource, List<String> objects) {
private static class FloatingMenuArrayAdapter extends ArrayAdapter<FloatingMenuItem> {
public FloatingMenuArrayAdapter(Context context, int resource, List<FloatingMenuItem> objects) {
super(context, resource, objects);
}
@ -204,8 +205,12 @@ public class FloatingMenu {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.toolbar_menu_item, parent, false);
}
FloatingMenuItem item = getItem(position);
TextView textView = (TextView) convertView;
textView.setText(getItem(position));
textView.setText(item.getText());
textView.setEnabled(item.isEnabled());
textView.setTextColor(getAttrColor(getContext(), item.isEnabled() ? R.attr.text_color_primary : R.attr.text_color_hint));
textView.setTypeface(AndroidUtils.ROBOTO_MEDIUM);
return textView;

@ -22,15 +22,24 @@ import static org.floens.chan.utils.AndroidUtils.getString;
public class FloatingMenuItem {
private Object id;
private String text;
private boolean enabled = true;
public FloatingMenuItem(Object id, int text) {
this(id, getString(text));
}
public FloatingMenuItem(Object id, int text, boolean enabled) {
this(id, getString(text), enabled);
}
public FloatingMenuItem(Object id, String text) {
this.id = id;
this.text = text;
this(id, text, true);
}
public FloatingMenuItem(Object id, int text) {
public FloatingMenuItem(Object id, String text, boolean enabled) {
this.id = id;
this.text = getString(text);
this.text = text;
this.enabled = enabled;
}
public Object getId() {
@ -48,4 +57,12 @@ public class FloatingMenuItem {
public void setText(String text) {
this.text = text;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

Loading…
Cancel
Save