mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-12-22 14:48:23 -05:00
Remove a static field
Because dependency injection
This commit is contained in:
parent
d6951fcc9f
commit
a15e78978b
@ -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<BookCategory> 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) {
|
||||
|
@ -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<BookCategory> provideValidCategories() {
|
||||
return new ArrayList<BookCategory>() {{
|
||||
add(BookCategory.BIBLE);
|
||||
add(BookCategory.COMMENTARY);
|
||||
add(BookCategory.DICTIONARY);
|
||||
add(BookCategory.MAPS);
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
@ -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<BookCategory> 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<String>(getActionBar()
|
||||
|
||||
mDrawerListView.setAdapter(new ArrayAdapter<BookCategory>(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;
|
||||
}
|
||||
|
@ -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 };
|
||||
}
|
Loading…
Reference in New Issue
Block a user