Browse Source

Fixing the details fragment to show and with a proper layout of headers.\nStarting task execution.

pull/11/head
Eric Kok 12 years ago
parent
commit
ee824238d0
  1. 4
      lite/res/layout/list_item_filter.xml
  2. 2
      lite/res/layout/list_item_separator.xml
  3. 2
      lite/res/menu/fragment_details.xml
  4. 14
      lite/res/values/strings.xml
  5. 3
      lite/res/xml/pref_system.xml
  6. 42
      lite/src/org/transdroid/core/gui/DetailsFragment.java
  7. 84
      lite/src/org/transdroid/core/gui/TorrentsActivity.java
  8. 7
      lite/src/org/transdroid/core/gui/TorrentsFragment.java
  9. 15
      lite/src/org/transdroid/core/gui/lists/DetailsAdapter.java
  10. 12
      lite/src/org/transdroid/core/gui/lists/TorrentDetailsView.java
  11. 7
      lite/src/org/transdroid/core/gui/navigation/FilterSeparatorView.java
  12. 2
      lite/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java

4
lite/res/layout/list_item_filter.xml

@ -2,8 +2,8 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingTop="@dimen/margin_half" android:paddingTop="4dip"
android:paddingBottom="@dimen/margin_half" android:paddingBottom="4dip"
android:paddingLeft="@dimen/margin_default" android:paddingLeft="@dimen/margin_default"
android:paddingRight="@dimen/margin_default" > android:paddingRight="@dimen/margin_default" >

2
lite/res/layout/list_item_separator.xml

@ -2,6 +2,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingTop="@dimen/margin_half"
android:paddingBottom="@dimen/margin_half"
android:orientation="horizontal" > android:orientation="horizontal" >
<TextView <TextView

2
lite/res/menu/fragment_details.xml

@ -37,7 +37,7 @@
android:title="@string/action_setlabel" /> android:title="@string/action_setlabel" />
<item <item
android:id="@+id/action_updatetrackers" android:id="@+id/action_updatetrackers"
android:showAsAction="never" android:showAsAction="ifRoom"
android:title="@string/action_updatetrackers" /> android:title="@string/action_updatetrackers" />
</menu> </menu>

14
lite/res/values/strings.xml

@ -84,6 +84,20 @@
<string name="labels_newlabel">New label</string> <string name="labels_newlabel">New label</string>
<string name="labels_no_support">Setting a label is not supported by your client</string> <string name="labels_no_support">Setting a label is not supported by your client</string>
<string name="result_added">Torrent added (refreshing)</string>
<string name="result_removed">%1$s removed</string>
<string name="result_removed_with_data">%1$s removed and data deleted</string>
<string name="result_resumed">%1$s resumed (refreshing)</string>
<string name="result_stopped">%1$s stopped</string>
<string name="result_started">%1$s started (refreshing)</string>
<string name="result_paused">%1$s paused</string>
<string name="result_paused_all">Torrents paused</string>
<string name="result_resumed_all">Torrents resumed (refreshing)</string>
<string name="result_stopped_all">Torrents stopped</string>
<string name="result_started_all">Torrents started (refreshing)</string>
<string name="result_trackersupdated">Trackers updated</string>
<string name="result_locationset">Torrent moved to \'%1$s\'</string>
<string name="search_torrentsearch">Torrent search</string> <string name="search_torrentsearch">Torrent search</string>
<string name="search_hint">Search for torrents</string> <string name="search_hint">Search for torrents</string>
<string name="search_"></string> <string name="search_"></string>

3
lite/res/xml/pref_system.xml

@ -10,8 +10,7 @@
<Preference <Preference
android:key="system_sendlog" android:key="system_sendlog"
android:title="@string/pref_sendlog" android:title="@string/pref_sendlog"
android:summary="@string/pref_sendlog_info"> android:summary="@string/pref_sendlog_info" />
</Preference>
<Preference <Preference
android:key="system_installhelp" android:key="system_installhelp"

42
lite/src/org/transdroid/core/gui/DetailsFragment.java

