mirror of
https://github.com/MinimalBible/MinimalBible-Legacy
synced 2024-11-12 19:18:34 -05:00
Oh man is it ugly, but I can download module lists.
This commit is contained in:
parent
1465c81b9b
commit
f5e523417a
@ -7,12 +7,14 @@
|
||||
<uses-sdk
|
||||
android:minSdkVersion="8"
|
||||
android:targetSdkVersion="19" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
android:theme="@style/AppTheme"
|
||||
android:name="org.bspeice.minimalbible.MinimalBible" >
|
||||
<activity
|
||||
android:name="org.bspeice.minimalbible.activities.viewer.BibleViewer"
|
||||
android:label="@string/app_name" >
|
||||
|
18
MinimalBible/src/org/bspeice/minimalbible/MinimalBible.java
Normal file
18
MinimalBible/src/org/bspeice/minimalbible/MinimalBible.java
Normal file
@ -0,0 +1,18 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
public class MinimalBible extends Application {
|
||||
|
||||
private static MinimalBible instance;
|
||||
|
||||
public MinimalBible() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public static Context getAppContext() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,17 @@
|
||||
package org.bspeice.minimalbible.activities.downloader;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBibleConstants;
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activities.BaseActivity;
|
||||
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
|
||||
import org.bspeice.minimalbible.activities.downloader.DownloadManager.BookRefreshListener;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
@ -14,6 +19,7 @@ import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@ -25,6 +31,8 @@ import android.widget.Toast;
|
||||
public class DownloadActivity extends BaseActivity implements
|
||||
BaseNavigationDrawerFragment.NavigationDrawerCallbacks {
|
||||
|
||||
private ProgressDialog refreshDialog;
|
||||
|
||||
/**
|
||||
* Fragment managing the behaviors, interactions and presentation of the
|
||||
* navigation drawer.
|
||||
@ -49,6 +57,10 @@ public class DownloadActivity extends BaseActivity implements
|
||||
// Set up the drawer.
|
||||
mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
|
||||
(DrawerLayout) findViewById(R.id.drawer_layout));
|
||||
|
||||
// Refresh our modules - prompts user if they do actually want to
|
||||
// connect to the internet
|
||||
doRefreshModules();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -150,47 +162,82 @@ public class DownloadActivity extends BaseActivity implements
|
||||
.getInt(ARG_SECTION_NUMBER));
|
||||
}
|
||||
}
|
||||
|
||||
private void displayInternetWarning() {
|
||||
SharedPreferences prefs = getSharedPreferences(MinimalBibleConstants.DOWNLOAD_PREFS_FILE, MODE_PRIVATE);
|
||||
|
||||
// If downloading has not been enabled, or user has permanently disabled downloading, WARN THEM!
|
||||
if (!prefs.getBoolean(MinimalBibleConstants.KEY_DOWNLOAD_ENABLED, false) || prefs.getBoolean(MinimalBibleConstants.KEY_PERM_DISABLE_DOWNLOAD, false)) {
|
||||
|
||||
private void doRefreshModules() {
|
||||
SharedPreferences prefs = getSharedPreferences(
|
||||
MinimalBibleConstants.DOWNLOAD_PREFS_FILE, MODE_PRIVATE);
|
||||
|
||||
// If downloading has not been enabled, or user has permanently disabled
|
||||
// downloading, WARN THEM!
|
||||
if (!prefs
|
||||
.getBoolean(MinimalBibleConstants.KEY_DOWNLOAD_ENABLED, false)
|
||||
|| prefs.getBoolean(
|
||||
MinimalBibleConstants.KEY_PERM_DISABLE_DOWNLOAD, false)) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
DownloadDialogListener dialogListener = new DownloadDialogListener();
|
||||
builder.setMessage("About to contact servers to download content. Continue?")
|
||||
.setPositiveButton("Yes", dialogListener).setNegativeButton("No", dialogListener)
|
||||
.setCancelable(false).show();
|
||||
builder.setMessage(
|
||||
"About to contact servers to download content. Continue?")
|
||||
.setPositiveButton("Yes", dialogListener)
|
||||
.setNegativeButton("No", dialogListener)
|
||||
.setCancelable(false).show();
|
||||
} else {
|
||||
downloadModules();
|
||||
refreshModules();
|
||||
}
|
||||
}
|
||||
|
||||
private void downloadModules() {
|
||||
|
||||
|
||||
private void refreshModules() {
|
||||
// TODO: Discover if we need to refresh over Internet, or use a cached
|
||||
// copy
|
||||
// Fun fact - jSword handles the caching for us.
|
||||
ProgressDialog refreshDialog = new ProgressDialog(this);
|
||||
refreshDialog.setMessage("Refreshing available modules...");
|
||||
refreshDialog.setCancelable(false);
|
||||
refreshDialog.show();
|
||||
DownloadManager dm = new DownloadManager();
|
||||
dm.fetchAvailableBooks(true, new DlBookRefreshListener(refreshDialog));
|
||||
}
|
||||
|
||||
private class DownloadDialogListener implements DialogInterface.OnClickListener {
|
||||
|
||||
private class DownloadDialogListener implements
|
||||
DialogInterface.OnClickListener {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which){
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
// Clicked ready to continue - allow downloading in the future
|
||||
SharedPreferences prefs = getSharedPreferences(MinimalBibleConstants.DOWNLOAD_PREFS_FILE, MODE_PRIVATE);
|
||||
prefs.edit().putBoolean(MinimalBibleConstants.KEY_DOWNLOAD_ENABLED, true).commit();
|
||||
|
||||
SharedPreferences prefs = getSharedPreferences(
|
||||
MinimalBibleConstants.DOWNLOAD_PREFS_FILE, MODE_PRIVATE);
|
||||
prefs.edit()
|
||||
.putBoolean(MinimalBibleConstants.KEY_DOWNLOAD_ENABLED,
|
||||
true).commit();
|
||||
|
||||
// And warn them that it has been enabled in the future.
|
||||
Toast.makeText(DownloadActivity.this,
|
||||
"Downloading now enabled. Disable in settings.", Toast.LENGTH_SHORT).show();
|
||||
downloadModules();
|
||||
"Downloading now enabled. Disable in settings.",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
refreshModules();
|
||||
break;
|
||||
|
||||
|
||||
case DialogInterface.BUTTON_NEGATIVE:
|
||||
// Not going to continue, still show what has
|
||||
// already been downloaded.
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private class DlBookRefreshListener implements BookRefreshListener {
|
||||
// TODO: Figure out why I need to pass in the ProgressDialog, and can't cancel it from onRefreshComplete.
|
||||
ProgressDialog dl;
|
||||
public DlBookRefreshListener(ProgressDialog dl) {
|
||||
this.dl = dl;
|
||||
}
|
||||
@Override
|
||||
public void onRefreshComplete(List<Book> results) {
|
||||
dl.cancel();
|
||||
for (Book b : results) {
|
||||
Log.d("DlBookRefreshListener", b.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,77 @@
|
||||
package org.bspeice.minimalbible.activities.downloader;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.install.InstallException;
|
||||
import org.crosswire.jsword.book.install.InstallManager;
|
||||
import org.crosswire.jsword.book.install.Installer;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
public class DownloadManager {
|
||||
|
||||
private final String TAG = "DownloadManager";
|
||||
|
||||
public DownloadManager() {
|
||||
setDownloadDir();
|
||||
}
|
||||
|
||||
public InstallerReloadTask fetchAvailableBooks(boolean forceRefresh, BookRefreshListener bookRefreshListener) {
|
||||
|
||||
Map<String, Installer> installers = getInstallers();
|
||||
|
||||
return (InstallerReloadTask)
|
||||
new InstallerReloadTask(bookRefreshListener).execute(installers.values().toArray(new Installer[installers.size()]));
|
||||
}
|
||||
|
||||
public Map<String, Installer> getInstallers() {
|
||||
return new InstallManager().getInstallers();
|
||||
}
|
||||
|
||||
private void setDownloadDir() {
|
||||
// We need to set the download directory for jSword to stick with Android.
|
||||
String home = MinimalBible.getAppContext().getFilesDir().toString();
|
||||
Log.d(TAG, "Setting jsword.home to: " + home);
|
||||
System.setProperty("jsword.home", home);
|
||||
}
|
||||
|
||||
public class InstallerReloadTask extends AsyncTask<Installer, Float, List<Book>> {
|
||||
private BookRefreshListener listener;
|
||||
|
||||
public InstallerReloadTask(BookRefreshListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Book> doInBackground(Installer... params) {
|
||||
List<Book> books = new LinkedList<Book>();
|
||||
for (Installer i: params) {
|
||||
try {
|
||||
i.reloadBookList();
|
||||
} catch (InstallException e) {
|
||||
Log.e(TAG, "Error downloading books from installer: " + i.toString(), e);
|
||||
}
|
||||
books.addAll(i.getBooks());
|
||||
}
|
||||
|
||||
return books;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<Book> result) {
|
||||
super.onPostExecute(result);
|
||||
listener.onRefreshComplete(result);
|
||||
}
|
||||
}
|
||||
|
||||
public interface BookRefreshListener {
|
||||
public void onRefreshComplete(List<Book> results);
|
||||
}
|
||||
|
||||
}
|
@ -37,7 +37,7 @@ public class DownloadNavDrawerFragment extends BaseNavigationDrawerFragment {
|
||||
for (int i = 0; i < displayCategories.length; i++) {
|
||||
sCategories[i] = displayCategories[i].toString();
|
||||
}
|
||||
|
||||
|
||||
mDrawerListView.setAdapter(new ArrayAdapter<String>(getActionBar()
|
||||
.getThemedContext(), android.R.layout.simple_list_item_1,
|
||||
android.R.id.text1, sCategories));
|
||||
|
Loading…
Reference in New Issue
Block a user