Browse Source

Showing labels in the navigation list or spinner.

pull/11/head
Eric Kok 12 years ago
parent
commit
597c6b1ac3
  1. 2
      core/res/layout/list_item_filter.xml
  2. 3
      core/res/layout/list_item_navigation.xml
  3. 20
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  4. 19
      core/src/org/transdroid/core/gui/log/Log.java
  5. 17
      core/src/org/transdroid/core/gui/navigation/FilterListAdapter.java
  6. 16
      core/src/org/transdroid/core/gui/navigation/Label.java
  7. 10
      lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java
  8. 5
      lib/src/org/xmlrpc/android/XMLRPCClient.java

2
core/res/layout/list_item_filter.xml

@ -12,6 +12,6 @@ @@ -12,6 +12,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:textIsSelectable="true" />
android:textIsSelectable="false" />
</FrameLayout>

3
core/res/layout/list_item_navigation.xml

@ -3,8 +3,7 @@ @@ -3,8 +3,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/margin_default"
android:paddingRight="@dimen/margin_default" >
android:paddingRight="@dimen/margin_half" >
<TextView
android:id="@+id/filter_text"

20
core/src/org/transdroid/core/gui/TorrentsActivity.java

@ -20,9 +20,8 @@ import org.transdroid.core.app.settings.ServerSetting; @@ -20,9 +20,8 @@ import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.log.Log_;
import org.transdroid.core.gui.navigation.*;
import org.transdroid.core.gui.navigation.NavigationFilter;
import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.gui.navigation.NavigationSelectionView.NavigationFilterManager;
import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.core.gui.settings.*;
@ -45,6 +44,7 @@ import org.transdroid.daemon.task.SetLabelTask; @@ -45,6 +44,7 @@ import org.transdroid.daemon.task.SetLabelTask;
import org.transdroid.daemon.task.SetTrackersTask;
import org.transdroid.daemon.task.StartTask;
import org.transdroid.daemon.task.StopTask;
import org.transdroid.daemon.util.DLog;
import android.annotation.TargetApi;
import android.app.SearchManager;
@ -116,19 +116,22 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -116,19 +116,22 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
navigationListAdapter = FilterListAdapter_.getInstance_(this);
navigationListAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this));
// Add an empty labels list (which will be updated later, but the adapter needs to be created now)
navigationListAdapter.updateLabels(new ArrayList<SimpleListItem>());
navigationListAdapter.updateLabels(new ArrayList<Label>());
filtersList.setAdapter(navigationListAdapter);
filtersList.setOnItemSelectedListener(onFilterListItemSelected);
} else {
// Add status types directly to the action bar spinner
navigationSpinnerAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this));
// Add an empty labels list (which will be updated later, but the adapter needs to be created now)
navigationSpinnerAdapter.updateLabels(new ArrayList<SimpleListItem>());
navigationSpinnerAdapter.updateLabels(new ArrayList<Label>());
}
// Now that all items (or at least their adapters) have been added
getSupportActionBar().setListNavigationCallbacks(navigationSpinnerAdapter, this);
currentFilter = StatusType.getShowAllType(this);
// Log messages from the server daemons using our singleton logger
DLog.setLogger(Log_.getInstance_(this));
// Connect to the last used server
ServerSetting lastUsed = applicationSettings.getLastUsedServer();
if (lastUsed == null) {
@ -497,7 +500,14 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -497,7 +500,14 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (fragmentDetails != null) {
fragmentDetails.perhapsUpdateTorrent(torrents);
}
// TODO: Update local list of labels
// Update local list of labels in the navigation
if (navigationListAdapter != null) {
// Labels are shown in the dedicated side navigation
navigationListAdapter.updateLabels(Label.convertToNavigationLabels(labels));
} else {
// Labels are shown in the action bar spinner
navigationSpinnerAdapter.updateLabels(Label.convertToNavigationLabels(labels));
}
}
@UiThread

19
core/src/org/transdroid/core/gui/log/Log.java

