From a0e993995414c5fdee2cc79a45f3395b4c1f7aec Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Mon, 21 Jul 2014 22:55:34 -0400 Subject: [PATCH] BibleViewer uses OGHolder pattern too. --- .../org/bspeice/minimalbible/OGHolder.java | 25 ++++++------- .../activity/viewer/BibleViewer.java | 35 +++++++++++-------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/org/bspeice/minimalbible/OGHolder.java b/app/src/main/java/org/bspeice/minimalbible/OGHolder.java index 6eafc42..e6ebf33 100644 --- a/app/src/main/java/org/bspeice/minimalbible/OGHolder.java +++ b/app/src/main/java/org/bspeice/minimalbible/OGHolder.java @@ -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; - } } diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewer.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewer.java index ecfac10..d213a56 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewer.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewer.java @@ -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);