diff --git a/qBittorrentClient/AndroidManifest.xml b/qBittorrentClient/AndroidManifest.xml index a9b5dba2..8377d4b7 100644 --- a/qBittorrentClient/AndroidManifest.xml +++ b/qBittorrentClient/AndroidManifest.xml @@ -11,8 +11,8 @@ --> + android:versionCode="301" + android:versionName="3.0.1" > + tools:context=".TorrentActionsActivity"> + android:layout_height="wrap_content"> + android:orientation="vertical"> + android:orientation="vertical"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> - + android:text="Ratio"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> - - - - - - - - - - - - - - - - + android:orientation="vertical" + android:visibility="visible"> + android:layout_height="wrap_content" + android:layout_marginTop="10dp" + android:orientation="vertical"> - - + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:text="@string/torrent_details_content" + android:textSize="18sp" + android:textStyle="bold" /> - - - - + android:layout_height="wrap_content" + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:background="@drawable/container_dropshadow" + android:orientation="vertical"> + + + + + + - - - - - - - - - - - - - + + android:layout_height="wrap_content" + android:layout_marginTop="10dp" + android:orientation="vertical"> - - + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:text="@string/torrent_details_trackers" + android:textSize="18sp" + android:textStyle="bold" /> - - - - + android:layout_height="wrap_content" + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:background="@drawable/container_dropshadow" + android:orientation="vertical"> + + + - - - - - - + - - + android:layout_height="wrap_content" + android:layout_marginTop="10dp" + android:orientation="vertical"> + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:text="@string/torrent_details_general_info" + android:textSize="18sp" + android:textStyle="bold" /> - - - - + android:layout_height="wrap_content" + android:layout_marginBottom="5dp" + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:background="@drawable/container_dropshadow" + android:orientation="vertical"> + + diff --git a/qBittorrentClient/res/layout-sw600dp/torrent_details.xml b/qBittorrentClient/res/layout-sw600dp/torrent_details.xml index 34cbaf4c..d7d41ab1 100644 --- a/qBittorrentClient/res/layout-sw600dp/torrent_details.xml +++ b/qBittorrentClient/res/layout-sw600dp/torrent_details.xml @@ -1,4 +1,3 @@ - + tools:context=".TorrentActionsActivity"> + android:layout_height="wrap_content"> + android:orientation="vertical"> + android:orientation="vertical"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> - + android:text="Ratio"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> - - - - - - - - - - - - - - - - + android:orientation="vertical" + android:visibility="visible"> + android:layout_height="wrap_content" + android:layout_marginTop="10dp" + android:orientation="vertical"> - - + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:text="@string/torrent_details_content" + android:textSize="18sp" + android:textStyle="bold" /> - - - - + android:layout_height="wrap_content" + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:background="@drawable/container_dropshadow" + android:orientation="vertical"> + + + + + + - - - - - - - - - - - - - + + android:layout_height="wrap_content" + android:layout_marginTop="10dp" + android:orientation="vertical"> - - + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:text="@string/torrent_details_trackers" + android:textSize="18sp" + android:textStyle="bold" /> - - - - + android:layout_height="wrap_content" + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:background="@drawable/container_dropshadow" + android:orientation="vertical"> + + + - - - - - - + - - + android:layout_height="wrap_content" + android:layout_marginTop="10dp" + android:orientation="vertical"> + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:text="@string/torrent_details_general_info" + android:textSize="18sp" + android:textStyle="bold" /> - - - - + android:layout_height="wrap_content" + android:layout_marginBottom="5dp" + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:background="@drawable/container_dropshadow" + android:orientation="vertical"> + + diff --git a/qBittorrentClient/res/layout/contentfile_row.xml b/qBittorrentClient/res/layout/contentfile_row.xml new file mode 100644 index 00000000..ca77e785 --- /dev/null +++ b/qBittorrentClient/res/layout/contentfile_row.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/qBittorrentClient/res/layout/property_row.xml b/qBittorrentClient/res/layout/property_row.xml new file mode 100644 index 00000000..62eb89f1 --- /dev/null +++ b/qBittorrentClient/res/layout/property_row.xml @@ -0,0 +1,34 @@ + + + + + + + + + \ No newline at end of file diff --git a/qBittorrentClient/res/layout/torrent_details.xml b/qBittorrentClient/res/layout/torrent_details.xml index 9b10332b..2fce97a9 100644 --- a/qBittorrentClient/res/layout/torrent_details.xml +++ b/qBittorrentClient/res/layout/torrent_details.xml @@ -36,7 +36,8 @@ android:layout_marginStart="5dp" android:layout_marginTop="5dp" android:text="Torrent Name" - android:textSize="20sp" /> + android:textSize="20sp" + android:layout_gravity="center_vertical" /> - + + + android:orientation="vertical" > + + + - - - - - - - + android:layout_height="wrap_content" + android:orientation="vertical" > - - - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" > + + + - - - - - - - - - - - - - - - - - - - - + - + - + + - - + - - - - + android:layout_height="wrap_content" + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="vertical" > + + - - - - - - + - + - + + - - + - - - - + android:layout_height="wrap_content" + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="vertical" > + + - - - - - - diff --git a/qBittorrentClient/res/layout/tracker_row.xml b/qBittorrentClient/res/layout/tracker_row.xml new file mode 100644 index 00000000..5853c15e --- /dev/null +++ b/qBittorrentClient/res/layout/tracker_row.xml @@ -0,0 +1,31 @@ + + + + + + + + + + \ No newline at end of file diff --git a/qBittorrentClient/res/values-es/strings.xml b/qBittorrentClient/res/values-es/strings.xml index aaef3514..cac3a12b 100644 --- a/qBittorrentClient/res/values-es/strings.xml +++ b/qBittorrentClient/res/values-es/strings.xml @@ -163,5 +163,9 @@ Agregar URL aquí Límite de bajada (KiB/s) Límite de subida (KiB/s) + Trackers + Propiedades + Archivos + Configuración \ No newline at end of file diff --git a/qBittorrentClient/res/values-fr/strings.xml b/qBittorrentClient/res/values-fr/strings.xml index ea6ffc50..9bc4d4ec 100644 --- a/qBittorrentClient/res/values-fr/strings.xml +++ b/qBittorrentClient/res/values-fr/strings.xml @@ -163,5 +163,9 @@ Ajouter URL ici Limite de vitesse de téléchargement (KiB/s) Limite de vitesse de charge (KiB/s) + Trackers + Propriétés + Paramètres + Fichiers \ No newline at end of file diff --git a/qBittorrentClient/res/values-it-rIT/strings.xml b/qBittorrentClient/res/values-it-rIT/strings.xml index 0a1f83f2..ca7c26a9 100644 --- a/qBittorrentClient/res/values-it-rIT/strings.xml +++ b/qBittorrentClient/res/values-it-rIT/strings.xml @@ -163,5 +163,9 @@ Aggiungi URL qui: Limite di velocità di download (KiB/s) Limite di velocità di upload (KiB/s) + Trackers + Proprietà + Impostazioni + File \ No newline at end of file diff --git a/qBittorrentClient/res/values-pl/strings.xml b/qBittorrentClient/res/values-pl/strings.xml index 7170e188..990614a1 100644 --- a/qBittorrentClient/res/values-pl/strings.xml +++ b/qBittorrentClient/res/values-pl/strings.xml @@ -163,5 +163,9 @@ Dodaj URL tutaj Szybkość pobierania limitu (KiB/s) Wskaźnik obciążenia limitu (KiB/s) + Trackers + Właściwości + Ustawienia + Pliki \ No newline at end of file diff --git a/qBittorrentClient/res/values-pt-rBR/strings.xml b/qBittorrentClient/res/values-pt-rBR/strings.xml index f60715cf..cfe44b4f 100644 --- a/qBittorrentClient/res/values-pt-rBR/strings.xml +++ b/qBittorrentClient/res/values-pt-rBR/strings.xml @@ -164,5 +164,9 @@ Adicionar URL aqui Limite de taxa de download (KiB/s) Limite da taxa de carga (KiB/s) + Trackers + Propriedades + Definições + Arquivos \ No newline at end of file diff --git a/qBittorrentClient/res/values-pt-rPT/strings.xml b/qBittorrentClient/res/values-pt-rPT/strings.xml index cc338984..f4aeee4d 100644 --- a/qBittorrentClient/res/values-pt-rPT/strings.xml +++ b/qBittorrentClient/res/values-pt-rPT/strings.xml @@ -163,5 +163,9 @@ Adicionar URL aqui Limite de taxa de download (KiB/s) Limite da taxa de carga (KiB/s) + Trackers + Propriedades + Definições + Arquivos \ No newline at end of file diff --git a/qBittorrentClient/res/values-sv/strings.xml b/qBittorrentClient/res/values-sv/strings.xml index e61683e1..3ff41b5a 100644 --- a/qBittorrentClient/res/values-sv/strings.xml +++ b/qBittorrentClient/res/values-sv/strings.xml @@ -157,4 +157,10 @@ Hämta hastighet: Storlek: Uppladdningshastighet: + Stäng navigering låda + Öppen navigering låda + Filer + Egenskaper + Trackers + Inställningar \ No newline at end of file diff --git a/qBittorrentClient/res/values/strings.xml b/qBittorrentClient/res/values/strings.xml index 4cb983b9..cbe38359 100644 --- a/qBittorrentClient/res/values/strings.xml +++ b/qBittorrentClient/res/values/strings.xml @@ -86,6 +86,9 @@ No torrents found Use the drawer menu to choose an option Size: + Properties + Files + Trackers General info Save path: Ratio: diff --git a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/ContentFile.java b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/ContentFile.java new file mode 100644 index 00000000..8541a837 --- /dev/null +++ b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/ContentFile.java @@ -0,0 +1,55 @@ +package com.lgallardo.qbittorrentclient; + +public class ContentFile { + + private String name; + private String size; + private Double progress; + private int priority; + + public ContentFile(String name, String size, Double progress, int priority) { + + this.name = name; + this.size = size; + this.progress = progress; + this.priority = priority; + + } + + public String getName() { + return name; + } + + public String getSize() { + return size; + } + + public Double getProgress() { + return progress; + } + + public int getPriority() { + return priority; + } + + public void setName(String name) { + this.name = name; + } + + public void setSize(String size) { + this.size = size; + } + + public void setProgress(Double progress) { + this.progress = progress; + } + + public void setPriority(int priority) { + this.priority = priority; + } + + public String getProgressAsString(){ + return String.format("%.2f", this.progress * 100) + "%"; + } + +} diff --git a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/DrawerItemCustomAdapter.java b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/DrawerItemCustomAdapter.java index ebc98749..1f311da1 100644 --- a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/DrawerItemCustomAdapter.java +++ b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/DrawerItemCustomAdapter.java @@ -12,7 +12,6 @@ import android.app.Activity; import android.content.Context; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -37,7 +36,6 @@ public DrawerItemCustomAdapter(Context mContext, int layoutResourceId, @Override public View getView(int position, View convertView, ViewGroup parent) { - Log.i("Adapter", "getView reached"); View listItem = convertView; diff --git a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java index 58dbeec0..3ffb120e 100644 --- a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java @@ -4,15 +4,14 @@ * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html - * + * * Contributors: * Luis M. Gallardo D. - initial implementation ******************************************************************************/ package com.lgallardo.qbittorrentclient; -import org.json.JSONObject; - import android.app.Fragment; +import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; @@ -21,386 +20,735 @@ import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.LinearLayout; +import android.widget.ListAdapter; import android.widget.ListView; +import android.widget.ProgressBar; import android.widget.TextView; -import android.widget.Toast; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdView; +import org.json.JSONArray; +import org.json.JSONObject; + public class TorrentDetailsFragment extends Fragment { - // Torrent variables - String name, info, hash, ratio, size, progress, state, leechs, seeds, priority, savePath, creationDate, comment, totalWasted, totalUploaded, - totalDownloaded, timeElapsed, nbConnections, shareRatio, uploadRateLimit, downloadRateLimit, downloaded, eta, downloadSpeed, uploadSpeed, - percentage = ""; - - String hostname; - String protocol; - int port; - String username; - String password; - String url; - - int position; - - JSONObject json2; - - private AdView adView; - private View rootView; - - public TorrentDetailsFragment() { - } - - public void setPosition(int position) { - this.position = position; - } - - public int getPosition() { - return this.position; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - - // Restore last position from savedInstanceState - if (savedInstanceState != null) { - // Restore last state for checked position. - position = savedInstanceState.getInt("itemPosition", 0); - } - - // Tell the host activity that your fragment has menu options that it - // wants to add/replace/delete using the onCreateOptionsMenu method. - setHasOptionsMenu(true); - - rootView = inflater.inflate(R.layout.torrent_details, container, false); - - savePath = ""; - creationDate = ""; - comment = ""; - uploadRateLimit = ""; - downloadRateLimit = ""; - totalWasted = ""; - totalUploaded = ""; - totalDownloaded = ""; - timeElapsed = ""; - nbConnections = ""; - shareRatio = ""; - - try { - - if (savedInstanceState != null) { - - // Get saved values - - name = savedInstanceState.getString("torrentDetailName", ""); - size = savedInstanceState.getString("torrentDetailSize", ""); - hash = savedInstanceState.getString("torrentDetailHash", ""); - ratio = savedInstanceState.getString("torrentDetailRatio", ""); - state = savedInstanceState.getString("torrentDetailState", ""); - leechs = savedInstanceState.getString("torrentDetailLeechs", ""); - seeds = savedInstanceState.getString("torrentDetailSeeds", ""); - progress = savedInstanceState.getString("torrentDetailProgress", ""); - priority = savedInstanceState.getString("torrentDetailPriority", ""); - eta = savedInstanceState.getString("torrentDetailEta", ""); - uploadSpeed = savedInstanceState.getString("torrentDetailUploadSpeed", ""); - downloadSpeed = savedInstanceState.getString("torrentDetailDownloadSpeed", ""); - downloaded = savedInstanceState.getString("torrentDetailDownloaded", ""); - - } else { - - name = MainActivity.lines[position].getFile(); - size = MainActivity.lines[position].getSize(); - hash = MainActivity.lines[position].getHash(); - ratio = MainActivity.lines[position].getRatio(); - progress = MainActivity.lines[position].getProgress(); - state = MainActivity.lines[position].getState(); - leechs = MainActivity.lines[position].getLeechs(); - seeds = MainActivity.lines[position].getSeeds(); - hash = MainActivity.lines[position].getHash(); - priority = MainActivity.lines[position].getPriority(); - eta = MainActivity.lines[position].getEta(); - uploadSpeed = MainActivity.lines[position].getUploadSpeed(); - downloadSpeed = MainActivity.lines[position].getDownloadSpeed(); - downloaded = MainActivity.lines[position].getDownloaded(); - } - - TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName); - TextView sizeTextView = (TextView) rootView.findViewById(R.id.torrentSize); - TextView ratioTextView = (TextView) rootView.findViewById(R.id.torrentRatio); - TextView progressTextView = (TextView) rootView.findViewById(R.id.torrentProgress); - TextView stateTextView = (TextView) rootView.findViewById(R.id.torrentState); - TextView leechsTextView = (TextView) rootView.findViewById(R.id.torrentLeechs); - TextView seedsTextView = (TextView) rootView.findViewById(R.id.torrentSeeds); - TextView hashTextView = (TextView) rootView.findViewById(R.id.torrentHash); - TextView etaTextView = (TextView) rootView.findViewById(R.id.torrentEta); - TextView priorityTextView = (TextView) rootView.findViewById(R.id.torrentPriority); - TextView downloadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentDownloadSpeed); - TextView uploadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentUploadSpeed); - TextView pathTextView = (TextView) rootView.findViewById(R.id.torrentSavePath); - TextView creationDateTextView = (TextView) rootView.findViewById(R.id.torrentCreationDate); - TextView commentTextView = (TextView) rootView.findViewById(R.id.torrentComment); - TextView totalWastedTextView = (TextView) rootView.findViewById(R.id.torrentTotalWasted); - TextView totalUploadedTextView = (TextView) rootView.findViewById(R.id.torrentTotalUploaded); - TextView totalDownloadedTextView = (TextView) rootView.findViewById(R.id.torrentTotalDownloaded); - TextView timeElapsedTextView = (TextView) rootView.findViewById(R.id.torrentTimeElapsed); - TextView nbConnectionsTextView = (TextView) rootView.findViewById(R.id.torrentNbConnections); - TextView shareRatioTextView = (TextView) rootView.findViewById(R.id.torrentShareRatio); - TextView uploadRateLimitTextView = (TextView) rootView.findViewById(R.id.torrentUploadRateLimit); - TextView downloadRateLimitTextView = (TextView) rootView.findViewById(R.id.torrentDownloadRateLimit); - - nameTextView.setText(name); - sizeTextView.setText(size); - ratioTextView.setText(ratio); - stateTextView.setText(state); - leechsTextView.setText(leechs); - seedsTextView.setText(seeds); - progressTextView.setText(progress); - hashTextView.setText(hash); - etaTextView.setText(eta); - priorityTextView.setText(priority); - downloadSpeedTextView.setText(downloadSpeed); - uploadSpeedTextView.setText(uploadSpeed); - - 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); - - // Set status icon - - nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.checking, 0, 0, 0); - - if ("pausedUP".equals(state) || "pausedDL".equals(state)) { - nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.paused, 0, 0, 0); - } - - if ("stalledUP".equals(state)) { - nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.stalledup, 0, 0, 0); - } - - if ("stalledDL".equals(state)) { - nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.stalleddl, 0, 0, 0); - } - - if ("downloading".equals(state)) { - nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.downloading, 0, 0, 0); - } - - if ("uploading".equals(state)) { - nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.uploading, 0, 0, 0); - } - - if ("queuedDL".equals(state) || "queuedUP".equals(state)) { - nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.queued, 0, 0, 0); - } - - // Execute the task in background - qBittorrentGeneralInfoTask qgit = new qBittorrentGeneralInfoTask(); - - qgit.execute(new View[] { rootView }); - - } catch (Exception e) { - // TODO Auto-generated catch block - Log.e("TorrentDetailsFragment - onCreateView", e.toString()); - } - - // Show progressBar - if (MainActivity.progressBar != null) { - MainActivity.progressBar.setVisibility(View.VISIBLE); - } - - // Load banner - loadBanner(); - - // Execute the task in background - qBittorrentGeneralInfoTask qgit = new qBittorrentGeneralInfoTask(); - - qgit.execute(new View[] { rootView }); - return rootView; - } - - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - outState.putString("torrentDetailName", name); - outState.putString("torrentDetailSize", size); - outState.putString("torrentDetailHash", hash); - outState.putString("torrentDetailRatio", ratio); - outState.putString("torrentDetailState", state); - outState.putString("torrentDetailLeechs", leechs); - outState.putString("torrentDetailSeeds", seeds); - outState.putString("torrentDetailProgress", progress); - outState.putString("torrentDetailPriority", priority); - outState.putString("torrentDetailEta", eta); - outState.putString("torrentDetailUploadSpeed", uploadSpeed); - outState.putString("torrentDetailDownloadSpeed", downloadSpeed); - outState.putString("torrentDetailDownloaded", downloaded); - - } - - // @Override - public void onListItemClick(ListView parent, View v, int position, long id) { - - } - - // @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - if (menu != null) { - - if (getActivity().findViewById(R.id.one_frame) != null) { - menu.findItem(R.id.action_refresh).setVisible(false); - } - - menu.findItem(R.id.action_search).setVisible(false); - menu.findItem(R.id.action_resume_all).setVisible(false); - menu.findItem(R.id.action_pause_all).setVisible(false); - menu.findItem(R.id.action_add).setVisible(false); - - menu.findItem(R.id.action_resume).setVisible(true); - menu.findItem(R.id.action_pause).setVisible(true); - menu.findItem(R.id.action_increase_prio).setVisible(true); - menu.findItem(R.id.action_decrease_prio).setVisible(true); - menu.findItem(R.id.action_delete).setVisible(true); - menu.findItem(R.id.action_delete_drive).setVisible(true); - menu.findItem(R.id.action_download_rate_limit).setVisible(true); - menu.findItem(R.id.action_upload_rate_limit).setVisible(true); - - } - } - - // Load Banner - public void loadBanner() { - - // Get the adView. - adView = (AdView) getActivity().findViewById(R.id.adView); - - AdRequest adRequest = new AdRequest.Builder().build(); - - // Start loading the ad in the background. - adView.loadAd(adRequest); - - } - - // Here is where the action happens - private class qBittorrentGeneralInfoTask extends AsyncTask { - - protected View[] doInBackground(View... rootViews) { - // Get torrent's extra info - url = "json/propertiesGeneral/"; - - try { - - JSONParser jParser = new JSONParser(MainActivity.hostname, MainActivity.subfolder, MainActivity.protocol, MainActivity.port, - MainActivity.username, MainActivity.password, MainActivity.connection_timeout, MainActivity.data_timeout); - - json2 = jParser.getJSONFromUrl(url + hash); - - MainActivity.lines[position].setSavePath(json2.getString(MainActivity.TAG_SAVE_PATH)); - MainActivity.lines[position].setCreationDate(json2.getString(MainActivity.TAG_CREATION_DATE)); - MainActivity.lines[position].setComment(json2.getString(MainActivity.TAG_COMMENT)); - MainActivity.lines[position].setTotalWasted(json2.getString(MainActivity.TAG_TOTAL_WASTED)); - MainActivity.lines[position].setTotalUploaded(json2.getString(MainActivity.TAG_TOTAL_UPLOADED)); - MainActivity.lines[position].setTotalDownloaded(json2.getString(MainActivity.TAG_TOTAL_DOWNLOADED)); - MainActivity.lines[position].setTimeElapsed(json2.getString(MainActivity.TAG_TIME_ELAPSED)); - MainActivity.lines[position].setNbConnections(json2.getString(MainActivity.TAG_NB_CONNECTIONS)); - MainActivity.lines[position].setShareRatio(json2.getString(MainActivity.TAG_SHARE_RATIO)); - MainActivity.lines[position].setUploadLimit(json2.getString(MainActivity.TAG_UPLOAD_LIMIT)); - MainActivity.lines[position].setDownloadLimit(json2.getString(MainActivity.TAG_DOWNLOAD_LIMIT)); - - } catch (Exception e) { - - // MainActivity.lines[position].setSavePath(" "); - // MainActivity.lines[position].setCreationDate(" "); - // MainActivity.lines[position].setComment(" "); - // MainActivity.lines[position].setTotalWasted(" "); - // MainActivity.lines[position].setTotalUploaded(" "); - // MainActivity.lines[position].setTotalDownloaded(" "); - // MainActivity.lines[position].setTimeElapsed(" "); - // MainActivity.lines[position].setNbConnections(" "); - // MainActivity.lines[position].setShareRatio(" "); - // MainActivity.lines[position].setUploadLimit(" "); - // MainActivity.lines[position].setDownloadLimit(" "); - - Log.e("TorrentFragment:", e.toString()); - - } - - return rootViews; - - } - - @Override - protected void onPostExecute(View[] rootViews) { - - View rootView = rootViews[0]; - - TextView pathTextView, creationDateTextView, commentTextView, uploadRateLimitTextView, downloadRateLimitTextView, totalWastedTextView, totalUploadedTextView, totalDownloadedTextView, timeElapsedTextView, nbConnectionsTextView, shareRatioTextView = null; - - pathTextView = (TextView) rootView.findViewById(R.id.torrentSavePath); - creationDateTextView = (TextView) rootView.findViewById(R.id.torrentCreationDate); - commentTextView = (TextView) rootView.findViewById(R.id.torrentComment); - uploadRateLimitTextView = (TextView) rootView.findViewById(R.id.torrentUploadRateLimit); - downloadRateLimitTextView = (TextView) rootView.findViewById(R.id.torrentDownloadRateLimit); - totalWastedTextView = (TextView) rootView.findViewById(R.id.torrentTotalWasted); - totalUploadedTextView = (TextView) rootView.findViewById(R.id.torrentTotalUploaded); - totalDownloadedTextView = (TextView) rootView.findViewById(R.id.torrentTotalDownloaded); - timeElapsedTextView = (TextView) rootView.findViewById(R.id.torrentTimeElapsed); - nbConnectionsTextView = (TextView) rootView.findViewById(R.id.torrentNbConnections); - shareRatioTextView = (TextView) rootView.findViewById(R.id.torrentShareRatio); - - savePath = MainActivity.lines[position].getSavePath(); - creationDate = MainActivity.lines[position].getCreationDate(); - comment = MainActivity.lines[position].getComment(); - uploadRateLimit = MainActivity.lines[position].getUploadLimit(); - downloadRateLimit = MainActivity.lines[position].getDownloadLimit(); - totalWasted = MainActivity.lines[position].getTotalWasted(); - totalUploaded = MainActivity.lines[position].getTotalUploaded(); - totalDownloaded = MainActivity.lines[position].getTotalDownloaded(); - timeElapsed = MainActivity.lines[position].getTimeElapsed(); - nbConnections = MainActivity.lines[position].getNbConnections(); - shareRatio = MainActivity.lines[position].getShareRatio(); - - pathTextView.setText(savePath); - creationDateTextView.setText(creationDate); - commentTextView.setText(comment); - uploadRateLimitTextView.setText(uploadRateLimit); - downloadRateLimitTextView.setText(downloadRateLimit); - totalWastedTextView.setText(totalWasted); - totalUploadedTextView.setText(totalUploaded); - totalDownloadedTextView.setText(totalDownloaded); - timeElapsedTextView.setText(timeElapsed); - nbConnectionsTextView.setText(nbConnections); - shareRatioTextView.setText(shareRatio); - - try { - if (json2 == null) { - Toast.makeText(getActivity(), R.string.torrent_details_cant_general_info, Toast.LENGTH_SHORT).show(); - } - } catch (Exception e) { - // TODO Auto-generated catch block - - } - - // Hide progressBar - if (MainActivity.progressBar != null) { - MainActivity.progressBar.setVisibility(View.INVISIBLE); - } - - } - - } + // Torrent variables + String name, info, hash, ratio, size, progress, state, leechs, seeds, priority, savePath, creationDate, comment, totalWasted, totalUploaded, + totalDownloaded, timeElapsed, nbConnections, shareRatio, uploadRateLimit, downloadRateLimit, downloaded, eta, downloadSpeed, uploadSpeed, + percentage = ""; + + String hostname; + String protocol; + int port; + String username; + String password; + String url; + + int position; + + JSONObject json2; + + // Arrays for holding retrieved data + static ContentFile[] files; + static Tracker[] trackers; + static String[] names, trackerNames; + + // TAGS + 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"; + protected static final String TAG_TOTAL_WASTED = "total_wasted"; + protected static final String TAG_TOTAL_UPLOADED = "total_uploaded"; + protected static final String TAG_TOTAL_DOWNLOADED = "total_downloaded"; + protected static final String TAG_TIME_ELAPSED = "time_elapsed"; + protected static final String TAG_NB_CONNECTIONS = "nb_connections"; + protected static final String TAG_SHARE_RATIO = "share_ratio"; + protected static final String TAG_UPLOAD_LIMIT = "up_limit"; + protected static final String TAG_DOWNLOAD_LIMIT = "dl_limit"; + protected static final String TAG_URL = "url"; + + + // Adapters + myFileAdapter fileAdpater; + myTrackerAdapter trackerAdapter; + myPropertyAdapter propertyAdapter; + + private AdView adView; + private View rootView; + + public TorrentDetailsFragment() { + } + + public void setPosition(int position) { + this.position = position; + } + + public int getPosition() { + return this.position; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + // Restore last position from savedInstanceState + if (savedInstanceState != null) { + // Restore last state for checked position. + position = savedInstanceState.getInt("itemPosition", 0); + } + + // Tell the host activity that your fragment has menu options that it + // wants to add/replace/delete using the onCreateOptionsMenu method. + setHasOptionsMenu(true); + + rootView = inflater.inflate(R.layout.torrent_details, container, false); + + savePath = ""; + creationDate = ""; + comment = ""; + uploadRateLimit = ""; + downloadRateLimit = ""; + totalWasted = ""; + totalUploaded = ""; + totalDownloaded = ""; + timeElapsed = ""; + nbConnections = ""; + shareRatio = ""; + + try { + + if (savedInstanceState != null) { + + // Get saved values + + name = savedInstanceState.getString("torrentDetailName", ""); + size = savedInstanceState.getString("torrentDetailSize", ""); + hash = savedInstanceState.getString("torrentDetailHash", ""); + ratio = savedInstanceState.getString("torrentDetailRatio", ""); + state = savedInstanceState.getString("torrentDetailState", ""); + leechs = savedInstanceState.getString("torrentDetailLeechs", ""); + seeds = savedInstanceState.getString("torrentDetailSeeds", ""); + progress = savedInstanceState.getString("torrentDetailProgress", ""); + priority = savedInstanceState.getString("torrentDetailPriority", ""); + eta = savedInstanceState.getString("torrentDetailEta", ""); + uploadSpeed = savedInstanceState.getString("torrentDetailUploadSpeed", ""); + downloadSpeed = savedInstanceState.getString("torrentDetailDownloadSpeed", ""); + downloaded = savedInstanceState.getString("torrentDetailDownloaded", ""); + + } else { + + name = MainActivity.lines[position].getFile(); + size = MainActivity.lines[position].getSize(); + hash = MainActivity.lines[position].getHash(); + ratio = MainActivity.lines[position].getRatio(); + progress = MainActivity.lines[position].getProgress(); + state = MainActivity.lines[position].getState(); + leechs = MainActivity.lines[position].getLeechs(); + seeds = MainActivity.lines[position].getSeeds(); + hash = MainActivity.lines[position].getHash(); + priority = MainActivity.lines[position].getPriority(); + eta = MainActivity.lines[position].getEta(); + uploadSpeed = MainActivity.lines[position].getUploadSpeed(); + downloadSpeed = MainActivity.lines[position].getDownloadSpeed(); + downloaded = MainActivity.lines[position].getDownloaded(); + } + + TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName); + TextView sizeTextView = (TextView) rootView.findViewById(R.id.torrentSize); + TextView ratioTextView = (TextView) rootView.findViewById(R.id.torrentRatio); + TextView progressTextView = (TextView) rootView.findViewById(R.id.torrentProgress); + TextView stateTextView = (TextView) rootView.findViewById(R.id.torrentState); + TextView leechsTextView = (TextView) rootView.findViewById(R.id.torrentLeechs); + TextView seedsTextView = (TextView) rootView.findViewById(R.id.torrentSeeds); + TextView hashTextView = (TextView) rootView.findViewById(R.id.torrentHash); + TextView etaTextView = (TextView) rootView.findViewById(R.id.torrentEta); + TextView priorityTextView = (TextView) rootView.findViewById(R.id.torrentPriority); + TextView downloadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentDownloadSpeed); + TextView uploadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentUploadSpeed); + +// TextView pathTextView = (TextView) rootView.findViewById(R.id.torrentSavePath); +// TextView creationDateTextView = (TextView) rootView.findViewById(R.id.torrentCreationDate); +// TextView commentTextView = (TextView) rootView.findViewById(R.id.torrentComment); +// TextView totalWastedTextView = (TextView) rootView.findViewById(R.id.torrentTotalWasted); +// TextView totalUploadedTextView = (TextView) rootView.findViewById(R.id.torrentTotalUploaded); +// TextView totalDownloadedTextView = (TextView) rootView.findViewById(R.id.torrentTotalDownloaded); +// TextView timeElapsedTextView = (TextView) rootView.findViewById(R.id.torrentTimeElapsed); +// TextView nbConnectionsTextView = (TextView) rootView.findViewById(R.id.torrentNbConnections); +// TextView shareRatioTextView = (TextView) rootView.findViewById(R.id.torrentShareRatio); +// TextView uploadRateLimitTextView = (TextView) rootView.findViewById(R.id.torrentUploadRateLimit); +// TextView downloadRateLimitTextView = (TextView) rootView.findViewById(R.id.torrentDownloadRateLimit); + + nameTextView.setText(name); + sizeTextView.setText(size); + ratioTextView.setText(ratio); + stateTextView.setText(state); + leechsTextView.setText(leechs); + seedsTextView.setText(seeds); + progressTextView.setText(progress); + hashTextView.setText(hash); + etaTextView.setText(eta); + priorityTextView.setText(priority); + downloadSpeedTextView.setText(downloadSpeed); + uploadSpeedTextView.setText(uploadSpeed); + +// 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); + + // Set status icon + + nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.checking, 0, 0, 0); + + if ("pausedUP".equals(state) || "pausedDL".equals(state)) { + nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.paused, 0, 0, 0); + } + + if ("stalledUP".equals(state)) { + nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.stalledup, 0, 0, 0); + } + + if ("stalledDL".equals(state)) { + nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.stalleddl, 0, 0, 0); + } + + if ("downloading".equals(state)) { + nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.downloading, 0, 0, 0); + } + + if ("uploading".equals(state)) { + nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.uploading, 0, 0, 0); + } + + if ("queuedDL".equals(state) || "queuedUP".equals(state)) { + nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.queued, 0, 0, 0); + } + + // Show progressBar + if (MainActivity.progressBar != null) { + MainActivity.progressBar.setVisibility(View.VISIBLE); + } + + // Get Content files in background + qBittorrentContentFile qcf = new qBittorrentContentFile(); + qcf.execute(new View[]{rootView}); + + // Get trackers in background + qBittorrentTrackers qt = new qBittorrentTrackers(); + qt.execute(new View[]{rootView}); + + // get general info in background + qBittorrentGeneralInfoTask qgit = new qBittorrentGeneralInfoTask(); + qgit.execute(new View[]{rootView}); + + } catch (Exception e) { + // TODO Auto-generated catch block + Log.e("TorrentDetailsFragment - onCreateView", e.toString()); + } + + // Load banner + loadBanner(); + + return rootView; + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putString("torrentDetailName", name); + outState.putString("torrentDetailSize", size); + outState.putString("torrentDetailHash", hash); + outState.putString("torrentDetailRatio", ratio); + outState.putString("torrentDetailState", state); + outState.putString("torrentDetailLeechs", leechs); + outState.putString("torrentDetailSeeds", seeds); + outState.putString("torrentDetailProgress", progress); + outState.putString("torrentDetailPriority", priority); + outState.putString("torrentDetailEta", eta); + outState.putString("torrentDetailUploadSpeed", uploadSpeed); + outState.putString("torrentDetailDownloadSpeed", downloadSpeed); + outState.putString("torrentDetailDownloaded", downloaded); + + } + + // @Override + public void onListItemClick(ListView parent, View v, int position, long id) { + + } + + // @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + if (menu != null) { + + if (getActivity().findViewById(R.id.one_frame) != null) { + menu.findItem(R.id.action_refresh).setVisible(false); + } + + menu.findItem(R.id.action_search).setVisible(false); + menu.findItem(R.id.action_resume_all).setVisible(false); + menu.findItem(R.id.action_pause_all).setVisible(false); + menu.findItem(R.id.action_add).setVisible(false); + + menu.findItem(R.id.action_resume).setVisible(true); + menu.findItem(R.id.action_pause).setVisible(true); + menu.findItem(R.id.action_increase_prio).setVisible(true); + menu.findItem(R.id.action_decrease_prio).setVisible(true); + menu.findItem(R.id.action_delete).setVisible(true); + menu.findItem(R.id.action_delete_drive).setVisible(true); + menu.findItem(R.id.action_download_rate_limit).setVisible(true); + menu.findItem(R.id.action_upload_rate_limit).setVisible(true); + + } + } + + // Load Banner + public void loadBanner() { + + // Get the adView. + adView = (AdView) getActivity().findViewById(R.id.adView); + + AdRequest adRequest = new AdRequest.Builder().build(); + + // Start loading the ad in the background. + adView.loadAd(adRequest); + + } + + + // // Here is where the action happens + private class qBittorrentContentFile extends AsyncTask { + + String name, size; + Double progress; + int priority; + + protected View[] doInBackground(View... rootViews) { + // Get torrent's extra info + url = "json/propertiesFiles/"; + + files = null; + names = null; + + try { + + JSONParser jParser = new JSONParser(MainActivity.hostname, MainActivity.subfolder, MainActivity.protocol, MainActivity.port, + MainActivity.username, MainActivity.password, MainActivity.connection_timeout, MainActivity.data_timeout); + + JSONArray jArray = jParser.getJSONArrayFromUrl(url + hash); + + if (jArray != null) { + + files = new ContentFile[jArray.length()]; + TorrentDetailsFragment.names = new String[jArray.length()]; + + for (int i = 0; i < jArray.length(); i++) { + + JSONObject json = jArray.getJSONObject(i); + + name = json.getString(MainActivity.TAG_NAME); + size = json.getString(MainActivity.TAG_SIZE).replace(",", "."); + progress = json.getDouble(MainActivity.TAG_PROGRESS); + priority = json.getInt(MainActivity.TAG_PRIORITY); + + files[i] = new ContentFile(name, size, progress, priority); + names[i] = name; + + } + + } + + } catch (Exception e) { + + Log.e("TorrentFragment:", e.toString()); + + } + + return rootViews; + + } + + @Override + protected void onPostExecute(View[] rootViews) { + + try { + + View rootView = rootViews[0]; + + fileAdpater = new myFileAdapter(getActivity(), names, files); + + ListView lv = (ListView) rootView.findViewById(R.id.theList); + + lv.setAdapter(fileAdpater); + + setListViewHeightBasedOnChildren(lv); + + } catch (Exception e) { + // TODO Auto-generated catch block + Log.e("Content2", e.toString()); + + } + + } + + } + + // // Here is where the action happens + private class qBittorrentTrackers extends AsyncTask { + + String url; + + protected View[] doInBackground(View... rootViews) { + // Get torrent's extra info + url = "json/propertiesTrackers/"; + + trackers = null; + trackerNames = null; + + try { + + JSONParser jParser = new JSONParser(MainActivity.hostname, MainActivity.subfolder, MainActivity.protocol, MainActivity.port, + MainActivity.username, MainActivity.password, MainActivity.connection_timeout, MainActivity.data_timeout); + + JSONArray jArray = jParser.getJSONArrayFromUrl(url + hash); + + if (jArray != null) { + + trackers = new Tracker[jArray.length()]; + TorrentDetailsFragment.trackerNames = new String[jArray.length()]; + + for (int i = 0; i < jArray.length(); i++) { + + JSONObject json = jArray.getJSONObject(i); + + url = json.getString(TAG_URL); + + trackers[i] = new Tracker(url); + trackerNames[i] = url; + + } + + } + + } catch (Exception e) { + + Log.e("TorrentFragment:", e.toString()); + + } + + return rootViews; + + } + + @Override + protected void onPostExecute(View[] rootViews) { + + try { + + View rootView = rootViews[0]; + + trackerAdapter = new myTrackerAdapter(getActivity(), trackerNames, trackers); + + LinearLayout layout = (LinearLayout) rootView.findViewById(R.id.trackers); + + for (int i = 0; i < trackerAdapter.getCount(); i++) { + View item = trackerAdapter.getView(i, null, null); + layout.addView(item); + } + + } catch (Exception e) { + // TODO Auto-generated catch block + Log.e("Trackers", e.toString()); + + } + + } + + } + + // Here is where the action happens + private class qBittorrentGeneralInfoTask extends AsyncTask { + + String[] labels; + String[] values; + + protected View[] doInBackground(View... rootViews) { + // Get torrent's extra info + url = "json/propertiesGeneral/"; + + try { + + JSONParser jParser = new JSONParser(MainActivity.hostname, MainActivity.subfolder, MainActivity.protocol, MainActivity.port, + MainActivity.username, MainActivity.password, MainActivity.connection_timeout, MainActivity.data_timeout); + + json2 = jParser.getJSONFromUrl(url + hash); + + if (json2 != null && json2.length() > 0) { + + labels = new String[11]; + values = new String[11]; + + // Save path + labels[0] = getString(R.string.torrent_details_save_path); + values[0] = json2.getString(TAG_SAVE_PATH); + + // Creation date + labels[1] = getString(R.string.torrent_details_created_date); + values[1] = json2.getString(TAG_CREATION_DATE); + + // Comment + labels[2] = getString(R.string.torrent_details_comment); + values[2] = json2.getString(TAG_COMMENT); + + // Total wasted + labels[3] = getString(R.string.torrent_details_total_wasted); + values[3] = json2.getString(TAG_TOTAL_WASTED); + + // Total uploaded + labels[4] = getString(R.string.torrent_details_total_uploaded); + values[4] = json2.getString(TAG_TOTAL_UPLOADED); + + // Total downloaded + labels[5] = getString(R.string.torrent_details_total_downloaded); + values[5] = json2.getString(TAG_TOTAL_DOWNLOADED); + + // Time elapsed + labels[6] = getString(R.string.torrent_details_time_elapsed); + values[6] = json2.getString(TAG_TIME_ELAPSED); + + // Number of connections + labels[7] = getString(R.string.torrent_details_num_connections); + values[7] = json2.getString(TAG_NB_CONNECTIONS); + + // Share ratio + labels[8] = getString(R.string.torrent_details_share_ratio); + values[8] = json2.getString(TAG_SHARE_RATIO); + + // Upload limit + labels[9] = getString(R.string.torrent_details_upload_rate_limit); + values[9] = json2.getString(TAG_UPLOAD_LIMIT); + + // Download limit + labels[10] = getString(R.string.torrent_details_download_rate_limit); + values[10] = json2.getString(TAG_DOWNLOAD_LIMIT); + + } + + } catch (Exception e) { + + Log.e("TorrentFragment:", e.toString()); + + } + + return rootViews; + + } + + @Override + protected void onPostExecute(View[] rootViews) { + + try { + + View rootView = rootViews[0]; + + propertyAdapter = new myPropertyAdapter(getActivity(), labels, values); + + LinearLayout layout = (LinearLayout) rootView.findViewById(R.id.lines); + + for (int i = 0; i < propertyAdapter.getCount(); i++) { + View item = propertyAdapter.getView(i, null, null); + layout.addView(item); + } + + } catch (Exception e) { + // TODO Auto-generated catch block + Log.e("TorrentFragment:", e.toString()); + } + + // Hide progressBar + if (MainActivity.progressBar != null) { + MainActivity.progressBar.setVisibility(View.INVISIBLE); + } + + } + + } + + // My custom adapters + class myPropertyAdapter extends ArrayAdapter { + + private String[] labels; + private String[] values; + private Context context; + + public myPropertyAdapter(Context context, String[] labels, String[] values) { + // TODO Auto-generated constructor stub + super(context, R.layout.property_row, R.id.label, values); + + this.context = context; + this.labels = labels; + this.values = values; + + } + + @Override + public int getCount() { + // TODO Auto-generated method stub} + return (labels != null) ? labels.length : 0; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + View row = super.getView(position, convertView, parent); + + TextView label = (TextView) row.findViewById(R.id.label); + TextView value = (TextView) row.findViewById(R.id.value); + + label.setText("" + labels[position]); + value.setText("" + values[position]); + + return (row); + } + } + + class myFileAdapter extends ArrayAdapter { + + private String[] filesNames; + private ContentFile[] files; + private Context context; + + public myFileAdapter(Context context, String[] filesNames, ContentFile[] files) { + // TODO Auto-generated constructor stub + super(context, R.layout.contentfile_row, R.id.file, filesNames); + + this.context = context; + this.filesNames = filesNames; + this.files = files; + + } + + @Override + public int getCount() { + // TODO Auto-generated method stub} + return (filesNames != null) ? filesNames.length : 0; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + View row = super.getView(position, convertView, parent); + + TextView info = (TextView) row.findViewById(R.id.info); + + info.setText("" + files[position].getSize()); + + // Set progress bar + ProgressBar progressBar = (ProgressBar) row.findViewById(R.id.progressBar1); + TextView percentageTV = (TextView) row.findViewById(R.id.percentage); + + int index = files[position].getProgressAsString().indexOf("."); + + if (index == -1) { + index = files[position].getProgressAsString().indexOf(","); + + if (index == -1) { + index = files[position].getProgressAsString().length(); + } + } + + String percentage = files[position].getProgressAsString().substring(0, index); + + progressBar.setProgress(Integer.parseInt(percentage)); + + percentageTV.setText(percentage + "%"); + + return (row); + } + } + + class myTrackerAdapter extends ArrayAdapter { + + private String[] trackersNames; + private Tracker[] trackers; + private Context context; + + public myTrackerAdapter(Context context, String[] trackersNames, Tracker[] trackers) { + // TODO Auto-generated constructor stub + super(context, R.layout.tracker_row, R.id.tracker, trackersNames); + + this.context = context; + this.trackersNames = trackersNames; + this.trackers = trackers; + + } + + @Override + public int getCount() { + // TODO Auto-generated method stub} + return (trackersNames != null) ? trackersNames.length : 0; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + View row = super.getView(position, convertView, parent); + + TextView tracker = (TextView) row.findViewById(R.id.tracker); + + tracker.setText("" + trackers[position].getUrl()); + + return (row); + } + } + + /** + * * + * Method for Setting the Height of the ListView dynamically. Hack to fix + * the issue of not showing all the items of the ListView when placed inside + * a ScrollView + * ** + */ + public static void setListViewHeightBasedOnChildren(ListView listView) { + + ListAdapter listAdapter = listView.getAdapter(); + if (listAdapter == null) + return; + + int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED); + int totalHeight = 0; + View view = null; + + for (int i = 0; i < listAdapter.getCount(); i++) { + view = listAdapter.getView(i, view, listView); + if (i == 0) + view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT)); + + view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED); + totalHeight += view.getMeasuredHeight(); + } + + ViewGroup.LayoutParams params = listView.getLayoutParams(); + + params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); + + listView.setLayoutParams(params); + listView.requestLayout(); + + } + } diff --git a/qBittorrentClient/src/com/lgallardo/qbittorrentclient/Tracker.java b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/Tracker.java new file mode 100644 index 00000000..e031f4a7 --- /dev/null +++ b/qBittorrentClient/src/com/lgallardo/qbittorrentclient/Tracker.java @@ -0,0 +1,19 @@ +package com.lgallardo.qbittorrentclient; + +public class Tracker { + + private String url; + + public Tracker(String url){ + this.url = url; + + } + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + +}