mirror of
				https://github.com/MinimalBible/MinimalBible-Legacy
				synced 2025-11-03 18:00:34 -05:00 
			
		
		
		
	Compare commits
	
		
			16 Commits
		
	
	
		
			Rx/Retrola
			...
			master-old
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 3d19e751d9 | |||
| 2eeb8829f2 | |||
| 597b8b29cc | |||
| 26e754a6d8 | |||
| 1c15767d10 | |||
| db5adbd091 | |||
| b19b740c43 | |||
| 969adad9b0 | |||
| 018fe29a75 | |||
| f5800388d3 | |||
| 8c71d4372e | |||
| 348a6da9a3 | |||
| 8e54fdb86d | |||
| d260f98377 | |||
| 3649468e7f | |||
| d9f6eaa339 | 
@ -2,6 +2,11 @@ language: android
 | 
				
			|||||||
env:
 | 
					env:
 | 
				
			||||||
  matrix:
 | 
					  matrix:
 | 
				
			||||||
    - ANDROID_SDKS=android-19,sysimg-19 ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a
 | 
					    - ANDROID_SDKS=android-19,sysimg-19 ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					android:
 | 
				
			||||||
 | 
					  components:
 | 
				
			||||||
 | 
					    - build-tools-20.0.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
before_install:
 | 
					before_install:
 | 
				
			||||||
  - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
 | 
					  - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
 | 
				
			||||||
  - emulator -avd test -no-skin -no-audio -no-window &
 | 
					  - emulator -avd test -no-skin -no-audio -no-window &
 | 
				
			||||||
 | 
				
			|||||||
