Skip to content

Commit

Permalink
Prepared for #7 auto refresh by adding a system setting (and moving h…
Browse files Browse the repository at this point in the history
…elp options to a separate screen).
  • Loading branch information
erickok committed Feb 7, 2014
1 parent 35831ca commit df030db
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 72 deletions.
4 changes: 4 additions & 0 deletions core/res/values/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
-->
<resources>
<string name="system_changelog">
Transdroid 2.1.2\n
- Support for new Torrent Search\'s private sites\n
- Added optional auto refresh\n
\n
Transdroid 2.1.1\n
- Improved handling of RSS feed read state\n
- Fixes Xirvik seedbox configuration\n
Expand Down
18 changes: 18 additions & 0 deletions core/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@
<string name="pref_adw_info">Show torrent counter in ADW Launcher</string>

<string name="pref_system">System</string>
<string name="pref_autorefresh">Automatic refreshing</string>
<string name="pref_autorefresh_info">Interval-based refresh of the main screen</string>
<string-array name="pref_autorefresh_intervals">
<item>Disabled</item>
<item>2 seconds</item>
<item>5 seconds</item>
<item>10 seconds</item>
<item>30 seconds</item>
</string-array>
<string-array name="pref_autorefresh_intervalvalues" translatable="false">
<item>0</item>
<item>2</item>
<item>5</item>
<item>10</item>
<item>30</item>
</string-array>
<string name="pref_dormantasinactive">Treat dormant torrents as inactive</string>
<string name="pref_dormantasinactive_info">Torrents at 0KB/s (no data transfer) will be filtered as being inactive</string>
<string name="pref_checkupdates">Check for updates</string>
Expand All @@ -293,6 +309,8 @@
<string name="pref_export">Export settings</string>
<string name="pref_export_dialog">%1$s will export server (including passwords), web search, RSS and system settings to the following plain text JSON file: %2$s</string>
<string name="pref_export_success">Settings successfully exported</string>

<string name="pref_help">Transdroid help</string>
<string name="pref_sendlog">Send error log</string>
<string name="pref_sendlog_info">Get support or report a bug</string>
<string name="pref_installhelp">View install guides</string>
Expand Down
37 changes: 37 additions & 0 deletions core/res/xml/pref_help.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2010-2013 Eric Kok et al.
Transdroid 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.
Transdroid 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 Transdroid. If not, see <http://www.gnu.org/licenses/>.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<Preference
android:key="system_sendlog"
android:title="@string/pref_sendlog"
android:summary="@string/pref_sendlog_info" />

<Preference
android:key="system_installhelp"
android:title="@string/pref_installhelp"
android:summary="@string/pref_installhelp_info" />

<Preference
android:key="system_changelog"
android:title="@string/pref_changelog" />

<Preference
android:key="system_about" />

</PreferenceScreen>
4 changes: 4 additions & 0 deletions core/res/xml/pref_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
android:key="header_system"
android:title="@string/pref_system"
android:order="302" />
<Preference
android:key="header_help"
android:title="@string/pref_help"
android:order="303" />
</PreferenceCategory>

</PreferenceScreen>
33 changes: 12 additions & 21 deletions core/res/xml/pref_system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,25 @@
android:summary="@string/pref_dormantasinactive_info"
android:defaultValue="false" />

<CheckBoxPreference
android:key="system_checkupdates"
android:title="@string/pref_checkupdates"
android:summary="@string/pref_checkupdates_info"
android:defaultValue="true" />
<ListPreference
android:key="system_autorefresh"
android:title="@string/pref_autorefresh"
android:summary="@string/pref_autorefresh_info"
android:entries="@array/pref_autorefresh_intervals"
android:entryValues="@array/pref_autorefresh_intervalvalues"
android:defaultValue="0" />

<CheckBoxPreference
android:key="system_usedarktheme"
android:title="@string/pref_usedarktheme"
android:summary="@string/pref_usedarktheme_info"
android:defaultValue="false" />

<Preference
android:key="system_sendlog"
android:title="@string/pref_sendlog"
android:summary="@string/pref_sendlog_info" />

<Preference
android:key="system_installhelp"
android:title="@string/pref_installhelp"
android:summary="@string/pref_installhelp_info" />
<CheckBoxPreference
android:key="system_checkupdates"
android:title="@string/pref_checkupdates"
android:summary="@string/pref_checkupdates_info"
android:defaultValue="true" />

<Preference
android:key="system_clearsearch"
Expand All @@ -57,11 +55,4 @@
android:key="system_exportsettings"
android:title="@string/pref_export" />

<Preference
android:key="system_changelog"
android:title="@string/pref_changelog" />

<Preference
android:key="system_about" />

