Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
erickok committed Sep 11, 2014
2 parents 44c7de5 + cb29129 commit fef8157
Show file tree
Hide file tree
Showing 27 changed files with 295 additions and 105 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Designed and developed by [Eric Kok](eric@2312.nl) of [2312 development](http://
License
=======

Copyright 2010-2013 Eric Kok et al.
Copyright 2010-2014 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
Expand Down
2 changes: 1 addition & 1 deletion core/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.transdroid.core"
android:versionCode="214"
android:versionCode="215"
android:versionName="2.2.0" >

<uses-sdk
Expand Down
2 changes: 1 addition & 1 deletion core/res/layout-w600dp/activity_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
android:listSelector="?attr/selectable_background_transdroid" />

<fragment
android:id="@+id/searchresults_list"
android:id="@+id/searchresults_fragment"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="2"
Expand Down
2 changes: 1 addition & 1 deletion core/res/layout-w600dp/activity_torrents.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
android:listSelector="?attr/selectable_background_transdroid" />

<fragment
android:id="@+id/torrent_list"
android:id="@+id/torrents_fragment"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="3"
Expand Down
4 changes: 2 additions & 2 deletions core/res/layout-w900dp/activity_rssfeeds.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
tools:context=".RssfeedsActivity" >

<fragment
android:id="@+id/rssfeeds_list"
android:id="@+id/rssfeeds_fragment"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="2"
class="org.transdroid.core.gui.rss.RssfeedsFragment_"
tools:layout="@layout/fragment_rssfeeds" />

<fragment
android:id="@+id/rssitems_list"
android:id="@+id/rssitems_fragment"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="3"
Expand Down
4 changes: 2 additions & 2 deletions core/res/layout-w900dp/activity_torrents.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
android:listSelector="?attr/selectable_background_transdroid" />

<fragment
android:id="@+id/torrent_list"
android:id="@+id/torrents_fragment"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="2"
class="org.transdroid.core.gui.TorrentsFragment_"
tools:layout="@layout/fragment_torrents" />

<fragment
android:id="@+id/torrent_details"
android:id="@+id/torrentdetails_fragment"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="2"
Expand Down
2 changes: 1 addition & 1 deletion core/res/layout/activity_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
tools:context=".DetailsActivity" >

<fragment
android:id="@+id/torrent_details"
android:id="@+id/torrentdetails_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="org.transdroid.core.gui.DetailsFragment_"
Expand Down
2 changes: 1 addition & 1 deletion core/res/layout/activity_rssfeeds.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
tools:context=".RssfeedsActivity" >

<fragment
android:id="@+id/rssfeeds_list"
android:id="@+id/rssfeeds_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="org.transdroid.core.gui.rss.RssfeedsFragment_"
Expand Down
2 changes: 1 addition & 1 deletion core/res/layout/activity_rssitems.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
tools:context=".RssItemsActivity" >

<fragment
android:id="@+id/rssitems_list"
android:id="@+id/rssitems_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="org.transdroid.core.gui.rss.RssitemsFragment_"
Expand Down
2 changes: 1 addition & 1 deletion core/res/layout/activity_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
tools:context=".SearchActivity" >

<fragment
android:id="@+id/searchresults_list"
android:id="@+id/searchresults_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="org.transdroid.core.gui.search.SearchResultsFragment_"
Expand Down
2 changes: 1 addition & 1 deletion core/res/layout/activity_torrents.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
tools:context=".TorrentsActivity" >

<fragment
android:id="@+id/torrent_list"
android:id="@+id/torrents_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="org.transdroid.core.gui.TorrentsFragment_"
Expand Down
4 changes: 4 additions & 0 deletions core/res/menu/fragment_details_cab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@
android:id="@+id/action_download"
android:showAsAction="ifRoom"
android:title="@string/action_download" />
<item
android:id="@+id/action_copytoclipboard"
android:showAsAction="never"
android:title="@string/action_copytoclipboard" />

</menu>
19 changes: 10 additions & 9 deletions core/res/menu/fragment_rssitems_cab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,25 @@
android:id="@+id/action_addall"
android:icon="?attr/ic_action_new"
android:showAsAction="always"
android:title="@string/action_addall" />

android:title="@string/action_addall"/>
<item
android:id="@+id/action_showdetails"
android:icon="?attr/ic_action_info"
android:showAsAction="ifRoom"
android:title="@string/action_showdetails" />

android:title="@string/action_showdetails"/>
<item
android:id="@+id/action_openwebsite"
android:icon="?attr/ic_action_website"
android:showAsAction="ifRoom"
android:title="@string/action_openwebsite" />

android:title="@string/action_openwebsite"/>
<item
android:id="@+id/action_useassearch"
android:icon="?attr/ic_action_search"
android:showAsAction="ifRoom"
android:title="@string/action_useassearch" />

</menu>
android:title="@string/action_useassearch"/>
<item
android:id="@+id/action_copytoclipboard"
android:showAsAction="never"
android:title="@string/action_copytoclipboard"/>

</menu>
5 changes: 5 additions & 0 deletions core/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<string name="action_priority_high">High</string>
<string name="action_remoteplay">Remote play in VLC</string>
<string name="action_download">Download using FTP(S)</string>
<string name="action_copytoclipboard">Copy to clipboard</string>
<string name="action_showdetails">Show details</string>
<string name="action_openwebsite">Open website</string>
<string name="action_useassearch">Use as new search</string>
Expand Down Expand Up @@ -90,6 +91,7 @@
<string name="navigation_selectall">Select all</string>
<string name="navigation_selectfinished">Select finished</string>
<string name="navigation_invertselection">Invert selection</string>
<string name="navigation_pickserver">Add torrent to&#8230;</string>

<string name="status_status">STATUS: %1$s</string>
<string name="status_waiting">Waiting to check&#8230;</string>
Expand Down Expand Up @@ -216,6 +218,9 @@
<string name="pref_servers">Servers</string>
<string name="pref_addserver">Add new server</string>
<string name="pref_addseedbox">Add seedbox</string>
<string name="pref_defaultserver">Default server</string>
<string name="pref_defaultserver_lastused">Last used</string>
<string name="pref_defaultserver_askonadd">Ask when adding torrent</string>
<string name="pref_searchsites">Search sites</string>
<string name="pref_setsearchsite">Set default site</string>
<string name="pref_addwebsearch">Add web search site</string>
Expand Down
7 changes: 6 additions & 1 deletion core/res/xml/pref_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
<org.transdroid.core.gui.settings.OverflowPreference
android:key="header_addserver"
android:title="@string/pref_addserver"
android:order="99" />
android:order="98" />
<ListPreference
android:key="header_defaultserver"
android:title="@string/pref_defaultserver"
android:order="99"
android:defaultValue="-2" />
</PreferenceCategory>

<PreferenceCategory
Expand Down
66 changes: 63 additions & 3 deletions core/src/org/transdroid/core/app/settings/ApplicationSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
@EBean(scope = Scope.Singleton)
public class ApplicationSettings {

public static final int DEFAULTSERVER_LASTUSED = -2;
public static final int DEFAULTSERVER_ASKONADD = -1;

@RootContext
protected Context context;
private SharedPreferences prefs;
Expand Down Expand Up @@ -85,9 +88,9 @@ public int getMaxOfAllServers() {
}
return max;
}

/**
* Returns the server settings for either a normal or a seedbox server as the user configured. WARNING: This method
* Returns the server settings for either a normal or a seedbox server as the user configured. WARNING: This method
* does not check if the settings actually exist and may reply on empty default if called for a non-existing server.
* @param order The order number/identifying key of the server's settings to retrieve, where the normal servers are
* first and the seedboxes are numbers thereafter onwards
Expand Down Expand Up @@ -132,7 +135,7 @@ public int getMaxNormalServer() {
}

/**
* Returns the user-specified server settings for a normal (non-seedbox) server. WARNING: This method does not check
* Returns the user-specified server settings for a normal (non-seedbox) server. WARNING: This method does not check
* if the settings actually exist and may rely on empty defaults if called for a non-existing server.
* @param order The order number/identifying key of the normal server's settings to retrieve
* @return The server settings object, loaded from shared preferences
Expand Down Expand Up @@ -244,10 +247,67 @@ public void removeNormalServerSettings(int order) {
edit.remove("server_timeout_" + max);
edit.remove("server_alarmfinished_" + max);
edit.remove("server_alarmfinished_" + max);

// Perhaps we should also update the default server to match the server's new id or remove the default selection
// in case it was this server that was removed
int defaultServer = getDefaultServerKey();
if (defaultServer == order) {
edit.remove("header_defaultserver");
} else if (defaultServer > order) {
// Move 'up' one place to account for the removed server setting
edit.putInt("header_defaultserver", --order);
}

edit.commit();

}

/**
* Returns the settings of the server that was explicitly selected by the user to select as default or, when no
* specific default server was selected, the last used server settings. As opposed to getDefaultServerKey(int), this
* method checks whether the particular server still exists (and returns the first server if not). If no servers are
* configured, null is returned.
* @return A server settings object of the server to use by default, or null if no server is yet configured
*/
public ServerSetting getDefaultServer() {

int defaultServer = getDefaultServerKey();
if (defaultServer == DEFAULTSERVER_LASTUSED || defaultServer == DEFAULTSERVER_ASKONADD) {
return getLastUsedServer();
}

// Use the explicitly selected default server
int max = getMaxOfAllServers(); // Zero-based index, so with max == 0 there is 1 server
if (max < 0) {
// No servers configured
return null;
}
if (defaultServer < 0 || defaultServer > max) {
// Last server was never set or no longer exists
return getServerSetting(0);
}
return getServerSetting(defaultServer);

}

/**
* Returns the unique key of the server setting that the user selected as their default server, or code indicating
* that the last used server should be selected by default; use with getDefaultServer directly. WARNING: the
* returned string may no longer refer to a known server setting key.
* @return An integer; if it is 0 or higher it represents the unique key of a configured server setting, -2 means
* the last used server should be selected as default instead and -1 means the last used server should be
* selected by default for viewing yet it should always ask when adding a new torrent
*/
public int getDefaultServerKey() {
String defaultServer = prefs.getString("header_defaultserver", Integer.toString(DEFAULTSERVER_LASTUSED));
try {
return Integer.parseInt(defaultServer);
} catch (NumberFormatException e) {
// This should NEVER happen but if the setting somehow is not a number, return the default
return DEFAULTSERVER_LASTUSED;
}
}

/**
* Returns the settings of the server that was last used by the user. As opposed to getLastUsedServerKey(int), this
* method checks whether a server was already registered as being last used and check whether the server still
Expand Down
2 changes: 1 addition & 1 deletion core/src/org/transdroid/core/gui/DetailsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class DetailsActivity extends Activity implements TorrentTasksExecutor, R
private PullToRefreshAttacher pullToRefreshAttacher = null;

// Details view components
@FragmentById(resName = "torrent_details")
@FragmentById(resName = "torrentdetails_fragment")
protected DetailsFragment fragmentDetails;

@Override
Expand Down
17 changes: 17 additions & 0 deletions core/src/org/transdroid/core/gui/DetailsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@

import android.annotation.SuppressLint;
import android.app.Fragment;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.ActionMode;
Expand Down Expand Up @@ -475,6 +478,20 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
mode.finish();
return true;

} else if (itemId == R.id.action_copytoclipboard) {

StringBuilder names = new StringBuilder();
for (int f = 0; f < checked.size(); f++) {
if (f != 0)
names.append("\n");
names.append(checked.get(f).getName());
}
ClipboardManager clipboardManager = (ClipboardManager) getActivity().getSystemService(
Context.CLIPBOARD_SERVICE);
clipboardManager.setPrimaryClip(ClipData.newPlainText("Transdroid", names.toString()));
mode.finish();
return true;

} else {
Priority priority = Priority.Off;
if (itemId == R.id.action_priority_low)
Expand Down
41 changes: 41 additions & 0 deletions core/src/org/transdroid/core/gui/ServerPickerDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.transdroid.core.gui;

import java.util.List;

import org.transdroid.core.R;
import org.transdroid.core.app.settings.ServerSetting;

import android.app.AlertDialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

public class ServerPickerDialog {

/**
* Opens a dialog that allows the selection of a configured server (manual or seedbox). The calling activity will
* receive a callback on its switchServerAndAddFromIntent(int) method.
* @param activity The torrents activity from which the picker is started (and which received the callback)
* @param serverSettings The list of all available servers, of which their names will be offered to the user to pick
* from (and its position in the list is returned to the activity)
*/
public static void startServerPicker(final TorrentsActivity activity, List<ServerSetting> serverSettings) {
final String[] serverNames = new String[serverSettings.size()];
for (int i = 0; i < serverSettings.size(); i++) {
serverNames[i] = serverSettings.get(i).getName();
}
new DialogFragment() {
public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) {
return new AlertDialog.Builder(activity).setTitle(R.string.navigation_pickserver)
.setItems(serverNames, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (activity != null)
activity.switchServerAndAddFromIntent(which);
}
}).create();
};
}.show(activity.getFragmentManager(), "serverpicker");
}

}
Loading

0 comments on commit fef8157

Please sign in to comment.