mirror of
				https://github.com/MinimalBible/MinimalBible-Legacy
				synced 2025-11-04 02:10:30 -05:00 
			
		
		
		
	Oh man is it ugly, but I can download module lists.
This commit is contained in:
		@ -7,12 +7,14 @@
 | 
				
			|||||||
    <uses-sdk
 | 
					    <uses-sdk
 | 
				
			||||||
        android:minSdkVersion="8"
 | 
					        android:minSdkVersion="8"
 | 
				
			||||||
        android:targetSdkVersion="19" />
 | 
					        android:targetSdkVersion="19" />
 | 
				
			||||||
 | 
					    <uses-permission android:name="android.permission.INTERNET"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <application
 | 
					    <application
 | 
				
			||||||
        android:allowBackup="true"
 | 
					        android:allowBackup="true"
 | 
				
			||||||
        android:icon="@drawable/ic_launcher"
 | 
					        android:icon="@drawable/ic_launcher"
 | 
				
			||||||
        android:label="@string/app_name"
 | 
					        android:label="@string/app_name"
 | 
				
			||||||
        android:theme="@style/AppTheme" >
 | 
					        android:theme="@style/AppTheme"
 | 
				
			||||||
 | 
					        android:name="org.bspeice.minimalbible.MinimalBible" >
 | 
				
			||||||
        <activity
 | 
					        <activity
 | 
				
			||||||
            android:name="org.bspeice.minimalbible.activities.viewer.BibleViewer"
 | 
					            android:name="org.bspeice.minimalbible.activities.viewer.BibleViewer"
 | 
				
			||||||
            android:label="@string/app_name" >
 | 
					            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;
 | 
					package org.bspeice.minimalbible.activities.downloader;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bspeice.minimalbible.MinimalBibleConstants;
 | 
					import org.bspeice.minimalbible.MinimalBibleConstants;
 | 
				
			||||||
import org.bspeice.minimalbible.R;
 | 
					import org.bspeice.minimalbible.R;
 | 
				
			||||||
import org.bspeice.minimalbible.activities.BaseActivity;
 | 
					import org.bspeice.minimalbible.activities.BaseActivity;
 | 
				
			||||||
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
 | 
					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.Activity;
 | 
				
			||||||
import android.app.AlertDialog;
 | 
					import android.app.AlertDialog;
 | 
				
			||||||
 | 
					import android.app.ProgressDialog;
 | 
				
			||||||
import android.content.DialogInterface;
 | 
					import android.content.DialogInterface;
 | 
				
			||||||
import android.content.SharedPreferences;
 | 
					import android.content.SharedPreferences;
 | 
				
			||||||
import android.os.Bundle;
 | 
					import android.os.Bundle;
 | 
				
			||||||
@ -14,6 +19,7 @@ import android.support.v4.app.Fragment;
 | 
				
			|||||||
import android.support.v4.app.FragmentManager;
 | 
					import android.support.v4.app.FragmentManager;
 | 
				
			||||||
import android.support.v4.widget.DrawerLayout;
 | 
					import android.support.v4.widget.DrawerLayout;
 | 
				
			||||||
import android.support.v7.app.ActionBar;
 | 
					import android.support.v7.app.ActionBar;
 | 
				
			||||||
 | 
					import android.util.Log;
 | 
				
			||||||
import android.view.LayoutInflater;
 | 
					import android.view.LayoutInflater;
 | 
				
			||||||
import android.view.Menu;
 | 
					import android.view.Menu;
 | 
				
			||||||
import android.view.MenuItem;
 | 
					import android.view.MenuItem;
 | 
				
			||||||
@ -25,6 +31,8 @@ import android.widget.Toast;
 | 
				
			|||||||
