Get rid of getTextView() and provide setText methods for DraggableRow.

This commit is contained in:
Adrian Ulrich committed 2018-04-18 21:38:36 +02:00
1 parent 89237188b0
commit 1fb95734b5
9 files changed
+42 -38

No files matched your search

@@ -18,6 +18,10 @@
package ch.blinkenlights.android.vanilla;
import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
@@ -169,10 +173,26 @@ public class DraggableRow extends LinearLayout implements Checkable {
}
/**
* Returns an instance of our textview
* Sets the text to given string.
*
* @param line the text to display
*/
public TextView getTextView() {
return mTextView;
public void setText(CharSequence line) {
mTextView.setText(line);
}
/**
* Display two lines
*
* @param line1 the first line to show
* @param line2 the second line to show
*/
public void setText(CharSequence line1, CharSequence line2) {
SpannableStringBuilder sb = new SpannableStringBuilder(line1);
sb.append("\n");
sb.append(line2);
sb.setSpan(new ForegroundColorSpan(Color.GRAY), line1.length() + 1, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mTextView.setText(sb);
}
/**
@@ -262,10 +262,12 @@ public class FileSystemAdapter
holder = (ViewHolder)row.getTag();
}
holder.id = pos;
final File file = mFiles[pos];
row.getTextView().setText(file.getName());
final String title = file.getName();
holder.id = pos;
holder.title = title;
row.setText(file.getName());
row.getCoverView().setImageResource(getImageResourceForFile(file));
return row;
}
@@ -402,7 +404,7 @@ public class FileSystemAdapter
Intent intent = new Intent();
intent.putExtra(LibraryAdapter.DATA_TYPE, MediaUtils.TYPE_FILE);
intent.putExtra(LibraryAdapter.DATA_ID, holder.id);
intent.putExtra(LibraryAdapter.DATA_TITLE, ((DraggableRow)view).getTextView().getText().toString());
intent.putExtra(LibraryAdapter.DATA_TITLE, holder.title);
intent.putExtra(LibraryAdapter.DATA_EXPANDABLE, file.isDirectory());
intent.putExtra(LibraryAdapter.DATA_FILE, file.getAbsolutePath());
return intent;
@@ -96,7 +96,7 @@ public class FolderPickerAdapter
Item item = (Item)getItem(pos);
int res = (item.file == null ? R.drawable.arrow_up : R.drawable.folder);
row.getTextView().setText(item.name);
row.setText(item.name);
row.getCoverView().setImageResource(res);
row.getCoverView().setColorFilter(item.color);
return row;
@@ -341,7 +341,7 @@ public class LibraryPagerAdapter
view.setTag(type);
if (header != null) {
header.getTextView().setText(mHeaderText);
header.setText(mHeaderText);
header.setTag(new ViewHolder()); // behave like a normal library row
view.addHeaderView(header);
mHeaderViews.add(header);
@@ -447,7 +447,7 @@ public class LibraryPagerAdapter
public void setHeaderText(String text)
{
for(DraggableRow row : mHeaderViews) {
row.getTextView().setText(text);
row.setText(text);
}
mHeaderText = text;
}
@@ -29,12 +29,8 @@ import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.graphics.Color;
import android.provider.BaseColumns;
import android.provider.MediaStore;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
@@ -521,16 +517,12 @@ public class MediaAdapter
if (mProjection.length >= 6)
duration = MediaUtils.getFormattedDuration(cursor.getLong(5));
SpannableStringBuilder sb = new SpannableStringBuilder(line1);
sb.append('\n');
sb.append(line2);
sb.setSpan(new ForegroundColorSpan(Color.GRAY), line1.length() + 1, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
row.getTextView().setText(sb);
row.setText(line1, line2);
holder.title = line1;
} else {
String title = cursor.getString(2);
if(title == null) { title = DB_NULLSTRING_FALLBACK; }
row.getTextView().setText(title);
row.setText(title);
holder.title = title;
}
@@ -34,6 +34,7 @@ import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Button;
@@ -265,9 +266,9 @@ public class PlaylistActivity extends Activity
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id)
{
if (!mEditing && mDefaultAction != LibraryActivity.ACTION_DO_NOTHING) {
// fixme: this is butt ugly: the adapter should probably already set this on view (its parent)
// setting this on the textarea is hacky
performAction(mDefaultAction, position, (Long)view.findViewById(R.id.text).getTag());
// A DSLV row was clicked, but we need to get the DraggableRow class.
final View target = ((ViewGroup)view).getChildAt(0);
performAction(mDefaultAction, position, (Long)target.getTag());
}
}
@@ -108,10 +108,8 @@ public class PlaylistAdapter extends CursorAdapter implements Handler.Callback {
DraggableRow dview = (DraggableRow)view;
dview.setupLayout(DraggableRow.LAYOUT_DRAGGABLE);
dview.showDragger(mEditable);
TextView textView = dview.getTextView();
textView.setText(cursor.getString(1));
textView.setTag(cursor.getLong(3));
dview.setText(cursor.getString(1));
dview.setTag(cursor.getLong(3));
String duration = MediaUtils.getFormattedDuration(cursor.getLong(6));
dview.getDurationView().setText(duration);
@@ -24,11 +24,6 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.view.LayoutInflater;
import android.graphics.Color;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.text.Spannable;
public class ShowQueueAdapter extends BaseAdapter {
/**
* The resource to pass to the inflater
@@ -136,11 +131,7 @@ public class ShowQueueAdapter extends BaseAdapter {
Song song = getItem(position);
if (song.isFilled()) {
SpannableStringBuilder sb = new SpannableStringBuilder(song.title);
sb.append('\n');
sb.append(song.album+", "+song.artist);
sb.setSpan(new ForegroundColorSpan(Color.GRAY), song.title.length() + 1, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
row.getTextView().setText(sb);
row.setText(song.title, song.album+", "+song.artist);
row.getCoverView().setCover(MediaUtils.TYPE_ALBUM, song.albumId, null);
row.getDurationView().setText(MediaUtils.getFormattedDuration(song.duration));
}
@@ -94,7 +94,7 @@ public class TabOrderAdapter extends BaseAdapter {
} else {
view = (DraggableRow)convert;
}
view.getTextView().setText(LibraryPagerAdapter.TITLES[mTabIds[position]]);
view.setText(mActivity.getResources().getText(LibraryPagerAdapter.TITLES[mTabIds[position]]));
return view;
}