mirror of
https://github.com/MinimalBible/MinimalBible-Legacy
synced 2024-11-13 19:48:38 -05:00
Switch to Esperandro for SharedPreferences
This commit is contained in:
parent
d664f12d08
commit
d10626efe6
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
}
|
@ -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<DownloadPrefs_.DownloadPrefsEditor_>
|
||||
{
|
||||
|
||||
|
||||
DownloadPrefsEditor_(SharedPreferences sharedPreferences) {
|
||||
super(sharedPreferences);
|
||||
}
|
||||
|
||||
public BooleanPrefEditorField<DownloadPrefs_.DownloadPrefsEditor_> hasEnabledDownload() {
|
||||
return booleanField("hasEnabledDownload");
|
||||
}
|
||||
|
||||
public BooleanPrefEditorField<DownloadPrefs_.DownloadPrefsEditor_> showedDownloadDialog() {
|
||||
return booleanField("showedDownloadDialog");
|
||||
}
|
||||
|
||||
public LongPrefEditorField<DownloadPrefs_.DownloadPrefsEditor_> downloadRefreshedOn() {
|
||||
return longField("downloadRefreshedOn");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
@ -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<Installer, Integer, List<Book>> {
|
||||
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<Installer, Integer, List<Book>> {
|
||||
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<Installer, Integer, List<Book>> {
|
||||
}
|
||||
|
||||
private boolean downloadEnabled() {
|
||||
return downloadPrefs.hasEnabledDownload().get();
|
||||
return downloadPrefs.hasEnabledDownload();
|
||||
}
|
||||
|
||||
private boolean needsRefresh() {
|
||||
return (downloadPrefs.downloadRefreshedOn().get() > refreshAfter);
|
||||
return (downloadPrefs.downloadRefreshedOn() > refreshAfter);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user