Browse Source

Support file downloads via AndFTP (and possibly plain ftp:// intents).

pull/13/merge
Eric Kok 11 years ago
parent
commit
a43e09b891
  1. 1
      core/res/values/changelog.xml
  2. 1
      core/res/values/strings.xml
  3. 1
      core/src/org/transdroid/core/gui/DetailsActivity.java
  4. 68
      core/src/org/transdroid/core/gui/DetailsFragment.java
  5. 1
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  6. 8
      lite/AndroidManifest.xml

1
core/res/values/changelog.xml

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
<string name="system_changelog">
Transdroid 2.0.0\n
- Allow changing of storage location (Deluge and Transmission)\n
- Allow file downloads via AndFTP\n
- UI improvements for Lite version\n
\n
Transdroid 2.0.0-alpha4\n

1
core/res/values/strings.xml

@ -356,6 +356,7 @@ @@ -356,6 +356,7 @@
<string name="error_notanumber">Please enter a positive number</string>
<string name="error_notalabel">Please enter a valid label or pick from the list</string>
<string name="error_stillloadingdetails">Please wait until the torrent details have been loaded</string>
<string name="error_noftpapp">No app found that can download %1$s</string>
<string name="update_app_newversion">New Transdroid version available</string>
<string name="update_search_newversion">New Transdroid search module available</string>

1
core/src/org/transdroid/core/gui/DetailsActivity.java

@ -126,6 +126,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent @@ -126,6 +126,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
// Connect to the last used server
ServerSetting lastUsed = applicationSettings.getLastUsedServer();
fragmentDetails.setCurrentServerSettings(lastUsed);
currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName());
// Show details and load fine stats and torrent files

68
core/src/org/transdroid/core/gui/DetailsFragment.java

