Browse Source

Correct loading of RSS feeds UI and allow multi-select of items.

pull/11/head
Eric Kok 11 years ago
parent
commit
c6a4621979
  1. 4
      core/res/layout-w900dp/activity_rssfeeds.xml
  2. 2
      core/res/layout/activity_rssfeeds.xml
  3. 2
      core/res/layout/activity_rssitems.xml
  4. 2
      core/res/layout/fragment_rssfeeds.xml
  5. 9
      core/res/menu/fragment_rssitems_cab.xml
  6. 6
      core/res/values/strings.xml
  7. 3
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  8. 36
      core/src/org/transdroid/core/gui/rss/RssfeedsActivity.java
  9. 37
      core/src/org/transdroid/core/gui/rss/RssfeedsFragment.java
  10. 41
      core/src/org/transdroid/core/gui/rss/RssitemsActivity.java
  11. 82
      core/src/org/transdroid/core/gui/rss/RssitemsFragment.java
  12. 23
      core/src/org/transdroid/core/rssparser/Item.java
  13. 21
      full/AndroidManifest.xml

4
core/res/layout-w900dp/activity_rssfeeds.xml

@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
class="org.transdroid.core.gui.rss.RssFeedsFragment_"
class="org.transdroid.core.gui.rss.RssfeedsFragment_"
tools:layout="@layout/fragment_rssfeeds" />
<fragment
@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
class="org.transdroid.core.gui.rss.RssItemsFragment_"
class="org.transdroid.core.gui.rss.RssitemsFragment_"
tools:layout="@layout/fragment_rssitems" />
</LinearLayout>

2
core/res/layout/activity_rssfeeds.xml

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
android:id="@+id/rssfeeds_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="org.transdroid.core.gui.rss.RssFeedsFragment_"
class="org.transdroid.core.gui.rss.RssfeedsFragment_"
tools:layout="@layout/fragment_rssfeeds" />
</FrameLayout>

2
core/res/layout/activity_rssitems.xml

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
android:id="@+id/rssfitems_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="org.transdroid.core.gui.rss.RssItemsFragment_"
class="org.transdroid.core.gui.rss.RssitemsFragment_"
tools:layout="@layout/fragment_rssitems" />
</FrameLayout>

2
core/res/layout/fragment_rssfeeds.xml

@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
android:gravity="center"
android:maxWidth="400dip"
android:padding="@dimen/margin_default"
android:text="@string/navigation_nosettings"
android:text="@string/rss_nosettings"
android:textIsSelectable="false"
android:visibility="gone" />

9
core/res/menu/fragment_rssitems_cab.xml

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_addall"
android:icon="?attr/ic_action_new"
android:showAsAction="always"
android:title="@string/action_addall" />
</menu>

6
core/res/values/strings.xml

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
<resources>
<string name="action_add">Add</string>
<string name="action_addall">Add all</string>
<string name="action_addfromfile">From file</string>
<string name="action_addfromurl">From URL</string>
<string name="action_scanbarcode">Scan barcode</string>
@ -118,8 +119,13 @@ @@ -118,8 +119,13 @@
<string name="search_barcodescannernotfound">The Barcode Scanner could not be found. Would you like to install it from the Play Store?</string>
<string name="search_filemanagernotfound">No compatible file manager could not be found. Would you like to install IO File Manager from the Play Store?</string>
<string name="rss_feeds">RSS feeds</string>
<string name="rss_nosettings">You have not defined any RSS feeds yet to monitor. Torrent-specific RSS feeds keep you up to date with new releases and you are notified of new items.</string>
<string name="rss_empty">The RSS feed is not available or it contains no items</string>
<plurals name="rss_itemsselected">
<item quantity="one">%1$d item selected</item>
<item quantity="other">%1$d items selected</item>
</plurals>
<string name="pref_servers">Servers</string>
<string name="pref_addserver">Add new server</string>

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

