Eric Kok
8 years ago
committed by
GitHub
20 changed files with 1009 additions and 4 deletions
@ -0,0 +1,206 @@
@@ -0,0 +1,206 @@
|
||||
/* |
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
package org.transdroid.core.gui.remoterss; |
||||
|
||||
import android.annotation.TargetApi; |
||||
import android.os.Build; |
||||
import android.os.Bundle; |
||||
import android.os.Parcel; |
||||
import android.support.v4.widget.DrawerLayout; |
||||
import android.support.v7.app.AppCompatActivity; |
||||
import android.support.v7.widget.Toolbar; |
||||
import android.widget.LinearLayout; |
||||
import android.widget.ListView; |
||||
|
||||
import org.androidannotations.annotations.AfterViews; |
||||
import org.androidannotations.annotations.Bean; |
||||
import org.androidannotations.annotations.EActivity; |
||||
import org.androidannotations.annotations.FragmentById; |
||||
import org.androidannotations.annotations.InstanceState; |
||||
import org.androidannotations.annotations.ItemClick; |
||||
import org.androidannotations.annotations.OptionsItem; |
||||
import org.androidannotations.annotations.ViewById; |
||||
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.lists.SimpleListItemAdapter; |
||||
import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; |
||||
import org.transdroid.core.gui.remoterss.data.RemoteRssItem; |
||||
import org.transdroid.core.gui.remoterss.data.RemoteRssSupplier; |
||||
import org.transdroid.core.service.ConnectivityHelper; |
||||
import org.transdroid.daemon.IDaemonAdapter; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Calendar; |
||||
import java.util.Collections; |
||||
import java.util.Comparator; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 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 { |
||||
// @Extra
|
||||
@InstanceState |
||||
protected ArrayList<RemoteRssChannel> feeds; |
||||
|
||||
@InstanceState |
||||
protected ArrayList<RemoteRssItem> recentItems; |
||||
|
||||
// Server connection
|
||||
@Bean |
||||
protected ApplicationSettings applicationSettings; |
||||
@Bean |
||||
protected ConnectivityHelper connectivityHelper; |
||||
private IDaemonAdapter currentConnection; |
||||
|
||||
// Details view components
|
||||
@ViewById |
||||
protected DrawerLayout drawerLayout; |
||||
@ViewById |
||||
protected LinearLayout drawerContainer; |
||||
|
||||
@ViewById |
||||
protected Toolbar torrentsToolbar; |
||||
|
||||
@ViewById |
||||
protected ListView drawerList; |
||||
|
||||
@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() { |
||||
// Simple action bar with up, torrent name as title and refresh button
|
||||
torrentsToolbar.setNavigationIcon(R.drawable.ic_action_drawer); |
||||
setSupportActionBar(torrentsToolbar); |
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
||||
|
||||
// Connect to the last used server
|
||||
ServerSetting lastUsed = applicationSettings.getLastUsedServer(); |
||||
currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); |
||||
feeds = ((RemoteRssSupplier) (currentConnection)).getRemoteRssChannels(); |
||||
|
||||
// Fill in the filter list
|
||||
showChannelFilters(); |
||||
|
||||
// Show all items
|
||||
showRecentItems(); |
||||
} |
||||
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB) |
||||
@OptionsItem(android.R.id.home) |
||||
protected void navigateUp() { |
||||
if (drawerLayout.isDrawerOpen(drawerContainer)) { |
||||
drawerLayout.closeDrawers(); |
||||
} else { |
||||
drawerLayout.openDrawer(drawerContainer); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onBackPressed() { |
||||
if (drawerLayout.isDrawerOpen(drawerContainer)) { |
||||
drawerLayout.closeDrawers(); |
||||
} else { |
||||
finish(); |
||||
} |
||||
} |
||||
|
||||
protected void showRecentItems() { |
||||
if (recentItems == null) { |
||||
recentItems = new ArrayList<>(); |
||||
Calendar calendar = Calendar.getInstance(); |
||||
calendar.add(Calendar.MONTH, -1); |
||||
Date oneMonthAgo = calendar.getTime(); |
||||
|
||||
for (RemoteRssChannel feed : feeds) { |
||||
for (RemoteRssItem item : feed.getItems()) { |
||||
if (item.getTimestamp().after(oneMonthAgo)) { |
||||
recentItems.add(item); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// Sort by -newest
|
||||
Collections.sort(recentItems, new Comparator<RemoteRssItem>() { |
||||
@Override |
||||
public int compare(RemoteRssItem lhs, RemoteRssItem rhs) { |
||||
return rhs.getTimestamp().compareTo(lhs.getTimestamp()); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
fragmentRemoteRss.updateRemoteItems(recentItems); |
||||
RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(0); |
||||
getSupportActionBar().setSubtitle(channel.getName()); |
||||
} |
||||
|
||||
protected void showChannelFilters() { |
||||
List<RemoteRssChannel> feedLabels = new ArrayList<>(feeds.size() +1); |
||||
feedLabels.add(new RemoteRssChannel() { |
||||
@Override |
||||
public String getName() { |
||||
return getString(R.string.remoterss_filter_allrecent); |
||||
} |
||||
|
||||
@Override |
||||
public void writeToParcel(Parcel dest, int flags) { |
||||
} |
||||
}); |
||||
feedLabels.addAll(feeds); |
||||
|
||||
drawerList.setAdapter(new SimpleListItemAdapter(this, feedLabels)); |
||||
} |
||||
|
||||
@ItemClick(R.id.drawer_list) |
||||
protected void onFeedSelected(int position) { |
||||
if (position == 0) { |
||||
showRecentItems(); |
||||
} |
||||
else { |
||||
fragmentRemoteRss.updateRemoteItems(feeds.get(position -1).getItems()); |
||||
} |
||||
|
||||
RemoteRssChannel channel = (RemoteRssChannel) drawerList.getAdapter().getItem(position); |
||||
getSupportActionBar().setSubtitle(channel.getName()); |
||||
|
||||
drawerLayout.closeDrawers(); |
||||
} |
||||
|
||||
public IDaemonAdapter getCurrentConnection() { |
||||
return currentConnection; |
||||
} |
||||
} |
@ -0,0 +1,175 @@
@@ -0,0 +1,175 @@
|
||||
/* |
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
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 android.widget.TextView; |
||||
|
||||
import com.nispok.snackbar.Snackbar; |
||||
import com.nispok.snackbar.SnackbarManager; |
||||
import com.nispok.snackbar.enums.SnackbarType; |
||||
|
||||
import org.androidannotations.annotations.AfterViews; |
||||
import org.androidannotations.annotations.Background; |
||||
import org.androidannotations.annotations.Bean; |
||||
import org.androidannotations.annotations.EFragment; |
||||
import org.androidannotations.annotations.InstanceState; |
||||
import org.androidannotations.annotations.ItemClick; |
||||
import org.androidannotations.annotations.UiThread; |
||||
import org.androidannotations.annotations.ViewById; |
||||
import org.transdroid.R; |
||||
import org.transdroid.core.gui.lists.LocalTorrent; |
||||
import org.transdroid.core.gui.log.Log; |
||||
import org.transdroid.core.gui.remoterss.data.RemoteRssItem; |
||||
import org.transdroid.daemon.Daemon; |
||||
import org.transdroid.daemon.IDaemonAdapter; |
||||
import org.transdroid.daemon.task.AddByMagnetUrlTask; |
||||
import org.transdroid.daemon.task.AddByUrlTask; |
||||
import org.transdroid.daemon.task.DaemonTaskFailureResult; |
||||
import org.transdroid.daemon.task.DaemonTaskResult; |
||||
import org.transdroid.daemon.task.DaemonTaskSuccessResult; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Fragment that shows a list of RSS items from the server and allows the user |
||||
* to download remotely, without having to set up RSS feeds on the Android device. |
||||
* @author Twig |
||||
*/ |
||||
@EFragment(R.layout.fragment_remoterss) |
||||
public class RemoteRssFragment extends Fragment { |
||||
@Bean |
||||
protected Log log; |
||||
|
||||
// Local data
|
||||
@InstanceState |
||||
protected ArrayList<RemoteRssItem> remoteRssItems; |
||||
|
||||
// Views
|
||||
@ViewById |
||||
protected View detailsContainer; |
||||
@ViewById(R.id.contextual_menu) |
||||
protected ActionMenuView contextualMenu; |
||||
@ViewById |
||||
protected SwipeRefreshLayout swipeRefreshLayout; |
||||
@ViewById |
||||
protected ListView torrentsList; |
||||
@ViewById |
||||
protected TextView remoterssNoFilesMessage; |
||||
|
||||
protected RemoteRssItemsAdapter 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);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Set up details adapter
|
||||
adapter = new RemoteRssItemsAdapter(getActivity()); |
||||
torrentsList.setAdapter(adapter); |
||||
torrentsList.setFastScrollEnabled(true); |
||||
|
||||
// Restore the fragment state (on orientation changes et al.)
|
||||
if (remoteRssItems != null) { |
||||
updateRemoteItems(remoteRssItems); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Updates the UI with a new list of RSS items. |
||||
*/ |
||||
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); |
||||
} |
||||
|
||||
/** |
||||
* When the user clicks on an item, prepare to download it. |
||||
*/ |
||||
@ItemClick(resName = "torrents_list") |
||||
protected void detailsListClicked(int position) { |
||||
RemoteRssItem item = (RemoteRssItem) adapter.getItem(position); |
||||
downloadRemoteRssItem(item); |
||||
} |
||||
|
||||
/** |
||||
* Download the item in a background thread and display success/fail accordingly. |
||||
*/ |
||||
@Background |
||||
protected void downloadRemoteRssItem(RemoteRssItem item) { |
||||
RemoteRssActivity activity = (RemoteRssActivity) getActivity(); |
||||
IDaemonAdapter currentConnection = activity.getCurrentConnection(); |
||||
DaemonTaskResult result; |
||||
|
||||
if (item.isMagnetLink()) { |
||||
// Check if it's supported
|
||||
if (!Daemon.supportsAddByMagnetUrl(currentConnection.getType())) { |
||||
onTaskFailed(getString(R.string.error_magnet_links_unsupported)); |
||||
return; |
||||
} |
||||
|
||||
AddByMagnetUrlTask addByMagnetUrlTask = AddByMagnetUrlTask.create(currentConnection, item.getLink()); |
||||
result = addByMagnetUrlTask.execute(log); |
||||
} |
||||
else { |
||||
result = AddByUrlTask.create(currentConnection, item.getLink(), item.getTitle()).execute(log); |
||||
} |
||||
|
||||
if (result instanceof DaemonTaskSuccessResult) { |
||||
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, item.getTitle())); |
||||
} else if (result instanceof DaemonTaskFailureResult){ |
||||
DaemonTaskFailureResult failure = ((DaemonTaskFailureResult) result); |
||||
String message = getString(LocalTorrent.getResourceForDaemonException(failure.getException())); |
||||
onTaskFailed(message); |
||||
} |
||||
} |
||||
|
||||
@UiThread |
||||
protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) { |
||||
SnackbarManager.show(Snackbar.with(getActivity()).text(successMessage)); |
||||
} |
||||
|
||||
@UiThread |
||||
protected void onTaskFailed(String message) { |
||||
SnackbarManager.show(Snackbar.with(getActivity()) |
||||
.text(message) |
||||
.colorResource(R.color.red) |
||||
.type(SnackbarType.MULTI_LINE) |
||||
); |
||||
} |
||||
} |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
/* |
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
package org.transdroid.core.gui.remoterss; |
||||
|
||||
import android.content.Context; |
||||
import android.text.format.DateFormat; |
||||
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.gui.remoterss.data.RemoteRssItem; |
||||
|
||||
/** |
||||
* View that represents some {@link RemoteRssItem} object. |
||||
* @author Twig |
||||
*/ |
||||
@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(RemoteRssItem item) { |
||||
labelText.setText(item.getSourceName()); |
||||
nameText.setText(item.getName()); |
||||
dateText.setText( |
||||
DateFormat.getDateFormat(getContext()).format(item.getTimestamp()) + |
||||
" " + |
||||
DateFormat.getTimeFormat(getContext()).format(item.getTimestamp()) |
||||
); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,57 @@
@@ -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.core.gui.remoterss.data.RemoteRssItem; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class RemoteRssItemsAdapter extends BaseAdapter { |
||||
protected Context context; |
||||
protected List<RemoteRssItem> items; |
||||
|
||||
public RemoteRssItemsAdapter(Context context) { |
||||
this.context = context; |
||||
items = new ArrayList<>(); |
||||
} |
||||
|
||||
@Override |
||||
public int getCount() { |
||||
return items.size(); |
||||
} |
||||
|
||||
@Override |
||||
public Object getItem(int position) { |
||||
return items.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((RemoteRssItem) getItem(position)); |
||||
|
||||
return itemView; |
||||
} |
||||
|
||||
public void updateItems(List<RemoteRssItem> remoteItems) { |
||||
items = remoteItems; |
||||
notifyDataSetChanged(); |
||||
} |
||||
} |
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
package org.transdroid.core.gui.remoterss.data; |
||||
|
||||
import android.os.Parcelable; |
||||
|
||||
import org.transdroid.core.gui.lists.SimpleListItem; |
||||
|
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author Twig |
||||
*/ |
||||
public abstract class RemoteRssChannel implements Parcelable, SimpleListItem { |
||||
protected int id; |
||||
protected String name; |
||||
protected String link; |
||||
protected long lastUpdated; |
||||
protected List<RemoteRssItem> items; |
||||
|
||||
@Override |
||||
public int describeContents() { |
||||
return 0; |
||||
} |
||||
|
||||
public int getId() { |
||||
return id; |
||||
} |
||||
|
||||
public String getLink() { |
||||
return link; |
||||
} |
||||
|
||||
public Date getLastUpdated() { |
||||
return new Date(lastUpdated); |
||||
} |
||||
|
||||
public List<RemoteRssItem> getItems() { |
||||
return items; |
||||
} |
||||
|
||||
@Override |
||||
public String getName() { |
||||
return name; |
||||
} |
||||
} |
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
package org.transdroid.core.gui.remoterss.data; |
||||
|
||||
import android.os.Parcelable; |
||||
|
||||
import org.transdroid.core.gui.lists.SimpleListItem; |
||||
|
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @author Twig |
||||
*/ |
||||
public abstract class RemoteRssItem implements Parcelable, SimpleListItem { |
||||
protected String title; |
||||
protected String link; // May be magnet or http(s)
|
||||
protected String sourceName; // Name of RSS feed channel
|
||||
protected Date timestamp; |
||||
|
||||
@Override |
||||
public String getName() { |
||||
return title; |
||||
} |
||||
|
||||
public String getTitle() { |
||||
return title; |
||||
} |
||||
|
||||
public String getLink() { |
||||
return link; |
||||
} |
||||
|
||||
public String getSourceName() { |
||||
return sourceName; |
||||
} |
||||
|
||||
public void setSourceName(String sourceName) { |
||||
this.sourceName = sourceName; |
||||
} |
||||
|
||||
public Date getTimestamp() { |
||||
return timestamp; |
||||
} |
||||
|
||||
public boolean isMagnetLink() { |
||||
return link.startsWith("magnet:?"); |
||||
} |
||||
|
||||
@Override |
||||
public int describeContents() { |
||||
return 0; |
||||
} |
||||
} |
@ -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(); |
||||
} |
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
package org.transdroid.daemon.Utorrent.data; |
||||
|
||||
import android.os.Parcel; |
||||
import android.os.Parcelable; |
||||
|
||||
import org.json.JSONArray; |
||||
import org.json.JSONException; |
||||
import org.transdroid.core.gui.remoterss.data.RemoteRssChannel; |
||||
import org.transdroid.core.gui.remoterss.data.RemoteRssItem; |
||||
|
||||
import java.util.ArrayList; |
||||
|
||||
/** |
||||
* uTorrent implementation of RemoteRssChannel. |
||||
* |
||||
* @author Twig |
||||
*/ |
||||
public class UTorrentRemoteRssChannel extends RemoteRssChannel { |
||||
public UTorrentRemoteRssChannel(JSONArray json) throws JSONException { |
||||
// boolean enabled = json.getBoolean(1);
|
||||
boolean isCustomAlias = !json.getBoolean(2); |
||||
|
||||
id = json.getInt(0); |
||||
link = json.getString(6); |
||||
lastUpdated = json.getLong(7); |
||||
|
||||
if (isCustomAlias) { |
||||
name = link.split("\\|")[0]; |
||||
link = link.split("\\|")[1]; |
||||
} |
||||
else { |
||||
name = link; |
||||
} |
||||
|
||||
items = new ArrayList<>(); |
||||
|
||||
JSONArray filesJson = json.getJSONArray(8); |
||||
RemoteRssItem file; |
||||
|
||||
for (int i = 0; i < filesJson.length(); i++) { |
||||
file = new UTorrentRemoteRssItem(filesJson.getJSONArray(i)); |
||||
file.setSourceName(name); |
||||
items.add(file); |
||||
} |
||||
} |
||||
|
||||
public UTorrentRemoteRssChannel(Parcel in) { |
||||
id = in.readInt(); |
||||
name = in.readString(); |
||||
link = in.readString(); |
||||
lastUpdated = in.readLong(); |
||||
|
||||
items = new ArrayList<>(); |
||||
in.readList(items, UTorrentRemoteRssItem.class.getClassLoader()); |
||||
} |
||||
|
||||
@Override |
||||
public void writeToParcel(Parcel dest, int flags) { |
||||
dest.writeInt(id); |
||||
dest.writeString(name); |
||||
dest.writeString(link); |
||||
dest.writeLong(lastUpdated); |
||||
dest.writeList(items); |
||||
} |
||||
|
||||
public static final Parcelable.Creator<UTorrentRemoteRssChannel> CREATOR = new Parcelable.Creator<UTorrentRemoteRssChannel>() { |
||||
public UTorrentRemoteRssChannel createFromParcel(Parcel in) { |
||||
return new UTorrentRemoteRssChannel(in); |
||||
} |
||||
|
||||
public UTorrentRemoteRssChannel[] newArray(int size) { |
||||
return new UTorrentRemoteRssChannel[size]; |
||||
} |
||||
}; |
||||
} |
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
package org.transdroid.daemon.Utorrent.data; |
||||
|
||||
import android.os.Parcel; |
||||
import android.os.Parcelable; |
||||
|
||||
import org.json.JSONArray; |
||||
import org.json.JSONException; |
||||
import org.transdroid.core.gui.remoterss.data.RemoteRssItem; |
||||
|
||||
import java.util.Calendar; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* uTorrent implementation of RemoteRssItem. |
||||
* |
||||
* @author Twig |
||||
*/ |
||||
public class UTorrentRemoteRssItem extends RemoteRssItem { |
||||
// public String name;
|
||||
// public int season;
|
||||
// public int episode;
|
||||
|
||||
public UTorrentRemoteRssItem(JSONArray json) throws JSONException { |
||||
// name = json.getString(0); // clean name
|
||||
title = json.getString(1); // filename
|
||||
link = json.getString(2); |
||||
|
||||
Calendar calendar = Calendar.getInstance(); |
||||
calendar.setTimeInMillis(json.getLong(5) * 1000); |
||||
timestamp = calendar.getTime(); |
||||
|
||||
// season = json.getInt(6);
|
||||
// episode = json.getInt(7);
|
||||
} |
||||
|
||||
|
||||
public static final Parcelable.Creator<UTorrentRemoteRssItem> CREATOR = new Parcelable.Creator<UTorrentRemoteRssItem>() { |
||||
public UTorrentRemoteRssItem createFromParcel(Parcel in) { |
||||
return new UTorrentRemoteRssItem(in); |
||||
} |
||||
|
||||
public UTorrentRemoteRssItem[] newArray(int size) { |
||||
return new UTorrentRemoteRssItem[size]; |
||||
} |
||||
}; |
||||
|
||||
public UTorrentRemoteRssItem(Parcel in) { |
||||
// name = in.readString();
|
||||
title = in.readString(); |
||||
link = in.readString(); |
||||
sourceName = in.readString(); |
||||
timestamp = (Date) in.readSerializable(); |
||||
// season = in.readInt();
|
||||
// episode = in.readInt();
|
||||
} |
||||
|
||||
@Override |
||||
public void writeToParcel(Parcel dest, int flags) { |
||||
// dest.writeString(name);
|
||||
dest.writeString(title); |
||||
dest.writeString(link); |
||||
dest.writeString(sourceName); |
||||
dest.writeSerializable(timestamp); |
||||
// dest.writeInt(season);
|
||||
// dest.writeInt(episode);
|
||||
} |
||||
} |
@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:viewportWidth="24.0" |
||||
android:viewportHeight="24.0"> |
||||
<path |
||||
android:fillColor="#FFFFFFFF" |
||||
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96zM17,13l-5,5 -5,-5h3V9h4v4h3z"/> |
||||
</vector> |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!-- |
||||
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 <http://www.gnu.org/licenses/>. |
||||
--> |
||||
<!-- This layout is for phones in portrait and shows the remote RSS items list with the filters as navigation drawer. --> |
||||
<android.support.v4.widget.DrawerLayout |
||||
android:id="@+id/drawer_layout" |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:context=".core.gui.remoterss.RemoteRssActivity_"> |
||||
|
||||
<!-- The main content view --> |
||||
<RelativeLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical"> |
||||
|
||||
<android.support.v7.widget.Toolbar |
||||
android:id="@+id/torrents_toolbar" |
||||
style="@style/DefaultToolbar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:minHeight="?attr/actionBarSize" /> |
||||
|
||||
<fragment |
||||
android:id="@+id/remoterss_fragment" |
||||
class="org.transdroid.core.gui.remoterss.RemoteRssFragment_" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:layout_below="@id/torrents_toolbar" |
||||
tools:layout="@layout/fragment_torrents" /> |
||||
|
||||
<View |
||||
style="@style/DefaultToolbarShadow" |
||||
android:layout_below="@id/torrents_toolbar" /> |
||||
|
||||
<View |
||||
style="@style/SplitToolbarShadow" |
||||
/> |
||||
|
||||
</RelativeLayout> |
||||
|
||||
<!-- The navigation drawer --> |
||||
<LinearLayout |
||||
android:id="@+id/drawer_container" |
||||
android:layout_width="@dimen/ui_filters_list" |
||||
android:layout_height="match_parent" |
||||
android:layout_gravity="start" |
||||
android:background="?attr/drawer_background" |
||||
android:orientation="vertical"> |
||||
|
||||
<ListView |
||||
android:id="@+id/drawer_list" |
||||
android:layout_width="@dimen/ui_filters_list" |
||||
android:layout_height="0dp" |
||||
android:layout_weight="1" |
||||
android:choiceMode="singleChoice" |
||||
android:divider="@null" |
||||
tools:listitem="@layout/list_item_filter" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
</android.support.v4.widget.DrawerLayout> |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!-- |
||||
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 <http://www.gnu.org/licenses/>. |
||||
--> |
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
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" |
||||
android:layout_height="match_parent" |
||||
android:choiceMode="multipleChoiceModal" |
||||
android:clipToPadding="false" |
||||
tools:listitem="@layout/list_item_remoterssitem" |
||||
tools:visibility="visible"/> |
||||
|
||||
</FrameLayout> |
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<!-- |
||||
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 <http://www.gnu.org/licenses/>. |
||||
--> |
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="fill_parent" |
||||
android:layout_height="wrap_content" |
||||
android:background="?attr/activatable_background" |
||||
android:paddingBottom="@dimen/margin_default" |
||||
android:paddingLeft="@dimen/margin_default" |
||||
android:paddingRight="@dimen/margin_default" |
||||
android:paddingTop="@dimen/margin_default"> |
||||
|
||||
<TextView |
||||
android:id="@+id/label_text" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="4dip" |
||||
android:textIsSelectable="false" |
||||
android:textSize="@dimen/text_small" |
||||
tools:text="Source channel name"/> |
||||
|
||||
<TextView |
||||
android:id="@+id/name_text" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:fontFamily="sans-serif-condensed" |
||||
android:textColor="?attr/text_bright" |
||||
android:textIsSelectable="false" |
||||
android:textSize="@dimen/text_enlarged" |
||||
tools:text="Title for torrent" |
||||
android:layout_below="@+id/label_text"/> |
||||
|
||||
<TextView |
||||
android:id="@+id/date_text" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_below="@+id/name_text" |
||||
android:layout_marginTop="4dip" |
||||
android:textIsSelectable="false" |
||||
android:textSize="@dimen/text_small" |
||||
tools:text="25-12-2015" |
||||
/> |
||||
|
||||
</RelativeLayout> |
Loading…
Reference in new issue