Path refactoring

Also fixed an issue with View recycling
This commit is contained in:
Bradlee Speice
2014-05-19 22:34:56 -04:00
parent d16730781b
commit d664f12d08
62 changed files with 598 additions and 585 deletions

View File

@ -1,13 +1,11 @@
package org.bspeice.minimalbible.activities.downloader;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.todddavies.components.progressbar.ProgressWheel;
@ -26,11 +24,11 @@ import butterknife.OnClick;
public class BookListAdapter extends BaseAdapter {
private List<Book> bookList;
private Context ctx;
private LayoutInflater inflater;
public BookListAdapter(Context context, List<Book> bookList) {
public BookListAdapter(LayoutInflater inflater, List<Book> bookList) {
this.bookList = bookList;
this.ctx = context;
this.inflater = inflater;
}
@Override
@ -50,38 +48,40 @@ public class BookListAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
BookItemView itemView;
if (convertView == null) {
itemView = new BookItemView(this.ctx);
BookItemHolder viewHolder;
// Nasty Android issue - if you don't check the getTag(), Android will start recycling,
// and you'll get some really strange issues
if (convertView == null || convertView.getTag() == null) {
convertView = inflater.inflate(R.layout.list_download_items, null);
viewHolder = new BookItemHolder(convertView);
} else {
itemView = (BookItemView) convertView;
viewHolder = (BookItemHolder) convertView.getTag();
}
itemView.bind(getItem(position));
return itemView;
viewHolder.bindHolder(position);
return convertView;
}
public class BookItemView extends RelativeLayout {
public class BookItemHolder {
@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.download_ibtn_download) ImageButton isDownloaded;
@InjectView(R.id.download_prg_download) ProgressWheel downloadProgress;
public BookItemView (Context ctx) {
super(ctx);
View v = LayoutInflater.from(ctx).inflate(R.layout.list_download_items, this);
public BookItemHolder(View v) {
ButterKnife.inject(this, v);
}
public void bind(Book b) {
public void bindHolder(int position) {
Book b = BookListAdapter.this.getItem(position);
acronym.setText(b.getInitials());
itemName.setText(b.getName());
}
@OnClick(R.id.download_ibtn_download)
public void onDownloadItem(View v) {
Log.d("BookListAdapter", v.toString());
isDownloaded.setVisibility(View.GONE);
downloadProgress.setVisibility(View.VISIBLE);
downloadProgress.setProgress(75); // Out of 360

View File

@ -54,6 +54,7 @@ public class BookListFragment extends BaseFragment {
@Inject DownloadPrefs_ downloadPrefs;
private ProgressDialog refreshDialog;
private LayoutInflater inflater;
/**
* Returns a new instance of this fragment for the given section number.
@ -76,6 +77,7 @@ public class BookListFragment extends BaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
this.inflater = inflater;
View rootView = inflater.inflate(R.layout.fragment_download, container,
false);
ButterKnife.inject(this, rootView);
@ -154,7 +156,7 @@ public class BookListFragment extends BaseFragment {
displayList = FilterUtil.applyFilter(bookList, f);
Collections.sort(displayList, BookComparators.getInitialComparator());
downloadsAvailable.setAdapter(new BookListAdapter(this.getActivity(), displayList));
downloadsAvailable.setAdapter(new BookListAdapter(inflater, displayList));
setInsets(getActivity(), downloadsAvailable);
} catch (FilterUtil.InvalidFilterCategoryMappingException e) {
// To be honest, there should be no reason you end up here.

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 702 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 650 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

@ -0,0 +1,42 @@
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.bspeice.minimalbible.activities.viewer.BibleViewer" >
<!--
As the main content view, the view below consumes the entire
space available using match_parent in both dimensions.
-->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:clipToPadding="false" />
<!--
android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead.
-->
<!--
The drawer is given a fixed width in dp and extends the full height of
the container.
-->
<fragment
android:id="@+id/navigation_drawer"
android:name="org.bspeice.minimalbible.activities.viewer.ViewerNavDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:clipToPadding="false"
android:layout_gravity="start" />
</android.support.v4.widget.DrawerLayout>

View File

@ -0,0 +1,38 @@
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.bspeice.minimalbible.activities.downloader.DownloadActivity" >
<!--
As the main content view, the view below consumes the entire
space available using match_parent in both dimensions.
-->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!--
android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead.
-->
<!--
The drawer is given a fixed width in dp and extends the full height of
the container.
-->
<fragment
android:id="@+id/navigation_drawer"
android:name="org.bspeice.minimalbible.activities.downloader.DownloadNavDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start" />
</android.support.v4.widget.DrawerLayout>

View File

@ -0,0 +1,15 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.bspeice.minimalbible.DownloadActivity$PlaceholderFragment" >
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lst_download_available"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:clipToPadding="false" />
</RelativeLayout>

View File

@ -0,0 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

View File

@ -0,0 +1,11 @@
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list_nav_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccc"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
tools:context="org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment" />

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
<TextView
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_alignParentStart="true"
android:layout_toLeftOf="@+id/download_ibtn_download"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/download_txt_item_acronym"
android:paddingTop="4dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_alignParentStart="true"
android:layout_below="@+id/txt_download_item_name"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_action_download"
android:layout_alignParentEnd="true"
android:id="@+id/download_ibtn_download"
style="@style/AppBaseTheme.Borderless" />
<com.todddavies.components.progressbar.ProgressWheel
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentEnd="true"
android:visibility="gone"
android:id="@+id/download_prg_download"
app:rimWidth="0dp"
app:barWidth="4dp" />
</RelativeLayout>

View File

@ -0,0 +1,16 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="org.bspeice.minimalbible.DownloadActivity" >
<item
android:id="@+id/action_example"
android:title="@string/action_example"
app:showAsAction="withText|ifRoom"/>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
</menu>

View File

@ -0,0 +1,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>

View File

@ -0,0 +1,10 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
</menu>

View File

@ -0,0 +1,21 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="org.bspeice.minimalbible.MainActivity" >
<item
android:id="@+id/action_example"
android:title="@string/action_example"
app:showAsAction="withText|ifRoom"/>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
<item
android:id="@+id/action_downloads"
android:orderInCategory="100"
android:title="@string/title_activity_downloader" />
</menu>

View File

@ -0,0 +1,8 @@
<resources>
<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw600dp devices (e.g. 7" tablets) here.
-->
</resources>

View File

@ -0,0 +1,9 @@
<resources>
<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
-->
<dimen name="activity_horizontal_margin">128dp</dimen>
</resources>

View File

@ -0,0 +1,17 @@
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 11 theme customizations can go here. -->
<item name="android:actionBarStyle">@style/ActionBar</item>
</style>
<style name="ActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">@color/actionbar</item>
</style>
</resources>

View File

@ -0,0 +1,18 @@
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
<item name="android:actionBarStyle">@style/ActionBar</item>
</style>
<style name="ActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">@color/actionbar</item>
</style>
</resources>

View File

@ -0,0 +1,20 @@
<resources>
<!--
Base application theme for API 19+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 19+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 19 theme customizations can go here. -->
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:actionBarStyle">@style/ActionBar</item>
</style>
<style name="ActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">@color/actionbar</item>
</style>
</resources>

View File

@ -0,0 +1,10 @@
<resources>
<!--
Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively).
-->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="ProgressWheel">
<attr name="text" format="string" />
<attr name="textColor" format="color" />
<attr name="textSize" format="dimension" />
<attr name="barColor" format="color" />
<attr name="rimColor" format="color" />
<attr name="rimWidth" format="dimension" />
<attr name="spinSpeed" format="dimension" />
<attr name="delayMillis" format="integer" />
<attr name="circleColor" format="color" />
<attr name="radius" format="dimension" />
<attr name="barWidth" format="dimension" />
<attr name="barLength" format="dimension" />
<attr name="contourColor" format="color"/>
<attr name="contourSize" format="dimension"/>
</declare-styleable>
</resources>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="statusbar">#dddddd</color>
<color name="actionbar">#dddddd</color>
</resources>

View File

@ -0,0 +1,13 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<!--
Per the design guidelines, navigation drawers should be between 240dp and 320dp:
https://developer.android.com/design/patterns/navigation-drawer.html
-->
<dimen name="navigation_drawer_width">240dp</dimen>
</resources>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Minimal Bible</string>
<string name="title_section1">Section 1</string>
<string name="title_section2">Section 2</string>
<string name="title_section3">Section 3</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="action_example">Example action</string>
<string name="action_settings">Settings</string>
<string name="title_activity_downloader">Downloads</string>
<string name="hello_world">Hello world!</string>
<string name="title_activity_download">DownloadActivity</string>
</resources>

View File

@ -0,0 +1,33 @@
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<!-- Almost re-use style from Widget.Holo.Button.Borderless -->
<style name="AppBaseTheme.Borderless">
<item name="android:background">?android:attr/selectableItemBackground</item>
<item name="android:paddingLeft">4dip</item>
<item name="android:paddingRight">4dip</item>
<!-- Requires API 17
<item name="android:paddingStart">4dip</item>
<item name="android:paddingEnd">4dip</item>
-->
</style>
</resources>

View File

@ -0,0 +1,20 @@
package test.org.bspeice.minimalbible.test;
import android.test.InstrumentationTestCase;
/**
* Tests for the Download activity
*/
public class DownloadActivityTest extends InstrumentationTestCase {
/**
* For whatever reason, when we create one ProgressWheel with ButterKnife, multiple
* others are shown as well...
*/
public void testOnlyOneProgressWheelShown() {
}
}