simplify and cleanup FilebrowserStart adapter code
This commit is contained in:
parent
d0e1882f55
commit
4611a6c533
src/ch/blinkenlights/android/vanilla
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2013 Adrian Ulrich <adrian@blinkenlights.ch>
|
* Copyright (C) 2013-2016 Adrian Ulrich <adrian@blinkenlights.ch>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -24,6 +24,7 @@ import android.os.Bundle;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
import android.widget.AdapterView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
@ -31,7 +32,9 @@ import android.widget.Toast;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
|
|
||||||
public class FilebrowserStartActivity extends Activity {
|
public class FilebrowserStartActivity extends Activity
|
||||||
|
implements AdapterView.OnItemClickListener
|
||||||
|
{
|
||||||
|
|
||||||
private ListView mListView;
|
private ListView mListView;
|
||||||
private TextView mPathDisplay;
|
private TextView mPathDisplay;
|
||||||
@ -49,12 +52,13 @@ public class FilebrowserStartActivity extends Activity {
|
|||||||
setContentView(R.layout.filebrowser_content);
|
setContentView(R.layout.filebrowser_content);
|
||||||
mCurrentPath = (String)FileUtils.getFilesystemBrowseStart(this).getAbsolutePath();
|
mCurrentPath = (String)FileUtils.getFilesystemBrowseStart(this).getAbsolutePath();
|
||||||
mPrefEditor = PlaybackService.getSettings(this).edit();
|
mPrefEditor = PlaybackService.getSettings(this).edit();
|
||||||
mListAdapter = new FilebrowserStartAdapter((FilebrowserStartActivity)this, 0);
|
mListAdapter = new FilebrowserStartAdapter(this, 0);
|
||||||
mPathDisplay = (TextView) findViewById(R.id.path_display);
|
mPathDisplay = (TextView) findViewById(R.id.path_display);
|
||||||
mListView = (ListView) findViewById(R.id.list);
|
mListView = (ListView) findViewById(R.id.list);
|
||||||
mSaveButton = (Button) findViewById(R.id.save_button);
|
mSaveButton = (Button) findViewById(R.id.save_button);
|
||||||
|
|
||||||
mListView.setAdapter(mListAdapter);
|
mListView.setAdapter(mListAdapter);
|
||||||
|
mListView.setOnItemClickListener(this);
|
||||||
|
|
||||||
mSaveButton.setOnClickListener(new View.OnClickListener() {
|
mSaveButton.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@ -64,9 +68,9 @@ public class FilebrowserStartActivity extends Activity {
|
|||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
** Called when we are displayed (again)
|
* Called when we are displayed (again)
|
||||||
** This will always refresh the whole song list
|
* This will always refresh the whole song list
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
@ -74,13 +78,14 @@ public class FilebrowserStartActivity extends Activity {
|
|||||||
refreshDirectoryList();
|
refreshDirectoryList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
** Create a bare-bones actionbar
|
* Create a bare-bones actionbar
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item)
|
public boolean onOptionsItemSelected(MenuItem item)
|
||||||
{
|
{
|
||||||
@ -92,10 +97,13 @@ public class FilebrowserStartActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
** Enters selected directory at 'pos'
|
* Called if user taps a row
|
||||||
*/
|
*/
|
||||||
public void onDirectoryClicked(int pos) {
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
ViewHolder holder = (ViewHolder)view.getTag();
|
||||||
|
int pos = (int)holder.id;
|
||||||
String dirent = mListAdapter.getItem(pos);
|
String dirent = mListAdapter.getItem(pos);
|
||||||
|
|
||||||
if(pos == 0) {
|
if(pos == 0) {
|
||||||
@ -111,8 +119,8 @@ public class FilebrowserStartActivity extends Activity {
|
|||||||
refreshDirectoryList();
|
refreshDirectoryList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
** display mCurrentPath in the dialog
|
* display mCurrentPath in the dialog
|
||||||
*/
|
*/
|
||||||
private void refreshDirectoryList() {
|
private void refreshDirectoryList() {
|
||||||
File path = new File(mCurrentPath);
|
File path = new File(mCurrentPath);
|
||||||
|
@ -31,18 +31,13 @@ import android.graphics.drawable.Drawable;
|
|||||||
|
|
||||||
public class FilebrowserStartAdapter
|
public class FilebrowserStartAdapter
|
||||||
extends ArrayAdapter<String>
|
extends ArrayAdapter<String>
|
||||||
implements View.OnClickListener
|
|
||||||
{
|
{
|
||||||
|
|
||||||
private final FilebrowserStartActivity mActivity;
|
|
||||||
private final Drawable mFolderIcon;
|
|
||||||
private final LayoutInflater mInflater;
|
private final LayoutInflater mInflater;
|
||||||
|
|
||||||
public FilebrowserStartAdapter(FilebrowserStartActivity activity, int resource) {
|
public FilebrowserStartAdapter(Context context, int resource) {
|
||||||
super(activity, resource);
|
super(context, resource);
|
||||||
mActivity = activity;
|
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
mFolderIcon = activity.getResources().getDrawable(R.drawable.folder);
|
|
||||||
mInflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -54,8 +49,7 @@ public class FilebrowserStartAdapter
|
|||||||
row = (DraggableRow)mInflater.inflate(R.layout.draggable_row, null);
|
row = (DraggableRow)mInflater.inflate(R.layout.draggable_row, null);
|
||||||
row.setupLayout(DraggableRow.LAYOUT_LISTVIEW);
|
row.setupLayout(DraggableRow.LAYOUT_LISTVIEW);
|
||||||
|
|
||||||
row.getCoverView().setImageDrawable(mFolderIcon);
|
row.getCoverView().setImageResource(R.drawable.folder);
|
||||||
row.setOnClickListener(this);
|
|
||||||
|
|
||||||
holder = new ViewHolder();
|
holder = new ViewHolder();
|
||||||
row.setTag(holder);
|
row.setTag(holder);
|
||||||
@ -70,10 +64,4 @@ public class FilebrowserStartAdapter
|
|||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
ViewHolder holder = (ViewHolder)view.getTag();
|
|
||||||
mActivity.onDirectoryClicked((int)holder.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user