diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/ActivityDownloaderModule.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/ActivityDownloaderModule.java index 9cd1e3d..13a7f6f 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/ActivityDownloaderModule.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/ActivityDownloaderModule.java @@ -8,6 +8,7 @@ import javax.inject.Singleton; import dagger.Module; import dagger.Provides; +import de.devland.esperandro.Esperandro; import de.greenrobot.event.EventBus; /** @@ -40,7 +41,7 @@ public class ActivityDownloaderModule { @Provides //@Singleton - DownloadPrefs_ provideDownloadPrefs() { - return new DownloadPrefs_(MinimalBible.getApplication()); + DownloadPrefs provideDownloadPrefs() { + return Esperandro.getPreferences(DownloadPrefs.class, MinimalBible.getAppContext()); } } diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListFragment.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListFragment.java index 8acad4a..8a7030e 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListFragment.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListFragment.java @@ -12,8 +12,6 @@ import android.view.ViewGroup; import android.widget.ListView; import android.widget.Toast; -import com.f2prateek.dart.InjectExtra; - import org.bspeice.minimalbible.MinimalBible; import org.bspeice.minimalbible.R; import org.bspeice.minimalbible.activities.BaseFragment; @@ -51,7 +49,7 @@ public class BookListFragment extends BaseFragment { @Inject DownloadManager downloadManager; - @Inject DownloadPrefs_ downloadPrefs; + @Inject DownloadPrefs downloadPrefs; private ProgressDialog refreshDialog; private LayoutInflater inflater; @@ -97,7 +95,7 @@ public class BookListFragment extends BaseFragment { * from the internet is allowable. */ public void displayModules() { - boolean dialogDisplayed = downloadPrefs.showedDownloadDialog().get(); + boolean dialogDisplayed = downloadPrefs.hasShownDownloadDialog(); if (!dialogDisplayed) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); @@ -168,12 +166,12 @@ public class BookListFragment extends BaseFragment { DialogInterface.OnClickListener { @Override public void onClick(DialogInterface dialog, int which) { - downloadPrefs.showedDownloadDialog().put(true); + downloadPrefs.hasShownDownloadDialog(true); switch (which) { case DialogInterface.BUTTON_POSITIVE: // Clicked ready to continue - allow downloading in the future - downloadPrefs.hasEnabledDownload().put(true); + downloadPrefs.hasEnabledDownload(true); // And warn them that it has been enabled in the future. Toast.makeText(getActivity(), @@ -184,7 +182,7 @@ public class BookListFragment extends BaseFragment { case DialogInterface.BUTTON_NEGATIVE: // Clicked to not download - Permanently disable downloading - downloadPrefs.hasEnabledDownload().put(false); + downloadPrefs.hasEnabledDownload(false); Toast.makeText(getActivity(), "Disabling downloading. Re-enable it in settings.", Toast.LENGTH_SHORT).show(); diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/DownloadPrefs.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/DownloadPrefs.java new file mode 100644 index 0000000..7b380e0 --- /dev/null +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/DownloadPrefs.java @@ -0,0 +1,20 @@ +package org.bspeice.minimalbible.activities.downloader; + +import de.devland.esperandro.annotations.SharedPreferences; + +/** + * Created by bspeice on 5/19/14. + */ +@SharedPreferences(name="DownloadPrefs") +public interface DownloadPrefs { + + boolean hasEnabledDownload(); + void hasEnabledDownload(boolean hasEnabledDownload); + + boolean hasShownDownloadDialog(); + void hasShownDownloadDialog(boolean hasShownDownloadDialog); + + long downloadRefreshedOn(); + void downloadRefreshedOn(long downloadRefreshedOn); + +} diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/DownloadPrefs_.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/DownloadPrefs_.java deleted file mode 100644 index c1f9ca0..0000000 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/DownloadPrefs_.java +++ /dev/null @@ -1,72 +0,0 @@ -/* -This is brutally ugly, but until https://github.com/square/dagger/issues/410 is resolved, -this is the best I can do while making sure that I can easily switch the API later - */ -// -// DO NOT EDIT THIS FILE, IT HAS BEEN GENERATED USING AndroidAnnotations 3.0.1. -// - - -package org.bspeice.minimalbible.activities.downloader; - -import android.content.Context; -import android.content.SharedPreferences; - -import org.androidannotations.api.sharedpreferences.BooleanPrefEditorField; -import org.androidannotations.api.sharedpreferences.BooleanPrefField; -import org.androidannotations.api.sharedpreferences.EditorHelper; -import org.androidannotations.api.sharedpreferences.LongPrefEditorField; -import org.androidannotations.api.sharedpreferences.LongPrefField; -import org.androidannotations.api.sharedpreferences.SharedPreferencesHelper; - -public final class DownloadPrefs_ - extends SharedPreferencesHelper -{ - - private Context context_; - - public DownloadPrefs_(Context context) { - super(context.getSharedPreferences("DownloadPrefs", 0)); - this.context_ = context; - } - - public DownloadPrefs_.DownloadPrefsEditor_ edit() { - return new DownloadPrefs_.DownloadPrefsEditor_(getSharedPreferences()); - } - - public BooleanPrefField hasEnabledDownload() { - return booleanField("hasEnabledDownload", false); - } - - public BooleanPrefField showedDownloadDialog() { - return booleanField("showedDownloadDialog", false); - } - - public LongPrefField downloadRefreshedOn() { - return longField("downloadRefreshedOn", 0L); - } - - public final static class DownloadPrefsEditor_ - extends EditorHelper - { - - - DownloadPrefsEditor_(SharedPreferences sharedPreferences) { - super(sharedPreferences); - } - - public BooleanPrefEditorField hasEnabledDownload() { - return booleanField("hasEnabledDownload"); - } - - public BooleanPrefEditorField showedDownloadDialog() { - return booleanField("showedDownloadDialog"); - } - - public LongPrefEditorField downloadRefreshedOn() { - return longField("downloadRefreshedOn"); - } - - } - -} diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/_DownloadPrefs.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/_DownloadPrefs.java deleted file mode 100644 index 45b76d4..0000000 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/_DownloadPrefs.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.bspeice.minimalbible.activities.downloader; - -import org.androidannotations.annotations.sharedpreferences.DefaultBoolean; -import org.androidannotations.annotations.sharedpreferences.DefaultLong; -import org.androidannotations.annotations.sharedpreferences.SharedPref; - -/** - * Renamed while waiting for https://github.com/square/dagger/issues/410 to get resolved. - * Once the issue is fixed, this should go back to being DownloadPrefs - */ -@SharedPref(value= SharedPref.Scope.UNIQUE) -public interface _DownloadPrefs { - - @DefaultBoolean(false) - boolean hasEnabledDownload(); - - @DefaultBoolean(false) - boolean showedDownloadDialog(); - - @DefaultLong(0) - long downloadRefreshedOn(); -} \ No newline at end of file diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookRefreshTask.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookRefreshTask.java index b1ab7d7..778c1d5 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookRefreshTask.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookRefreshTask.java @@ -7,7 +7,7 @@ import android.os.AsyncTask; import android.util.Log; import org.bspeice.minimalbible.MinimalBible; -import org.bspeice.minimalbible.activities.downloader.DownloadPrefs_; +import org.bspeice.minimalbible.activities.downloader.DownloadPrefs; import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.install.InstallException; import org.crosswire.jsword.book.install.Installer; @@ -26,7 +26,7 @@ public class BookRefreshTask extends AsyncTask> { private final Long refreshAfter = System.currentTimeMillis() - 604800000L; // 1 Week in millis @Inject - DownloadPrefs_ downloadPrefs; + DownloadPrefs downloadPrefs; private EventBus downloadBus; @@ -44,7 +44,7 @@ public class BookRefreshTask extends AsyncTask> { if (doRefresh()) { try { i.reloadBookList(); - downloadPrefs.downloadRefreshedOn().put(System.currentTimeMillis()); + downloadPrefs.downloadRefreshedOn(System.currentTimeMillis()); } catch (InstallException e) { Log.e(TAG, "Error downloading books from installer: " @@ -76,10 +76,10 @@ public class BookRefreshTask extends AsyncTask> { } private boolean downloadEnabled() { - return downloadPrefs.hasEnabledDownload().get(); + return downloadPrefs.hasEnabledDownload(); } private boolean needsRefresh() { - return (downloadPrefs.downloadRefreshedOn().get() > refreshAfter); + return (downloadPrefs.downloadRefreshedOn() > refreshAfter); } }