From a15e78978b9bf0f4ad93ee498c667dbf369526af Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Mon, 7 Jul 2014 23:13:25 -0400 Subject: [PATCH] Remove a static field Because dependency injection --- .../activity/downloader/DownloadActivity.java | 14 ++++++++-- .../downloader/DownloadActivityModules.java | 21 ++++++++++++++- .../downloader/DownloadNavDrawerFragment.java | 26 ++++++++++++------- .../downloader/manager/DownloadManager.java | 14 ---------- 4 files changed, 48 insertions(+), 27 deletions(-) delete mode 100644 app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/DownloadManager.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 3397914..ac1157e 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 @@ -12,7 +12,12 @@ import org.bspeice.minimalbible.MinimalBible; import org.bspeice.minimalbible.R; import org.bspeice.minimalbible.activity.BaseActivity; import org.bspeice.minimalbible.activity.BaseNavigationDrawerFragment; -import org.bspeice.minimalbible.activity.downloader.manager.DownloadManager; +import org.crosswire.jsword.book.BookCategory; + +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Named; import dagger.ObjectGraph; @@ -32,6 +37,9 @@ public class DownloadActivity extends BaseActivity implements */ private CharSequence mTitle; + @Inject @Named("ValidCategories") + List validCategories; + private ObjectGraph daObjectGraph; /** @@ -42,6 +50,7 @@ public class DownloadActivity extends BaseActivity implements daObjectGraph = MinimalBible.get(this) .plus(new DownloadActivityModules(this)); } + daObjectGraph.inject(this); } @Override @@ -53,6 +62,7 @@ public class DownloadActivity extends BaseActivity implements @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + buildObjGraph(); setContentView(R.layout.activity_download); mNavigationDrawerFragment = (DownloadNavDrawerFragment) getSupportFragmentManager() @@ -72,7 +82,7 @@ public class DownloadActivity extends BaseActivity implements fragmentManager .beginTransaction() .replace(R.id.container, - BookListFragment.newInstance(DownloadManager.VALID_CATEGORIES[position])).commit(); + BookListFragment.newInstance(validCategories.get(position))).commit(); } public void onSectionAttached(String category) { 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 08a80d1..8a4b339 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 @@ -4,7 +4,13 @@ import org.bspeice.minimalbible.MinimalBibleModules; import org.bspeice.minimalbible.activity.downloader.manager.BookDownloadManager; import org.bspeice.minimalbible.activity.downloader.manager.BookDownloadThread; import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager; +import org.crosswire.jsword.book.BookCategory; +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Named; +import javax.inject.Qualifier; import javax.inject.Singleton; import dagger.Module; @@ -20,7 +26,9 @@ import de.devland.esperandro.Esperandro; BookItemHolder.class, BookDownloadManager.class, BookDownloadThread.class, - RefreshManager.class + RefreshManager.class, + DownloadNavDrawerFragment.class, + DownloadActivity.class }, addsTo = MinimalBibleModules.class ) @@ -45,4 +53,15 @@ public class DownloadActivityModules { BookDownloadManager provideBookDownloadManager() { return new BookDownloadManager(activity); } + + @Provides @Singleton + @Named("ValidCategories") + List provideValidCategories() { + return new ArrayList() {{ + add(BookCategory.BIBLE); + add(BookCategory.COMMENTARY); + add(BookCategory.DICTIONARY); + add(BookCategory.MAPS); + }}; + } } 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 45a60d4..1612fb1 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 @@ -10,13 +10,24 @@ import android.widget.ListView; import org.bspeice.minimalbible.R; import org.bspeice.minimalbible.activity.BaseNavigationDrawerFragment; -import org.bspeice.minimalbible.activity.downloader.manager.DownloadManager; +import org.crosswire.jsword.book.Book; +import org.crosswire.jsword.book.BookCategory; + +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Named; public class DownloadNavDrawerFragment extends BaseNavigationDrawerFragment { - + + @Inject @Named("ValidCategories") + List validCategories; + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + ((DownloadActivity)getActivity()).inject(this); + mDrawerListView = (ListView) inflater.inflate( R.layout.fragment_navigation_drawer, container, false); mDrawerListView @@ -27,15 +38,10 @@ public class DownloadNavDrawerFragment extends BaseNavigationDrawerFragment { selectItem(position); } }); - - String[] sCategories = new String[DownloadManager.VALID_CATEGORIES.length]; - for (int i = 0; i < DownloadManager.VALID_CATEGORIES.length; i++) { - sCategories[i] = DownloadManager.VALID_CATEGORIES[i].toString(); - } - - mDrawerListView.setAdapter(new ArrayAdapter(getActionBar() + + mDrawerListView.setAdapter(new ArrayAdapter(getActionBar() .getThemedContext(), android.R.layout.simple_list_item_1, - android.R.id.text1, sCategories)); + android.R.id.text1, validCategories)); mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); return mDrawerListView; } diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/DownloadManager.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/DownloadManager.java deleted file mode 100644 index db08f48..0000000 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/DownloadManager.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.bspeice.minimalbible.activity.downloader.manager; - -import org.crosswire.jsword.book.BookCategory; - -// TODO: Listen to BookInstall events? -public class DownloadManager { - - private final String TAG = "DownloadManager"; - - // TODO: Inject this, don't have any static references - public static final BookCategory[] VALID_CATEGORIES = { BookCategory.BIBLE, - BookCategory.COMMENTARY, BookCategory.DICTIONARY, - BookCategory.MAPS }; -}