Path refactoring

Also fixed an issue with View recycling
ugly-unit-test
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

@ -47,16 +47,16 @@ android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/res']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
instrumentTest.setRoot('src/test')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
@ -76,6 +76,4 @@ android {
exclude 'META-INF/NOTICE'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
}

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.

View File

Before

Width:  |  Height:  |  Size: 161 B

After

Width:  |  Height:  |  Size: 161 B

View File

Before

Width:  |  Height:  |  Size: 398 B

After

Width:  |  Height:  |  Size: 398 B

View File

Before

Width:  |  Height:  |  Size: 702 B

After

Width:  |  Height:  |  Size: 702 B

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 142 B

After

Width:  |  Height:  |  Size: 142 B

View File

Before

Width:  |  Height:  |  Size: 324 B

After

Width:  |  Height:  |  Size: 324 B

View File

Before

Width:  |  Height:  |  Size: 479 B

After

Width:  |  Height:  |  Size: 479 B

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 174 B

After

Width:  |  Height:  |  Size: 174 B

View File

Before

Width:  |  Height:  |  Size: 552 B

After

Width:  |  Height:  |  Size: 552 B

View File

Before

Width:  |  Height:  |  Size: 900 B

After

Width:  |  Height:  |  Size: 900 B

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

Before

Width:  |  Height:  |  Size: 208 B

After

Width:  |  Height:  |  Size: 208 B

View File

Before

Width:  |  Height:  |  Size: 650 B

After

Width:  |  Height:  |  Size: 650 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 202 B

After

Width:  |  Height:  |  Size: 202 B

View File

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

@ -6,13 +6,6 @@
android:layout_height="match_parent"
android:padding="8dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img_download_icon"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -20,8 +13,8 @@
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_toRightOf="@+id/img_download_icon"
android:layout_toLeftOf="@+id/download_ibtn_download" />
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/download_ibtn_download"/>
<TextView
android:layout_width="wrap_content"
@ -29,7 +22,7 @@
android:id="@+id/download_txt_item_acronym"
android:paddingTop="4dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_toRightOf="@+id/img_download_icon"
android:layout_alignParentStart="true"
android:layout_below="@+id/txt_download_item_name"/>
<ImageButton

View File

@ -1,19 +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>
<?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,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() {
}
}