From e171266ef88921fc7d147629b0e27bffd33434b5 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Thu, 4 Oct 2018 10:33:14 +0200 Subject: [PATCH] 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. --- README.md | 7 +- .../GoogleWebSearchBarcodeResolver.java | 93 ------------------ .../transdroid/core/gui/TorrentsActivity.java | 33 ------- .../core/gui/search/BarcodeHelper.java | 48 ++------- .../res/drawable-hdpi/ic_action_barcode.png | Bin 1222 -> 0 bytes .../res/drawable-xhdpi/ic_action_barcode.png | Bin 1193 -> 0 bytes .../res/drawable-xxhdpi/ic_action_barcode.png | Bin 1293 -> 0 bytes .../drawable-xxxhdpi/ic_action_barcode.png | Bin 1170 -> 0 bytes .../main/res/layout/actionbar_addbutton.xml | 9 -- 9 files changed, 10 insertions(+), 180 deletions(-) delete mode 100644 app/src/main/java/org/transdroid/core/app/search/GoogleWebSearchBarcodeResolver.java delete mode 100644 app/src/main/res/drawable-hdpi/ic_action_barcode.png delete mode 100644 app/src/main/res/drawable-xhdpi/ic_action_barcode.png delete mode 100644 app/src/main/res/drawable-xxhdpi/ic_action_barcode.png delete mode 100644 app/src/main/res/drawable-xxxhdpi/ic_action_barcode.png diff --git a/README.md b/README.md index d5f96be7..32e43834 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ Transdroid Screen shot of the main torrents listing screen -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 ============= @@ -27,7 +28,7 @@ Please respect the coding standards for easier merging. master contains the curr 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 ============ @@ -37,7 +38,7 @@ Designed and developed by [Eric Kok](eric@2312.nl) of [2312 development](http:// 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 it under the terms of the GNU General Public License as published by diff --git a/app/src/main/java/org/transdroid/core/app/search/GoogleWebSearchBarcodeResolver.java b/app/src/main/java/org/transdroid/core/app/search/GoogleWebSearchBarcodeResolver.java deleted file mode 100644 index df013b07..00000000 --- a/app/src/main/java/org/transdroid/core/app/search/GoogleWebSearchBarcodeResolver.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * This file is part of Transdroid - * - * 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.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", "&", """, "'", "<", ">"}) { - 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; - - } - -} 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 8f45b733..1c8e6572 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/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.SearchView; import android.support.v7.widget.Toolbar; -import android.text.TextUtils; import android.view.Menu; import android.view.MenuItem; 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.remoterss.RemoteRssActivity_; 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.UrlEntryDialog; 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) public void refreshScreen() { fragmentTorrents.updateIsLoading(true); diff --git a/app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java b/app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java index 9113bf2f..71cfeaf0 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java +++ b/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.Intent; import android.net.Uri; -import android.text.TextUtils; import org.transdroid.R; -import org.transdroid.core.app.search.GoogleWebSearchBarcodeResolver; 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 - 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 - * #ACTIVITY_BARCODE_ADDTORRENT} or {@link #ACTIVITY_BARCODE_QRSETTINGS}. From there {@link #handleScanResult(int, - * android.content.Intent, boolean)} can be called to parse the result into a search query, in case of {@link - * #ACTIVITY_BARCODE_ADDTORRENT} scans. + * Call this to start a bar code scanner intent. The calling activity will receive an Intent result with the given + * request code. * @param activity The calling activity, to which the result is returned or a dialog is bound that asks to install * 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) { // 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() { @Override 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(); } - - ; }.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); - } - } - } diff --git a/app/src/main/res/drawable-hdpi/ic_action_barcode.png b/app/src/main/res/drawable-hdpi/ic_action_barcode.png deleted file mode 100644 index d08b52a588ff15ab063dcd6c25034c09a5e1c866..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1222 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`Gjk|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*9U+nA0*tB1$5BeXNr6bM+EIYV;~{3xK*A7;Nk-3KEmEQ%e+* zQqwc@Y?a>c-mj#PnPRIHZt82`Ti~3Uk?B!Ylp0*+7m{3+ootz+WN)WnQ(*-(AUCxn zQK2F?C$HG5!d3}vt`(3C64qBz04piUwpD^SD#ABF!8yMuRl!uxKsVXI%s|1+P|wiV z#N6CmN5ROz&_Lh7NZ-&%*U;R`*vQJjKmiJrfVLH-q*(>IxIyg#@@$ndN=gc>^!3Zj z%k|2Q_413-^$jg8EkR}&8R-I5=oVMzl_XZ^<`pZ$OmImpPA){ffi_eM3D1{oGuTzrd=COM+4n&cLd=IHa;5RX-@T zIKQ+g85kdF$}r8qu)}W=NFmTQR{lkqz(`5Vami0E%}vcK@pQ3O0?O#6WTsdd7+M$@ z8k(CJm>U_GSr{5RxtKXSI~iNLxVSkQnixC5%)qAC$->Ck$-vaj+|0$*(9qSy5{%6a zEzAv#%*+f;V0u0Cic1pnl2c*!W&-Vn>UG7d*UGslHL)bWC?r2W2bKZ?GV)9Ei!<^I z6r6)i6?_wuGxI=vQ1n22>ylcOS(cjOR+OKs01jWPOf2>r7!mR}L~jZ?VWtmsj6NuF zASD)<5HJOTnDC?zD)cddn|``~|nlyLImrvXovJaXad4%_4^{A8c=f+s#$jjp>+B4Jtu2TQq%9#BfLdha_+n=2L)h^Nd z+jnk*@Q-({Q5~;m+&?mV@>i>SC6gNbH*;CE9oqBcj`%#0uHS$7(|s&1T0LOWTEMYx z(dr5N7H6=#Ur6y~p5w?pXU)}&@|1u34@5UGGHlso7x^eF6chpsp00i_>zopr0B>iS Ad;kCd diff --git a/app/src/main/res/drawable-xhdpi/ic_action_barcode.png b/app/src/main/res/drawable-xhdpi/ic_action_barcode.png deleted file mode 100644 index aad3f6c9da6554b22312b992a40e3dd12b17e0d3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1193 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTC$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWuD@%xRe+5hW46K32*3xq68pHF_1f1wh>l3^w)^1&PVosU-?Y zsp*+{wo31J?^jaDOtDo8H}y5}EpSfF$n>ZxN)4{^3rViZPPR-@vbR&PsjvbXkegbP zs8ErclUHn2VXFi-*9yo63F|8_xQ#$mCU_UCM>=Yd9?IMY{WF#^yJhJwLf^|+xYVjo6Wvu8Lk_-I_n`5ICnnS z&v=d1y17DK?r80lqa(y!J=f-uPoq xeWhQE*FTx#c3<+>n!XM8(hb&d6Ev#03>XYPXh|Hasfq`Qdb;|#taD0e0su+cfeQct diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_barcode.png b/app/src/main/res/drawable-xxhdpi/ic_action_barcode.png deleted file mode 100644 index cb6189e20fd0620dda81cea280aa8c77596357c7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1293 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@ZgvM!k|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*9U+nA0*tB1$5BeXNr6bM+EIYV;~{3xK*A7;Nk-3KEmEQ%e+* zQqwc@Y?a>c-mj#PnPRIHZt82`Ti~3Uk?B!Ylp0*+7m{3+ootz+WN)WnQ(*-(AUCxn zQK2F?C$HG5!d3}vt`(3C64qBz04piUwpD^SD#ABF!8yMuRl!uxKsVXI%s|1+P|wiV z#N6CmN5ROz&_Lh7NZ-&%*U;R`*vQJjKmiJrfVLH-q*(>IxIyg#@@$ndN=gc>^!3Zj z%k|2Q_413-^$jg8EkR}&8R-I5=oVMzl_XZ^<`pZ$OmImpPA){ffi_eM3D1{oGuTzrd=COM+4n&cLd=IHa;5RX-@T zIKQ+g85kdF$}r8qu)}W=NFmTQR{lkqz(`5Vami0E%}vcK@pQ3O0?O#6WTsdd7+M$@ z8k(CJm>U_GSr{5RxtKXSI~iNLxVSkQnixC5%)qAC$->Ck$-vay+|0$*(9qSy5{%6a zEzAv#%*+f;V0u0Cic1pnl2c*!W&-Vn>NUfw*UGslHL)bWC?r2W2bKZ?GV)9Ei!<^I z6r6)i6?_wuGxI=vQ1n22>ylcOS(cjOR+OKs01jWPOf2>r7!mR}L~jZ?VWtmsj6NuF zASD)<5HJOTnDC?z<*H4itZ1YUBz zy>04~;x+~W1&0O(MkW>y5W#Ul{`AkD?7YKk7JrSMvE4=fx#^i@_WSsYV_$eza(te1 zKchU=C3ul<}RiGT_yPgg&ebxsLQ0Q!@*?EnA( diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_barcode.png b/app/src/main/res/drawable-xxxhdpi/ic_action_barcode.png deleted file mode 100644 index 7bc409c630c1ccb38591be032007b9c17c997f8d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1170 zcmbVLO=}ZD7@oGGrL-V|2Mf|+b8U8KHfc6l8rvkB*ichT5-{Gn-JLW`yC3dOOj<9c zDA*q$_;u(HkY2=7D~dOJQamYEiU*-ZD1vycv-z@?P{D=S`Fft`{h0S%pPjinG%!2> z02s=ShxEfNan$%0|Uxx=kj95nPecVjGva!!g=jHwlu6jo-6 z+RCC9)47Q&aJ()v0h3S_*3Bi$lk0J=p)0ese=KmY0ila=uIW@MHw#m?OW+uff*Oh- z7{NRag(XQEg(AX8K%#)fAeQ8iC?f=0AIGe@dRfjZnU*cKi*pr99a#`+wHjXw@wU4l z;8-l?YlvcyA%fnrMb&!H@&auIg?O54IMlE$=qsx8c9q6C=4mqo)5+yJ!j{)c6ib;< zR~-TKNH9%5t_IqpdGg1Nu4u2g><}SOJiF>@>^;hXHksw_bVELnc_UwU4fZJNl45IB zlUOvX#5s1u>xM2P97PyQVI+wt62&;FL{h0_D5fZx1P+IiZH;c+7{Z~nl8j0bC5>@9 z9BT{-MHBB9)w`GX`Y#-Zo#g&4 qa`LvRoVs^(|6@-Vn;rP-;X&^p*bWSBjeJ<&2kgtHXOzw4+}dv{$W~bZ diff --git a/app/src/main/res/layout/actionbar_addbutton.xml b/app/src/main/res/layout/actionbar_addbutton.xml index ec584dfb..9f451451 100644 --- a/app/src/main/res/layout/actionbar_addbutton.xml +++ b/app/src/main/res/layout/actionbar_addbutton.xml @@ -26,14 +26,5 @@ app:fab_colorPressed="@color/green_dark" app:fab_icon="@drawable/ic_action_link" /> - - - \ No newline at end of file