20 Commits

Author SHA1 Message Date
4269988b7c Backport to Java 6...
Android Studio automatically folds lambda-style, so it won't get too out of hand.
2014-06-14 16:41:11 -04:00
e945ef51a7 Get the unit tests passing again
Note: I need to write more. Lots more.
2014-06-14 16:25:13 -04:00
04fe4d13b4 Add lots of Lint fixes 2014-06-14 15:13:44 -04:00
dda5c79299 Fix books not being removed... 2014-06-14 15:04:17 -04:00
93abe065a2 Fix a NetworkOnMainThreadException 2014-06-14 14:10:43 -04:00
ba3c6ebe6c Some refactoring and Async fixes. 2014-06-14 14:08:50 -04:00
3869cf0b9b Synchronization needs fixing, otherwise works. 2014-06-10 23:46:29 -04:00
8d17b6db64 Silly DownloadManager
Injects are for classes that need them.
2014-06-10 23:44:35 -04:00
7070c933d1 Fix the dagger compile errors
If you have an @Singleton with no @Injects inside it, you need to add an
@Injects constructor for Dagger to validate.
2014-06-10 23:41:35 -04:00
28dfec81d7 [broken probably] Refactoring to Rx should be done...
But having issues with compiling. Checking if Dagger and retrolambda
play nice.
2014-06-10 23:17:20 -04:00
fb0c5fdaaa [broken] BookListFragment to Rx 2014-06-10 22:56:52 -04:00
6eb5f66dcc [broken] BookItemHolder to Rx 2014-06-10 22:49:47 -04:00
e356c8d1fc Revert "[broken] Remove the BookDownloadThread again"
This reverts commit 8f346f17e4.
2014-06-10 22:40:46 -04:00
287b8cb40d [broken] Add a note on the InstalledManager 2014-06-10 22:39:06 -04:00
899b054c8b [broken] Slight semantic change to RefreshManager 2014-06-10 22:37:53 -04:00
8f346f17e4 [broken] Remove the BookDownloadThread again 2014-06-10 22:36:12 -04:00
1a7364da86 [broken] Convert BookDownloadManager to Rx 2014-06-10 22:35:40 -04:00
ca1ccd9942 [broken] Convert RefreshManager to Rx 2014-06-10 22:04:53 -04:00
5770e8dd74 Add RxAndroid support, remove eventbus 2014-06-10 19:32:23 -04:00
3f5909be08 Add retrolambda support 2014-06-10 19:30:45 -04:00
24 changed files with 249 additions and 604 deletions

View File

@ -2,11 +2,6 @@ language: android
env:
matrix:
- ANDROID_SDKS=android-19,sysimg-19 ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a
android:
components:
- build-tools-20.0.0
before_install:
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
- emulator -avd test -no-skin -no-audio -no-window &

View File

@ -6,7 +6,7 @@
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="20" />
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

View File

