diff --git a/qBittorrentClient/AndroidManifest.xml b/qBittorrentClient/AndroidManifest.xml index f2731333..66b74b31 100644 --- a/qBittorrentClient/AndroidManifest.xml +++ b/qBittorrentClient/AndroidManifest.xml @@ -11,8 +11,8 @@ --> + android:versionCode="200" + android:versionName="2.0" > - @@ -61,9 +61,33 @@ + + + + + + + + + + + + + + + + + @@ -72,6 +96,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -93,6 +150,7 @@ android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" > + diff --git a/qBittorrentClient/libs/httpcore-4.3.2.jar b/qBittorrentClient/libs/httpcore-4.3.2.jar new file mode 100644 index 00000000..813ec234 Binary files /dev/null and b/qBittorrentClient/libs/httpcore-4.3.2.jar differ diff --git a/qBittorrentClient/libs/httpmime-4.3.5.jar b/qBittorrentClient/libs/httpmime-4.3.5.jar new file mode 100644 index 00000000..8a02dd22 Binary files /dev/null and b/qBittorrentClient/libs/httpmime-4.3.5.jar differ diff --git a/qBittorrentClient/res/layout-large/activity_main.xml b/qBittorrentClient/res/layout-large/activity_main.xml index b7c1fc79..c6e4215d 100644 --- a/qBittorrentClient/res/layout-large/activity_main.xml +++ b/qBittorrentClient/res/layout-large/activity_main.xml @@ -35,7 +35,8 @@ android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_above="@+id/adView" - android:orientation="horizontal" > + android:orientation="horizontal" + android:baselineAligned="false" > @@ -50,7 +51,7 @@ android:layout_below="@+id/textView2" android:layout_marginTop="10dp" android:padding="10dp" - android:text="To start using the client, set your qBittorrent server's settings and account by selecting 'Settings' from the drawer menu" /> + android:text="@string/about_help1" /> + android:text="@string/about_help2" /> + android:text="@string/about_motto" /> diff --git a/qBittorrentClient/res/layout/activity_main_original.xml b/qBittorrentClient/res/layout/activity_main_original.xml index 5a210a09..5de8761d 100644 --- a/qBittorrentClient/res/layout/activity_main_original.xml +++ b/qBittorrentClient/res/layout/activity_main_original.xml @@ -14,16 +14,18 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" - android:paddingBottom="@dimen/activity_vertical_margin" - android:paddingLeft="@dimen/activity_horizontal_margin" - android:paddingRight="@dimen/activity_horizontal_margin" - android:paddingTop="@dimen/activity_vertical_margin" - tools:context=".MainActivity" > + android:paddingBottom="5dp" + android:paddingLeft="10dp" + android:paddingRight="10dp" + android:paddingTop="10dp" + tools:context=".MainActivity" + android:baselineAligned="false" > + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" > \ No newline at end of file diff --git a/qBittorrentClient/res/layout/listview_item_row.xml b/qBittorrentClient/res/layout/listview_item_row.xml index 6e0deb74..01f9bc72 100644 --- a/qBittorrentClient/res/layout/listview_item_row.xml +++ b/qBittorrentClient/res/layout/listview_item_row.xml @@ -17,6 +17,7 @@ diff --git a/qBittorrentClient/res/layout/listview_main.xml b/qBittorrentClient/res/layout/listview_main.xml index a923e74e..bbd18e32 100644 --- a/qBittorrentClient/res/layout/listview_main.xml +++ b/qBittorrentClient/res/layout/listview_main.xml @@ -8,6 +8,8 @@ Contributors: Luis M. Gallardo D. - initial implementation + + CHECK IF IT USED! --> + android:layout_height="wrap_content" + > diff --git a/qBittorrentClient/res/layout/no_items_found.xml b/qBittorrentClient/res/layout/no_items_found.xml index d52e8883..d5a4e9b6 100644 --- a/qBittorrentClient/res/layout/no_items_found.xml +++ b/qBittorrentClient/res/layout/no_items_found.xml @@ -21,6 +21,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingRight="10dp" - android:text="No results" /> + android:text="@string/no_results" /> diff --git a/qBittorrentClient/res/layout/row.xml b/qBittorrentClient/res/layout/row.xml index e59aa6a6..fba7d17d 100644 --- a/qBittorrentClient/res/layout/row.xml +++ b/qBittorrentClient/res/layout/row.xml @@ -15,7 +15,7 @@ android:orientation="horizontal" > @@ -23,12 +23,13 @@ android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:src="@drawable/downloading" - android:layout_marginRight="5dp" /> + android:layout_marginRight="5dp" + android:src="@drawable/downloading" /> - + \ No newline at end of file diff --git a/qBittorrentClient/res/layout/tablet_help.xml b/qBittorrentClient/res/layout/tablet_help.xml index 8bdf6d3f..1f6c49cf 100644 --- a/qBittorrentClient/res/layout/tablet_help.xml +++ b/qBittorrentClient/res/layout/tablet_help.xml @@ -21,7 +21,7 @@ android:layout_toRightOf="@+id/arrow" android:background="@android:color/white" android:padding="10dp" - android:text="Use the drawer menu to choose an option" /> + android:text="@string/tablet_help" /> - + \ No newline at end of file diff --git a/qBittorrentClient/res/layout/torrent_details.xml b/qBittorrentClient/res/layout/torrent_details.xml index 24574274..cb7f7a8f 100644 --- a/qBittorrentClient/res/layout/torrent_details.xml +++ b/qBittorrentClient/res/layout/torrent_details.xml @@ -7,7 +7,7 @@ http://www.gnu.org/licenses/gpl.html Contributors: - Luis M. Gallardo D. - initial implementation + Luis M. Gallardo D. --> + android:orientation="vertical" + tools:context=".TorrentActionsActivity" > @@ -42,68 +43,184 @@ android:layout_height="1dp" android:background="@android:color/darker_gray" /> - + - + - + + - + - + - + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -114,82 +231,237 @@ android:layout_marginTop="10dp" android:background="@android:color/darker_gray" /> - + - + - + + - + - + - + + - + - + - + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/qBittorrentClient/res/menu/main.xml b/qBittorrentClient/res/menu/main.xml index 49dfadd4..1fbc629a 100644 --- a/qBittorrentClient/res/menu/main.xml +++ b/qBittorrentClient/res/menu/main.xml @@ -24,12 +24,12 @@ android:id="@+id/action_resume_all" android:icon="@drawable/ic_action_resume" android:showAsAction="ifRoom" - android:title="Resume all"/> + android:title="@string/action_resume_all"/> + android:title="@string/action_pause_all"/> + android:title="@string/action_delete"/> + android:title="@string/action_delete_drive"/> + android:title="@string/action_increase_priority"/> + android:title="@string/action_decrease_priority"/> + android:title="@string/action_download_rate_limit"/> + android:title="@string/action_upload_rate_limit"/> \ No newline at end of file diff --git a/qBittorrentClient/res/values-es/strings.xml b/qBittorrentClient/res/values-es/strings.xml new file mode 100644 index 00000000..63ba03c6 --- /dev/null +++ b/qBittorrentClient/res/values-es/strings.xml @@ -0,0 +1,106 @@ + + + + qBittorrent Client + Ajustes + Actualizar + Añadir + Pausar + Reanudar + Reanudar todos + Pausar todos + Eliminar datos + Aumentar prioridad + Disminuir prioridad + Configurar límite de descarga + Configurar limite de carga + Eliminar + Error de conexión + Ok + Cancelar + Actualizando + Acción + Presionando OK eliminará el torrent + Eliminar torrent + Presionando OK eliminará el torrent y sus datos del disco duro + Eliminar el torrent y sus datos + Torrent enviado! + Archivo torrent enviado! + Torrent iniciado! + Torrent detenido! + Todos los torrents se detuvieron! + Todos los torrents se reanudaron! + Torrent borrado! + Torrent y datos borrados! + Prioridad incrementada! + Prioridad disminuida! + Abrir menú de navegación + Cierre el menú de navegación + Obteniendo opciones ... + Opciones guardan + Límite de subida cambiado + Límite de bajada cambiado + Error + Un valor global no puede ser recuperado. Por favor, revise la configuración de conexión! + + + Todos + Descargando + Completados + Pausados + Activos + Inactivos + Opciones + Configuración + + + Para empezar a utilizar el cliente, proporciona los datos de conexión seleccionando \'Configuración\' en el menú desplegable + Pulsa el botón de actualización en el menú para obtener nuevos resultados, o elije una opción del menú de navegación para obtener la lista de torrents desde el servidor. + Gestiona todos tus torrents desde Android usando qBittorrent Client + icono + No hay resultados + Utilice el menú de navegación para elegir una opción + Tamaño + Información general + Ruta: + Ratio: + Prioridad: + Leechs: + Seeds: + Estado: + Progreso: + Torrent Hash: + Fecha de Creación: + Comentario: + Límite de subida: + Límite de bajada: + Total perdido: + Total subido: + Total descargado: + Tiempo transcurrido: + Num. Conexiones: + Ratio: + Cuentas + Servidor qBittorrent + Selecciona un servidor + Servidor qBitttorent + Host de conexión + Hostname o IP + Hostname o IP? + Habilitar https + Connectar usando https + Puerto dde conexión + Puerto (80, 8080, etc) + Puerto dde conexión? + Usuario + Indique usuario + Usuario? + Contraseña + Indique contraseña + Contraseña? + qBittorrent 2.x + Usar servidor qBittorrent anterior + Opción no disponible + Esta opción está solo disponible en la versión qBittorrent PRO! + + \ No newline at end of file diff --git a/qBittorrentClient/res/values/arrays.xml b/qBittorrentClient/res/values/arrays.xml new file mode 100644 index 00000000..f286950c --- /dev/null +++ b/qBittorrentClient/res/values/arrays.xml @@ -0,0 +1,15 @@ + + + + + Server 1 + Server 2 + Server 3 + + + 1 + 2 + 3 + + + \ No newline at end of file diff --git a/qBittorrentClient/res/values/strings.xml b/qBittorrentClient/res/values/strings.xml index ca6acbaf..c1dc50eb 100644 --- a/qBittorrentClient/res/values/strings.xml +++ b/qBittorrentClient/res/values/strings.xml @@ -17,20 +17,25 @@ Add Pause Resume - TextView - Network connection failed - Error + Resume all + Pause all + Delete + Delete data + Increase priority + Decrease priority + Download rate limit + Upload rate limit Network connection failed OK Cancel Refreshing Action - Settings Pressing OK will delete the torrent Delete torrent Pressing OK will delete torrent and its data from the hard drive Delete torrent and its data Torrent sent! + Torrent file sent! Torrent started! Torrent paused! All torrents were paused! @@ -47,6 +52,14 @@ Download rate limit set Error Global value cannot be retrieved. Please check your connection settings! + All + Downloading + Completed + Paused + Active + Inactive + Options + Settings All @@ -59,4 +72,53 @@ Settings + To start using the client, set your qBittorrent server\'s settings and account by selecting \'Settings\' from the drawer menu + Press the refresh button on the menu to get new results, or choose an option from the drawer menu to get the torrent list from the server. + Manage all your torrent from Android using qBittorrent Client + icon + No results + Use the drawer menu to choose an option + Size + General info + Save path: + Ratio: + Priority: + Leechs: + Seeds: + State: + Progress: + Torrent Hash: + Created Date: + Comment: + Upload Rate Limit: + Download Rate Limit: + Total wasted: + Total Uploaded: + Total Downloaded: + Time Elapsed: + Num. Connections: + Share Ratio: + Accounts + Choose a qBittorrent server + Choose a server + qBitttorent Server + Connection Host + Hostname or IP + Hostname or IP? + Enable https + Connect using https + Connection Port + Port (80, 8080, etc) + Connection Port? + Username + Provide username + Username? + Password + Provide password + Password? + qBittorrent 2.x + Use old qBittorrent server version + Feature not available + This feature is only available on qBittorrent PRO version! + \ No newline at end of file diff --git a/qBittorrentClient/res/xml/preferences.xml b/qBittorrentClient/res/xml/preferences.xml index 678e7585..fcd321c4 100644 --- a/qBittorrentClient/res/xml/preferences.xml +++ b/qBittorrentClient/res/xml/preferences.xml @@ -6,52 +6,61 @@ http://www.gnu.org/licenses/gpl.html Contributors: - Luis M. Gallardo D. - initial implementation + Luis M. Gallardo D. --> + android:title="@string/settings_account" > + + + android:summary="@string/settings_qbittorrent_hostname_summary" + android:title="@string/settings_qbittorrent_hostname_title" /> + android:summary="@string/settings_qbittorrent_https_summary" + android:title="@string/settings_qbittorrent_https_title" /> + android:summary="@string/settings_qbittorrent_port_summary" + android:title="@string/settings_qbittorrent_port_title" /> + android:summary="@string/settings_qbittorrent_username_dialog_title" + android:title="@string/settings_qbittorrent_username_title" /> + android:summary="@string/settings_qbittorrent_password_summary" + android:title="@string/settings_qbittorrent_password_title" /> + android:summary="@string/settings_qbittorrent_version_summary" + android:title="@string/settings_qbittorrent_version_title" /> \ No newline at end of file diff --git a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/DrawerItemCustomAdapter.java b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/DrawerItemCustomAdapter.java index 708b8f89..ebc98749 100644 --- a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/DrawerItemCustomAdapter.java +++ b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/DrawerItemCustomAdapter.java @@ -6,7 +6,7 @@ * http://www.gnu.org/licenses/gpl.html * * Contributors: - * Luis M. Gallardo D. - initial implementation + * Luis M. Gallardo D. ******************************************************************************/ package com.lgallardo.qbittorrentclient; @@ -46,15 +46,9 @@ public View getView(int position, View convertView, ViewGroup parent) { ImageView imageViewIcon = (ImageView) listItem.findViewById(R.id.imageViewIcon); TextView textViewName = (TextView) listItem.findViewById(R.id.textViewName); - -// Log.i("Adapter", "ImageView and TextView reached"); - ObjectDrawerItem folder = data[position]; -// Log.i("Adapter", "Icon:"+folder.icon); -// Log.i("Adapter", "Name:"+folder.name); - imageViewIcon.setImageResource(folder.icon); textViewName.setText(folder.name); diff --git a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/ItemstFragment.java b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/ItemstFragment.java index 688c8958..7fd771b3 100644 --- a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/ItemstFragment.java +++ b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/ItemstFragment.java @@ -10,19 +10,14 @@ ******************************************************************************/ package com.lgallardo.qbittorrentclient; -import android.app.Activity; import android.app.FragmentManager; import android.app.ListFragment; -import android.content.Intent; -import android.content.pm.ActivityInfo; import android.os.Bundle; -import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; -import android.view.Window; import android.widget.ListView; public class ItemstFragment extends ListFragment { @@ -46,15 +41,13 @@ public int getSecondFragmentContainer() { } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Tell the host activity that your fragment has menu options that it // wants to add/replace/delete using the onCreateOptionsMenu method. setHasOptionsMenu(true); - View rootView = inflater.inflate(R.layout.activity_main_original, - container, false); + View rootView = inflater.inflate(R.layout.activity_main_original, container, false); return rootView; } @@ -72,23 +65,18 @@ public void ListItemClicked(int position) { int count = lv.getCount(); - if (count == 1 - && lv.getItemAtPosition(0).equals(MainActivity.NO_RESULTS)) { + if (count == 1 && lv.getItemAtPosition(0).equals(MainActivity.NO_RESULTS)) { return; } -// Log.i("ItemsFragment", "Position => "+ position); - detailFragment = new TorrentDetailsFragment(); detailFragment.setPosition(position); if (detailFragment != null) { FragmentManager fragmentManager = getFragmentManager(); - fragmentManager.beginTransaction() - .replace(this.getSecondFragmentContainer(), detailFragment) - .addToBackStack("secondFragment").commit(); + fragmentManager.beginTransaction().replace(this.getSecondFragmentContainer(), detailFragment).addToBackStack("secondFragment").commit(); } } @@ -123,15 +111,14 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { if (menu.findItem(R.id.action_delete_drive) != null) { menu.findItem(R.id.action_delete_drive).setVisible(false); } - + if (menu.findItem(R.id.action_upload_rate_limit) != null) { menu.findItem(R.id.action_upload_rate_limit).setVisible(false); } - + if (menu.findItem(R.id.action_download_rate_limit) != null) { menu.findItem(R.id.action_download_rate_limit).setVisible(false); } - } } diff --git a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/JSONParser.java b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/JSONParser.java index 0217324e..04aa5508 100644 --- a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/JSONParser.java +++ b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/JSONParser.java @@ -11,12 +11,14 @@ package com.lgallardo.qbittorrentclient; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.security.KeyStore; import java.util.ArrayList; +import java.util.Date; import java.util.List; import org.apache.http.HttpEntity; @@ -35,6 +37,9 @@ import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; import org.apache.http.message.BasicNameValuePair; @@ -67,13 +72,11 @@ public JSONParser() { this("", "", 0, "", ""); } - public JSONParser(String hostname, int port, String username, - String password) { + public JSONParser(String hostname, int port, String username, String password) { this(hostname, "http", port, username, password); } - public JSONParser(String hostname, String protocol, int port, - String username, String password) { + public JSONParser(String hostname, String protocol, int port, String username, String password) { this.hostname = hostname; this.protocol = protocol; @@ -99,13 +102,11 @@ public JSONObject getJSONFromUrl(String url) { int timeoutSocket = 5000; // Set http parameters - HttpConnectionParams.setConnectionTimeout(httpParameters, - timeoutConnection); + HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); // Making HTTP request - HttpHost targetHost = new HttpHost(this.hostname, this.port, - this.protocol); + HttpHost targetHost = new HttpHost(this.hostname, this.port, this.protocol); // httpclient = new DefaultHttpClient(httpParameters); // httpclient = new DefaultHttpClient(); @@ -115,13 +116,10 @@ public JSONObject getJSONFromUrl(String url) { try { - AuthScope authScope = new AuthScope(targetHost.getHostName(), - targetHost.getPort()); - UsernamePasswordCredentials credentials = new UsernamePasswordCredentials( - this.username, this.password); + AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); + UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(this.username, this.password); - httpclient.getCredentialsProvider().setCredentials(authScope, - credentials); + httpclient.getCredentialsProvider().setCredentials(authScope, credentials); // set http parameters @@ -131,11 +129,10 @@ public JSONObject getJSONFromUrl(String url) { HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); -// Log.i("parser", is.toString()); + // Log.i("parser", is.toString()); // Build JSON - BufferedReader reader = new BufferedReader(new InputStreamReader( - is, "iso-8859-1"), 8); + BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { @@ -188,8 +185,7 @@ public JSONArray getJSONArrayFromUrl(String url) { int timeoutSocket = 5000; // Set http parameters - HttpConnectionParams.setConnectionTimeout(httpParameters, - timeoutConnection); + HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); // Making HTTP request @@ -203,13 +199,10 @@ public JSONArray getJSONArrayFromUrl(String url) { try { - AuthScope authScope = new AuthScope(targetHost.getHostName(), - targetHost.getPort()); - UsernamePasswordCredentials credentials = new UsernamePasswordCredentials( - username, password); + AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); + UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); - httpclient.getCredentialsProvider().setCredentials(authScope, - credentials); + httpclient.getCredentialsProvider().setCredentials(authScope, credentials); HttpGet httpget = new HttpGet(url); @@ -217,16 +210,15 @@ public JSONArray getJSONArrayFromUrl(String url) { StatusLine statusLine = httpResponse.getStatusLine(); int mStatusCode = statusLine.getStatusCode(); -// Log.i("Status", "CODE: " + mStatusCode); + // Log.i("Status", "CODE: " + mStatusCode); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); -// Log.i("parser", is.toString()); + // Log.i("parser", is.toString()); // Build JSON - BufferedReader reader = new BufferedReader(new InputStreamReader( - is, "iso-8859-1"), 8); + BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { @@ -252,7 +244,7 @@ public JSONArray getJSONArrayFromUrl(String url) { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources -// Log.i("qbittorrent", "finaly - goodbye!"); + // Log.i("qbittorrent", "finaly - goodbye!"); httpclient.getConnectionManager().shutdown(); } @@ -267,7 +259,12 @@ public void postCommand(String command, String hash) { String urlContentType = "application/x-www-form-urlencoded"; String limit = ""; - + String boundary = null; + + String contentDisposition = ""; + + StringBuilder fileContent = null; + HttpResponse httpResponse; DefaultHttpClient httpclient; @@ -291,6 +288,15 @@ public void postCommand(String command, String hash) { url = "command/download"; key = "urls"; } + if ("addTorrentFile".equals(command)) { + url = "command/upload"; + key = "urls"; + + boundary = "-----------------------" + (new Date()).getTime(); + + urlContentType = "multipart/form-data; boundary=" + boundary; + + } if ("pauseAll".equals(command)) { url = "command/pauseall"; } @@ -309,19 +315,19 @@ public void postCommand(String command, String hash) { if ("setQBittorrentPrefefrences".equals(command)) { url = "command/setPreferences"; key = "json"; -// Log.i("setQBittorrentPrefefrences", "setQBittorrentPrefefrences"); + // Log.i("setQBittorrentPrefefrences", + // "setQBittorrentPrefefrences"); } - + if ("setUploadRateLimit".equals(command)) { url = "command/setTorrentUpLimit"; String[] tmpString = hash.split("&"); hash = tmpString[0]; limit = tmpString[1]; - + Log.i("upload_rate_limit", "limit: " + limit); } - if ("setDownloadRateLimit".equals(command)) { url = "command/setTorrentDlLimit"; @@ -329,33 +335,27 @@ public void postCommand(String command, String hash) { String[] tmpString = hash.split("&"); hash = tmpString[0]; limit = tmpString[1]; - + Log.i("download_rate_limit", "limit: " + limit); } - - // Making HTTP request - HttpHost targetHost = new HttpHost(this.hostname, this.port, - this.protocol); + HttpHost targetHost = new HttpHost(this.hostname, this.port, this.protocol); // httpclient = new DefaultHttpClient(); httpclient = getNewHttpClient(); try { - AuthScope authScope = new AuthScope(targetHost.getHostName(), - targetHost.getPort()); + AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); - UsernamePasswordCredentials credentials = new UsernamePasswordCredentials( - this.username, this.password); + UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(this.username, this.password); - httpclient.getCredentialsProvider().setCredentials(authScope, - credentials); + httpclient.getCredentialsProvider().setCredentials(authScope, credentials); HttpPost httpget = new HttpPost(url); -// Log.i("qbittorrent", "1"); + // Log.i("qbittorrent", "1"); // In order to pass the has we must set the pair name value @@ -363,45 +363,77 @@ public void postCommand(String command, String hash) { List nvps = new ArrayList(); nvps.add(bnvp); - + // Add limit - if(!limit.equals("")){ + if (!limit.equals("")) { nvps.add(new BasicNameValuePair("limit", limit)); - + } - + httpget.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); // Set content type and urls - if ("addTorrent".equals(command) || "increasePrio".equals(command) - || "decreasePrio".equals(command)) { + if ("addTorrent".equals(command) || "increasePrio".equals(command) || "decreasePrio".equals(command)) { httpget.setHeader("Content-Type", urlContentType); -// Log.i("qbittorrent", "urlContentType"); + // Log.i("qbittorrent", "urlContentType"); + } + + // Set content type and urls + if ("addTorrentFile".equals(command)) { + + Log.i("addTorrentFile", "Sending file: " + hash); + httpget.setHeader("Content-Type", urlContentType); + + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); + + // Add boundary + builder.setBoundary(boundary); + + // Add text expected by qBittorrent server + // builder.addTextBody("text", + // "Content-Disposition: form-data; name=\"torrents\"; filename=\"" + // + hash + "\"\n" + // + "Content-Type: application/x-bittorrent\n\n"); + + // Add torrent file as binary + File file = new File(hash); + // FileBody fileBody = new FileBody(file); + // builder.addPart("file", fileBody); + + builder.addBinaryBody("upfile", file, ContentType.DEFAULT_BINARY, hash); + + // Build entity + HttpEntity entity = builder.build(); + + // Set entity to http post + httpget.setEntity(entity); + } -// Log.i("qbittorrent", "2"); + // Log.i("qbittorrent", "2"); httpResponse = httpclient.execute(targetHost, httpget); -// Log.i("qbittorrent", "3"); + // Log.i("qbittorrent", "3"); HttpEntity httpEntity = httpResponse.getEntity(); -// Log.i("qbittorrent", "4"); + // Log.i("qbittorrent", "4"); is = httpEntity.getContent(); -// Log.i("qbittorrent", "5"); -// -// Log.i("parser", is.toString()); -// -// Log.i("qbittorrent", "url:" + url); -// Log.i("qbittorrent", "hostname:" + this.hostname); -// Log.i("qbittorrent", "port:" + this.port); -// Log.i("qbittorrent", "protocol:" + this.protocol); -// Log.i("qbittorrent", "username:" + this.username); -// Log.i("qbittorrent", "password:" + this.password); -// Log.i("qbittorrent", "hash:" + hash); + // Log.i("qbittorrent", "5"); + // + // Log.i("parser", is.toString()); + // + // Log.i("qbittorrent", "url:" + url); + // Log.i("qbittorrent", "hostname:" + this.hostname); + // Log.i("qbittorrent", "port:" + this.port); + // Log.i("qbittorrent", "protocol:" + this.protocol); + // Log.i("qbittorrent", "username:" + this.username); + // Log.i("qbittorrent", "password:" + this.password); + // Log.i("qbittorrent", "hash:" + hash); } @@ -419,7 +451,7 @@ public void postCommand(String command, String hash) { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources -// Log.i("qbittorrent", "finaly - goodbye!"); + // Log.i("qbittorrent", "finaly - goodbye!"); httpclient.getConnectionManager().shutdown(); } @@ -428,8 +460,7 @@ public void postCommand(String command, String hash) { // https public DefaultHttpClient getNewHttpClient() { try { - KeyStore trustStore = KeyStore.getInstance(KeyStore - .getDefaultType()); + KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); MySSLSocketFactory sf = new MySSLSocketFactory(trustStore); @@ -441,12 +472,10 @@ public DefaultHttpClient getNewHttpClient() { HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); - registry.register(new Scheme("http", PlainSocketFactory - .getSocketFactory(), 80)); + registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); - ClientConnectionManager ccm = new ThreadSafeClientConnManager( - params, registry); + ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { diff --git a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/MainActivity.java b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/MainActivity.java index 79fbdc57..93bd6124 100644 --- a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/MainActivity.java @@ -15,10 +15,6 @@ import org.json.JSONArray; import org.json.JSONObject; -import com.google.android.gms.ads.AdRequest; -import com.google.android.gms.ads.AdSize; -import com.google.android.gms.ads.AdView; - import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.FragmentManager; @@ -30,6 +26,7 @@ import android.content.SharedPreferences.Editor; import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; @@ -46,13 +43,14 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; -import android.widget.FrameLayout; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; +import com.google.android.gms.ads.AdRequest; +import com.google.android.gms.ads.AdView; + public class MainActivity extends FragmentActivity { // Params to get JSON Array @@ -76,6 +74,7 @@ public class MainActivity extends FragmentActivity { protected static final String TAG_NUMSEEDS = "num_seeds"; protected static final String TAG_RATIO = "ratio"; protected static final String TAG_PRIORITY = "priority"; + protected static final String TAG_ETA = "eta"; protected static final String TAG_SAVE_PATH = "save_path"; protected static final String TAG_CREATION_DATE = "creation_date"; protected static final String TAG_COMMENT = "comment"; @@ -178,14 +177,14 @@ protected void onCreate(Bundle savedInstanceState) { // Drawer item list objects ObjectDrawerItem[] drawerItem = new ObjectDrawerItem[8]; - drawerItem[0] = new ObjectDrawerItem(R.drawable.ic_drawer_all, "All"); - drawerItem[1] = new ObjectDrawerItem(R.drawable.ic_drawer_downloading, "Downloading"); - drawerItem[2] = new ObjectDrawerItem(R.drawable.ic_drawer_completed, "Completed"); - drawerItem[3] = new ObjectDrawerItem(R.drawable.ic_drawer_paused, "Paused"); - drawerItem[4] = new ObjectDrawerItem(R.drawable.ic_drawer_active, "Active"); - drawerItem[5] = new ObjectDrawerItem(R.drawable.ic_drawer_inactive, "Inactive"); - drawerItem[6] = new ObjectDrawerItem(R.drawable.ic_action_options, "Options"); - drawerItem[7] = new ObjectDrawerItem(R.drawable.ic_drawer_settings, "Settings"); + drawerItem[0] = new ObjectDrawerItem(R.drawable.ic_drawer_all, navigationDrawerItemTitles[0]); + drawerItem[1] = new ObjectDrawerItem(R.drawable.ic_drawer_downloading, navigationDrawerItemTitles[1]); + drawerItem[2] = new ObjectDrawerItem(R.drawable.ic_drawer_completed, navigationDrawerItemTitles[2]); + drawerItem[3] = new ObjectDrawerItem(R.drawable.ic_drawer_paused, navigationDrawerItemTitles[3]); + drawerItem[4] = new ObjectDrawerItem(R.drawable.ic_drawer_active, navigationDrawerItemTitles[4]); + drawerItem[5] = new ObjectDrawerItem(R.drawable.ic_drawer_inactive, navigationDrawerItemTitles[5]); + drawerItem[6] = new ObjectDrawerItem(R.drawable.ic_action_options, navigationDrawerItemTitles[6]); + drawerItem[7] = new ObjectDrawerItem(R.drawable.ic_drawer_settings, navigationDrawerItemTitles[7]); // Create object for drawer item OnbjectDrawerItem DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.listview_item_row, drawerItem); @@ -233,7 +232,23 @@ public void onDrawerOpened(View drawerView) { String urlTorrent = intent.getDataString(); if (urlTorrent != null && urlTorrent.length() != 0) { - addTorrent(intent.getDataString()); + + // File + Log.i("intent started", urlTorrent.substring(0, 4)); + + if (urlTorrent.substring(0, 4).equals("file")) { + // File + Log.i("FILE:", urlTorrent); + + addTorrentFile(Uri.parse(urlTorrent).getPath()); + } else { + + // URL + addTorrent(intent.getDataString()); + + // File + Log.i("WEB", urlTorrent); + } } // Fragments @@ -298,7 +313,7 @@ public void onDrawerOpened(View drawerView) { fragmentTransaction.commit(); } - + refresh(); } @@ -306,11 +321,11 @@ public void onDrawerOpened(View drawerView) { // Load Banner public void loadBanner() { - + // Look up the AdView as a resource and load a request. - adView = (AdView)this.findViewById(R.id.adView); + adView = (AdView) this.findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); - + // Start loading the ad in the background. adView.loadAd(adRequest); } @@ -655,14 +670,14 @@ public void onClick(DialogInterface dialog, int id) { case R.id.action_upload_rate_limit: - Log.i("upload_rate_limit", "upload_rate_limit"); + // Log.i("upload_rate_limit", "upload_rate_limit"); tf = this.getTorrentDetailsFragment(); if (tf != null) { position = tf.position; hash = MainActivity.lines[position].getHash(); - Log.i("upload_rate_limit", "hash: " + hash); + // Log.i("upload_rate_limit", "hash: " + hash); uploadRateLimitDialog(hash); // if (findViewById(R.id.one_frame) != null) { // getFragmentManager().popBackStack(); @@ -694,7 +709,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == SETTINGS_CODE) { - // Get options and save them as shared preferences + // Get options from server and save them as shared preferences + // locally qBittorrentOptions qso = new qBittorrentOptions(); qso.execute(new String[] { "json/preferences", "getSettings" }); @@ -842,6 +858,12 @@ public void addTorrent(String url) { qtc.execute(new String[] { "addTorrent", url }); } + public void addTorrentFile(String url) { + // Execute the task in background + qBittorrentCommand qtc = new qBittorrentCommand(); + qtc.execute(new String[] { "addTorrentFile", url }); + } + public void pauseAllTorrents() { // Execute the task in background qBittorrentCommand qtc = new qBittorrentCommand(); @@ -954,21 +976,21 @@ public void setUploadRateLimit(String hash, String uploadRateLimit) { if (uploadRateLimit != null && !uploadRateLimit.equals("")) { - Log.i("upload_rate_limit", "global_upload: " + global_upload); - Log.i("upload_rate_limit", "uploadRateLimit: " + uploadRateLimit); + // Log.i("upload_rate_limit", "global_upload: " + global_upload); + // Log.i("upload_rate_limit", "uploadRateLimit: " + + // uploadRateLimit); if (global_upload != null) { limit = (Integer.parseInt(uploadRateLimit) > Integer.parseInt(global_upload) && Integer.parseInt(global_upload) != 0) ? Integer .parseInt(global_upload) : Integer.parseInt(uploadRateLimit); - Log.i("upload_rate_limit", hash + "&limit=" + limit * 1024); + // Log.i("upload_rate_limit", hash + "&limit=" + limit * 1024); qBittorrentCommand qtc = new qBittorrentCommand(); qtc.execute(new String[] { "setUploadRateLimit", hash + "&" + limit * 1024 }); } else { - // TODO: Dialog with error message genericOkDialog(R.string.error, R.string.global_value_error); } @@ -982,20 +1004,22 @@ public void setDownloadRateLimit(String hash, String downloadRateLimit) { if (downloadRateLimit != null && !downloadRateLimit.equals("")) { - Log.i("download_rate_limit", "global_download: " + global_download); - Log.i("download_rate_limit", "downloadRateLimit: " + downloadRateLimit); + // Log.i("download_rate_limit", "global_download: " + + // global_download); + // Log.i("download_rate_limit", "downloadRateLimit: " + + // downloadRateLimit); if (global_download != null) { limit = (Integer.parseInt(downloadRateLimit) > Integer.parseInt(global_download)) ? Integer.parseInt(global_download) : Integer .parseInt(downloadRateLimit); - Log.i("download_rate_limit", hash + "&limit=" + limit * 1024); + // Log.i("download_rate_limit", hash + "&limit=" + limit * + // 1024); qBittorrentCommand qtc = new qBittorrentCommand(); qtc.execute(new String[] { "setDownloadRateLimit", hash + "&" + limit * 1024 }); } else { - // TODO: Dialog with error message genericOkDialog(R.string.error, R.string.global_value_error); } @@ -1153,10 +1177,18 @@ protected void onPostExecute(String result) { messageId = R.string.torrentAdded; } + if ("addTorrentFile".equals(result)) { + messageId = R.string.torrentFileAdded; + } + if ("pauseAll".equals(result)) { messageId = R.string.AllTorrentsPaused; } + if ("resumeAll".equals(result)) { + messageId = R.string.AllTorrentsResumed; + } + if ("increasePrio".equals(result)) { messageId = R.string.increasePrioTorrent; } @@ -1187,39 +1219,39 @@ protected void onPostExecute(String result) { switch (drawerList.getCheckedItemPosition()) { case 0: - Log.i("qBittorrentCommand", "case 0"); + // Log.i("qBittorrentCommand", "case 0"); refreshWithDelay("all", 3); break; case 1: - Log.i("qBittorrentCommand", "case 1"); + // Log.i("qBittorrentCommand", "case 1"); refreshWithDelay("downloading", 3); break; case 2: - Log.i("qBittorrentCommand", "case 2"); + // Log.i("qBittorrentCommand", "case 2"); refreshWithDelay("completed", 3); break; case 3: - Log.i("qBittorrentCommand", "case 3"); + // Log.i("qBittorrentCommand", "case 3"); refreshWithDelay("paused", 3); break; case 4: - Log.i("qBittorrentCommand", "case 4"); + // Log.i("qBittorrentCommand", "case 4"); refreshWithDelay("active", 3); break; case 5: - Log.i("qBittorrentCommand", "case 5"); + // Log.i("qBittorrentCommand", "case 5"); refreshWithDelay("inactive", 3); break; case 6: - Log.i("qBittorrentCommand", "case 6"); + // Log.i("qBittorrentCommand", "case 6"); // Select "All" torrents list selectItem(0); break; case 7: - Log.i("qBittorrentCommand", "case 7"); + // Log.i("qBittorrentCommand", "case 7"); break; default: - Log.i("qBittorrentCommand", "default"); + // Log.i("qBittorrentCommand", "default"); refreshWithDelay("all", 3); break; } @@ -1235,7 +1267,7 @@ private class qBittorrentTask extends AsyncTask { @Override protected Torrent[] doInBackground(String... params) { - String name, size, info, progress, state, hash, ratio, leechs, seeds, priority; + String name, size, info, progress, state, hash, ratio, leechs, seeds, priority, downloaded, eta; Torrent[] torrents = null; @@ -1263,15 +1295,16 @@ protected Torrent[] doInBackground(String... params) { name = json.getString(TAG_NAME); size = json.getString(TAG_SIZE); progress = String.format("%.2f", json.getDouble(TAG_PROGRESS) * 100) + "%"; - info = size + " | D:" + json.getString(TAG_DLSPEED) + " | U:" + json.getString(TAG_UPSPEED) + " | " + progress; + info = ""; state = json.getString(TAG_STATE); hash = json.getString(TAG_HASH); ratio = json.getString(TAG_RATIO); leechs = json.getString(TAG_NUMLEECHS); seeds = json.getString(TAG_NUMSEEDS); priority = json.getString(TAG_PRIORITY); + eta = json.getString(TAG_ETA); - torrents[i] = new Torrent(name, size, state, hash, info, ratio, progress, leechs, seeds, priority); + torrents[i] = new Torrent(name, size, state, hash, info, ratio, progress, leechs, seeds, priority, eta); MainActivity.names[i] = name; @@ -1302,6 +1335,14 @@ protected Torrent[] doInBackground(String... params) { torrents[i].setShareRatio(json2.getString(TAG_SHARE_RATIO)); torrents[i].setUploadLimit(json2.getString(TAG_UPLOAD_LIMIT)); torrents[i].setDownloadLimit(json2.getString(TAG_DOWNLOAD_LIMIT)); + + // Info + downloaded = torrents[i].getTotalDownloaded(); + downloaded = downloaded.substring(0, downloaded.indexOf("(") - 1); + + torrents[i].setInfo(downloaded + " " + Character.toString('\u2193') + " " + json.getString(TAG_DLSPEED) + " " + + Character.toString('\u2191') + " " + json.getString(TAG_UPSPEED) + " - " + progress + " - " + torrents[i].getEta()); + } } @@ -1385,12 +1426,9 @@ protected void onPostExecute(Torrent[] result) { } if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); - } - // Log.i("Refresh >", "About to set Adapter"); firstFragment.setListAdapter(new myAdapter()); // Create the about fragment @@ -1415,9 +1453,6 @@ protected void onPostExecute(Torrent[] result) { fragmentTransaction.commit(); - // Log.i("Refresh", "ItemList?: " + (firstFragment - // instanceof ItemstFragment)); - ListView lv = firstFragment.getListView(); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); @@ -1515,7 +1550,6 @@ protected void onPostExecute(Torrent[] result) { fragmentTransaction.commit(); } - } } diff --git a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/SettingsActivity.java b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/SettingsActivity.java index 1e3f3b77..456990af 100644 --- a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/SettingsActivity.java +++ b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/SettingsActivity.java @@ -11,23 +11,183 @@ package com.lgallardo.qbittorrentclient; import android.os.Bundle; +import android.preference.CheckBoxPreference; +import android.preference.EditTextPreference; +import android.preference.ListPreference; +import android.preference.Preference; import android.preference.PreferenceActivity; +import android.preference.PreferenceManager; +import android.util.Log; import android.view.Menu; +import android.app.Activity; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; +import android.content.Context; +import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; -public class SettingsActivity extends PreferenceActivity { +public class SettingsActivity extends PreferenceActivity implements android.content.SharedPreferences.OnSharedPreferenceChangeListener { + + private ListPreference currentServer; + private EditTextPreference hostname; + private CheckBoxPreference https; + private EditTextPreference port; + private EditTextPreference username; + private EditTextPreference password; + private CheckBoxPreference old_version; + private String currentServerValue; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); + + // Get preferences from screen + currentServer = (ListPreference) findPreference("currentServer"); + hostname = (EditTextPreference) findPreference("hostname"); + https = (CheckBoxPreference) findPreference("https"); + port = (EditTextPreference) findPreference("port"); + username = (EditTextPreference) findPreference("username"); + password = (EditTextPreference) findPreference("password"); + old_version = (CheckBoxPreference) findPreference("old_version"); + + // Get values for server + getQBittorrentServerValues(currentServer.getValue()); + + Preference pref = findPreference("currentServer"); + pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + // do whatever you want with new value + + Builder builder = new AlertDialog.Builder(SettingsActivity.this); + + // Message + builder.setMessage(R.string.settings_qbittorrent_pro_message).setTitle(R.string.settings_qbittorrent_pro_title); + + // Ok + builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + + public void onClick(DialogInterface dialog, int id) { + // User accepted the dialog + + // Set first server + currentServer.setValueIndex(0); + } + }); + + // Create dialog + AlertDialog dialog = builder.create(); + + // Show dialog + dialog.show(); + + return true; + } + }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. -// getMenuInflater().inflate(R.menu.setting, menu); + // getMenuInflater().inflate(R.menu.setting, menu); return true; } -} + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + // TODO Auto-generated method stub + + // Update values on Screen + refreshScreenValues(); + } + + @Override + public void onResume() { + super.onResume(); + getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); + + } + + @Override + public void onPause() { + getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); + + saveQBittorrentServerValues(); + super.onPause(); + } + + public void getQBittorrentServerValues(String value) { + + SharedPreferences sharedPrefs = getPreferenceManager().getSharedPreferences(); + + currentServer.setSummary(currentServer.getEntry()); + hostname.setText(sharedPrefs.getString("hostname" + value, "192.168.1.1")); + hostname.setSummary(sharedPrefs.getString("hostname" + value, "192.168.1.1")); + + https.setChecked(sharedPrefs.getBoolean("https" + value, false)); + + port.setText(sharedPrefs.getString("port" + value, "8080")); + port.setSummary(sharedPrefs.getString("port" + value, "8080")); + + username.setText(sharedPrefs.getString("username" + value, "admin")); + username.setSummary(sharedPrefs.getString("username" + value, "admin")); + + password.setText(sharedPrefs.getString("password" + value, "adminadmin")); + old_version.setChecked(sharedPrefs.getBoolean("old_version" + value, false)); + + } + + public void refreshScreenValues() { + + currentServer.setSummary(currentServer.getEntry()); + hostname.setSummary(hostname.getText()); + port.setSummary(port.getText()); + username.setSummary(username.getText()); + + } + + public void saveQBittorrentServerValues() { + + currentServerValue = currentServer.getValue(); + + // Save options locally + SharedPreferences sharedPrefs = getPreferenceManager().getSharedPreferences(); + + // SharedPreferences sharedPrefs = + // PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + Editor editor = sharedPrefs.edit(); + + if (hostname.getText().toString() != null && hostname.getText().toString() != "") { + + editor.putString("hostname" + currentServerValue, hostname.getText().toString()); + Log.i("Preferences", "Saving hostname" + currentServer.getValue()); + } + + editor.putBoolean("https" + currentServerValue, https.isChecked()); + + if (port.getText().toString() != null && port.getText().toString() != "") { + + editor.putString("port" + currentServerValue, port.getText().toString()); + } + + if (username.getText().toString() != null && username.getText().toString() != "") { + + editor.putString("username" + currentServerValue, username.getText().toString()); + } + + if (password.getText().toString() != null && password.getText().toString() != "") { + + editor.putString("password" + currentServerValue, password.getText().toString()); + } + + editor.putBoolean("old_version" + currentServerValue, old_version.isChecked()); + + // Commit changes + editor.commit(); + + } + +} \ No newline at end of file diff --git a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/Torrent.java b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/Torrent.java index 71aab8f1..7fd5fe55 100644 --- a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/Torrent.java +++ b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/Torrent.java @@ -23,6 +23,7 @@ class Torrent { private String leechs; private String seeds; private String priority; + private String eta; private String savePath; private String creationDate; private String comment; @@ -32,12 +33,11 @@ class Torrent { private String timeElapsed; private String nbConnections; private String shareRatio; - private String uploadLimit; - private String downloadLimit; - - public Torrent(String file, String size, String state, String hash, - String info, String ratio, String progress, String leechs, - String seeds, String priority) { + private String uploadLimit; + private String downloadLimit; + + public Torrent(String file, String size, String state, String hash, String info, String ratio, String progress, String leechs, String seeds, + String priority, String eta) { this.file = file; this.size = size; this.state = state; @@ -48,6 +48,7 @@ public Torrent(String file, String size, String state, String hash, this.leechs = leechs; this.seeds = seeds; this.priority = priority; + this.eta = eta; this.uploadLimit = null; this.downloadLimit = null; } @@ -129,6 +130,19 @@ public String getPriority() { return priority; } + /** + * @return the eta + */ + public String getEta() { + + // If apply, return infinity symbol + if (eta != null && Character.codePointAt(eta, 0) == 226) { + return Character.toString('\u221E'); + } + + return eta; + } + /** * @return the path */ @@ -191,11 +205,11 @@ public String getNbConnections() { public String getShareRatio() { return shareRatio; } - + public String getUploadLimit() { - + // If apply, return infinity symbol - if(uploadLimit != null && Character.codePointAt(uploadLimit, 0) == 226){ + if (uploadLimit != null && Character.codePointAt(uploadLimit, 0) == 226) { return Character.toString('\u221E'); } @@ -203,151 +217,177 @@ public String getUploadLimit() { } public String getDownloadLimit() { - + // If apply, return infinity symbol - if(downloadLimit != null && Character.codePointAt(downloadLimit, 0) == 226){ + if (downloadLimit != null && Character.codePointAt(downloadLimit, 0) == 226) { return Character.toString('\u221E'); } - + return downloadLimit; } - /** - * @param file the file to set + * @param file + * the file to set */ public void setFile(String file) { this.file = file; } /** - * @param size the size to set + * @param size + * the size to set */ public void setSize(String size) { this.size = size; } /** - * @param info the info to set + * @param info + * the info to set */ public void setInfo(String info) { this.info = info; } /** - * @param state the state to set + * @param state + * the state to set */ public void setState(String state) { this.state = state; } /** - * @param hash the hash to set + * @param hash + * the hash to set */ public void setHash(String hash) { this.hash = hash; } /** - * @param downloadSpeed the downloadSpeed to set + * @param downloadSpeed + * the downloadSpeed to set */ public void setDownloadSpeed(String downloadSpeed) { this.downloadSpeed = downloadSpeed; } /** - * @param ratio the ratio to set + * @param ratio + * the ratio to set */ public void setRatio(String ratio) { this.ratio = ratio; } /** - * @param progress the progress to set + * @param progress + * the progress to set */ public void setProgress(String progress) { this.progress = progress; } /** - * @param leechs the leechs to set + * @param leechs + * the leechs to set */ public void setLeechs(String leechs) { this.leechs = leechs; } /** - * @param seeds the seeds to set + * @param seeds + * the seeds to set */ public void setSeeds(String seeds) { this.seeds = seeds; } /** - * @param priority the priority to set + * @param priority + * the priority to set */ public void setPriority(String priority) { this.priority = priority; } /** - * @param path the path to set + * @param priority the eta to set + */ + public void setEta(String eta) { + this.eta = eta; + } + + /** + * @param path + * the path to set */ public void setSavePath(String savePath) { this.savePath = savePath; } /** - * @param creationDate the creationDate to set + * @param creationDate + * the creationDate to set */ public void setCreationDate(String creationDate) { this.creationDate = creationDate; } /** - * @param comment the comment to set + * @param comment + * the comment to set */ public void setComment(String comment) { this.comment = comment; } /** - * @param totalWasted the totalWasted to set + * @param totalWasted + * the totalWasted to set */ public void setTotalWasted(String totalWasted) { this.totalWasted = totalWasted; } /** - * @param totalUploaded the totalUploaded to set + * @param totalUploaded + * the totalUploaded to set */ public void setTotalUploaded(String totalUploaded) { this.totalUploaded = totalUploaded; } /** - * @param totalDownloaded the totalDownloaded to set + * @param totalDownloaded + * the totalDownloaded to set */ public void setTotalDownloaded(String totalDownloaded) { this.totalDownloaded = totalDownloaded; } /** - * @param timeElapsed the timeElapsed to set + * @param timeElapsed + * the timeElapsed to set */ public void setTimeElapsed(String timeElapsed) { this.timeElapsed = timeElapsed; } /** - * @param nbConnections the nbConnections to set + * @param nbConnections + * the nbConnections to set */ public void setNbConnections(String nbConnections) { this.nbConnections = nbConnections; } /** - * @param shareRatio the shareRatio to set + * @param shareRatio + * the shareRatio to set */ public void setShareRatio(String shareRatio) { this.shareRatio = shareRatio; diff --git a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java index b9902144..af9d1bd8 100644 --- a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java @@ -117,26 +117,26 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa TextView downloadRateLimitTextView = (TextView) rootView.findViewById(R.id.torrentDownloadRateLimit); nameTextView.setText(name); - sizeTextView.setText("Size: " + size); - ratioTextView.setText("Ratio: " + ratio); - progressTextView.setText("Progress: " + progress); - stateTextView.setText("State: " + state); - leechsTextView.setText("Leechs: " + leechs); - seedsTextView.setText("Seeds: " + seeds); - hashTextView.setText("Hash: " + hash); - priorityTextView.setText("Priority: " + priority); - pathTextView.setText("Save Path: " + savePath); - creationDateTextView.setText("Create Date: " + creationDate); - commentTextView.setText("Comment: " + comment); - totalWastedTextView.setText("Total Wasted: " + totalWasted); - totalUploadedTextView.setText("Tota lUploaded: " + totalUploaded); - totalDownloadedTextView.setText("Total Downloaded: " + totalDownloaded); - timeElapsedTextView.setText("Time Elapsed: " + timeElapsed); - nbConnectionsTextView.setText("Num. Connections: " + nbConnections); - shareRatioTextView.setText("Share Ratio: " + shareRatio); - uploadRateLimitTextView.setText("Upload Rate Limit: " + uploadRateLimit); - downloadRateLimitTextView.setText("Download Rate Limit: " + downloadRateLimit); - + sizeTextView.setText(size); + ratioTextView.setText(ratio); + stateTextView.setText(state); + leechsTextView.setText(leechs); + seedsTextView.setText(seeds); + progressTextView.setText(progress); + hashTextView.setText(hash); + priorityTextView.setText(priority); + pathTextView.setText(savePath); + creationDateTextView.setText(creationDate); + commentTextView.setText(comment); + totalWastedTextView.setText(totalWasted); + totalUploadedTextView.setText(totalUploaded); + totalDownloadedTextView.setText(totalDownloaded); + timeElapsedTextView.setText(timeElapsed); + nbConnectionsTextView.setText(nbConnections); + shareRatioTextView.setText(shareRatio); + uploadRateLimitTextView.setText(uploadRateLimit); + downloadRateLimitTextView.setText(downloadRateLimit); + } } catch (Exception e) { // TODO Auto-generated catch block