mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-22 07:58:20 -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.R;
|
||||||
import org.bspeice.minimalbible.activity.BaseActivity;
|
import org.bspeice.minimalbible.activity.BaseActivity;
|
||||||
import org.bspeice.minimalbible.activity.BaseNavigationDrawerFragment;
|
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;
|
import dagger.ObjectGraph;
|
||||||
|
|
||||||
@ -32,6 +37,9 @@ public class DownloadActivity extends BaseActivity implements
|
|||||||
*/
|
*/
|
||||||
private CharSequence mTitle;
|
private CharSequence mTitle;
|
||||||
|
|
||||||
|
@Inject @Named("ValidCategories")
|
||||||
|
List<BookCategory> validCategories;
|
||||||
|
|
||||||
private ObjectGraph daObjectGraph;
|
private ObjectGraph daObjectGraph;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,6 +50,7 @@ public class DownloadActivity extends BaseActivity implements
|
|||||||
daObjectGraph = MinimalBible.get(this)
|
daObjectGraph = MinimalBible.get(this)
|
||||||
.plus(new DownloadActivityModules(this));
|
.plus(new DownloadActivityModules(this));
|
||||||
}
|
}
|
||||||
|
daObjectGraph.inject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -53,6 +62,7 @@ public class DownloadActivity extends BaseActivity implements
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
buildObjGraph();
|
||||||
setContentView(R.layout.activity_download);
|
setContentView(R.layout.activity_download);
|
||||||
|
|
||||||
mNavigationDrawerFragment = (DownloadNavDrawerFragment) getSupportFragmentManager()
|
mNavigationDrawerFragment = (DownloadNavDrawerFragment) getSupportFragmentManager()
|
||||||
@ -72,7 +82,7 @@ public class DownloadActivity extends BaseActivity implements
|
|||||||
fragmentManager
|
fragmentManager
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
.replace(R.id.container,
|
.replace(R.id.container,
|
||||||
BookListFragment.newInstance(DownloadManager.VALID_CATEGORIES[position])).commit();
|
BookListFragment.newInstance(validCategories.get(position))).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSectionAttached(String category) {
|
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.BookDownloadManager;
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.BookDownloadThread;
|
import org.bspeice.minimalbible.activity.downloader.manager.BookDownloadThread;
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager;
|
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 javax.inject.Singleton;
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
@ -20,7 +26,9 @@ import de.devland.esperandro.Esperandro;
|
|||||||
BookItemHolder.class,
|
BookItemHolder.class,
|
||||||
BookDownloadManager.class,
|
BookDownloadManager.class,
|
||||||
BookDownloadThread.class,
|
BookDownloadThread.class,
|
||||||
RefreshManager.class
|
RefreshManager.class,
|
||||||
|
DownloadNavDrawerFragment.class,
|
||||||
|
DownloadActivity.class
|
||||||
},
|
},
|
||||||
addsTo = MinimalBibleModules.class
|
addsTo = MinimalBibleModules.class
|
||||||
)
|
)
|
||||||
@ -45,4 +53,15 @@ public class DownloadActivityModules {
|
|||||||
BookDownloadManager provideBookDownloadManager() {
|
BookDownloadManager provideBookDownloadManager() {
|
||||||
return new BookDownloadManager(activity);
|
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.R;
|
||||||
import org.bspeice.minimalbible.activity.BaseNavigationDrawerFragment;
|
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 {
|
public class DownloadNavDrawerFragment extends BaseNavigationDrawerFragment {
|
||||||
|
|
||||||
|
@Inject @Named("ValidCategories")
|
||||||
|
List<BookCategory> validCategories;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
((DownloadActivity)getActivity()).inject(this);
|
||||||
|
|
||||||
mDrawerListView = (ListView) inflater.inflate(
|
mDrawerListView = (ListView) inflater.inflate(
|
||||||
R.layout.fragment_navigation_drawer, container, false);
|
R.layout.fragment_navigation_drawer, container, false);
|
||||||
mDrawerListView
|
mDrawerListView
|
||||||
@ -28,14 +39,9 @@ public class DownloadNavDrawerFragment extends BaseNavigationDrawerFragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
String[] sCategories = new String[DownloadManager.VALID_CATEGORIES.length];
|
mDrawerListView.setAdapter(new ArrayAdapter<BookCategory>(getActionBar()
|
||||||
for (int i = 0; i < DownloadManager.VALID_CATEGORIES.length; i++) {
|
|
||||||
sCategories[i] = DownloadManager.VALID_CATEGORIES[i].toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
mDrawerListView.setAdapter(new ArrayAdapter<String>(getActionBar()
|
|
||||||
.getThemedContext(), android.R.layout.simple_list_item_1,
|
.getThemedContext(), android.R.layout.simple_list_item_1,
|
||||||
android.R.id.text1, sCategories));
|
android.R.id.text1, validCategories));
|
||||||
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
|
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
|
||||||
return mDrawerListView;
|
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