mirror of
https://github.com/MinimalBible/MinimalBible-Legacy
synced 2024-12-22 06:38:28 -05:00
Refactoring, and download layout alignment fixes
This commit is contained in:
parent
4da25f0e23
commit
1530364abc
@ -2,10 +2,6 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="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" >
|
tools:context="org.bspeice.minimalbible.DownloadActivity$PlaceholderFragment" >
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:padding="2dip">
|
android:padding="8dp" >
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -18,9 +18,20 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:id="@+id/txt_download_item_name"
|
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_toRightOf="@+id/img_download_icon"
|
||||||
android:layout_toLeftOf="@+id/img_download_index_downloaded" />
|
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
|
<ImageButton
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -35,7 +46,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:id="@+id/img_download_item_downloaded"
|
android:id="@+id/img_download_item_downloaded"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
style="@style/AppBaseTheme.Borderless" />
|
style="@style/AppBaseTheme.Borderless" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
@ -1,6 +1,6 @@
|
|||||||
package org.bspeice.minimalbible.activities;
|
package org.bspeice.minimalbible.activities;
|
||||||
|
|
||||||
import org.bspeice.minimalbible.activities.downloader.ActivityDownloaderModule;
|
import org.bspeice.minimalbible.activities.downloader.manager.ActivityDownloaderModule;
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ public class BookListAdapter extends BaseAdapter {
|
|||||||
public class BookItemView extends RelativeLayout {
|
public class BookItemView extends RelativeLayout {
|
||||||
|
|
||||||
@InjectView(R.id.img_download_icon) ImageView downloadIcon;
|
@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.txt_download_item_name) TextView itemName;
|
||||||
@InjectView(R.id.img_download_index_downloaded) ImageView isIndexedDownloaded;
|
@InjectView(R.id.img_download_index_downloaded) ImageView isIndexedDownloaded;
|
||||||
@InjectView(R.id.img_download_item_downloaded) ImageView isDownloaded;
|
@InjectView(R.id.img_download_item_downloaded) ImageView isDownloaded;
|
||||||
@ -72,6 +73,7 @@ public class BookListAdapter extends BaseAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void bind(Book b) {
|
public void bind(Book b) {
|
||||||
|
acronym.setText(b.getInitials());
|
||||||
itemName.setText(b.getName());
|
itemName.setText(b.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@ import com.readystatesoftware.systembartint.SystemBarTintManager;
|
|||||||
import org.bspeice.minimalbible.MinimalBible;
|
import org.bspeice.minimalbible.MinimalBible;
|
||||||
import org.bspeice.minimalbible.MinimalBibleConstants;
|
import org.bspeice.minimalbible.MinimalBibleConstants;
|
||||||
import org.bspeice.minimalbible.R;
|
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.Book;
|
||||||
import org.crosswire.jsword.book.BookCategory;
|
import org.crosswire.jsword.book.BookCategory;
|
||||||
import org.crosswire.jsword.book.BookFilter;
|
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.R;
|
||||||
import org.bspeice.minimalbible.activities.BaseActivity;
|
import org.bspeice.minimalbible.activities.BaseActivity;
|
||||||
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
|
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
|
||||||
|
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.FragmentManager;
|
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.R;
|
||||||
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
|
import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment;
|
||||||
|
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
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;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
@ -17,6 +19,12 @@ import de.greenrobot.event.EventBus;
|
|||||||
)
|
)
|
||||||
public class ActivityDownloaderModule {
|
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
|
@Provides @Singleton
|
||||||
DownloadManager provideDownloadManager() {
|
DownloadManager provideDownloadManager() {
|
||||||
return new DownloadManager();
|
return new DownloadManager();
|
@ -1,77 +1,77 @@
|
|||||||
package org.bspeice.minimalbible.activities.downloader;
|
package org.bspeice.minimalbible.activities.downloader.manager;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bspeice.minimalbible.MinimalBible;
|
import org.bspeice.minimalbible.MinimalBible;
|
||||||
import org.bspeice.minimalbible.MinimalBibleConstants;
|
import org.bspeice.minimalbible.MinimalBibleConstants;
|
||||||
import org.crosswire.jsword.book.Book;
|
import org.crosswire.jsword.book.Book;
|
||||||
import org.crosswire.jsword.book.BookFilter;
|
import org.crosswire.jsword.book.BookFilter;
|
||||||
import org.crosswire.jsword.book.install.InstallException;
|
import org.crosswire.jsword.book.install.InstallException;
|
||||||
import org.crosswire.jsword.book.install.Installer;
|
import org.crosswire.jsword.book.install.Installer;
|
||||||
|
|
||||||
import de.greenrobot.event.EventBus;
|
import de.greenrobot.event.EventBus;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class BookRefreshTask extends AsyncTask<Installer, Integer, List<Book>> {
|
public class BookRefreshTask extends AsyncTask<Installer, Integer, List<Book>> {
|
||||||
private static final String TAG = "EventBookRefreshTask";
|
private static final String TAG = "EventBookRefreshTask";
|
||||||
|
|
||||||
private EventBus downloadBus;
|
private EventBus downloadBus;
|
||||||
private BookFilter filter;
|
private BookFilter filter;
|
||||||
|
|
||||||
public BookRefreshTask(EventBus downloadBus) {
|
public BookRefreshTask(EventBus downloadBus) {
|
||||||
this.downloadBus = downloadBus;
|
this.downloadBus = downloadBus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BookRefreshTask(EventBus downloadBus, BookFilter f) {
|
public BookRefreshTask(EventBus downloadBus, BookFilter f) {
|
||||||
this.downloadBus = downloadBus;
|
this.downloadBus = downloadBus;
|
||||||
this.filter = f;
|
this.filter = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<Book> doInBackground(Installer... params) {
|
protected List<Book> doInBackground(Installer... params) {
|
||||||
List<Book> books = new LinkedList<Book>();
|
List<Book> books = new LinkedList<Book>();
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (Installer i : params) {
|
for (Installer i : params) {
|
||||||
if (doRefresh()) {
|
if (doRefresh()) {
|
||||||
try {
|
try {
|
||||||
i.reloadBookList();
|
i.reloadBookList();
|
||||||
} catch (InstallException e) {
|
} catch (InstallException e) {
|
||||||
Log.e(TAG,
|
Log.e(TAG,
|
||||||
"Error downloading books from installer: "
|
"Error downloading books from installer: "
|
||||||
+ i.toString(), e);
|
+ i.toString(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter != null) {
|
if (filter != null) {
|
||||||
books.addAll(i.getBooks(filter));
|
books.addAll(i.getBooks(filter));
|
||||||
} else {
|
} else {
|
||||||
books.addAll(i.getBooks());
|
books.addAll(i.getBooks());
|
||||||
}
|
}
|
||||||
publishProgress(++index, params.length);
|
publishProgress(++index, params.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadBus.postSticky(new EventBookList(books));
|
downloadBus.postSticky(new EventBookList(books));
|
||||||
return books;
|
return books;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean doRefresh() {
|
private boolean doRefresh() {
|
||||||
// Check if we should refresh over the internet, or use the local copy
|
// 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
|
// TODO: Discover if we need to refresh over Internet, or use a cached
|
||||||
// copy - likely something time-based, also check network state.
|
// copy - likely something time-based, also check network state.
|
||||||
// Fun fact - jSword handles the caching for us.
|
// Fun fact - jSword handles the caching for us.
|
||||||
|
|
||||||
SharedPreferences prefs = MinimalBible.getAppContext()
|
SharedPreferences prefs = MinimalBible.getAppContext()
|
||||||
.getSharedPreferences(
|
.getSharedPreferences(
|
||||||
MinimalBibleConstants.DOWNLOAD_PREFS_FILE,
|
MinimalBibleConstants.DOWNLOAD_PREFS_FILE,
|
||||||
Context.MODE_PRIVATE);
|
Context.MODE_PRIVATE);
|
||||||
|
|
||||||
// Refresh if download enabled
|
// Refresh if download enabled
|
||||||
return prefs.getBoolean(MinimalBibleConstants.KEY_DOWNLOAD_ENABLED, false);
|
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;
|
import android.util.Log;
|
||||||
|
|
@ -1,18 +1,18 @@
|
|||||||
package org.bspeice.minimalbible.activities.downloader;
|
package org.bspeice.minimalbible.activities.downloader.manager;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.crosswire.jsword.book.Book;
|
import org.crosswire.jsword.book.Book;
|
||||||
|
|
||||||
public class EventBookList {
|
public class EventBookList {
|
||||||
|
|
||||||
private List<Book> bookList;
|
private List<Book> bookList;
|
||||||
|
|
||||||
public EventBookList(List<Book> bookList) {
|
public EventBookList(List<Book> bookList) {
|
||||||
this.bookList = bookList;
|
this.bookList = bookList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Book> getBookList() {
|
public List<Book> getBookList() {
|
||||||
return bookList;
|
return bookList;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user