-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 100: Add a settings menu with a single preference for controlling sync frequency. #103
base: master
Are you sure you want to change the base?
Changes from all commits
fa7b122
9b1a307
8e21164
185c0cf
ab7b25a
fe03d0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<PreferenceScreen | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:title="@string/settings"> | ||
|
||
<PreferenceCategory | ||
android:title="@string/settings_category_sync"> | ||
<ListPreference | ||
android:id="@+id/setting_sync_frequency_listPref" | ||
android:key="@string/setting_sync_frequency_key" | ||
android:title="@string/setting_title_sync_frequency" | ||
android:summary="@string/setting_instruction_sync_frequency" | ||
android:entries="@array/setting_sync_choices" | ||
android:entryValues="@array/setting_sync_choices_values" | ||
android:dialogTitle="@string/setting_title_sync_frequency"> | ||
</ListPreference> | ||
</PreferenceCategory> | ||
</PreferenceScreen> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
<string name="using_ssh_activity_title">SSH Install Guide</string> | ||
<string name="clone_launcher_activity_title">Clone...</string> | ||
<string name="clone_menu_option">Clone...</string> | ||
<string name="settings_app_menu_option">Settings...</string> | ||
<string name="enter_clone_url">Url</string> | ||
<string name="clone_target_folder_label">Target Folder</string> | ||
<string name="clone_url_hint">Repository url</string> | ||
|
@@ -112,4 +113,46 @@ | |
|
||
<string name="no_viewer_available_for_file">"No viewer available for '%1$s'"</string> | ||
|
||
<!-- Settings Strings --> | ||
<string name="settings">Settings</string> | ||
<string name="settings_category_sync">Sync Settings</string> | ||
<string name="setting_title_sync_frequency">Sync Frequency</string> | ||
<string name="setting_instruction_sync_frequency">Tap to set how often repository synchronization will occur</string> | ||
<string name="setting_sync_frequency_key">setting_sync_frequency</string> | ||
|
||
<string name="setting_sync_frequency_daily">0</string> | ||
<string name="setting_sync_frequency_daily_title">Sync daily at</string> | ||
<string name="setting_sync_frequency_daily_hour_key">setting_sync_frequency_daily_hour</string> | ||
<string name="setting_sync_frequency_daily_min_key">setting_sync_frequency_daily_min</string> | ||
<string name="setting_sync_frequency_subtitle_key">setting_sync_frequency_subtitle</string> | ||
|
||
<!-- | ||
These next two arrays need to be in sync (no pun intended). In other words, if you change | ||
setting_sync_choices to have another value, you need to put a corresponding integer value | ||
into the setting_sync_choices_values | ||
--> | ||
<string-array name="setting_sync_choices"> | ||
<item>Manually</item> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should apologise here, as I should have specified in my comment #103 (comment) that while I thought the screenshot represented a reasonable look-and-feel (ie using a restricted set of options in a list box), the preferred list of options was actually mentioned in #103 (comment), ie the list would be this:
I wasn't actually anticipating you implementing the 'Schedule daily at...' functionality, and initially I was going to ask you to take it out, because I wasn't sure it was worth the extra code and requirement for an additional permission. I'm still rather ambivalent about it, but if you think it's worth having, then it can stay in... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've now updated the list of sync possibilities to include the options (and only those options) that you specify in this list.
Oh, my mistake. I didn't realize you weren't thinking this would go into the change. I actually think this is the one I'll use most frequently. I use agit quite frequently for updating my configuration repository. Since it's on my phone, I can then just pull updated configuration files off of my phone onto another machine when doing sysadmin tasks (e.g. if it doesn't have internet access for some reason, I can use my phone as a USB drive quite easily). Since I do update these configuration files remotely, but not very often, I thought it would be nice if it sync'ed every night. However, since there are a lot of them, I'd like to sync every night when I'm sleeping (and thus not using my phone). :) On the other hand, I can totally see that the added permission is not ideal. It's up to you - I'd be fine taking it out if you would rather not incur the cost of the app permission. |
||
<item>Schedule daily at…</item> | ||
<item>Every minute</item> | ||
<item>Every 5 minutes</item> | ||
<item>Every 15 minutes</item> | ||
<item>Every hour</item> | ||
<item>Every 4 hours</item> | ||
<item>Every day</item> | ||
<item>Every week</item> | ||
</string-array> | ||
|
||
<!-- These next values are in MINUTES (except for the special values for "Manually" and "Sync Daily" --> | ||
<string-array name="setting_sync_choices_values"> | ||
<item>-1</item> | ||
<item>@string/setting_sync_frequency_daily</item> | ||
<item>1</item> | ||
<item>5</item> | ||
<item>15</item> | ||
<item>60</item> | ||
<item>240</item> | ||
<item>1440</item> | ||
<item>10080</item> | ||
</string-array> | ||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright (c) 2011, 2012 Roberto Tyley | ||
* | ||
* This file is part of 'Agit' - an Android Git client. | ||
* | ||
* Agit 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. | ||
* | ||
* Agit 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 com.madgag.agit; | ||
|
||
import static com.madgag.agit.sync.AccountAuthenticatorService.addAccount; | ||
import android.app.TimePickerDialog; | ||
import android.content.SharedPreferences; | ||
import android.os.Bundle; | ||
import android.preference.ListPreference; | ||
import android.preference.Preference; | ||
import android.preference.PreferenceActivity; | ||
import android.preference.PreferenceManager; | ||
import android.util.Log; | ||
import android.widget.TimePicker; | ||
|
||
import com.madgag.agit.sync.SyncRepoManager; | ||
|
||
public class SettingsActivity extends PreferenceActivity { | ||
public void onCreate(Bundle aSavedInstanceState) { | ||
super.onCreate(aSavedInstanceState); | ||
addPreferencesFromResource(R.layout.settings_activity); | ||
ListPreference syncFreq = (ListPreference) findPreference(getString(R.string.setting_sync_frequency_key)); | ||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this); | ||
setSummary(); | ||
syncFreq.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { | ||
@Override | ||
public boolean onPreferenceChange(Preference preference, Object o) { | ||
String value = (String)o; | ||
final SharedPreferences.Editor edtr = prefs.edit(); | ||
|
||
if (value.equals(getString(R.string.setting_sync_frequency_daily))) { | ||
// Check if our previous value was the same thing, so we can set it in the time | ||
// picker dialog. | ||
int hourDefault = 12; | ||
int minDefault = 0; | ||
String prevVal = prefs.getString(getString(R.string.setting_sync_frequency_key), "-1"); | ||
if (prevVal.equals(o)) { | ||
hourDefault = prefs.getInt(getString(R.string.setting_sync_frequency_daily_hour_key), hourDefault); | ||
minDefault = prefs.getInt(getString(R.string.setting_sync_frequency_daily_min_key), minDefault); | ||
} | ||
|
||
TimePickerDialog.OnTimeSetListener timeListener = new TimePickerDialog.OnTimeSetListener() { | ||
@Override | ||
public void onTimeSet(TimePicker timePicker, int hourOfDay, int minOfHour) { | ||
String subTitle = "Sync daily at " + hourOfDay + ":" + (minOfHour < 10 ? "0" : "") + minOfHour; | ||
edtr.putInt(getString(R.string.setting_sync_frequency_daily_hour_key), hourOfDay); | ||
edtr.putInt(getString(R.string.setting_sync_frequency_daily_min_key), minOfHour); | ||
edtr.putString(getString(R.string.setting_sync_frequency_subtitle_key), subTitle); | ||
edtr.commit(); | ||
|
||
SyncRepoManager manager = new SyncRepoManager(); | ||
manager.setDailySync(SettingsActivity.this, hourOfDay, minOfHour); | ||
SettingsActivity.this.setSummary(); | ||
} | ||
}; | ||
|
||
// Display new dialog with the available options. | ||
TimePickerDialog timePicker = new TimePickerDialog(SettingsActivity.this, timeListener, hourDefault, minDefault, false); | ||
timePicker.setTitle(getString(R.string.setting_sync_frequency_daily_title)); | ||
timePicker.show(); | ||
} else { | ||
// Loop to find out what the index of the chosen value is in the array - it should be the same | ||
// as the chosen value in the array of possible choices (see comment in strings.xml). | ||
String[] indexArray = getResources().getStringArray(R.array.setting_sync_choices_values); | ||
String[] subtitleArray = getResources().getStringArray(R.array.setting_sync_choices); | ||
int subtitleIndex = 0; | ||
for (String s : indexArray) { | ||
if (s.equals(o)) { | ||
break; | ||
} | ||
subtitleIndex++; | ||
} | ||
|
||
String subTitle = subtitleArray[subtitleIndex]; | ||
edtr.putString(getString(R.string.setting_sync_frequency_subtitle_key), subTitle); | ||
edtr.commit(); | ||
SyncRepoManager manager = new SyncRepoManager(); | ||
manager.cancelDailySync(SettingsActivity.this); | ||
} | ||
|
||
SettingsActivity.this.setSummary(); | ||
|
||
return true; | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
try { | ||
addAccount(this); | ||
} catch (Exception e) { | ||
Log.w(TAG, "Unable to re-add account for syncing after preference changes", e); | ||
} | ||
} | ||
|
||
/** | ||
* Displays the value stored in the preference setting_sync_frequency_subtitle_key in the summary line of the | ||
* list preference, so the user doesn't have to click through to view which option is selected. | ||
*/ | ||
private void setSummary() { | ||
ListPreference syncFreq = (ListPreference) findPreference(getString(R.string.setting_sync_frequency_key)); | ||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this); | ||
syncFreq.setSummary(prefs.getString(getString(R.string.setting_sync_frequency_subtitle_key), | ||
getString(R.string.setting_instruction_sync_frequency))); | ||
} | ||
|
||
private static final String TAG = "SettingsActivity"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The summary text shown to the user on the 'Settings' screen should actually tell them what the schedule is, so they don't have to tap through to see what it is. Ie 'Every Hour' (PocketCast again):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this now to perform this action. It's included in the most recent diff.