From 7c483695d3172af3adc6b8dd9d6f8374968bc403 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Mon, 21 Jul 2014 22:19:52 -0400 Subject: [PATCH] PoC: Don't rebuild the OG on conf change --- .../activity/downloader/DownloadActivity.java | 20 +++++++++++-- .../downloader/DownloadActivityModules.java | 8 +++++- .../downloader/DownloadNavDrawerFragment.java | 1 + .../activity/downloader/DownloadOGHolder.java | 28 +++++++++++++++++++ 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadOGHolder.java diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivity.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivity.java index ac1157e..16c00e1 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivity.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivity.java @@ -4,6 +4,7 @@ import android.os.Bundle; 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.Menu; import android.view.MenuItem; @@ -47,8 +48,20 @@ public class DownloadActivity extends BaseActivity implements */ private void buildObjGraph() { if (daObjectGraph == null) { - daObjectGraph = MinimalBible.get(this) - .plus(new DownloadActivityModules(this)); + FragmentManager fM = getSupportFragmentManager(); + DownloadOGHolder ogHolder = (DownloadOGHolder) fM.findFragmentByTag("OG_HOLDER"); + if (ogHolder == null) { + Log.e("DownloadActivity", "Creating new holder..."); + ogHolder = new DownloadOGHolder(); + daObjectGraph = MinimalBible.get(this) + .plus(new DownloadActivityModules(this)); + ogHolder.persistObjectGraph(daObjectGraph); + fM.beginTransaction().add(ogHolder, "OG_HOLDER").commit(); + } else { + Log.e("DownloadActivity", "Found existing holder..."); + daObjectGraph = ogHolder.fetchObjectGraph(); + daObjectGraph.inject(this); + } } daObjectGraph.inject(this); } @@ -62,7 +75,8 @@ public class DownloadActivity extends BaseActivity implements @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - buildObjGraph(); + inject(this); + setContentView(R.layout.activity_download); mNavigationDrawerFragment = (DownloadNavDrawerFragment) getSupportFragmentManager() diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivityModules.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivityModules.java index f6f436f..cef842a 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivityModules.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivityModules.java @@ -37,7 +37,8 @@ import de.devland.esperandro.Esperandro; DownloadActivity.class, InstalledManager.class }, - addsTo = MinimalBibleModules.class + addsTo = MinimalBibleModules.class, + library = true ) public class DownloadActivityModules { DownloadActivity activity; @@ -102,4 +103,9 @@ public class DownloadActivityModules { Collection provideInstallers() { return new InstallManager().getInstallers().values(); } + + @Provides @Singleton + RefreshManager provideRefreshManager() { + return new RefreshManager(activity); + } } diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadNavDrawerFragment.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadNavDrawerFragment.java index 7bb77e6..b96a295 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadNavDrawerFragment.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadNavDrawerFragment.java @@ -1,6 +1,7 @@ package org.bspeice.minimalbible.activity.downloader; import android.os.Bundle; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadOGHolder.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadOGHolder.java new file mode 100644 index 0000000..586c9de --- /dev/null +++ b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadOGHolder.java @@ -0,0 +1,28 @@ +package org.bspeice.minimalbible.activity.downloader; + +import android.os.Bundle; +import android.support.v4.app.Fragment; + +import dagger.ObjectGraph; + +/** + * Created by bspeice on 7/21/14. + */ +public class DownloadOGHolder extends Fragment { + + ObjectGraph holder; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setRetainInstance(true); + } + + public void persistObjectGraph(ObjectGraph holder) { + this.holder = holder; + } + + public ObjectGraph fetchObjectGraph() { + return this.holder; + } +}