@ -7,7 +7,8 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.3'
//classpath 'me.tatarka:gradle-retrolambda:1.3.2'
}
}
@ -26,11 +27,10 @@ dependencies {
apt 'de.devland.esperandro:esperandro:1.1.2'
// compile 'com.f2prateek.dart:dart:1.1.0'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
// compile 'de.greenrobot:eventbus:2.2.0'
compile 'com.netflix.rxjava:rxjava-android:0.19.0'
// Handled by appcompat
// compile 'com.google.android:support-v4:r7'
// And our unit testing needs some specific stuff (and specific stuff included again)
androidTestCompile 'junit:junit:4.11+'
androidTestCompile 'com.jayway.awaitility:awaitility:1.6.0'
@ -39,10 +39,10 @@ dependencies {
android {
compileSdkVersion 19
buildToolsVersion '20'
buildToolsVersion '19.1.0'
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/res']
aidl.srcDirs = ['src']
@ -52,12 +52,7 @@ android {
}
// Move the tests to tests/java, tests/res, etc...
androidTest {
manifest.srcFile 'src/test/AndroidManifest.xml'
java.srcDirs = ['src/test/java']
resources.srcDirs = ['src/test/res']
assets.srcDirs = ['src/test/assets']
}
androidTest.setRoot('src/test')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
@ -80,4 +75,17 @@ android {
lintOptions {
abortOnError false
}
/*
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
*/
defaultConfig {}
productFlavors {
}
buildTypes {
}
}

View File

@ -1,11 +0,0 @@
<html>
<body>
<div id="content" />
<script type="text/javascript">
function set_content(content) {
document.getElementById("content").innerHTML = content;
}
</script>
</body>
</html>

View File

@ -2,11 +2,6 @@ package org.bspeice.minimalbible;
import android.app.Application;
import android.content.Context;
import android.util.Log;
import org.crosswire.jsword.book.sword.SwordBookPath;
import java.io.File;
import dagger.ObjectGraph;
@ -23,8 +18,6 @@ public class MinimalBible extends Application {
*/
private static MinimalBible instance;
private String TAG = "MinimalBible";
/**
* Create the application, and persist the application Context
*/
@ -58,7 +51,6 @@ public class MinimalBible extends Application {
public void onCreate() {
//TODO: Is this necessary?
inject(this);
setJswordHome();
}
/**
@ -75,24 +67,4 @@ public class MinimalBible extends Application {
}
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());
}
}

View File

@ -1,7 +1,6 @@
package org.bspeice.minimalbible.activities;
import org.bspeice.minimalbible.activities.downloader.ActivityDownloaderModule;
import org.bspeice.minimalbible.activities.viewer.ActivityViewerModule;
import dagger.Module;
@ -10,8 +9,7 @@ import dagger.Module;
*/
@Module(
includes = {
ActivityDownloaderModule.class,
ActivityViewerModule.class
ActivityDownloaderModule.class
}
)
public class ActivityModules {

View File

@ -40,7 +40,7 @@ public class BookListFragment extends BaseFragment {
* 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.
*/
protected static final String ARG_BOOK_CATEGORY = "book_category";
private static final String ARG_BOOK_CATEGORY = "book_category";
private final String TAG = "BookListFragment";
@ -48,9 +48,9 @@ public class BookListFragment extends BaseFragment {
ListView downloadsAvailable;
@Inject RefreshManager refreshManager;
@Inject protected DownloadPrefs downloadPrefs;
@Inject DownloadPrefs downloadPrefs;
protected ProgressDialog refreshDialog;
private ProgressDialog refreshDialog;
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
* from the internet is allowable.
*/
protected void displayModules() {
private void displayModules() {
boolean dialogDisplayed = downloadPrefs.hasShownDownloadDialog();
if (!dialogDisplayed) {

View File

@ -1,15 +0,0 @@
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 {
}

View File

@ -1,33 +1,27 @@
package org.bspeice.minimalbible.activities.viewer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Looper;
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;
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.activities.BaseActivity;
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
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
BaseNavigationDrawerFragment.NavigationDrawerCallbacks {
@Inject BookManager bookManager;
/**
* Fragment managing the behaviors, interactions and presentation of the
* navigation drawer.
@ -43,31 +37,6 @@ public class BibleViewer extends BaseActivity implements
@Override
protected void onCreate(Bundle 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);
mNavigationDrawerFragment = (ViewerNavDrawerFragment) getSupportFragmentManager()
@ -76,19 +45,32 @@ public class BibleViewer extends BaseActivity implements
// Set up the drawer.
mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
(DrawerLayout) findViewById(R.id.drawer_layout));
}
@Override
public void onNavigationDrawerItemSelected(int position) {
// Handle a navigation movement
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager
.beginTransaction()
.replace(R.id.container,
PlaceholderFragment.newInstance(position + 1)).commit();
}
public void setActionBarTitle(String title) {
ActionBar actionBar = getSupportActionBar();
mTitle = title;
actionBar.setTitle(title);
}
public void onSectionAttached(int number) {
switch (number) {
case 1:
mTitle = getString(R.string.title_section1);
break;
case 2:
mTitle = getString(R.string.title_section2);
break;
case 3:
mTitle = getString(R.string.title_section3);
break;
}
}
public void restoreActionBar() {
ActionBar actionBar = getSupportActionBar();
@ -124,13 +106,48 @@ public class BibleViewer extends BaseActivity implements
return super.onOptionsItemSelected(item);
}
private void displayMainBook(Book b) {
Log.d("BibleViewer", "Initializing main book: " + b.getName());
Log.d("MainThread?", Boolean.toString(Looper.myLooper() == Looper.getMainLooper()));
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment f = BookFragment.newInstance(b.getName());
fragmentManager.beginTransaction()
.replace(R.id.container, f)
.commit();
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
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));
}
}
}

View File

@ -1,140 +0,0 @@
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();
}
}
}

View File

@ -1,50 +0,0 @@
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;
}
}

View File

@ -0,0 +1,16 @@
<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>

View File

@ -3,7 +3,6 @@
android:id="@+id/list_nav_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccccc"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"

View File

@ -1,12 +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"
tools:context="org.bspeice.minimalbible.MainActivity$PlaceholderFragment" >
<WebView
android:id="@+id/book_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>

View File

@ -3,6 +3,10 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context="org.bspeice.minimalbible.MainActivity" >
<item
android:id="@+id/action_example"
android:title="@string/action_example"
app:showAsAction="withText|ifRoom"/>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="content_page">file:///android_asset/book.html</string>
</resources>

View File

@ -1,19 +0,0 @@
<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>

View File

@ -0,0 +1,99 @@
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);
}
});
}
}

View File

@ -1,20 +0,0 @@
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 {
}

View File

@ -1,75 +0,0 @@
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;
}
}

View File

@ -1,117 +0,0 @@
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())));
}
}

View File

@ -6,7 +6,7 @@ dependencies {
android {
compileSdkVersion 19
buildToolsVersion "20"
buildToolsVersion "19.1.0"
sourceSets {
main {

View File

@ -4,6 +4,6 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'com.android.tools.build:gradle:0.11.+'
}
}

View File

@ -1,4 +1,4 @@
#Fri Jun 27 21:15:50 EDT 2014
#Tue Jun 10 19:26:46 EDT 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME