mirror of
https://github.com/MinimalBible/MinimalBible
synced 2025-07-16 21:24:47 -04:00
Switch off build variants to build types
Should be much easier to maintain
This commit is contained in:
@ -0,0 +1,66 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import org.acra.ACRA;
|
||||
import org.acra.ReportingInteractionMode;
|
||||
import org.acra.annotation.ReportsCrashes;
|
||||
import org.crosswire.jsword.book.sword.SwordBookPath;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import dagger.ObjectGraph;
|
||||
|
||||
/**
|
||||
* Created by bspeice on 9/12/14.
|
||||
*/
|
||||
@ReportsCrashes(formKey = "",
|
||||
mailTo = "bspeice.nc@gmail.com",
|
||||
mode = ReportingInteractionMode.SILENT
|
||||
)
|
||||
public class MinimalBible extends Application implements Injector {
|
||||
private String TAG = "MinimalBible";
|
||||
private ObjectGraph mObjectGraph;
|
||||
|
||||
public static MinimalBible get(Context ctx) {
|
||||
return (MinimalBible) ctx.getApplicationContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
buildObjGraph();
|
||||
setJswordHome();
|
||||
ACRA.init(this);
|
||||
}
|
||||
|
||||
public void buildObjGraph() {
|
||||
mObjectGraph = ObjectGraph.create(Modules.list(this));
|
||||
}
|
||||
|
||||
public void inject(Object o) {
|
||||
mObjectGraph.inject(o);
|
||||
}
|
||||
|
||||
public ObjectGraph plus(Object... modules) {
|
||||
return mObjectGraph.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 = this.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());
|
||||
}
|
||||
}
|
20
app/src/debug/java/org/bspeice/minimalbible/Modules.java
Normal file
20
app/src/debug/java/org/bspeice/minimalbible/Modules.java
Normal file
@ -0,0 +1,20 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
/**
|
||||
* List modules to be used during testing
|
||||
* Also the entry point for setting whether or not we are using testing mode
|
||||
*/
|
||||
public class Modules {
|
||||
|
||||
public static TestModules testModules = new TestModules();
|
||||
|
||||
private Modules() {
|
||||
}
|
||||
|
||||
public static Object[] list(MinimalBible app) {
|
||||
return new Object[]{
|
||||
new MinimalBibleModules(app),
|
||||
testModules
|
||||
};
|
||||
}
|
||||
}
|
54
app/src/debug/java/org/bspeice/minimalbible/TestModules.java
Normal file
54
app/src/debug/java/org/bspeice/minimalbible/TestModules.java
Normal file
@ -0,0 +1,54 @@
|
||||
package org.bspeice.minimalbible;
|
||||
|
||||
|
||||
import org.bspeice.minimalbible.activity.downloader.DownloadActivity;
|
||||
import org.bspeice.minimalbible.service.manager.BookManager;
|
||||
import org.crosswire.jsword.book.BookCategory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
/**
|
||||
* Created by Bradlee Speice on 7/5/2014.
|
||||
*/
|
||||
@Module(injects = DownloadActivity.class,
|
||||
overrides = true,
|
||||
library = true)
|
||||
public class TestModules {
|
||||
|
||||
public static CharSequence testActivityTitle = "Test";
|
||||
private BookManager bookManager;
|
||||
|
||||
@Provides
|
||||
CharSequence provideString() {
|
||||
return testActivityTitle;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("ValidCategories")
|
||||
List<BookCategory> provideValidCategories() {
|
||||
return new ArrayList<BookCategory>() {{
|
||||
add(BookCategory.BIBLE);
|
||||
add(BookCategory.COMMENTARY);
|
||||
add(BookCategory.DICTIONARY);
|
||||
add(BookCategory.MAPS);
|
||||
}};
|
||||
}
|
||||
|
||||
public void setBookManager(BookManager bookManager) {
|
||||
this.bookManager = bookManager;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
BookManager provideBookManager() {
|
||||
return bookManager;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package org.bspeice.minimalbible.test.activity;
|
||||
|
||||
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.support.v7.app.ActionBarActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import org.bspeice.minimalbible.R;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
public class FragmentTestActivity extends ActionBarActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_fragment_test);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.fragment_test, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_settings) {
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public void startFragment(Fragment f) {
|
||||
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
|
||||
fragmentManager.beginTransaction()
|
||||
.add(R.id.container, f)
|
||||
.commit();
|
||||
|
||||
// Do the ugly work of waiting for the transaction to complete...
|
||||
final CountDownLatch signal = new CountDownLatch(1);
|
||||
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
fragmentManager.executePendingTransactions();
|
||||
signal.countDown();
|
||||
}
|
||||
});
|
||||
try {
|
||||
signal.await();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user