mirror of
				https://github.com/MinimalBible/MinimalBible-Legacy
				synced 2025-11-04 02:10:30 -05:00 
			
		
		
		
	Refactoring, and download layout alignment fixes
This commit is contained in:
		@ -1,6 +1,6 @@
 | 
			
		||||
package org.bspeice.minimalbible.activities;
 | 
			
		||||
 | 
			
		||||
import org.bspeice.minimalbible.activities.downloader.ActivityDownloaderModule;
 | 
			
		||||
import org.bspeice.minimalbible.activities.downloader.manager.ActivityDownloaderModule;
 | 
			
		||||
 | 
			
		||||
import dagger.Module;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -61,6 +61,7 @@ public class BookListAdapter extends BaseAdapter {
 | 
			
		||||
    public class BookItemView extends RelativeLayout {
 | 
			
		||||
 | 
			
		||||
        @InjectView(R.id.img_download_icon) ImageView downloadIcon;
 | 
			
		||||
        @InjectView(R.id.download_txt_item_acronym) TextView acronym;
 | 
			
		||||
        @InjectView(R.id.txt_download_item_name) TextView itemName;
 | 
			
		||||
        @InjectView(R.id.img_download_index_downloaded) ImageView isIndexedDownloaded;
 | 
			
		||||
        @InjectView(R.id.img_download_item_downloaded) ImageView isDownloaded;
 | 
			
		||||
@ -72,6 +73,7 @@ public class BookListAdapter extends BaseAdapter {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void bind(Book b) {
 | 
			
		||||
            acronym.setText(b.getInitials());
 | 
			
		||||
            itemName.setText(b.getName());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -21,6 +21,8 @@ import com.readystatesoftware.systembartint.SystemBarTintManager;
 | 
			
		||||
import org.bspeice.minimalbible.MinimalBible;
 | 
			
		||||
import org.bspeice.minimalbible.MinimalBibleConstants;
 | 
			
		||||
import org.bspeice.minimalbible.R;
 | 
			
		||||
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
 | 
			
		||||
import org.bspeice.minimalbible.activities.downloader.manager.EventBookList;
 | 
			
		||||
import org.crosswire.jsword.book.Book;
 | 
			
		||||
import org.crosswire.jsword.book.BookCategory;
 | 
			
		||||
import org.crosswire.jsword.book.BookFilter;
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,7 @@ package org.bspeice.minimalbible.activities.downloader;
 | 
			
		||||
import org.bspeice.minimalbible.R;
 | 
			
		||||
import org.bspeice.minimalbible.activities.BaseActivity;
 | 
			
		||||
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
 | 
			
		||||
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
 | 
			
		||||
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.support.v4.app.FragmentManager;
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,7 @@ package org.bspeice.minimalbible.activities.downloader;
 | 
			
		||||
 | 
			
		||||
import org.bspeice.minimalbible.R;
 | 
			
		||||
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
 | 
			
		||||
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
 | 
			
		||||
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.view.LayoutInflater;
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,6 @@
 | 
			
		||||
package org.bspeice.minimalbible.activities.downloader;
 | 
			
		||||
package org.bspeice.minimalbible.activities.downloader.manager;
 | 
			
		||||
 | 
			
		||||
import org.bspeice.minimalbible.activities.downloader.BookListFragment;
 | 
			
		||||
 | 
			
		||||
import javax.inject.Singleton;
 | 
			
		||||
 | 
			
		||||
@ -17,6 +19,12 @@ import de.greenrobot.event.EventBus;
 | 
			
		||||
)
 | 
			
		||||
public class ActivityDownloaderModule {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Provide a Singleton DownloadManager for injection
 | 
			
		||||
     * Note that we need to annotate Singleton here, only annotating on the
 | 
			
		||||
     * DownloadManager itself is not enough.
 | 
			
		||||
     * @return global DownloadManager instance
 | 
			
		||||
     */
 | 
			
		||||
    @Provides @Singleton
 | 
			
		||||
    DownloadManager provideDownloadManager() {
 | 
			
		||||
        return new DownloadManager();
 | 
			
		||||
@ -1,77 +1,77 @@
 | 
			
		||||
package org.bspeice.minimalbible.activities.downloader;
 | 
			
		||||
 | 
			
		||||
import java.util.LinkedList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.bspeice.minimalbible.MinimalBible;
 | 
			
		||||
import org.bspeice.minimalbible.MinimalBibleConstants;
 | 
			
		||||
import org.crosswire.jsword.book.Book;
 | 
			
		||||
import org.crosswire.jsword.book.BookFilter;
 | 
			
		||||
import org.crosswire.jsword.book.install.InstallException;
 | 
			
		||||
import org.crosswire.jsword.book.install.Installer;
 | 
			
		||||
 | 
			
		||||
import de.greenrobot.event.EventBus;
 | 
			
		||||
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.content.SharedPreferences;
 | 
			
		||||
import android.os.AsyncTask;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
 | 
			
		||||
public class BookRefreshTask extends AsyncTask<Installer, Integer, List<Book>> {
 | 
			
		||||
	private static final String TAG = "EventBookRefreshTask";
 | 
			
		||||
 | 
			
		||||
	private EventBus downloadBus;
 | 
			
		||||
	private BookFilter filter;
 | 
			
		||||
 | 
			
		||||
	public BookRefreshTask(EventBus downloadBus) {
 | 
			
		||||
		this.downloadBus = downloadBus;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public BookRefreshTask(EventBus downloadBus, BookFilter f) {
 | 
			
		||||
		this.downloadBus = downloadBus;
 | 
			
		||||
		this.filter = f;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected List<Book> doInBackground(Installer... params) {
 | 
			
		||||
		List<Book> books = new LinkedList<Book>();
 | 
			
		||||
 | 
			
		||||
		int index = 0;
 | 
			
		||||
		for (Installer i : params) {
 | 
			
		||||
			if (doRefresh()) {
 | 
			
		||||
				try {
 | 
			
		||||
					i.reloadBookList();
 | 
			
		||||
				} catch (InstallException e) {
 | 
			
		||||
					Log.e(TAG,
 | 
			
		||||
							"Error downloading books from installer: "
 | 
			
		||||
									+ i.toString(), e);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if (filter != null) {
 | 
			
		||||
				books.addAll(i.getBooks(filter));
 | 
			
		||||
			} else {
 | 
			
		||||
				books.addAll(i.getBooks());
 | 
			
		||||
			}
 | 
			
		||||
			publishProgress(++index, params.length);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		downloadBus.postSticky(new EventBookList(books));
 | 
			
		||||
		return books;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private boolean doRefresh() {
 | 
			
		||||
		// Check if we should refresh over the internet, or use the local copy
 | 
			
		||||
		// TODO: Discover if we need to refresh over Internet, or use a cached
 | 
			
		||||
		// copy - likely something time-based, also check network state.
 | 
			
		||||
		// Fun fact - jSword handles the caching for us.
 | 
			
		||||
 | 
			
		||||
		SharedPreferences prefs = MinimalBible.getAppContext()
 | 
			
		||||
				.getSharedPreferences(
 | 
			
		||||
						MinimalBibleConstants.DOWNLOAD_PREFS_FILE,
 | 
			
		||||
						Context.MODE_PRIVATE);
 | 
			
		||||
 | 
			
		||||
		// Refresh if download enabled
 | 
			
		||||
		return prefs.getBoolean(MinimalBibleConstants.KEY_DOWNLOAD_ENABLED, false);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
package org.bspeice.minimalbible.activities.downloader.manager;
 | 
			
		||||
 | 
			
		||||
import java.util.LinkedList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.bspeice.minimalbible.MinimalBible;
 | 
			
		||||
import org.bspeice.minimalbible.MinimalBibleConstants;
 | 
			
		||||
import org.crosswire.jsword.book.Book;
 | 
			
		||||
import org.crosswire.jsword.book.BookFilter;
 | 
			
		||||
import org.crosswire.jsword.book.install.InstallException;
 | 
			
		||||
import org.crosswire.jsword.book.install.Installer;
 | 
			
		||||
 | 
			
		||||
import de.greenrobot.event.EventBus;
 | 
			
		||||
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.content.SharedPreferences;
 | 
			
		||||
import android.os.AsyncTask;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
 | 
			
		||||
public class BookRefreshTask extends AsyncTask<Installer, Integer, List<Book>> {
 | 
			
		||||
	private static final String TAG = "EventBookRefreshTask";
 | 
			
		||||
 | 
			
		||||
	private EventBus downloadBus;
 | 
			
		||||
	private BookFilter filter;
 | 
			
		||||
 | 
			
		||||
	public BookRefreshTask(EventBus downloadBus) {
 | 
			
		||||
		this.downloadBus = downloadBus;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public BookRefreshTask(EventBus downloadBus, BookFilter f) {
 | 
			
		||||
		this.downloadBus = downloadBus;
 | 
			
		||||
		this.filter = f;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected List<Book> doInBackground(Installer... params) {
 | 
			
		||||
		List<Book> books = new LinkedList<Book>();
 | 
			
		||||
 | 
			
		||||
		int index = 0;
 | 
			
		||||
		for (Installer i : params) {
 | 
			
		||||
			if (doRefresh()) {
 | 
			
		||||
				try {
 | 
			
		||||
					i.reloadBookList();
 | 
			
		||||
				} catch (InstallException e) {
 | 
			
		||||
					Log.e(TAG,
 | 
			
		||||
							"Error downloading books from installer: "
 | 
			
		||||
									+ i.toString(), e);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if (filter != null) {
 | 
			
		||||
				books.addAll(i.getBooks(filter));
 | 
			
		||||
			} else {
 | 
			
		||||
				books.addAll(i.getBooks());
 | 
			
		||||
			}
 | 
			
		||||
			publishProgress(++index, params.length);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		downloadBus.postSticky(new EventBookList(books));
 | 
			
		||||
		return books;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private boolean doRefresh() {
 | 
			
		||||
		// Check if we should refresh over the internet, or use the local copy
 | 
			
		||||
		// TODO: Discover if we need to refresh over Internet, or use a cached
 | 
			
		||||
		// copy - likely something time-based, also check network state.
 | 
			
		||||
		// Fun fact - jSword handles the caching for us.
 | 
			
		||||
 | 
			
		||||
		SharedPreferences prefs = MinimalBible.getAppContext()
 | 
			
		||||
				.getSharedPreferences(
 | 
			
		||||
						MinimalBibleConstants.DOWNLOAD_PREFS_FILE,
 | 
			
		||||
						Context.MODE_PRIVATE);
 | 
			
		||||
 | 
			
		||||
		// Refresh if download enabled
 | 
			
		||||
		return prefs.getBoolean(MinimalBibleConstants.KEY_DOWNLOAD_ENABLED, false);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
package org.bspeice.minimalbible.activities.downloader;
 | 
			
		||||
package org.bspeice.minimalbible.activities.downloader.manager;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
 | 
			
		||||
@ -1,18 +1,18 @@
 | 
			
		||||
package org.bspeice.minimalbible.activities.downloader;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.crosswire.jsword.book.Book;
 | 
			
		||||
 | 
			
		||||
public class EventBookList {
 | 
			
		||||
	
 | 
			
		||||
	private List<Book> bookList;
 | 
			
		||||
	
 | 
			
		||||
	public EventBookList(List<Book> bookList) {
 | 
			
		||||
		this.bookList = bookList;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public List<Book> getBookList() {
 | 
			
		||||
		return bookList;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
package org.bspeice.minimalbible.activities.downloader.manager;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.crosswire.jsword.book.Book;
 | 
			
		||||
 | 
			
		||||
public class EventBookList {
 | 
			
		||||
	
 | 
			
		||||
	private List<Book> bookList;
 | 
			
		||||
	
 | 
			
		||||
	public EventBookList(List<Book> bookList) {
 | 
			
		||||
		this.bookList = bookList;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public List<Book> getBookList() {
 | 
			
		||||
		return bookList;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user