simplify use of draggable row

This commit is contained in:
Adrian Ulrich 2015-08-11 13:41:37 +02:00
parent 1802214fc1
commit bd77ac3b5d
5 changed files with 60 additions and 52 deletions

View File

@ -30,19 +30,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<View
android:id="@+id/pmark"
android:visibility="gone"
android:layout_width="4dip"
android:layout_height="44dip"
android:visibility="invisible"
android:background="@color/now_playing_marker" />
<ch.blinkenlights.android.vanilla.LazyCoverView
android:id="@+id/cover"
android:visibility="gone"
android:background="?android:attr/selectableItemBackground"
android:longClickable="true"
android:scaleType="fitCenter"
android:layout_width="44dip"
android:layout_height="44dip"
android:visibility="gone"
/>
android:layout_height="44dip" />
<TextView
android:id="@+id/text"
android:maxLines="2"
@ -55,19 +56,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:paddingBottom="2dip"
android:paddingLeft="4dip" />
<CheckedTextView
android:id="@+id/checkbox"
android:visibility="gone"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center_vertical"
android:layout_height="match_parent"
android:layout_width="44dip"/>
<ImageView
android:id="@+id/dragger"
android:scaleType="center"
android:src="@drawable/grabber"
android:layout_width="44dip"
android:layout_height="44dip" />
<CheckedTextView
android:id="@+id/checkbox"
android:visibility="gone"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:gravity="center_vertical"
android:layout_height="match_parent"
android:layout_width="44dip"/>
<ImageView
android:id="@+id/dragger"
android:visibility="gone"
android:scaleType="center"
android:src="@drawable/grabber"
android:layout_width="44dip"
android:layout_height="44dip" />
</LinearLayout>
<View

View File

@ -27,10 +27,14 @@ import android.widget.CheckedTextView;
import android.widget.Checkable;
public class DraggableRow extends LinearLayout implements Checkable {
private boolean mShowCheckBox;
private boolean mShowCover;
private boolean mHighlighted;
/**
* True if the checkbox is checked
*/
private boolean mChecked;
/**
* True if setupLayout has been called
*/
private boolean mLayoutSet;
private TextView mTextView;
private CheckedTextView mCheckBox;
@ -38,6 +42,12 @@ public class DraggableRow extends LinearLayout implements Checkable {
private ImageView mDragger;
private LazyCoverView mCoverView;
/**
* Layout types for use with setupLayout
*/
public static final int LAYOUT_CHECKBOXES = 1;
public static final int LAYOUT_COVERVIEW = 2;
public DraggableRow(Context context, AttributeSet attrs) {
super(context, attrs);
@ -54,7 +64,28 @@ public class DraggableRow extends LinearLayout implements Checkable {
super.onFinishInflate();
}
/**
* Sets up commonly used layouts - can only be called once per view
*
* @param type the layout type to use
*/
public void setupLayout(int type) {
if (!mLayoutSet) {
switch (type) {
case LAYOUT_CHECKBOXES:
mCheckBox.setVisibility(View.VISIBLE);
showDragger(true);
break;
case LAYOUT_COVERVIEW:
mCoverView.setVisibility(View.VISIBLE);
showDragger(true);
break;
default:
break; // do not care
}
mLayoutSet = true;
}
}
@Override
public boolean isChecked() {
@ -77,34 +108,7 @@ public class DraggableRow extends LinearLayout implements Checkable {
* @param state Enable or disable highlighting
*/
public void highlightRow(boolean state) {
if (mHighlighted != state) {
mPmark.setVisibility( state ? View.VISIBLE : View.INVISIBLE );
mHighlighted = state;
}
}
/**
* Changes the visibility of the checkbox
*
* @param state show or destroy the checkbox
*/
public void showCheckBox(boolean state) {
if (mShowCheckBox != state) {
mCheckBox.setVisibility( state ? View.VISIBLE : View.GONE );
mShowCheckBox = state;
}
}
/**
* Change the visibility of the cover view
*
* @param state show or hide the cover view
*/
public void showCoverView(boolean state) {
if (mShowCover != state) {
mCoverView.setVisibility( state ? View.VISIBLE : View.GONE );
mShowCover = state;
}
mPmark.setVisibility( state ? View.VISIBLE : View.INVISIBLE );
}
/**

View File

@ -108,13 +108,14 @@ public class PlaylistAdapter extends CursorAdapter implements Handler.Callback {
public void bindView(View view, Context context, Cursor cursor)
{
DraggableRow dview = (DraggableRow)view;
dview.setupLayout(DraggableRow.LAYOUT_COVERVIEW);
dview.showDragger(mEditable);
TextView textView = dview.getTextView();
textView.setText(cursor.getString(1));
textView.setTag(cursor.getLong(3));
LazyCoverView cover = dview.getCoverView();
dview.showCoverView(true);
cover.setup(mWorkerHandler.getLooper());
cover.setCover(MediaUtils.TYPE_ALBUM, cursor.getLong(4));
}

View File

@ -67,7 +67,7 @@ public class ShowQueueAdapter
} else {
LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
row = (DraggableRow)inflater.inflate(mResource, parent, false);
row.showCoverView(true);
row.setupLayout(DraggableRow.LAYOUT_COVERVIEW);
row.getCoverView().setup(mLooper);
}

View File

@ -90,11 +90,11 @@ public class TabOrderAdapter extends BaseAdapter {
DraggableRow view;
if (convert == null) {
view = (DraggableRow)mInflater.inflate(R.layout.draggable_row, null);
view.setupLayout(DraggableRow.LAYOUT_CHECKBOXES);
} else {
view = (DraggableRow)convert;
}
view.getTextView().setText(LibraryPagerAdapter.TITLES[mTabIds[position]]);
view.showCheckBox(true);
return view;
}