optimize queue listview performance

This commit is contained in:
Adrian Ulrich committed 2014-10-19 17:02:21 +02:00
1 parent 8c43b1a3c7
commit c76d997db1
3 files changed
+20 -8

No files matched your search

+2 -2
View File
@@ -30,7 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<View
android:id="@+id/pmark"
android:layout_width="2dip"
android:layout_width="4dip"
android:layout_height="44dip"
android:visibility="invisible"
android:background="@android:color/holo_blue_dark" />
@@ -43,7 +43,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:layout_height="match_parent"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:paddingLeft="6dip" />
android:paddingLeft="4dip" />
<!-- spacer -->
<View
android:layout_height="match_parent"
@@ -25,13 +25,15 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.CheckedTextView;
import android.widget.Checkable;
import android.util.Log;
public class DraggableRow extends LinearLayout implements Checkable {
private boolean mShowCheckBox;
private boolean mHighlighted;
private boolean mChecked;
private float mDensity;
private static int sWidth = -1;
private TextView mTextView;
private CheckedTextView mCheckBox;
private View mPmark;
@@ -39,10 +41,10 @@ public class DraggableRow extends LinearLayout implements Checkable {
// Hardcoded sizes of elements in DPI
// MUST match definition in draggable_row
private final int DPI_PMARK = 2;
private final int DPI_PMARK = 4;
private final int DPI_CHECKBOX = 44;
private final int DPI_DRAGGER = 44;
private final int DPI_SLACK = 2; // safety margin
private final int DPI_SLACK = 1; // safety margin
public DraggableRow(Context context, AttributeSet attrs) {
@@ -106,7 +108,10 @@ public class DraggableRow extends LinearLayout implements Checkable {
* @param state Enable or disable highlighting
*/
public void highlightRow(boolean state) {
mPmark.setVisibility( state ? View.VISIBLE : View.INVISIBLE );
if (mHighlighted != state) {
mPmark.setVisibility( state ? View.VISIBLE : View.INVISIBLE );
mHighlighted = state;
}
}
/**
@@ -57,8 +57,15 @@ public class ShowQueueAdapter
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
DraggableRow row = (DraggableRow)inflater.inflate(mResource, parent, false);
DraggableRow row;
if (convertView != null) {
row = (DraggableRow)convertView;
} else {
LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
row = (DraggableRow)inflater.inflate(mResource, parent, false);
}
Song song = getItem(position);
if (song != null) { // unlikely to fail but seems to happen in the wild.