Skip to content

Commit

Permalink
only new posts preference
Browse files Browse the repository at this point in the history
  • Loading branch information
miku-nyan committed May 27, 2016
1 parent 6e21675 commit 8f97902
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 78 deletions.
2 changes: 0 additions & 2 deletions res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

<string name="infinity_tor_message">Um 8chan über Tor zu senden, müssen Sie den .onion Domain verwenden.</string>

<string name="inach_prefs_ajax_update">JSON-Update</string>

<string name="fourchan_prefs_new_recaptcha">Recaptcha 2.0</string>
<string name="fourchan_prefs_new_recaptcha_summary">Die neue Version von Recaptcha verwenden</string>
<string name="fourchan_prefs_new_recaptcha_fallback">Recaptcha 2.0 Fallback</string>
Expand Down
2 changes: 0 additions & 2 deletions res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

<string name="infinity_tor_message">Чтобы постить на 8chan через Tor, вы должны использовать .onion домен.</string>

<string name="inach_prefs_ajax_update">JSON обновление</string>

<string name="fourchan_prefs_new_recaptcha">Recaptcha 2.0</string>
<string name="fourchan_prefs_new_recaptcha_summary">Использовать новую версию Recaptcha</string>
<string name="fourchan_prefs_new_recaptcha_fallback">Recaptcha 2.0 fallback</string>
Expand Down
2 changes: 0 additions & 2 deletions res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

<string name="infinity_tor_message">Домен .onion потрібен, щоб постити на 8ch через Tor.</string>

<string name="inach_prefs_ajax_update">JSON-оновлення</string>

<string name="fourchan_prefs_new_recaptcha">Recaptcha 2.0</string>
<string name="fourchan_prefs_new_recaptcha_summary">Використовувати нову версію Recaptcha</string>
<string name="fourchan_prefs_new_recaptcha_fallback">Recaptcha 2.0 fallback</string>
Expand Down
2 changes: 0 additions & 2 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

<string name="infinity_tor_message">To post on 8chan over Tor, you must use the .onion domain.</string>

<string name="inach_prefs_ajax_update">JSON Update</string>