@ -6,10 +6,13 @@ import java.util.List;
import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EFragment; import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.InstanceState; import org.androidannotations.annotations.InstanceState;
import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu;
import org.androidannotations.annotations.ViewById; import org.androidannotations.annotations.ViewById;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.gui.lists.DetailsAdapter; import org.transdroid.core.gui.lists.DetailsAdapter;
import org.transdroid.core.gui.lists.SimpleListItemAdapter; import org.transdroid.core.gui.lists.SimpleListItemAdapter;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.Torrent; import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentDetails; import org.transdroid.daemon.TorrentDetails;
import org.transdroid.daemon.TorrentFile; import org.transdroid.daemon.TorrentFile;
@ -17,6 +20,7 @@ import org.transdroid.daemon.TorrentFile;
import android.widget.TextView; import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.SherlockListView; import com.actionbarsherlock.view.SherlockListView;
/** /**
@ -25,6 +29,7 @@ import com.actionbarsherlock.view.SherlockListView;
* @author Eric Kok * @author Eric Kok
*/ */
@EFragment(R.layout.fragment_details) @EFragment(R.layout.fragment_details)
@OptionsMenu(R.menu.fragment_details)
public class DetailsFragment extends SherlockFragment { public class DetailsFragment extends SherlockFragment {
// Local data // Local data
@ -60,8 +65,11 @@ public class DetailsFragment extends SherlockFragment {
* @param newTorrent The new torrent object * @param newTorrent The new torrent object
*/ */
public void updateTorrent(Torrent newTorrent) { public void updateTorrent(Torrent newTorrent) {
clear();
this.torrent = newTorrent; this.torrent = newTorrent;
((DetailsAdapter) detailsList.getAdapter()).updateTorrent(newTorrent); ((DetailsAdapter) detailsList.getAdapter()).updateTorrent(newTorrent);
// Also update the available actions in the action bar
getActivity().supportInvalidateOptionsMenu();
} }
/** /**
@ -110,4 +118,38 @@ public class DetailsFragment extends SherlockFragment {
torrentFiles = null; torrentFiles = null;
} }
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
// Update action availability
boolean startStop = Daemon.supportsStoppingStarting(torrent.getDaemon());
menu.findItem(R.id.action_resume).setVisible(torrent.canResume());
menu.findItem(R.id.action_pause).setVisible(torrent.canPause());
menu.findItem(R.id.action_start).setVisible(startStop && torrent.canStart());
menu.findItem(R.id.action_stop).setVisible(startStop && torrent.canStop());
boolean removeWithData = Daemon.supportsRemoveWithData(torrent.getDaemon());
menu.findItem(R.id.action_remove_withdata).setVisible(removeWithData);
boolean setLabel = Daemon.supportsSetLabel(torrent.getDaemon());
menu.findItem(R.id.action_setlabel).setVisible(setLabel);
boolean setTrackers = Daemon.supportsSetTrackers(torrent.getDaemon());
menu.findItem(R.id.action_updatetrackers).setVisible(setTrackers);
}
@OptionsItem(R.id.action_start)
protected void startTorrent() {
}
public interface DetailsTasksExecutor {
void resumeTorrent(Torrent torrent);
void pauseTorrent(Torrent torrent);
void startTorrent(Torrent torrent);
void stopTorrent(Torrent torrent);
void removeTorrent(Torrent torrent, boolean withData);
void setLabel(Torrent torrent);
void updateTrackers(Torrent torrent);
}
} }

84
lite/src/org/transdroid/core/gui/TorrentsActivity.java

@ -17,6 +17,8 @@ import org.androidannotations.annotations.ViewById;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.app.settings.ServerSetting; import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.gui.DetailsFragment.DetailsTasksExecutor;
import org.transdroid.core.gui.TorrentsFragment.TorrentsTasksExecutor;
import org.transdroid.core.gui.lists.LocalTorrent; import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.lists.SimpleListItem; import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.navigation.FilterListAdapter; import org.transdroid.core.gui.navigation.FilterListAdapter;
@ -31,6 +33,8 @@ import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Torrent; import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.task.DaemonTaskFailureResult; import org.transdroid.daemon.task.DaemonTaskFailureResult;
import org.transdroid.daemon.task.DaemonTaskResult; import org.transdroid.daemon.task.DaemonTaskResult;
import org.transdroid.daemon.task.DaemonTaskSuccessResult;
import org.transdroid.daemon.task.ResumeTask;
import org.transdroid.daemon.task.RetrieveTask; import org.transdroid.daemon.task.RetrieveTask;
import org.transdroid.daemon.task.RetrieveTaskSuccessResult; import org.transdroid.daemon.task.RetrieveTaskSuccessResult;
@ -52,7 +56,7 @@ import com.actionbarsherlock.widget.SearchView;
@EActivity(R.layout.activity_torrents) @EActivity(R.layout.activity_torrents)
@OptionsMenu(R.menu.activity_torrents) @OptionsMenu(R.menu.activity_torrents)
public class TorrentsActivity extends SherlockFragmentActivity implements OnNavigationListener { public class TorrentsActivity extends SherlockFragmentActivity implements OnNavigationListener, DetailsTasksExecutor, TorrentsTasksExecutor {
// Navigation components // Navigation components
@Bean @Bean
@ -298,6 +302,12 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// TODO: Update local list of labels // TODO: Update local list of labels
} }
@UiThread
protected void onTaskSucceeded(DaemonTaskSuccessResult result, int successMessageId, Torrent target) {
// TODO: Properly report this success
Toast.makeText(this, getString(successMessageId, target.getName()),Toast.LENGTH_LONG).show();
}
@UiThread @UiThread
protected void onCommunicationError(DaemonTaskFailureResult result) { protected void onCommunicationError(DaemonTaskFailureResult result) {
// TODO: Properly report this error // TODO: Properly report this error
@ -305,4 +315,76 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
} }
@Background
@Override
public void resumeTorrent(Torrent torrent) {
torrent.mimicResume();
DaemonTaskResult result = ResumeTask.create(currentConnection, torrent).execute();
if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_resumed, torrent);
} else {
onCommunicationError((DaemonTaskFailureResult) result);
}
}
@Override
public void pauseTorrent(Torrent torrent) {
// TODO Auto-generated method stub
}
@Override
public void startTorrent(Torrent torrent) {
// TODO Auto-generated method stub
}
@Override
public void stopTorrent(Torrent torrent) {
// TODO Auto-generated method stub
}
@Override
public void removeTorrent(Torrent torrent, boolean withData) {
// TODO Auto-generated method stub
}
@Override
public void setLabel(Torrent torrent) {
// TODO Auto-generated method stub
}
@Override
public void updateTrackers(Torrent torrent) {
// TODO Auto-generated method stub
}
@Override
public void resumeTorrents(List<Torrent> torrents) {
// TODO Auto-generated method stub
}
@Override
public void pauseTorrents(List<Torrent> torrents) {
// TODO Auto-generated method stub
}
@Override
public void removeTorrents(List<Torrent> torrents, boolean withData) {
// TODO Auto-generated method stub
}
@Override
public void setLabels(List<Torrent> torrents) {
// TODO Auto-generated method stub
}
} }

7
lite/src/org/transdroid/core/gui/TorrentsFragment.java

@ -146,4 +146,11 @@ public class TorrentsFragment extends SherlockFragment {
// TODO: Implement action // TODO: Implement action
} }
public interface TorrentsTasksExecutor {
void resumeTorrents(List<Torrent> torrents);
void pauseTorrents(List<Torrent> torrents);
void removeTorrents(List<Torrent> torrents, boolean withData);
void setLabels(List<Torrent> torrents);
}
} }

15
lite/src/org/transdroid/core/gui/lists/DetailsAdapter.java

@ -81,7 +81,7 @@ public class DetailsAdapter extends MergeAdapter {
torrentFilesSeparatorView.setVisibility(View.GONE); torrentFilesSeparatorView.setVisibility(View.GONE);
} else { } else {
torrentFilesAdapter.update(torrentFiles); torrentFilesAdapter.update(torrentFiles);
torrentFilesSeparatorView.setVisibility(View.GONE); torrentFilesSeparatorView.setVisibility(View.VISIBLE);
} }
} }
@ -95,7 +95,7 @@ public class DetailsAdapter extends MergeAdapter {
trackersSeparatorView.setVisibility(View.GONE); trackersSeparatorView.setVisibility(View.GONE);
} else { } else {
trackersAdapter.update(trackers); trackersAdapter.update(trackers);
trackersSeparatorView.setVisibility(View.GONE); trackersSeparatorView.setVisibility(View.VISIBLE);
} }
} }
@ -109,10 +109,19 @@ public class DetailsAdapter extends MergeAdapter {
errorsSeparatorView.setVisibility(View.GONE); errorsSeparatorView.setVisibility(View.GONE);
} else { } else {
errorsAdapter.update(errors); errorsAdapter.update(errors);
errorsSeparatorView.setVisibility(View.GONE); errorsSeparatorView.setVisibility(View.VISIBLE);
} }
} }
/**
* The details adapter is empty if it is not showing any torrent (regardless of errors, trackers and files)
*/
@Override
public boolean isEmpty() {
//return torrentDetailsView.isBound();
return false;
}
/** /**
* Clear currently visible torrent, including header and shown lists * Clear currently visible torrent, including header and shown lists
*/ */

12
lite/src/org/transdroid/core/gui/lists/TorrentDetailsView.java

@ -21,6 +21,8 @@ import android.widget.TextView;
@EViewGroup(R.layout.fragment_details_header) @EViewGroup(R.layout.fragment_details_header)
public class TorrentDetailsView extends RelativeLayout { public class TorrentDetailsView extends RelativeLayout {
private boolean isShowingData = false;
@ViewById @ViewById
protected TextView labelText, dateaddedText, uploadedText, uploadedunitText, ratioText, upspeedText, seedersText, protected TextView labelText, dateaddedText, uploadedText, uploadedunitText, ratioText, upspeedText, seedersText,
downloadedunitText, downloadedText, totalsizeText, downspeedText, leechersText, statusText; downloadedunitText, downloadedText, totalsizeText, downspeedText, leechersText, statusText;
@ -35,6 +37,12 @@ public class TorrentDetailsView extends RelativeLayout {
*/ */
public void update(Torrent torrent) { public void update(Torrent torrent) {
if (torrent == null) {
isShowingData = false;
return;
}
isShowingData = true;
LocalTorrent local = LocalTorrent.fromTorrent(torrent); LocalTorrent local = LocalTorrent.fromTorrent(torrent);
// Set label text // Set label text
@ -82,4 +90,8 @@ public class TorrentDetailsView extends RelativeLayout {
} }
public boolean isBound() {
return isShowingData ;
}
} }

7
lite/src/org/transdroid/core/gui/navigation/FilterSeparatorView.java

@ -3,7 +3,6 @@ package org.transdroid.core.gui.navigation;
import org.androidannotations.annotations.EViewGroup; import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById; import org.androidannotations.annotations.ViewById;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.gui.lists.SimpleListItem;
import android.content.Context; import android.content.Context;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -26,17 +25,13 @@ public class FilterSeparatorView extends LinearLayout {
super(context); super(context);
} }
public void bind(SimpleListItem filterItem) {
separatorText.setText(text);
}
/** /**
* Sets the text that will be shown in this separator (sub header) * Sets the text that will be shown in this separator (sub header)
* @param text The new text to show * @param text The new text to show
* @return Itself, for convenience of method chaining * @return Itself, for convenience of method chaining
*/ */
public FilterSeparatorView setText(String text) { public FilterSeparatorView setText(String text) {
this.text = text; separatorText.setText(text);
return this; return this;
} }

2
lite/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java

@ -27,7 +27,7 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Just load the system-related preferences from XML // Just load the system-related preferences from XML
addPreferencesFromResource(R.xml.pref_notifications); addPreferencesFromResource(R.xml.pref_system);
// Handle outgoing links // Handle outgoing links
findPreference("system_sendlog").setOnPreferenceClickListener(onSendLogClick); findPreference("system_sendlog").setOnPreferenceClickListener(onSendLogClick);

Loading…
Cancel
Save