public class DownloadActivity extends BaseActivity implements
 | 
					public class DownloadActivity extends BaseActivity implements
 | 
				
			||||||
		BaseNavigationDrawerFragment.NavigationDrawerCallbacks {
 | 
							BaseNavigationDrawerFragment.NavigationDrawerCallbacks {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private ProgressDialog refreshDialog;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Fragment managing the behaviors, interactions and presentation of the
 | 
						 * Fragment managing the behaviors, interactions and presentation of the
 | 
				
			||||||
	 * navigation drawer.
 | 
						 * navigation drawer.
 | 
				
			||||||
@ -49,6 +57,10 @@ public class DownloadActivity extends BaseActivity implements
 | 
				
			|||||||
		// Set up the drawer.
 | 
							// Set up the drawer.
 | 
				
			||||||
		mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
 | 
							mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
 | 
				
			||||||
				(DrawerLayout) findViewById(R.id.drawer_layout));
 | 
									(DrawerLayout) findViewById(R.id.drawer_layout));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Refresh our modules - prompts user if they do actually want to
 | 
				
			||||||
 | 
							// connect to the internet
 | 
				
			||||||
 | 
							doRefreshModules();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
@ -151,38 +163,58 @@ public class DownloadActivity extends BaseActivity implements
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private void displayInternetWarning() {
 | 
						private void doRefreshModules() {
 | 
				
			||||||
		SharedPreferences prefs = getSharedPreferences(MinimalBibleConstants.DOWNLOAD_PREFS_FILE, MODE_PRIVATE);
 | 
							SharedPreferences prefs = getSharedPreferences(
 | 
				
			||||||
 | 
									MinimalBibleConstants.DOWNLOAD_PREFS_FILE, MODE_PRIVATE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// If downloading has not been enabled, or user has permanently disabled downloading, WARN THEM!
 | 
							// If downloading has not been enabled, or user has permanently disabled
 | 
				
			||||||
		if (!prefs.getBoolean(MinimalBibleConstants.KEY_DOWNLOAD_ENABLED, false) || prefs.getBoolean(MinimalBibleConstants.KEY_PERM_DISABLE_DOWNLOAD, false)) {
 | 
							// 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);
 | 
								AlertDialog.Builder builder = new AlertDialog.Builder(this);
 | 
				
			||||||
			DownloadDialogListener dialogListener = new DownloadDialogListener();
 | 
								DownloadDialogListener dialogListener = new DownloadDialogListener();
 | 
				
			||||||
			builder.setMessage("About to contact servers to download content. Continue?")
 | 
								builder.setMessage(
 | 
				
			||||||
				.setPositiveButton("Yes", dialogListener).setNegativeButton("No", dialogListener)
 | 
										"About to contact servers to download content. Continue?")
 | 
				
			||||||
 | 
										.setPositiveButton("Yes", dialogListener)
 | 
				
			||||||
 | 
										.setNegativeButton("No", dialogListener)
 | 
				
			||||||
					.setCancelable(false).show();
 | 
										.setCancelable(false).show();
 | 
				
			||||||
		} else {
 | 
							} 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
 | 
							@Override
 | 
				
			||||||
		public void onClick(DialogInterface dialog, int which) {
 | 
							public void onClick(DialogInterface dialog, int which) {
 | 
				
			||||||
			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 = getSharedPreferences(MinimalBibleConstants.DOWNLOAD_PREFS_FILE, MODE_PRIVATE);
 | 
									SharedPreferences prefs = getSharedPreferences(
 | 
				
			||||||
				prefs.edit().putBoolean(MinimalBibleConstants.KEY_DOWNLOAD_ENABLED, true).commit();
 | 
											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.
 | 
									// And warn them that it has been enabled in the future.
 | 
				
			||||||
				Toast.makeText(DownloadActivity.this,
 | 
									Toast.makeText(DownloadActivity.this,
 | 
				
			||||||
						"Downloading now enabled. Disable in settings.", Toast.LENGTH_SHORT).show();
 | 
											"Downloading now enabled. Disable in settings.",
 | 
				
			||||||
				downloadModules();
 | 
											Toast.LENGTH_SHORT).show();
 | 
				
			||||||
 | 
									refreshModules();
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			case DialogInterface.BUTTON_NEGATIVE:
 | 
								case DialogInterface.BUTTON_NEGATIVE:
 | 
				
			||||||
@ -194,4 +226,19 @@ public class DownloadActivity extends BaseActivity implements
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user