<string name="fourchan_prefs_new_recaptcha">Recaptcha 2.0</string>
<string name="fourchan_prefs_new_recaptcha_summary">Use the new version of Recaptcha</string>
<string name="fourchan_prefs_new_recaptcha_fallback">Recaptcha 2.0 fallback</string>
Expand Down
30 changes: 30 additions & 0 deletions src/nya/miku/wishmaster/api/AbstractChanModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public abstract class AbstractChanModule implements HttpChanModule {
protected static final String PREF_KEY_PROXY_PORT = "PREF_KEY_PROXY_PORT";
protected static final String PREF_KEY_PASSWORD = "PREF_KEY_PASSWORD";
protected static final String PREF_KEY_USE_HTTPS = "PREF_KEY_USE_HTTPS";
protected static final String PREF_KEY_ONLY_NEW_POSTS = "PREF_KEY_ONLY_NEW_POSTS";

/**
* Основной HTTP-клиент
Expand Down Expand Up @@ -277,6 +278,35 @@ protected boolean useHttps(boolean defaultValue) {
return preferences.getBoolean(getSharedKey(PREF_KEY_USE_HTTPS), defaultValue);
}

/**
* Добавить в группу параметров (на экран/в категорию) настройку выбора использования инкрементальной загрузки (загрузки только новых постов).
* Для хранения используется ключ общих параметров {@link #PREF_KEY_ONLY_NEW_POSTS} ({@link #getSharedKey(String)}).
* См. также: {@link #loadOnlyNewPosts(boolean)} - для получения значения параметра.
* @param group группа, на которую добавляется параметр
* @param defaultValue значение параметра по умолчанию
* return объект {@link CheckBoxPreference} с параметром
*/
protected CheckBoxPreference addOnlyNewPostsPreference(PreferenceGroup group, boolean defaultValue) {
final Context context = group.getContext();
CheckBoxPreference onlyNewPostsPref = new CheckBoxPreference(context);
onlyNewPostsPref.setTitle(R.string.pref_only_new_posts);
onlyNewPostsPref.setSummary(R.string.pref_only_new_posts_summary);
onlyNewPostsPref.setKey(getSharedKey(PREF_KEY_ONLY_NEW_POSTS));
onlyNewPostsPref.setDefaultValue(defaultValue);
group.addPreference(onlyNewPostsPref);
return onlyNewPostsPref;
}

/**
* Определить значение параметра использования инкрементальной загрузки из ключа общих настроек {@link #PREF_KEY_ONLY_NEW_POSTS}.
* Настройка добавляется на экран (в группу) настроек методом {@link #addOnlyNewPostsPreference(PreferenceGroup, boolean)}.
* @param defaultValue значение параметра по умолчанию
* @return значение параметра
*/
protected boolean loadOnlyNewPosts(boolean defaultValue) {
return preferences.getBoolean(getSharedKey(PREF_KEY_ONLY_NEW_POSTS), defaultValue);
}

@Override
public String getDefaultPassword() {
return preferences.getString(getSharedKey(PREF_KEY_PASSWORD), "");
Expand Down
9 changes: 2 additions & 7 deletions src/nya/miku/wishmaster/chans/allchan/AllchanModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public class AllchanModule extends CloudflareChanModule {

private static final String RECAPTCHA_PUBLIC_KEY = "6LfKRgcTAAAAAIe-bmV_pCbMzvKvBZGbZNRsfmED";

private static final String PREF_KEY_ONLY_NEW_POSTS = "PREF_KEY_ONLY_NEW_POSTS";
private static final String PREF_KEY_CAPTCHA_TYPE = "PREF_KEY_CAPTCHA_TYPE";

public static final String[] CATALOG_TYPES = new String[] { "date", "recent", "bumps" };
Expand Down Expand Up @@ -141,11 +140,7 @@ protected String getCloudflareCookieDomain() {
@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
Context context = preferenceGroup.getContext();
CheckBoxPreference onlyNewPostsPreference = new CheckBoxPreference(context); //only_new_posts
onlyNewPostsPreference.setTitle(R.string.pref_only_new_posts);
onlyNewPostsPreference.setKey(getSharedKey(PREF_KEY_ONLY_NEW_POSTS));
onlyNewPostsPreference.setDefaultValue(true);
preferenceGroup.addPreference(onlyNewPostsPreference);
addOnlyNewPostsPreference(preferenceGroup, true);
final ListPreference captchaPreference = new ListPreference(context); //captcha_type
captchaPreference.setTitle(R.string.pref_captcha_type);
captchaPreference.setDialogTitle(R.string.pref_captcha_type);
Expand Down Expand Up @@ -183,7 +178,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}

private boolean loadOnlyNewPosts() {
return preferences.getBoolean(getSharedKey(PREF_KEY_ONLY_NEW_POSTS), true);
return loadOnlyNewPosts(true);
}

private int getUsingCaptchaType() {
Expand Down
15 changes: 2 additions & 13 deletions src/nya/miku/wishmaster/chans/dobrochan/DobroModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public class DobroModule extends AbstractChanModule {

private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);

private static final String PREF_KEY_ONLY_NEW_POSTS = "PREF_KEY_ONLY_NEW_POSTS";
private static final String PREF_KEY_MAX_RATING = "PREF_KEY_MAX_RATING";
private static final String PREF_KEY_SHOW_CAPTCHA = "PREF_KEY_SHOW_CAPTCHA";
private static final String PREF_KEY_DOMAIN = "PREF_KEY_DOMAIN";
Expand Down Expand Up @@ -174,18 +173,8 @@ protected JSONObject downloadJSONObject(String url, boolean checkIfModidied, Pro
return response;
}

private void addOnlyNewPostsPreference(PreferenceGroup group) {
Context context = group.getContext();
CheckBoxPreference onlyNewPostsPreference = new CheckBoxPreference(context);
onlyNewPostsPreference.setTitle(R.string.pref_only_new_posts);
onlyNewPostsPreference.setSummary(R.string.pref_only_new_posts_summary);
onlyNewPostsPreference.setKey(getSharedKey(PREF_KEY_ONLY_NEW_POSTS));
onlyNewPostsPreference.setDefaultValue(true);
group.addPreference(onlyNewPostsPreference);
}

private boolean loadOnlyNewPosts() {
return preferences.getBoolean(getSharedKey(PREF_KEY_ONLY_NEW_POSTS), true);
return loadOnlyNewPosts(true);
}

private void addDomainPreferences(PreferenceGroup group) {
Expand Down Expand Up @@ -262,7 +251,7 @@ private void addCaptchaPreference(PreferenceGroup group) {

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
addOnlyNewPostsPreference(preferenceGroup);
addOnlyNewPostsPreference(preferenceGroup, true);
addRatingPreference(preferenceGroup);
addCaptchaPreference(preferenceGroup);
addDomainPreferences(preferenceGroup);
Expand Down
10 changes: 2 additions & 8 deletions src/nya/miku/wishmaster/chans/horochan/HorochanModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public class HorochanModule extends CloudflareChanModule {

private static final String[] ATTACHMENT_FORMATS = new String[] { "gif", "jpg", "jpeg", "png", "bmp", "webm" };

private static final String PREF_KEY_ONLY_NEW_POSTS = "PREF_KEY_ONLY_NEW_POSTS";
private static final String PREF_KEY_RECAPTCHA_FALLBACK = "PREF_KEY_RECAPTCHA_FALLBACK";

private Map<String, String> boardNames = null;
Expand Down Expand Up @@ -136,12 +135,7 @@ protected String getCloudflareCookieDomain() {
@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
Context context = preferenceGroup.getContext();
CheckBoxPreference onlyNewPostsPreference = new CheckBoxPreference(context); //only_new_posts
onlyNewPostsPreference.setTitle(R.string.pref_only_new_posts);
onlyNewPostsPreference.setSummary(R.string.pref_only_new_posts_summary);
onlyNewPostsPreference.setKey(getSharedKey(PREF_KEY_ONLY_NEW_POSTS));
onlyNewPostsPreference.setDefaultValue(true);
preferenceGroup.addPreference(onlyNewPostsPreference);
addOnlyNewPostsPreference(preferenceGroup, true);
CheckBoxPreference fallbackRecaptchaPref = new CheckBoxPreference(context); // recaptcha fallback
fallbackRecaptchaPref.setTitle(R.string.fourchan_prefs_new_recaptcha_fallback);
fallbackRecaptchaPref.setSummary(R.string.fourchan_prefs_new_recaptcha_fallback_summary);
Expand All @@ -154,7 +148,7 @@ public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
}

private boolean loadOnlyNewPosts() {
return preferences.getBoolean(getSharedKey(PREF_KEY_ONLY_NEW_POSTS), true);
return loadOnlyNewPosts(true);
}

private boolean recaptchaFallback() {
Expand Down
10 changes: 1 addition & 9 deletions src/nya/miku/wishmaster/chans/inach/InachModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@
import cz.msebera.android.httpclient.client.entity.UrlEncodedFormEntity;
import cz.msebera.android.httpclient.message.BasicNameValuePair;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceGroup;
import android.support.v4.content.res.ResourcesCompat;
import nya.miku.wishmaster.R;
Expand Down Expand Up @@ -117,13 +115,7 @@ protected String getUsingDomain() {

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
Context context = preferenceGroup.getContext();
CheckBoxPreference ajaxPref = new CheckBoxPreference(context);
ajaxPref.setTitle(R.string.inach_prefs_ajax_update);
ajaxPref.setSummary(R.string.pref_only_new_posts_summary);
ajaxPref.setKey(getSharedKey(PREF_AJAX_UPDATE));
ajaxPref.setDefaultValue(true);
preferenceGroup.addPreference(ajaxPref);
addOnlyNewPostsPreference(preferenceGroup, true);
super.addPreferencesOnScreen(preferenceGroup);
}

Expand Down
19 changes: 2 additions & 17 deletions src/nya/miku/wishmaster/chans/nullchan/AbstractInstant0chan.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,11 @@
import java.util.regex.Pattern;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceGroup;
import cz.msebera.android.httpclient.NameValuePair;
import cz.msebera.android.httpclient.message.BasicNameValuePair;
import nya.miku.wishmaster.R;
import nya.miku.wishmaster.api.AbstractKusabaModule;
import nya.miku.wishmaster.api.interfaces.CancellableTask;
import nya.miku.wishmaster.api.interfaces.ProgressListener;
Expand All @@ -56,29 +53,17 @@
import nya.miku.wishmaster.http.ExtendedMultipartBuilder;

public abstract class AbstractInstant0chan extends AbstractKusabaModule {
private static final String PREF_KEY_ONLY_NEW_POSTS = "PREF_KEY_ONLY_NEW_POSTS";

public AbstractInstant0chan(SharedPreferences preferences, Resources resources) {
super(preferences, resources);
}

protected void addOnlyNewPostsPreference(PreferenceGroup group) {
Context context = group.getContext();
CheckBoxPreference onlyNewPostsPreference = new CheckBoxPreference(context);
onlyNewPostsPreference.setTitle(R.string.pref_only_new_posts);
onlyNewPostsPreference.setSummary(R.string.pref_only_new_posts_summary);
onlyNewPostsPreference.setKey(getSharedKey(PREF_KEY_ONLY_NEW_POSTS));
onlyNewPostsPreference.setDefaultValue(true);
group.addPreference(onlyNewPostsPreference);
}

protected boolean loadOnlyNewPosts() {
return preferences.getBoolean(getSharedKey(PREF_KEY_ONLY_NEW_POSTS), true);
return loadOnlyNewPosts(true);
}

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
addOnlyNewPostsPreference(preferenceGroup);
addOnlyNewPostsPreference(preferenceGroup, true);
super.addPreferencesOnScreen(preferenceGroup);
}

Expand Down
18 changes: 2 additions & 16 deletions src/nya/miku/wishmaster/chans/sevenchan/SevenchanModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@
import nya.miku.wishmaster.api.util.WakabaReader;
import nya.miku.wishmaster.http.ExtendedMultipartBuilder;
import nya.miku.wishmaster.http.recaptcha.Recaptcha;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceGroup;
import android.support.v4.content.res.ResourcesCompat;

Expand All @@ -52,8 +50,6 @@ public class SevenchanModule extends AbstractKusabaModule {

private static final Pattern THREAD_REFERENCE_ALT = Pattern.compile("read.php\\?b=([^&]+)&t=(\\d+)(?:&p=)?(\\d*).*");

private static final String PREF_KEY_ONLY_NEW_POSTS = "PREF_KEY_ONLY_NEW_POSTS";

private static final SimpleBoardModel[] BOARDS = new SimpleBoardModel[] {
ChanModels.obtainSimpleBoardModel(CHAN_NAME, "7ch", "Site Discussion", "7chan & Related Services", false),
ChanModels.obtainSimpleBoardModel(CHAN_NAME, "ch7", "Channel7 & Radio7", "7chan & Related Services", true),
Expand Down Expand Up @@ -139,23 +135,13 @@ protected boolean canCloudflare() {
return true;
}

private void addOnlyNewPostsPreference(PreferenceGroup group) {
Context context = group.getContext();
CheckBoxPreference onlyNewPostsPreference = new CheckBoxPreference(context);
onlyNewPostsPreference.setTitle(R.string.pref_only_new_posts);
onlyNewPostsPreference.setSummary(R.string.pref_only_new_posts_summary);
onlyNewPostsPreference.setKey(getSharedKey(PREF_KEY_ONLY_NEW_POSTS));
onlyNewPostsPreference.setDefaultValue(true);
group.addPreference(onlyNewPostsPreference);
}

private boolean loadOnlyNewPosts() {
return preferences.getBoolean(getSharedKey(PREF_KEY_ONLY_NEW_POSTS), true);
return loadOnlyNewPosts(true);
}

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
addOnlyNewPostsPreference(preferenceGroup);
addOnlyNewPostsPreference(preferenceGroup, true);
super.addPreferencesOnScreen(preferenceGroup);
}

Expand Down

0 comments on commit 8f97902

Please sign in to comment.