@ -27,6 +27,7 @@ import org.androidannotations.annotations.OptionsItem; @@ -27,6 +27,7 @@ import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu;
import org.androidannotations.annotations.ViewById;
import org.transdroid.core.R;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.app.settings.SystemSettings_;
import org.transdroid.core.gui.lists.DetailsAdapter;
import org.transdroid.core.gui.lists.SimpleListItemAdapter;
@ -46,6 +47,9 @@ import org.transdroid.daemon.Torrent; @@ -46,6 +47,9 @@ import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentDetails;
import org.transdroid.daemon.TorrentFile;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
@ -81,6 +85,7 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat @@ -81,6 +85,7 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat
protected ArrayList<Label> currentLabels = null;
@InstanceState
protected boolean isLoadingTorrent = false;
private ServerSetting currentServerSettings = null;
// Views
@ViewById(resName = "details_list")
@ -117,6 +122,10 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat @@ -117,6 +122,10 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat
}
public void setCurrentServerSettings(ServerSetting serverSettings) {
currentServerSettings = serverSettings;
}
/**
* Updates the details adapter header to show the new torrent data.
* @param newTorrent The new torrent object
@ -340,6 +349,7 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat @@ -340,6 +349,7 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat
return selectionManagerMode.onPrepareActionMode(mode, menu);
}
@SuppressLint("SdCardPath")
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
@ -354,13 +364,61 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat @@ -354,13 +364,61 @@ public class DetailsFragment extends SherlockFragment implements OnTrackersUpdat
int itemId = item.getItemId();
if (itemId == R.id.action_download) {
// TODO: Start FTP download command for the selected torrents
Crouton.showText(getActivity(), "TODO: Start FTP download command for the selected torrents",
NavigationHelper.CROUTON_INFO_STYLE);
// for (TorrentFile file : checked) {
// }
if (checked.size() < 1 || currentServerSettings == null)
return true;
String urlBase = currentServerSettings.getFtpUrl();
if (urlBase == null || urlBase.equals(""))
urlBase = "ftp://" + currentServerSettings.getAddress();
// Try using AndFTP intents
Intent andftpStart = new Intent(Intent.ACTION_PICK);
andftpStart.setDataAndType(Uri.parse(urlBase), "vnd.android.cursor.dir/lysesoft.andftp.uri");
andftpStart.putExtra("command_type", "download");
andftpStart.putExtra("ftp_pasv", "true");
if (Uri.parse(urlBase).getUserInfo() != null)
andftpStart.putExtra("ftp_username", Uri.parse(urlBase).getUserInfo());
else
andftpStart.putExtra("ftp_username", currentServerSettings.getUsername());
if (currentServerSettings.getFtpPassword() != null
&& !currentServerSettings.getFtpPassword().equals("")) {
andftpStart.putExtra("ftp_password", currentServerSettings.getFtpPassword());
} else {
andftpStart.putExtra("ftp_password", currentServerSettings.getPassword());
}
// Note: AndFTP doesn't understand the directory that Environment.getExternalStoragePublicDirectory()
// uses :(
andftpStart.putExtra("local_folder", "/sdcard/Download");
for (int f = 0; f < checked.size(); f++) {
String file = checked.get(f).getRelativePath();
// If the file is directly in the root, AndFTP fails if we supply the proper path (like /file.pdf)
// Work around this bug by removing the leading / if no further directories are used in the path
if (file.startsWith("/") && file.indexOf("/", 1) < 0)
file = file.substring(1);
andftpStart.putExtra("remote_file" + (f + 1), file);
}
if (andftpStart.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(andftpStart);
mode.finish();
return true;
}
// Try using a VIEW intent given an ftp:// scheme URI
String url = urlBase + checked.get(0).getFullPath();
Intent simpleStart = new Intent(Intent.ACTION_VIEW, Uri.parse(url))
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (simpleStart.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(simpleStart);
mode.finish();
return true;
}
// No app is available that can handle FTP downloads
Crouton.showText(getActivity(), getString(R.string.error_noftpapp, url),
NavigationHelper.CROUTON_ERROR_STYLE);
mode.finish();
return true;
} else {
Priority priority = Priority.Off;
if (itemId == R.id.action_priority_low)

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

@ -372,6 +372,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -372,6 +372,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
fragmentTorrents.clear(true, true);
if (fragmentDetails != null && fragmentDetails.getActivity() != null) {
fragmentDetails.clear();
fragmentDetails.setCurrentServerSettings(server);
}
updateFragmentVisibility(true);
refreshScreen();

8
lite/AndroidManifest.xml

@ -75,6 +75,7 @@ @@ -75,6 +75,7 @@
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*"
android:mimeType="application/x-bittorrent"
android:scheme="http" />
</intent-filter>
@ -85,6 +86,7 @@ @@ -85,6 +86,7 @@
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*"
android:pathPattern=".*\\.torrent"
android:scheme="http" />
</intent-filter>
@ -95,6 +97,7 @@ @@ -95,6 +97,7 @@
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*"
android:mimeType="application/x-bittorrent"
android:scheme="https" />
</intent-filter>
@ -105,6 +108,7 @@ @@ -105,6 +108,7 @@
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*"
android:pathPattern=".*\\.torrent"
android:scheme="https" />
</intent-filter>
@ -115,6 +119,7 @@ @@ -115,6 +119,7 @@
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*"
android:mimeType="application/x-bittorrent"
android:scheme="file" />
</intent-filter>
@ -125,6 +130,7 @@ @@ -125,6 +130,7 @@
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*"
android:pathPattern=".*\\.torrent"
android:scheme="file" />
</intent-filter>
@ -135,6 +141,7 @@ @@ -135,6 +141,7 @@
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*"
android:mimeType="application/x-bittorrent"
android:scheme="content" />
</intent-filter>
@ -145,6 +152,7 @@ @@ -145,6 +152,7 @@
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="*"
android:pathPattern=".*\\.torrent"
android:scheme="content" />
</intent-filter>

Loading…
Cancel
Save