mirror of
https://github.com/MinimalBible/MinimalBible-Legacy
synced 2024-12-22 06:38:28 -05:00
Fragments know what category they are
Filtering not quite working yet, not sure why...
This commit is contained in:
parent
4dc920186f
commit
0f98338504
@ -5,6 +5,6 @@ public class MinimalBibleConstants {
|
|||||||
public static final String DOWNLOAD_PREFS_FILE = "DOWNLOADER_PREFERENCES";
|
public static final String DOWNLOAD_PREFS_FILE = "DOWNLOADER_PREFERENCES";
|
||||||
|
|
||||||
public static final String KEY_DOWNLOAD_ENABLED = "HAS_ENABLED_DOWNLOAD";
|
public static final String KEY_DOWNLOAD_ENABLED = "HAS_ENABLED_DOWNLOAD";
|
||||||
public static final String KEY_PERM_DISABLE_DOWNLOAD = "PERMANENTLY_DISABLE_DOWNLOAD";
|
public static final String KEY_SHOWED_DOWNLOAD_DIALOG = "SHOWED_DOWNLOAD_DIALOG";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import org.bspeice.minimalbible.MinimalBibleConstants;
|
|||||||
import org.bspeice.minimalbible.R;
|
import org.bspeice.minimalbible.R;
|
||||||
import org.crosswire.jsword.book.Book;
|
import org.crosswire.jsword.book.Book;
|
||||||
import org.crosswire.jsword.book.BookCategory;
|
import org.crosswire.jsword.book.BookCategory;
|
||||||
|
import org.crosswire.jsword.book.BookFilter;
|
||||||
|
import org.crosswire.jsword.book.BookFilters;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@ -15,7 +17,6 @@ import android.content.DialogInterface;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -31,6 +32,8 @@ public class BookListFragment extends Fragment {
|
|||||||
*/
|
*/
|
||||||
private static final String ARG_BOOK_CATEGORY = "book_category";
|
private static final String ARG_BOOK_CATEGORY = "book_category";
|
||||||
|
|
||||||
|
protected TextView tv;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new instance of this fragment for the given section number.
|
* Returns a new instance of this fragment for the given section number.
|
||||||
*/
|
*/
|
||||||
@ -50,9 +53,9 @@ public class BookListFragment extends Fragment {
|
|||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View rootView = inflater.inflate(R.layout.fragment_download, container,
|
View rootView = inflater.inflate(R.layout.fragment_download, container,
|
||||||
false);
|
false);
|
||||||
TextView textView = (TextView) rootView
|
tv = (TextView) rootView.findViewById(R.id.section_label);
|
||||||
.findViewById(R.id.section_label);
|
tv.setText(getArguments().getString(ARG_BOOK_CATEGORY));
|
||||||
textView.setText(getArguments().getString(ARG_BOOK_CATEGORY));
|
displayModules();
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,9 +67,14 @@ public class BookListFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void displayModules() {
|
public void displayModules() {
|
||||||
DownloadManager dm = new DownloadManager();
|
SharedPreferences prefs = getActivity()
|
||||||
|
.getSharedPreferences(
|
||||||
if (dm.willRefresh()) {
|
MinimalBibleConstants.DOWNLOAD_PREFS_FILE,
|
||||||
|
Context.MODE_PRIVATE);
|
||||||
|
boolean dialogDisplayed = prefs.getBoolean(
|
||||||
|
MinimalBibleConstants.KEY_SHOWED_DOWNLOAD_DIALOG, false);
|
||||||
|
|
||||||
|
if (!dialogDisplayed) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
DownloadDialogListener dialogListener = new DownloadDialogListener();
|
DownloadDialogListener dialogListener = new DownloadDialogListener();
|
||||||
builder.setMessage(
|
builder.setMessage(
|
||||||
@ -80,17 +88,50 @@ public class BookListFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refreshModules() {
|
private void refreshModules() {
|
||||||
|
BookCategory bc = BookCategory.fromString(getArguments().getString(
|
||||||
|
ARG_BOOK_CATEGORY));
|
||||||
|
BookFilter f;
|
||||||
|
// We wouldn't need this switch if BookFilters.BookCategoryFilter were
|
||||||
|
// public...
|
||||||
|
switch (bc) {
|
||||||
|
case BIBLE:
|
||||||
|
f = BookFilters.getBibles();
|
||||||
|
break;
|
||||||
|
case COMMENTARY:
|
||||||
|
f = BookFilters.getCommentaries();
|
||||||
|
break;
|
||||||
|
case DAILY_DEVOTIONS:
|
||||||
|
f = BookFilters.getDailyDevotionals();
|
||||||
|
break;
|
||||||
|
case DICTIONARY:
|
||||||
|
f = BookFilters.getDictionaries();
|
||||||
|
break;
|
||||||
|
case GENERAL_BOOK:
|
||||||
|
f = BookFilters.getGeneralBooks();
|
||||||
|
break;
|
||||||
|
case GLOSSARY:
|
||||||
|
f = BookFilters.getGlossaries();
|
||||||
|
break;
|
||||||
|
case MAPS:
|
||||||
|
f = BookFilters.getMaps();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// DownloadManager takes care of accepting a null value
|
||||||
|
f = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
DownloadManager dm = new DownloadManager();
|
DownloadManager dm = new DownloadManager();
|
||||||
|
|
||||||
|
ProgressDialog refreshDialog = new ProgressDialog(getActivity());
|
||||||
if (dm.willRefresh()) {
|
if (dm.willRefresh()) {
|
||||||
ProgressDialog refreshDialog = new ProgressDialog(getActivity());
|
|
||||||
refreshDialog.setMessage("Refreshing available modules...");
|
refreshDialog.setMessage("Refreshing available modules...");
|
||||||
refreshDialog.setCancelable(false);
|
|
||||||
refreshDialog.show();
|
|
||||||
dm.fetchAvailableBooks(new DlBookRefreshListener(refreshDialog));
|
|
||||||
} else {
|
} else {
|
||||||
dm.fetchAvailableBooks(new DlBookRefreshListener());
|
refreshDialog
|
||||||
|
.setMessage("Fetching available modules from cache...");
|
||||||
}
|
}
|
||||||
|
refreshDialog.setCancelable(false);
|
||||||
|
refreshDialog.show();
|
||||||
|
dm.fetchAvailableBooks(f, new DlBookRefreshListener(refreshDialog));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DlBookRefreshListener implements
|
private class DlBookRefreshListener implements
|
||||||
@ -102,19 +143,14 @@ public class BookListFragment extends Fragment {
|
|||||||
public DlBookRefreshListener(ProgressDialog dl) {
|
public DlBookRefreshListener(ProgressDialog dl) {
|
||||||
this.dl = dl;
|
this.dl = dl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DlBookRefreshListener() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefreshComplete(List<Book> results) {
|
public void onRefreshComplete(List<Book> results) {
|
||||||
if (dl != null) {
|
if (dl != null) {
|
||||||
dl.cancel();
|
dl.cancel();
|
||||||
}
|
}
|
||||||
|
tv.setText(results.get(0).getName());
|
||||||
for (Book b : results) {
|
|
||||||
Log.d("DlBookRefreshListener", b.getName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,11 +158,15 @@ public class BookListFragment extends Fragment {
|
|||||||
DialogInterface.OnClickListener {
|
DialogInterface.OnClickListener {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
SharedPreferences prefs = getActivity().getSharedPreferences(
|
||||||
|
MinimalBibleConstants.DOWNLOAD_PREFS_FILE,
|
||||||
|
Context.MODE_PRIVATE);
|
||||||
|
prefs.edit().putBoolean(MinimalBibleConstants.KEY_SHOWED_DOWNLOAD_DIALOG, true)
|
||||||
|
.commit();
|
||||||
|
|
||||||
switch (which) {
|
switch (which) {
|
||||||
case DialogInterface.BUTTON_POSITIVE:
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
// Clicked ready to continue - allow downloading in the future
|
// Clicked ready to continue - allow downloading in the future
|
||||||
SharedPreferences prefs = getActivity().getSharedPreferences(
|
|
||||||
MinimalBibleConstants.DOWNLOAD_PREFS_FILE, Context.MODE_PRIVATE);
|
|
||||||
prefs.edit()
|
prefs.edit()
|
||||||
.putBoolean(MinimalBibleConstants.KEY_DOWNLOAD_ENABLED,
|
.putBoolean(MinimalBibleConstants.KEY_DOWNLOAD_ENABLED,
|
||||||
true).commit();
|
true).commit();
|
||||||
@ -139,11 +179,16 @@ public class BookListFragment extends Fragment {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case DialogInterface.BUTTON_NEGATIVE:
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
// Not going to continue, still show what has
|
// Clicked to not download - Permanently disable downloading
|
||||||
// already been downloaded.
|
prefs.edit()
|
||||||
|
.putBoolean(MinimalBibleConstants.KEY_DOWNLOAD_ENABLED,
|
||||||
|
false).commit();
|
||||||
|
Toast.makeText(getActivity(),
|
||||||
|
"Disabling downloading. Re-enable it in settings.",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
refreshModules();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import java.util.Map;
|
|||||||
import org.bspeice.minimalbible.MinimalBible;
|
import org.bspeice.minimalbible.MinimalBible;
|
||||||
import org.bspeice.minimalbible.MinimalBibleConstants;
|
import org.bspeice.minimalbible.MinimalBibleConstants;
|
||||||
import org.crosswire.jsword.book.BookCategory;
|
import org.crosswire.jsword.book.BookCategory;
|
||||||
|
import org.crosswire.jsword.book.BookFilter;
|
||||||
import org.crosswire.jsword.book.install.InstallManager;
|
import org.crosswire.jsword.book.install.InstallManager;
|
||||||
import org.crosswire.jsword.book.install.Installer;
|
import org.crosswire.jsword.book.install.Installer;
|
||||||
|
|
||||||
@ -13,6 +14,8 @@ import android.content.SharedPreferences;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class DownloadManager {
|
public class DownloadManager {
|
||||||
|
|
||||||
|
// TODO: Probably should be a singleton.
|
||||||
|
|
||||||
private final String TAG = "DownloadManager";
|
private final String TAG = "DownloadManager";
|
||||||
|
|
||||||
@ -26,7 +29,17 @@ public class DownloadManager {
|
|||||||
|
|
||||||
public BookRefreshTask fetchAvailableBooks(
|
public BookRefreshTask fetchAvailableBooks(
|
||||||
BookRefreshTask.BookRefreshListener bookRefreshListener) {
|
BookRefreshTask.BookRefreshListener bookRefreshListener) {
|
||||||
|
return _fetchAvailableBooks(null, bookRefreshListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BookRefreshTask fetchAvailableBooks(BookFilter f,
|
||||||
|
BookRefreshTask.BookRefreshListener bookRefreshListener) {
|
||||||
|
return _fetchAvailableBooks(f, bookRefreshListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BookRefreshTask _fetchAvailableBooks(BookFilter f,
|
||||||
|
BookRefreshTask.BookRefreshListener bookRefreshListener) {
|
||||||
|
|
||||||
Map<String, Installer> installers = getInstallers();
|
Map<String, Installer> installers = getInstallers();
|
||||||
|
|
||||||
return (BookRefreshTask) new BookRefreshTask(willRefresh(),
|
return (BookRefreshTask) new BookRefreshTask(willRefresh(),
|
||||||
@ -38,7 +51,7 @@ public class DownloadManager {
|
|||||||
// Method to determine if we need a refresh
|
// Method to determine if we need a refresh
|
||||||
// Public, so other modules can predict and take action accordingly.
|
// Public, so other modules can predict and take action accordingly.
|
||||||
// TODO: Discover if we need to refresh over Internet, or use a cached
|
// TODO: Discover if we need to refresh over Internet, or use a cached
|
||||||
// copy
|
// copy - likely something time-based, also check network state.
|
||||||
// Fun fact - jSword handles the caching for us.
|
// Fun fact - jSword handles the caching for us.
|
||||||
|
|
||||||
SharedPreferences prefs = MinimalBible.getAppContext()
|
SharedPreferences prefs = MinimalBible.getAppContext()
|
||||||
@ -46,9 +59,7 @@ public class DownloadManager {
|
|||||||
MinimalBibleConstants.DOWNLOAD_PREFS_FILE,
|
MinimalBibleConstants.DOWNLOAD_PREFS_FILE,
|
||||||
Context.MODE_PRIVATE);
|
Context.MODE_PRIVATE);
|
||||||
|
|
||||||
return (!prefs.getBoolean(MinimalBibleConstants.KEY_DOWNLOAD_ENABLED,
|
return (prefs.getBoolean(MinimalBibleConstants.KEY_DOWNLOAD_ENABLED, false));
|
||||||
false) || prefs.getBoolean(
|
|
||||||
MinimalBibleConstants.KEY_PERM_DISABLE_DOWNLOAD, false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Installer> getInstallers() {
|
public Map<String, Installer> getInstallers() {
|
||||||
|
Loading…
Reference in New Issue
Block a user