BibleViewer uses OGHolder pattern too.

This commit is contained in:
Bradlee Speice 2014-07-21 22:55:34 -04:00
parent 915467c465
commit a0e9939954
2 changed files with 31 additions and 29 deletions

View File

@ -1,14 +1,10 @@
package org.bspeice.minimalbible;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import java.util.HashMap;
import java.util.Map;
import dagger.ObjectGraph;
/**
@ -17,13 +13,22 @@ import dagger.ObjectGraph;
* everything it could be extended to likely needs to be in
* an ObjectGraph anyway.
* This works because getSupportFragmentManager() is scoped to each activity.
* TODO: Prove the above claim.
*/
public class OGHolder extends Fragment {
private final static String TAG = "OGHolder";
private ObjectGraph mObjectGraph;
public static OGHolder get(FragmentActivity activity) {
FragmentManager manager = activity.getSupportFragmentManager();
OGHolder holder = (OGHolder) manager.findFragmentByTag(TAG);
if (holder == null) {
holder = new OGHolder();
manager.beginTransaction().add(holder, TAG).commit();
}
return holder;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -37,14 +42,4 @@ public class OGHolder extends Fragment {
public ObjectGraph fetchGraph() {
return mObjectGraph;
}
public static OGHolder get(FragmentActivity activity) {
FragmentManager manager = activity.getSupportFragmentManager();
OGHolder holder = (OGHolder) manager.findFragmentByTag(TAG);
if (holder == null) {
holder = new OGHolder();
manager.beginTransaction().add(holder, TAG).commit();
}
return holder;
}
}

View File

@ -13,6 +13,7 @@ import android.view.MenuItem;
import org.bspeice.minimalbible.Injector;
import org.bspeice.minimalbible.MinimalBible;
import org.bspeice.minimalbible.OGHolder;
import org.bspeice.minimalbible.R;
import org.bspeice.minimalbible.activity.BaseActivity;
import org.bspeice.minimalbible.activity.BaseNavigationDrawerFragment;
@ -32,13 +33,31 @@ public class BibleViewer extends BaseActivity implements
@Inject BookManager bookManager;
private ObjectGraph bvObjectGraph;
/**
* Fragment managing the behaviors, interactions and presentation of the
* navigation drawer.
*/
private ViewerNavDrawerFragment mNavigationDrawerFragment;
/**
* Used to store the last screen title. For use in
* {@link #restoreActionBar()}.
*/
private CharSequence mTitle;
/**
* Build a scoped object graph for anything used by the DownloadActivity
*/
private void buildObjGraph() {
if (bvObjectGraph == null) {
bvObjectGraph = MinimalBible.get(this)
.plus(new BibleViewerModules(this));
OGHolder holder = OGHolder.get(this);
ObjectGraph holderGraph = holder.fetchGraph();
if (holderGraph == null) {
bvObjectGraph = MinimalBible.get(this)
.plus(new BibleViewerModules(this));
holder.persistGraph(holderGraph);
} else {
bvObjectGraph = holderGraph;
}
}
bvObjectGraph.inject(this);
}
@ -49,18 +68,6 @@ public class BibleViewer extends BaseActivity implements
bvObjectGraph.inject(o);
}
/**
* Fragment managing the behaviors, interactions and presentation of the
* navigation drawer.
*/
private ViewerNavDrawerFragment mNavigationDrawerFragment;
/**
* Used to store the last screen title. For use in
* {@link #restoreActionBar()}.
*/
private CharSequence mTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);