From a20f9156f250792b12da186896831c0075616e3e Mon Sep 17 00:00:00 2001 From: twig Date: Tue, 31 May 2016 23:00:59 +1000 Subject: [PATCH] - added remoterss/RemoteRssActivity.java - added test menu to access it - now parses uTorrent server RSS feeds/items --- app/src/main/AndroidManifest.xml | 6 +- .../transdroid/core/gui/TorrentsActivity.java | 15 + .../core/gui/remoterss/RemoteRssActivity.java | 317 ++++++++++++++++++ .../gui/remoterss/RemoteRssFilesAdapter.java | 57 ++++ .../core/gui/remoterss/RemoteRssFragment.java | 138 ++++++++ .../core/gui/remoterss/RemoteRssItemView.java | 50 +++ .../daemon/Utorrent/UtorrentAdapter.java | 27 ++ .../daemon/Utorrent/data/RemoteRssFile.java | 69 ++++ .../daemon/Utorrent/data/UTorrentRssFeed.java | 169 ++++++++++ .../main/res/layout/activity_remoterss.xml | 124 +++++++ .../main/res/layout/fragment_remoterss.xml | 40 +++ .../res/layout/list_item_remoterssitem.xml | 58 ++++ .../main/res/menu/activity_torrents_main.xml | 5 + 13 files changed, 1074 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java create mode 100644 app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFilesAdapter.java create mode 100644 app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java create mode 100644 app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemView.java create mode 100644 app/src/main/java/org/transdroid/daemon/Utorrent/data/RemoteRssFile.java create mode 100644 app/src/main/java/org/transdroid/daemon/Utorrent/data/UTorrentRssFeed.java create mode 100644 app/src/main/res/layout/activity_remoterss.xml create mode 100644 app/src/main/res/layout/fragment_remoterss.xml create mode 100644 app/src/main/res/layout/list_item_remoterssitem.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7b88f377..7c79a686 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -239,6 +239,10 @@ android:name="org.transdroid.core.gui.rss.RssitemsActivity_" android:label="@string/rss_feeds" android:theme="@style/TransdroidTheme" /> + @@ -293,4 +297,4 @@ - \ No newline at end of file + diff --git a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java index 7192c34c..310f5cbf 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -83,6 +83,7 @@ import org.transdroid.core.gui.navigation.NavigationFilter; import org.transdroid.core.gui.navigation.NavigationHelper; 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.rss.RssfeedsActivity_; import org.transdroid.core.gui.search.BarcodeHelper; import org.transdroid.core.gui.search.FilePickerHelper; @@ -99,6 +100,8 @@ 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.Utorrent.data.UTorrentRssFeed; import org.transdroid.daemon.task.AddByFileTask; import org.transdroid.daemon.task.AddByMagnetUrlTask; import org.transdroid.daemon.task.AddByUrlTask; @@ -847,6 +850,18 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE MainSettingsActivity_.intent(this).start(); } + @OptionsItem(R.id.action_testing) + protected void openTesting() { + if (currentConnection instanceof UtorrentAdapter) { + ArrayList rssFeedItems = ((UtorrentAdapter) (currentConnection)).getRemoteRssFeeds(); + + RemoteRssActivity_.intent(this) + .feeds(rssFeedItems) + .start() + ; + } + } + @OptionsItem(R.id.action_help) protected void openHelp() { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.transdroid.org/download/"))); diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java new file mode 100644 index 00000000..ca2056b9 --- /dev/null +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssActivity.java @@ -0,0 +1,317 @@ +/* + * Copyright 2010-2013 Eric Kok et al. + * + * Transdroid is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Transdroid is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Transdroid. If not, see . + */ +package org.transdroid.core.gui.remoterss; + +import android.annotation.TargetApi; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; + +import org.androidannotations.annotations.AfterViews; +import org.androidannotations.annotations.EActivity; +import org.androidannotations.annotations.Extra; +import org.androidannotations.annotations.FragmentById; +import org.androidannotations.annotations.InstanceState; +import org.androidannotations.annotations.OptionsItem; +import org.androidannotations.annotations.OptionsMenu; +import org.androidannotations.annotations.ViewById; +import org.transdroid.R; +import org.transdroid.core.app.settings.SystemSettings_; +import org.transdroid.core.gui.TorrentsActivity; +import org.transdroid.core.gui.TorrentsActivity_; +import org.transdroid.daemon.Utorrent.data.UTorrentRssFeed; + +import java.util.ArrayList; + +/** + * 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 + */ +@EActivity(R.layout.activity_remoterss) +@OptionsMenu(R.menu.activity_details) +public class RemoteRssActivity extends AppCompatActivity { + @Extra + @InstanceState + protected ArrayList feeds; + + // Settings +// private IDaemonAdapter currentConnection = null; + + // Details view components + @ViewById + protected Toolbar torrentsToolbar; + + @FragmentById(R.id.remoterss_fragment) + protected RemoteRssFragment fragmentRemoteRss; + + @Override + public void onCreate(Bundle savedInstanceState) { + // Set the theme according to the user preference + if (SystemSettings_.getInstance_(this).useDarkTheme()) { + setTheme(R.style.TransdroidTheme_Dark); + } + super.onCreate(savedInstanceState); + } + + @AfterViews + protected void init() { + + // We require feeds to be specified; otherwise close the activity + if (feeds == null) { + finish(); + return; + } + + // Simple action bar with up, torrent name as title and refresh button + setSupportActionBar(torrentsToolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); +// getSupportActionBar().setTitle(NavigationHelper.buildCondensedFontString(torrent.getName())); + +// // Connect to the last used server +// ServerSetting lastUsed = applicationSettings.getLastUsedServer(); +// fragmentDetails.setCurrentServerSettings(lastUsed); +// currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); + +// // Show details and load fine stats and torrent files +// fragmentDetails.updateTorrent(torrent); +// fragmentDetails.updateLabels(currentLabels); + + // TODO: show all items + fragmentRemoteRss.updateTorrentFiles(feeds.get(0).files); + } + + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + @OptionsItem(android.R.id.home) + protected void navigateUp() { + TorrentsActivity_.intent(this) + .flags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + .start(); + } + +// @OptionsItem(R.id.action_refresh) +// public void refreshScreen() { +// fragmentRemoteRss.updateIsLoading(true, null); +// refreshTorrent(); +// refreshTorrentDetails(torrent); +// refreshTorrentFiles(torrent); +// } + +// @Background +// protected void refreshTorrent() { +// DaemonTaskResult result = RetrieveTask.create(currentConnection).execute(log); +// if (result instanceof RetrieveTaskSuccessResult) { +// onTorrentsRetrieved(((RetrieveTaskSuccessResult) result).getTorrents(), ((RetrieveTaskSuccessResult) result).getLabels()); +// } else { +// onCommunicationError((DaemonTaskFailureResult) result, true); +// } +// } +// +// @Background +// public void refreshTorrentDetails(Torrent torrent) { +// if (!Daemon.supportsFineDetails(torrent.getDaemon())) { +// return; +// } +// DaemonTaskResult result = GetTorrentDetailsTask.create(currentConnection, torrent).execute(log); +// if (result instanceof GetTorrentDetailsTaskSuccessResult) { +// onTorrentDetailsRetrieved(torrent, ((GetTorrentDetailsTaskSuccessResult) result).getTorrentDetails()); +// } else { +// onCommunicationError((DaemonTaskFailureResult) result, false); +// } +// } +// +// @Background +// public void refreshTorrentFiles(Torrent torrent) { +// if (!Daemon.supportsFileListing(torrent.getDaemon())) { +// return; +// } +// DaemonTaskResult result = GetFileListTask.create(currentConnection, torrent).execute(log); +// if (result instanceof GetFileListTaskSuccessResult) { +// onTorrentFilesRetrieved(torrent, ((GetFileListTaskSuccessResult) result).getFiles()); +// } else { +// onCommunicationError((DaemonTaskFailureResult) result, false); +// } +// } +// +// @Background +// @Override +// public void resumeTorrent(Torrent torrent) { +// torrent.mimicResume(); +// DaemonTaskResult result = ResumeTask.create(currentConnection, torrent).execute(log); +// if (result instanceof DaemonTaskSuccessResult) { +// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_resumed, torrent.getName())); +// } else { +// onCommunicationError((DaemonTaskFailureResult) result, false); +// } +// } +// +// @Background +// @Override +// public void pauseTorrent(Torrent torrent) { +// torrent.mimicPause(); +// DaemonTaskResult result = PauseTask.create(currentConnection, torrent).execute(log); +// if (result instanceof DaemonTaskSuccessResult) { +// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_paused, torrent.getName())); +// } else { +// onCommunicationError((DaemonTaskFailureResult) result, false); +// } +// } +// +// @Background +// @Override +// public void startTorrent(Torrent torrent, boolean forced) { +// torrent.mimicStart(); +// DaemonTaskResult result = StartTask.create(currentConnection, torrent, forced).execute(log); +// if (result instanceof DaemonTaskSuccessResult) { +// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_started, torrent.getName())); +// } else { +// onCommunicationError((DaemonTaskFailureResult) result, false); +// } +// } +// +// @Background +// @Override +// public void stopTorrent(Torrent torrent) { +// torrent.mimicStop(); +// DaemonTaskResult result = StopTask.create(currentConnection, torrent).execute(log); +// if (result instanceof DaemonTaskSuccessResult) { +// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_stopped, torrent.getName())); +// } else { +// onCommunicationError((DaemonTaskFailureResult) result, false); +// } +// } +// +// @Background +// @Override +// public void removeTorrent(Torrent torrent, boolean withData) { +// DaemonTaskResult result = RemoveTask.create(currentConnection, torrent, withData).execute(log); +// if (result instanceof DaemonTaskSuccessResult) { +// // Close the details activity (as the torrent is now removed) +// closeActivity(getString(withData ? R.string.result_removed_with_data : R.string.result_removed, torrent.getName())); +// } else { +// onCommunicationError((DaemonTaskFailureResult) result, false); +// } +// } +// +// @UiThread +// protected void closeActivity(String closeText) { +// setResult(RESULT_OK, new Intent().putExtra("torrent_removed", true).putExtra("affected_torrent", torrent)); +// finish(); +// if (closeText != null) { +// SnackbarManager.show(Snackbar.with(this).text(closeText)); +// } +// } +// +// @Background +// @Override +// public void updateLabel(Torrent torrent, String newLabel) { +// torrent.mimicNewLabel(newLabel); +// DaemonTaskResult result = SetLabelTask.create(currentConnection, torrent, newLabel == null ? "" : newLabel).execute(log); +// if (result instanceof DaemonTaskSuccessResult) { +// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_labelset, newLabel)); +// } else { +// onCommunicationError((DaemonTaskFailureResult) result, false); +// } +// } +// +// @Background +// @Override +// public void forceRecheckTorrent(Torrent torrent) { +// torrent.mimicCheckingStatus(); +// DaemonTaskResult result = ForceRecheckTask.create(currentConnection, torrent).execute(log); +// if (result instanceof DaemonTaskSuccessResult) { +// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_recheckedstarted, torrent.getName())); +// } else { +// onCommunicationError((DaemonTaskFailureResult) result, false); +// } +// } +// +// @Background +// @Override +// public void updateTrackers(Torrent torrent, List newTrackers) { +// DaemonTaskResult result = SetTrackersTask.create(currentConnection, torrent, newTrackers).execute(log); +// if (result instanceof DaemonTaskSuccessResult) { +// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_trackersupdated)); +// } else { +// onCommunicationError((DaemonTaskFailureResult) result, false); +// } +// } +// +// @Background +// @Override +// public void updateLocation(Torrent torrent, String newLocation) { +// DaemonTaskResult result = SetDownloadLocationTask.create(currentConnection, torrent, newLocation).execute(log); +// if (result instanceof DaemonTaskSuccessResult) { +// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_locationset, newLocation)); +// } else { +// onCommunicationError((DaemonTaskFailureResult) result, false); +// } +// } +// +// @Background +// @Override +// public void updatePriority(Torrent torrent, List files, Priority priority) { +// DaemonTaskResult result = SetFilePriorityTask.create(currentConnection, torrent, priority, new ArrayList<>(files)).execute(log); +// if (result instanceof DaemonTaskSuccessResult) { +// onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_priotitiesset)); +// } else { +// onCommunicationError((DaemonTaskFailureResult) result, false); +// } +// } +// +// @UiThread +// protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) { +// // Set the activity result so the calling activity knows it needs to update its view +// setResult(RESULT_OK, new Intent().putExtra("torrent_updated", true).putExtra("affected_torrent", torrent)); +// // Refresh the screen as well +// refreshTorrent(); +// refreshTorrentDetails(torrent); +// SnackbarManager.show(Snackbar.with(this).text(successMessage)); +// } +// +// @UiThread +// protected void onTorrentDetailsRetrieved(Torrent torrent, TorrentDetails torrentDetails) { +// // Update the details fragment with the new fine details for the shown torrent +// fragmentDetails.updateTorrentDetails(torrent, torrentDetails); +// } +// +// @UiThread +// protected void onTorrentFilesRetrieved(Torrent torrent, List torrentFiles) { +// // Update the details fragment with the newly retrieved list of files +// fragmentDetails.updateTorrentFiles(torrent, new ArrayList<>(torrentFiles)); +// } +// +// @UiThread +// protected void onCommunicationError(DaemonTaskFailureResult result, boolean isCritical) { +// log.i(this, result.getException().toString()); +// String error = getString(LocalTorrent.getResourceForDaemonException(result.getException())); +// fragmentDetails.updateIsLoading(false, isCritical ? error : null); +// SnackbarManager.show(Snackbar.with(this).text(getString(LocalTorrent.getResourceForDaemonException(result.getException()))) +// .colorResource(R.color.red)); +// } +// +// @UiThread +// protected void onTorrentsRetrieved(List torrents, List labels) { +// // Update the details fragment accordingly +// fragmentDetails.updateIsLoading(false, null); +// fragmentDetails.perhapsUpdateTorrent(torrents); +// fragmentDetails.updateLabels(Label.convertToNavigationLabels(labels, getResources().getString(R.string.labels_unlabeled))); +// } +} diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFilesAdapter.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFilesAdapter.java new file mode 100644 index 00000000..97ae6a9b --- /dev/null +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFilesAdapter.java @@ -0,0 +1,57 @@ +package org.transdroid.core.gui.remoterss; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; + +import org.transdroid.daemon.Utorrent.data.RemoteRssFile; + +import java.util.ArrayList; +import java.util.List; + +public class RemoteRssFilesAdapter extends BaseAdapter { + protected Context context; + protected List files; + + public RemoteRssFilesAdapter(Context context) { + this.context = context; + files = new ArrayList<>(); + } + + @Override + public int getCount() { + return files.size(); + } + + @Override + public Object getItem(int position) { + return files.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + RemoteRssItemView itemView; + + if (convertView == null) { + itemView = RemoteRssItemView_.build(context); + } + else { + itemView = (RemoteRssItemView) convertView; + } + + itemView.bind((RemoteRssFile) getItem(position)); + + return itemView; + } + + public void updateFiles(List torrentFiles) { + files = torrentFiles; + notifyDataSetChanged(); + } +} diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java new file mode 100644 index 00000000..f35552ff --- /dev/null +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssFragment.java @@ -0,0 +1,138 @@ +/* + * Copyright 2010-2013 Eric Kok et al. + * + * Transdroid is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Transdroid is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Transdroid. If not, see . + */ +package org.transdroid.core.gui.remoterss; + + +import android.app.Fragment; +import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.widget.ActionMenuView; +import android.view.View; +import android.widget.ListView; + +import org.androidannotations.annotations.AfterViews; +import org.androidannotations.annotations.EFragment; +import org.androidannotations.annotations.InstanceState; +import org.androidannotations.annotations.ItemClick; +import org.androidannotations.annotations.ViewById; +import org.transdroid.R; +import org.transdroid.daemon.Utorrent.data.RemoteRssFile; + +import java.util.ArrayList; +import java.util.List; + +/** + * Fragment that shows detailed statistics about some torrent. These come from some already fetched {@link Torrent} object, but it also retrieves + * further detailed statistics. The actual execution of tasks is performed by the activity that contains this fragment, as per the {@link + * TorrentTasksExecutor} interface. + * @author Eric Kok + */ +@EFragment(R.layout.fragment_remoterss) +public class RemoteRssFragment extends Fragment { + + // Local data + @InstanceState + protected ArrayList torrentFiles; + + // Views + @ViewById + protected View detailsContainer; + @ViewById(R.id.contextual_menu) + protected ActionMenuView contextualMenu; + @ViewById + protected SwipeRefreshLayout swipeRefreshLayout; + @ViewById + protected ListView torrentsList; + + protected RemoteRssFilesAdapter adapter; + + @AfterViews + protected void init() { + + // Inject menu options in the actions toolbar + setHasOptionsMenu(true); + +// // On large screens where this fragment is shown next to the torrents list, we show a continues grey vertical +// // line to separate the lists visually +// if (!NavigationHelper_.getInstance_(getActivity()).isSmallScreen()) { +// if (SystemSettings_.getInstance_(getActivity()).useDarkTheme()) { +// detailsContainer.setBackgroundResource(R.drawable.details_list_background_dark); +// } else { +// detailsContainer.setBackgroundResource(R.drawable.details_list_background_light); +// } +// } + +// if (getActivity() != null && getActivity() instanceof RefreshableActivity) { +// swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { +// @Override +// public void onRefresh() { +// ((RefreshableActivity) getActivity()).refreshScreen(); +// swipeRefreshLayout.setRefreshing(false); // Use our custom indicator +// } +// }); +// } + + // Set up details adapter (itself containing the actual lists to show), which allows multi-select and fast + // scrolling + adapter = new RemoteRssFilesAdapter(getActivity()); + torrentsList.setAdapter(adapter); + torrentsList.setFastScrollEnabled(true); + + // Restore the fragment state (on orientation changes et al.) + if (torrentFiles != null) { + updateTorrentFiles(torrentFiles); + } + } + + /** + * Updates the list adapter to show a new list of torrent files, replacing the old files list. + * @param checkTorrent The torrent for which the details were retrieved + * @param newTorrentFiles The new, updated list of torrent file objects + */ + public void updateTorrentFiles(List remoteRssFiles) { + torrentFiles = new ArrayList<>(remoteRssFiles); + adapter.updateFiles(torrentFiles); + } + + @ItemClick(resName = "torrents_list") + protected void detailsListClicked(int position) { + torrentsList.setItemChecked(position, false); + } + +// @Override +// public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { +// super.onCreateOptionsMenu(menu, inflater); +// +// inflater.inflate(R.menu.fragment_details, menu); +// } +// +// @Override +// public boolean onOptionsItemSelected(MenuItem item) { +// switch (item.getItemId()) { +// case R.id.action_start_default: +//// startTorrentDefault(); +// return true; +// } +// +// return super.onOptionsItemSelected(item); +// } + +// @OptionsItem(R.id.action_start_default) +// protected void startTorrentDefault() { +// if (getTasksExecutor() != null) +// getTasksExecutor().startTorrent(torrent, false); +// } +} diff --git a/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemView.java b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemView.java new file mode 100644 index 00000000..e7701472 --- /dev/null +++ b/app/src/main/java/org/transdroid/core/gui/remoterss/RemoteRssItemView.java @@ -0,0 +1,50 @@ +/* + * Copyright 2010-2013 Eric Kok et al. + * + * Transdroid is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Transdroid is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Transdroid. If not, see . + */ +package org.transdroid.core.gui.remoterss; + +import android.content.Context; +import android.widget.LinearLayout; +import android.widget.TextView; + +import org.androidannotations.annotations.EViewGroup; +import org.androidannotations.annotations.ViewById; +import org.transdroid.R; +import org.transdroid.core.app.settings.RssfeedSetting; +import org.transdroid.daemon.Utorrent.data.RemoteRssFile; + +/** + * View that represents some {@link RssfeedSetting} object and displays name as well as loads a favicon for the feed's site and can load how many new + * items are available. + * @author Eric Kok + */ +@EViewGroup(R.layout.list_item_remoterssitem) +public class RemoteRssItemView extends LinearLayout { + // Views + @ViewById + protected TextView nameText, dateText, labelText; + + public RemoteRssItemView(Context context) { + super(context); + } + + public void bind(RemoteRssFile file) { + nameText.setText(file.getName()); + dateText.setText(String.valueOf(file.timestamp)); + labelText.setText(file.feedLabel); + } + +} diff --git a/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java b/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java index 342cf5d1..cbf0aea8 100644 --- a/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java +++ b/app/src/main/java/org/transdroid/daemon/Utorrent/UtorrentAdapter.java @@ -40,6 +40,7 @@ import org.transdroid.daemon.Torrent; import org.transdroid.daemon.TorrentDetails; import org.transdroid.daemon.TorrentFile; import org.transdroid.daemon.TorrentStatus; +import org.transdroid.daemon.Utorrent.data.UTorrentRssFeed; import org.transdroid.daemon.task.AddByFileTask; import org.transdroid.daemon.task.AddByMagnetUrlTask; import org.transdroid.daemon.task.AddByUrlTask; @@ -113,6 +114,10 @@ public class UtorrentAdapter implements IDaemonAdapter { private DaemonSettings settings; private DefaultHttpClient httpclient; + private static ArrayList rssFeedItems; + + + /** * Initialises an adapter that provides operations to the uTorrent web daemon */ @@ -129,6 +134,11 @@ public class UtorrentAdapter implements IDaemonAdapter { // Request all torrents from server JSONObject result = makeUtorrentRequest(log, "&list=1"); + + if (result.has("rssfeeds")) { + parseJsonRemoteRssLists(result.getJSONArray("rssfeeds")); + } + return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONArray("torrents")), parseJsonRetrieveGetLabels(result.getJSONArray("label"))); @@ -310,6 +320,20 @@ public class UtorrentAdapter implements IDaemonAdapter { } } + private void parseJsonRemoteRssLists(JSONArray results) { + rssFeedItems = new ArrayList<>(); + UTorrentRssFeed item; + + for (int i = 0; i < results.length(); i++) { + try { + item = new UTorrentRssFeed(results.getJSONArray(i)); + rssFeedItems.add(item); + } catch (JSONException e) { + e.printStackTrace(); + } + } + } + private ArrayList