Path refactoring
Also fixed an issue with View recycling
@ -47,16 +47,16 @@ android {
|
|||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
manifest.srcFile 'AndroidManifest.xml'
|
manifest.srcFile 'AndroidManifest.xml'
|
||||||
java.srcDirs = ['src']
|
java.srcDirs = ['src/main/java']
|
||||||
resources.srcDirs = ['src']
|
resources.srcDirs = ['src/main/res']
|
||||||
aidl.srcDirs = ['src']
|
aidl.srcDirs = ['src']
|
||||||
renderscript.srcDirs = ['src']
|
renderscript.srcDirs = ['src']
|
||||||
res.srcDirs = ['res']
|
res.srcDirs = ['src/main/res']
|
||||||
assets.srcDirs = ['assets']
|
assets.srcDirs = ['src/main/assets']
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move the tests to tests/java, tests/res, etc...
|
// Move the tests to tests/java, tests/res, etc...
|
||||||
instrumentTest.setRoot('tests')
|
instrumentTest.setRoot('src/test')
|
||||||
|
|
||||||
// Move the build types to build-types/<type>
|
// Move the build types to build-types/<type>
|
||||||
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
|
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
|
||||||
@ -77,5 +77,3 @@ android {
|
|||||||
exclude 'META-INF/services/javax.annotation.processing.Processor'
|
exclude 'META-INF/services/javax.annotation.processing.Processor'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package org.bspeice.minimalbible.activities.downloader;
|
package org.bspeice.minimalbible.activities.downloader;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.todddavies.components.progressbar.ProgressWheel;
|
import com.todddavies.components.progressbar.ProgressWheel;
|
||||||
@ -26,11 +24,11 @@ import butterknife.OnClick;
|
|||||||
public class BookListAdapter extends BaseAdapter {
|
public class BookListAdapter extends BaseAdapter {
|
||||||
private List<Book> bookList;
|
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.bookList = bookList;
|
||||||
this.ctx = context;
|
this.inflater = inflater;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,38 +48,40 @@ public class BookListAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
BookItemView itemView;
|
BookItemHolder viewHolder;
|
||||||
if (convertView == null) {
|
// Nasty Android issue - if you don't check the getTag(), Android will start recycling,
|
||||||
itemView = new BookItemView(this.ctx);
|
// 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 {
|
} else {
|
||||||
itemView = (BookItemView) convertView;
|
viewHolder = (BookItemHolder) convertView.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
itemView.bind(getItem(position));
|
viewHolder.bindHolder(position);
|
||||||
return itemView;
|
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.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.download_ibtn_download) ImageButton isDownloaded;
|
@InjectView(R.id.download_ibtn_download) ImageButton isDownloaded;
|
||||||
@InjectView(R.id.download_prg_download) ProgressWheel downloadProgress;
|
@InjectView(R.id.download_prg_download) ProgressWheel downloadProgress;
|
||||||
|
|
||||||
public BookItemView (Context ctx) {
|
public BookItemHolder(View v) {
|
||||||
super(ctx);
|
|
||||||
View v = LayoutInflater.from(ctx).inflate(R.layout.list_download_items, this);
|
|
||||||
ButterKnife.inject(this, 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());
|
acronym.setText(b.getInitials());
|
||||||
itemName.setText(b.getName());
|
itemName.setText(b.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.download_ibtn_download)
|
@OnClick(R.id.download_ibtn_download)
|
||||||
public void onDownloadItem(View v) {
|
public void onDownloadItem(View v) {
|
||||||
|
Log.d("BookListAdapter", v.toString());
|
||||||
isDownloaded.setVisibility(View.GONE);
|
isDownloaded.setVisibility(View.GONE);
|
||||||
downloadProgress.setVisibility(View.VISIBLE);
|
downloadProgress.setVisibility(View.VISIBLE);
|
||||||
downloadProgress.setProgress(75); // Out of 360
|
downloadProgress.setProgress(75); // Out of 360
|
@ -54,6 +54,7 @@ public class BookListFragment extends BaseFragment {
|
|||||||
@Inject DownloadPrefs_ downloadPrefs;
|
@Inject DownloadPrefs_ downloadPrefs;
|
||||||
|
|
||||||
private ProgressDialog refreshDialog;
|
private ProgressDialog refreshDialog;
|
||||||
|
private LayoutInflater inflater;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new instance of this fragment for the given section number.
|
* Returns a new instance of this fragment for the given section number.
|
||||||
@ -76,6 +77,7 @@ public class BookListFragment extends BaseFragment {
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
this.inflater = inflater;
|
||||||
View rootView = inflater.inflate(R.layout.fragment_download, container,
|
View rootView = inflater.inflate(R.layout.fragment_download, container,
|
||||||
false);
|
false);
|
||||||
ButterKnife.inject(this, rootView);
|
ButterKnife.inject(this, rootView);
|
||||||
@ -154,7 +156,7 @@ public class BookListFragment extends BaseFragment {
|
|||||||
displayList = FilterUtil.applyFilter(bookList, f);
|
displayList = FilterUtil.applyFilter(bookList, f);
|
||||||
Collections.sort(displayList, BookComparators.getInitialComparator());
|
Collections.sort(displayList, BookComparators.getInitialComparator());
|
||||||
|
|
||||||
downloadsAvailable.setAdapter(new BookListAdapter(this.getActivity(), displayList));
|
downloadsAvailable.setAdapter(new BookListAdapter(inflater, displayList));
|
||||||
setInsets(getActivity(), downloadsAvailable);
|
setInsets(getActivity(), downloadsAvailable);
|
||||||
} catch (FilterUtil.InvalidFilterCategoryMappingException e) {
|
} catch (FilterUtil.InvalidFilterCategoryMappingException e) {
|
||||||
// To be honest, there should be no reason you end up here.
|
// To be honest, there should be no reason you end up here.
|
Before Width: | Height: | Size: 161 B After Width: | Height: | Size: 161 B |
Before Width: | Height: | Size: 398 B After Width: | Height: | Size: 398 B |
Before Width: | Height: | Size: 702 B After Width: | Height: | Size: 702 B |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 142 B After Width: | Height: | Size: 142 B |
Before Width: | Height: | Size: 324 B After Width: | Height: | Size: 324 B |
Before Width: | Height: | Size: 479 B After Width: | Height: | Size: 479 B |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 174 B After Width: | Height: | Size: 174 B |
Before Width: | Height: | Size: 552 B After Width: | Height: | Size: 552 B |
Before Width: | Height: | Size: 900 B After Width: | Height: | Size: 900 B |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 208 B After Width: | Height: | Size: 208 B |
Before Width: | Height: | Size: 650 B After Width: | Height: | Size: 650 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 202 B After Width: | Height: | Size: 202 B |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
@ -6,13 +6,6 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:padding="8dp">
|
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
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -20,8 +13,8 @@
|
|||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:layout_toRightOf="@+id/img_download_icon"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_toLeftOf="@+id/download_ibtn_download" />
|
android:layout_toLeftOf="@+id/download_ibtn_download"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -29,7 +22,7 @@
|
|||||||
android:id="@+id/download_txt_item_acronym"
|
android:id="@+id/download_txt_item_acronym"
|
||||||
android:paddingTop="4dp"
|
android:paddingTop="4dp"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
android:layout_toRightOf="@+id/img_download_icon"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_below="@+id/txt_download_item_name"/>
|
android:layout_below="@+id/txt_download_item_name"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
@ -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() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|