Browse Source

- renamed RemoteRssFilesAdapter to RemoteRssItemsAdapter

- renamed RemoteRssItemsAdapter.updateFiles() to updateItems()
- added RemoteRssSupplier interface
- removed hard cast in openRemoteRss() and used RemoteRssSupplier
- updated comment for RemoteRssActivity
- RemoteRssActivity.init() now displays a message about configuring RSS feeds if no items are found
- moved "(All recent)" hardcoded string to strings.xml
- renamed RemoteRssFragment.torrentFiles to remoteRssItems
- misc commenting changes
pull/313/head
twig 9 years ago
parent
commit
255311300f
  1. 4
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  2. 20
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java
  3. 22
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java
  4. 8
      app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemsAdapter.java
  5. 12
      app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssSupplier.java
  6. 5
      app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java
  7. 12
      app/src/main/res/layout/activity_remoterss.xml
  8. 7
      app/src/main/res/layout/fragment_remoterss.xml
  9. 5
      app/src/main/res/values/strings.xml

4
app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java

@ -85,6 +85,7 @@ import org.transdroid.core.gui.navigation.RefreshableActivity;
import org.transdroid.core.gui.navigation.StatusType; import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.core.gui.remoterss.RemoteRssActivity_; import org.transdroid.core.gui.remoterss.RemoteRssActivity_;
import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel;
import org.transdroid.core.gui.remoterss.data.RemoteRssSupplier;
import org.transdroid.core.gui.rss.RssfeedsActivity_; import org.transdroid.core.gui.rss.RssfeedsActivity_;
import org.transdroid.core.gui.search.BarcodeHelper; import org.transdroid.core.gui.search.BarcodeHelper;
import org.transdroid.core.gui.search.FilePickerHelper; import org.transdroid.core.gui.search.FilePickerHelper;
@ -101,7 +102,6 @@ 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;
import org.transdroid.daemon.TorrentsSortBy; import org.transdroid.daemon.TorrentsSortBy;
import org.transdroid.daemon.Utorrent.UtorrentAdapter;
import org.transdroid.daemon.task.AddByFileTask; import org.transdroid.daemon.task.AddByFileTask;
import org.transdroid.daemon.task.AddByMagnetUrlTask; import org.transdroid.daemon.task.AddByMagnetUrlTask;
import org.transdroid.daemon.task.AddByUrlTask; import org.transdroid.daemon.task.AddByUrlTask;
@ -855,7 +855,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
@OptionsItem(R.id.action_remoterss) @OptionsItem(R.id.action_remoterss)
protected void openRemoteRss() { protected void openRemoteRss() {
ArrayList<RemoteRssChannel> rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssChannels(); ArrayList<RemoteRssChannel> rssFeedItems = ((RemoteRssSupplier) (currentConnection)).getRemoteRssChannels();
if (rssFeedItems.size() == 0) { if (rssFeedItems.size() == 0) {
return; return;

20
app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java

@ -39,7 +39,6 @@ import org.transdroid.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.app.settings.SystemSettings_; import org.transdroid.core.app.settings.SystemSettings_;
import org.transdroid.core.gui.TorrentsActivity;
import org.transdroid.core.gui.lists.SimpleListItemAdapter; import org.transdroid.core.gui.lists.SimpleListItemAdapter;
import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel;
import org.transdroid.core.gui.remoterss.data.RemoteRssItem; import org.transdroid.core.gui.remoterss.data.RemoteRssItem;
@ -54,10 +53,12 @@ import java.util.Date;
import java.util.List; import java.util.List;
/** /**
* An activity that holds a single torrents details fragment. It is used on devices (i.e. phones) where there is no room to show details in the {@link * An activity that displays a list of {@link RemoteRssItem}s via an instance of {@link RemoteRssFragment}.
* TorrentsActivity} directly. Task execution, such as loading of more details and updating file priorities, is performed in this activity via * The activity manages the drawer to filter items by the feed they came through.
* background methods. *
* @author Eric Kok * By default it displays the latest items within the last month.
*
* @author Twig Nguyen
*/ */
@EActivity(R.layout.activity_remoterss) @EActivity(R.layout.activity_remoterss)
public class RemoteRssActivity extends AppCompatActivity { public class RemoteRssActivity extends AppCompatActivity {
@ -104,8 +105,7 @@ public class RemoteRssActivity extends AppCompatActivity {
// We require feeds to be specified; otherwise close the activity // We require feeds to be specified; otherwise close the activity
if (feeds == null) { if (feeds == null) {
finish(); feeds = new ArrayList<>();
return;
} }
// Simple action bar with up, torrent name as title and refresh button // Simple action bar with up, torrent name as title and refresh button
@ -168,7 +168,7 @@ public class RemoteRssActivity extends AppCompatActivity {
}); });
} }
fragmentRemoteRss.updateTorrentFiles(recentItems); fragmentRemoteRss.updateRemoteItems(recentItems);
RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(0); RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(0);
getSupportActionBar().setSubtitle(channel.getName()); getSupportActionBar().setSubtitle(channel.getName());
} }
@ -178,7 +178,7 @@ public class RemoteRssActivity extends AppCompatActivity {
feedLabels.add(new RemoteRssChannel() { feedLabels.add(new RemoteRssChannel() {
@Override @Override
public String getName() { public String getName() {
return "(All recent)"; return getString(R.string.remoterss_filter_allrecent);
} }
@Override @Override
@ -196,7 +196,7 @@ public class RemoteRssActivity extends AppCompatActivity {
showRecentItems(); showRecentItems();
} }
else { else {
fragmentRemoteRss.updateTorrentFiles(feeds.get(position -1).getItems()); fragmentRemoteRss.updateRemoteItems(feeds.get(position -1).getItems());
} }
RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(position); RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(position);

22
app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java

@ -22,6 +22,7 @@ import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.ActionMenuView; import android.support.v7.widget.ActionMenuView;
import android.view.View; import android.view.View;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView;
import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager; import com.nispok.snackbar.SnackbarManager;
@ -62,7 +63,7 @@ public class RemoteRssFragment extends Fragment {
// Local data // Local data
@InstanceState @InstanceState
protected ArrayList<RemoteRssItem> torrentFiles; protected ArrayList<RemoteRssItem> remoteRssItems;
// Views // Views
@ViewById @ViewById
@ -73,8 +74,10 @@ public class RemoteRssFragment extends Fragment {
protected SwipeRefreshLayout swipeRefreshLayout; protected SwipeRefreshLayout swipeRefreshLayout;
@ViewById @ViewById
protected ListView torrentsList; protected ListView torrentsList;
@ViewById
protected TextView remoterssNoFilesMessage;
protected RemoteRssFilesAdapter adapter; protected RemoteRssItemsAdapter adapter;
@AfterViews @AfterViews
protected void init() { protected void init() {
@ -93,23 +96,26 @@ public class RemoteRssFragment extends Fragment {
// } // }
// Set up details adapter // Set up details adapter
adapter = new RemoteRssFilesAdapter(getActivity()); adapter = new RemoteRssItemsAdapter(getActivity());
torrentsList.setAdapter(adapter); torrentsList.setAdapter(adapter);
torrentsList.setFastScrollEnabled(true); torrentsList.setFastScrollEnabled(true);
// Restore the fragment state (on orientation changes et al.) // Restore the fragment state (on orientation changes et al.)
if (torrentFiles != null) { if (remoteRssItems != null) {
updateTorrentFiles(torrentFiles); updateRemoteItems(remoteRssItems);
} }
} }
/** /**
* Updates the list adapter to show a new list of torrent files, replacing the old files list. * Updates the list adapter to show a new list of torrent files, replacing the old files list.
*/ */
public void updateTorrentFiles(List<RemoteRssItem> remoteRssFiles) { public void updateRemoteItems(List<RemoteRssItem> remoteItems) {
torrentFiles = new ArrayList<>(remoteRssFiles); remoteRssItems = new ArrayList<>(remoteItems);
adapter.updateFiles(torrentFiles); adapter.updateItems(remoteRssItems);
torrentsList.smoothScrollToPosition(0); torrentsList.smoothScrollToPosition(0);
// Show/hide a nice message if there are no items to show
remoterssNoFilesMessage.setVisibility(remoteRssItems.size() > 0 ? View.GONE : View.VISIBLE);
} }
/** /**

8
app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFilesAdapter.java → app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemsAdapter.java

@ -10,11 +10,11 @@ import org.transdroid.core.gui.remoterss.data.RemoteRssItem;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class RemoteRssFilesAdapter extends BaseAdapter { public class RemoteRssItemsAdapter extends BaseAdapter {
protected Context context; protected Context context;
protected List<RemoteRssItem> items; protected List<RemoteRssItem> items;
public RemoteRssFilesAdapter(Context context) { public RemoteRssItemsAdapter(Context context) {
this.context = context; this.context = context;
items = new ArrayList<>(); items = new ArrayList<>();
} }
@ -50,8 +50,8 @@ public class RemoteRssFilesAdapter extends BaseAdapter {
return itemView; return itemView;
} }
public void updateFiles(List<RemoteRssItem> torrentFiles) { public void updateItems(List<RemoteRssItem> remoteItems) {
items = torrentFiles; items = remoteItems;
notifyDataSetChanged(); notifyDataSetChanged();
} }
} }

12
app/src/main/java/org/transdroid/core/gui/remoterss/data/RemoteRssSupplier.java

@ -0,0 +1,12 @@
package org.transdroid.core.gui.remoterss.data;
import java.util.ArrayList;
/**
* Interface for daemon adapters if they support remote RSS management.
*
* @author Twig
*/
public interface RemoteRssSupplier {
ArrayList<RemoteRssChannel> getRemoteRssChannels();
}

5
app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java

@ -30,6 +30,7 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; import org.transdroid.core.gui.remoterss.data.RemoteRssChannel;
import org.transdroid.core.gui.remoterss.data.RemoteRssSupplier;
import org.transdroid.daemon.Daemon; import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.DaemonException; import org.transdroid.daemon.DaemonException;
import org.transdroid.daemon.DaemonException.ExceptionType; import org.transdroid.daemon.DaemonException.ExceptionType;
@ -81,7 +82,7 @@ import java.util.List;
* HTTP GET requests and responses. * HTTP GET requests and responses.
* @author erickok * @author erickok
*/ */
public class UtorrentAdapter implements IDaemonAdapter { public class UtorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
private static final String LOG_NAME = "uTorrent daemon"; private static final String LOG_NAME = "uTorrent daemon";
private static final String RPC_URL_HASH = "&hash="; private static final String RPC_URL_HASH = "&hash=";
@ -332,6 +333,8 @@ public class UtorrentAdapter implements IDaemonAdapter {
item = new UTorrentRemoteRssChannel(results.getJSONArray(i)); item = new UTorrentRemoteRssChannel(results.getJSONArray(i));
remoteRssChannels.add(item); remoteRssChannels.add(item);
} catch (JSONException e) { } catch (JSONException e) {
// Ignore unparseable items so app doesn't crash.
// Haven't run into a case where this fails, yet.
e.printStackTrace(); e.printStackTrace();
} }
} }

12
app/src/main/res/layout/activity_remoterss.xml

@ -74,18 +74,6 @@
android:divider="@null" android:divider="@null"
tools:listitem="@layout/list_item_filter" /> tools:listitem="@layout/list_item_filter" />
<!--<android.support.v7.widget.SearchView-->
<!--android:id="@+id/filter_search"-->
<!--android:layout_width="@dimen/ui_filters_list"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_marginBottom="5dp"-->
<!--android:layout_marginEnd="5dp"-->
<!--android:layout_marginRight="10dp"-->
<!--android:layout_marginTop="5dp"-->
<!--app:iconifiedByDefault="false"-->
<!--app:queryHint="@string/action_filter"-->
<!--app:searchIcon="@drawable/ic_action_filter" />-->
</LinearLayout> </LinearLayout>
</android.support.v4.widget.DrawerLayout> </android.support.v4.widget.DrawerLayout>

7
app/src/main/res/layout/fragment_remoterss.xml

@ -20,6 +20,13 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/remoterss_no_files"
android:gravity="center"
android:id="@+id/remoterss_no_files_message"/>
<ListView <ListView
android:id="@+id/torrents_list" android:id="@+id/torrents_list"
android:layout_width="match_parent" android:layout_width="match_parent"

5
app/src/main/res/values/strings.xml

@ -210,7 +210,10 @@
<item quantity="other">%1$s new RSS feed torrents</item> <item quantity="other">%1$s new RSS feed torrents</item>
</plurals> </plurals>
<string name="rss_service_newfor">New torrents for %1$s</string> <string name="rss_service_newfor">New torrents for %1$s</string>
<string name="remoterss_filter_allrecent">(All recent)</string>
<string name="remoterss_no_files">No torrent files found.\n\nAre your RSS feeds configured correctly?</string>
<string name="widget_loading">Loading&#8230;</string> <string name="widget_loading">Loading&#8230;</string>
<string name="widget_opentransdroid">Open Transdroid</string> <string name="widget_opentransdroid">Open Transdroid</string>
<string name="widget_filter">SERVER VIEW</string> <string name="widget_filter">SERVER VIEW</string>

Loading…
Cancel
Save