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

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

@ -39,7 +39,6 @@ import org.transdroid.R; @@ -39,7 +39,6 @@ import org.transdroid.R;
import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.app.settings.ServerSetting;
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.remoterss.data.RemoteRssChannel;
import org.transdroid.core.gui.remoterss.data.RemoteRssItem;
@ -54,10 +53,12 @@ import java.util.Date; @@ -54,10 +53,12 @@ import java.util.Date;
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
* TorrentsActivity} directly. Task execution, such as loading of more details and updating file priorities, is performed in this activity via
* background methods.
* @author Eric Kok
* An activity that displays a list of {@link RemoteRssItem}s via an instance of {@link RemoteRssFragment}.
* The activity manages the drawer to filter items by the feed they came through.
*
* By default it displays the latest items within the last month.
*
* @author Twig Nguyen
*/
@EActivity(R.layout.activity_remoterss)
public class RemoteRssActivity extends AppCompatActivity {
@ -104,8 +105,7 @@ public class RemoteRssActivity extends AppCompatActivity { @@ -104,8 +105,7 @@ public class RemoteRssActivity extends AppCompatActivity {
// We require feeds to be specified; otherwise close the activity
if (feeds == null) {
finish();
return;
feeds = new ArrayList<>();
}
// Simple action bar with up, torrent name as title and refresh button
@ -168,7 +168,7 @@ public class RemoteRssActivity extends AppCompatActivity { @@ -168,7 +168,7 @@ public class RemoteRssActivity extends AppCompatActivity {
});
}
fragmentRemoteRss.updateTorrentFiles(recentItems);
fragmentRemoteRss.updateRemoteItems(recentItems);
RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(0);
getSupportActionBar().setSubtitle(channel.getName());
}
@ -178,7 +178,7 @@ public class RemoteRssActivity extends AppCompatActivity { @@ -178,7 +178,7 @@ public class RemoteRssActivity extends AppCompatActivity {
feedLabels.add(new RemoteRssChannel() {
@Override
public String getName() {
return "(All recent)";
return getString(R.string.remoterss_filter_allrecent);
}
@Override
@ -196,7 +196,7 @@ public class RemoteRssActivity extends AppCompatActivity { @@ -196,7 +196,7 @@ public class RemoteRssActivity extends AppCompatActivity {
showRecentItems();
}
else {
fragmentRemoteRss.updateTorrentFiles(feeds.get(position -1).getItems());
fragmentRemoteRss.updateRemoteItems(feeds.get(position -1).getItems());
}
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; @@ -22,6 +22,7 @@ import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.ActionMenuView;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager;
@ -62,7 +63,7 @@ public class RemoteRssFragment extends Fragment { @@ -62,7 +63,7 @@ public class RemoteRssFragment extends Fragment {
// Local data
@InstanceState
protected ArrayList<RemoteRssItem> torrentFiles;
protected ArrayList<RemoteRssItem> remoteRssItems;
// Views
@ViewById
@ -73,8 +74,10 @@ public class RemoteRssFragment extends Fragment { @@ -73,8 +74,10 @@ public class RemoteRssFragment extends Fragment {
protected SwipeRefreshLayout swipeRefreshLayout;
@ViewById
protected ListView torrentsList;
@ViewById
protected TextView remoterssNoFilesMessage;
protected RemoteRssFilesAdapter adapter;
protected RemoteRssItemsAdapter adapter;
@AfterViews
protected void init() {
@ -93,23 +96,26 @@ public class RemoteRssFragment extends Fragment { @@ -93,23 +96,26 @@ public class RemoteRssFragment extends Fragment {
// }
// Set up details adapter
adapter = new RemoteRssFilesAdapter(getActivity());
adapter = new RemoteRssItemsAdapter(getActivity());
torrentsList.setAdapter(adapter);
torrentsList.setFastScrollEnabled(true);
// Restore the fragment state (on orientation changes et al.)
if (torrentFiles != null) {
updateTorrentFiles(torrentFiles);
if (remoteRssItems != null) {
updateRemoteItems(remoteRssItems);
}
}
/**
* Updates the list adapter to show a new list of torrent files, replacing the old files list.
*/
public void updateTorrentFiles(List<RemoteRssItem> remoteRssFiles) {
torrentFiles = new ArrayList<>(remoteRssFiles);
adapter.updateFiles(torrentFiles);
public void updateRemoteItems(List<RemoteRssItem> remoteItems) {
remoteRssItems = new ArrayList<>(remoteItems);
adapter.updateItems(remoteRssItems);
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; @@ -10,11 +10,11 @@ import org.transdroid.core.gui.remoterss.data.RemoteRssItem;
import java.util.ArrayList;
import java.util.List;
public class RemoteRssFilesAdapter extends BaseAdapter {
public class RemoteRssItemsAdapter extends BaseAdapter {
protected Context context;
protected List<RemoteRssItem> items;
public RemoteRssFilesAdapter(Context context) {
public RemoteRssItemsAdapter(Context context) {
this.context = context;
items = new ArrayList<>();
}
@ -50,8 +50,8 @@ public class RemoteRssFilesAdapter extends BaseAdapter { @@ -50,8 +50,8 @@ public class RemoteRssFilesAdapter extends BaseAdapter {
return itemView;
}
public void updateFiles(List<RemoteRssItem> torrentFiles) {
items = torrentFiles;
public void updateItems(List<RemoteRssItem> remoteItems) {
items = remoteItems;
notifyDataSetChanged();
}
}

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

@ -0,0 +1,12 @@ @@ -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; @@ -30,6 +30,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.transdroid.core.gui.log.Log;
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.DaemonException;
import org.transdroid.daemon.DaemonException.ExceptionType;
@ -81,7 +82,7 @@ import java.util.List; @@ -81,7 +82,7 @@ import java.util.List;
* HTTP GET requests and responses.
* @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 RPC_URL_HASH = "&hash=";
@ -332,6 +333,8 @@ public class UtorrentAdapter implements IDaemonAdapter { @@ -332,6 +333,8 @@ public class UtorrentAdapter implements IDaemonAdapter {
item = new UTorrentRemoteRssChannel(results.getJSONArray(i));
remoteRssChannels.add(item);
} catch (JSONException e) {
// Ignore unparseable items so app doesn't crash.
// Haven't run into a case where this fails, yet.
e.printStackTrace();
}
}

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

@ -74,18 +74,6 @@ @@ -74,18 +74,6 @@
android:divider="@null"
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>
</android.support.v4.widget.DrawerLayout>

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

@ -20,6 +20,13 @@ @@ -20,6 +20,13 @@
android:layout_width="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
android:id="@+id/torrents_list"
android:layout_width="match_parent"

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

@ -210,7 +210,10 @@ @@ -210,7 +210,10 @@
<item quantity="other">%1$s new RSS feed torrents</item>
</plurals>
<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_opentransdroid">Open Transdroid</string>
<string name="widget_filter">SERVER VIEW</string>

Loading…
Cancel
Save