@ -7,8 +7,7 @@ buildscript {
 | 
				
			|||||||
        mavenCentral()
 | 
					        mavenCentral()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    dependencies {
 | 
					    dependencies {
 | 
				
			||||||
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.3'
 | 
					        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
 | 
				
			||||||
        //classpath 'me.tatarka:gradle-retrolambda:1.3.2'
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -27,10 +26,11 @@ dependencies {
 | 
				
			|||||||
    apt 'de.devland.esperandro:esperandro:1.1.2'
 | 
					    apt 'de.devland.esperandro:esperandro:1.1.2'
 | 
				
			||||||
    // compile 'com.f2prateek.dart:dart:1.1.0'
 | 
					    // compile 'com.f2prateek.dart:dart:1.1.0'
 | 
				
			||||||
    compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
 | 
					    compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
 | 
				
			||||||
    // compile 'de.greenrobot:eventbus:2.2.0'
 | 
					 | 
				
			||||||
    compile 'com.netflix.rxjava:rxjava-android:0.19.0'
 | 
					    compile 'com.netflix.rxjava:rxjava-android:0.19.0'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Handled by appcompat
 | 
					    // Handled by appcompat
 | 
				
			||||||
    // compile 'com.google.android:support-v4:r7'
 | 
					    // compile 'com.google.android:support-v4:r7'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // And our unit testing needs some specific stuff (and specific stuff included again)
 | 
					    // And our unit testing needs some specific stuff (and specific stuff included again)
 | 
				
			||||||
    androidTestCompile 'junit:junit:4.11+'
 | 
					    androidTestCompile 'junit:junit:4.11+'
 | 
				
			||||||
    androidTestCompile 'com.jayway.awaitility:awaitility:1.6.0'
 | 
					    androidTestCompile 'com.jayway.awaitility:awaitility:1.6.0'
 | 
				
			||||||
@ -39,10 +39,10 @@ dependencies {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
android {
 | 
					android {
 | 
				
			||||||
    compileSdkVersion 19
 | 
					    compileSdkVersion 19
 | 
				
			||||||
    buildToolsVersion '19.1.0'
 | 
					    buildToolsVersion '20'
 | 
				
			||||||
    sourceSets {
 | 
					    sourceSets {
 | 
				
			||||||
        main {
 | 
					        main {
 | 
				
			||||||
            manifest.srcFile 'AndroidManifest.xml'
 | 
					            manifest.srcFile 'src/main/AndroidManifest.xml'
 | 
				
			||||||
            java.srcDirs = ['src/main/java']
 | 
					            java.srcDirs = ['src/main/java']
 | 
				
			||||||
            resources.srcDirs = ['src/main/res']
 | 
					            resources.srcDirs = ['src/main/res']
 | 
				
			||||||
            aidl.srcDirs = ['src']
 | 
					            aidl.srcDirs = ['src']
 | 
				
			||||||
@ -52,7 +52,12 @@ android {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Move the tests to tests/java, tests/res, etc...
 | 
					        // Move the tests to tests/java, tests/res, etc...
 | 
				
			||||||
        androidTest.setRoot('src/test')
 | 
					        androidTest {
 | 
				
			||||||
 | 
					            manifest.srcFile 'src/test/AndroidManifest.xml'
 | 
				
			||||||
 | 
					            java.srcDirs = ['src/test/java']
 | 
				
			||||||
 | 
					            resources.srcDirs = ['src/test/res']
 | 
				
			||||||
 | 
					            assets.srcDirs = ['src/test/assets']
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Move the build types to build-types/<type>
 | 
					        // Move the build types to build-types/<type>
 | 
				
			||||||
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
 | 
					        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
 | 
				
			||||||
@ -75,17 +80,4 @@ android {
 | 
				
			|||||||
    lintOptions {
 | 
					    lintOptions {
 | 
				
			||||||
        abortOnError false
 | 
					        abortOnError false
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /*
 | 
					 | 
				
			||||||
    compileOptions {
 | 
					 | 
				
			||||||
        sourceCompatibility JavaVersion.VERSION_1_8
 | 
					 | 
				
			||||||
        targetCompatibility JavaVersion.VERSION_1_8
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    defaultConfig {}
 | 
					 | 
				
			||||||
    productFlavors {
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    buildTypes {
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -6,7 +6,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    <uses-sdk
 | 
					    <uses-sdk
 | 
				
			||||||
        android:minSdkVersion="8"
 | 
					        android:minSdkVersion="8"
 | 
				
			||||||
        android:targetSdkVersion="19" />
 | 
					        android:targetSdkVersion="20" />
 | 
				
			||||||
    <uses-permission android:name="android.permission.INTERNET"/>
 | 
					    <uses-permission android:name="android.permission.INTERNET"/>
 | 
				
			||||||
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
 | 
					    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										11
									
								
								MinimalBible/src/main/assets/book.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								MinimalBible/src/main/assets/book.html
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					<html>
 | 
				
			||||||
 | 
					    <body>
 | 
				
			||||||
 | 
					        <div id="content" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <script type="text/javascript">
 | 
				
			||||||
 | 
					            function set_content(content) {
 | 
				
			||||||
 | 
					                document.getElementById("content").innerHTML = content;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        </script>
 | 
				
			||||||
 | 
					    </body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
@ -2,6 +2,11 @@ package org.bspeice.minimalbible;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import android.app.Application;
 | 
					import android.app.Application;
 | 
				
			||||||
import android.content.Context;
 | 
					import android.content.Context;
 | 
				
			||||||
 | 
					import android.util.Log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.crosswire.jsword.book.sword.SwordBookPath;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import dagger.ObjectGraph;
 | 
					import dagger.ObjectGraph;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -18,6 +23,8 @@ public class MinimalBible extends Application {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
	private static MinimalBible instance;
 | 
						private static MinimalBible instance;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String TAG = "MinimalBible";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Create the application, and persist the application Context
 | 
					     * Create the application, and persist the application Context
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
@ -51,6 +58,7 @@ public class MinimalBible extends Application {
 | 
				
			|||||||
    public void onCreate() {
 | 
					    public void onCreate() {
 | 
				
			||||||
        //TODO: Is this necessary?
 | 
					        //TODO: Is this necessary?
 | 
				
			||||||
        inject(this);
 | 
					        inject(this);
 | 
				
			||||||
 | 
					        setJswordHome();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -67,4 +75,24 @@ public class MinimalBible extends Application {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        return graph;
 | 
					        return graph;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void plusObjGraph(Object... modules) {
 | 
				
			||||||
 | 
					        graph = graph.plus(modules);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Notify jSword that it needs to store files in the Android internal directory
 | 
				
			||||||
 | 
					     * NOTE: Android will uninstall these files if you uninstall MinimalBible.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @SuppressWarnings("null")
 | 
				
			||||||
 | 
					    private void setJswordHome() {
 | 
				
			||||||
 | 
					        // 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);
 | 
				
			||||||
 | 
					        System.setProperty("sword.home", home);
 | 
				
			||||||
 | 
					        SwordBookPath.setDownloadDir(new File(home));
 | 
				
			||||||
 | 
					        Log.d(TAG, "Sword download path: " + SwordBookPath.getSwordDownloadDir());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,7 @@
 | 
				
			|||||||
package org.bspeice.minimalbible.activities;
 | 
					package org.bspeice.minimalbible.activities;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bspeice.minimalbible.activities.downloader.ActivityDownloaderModule;
 | 
					import org.bspeice.minimalbible.activities.downloader.ActivityDownloaderModule;
 | 
				
			||||||
 | 
					import org.bspeice.minimalbible.activities.viewer.ActivityViewerModule;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import dagger.Module;
 | 
					import dagger.Module;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -9,7 +10,8 @@ import dagger.Module;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
@Module(
 | 
					@Module(
 | 
				
			||||||
    includes = {
 | 
					    includes = {
 | 
				
			||||||
        ActivityDownloaderModule.class
 | 
					        ActivityDownloaderModule.class,
 | 
				
			||||||
 | 
					        ActivityViewerModule.class
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
public class ActivityModules {
 | 
					public class ActivityModules {
 | 
				
			||||||
 | 
				
			|||||||
@ -40,7 +40,7 @@ public class BookListFragment extends BaseFragment {
 | 
				
			|||||||
     * The fragment argument representing the section number for this fragment.
 | 
					     * The fragment argument representing the section number for this fragment.
 | 
				
			||||||
     * Not a candidate for Dart (yet) because I would have to write a Parcelable around it.
 | 
					     * Not a candidate for Dart (yet) because I would have to write a Parcelable around it.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private static final String ARG_BOOK_CATEGORY = "book_category";
 | 
					    protected static final String ARG_BOOK_CATEGORY = "book_category";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final String TAG = "BookListFragment";
 | 
					    private final String TAG = "BookListFragment";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -48,9 +48,9 @@ public class BookListFragment extends BaseFragment {
 | 
				
			|||||||
    ListView downloadsAvailable;
 | 
					    ListView downloadsAvailable;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Inject RefreshManager refreshManager;
 | 
					    @Inject RefreshManager refreshManager;
 | 
				
			||||||
    @Inject DownloadPrefs downloadPrefs;
 | 
					    @Inject protected DownloadPrefs downloadPrefs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private ProgressDialog refreshDialog;
 | 
						protected ProgressDialog refreshDialog;
 | 
				
			||||||
    private LayoutInflater inflater;
 | 
					    private LayoutInflater inflater;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -93,7 +93,7 @@ public class BookListFragment extends BaseFragment {
 | 
				
			|||||||
     * Trigger the functionality to display a list of modules. Prompts user if downloading
 | 
					     * Trigger the functionality to display a list of modules. Prompts user if downloading
 | 
				
			||||||
     * from the internet is allowable.
 | 
					     * from the internet is allowable.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 	private void displayModules() {
 | 
					 	protected void displayModules() {
 | 
				
			||||||
		boolean dialogDisplayed = downloadPrefs.hasShownDownloadDialog();
 | 
							boolean dialogDisplayed = downloadPrefs.hasShownDownloadDialog();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (!dialogDisplayed) {
 | 
							if (!dialogDisplayed) {
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					package org.bspeice.minimalbible.activities.viewer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import dagger.Module;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Created by bspeice on 6/18/14.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Module(
 | 
				
			||||||
 | 
					        injects = {
 | 
				
			||||||
 | 
					                BibleViewer.class,
 | 
				
			||||||
 | 
					                BookFragment.class
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					public class ActivityViewerModule {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,27 +1,33 @@
 | 
				
			|||||||
package org.bspeice.minimalbible.activities.viewer;
 | 
					package org.bspeice.minimalbible.activities.viewer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.app.Activity;
 | 
					 | 
				
			||||||
import android.content.Intent;
 | 
					import android.content.Intent;
 | 
				
			||||||
import android.os.Bundle;
 | 
					import android.os.Bundle;
 | 
				
			||||||
 | 
					import android.os.Looper;
 | 
				
			||||||
import android.support.v4.app.Fragment;
 | 
					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.view.LayoutInflater;
 | 
					import android.util.Log;
 | 
				
			||||||
import android.view.Menu;
 | 
					import android.view.Menu;
 | 
				
			||||||
import android.view.MenuItem;
 | 
					import android.view.MenuItem;
 | 
				
			||||||
import android.view.View;
 | 
					 | 
				
			||||||
import android.view.ViewGroup;
 | 
					 | 
				
			||||||
import android.widget.TextView;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bspeice.minimalbible.MinimalBible;
 | 
				
			||||||
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.DownloadActivity;
 | 
					import org.bspeice.minimalbible.activities.downloader.DownloadActivity;
 | 
				
			||||||
 | 
					import org.crosswire.jsword.book.Book;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.inject.Inject;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import rx.android.schedulers.AndroidSchedulers;
 | 
				
			||||||
 | 
					import rx.functions.Action1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class BibleViewer extends BaseActivity implements
 | 
					public class BibleViewer extends BaseActivity implements
 | 
				
			||||||
		BaseNavigationDrawerFragment.NavigationDrawerCallbacks {
 | 
							BaseNavigationDrawerFragment.NavigationDrawerCallbacks {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Inject BookManager bookManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Fragment managing the behaviors, interactions and presentation of the
 | 
						 * Fragment managing the behaviors, interactions and presentation of the
 | 
				
			||||||
	 * navigation drawer.
 | 
						 * navigation drawer.
 | 
				
			||||||
@ -37,6 +43,31 @@ public class BibleViewer extends BaseActivity implements
 | 
				
			|||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	protected void onCreate(Bundle savedInstanceState) {
 | 
						protected void onCreate(Bundle savedInstanceState) {
 | 
				
			||||||
		super.onCreate(savedInstanceState);
 | 
							super.onCreate(savedInstanceState);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        MinimalBible.getApplication().inject(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // If no books are installed, we need to download one first.
 | 
				
			||||||
 | 
					        int count = bookManager.getInstalledBooks()
 | 
				
			||||||
 | 
					                .count()
 | 
				
			||||||
 | 
					                .toBlocking()
 | 
				
			||||||
 | 
					                .last();
 | 
				
			||||||
 | 
					        if (count <= 0) {
 | 
				
			||||||
 | 
					            Intent i = new Intent(this, DownloadActivity.class);
 | 
				
			||||||
 | 
					            startActivityForResult(i, 0);
 | 
				
			||||||
 | 
					            finish();
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            bookManager.getInstalledBooks()
 | 
				
			||||||
 | 
					                    .first()
 | 
				
			||||||
 | 
					                    .subscribeOn(AndroidSchedulers.mainThread())
 | 
				
			||||||
 | 
					                    .subscribe(new Action1<Book>() {
 | 
				
			||||||
 | 
					                        @Override
 | 
				
			||||||
 | 
					                        public void call(Book book) {
 | 
				
			||||||
 | 
					                            Log.d("BibleViewer", "Subscribed to display book: " + book.getName());
 | 
				
			||||||
 | 
					                            displayMainBook(book);
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		setContentView(R.layout.activity_bible_viewer);
 | 
							setContentView(R.layout.activity_bible_viewer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		mNavigationDrawerFragment = (ViewerNavDrawerFragment) getSupportFragmentManager()
 | 
							mNavigationDrawerFragment = (ViewerNavDrawerFragment) getSupportFragmentManager()
 | 
				
			||||||
@ -50,26 +81,13 @@ public class BibleViewer extends BaseActivity implements
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void onNavigationDrawerItemSelected(int position) {
 | 
						public void onNavigationDrawerItemSelected(int position) {
 | 
				
			||||||
		// update the main content by replacing fragments
 | 
							// Handle a navigation movement
 | 
				
			||||||
		FragmentManager fragmentManager = getSupportFragmentManager();
 | 
					 | 
				
			||||||
		fragmentManager
 | 
					 | 
				
			||||||
				.beginTransaction()
 | 
					 | 
				
			||||||
				.replace(R.id.container,
 | 
					 | 
				
			||||||
						PlaceholderFragment.newInstance(position + 1)).commit();
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public void onSectionAttached(int number) {
 | 
					    public void setActionBarTitle(String title) {
 | 
				
			||||||
		switch (number) {
 | 
					        ActionBar actionBar = getSupportActionBar();
 | 
				
			||||||
		case 1:
 | 
					        mTitle = title;
 | 
				
			||||||
			mTitle = getString(R.string.title_section1);
 | 
					        actionBar.setTitle(title);
 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
		case 2:
 | 
					 | 
				
			||||||
			mTitle = getString(R.string.title_section2);
 | 
					 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
		case 3:
 | 
					 | 
				
			||||||
			mTitle = getString(R.string.title_section3);
 | 
					 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public void restoreActionBar() {
 | 
						public void restoreActionBar() {
 | 
				
			||||||
@ -106,48 +124,13 @@ public class BibleViewer extends BaseActivity implements
 | 
				
			|||||||
		return super.onOptionsItemSelected(item);
 | 
							return super.onOptionsItemSelected(item);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    private void displayMainBook(Book b) {
 | 
				
			||||||
	 * A placeholder fragment containing a simple view.
 | 
					        Log.d("BibleViewer", "Initializing main book: " + b.getName());
 | 
				
			||||||
	 */
 | 
					        Log.d("MainThread?", Boolean.toString(Looper.myLooper() == Looper.getMainLooper()));
 | 
				
			||||||
	public static class PlaceholderFragment extends Fragment {
 | 
					        FragmentManager fragmentManager = getSupportFragmentManager();
 | 
				
			||||||
		/**
 | 
					        Fragment f = BookFragment.newInstance(b.getName());
 | 
				
			||||||
		 * The fragment argument representing the section number for this
 | 
					        fragmentManager.beginTransaction()
 | 
				
			||||||
		 * fragment.
 | 
					                .replace(R.id.container, f)
 | 
				
			||||||
		 */
 | 
					                .commit();
 | 
				
			||||||
		private static final String ARG_SECTION_NUMBER = "section_number";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		/**
 | 
					 | 
				
			||||||
		 * Returns a new instance of this fragment for the given section number.
 | 
					 | 
				
			||||||
		 */
 | 
					 | 
				
			||||||
		public static PlaceholderFragment newInstance(int sectionNumber) {
 | 
					 | 
				
			||||||
			PlaceholderFragment fragment = new PlaceholderFragment();
 | 
					 | 
				
			||||||
			Bundle args = new Bundle();
 | 
					 | 
				
			||||||
			args.putInt(ARG_SECTION_NUMBER, sectionNumber);
 | 
					 | 
				
			||||||
			fragment.setArguments(args);
 | 
					 | 
				
			||||||
			return fragment;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
		public PlaceholderFragment() {
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		@Override
 | 
					 | 
				
			||||||
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
 | 
					 | 
				
			||||||
				Bundle savedInstanceState) {
 | 
					 | 
				
			||||||
			View rootView = inflater.inflate(R.layout.fragment_main, container,
 | 
					 | 
				
			||||||
					false);
 | 
					 | 
				
			||||||
			TextView textView = (TextView) rootView
 | 
					 | 
				
			||||||
					.findViewById(R.id.section_label);
 | 
					 | 
				
			||||||
			textView.setText(Integer.toString(getArguments().getInt(
 | 
					 | 
				
			||||||
					ARG_SECTION_NUMBER)));
 | 
					 | 
				
			||||||
			return rootView;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		@Override
 | 
					 | 
				
			||||||
		public void onAttach(Activity activity) {
 | 
					 | 
				
			||||||
			super.onAttach(activity);
 | 
					 | 
				
			||||||
			((BibleViewer) activity).onSectionAttached(getArguments().getInt(
 | 
					 | 
				
			||||||
					ARG_SECTION_NUMBER));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,140 @@
 | 
				
			|||||||
 | 
					package org.bspeice.minimalbible.activities.viewer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.app.Activity;
 | 
				
			||||||
 | 
					import android.os.Bundle;
 | 
				
			||||||
 | 
					import android.util.Log;
 | 
				
			||||||
 | 
					import android.view.LayoutInflater;
 | 
				
			||||||
 | 
					import android.view.View;
 | 
				
			||||||
 | 
					import android.view.ViewGroup;
 | 
				
			||||||
 | 
					import android.webkit.WebView;
 | 
				
			||||||
 | 
					import android.webkit.WebViewClient;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bspeice.minimalbible.MinimalBible;
 | 
				
			||||||
 | 
					import org.bspeice.minimalbible.R;
 | 
				
			||||||
 | 
					import org.bspeice.minimalbible.activities.BaseFragment;
 | 
				
			||||||
 | 
					import org.crosswire.jsword.book.Book;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.inject.Inject;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import butterknife.ButterKnife;
 | 
				
			||||||
 | 
					import butterknife.InjectView;
 | 
				
			||||||
 | 
					import rx.android.schedulers.AndroidSchedulers;
 | 
				
			||||||
 | 
					import rx.functions.Action1;
 | 
				
			||||||
 | 
					import rx.functions.Func1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * A placeholder fragment containing a simple view.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class BookFragment extends BaseFragment {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Inject BookManager bookManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @InjectView(R.id.book_content)
 | 
				
			||||||
 | 
					    WebView mainContent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static final String ARG_BOOK_NAME = "book_name";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Book mBook;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Returns a new instance of this fragment for the given section number.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static BookFragment newInstance(String bookName) {
 | 
				
			||||||
 | 
					        BookFragment fragment = new BookFragment();
 | 
				
			||||||
 | 
					        Bundle args = new Bundle();
 | 
				
			||||||
 | 
					        args.putString(ARG_BOOK_NAME, bookName);
 | 
				
			||||||
 | 
					        fragment.setArguments(args);
 | 
				
			||||||
 | 
					        return fragment;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public BookFragment() {
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void onCreate(Bundle state) {
 | 
				
			||||||
 | 
					        super.onCreate(state);
 | 
				
			||||||
 | 
					        MinimalBible.getApplication().inject(this);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public View onCreateView(LayoutInflater inflater, ViewGroup container,
 | 
				
			||||||
 | 
					            Bundle savedInstanceState) {
 | 
				
			||||||
 | 
					        View rootView = inflater.inflate(R.layout.fragment_viewer_main, container,
 | 
				
			||||||
 | 
					                false);
 | 
				
			||||||
 | 
					        ButterKnife.inject(this, rootView);
 | 
				
			||||||
 | 
					        mainContent.getSettings().setJavaScriptEnabled(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // TODO: Load initial text from SharedPreferences
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // And due to Observable async, we can kick off fetching the actual book asynchronously!
 | 
				
			||||||
 | 
					        bookManager.getInstalledBooks()
 | 
				
			||||||
 | 
					                .first(new Func1<Book, Boolean>() {
 | 
				
			||||||
 | 
					                    @Override
 | 
				
			||||||
 | 
					                    public Boolean call(Book book) {
 | 
				
			||||||
 | 
					                        String mBookName = getArguments().getString(ARG_BOOK_NAME);
 | 
				
			||||||
 | 
					                        return book.getName().equals(mBookName);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					                .observeOn(AndroidSchedulers.mainThread())
 | 
				
			||||||
 | 
					                .subscribe(new Action1<Book>() {
 | 
				
			||||||
 | 
					                    @Override
 | 
				
			||||||
 | 
					                    public void call(Book book) {
 | 
				
			||||||
 | 
					                        BookFragment.this.mBook = book;
 | 
				
			||||||
 | 
					                        displayBook(book);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }, new Action1<Throwable>() {
 | 
				
			||||||
 | 
					                    @Override
 | 
				
			||||||
 | 
					                    public void call(Throwable throwable) {
 | 
				
			||||||
 | 
					                        Log.d("BookFragment", "No books installed?");
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return rootView;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // TODO: Remove?
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void onAttach(Activity activity) {
 | 
				
			||||||
 | 
					        super.onAttach(activity);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void displayBook(Book b) {
 | 
				
			||||||
 | 
					        Log.d("BookFragment", b.getName());
 | 
				
			||||||
 | 
					        ((BibleViewer)getActivity()).setActionBarTitle(b.getInitials());
 | 
				
			||||||
 | 
					        mainContent.loadUrl(getString(R.string.content_page));
 | 
				
			||||||
 | 
					        mainContent.setWebViewClient(new WebViewClient(){
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public void onPageFinished(WebView view, String url) {
 | 
				
			||||||
 | 
					                super.onPageFinished(view, url);
 | 
				
			||||||
 | 
					                invokeJavascript("set_content", BookFragment.this.mBook.getName());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void invokeJavascript(String function, Object arg) {
 | 
				
			||||||
 | 
					        mainContent.loadUrl("javascript:" + function + "('" + arg.toString() + "')");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void invokeJavascript(String function, List<Object> args) {
 | 
				
			||||||
 | 
					        mainContent.loadUrl("javascript:" + function + "(" + joinString(",", args.toArray()) + ")");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Convenience from http://stackoverflow.com/a/17795110/1454178
 | 
				
			||||||
 | 
					    public static String joinString(String join, Object... strings) {
 | 
				
			||||||
 | 
					        if (strings == null || strings.length == 0) {
 | 
				
			||||||
 | 
					            return "";
 | 
				
			||||||
 | 
					        } else if (strings.length == 1) {
 | 
				
			||||||
 | 
					            return strings[0].toString();
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            StringBuilder sb = new StringBuilder();
 | 
				
			||||||
 | 
					            sb.append(strings[0]);
 | 
				
			||||||
 | 
					            for (int i = 1; i < strings.length; i++) {
 | 
				
			||||||
 | 
					                sb.append(join).append(strings[i].toString());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return sb.toString();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,50 @@
 | 
				
			|||||||
 | 
					package org.bspeice.minimalbible.activities.viewer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.crosswire.jsword.book.Book;
 | 
				
			||||||
 | 
					import org.crosswire.jsword.book.Books;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.inject.Inject;
 | 
				
			||||||
 | 
					import javax.inject.Singleton;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import rx.Observable;
 | 
				
			||||||
 | 
					import rx.functions.Action0;
 | 
				
			||||||
 | 
					import rx.functions.Action1;
 | 
				
			||||||
 | 
					import rx.schedulers.Schedulers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Created by bspeice on 6/18/14.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Singleton
 | 
				
			||||||
 | 
					public class BookManager {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Observable<Book> installedBooks;
 | 
				
			||||||
 | 
					    private Boolean refreshComplete;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Inject
 | 
				
			||||||
 | 
					    BookManager() {
 | 
				
			||||||
 | 
					        installedBooks = Observable.from(Books.installed().getBooks())
 | 
				
			||||||
 | 
					            .cache();
 | 
				
			||||||
 | 
					        installedBooks.subscribeOn(Schedulers.io())
 | 
				
			||||||
 | 
					                .subscribe(new Action1<Book>() {
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public void call(Book book) {}
 | 
				
			||||||
 | 
					        }, new Action1<Throwable>() {
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public void call(Throwable throwable) {}
 | 
				
			||||||
 | 
					        }, new Action0() {
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public void call() {
 | 
				
			||||||
 | 
					                BookManager.this.refreshComplete = true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Observable<Book> getInstalledBooks() {
 | 
				
			||||||
 | 
					        return installedBooks;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Boolean isRefreshComplete() {
 | 
				
			||||||
 | 
					        return refreshComplete;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,16 +0,0 @@
 | 
				
			|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 | 
					 | 
				
			||||||
    xmlns:tools="http://schemas.android.com/tools"
 | 
					 | 
				
			||||||
    android:layout_width="match_parent"
 | 
					 | 
				
			||||||
    android:layout_height="match_parent"
 | 
					 | 
				
			||||||
    android:paddingBottom="@dimen/activity_vertical_margin"
 | 
					 | 
				
			||||||
    android:paddingLeft="@dimen/activity_horizontal_margin"
 | 
					 | 
				
			||||||
    android:paddingRight="@dimen/activity_horizontal_margin"
 | 
					 | 
				
			||||||
    android:paddingTop="@dimen/activity_vertical_margin"
 | 
					 | 
				
			||||||
    tools:context="org.bspeice.minimalbible.MainActivity$PlaceholderFragment" >
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <TextView
 | 
					 | 
				
			||||||
        android:id="@+id/section_label"
 | 
					 | 
				
			||||||
        android:layout_width="wrap_content"
 | 
					 | 
				
			||||||
        android:layout_height="wrap_content" />
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
</RelativeLayout>
 | 
					 | 
				
			||||||
@ -3,6 +3,7 @@
 | 
				
			|||||||
    android:id="@+id/list_nav_drawer"
 | 
					    android:id="@+id/list_nav_drawer"
 | 
				
			||||||
    android:layout_width="match_parent"
 | 
					    android:layout_width="match_parent"
 | 
				
			||||||
    android:layout_height="match_parent"
 | 
					    android:layout_height="match_parent"
 | 
				
			||||||
 | 
					    android:background="#cccccc"
 | 
				
			||||||
    android:choiceMode="singleChoice"
 | 
					    android:choiceMode="singleChoice"
 | 
				
			||||||
    android:divider="@android:color/transparent"
 | 
					    android:divider="@android:color/transparent"
 | 
				
			||||||
    android:dividerHeight="0dp"
 | 
					    android:dividerHeight="0dp"
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										12
									
								
								MinimalBible/src/main/res/layout/fragment_viewer_main.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								MinimalBible/src/main/res/layout/fragment_viewer_main.xml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 | 
				
			||||||
 | 
					    xmlns:tools="http://schemas.android.com/tools"
 | 
				
			||||||
 | 
					    android:layout_width="match_parent"
 | 
				
			||||||
 | 
					    android:layout_height="match_parent"
 | 
				
			||||||
 | 
					    tools:context="org.bspeice.minimalbible.MainActivity$PlaceholderFragment" >
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <WebView
 | 
				
			||||||
 | 
					        android:id="@+id/book_content"
 | 
				
			||||||
 | 
					        android:layout_width="fill_parent"
 | 
				
			||||||
 | 
					        android:layout_height="fill_parent" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</RelativeLayout>
 | 
				
			||||||
@ -3,10 +3,6 @@
 | 
				
			|||||||
    xmlns:tools="http://schemas.android.com/tools"
 | 
					    xmlns:tools="http://schemas.android.com/tools"
 | 
				
			||||||
    tools:context="org.bspeice.minimalbible.MainActivity" >
 | 
					    tools:context="org.bspeice.minimalbible.MainActivity" >
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <item
 | 
					 | 
				
			||||||
        android:id="@+id/action_example"
 | 
					 | 
				
			||||||
        android:title="@string/action_example"
 | 
					 | 
				
			||||||
        app:showAsAction="withText|ifRoom"/>
 | 
					 | 
				
			||||||
    <item
 | 
					    <item
 | 
				
			||||||
        android:id="@+id/action_settings"
 | 
					        android:id="@+id/action_settings"
 | 
				
			||||||
        android:orderInCategory="100"
 | 
					        android:orderInCategory="100"
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										4
									
								
								MinimalBible/src/main/res/values/html_strings.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								MinimalBible/src/main/res/values/html_strings.xml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="utf-8"?>
 | 
				
			||||||
 | 
					<resources>
 | 
				
			||||||
 | 
					    <string name="content_page">file:///android_asset/book.html</string>
 | 
				
			||||||
 | 
					</resources>
 | 
				
			||||||
							
								
								
									
										19
									
								
								MinimalBible/src/test/AndroidManifest.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								MinimalBible/src/test/AndroidManifest.xml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 | 
				
			||||||
 | 
					    package="org.bspeice.minimalbible">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <uses-sdk
 | 
				
			||||||
 | 
					        android:minSdkVersion="8"
 | 
				
			||||||
 | 
					        android:targetSdkVersion="20" />
 | 
				
			||||||
 | 
					    <uses-permission android:name="android.permission.INTERNET"/>
 | 
				
			||||||
 | 
					    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <application
 | 
				
			||||||
 | 
					        android:allowBackup="true"
 | 
				
			||||||
 | 
					        android:icon="@drawable/ic_launcher"
 | 
				
			||||||
 | 
					        android:label="@string/app_name"
 | 
				
			||||||
 | 
					        android:theme="@style/AppTheme"
 | 
				
			||||||
 | 
					        android:name="org.bspeice.minimalbible.test.MinimalBibleTest" >
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    </application>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</manifest>
 | 
				
			||||||
@ -1,99 +0,0 @@
 | 
				
			|||||||
package org.bspeice.minimalbible.test;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import android.test.InstrumentationTestCase;
 | 
					 | 
				
			||||||
import android.util.Log;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bspeice.minimalbible.MinimalBible;
 | 
					 | 
				
			||||||
import org.bspeice.minimalbible.MinimalBibleModules;
 | 
					 | 
				
			||||||
import org.bspeice.minimalbible.activities.downloader.manager.BookDownloadManager;
 | 
					 | 
				
			||||||
import org.bspeice.minimalbible.activities.downloader.manager.DLProgressEvent;
 | 
					 | 
				
			||||||
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
 | 
					 | 
				
			||||||
import org.bspeice.minimalbible.activities.downloader.manager.InstalledManager;
 | 
					 | 
				
			||||||
import org.bspeice.minimalbible.activities.downloader.manager.RefreshManager;
 | 
					 | 
				
			||||||
import org.crosswire.jsword.book.Book;
 | 
					 | 
				
			||||||
import org.crosswire.jsword.book.BookException;
 | 
					 | 
				
			||||||
import org.crosswire.jsword.book.Books;
 | 
					 | 
				
			||||||
import org.crosswire.jsword.book.install.InstallException;
 | 
					 | 
				
			||||||
import org.crosswire.jsword.book.install.Installer;
 | 
					 | 
				
			||||||
import org.crosswire.jsword.passage.NoSuchKeyException;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.HashMap;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
import java.util.Map;
 | 
					 | 
				
			||||||
import java.util.concurrent.Callable;
 | 
					 | 
				
			||||||
import java.util.concurrent.CountDownLatch;
 | 
					 | 
				
			||||||
import java.util.concurrent.TimeUnit;
 | 
					 | 
				
			||||||
import java.util.concurrent.atomic.AtomicBoolean;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import javax.inject.Inject;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import dagger.Module;
 | 
					 | 
				
			||||||
import dagger.ObjectGraph;
 | 
					 | 
				
			||||||
import rx.Observable;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import static com.jayway.awaitility.Awaitility.await;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Tests for the Download activity
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public class DownloadActivityTest extends InstrumentationTestCase {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Module(addsTo = MinimalBibleModules.class,
 | 
					 | 
				
			||||||
            injects = DownloadActivityTest.class)
 | 
					 | 
				
			||||||
    public static class DownloadActivityTestModule {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Inject DownloadManager dm;
 | 
					 | 
				
			||||||
    @Inject InstalledManager im;
 | 
					 | 
				
			||||||
    @Inject RefreshManager rm;
 | 
					 | 
				
			||||||
    @Inject BookDownloadManager bdm;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void setUp() {
 | 
					 | 
				
			||||||
        MinimalBible application = MinimalBible.getApplication();
 | 
					 | 
				
			||||||
        ObjectGraph graph = application.getObjGraph();
 | 
					 | 
				
			||||||
        ObjectGraph plusGraph = graph.plus(DownloadActivityTestModule.class);
 | 
					 | 
				
			||||||
        plusGraph.inject(this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void testBasicAssertion() {
 | 
					 | 
				
			||||||
        assertEquals(true, true);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Test that we can successfully download and remove a book
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public void testInstallAndRemoveBook() {
 | 
					 | 
				
			||||||
        // Install a book
 | 
					 | 
				
			||||||
        Installer i = (Installer) dm.getInstallers().values().toArray()[0];
 | 
					 | 
				
			||||||
        final Book testBook = i.getBooks().get(0);
 | 
					 | 
				
			||||||
        bdm.installBook(testBook);
 | 
					 | 
				
			||||||
        await().atMost(30, TimeUnit.SECONDS)
 | 
					 | 
				
			||||||
                .until(new Callable<Boolean>() {
 | 
					 | 
				
			||||||
                    @Override
 | 
					 | 
				
			||||||
                    public Boolean call() throws Exception {
 | 
					 | 
				
			||||||
                        return Books.installed().getBooks().contains(testBook);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Validate that we can actually do something with the book
 | 
					 | 
				
			||||||
        // TODO: Validate that the book exists on the filesystem too
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            assertNotNull(testBook.getRawText(testBook.getKey("Gen 1:1")));
 | 
					 | 
				
			||||||
        } catch (BookException e) {
 | 
					 | 
				
			||||||
            fail(e.getMessage());
 | 
					 | 
				
			||||||
        } catch (NoSuchKeyException e) {
 | 
					 | 
				
			||||||
            fail(e.getMessage());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Remove the book and make sure it's gone
 | 
					 | 
				
			||||||
        // TODO: Validate that the book is off the filesystem
 | 
					 | 
				
			||||||
        im.removeBook(testBook);
 | 
					 | 
				
			||||||
        await().atMost(10, TimeUnit.SECONDS)
 | 
					 | 
				
			||||||
                .until(new Callable<Boolean>() {
 | 
					 | 
				
			||||||
                    @Override
 | 
					 | 
				
			||||||
                    public Boolean call() throws Exception {
 | 
					 | 
				
			||||||
                        return !Books.installed().getBooks().contains(testBook);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					package org.bspeice.minimalbible.test;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bspeice.minimalbible.MinimalBible;
 | 
				
			||||||
 | 
					import org.bspeice.minimalbible.MinimalBibleModules;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import dagger.Module;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Master module for MinimalBible
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Module(
 | 
				
			||||||
 | 
					    injects = {
 | 
				
			||||||
 | 
					        MinimalBible.class
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    includes = {
 | 
				
			||||||
 | 
					            MinimalBibleModules.class
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					public class MinimalBibleModulesTest {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,75 @@
 | 
				
			|||||||
 | 
					package org.bspeice.minimalbible.test;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.content.Context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bspeice.minimalbible.MinimalBible;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import dagger.ObjectGraph;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class MinimalBibleTest extends MinimalBible {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * The graph used by Dagger to track dependencies
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private ObjectGraph graph;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * A singleton reference to the Application currently being run.
 | 
				
			||||||
 | 
					     * Used mostly so we have a fixed point to get the App Context from
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
						private static MinimalBibleTest instance;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String TAG = "MinimalBibleTest";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Create the application, and persist the application Context
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
						public MinimalBibleTest() {
 | 
				
			||||||
 | 
							instance = this;		
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Get the Application Context. Please note, all attempts to get the App Context should come
 | 
				
			||||||
 | 
					     * through here, and please be sure that the Application won't satisfy what you need.
 | 
				
			||||||
 | 
					     * @return The Application Context
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
						public static Context getAppContext() {
 | 
				
			||||||
 | 
					        return instance;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Get the Application, rather than just the Application Context. You likely should be using
 | 
				
			||||||
 | 
					     * this, rather than {@link #getAppContext()}
 | 
				
			||||||
 | 
					     * @return The MinimalBible {@link android.app.Application} object
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static MinimalBibleTest getApplication() {
 | 
				
			||||||
 | 
					        return instance;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Create the {@link android.app.Application}. Responsible for building and
 | 
				
			||||||
 | 
					     * holding on to the master ObjectGraph.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void onCreate() {
 | 
				
			||||||
 | 
					        super.onCreate();
 | 
				
			||||||
 | 
					        //TODO: Is this necessary?
 | 
				
			||||||
 | 
					        inject(this);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Inject a Dagger object
 | 
				
			||||||
 | 
					     * @param o The object to be injected
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void inject(Object o) {
 | 
				
			||||||
 | 
					        getObjGraph().inject(o);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public ObjectGraph getObjGraph() {
 | 
				
			||||||
 | 
					        if (graph == null) {
 | 
				
			||||||
 | 
					            graph = ObjectGraph.create(MinimalBibleModulesTest.class);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return graph;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,117 @@
 | 
				
			|||||||
 | 
					package org.bspeice.minimalbible.test.activities.downloader;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.os.Bundle;
 | 
				
			||||||
 | 
					import android.os.Handler;
 | 
				
			||||||
 | 
					import android.os.Looper;
 | 
				
			||||||
 | 
					import android.support.v4.app.Fragment;
 | 
				
			||||||
 | 
					import android.support.v4.app.FragmentManager;
 | 
				
			||||||
 | 
					import android.test.ActivityInstrumentationTestCase2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bspeice.minimalbible.MinimalBible;
 | 
				
			||||||
 | 
					import org.bspeice.minimalbible.activities.downloader.BookListFragment;
 | 
				
			||||||
 | 
					import org.bspeice.minimalbible.activities.downloader.DownloadActivity;
 | 
				
			||||||
 | 
					import org.bspeice.minimalbible.activities.downloader.DownloadPrefs;
 | 
				
			||||||
 | 
					import org.bspeice.minimalbible.test.MinimalBibleModulesTest;
 | 
				
			||||||
 | 
					import org.crosswire.jsword.book.BookCategory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.concurrent.CountDownLatch;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import dagger.Module;
 | 
				
			||||||
 | 
					import de.devland.esperandro.Esperandro;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Created by bspeice on 6/23/14.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class BookListFragmentTest extends ActivityInstrumentationTestCase2<DownloadActivity> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Module(injects = TestDialogDisplayedIfFirstTimeFragment.class,
 | 
				
			||||||
 | 
					            addsTo = MinimalBibleModulesTest.class
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    protected static class BookListFragmentTestModule{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public BookListFragmentTest() {
 | 
				
			||||||
 | 
					        super(DownloadActivity.class);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    FragmentManager mFragmentManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setUp() throws Exception {
 | 
				
			||||||
 | 
					        super.setUp();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        mFragmentManager = getActivity().getSupportFragmentManager();
 | 
				
			||||||
 | 
					        assertNotNull(mFragmentManager);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public <F extends Fragment> F startFragment(F fragment) {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            mFragmentManager.beginTransaction()
 | 
				
			||||||
 | 
					                    .replace(android.R.id.content, fragment)
 | 
				
			||||||
 | 
					                    .commit();
 | 
				
			||||||
 | 
					        } catch (Exception e) {
 | 
				
			||||||
 | 
					            e.printStackTrace();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        final CountDownLatch signal = new CountDownLatch(1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        new Handler(Looper.getMainLooper()).post(new Runnable() {
 | 
				
			||||||
 | 
					            @Override
 | 
				
			||||||
 | 
					            public void run() {
 | 
				
			||||||
 | 
					                mFragmentManager.executePendingTransactions();
 | 
				
			||||||
 | 
					                signal.countDown();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            signal.await();
 | 
				
			||||||
 | 
					        } catch (InterruptedException e) {
 | 
				
			||||||
 | 
					            e.printStackTrace();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return (F)(mFragmentManager.findFragmentById(android.R.id.content));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected class TestDialogDisplayedIfFirstTimeFragment extends BookListFragment {
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         * If the refresh dialog is blank after calling display, it must be showing the warning
 | 
				
			||||||
 | 
					         * @return Whether the warning dialog is showing
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        public boolean callDisplayModules(DownloadPrefs prefs) {
 | 
				
			||||||
 | 
					            // Inject the new preferences...
 | 
				
			||||||
 | 
					            this.downloadPrefs = prefs;
 | 
				
			||||||
 | 
					            displayModules();
 | 
				
			||||||
 | 
					            return (refreshDialog == null);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void setArgs(BookCategory c) {
 | 
				
			||||||
 | 
					            Bundle args = new Bundle();
 | 
				
			||||||
 | 
					            args.putString(ARG_BOOK_CATEGORY, c.toString());
 | 
				
			||||||
 | 
					            this.setArguments(args);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void testDialogDisplayedIfFirstTime() {
 | 
				
			||||||
 | 
					        ((MinimalBible)getActivity().getApplication()).plusObjGraph(BookListFragmentTestModule.class);
 | 
				
			||||||
 | 
					        TestDialogDisplayedIfFirstTimeFragment f = new TestDialogDisplayedIfFirstTimeFragment();
 | 
				
			||||||
 | 
					        f.setArgs(BookCategory.BIBLE);
 | 
				
			||||||
 | 
					        startFragment(f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        DownloadPrefs prefs = Esperandro.getPreferences(DownloadPrefs.class, getActivity());
 | 
				
			||||||
 | 
					        prefs.hasShownDownloadDialog(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assertNotNull(f);
 | 
				
			||||||
 | 
					        assertTrue(f.callDisplayModules(Esperandro.getPreferences(DownloadPrefs.class, getActivity())));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void testRefreshDisplayedAfterFirstTime() {
 | 
				
			||||||
 | 
					        ((MinimalBible)getActivity().getApplication()).plusObjGraph(BookListFragmentTestModule.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        TestDialogDisplayedIfFirstTimeFragment f = new TestDialogDisplayedIfFirstTimeFragment();
 | 
				
			||||||
 | 
					        f.setArgs(BookCategory.BIBLE);
 | 
				
			||||||
 | 
					        startFragment(f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        DownloadPrefs prefs = Esperandro.getPreferences(DownloadPrefs.class, getActivity());
 | 
				
			||||||
 | 
					        prefs.hasShownDownloadDialog(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assertNotNull(f);
 | 
				
			||||||
 | 
					        assertFalse(f.callDisplayModules(Esperandro.getPreferences(DownloadPrefs.class, getActivity())));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -6,7 +6,7 @@ dependencies {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
android {
 | 
					android {
 | 
				
			||||||
    compileSdkVersion 19
 | 
					    compileSdkVersion 19
 | 
				
			||||||
    buildToolsVersion "19.1.0"
 | 
					    buildToolsVersion "20"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sourceSets {
 | 
					    sourceSets {
 | 
				
			||||||
        main {
 | 
					        main {
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,6 @@ buildscript {
 | 
				
			|||||||
        mavenCentral()
 | 
					        mavenCentral()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    dependencies {
 | 
					    dependencies {
 | 
				
			||||||
        classpath 'com.android.tools.build:gradle:0.11.+'
 | 
					        classpath 'com.android.tools.build:gradle:0.12.+'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							@ -1,4 +1,4 @@
 | 
				
			|||||||
#Tue Jun 10 19:26:46 EDT 2014
 | 
					#Fri Jun 27 21:15:50 EDT 2014
 | 
				
			||||||
distributionBase=GRADLE_USER_HOME
 | 
					distributionBase=GRADLE_USER_HOME
 | 
				
			||||||
distributionPath=wrapper/dists
 | 
					distributionPath=wrapper/dists
 | 
				
			||||||
zipStoreBase=GRADLE_USER_HOME
 | 
					zipStoreBase=GRADLE_USER_HOME
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user