diff options
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod')
4 files changed, 55 insertions, 3 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java index ba22a42b4..474c57169 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -118,5 +118,14 @@ public class PreferenceActivity extends AppCompatActivity { activity.preferenceController.onResume(); } } + + @Override + public void onPause() { + PreferenceActivity activity = instance.get(); + if(activity != null && activity.preferenceController != null) { + activity.preferenceController.onPause(); + } + super.onPause(); + } } } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivityGingerbread.java b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivityGingerbread.java index 633f8d66d..4af988ea0 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivityGingerbread.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivityGingerbread.java @@ -55,6 +55,12 @@ public class PreferenceActivityGingerbread extends android.preference.Preference } @Override + protected void onPause() { + preferenceController.onPause(); + super.onPause(); + } + + @Override protected void onApplyThemeResource(Theme theme, int resid, boolean first) { theme.applyStyle(UserPreferences.getTheme(), true); } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java index d46a3d6c2..0c4ff4a7a 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java @@ -6,7 +6,7 @@ import android.content.res.Configuration; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.LayoutInflater; import android.view.MenuItem; @@ -40,7 +40,7 @@ import de.danoeh.antennapod.core.service.GpodnetSyncService; * Step 2: Choose device from a list of available devices or create a new one * Step 3: Choose from a list of actions */ -public class GpodnetAuthenticationActivity extends ActionBarActivity { +public class GpodnetAuthenticationActivity extends AppCompatActivity { private static final String TAG = "GpodnetAuthActivity"; private static final String CURRENT_STEP = "current_step"; diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java index e1ef24afd..159f64792 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -28,10 +28,11 @@ import android.text.Editable; import android.text.Html; import android.text.TextWatcher; import android.text.format.DateFormat; +import android.text.format.DateUtils; import android.util.Log; import android.widget.EditText; -import android.widget.Toast; import android.widget.ListView; +import android.widget.Toast; import com.afollestad.materialdialogs.MaterialDialog; @@ -89,6 +90,8 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc public static final String PREF_GPODNET_SYNC = "pref_gpodnet_sync"; public static final String PREF_GPODNET_LOGOUT = "pref_gpodnet_logout"; public static final String PREF_GPODNET_HOSTNAME = "pref_gpodnet_hostname"; + public static final String PREF_GPODNET_NOTIFICATIONS = "pref_gpodnet_notifications"; + public static final String PREF_GPODNET_SYNC_REPORT = "pref_gpodnet_sync_report"; public static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify"; public static final String PREF_PROXY = "prefProxy"; public static final String PREF_KNOWN_ISSUES = "prefKnownIssues"; @@ -433,9 +436,17 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc setParallelDownloadsText(UserPreferences.getParallelDownloads()); setEpisodeCacheSizeText(UserPreferences.getEpisodeCacheSize()); setDataFolderText(); + GpodnetPreferences.setSyncAttemptListener(() -> ui.getActivity().runOnUiThread( + () -> updateLastGpodnetSyncReport( + GpodnetPreferences.getLastSyncAttemptResult(), + GpodnetPreferences.getLastSyncAttemptTimestamp()))); updateGpodnetPreferenceScreen(); } + public void onPause() { + GpodnetPreferences.setSyncAttemptListener(null); + } + @SuppressLint("NewApi") public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK && @@ -478,17 +489,43 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc ui.findPreference(PreferenceController.PREF_GPODNET_SETLOGIN_INFORMATION).setEnabled(loggedIn); ui.findPreference(PreferenceController.PREF_GPODNET_SYNC).setEnabled(loggedIn); ui.findPreference(PreferenceController.PREF_GPODNET_LOGOUT).setEnabled(loggedIn); + ui.findPreference(PREF_GPODNET_NOTIFICATIONS).setEnabled(loggedIn); if(loggedIn) { String format = ui.getActivity().getString(R.string.pref_gpodnet_login_status); String summary = String.format(format, GpodnetPreferences.getUsername(), GpodnetPreferences.getDeviceID()); ui.findPreference(PreferenceController.PREF_GPODNET_LOGOUT).setSummary(Html.fromHtml(summary)); + updateLastGpodnetSyncReport(GpodnetPreferences.getLastSyncAttemptResult(), + GpodnetPreferences.getLastSyncAttemptTimestamp()); } else { ui.findPreference(PreferenceController.PREF_GPODNET_LOGOUT).setSummary(null); + updateLastGpodnetSyncReport(false, 0); } ui.findPreference(PreferenceController.PREF_GPODNET_HOSTNAME).setSummary(GpodnetPreferences.getHostname()); } + private void updateLastGpodnetSyncReport(boolean successful, long lastTime) { + Preference syncReport = ui.findPreference(PREF_GPODNET_SYNC_REPORT); + if (lastTime != 0) { + syncReport.setTitle(ui.getActivity().getString(R.string.pref_gpodnet_last_sync_title, + ui.getActivity().getString(successful ? + R.string.gpodnetsync_pref_report_successful : + R.string.gpodnetsync_pref_report_failed))); + syncReport.setSummary(DateUtils.getRelativeDateTimeString( + ui.getActivity(), + lastTime, + DateUtils.MINUTE_IN_MILLIS, + DateUtils.WEEK_IN_MILLIS, + DateUtils.FORMAT_SHOW_TIME)); + syncReport.setEnabled(true); + } else { + syncReport.setTitle(ui.getActivity().getString(R.string.pref_gpodnet_last_sync_title, + ui.getActivity().getString(R.string.gpodnetsync_pref_report_undetermined))); + syncReport.setSummary(null); + syncReport.setEnabled(false); + } + } + private String[] getUpdateIntervalEntries(final String[] values) { final Resources res = ui.getActivity().getResources(); String[] entries = new String[values.length]; |