mirror of
				https://github.com/MinimalBible/MinimalBible-Legacy
				synced 2025-11-04 02:10:30 -05:00 
			
		
		
		
	Dagger support now working
Could've saved an hour or two if someone had told me every class needs to inject itself...
This commit is contained in:
		@ -3,7 +3,11 @@ package org.bspeice.minimalbible;
 | 
			
		||||
import android.app.Application;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
 | 
			
		||||
import dagger.ObjectGraph;
 | 
			
		||||
 | 
			
		||||
public class MinimalBible extends Application {
 | 
			
		||||
 | 
			
		||||
    private ObjectGraph graph;
 | 
			
		||||
	
 | 
			
		||||
	private static MinimalBible instance;
 | 
			
		||||
	
 | 
			
		||||
@ -15,4 +19,21 @@ public class MinimalBible extends Application {
 | 
			
		||||
		return instance;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onCreate() {
 | 
			
		||||
        graph = ObjectGraph.create(new MinimalBibleModules());
 | 
			
		||||
        graph.inject(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void inject(Object o) {
 | 
			
		||||
        graph.inject(o);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static MinimalBible getApplication(Context ctx) {
 | 
			
		||||
        return (MinimalBible)ctx.getApplicationContext();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static MinimalBible getApplication() {
 | 
			
		||||
        return (MinimalBible)getAppContext();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,19 @@
 | 
			
		||||
package org.bspeice.minimalbible;
 | 
			
		||||
 | 
			
		||||
import org.bspeice.minimalbible.activities.ActivityModules;
 | 
			
		||||
 | 
			
		||||
import dagger.Module;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Modules for the global application
 | 
			
		||||
 */
 | 
			
		||||
@Module(
 | 
			
		||||
    injects = {
 | 
			
		||||
        MinimalBible.class
 | 
			
		||||
    },
 | 
			
		||||
    includes = {
 | 
			
		||||
        ActivityModules.class
 | 
			
		||||
    }
 | 
			
		||||
)
 | 
			
		||||
public class MinimalBibleModules {
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,16 @@
 | 
			
		||||
package org.bspeice.minimalbible.activities;
 | 
			
		||||
 | 
			
		||||
import org.bspeice.minimalbible.activities.downloader.ActivityDownloaderModule;
 | 
			
		||||
 | 
			
		||||
import dagger.Module;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Modules for all activities
 | 
			
		||||
 */
 | 
			
		||||
@Module(
 | 
			
		||||
    includes = {
 | 
			
		||||
        ActivityDownloaderModule.class
 | 
			
		||||
    }
 | 
			
		||||
)
 | 
			
		||||
public class ActivityModules {
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,29 @@
 | 
			
		||||
package org.bspeice.minimalbible.activities.downloader;
 | 
			
		||||
 | 
			
		||||
import javax.inject.Singleton;
 | 
			
		||||
 | 
			
		||||
import dagger.Module;
 | 
			
		||||
import dagger.Provides;
 | 
			
		||||
import de.greenrobot.event.EventBus;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Module mappings for the classes under the Download Activity
 | 
			
		||||
 */
 | 
			
		||||
@Module(
 | 
			
		||||
        injects = {
 | 
			
		||||
            BookListFragment.class,
 | 
			
		||||
            DownloadManager.class
 | 
			
		||||
        }
 | 
			
		||||
)
 | 
			
		||||
public class ActivityDownloaderModule {
 | 
			
		||||
 | 
			
		||||
    @Provides @Singleton
 | 
			
		||||
    DownloadManager provideDownloadManager() {
 | 
			
		||||
        return new DownloadManager();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Provides
 | 
			
		||||
    EventBus provideBus() {
 | 
			
		||||
        return new EventBus();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -18,6 +18,7 @@ import android.widget.Toast;
 | 
			
		||||
 | 
			
		||||
import com.readystatesoftware.systembartint.SystemBarTintManager;
 | 
			
		||||
 | 
			
		||||
import org.bspeice.minimalbible.MinimalBible;
 | 
			
		||||
import org.bspeice.minimalbible.MinimalBibleConstants;
 | 
			
		||||
import org.bspeice.minimalbible.R;
 | 
			
		||||
import org.crosswire.jsword.book.Book;
 | 
			
		||||
@ -27,12 +28,15 @@ import org.crosswire.jsword.book.FilterUtil;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import javax.inject.Inject;
 | 
			
		||||
 | 
			
		||||
import butterknife.ButterKnife;
 | 
			
		||||
import butterknife.InjectView;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A placeholder fragment containing a simple view.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class BookListFragment extends Fragment {
 | 
			
		||||
    /**
 | 
			
		||||
     * The fragment argument representing the section number for this fragment.
 | 
			
		||||
@ -44,6 +48,9 @@ public class BookListFragment extends Fragment {
 | 
			
		||||
    @InjectView(R.id.lst_download_available)
 | 
			
		||||
    ListView downloadsAvailable;
 | 
			
		||||
 | 
			
		||||
    @Inject
 | 
			
		||||
    DownloadManager downloadManager;
 | 
			
		||||
 | 
			
		||||
	private ProgressDialog refreshDialog;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -58,7 +65,11 @@ public class BookListFragment extends Fragment {
 | 
			
		||||
        return fragment;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public BookListFragment() {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onCreate(Bundle state) {
 | 
			
		||||
        super.onCreate(state);
 | 
			
		||||
        MinimalBible app = MinimalBible.getApplication(getActivity());
 | 
			
		||||
        app.inject(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@ -100,10 +111,9 @@ public class BookListFragment extends Fragment {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void refreshModules() {
 | 
			
		||||
		DownloadManager dm = DownloadManager.getInstance();
 | 
			
		||||
		EventBookList bookList = dm.getDownloadBus().getStickyEvent(EventBookList.class);
 | 
			
		||||
		EventBookList bookList = downloadManager.getDownloadBus().getStickyEvent(EventBookList.class);
 | 
			
		||||
		if (bookList == null) {
 | 
			
		||||
            dm.getDownloadBus().registerSticky(this);
 | 
			
		||||
            downloadManager.getDownloadBus().registerSticky(this);
 | 
			
		||||
            refreshDialog = new ProgressDialog(getActivity());
 | 
			
		||||
            refreshDialog.setMessage("Refreshing available modules...");
 | 
			
		||||
            refreshDialog.setCancelable(false);
 | 
			
		||||
 | 
			
		||||
@ -4,35 +4,31 @@ import android.util.Log;
 | 
			
		||||
 | 
			
		||||
import org.bspeice.minimalbible.MinimalBible;
 | 
			
		||||
import org.crosswire.jsword.book.BookCategory;
 | 
			
		||||
import org.crosswire.jsword.book.BookFilter;
 | 
			
		||||
import org.crosswire.jsword.book.BookFilters;
 | 
			
		||||
import org.crosswire.jsword.book.install.InstallManager;
 | 
			
		||||
import org.crosswire.jsword.book.install.Installer;
 | 
			
		||||
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import javax.inject.Inject;
 | 
			
		||||
import javax.inject.Singleton;
 | 
			
		||||
 | 
			
		||||
import de.greenrobot.event.EventBus;
 | 
			
		||||
 | 
			
		||||
@Singleton
 | 
			
		||||
public class DownloadManager {
 | 
			
		||||
 | 
			
		||||
	private final String TAG = "DownloadManager";
 | 
			
		||||
	private static DownloadManager instance;
 | 
			
		||||
	private EventBus downloadBus;
 | 
			
		||||
 | 
			
		||||
    @Inject
 | 
			
		||||
    protected EventBus downloadBus;
 | 
			
		||||
 | 
			
		||||
	public static final BookCategory[] VALID_CATEGORIES = { BookCategory.BIBLE,
 | 
			
		||||
			BookCategory.COMMENTARY, BookCategory.DICTIONARY,
 | 
			
		||||
			BookCategory.MAPS };
 | 
			
		||||
 | 
			
		||||
	public static DownloadManager getInstance() {
 | 
			
		||||
		if (instance == null) {
 | 
			
		||||
			instance = new DownloadManager();
 | 
			
		||||
		}
 | 
			
		||||
		return instance;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private DownloadManager() {
 | 
			
		||||
	public DownloadManager() {
 | 
			
		||||
        MinimalBible.getApplication().inject(this);
 | 
			
		||||
		setDownloadDir();
 | 
			
		||||
		downloadBus = new EventBus();
 | 
			
		||||
		downloadEvents();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user