From abdc3d5c628738807819013c954df82e10010813 Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Sun, 12 Apr 2015 20:26:24 +0200 Subject: [PATCH] use normal library row for filebrowser settings --- res/layout/filebrowser_row.xml | 12 --- .../vanilla/FilebrowserStartActivity.java | 14 +--- .../vanilla/FilebrowserStartAdapter.java | 81 +++++++++++++------ 3 files changed, 60 insertions(+), 47 deletions(-) delete mode 100644 res/layout/filebrowser_row.xml diff --git a/res/layout/filebrowser_row.xml b/res/layout/filebrowser_row.xml deleted file mode 100644 index 11d93a11..00000000 --- a/res/layout/filebrowser_row.xml +++ /dev/null @@ -1,12 +0,0 @@ - - diff --git a/src/ch/blinkenlights/android/vanilla/FilebrowserStartActivity.java b/src/ch/blinkenlights/android/vanilla/FilebrowserStartActivity.java index 4f0babc2..a114f1ef 100644 --- a/src/ch/blinkenlights/android/vanilla/FilebrowserStartActivity.java +++ b/src/ch/blinkenlights/android/vanilla/FilebrowserStartActivity.java @@ -49,21 +49,15 @@ public class FilebrowserStartActivity extends PlaybackActivity { setTitle(R.string.filebrowser_start); setContentView(R.layout.filebrowser_content); - mCurrentPath = (String)getFilesystemBrowseStart().getAbsolutePath(); mPrefEditor = PlaybackService.getSettings(this).edit(); - mListAdapter = new FilebrowserStartAdapter(this, R.layout.filebrowser_row); + mListAdapter = new FilebrowserStartAdapter((FilebrowserStartActivity)this, 0); mPathDisplay = (TextView) findViewById(R.id.path_display); mListView = (ListView) findViewById(R.id.list); mSaveButton = (Button) findViewById(R.id.save_button); - + mListView.setAdapter(mListAdapter); - mListView.setOnItemClickListener(new OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - jumpToDirectory(position); - }}); - + mSaveButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { mPrefEditor.putString("filesystem_browse_start", mCurrentPath); @@ -103,7 +97,7 @@ public class FilebrowserStartActivity extends PlaybackActivity { /* ** Enters selected directory at 'pos' */ - private void jumpToDirectory(int pos) { + public void onDirectoryClicked(int pos) { String dirent = mListAdapter.getItem(pos); if(pos == 0) { diff --git a/src/ch/blinkenlights/android/vanilla/FilebrowserStartAdapter.java b/src/ch/blinkenlights/android/vanilla/FilebrowserStartAdapter.java index 461172b3..54cfd106 100644 --- a/src/ch/blinkenlights/android/vanilla/FilebrowserStartAdapter.java +++ b/src/ch/blinkenlights/android/vanilla/FilebrowserStartAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Adrian Ulrich + * Copyright (C) 2013-2015 Adrian Ulrich * * 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 @@ -19,39 +19,70 @@ package ch.blinkenlights.android.vanilla; import android.content.Context; import android.app.Activity; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ArrayAdapter; import android.view.LayoutInflater; import android.widget.TextView; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.ArrayAdapter; import android.graphics.drawable.Drawable; - -public class FilebrowserStartAdapter extends ArrayAdapter { +public class FilebrowserStartAdapter + extends ArrayAdapter + implements View.OnClickListener +{ - int resource; - Context context; + private final FilebrowserStartActivity mActivity; private final Drawable mFolderIcon; - - public FilebrowserStartAdapter(Context ctx, int res) { - super(ctx, res); - context = ctx; - resource = res; - mFolderIcon = context.getResources().getDrawable(R.drawable.folder); + private final LayoutInflater mInflater; + + public FilebrowserStartAdapter(FilebrowserStartActivity activity, int resource) { + super(activity, resource); + mActivity = activity; + mFolderIcon = activity.getResources().getDrawable(R.drawable.folder); + mInflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } - + + private static class ViewHolder { + public int id; + public TextView text; + public View divider; + public ImageView arrow; + } + @Override - public View getView(int position, View convertView, ViewGroup parent) { - LayoutInflater inflater = ((Activity)context).getLayoutInflater(); - View row = inflater.inflate(resource, parent, false); - String label = getItem(position); - TextView target = ((TextView)row.findViewById(R.id.text)); - - target.setText(label); - target.setCompoundDrawablesWithIntrinsicBounds(mFolderIcon, null, null, null); - - return row; + public View getView(int pos, View convertView, ViewGroup parent) { + View view; + ViewHolder holder; + + if (convertView == null) { + 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); + view.setTag(holder); + } else { + view = convertView; + holder = (ViewHolder)view.getTag(); + } + + String label = getItem(pos); + holder.id = pos; + holder.text.setText(label); + holder.divider.setVisibility(View.GONE); + holder.arrow.setVisibility(View.GONE); + holder.text.setCompoundDrawablesWithIntrinsicBounds(mFolderIcon, null, null, null); + return view; } - - + + @Override + public void onClick(View view) { + ViewHolder holder = (ViewHolder)((View)view.getParent()).getTag(); + mActivity.onDirectoryClicked(holder.id); + } + }