simplify views

This commit is contained in:
Adrian Ulrich committed 2015-08-05 17:58:50 +02:00
1 parent edc4abb1f4
commit 8d2df9b8a9
6 files changed
+41 -65

No files matched your search

-37
View File
@@ -1,37 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2012 Christopher Eby <kreed@kreed.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
<TextView
android:id="@+id/text"
android:longClickable="true"
android:background="?android:attr/selectableItemBackground"
android:maxLines="2"
android:padding="3dip"
android:textColor="?android:textColorPrimary"
android:gravity="left|center_vertical"
android:layout_width="0px"
android:layout_height="44dip"
android:layout_weight="1" />
</LinearLayout>
+1
View File
@@ -47,5 +47,6 @@ THE SOFTWARE.
android:src="@drawable/arrow"
android:layout_width="44dip"
android:layout_height="44dip"
android:visibility="gone"
android:contentDescription="@string/expand" />
</LinearLayout>
@@ -188,13 +188,6 @@ public class FileSystemAdapter
return pos;
}
private static class ViewHolder {
public int id;
public TextView text;
public View divider;
public ImageView arrow;
}
@Override
public View getView(int pos, View convertView, ViewGroup parent)
{
@@ -205,7 +198,6 @@ public class FileSystemAdapter
view = mInflater.inflate(R.layout.library_row_expandable, null);
holder = new ViewHolder();
holder.text = (TextView)view.findViewById(R.id.text);
holder.divider = view.findViewById(R.id.divider);
holder.arrow = (ImageView)view.findViewById(R.id.arrow);
holder.text.setOnClickListener(this);
holder.arrow.setOnClickListener(this);
@@ -219,7 +211,6 @@ public class FileSystemAdapter
boolean isDirectory = file.isDirectory();
holder.id = pos;
holder.text.setText(file.getName());
holder.divider.setVisibility(isDirectory ? View.VISIBLE : View.GONE);
holder.arrow.setVisibility(isDirectory ? View.VISIBLE : View.GONE);
holder.text.setCompoundDrawablesWithIntrinsicBounds(isDirectory ? mFolderIcon : null, null, null, null);
return view;
@@ -295,11 +286,11 @@ public class FileSystemAdapter
public Intent createData(View view)
{
ViewHolder holder = (ViewHolder)view.getTag();
File file = mFiles[holder.id];
File file = mFiles[(int)holder.id];
Intent intent = new Intent();
intent.putExtra(LibraryAdapter.DATA_TYPE, MediaUtils.TYPE_FILE);
intent.putExtra(LibraryAdapter.DATA_ID, (long)holder.id);
intent.putExtra(LibraryAdapter.DATA_ID, holder.id);
intent.putExtra(LibraryAdapter.DATA_TITLE, holder.text.getText().toString());
intent.putExtra(LibraryAdapter.DATA_EXPANDABLE, file.isDirectory());
@@ -314,18 +314,18 @@ public class LibraryPagerAdapter
case MediaUtils.TYPE_ARTIST:
adapter = mArtistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ARTIST, null);
mArtistAdapter.setExpandable(mSongsPosition != -1 || mAlbumsPosition != -1);
mArtistHeader = header = (LinearLayout)inflater.inflate(R.layout.library_row, null);
mArtistHeader = header = (LinearLayout)inflater.inflate(R.layout.library_row_expandable, null);
break;
case MediaUtils.TYPE_ALBUM:
adapter = mAlbumAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ALBUM, mPendingAlbumLimiter);
mAlbumAdapter.setExpandable(mSongsPosition != -1);
mPendingAlbumLimiter = null;
mAlbumHeader = header = (LinearLayout)inflater.inflate(R.layout.library_row, null);
mAlbumHeader = header = (LinearLayout)inflater.inflate(R.layout.library_row_expandable, null);
break;
case MediaUtils.TYPE_SONG:
adapter = mSongAdapter = new MediaAdapter(activity, MediaUtils.TYPE_SONG, mPendingSongLimiter);
mPendingSongLimiter = null;
mSongHeader = header = (LinearLayout)inflater.inflate(R.layout.library_row, null);
mSongHeader = header = (LinearLayout)inflater.inflate(R.layout.library_row_expandable, null);
break;
case MediaUtils.TYPE_PLAYLIST:
adapter = mPlaylistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_PLAYLIST, null);
@@ -433,33 +433,25 @@ public class MediaAdapter
}
}
private static class ViewHolder {
public long id;
public String title;
public TextView text;
public ImageView arrow;
}
@Override
public View getView(int position, View view, ViewGroup parent)
{
ViewHolder holder;
if (view == null || mExpandable != view instanceof LinearLayout) {
if (view == null) {
// We must create a new view if we're not given a recycle view or
// if the recycle view has the wrong layout.
int layout = mExpandable ? R.layout.library_row_expandable : R.layout.library_row;
view = mInflater.inflate(layout, null);
view = mInflater.inflate(R.layout.library_row_expandable, null);
holder = new ViewHolder();
view.setTag(holder);
holder.text = (TextView)view.findViewById(R.id.text);
if (mExpandable) {
holder.arrow = (ImageView)view.findViewById(R.id.arrow);
holder.arrow.setOnClickListener(this);
}
holder.arrow = (ImageView)view.findViewById(R.id.arrow);
holder.arrow.setOnClickListener(this);
holder.text.setOnClickListener(this);
holder.arrow.setVisibility(mExpandable ? View.VISIBLE : View.GONE);
} else {
holder = (ViewHolder)view.getTag();
}
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2015 Adrian Ulrich <adrian@blinkenlights.ch>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package ch.blinkenlights.android.vanilla;
import android.widget.TextView;
import android.widget.ImageView;
public class ViewHolder {
public long id;
public String title;
public TextView text;
public ImageView arrow;
}