</PreferenceScreen>
10 changes: 9 additions & 1 deletion core/src/org/transdroid/core/app/settings/SystemSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public boolean treatDormantAsInactive() {
return prefs.getBoolean("system_dormantasinactive", false);
}

/**
* Returns the interval in which automatic screen refreshes should be scheduled.
* @return The selected refresh interval in milliseconds or 0 if automatic refreshes should be disabled
*/
public int getRefreshIntervalMilliseconds() {
return Integer.parseInt(prefs.getString("system_autorefresh", "0"));
}

public boolean checkForUpdates() {
return prefs.getBoolean("system_checkupdates", true);
}
Expand All @@ -70,5 +78,5 @@ public Date getLastCheckedForAppUpdates() {
public void setLastCheckedForAppUpdates(Date lastChecked) {
prefs.edit().putLong("system_lastappupdatecheck", lastChecked == null ? -1L : lastChecked.getTime()).commit();
}

}
124 changes: 124 additions & 0 deletions core/src/org/transdroid/core/gui/settings/HelpSettingsActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* Copyright 2010-2013 Eric Kok et al.
*
* Transdroid 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.
*
* Transdroid 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 Transdroid. If not, see <http://www.gnu.org/licenses/>.
*/
package org.transdroid.core.gui.settings;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem;
import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.app.settings.SettingsPersistence;
import org.transdroid.core.gui.log.ErrorLogSender;
import org.transdroid.core.gui.navigation.DialogHelper;
import org.transdroid.core.gui.navigation.NavigationHelper;

import android.annotation.TargetApi;
import android.app.Dialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;

import com.actionbarsherlock.app.SherlockPreferenceActivity;

@EActivity
public class HelpSettingsActivity extends SherlockPreferenceActivity {

protected static final int DIALOG_CHANGELOG = 0;
protected static final int DIALOG_ABOUT = 1;
protected static final String INSTALLHELP_URI = "http://www.transdroid.org/download/";

@Bean
protected NavigationHelper navigationHelper;
@Bean
protected ApplicationSettings applicationSettings;
@Bean
protected ErrorLogSender errorLogSender;
@Bean
protected SettingsPersistence settingsPersistence;

@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

// Just load the system-related preferences from XML
addPreferencesFromResource(R.xml.pref_help);

// Handle outgoing links and preference changes
findPreference("system_sendlog").setOnPreferenceClickListener(onSendLogClick);
findPreference("system_installhelp").setOnPreferenceClickListener(onInstallHelpClick);
findPreference("system_changelog").setOnPreferenceClickListener(onChangeLogClick);
findPreference("system_about").setTitle(getString(R.string.pref_about, getString(R.string.app_name)));
findPreference("system_about").setOnPreferenceClickListener(onAboutClick);
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@OptionsItem(android.R.id.home)
protected void navigateUp() {
MainSettingsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start();
}

private OnPreferenceClickListener onSendLogClick = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
errorLogSender.collectAndSendLog(HelpSettingsActivity.this, applicationSettings.getLastUsedServer());
return true;
}
};

private OnPreferenceClickListener onInstallHelpClick = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(INSTALLHELP_URI)));
return true;
}
};

private OnPreferenceClickListener onChangeLogClick = new OnPreferenceClickListener() {
@SuppressWarnings("deprecation")
@Override
public boolean onPreferenceClick(Preference preference) {
showDialog(DIALOG_CHANGELOG);
return true;
}
};

private OnPreferenceClickListener onAboutClick = new OnPreferenceClickListener() {
@SuppressWarnings("deprecation")
@Override
public boolean onPreferenceClick(Preference preference) {
showDialog(DIALOG_ABOUT);
return true;
}
};

protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_CHANGELOG:
return DialogHelper.showDialog(this, new ChangelogDialog());
case DIALOG_ABOUT:
return DialogHelper.showDialog(this, new AboutDialog());
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ protected void onResume() {
findPreference("header_addrssfeed").setOnPreferenceClickListener(onAddRssfeed);
findPreference("header_background").setOnPreferenceClickListener(onBackgroundSettings);
findPreference("header_system").setOnPreferenceClickListener(onSystemSettings);
findPreference("header_help").setOnPreferenceClickListener(onHelpSettings);

// Add existing servers
List<ServerSetting> servers = applicationSettings.getNormalServerSettings();
Expand Down Expand Up @@ -238,6 +239,14 @@ public boolean onPreferenceClick(Preference preference) {
}
};

private OnPreferenceClickListener onHelpSettings = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
HelpSettingsActivity_.intent(MainSettingsActivity.this).start();
return true;
}
};

private OnServerClickedListener onServerClicked = new OnServerClickedListener() {
@Override
public void onServerClicked(ServerSetting serverSetting) {
Expand Down
Loading

0 comments on commit df030db

Please sign in to comment.