@ -25,7 +25,7 @@ import org.transdroid.core.gui.lists.LocalTorrent; @@ -25,7 +25,7 @@ import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.log.*;
import org.transdroid.core.gui.navigation.*;
import org.transdroid.core.gui.rss.RssfeedsActivity_;
import org.transdroid.core.gui.rss.*;
import org.transdroid.core.gui.search.BarcodeHelper;
import org.transdroid.core.gui.search.FilePickerHelper;
import org.transdroid.core.gui.search.UrlEntryDialog;
@ -374,6 +374,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -374,6 +374,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
String action = intent.getAction();
// Adding multiple torrents at the same time (as found in the Intent extras Bundle)
if (action != null && action.equals("org.transdroid.ADD_MULTIPLE")) {
// Intent should have some extras pointing to possibly multiple torrents
String[] urls = intent.getStringArrayExtra("TORRENT_URLS");

36
core/src/org/transdroid/core/gui/rss/RssfeedsActivity.java

@ -6,17 +6,26 @@ import java.util.List; @@ -6,17 +6,26 @@ import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.FragmentById;
import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.UiThread;
import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.app.settings.RssfeedSetting;
import org.transdroid.core.R;
import org.transdroid.core.app.settings.*;
import org.transdroid.core.gui.*;
import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.rssparser.Channel;
import org.transdroid.core.rssparser.RssParser;
import org.xml.sax.SAXException;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
@EActivity(resName = "activity_rssfeeds")
@ -33,6 +42,23 @@ public class RssfeedsActivity extends SherlockFragmentActivity { @@ -33,6 +42,23 @@ public class RssfeedsActivity extends SherlockFragmentActivity {
@FragmentById(resName = "rssitems_list")
protected RssitemsFragment fragmentItems;
@Override
public void onCreate(Bundle savedInstanceState) {
// Set the theme according to the user preference
if (SystemSettings_.getInstance_(this).useDarkTheme()) {
setTheme(R.style.TransdroidTheme_Dark);
getSupportActionBar().setIcon(R.drawable.ic_activity_torrents);
}
super.onCreate(savedInstanceState);
}
@AfterViews
protected void init() {
// Simple action bar with up button and correct title font
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(getString(R.string.rss_feeds)));
}
@Override
protected void onResume() {
super.onResume();
@ -47,6 +73,12 @@ public class RssfeedsActivity extends SherlockFragmentActivity { @@ -47,6 +73,12 @@ public class RssfeedsActivity extends SherlockFragmentActivity {
fragmentFeeds.update(loaders);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@OptionsItem(android.R.id.home)
protected void navigateUp() {
TorrentsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start();
}
/**
* Performs the loading of the RSS feed content and parsing of items, in a background thread.
* @param loader The RSS feed loader for which to retrieve the contents

37
core/src/org/transdroid/core/gui/rss/RssfeedsFragment.java

@ -5,15 +5,19 @@ import java.util.List; @@ -5,15 +5,19 @@ import java.util.List;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ItemClick;
import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu;
import org.androidannotations.annotations.ViewById;
import org.transdroid.core.R;
import org.transdroid.core.gui.settings.MainSettingsActivity_;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.SherlockListView;
/**
@ -35,20 +39,33 @@ public class RssfeedsFragment extends SherlockFragment { @@ -35,20 +39,33 @@ public class RssfeedsFragment extends SherlockFragment {
@AfterViews
protected void init() {
feedsList.setAdapter(rssfeedsAdapter);
feedsList.setOnItemClickListener(onRssfeedSelected);
}
public void update(List<RssfeedLoader> loaders) {
rssfeedsAdapter.update(loaders);
boolean hasSettings = !(loaders == null || loaders.size() == 0);
feedsList.setVisibility(hasSettings ? View.VISIBLE: View.GONE);
nosettingsText.setVisibility(hasSettings ? View.GONE: View.VISIBLE);
getActivity().supportInvalidateOptionsMenu();
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.action_settings).setShowAsAction(
rssfeedsAdapter.getCount() == 0 ? MenuItem.SHOW_AS_ACTION_ALWAYS : MenuItem.SHOW_AS_ACTION_NEVER);
}
private OnItemClickListener onRssfeedSelected = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
((RssfeedsActivity)getActivity()).openRssfeed(rssfeedsAdapter.getItem(position));
}
};
@OptionsItem(resName = "action_settings")
protected void openSettings() {
MainSettingsActivity_.intent(getActivity()).start();
}
@ItemClick(resName = "rssfeeds_list")
protected void onFeedClicked(RssfeedLoader loader) {
((RssfeedsActivity)getActivity()).openRssfeed(loader);
}
/**
* Notifies the contained list of RSS feeds that the underlying data has been changed.
*/

41
core/src/org/transdroid/core/gui/rss/RssitemsActivity.java

@ -4,8 +4,18 @@ import org.androidannotations.annotations.AfterViews; @@ -4,8 +4,18 @@ import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.FragmentById;
import org.androidannotations.annotations.OptionsItem;
import org.transdroid.core.R;
import org.transdroid.core.app.settings.*;
import org.transdroid.core.gui.*;
import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.rssparser.Channel;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
@EActivity(resName = "activity_rssfeeds")
@ -13,14 +23,41 @@ public class RssitemsActivity extends SherlockFragmentActivity { @@ -13,14 +23,41 @@ public class RssitemsActivity extends SherlockFragmentActivity {
@Extra
protected Channel rssfeed = null;
@FragmentById(resName = "rssitems_list")
protected RssitemsFragment fragmentItems;
@Override
public void onCreate(Bundle savedInstanceState) {
// Set the theme according to the user preference
if (SystemSettings_.getInstance_(this).useDarkTheme()) {
setTheme(R.style.TransdroidTheme_Dark);
getSupportActionBar().setIcon(R.drawable.ic_activity_torrents);
}
super.onCreate(savedInstanceState);
}
@AfterViews
protected void init() {
// We require an RSS feed to be specified; otherwise close the activity
if (rssfeed == null) {
finish();
return;
}
// Simple action bar with up button and torrent name as title
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(rssfeed.getTitle()));
// Get the intent extras and show them to the already loaded fragment
fragmentItems.update(rssfeed);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@OptionsItem(android.R.id.home)
protected void navigateUp() {
TorrentsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_CLEAR_TOP).start();
}
}

82
core/src/org/transdroid/core/gui/rss/RssitemsFragment.java

@ -1,16 +1,28 @@ @@ -1,16 +1,28 @@
package org.transdroid.core.gui.rss;
import java.util.ArrayList;
import java.util.List;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.InstanceState;
import org.androidannotations.annotations.ItemClick;
import org.androidannotations.annotations.ViewById;
import org.transdroid.core.R;
import org.transdroid.core.gui.navigation.SelectionManagerMode;
import org.transdroid.core.rssparser.Channel;
import org.transdroid.core.rssparser.Item;
import android.content.Intent;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.SherlockListView;
import com.actionbarsherlock.view.SherlockListView.MultiChoiceModeListenerCompat;
/**
* Fragment that lists the items in a specific RSS feed
@ -32,8 +44,12 @@ public class RssitemsFragment extends SherlockFragment { @@ -32,8 +44,12 @@ public class RssitemsFragment extends SherlockFragment {
@AfterViews
protected void init() {
// Set up the list adapter, which allows multi-select
rssitemsList.setAdapter(rssitemsAdapter);
rssitemsList.setMultiChoiceModeListener(onItemsSelected);
update(rssfeed);
}
/**
@ -45,4 +61,70 @@ public class RssitemsFragment extends SherlockFragment { @@ -45,4 +61,70 @@ public class RssitemsFragment extends SherlockFragment {
rssitemsAdapter.update(rssfeed);
}
@ItemClick(resName = "rssitems_list")
protected void onItemClicked(Item item) {
startActivity(new Intent(Intent.ACTION_VIEW, item.getTheLinkUri()));
}
private MultiChoiceModeListenerCompat onItemsSelected = new MultiChoiceModeListenerCompat() {
SelectionManagerMode selectionManagerMode;
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// Show contextual action bar to add items in batch mode
mode.getMenuInflater().inflate(R.menu.fragment_rssitems_cab, menu);
selectionManagerMode = new SelectionManagerMode(rssitemsList, R.plurals.rss_itemsselected);
selectionManagerMode.onCreateActionMode(mode, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return selectionManagerMode.onPrepareActionMode(mode, menu);
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Get checked torrents
List<Item> checked = new ArrayList<Item>();
for (int i = 0; i < rssitemsList.getCheckedItemPositions().size(); i++) {
if (rssitemsList.getCheckedItemPositions().valueAt(i))
checked.add(rssitemsAdapter.getItem(
rssitemsList.getCheckedItemPositions().keyAt(i)));
}
int itemId = item.getItemId();
if (itemId == R.id.action_addall) {
// Start an Intent that adds multiple items at once, by supplying the urls and titles as string array
// extras and setting the Intent action to ADD_MULTIPLE
Intent intent = new Intent("org.transdroid.ADD_MULTIPLE");
String[] urls = new String[checked.size()];
String[] titles = new String[checked.size()];
for (int i = 0; i < checked.size(); i++) {
urls[i] = checked.get(0).getTheLink();
titles[i] = checked.get(0).getTitle();
}
intent.putExtra("TORRENT_URLS", urls);
intent.putExtra("TORRENT_TITLES", titles);
startActivity(intent);
mode.finish();
return true;
} else {
return false;
}
}
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
selectionManagerMode.onItemCheckedStateChanged(mode, position, id, checked);
}
@Override
public void onDestroyActionMode(ActionMode mode) {
selectionManagerMode.onDestroyActionMode(mode);
}
};
}

23
core/src/org/transdroid/core/rssparser/Item.java

@ -6,6 +6,7 @@ package org.transdroid.core.rssparser; @@ -6,6 +6,7 @@ package org.transdroid.core.rssparser;
import java.util.Date;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
@ -19,7 +20,7 @@ public class Item implements Parcelable { @@ -19,7 +20,7 @@ public class Item implements Parcelable {
private String enclosureUrl;
private String enclosureType;
private long enclosureLength;
/**
* isNew is not parsed from the RSS feed but may be set using {@link #setIsNew(boolean)} manually
*/
@ -98,9 +99,9 @@ public class Item implements Parcelable { @@ -98,9 +99,9 @@ public class Item implements Parcelable {
}
/**
* Returns 'the' item link, which preferably is the enclosure url, but otherwise the link (or null if that is empty
* too).
* @return A single link url to be used
* Returns 'the' item link as string, which preferably is the enclosure URL, but otherwise the link (or null if that
* is empty too).
* @return A single link URL string to be used
*/
public String getTheLink() {
if (this.getEnclosureUrl() != null) {
@ -110,6 +111,16 @@ public class Item implements Parcelable { @@ -110,6 +111,16 @@ public class Item implements Parcelable {
}
}
/**
* Returns 'the' item link as URI, which preferably is the enclosure URL, but otherwise the link (or null if that is
* empty too).
* @return A single link URI to be used
*/
public Uri getTheLinkUri() {
// TODO Auto-generated method stub
return null;
}
@Override
public int describeContents() {
return 0;
@ -125,7 +136,7 @@ public class Item implements Parcelable { @@ -125,7 +136,7 @@ public class Item implements Parcelable {
out.writeString(enclosureUrl);
out.writeString(enclosureType);
out.writeLong(enclosureLength);
out.writeInt(isNew? 1: 0);
out.writeInt(isNew ? 1 : 0);
}
public static final Parcelable.Creator<Item> CREATOR = new Parcelable.Creator<Item>() {
@ -151,7 +162,7 @@ public class Item implements Parcelable { @@ -151,7 +162,7 @@ public class Item implements Parcelable {
enclosureUrl = in.readString();
enclosureType = in.readString();
enclosureLength = in.readLong();
isNew = in.readInt() == 1? true: false;
isNew = in.readInt() == 1 ? true : false;
}
}

21
full/AndroidManifest.xml

@ -44,6 +44,21 @@ @@ -44,6 +44,21 @@
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/x-bittorrent" />
<data android:scheme="http" android:mimeType="application/x-bittorrent" />
<data android:scheme="http" android:pathPattern=".*\\.torrent" />
<data android:scheme="https" android:mimeType="application/x-bittorrent" />
<data android:scheme="https" android:pathPattern=".*\\.torrent" />
<data android:scheme="file" android:mimeType="application/x-bittorrent" />
<data android:scheme="file" android:pathPattern=".*\\.torrent" />
<data android:scheme="content" android:mimeType="application/x-bittorrent" />
<data android:scheme="content" android:pathPattern=".*\\.torrent" />
<data android:scheme="magnet" />
</intent-filter>
<meta-data
android:name="android.app.default_searchable"
@ -94,7 +109,11 @@ @@ -94,7 +109,11 @@
<!-- RSS -->
<activity
android:name="org.transdroid.core.gui.rss.RssfeedsActivity_"
android:label="@string/action_rss"
android:label="@string/rss_feeds"
android:theme="@style/TransdroidTheme" />
<activity
android:name="org.transdroid.core.gui.rss.RssitemsActivity_"
android:label="@string/rss_feeds"
android:theme="@style/TransdroidTheme" />
<provider

Loading…
Cancel
Save