Add settings to watch settings

tempwork
Floens 10 years ago
parent 27ea0fb78f
commit d2eb9f6e51
  1. 8
      Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java
  2. 8
      Clover/app/src/main/java/org/floens/chan/ui/controller/MainSettingsController.java
  3. 54
      Clover/app/src/main/java/org/floens/chan/ui/controller/WatchSettingsController.java
  4. 19
      Clover/app/src/main/java/org/floens/chan/ui/preferences/ListSettingView.java
  5. 18
      Clover/app/src/main/java/org/floens/chan/ui/preferences/SettingsController.java
  6. 21
      Clover/app/src/main/java/org/floens/chan/utils/AndroidUtils.java
  7. 28
      Clover/app/src/main/res/values/strings.xml

@ -50,6 +50,10 @@ public class ChanSettings {
public static BooleanSetting watchCountdown;
public static BooleanSetting watchBackground;
public static StringSetting watchBackgroundTimeout;
public static StringSetting watchNotifyMode;
public static StringSetting watchSound;
public static StringSetting watchLed;
static {
SharedPreferences p = AndroidUtils.getPreferences();
@ -78,6 +82,10 @@ public class ChanSettings {
watchCountdown = new BooleanSetting(p, "preference_watch_countdown", false);
watchBackground = new BooleanSetting(p, "preference_watch_background_enabled", false);
watchBackgroundTimeout = new StringSetting(p, "preference_watch_background_timeout", "60");
watchNotifyMode = new StringSetting(p, "preference_watch_notify_mode", "all");
watchSound = new StringSetting(p, "preference_watch_sound", "all");
watchLed = new StringSetting(p, "preference_watch_led", "ffffffff");
}
private static SharedPreferences p() {

@ -127,15 +127,15 @@ public class MainSettingsController extends SettingsController implements Toolba
SettingsGroup browsing = new SettingsGroup(s(R.string.settings_group_browsing));
browsing.add(new ListSettingView(this, ChanSettings.theme, s(R.string.setting_theme), new ListSettingView.Item[]{
new ListSettingView.Item<>(s(R.string.setting_theme_light), "light"),
new ListSettingView.Item<>(s(R.string.setting_theme_dark), "dark"),
new ListSettingView.Item<>(s(R.string.setting_theme_black), "black")
new ListSettingView.Item(s(R.string.setting_theme_light), "light"),
new ListSettingView.Item(s(R.string.setting_theme_dark), "dark"),
new ListSettingView.Item(s(R.string.setting_theme_black), "black")
}));
List<ListSettingView.Item> fontSizes = new ArrayList<>();
for (int size = 10; size <= 19; size++) {
String name = size + (String.valueOf(size).equals(ChanSettings.fontSize.getDefault()) ? " " + s(R.string.setting_font_size_default) : "");
fontSizes.add(new ListSettingView.Item<>(name, String.valueOf(size)));
fontSizes.add(new ListSettingView.Item(name, String.valueOf(size)));
}
browsing.add(new ListSettingView(this, ChanSettings.fontSize, s(R.string.setting_font_size), fontSizes.toArray(new ListSettingView.Item[fontSizes.size()])));

@ -1,19 +1,29 @@
package org.floens.chan.ui.controller;
import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import org.floens.chan.R;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.ui.preferences.BooleanSettingView;
import org.floens.chan.ui.preferences.ListSettingView;
import org.floens.chan.ui.preferences.SettingView;
import org.floens.chan.ui.preferences.SettingsController;
import org.floens.chan.ui.preferences.SettingsGroup;
import org.floens.chan.utils.AndroidUtils;
public class WatchSettingsController extends SettingsController {
public WatchSettingsController(Context context) {
super(context);
}
private SettingView enableBackground;
private SettingView backgroundTimeout;
private SettingView notifyMode;
private SettingView soundMode;
private SettingView ledMode;
@Override
public void onCreate() {
super.onCreate();
@ -26,13 +36,55 @@ public class WatchSettingsController extends SettingsController {
populatePreferences();
buildPreferences();
setEnabledHeights();
}
@Override
public void onPreferenceChange(SettingView item) {
super.onPreferenceChange(item);
if (item == enableBackground) {
boolean enabled = ChanSettings.watchBackground.get();
AndroidUtils.animateHeight(backgroundTimeout.view, enabled);
AndroidUtils.animateHeight(notifyMode.view, enabled);
AndroidUtils.animateHeight(soundMode.view, enabled);
AndroidUtils.animateHeight(ledMode.view, enabled);
}
}
private void setEnabledHeights() {
if (!ChanSettings.watchBackground.get()) {
backgroundTimeout.view.setVisibility(View.GONE);
notifyMode.view.setVisibility(View.GONE);
soundMode.view.setVisibility(View.GONE);
ledMode.view.setVisibility(View.GONE);
}
}
private void populatePreferences() {
SettingsGroup settings = new SettingsGroup(string(R.string.settings_group_watch));
settings.add(new BooleanSettingView(this, ChanSettings.watchCountdown, string(R.string.setting_watch_countdown), string(R.string.setting_watch_countdown_description)));
settings.add(new BooleanSettingView(this, ChanSettings.watchBackground, string(R.string.setting_watch_enable_background), string(R.string.setting_watch_enable_background_description)));
enableBackground = settings.add(new BooleanSettingView(this, ChanSettings.watchBackground, string(R.string.setting_watch_enable_background), string(R.string.setting_watch_enable_background_description)));
int[] timeouts = new int[]{1, 2, 3, 5, 10, 30, 60};
ListSettingView.Item[] timeoutsItems = new ListSettingView.Item[timeouts.length];
for (int i = 0; i < timeouts.length; i++) {
String name = context.getResources().getQuantityString(R.plurals.minutes, timeouts[i], timeouts[i]);
timeoutsItems[i] = new ListSettingView.Item(name, String.valueOf(timeouts[i]));
}
backgroundTimeout = settings.add(new ListSettingView(this, ChanSettings.watchBackgroundTimeout, string(R.string.setting_watch_background_timeout), timeoutsItems));
notifyMode = settings.add(new ListSettingView(this, ChanSettings.watchNotifyMode, string(R.string.setting_watch_notify_mode),
context.getResources().getStringArray(R.array.setting_watch_notify_modes), new String[]{"all", "quotes"}));
soundMode = settings.add(new ListSettingView(this, ChanSettings.watchSound, string(R.string.setting_watch_sound),
context.getResources().getStringArray(R.array.setting_watch_sounds), new String[]{"all", "quotes"}));
ledMode = settings.add(new ListSettingView(this, ChanSettings.watchLed, string(R.string.setting_watch_led),
context.getResources().getStringArray(R.array.setting_watch_leds),
new String[]{"-1", "ffffffff", "ffff0000", "ffffff00", "ff00ff00", "ff00ffff", "ff0000ff", "ffff00ff"}));
groups.add(settings);
}

@ -20,6 +20,19 @@ public class ListSettingView extends SettingView implements FloatingMenu.Floatin
private int selected;
public ListSettingView(SettingsController settingsController, Setting<String> setting, String name, String[] itemNames, String[] keys) {
super(settingsController, name);
this.setting = setting;
items = new Item[itemNames.length];
for (int i = 0; i < itemNames.length; i++) {
items[i] = new Item(itemNames[i], keys[i]);
}
selectItem();
}
public ListSettingView(SettingsController settingsController, Setting<String> setting, String name, Item[] items) {
super(settingsController, name);
this.setting = setting;
@ -86,11 +99,11 @@ public class ListSettingView extends SettingView implements FloatingMenu.Floatin
}
}
public static class Item<T> {
public static class Item {
public final String name;
public final T key;
public final String key;
public Item(String name, T key) {
public Item(String name, String key) {
this.name = name;
this.key = key;
}

@ -5,7 +5,6 @@ import android.content.res.Configuration;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -132,23 +131,6 @@ public class SettingsController extends Controller implements AndroidUtils.OnMea
}
AndroidUtils.animateHeight(bottom, bottomText != null);
if (bottom.getAnimation() != null) {
bottom.getAnimation().setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
bottom.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
} else {
bottom.setText(bottomText);
bottom.setVisibility(bottomText == null ? View.GONE : View.VISIBLE);

@ -34,6 +34,7 @@ import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;
@ -236,8 +237,8 @@ public class AndroidUtils {
return views;
}
public static void animateHeight(View view, boolean expand) {
if ((view.getHeight() > 0 && expand) || (view.getHeight() == 0 && !expand)) {
public static void animateHeight(final View view, boolean expand) {
if (view.getAnimation() == null && ((view.getHeight() > 0 && expand) || (view.getHeight() == 0 && !expand))) {
return;
}
@ -252,5 +253,21 @@ public class AndroidUtils {
heightAnimation = new HeightAnimation(view, view.getHeight(), 0, 300);
}
view.startAnimation(heightAnimation);
view.getAnimation().setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
view.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
}

@ -27,6 +27,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<string name="on">On</string>
<string name="off">Off</string>
<plurals name="minutes">
<item quantity="one">%d minute</item>
<item quantity="other">%d minutes</item>
</plurals>
<string name="action_settings">Settings</string>
<string name="action_reload">Reload</string>
<string name="action_reload_board">Reload board</string>
@ -200,7 +205,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<string name="setting_watch_countdown_description">Show a countdown left of the new post counter</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">Time between loads in 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 and vibrate</string>
<string-array name="setting_watch_sounds">
<item>All posts</item>
<item>Only posts quoting you</item>
</string-array>
<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>

Loading…
Cancel
Save