From 5c9e0ecba4587afb97b15979cb206bf0174a8fa6 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Tue, 6 May 2014 00:29:12 -0400 Subject: [PATCH] Browsing documents, now with 100% more butter! --- MinimalBible/build.gradle | 11 +-- .../res/layout/list_download_items.xml | 4 -- .../activities/downloader/BookItemView.java | 28 -------- .../downloader/BookListAdapter.java | 29 +++++++- .../downloader/BookListFragment.java | 67 +++++++++++++------ .../downloader/DownloadActivity.java | 2 +- 6 files changed, 76 insertions(+), 65 deletions(-) delete mode 100644 MinimalBible/src/org/bspeice/minimalbible/activities/downloader/BookItemView.java diff --git a/MinimalBible/build.gradle b/MinimalBible/build.gradle index c193c28..2a4c165 100644 --- a/MinimalBible/build.gradle +++ b/MinimalBible/build.gradle @@ -21,8 +21,8 @@ dependencies { // apt "org.androidannotations:androidannotations:3.0+" // compile "org.androidannotations:androidannotations-api:3.0+" - apt 'com.squareup.dagger:dagger-compiler:1.1.0' - compile 'com.squareup.dagger:dagger:1.1.0' + apt 'com.squareup.dagger:dagger-compiler:1.2.1+' + compile 'com.squareup.dagger:dagger:1.2.1+' apt 'com.jakewharton:butterknife:5.0.1' compile 'com.jakewharton:butterknife:5.0.1' @@ -34,13 +34,6 @@ dependencies { // compile 'com.google.android:support-v4:r7' } -apt { - arguments { - androidManifestFile variant.processResources.manifestFile - resourcePackageName "org.bspeice.minimalbible" - } -} - android { compileSdkVersion 19 buildToolsVersion "19.0.3" diff --git a/MinimalBible/res/layout/list_download_items.xml b/MinimalBible/res/layout/list_download_items.xml index 501be4c..6b56d07 100644 --- a/MinimalBible/res/layout/list_download_items.xml +++ b/MinimalBible/res/layout/list_download_items.xml @@ -9,7 +9,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/img_download_icon" - android:layout_weight="1" android:layout_alignParentLeft="true" android:layout_marginLeft="0dp" android:layout_alignParentTop="true" @@ -19,7 +18,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/txt_download_item_name" - android:layout_weight="1" android:layout_toRightOf="@+id/img_download_icon" android:layout_toLeftOf="@+id/img_download_index_downloaded" /> @@ -29,7 +27,6 @@ android:id="@+id/img_download_index_downloaded" android:src="@drawable/ic_action_search" style="@style/AppBaseTheme.Borderless" - android:layout_weight="1" android:layout_alignParentTop="true" android:layout_toLeftOf="@+id/img_download_item_downloaded" /> @@ -37,7 +34,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/img_download_item_downloaded" - android:layout_weight="1" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" style="@style/AppBaseTheme.Borderless" /> diff --git a/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/BookItemView.java b/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/BookItemView.java deleted file mode 100644 index 2bcde3e..0000000 --- a/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/BookItemView.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.bspeice.minimalbible.activities.downloader; - -import android.content.Context; -import android.widget.ImageView; -import android.widget.RelativeLayout; -import android.widget.TextView; - -import org.androidannotations.annotations.EViewGroup; -import org.androidannotations.annotations.ViewById; -import org.bspeice.minimalbible.R; -import org.crosswire.jsword.book.Book; - -@EViewGroup(R.layout.list_download_items) -public class BookItemView extends RelativeLayout { - - @ViewById (R.id.img_download_icon) ImageView downloadIcon; - @ViewById(R.id.txt_download_item_name) TextView itemName; - @ViewById(R.id.img_download_index_downloaded) ImageView isIndexedDownloaded; - @ViewById(R.id.img_download_item_downloaded) ImageView isDownloaded; - - public BookItemView (Context ctx) { - super(ctx); - } - - public void bind(Book b) { - itemName.setText(b.getName()); - } -} diff --git a/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/BookListAdapter.java b/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/BookListAdapter.java index edac3e1..bc1b0af 100644 --- a/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/BookListAdapter.java +++ b/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/BookListAdapter.java @@ -1,14 +1,22 @@ package org.bspeice.minimalbible.activities.downloader; import android.content.Context; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TextView; +import org.bspeice.minimalbible.R; import org.crosswire.jsword.book.Book; import java.util.List; +import butterknife.ButterKnife; +import butterknife.InjectView; + /** * Adapter to inflate list_download_items.xml */ @@ -41,8 +49,7 @@ public class BookListAdapter extends BaseAdapter { public View getView(int position, View convertView, ViewGroup parent) { BookItemView itemView; if (convertView == null) { - itemView = BookItemView_.build(this.ctx); - + itemView = new BookItemView(this.ctx); } else { itemView = (BookItemView) convertView; } @@ -50,4 +57,22 @@ public class BookListAdapter extends BaseAdapter { itemView.bind(getItem(position)); return itemView; } + + public class BookItemView extends RelativeLayout { + + @InjectView(R.id.img_download_icon) ImageView downloadIcon; + @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; + + public BookItemView (Context ctx) { + super(ctx); + View v = LayoutInflater.from(ctx).inflate(R.layout.list_download_items, this); + ButterKnife.inject(this, v); + } + + public void bind(Book b) { + itemName.setText(b.getName()); + } + } } diff --git a/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/BookListFragment.java b/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/BookListFragment.java index c422e9a..404a41c 100644 --- a/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/BookListFragment.java +++ b/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/BookListFragment.java @@ -7,19 +7,17 @@ import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Build; +import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.ListView; import android.widget.Toast; import com.readystatesoftware.systembartint.SystemBarTintManager; -import org.androidannotations.annotations.AfterViews; -import org.androidannotations.annotations.EFragment; -import org.androidannotations.annotations.FragmentArg; -import org.androidannotations.annotations.Trace; -import org.androidannotations.annotations.ViewById; import org.bspeice.minimalbible.MinimalBibleConstants; import org.bspeice.minimalbible.R; import org.crosswire.jsword.book.Book; @@ -29,33 +27,58 @@ import org.crosswire.jsword.book.FilterUtil; import java.util.List; +import butterknife.ButterKnife; +import butterknife.InjectView; + /** * A placeholder fragment containing a simple view. */ -@EFragment(R.layout.fragment_download) public class BookListFragment extends Fragment { - /** - * The fragment argument representing the section number for this fragment. - */ + /** + * The fragment argument representing the section number for this fragment. + */ + private static final String ARG_BOOK_CATEGORY = "book_category"; private final String TAG = "BookListFragment"; - @FragmentArg - BookCategory bookCategory; - - @ViewById(R.id.lst_download_available) - protected ListView downloadsAvailable; + @InjectView(R.id.lst_download_available) + ListView downloadsAvailable; private ProgressDialog refreshDialog; - @Trace - @AfterViews - public void updateName() { - ((DownloadActivity) getActivity()).onSectionAttached(bookCategory.toString()); - displayModules(); + /** + * Returns a new instance of this fragment for the given section number. + * TODO: This will need to be switched to an @Provides class + */ + public static BookListFragment newInstance(BookCategory c) { + BookListFragment fragment = new BookListFragment(); + Bundle args = new Bundle(); + args.putString(ARG_BOOK_CATEGORY, c.toString()); + fragment.setArguments(args); + return fragment; } - public void displayModules() { + public BookListFragment() { + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_download, container, + false); + ButterKnife.inject(this, rootView); + displayModules(); + return rootView; + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + ((DownloadActivity) activity).onSectionAttached(getArguments() + .getString(ARG_BOOK_CATEGORY)); + } + + public void displayModules() { SharedPreferences prefs = getActivity() .getSharedPreferences( MinimalBibleConstants.DOWNLOAD_PREFS_FILE, @@ -110,7 +133,9 @@ public class BookListFragment extends Fragment { public void displayBooks(List bookList) { try { - BookFilter f = FilterUtil.filterFromCategory(bookCategory); + // TODO: Should the filter be applied earlier in the process? + BookCategory c = BookCategory.fromString(getArguments().getString(ARG_BOOK_CATEGORY)); + BookFilter f = FilterUtil.filterFromCategory(c); List filteredBooks = FilterUtil.applyFilter(bookList, f); downloadsAvailable.setAdapter(new BookListAdapter(this.getActivity(), filteredBooks)); setInsets(getActivity(), downloadsAvailable); diff --git a/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/DownloadActivity.java b/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/DownloadActivity.java index 128c599..8789b59 100644 --- a/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/DownloadActivity.java +++ b/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/DownloadActivity.java @@ -47,7 +47,7 @@ public class DownloadActivity extends BaseActivity implements fragmentManager .beginTransaction() .replace(R.id.container, - BookListFragment_.builder().bookCategory(DownloadManager.VALID_CATEGORIES[position]).build()).commit(); + BookListFragment.newInstance(DownloadManager.VALID_CATEGORIES[position])).commit(); } public void onSectionAttached(String category) {