Commit 1f6123cd authored by Sébastien Toque's avatar Sébastien Toque

UI: update list style in search & folder browser

parent 5f37161f
......@@ -2,9 +2,11 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/item_common"
android:orientation="vertical">
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
android:divider="@color/item_common"
android:dividerHeight="1dp" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_item"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="5dip"
......
......@@ -3,7 +3,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_height="fill_parent"
android:background="@color/item_common">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="48dip"
......@@ -34,5 +35,7 @@
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@color/item_common"
android:dividerHeight="1dp"
android:fastScrollEnabled="true" />
</LinearLayout>
......@@ -26,6 +26,7 @@ import java.util.List;
import org.videolan.vlc.DatabaseManager;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import android.content.Context;
import android.util.Log;
......@@ -63,6 +64,7 @@ public class BrowserAdapter extends ArrayAdapter<File>
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.browser_item, parent, false);
holder = new ViewHolder();
holder.layout = (View) view.findViewById(R.id.layout_item);
holder.check = (CheckBox) view.findViewById(R.id.browser_item_selected);
holder.text = (TextView) view.findViewById(R.id.browser_item_dir);
view.setTag(holder);
......@@ -73,6 +75,7 @@ public class BrowserAdapter extends ArrayAdapter<File>
final DatabaseManager dbManager = DatabaseManager.getInstance(view.getContext());
if (item != null && item.getName() != null) {
Util.setItemBackground(holder.layout, position);
holder.text.setText(item.getName());
holder.check.setOnCheckedChangeListener(null);
holder.check.setTag(item);
......@@ -129,6 +132,7 @@ public class BrowserAdapter extends ArrayAdapter<File>
}
static class ViewHolder {
View layout;
CheckBox check;
TextView text;
}
......
......@@ -44,7 +44,6 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
......@@ -56,8 +55,7 @@ public class SearchActivity extends ListActivity {
public final static String TAG = "VLC/SearchActivit";
private EditText mSearchText;
private ArrayAdapter<String> mHistoryAdapter;
private ArrayList<String> mHistory = new ArrayList<String>();
private SearchHistoryAdapter mHistoryAdapter;
private SearchResultAdapter mResultAdapter;
private LinearLayout mListHeader;
......@@ -67,6 +65,7 @@ public class SearchActivity extends ListActivity {
setContentView(R.layout.search);
// TODO: create layout
mHistoryAdapter = new SearchHistoryAdapter(this);
mResultAdapter = new SearchResultAdapter(this);
mSearchText = (EditText) findViewById(R.id.search_text);
......@@ -102,9 +101,7 @@ public class SearchActivity extends ListActivity {
@Override
protected void onDestroy() {
if (mHistoryAdapter != null)
mHistoryAdapter.clear();
mHistory.clear();
mHistoryAdapter.clear();
mResultAdapter.clear();
super.onDestroy();
}
......@@ -166,14 +163,9 @@ public class SearchActivity extends ListActivity {
showListHeader(headerText);
DatabaseManager db = DatabaseManager.getInstance(this);
mHistory.clear();
mHistory.addAll(db.getSearchhistory(20));
if (mHistoryAdapter == null) {
mHistoryAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, mHistory);
} else {
mHistoryAdapter.notifyDataSetChanged();
}
mHistoryAdapter.clear();
mHistoryAdapter.addAll(db.getSearchhistory(20));
mHistoryAdapter.notifyDataSetChanged();
setListAdapter(mHistoryAdapter);
}
......
/*****************************************************************************
* SearchResultAdapter.java
*****************************************************************************
* Copyright © 2011-2012 VLC authors and VideoLAN
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package org.videolan.vlc.gui;
import org.videolan.vlc.Util;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class SearchHistoryAdapter extends ArrayAdapter<String> {
public SearchHistoryAdapter(Context context) {
super(context, 0);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
holder = new ViewHolder();
holder.text = (TextView) view.findViewById(android.R.id.text1);
view.setTag(holder);
} else
holder = (ViewHolder) view.getTag();
String item = getItem(position);
Util.setItemBackground(holder.text, position);
holder.text.setText(item);
return view;
}
static class ViewHolder {
TextView text;
}
}
......@@ -23,6 +23,7 @@ package org.videolan.vlc.gui;
import java.util.Comparator;
import org.videolan.vlc.Media;
import org.videolan.vlc.Util;
import android.content.Context;
import android.view.LayoutInflater;
......@@ -32,7 +33,7 @@ import android.widget.ArrayAdapter;
import android.widget.TextView;
public class SearchResultAdapter extends ArrayAdapter<Media>
implements Comparator<Media> {
implements Comparator<Media> {
public SearchResultAdapter(Context context) {
super(context, 0);
......@@ -40,19 +41,22 @@ public class SearchResultAdapter extends ArrayAdapter<Media>
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater)
getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(android.R.layout.simple_list_item_1,
parent, false);
}
ViewHolder holder;
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
holder = new ViewHolder();
holder.text = (TextView) view.findViewById(android.R.id.text1);
view.setTag(holder);
} else
holder = (ViewHolder) view.getTag();
Media item = getItem(position);
TextView textView = (TextView) v.findViewById(android.R.id.text1);
textView.setText(item.getTitle());
Util.setItemBackground(holder.text, position);
holder.text.setText(item.getTitle());
return v;
return view;
}
@Override
......@@ -64,4 +68,7 @@ public class SearchResultAdapter extends ArrayAdapter<Media>
super.sort(this);
}
static class ViewHolder {
TextView text;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment