Refactoring, and download layout alignment fixes

ugly-unit-test
DjBushido 2014-05-08 20:39:38 -04:00
parent 4da25f0e23
commit 1530364abc
11 changed files with 124 additions and 104 deletions

View File

@ -2,10 +2,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="org.bspeice.minimalbible.DownloadActivity$PlaceholderFragment" >
<ListView

View File

@ -3,7 +3,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dip">
android:padding="8dp" >
<ImageView
android:layout_width="wrap_content"
@ -18,9 +18,20 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txt_download_item_name"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_toRightOf="@+id/img_download_icon"
android:layout_toLeftOf="@+id/img_download_index_downloaded" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/download_txt_item_acronym"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_toRightOf="@+id/img_download_icon"
android:layout_below="@+id/txt_download_item_name"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -35,7 +46,6 @@
android:layout_height="wrap_content"
android:id="@+id/img_download_item_downloaded"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
style="@style/AppBaseTheme.Borderless" />
</RelativeLayout>

View File

@ -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;

View File

@ -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());
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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();

View File

@ -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);
}
}

View File

@ -1,4 +1,4 @@
package org.bspeice.minimalbible.activities.downloader;
package org.bspeice.minimalbible.activities.downloader.manager;
import android.util.Log;

View File

@ -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;
}
}