Browse Source

Fixed widget preview torrents list UI.

pull/82/head
Eric Kok 11 years ago
parent
commit
e3c0af1557
  1. 6
      core/src/org/transdroid/core/widget/WidgetConfigActivity.java
  2. 102
      core/src/org/transdroid/core/widget/WidgetPreviewAdapter.java

6
core/src/org/transdroid/core/widget/WidgetConfigActivity.java

@ -32,7 +32,6 @@ import org.transdroid.core.app.settings.ApplicationSettings; @@ -32,7 +32,6 @@ import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.gui.lists.SimpleListItemSpinnerAdapter;
import org.transdroid.core.gui.lists.SortByListItem;
import org.transdroid.core.gui.lists.TorrentsAdapter;
import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.core.gui.navigation.StatusType.StatusTypeFilter;
import org.transdroid.core.service.ConnectivityHelper;
@ -76,8 +75,6 @@ public class WidgetConfigActivity extends SherlockActivity { @@ -76,8 +75,6 @@ public class WidgetConfigActivity extends SherlockActivity {
protected TextView filterText, serverText, errorText;
@ViewById
protected ListView torrentsList;
@Bean
protected TorrentsAdapter previewTorrentsAdapter;
private List<Torrent> previewTorrents = null;
// Settings and helpers
@ -122,7 +119,6 @@ public class WidgetConfigActivity extends SherlockActivity { @@ -122,7 +119,6 @@ public class WidgetConfigActivity extends SherlockActivity {
sortSpinner.setAdapter(new SimpleListItemSpinnerAdapter<SortByListItem>(this, 0, sortOrders));
// TODO: Update to AndroidAnnotations 3.0 and use @CheckedChanged
reverseorderCheckBox.setOnCheckedChangeListener(reverseorderCheckedChanged);
torrentsList.setAdapter(previewTorrentsAdapter);
torrentsList.setEmptyView(errorText);
// Set up action bar with a done button
@ -215,7 +211,7 @@ public class WidgetConfigActivity extends SherlockActivity { @@ -215,7 +211,7 @@ public class WidgetConfigActivity extends SherlockActivity {
.sort(filteredTorrents, new TorrentsComparator(serverType, sortBy, reverseorderCheckBox.isChecked()));
// Finally update the widget preview with the live, filtered and sorted torrents list
previewTorrentsAdapter.update(filteredTorrents);
torrentsList.setAdapter(new WidgetPreviewAdapter(this, 0, filteredTorrents));
torrentsList.setVisibility(View.VISIBLE);
errorText.setVisibility(View.GONE);
}

102
core/src/org/transdroid/core/widget/WidgetPreviewAdapter.java

@ -0,0 +1,102 @@ @@ -0,0 +1,102 @@
/*
* Copyright 2010-2013 Eric Kok et al.
*
* Transdroid 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.
*
* Transdroid 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 Transdroid. If not, see <http://www.gnu.org/licenses/>.
*/
package org.transdroid.core.widget;
import java.util.List;
import org.transdroid.core.R;
import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.daemon.Torrent;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
/**
* A list list item adapter that shows torrents as simplified, widget-style list items; the light theme is always used.
* @author Eric Kok
*/
public class WidgetPreviewAdapter extends ArrayAdapter<Torrent> {
/**
* Constructs the custom array adapter that shows torrents in a widget list style for preview.
* @param context The widget configuration activity context
* @param foo Ignored parameter; the light theme widget appearance is always used
* @param torrents The already-retrieved, non-null list of torrents to show
*/
public WidgetPreviewAdapter(Context context, int foo, List<Torrent> torrents) {
super(context, R.layout.list_item_widget_light, torrents);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the views
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_widget_light, parent, false);
holder = new ViewHolder();
holder.nameText = (TextView) convertView.findViewById(R.id.name_text);
holder.progressText = (TextView) convertView.findViewById(R.id.progress_text);
holder.ratioText = (TextView) convertView.findViewById(R.id.ratio_text);
holder.statusView = convertView.findViewById(R.id.status_view);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
// Bind the torrent values
Torrent torrent = getItem(position);
LocalTorrent local = LocalTorrent.fromTorrent(torrent);
int statusColour;
switch (torrent.getStatusCode()) {
case Downloading:
statusColour = R.color.torrent_downloading;
break;
case Paused:
statusColour = R.color.torrent_paused;
break;
case Seeding:
statusColour = R.color.torrent_seeding;
break;
case Error:
statusColour = R.color.torrent_error;
break;
default: // Checking, Waiting, Queued, Unknown
statusColour = R.color.torrent_other;
break;
}
holder.nameText.setText(torrent.getName());
holder.progressText.setText(local.getProgressSizeText(getContext().getResources(), false));
holder.ratioText.setText(local.getProgressEtaRatioText(getContext().getResources()));
holder.statusView.setBackgroundColor(getContext().getResources().getColor(statusColour));
return convertView;
}
protected static class ViewHolder {
public TextView nameText;
public TextView progressText;
public TextView ratioText;
public View statusView;
}
}
Loading…
Cancel
Save