@ -6,6 +6,7 @@ import java.util.Date; @@ -6,6 +6,7 @@ import java.util.Date;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.EBean.Scope;
import org.androidannotations.annotations.OrmLiteDao;
import org.transdroid.daemon.util.ITLogger;
import android.content.Context;
@ -17,14 +18,20 @@ import com.j256.ormlite.stmt.DeleteBuilder; @@ -17,14 +18,20 @@ import com.j256.ormlite.stmt.DeleteBuilder;
* @author Eric Kok
*/
@EBean(scope = Scope.Singleton)
public class Log {
public class Log implements ITLogger {
public static final String LOG_NAME = "Transdroid";
private static final long MAX_LOG_AGE = 15 * 60 * 1000; // 15 minutes
// Access to resources and database in local singleton instance
private Context context;
@OrmLiteDao(helper = DatabaseHelper.class, model = ErrorLogEntry.class)
Dao<ErrorLogEntry, Integer> errorLogDao;
protected Log(Context context) {
this.context = context;
}
protected void log(String logName, int priority, String message) {
android.util.Log.println(priority, LOG_NAME, message);
try {
@ -51,4 +58,14 @@ public class Log { @@ -51,4 +58,14 @@ public class Log {
Log_.getInstance_(caller).log(caller.getClass().toString(), android.util.Log.DEBUG, message);
}
@Override
public void d(String self, String msg) {
Log.d(context, msg);
}
@Override
public void e(String self, String msg) {
Log.e(context, msg);
}
}

17
core/src/org/transdroid/core/gui/navigation/FilterListAdapter.java

@ -5,9 +5,10 @@ import java.util.List; @@ -5,9 +5,10 @@ import java.util.List;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;
import org.transdroid.core.R;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.gui.lists.SimpleListItemAdapter;
import org.transdroid.core.gui.navigation.NavigationSelectionView.NavigationFilterManager;
import org.transdroid.core.gui.navigation.StatusType.StatusTypeFilter;
import android.content.Context;
import android.view.View;
@ -46,10 +47,10 @@ public class FilterListAdapter extends MergeAdapter { @@ -46,10 +47,10 @@ public class FilterListAdapter extends MergeAdapter {
* Update the list of available servers
* @param servers The new list of available servers
*/
public void updateServers(List<? extends SimpleListItem> servers) {
public void updateServers(List<ServerSetting> servers) {
if (this.serverItems == null && servers != null) {
serverSeparator = FilterSeparatorView_.build(context).setText(context.getString(R.string.navigation_servers));
serverSeparator.setVisibility(serverItems.isEmpty()? View.GONE: View.VISIBLE);
serverSeparator.setVisibility(servers.isEmpty()? View.GONE: View.VISIBLE);
addView(serverSeparator, false);
this.serverItems = new SimpleListItemAdapter(context, servers);
addAdapter(serverItems);
@ -66,11 +67,11 @@ public class FilterListAdapter extends MergeAdapter { @@ -66,11 +67,11 @@ public class FilterListAdapter extends MergeAdapter {
* Update the list of available status types
* @param statusTypes The new list of available status types
*/
public void updateStatusTypes(List<? extends SimpleListItem> statusTypes) {
public void updateStatusTypes(List<StatusTypeFilter> statusTypes) {
if (this.statusTypeItems == null && statusTypes != null) {
statusTypeSeparator = FilterSeparatorView_.build(context).setText(
context.getString(R.string.navigation_status));
statusTypeSeparator.setVisibility(statusTypeItems.isEmpty()? View.GONE: View.VISIBLE);
statusTypeSeparator.setVisibility(statusTypes.isEmpty()? View.GONE: View.VISIBLE);
addView(statusTypeSeparator, false);
this.statusTypeItems = new SimpleListItemAdapter(context, statusTypes);
addAdapter(statusTypeItems);
@ -87,14 +88,14 @@ public class FilterListAdapter extends MergeAdapter { @@ -87,14 +88,14 @@ public class FilterListAdapter extends MergeAdapter {
* Update the list of available labels
* @param labels The new list of available labels
*/
public void updateLabels(List<? extends SimpleListItem> labels) {
public void updateLabels(List<Label> labels) {
if (this.labelItems == null && labels != null) {
labelSeperator = FilterSeparatorView_.build(context).setText(context.getString(R.string.navigation_labels));
labelSeperator.setVisibility(labelItems.isEmpty()? View.GONE: View.VISIBLE);
labelSeperator.setVisibility(labels.isEmpty()? View.GONE: View.VISIBLE);
addView(labelSeperator, false);
this.labelItems = new SimpleListItemAdapter(context, labels);
addAdapter(labelItems);
} else if (this.serverItems != null && labels != null) {
} else if (this.labelItems != null && labels != null) {
labelSeperator.setVisibility(labelItems.isEmpty()? View.GONE: View.VISIBLE);
this.labelItems.update(labels);
} else {

16
core/src/org/transdroid/core/gui/navigation/Label.java

@ -13,12 +13,14 @@ import android.os.Parcelable; @@ -13,12 +13,14 @@ import android.os.Parcelable;
* Represents some label that is active or available on the server.
* @author Eric Kok
*/
public class Label extends org.transdroid.daemon.Label implements SimpleListItem, NavigationFilter {
public class Label implements SimpleListItem, NavigationFilter {
private final String name;
private final int count;
public Label(String name) {
this.name = name;
public Label(org.transdroid.daemon.Label daemonLabel) {
this.name = daemonLabel.getName();
this.count = daemonLabel.getCount();
}
@Override
@ -26,6 +28,10 @@ public class Label extends org.transdroid.daemon.Label implements SimpleListItem @@ -26,6 +28,10 @@ public class Label extends org.transdroid.daemon.Label implements SimpleListItem
return this.name;
}
public int getCount() {
return count;
}
@Override
public boolean matches(Torrent torrent) {
return torrent.getLabelName() != null && torrent.getLabelName().equals(name);
@ -36,13 +42,14 @@ public class Label extends org.transdroid.daemon.Label implements SimpleListItem @@ -36,13 +42,14 @@ public class Label extends org.transdroid.daemon.Label implements SimpleListItem
return null;
List<Label> localLabels = new ArrayList<Label>();
for (org.transdroid.daemon.Label label : daemonLabels) {
localLabels.add(new Label(label.getName()));
localLabels.add(new Label(label));
}
return localLabels;
}
private Label(Parcel in) {
this.name = in.readString();
this.count = in.readInt();
}
public static final Parcelable.Creator<Label> CREATOR = new Parcelable.Creator<Label>() {
@ -63,6 +70,7 @@ public class Label extends org.transdroid.daemon.Label implements SimpleListItem @@ -63,6 +70,7 @@ public class Label extends org.transdroid.daemon.Label implements SimpleListItem
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(count);
}
}

10
lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java

@ -241,14 +241,16 @@ public class RtorrentAdapter implements IDaemonAdapter { @@ -241,14 +241,16 @@ public class RtorrentAdapter implements IDaemonAdapter {
initialise();
}
String params = "";
for (Object arg : arguments) params += " " + arg.toString();
try {
String params = "";
for (Object arg : arguments) params += " " + arg.toString();
DLog.d(LOG_NAME, "Calling " + serverMethod + " with params [" + (params.length() > 300? params.substring(0, 300) + "...": params) + " ]");
DLog.d(LOG_NAME, "Calling " + serverMethod + " with params [" + (params.length() > 100? params.substring(0, 100) + "...": params) + " ]");
return rpcclient.call(serverMethod, arguments);
} catch (XMLRPCException e) {
DLog.d(LOG_NAME, e.toString());
throw new DaemonException(ExceptionType.ConnectionError, "Error making call to " + serverMethod + " with params " + arguments.toString() + ": " + e.toString());
if (e.getCause() instanceof DaemonException)
throw (DaemonException) e.getCause();
throw new DaemonException(ExceptionType.ConnectionError, "Error making call to " + serverMethod + " with params [" + (params.length() > 100? params.substring(0, 100) + "...": params) + " ]: " + e.toString());
}
}

5
lib/src/org/xmlrpc/android/XMLRPCClient.java

@ -14,6 +14,8 @@ import org.apache.http.client.methods.HttpPost; @@ -14,6 +14,8 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.transdroid.daemon.DaemonException;
import org.transdroid.daemon.DaemonMethod;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
@ -319,6 +321,9 @@ public class XMLRPCClient { @@ -319,6 +321,9 @@ public class XMLRPCClient {
// check status code
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
if (statusCode == HttpStatus.SC_UNAUTHORIZED)
throw new DaemonException(DaemonException.ExceptionType.AuthenticationFailure, "HTTP status code: "
+ statusCode + " != " + HttpStatus.SC_OK);
throw new XMLRPCException("HTTP status code: " + statusCode + " != " + HttpStatus.SC_OK);
}

Loading…
Cancel
Save