Browse Source

Remove adding torrent by barcode scanner, as not free adn token-less web search API seems to exist that can help us get a product name from upc code. Closes #449.

pull/465/head v2.5.11
Eric Kok 6 years ago
parent
commit
e171266ef8
  1. 7
      README.md
  2. 93
      app/src/main/java/org/transdroid/core/app/search/GoogleWebSearchBarcodeResolver.java
  3. 33
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  4. 46
      app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java
  5. BIN
      app/src/main/res/drawable-hdpi/ic_action_barcode.png
  6. BIN
      app/src/main/res/drawable-xhdpi/ic_action_barcode.png
  7. BIN
      app/src/main/res/drawable-xxhdpi/ic_action_barcode.png
  8. BIN
      app/src/main/res/drawable-xxxhdpi/ic_action_barcode.png
  9. 9
      app/src/main/res/layout/actionbar_addbutton.xml

7
README.md

@ -15,7 +15,8 @@ Transdroid
<img src="http://2312.nl/images/screenshot_transdroid_main.png" alt="Screen shot of the main torrents listing screen" width="280" /> <img src="http://2312.nl/images/screenshot_transdroid_main.png" alt="Screen shot of the main torrents listing screen" width="280" />
Manage your torrents from your Android device with Transdroid. All popular clients are supported: µTorrent, Transmission, rTorrent, Vuze, Deluge, BitTorrent 6, qBittorrent and many more. You can view and manage the running torrents and individual files. Adding is easy via the integrated search, RSS feeds or the barcode scanner (full version required). Monitor progress using the home screen widget or background alarm service.
Manage your torrents from your Android device with Transdroid. All popular clients are supported: µTorrent, Transmission, rTorrent, Vuze, Deluge, BitTorrent 6, qBittorrent and many more. You can view and manage the running torrents and individual files. Adding is easy via the integrated search or RSS feeds (full version required). Monitor progress using the home screen widget or background alarm service.
Contributions Contributions
============= =============
@ -27,7 +28,7 @@ Please respect the coding standards for easier merging. master contains the curr
Code structure Code structure
============== ==============
Starting with version 2.3.0, Transdroid is developed in Android Studio, fully integrating with the Gradle build system. It is (since version 2.5.0) compiled against Android 5.1 (API level 22) and (since version 2.2.0) supporting ICS (API level 15) and up only. To support lite (Transdrone, specially for the Play Store) and full (Transdroid) versions of the app, build flavours are defined in gradle, which contain version-specific resources. Dependencies are managed via JCentral in the app's build.gradle file. Starting with version 2.3.0, Transdroid is developed in Android Studio, fully integrating with the Gradle build system. It is (since version 2.5.0) compiled against Android 5.1 (API level 22) and (since version 2.2.0) supporting ICS (API level 15) and up only. To support lite (Transdrone, specially for the Play Store) and full (Transdroid) versions of the app, build flavours are defined in gradle, which contain version-specific resources. Dependencies are managed via JCentral et al. in the app's build.gradle file.
Developed By Developed By
============ ============
@ -37,7 +38,7 @@ Designed and developed by [Eric Kok](eric@2312.nl) of [2312 development](http://
License License
======= =======
Copyright 2010-2017 Eric Kok et al. Copyright 2010-2018 Eric Kok et al.
Transdroid is free software: you can redistribute it and/or modify Transdroid is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

93
app/src/main/java/org/transdroid/core/app/search/GoogleWebSearchBarcodeResolver.java

@ -1,93 +0,0 @@
/*
* This file is part of Transdroid <http://www.transdroid.org>
*
* 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.app.search;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.transdroid.daemon.util.HttpHelper;
import java.io.InputStream;
import java.util.Locale;
public class GoogleWebSearchBarcodeResolver {
public static final String apiUrl = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=%s";
public static String resolveBarcode(String barcode) {
try {
// We use the Google AJAX Search API to get a JSON-formatted list of web search results
String callUrl = apiUrl.replace("%s", barcode);
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(callUrl);
HttpResponse response = httpclient.execute(httpget);
InputStream instream = response.getEntity().getContent();
String result = HttpHelper.convertStreamToString(instream);
JSONArray results = new JSONObject(result).getJSONObject("responseData").getJSONArray("results");
// Use the first result, if any, after cleaning it from special characters
if (results.length() < 1) {
return null;
}
return stripGarbage(results.getJSONObject(0), barcode);
} catch (Exception e) {
return null;
}
}
private static String stripGarbage(JSONObject item, String barcode) throws JSONException {
String good = " abcdefghijklmnopqrstuvwxyz1234567890";
// Find the unformatted title
String title = item.getString("titleNoFormatting");
// Make string lowercase first
title = title.toLowerCase(Locale.US);
// Remove the barcode number if it's there
title = title.replace(barcode, "");
// Remove unwanted words and HTML special chars
for (String rem : new String[]{"dvd", "blu-ray", "bluray", "&amp;", "&quot;", "&apos;", "&lt;", "&gt;"}) {
title = title.replace(rem, "");
}
// Remove all non-alphanumeric (and space) characters
String result = "";
for (int j = 0; j < title.length(); j++) {
if (good.indexOf(title.charAt(j)) >= 0) {
result += title.charAt(j);
}
}
// Remove double spaces
while (result.contains(" ")) {
result = result.replace(" ", " ");
}
return result;
}
}

33
app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java

@ -32,7 +32,6 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ActionMenuView; import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -85,7 +84,6 @@ import org.transdroid.core.gui.navigation.RefreshableActivity;
import org.transdroid.core.gui.navigation.StatusType; import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.core.gui.remoterss.RemoteRssActivity_; import org.transdroid.core.gui.remoterss.RemoteRssActivity_;
import org.transdroid.core.gui.rss.RssfeedsActivity_; import org.transdroid.core.gui.rss.RssfeedsActivity_;
import org.transdroid.core.gui.search.BarcodeHelper;
import org.transdroid.core.gui.search.FilePickerHelper; import org.transdroid.core.gui.search.FilePickerHelper;
import org.transdroid.core.gui.search.UrlEntryDialog; import org.transdroid.core.gui.search.UrlEntryDialog;
import org.transdroid.core.gui.settings.MainSettingsActivity_; import org.transdroid.core.gui.settings.MainSettingsActivity_;
@ -791,37 +789,6 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
} }
} }
@Click(R.id.addmenu_barcode_button)
protected void startBarcodeScanner() {
addmenuButton.collapse();
BarcodeHelper.startBarcodeScanner(this, BarcodeHelper.ACTIVITY_BARCODE_ADDTORRENT);
}
@Background
@OnActivityResult(BarcodeHelper.ACTIVITY_BARCODE_ADDTORRENT)
public void onBarcodeScanned(int resultCode, Intent data) {
if (data != null) {
// We receive from the helper either a URL (as string) or a query we can start a search for
String query = BarcodeHelper.handleScanResult(resultCode, data, navigationHelper.enableSearchUi());
onBarcodeScanHandled(data.getStringExtra("SCAN_RESULT"), query);
}
}
@UiThread
protected void onBarcodeScanHandled(String barcode, String result) {
log.d(this, "Scanned barcode " + barcode + " and got " + result);
if (TextUtils.isEmpty(result)) {
SnackbarManager.show(Snackbar.with(this).text(R.string.error_noproductforcode).colorResource(R.color.red).type(SnackbarType.MULTI_LINE));
} else if (result.startsWith("http") || result.startsWith("https")) {
addTorrentByUrl(result, "QR code result"); // No torrent title known
} else if (result.startsWith("magnet")) {
String title = NavigationHelper.extractNameFromUri(Uri.parse(result));
addTorrentByMagnetUrl(result, title);
} else if (navigationHelper.enableSearchUi()) {
startSearch(result, false, null, false);
}
}
@OptionsItem(R.id.action_refresh) @OptionsItem(R.id.action_refresh)
public void refreshScreen() { public void refreshScreen() {
fragmentTorrents.updateIsLoading(true); fragmentTorrents.updateIsLoading(true);

46
app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java

@ -24,27 +24,21 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils;
import org.transdroid.R; import org.transdroid.R;
import org.transdroid.core.app.search.GoogleWebSearchBarcodeResolver;
public class BarcodeHelper { public class BarcodeHelper {
public static final int ACTIVITY_BARCODE_ADDTORRENT = 0x0000c0de;
// A 'random' ID to identify torrent adding scan intents
public static final int ACTIVITY_BARCODE_QRSETTINGS = 0x0000c0df;
// A 'random' ID to identify QR-encoded settings scan intents // A 'random' ID to identify QR-encoded settings scan intents
public static final Uri SCANNER_MARKET_URI = Uri.parse("market://search?q=pname:com.google.zxing.client.android"); public static final int ACTIVITY_BARCODE_QRSETTINGS = 0x0000c0df;
private static final Uri SCANNER_MARKET_URI = Uri.parse("market://search?q=pname:com.google.zxing.client.android");
/** /**
* Call this to start a bar code scanner intent. The calling activity will receive an Intent result with ID {@link * Call this to start a bar code scanner intent. The calling activity will receive an Intent result with the given
* #ACTIVITY_BARCODE_ADDTORRENT} or {@link #ACTIVITY_BARCODE_QRSETTINGS}. From there {@link #handleScanResult(int, * request code.
* android.content.Intent, boolean)} can be called to parse the result into a search query, in case of {@link
* #ACTIVITY_BARCODE_ADDTORRENT} scans.
* @param activity The calling activity, to which the result is returned or a dialog is bound that asks to install * @param activity The calling activity, to which the result is returned or a dialog is bound that asks to install
* the bar code scanner * the bar code scanner
* @param requestCode {@link #ACTIVITY_BARCODE_ADDTORRENT} or {@link #ACTIVITY_BARCODE_QRSETTINGS * @param requestCode {@link #ACTIVITY_BARCODE_QRSETTINGS}
*/ */
public static void startBarcodeScanner(final Activity activity, int requestCode) { public static void startBarcodeScanner(final Activity activity, int requestCode) {
// Start a bar code scanner that can handle the SCAN intent (specifically ZXing) // Start a bar code scanner that can handle the SCAN intent (specifically ZXing)
@ -82,42 +76,12 @@ public class BarcodeHelper {
.setPositiveButton(android.R.string.yes, new OnClickListener() { .setPositiveButton(android.R.string.yes, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (activity != null) {
activity.startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI)); activity.startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI));
} }
}
}).setNegativeButton(android.R.string.no, null).create(); }).setNegativeButton(android.R.string.no, null).create();
} }
;
}.show(activity.getFragmentManager(), "installscanner"); }.show(activity.getFragmentManager(), "installscanner");
} }
} }
/**
* The activity that called {@link #startBarcodeScanner(android.app.Activity, int)} with {@link
* #ACTIVITY_BARCODE_ADDTORRENT} should call this after the scan result was returned. This will parse the scan data
* and return a query search query appropriate to the bar code.
* @param resultCode The raw result code as returned by the bar code scanner
* @param data The raw data as returned from the bar code scanner
* @param supportsSearch Whether the application has the search UI enabled, such that it can use the scanned barcode
* to find torrents
* @return A String that can be used as new search query, or null if the bar code could not be scanned or no query
* can be constructed for it
*/
public static String handleScanResult(int resultCode, Intent data, boolean supportsSearch) {
String contents = data != null ? data.getStringExtra("SCAN_RESULT") : null;
String formatName = data != null ? data.getStringExtra("SCAN_RESULT_FORMAT") : null;
if (formatName != null && formatName.equals("QR_CODE")) {
// Scanned barcode was a QR code: return the contents directly
return contents;
} else {
if (TextUtils.isEmpty(contents) || !supportsSearch) {
return null;
}
// Get a meaningful search query based on a Google Search product lookup
return GoogleWebSearchBarcodeResolver.resolveBarcode(contents);
}
}
} }

BIN
app/src/main/res/drawable-hdpi/ic_action_barcode.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

BIN
app/src/main/res/drawable-xhdpi/ic_action_barcode.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

BIN
app/src/main/res/drawable-xxhdpi/ic_action_barcode.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

BIN
app/src/main/res/drawable-xxxhdpi/ic_action_barcode.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

9
app/src/main/res/layout/actionbar_addbutton.xml

@ -26,14 +26,5 @@
app:fab_colorPressed="@color/green_dark" app:fab_colorPressed="@color/green_dark"
app:fab_icon="@drawable/ic_action_link" /> app:fab_icon="@drawable/ic_action_link" />
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/addmenu_barcode_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fab_colorNormal="@color/green"
app:fab_colorPressed="@color/green_dark"
app:fab_icon="@drawable/ic_action_barcode" />
</com.getbase.floatingactionbutton.FloatingActionsMenu> </com.getbase.floatingactionbutton.FloatingActionsMenu>
Loading…
Cancel
Save