From fcbb2d5e849ef8689a771b588bae7702a720b1d7 Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Thu, 16 Apr 2015 18:18:09 -0430 Subject: [PATCH 01/26] * Started Google Material Design implementation --- qBittorrentClient/app/build.gradle | 9 +++++++-- qBittorrentClient/app/src/main/res/values-v21/styles.xml | 7 +++++++ qBittorrentClient/app/src/main/res/values/styles.xml | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 qBittorrentClient/app/src/main/res/values-v21/styles.xml diff --git a/qBittorrentClient/app/build.gradle b/qBittorrentClient/app/build.gradle index 1f313728..c7d34627 100644 --- a/qBittorrentClient/app/build.gradle +++ b/qBittorrentClient/app/build.gradle @@ -1,8 +1,9 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 19 + buildToolsVersion "22.0.0" + compileSdkVersion 21 defaultConfig { applicationId 'com.lgallardo.qbittorrentclient' @@ -51,7 +52,11 @@ android { } dependencies { - compile 'com.android.support:support-v4:21.0.3' + + compile 'com.android.support:support-v4:21.0.0' + compile 'com.android.support:appcompat-v7:21.0.0' + compile 'com.android.support:recyclerview-v7:21.0.0' + compile 'com.android.support:cardview-v7:21.0.0' compile 'com.google.android.gms:play-services:7.0.0' compile files('libs/httpcore-4.3.2.jar') compile files('libs/httpmime-4.3.5.jar') diff --git a/qBittorrentClient/app/src/main/res/values-v21/styles.xml b/qBittorrentClient/app/src/main/res/values-v21/styles.xml new file mode 100644 index 00000000..dab12eb5 --- /dev/null +++ b/qBittorrentClient/app/src/main/res/values-v21/styles.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/values/styles.xml b/qBittorrentClient/app/src/main/res/values/styles.xml index 64c09334..7fd85f19 100644 --- a/qBittorrentClient/app/src/main/res/values/styles.xml +++ b/qBittorrentClient/app/src/main/res/values/styles.xml @@ -14,7 +14,7 @@ Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. --> - - From ad42a17f0f56fa6064ae98fd56b28a22f3018883 Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Fri, 17 Apr 2015 01:12:00 -0430 Subject: [PATCH 02/26] * Added Toolbar in favor of ActionBar * Added Indigo palette of colors * Customized Toolbar with custom colors * Added first theme (fixed, no dark option for now) * Fixed padding in torrent item row * Added custom shape (rectangle) for elevation effect (shadows) --- .../app/src/main/AndroidManifest.xml | 2 +- .../app/src/main/res/drawable/gmd_shadow.xml | 8 ++ .../res/layout/activity_main_original.xml | 5 +- .../app/src/main/res/layout/app_bar.xml | 9 ++ .../app/src/main/res/menu/main.xml | 41 +++--- .../app/src/main/res/values/colors.xml | 11 ++ .../app/src/main/res/values/styles.xml | 12 +- .../MainActivity.java | 125 ++++++++++-------- .../app/src/pro/res/layout/activity_main.xml | 5 +- .../app/src/{main => pro}/res/layout/row.xml | 5 +- .../pro/res/layout/torrent_details_old.xml | 15 ++- 11 files changed, 148 insertions(+), 90 deletions(-) create mode 100644 qBittorrentClient/app/src/main/res/drawable/gmd_shadow.xml create mode 100644 qBittorrentClient/app/src/main/res/layout/app_bar.xml create mode 100644 qBittorrentClient/app/src/main/res/values/colors.xml rename qBittorrentClient/app/src/{main => pro}/res/layout/row.xml (95%) diff --git a/qBittorrentClient/app/src/main/AndroidManifest.xml b/qBittorrentClient/app/src/main/AndroidManifest.xml index 1ac56dee..6ca1c0a0 100644 --- a/qBittorrentClient/app/src/main/AndroidManifest.xml +++ b/qBittorrentClient/app/src/main/AndroidManifest.xml @@ -26,7 +26,7 @@ android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" - android:theme="@style/Theme_Light"> + android:theme="@style/AppTheme"> + + + + android:shape="rectangle"> + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/layout/activity_main_original.xml b/qBittorrentClient/app/src/main/res/layout/activity_main_original.xml index 3d2e57fc..fe4e842a 100644 --- a/qBittorrentClient/app/src/main/res/layout/activity_main_original.xml +++ b/qBittorrentClient/app/src/main/res/layout/activity_main_original.xml @@ -13,9 +13,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="5dp" - android:paddingLeft="10dp" - android:paddingRight="10dp" - android:paddingTop="0dp"> + android:paddingTop="0dp" + > + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/menu/main.xml b/qBittorrentClient/app/src/main/res/menu/main.xml index d3aefd36..10a2ce33 100644 --- a/qBittorrentClient/app/src/main/res/menu/main.xml +++ b/qBittorrentClient/app/src/main/res/menu/main.xml @@ -8,18 +8,19 @@ Contributors: Luis M. Gallardo D. --> - + @@ -52,37 +53,37 @@ \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/values/colors.xml b/qBittorrentClient/app/src/main/res/values/colors.xml new file mode 100644 index 00000000..c0b4976c --- /dev/null +++ b/qBittorrentClient/app/src/main/res/values/colors.xml @@ -0,0 +1,11 @@ + + + #3F51B5 + #303F9F + #C5CAE9 + #FF5252 + #212121 + #727272 + #FFFFFF + #B6B6B6 + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/values/styles.xml b/qBittorrentClient/app/src/main/res/values/styles.xml index 7fd85f19..44017e3d 100644 --- a/qBittorrentClient/app/src/main/res/values/styles.xml +++ b/qBittorrentClient/app/src/main/res/values/styles.xml @@ -23,8 +23,18 @@ - + + + diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index 62dd000c..04fdc93b 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -35,6 +35,8 @@ import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.app.FragmentActivity; import android.support.v4.widget.DrawerLayout; +import android.support.v7.app.ActionBarActivity; +import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; @@ -59,7 +61,7 @@ import java.util.Collections; import java.util.HashMap; -public class MainActivity extends FragmentActivity { +public class MainActivity extends ActionBarActivity { // Torrent Info TAGs protected static final String TAG_NAME = "name"; @@ -101,7 +103,7 @@ public class MainActivity extends FragmentActivity { public static LinearLayout headerInfo; // Current state public static String currentState; - protected static JSONParser jParser; + protected static com.lgallardo.qbittorrentclient.JSONParser jParser; // Preferences properties protected static String hostname; protected static String subfolder; @@ -141,7 +143,7 @@ public class MainActivity extends FragmentActivity { static String[] names; // Params to get JSON Array private static String[] params = new String[2]; - public ItemstFragment firstFragment; + public com.lgallardo.qbittorrentclient.ItemstFragment firstFragment; // myAdapter myadapter public TorrentListAdapter myadapter; // Http status code @@ -177,6 +179,9 @@ public class MainActivity extends FragmentActivity { private AlarmManager alarmMgr; private PendingIntent alarmIntent; + // New ToolBar in Material Desing + Toolbar toolbar; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -215,15 +220,19 @@ protected void onCreate(Bundle savedInstanceState) { cookie = ""; } - // Set Theme (It must be fore inflating or setContentView) - if (dark_ui) { - this.setTheme(R.style.Theme_Dark); - } else { - this.setTheme(R.style.Theme_Light); - } +// // Set Theme (It must be fore inflating or setContentView) +// if (dark_ui) { +// this.setTheme(R.style.Theme_Dark); +// } else { +// this.setTheme(R.style.Theme_Light); +// } setContentView(R.layout.activity_main); + toolbar = (Toolbar) findViewById(R.id.app_bar); + + setSupportActionBar(toolbar); + // Get progress bar progressBar = (ProgressBar) findViewById(R.id.progressBarConnecting); @@ -274,7 +283,7 @@ protected void onCreate(Bundle savedInstanceState) { */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); - // getActionBar().setTitle(title); + // getSupportActionBar().setTitle(title); } /** @@ -282,7 +291,7 @@ public void onDrawerClosed(View view) { */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); - // getActionBar().setTitle(drawerTitle); + // getSupportActionBar().setTitle(drawerTitle); // setTitle(R.string.app_shortname); } }; @@ -290,8 +299,8 @@ public void onDrawerOpened(View drawerView) { drawerLayout.setDrawerListener(drawerToggle); - getActionBar().setDisplayHomeAsUpEnabled(true); - getActionBar().setHomeButtonEnabled(true); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); // Get options and save them as shared preferences @@ -318,7 +327,7 @@ public void onDrawerOpened(View drawerView) { // This fragment will hold the list of torrents if (firstFragment == null) { - firstFragment = new ItemstFragment(); + firstFragment = new com.lgallardo.qbittorrentclient.ItemstFragment(); } // This fragment will hold the list of torrents helpTabletFragment = new HelpFragment(); @@ -357,7 +366,7 @@ public void onDrawerOpened(View drawerView) { // Create an instance of ItemsFragments if (firstFragment == null) { - firstFragment = new ItemstFragment(); + firstFragment = new com.lgallardo.qbittorrentclient.ItemstFragment(); } firstFragment.setSecondFragmentContainer(R.id.one_frame); @@ -375,7 +384,7 @@ public void onDrawerOpened(View drawerView) { try { FragmentManager fm = getFragmentManager(); - if (fm.getBackStackEntryCount() == 1 && fm.findFragmentById(R.id.one_frame) instanceof TorrentDetailsFragment) { + if (fm.getBackStackEntryCount() == 1 && fm.findFragmentById(R.id.one_frame) instanceof com.lgallardo.qbittorrentclient.TorrentDetailsFragment) { refreshCurrent(); @@ -481,9 +490,9 @@ public void onResume() { FragmentManager fm = getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); - if (fm.getBackStackEntryCount() == 0 && fm.findFragmentById(R.id.one_frame) instanceof ItemstFragment) { + if (fm.getBackStackEntryCount() == 0 && fm.findFragmentById(R.id.one_frame) instanceof com.lgallardo.qbittorrentclient.ItemstFragment) { - ItemstFragment fragment = (ItemstFragment) fm.findFragmentById(R.id.one_frame); + com.lgallardo.qbittorrentclient.ItemstFragment fragment = (com.lgallardo.qbittorrentclient.ItemstFragment) fm.findFragmentById(R.id.one_frame); if (fragment.getListView().getCount() == 0) { @@ -561,7 +570,7 @@ public void refreshCurrent() { @Override public void setTitle(CharSequence title) { this.title = title; - getActionBar().setTitle(title); + getSupportActionBar().setTitle(title); } @Override @@ -749,9 +758,9 @@ public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); // Associate searchable configuration with the SearchView - SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); - SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); - searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); +// SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); +// SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); +// searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); return true; } @@ -802,8 +811,8 @@ public boolean onOptionsItemSelected(MenuItem item) { addUrlTorrent(); return true; case R.id.action_pause: - if (TorrentDetailsFragment.hashToUpdate != null) { - pauseTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + pauseTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { getFragmentManager().popBackStack(); @@ -811,8 +820,8 @@ public boolean onOptionsItemSelected(MenuItem item) { } return true; case R.id.action_resume: - if (TorrentDetailsFragment.hashToUpdate != null) { - startTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + startTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { getFragmentManager().popBackStack(); @@ -844,8 +853,8 @@ public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) { // User accepted the dialog - if (TorrentDetailsFragment.hashToUpdate != null) { - deleteTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + deleteTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { getFragmentManager().popBackStack(); @@ -881,8 +890,8 @@ public void onClick(DialogInterface dialog, int id) { builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User accepted the dialog - if (TorrentDetailsFragment.hashToUpdate != null) { - deleteDriveTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + deleteDriveTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { getFragmentManager().popBackStack(); @@ -901,8 +910,8 @@ public void onClick(DialogInterface dialog, int id) { } return true; case R.id.action_increase_prio: - if (TorrentDetailsFragment.hashToUpdate != null) { - increasePrioTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + increasePrioTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { getFragmentManager().popBackStack(); @@ -910,8 +919,8 @@ public void onClick(DialogInterface dialog, int id) { } return true; case R.id.action_decrease_prio: - if (TorrentDetailsFragment.hashToUpdate != null) { - decreasePrioTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + decreasePrioTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { getFragmentManager().popBackStack(); @@ -919,8 +928,8 @@ public void onClick(DialogInterface dialog, int id) { } return true; case R.id.action_max_prio: - if (TorrentDetailsFragment.hashToUpdate != null) { - maxPrioTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + maxPrioTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { getFragmentManager().popBackStack(); @@ -928,8 +937,8 @@ public void onClick(DialogInterface dialog, int id) { } return true; case R.id.action_min_prio: - if (TorrentDetailsFragment.hashToUpdate != null) { - minPrioTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + minPrioTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { getFragmentManager().popBackStack(); @@ -943,8 +952,8 @@ public void onClick(DialogInterface dialog, int id) { pauseAllTorrents(); return true; case R.id.action_upload_rate_limit: - if (TorrentDetailsFragment.hashToUpdate != null) { - uploadRateLimitDialog(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + uploadRateLimitDialog(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { getFragmentManager().popBackStack(); } @@ -952,32 +961,32 @@ public void onClick(DialogInterface dialog, int id) { return true; case R.id.action_download_rate_limit: - if (TorrentDetailsFragment.hashToUpdate != null) { - downloadRateLimitDialog(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + downloadRateLimitDialog(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { getFragmentManager().popBackStack(); } } return true; case R.id.action_recheck: - if (TorrentDetailsFragment.hashToUpdate != null) { - recheckTorrents(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + recheckTorrents(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { getFragmentManager().popBackStack(); } } return true; case R.id.action_firts_last_piece_prio: - if (TorrentDetailsFragment.hashToUpdate != null) { - toggleFirstLastPiecePrio(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + toggleFirstLastPiecePrio(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { getFragmentManager().popBackStack(); } } return true; case R.id.action_sequential_download: - if (TorrentDetailsFragment.hashToUpdate != null) { - toggleSequentialDownload(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + toggleSequentialDownload(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { getFragmentManager().popBackStack(); } @@ -1221,7 +1230,7 @@ public void onClick(DialogInterface dialog, int id) { private void openSettings() { canrefresh = false; - Intent intent = new Intent(getBaseContext(), SettingsActivity.class); + Intent intent = new Intent(getBaseContext(), com.lgallardo.qbittorrentclient.SettingsActivity.class); // startActivity(intent); startActivityForResult(intent, SETTINGS_CODE); @@ -1866,7 +1875,7 @@ private void selectItem(int position) { if (findViewById(R.id.one_frame) != null) { FragmentManager fragmentManager = getFragmentManager(); - if (fragmentManager.findFragmentByTag("firstFragment") instanceof TorrentDetailsFragment) { + if (fragmentManager.findFragmentByTag("firstFragment") instanceof com.lgallardo.qbittorrentclient.TorrentDetailsFragment) { // Reset back button stack for (int i = 0; i < fragmentManager.getBackStackEntryCount(); ++i) { fragmentManager.popBackStack(); @@ -1949,7 +1958,7 @@ protected String[] doInBackground(Void... params) { // Creating new JSON Parser - JSONParser jParser = new JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); + com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); String cookie = ""; String api = ""; @@ -2021,7 +2030,7 @@ protected String doInBackground(String... params) { // Creating new JSON Parser - JSONParser jParser = new JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); + com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); jParser.setCookie(cookie); @@ -2200,7 +2209,7 @@ protected Torrent[] doInBackground(String... params) { // Creating new JSON Parser - jParser = new JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); + jParser = new com.lgallardo.qbittorrentclient.JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); jParser.setCookie(MainActivity.cookie); @@ -2443,7 +2452,7 @@ protected void onPostExecute(Torrent[] result) { MainActivity.names[i] = torrent.getFile(); MainActivity.lines[i] = torrent; - if (torrent.getHash().equals(TorrentDetailsFragment.hashToUpdate)) { + if (torrent.getHash().equals(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate)) { torrentToUpdate = torrent; @@ -2527,7 +2536,7 @@ protected void onPostExecute(Torrent[] result) { // Set second fragment if (!(fragmentManager.findFragmentByTag("secondFragment") instanceof AboutFragment)) { - TorrentDetailsFragment detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("secondFragment"); + com.lgallardo.qbittorrentclient.TorrentDetailsFragment detailsFragment = (com.lgallardo.qbittorrentclient.TorrentDetailsFragment) fragmentManager.findFragmentByTag("secondFragment"); if (torrentToUpdate != null) { // Update torrent details @@ -2566,10 +2575,10 @@ protected void onPostExecute(Torrent[] result) { fragmentTransaction.replace(R.id.one_frame, firstFragment, "firstFragment"); } - if (fragmentManager.findFragmentByTag("firstFragment") instanceof TorrentDetailsFragment) { + if (fragmentManager.findFragmentByTag("firstFragment") instanceof com.lgallardo.qbittorrentclient.TorrentDetailsFragment) { - TorrentDetailsFragment detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("firstFragment"); + com.lgallardo.qbittorrentclient.TorrentDetailsFragment detailsFragment = (com.lgallardo.qbittorrentclient.TorrentDetailsFragment) fragmentManager.findFragmentByTag("firstFragment"); if (torrentToUpdate != null) { // Update torrent @@ -2698,7 +2707,7 @@ protected String doInBackground(String... params) { getSettings(); // Creating new JSON Parser - JSONParser jParser = new JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); + com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); jParser.setCookie(cookie); diff --git a/qBittorrentClient/app/src/pro/res/layout/activity_main.xml b/qBittorrentClient/app/src/pro/res/layout/activity_main.xml index a12d8881..edc82c60 100644 --- a/qBittorrentClient/app/src/pro/res/layout/activity_main.xml +++ b/qBittorrentClient/app/src/pro/res/layout/activity_main.xml @@ -18,6 +18,8 @@ android:layout_height="wrap_content" android:orientation="vertical"> + + + android:layout_height="match_parent" + android:background="@android:color/white"/> + android:paddingLeft="10dp" + android:paddingRight="10dp" + android:paddingTop="5dp" + android:paddingBottom="5dp"> Date: Wed, 22 Apr 2015 12:10:22 -0430 Subject: [PATCH 03/26] * [Pro] Added light and dark theme for Material Design --- .../app/src/free/res/layout-large/row.xml | 1 - .../app/src/free/res/layout-sw600dp/row.xml | 1 - .../app/src/free/res/layout/activity_main.xml | 3 +- .../app/src/free/res/layout/row.xml | 1 - .../ab_background_textured_theme_dark.xml | 21 --- .../res/drawable/background_selector_dark.xml | 2 +- .../res/drawable/btn_cab_done_theme_dark.xml | 27 ---- .../{gmd_shadow.xml => gmd_shadow_dark.xml} | 6 +- .../main/res/drawable/gmd_shadow_light.xml | 8 ++ .../progress_horizontal_theme_dark.xml | 35 ----- .../selectable_background_theme_dark.xml | 23 ---- .../spinner_background_ab_theme_dark.xml | 28 ---- .../drawable/tab_indicator_ab_theme_dark.xml | 37 ------ ...me_dark_activated_background_holo_dark.xml | 20 --- .../theme_dark_btn_check_holo_dark.xml | 65 --------- .../theme_dark_btn_default_holo_dark.xml | 32 ----- .../theme_dark_btn_radio_holo_dark.xml | 59 --------- .../theme_dark_btn_toggle_holo_dark.xml | 50 ------- .../theme_dark_edit_text_holo_dark.xml | 25 ---- .../theme_dark_fastscroll_thumb_holo.xml | 20 --- .../theme_dark_item_background_holo_dark.xml | 26 ---- ...lector_background_transition_holo_dark.xml | 20 --- .../theme_dark_list_selector_holo_dark.xml | 27 ---- ...eme_dark_progress_horizontal_holo_dark.xml | 32 ----- ...ess_indeterminate_horizontal_holo_dark.xml | 30 ----- ...me_dark_ratingbar_full_empty_holo_dark.xml | 34 ----- ...e_dark_ratingbar_full_filled_holo_dark.xml | 34 ----- .../theme_dark_ratingbar_full_holo_dark.xml | 22 ---- .../theme_dark_ratingbar_holo_dark.xml | 22 ---- .../theme_dark_ratingbar_small_holo_dark.xml | 22 ---- ...rk_scrubber_control_selector_holo_dark.xml | 22 ---- ...scrubber_progress_horizontal_holo_dark.xml | 28 ---- ...heme_dark_spinner_background_holo_dark.xml | 25 ---- .../theme_dark_switch_inner_holo_dark.xml | 22 ---- .../theme_dark_switch_track_holo_dark.xml | 20 --- .../theme_dark_tab_indicator_holo.xml | 34 ----- ..._light_activated_background_holo_light.xml | 20 --- .../theme_light_btn_check_holo_light.xml | 65 --------- .../theme_light_btn_default_holo_light.xml | 32 ----- .../theme_light_btn_radio_holo_light.xml | 59 --------- .../theme_light_btn_toggle_holo_light.xml | 50 ------- .../theme_light_edit_text_holo_light.xml | 25 ---- .../theme_light_fastscroll_thumb_holo.xml | 20 --- ...theme_light_item_background_holo_light.xml | 26 ---- ...ector_background_transition_holo_light.xml | 20 --- .../theme_light_list_selector_holo_light.xml | 28 ---- ...e_light_progress_horizontal_holo_light.xml | 32 ----- ...ss_indeterminate_horizontal_holo_light.xml | 30 ----- ..._light_ratingbar_full_empty_holo_light.xml | 34 ----- ...light_ratingbar_full_filled_holo_light.xml | 34 ----- .../theme_light_ratingbar_full_holo_light.xml | 22 ---- .../theme_light_ratingbar_holo_light.xml | 22 ---- ...theme_light_ratingbar_small_holo_light.xml | 22 ---- ...t_scrubber_control_selector_holo_light.xml | 22 ---- ...crubber_progress_horizontal_holo_light.xml | 28 ---- ...me_light_spinner_background_holo_light.xml | 25 ---- .../theme_light_switch_inner_holo_light.xml | 22 ---- .../theme_light_switch_track_holo_light.xml | 20 --- .../theme_light_tab_indicator_holo.xml | 34 ----- .../app/src/main/res/layout/about.xml | 9 +- .../res/layout/activity_main_original.xml | 17 ++- .../layout/theme_dark_tab_indicator_holo.xml | 38 ------ .../layout/theme_light_tab_indicator_holo.xml | 38 ------ .../app/src/main/res/values/attrs.xml | 4 +- .../app/src/main/res/values/colors.xml | 2 + .../app/src/main/res/values/colors_dark.xml | 14 ++ .../src/main/res/values/colors_theme_dark.xml | 4 - .../main/res/values/colors_theme_light.xml | 4 - .../src/main/res/values/dimens_theme_dark.xml | 4 - .../app/src/main/res/values/styles.xml | 58 +++++++- .../src/main/res/values/styles_theme_dark.xml | 75 ----------- .../main/res/values/styles_theme_light.xml | 74 ----------- .../src/main/res/values/themes_theme_dark.xml | 124 ------------------ .../main/res/values/themes_theme_light.xml | 65 --------- .../ItemstFragment.java | 34 ++--- .../MainActivity.java | 45 +++++-- .../TorrentDetailsFragment.java | 6 + .../pro/res/layout-large/activity_main.xml | 13 +- .../layout-large/activity_main_original.xml | 2 +- .../pro/res/layout-large/torrent_details.xml | 118 +++++++++-------- .../res/layout-large/torrent_details_old.xml | 85 ++++++------ .../app/src/pro/res/layout-sw600dp/about.xml | 2 +- .../app/src/pro/res/layout-sw600dp/row.xml | 4 +- .../res/layout-sw600dp/torrent_details.xml | 65 +++++---- .../layout-sw600dp/torrent_details_old.xml | 56 ++++---- .../app/src/pro/res/layout/activity_main.xml | 9 +- .../app/src/pro/res/layout/row.xml | 3 +- .../src/pro/res/layout/torrent_details.xml | 54 ++++---- .../pro/res/layout/torrent_details_old.xml | 62 +++++---- 89 files changed, 424 insertions(+), 2240 deletions(-) delete mode 100644 qBittorrentClient/app/src/main/res/drawable/ab_background_textured_theme_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/btn_cab_done_theme_dark.xml rename qBittorrentClient/app/src/main/res/drawable/{gmd_shadow.xml => gmd_shadow_dark.xml} (64%) create mode 100644 qBittorrentClient/app/src/main/res/drawable/gmd_shadow_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/progress_horizontal_theme_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/selectable_background_theme_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/spinner_background_ab_theme_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/tab_indicator_ab_theme_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_activated_background_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_check_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_default_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_radio_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_toggle_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_edit_text_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_fastscroll_thumb_holo.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_item_background_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_list_selector_background_transition_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_list_selector_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_progress_horizontal_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_progress_indeterminate_horizontal_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_full_empty_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_full_filled_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_full_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_small_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_scrubber_control_selector_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_scrubber_progress_horizontal_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_spinner_background_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_switch_inner_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_switch_track_holo_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_dark_tab_indicator_holo.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_activated_background_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_btn_check_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_btn_default_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_btn_radio_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_btn_toggle_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_edit_text_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_fastscroll_thumb_holo.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_item_background_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_list_selector_background_transition_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_list_selector_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_progress_horizontal_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_progress_indeterminate_horizontal_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_full_empty_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_full_filled_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_full_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_small_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_scrubber_control_selector_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_scrubber_progress_horizontal_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_spinner_background_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_switch_inner_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_switch_track_holo_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/drawable/theme_light_tab_indicator_holo.xml delete mode 100644 qBittorrentClient/app/src/main/res/layout/theme_dark_tab_indicator_holo.xml delete mode 100644 qBittorrentClient/app/src/main/res/layout/theme_light_tab_indicator_holo.xml create mode 100644 qBittorrentClient/app/src/main/res/values/colors_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/values/colors_theme_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/values/colors_theme_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/values/dimens_theme_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/values/styles_theme_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/values/styles_theme_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/values/themes_theme_dark.xml delete mode 100644 qBittorrentClient/app/src/main/res/values/themes_theme_light.xml diff --git a/qBittorrentClient/app/src/free/res/layout-large/row.xml b/qBittorrentClient/app/src/free/res/layout-large/row.xml index 3cf71a8a..4da94a0a 100644 --- a/qBittorrentClient/app/src/free/res/layout-large/row.xml +++ b/qBittorrentClient/app/src/free/res/layout-large/row.xml @@ -17,7 +17,6 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" - android:background="?backgroundSelector" android:paddingLeft="10dp" android:paddingRight="10dp"> diff --git a/qBittorrentClient/app/src/free/res/layout-sw600dp/row.xml b/qBittorrentClient/app/src/free/res/layout-sw600dp/row.xml index 027aa180..116a259b 100644 --- a/qBittorrentClient/app/src/free/res/layout-sw600dp/row.xml +++ b/qBittorrentClient/app/src/free/res/layout-sw600dp/row.xml @@ -17,7 +17,6 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" - android:background="?backgroundSelector" android:paddingLeft="10dp" android:paddingRight="10dp"> diff --git a/qBittorrentClient/app/src/free/res/layout/activity_main.xml b/qBittorrentClient/app/src/free/res/layout/activity_main.xml index f80a3344..f98c8780 100644 --- a/qBittorrentClient/app/src/free/res/layout/activity_main.xml +++ b/qBittorrentClient/app/src/free/res/layout/activity_main.xml @@ -17,7 +17,8 @@ + android:orientation="vertical" + android:background="?windowBackground"> diff --git a/qBittorrentClient/app/src/main/res/drawable/ab_background_textured_theme_dark.xml b/qBittorrentClient/app/src/main/res/drawable/ab_background_textured_theme_dark.xml deleted file mode 100644 index 0a62adb4..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/ab_background_textured_theme_dark.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/drawable/background_selector_dark.xml b/qBittorrentClient/app/src/main/res/drawable/background_selector_dark.xml index 0e0116d9..cdedd152 100644 --- a/qBittorrentClient/app/src/main/res/drawable/background_selector_dark.xml +++ b/qBittorrentClient/app/src/main/res/drawable/background_selector_dark.xml @@ -5,6 +5,6 @@ - + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/drawable/btn_cab_done_theme_dark.xml b/qBittorrentClient/app/src/main/res/drawable/btn_cab_done_theme_dark.xml deleted file mode 100644 index 8196cf69..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/btn_cab_done_theme_dark.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/gmd_shadow.xml b/qBittorrentClient/app/src/main/res/drawable/gmd_shadow_dark.xml similarity index 64% rename from qBittorrentClient/app/src/main/res/drawable/gmd_shadow.xml rename to qBittorrentClient/app/src/main/res/drawable/gmd_shadow_dark.xml index 81335bb7..09af557d 100644 --- a/qBittorrentClient/app/src/main/res/drawable/gmd_shadow.xml +++ b/qBittorrentClient/app/src/main/res/drawable/gmd_shadow_dark.xml @@ -1,8 +1,8 @@ - + - - + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/drawable/gmd_shadow_light.xml b/qBittorrentClient/app/src/main/res/drawable/gmd_shadow_light.xml new file mode 100644 index 00000000..c13f3b1d --- /dev/null +++ b/qBittorrentClient/app/src/main/res/drawable/gmd_shadow_light.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/drawable/progress_horizontal_theme_dark.xml b/qBittorrentClient/app/src/main/res/drawable/progress_horizontal_theme_dark.xml deleted file mode 100644 index 23fbd875..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/progress_horizontal_theme_dark.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/selectable_background_theme_dark.xml b/qBittorrentClient/app/src/main/res/drawable/selectable_background_theme_dark.xml deleted file mode 100644 index 240d7696..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/selectable_background_theme_dark.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/drawable/spinner_background_ab_theme_dark.xml b/qBittorrentClient/app/src/main/res/drawable/spinner_background_ab_theme_dark.xml deleted file mode 100644 index 4137bbfd..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/spinner_background_ab_theme_dark.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/tab_indicator_ab_theme_dark.xml b/qBittorrentClient/app/src/main/res/drawable/tab_indicator_ab_theme_dark.xml deleted file mode 100644 index 72012770..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/tab_indicator_ab_theme_dark.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_activated_background_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_activated_background_holo_dark.xml deleted file mode 100644 index 494bfb8c..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_activated_background_holo_dark.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_check_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_check_holo_dark.xml deleted file mode 100644 index f04cb390..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_check_holo_dark.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_default_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_default_holo_dark.xml deleted file mode 100644 index a0477b04..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_default_holo_dark.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_radio_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_radio_holo_dark.xml deleted file mode 100644 index e553ca4b..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_radio_holo_dark.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_toggle_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_toggle_holo_dark.xml deleted file mode 100644 index e60fa5ca..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_btn_toggle_holo_dark.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_edit_text_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_edit_text_holo_dark.xml deleted file mode 100644 index ab9060e7..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_edit_text_holo_dark.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_fastscroll_thumb_holo.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_fastscroll_thumb_holo.xml deleted file mode 100644 index 43de7335..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_fastscroll_thumb_holo.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_item_background_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_item_background_holo_dark.xml deleted file mode 100644 index 5c94d901..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_item_background_holo_dark.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_list_selector_background_transition_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_list_selector_background_transition_holo_dark.xml deleted file mode 100644 index 2c7a28fc..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_list_selector_background_transition_holo_dark.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_list_selector_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_list_selector_holo_dark.xml deleted file mode 100644 index 3b91682b..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_list_selector_holo_dark.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_progress_horizontal_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_progress_horizontal_holo_dark.xml deleted file mode 100644 index d554abbb..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_progress_horizontal_holo_dark.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_progress_indeterminate_horizontal_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_progress_indeterminate_horizontal_holo_dark.xml deleted file mode 100644 index 685c3f2e..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_progress_indeterminate_horizontal_holo_dark.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_full_empty_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_full_empty_holo_dark.xml deleted file mode 100644 index ccd1565c..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_full_empty_holo_dark.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_full_filled_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_full_filled_holo_dark.xml deleted file mode 100644 index b6ca1a9b..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_full_filled_holo_dark.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_full_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_full_holo_dark.xml deleted file mode 100644 index cb6c3b40..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_full_holo_dark.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_holo_dark.xml deleted file mode 100644 index df853779..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_holo_dark.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_small_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_small_holo_dark.xml deleted file mode 100644 index e172bb98..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_ratingbar_small_holo_dark.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_scrubber_control_selector_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_scrubber_control_selector_holo_dark.xml deleted file mode 100644 index c2cc29de..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_scrubber_control_selector_holo_dark.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_scrubber_progress_horizontal_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_scrubber_progress_horizontal_holo_dark.xml deleted file mode 100644 index 8619e695..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_scrubber_progress_horizontal_holo_dark.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_spinner_background_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_spinner_background_holo_dark.xml deleted file mode 100644 index 50bb92a0..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_spinner_background_holo_dark.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_switch_inner_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_switch_inner_holo_dark.xml deleted file mode 100644 index d801105a..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_switch_inner_holo_dark.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_switch_track_holo_dark.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_switch_track_holo_dark.xml deleted file mode 100644 index 12037e96..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_switch_track_holo_dark.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_dark_tab_indicator_holo.xml b/qBittorrentClient/app/src/main/res/drawable/theme_dark_tab_indicator_holo.xml deleted file mode 100644 index cb16e3a8..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_dark_tab_indicator_holo.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_activated_background_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_activated_background_holo_light.xml deleted file mode 100644 index a483c377..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_activated_background_holo_light.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_btn_check_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_btn_check_holo_light.xml deleted file mode 100644 index fb9e59f4..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_btn_check_holo_light.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_btn_default_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_btn_default_holo_light.xml deleted file mode 100644 index f8d380b3..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_btn_default_holo_light.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_btn_radio_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_btn_radio_holo_light.xml deleted file mode 100644 index aa012749..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_btn_radio_holo_light.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_btn_toggle_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_btn_toggle_holo_light.xml deleted file mode 100644 index 24e4feb8..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_btn_toggle_holo_light.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_edit_text_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_edit_text_holo_light.xml deleted file mode 100644 index e1e62e70..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_edit_text_holo_light.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_fastscroll_thumb_holo.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_fastscroll_thumb_holo.xml deleted file mode 100644 index da8a0e2a..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_fastscroll_thumb_holo.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_item_background_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_item_background_holo_light.xml deleted file mode 100644 index 549c18a1..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_item_background_holo_light.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_list_selector_background_transition_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_list_selector_background_transition_holo_light.xml deleted file mode 100644 index a6d634b4..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_list_selector_background_transition_holo_light.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_list_selector_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_list_selector_holo_light.xml deleted file mode 100644 index ce11a0ed..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_list_selector_holo_light.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_progress_horizontal_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_progress_horizontal_holo_light.xml deleted file mode 100644 index 5dfc0843..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_progress_horizontal_holo_light.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_progress_indeterminate_horizontal_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_progress_indeterminate_horizontal_holo_light.xml deleted file mode 100644 index b55c3ac0..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_progress_indeterminate_horizontal_holo_light.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_full_empty_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_full_empty_holo_light.xml deleted file mode 100644 index aa872a31..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_full_empty_holo_light.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_full_filled_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_full_filled_holo_light.xml deleted file mode 100644 index fae44999..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_full_filled_holo_light.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_full_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_full_holo_light.xml deleted file mode 100644 index d5d0dabd..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_full_holo_light.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_holo_light.xml deleted file mode 100644 index ce05f9e5..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_holo_light.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_small_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_small_holo_light.xml deleted file mode 100644 index b208349f..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_ratingbar_small_holo_light.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_scrubber_control_selector_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_scrubber_control_selector_holo_light.xml deleted file mode 100644 index d6c0bcc0..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_scrubber_control_selector_holo_light.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_scrubber_progress_horizontal_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_scrubber_progress_horizontal_holo_light.xml deleted file mode 100644 index ecbd6769..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_scrubber_progress_horizontal_holo_light.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_spinner_background_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_spinner_background_holo_light.xml deleted file mode 100644 index d8f75a1a..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_spinner_background_holo_light.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_switch_inner_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_switch_inner_holo_light.xml deleted file mode 100644 index 9b5ade21..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_switch_inner_holo_light.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_switch_track_holo_light.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_switch_track_holo_light.xml deleted file mode 100644 index 42f6eb89..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_switch_track_holo_light.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/drawable/theme_light_tab_indicator_holo.xml b/qBittorrentClient/app/src/main/res/drawable/theme_light_tab_indicator_holo.xml deleted file mode 100644 index 9bbbd16b..00000000 --- a/qBittorrentClient/app/src/main/res/drawable/theme_light_tab_indicator_holo.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/layout/about.xml b/qBittorrentClient/app/src/main/res/layout/about.xml index 37a26864..4d4b5d4a 100644 --- a/qBittorrentClient/app/src/main/res/layout/about.xml +++ b/qBittorrentClient/app/src/main/res/layout/about.xml @@ -11,16 +11,16 @@ + android:orientation="vertical"> + android:layout_height="wrap_content"> + android:orientation="vertical"> + android:text="@string/app_name" /> + android:background="?windowBackground"> + + + - + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/layout/theme_dark_tab_indicator_holo.xml b/qBittorrentClient/app/src/main/res/layout/theme_dark_tab_indicator_holo.xml deleted file mode 100644 index 56cb34be..00000000 --- a/qBittorrentClient/app/src/main/res/layout/theme_dark_tab_indicator_holo.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/layout/theme_light_tab_indicator_holo.xml b/qBittorrentClient/app/src/main/res/layout/theme_light_tab_indicator_holo.xml deleted file mode 100644 index 8213af08..00000000 --- a/qBittorrentClient/app/src/main/res/layout/theme_light_tab_indicator_holo.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/values/attrs.xml b/qBittorrentClient/app/src/main/res/values/attrs.xml index b817d7df..025435a1 100644 --- a/qBittorrentClient/app/src/main/res/values/attrs.xml +++ b/qBittorrentClient/app/src/main/res/values/attrs.xml @@ -1,7 +1,7 @@ - + - + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/values/colors.xml b/qBittorrentClient/app/src/main/res/values/colors.xml index c0b4976c..004137db 100644 --- a/qBittorrentClient/app/src/main/res/values/colors.xml +++ b/qBittorrentClient/app/src/main/res/values/colors.xml @@ -8,4 +8,6 @@ #727272 #FFFFFF #B6B6B6 + + @android:color/background_light \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/values/colors_dark.xml b/qBittorrentClient/app/src/main/res/values/colors_dark.xml new file mode 100644 index 00000000..d8848210 --- /dev/null +++ b/qBittorrentClient/app/src/main/res/values/colors_dark.xml @@ -0,0 +1,14 @@ + + + #212121 + #455A64 + #CFD8DC + #9E9E9E + #212121 + #727272 + #FFFFFF + #B6B6B6 + + #ff434343 + #212121 + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/values/colors_theme_dark.xml b/qBittorrentClient/app/src/main/res/values/colors_theme_dark.xml deleted file mode 100644 index 8834a858..00000000 --- a/qBittorrentClient/app/src/main/res/values/colors_theme_dark.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - #2d2d2d - diff --git a/qBittorrentClient/app/src/main/res/values/colors_theme_light.xml b/qBittorrentClient/app/src/main/res/values/colors_theme_light.xml deleted file mode 100644 index e2d10f73..00000000 --- a/qBittorrentClient/app/src/main/res/values/colors_theme_light.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - #0099cc - diff --git a/qBittorrentClient/app/src/main/res/values/dimens_theme_dark.xml b/qBittorrentClient/app/src/main/res/values/dimens_theme_dark.xml deleted file mode 100644 index 5a0fa8d0..00000000 --- a/qBittorrentClient/app/src/main/res/values/dimens_theme_dark.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - 48dp - \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/values/styles.xml b/qBittorrentClient/app/src/main/res/values/styles.xml index 44017e3d..38c8d763 100644 --- a/qBittorrentClient/app/src/main/res/values/styles.xml +++ b/qBittorrentClient/app/src/main/res/values/styles.xml @@ -25,16 +25,64 @@ + + + + + + - + diff --git a/qBittorrentClient/app/src/main/res/values/styles_theme_dark.xml b/qBittorrentClient/app/src/main/res/values/styles_theme_dark.xml deleted file mode 100644 index bbf4f05e..00000000 --- a/qBittorrentClient/app/src/main/res/values/styles_theme_dark.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/values/styles_theme_light.xml b/qBittorrentClient/app/src/main/res/values/styles_theme_light.xml deleted file mode 100644 index 5192f3ae..00000000 --- a/qBittorrentClient/app/src/main/res/values/styles_theme_light.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/values/themes_theme_dark.xml b/qBittorrentClient/app/src/main/res/values/themes_theme_dark.xml deleted file mode 100644 index cec4156b..00000000 --- a/qBittorrentClient/app/src/main/res/values/themes_theme_dark.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/qBittorrentClient/app/src/main/res/values/themes_theme_light.xml b/qBittorrentClient/app/src/main/res/values/themes_theme_light.xml deleted file mode 100644 index 572c2216..00000000 --- a/qBittorrentClient/app/src/main/res/values/themes_theme_light.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java index dd9b6a96..5c2c2ddf 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java @@ -15,6 +15,7 @@ import android.app.ListFragment; import android.content.DialogInterface; import android.os.Bundle; +import android.support.v7.widget.RecyclerView; import android.view.ActionMode; import android.view.LayoutInflater; import android.view.Menu; @@ -31,7 +32,8 @@ public class ItemstFragment extends ListFragment { static public ActionMode mActionMode; public int nr = 0; int secondContainer; - TorrentDetailsFragment detailsFragment; + com.lgallardo.qbittorrentclient.TorrentDetailsFragment detailsFragment; + private RecyclerView recyclerView; public ItemstFragment() { @@ -60,6 +62,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa View rootView = inflater.inflate(R.layout.activity_main_original, container, false); +// recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerViewList); + return rootView; } @@ -112,7 +116,7 @@ public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { - if (MainActivity.qb_version.equals("3.2.x")) { + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { menu.findItem(R.id.action_firts_last_piece_prio).setVisible(true); menu.findItem(R.id.action_sequential_download).setVisible(true); } else { @@ -131,7 +135,7 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) { final String hashesStr; // Get MainActivity - final MainActivity m = (MainActivity) getActivity(); + final com.lgallardo.qbittorrentclient.MainActivity m = (com.lgallardo.qbittorrentclient.MainActivity) getActivity(); // Get hashes for (int i = 0; mAdapter.getCount() > i; i++) { @@ -399,9 +403,9 @@ public void ListItemClicked(int position) { // } - Torrent torrent = MainActivity.lines[position]; + Torrent torrent = com.lgallardo.qbittorrentclient.MainActivity.lines[position]; - if (torrent.getHash().equals(TorrentDetailsFragment.hashToUpdate) && getActivity().findViewById(R.id.fragment_container) != null) { + if (torrent.getHash().equals(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate) && getActivity().findViewById(R.id.fragment_container) != null) { // Update torrent details @@ -410,7 +414,7 @@ public void ListItemClicked(int position) { - detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("secondFragment"); + detailsFragment = (com.lgallardo.qbittorrentclient.TorrentDetailsFragment) fragmentManager.findFragmentByTag("secondFragment"); if (detailsFragment != null && torrent != null) { @@ -429,10 +433,10 @@ public void ListItemClicked(int position) { private void newDetailsFragment(int position){ - detailsFragment = new TorrentDetailsFragment(); + detailsFragment = new com.lgallardo.qbittorrentclient.TorrentDetailsFragment(); // Get torrent from MainActivity - detailsFragment.setTorrent(MainActivity.lines[position]); + detailsFragment.setTorrent(com.lgallardo.qbittorrentclient.MainActivity.lines[position]); detailsFragment.setPosition(position); @@ -527,35 +531,35 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.findItem(R.id.action_sortby_uploadSpeed).setVisible(true); - if (MainActivity.sortby.equals("Name")) { + if (com.lgallardo.qbittorrentclient.MainActivity.sortby.equals("Name")) { menu.findItem(R.id.action_sortby_name).setIcon(R.drawable.ic_stat_completed); } - if (MainActivity.sortby.equals("ETA")) { + if (com.lgallardo.qbittorrentclient.MainActivity.sortby.equals("ETA")) { menu.findItem(R.id.action_sortby_eta).setIcon(R.drawable.ic_stat_completed); } - if (MainActivity.sortby.equals("Priority")) { + if (com.lgallardo.qbittorrentclient.MainActivity.sortby.equals("Priority")) { ; menu.findItem(R.id.action_sortby_priority).setIcon(R.drawable.ic_stat_completed); } - if (MainActivity.sortby.equals("Progress")) { + if (com.lgallardo.qbittorrentclient.MainActivity.sortby.equals("Progress")) { menu.findItem(R.id.action_sortby_progress).setIcon(R.drawable.ic_stat_completed); } - if (MainActivity.sortby.equals("Ratio")) { + if (com.lgallardo.qbittorrentclient.MainActivity.sortby.equals("Ratio")) { menu.findItem(R.id.action_sortby_ratio).setIcon(R.drawable.ic_stat_completed); } - if (MainActivity.sortby.equals("DownloadSpeed")) { + if (com.lgallardo.qbittorrentclient.MainActivity.sortby.equals("DownloadSpeed")) { menu.findItem(R.id.action_sortby_downloadSpeed).setIcon(R.drawable.ic_stat_completed); } - if (MainActivity.sortby.equals("UploadSpeed")) { + if (com.lgallardo.qbittorrentclient.MainActivity.sortby.equals("UploadSpeed")) { menu.findItem(R.id.action_sortby_uploadSpeed).setIcon(R.drawable.ic_stat_completed); } diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index 04fdc93b..b2ffdd02 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -28,12 +28,12 @@ import android.net.NetworkInfo; import android.net.Uri; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.SystemClock; import android.preference.PreferenceManager; import android.support.v4.app.ActionBarDrawerToggle; -import android.support.v4.app.FragmentActivity; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; @@ -47,7 +47,6 @@ import android.widget.LinearLayout; import android.widget.ListView; import android.widget.ProgressBar; -import android.widget.SearchView; import android.widget.TextView; import android.widget.Toast; @@ -220,16 +219,31 @@ protected void onCreate(Bundle savedInstanceState) { cookie = ""; } -// // Set Theme (It must be fore inflating or setContentView) -// if (dark_ui) { -// this.setTheme(R.style.Theme_Dark); -// } else { -// this.setTheme(R.style.Theme_Light); -// } + // Set Theme (It must be fore inflating or setContentView) + if (dark_ui) { + this.setTheme(R.style.Theme_Dark); + + if (Build.VERSION.SDK_INT >= 21) { + getWindow().setNavigationBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); + getWindow().setStatusBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground )); + } + } else { + this.setTheme(R.style.Theme_Light); + + if (Build.VERSION.SDK_INT >= 21) { + getWindow().setNavigationBarColor(getResources().getColor(R.color.primary)); + getWindow().setStatusBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground )); + } + + } setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.app_bar); + + if(dark_ui) { + toolbar.setBackgroundColor(getResources().getColor(R.color.Theme_Dark_primary)); + } setSupportActionBar(toolbar); @@ -582,12 +596,23 @@ protected void onPostCreate(Bundle savedInstanceState) { @Override public void onBackPressed() { - if (getFragmentManager().getBackStackEntryCount() == 0) { + FragmentManager fragmentManager = getFragmentManager(); + + if (fragmentManager.getBackStackEntryCount() == 0) { this.finish(); } else { - getFragmentManager().popBackStack(); + fragmentManager.popBackStack(); + } + + if (findViewById(R.id.one_frame) != null) { + if (header) { + headerInfo.setVisibility(View.VISIBLE); + } else { + headerInfo.setVisibility(View.GONE); + } } + } private void refresh() { diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java index e6606ef4..8acfba40 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java @@ -176,6 +176,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa } + // Hide herderInfo in phone's view + if (getActivity().findViewById(R.id.one_frame) != null) { + com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.GONE); + } + + savePath = ""; creationDate = ""; comment = ""; diff --git a/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml b/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml index 7dee0596..101f1a29 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml @@ -17,7 +17,12 @@ android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal"> + android:orientation="horizontal" + android:background="?windowBackground"> + + + android:visibility="invisible" + android:layout_below="@+id/app_bar"/> + diff --git a/qBittorrentClient/app/src/pro/res/layout-large/activity_main_original.xml b/qBittorrentClient/app/src/pro/res/layout-large/activity_main_original.xml index adb1e99f..5ee18306 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/activity_main_original.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/activity_main_original.xml @@ -13,7 +13,7 @@ android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" - + android:background="?windowBackground" android:paddingBottom="5dp" android:paddingLeft="10dp"> diff --git a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details.xml b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details.xml index 3ae1dacd..682e0bec 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details.xml @@ -1,4 +1,3 @@ - + android:layout_height="match_parent"> + android:orientation="vertical" + android:background="?windowBackground"> + android:orientation="horizontal"> + android:elevation="5dp" + android:orientation="vertical"> + android:orientation="horizontal"> + android:orientation="vertical"> + android:orientation="horizontal"> + android:elevation="5dp" + android:orientation="vertical"> + android:orientation="horizontal"> + android:orientation="horizontal"> + android:orientation="horizontal"> + android:orientation="horizontal"> + android:orientation="horizontal"> + android:gravity="start" /> + android:layout_gravity="center" /> @@ -337,14 +339,14 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="false" - android:gravity="start"/> + android:gravity="start" /> + android:layout_gravity="center" /> @@ -354,20 +356,20 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:visibility="visible" > + android:visibility="visible"> + android:orientation="vertical"> @@ -376,24 +378,25 @@ + android:elevation="5dp" + android:orientation="vertical"> + android:orientation="vertical"> - + android:layout_marginRight="5dp"> @@ -403,19 +406,19 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:visibility="visible" > + android:visibility="visible"> + android:orientation="vertical"> @@ -424,10 +427,12 @@ + android:elevation="5dp" + android:orientation="vertical"> - + android:orientation="vertical"> @@ -445,19 +449,19 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:visibility="visible" > + android:visibility="visible"> + android:orientation="vertical"> @@ -466,11 +470,12 @@ + android:elevation="5dp" + android:orientation="vertical"> - + android:orientation="vertical"> diff --git a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml index 02accef7..692480b3 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml @@ -1,4 +1,3 @@ - + android:layout_height="match_parent"> + android:orientation="vertical" + android:background="?windowBackground"> + android:orientation="horizontal"> + android:elevation="5dp" + android:orientation="vertical"> + android:orientation="horizontal"> + android:orientation="vertical"> + android:orientation="horizontal"> + android:elevation="5dp" + android:orientation="vertical"> + android:orientation="horizontal"> + android:orientation="horizontal"> + android:orientation="horizontal"> + android:orientation="horizontal"> + android:orientation="horizontal"> + android:visibility="visible"> + android:orientation="vertical"> @@ -332,21 +333,21 @@ android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="?dropShadowBackground" - android:orientation="vertical" > + android:elevation="5dp" + android:orientation="vertical"> + android:orientation="vertical"> - + android:layout_marginRight="5dp"> @@ -356,19 +357,19 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:visibility="visible" > + android:visibility="visible"> + android:orientation="vertical"> @@ -380,7 +381,8 @@ android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="?dropShadowBackground" - android:orientation="vertical" > + android:elevation="5dp" + android:orientation="vertical"> - + android:orientation="vertical"> @@ -398,19 +399,19 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:visibility="visible" > + android:visibility="visible"> + android:orientation="vertical"> @@ -423,7 +424,8 @@ android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="?dropShadowBackground" - android:orientation="vertical" > + android:elevation="5dp" + android:orientation="vertical"> - + android:orientation="vertical"> diff --git a/qBittorrentClient/app/src/pro/res/layout-sw600dp/about.xml b/qBittorrentClient/app/src/pro/res/layout-sw600dp/about.xml index 37a26864..f4a0075e 100644 --- a/qBittorrentClient/app/src/pro/res/layout-sw600dp/about.xml +++ b/qBittorrentClient/app/src/pro/res/layout-sw600dp/about.xml @@ -29,7 +29,7 @@ android:layout_below="@+id/qBittorrent_logo" android:layout_centerHorizontal="true" android:text="@string/app_name" - android:textAppearance="?android:attr/textAppearanceLarge" /> + android:textSize="18dp" /> + android:paddingTop="10dp" + android:background="?backgroundSelector"> + android:layout_height="match_parent"> + android:orientation="vertical" + android:background="?windowBackground"> + + android:gravity="start" /> + android:layout_gravity="center" /> @@ -333,14 +337,14 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="false" - android:gravity="start"/> + android:gravity="start" /> + android:layout_gravity="center" /> @@ -362,8 +366,8 @@ android:id="@+id/content" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginLeft="10dp" - android:layout_marginRight="10dp" + android:layout_marginLeft="15dp" + android:layout_marginRight="15dp" android:text="@string/torrent_details_content" android:textSize="18sp" android:textStyle="bold" /> @@ -372,9 +376,11 @@ @@ -419,9 +425,11 @@ @@ -460,10 +468,11 @@ + android:layout_height="match_parent"> + android:orientation="vertical" + android:background="?windowBackground"> @@ -326,9 +329,11 @@ @@ -373,9 +378,11 @@ @@ -414,10 +421,11 @@ + android:orientation="vertical" + android:background="?windowBackground"> - + + android:padding="5dp"/> + android:paddingBottom="5dp" + android:background="?backgroundSelector"> + android:orientation="vertical" + android:background="?windowBackground"> @@ -375,9 +380,11 @@ @@ -422,9 +429,11 @@ @@ -463,10 +472,11 @@ + android:orientation="vertical" + android:background="?windowBackground"> + android:textStyle="bold" + android:gravity="center_vertical" /> @@ -133,8 +136,8 @@ android:id="@+id/properties" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginLeft="10dp" - android:layout_marginRight="10dp" + android:layout_marginLeft="15dp" + android:layout_marginRight="15dp" android:layout_marginTop="5dp" android:text="@string/torrent_details_properties" android:textSize="18sp" @@ -143,9 +146,9 @@ @@ -320,8 +323,8 @@ android:id="@+id/content" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginLeft="10dp" - android:layout_marginRight="10dp" + android:layout_marginLeft="15dp" + android:layout_marginRight="15dp" android:text="@string/torrent_details_content" android:textSize="18sp" android:textStyle="bold" /> @@ -330,9 +333,9 @@ @@ -368,8 +371,8 @@ @@ -378,9 +381,10 @@ @@ -410,8 +414,8 @@ @@ -421,9 +425,9 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="5dp" - android:layout_marginLeft="10dp" - android:layout_marginRight="10dp" - android:background="@drawable/gmd_shadow" + android:layout_marginLeft="15dp" + android:layout_marginRight="15dp" + android:background="?dropShadowBackground" android:elevation="5dp" android:orientation="vertical"> @@ -431,8 +435,8 @@ android:id="@+id/lines" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginLeft="5dp" - android:layout_marginRight="5dp" + android:layout_marginLeft="15dp" + android:layout_marginRight="15dp" android:orientation="vertical"> From 4215bf38c24ea33569424218a8877eb6b876baf4 Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Mon, 27 Apr 2015 01:13:39 -0430 Subject: [PATCH 04/26] * [Pro] Added SwipeRefresh for torrents list ad torrent's details (qB v2.x and v3.1.x) * [Pro] Deleted connecting progress bar in favor of swipe to refresh indicators * [Pro] Added drawer list styling for older (and newer) devices. * [Pro] Removed Android Holo themes in favor of Google Material Design * [Pro] Fixed torrent's row contextual menu for Google Material Design --- .../qbittorrentclient/ItemstFragment.java | 12 + .../qbittorrentclient/MainActivity.java | 20 +- .../background_drawer_selector_dark.xml | 10 + .../background_drawer_selector_light.xml | 10 + .../res/layout/activity_main_original.xml | 14 +- .../app/src/main/res/layout/drawer.xml | 31 - .../{listview_item_row.xml => drawer_row.xml} | 2 +- .../res/menu/main_contextual_action_bar.xml | 29 +- .../app/src/main/res/values/attrs.xml | 1 + .../app/src/main/res/values/colors.xml | 3 +- .../app/src/main/res/values/colors_dark.xml | 1 + .../app/src/main/res/values/styles.xml | 10 +- .../ItemstFragment.java | 104 ++- .../MainActivity.java | 104 ++- .../TorrentDetailsFragment.java | 43 +- .../TorrentListAdapter.java | 2 +- .../pro/res/layout-large/activity_main.xml | 13 +- .../layout-large/activity_main_original.xml | 13 +- .../res/layout-large/torrent_details_old.xml | 660 ++++++++--------- .../layout-sw600dp/torrent_details_old.xml | 659 ++++++++--------- .../app/src/pro/res/layout/activity_main.xml | 10 +- .../src/pro/res/layout/torrent_details.xml | 40 +- .../pro/res/layout/torrent_details_old.xml | 665 +++++++++--------- 23 files changed, 1304 insertions(+), 1152 deletions(-) create mode 100644 qBittorrentClient/app/src/main/res/drawable/background_drawer_selector_dark.xml create mode 100644 qBittorrentClient/app/src/main/res/drawable/background_drawer_selector_light.xml delete mode 100644 qBittorrentClient/app/src/main/res/layout/drawer.xml rename qBittorrentClient/app/src/main/res/layout/{listview_item_row.xml => drawer_row.xml} (95%) diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/ItemstFragment.java b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/ItemstFragment.java index c2deaff5..f793f5c9 100644 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/ItemstFragment.java +++ b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/ItemstFragment.java @@ -27,6 +27,8 @@ import android.widget.AdapterView; import android.widget.ListView; +import com.lgallardo.qbittorrentclient.MainActivity; + public class ItemstFragment extends ListFragment { static public ActionMode mActionMode; @@ -61,6 +63,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa View rootView = inflater.inflate(R.layout.activity_main_original, container, false); + SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.activity_main_swipe_refresh_layout); + + mSwipeRefreshLayout.setColo + mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + MainActivity.refreshCurrent(); + } + }); + return rootView; } diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java index 524d745d..e49b44bc 100644 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java @@ -257,9 +257,6 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); - // Get progress bar - progressBar = (ProgressBar) findViewById(R.id.progressBarConnecting); - // Set App title setTitle(R.string.app_shortname); @@ -285,7 +282,7 @@ protected void onCreate(Bundle savedInstanceState) { drawerItem[9] = new ObjectDrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[9]); // Create object for drawer item OnbjectDrawerItem - DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.listview_item_row, drawerItem); + DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.drawer_row, drawerItem); drawerList.setAdapter(adapter); // Set selection according to last state @@ -681,20 +678,9 @@ private void refresh(String state) { loadBanner(); if (hostname.equals("")) { - // Hide progressBar - if (progressBar != null) { - progressBar.setVisibility(View.INVISIBLE); - } - - // genericOkDialog(R.string.info, R.string.about_help1); } else { - // Show progressBar - if (progressBar != null) { - progressBar.setVisibility(View.VISIBLE); - } - // Execute the task in background qBittorrentTask qtt = new qBittorrentTask(); @@ -2484,10 +2470,6 @@ protected void onPostExecute(Torrent[] result) { } - // Hide progressBar - if (progressBar != null) { - progressBar.setVisibility(View.INVISIBLE); - } } } diff --git a/qBittorrentClient/app/src/main/res/drawable/background_drawer_selector_dark.xml b/qBittorrentClient/app/src/main/res/drawable/background_drawer_selector_dark.xml new file mode 100644 index 00000000..eeac9fb1 --- /dev/null +++ b/qBittorrentClient/app/src/main/res/drawable/background_drawer_selector_dark.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/drawable/background_drawer_selector_light.xml b/qBittorrentClient/app/src/main/res/drawable/background_drawer_selector_light.xml new file mode 100644 index 00000000..4306d014 --- /dev/null +++ b/qBittorrentClient/app/src/main/res/drawable/background_drawer_selector_light.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/layout/activity_main_original.xml b/qBittorrentClient/app/src/main/res/layout/activity_main_original.xml index f7a07b6f..fe189947 100644 --- a/qBittorrentClient/app/src/main/res/layout/activity_main_original.xml +++ b/qBittorrentClient/app/src/main/res/layout/activity_main_original.xml @@ -8,15 +8,15 @@ Contributors: Luis M. Gallardo D. --> - + android:background="?windowBackground" + xmlns:android="http://schemas.android.com/apk/res/android"> - - - - - - - \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/layout/listview_item_row.xml b/qBittorrentClient/app/src/main/res/layout/drawer_row.xml similarity index 95% rename from qBittorrentClient/app/src/main/res/layout/listview_item_row.xml rename to qBittorrentClient/app/src/main/res/layout/drawer_row.xml index 01f9bc72..f8185f33 100644 --- a/qBittorrentClient/app/src/main/res/layout/listview_item_row.xml +++ b/qBittorrentClient/app/src/main/res/layout/drawer_row.xml @@ -11,7 +11,7 @@ diff --git a/qBittorrentClient/app/src/main/res/menu/main_contextual_action_bar.xml b/qBittorrentClient/app/src/main/res/menu/main_contextual_action_bar.xml index 3a5541c2..677b858e 100644 --- a/qBittorrentClient/app/src/main/res/menu/main_contextual_action_bar.xml +++ b/qBittorrentClient/app/src/main/res/menu/main_contextual_action_bar.xml @@ -1,25 +1,26 @@ - + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/values/attrs.xml b/qBittorrentClient/app/src/main/res/values/attrs.xml index 025435a1..d7567a90 100644 --- a/qBittorrentClient/app/src/main/res/values/attrs.xml +++ b/qBittorrentClient/app/src/main/res/values/attrs.xml @@ -2,6 +2,7 @@ + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/values/colors.xml b/qBittorrentClient/app/src/main/res/values/colors.xml index 004137db..2c69076f 100644 --- a/qBittorrentClient/app/src/main/res/values/colors.xml +++ b/qBittorrentClient/app/src/main/res/values/colors.xml @@ -3,11 +3,12 @@ #3F51B5 #303F9F #C5CAE9 - #FF5252 + #448AFF #212121 #727272 #FFFFFF #B6B6B6 @android:color/background_light + #111 \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/values/colors_dark.xml b/qBittorrentClient/app/src/main/res/values/colors_dark.xml index d8848210..73de1080 100644 --- a/qBittorrentClient/app/src/main/res/values/colors_dark.xml +++ b/qBittorrentClient/app/src/main/res/values/colors_dark.xml @@ -10,5 +10,6 @@ #B6B6B6 #ff434343 + #111 #212121 \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/values/styles.xml b/qBittorrentClient/app/src/main/res/values/styles.xml index 38c8d763..c5891613 100644 --- a/qBittorrentClient/app/src/main/res/values/styles.xml +++ b/qBittorrentClient/app/src/main/res/values/styles.xml @@ -33,11 +33,14 @@ @color/Theme_Light_windowBackground @color/Theme_Light_windowBackground - - @drawable/background_selector_light + + @drawable/background_drawer_selector_light + + backgroundDrawerSelector + @drawable/gmd_shadow_light @@ -71,6 +74,9 @@ @drawable/background_selector_dark + + @drawable/background_drawer_selector_dark + @drawable/gmd_shadow_dark diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java index 5c2c2ddf..622a8b29 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java @@ -15,7 +15,9 @@ import android.app.ListFragment; import android.content.DialogInterface; import android.os.Bundle; +import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.RecyclerView; +import android.util.Log; import android.view.ActionMode; import android.view.LayoutInflater; import android.view.Menu; @@ -34,7 +36,9 @@ public class ItemstFragment extends ListFragment { int secondContainer; com.lgallardo.qbittorrentclient.TorrentDetailsFragment detailsFragment; private RecyclerView recyclerView; + private com.lgallardo.qbittorrentclient.RefreshListener refreshListener; + public static SwipeRefreshLayout mSwipeRefreshLayout; public ItemstFragment() { } @@ -60,8 +64,31 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa // wants to add/replace/delete using the onCreateOptionsMenu method. setHasOptionsMenu(true); + // Get Refresh Listener + refreshListener = (com.lgallardo.qbittorrentclient.RefreshListener) getActivity(); + View rootView = inflater.inflate(R.layout.activity_main_original, container, false); + + mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.activity_main_swipe_refresh_layout); + + mSwipeRefreshLayout.setColorSchemeColors(R.color.primary, R.color.primary_dark, R.color.primary_text); + + mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { +// com.lgallardo.qbittorrentclient.MainActivity.refreshCurrent(); + Log.d("Debug", "Swipe!"); + + refreshListener.swipeRefresh(); + + } + }); + + + + + // recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerViewList); return rootView; @@ -77,6 +104,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); try { + getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); // Get adapter @@ -88,6 +116,15 @@ public void onViewCreated(View view, Bundle savedInstanceState) { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { + + if(com.lgallardo.qbittorrentclient.MainActivity.listViewRefreshing) { + Log.d("Debug", "onViewCreated - listview is refreshing pal"); + } + else{ + Log.d("Debug", "onViewCreated - listview is NOT refreshing dude"); + } + + if (checked) { nr++; mAdapter.setNewSelection(position, checked); @@ -108,6 +145,8 @@ public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.main_contextual_action_bar, menu); + mSwipeRefreshLayout.setEnabled(false); + ItemstFragment.mActionMode = actionMode; return true; @@ -162,6 +201,10 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) { // Clear selection nr = 0; + + // Enable SwipeRefresh + mSwipeRefreshLayout.setEnabled(true); + mAdapter.clearSelection(); mode.finish(); @@ -173,6 +216,10 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) { // Clear selection nr = 0; + + // Enable SwipeRefresh + mSwipeRefreshLayout.setEnabled(true); + mAdapter.clearSelection(); mode.finish(); @@ -210,6 +257,10 @@ public void onClick(DialogInterface dialog, int id) { // Clear selection nr = 0; + + // Enable SwipeRefresh + mSwipeRefreshLayout.setEnabled(true); + mAdapter.clearSelection(); mode.finish(); @@ -248,6 +299,10 @@ public void onClick(DialogInterface dialog, int id) { // Clear selection nr = 0; + + // Enable SwipeRefresh + mSwipeRefreshLayout.setEnabled(true); + mAdapter.clearSelection(); mode.finish(); @@ -260,6 +315,10 @@ public void onClick(DialogInterface dialog, int id) { // Clear selection nr = 0; + + // Enable SwipeRefresh + mSwipeRefreshLayout.setEnabled(true); + mAdapter.clearSelection(); mode.finish(); @@ -270,6 +329,10 @@ public void onClick(DialogInterface dialog, int id) { // Clear selection nr = 0; + + // Enable SwipeRefresh + mSwipeRefreshLayout.setEnabled(true); + mAdapter.clearSelection(); mode.finish(); @@ -280,6 +343,10 @@ public void onClick(DialogInterface dialog, int id) { // Clear selection nr = 0; + + // Enable SwipeRefresh + mSwipeRefreshLayout.setEnabled(true); + mAdapter.clearSelection(); mode.finish(); @@ -290,6 +357,10 @@ public void onClick(DialogInterface dialog, int id) { // Clear selection nr = 0; + + // Enable SwipeRefresh + mSwipeRefreshLayout.setEnabled(true); + mAdapter.clearSelection(); mode.finish(); @@ -301,6 +372,10 @@ public void onClick(DialogInterface dialog, int id) { // Clear selection nr = 0; + + // Enable SwipeRefresh + mSwipeRefreshLayout.setEnabled(true); + mAdapter.clearSelection(); mode.finish(); @@ -312,6 +387,10 @@ public void onClick(DialogInterface dialog, int id) { // Clear selection nr = 0; + + // Enable SwipeRefresh + mSwipeRefreshLayout.setEnabled(true); + mAdapter.clearSelection(); mode.finish(); @@ -322,6 +401,10 @@ public void onClick(DialogInterface dialog, int id) { // Clear selection nr = 0; + + // Enable SwipeRefresh + mSwipeRefreshLayout.setEnabled(true); + mAdapter.clearSelection(); mode.finish(); @@ -332,6 +415,10 @@ public void onClick(DialogInterface dialog, int id) { // Clear selection nr = 0; + + // Enable SwipeRefresh + mSwipeRefreshLayout.setEnabled(true); + mAdapter.clearSelection(); mode.finish(); @@ -342,12 +429,18 @@ public void onClick(DialogInterface dialog, int id) { // Clear selection nr = 0; + + // Enable SwipeRefresh + mSwipeRefreshLayout.setEnabled(true); + mAdapter.clearSelection(); mode.finish(); return true; default: + // Enable SwipeRefresh + mSwipeRefreshLayout.setEnabled(true); return true; @@ -361,6 +454,7 @@ public void onDestroyActionMode(ActionMode actionMode) { mAdapter.clearSelection(); } ItemstFragment.mActionMode = null; + mSwipeRefreshLayout.setEnabled(true); } @@ -369,6 +463,10 @@ public void onDestroyActionMode(ActionMode actionMode) { getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView arg0, View arg1, int position, long arg3) { + + if(com.lgallardo.qbittorrentclient.MainActivity.listViewRefreshing) { + return true; + } getListView().setItemChecked(position, !mAdapter.isPositionChecked(position)); return false; } @@ -385,7 +483,11 @@ public boolean onItemLongClick(AdapterView arg0, View arg1, int position, lon @Override public void onListItemClick(ListView parent, View v, int position, long id) { - ListItemClicked(position); + if(!com.lgallardo.qbittorrentclient.MainActivity.listViewRefreshing) { + ListItemClicked(position); + + Log.d("Debug", "onListItemClick - not refreshing"); + } } public void ListItemClicked(int position) { diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index b2ffdd02..1a4fa1f5 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -60,7 +60,11 @@ import java.util.Collections; import java.util.HashMap; -public class MainActivity extends ActionBarActivity { +interface RefreshListener { + public void swipeRefresh(); +} + +public class MainActivity extends ActionBarActivity implements RefreshListener { // Torrent Info TAGs protected static final String TAG_NAME = "name"; @@ -133,7 +137,6 @@ public class MainActivity extends ActionBarActivity { protected static String max_act_downloads; protected static String max_act_uploads; protected static String max_act_torrents; - protected static ProgressBar progressBar; protected static long uploadSpeedCount; protected static long downloadSpeedCount; protected static int uploadCount; @@ -180,6 +183,7 @@ public class MainActivity extends ActionBarActivity { // New ToolBar in Material Desing Toolbar toolbar; + public static boolean listViewRefreshing; @Override protected void onCreate(Bundle savedInstanceState) { @@ -225,30 +229,27 @@ protected void onCreate(Bundle savedInstanceState) { if (Build.VERSION.SDK_INT >= 21) { getWindow().setNavigationBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); - getWindow().setStatusBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground )); + getWindow().setStatusBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); } } else { this.setTheme(R.style.Theme_Light); if (Build.VERSION.SDK_INT >= 21) { getWindow().setNavigationBarColor(getResources().getColor(R.color.primary)); - getWindow().setStatusBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground )); } } setContentView(R.layout.activity_main); + toolbar = (Toolbar) findViewById(R.id.app_bar); - if(dark_ui) { + if (dark_ui) { toolbar.setBackgroundColor(getResources().getColor(R.color.Theme_Dark_primary)); } - - setSupportActionBar(toolbar); - // Get progress bar - progressBar = (ProgressBar) findViewById(R.id.progressBarConnecting); + setSupportActionBar(toolbar); // Set App title setTitle(R.string.app_shortname); @@ -274,7 +275,7 @@ protected void onCreate(Bundle savedInstanceState) { drawerItem[8] = new ObjectDrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[8]); // Create object for drawer item OnbjectDrawerItem - DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.listview_item_row, drawerItem); + DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.drawer_row, drawerItem); drawerList.setAdapter(adapter); @@ -596,21 +597,29 @@ protected void onPostCreate(Bundle savedInstanceState) { @Override public void onBackPressed() { - FragmentManager fragmentManager = getFragmentManager(); - if (fragmentManager.getBackStackEntryCount() == 0) { - this.finish(); - } else { + if (!com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.isRefreshing()) { - fragmentManager.popBackStack(); - } - if (findViewById(R.id.one_frame) != null) { - if (header) { - headerInfo.setVisibility(View.VISIBLE); + FragmentManager fragmentManager = getFragmentManager(); + + if (fragmentManager.getBackStackEntryCount() == 0) { + this.finish(); } else { - headerInfo.setVisibility(View.GONE); + + fragmentManager.popBackStack(); } + + if (findViewById(R.id.one_frame) != null) { + if (headerInfo != null) { + if (header) { + headerInfo.setVisibility(View.VISIBLE); + } else { + headerInfo.setVisibility(View.GONE); + } + } + } + } } @@ -662,21 +671,21 @@ private void refresh(String state) { if (networkInfo != null && networkInfo.isConnected() && !networkInfo.isFailover()) { if (hostname.equals("")) { - // Hide progressBar - if (progressBar != null) { - progressBar.setVisibility(View.INVISIBLE); - } - // genericOkDialog(R.string.info, R.string.about_help1); } else { - // Show progressBar - if (progressBar != null && refresh_period != 1000) { - progressBar.setVisibility(View.VISIBLE); + + if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(true); + } + + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(true); } + // Execute the task in background qBittorrentTask qtt = new qBittorrentTask(); @@ -757,8 +766,8 @@ private void addTorrentByIntent(Intent intent) { // addTorrent(Uri.decode(urlTorrent)); try { addTorrent(Uri.decode(URLEncoder.encode(urlTorrent, "UTF-8"))); - }catch(UnsupportedEncodingException e){ - Log.e("Debug", "Check URL: "+e.toString()); + } catch (UnsupportedEncodingException e) { + Log.e("Debug", "Check URL: " + e.toString()); } } @@ -1972,6 +1981,17 @@ private void selectItem(int position) { } + @Override + public void swipeRefresh() { + Log.d("Debug", "Swipe 2!"); + + listViewRefreshing = true; + + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(false); + + refreshCurrent(); + } + // Here is where the action happens private class qBittorrentCookie extends AsyncTask { @@ -2548,7 +2568,7 @@ protected void onPostExecute(Torrent[] result) { //Set first and second fragments if (findViewById(R.id.fragment_container) != null) { - Log.d("Debug","fragment_container"); + Log.d("Debug", "fragment_container"); // Set where is the second container firstFragment.setSecondFragmentContainer(R.id.content_frame); @@ -2590,7 +2610,7 @@ protected void onPostExecute(Torrent[] result) { } else { - Log.d("Debug","one_frame"); + Log.d("Debug", "one_frame"); // Set where is the second container firstFragment.setSecondFragmentContainer(R.id.one_frame); @@ -2639,7 +2659,6 @@ protected void onPostExecute(Torrent[] result) { downloadSpeedTextView.setText(""); - //Set first and second fragments if (findViewById(R.id.fragment_container) != null) { @@ -2661,7 +2680,7 @@ protected void onPostExecute(Torrent[] result) { } } - }else{ + } else { // Set where is the second container firstFragment.setSecondFragmentContainer(R.id.one_frame); @@ -2714,11 +2733,22 @@ protected void onPostExecute(Torrent[] result) { } - // Hide progressBar - if (progressBar != null) { - progressBar.setVisibility(View.INVISIBLE); + if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(false); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.clearAnimation(); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(true); } + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(false); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.clearAnimation(); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(true); + } + + listViewRefreshing = false; + + + } } diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java index 8acfba40..c2f85371 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java @@ -15,6 +15,7 @@ import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; +import android.support.v4.widget.SwipeRefreshLayout; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; @@ -67,6 +68,8 @@ public class TorrentDetailsFragment extends Fragment { myPropertyAdapter propertyAdapter; private String qbQueryString = "query"; private Torrent torrent; + public static SwipeRefreshLayout mSwipeRefreshLayout; + private com.lgallardo.qbittorrentclient.RefreshListener refreshListener; public TorrentDetailsFragment() { @@ -176,6 +179,22 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa } + // Get Refresh Listener + refreshListener = (com.lgallardo.qbittorrentclient.RefreshListener) getActivity(); + mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.details_refresh_layout); + + if(mSwipeRefreshLayout != null) { + mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { +// com.lgallardo.qbittorrentclient.MainActivity.refreshCurrent(); + Log.d("Debug", "Swipe!"); + refreshListener.swipeRefresh(); + + } + }); + } + // Hide herderInfo in phone's view if (getActivity().findViewById(R.id.one_frame) != null) { com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.GONE); @@ -343,10 +362,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa } - // Show progressBar - if (com.lgallardo.qbittorrentclient.MainActivity.progressBar != null) { - com.lgallardo.qbittorrentclient.MainActivity.progressBar.setVisibility(View.VISIBLE); - } +// // Show progressBar +// if (com.lgallardo.qbittorrentclient.MainActivity.progressBar != null) { +// com.lgallardo.qbittorrentclient.MainActivity.progressBar.setVisibility(View.VISIBLE); +// } // Get Content files in background qBittorrentContentFile qcf = new qBittorrentContentFile(); @@ -494,10 +513,10 @@ public void updateDetails(Torrent torrent) { } - // Show progressBar - if (com.lgallardo.qbittorrentclient.MainActivity.progressBar != null) { - com.lgallardo.qbittorrentclient.MainActivity.progressBar.setVisibility(View.VISIBLE); - } +// // Show progressBar +// if (com.lgallardo.qbittorrentclient.MainActivity.progressBar != null) { +// com.lgallardo.qbittorrentclient.MainActivity.progressBar.setVisibility(View.VISIBLE); +// } // Get Content files in background qBittorrentContentFile qcf = new qBittorrentContentFile(); @@ -934,10 +953,10 @@ protected void onPostExecute(View[] rootViews) { Log.e("TorrentFragment:", e.toString()); } - // Hide progressBar - if (com.lgallardo.qbittorrentclient.MainActivity.progressBar != null) { - com.lgallardo.qbittorrentclient.MainActivity.progressBar.setVisibility(View.INVISIBLE); - } +// // Hide progressBar +// if (com.lgallardo.qbittorrentclient.MainActivity.progressBar != null) { +// com.lgallardo.qbittorrentclient.MainActivity.progressBar.setVisibility(View.INVISIBLE); +// } } diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentListAdapter.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentListAdapter.java index 766608c6..f7e9f494 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentListAdapter.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentListAdapter.java @@ -181,7 +181,7 @@ public boolean isEnabled(int position) { @Override public boolean areAllItemsEnabled() { - if (torrentsData != null) { + if (torrentsData != null && !com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.isRefreshing()) { return true; } else { return false; diff --git a/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml b/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml index 101f1a29..081f72ef 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml @@ -24,26 +24,17 @@ android:id="@+id/app_bar" layout="@layout/app_bar" /> - + - - - + android:paddingLeft="10dp" + xmlns:android="http://schemas.android.com/apk/res/android"> - \ No newline at end of file + \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml index 692480b3..6b8356c6 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml @@ -8,47 +8,31 @@ Contributors: Luis M. Gallardo D. - initial implementation --> - + android:layout_height="wrap_content" + android:paddingBottom="5dp" + android:paddingLeft="10dp" + xmlns:android="http://schemas.android.com/apk/res/android"> - + android:layout_height="match_parent"> - + android:layout_height="wrap_content"> - - + android:orientation="vertical" + android:background="?windowBackground"> - - - - - - + android:text="Torrent Name" + android:textSize="18sp" + android:textStyle="bold" /> - - + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + + + + + + + + + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:indeterminate="false" + android:max="100" + android:progress="0" /> - - - + android:layout_marginBottom="5dp" + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_marginTop="5dp" + android:orientation="horizontal"> - + - + + + + + + + + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_marginTop="5dp" + android:orientation="horizontal"> - + - + - + - - + - + + - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + - + - + - - + - + + - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_marginTop="10dp" + android:orientation="horizontal"> - - + - + + - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - - + - + + - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - - - + - + + + + android:orientation="vertical" + android:visibility="visible"> - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + - + android:orientation="vertical"> + + + - - - + android:orientation="vertical" + android:visibility="visible"> - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + - - + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> - + + + + android:orientation="vertical" + android:visibility="visible"> - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + + android:layout_marginBottom="5dp" + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> + + + - - \ No newline at end of file + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml b/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml index b0b0971e..028af410 100644 --- a/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml +++ b/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml @@ -8,45 +8,22 @@ Contributors: Luis M. Gallardo D. - initial implementation --> - + android:layout_height="wrap_content" + xmlns:android="http://schemas.android.com/apk/res/android"> - + android:layout_height="match_parent"> - - - - - + android:orientation="vertical" + android:background="?windowBackground"> - + android:text="Torrent Name" + android:textSize="18sp" + android:textStyle="bold" /> + + + + + + + + + + + android:layout_marginLeft="5dp" + android:text="0%" + android:textSize="25sp" /> - + + + android:layout_marginRight="5dp" + android:layout_marginTop="5dp" + android:orientation="horizontal"> + + + + + + + - + android:layout_marginLeft="15dp" + android:layout_marginRight="15dp" + android:layout_marginTop="5dp" + android:text="@string/torrent_details_properties" + android:textSize="18sp" + android:textStyle="bold" /> - - + android:layout_marginLeft="15dp" + android:layout_marginRight="15dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_marginTop="5dp" + android:orientation="horizontal"> - - - + - + - + - + - + + - - - - - + android:orientation="horizontal"> - - + - + - + - + - + + - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_marginTop="10dp" + android:orientation="horizontal"> - - + - + + - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - - + - + + - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + + + + - - + android:orientation="vertical" + android:visibility="visible"> - - - - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + - + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> + + + + + + + android:orientation="vertical" + android:visibility="visible"> - + android:layout_marginLeft="15dp" + android:layout_marginRight="15dp" + android:text="@string/torrent_details_trackers" + android:textSize="18sp" + android:textStyle="bold" /> - - - - - - - + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> + + + + android:orientation="vertical" + android:visibility="visible"> - - - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + - - - - + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> - + + - - \ No newline at end of file + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout/activity_main.xml b/qBittorrentClient/app/src/pro/res/layout/activity_main.xml index 841b8d13..d6356446 100644 --- a/qBittorrentClient/app/src/pro/res/layout/activity_main.xml +++ b/qBittorrentClient/app/src/pro/res/layout/activity_main.xml @@ -17,20 +17,12 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:background="?windowBackground"> + android:background="?backgroundSelector"> - - @@ -380,8 +380,8 @@ @@ -429,8 +429,8 @@ @@ -472,8 +472,8 @@ - + android:layout_height="wrap_content" + xmlns:android="http://schemas.android.com/apk/res/android"> - + android:layout_height="match_parent"> + android:orientation="vertical" + android:background="?windowBackground"> - - + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:orientation="horizontal"> - + + + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:layout_marginTop="5dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> + + + + + + android:layout_marginLeft="5dp" + android:text="0%" + android:textSize="25sp" /> - - - - - - + android:layout_marginRight="5dp" + android:indeterminate="false" + android:max="100" + android:progress="0" /> - + android:layout_marginBottom="5dp" + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_marginTop="5dp" + android:orientation="horizontal"> - + - - - + - + + + - + - - + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> - - - + android:layout_marginTop="5dp" + android:orientation="horizontal"> - + - - + - + - + - + + - + android:orientation="horizontal"> - + - - + - + - + - + + + - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_marginTop="10dp" + android:orientation="horizontal"> - + - + + - - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + - + + - - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + - + + + + android:orientation="vertical" + android:visibility="visible"> - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + - + android:orientation="vertical"> + + + - - - + android:orientation="vertical" + android:visibility="visible"> - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + - - + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> - + + + + android:orientation="vertical" + android:visibility="visible"> - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> + + + - - \ No newline at end of file + + \ No newline at end of file From 6410645e74efd31808c4ee21dbbfba3827c191c1 Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Mon, 27 Apr 2015 01:49:31 -0430 Subject: [PATCH 05/26] * [Pro] Fixed torrent list contextual menu issue when quiting the app * [Pro] Fixed torrent list contextual menu order to force main actions to appear --- .../app/src/main/res/menu/main.xml | 4 +-- .../res/menu/main_contextual_action_bar.xml | 4 +-- .../MainActivity.java | 25 ++++++++++++++----- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/qBittorrentClient/app/src/main/res/menu/main.xml b/qBittorrentClient/app/src/main/res/menu/main.xml index 10a2ce33..fdce5606 100644 --- a/qBittorrentClient/app/src/main/res/menu/main.xml +++ b/qBittorrentClient/app/src/main/res/menu/main.xml @@ -78,12 +78,12 @@ Date: Mon, 27 Apr 2015 12:17:53 -0430 Subject: [PATCH 06/26] * [Pro] Fixed all layouts to include the swipe to refresh feature --- .../MainActivity.java | 44 +- .../TorrentDetailsFragment.java | 6 +- .../pro/res/layout-large/torrent_details.xml | 741 +++++++++--------- .../res/layout-large/torrent_details_old.xml | 13 +- .../res/layout-sw600dp/torrent_details.xml | 736 ++++++++--------- .../layout-sw600dp/torrent_details_old.xml | 7 +- .../src/pro/res/layout/torrent_details.xml | 736 ++++++++--------- 7 files changed, 1147 insertions(+), 1136 deletions(-) diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index fca5fc3a..5ec5ecfb 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -597,45 +597,45 @@ protected void onPostCreate(Bundle savedInstanceState) { public void onBackPressed() { - if (!com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.isRefreshing()) { +// if (!com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.isRefreshing()) { - FragmentManager fm = getFragmentManager(); - com.lgallardo.qbittorrentclient.ItemstFragment fragment = null; - - // Close Contextual Action Bar - if (com.lgallardo.qbittorrentclient.ItemstFragment.mActionMode != null) { + FragmentManager fm = getFragmentManager(); + com.lgallardo.qbittorrentclient.ItemstFragment fragment = null; - com.lgallardo.qbittorrentclient.ItemstFragment.mActionMode.finish(); + // Close Contextual Action Bar + if (com.lgallardo.qbittorrentclient.ItemstFragment.mActionMode != null) { - } else { + com.lgallardo.qbittorrentclient.ItemstFragment.mActionMode.finish(); + } else { - if (fm.getBackStackEntryCount() == 0) { - // Close the app - this.finish(); + if (fm.getBackStackEntryCount() == 0) { + // Close the app + this.finish(); - } else { - fm.popBackStack(); - } + } else { + fm.popBackStack(); } - if (findViewById(R.id.one_frame) != null) { - if (headerInfo != null) { - if (header) { - headerInfo.setVisibility(View.VISIBLE); - } else { - headerInfo.setVisibility(View.GONE); - } + } + + if (findViewById(R.id.one_frame) != null) { + if (headerInfo != null) { + if (header) { + headerInfo.setVisibility(View.VISIBLE); + } else { + headerInfo.setVisibility(View.GONE); } } - } +// } + } private void refresh() { diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java index c2f85371..ebb1271c 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java @@ -575,7 +575,11 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.findItem(R.id.action_pause_all).setVisible(false); menu.findItem(R.id.action_add).setVisible(false); - menu.findItem(R.id.action_refresh).setVisible(true); + if (getActivity().findViewById(R.id.one_frame) != null) { + menu.findItem(R.id.action_refresh).setVisible(false); + }else{ + menu.findItem(R.id.action_refresh).setVisible(true); + } if (getActivity().findViewById(R.id.one_frame) != null) { menu.findItem(R.id.action_sort_menu).setVisible(false); diff --git a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details.xml b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details.xml index 682e0bec..665783e1 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details.xml @@ -8,484 +8,491 @@ Contributors: Luis M. Gallardo D. - initial implementation --> - + android:layout_height="wrap_content" + android:paddingBottom="5dp" + android:paddingLeft="10dp" + xmlns:android="http://schemas.android.com/apk/res/android"> - + android:layout_height="match_parent"> + android:orientation="vertical" + android:background="?windowBackground"> - - + android:layout_marginLeft="10dp" + android:layout_marginRight="15dp" + android:orientation="horizontal" + > - + + + android:layout_marginLeft="10dp" + android:layout_marginRight="15dp" + android:layout_marginTop="5dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> + + + + + + android:layout_marginLeft="5dp" + android:text="0%" + android:textSize="25sp" /> - - - - - - + android:layout_marginRight="5dp" + android:indeterminate="false" + android:max="100" + android:progress="0" /> - + android:layout_marginBottom="5dp" + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_marginTop="5dp" + android:orientation="horizontal"> - + - - - + - + + + - + - - + android:layout_marginLeft="10dp" + android:layout_marginRight="15dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> - - - + android:layout_marginTop="5dp" + android:orientation="horizontal"> - + - - + - + - + - + + - + android:orientation="horizontal"> - + - - + - + - + - + + + - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_marginTop="10dp" + android:orientation="horizontal"> - + - + + - - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + - + + - - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + - + + - + android:layout_marginLeft="0dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + - + + - + android:layout_marginLeft="0dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - - - + - + + + + + android:orientation="vertical" + android:visibility="visible"> - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + - + android:orientation="vertical"> + + + - - - + android:orientation="vertical" + android:visibility="visible"> - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + - - + android:layout_marginLeft="10dp" + android:layout_marginRight="15dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> - + + + + android:orientation="vertical" + android:visibility="visible"> - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + + android:layout_marginLeft="10dp" + android:layout_marginRight="15dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> + + + - - \ No newline at end of file + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml index 6b8356c6..a8922fa7 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml @@ -22,12 +22,6 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - - - + android:layout_height="match_parent" + xmlns:android="http://schemas.android.com/apk/res/android"> - + android:layout_height="match_parent"> + android:orientation="vertical" + android:background="?windowBackground"> - - + android:layout_marginLeft="10dp" + android:layout_marginRight="15dp" + android:orientation="horizontal"> - + + + android:layout_marginLeft="10dp" + android:layout_marginRight="15dp" + android:layout_marginTop="5dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> + + + + + + android:layout_marginLeft="5dp" + android:text="0%" + android:textSize="25sp" /> - - - - - - + android:layout_marginRight="5dp" + android:indeterminate="false" + android:max="100" + android:progress="0" /> - + android:layout_marginBottom="5dp" + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_marginTop="5dp" + android:orientation="horizontal"> - + - - - + - + + + - + - - + android:layout_marginLeft="10dp" + android:layout_marginRight="15dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> - - - + android:layout_marginTop="5dp" + android:orientation="horizontal"> - + - - + - + - + - + + - + android:orientation="horizontal"> - + - - + - + - + - + + + - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_marginTop="10dp" + android:orientation="horizontal"> - + - + + - - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + - + + - - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + - + + - + android:layout_marginLeft="0dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + - + + - + android:layout_marginLeft="0dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - - - + - + + + + + android:orientation="vertical" + android:visibility="visible"> - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + - + android:orientation="vertical"> + + + - - - + android:orientation="vertical" + android:visibility="visible"> - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + - - + android:layout_marginLeft="10dp" + android:layout_marginRight="15dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> - + + + + android:orientation="vertical" + android:visibility="visible"> - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + + android:layout_marginLeft="10dp" + android:layout_marginRight="15dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> + + + - - \ No newline at end of file + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml b/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml index 028af410..1a0b0804 100644 --- a/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml +++ b/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml @@ -11,7 +11,7 @@ - + android:layout_height="wrap_content" + xmlns:android="http://schemas.android.com/apk/res/android"> - + android:layout_height="match_parent"> + android:orientation="vertical" + android:background="?windowBackground"> - - + android:layout_marginRight="10dp" + android:orientation="horizontal" + > - + + + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:layout_marginTop="5dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> + + + + + + android:layout_marginLeft="5dp" + android:text="0%" + android:textSize="25sp" /> - - - - - - + android:layout_marginRight="5dp" + android:indeterminate="false" + android:max="100" + android:progress="0" /> - + android:layout_marginBottom="5dp" + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_marginTop="5dp" + android:orientation="horizontal"> - + - - - + - + + + - + - - + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> - - - + android:layout_marginTop="5dp" + android:orientation="horizontal"> - + - - + - + - + - + + - + android:orientation="horizontal"> - + - - + - + - + - + + + - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:layout_marginTop="10dp" + android:orientation="horizontal"> - + - + + - - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + - + + - - + android:layout_marginLeft="5dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + - + + - - - + android:layout_marginLeft="0dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + + - + - - + android:layout_marginLeft="0dp" + android:layout_marginRight="5dp" + android:orientation="horizontal"> - + - + + - - + android:orientation="vertical" + android:visibility="visible"> - + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:text="@string/torrent_details_content" + android:textSize="18sp" + android:textStyle="bold" /> - - - - - - - + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> + + + + + + + android:orientation="vertical" + android:visibility="visible"> - - - - + android:layout_marginTop="10dp" + android:orientation="vertical"> - + + - + android:layout_marginBottom="10dp" + android:background="?dropShadowBackground" + android:elevation="5dp" + android:orientation="vertical"> + + + + android:orientation="vertical" + android:visibility="visible"> + android:layout_marginTop="10dp" + android:orientation="vertical"> + + + + + + + + - - \ No newline at end of file + + \ No newline at end of file From caa069e7bec55a0f1ca70ed81d244573c598531e Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Wed, 29 Apr 2015 10:34:26 -0430 Subject: [PATCH 07/26] * [Pro] Fixed refresh behaviour to be complaint with Google Material Design --- .../qbittorrentclient/AboutFragment.java | 22 +++++++ .../app/src/main/res/layout/about.xml | 16 +++-- .../MainActivity.java | 66 +++++++------------ .../TorrentDetailsFragment.java | 1 - .../app/src/pro/res/layout-sw600dp/about.xml | 20 +++--- 5 files changed, 66 insertions(+), 59 deletions(-) diff --git a/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/AboutFragment.java b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/AboutFragment.java index a2f36b2a..0ee35dcf 100644 --- a/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/AboutFragment.java +++ b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/AboutFragment.java @@ -12,6 +12,8 @@ import android.app.Fragment; import android.os.Bundle; +import android.support.v4.widget.SwipeRefreshLayout; +import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -20,6 +22,9 @@ public class AboutFragment extends Fragment { + public static SwipeRefreshLayout mSwipeRefreshLayout; + private com.lgallardo.qbittorrentclient.RefreshListener refreshListener; + public AboutFragment() { } @@ -32,6 +37,23 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa View rootView = inflater.inflate(R.layout.about, container, false); + // Get Refresh Listener + refreshListener = (com.lgallardo.qbittorrentclient.RefreshListener) getActivity(); + + mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.about_refresh_layout); + + if(mSwipeRefreshLayout != null) { + mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + Log.d("Debug", "Swipe!"); + refreshListener.swipeRefresh(); + + } + }); + } + + return rootView; } diff --git a/qBittorrentClient/app/src/main/res/layout/about.xml b/qBittorrentClient/app/src/main/res/layout/about.xml index 4d4b5d4a..a5cec3b1 100644 --- a/qBittorrentClient/app/src/main/res/layout/about.xml +++ b/qBittorrentClient/app/src/main/res/layout/about.xml @@ -8,10 +8,11 @@ Contributors: Luis M. Gallardo D. - initial implementation --> - + - \ No newline at end of file + \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index 5ec5ecfb..3a4f4143 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -691,16 +691,7 @@ private void refresh(String state) { } else { - if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { - com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(true); - } - - if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { - com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(true); - } - - - // Execute the task in background + // Execute the task in background qBittorrentTask qtt = new qBittorrentTask(); qtt.execute(params); @@ -825,34 +816,7 @@ public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_refresh: - // Refresh option clicked. - switch (drawerList.getCheckedItemPosition()) { - case 0: - refresh("all"); - break; - case 1: - refresh("downloading"); - break; - case 2: - refresh("completed"); - break; - case 3: - refresh("paused"); - break; - case 4: - refresh("active"); - break; - case 5: - refresh("inactive"); - break; - case 6: - break; - case 7: - break; - default: - selectItem(0); - break; - } + swipeRefresh(); return true; case R.id.action_add: // Add URL torrent @@ -2001,7 +1965,20 @@ public void swipeRefresh() { listViewRefreshing = true; - com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(false); + + if (AboutFragment.mSwipeRefreshLayout != null) { + AboutFragment.mSwipeRefreshLayout.setRefreshing(true); + } + + if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(true); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(false); + } + + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(true); + } + refreshCurrent(); } @@ -2747,6 +2724,13 @@ protected void onPostExecute(Torrent[] result) { } + + if (com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.setRefreshing(false); + com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.clearAnimation(); + com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.setEnabled(true); + } + if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(false); com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.clearAnimation(); @@ -2755,8 +2739,8 @@ protected void onPostExecute(Torrent[] result) { if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(false); - com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.clearAnimation(); - com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(true); + com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.clearAnimation(); + com.lgallardo.qbittorrentclient.TorrentDetailsFragment .mSwipeRefreshLayout.setEnabled(true); } listViewRefreshing = false; diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java index ebb1271c..44c78a78 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java @@ -187,7 +187,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { -// com.lgallardo.qbittorrentclient.MainActivity.refreshCurrent(); Log.d("Debug", "Swipe!"); refreshListener.swipeRefresh(); diff --git a/qBittorrentClient/app/src/pro/res/layout-sw600dp/about.xml b/qBittorrentClient/app/src/pro/res/layout-sw600dp/about.xml index f4a0075e..a67df99c 100644 --- a/qBittorrentClient/app/src/pro/res/layout-sw600dp/about.xml +++ b/qBittorrentClient/app/src/pro/res/layout-sw600dp/about.xml @@ -8,19 +8,21 @@ Contributors: Luis M. Gallardo D. - initial implementation --> - + + + android:layout_height="wrap_content"> + android:orientation="vertical"> - - \ No newline at end of file + \ No newline at end of file From 704533044475d65d27311b23fc87dc9f02fd4b7a Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Sat, 2 May 2015 03:55:11 -0430 Subject: [PATCH 08/26] * Unified JSONParser in one common class for free and pro version (it's in main now)) * Replaced old android.support.v4.app.ActionBarDrawerToggle for android.support.v7.app.ActionBarDrawerToggle (new implementation for Google Material Design) * Changed behaviour of toolbar's home button when replacing the torrent's details fragment on phone versions. --- .../qbittorrentclient/JSONParser.java | 800 ------------------ .../qbittorrentclient}/JSONParser.java | 12 +- .../ItemstFragment.java | 22 + .../MainActivity.java | 19 +- 4 files changed, 39 insertions(+), 814 deletions(-) delete mode 100644 qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/JSONParser.java rename qBittorrentClient/app/src/{pro/java/com.lgallardo.qbittorrentclient => main/java/com/lgallardo/qbittorrentclient}/JSONParser.java (98%) diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/JSONParser.java b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/JSONParser.java deleted file mode 100644 index dec8664c..00000000 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/JSONParser.java +++ /dev/null @@ -1,800 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Luis M. Gallardo D.. - * All rights reserved. This program and the accompanying materials - * 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. - ******************************************************************************/ -package com.lgallardo.qbittorrentclient; - -import android.util.Log; - -import org.apache.http.HttpEntity; -import org.apache.http.HttpHost; -import org.apache.http.HttpResponse; -import org.apache.http.HttpVersion; -import org.apache.http.NameValuePair; -import org.apache.http.StatusLine; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.conn.ClientConnectionManager; -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.cookie.Cookie; -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; -import org.apache.http.params.BasicHttpParams; -import org.apache.http.params.HttpConnectionParams; -import org.apache.http.params.HttpParams; -import org.apache.http.params.HttpProtocolParams; -import org.apache.http.protocol.HTTP; -import org.apache.http.util.EntityUtils; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -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.net.URI; -import java.security.KeyStore; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class JSONParser { - static InputStream is = null; - private JSONObject jObj = null; - private JSONArray jArray = null; - private String json = ""; - private String hostname; - private String subfolder; - private int port; - private String protocol; - private String username; - private String password; - private int connection_timeout; - private int data_timeout; - - private static final int TIMEOUT_ERROR = 1; - private String cookie; - - // constructor - public JSONParser() { - this("", "", "", 0, "", "", 5, 8); - } - - public JSONParser(String hostname, String subfolder, int port, String username, String password) { - this(hostname, subfolder, "http", port, username, password, 5, 8); - } - - public JSONParser(String hostname, String subfolder, String protocol, int port, String username, String password, int connection_timeout, int data_timeout) { - - this.hostname = hostname; - this.subfolder = subfolder; - this.protocol = protocol; - this.port = port; - this.username = username; - this.password = password; - this.connection_timeout = connection_timeout; - this.data_timeout = data_timeout; - - } - - public void setCookie(String cookie) { - this.cookie = cookie; - } - - - public JSONObject getJSONFromUrl(String url) throws JSONParserStatusCodeException { - - // if server is published in a subfolder, fix url - if (subfolder != null && subfolder != "") { - url = subfolder + "/" + url; - } - - HttpResponse httpResponse; - DefaultHttpClient httpclient; - - HttpParams httpParameters = new BasicHttpParams(); - - // Set the timeout in milliseconds until a connection is established. - // The default value is zero, that means the timeout is not used. - int timeoutConnection = connection_timeout * 1000; - - // Set the default socket timeout (SO_TIMEOUT) - // in milliseconds which is the timeout for waiting for data. - int timeoutSocket = data_timeout * 1000; - - // Set http parameters - HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); - HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); - HttpProtocolParams.setUserAgent(httpParameters,"qBittorrent for Android"); - HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1); - HttpProtocolParams.setContentCharset(httpParameters,HTTP.UTF_8); - - // Making HTTP request - HttpHost targetHost = new HttpHost(this.hostname, this.port, this.protocol); - - // httpclient = new DefaultHttpClient(httpParameters); - // httpclient = new DefaultHttpClient(); - httpclient = getNewHttpClient(); - - httpclient.setParams(httpParameters); - - try { - - AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); - UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(this.username, this.password); - - httpclient.getCredentialsProvider().setCredentials(authScope, credentials); - - // set http parameters - - url = protocol + "://" + hostname + ":" + port +"/" +url; - - HttpGet httpget = new HttpGet(url); - - if (this.cookie != null) { - - httpget.setHeader("Cookie", this.cookie); - } - - httpResponse = httpclient.execute(targetHost, httpget); - - StatusLine statusLine = httpResponse.getStatusLine(); - - int mStatusCode = statusLine.getStatusCode(); - - if (mStatusCode != 200) { - httpclient.getConnectionManager().shutdown(); - throw new JSONParserStatusCodeException(mStatusCode); - } - - HttpEntity httpEntity = httpResponse.getEntity(); - is = httpEntity.getContent(); - - // Build JSON - BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8); - StringBuilder sb = new StringBuilder(); - String line = null; - while ((line = reader.readLine()) != null) { - sb.append(line + "\n"); - } - is.close(); - json = sb.toString(); - - // try parse the string to a JSON object - jObj = new JSONObject(json); - - } catch (JSONException e) { - Log.e("JSON Parser", "Error parsing data " + e.toString()); - } catch (UnsupportedEncodingException e) { - Log.e("JSON", "UnsupportedEncodingException: " + e.toString()); - - } catch (ClientProtocolException e) { - Log.e("JSON", "ClientProtocolException: " + e.toString()); - } catch (IOException e) { - Log.e("JSON", "IOException: " + e.toString()); - httpclient.getConnectionManager().shutdown(); - throw new JSONParserStatusCodeException(TIMEOUT_ERROR); - } catch (JSONParserStatusCodeException e) { - httpclient.getConnectionManager().shutdown(); - throw new JSONParserStatusCodeException(e.getCode()); - } catch (Exception e) { - Log.e("JSON", "Generic: " + e.toString()); - } finally { - // When HttpClient instance is no longer needed, - // shut down the connection manager to ensure - // immediate deallocation of all system resources - httpclient.getConnectionManager().shutdown(); - } - - // return JSON String - return jObj; - } - - public JSONArray getJSONArrayFromUrl(String url) throws JSONParserStatusCodeException { - - // if server is publish in a subfolder, fix url - if (subfolder != null && subfolder != "") { - url = subfolder + "/" + url; - } - - HttpResponse httpResponse; - DefaultHttpClient httpclient; - - HttpParams httpParameters = new BasicHttpParams(); - - // Set the timeout in milliseconds until a connection is established. - // The default value is zero, that means the timeout is not used. - int timeoutConnection = connection_timeout * 1000; - - // Set the default socket timeout (SO_TIMEOUT) - // in milliseconds which is the timeout for waiting for data. - int timeoutSocket = data_timeout * 1000; - - // Set http parameters - HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); - HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); - HttpProtocolParams.setUserAgent(httpParameters,"qBittorrent for Android"); - HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1); - HttpProtocolParams.setContentCharset(httpParameters,HTTP.UTF_8); - - // Making HTTP request - HttpHost targetHost = new HttpHost(hostname, port, protocol); - - httpclient = getNewHttpClient(); - - httpclient.setParams(httpParameters); - - try { - - AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); - UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); - - httpclient.getCredentialsProvider().setCredentials(authScope, credentials); - - url = protocol + "://" + hostname + ":" + port +"/" +url; - - HttpGet httpget = new HttpGet(url); - - if (this.cookie != null) { - httpget.setHeader("Cookie", this.cookie); - } - - httpResponse = httpclient.execute(targetHost, httpget); - - // This could help to detect if device is banned - StatusLine statusLine = httpResponse.getStatusLine(); - - int mStatusCode = statusLine.getStatusCode(); - - if (mStatusCode != 200) { - httpclient.getConnectionManager().shutdown(); - throw new JSONParserStatusCodeException(mStatusCode); - } - ; - - HttpEntity httpEntity = httpResponse.getEntity(); - is = httpEntity.getContent(); - - // Build JSON - - BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8); - StringBuilder sb = new StringBuilder(); - String line = null; - while ((line = reader.readLine()) != null) { - sb.append(line + "\n"); - } - is.close(); - json = sb.toString(); - - jArray = new JSONArray(json); - } catch (JSONException e) { - Log.e("JSON Parser", "Error parsing data " + e.toString()); - } catch (UnsupportedEncodingException e) { - } catch (ClientProtocolException e) { - Log.e("JSON", "Client: " + e.toString()); - } catch (IOException e) { - Log.e("JSON", "IO: " + e.toString()); - httpclient.getConnectionManager().shutdown(); - throw new JSONParserStatusCodeException(TIMEOUT_ERROR); - } catch (JSONParserStatusCodeException e) { - httpclient.getConnectionManager().shutdown(); - throw new JSONParserStatusCodeException(e.getCode()); - } catch (Exception e) { - Log.e("JSON", "Generic: " + e.toString()); - } finally { - // When HttpClient instance is no longer needed, - // shut down the connection manager to ensure - // immediate deallocation of all system resources - httpclient.getConnectionManager().shutdown(); - } - - // return JSON String - return jArray; - } - - public void postCommand(String command, String hash) throws JSONParserStatusCodeException { - - String key = "hash"; - - String urlContentType = "application/x-www-form-urlencoded"; - - String limit = ""; - String boundary = null; - - HttpResponse httpResponse; - DefaultHttpClient httpclient; - - String url = ""; - - if ("start".equals(command) || "startSelected".equals(command)) { - url = "command/resume"; - } - - if ("pause".equals(command) || "pauseSelected".equals(command)) { - url = "command/pause"; - } - - if ("delete".equals(command) || "deleteSelected".equals(command)) { - url = "command/delete"; - key = "hashes"; - } - - if ("deleteDrive".equals(command) || "deleteDriveSelected".equals(command)) { - url = "command/deletePerm"; - key = "hashes"; - } - - if ("addTorrent".equals(command)) { - 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"; - } - - if ("resumeAll".equals(command)) { - url = "command/resumeall"; - } - - if ("increasePrio".equals(command)) { - url = "command/increasePrio"; - key = "hashes"; - } - - if ("decreasePrio".equals(command)) { - url = "command/decreasePrio"; - key = "hashes"; - ; - } - - if ("maxPrio".equals(command)) { - url = "command/topPrio"; - key = "hashes"; - } - - if ("minPrio".equals(command)) { - url = "command/bottomPrio"; - key = "hashes"; - ; - } - - if ("setQBittorrentPrefefrences".equals(command)) { - url = "command/setPreferences"; - key = "json"; - } - - if ("setUploadRateLimit".equals(command)) { - url = "command/setTorrentUpLimit"; - - String[] tmpString = hash.split("&"); - hash = tmpString[0]; - limit = tmpString[1]; - } - - if ("setDownloadRateLimit".equals(command)) { - url = "command/setTorrentDlLimit"; - - String[] tmpString = hash.split("&"); - hash = tmpString[0]; - limit = tmpString[1]; - } - - if ("recheckSelected".equals(command)) { - url = "command/recheck"; - } - - if ("recheckSelected".equals(command)) { - url = "command/recheck"; - } - - if ("toggleFirstLastPiecePrio".equals(command)) { - url = "command/toggleFirstLastPiecePrio"; - key = "hashes"; - - } - - if ("toggleSequentialDownload".equals(command)) { - url = "command/toggleSequentialDownload"; - key = "hashes"; - - } - - // if server is publish in a subfolder, fix url - if (subfolder != null && subfolder != "") { - url = subfolder + "/" + url; - } - - HttpParams httpParameters = new BasicHttpParams(); - - // Set the timeout in milliseconds until a connection is established. - // The default value is zero, that means the timeout is not used. - int timeoutConnection = connection_timeout * 1000; - - // Set the default socket timeout (SO_TIMEOUT) - // in milliseconds which is the timeout for waiting for data. - int timeoutSocket = data_timeout * 1000; - - // Set http parameters - HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); - HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); - HttpProtocolParams.setUserAgent(httpParameters,"qBittorrent for Android"); - HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1); - HttpProtocolParams.setContentCharset(httpParameters,HTTP.UTF_8); - - - // Making HTTP request - HttpHost targetHost = new HttpHost(this.hostname, this.port, this.protocol); - - // httpclient = new DefaultHttpClient(); - httpclient = getNewHttpClient(); - - try { - - AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); - - UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(this.username, this.password); - - httpclient.getCredentialsProvider().setCredentials(authScope, credentials); - - url = protocol + "://" + hostname + ":" + port +"/" +url; - - HttpPost httpget = new HttpPost(url); - - if ("addTorrent".equals(command)) { - URI hash_uri = new URI(hash); - hash = hash_uri.toString(); - } - - // In order to pass the has we must set the pair name value - BasicNameValuePair bnvp = new BasicNameValuePair(key, hash); - - List nvps = new ArrayList(); - nvps.add(bnvp); - - // Add limit - 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) || "maxPrio".equals(command)) { - httpget.setHeader("Content-Type", urlContentType); - } - - if (this.cookie != null) { - httpget.setHeader("Cookie", this.cookie); - } - - // Set content type and urls - if ("addTorrentFile".equals(command)) { - - 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); - - } - - httpResponse = httpclient.execute(targetHost, httpget); - - StatusLine statusLine = httpResponse.getStatusLine(); - - int mStatusCode = statusLine.getStatusCode(); - - if (mStatusCode != 200) { - httpclient.getConnectionManager().shutdown(); - throw new JSONParserStatusCodeException(mStatusCode); - } - - HttpEntity httpEntity = httpResponse.getEntity(); - - is = httpEntity.getContent(); - - } catch (UnsupportedEncodingException e) { - } catch (ClientProtocolException e) { - Log.e("qbittorrent", "Client: " + e.toString()); - } catch (IOException e) { - Log.e("qbittorrent", "IO: " + e.toString()); - httpclient.getConnectionManager().shutdown(); - throw new JSONParserStatusCodeException(TIMEOUT_ERROR); - } catch (JSONParserStatusCodeException e) { - httpclient.getConnectionManager().shutdown(); - throw new JSONParserStatusCodeException(e.getCode()); - } catch (Exception e) { - Log.e("qbittorrent", "Generic: " + e.toString()); - } finally { - // When HttpClient instance is no longer needed, - // shut down the connection manager to ensure - // immediate deallocation of all system resources - httpclient.getConnectionManager().shutdown(); - } - - } - - // https - public DefaultHttpClient getNewHttpClient() { - try { - KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); - trustStore.load(null, null); - - MySSLSocketFactory sf = new MySSLSocketFactory(trustStore); - sf.setHostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); - - HttpParams params = new BasicHttpParams(); - -// HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); -// HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); - - SchemeRegistry registry = new SchemeRegistry(); - registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); - registry.register(new Scheme("https", sf, 443)); - - ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); - - return new DefaultHttpClient(ccm, params); - } catch (Exception e) { - return new DefaultHttpClient(); - } - } - - // Cookies - public String getNewCookie() throws JSONParserStatusCodeException { - - - String url = "/login"; - - // if server is publish in a subfolder, fix url - if (subfolder != null && subfolder != "") { - url = subfolder + "/" + url; - } - - String cookieString = null; - - HttpResponse httpResponse; - DefaultHttpClient httpclient; - - HttpParams httpParameters = new BasicHttpParams(); - - // Set the timeout in milliseconds until a connection is established. - // The default value is zero, that means the timeout is not used. - int timeoutConnection = connection_timeout * 1000; - - // Set the default socket timeout (SO_TIMEOUT) - // in milliseconds which is the timeout for waiting for data. - int timeoutSocket = data_timeout * 1000; - - // Set http parameters - HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); - HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); - HttpProtocolParams.setUserAgent(httpParameters,"qBittorrent for Android"); - HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1); - HttpProtocolParams.setContentCharset(httpParameters,HTTP.UTF_8); - - - // Making HTTP request - HttpHost targetHost = new HttpHost(hostname, port, protocol); - - // httpclient = new DefaultHttpClient(); - httpclient = getNewHttpClient(); - - try { - -// AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); -// -// UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(this.username, this.password); -// -// httpclient.getCredentialsProvider().setCredentials(authScope, credentials); - - url = protocol + "://" + hostname + ":" + port +"/" +url; - - HttpPost httpget = new HttpPost(url); - -// // In order to pass the username and password we must set the pair name value - - List nvps = new ArrayList(); - - - nvps.add(new BasicNameValuePair("username", this.username)); - nvps.add(new BasicNameValuePair("password", this.password)); - - httpget.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); - - - HttpResponse response = httpclient.execute(targetHost, httpget); - HttpEntity entity = response.getEntity(); - -// Log.i("Cookies", "Login form get: " + response.getStatusLine()); - - StatusLine statusLine = response.getStatusLine(); - - int mStatusCode = statusLine.getStatusCode(); - - if (mStatusCode == 200) { - - // Save cookie - - -// Log.i("Cookies", "Initial set of cookies"); - - List cookies = httpclient.getCookieStore().getCookies(); - if (cookies.isEmpty()) { -// Log.i("Cookies", "None"); - - } else { - - -// Log.i("Cookies", "Cookie=>" + cookies.get(0).toString()); - - // Save cookie - cookieString = cookies.get(0).getName() + "=" + cookies.get(0).getValue() + "; domain=" + cookies.get(0).getDomain(); - - cookieString = cookies.get(0).getName() + "=" + cookies.get(0).getValue(); - - - } - - } - - if (entity != null) { - entity.consumeContent(); - } - - - // When HttpClient instance is no longer needed, - // shut down the connection manager to ensure - // immediate deallocation of all system resources - httpclient.getConnectionManager().shutdown(); - - } catch (Exception e) { - -// Log.i("Cookies", "Exception " + e.toString()); - } - - if (cookieString == null) { - cookieString = ""; - } - return cookieString; - - - } - - public String getApiVersion() throws JSONParserStatusCodeException { - - - String url = "/version/api"; - - // if server is publish in a subfolder, fix url - if (subfolder != null && subfolder != "") { - url = subfolder + "/" + url; - } - - String APIVersionString = null; - - HttpResponse httpResponse; - DefaultHttpClient httpclient; - - HttpParams httpParameters = new BasicHttpParams(); - - // Set the timeout in milliseconds until a connection is established. - // The default value is zero, that means the timeout is not used. - int timeoutConnection = connection_timeout * 1000; - - // Set the default socket timeout (SO_TIMEOUT) - // in milliseconds which is the timeout for waiting for data. - int timeoutSocket = data_timeout * 1000; - - // Set http parameters - HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); - HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); - HttpProtocolParams.setUserAgent(httpParameters,"qBittorrent for Android"); - HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1); - HttpProtocolParams.setContentCharset(httpParameters,HTTP.UTF_8); - - - // Making HTTP request - HttpHost targetHost = new HttpHost(hostname, port, protocol); - - // httpclient = new DefaultHttpClient(); - httpclient = getNewHttpClient(); - - try { - - url = protocol + "://" + hostname + ":" + port +"/" +url; - - HttpGet httpget = new HttpGet(url); - - HttpResponse response = httpclient.execute(targetHost, httpget); - HttpEntity entity = response.getEntity(); - -// Log.i("APIVer", "API Ver Status: " + response.getStatusLine()); - - StatusLine statusLine = response.getStatusLine(); - - int mStatusCode = statusLine.getStatusCode(); - - if (mStatusCode == 200) { - - // Save API - - APIVersionString = EntityUtils.toString(response.getEntity()); - - } - - - if (entity != null) { - entity.consumeContent(); - } - - // When HttpClient instance is no longer needed, - // shut down the connection manager to ensure - // immediate deallocation of all system resources - httpclient.getConnectionManager().shutdown(); - - } catch (Exception e) { - -// Log.i("APIVer", "Exception " + e.toString()); - } - - if (APIVersionString == null) { - APIVersionString = ""; - } - return APIVersionString; - } - - -} diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/JSONParser.java b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java similarity index 98% rename from qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/JSONParser.java rename to qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java index c3e009ae..6dd488e6 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/JSONParser.java +++ b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java @@ -234,8 +234,8 @@ public JSONArray getJSONArrayFromUrl(String url) throws JSONParserStatusCodeExce HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); HttpProtocolParams.setUserAgent(httpParameters,"qBittorrent for Android"); - HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1); - HttpProtocolParams.setContentCharset(httpParameters,HTTP.UTF_8); + HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1); + HttpProtocolParams.setContentCharset(httpParameters, HTTP.UTF_8); // Making HTTP request HttpHost targetHost = new HttpHost(hostname, port, protocol); @@ -639,8 +639,8 @@ public String getNewCookie() throws JSONParserStatusCodeException { HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); HttpProtocolParams.setUserAgent(httpParameters,"qBittorrent for Android"); - HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1); - HttpProtocolParams.setContentCharset(httpParameters,HTTP.UTF_8); + HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1); + HttpProtocolParams.setContentCharset(httpParameters, HTTP.UTF_8); // Making HTTP request HttpHost targetHost = new HttpHost(hostname, port, protocol); @@ -758,8 +758,8 @@ public String getApiVersion() throws JSONParserStatusCodeException { HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); HttpProtocolParams.setUserAgent(httpParameters,"qBittorrent for Android"); - HttpProtocolParams.setVersion(httpParameters,HttpVersion.HTTP_1_1); - HttpProtocolParams.setContentCharset(httpParameters,HTTP.UTF_8); + HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1); + HttpProtocolParams.setContentCharset(httpParameters, HTTP.UTF_8); // Making HTTP request HttpHost targetHost = new HttpHost(hostname, port, protocol); diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java index 622a8b29..fb4e42e8 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java @@ -29,6 +29,8 @@ import android.widget.AdapterView; import android.widget.ListView; +import java.util.Set; + public class ItemstFragment extends ListFragment { static public ActionMode mActionMode; @@ -37,6 +39,7 @@ public class ItemstFragment extends ListFragment { com.lgallardo.qbittorrentclient.TorrentDetailsFragment detailsFragment; private RecyclerView recyclerView; private com.lgallardo.qbittorrentclient.RefreshListener refreshListener; + private View.OnClickListener originalListener; public static SwipeRefreshLayout mSwipeRefreshLayout; @@ -547,6 +550,25 @@ private void newDetailsFragment(int position){ if (getActivity().findViewById(R.id.one_frame) != null) { fragmentManager.beginTransaction().replace(this.getSecondFragmentContainer(), detailsFragment, "firstFragment").addToBackStack("secondFragment").commit(); + + // Change toolbal home button behaviour + originalListener = com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.getToolbarNavigationClickListener(); + + com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setDrawerIndicatorEnabled(false); + com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setHomeAsUpIndicator(R.drawable.ic_drawer); + com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + // Set default toolbar behaviour + com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setDrawerIndicatorEnabled(true); + com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setToolbarNavigationClickListener(originalListener); + FragmentManager fm = getFragmentManager(); + fm.popBackStack(); + } + }); + + } else { fragmentManager.beginTransaction().replace(this.getSecondFragmentContainer(), detailsFragment, "secondFragment").addToBackStack("secondFragment").commit(); } diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index 3a4f4143..cf542a87 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -10,6 +10,7 @@ ******************************************************************************/ package com.lgallardo.qbittorrentclient; +import android.app.Activity; import android.app.AlarmManager; import android.app.AlertDialog; import android.app.AlertDialog.Builder; @@ -33,7 +34,7 @@ import android.os.Handler; import android.os.SystemClock; import android.preference.PreferenceManager; -import android.support.v4.app.ActionBarDrawerToggle; +import android.support.v7.app.ActionBarDrawerToggle; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; @@ -149,19 +150,18 @@ public class MainActivity extends ActionBarActivity implements RefreshListener { public TorrentListAdapter myadapter; // Http status code public int httpStatusCode = 0; - protected DrawerLayout drawerLayout; + TextView name1, size1; // Preferences fields private SharedPreferences sharedPrefs; private StringBuilder builderPrefs; // Drawer properties - private String[] navigationDrawerItemTitles; - private ListView drawerList; private CharSequence drawerTitle; private CharSequence title; - // For app icon control for navigation drawer, add new property on - // MainActivity - private ActionBarDrawerToggle drawerToggle; + private String[] navigationDrawerItemTitles; + private ListView drawerList; + public static DrawerLayout drawerLayout; + public static ActionBarDrawerToggle drawerToggle; private AboutFragment secondFragment; private HelpFragment helpTabletFragment; private AboutFragment aboutFragment; @@ -290,7 +290,10 @@ protected void onCreate(Bundle savedInstanceState) { // Add the application icon control code inside MainActivity onCreate drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); - drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { + + // New ActionBarDrawerToggle for Google Material Desing (v7) + drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { + /** * Called when a drawer has settled in a completely closed state. From 94a15009f14d4b9f9248939d92bbb4e46b2c5b3c Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Wed, 13 May 2015 03:11:49 -0430 Subject: [PATCH 09/26] * Added default SearchView (pre L) --- .../app/src/main/res/menu/main.xml | 4 +- .../app/src/main/res/values/styles.xml | 2 +- .../MainActivity.java | 54 +++++++++++++++---- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/qBittorrentClient/app/src/main/res/menu/main.xml b/qBittorrentClient/app/src/main/res/menu/main.xml index fdce5606..fb9cf3d5 100644 --- a/qBittorrentClient/app/src/main/res/menu/main.xml +++ b/qBittorrentClient/app/src/main/res/menu/main.xml @@ -139,9 +139,9 @@ \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/values/styles.xml b/qBittorrentClient/app/src/main/res/values/styles.xml index c5891613..af92e600 100644 --- a/qBittorrentClient/app/src/main/res/values/styles.xml +++ b/qBittorrentClient/app/src/main/res/values/styles.xml @@ -44,9 +44,9 @@ @drawable/gmd_shadow_light - true + diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index cf542a87..9040e83a 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -10,7 +10,6 @@ ******************************************************************************/ package com.lgallardo.qbittorrentclient; -import android.app.Activity; import android.app.AlarmManager; import android.app.AlertDialog; import android.app.AlertDialog.Builder; @@ -34,9 +33,11 @@ import android.os.Handler; import android.os.SystemClock; import android.preference.PreferenceManager; -import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v4.view.MenuItemCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.LayoutInflater; @@ -184,6 +185,11 @@ public class MainActivity extends ActionBarActivity implements RefreshListener { Toolbar toolbar; public static boolean listViewRefreshing; + // Search bar in Material Design + private MenuItem mSearchAction; + private boolean isSearchOpened = false; + private EditText editSearch; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -316,8 +322,8 @@ public void onDrawerOpened(View drawerView) { drawerLayout.setDrawerListener(drawerToggle); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setHomeButtonEnabled(true); + getSupportActionBar().setDisplayHomeAsUpEnabled(false); + getSupportActionBar().setHomeButtonEnabled(false); // Get options and save them as shared preferences @@ -444,6 +450,14 @@ public void onDrawerOpened(View drawerView) { } + // Search bar in Material Design + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + mSearchAction = menu.findItem(R.id.action_search); + return super.onPrepareOptionsMenu(menu); + } + + // Set selection and title on drawer public void setSelectionAndTitle(String state) { // Set selection according to last state @@ -599,10 +613,6 @@ protected void onPostCreate(Bundle savedInstanceState) { @Override public void onBackPressed() { - -// if (!com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.isRefreshing()) { - - FragmentManager fm = getFragmentManager(); com.lgallardo.qbittorrentclient.ItemstFragment fragment = null; @@ -637,7 +647,6 @@ public void onBackPressed() { } } -// } } @@ -797,13 +806,31 @@ private void addTorrentByIntent(Intent intent) { @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.main, menu); +// getMenuInflater().inflate(R.menu.main, menu); - // Associate searchable configuration with the SearchView +// // Associate searchable configuration with the SearchView // SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); // SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); // searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); +// return true; + + + + getMenuInflater().inflate(R.menu.main, menu); + + SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); + + SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); + + if (searchView != null) { + searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); + searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default + + Log.d("Debug", "searchView is not NULL"); + + } + return true; } @@ -818,6 +845,11 @@ public boolean onOptionsItemSelected(MenuItem item) { } switch (item.getItemId()) { + + case R.id.action_search: + Log.d("Debug", "Search in Main"); + onSearchRequested(); + return true; case R.id.action_refresh: swipeRefresh(); return true; From 17d2716e82b71dc88a09846c633d095e2caf4a29 Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Fri, 15 May 2015 01:11:24 -0430 Subject: [PATCH 10/26] * Fixed authentication issue with qBittorrent version 3.2.0 --- .../main/java/com/lgallardo/qbittorrentclient/JSONParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java index 6dd488e6..a0c2d80b 100644 --- a/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java +++ b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java @@ -613,7 +613,7 @@ public DefaultHttpClient getNewHttpClient() { public String getNewCookie() throws JSONParserStatusCodeException { - String url = "/login"; + String url = "login"; // if server is publish in a subfolder, fix url if (subfolder != null && subfolder != "") { From 40a9154b3adb139272e8c6be87163b056b2d611a Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Mon, 18 May 2015 12:09:42 -0430 Subject: [PATCH 11/26] * Fixed Resume all and pause all in qBittorrent v3.2.0 --- .../lgallardo/qbittorrentclient/JSONParser.java | 13 +++++++++++-- .../MainActivity.java | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java index a0c2d80b..838133d5 100644 --- a/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java +++ b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java @@ -364,14 +364,23 @@ public void postCommand(String command, String hash) throws JSONParserStatusCode } - if ("pauseAll".equals(command)) { + if ("pauseall".equals(command)) { url = "command/pauseall"; } - if ("resumeAll".equals(command)) { + if ("pauseAll".equals(command)) { + url = "command/pauseAll"; + } + + + if ("resumeall".equals(command)) { url = "command/resumeall"; } + if ("resumeAll".equals(command)) { + url = "command/resumeAll"; + } + if ("increasePrio".equals(command)) { url = "command/increasePrio"; key = "hashes"; diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index 9040e83a..9ff7e5f0 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -1428,13 +1428,24 @@ public void addTorrentFile(String url) { public void pauseAllTorrents() { // Execute the task in background qBittorrentCommand qtc = new qBittorrentCommand(); - qtc.execute(new String[]{"pauseAll", null}); + + if (qb_version.equals("3.2.x")) { + qtc.execute(new String[]{"pauseAll", null}); + } + else{ + qtc.execute(new String[]{"pauseall", null}); + } } public void resumeAllTorrents() { // Execute the task in background qBittorrentCommand qtc = new qBittorrentCommand(); - qtc.execute(new String[]{"resumeAll", null}); + + if (qb_version.equals("3.2.x")) { + qtc.execute(new String[]{"resumeAll", null}); + }else{ + qtc.execute(new String[]{"resumeall", null}); + } } public void increasePrioTorrent(String hash) { From e7b51621b1cea8be4d913535e24ac6b232ddcf92 Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Tue, 19 May 2015 16:22:55 -0430 Subject: [PATCH 12/26] * Added SwipeRefresh when launching the app. Also when selecting an option on the drawer menu --- .../qbittorrentclient/AboutFragment.java | 20 ++++ .../app/src/main/res/layout/about.xml | 2 +- .../MainActivity.java | 98 ++++++++++++++++--- .../app/src/pro/res/layout-sw600dp/about.xml | 2 +- 4 files changed, 108 insertions(+), 14 deletions(-) diff --git a/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/AboutFragment.java b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/AboutFragment.java index 0ee35dcf..441b162f 100644 --- a/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/AboutFragment.java +++ b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/AboutFragment.java @@ -14,6 +14,7 @@ import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.util.Log; +import android.util.TypedValue; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -24,6 +25,7 @@ public class AboutFragment extends Fragment { public static SwipeRefreshLayout mSwipeRefreshLayout; private com.lgallardo.qbittorrentclient.RefreshListener refreshListener; + public static boolean isFragmentFirstLoaded = true; public AboutFragment() { } @@ -42,6 +44,23 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.about_refresh_layout); + // This fix the SwipeRefreshLayout setRefreshing not showing indicator initially issue + // by calling setProgressViewOffset() on the SwipeRefreshLayout that invalidtes the circle view of the layout causing + // SwipeRefreshLayout.onMeasure() to be called immediately. + + if(isFragmentFirstLoaded) { + + TypedValue typed_value = new TypedValue(); + getActivity().getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, typed_value, true); + mSwipeRefreshLayout.setProgressViewOffset(false, 0, getResources().getDimensionPixelSize(typed_value.resourceId) * 2); + + mSwipeRefreshLayout.setColorSchemeColors(R.color.primary, R.color.primary_dark, R.color.primary_text); + + mSwipeRefreshLayout.setRefreshing(true); + + isFragmentFirstLoaded = false; + } + if(mSwipeRefreshLayout != null) { mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override @@ -54,6 +73,7 @@ public void onRefresh() { } + return rootView; } diff --git a/qBittorrentClient/app/src/main/res/layout/about.xml b/qBittorrentClient/app/src/main/res/layout/about.xml index a5cec3b1..2141a846 100644 --- a/qBittorrentClient/app/src/main/res/layout/about.xml +++ b/qBittorrentClient/app/src/main/res/layout/about.xml @@ -37,7 +37,7 @@ android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" - android:layout_marginTop="75dp" + android:layout_marginTop="10dp" android:contentDescription="@string/app_name" android:src="@drawable/ic_launcher" /> diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index 9ff7e5f0..10ec5c47 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -442,9 +442,18 @@ public void onDrawerOpened(View drawerView) { // Activity is visble activityIsVisible = true; - // // Autorefresh + +// // Set the refresh layout (refresh icon, etc) +// refreshSwipeLayout(); +// if (secondFragment.mSwipeRefreshLayout != null) { +// secondFragment.mSwipeRefreshLayout.setRefreshing(true); +// } + + // First refresh refreshCurrent(); + Log.d("Debug","First refresh done"); + handler = new Handler(); handler.postDelayed(m_Runnable, refresh_period); @@ -556,11 +565,24 @@ public void onResume() { } - @Override - public void onPause() { - super.onPause(); - activityIsVisible = false; - } +// @Override +// public void onPause() { +// super.onPause(); +// activityIsVisible = false; +// } + +// @Override +// public void onStart(){ +// // Set the refresh layout (refresh icon, etc) +// refreshSwipeLayout(); +// +// // First refresh +//// refreshCurrent(); +// +// Log.d("Debug","First refresh done"); +// +// super.onStart(); +// } @Override public void onSaveInstanceState(Bundle outState) { @@ -626,6 +648,9 @@ public void onBackPressed() { if (fm.getBackStackEntryCount() == 0) { + // Set About first load to true + AboutFragment.isFragmentFirstLoaded = true; + // Close the app this.finish(); @@ -663,7 +688,6 @@ private void refresh(String state) { return; } - if (qb_version.equals("2.x")) { qbQueryString = "json"; params[0] = qbQueryString + "/events"; @@ -702,7 +726,6 @@ private void refresh(String state) { } else { - // Execute the task in background qBittorrentTask qtt = new qBittorrentTask(); @@ -1131,6 +1154,27 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Commit changes editor.apply(); + + // Set theme + + if (dark_ui) { + this.setTheme(R.style.Theme_Dark); + + if (Build.VERSION.SDK_INT >= 21) { + getWindow().setNavigationBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); + getWindow().setStatusBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); + } + } else { + this.setTheme(R.style.Theme_Light); + + if (Build.VERSION.SDK_INT >= 21) { + getWindow().setNavigationBarColor(getResources().getColor(R.color.primary)); + } + + } + +// this.recreate(); + alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplication(), NotifierService.class); alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0); @@ -1945,27 +1989,38 @@ private void selectItem(int position) { switch (position) { case 0: - + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); refresh("all"); saveLastState("all"); break; case 1: + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); refresh("downloading"); saveLastState("downloading"); break; case 2: + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); refresh("completed"); saveLastState("completed"); break; case 3: + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); refresh("paused"); saveLastState("paused"); break; case 4: + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); refresh("active"); saveLastState("active"); break; case 5: + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); refresh("inactive"); saveLastState("inactive"); break; @@ -2007,6 +2062,16 @@ private void selectItem(int position) { @Override public void swipeRefresh() { + + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); + + // Actually refresh data + refreshCurrent(); + } + + public void refreshSwipeLayout() { + Log.d("Debug", "Swipe 2!"); listViewRefreshing = true; @@ -2014,19 +2079,26 @@ public void swipeRefresh() { if (AboutFragment.mSwipeRefreshLayout != null) { AboutFragment.mSwipeRefreshLayout.setRefreshing(true); + }else{ + Log.d("Debug", "AboutFragment.mSwipeRefreshLayout is NULL"); + } if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(true); com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(false); + }else{ + Log.d("Debug", "ItemstFragment.mSwipeRefreshLayout is NULL"); + } if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(true); - } + }else{ + Log.d("Debug", "TorrentDetailsFragment.mSwipeRefreshLayout is NULL"); + } - refreshCurrent(); } // Here is where the action happens @@ -2765,12 +2837,14 @@ protected void onPostExecute(Torrent[] result) { Log.e("ADAPTER", e.toString()); } + + Log.d("Debug"," qBittorrentTask - post execute completed"); + // Clear serch field searchField = ""; } - if (com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout != null) { com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.setRefreshing(false); com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.clearAnimation(); diff --git a/qBittorrentClient/app/src/pro/res/layout-sw600dp/about.xml b/qBittorrentClient/app/src/pro/res/layout-sw600dp/about.xml index a67df99c..81f1ca3a 100644 --- a/qBittorrentClient/app/src/pro/res/layout-sw600dp/about.xml +++ b/qBittorrentClient/app/src/pro/res/layout-sw600dp/about.xml @@ -39,7 +39,7 @@ android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" - android:layout_marginTop="100dp" + android:layout_marginTop="50dp" android:contentDescription="@string/app_name" android:src="@drawable/ic_launcher" /> From d9f45128eca8e13530b3db84ea413036210daa30 Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Tue, 19 May 2015 18:56:02 -0430 Subject: [PATCH 13/26] * Added remove of toolbar title in torrent details for phone view --- .../java/com.lgallardo.qbittorrentclient/ItemstFragment.java | 4 +++- .../java/com.lgallardo.qbittorrentclient/MainActivity.java | 3 +++ .../TorrentDetailsFragment.java | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java index fb4e42e8..8a26e5a2 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java @@ -551,7 +551,7 @@ private void newDetailsFragment(int position){ if (getActivity().findViewById(R.id.one_frame) != null) { fragmentManager.beginTransaction().replace(this.getSecondFragmentContainer(), detailsFragment, "firstFragment").addToBackStack("secondFragment").commit(); - // Change toolbal home button behaviour + // Change toolbar home button behaviour originalListener = com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.getToolbarNavigationClickListener(); com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setDrawerIndicatorEnabled(false); @@ -561,8 +561,10 @@ private void newDetailsFragment(int position){ public void onClick(View v) { // Set default toolbar behaviour + ((com.lgallardo.qbittorrentclient.MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true); com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setDrawerIndicatorEnabled(true); com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setToolbarNavigationClickListener(originalListener); + FragmentManager fm = getFragmentManager(); fm.popBackStack(); } diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index 10ec5c47..f17d3508 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -657,6 +657,9 @@ public void onBackPressed() { } else { + // Enable toolbar title + getSupportActionBar().setDisplayShowTitleEnabled(true); + fm.popBackStack(); } diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java index 44c78a78..1a9c500b 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java @@ -197,6 +197,7 @@ public void onRefresh() { // Hide herderInfo in phone's view if (getActivity().findViewById(R.id.one_frame) != null) { com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.GONE); + ((com.lgallardo.qbittorrentclient.MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false); } From bb9f0039e29f979d520c8810ccca5810a1dc40f0 Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Wed, 20 May 2015 09:57:43 -0430 Subject: [PATCH 14/26] * Added toolbar title when performing an action (pause, resume, etc) --- .../ItemstFragment.java | 16 ++++++++++++++++ .../MainActivity.java | 3 +++ .../TorrentDetailsFragment.java | 7 ++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java index 8a26e5a2..896e9d10 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java @@ -197,6 +197,8 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) { hashesStr = hashes; + ((com.lgallardo.qbittorrentclient.MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true); + switch (item.getItemId()) { case R.id.action_pause: @@ -565,6 +567,20 @@ public void onClick(View v) { com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setDrawerIndicatorEnabled(true); com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setToolbarNavigationClickListener(originalListener); + // Show herderInfo in phone's view + if (getActivity().findViewById(R.id.one_frame) != null) { + + if (com.lgallardo.qbittorrentclient.MainActivity.headerInfo != null) { + if (com.lgallardo.qbittorrentclient.MainActivity.header) { + com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.VISIBLE); + } else { + com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.GONE); + } + } + + } + + FragmentManager fm = getFragmentManager(); fm.popBackStack(); } diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index f17d3508..4710a126 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -870,6 +870,9 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; } + // Enable title (just in case) + getSupportActionBar().setDisplayShowTitleEnabled(true); + switch (item.getItemId()) { case R.id.action_search: diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java index 1a9c500b..85574ef7 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java @@ -194,7 +194,7 @@ public void onRefresh() { }); } - // Hide herderInfo in phone's view + // Hide herderInfo and title in phone's view if (getActivity().findViewById(R.id.one_frame) != null) { com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.GONE); ((com.lgallardo.qbittorrentclient.MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false); @@ -392,6 +392,11 @@ public void updateDetails(Torrent torrent) { try { + // Hide herderInfo in phone's view + if (getActivity().findViewById(R.id.one_frame) != null) { + com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.GONE); + } + // Get values from current activity name = torrent.getFile(); size = torrent.getSize(); From c574d520a797f3ea5838436f604b1b308f2d770e Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Wed, 20 May 2015 11:31:57 -0430 Subject: [PATCH 15/26] * Fixed header info layout --- .../MainActivity.java | 20 ------------------- .../pro/res/layout-large/activity_main.xml | 4 +++- .../pro/res/layout-large/torrent_details.xml | 1 + .../res/layout-large/torrent_details_old.xml | 1 + .../res/layout-sw600dp/torrent_details.xml | 1 + .../layout-sw600dp/torrent_details_old.xml | 1 + .../app/src/pro/res/layout/activity_main.xml | 5 ++++- .../app/src/pro/res/layout/row.xml | 10 +++++----- 8 files changed, 16 insertions(+), 27 deletions(-) diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index 4710a126..0ca812de 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -1161,26 +1161,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { editor.apply(); - // Set theme - - if (dark_ui) { - this.setTheme(R.style.Theme_Dark); - - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setNavigationBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); - getWindow().setStatusBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); - } - } else { - this.setTheme(R.style.Theme_Light); - - if (Build.VERSION.SDK_INT >= 21) { - getWindow().setNavigationBarColor(getResources().getColor(R.color.primary)); - } - - } - -// this.recreate(); - alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplication(), NotifierService.class); alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0); diff --git a/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml b/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml index 081f72ef..aed3dbae 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml @@ -33,7 +33,9 @@ android:layout_below="@+id/app_bar" android:gravity="end" android:orientation="horizontal" - android:paddingBottom="5dp"> + android:paddingBottom="5dp" + android:background="?dropShadowBackground" + android:elevation="1dp"> diff --git a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml index a8922fa7..49d58679 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml @@ -33,6 +33,7 @@ android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="15dp" + android:layout_marginTop="5dp" android:orientation="horizontal"> + android:paddingTop="2dp" + android:paddingBottom="2dp" + android:background="?dropShadowBackground" + android:elevation="1dp"> + android:paddingLeft="4dp"> Date: Wed, 20 May 2015 12:10:27 -0430 Subject: [PATCH 16/26] Release 4.0.0 * Google Material Design adaptation * Fixed resume all nd pause all actions * Fixed header info in phone view --- qBittorrentClient/app/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qBittorrentClient/app/build.gradle b/qBittorrentClient/app/build.gradle index 8a771b18..dcf816b0 100644 --- a/qBittorrentClient/app/build.gradle +++ b/qBittorrentClient/app/build.gradle @@ -22,18 +22,18 @@ android { productFlavors { pro { applicationId 'com.lgallardo.qbittorrentclientpro' - versionName '3.9.3' + versionName '4.0.0' minSdkVersion 14 targetSdkVersion 21 - versionCode 393 + versionCode 400 archivesBaseName = "qBittorrentClient_v" + versionName } free { applicationId "com.lgallardo.qbittorrentclient" - versionName '3.9.3' + versionName '4.0.0' minSdkVersion 14 targetSdkVersion 21 - versionCode 393 + versionCode 400 archivesBaseName = "qBittorrentClient_v" + versionName } } From 918abf8f7081d5e1877cf403fd4dba62bccbabae Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Fri, 22 May 2015 17:06:30 -0430 Subject: [PATCH 17/26] * Fixed header info not showing after a command in phone view --- .../MainActivity.java | 36 ++++++++++--------- qBittorrentClient/qBittorrentClient.iml | 6 ++-- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index 0ca812de..a511bbd3 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -33,7 +33,6 @@ import android.os.Handler; import android.os.SystemClock; import android.preference.PreferenceManager; -import android.support.v4.view.MenuItemCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarDrawerToggle; @@ -860,6 +859,11 @@ public boolean onCreateOptionsMenu(Menu menu) { return true; } + public void popBackStackPhoneView(){ + getFragmentManager().popBackStack(); + headerInfo.setVisibility(View.VISIBLE); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -891,7 +895,7 @@ public boolean onOptionsItemSelected(MenuItem item) { pauseTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -900,7 +904,7 @@ public boolean onOptionsItemSelected(MenuItem item) { startTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -933,7 +937,7 @@ public void onClick(DialogInterface dialog, int id) { deleteTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } @@ -970,7 +974,7 @@ public void onClick(DialogInterface dialog, int id) { deleteDriveTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } @@ -990,7 +994,7 @@ public void onClick(DialogInterface dialog, int id) { increasePrioTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -999,7 +1003,7 @@ public void onClick(DialogInterface dialog, int id) { decreasePrioTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -1008,7 +1012,7 @@ public void onClick(DialogInterface dialog, int id) { maxPrioTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -1017,7 +1021,7 @@ public void onClick(DialogInterface dialog, int id) { minPrioTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -1031,7 +1035,7 @@ public void onClick(DialogInterface dialog, int id) { if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { uploadRateLimitDialog(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -1040,7 +1044,7 @@ public void onClick(DialogInterface dialog, int id) { if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { downloadRateLimitDialog(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -1048,7 +1052,7 @@ public void onClick(DialogInterface dialog, int id) { if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { recheckTorrents(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -1056,7 +1060,7 @@ public void onClick(DialogInterface dialog, int id) { if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { toggleFirstLastPiecePrio(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -1064,7 +1068,7 @@ public void onClick(DialogInterface dialog, int id) { if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { toggleSequentialDownload(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -2295,14 +2299,14 @@ protected void onPostExecute(String result) { if ("setUploadRateLimit".equals(result)) { messageId = R.string.setUploadRateLimit; if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } if ("setDownloadRateLimit".equals(result)) { messageId = R.string.setDownloadRateLimit; if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } diff --git a/qBittorrentClient/qBittorrentClient.iml b/qBittorrentClient/qBittorrentClient.iml index 0bb6048a..88b12b1c 100644 --- a/qBittorrentClient/qBittorrentClient.iml +++ b/qBittorrentClient/qBittorrentClient.iml @@ -1,9 +1,10 @@ - + @@ -15,5 +16,4 @@ - - + \ No newline at end of file From c0727265aaa2bfeb688f7373c872886978bad148 Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Tue, 26 May 2015 15:58:00 -0430 Subject: [PATCH 18/26] * Code rearrenged in odert to unify MainActivity.java * Unified ItemFragment.java --- .../qbittorrentclient/ItemstFragment.java | 568 ----------- .../qbittorrentclient/MainActivity.java | 892 +++++++++--------- .../qbittorrentclient}/ItemstFragment.java | 128 +-- .../MainActivity.java | 368 ++------ 4 files changed, 602 insertions(+), 1354 deletions(-) delete mode 100644 qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/ItemstFragment.java rename qBittorrentClient/app/src/{pro/java/com.lgallardo.qbittorrentclient => main/java/com/lgallardo/qbittorrentclient}/ItemstFragment.java (83%) diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/ItemstFragment.java b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/ItemstFragment.java deleted file mode 100644 index f793f5c9..00000000 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/ItemstFragment.java +++ /dev/null @@ -1,568 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Luis M. Gallardo D.. - * All rights reserved. This program and the accompanying materials - * 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. - ******************************************************************************/ -package com.lgallardo.qbittorrentclient; - -import android.app.AlertDialog; -import android.app.FragmentManager; -import android.app.ListFragment; -import android.content.DialogInterface; -import android.os.Bundle; -import android.util.Log; -import android.view.ActionMode; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AbsListView; -import android.widget.AdapterView; -import android.widget.ListView; - -import com.lgallardo.qbittorrentclient.MainActivity; - -public class ItemstFragment extends ListFragment { - - static public ActionMode mActionMode; - public int nr = 0; - int secondContainer; - TorrentDetailsFragment detailsFragment; - ; - - public ItemstFragment() { - } - - public void setSecondFragmentContainer(int container) { - - this.secondContainer = container; - - } - - public int getSecondFragmentContainer() { - - return this.secondContainer; - - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - - super.onCreateView(inflater, container, 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); - - SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.activity_main_swipe_refresh_layout); - - mSwipeRefreshLayout.setColo - mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - MainActivity.refreshCurrent(); - } - }); - - return rootView; - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - try { - getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); - - // Get adapter - final TorrentListAdapter mAdapter = (TorrentListAdapter) this.getListAdapter(); - getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { - - private int nr = 0; - - @Override - public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { - - if (checked) { - nr++; - mAdapter.setNewSelection(position, checked); - - } else { - nr--; - mAdapter.removeSelection(position); - } -// mode.setTitle(nr + " selected"); - mode.setTitle("" + nr); - - - } - - @Override - public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { - nr = 0; - MenuInflater inflater = getActivity().getMenuInflater(); - inflater.inflate(R.menu.main_contextual_action_bar, menu); - - ItemstFragment.mActionMode = actionMode; - - return true; - - } - - @Override - public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { - if (MainActivity.qb_version.equals("3.2.x")) { - menu.findItem(R.id.action_firts_last_piece_prio).setVisible(true); - menu.findItem(R.id.action_sequential_download).setVisible(true); - } else { - menu.findItem(R.id.action_firts_last_piece_prio).setVisible(false); - menu.findItem(R.id.action_sequential_download).setVisible(false); - } - return true; - } - - @Override - public boolean onActionItemClicked(ActionMode mode, MenuItem item) { - - AlertDialog.Builder builder; - AlertDialog dialog; - String hashes = null; - final String hashesStr; - - // Get MainActivity - final MainActivity m = (MainActivity) getActivity(); - - // Get hashes - for (int i = 0; mAdapter.getCount() > i; i++) { - - - if (mAdapter.isPositionChecked(i)) { - Log.i("ItemsFragment", "Name: " + mAdapter.getData()[i].getFile()); - Log.i("ItemsFragment", "Hash: " + mAdapter.getData()[i].getHash()); - - if (hashes == null) { - hashes = mAdapter.getData()[i].getHash(); - } else { - hashes = hashes + "|" + mAdapter.getData()[i].getHash(); - } - - } - - } - - hashesStr = hashes; - - - Log.i("ItemsFragment", "Hashes: " + hashes); - - switch (item.getItemId()) { - - case R.id.action_pause: - m.pauseSelectedTorrents(hashes); - - // Clear selection - nr = 0; - mAdapter.clearSelection(); - mode.finish(); - - return true; - - - case R.id.action_resume: - m.startSelectedTorrents(hashes); - - // Clear selection - nr = 0; - mAdapter.clearSelection(); - mode.finish(); - - return true; - - case R.id.action_delete: - - if (!getActivity().isFinishing()) { - builder = new AlertDialog.Builder(getActivity()); - - // Message - builder.setMessage(R.string.dm_deleteSelectedTorrents).setTitle(R.string.dt_deleteSelectedTorrents); - - // Cancel - builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - // User canceled the dialog - } - }); - - // Ok - builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - // User accepted the dialog - m.deleteSelectedTorrents(hashesStr); - - } - }); - - // Create dialog - dialog = builder.create(); - - // Show dialog - dialog.show(); - - // Clear selection - nr = 0; - mAdapter.clearSelection(); - mode.finish(); - - } - - return true; - case R.id.action_delete_drive: - - if (!getActivity().isFinishing()) { - builder = new AlertDialog.Builder(getActivity()); - - // Message - builder.setMessage(R.string.dm_deleteDriveSelectedTorrents).setTitle(R.string.dt_deleteDriveSelectedTorrents); - - // Cancel - builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - // User canceled the dialog - } - }); - - // Ok - builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - // User accepted the dialog - m.deleteDriveSelectedTorrents(hashesStr); - - } - }); - - // Create dialog - dialog = builder.create(); - - // Show dialog - dialog.show(); - - // Clear selection - nr = 0; - mAdapter.clearSelection(); - mode.finish(); - - } - - return true; - - - case R.id.action_increase_prio: - m.increasePrioTorrent(hashes); - - // Clear selection - nr = 0; - mAdapter.clearSelection(); - mode.finish(); - - return true; - - case R.id.action_decrease_prio: - m.decreasePrioTorrent(hashes); - - // Clear selection - nr = 0; - mAdapter.clearSelection(); - mode.finish(); - - return true; - - case R.id.action_max_prio: - m.maxPrioTorrent(hashes); - - // Clear selection - nr = 0; - mAdapter.clearSelection(); - mode.finish(); - - return true; - - case R.id.action_min_prio: - m.minPrioTorrent(hashes); - - // Clear selection - nr = 0; - mAdapter.clearSelection(); - mode.finish(); - - return true; - - case R.id.action_upload_rate_limit: - - m.uploadRateLimitDialog(hashes); - - // Clear selection - nr = 0; - mAdapter.clearSelection(); - mode.finish(); - - return true; - - case R.id.action_download_rate_limit: - - m.downloadRateLimitDialog(hashes); - - // Clear selection - nr = 0; - mAdapter.clearSelection(); - mode.finish(); - - case R.id.action_recheck: - - m.recheckTorrents(hashes); - - // Clear selection - nr = 0; - mAdapter.clearSelection(); - mode.finish(); - - case R.id.action_sequential_download: - - m.toggleSequentialDownload(hashes); - - // Clear selection - nr = 0; - mAdapter.clearSelection(); - mode.finish(); - - return true; - case R.id.action_firts_last_piece_prio: - - m.toggleFirstLastPiecePrio(hashes); - - // Clear selection - nr = 0; - mAdapter.clearSelection(); - mode.finish(); - - return true; - default: - return true; - - - } - - - } - - @Override - public void onDestroyActionMode(ActionMode actionMode) { - if (mAdapter != null) { - mAdapter.clearSelection(); - } - ItemstFragment.mActionMode = null; - - - } - }); - - getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { - @Override - public boolean onItemLongClick(AdapterView arg0, View arg1, int position, long arg3) { - getListView().setItemChecked(position, !mAdapter.isPositionChecked(position)); - return false; - } - }); - } catch (Exception e) { - getListView().setChoiceMode(ListView.CHOICE_MODE_NONE); - - } - - } - - // @Override - public void onListItemClick(ListView parent, View v, int position, long id) { - - ListItemClicked(position); - - } - - public void ListItemClicked(int position) { - - ListView lv = this.getListView(); - - int count = lv.getCount(); - -// if (count == 1 && lv.getItemAtPosition(0).equals(getString(R.string.no_results))) { -// -// return; -// } - - Torrent torrent = MainActivity.lines[position]; - - if (torrent.getHash().equals(TorrentDetailsFragment.hashToUpdate) && getActivity().findViewById(R.id.fragment_container) != null) { - - // Update torrent details - - FragmentManager fragmentManager = getFragmentManager(); - if(!(fragmentManager.findFragmentByTag("secondFragment") instanceof AboutFragment)) { - - - - detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("secondFragment"); - - if (detailsFragment != null && torrent != null) { - - detailsFragment.updateDetails(torrent); - } - } - else{ - newDetailsFragment(position); - } - } else { - - newDetailsFragment(position); - - } - } - - private void newDetailsFragment(int position){ - - detailsFragment = new TorrentDetailsFragment(); - - // Get torrent from MainActivity - detailsFragment.setTorrent(MainActivity.lines[position]); - - detailsFragment.setPosition(position); - - if (detailsFragment != null) { - FragmentManager fragmentManager = getFragmentManager(); - - if (getActivity().findViewById(R.id.one_frame) != null) { - fragmentManager.beginTransaction().replace(this.getSecondFragmentContainer(), detailsFragment, "firstFragment").addToBackStack("secondFragment").commit(); - } else { - fragmentManager.beginTransaction().replace(this.getSecondFragmentContainer(), detailsFragment, "secondFragment").addToBackStack("secondFragment").commit(); - } - } - - } - - // @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - // inflater.inflate(R.menu.main, menu); - // super.onCreateOptionsMenu(menu, inflater); - - if (menu != null) { - menu.findItem(R.id.action_refresh).setVisible(true); - menu.findItem(R.id.action_search).setVisible(true); - menu.findItem(R.id.action_resume_all).setVisible(true); - menu.findItem(R.id.action_pause_all).setVisible(true); - menu.findItem(R.id.action_add).setVisible(true); - - if (menu.findItem(R.id.action_resume) != null) { - menu.findItem(R.id.action_resume).setVisible(false); - } - if (menu.findItem(R.id.action_pause) != null) { - menu.findItem(R.id.action_pause).setVisible(false); - } - if (menu.findItem(R.id.action_increase_prio) != null) { - menu.findItem(R.id.action_increase_prio).setVisible(false); - } - if (menu.findItem(R.id.action_decrease_prio) != null) { - menu.findItem(R.id.action_decrease_prio).setVisible(false); - - } - - if (menu.findItem(R.id.action_max_prio) != null) { - menu.findItem(R.id.action_max_prio).setVisible(false); - } - - if (menu.findItem(R.id.action_min_prio) != null) { - menu.findItem(R.id.action_min_prio).setVisible(false); - } - - if (menu.findItem(R.id.action_delete) != null) { - menu.findItem(R.id.action_delete).setVisible(false); - } - 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); - } - - if (menu.findItem(R.id.action_recheck) != null) { - menu.findItem(R.id.action_recheck).setVisible(false); - } - - if (menu.findItem(R.id.action_firts_last_piece_prio) != null) { - menu.findItem(R.id.action_firts_last_piece_prio).setVisible(false); - } - - if (menu.findItem(R.id.action_sequential_download) != null) { - menu.findItem(R.id.action_sequential_download).setVisible(false); - } - - if (menu.findItem(R.id.action_priority_menu) != null) { - menu.findItem(R.id.action_priority_menu).setVisible(false); - } - - menu.findItem(R.id.action_sortby_name).setVisible(true); - menu.findItem(R.id.action_sortby_eta).setVisible(true); - menu.findItem(R.id.action_sortby_priority).setVisible(true); - menu.findItem(R.id.action_sortby_progress).setVisible(true); - menu.findItem(R.id.action_sortby_ratio).setVisible(true); - menu.findItem(R.id.action_sortby_downloadSpeed).setVisible(true); - menu.findItem(R.id.action_sortby_uploadSpeed).setVisible(true); - - - if (MainActivity.sortby.equals("Name")) { - menu.findItem(R.id.action_sortby_name).setIcon(R.drawable.ic_stat_completed); - - } - - - if (MainActivity.sortby.equals("ETA")) { - menu.findItem(R.id.action_sortby_eta).setIcon(R.drawable.ic_stat_completed); - } - - if (MainActivity.sortby.equals("Priority")) { - ; - menu.findItem(R.id.action_sortby_priority).setIcon(R.drawable.ic_stat_completed); - } - - if (MainActivity.sortby.equals("Progress")) { - menu.findItem(R.id.action_sortby_progress).setIcon(R.drawable.ic_stat_completed); - } - - if (MainActivity.sortby.equals("Ratio")) { - - menu.findItem(R.id.action_sortby_ratio).setIcon(R.drawable.ic_stat_completed); - } - - if (MainActivity.sortby.equals("DownloadSpeed")) { - menu.findItem(R.id.action_sortby_downloadSpeed).setIcon(R.drawable.ic_stat_completed); - } - - if (MainActivity.sortby.equals("UploadSpeed")) { - menu.findItem(R.id.action_sortby_uploadSpeed).setIcon(R.drawable.ic_stat_completed); - } - - - } - } - -} diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java index e49b44bc..78043950 100644 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java @@ -28,13 +28,15 @@ import android.net.NetworkInfo; import android.net.Uri; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.SystemClock; import android.preference.PreferenceManager; -import android.support.v4.app.ActionBarDrawerToggle; -import android.support.v4.app.FragmentActivity; import android.support.v4.widget.DrawerLayout; +import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; @@ -44,8 +46,6 @@ import android.widget.EditText; import android.widget.LinearLayout; import android.widget.ListView; -import android.widget.ProgressBar; -import android.widget.SearchView; import android.widget.TextView; import android.widget.Toast; @@ -62,16 +62,11 @@ import java.util.Collections; import java.util.HashMap; -public class MainActivity extends FragmentActivity { - - // Params to get JSON Array - private static String[] params = new String[2]; +interface RefreshListener { + public void swipeRefresh(); +} - // JSON Node Names -// protected static final String TAG_USER = "user"; -// protected static final String TAG_ID = "id"; -// protected static final String TAG_ALTDWLIM = "alt_dl_limit"; -// protected static final String TAG_DWLIM = "dl_limit"; +public class MainActivity extends ActionBarActivity implements RefreshListener { // Torrent Info TAGs protected static final String TAG_NAME = "name"; @@ -88,7 +83,6 @@ public class MainActivity extends FragmentActivity { protected static final String TAG_ETA = "eta"; protected static final String TAG_SEQDL = "seq_dl"; protected static final String TAG_FLPIECEPRIO = "f_l_piece_prio"; - protected static final String TAG_GLOBAL_MAX_NUM_CONNECTIONS = "max_connec"; protected static final String TAG_MAX_NUM_CONN_PER_TORRENT = "max_connec_per_torrent"; protected static final String TAG_MAX_NUM_UPSLOTS_PER_TORRENT = "max_uploads_per_torrent"; @@ -100,14 +94,23 @@ public class MainActivity extends FragmentActivity { protected static final String TAG_MAX_ACT_DOWNLOADS = "max_active_downloads"; protected static final String TAG_MAX_ACT_UPLOADS = "max_active_uploads"; protected static final String TAG_MAX_ACT_TORRENTS = "max_active_torrents"; - - protected static JSONParser jParser; + protected static final String TAG_URL = "url"; protected static final int SETTINGS_CODE = 0; protected static final int OPTION_CODE = 1; protected static final int GETPRO_CODE = 2; protected static final int HELP_CODE = 3; + // Cookie (SID - Session ID) + public static String cookie = null; + public static String qb_version = "3.1.x"; + public static LinearLayout headerInfo; + + // Current state + public static String currentState; + + protected static com.lgallardo.qbittorrentclient.JSONParser jParser; + // Preferences properties protected static String hostname; protected static String subfolder; @@ -115,7 +118,6 @@ public class MainActivity extends FragmentActivity { protected static String protocol; protected static String username; protected static String password; - protected static boolean oldVersion; protected static boolean https; protected static boolean auto_refresh; protected static int refresh_period; @@ -140,27 +142,37 @@ public class MainActivity extends FragmentActivity { protected static String max_act_downloads; protected static String max_act_uploads; protected static String max_act_torrents; - - // Preferences fields - private SharedPreferences sharedPrefs; - private StringBuilder builderPrefs; + protected static long uploadSpeedCount; + protected static long downloadSpeedCount; + protected static int uploadCount; + protected static int downloadCount; static Torrent[] lines; static String[] names; - TextView name1, size1; + // Params to get JSON Array + private static String[] params = new String[2]; + public com.lgallardo.qbittorrentclient.ItemstFragment firstFragment; + + // myAdapter myadapter + public TorrentListAdapter myadapter; + + // Http status code + public int httpStatusCode = 0; + + // Preferences fields + private SharedPreferences sharedPrefs; + private StringBuilder builderPrefs; // Drawer properties - private String[] navigationDrawerItemTitles; - protected DrawerLayout drawerLayout; - private ListView drawerList; private CharSequence drawerTitle; private CharSequence title; - // For app icon control for navigation drawer, add new property on - // MainActivity - private ActionBarDrawerToggle drawerToggle; + private String[] navigationDrawerItemTitles; + private ListView drawerList; + public static DrawerLayout drawerLayout; + public static ActionBarDrawerToggle drawerToggle; - private ItemstFragment firstFragment; + // Fragments private AboutFragment secondFragment; private HelpFragment helpTabletFragment; private AboutFragment aboutFragment; @@ -171,6 +183,7 @@ public class MainActivity extends FragmentActivity { private Handler handler; private boolean canrefresh = true; + // Ads View private AdView adView; // For checking if the app is visible @@ -181,39 +194,20 @@ public class MainActivity extends FragmentActivity { // Searching field private String searchField = ""; - - // Progress bar - protected static ProgressBar progressBar; - - // myAdapter myadapter - TorrentListAdapter myadapter; - - // Http status code - public int httpStatusCode = 0; - - // Cookie (SID - Session ID) - public static String cookie = null; - // qb Version - public static String qb_version = "3.1.x"; - private String qbQueryString = "query"; // Alarm manager private AlarmManager alarmMgr; private PendingIntent alarmIntent; - protected static long uploadSpeedCount; - protected static long downloadSpeedCount; - - protected static int uploadCount; - protected static int downloadCount; - - public static LinearLayout headerInfo; - - // Current state - public static String currentState; - + // New ToolBar in Material Desing + Toolbar toolbar; + public static boolean listViewRefreshing; + // Search bar in Material Design + private MenuItem mSearchAction; + private boolean isSearchOpened = false; + private EditText editSearch; @Override protected void onCreate(Bundle savedInstanceState) { @@ -233,11 +227,6 @@ protected void onCreate(Bundle savedInstanceState) { alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000, notification_period, alarmIntent); - -// Log.d("Debug", "Alarm was set!"); -// Log.d("Notifier", "notification_period: " + notification_period); - - } if (qb_version.equals("3.2.x")) { @@ -251,12 +240,30 @@ protected void onCreate(Bundle savedInstanceState) { // Set Theme (It must be fore inflating or setContentView) if (dark_ui) { this.setTheme(R.style.Theme_Dark); + + if (Build.VERSION.SDK_INT >= 21) { + getWindow().setNavigationBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); + getWindow().setStatusBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); + } } else { this.setTheme(R.style.Theme_Light); + + if (Build.VERSION.SDK_INT >= 21) { + getWindow().setNavigationBarColor(getResources().getColor(R.color.primary)); + } + } setContentView(R.layout.activity_main); + toolbar = (Toolbar) findViewById(R.id.app_bar); + + if (dark_ui) { + toolbar.setBackgroundColor(getResources().getColor(R.color.Theme_Dark_primary)); + } + + setSupportActionBar(toolbar); + // Set App title setTitle(R.string.app_shortname); @@ -267,6 +274,8 @@ protected void onCreate(Bundle savedInstanceState) { drawerList = (ListView) findViewById(R.id.left_drawer); + // TODO: Edit code for Free and Pro versions + // Drawer item list objects ObjectDrawerItem[] drawerItem = new ObjectDrawerItem[10]; @@ -297,14 +306,16 @@ protected void onCreate(Bundle savedInstanceState) { // Add the application icon control code inside MainActivity onCreate drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); - drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { + + // New ActionBarDrawerToggle for Google Material Desing (v7) + drawerToggle = new android.support.v7.app.ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { /** * Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); - // getActionBar().setTitle(title); + // getSupportActionBar().setTitle(title); } /** @@ -312,14 +323,16 @@ public void onDrawerClosed(View view) { */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); - // getActionBar().setTitle(drawerTitle); + // getSupportActionBar().setTitle(drawerTitle); + // setTitle(R.string.app_shortname); } }; drawerLayout.setDrawerListener(drawerToggle); - getActionBar().setDisplayHomeAsUpEnabled(true); - getActionBar().setHomeButtonEnabled(true); + getSupportActionBar().setDisplayHomeAsUpEnabled(false); + getSupportActionBar().setHomeButtonEnabled(false); + // Get options and save them as shared preferences qBittorrentOptions qso = new qBittorrentOptions(); @@ -345,7 +358,7 @@ public void onDrawerOpened(View drawerView) { // This fragment will hold the list of torrents if (firstFragment == null) { - firstFragment = new ItemstFragment(); + firstFragment = new com.lgallardo.qbittorrentclient.ItemstFragment(); } // This fragment will hold the list of torrents @@ -377,13 +390,12 @@ public void onDrawerOpened(View drawerView) { // Create an instance of ItemsFragments if (firstFragment == null) { - firstFragment = new ItemstFragment(); + firstFragment = new com.lgallardo.qbittorrentclient.ItemstFragment(); } firstFragment.setSecondFragmentContainer(R.id.one_frame); // This i the about fragment, holding a default message at the // beginning - secondFragment = new AboutFragment(); // If we're being restored from a previous state, @@ -395,13 +407,13 @@ public void onDrawerOpened(View drawerView) { try { FragmentManager fm = getFragmentManager(); - if (fm.getBackStackEntryCount() == 1 && fm.findFragmentById(R.id.one_frame) instanceof TorrentDetailsFragment) { + if (fm.getBackStackEntryCount() == 1 && fm.findFragmentById(R.id.one_frame) instanceof com.lgallardo.qbittorrentclient.TorrentDetailsFragment) { refreshCurrent(); } - } catch (Exception e) { - + } + catch (Exception e) { } return; @@ -419,7 +431,7 @@ public void onDrawerOpened(View drawerView) { // Activity is visble activityIsVisible = true; - // // Autorefresh + // // First refresh refreshCurrent(); handler = new Handler(); @@ -476,8 +488,6 @@ public void setSelectionAndTitle(String state) { @Override public void onDestroy() { super.onDestroy(); - -// getApplicationContext().unbindService(qbServiceConnection); } @@ -523,14 +533,13 @@ public void onResume() { } } - @Override - public void onPause() { - super.onPause(); - activityIsVisible = false; - } +// @Override +// public void onPause() { +// super.onPause(); +// activityIsVisible = false; +// } // Load Banner - public void loadBanner() { // Look up the AdView as a resource and load a request. @@ -544,6 +553,7 @@ public void loadBanner() { @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); + // TODO: Delete outState.putInt("itemPosition", itemPosition); } @@ -552,22 +562,9 @@ public void onSaveInstanceState(Bundle outState) { public void run() { - // Toast.makeText(MainActivity.this, "Refresh period: " + - // refresh_period, Toast.LENGTH_SHORT).show(); if (auto_refresh == true && canrefresh == true && activityIsVisible == true) { -// -// if (findViewById(R.id.fragment_container) != null) { -// refreshCurrent(); -// } else { -// -// FragmentManager fm = getFragmentManager(); -// -// if (fm.findFragmentById(R.id.one_frame) instanceof ItemstFragment || fm.findFragmentById(R.id.one_frame) instanceof AboutFragment) { -// refreshCurrent(); -// } -// -// } + refreshCurrent(); } @@ -603,15 +600,12 @@ public void refreshCurrent() { break; } } - } - // Drawer's method - @Override public void setTitle(CharSequence title) { this.title = title; - getActionBar().setTitle(title); + getSupportActionBar().setTitle(title); } @Override @@ -623,11 +617,46 @@ protected void onPostCreate(Bundle savedInstanceState) { @Override public void onBackPressed() { - if (getFragmentManager().getBackStackEntryCount() == 0) { - this.finish(); + FragmentManager fm = getFragmentManager(); + com.lgallardo.qbittorrentclient.ItemstFragment fragment = null; + + // Close Contextual Action Bar + if (com.lgallardo.qbittorrentclient.ItemstFragment.mActionMode != null) { + + com.lgallardo.qbittorrentclient.ItemstFragment.mActionMode.finish(); + } else { - getFragmentManager().popBackStack(); + + + if (fm.getBackStackEntryCount() == 0) { + + // Set About first load to true + AboutFragment.isFragmentFirstLoaded = true; + + // Close the app + this.finish(); + + + } else { + + // Enable toolbar title + getSupportActionBar().setDisplayShowTitleEnabled(true); + + fm.popBackStack(); + } + + } + + if (findViewById(R.id.one_frame) != null) { + if (headerInfo != null) { + if (header) { + headerInfo.setVisibility(View.VISIBLE); + } else { + headerInfo.setVisibility(View.GONE); + } + } } + } private void refresh() { @@ -643,7 +672,6 @@ private void refresh(String state) { return; } - if (qb_version.equals("2.x")) { qbQueryString = "json"; params[0] = qbQueryString + "/events"; @@ -658,13 +686,9 @@ private void refresh(String state) { qbQueryString = "query"; params[0] = qbQueryString + "/torrents?filter=" + state; - if (cookie == null || cookie.equals("")) { new qBittorrentCookie().execute(); } - -// Log.i("REFRESH", "Cookie:" + cookie); - } params[1] = state; @@ -686,12 +710,14 @@ private void refresh(String state) { qtt.execute(params); - // Close Contextual Action Bar - if (firstFragment != null && firstFragment.mActionMode != null) { - firstFragment.mActionMode.finish(); - } + // TODO: Delete +// // Close Contextual Action Bar +// if (firstFragment != null && firstFragment.mActionMode != null) { +// firstFragment.mActionMode.finish(); +// } } + } else { // Connection Error message @@ -722,6 +748,9 @@ private void handleIntent(Intent intent) { // Add torrent (file, url or magnet) addTorrentByIntent(intent); + // // Activity is visble + activityIsVisible = true; + // // // Autorefresh refreshCurrent(); @@ -741,9 +770,6 @@ private void addTorrentByIntent(Intent intent) { } else { - // Web -// addTorrent(Uri.decode(urlTorrent)); - try { addTorrent(Uri.decode(URLEncoder.encode(urlTorrent, "UTF-8"))); }catch(UnsupportedEncodingException e){ @@ -754,21 +780,51 @@ private void addTorrentByIntent(Intent intent) { } + try { + if (intent.getStringExtra("from").equals("NotifierService")) { + drawerList.setItemChecked(2, true); + setTitle(navigationDrawerItemTitles[2]); + refresh("completed"); + } + } catch (NullPointerException npe) { + + } + } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. +// getMenuInflater().inflate(R.menu.main, menu); + +// // Associate searchable configuration with the SearchView +// SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); +// SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); +// searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); + +// return true; + + + getMenuInflater().inflate(R.menu.main, menu); - // Associate searchable configuration with the SearchView SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); - SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); - searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); + + android.support.v7.widget.SearchView searchView = (android.support.v7.widget.SearchView) menu.findItem(R.id.action_search).getActionView(); + + if (searchView != null) { + searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); + searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default + } return true; } + public void popBackStackPhoneView(){ + getFragmentManager().popBackStack(); + headerInfo.setVisibility(View.VISIBLE); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -779,47 +835,27 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; } + // Enable title (just in case) + getSupportActionBar().setDisplayShowTitleEnabled(true); + switch (item.getItemId()) { + + case R.id.action_search: + onSearchRequested(); + return true; case R.id.action_refresh: - // Refresh option clicked. - switch (drawerList.getCheckedItemPosition()) { - case 0: - refresh("all"); - break; - case 1: - refresh("downloading"); - break; - case 2: - refresh("completed"); - break; - case 3: - refresh("paused"); - break; - case 4: - refresh("active"); - break; - case 5: - refresh("inactive"); - break; - case 6: - break; - case 7: - break; - default: - selectItem(0); - break; - } + swipeRefresh(); return true; case R.id.action_add: // Add URL torrent addUrlTorrent(); return true; case R.id.action_pause: - if (TorrentDetailsFragment.hashToUpdate != null) { - pauseTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + pauseTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -828,7 +864,7 @@ public boolean onOptionsItemSelected(MenuItem item) { startTorrent(TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -857,11 +893,11 @@ public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) { // User accepted the dialog - if (TorrentDetailsFragment.hashToUpdate != null) { - deleteTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + deleteTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } @@ -894,11 +930,11 @@ public void onClick(DialogInterface dialog, int id) { builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User accepted the dialog - if (TorrentDetailsFragment.hashToUpdate != null) { - deleteDriveTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + deleteDriveTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } @@ -914,38 +950,38 @@ public void onClick(DialogInterface dialog, int id) { } return true; case R.id.action_increase_prio: - if (TorrentDetailsFragment.hashToUpdate != null) { - increasePrioTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + increasePrioTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; case R.id.action_decrease_prio: - if (TorrentDetailsFragment.hashToUpdate != null) { - decreasePrioTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + decreasePrioTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; case R.id.action_max_prio: - if (TorrentDetailsFragment.hashToUpdate != null) { - maxPrioTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + maxPrioTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; case R.id.action_min_prio: - if (TorrentDetailsFragment.hashToUpdate != null) { - minPrioTorrent(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + minPrioTorrent(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -956,43 +992,48 @@ public void onClick(DialogInterface dialog, int id) { pauseAllTorrents(); return true; case R.id.action_upload_rate_limit: - if (TorrentDetailsFragment.hashToUpdate != null) { - uploadRateLimitDialog(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + uploadRateLimitDialog(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); + if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; case R.id.action_download_rate_limit: - if (TorrentDetailsFragment.hashToUpdate != null) { + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { downloadRateLimitDialog(TorrentDetailsFragment.hashToUpdate); + if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; case R.id.action_recheck: - if (TorrentDetailsFragment.hashToUpdate != null) { - recheckTorrents(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + recheckTorrents(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); + if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; case R.id.action_firts_last_piece_prio: - if (TorrentDetailsFragment.hashToUpdate != null) { - toggleFirstLastPiecePrio(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + toggleFirstLastPiecePrio(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); + if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; case R.id.action_sequential_download: - if (TorrentDetailsFragment.hashToUpdate != null) { - toggleSequentialDownload(TorrentDetailsFragment.hashToUpdate); + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { + toggleSequentialDownload(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); + if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } return true; @@ -1056,7 +1097,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { cookie = ""; } - // redraw menu invalidateOptionsMenu(); @@ -1092,7 +1132,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { SystemClock.elapsedRealtime() + 5000, notification_period, alarmIntent); - } if (requestCode == OPTION_CODE) { @@ -1152,16 +1191,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } - if (requestCode == GETPRO_CODE) { - // Select "All" torrents list - // selectItem(0);| - } +// if (requestCode == GETPRO_CODE) { +// // Now it can be refreshed +// canrefresh = true; +// } if (requestCode == HELP_CODE) { - // Now it can be refreshed canrefresh = true; - } if (resultCode == RESULT_OK) { @@ -1183,7 +1220,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { refresh(); } - } private void addUrlTorrent() { @@ -1228,7 +1264,8 @@ public void onClick(DialogInterface dialog, int id) { private void openSettings() { canrefresh = false; - Intent intent = new Intent(getBaseContext(), SettingsActivity.class); + + Intent intent = new Intent(getBaseContext(), com.lgallardo.qbittorrentclient.SettingsActivity.class); startActivityForResult(intent, SETTINGS_CODE); } @@ -1238,7 +1275,6 @@ private void openHelp() { Intent intent = new Intent(getBaseContext(), HelpActivity.class); intent.putExtra("current", lastState); -// startActivity(intent); startActivityForResult(intent, HELP_CODE); } @@ -1319,7 +1355,6 @@ public void deleteSelectedTorrents(String hashes) { refreshAfterCommand(1); } - public void deleteDriveTorrent(String hash) { // Execute the task in background qBittorrentCommand qtc = new qBittorrentCommand(); @@ -1352,13 +1387,24 @@ public void addTorrentFile(String url) { public void pauseAllTorrents() { // Execute the task in background qBittorrentCommand qtc = new qBittorrentCommand(); - qtc.execute(new String[]{"pauseAll", null}); + + if (qb_version.equals("3.2.x")) { + qtc.execute(new String[]{"pauseAll", null}); + } + else{ + qtc.execute(new String[]{"pauseall", null}); + } } public void resumeAllTorrents() { // Execute the task in background qBittorrentCommand qtc = new qBittorrentCommand(); - qtc.execute(new String[]{"resumeAll", null}); + + if (qb_version.equals("3.2.x")) { + qtc.execute(new String[]{"resumeAll", null}); + }else{ + qtc.execute(new String[]{"resumeall", null}); + } } public void increasePrioTorrent(String hash) { @@ -1532,7 +1578,6 @@ public void setUploadRateLimit(String hash, String uploadRateLimit) { // Delay of 1 second refreshAfterCommand(1); - } else { genericOkDialog(R.string.error, R.string.global_value_error); @@ -1555,6 +1600,7 @@ public void setDownloadRateLimit(String hash, String downloadRateLimit) { } else { limit = Integer.parseInt(downloadRateLimit); } + String[] hashesArray = hash.split("\\|"); for (int i = 0; hashesArray.length > i; i++) { @@ -1567,12 +1613,11 @@ public void setDownloadRateLimit(String hash, String downloadRateLimit) { // Delay of 1 second refreshAfterCommand(1); - } else { + } + else { genericOkDialog(R.string.error, R.string.global_value_error); } - } - } public void refreshAfterCommand(int delay) { @@ -1672,20 +1717,23 @@ protected void getSettings() { } username = sharedPrefs.getString("username", "NULL"); password = sharedPrefs.getString("password", "NULL"); - oldVersion = sharedPrefs.getBoolean("old_version", false); https = sharedPrefs.getBoolean("https", false); // Check https if (https) { - protocol = "https"; - } else { protocol = "http"; } + // Get refresh info auto_refresh = sharedPrefs.getBoolean("auto_refresh", true); - refresh_period = Integer.parseInt(sharedPrefs.getString("refresh_period", "120000")); + + try { + refresh_period = Integer.parseInt(sharedPrefs.getString("refresh_period", "120000")); + } catch (NumberFormatException e) { + refresh_period = 120000; + } // Get connection and data timeouts try { @@ -1753,6 +1801,177 @@ protected void getOptions() { } + protected void notifyCompleted(HashMap completedTorrents) { + + Intent intent = new Intent(this, MainActivity.class); + PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); + + // build notification + // the addAction re-use the same intent to keep the example short + Notification.Builder builder = new Notification.Builder(this) + .setContentTitle("qBittorrent") + .setContentText("Torrent(s) completed") + .setSmallIcon(R.drawable.ic_stat_completed) + .setNumber(completedTorrents.size()) + .setContentIntent(pIntent) + .setAutoCancel(true); + + + NotificationManager notificationManager = + (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + + Notification notification; + + notification = builder.getNotification(); + + notificationManager.notify(0, notification); + + + } + + private void saveLastState(String state) { + + currentState = state; + + // Save options locally + sharedPrefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); + Editor editor = sharedPrefs.edit(); + + // Save key-values + editor.putString("lastState", state); + + // Commit changes + editor.apply(); + + } + + private void saveSortBy(String sortBy) { + MainActivity.sortby = sortBy; + // Save options locally + sharedPrefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); + Editor editor = sharedPrefs.edit(); + + // Save key-values + editor.putString("sortby", sortBy); + + + // Commit changes + editor.apply(); + + } + + private void selectItem(int position) { + + + if (findViewById(R.id.one_frame) != null) { + FragmentManager fragmentManager = getFragmentManager(); + + if (fragmentManager.findFragmentByTag("firstFragment") instanceof com.lgallardo.qbittorrentclient.TorrentDetailsFragment) { + // Reset back button stack + for (int i = 0; i < fragmentManager.getBackStackEntryCount(); ++i) { + fragmentManager.popBackStack(); + } + } + + } + + + switch (position) { + case 0: + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); + refresh("all"); + saveLastState("all"); + break; + case 1: + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); + refresh("downloading"); + saveLastState("downloading"); + break; + case 2: + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); + refresh("completed"); + saveLastState("completed"); + break; + case 3: + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); + refresh("paused"); + saveLastState("paused"); + break; + case 4: + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); + refresh("active"); + saveLastState("active"); + break; + case 5: + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); + refresh("inactive"); + saveLastState("inactive"); + break; + case 6: + // Options - Execute the task in background + Toast.makeText(getApplicationContext(), R.string.getQBittorrentPrefefrences, Toast.LENGTH_SHORT).show(); + qBittorrentOptions qso = new qBittorrentOptions(); + qso.execute(new String[]{qbQueryString + "/preferences", "setOptions"}); + break; + case 7: + // Settings + openSettings(); + break; + case 8: + openHelp(); + break; + default: + break; + + + } + + if (position < 6) { + drawerList.setItemChecked(position, true); + drawerList.setSelection(position); + setTitle(navigationDrawerItemTitles[position]); + } + + drawerLayout.closeDrawer(drawerList); + + } + + @Override + public void swipeRefresh() { + + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); + + // Actually refresh data + refreshCurrent(); + } + + public void refreshSwipeLayout() { + + listViewRefreshing = true; + + + if (AboutFragment.mSwipeRefreshLayout != null) { + AboutFragment.mSwipeRefreshLayout.setRefreshing(true); + } + + if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(true); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(false); + } + + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(true); + } + + } + private class qBittorrentCookie extends AsyncTask { @Override @@ -1763,26 +1982,18 @@ protected String[] doInBackground(Void... params) { // Creating new JSON Parser - JSONParser jParser = new JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); + com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); String cookie = ""; String api = ""; - -// Log.i("qBittorrentCookie =>", "qBittorrentCookie"); - try { cookie = jParser.getNewCookie(); -// api = jParser.getApiVersion(); } catch (JSONParserStatusCodeException e) { httpStatusCode = e.getCode(); - -// Log.i("qBittorrentCookie", "httpStatusCode: " + httpStatusCode); -// Log.e("qBittorrentCookie", e.toString()); - } if (cookie == null) { @@ -1794,9 +2005,6 @@ protected String[] doInBackground(Void... params) { api = ""; } -// -// Log.i("qBittorrentCookie", "COOKIE: " + ">" + cookie + "<"); -// Log.i("qBittorrentCookie", "API: >" + api + "<"); return new String[]{cookie, api}; @@ -1804,8 +2012,6 @@ protected String[] doInBackground(Void... params) { @Override protected void onPostExecute(String[] result) { -// Log.i("qBittorrentCookie", "httpStatusCode:" + httpStatusCode); - MainActivity.cookie = result[0]; @@ -1834,7 +2040,7 @@ protected String doInBackground(String... params) { getSettings(); // Creating new JSON Parser - JSONParser jParser = new JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); + com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); jParser.setCookie(cookie); @@ -1871,6 +2077,7 @@ protected void onPostExecute(String result) { } if (httpStatusCode == 403) { + if (qb_version.equals("3.2.x")) { // Get new Cookie @@ -1929,7 +2136,7 @@ protected void onPostExecute(String result) { if ("resumeAll".equals(result)) { messageId = R.string.AllTorrentsResumed; - // Needed to refresh after a resume and see the change + // Needed to refresh after a "resume all" and see the changes delay = 3; } @@ -1957,14 +2164,14 @@ protected void onPostExecute(String result) { if ("setUploadRateLimit".equals(result)) { messageId = R.string.setUploadRateLimit; if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } if ("setDownloadRateLimit".equals(result)) { messageId = R.string.setDownloadRateLimit; if (findViewById(R.id.one_frame) != null) { - getFragmentManager().popBackStack(); + popBackStackPhoneView(); } } @@ -2005,14 +2212,14 @@ protected Torrent[] doInBackground(String... params) { getSettings(); try { + // Creating new JSON Parser - jParser = new JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); + jParser = new com.lgallardo.qbittorrentclient.JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); jParser.setCookie(MainActivity.cookie); JSONArray jArray = jParser.getJSONArrayFromUrl(params[0]); - if (jArray != null) { torrents = new Torrent[jArray.length()]; @@ -2071,16 +2278,22 @@ protected Torrent[] doInBackground(String... params) { String sizeUnit = size.substring(size.indexOf(" "), size.length()); torrents[i].setDownloaded(String.format("%.1f", sizeScalar * json.getDouble(TAG_PROGRESS)).replace(",", ".") + sizeUnit); + } catch (Exception e) { torrents[i].setDownloaded(size); } - // Info + // Info free torrents[i].setInfo(torrents[i].getDownloaded() + " " + Character.toString('\u2193') + " " + torrents[i].getDownloadSpeed() + " " + Character.toString('\u2191') + " " + torrents[i].getUploadSpeed() + " " + Character.toString('\u2022') + " " + torrents[i].getRatio() + " " + Character.toString('\u2022') + " " + progress + " " + Character.toString('\u2022') + " " + torrents[i].getEta()); +// // Info pro +// torrents[i].setInfo(torrents[i].getDownloaded() + " " + Character.toString('\u2193') + " " + torrents[i].getDownloadSpeed() + " " +// + Character.toString('\u2191') + " " + torrents[i].getUploadSpeed() + " " + Character.toString('\u2022') + " " +// + torrents[i].getRatio() + " " + Character.toString('\u2022') + " " + torrents[i].getEta()); + } } @@ -2088,6 +2301,7 @@ protected Torrent[] doInBackground(String... params) { httpStatusCode = e.getCode(); torrents = null; Log.e("JSONParserStatusCode", e.toString()); + } catch (Exception e) { torrents = null; Log.e("MAIN:", e.toString()); @@ -2127,15 +2341,9 @@ protected void onPostExecute(Torrent[] result) { Toast.makeText(getApplicationContext(), R.string.error403, Toast.LENGTH_SHORT).show(); httpStatusCode = 0; + } -// // Set App title -// setTitle(R.string.app_shortname); -// -// // Uncheck any item on the drawer menu -// for (int i = 0; i < drawerList.getCount(); i++) { -// drawerList.setItemChecked(i, false); -// } } else { @@ -2190,6 +2398,7 @@ protected void onPostExecute(Torrent[] result) { } } + // Sort by filename if (sortby.equals("Name")) { Collections.sort(torrentsFiltered, new TorrentNameComparator(reverse_order)); @@ -2221,6 +2430,7 @@ protected void onPostExecute(Torrent[] result) { if (sortby.equals("UploadSpeed")) { Collections.sort(torrentsFiltered, new TorrentUploadSpeedComparator(reverse_order)); } + // Get names (delete in background method) MainActivity.names = new String[torrentsFiltered.size()]; MainActivity.lines = new Torrent[torrentsFiltered.size()]; @@ -2242,7 +2452,7 @@ protected void onPostExecute(Torrent[] result) { MainActivity.names[i] = torrent.getFile(); MainActivity.lines[i] = torrent; - if (torrent.getHash().equals(TorrentDetailsFragment.hashToUpdate)) { + if (torrent.getHash().equals(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate)) { torrentToUpdate = torrent; } @@ -2256,6 +2466,7 @@ protected void onPostExecute(Torrent[] result) { if ("downloading".equals(torrent.getState())) { downloadCount = downloadCount + 1; } + } // Update torrent list @@ -2318,7 +2529,7 @@ protected void onPostExecute(Torrent[] result) { // Set second fragment if (!(fragmentManager.findFragmentByTag("secondFragment") instanceof AboutFragment)) { - TorrentDetailsFragment detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("secondFragment"); + com.lgallardo.qbittorrentclient.TorrentDetailsFragment detailsFragment = (com.lgallardo.qbittorrentclient.TorrentDetailsFragment) fragmentManager.findFragmentByTag("secondFragment"); if (torrentToUpdate != null) { // Update torrent details @@ -2355,9 +2566,9 @@ protected void onPostExecute(Torrent[] result) { fragmentTransaction.replace(R.id.one_frame, firstFragment, "firstFragment"); } - if (fragmentManager.findFragmentByTag("firstFragment") instanceof TorrentDetailsFragment) { + if (fragmentManager.findFragmentByTag("firstFragment") instanceof com.lgallardo.qbittorrentclient.TorrentDetailsFragment) { - TorrentDetailsFragment detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("firstFragment"); + com.lgallardo.qbittorrentclient.TorrentDetailsFragment detailsFragment = (com.lgallardo.qbittorrentclient.TorrentDetailsFragment) fragmentManager.findFragmentByTag("firstFragment"); if (torrentToUpdate != null) { // Update torrent @@ -2374,7 +2585,8 @@ protected void onPostExecute(Torrent[] result) { } } } - } else { + } + else { // No results // myadapter = null; @@ -2392,7 +2604,6 @@ protected void onPostExecute(Torrent[] result) { downloadSpeedTextView.setText(""); - //Set first and second fragments if (findViewById(R.id.fragment_container) != null) { @@ -2429,47 +2640,40 @@ protected void onPostExecute(Torrent[] result) { fragmentManager.popBackStack(); } } - - -// String[] emptyList = new String[]{getString(R.string.no_results)}; -// firstFragment.setListAdapter(new ArrayAdapter(MainActivity.this, R.layout.no_items_found, R.id.no_results, emptyList)); -// -// -// // Set the second fragments container -// if (findViewById(R.id.fragment_container) != null) { -// firstFragment.setSecondFragmentContainer(R.id.content_frame); -// fragmentTransaction.replace(R.id.list_frame, firstFragment, "firstFragment"); -// fragmentTransaction.replace(R.id.content_frame, aboutFragment, "secondFragment"); -// -// } else { -// firstFragment.setSecondFragmentContainer(R.id.one_frame); -// fragmentTransaction.replace(R.id.one_frame, firstFragment, "firstFragment"); -// -// -// // Reset back button stack -// for (int i = 0; i < fragmentManager.getBackStackEntryCount(); ++i) { -// fragmentManager.popBackStack(); -// } -// -// } - } - // Commit fragmentTransaction.commit(); } catch (Exception e) { - // TODO: handle exception Log.e("ADAPTER", e.toString()); } // Clear search field - searchField = ""; } + if (com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.setRefreshing(false); + com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.clearAnimation(); + com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.setEnabled(true); + } + + if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(false); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.clearAnimation(); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(true); + } + + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(false); + com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.clearAnimation(); + com.lgallardo.qbittorrentclient.TorrentDetailsFragment .mSwipeRefreshLayout.setEnabled(true); + } + + listViewRefreshing = false; + } } @@ -2483,7 +2687,7 @@ protected String doInBackground(String... params) { getSettings(); // Creating new JSON Parser - JSONParser jParser = new JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); + com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); jParser.setCookie(cookie); @@ -2574,9 +2778,7 @@ protected void onPostExecute(String result) { // Get new Cookie cookie = ""; new qBittorrentCookie().execute(); - } - } } else { @@ -2595,13 +2797,11 @@ protected void onPostExecute(String result) { // Do nothing } - } } } // Drawer classes - private class DrawerItemClickListener implements ListView.OnItemClickListener { @Override @@ -2610,160 +2810,4 @@ public void onItemClick(AdapterView parent, View view, int position, long id) } } - - protected void notifyCompleted(HashMap completedTorrents) { - - Intent intent = new Intent(this, MainActivity.class); - PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); - -// build notification -// the addAction re-use the same intent to keep the example short - Notification.Builder builder = new Notification.Builder(this) - .setContentTitle("qBittorrent") - .setContentText("Torrent(s) completed") - .setSmallIcon(R.drawable.ic_stat_completed) - .setNumber(completedTorrents.size()) - .setContentIntent(pIntent) - .setAutoCancel(true); - - - NotificationManager notificationManager = - (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - - Notification notification; - - notification = builder.getNotification(); - - notificationManager.notify(0, notification); - - -// // Notify individually and remove form completed list -// Iterator it = completedTorrents.entrySet().iterator(); -// while (it.hasNext()) { -// -// HashMap.Entry pairs = (HashMap.Entry) it.next(); -// -// Torrent t = (Torrent) pairs.getValue(); -// -// Log.i("Completed", t.getFile() + " - completed"); -// -// // Remove it -// completedTorrents.remove(pairs.getKey()); -// -// it.remove(); // avoids a ConcurrentModificationException -// } - } - - - private void saveLastState(String state) { - - currentState = state; - - // Save options locally - sharedPrefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); - Editor editor = sharedPrefs.edit(); - - // Save key-values - editor.putString("lastState", state); - - - // Commit changes - editor.apply(); - - } - - - private void saveSortBy(String sortBy) { - - MainActivity.sortby = sortBy; - - // Save options locally - sharedPrefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); - Editor editor = sharedPrefs.edit(); - - // Save key-values - editor.putString("sortby", sortBy); - - - // Commit changes - editor.apply(); - - } - - private void selectItem(int position) { - - if (findViewById(R.id.one_frame) != null) { - FragmentManager fragmentManager = getFragmentManager(); - - if (fragmentManager.findFragmentByTag("firstFragment") instanceof TorrentDetailsFragment) { - // Reset back button stack - for (int i = 0; i < fragmentManager.getBackStackEntryCount(); ++i) { - fragmentManager.popBackStack(); - } - } - } - - switch (position) { - case 0: - refresh("all"); - saveLastState("all"); - break; - case 1: - refresh("downloading"); - saveLastState("downloading"); - break; - case 2: - refresh("completed"); - saveLastState("completed"); - break; - case 3: - refresh("paused"); - saveLastState("paused"); - break; - case 4: - refresh("active"); - saveLastState("active"); - break; - case 5: - refresh("inactive"); - saveLastState("inactive"); - break; - case 6: - // Options - Execute the task in background - Toast.makeText(getApplicationContext(), R.string.getQBittorrentPrefefrences, Toast.LENGTH_SHORT).show(); - qBittorrentOptions qso = new qBittorrentOptions(); - qso.execute(new String[]{qbQueryString + "/preferences", "setOptions"}); - break; - case 7: - // Settings - openSettings(); - break; - case 8: - // Get Pro version - getPRO(); - break; - case 9: - openHelp(); - break; - default: - break; - } - - // if (fragment != null || listFragment != null || contentFragment != - // null) { - // // FragmentManager fragmentManager = getFragmentManager(); - // // fragmentManager.beginTransaction() - // // .replace(R.id.content_frame, fragment).commit(); - - if (position < 6) { - drawerList.setItemChecked(position, true); - drawerList.setSelection(position); - setTitle(navigationDrawerItemTitles[position]); - } - - drawerLayout.closeDrawer(drawerList); - - } - - } diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/ItemstFragment.java similarity index 83% rename from qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java rename to qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/ItemstFragment.java index 896e9d10..e9200843 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/ItemstFragment.java +++ b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/ItemstFragment.java @@ -17,7 +17,6 @@ import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.RecyclerView; -import android.util.Log; import android.view.ActionMode; import android.view.LayoutInflater; import android.view.Menu; @@ -29,16 +28,14 @@ import android.widget.AdapterView; import android.widget.ListView; -import java.util.Set; - public class ItemstFragment extends ListFragment { static public ActionMode mActionMode; public int nr = 0; int secondContainer; - com.lgallardo.qbittorrentclient.TorrentDetailsFragment detailsFragment; + TorrentDetailsFragment detailsFragment; private RecyclerView recyclerView; - private com.lgallardo.qbittorrentclient.RefreshListener refreshListener; + private RefreshListener refreshListener; private View.OnClickListener originalListener; public static SwipeRefreshLayout mSwipeRefreshLayout; @@ -46,15 +43,15 @@ public class ItemstFragment extends ListFragment { public ItemstFragment() { } - public int getSecondFragmentContainer() { + public void setSecondFragmentContainer(int container) { - return this.secondContainer; + this.secondContainer = container; } - public void setSecondFragmentContainer(int container) { + public int getSecondFragmentContainer() { - this.secondContainer = container; + return this.secondContainer; } @@ -68,7 +65,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa setHasOptionsMenu(true); // Get Refresh Listener - refreshListener = (com.lgallardo.qbittorrentclient.RefreshListener) getActivity(); + refreshListener = (RefreshListener) getActivity(); View rootView = inflater.inflate(R.layout.activity_main_original, container, false); @@ -80,20 +77,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { -// com.lgallardo.qbittorrentclient.MainActivity.refreshCurrent(); - Log.d("Debug", "Swipe!"); - refreshListener.swipeRefresh(); - } }); - - - - -// recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerViewList); - return rootView; } @@ -119,15 +106,6 @@ public void onViewCreated(View view, Bundle savedInstanceState) { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { - - if(com.lgallardo.qbittorrentclient.MainActivity.listViewRefreshing) { - Log.d("Debug", "onViewCreated - listview is refreshing pal"); - } - else{ - Log.d("Debug", "onViewCreated - listview is NOT refreshing dude"); - } - - if (checked) { nr++; mAdapter.setNewSelection(position, checked); @@ -136,10 +114,9 @@ public void onItemCheckedStateChanged(ActionMode mode, int position, long id, bo nr--; mAdapter.removeSelection(position); } -// mode.setTitle(nr + " selected"); - mode.setTitle("" + nr); - + // Set title with number of items selected + mode.setTitle("" + nr); } @Override @@ -158,7 +135,7 @@ public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { + if (MainActivity.qb_version.equals("3.2.x")) { menu.findItem(R.id.action_firts_last_piece_prio).setVisible(true); menu.findItem(R.id.action_sequential_download).setVisible(true); } else { @@ -177,7 +154,7 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) { final String hashesStr; // Get MainActivity - final com.lgallardo.qbittorrentclient.MainActivity m = (com.lgallardo.qbittorrentclient.MainActivity) getActivity(); + final MainActivity m = (MainActivity) getActivity(); // Get hashes for (int i = 0; mAdapter.getCount() > i; i++) { @@ -190,14 +167,12 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) { } else { hashes = hashes + "|" + mAdapter.getData()[i].getHash(); } - } - } hashesStr = hashes; - ((com.lgallardo.qbittorrentclient.MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true); + ((MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true); switch (item.getItemId()) { @@ -442,15 +417,11 @@ public void onClick(DialogInterface dialog, int id) { mode.finish(); return true; - default: // Enable SwipeRefresh mSwipeRefreshLayout.setEnabled(true); return true; - - } - } @Override @@ -459,8 +430,8 @@ public void onDestroyActionMode(ActionMode actionMode) { mAdapter.clearSelection(); } ItemstFragment.mActionMode = null; - mSwipeRefreshLayout.setEnabled(true); + mSwipeRefreshLayout.setEnabled(true); } }); @@ -469,7 +440,7 @@ public void onDestroyActionMode(ActionMode actionMode) { @Override public boolean onItemLongClick(AdapterView arg0, View arg1, int position, long arg3) { - if(com.lgallardo.qbittorrentclient.MainActivity.listViewRefreshing) { + if(MainActivity.listViewRefreshing) { return true; } getListView().setItemChecked(position, !mAdapter.isPositionChecked(position)); @@ -477,21 +448,15 @@ public boolean onItemLongClick(AdapterView arg0, View arg1, int position, lon } }); - } catch (Exception e) { getListView().setChoiceMode(ListView.CHOICE_MODE_NONE); - } - } - @Override public void onListItemClick(ListView parent, View v, int position, long id) { - if(!com.lgallardo.qbittorrentclient.MainActivity.listViewRefreshing) { + if(!MainActivity.listViewRefreshing) { ListItemClicked(position); - - Log.d("Debug", "onListItemClick - not refreshing"); } } @@ -501,27 +466,16 @@ public void ListItemClicked(int position) { int count = lv.getCount(); + Torrent torrent = MainActivity.lines[position]; -// if (count == 1 && lv.getItemAtPosition(0).equals(getString(R.string.no_results))) { -// -// Log.d("Debug", "Torrents not found"); -// -// return; -// } - - - Torrent torrent = com.lgallardo.qbittorrentclient.MainActivity.lines[position]; - - if (torrent.getHash().equals(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate) && getActivity().findViewById(R.id.fragment_container) != null) { + if (torrent.getHash().equals(TorrentDetailsFragment.hashToUpdate) && getActivity().findViewById(R.id.fragment_container) != null) { // Update torrent details FragmentManager fragmentManager = getFragmentManager(); if(!(fragmentManager.findFragmentByTag("secondFragment") instanceof AboutFragment)) { - - - detailsFragment = (com.lgallardo.qbittorrentclient.TorrentDetailsFragment) fragmentManager.findFragmentByTag("secondFragment"); + detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("secondFragment"); if (detailsFragment != null && torrent != null) { @@ -540,10 +494,10 @@ public void ListItemClicked(int position) { private void newDetailsFragment(int position){ - detailsFragment = new com.lgallardo.qbittorrentclient.TorrentDetailsFragment(); + detailsFragment = new TorrentDetailsFragment(); // Get torrent from MainActivity - detailsFragment.setTorrent(com.lgallardo.qbittorrentclient.MainActivity.lines[position]); + detailsFragment.setTorrent(MainActivity.lines[position]); detailsFragment.setPosition(position); @@ -554,27 +508,27 @@ private void newDetailsFragment(int position){ fragmentManager.beginTransaction().replace(this.getSecondFragmentContainer(), detailsFragment, "firstFragment").addToBackStack("secondFragment").commit(); // Change toolbar home button behaviour - originalListener = com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.getToolbarNavigationClickListener(); + originalListener = MainActivity.drawerToggle.getToolbarNavigationClickListener(); - com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setDrawerIndicatorEnabled(false); - com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setHomeAsUpIndicator(R.drawable.ic_drawer); - com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() { + MainActivity.drawerToggle.setDrawerIndicatorEnabled(false); + MainActivity.drawerToggle.setHomeAsUpIndicator(R.drawable.ic_drawer); + MainActivity.drawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Set default toolbar behaviour - ((com.lgallardo.qbittorrentclient.MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true); - com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setDrawerIndicatorEnabled(true); - com.lgallardo.qbittorrentclient.MainActivity.drawerToggle.setToolbarNavigationClickListener(originalListener); + ((MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true); + MainActivity.drawerToggle.setDrawerIndicatorEnabled(true); + MainActivity.drawerToggle.setToolbarNavigationClickListener(originalListener); // Show herderInfo in phone's view if (getActivity().findViewById(R.id.one_frame) != null) { - if (com.lgallardo.qbittorrentclient.MainActivity.headerInfo != null) { - if (com.lgallardo.qbittorrentclient.MainActivity.header) { - com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.VISIBLE); + if (MainActivity.headerInfo != null) { + if (MainActivity.header) { + MainActivity.headerInfo.setVisibility(View.VISIBLE); } else { - com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.GONE); + MainActivity.headerInfo.setVisibility(View.GONE); } } @@ -599,7 +553,6 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // inflater.inflate(R.menu.main, menu); // super.onCreateOptionsMenu(menu, inflater); - if (menu != null) { menu.findItem(R.id.action_refresh).setVisible(true); menu.findItem(R.id.action_search).setVisible(true); @@ -672,36 +625,31 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.findItem(R.id.action_sortby_downloadSpeed).setVisible(true); menu.findItem(R.id.action_sortby_uploadSpeed).setVisible(true); - - if (com.lgallardo.qbittorrentclient.MainActivity.sortby.equals("Name")) { + if (MainActivity.sortby.equals("Name")) { menu.findItem(R.id.action_sortby_name).setIcon(R.drawable.ic_stat_completed); - } - - if (com.lgallardo.qbittorrentclient.MainActivity.sortby.equals("ETA")) { + if (MainActivity.sortby.equals("ETA")) { menu.findItem(R.id.action_sortby_eta).setIcon(R.drawable.ic_stat_completed); } - if (com.lgallardo.qbittorrentclient.MainActivity.sortby.equals("Priority")) { - ; + if (MainActivity.sortby.equals("Priority")) { menu.findItem(R.id.action_sortby_priority).setIcon(R.drawable.ic_stat_completed); } - if (com.lgallardo.qbittorrentclient.MainActivity.sortby.equals("Progress")) { + if (MainActivity.sortby.equals("Progress")) { menu.findItem(R.id.action_sortby_progress).setIcon(R.drawable.ic_stat_completed); } - if (com.lgallardo.qbittorrentclient.MainActivity.sortby.equals("Ratio")) { - + if (MainActivity.sortby.equals("Ratio")) { menu.findItem(R.id.action_sortby_ratio).setIcon(R.drawable.ic_stat_completed); } - if (com.lgallardo.qbittorrentclient.MainActivity.sortby.equals("DownloadSpeed")) { + if (MainActivity.sortby.equals("DownloadSpeed")) { menu.findItem(R.id.action_sortby_downloadSpeed).setIcon(R.drawable.ic_stat_completed); } - if (com.lgallardo.qbittorrentclient.MainActivity.sortby.equals("UploadSpeed")) { + if (MainActivity.sortby.equals("UploadSpeed")) { menu.findItem(R.id.action_sortby_uploadSpeed).setIcon(R.drawable.ic_stat_completed); } diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index a511bbd3..2b3f61b9 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -81,7 +81,6 @@ public class MainActivity extends ActionBarActivity implements RefreshListener { protected static final String TAG_ETA = "eta"; protected static final String TAG_SEQDL = "seq_dl"; protected static final String TAG_FLPIECEPRIO = "f_l_piece_prio"; - protected static final String TAG_GLOBAL_MAX_NUM_CONNECTIONS = "max_connec"; protected static final String TAG_MAX_NUM_CONN_PER_TORRENT = "max_connec_per_torrent"; protected static final String TAG_MAX_NUM_UPSLOTS_PER_TORRENT = "max_uploads_per_torrent"; @@ -93,20 +92,23 @@ public class MainActivity extends ActionBarActivity implements RefreshListener { protected static final String TAG_MAX_ACT_DOWNLOADS = "max_active_downloads"; protected static final String TAG_MAX_ACT_UPLOADS = "max_active_uploads"; protected static final String TAG_MAX_ACT_TORRENTS = "max_active_torrents"; - - protected static final String TAG_URL = "url"; + protected static final int SETTINGS_CODE = 0; protected static final int OPTION_CODE = 1; - protected static final int HELP_CODE = 2; + protected static final int GETPRO_CODE = 2; + protected static final int HELP_CODE = 3; // Cookie (SID - Session ID) public static String cookie = null; public static String qb_version = "3.1.x"; public static LinearLayout headerInfo; + // Current state public static String currentState; + protected static com.lgallardo.qbittorrentclient.JSONParser jParser; + // Preferences properties protected static String hostname; protected static String subfolder; @@ -125,6 +127,7 @@ public class MainActivity extends ActionBarActivity implements RefreshListener { protected static String lastState; protected static long notification_period; protected static boolean header; + // Option protected static String global_max_num_connections; protected static String max_num_conn_per_torrent; @@ -141,20 +144,24 @@ public class MainActivity extends ActionBarActivity implements RefreshListener { protected static long downloadSpeedCount; protected static int uploadCount; protected static int downloadCount; + static Torrent[] lines; static String[] names; + // Params to get JSON Array private static String[] params = new String[2]; public com.lgallardo.qbittorrentclient.ItemstFragment firstFragment; + // myAdapter myadapter public TorrentListAdapter myadapter; + // Http status code public int httpStatusCode = 0; - TextView name1, size1; // Preferences fields private SharedPreferences sharedPrefs; private StringBuilder builderPrefs; + // Drawer properties private CharSequence drawerTitle; private CharSequence title; @@ -162,20 +169,31 @@ public class MainActivity extends ActionBarActivity implements RefreshListener { private ListView drawerList; public static DrawerLayout drawerLayout; public static ActionBarDrawerToggle drawerToggle; + + // Fragments private AboutFragment secondFragment; private HelpFragment helpTabletFragment; private AboutFragment aboutFragment; + private boolean okay = false; + // Auto-refresh private Handler handler; private boolean canrefresh = true; + +// // Ads View +// private AdView adView; + // For checking if the app is visible private boolean activityIsVisible = true; + // Item list position private int itemPosition = 0; + // Searching field private String searchField = ""; private String qbQueryString = "query"; + // Alarm manager private AlarmManager alarmMgr; private PendingIntent alarmIntent; @@ -196,7 +214,6 @@ protected void onCreate(Bundle savedInstanceState) { // Get preferences getSettings(); - // Set alarm for checking completed torrents, if not set if (PendingIntent.getBroadcast(getApplication(), 0, new Intent(getApplication(), NotifierService.class), PendingIntent.FLAG_NO_CREATE) == null) { @@ -208,15 +225,6 @@ protected void onCreate(Bundle savedInstanceState) { alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000, notification_period, alarmIntent); - -// Log.d("Debug", "Alarm was set!"); -// Log.d("Debug", "notification_period: " + notification_period); - - - } else { -// Log.d("Debug", "Alarm is already active"); -// Log.d("Debug", "notification_period: " + notification_period); - } if (qb_version.equals("3.2.x")) { @@ -246,7 +254,6 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); - toolbar = (Toolbar) findViewById(R.id.app_bar); if (dark_ui) { @@ -265,6 +272,8 @@ protected void onCreate(Bundle savedInstanceState) { drawerList = (ListView) findViewById(R.id.left_drawer); + // TODO: Edit code for Free and Pro versions + // Drawer item list objects ObjectDrawerItem[] drawerItem = new ObjectDrawerItem[9]; @@ -277,12 +286,12 @@ protected void onCreate(Bundle savedInstanceState) { drawerItem[6] = new ObjectDrawerItem(R.drawable.ic_action_options, navigationDrawerItemTitles[6]); drawerItem[7] = new ObjectDrawerItem(R.drawable.ic_drawer_settings, navigationDrawerItemTitles[7]); drawerItem[8] = new ObjectDrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[8]); +// drawerItem[9] = new ObjectDrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[9]); // Create object for drawer item OnbjectDrawerItem DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.drawer_row, drawerItem); drawerList.setAdapter(adapter); - // Set selection according to last state setSelectionAndTitle(lastState); @@ -299,7 +308,6 @@ protected void onCreate(Bundle savedInstanceState) { // New ActionBarDrawerToggle for Google Material Desing (v7) drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { - /** * Called when a drawer has settled in a completely closed state. */ @@ -320,7 +328,6 @@ public void onDrawerOpened(View drawerView) { drawerLayout.setDrawerListener(drawerToggle); - getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setHomeButtonEnabled(false); @@ -351,6 +358,7 @@ public void onDrawerOpened(View drawerView) { if (firstFragment == null) { firstFragment = new com.lgallardo.qbittorrentclient.ItemstFragment(); } + // This fragment will hold the list of torrents helpTabletFragment = new HelpFragment(); @@ -361,14 +369,6 @@ public void onDrawerOpened(View drawerView) { // beginning secondFragment = new AboutFragment(); - // If we're being restored from a previous state, - // then we don't need to do anything and should return or else - // we could end up with overlapping fragments. - if (savedInstanceState != null) { - - // return; - } - // Add the fragment to the 'list_frame' FrameLayout FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); @@ -402,7 +402,6 @@ public void onDrawerOpened(View drawerView) { if (savedInstanceState != null) { // Handle Item list empty due to Fragment stack - try { FragmentManager fm = getFragmentManager(); @@ -411,7 +410,8 @@ public void onDrawerOpened(View drawerView) { refreshCurrent(); } - } catch (Exception e) { + } + catch (Exception e) { } return; @@ -426,33 +426,12 @@ public void onDrawerOpened(View drawerView) { fragmentTransaction.commit(); } -// // Force overflow menu on all devices -// try { -// ViewConfiguration config = ViewConfiguration.get(this); -// Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey"); -// if(menuKeyField != null) { -// menuKeyField.setAccessible(true); -// menuKeyField.setBoolean(config, false); -// } -// } catch (Exception ex) { -// // Ignore -// } - // Activity is visble activityIsVisible = true; - -// // Set the refresh layout (refresh icon, etc) -// refreshSwipeLayout(); -// if (secondFragment.mSwipeRefreshLayout != null) { -// secondFragment.mSwipeRefreshLayout.setRefreshing(true); -// } - // First refresh refreshCurrent(); - Log.d("Debug","First refresh done"); - handler = new Handler(); handler.postDelayed(m_Runnable, refresh_period); @@ -512,7 +491,6 @@ public void setSelectionAndTitle(String state) { } } - @Override public void onDestroy() { super.onDestroy(); @@ -547,9 +525,7 @@ public void onResume() { // Close Contextual Action Bar if (firstFragment != null && firstFragment.mActionMode != null) { - firstFragment.mActionMode.finish(); - } // Refresh current list @@ -568,28 +544,31 @@ public void onResume() { // public void onPause() { // super.onPause(); // activityIsVisible = false; -// } - -// @Override -// public void onStart(){ -// // Set the refresh layout (refresh icon, etc) -// refreshSwipeLayout(); -// -// // First refresh -//// refreshCurrent(); -// -// Log.d("Debug","First refresh done"); -// -// super.onStart(); // } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); + // TODO: Delete outState.putInt("itemPosition", itemPosition); - } + // Auto-refresh runnable + private final Runnable m_Runnable = new Runnable() { + public void run() + + { + + if (auto_refresh == true && canrefresh == true && activityIsVisible == true) { + + refreshCurrent(); + } + + MainActivity.this.handler.postDelayed(m_Runnable, refresh_period); + } + + };// runnable + public void refreshCurrent() { if (!hostname.equals("")) { @@ -617,7 +596,7 @@ public void refreshCurrent() { break; } } - } // Auto-refresh runnable + } @Override public void setTitle(CharSequence title) { @@ -674,7 +653,6 @@ public void onBackPressed() { } } - } private void refresh() { @@ -707,14 +685,8 @@ private void refresh(String state) { if (cookie == null || cookie.equals("")) { new qBittorrentCookie().execute(); } - -// Log.i("REFRESH", "Cookie:" + cookie); - } - -// Log.i("REFRESH", params[0]); - params[1] = state; ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); @@ -722,10 +694,11 @@ private void refresh(String state) { if (networkInfo != null && networkInfo.isConnected() && !networkInfo.isFailover()) { - if (hostname.equals("")) { +// // Load banner +// loadBanner(); + if (hostname.equals("")) { genericOkDialog(R.string.info, R.string.about_help1); - } else { // Execute the task in background @@ -733,6 +706,11 @@ private void refresh(String state) { qtt.execute(params); + // TODO: Delete +// // Close Contextual Action Bar +// if (firstFragment != null && firstFragment.mActionMode != null) { +// firstFragment.mActionMode.finish(); +// } } @@ -759,7 +737,6 @@ private void handleIntent(Intent intent) { // Autorefresh refreshCurrent(); - } if (Intent.ACTION_VIEW.equals(intent.getAction())) { @@ -793,8 +770,6 @@ private void addTorrentByIntent(Intent intent) { String urlTorrent = intent.getDataString(); -// Log.d("Debug", "urlTorrent: " + urlTorrent); - if (urlTorrent != null && urlTorrent.length() != 0) { if (urlTorrent.substring(0, 4).equals("file")) { @@ -804,8 +779,6 @@ private void addTorrentByIntent(Intent intent) { } else { - // Web -// addTorrent(Uri.decode(urlTorrent)); try { addTorrent(Uri.decode(URLEncoder.encode(urlTorrent, "UTF-8"))); } catch (UnsupportedEncodingException e) { @@ -851,9 +824,6 @@ public boolean onCreateOptionsMenu(Menu menu) { if (searchView != null) { searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default - - Log.d("Debug", "searchView is not NULL"); - } return true; @@ -880,7 +850,6 @@ public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_search: - Log.d("Debug", "Search in Main"); onSearchRequested(); return true; case R.id.action_refresh: @@ -1034,6 +1003,7 @@ public void onClick(DialogInterface dialog, int id) { case R.id.action_upload_rate_limit: if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { uploadRateLimitDialog(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); + if (findViewById(R.id.one_frame) != null) { popBackStackPhoneView(); } @@ -1043,6 +1013,7 @@ public void onClick(DialogInterface dialog, int id) { case R.id.action_download_rate_limit: if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { downloadRateLimitDialog(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); + if (findViewById(R.id.one_frame) != null) { popBackStackPhoneView(); } @@ -1051,6 +1022,7 @@ public void onClick(DialogInterface dialog, int id) { case R.id.action_recheck: if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { recheckTorrents(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); + if (findViewById(R.id.one_frame) != null) { popBackStackPhoneView(); } @@ -1059,6 +1031,7 @@ public void onClick(DialogInterface dialog, int id) { case R.id.action_firts_last_piece_prio: if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { toggleFirstLastPiecePrio(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); + if (findViewById(R.id.one_frame) != null) { popBackStackPhoneView(); } @@ -1067,6 +1040,7 @@ public void onClick(DialogInterface dialog, int id) { case R.id.action_sequential_download: if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate != null) { toggleSequentialDownload(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate); + if (findViewById(R.id.one_frame) != null) { popBackStackPhoneView(); } @@ -1107,7 +1081,6 @@ public void onClick(DialogInterface dialog, int id) { invalidateOptionsMenu(); refreshCurrent(); return true; - default: return super.onOptionsItemSelected(item); } @@ -1146,13 +1119,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { qBittorrentOptions qso = new qBittorrentOptions(); qso.execute(new String[]{qbQueryString + "/preferences", "getSettings"}); - // Now it can be refreshed canrefresh = true; - // Set notification alarm service - // Set Alarm for checking completed torrents - // Save completedHashes sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); Editor editor = sharedPrefs.edit(); @@ -1164,7 +1133,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Commit changes editor.apply(); - alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplication(), NotifierService.class); alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0); @@ -1173,10 +1141,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { SystemClock.elapsedRealtime() + 5000, notification_period, alarmIntent); - -// Log.d("Notifier", "notification_period 2: " + notification_period); - - } if (requestCode == OPTION_CODE) { @@ -1236,15 +1200,17 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } - if (requestCode == HELP_CODE) { - + if (requestCode == GETPRO_CODE) { // Now it can be refreshed canrefresh = true; + } + if (requestCode == HELP_CODE) { + // Now it can be refreshed + canrefresh = true; } if (resultCode == RESULT_OK) { -// Log.d("Debug", "CurrentState: " + data.getStringExtra("currentState")); String stateBefore = data.getStringExtra("currentState"); @@ -1259,9 +1225,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } if (resultCode == RESULT_CANCELED) { - //Write your code if there's no result -// Log.d("Debug", "No result"); - // Refresh refresh(); } @@ -1312,7 +1275,6 @@ private void openSettings() { canrefresh = false; Intent intent = new Intent(getBaseContext(), com.lgallardo.qbittorrentclient.SettingsActivity.class); - // startActivity(intent); startActivityForResult(intent, SETTINGS_CODE); } @@ -1322,24 +1284,28 @@ private void openHelp() { Intent intent = new Intent(getBaseContext(), HelpActivity.class); intent.putExtra("current", lastState); -// startActivity(intent); startActivityForResult(intent, HELP_CODE); } private void openOptions() { - // Retrieve preferences for options canrefresh = false; + // Retrieve preferences for options Intent intent = new Intent(getBaseContext(), OptionsActivity.class); startActivityForResult(intent, OPTION_CODE); } +// private void getPRO() { +// Intent intent = new Intent( +// new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.lgallardo.qbittorrentclientpro"))); +// startActivityForResult(intent, GETPRO_CODE); +// } + public void startTorrent(String hash) { // Execute the task in background qBittorrentCommand qtc = new qBittorrentCommand(); qtc.execute(new String[]{"start", hash}); - } public void startSelectedTorrents(String hashes) { @@ -1356,14 +1322,12 @@ public void startSelectedTorrents(String hashes) { // Delay of 3 seconds refreshAfterCommand(3); - } public void pauseTorrent(String hash) { // Execute the task in background qBittorrentCommand qtc = new qBittorrentCommand(); qtc.execute(new String[]{"pause", hash}); - } public void pauseSelectedTorrents(String hashes) { @@ -1406,34 +1370,6 @@ public void deleteDriveTorrent(String hash) { qtc.execute(new String[]{"deleteDrive", hash}); } - private final Runnable m_Runnable = new Runnable() { - public void run() - - { - // Toast.makeText(MainActivity.this, "Refresh period: " + - // refresh_period, Toast.LENGTH_SHORT).show(); - - if (auto_refresh == true && canrefresh == true && activityIsVisible == true) { - -// if (findViewById(R.id.fragment_container) != null) { -// refreshCurrent(); -// } else { -// -// FragmentManager fm = getFragmentManager(); -// -// if (fm.findFragmentById(R.id.one_frame) instanceof ItemstFragment || fm.findFragmentById(R.id.one_frame) instanceof AboutFragment) { -// refreshCurrent(); -// } -// } - - refreshCurrent(); - } - - MainActivity.this.handler.postDelayed(m_Runnable, refresh_period); - } - - };// runnable - public void deleteDriveSelectedTorrents(String hashes) { // Execute the task in background qBittorrentCommand qtc = new qBittorrentCommand(); @@ -1445,8 +1381,6 @@ public void deleteDriveSelectedTorrents(String hashes) { refreshAfterCommand(1); } - // Drawer's method - public void addTorrent(String url) { // Execute the task in background qBittorrentCommand qtc = new qBittorrentCommand(); @@ -1640,6 +1574,7 @@ public void setUploadRateLimit(String hash, String uploadRateLimit) { } else { limit = Integer.parseInt(uploadRateLimit); } + String[] hashesArray = hash.split("\\|"); for (int i = 0; hashesArray.length > i; i++) { @@ -1666,13 +1601,8 @@ public void setDownloadRateLimit(String hash, String downloadRateLimit) { if (downloadRateLimit != null && !downloadRateLimit.equals("")) { -// Log.i("setDownloadRateLimit", "downloadRateLimit: " + downloadRateLimit); - if (global_download != null) { -// Log.i("setDownloadRateLimit", "global_download: " + Integer.parseInt(global_download)); - - if (Integer.parseInt(global_download) > 0) { limit = (Integer.parseInt(downloadRateLimit) > Integer.parseInt(global_download)) ? Integer.parseInt(global_download) : Integer .parseInt(downloadRateLimit); @@ -1683,10 +1613,6 @@ public void setDownloadRateLimit(String hash, String downloadRateLimit) { String[] hashesArray = hash.split("\\|"); for (int i = 0; hashesArray.length > i; i++) { - -// Log.i("setDownloadRateLimit", "hash: " + hashesArray[i]); -// Log.i("setDownloadRateLimit", "limit: " + limit * 1024); - qBittorrentCommand qtc = new qBittorrentCommand(); qtc.execute(new String[]{"setDownloadRateLimit", hashesArray[i] + "&" + limit * 1024}); } @@ -1696,12 +1622,11 @@ public void setDownloadRateLimit(String hash, String downloadRateLimit) { // Delay of 1 second refreshAfterCommand(1); - - } else { + } + else { genericOkDialog(R.string.error, R.string.global_value_error); } } - } public void refreshAfterCommand(int delay) { @@ -1806,7 +1731,6 @@ protected void getSettings() { // Check https if (https) { protocol = "https"; - } else { protocol = "http"; } @@ -1840,7 +1764,6 @@ protected void getSettings() { qb_version = sharedPrefs.getString("qb_version", "3.1.x"); - MainActivity.cookie = sharedPrefs.getString("qbCookie", null); // Get last state @@ -1892,8 +1815,8 @@ protected void notifyCompleted(HashMap completedTorrents) { Intent intent = new Intent(this, MainActivity.class); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); -// build notification -// the addAction re-use the same intent to keep the example short + // build notification + // the addAction re-use the same intent to keep the example short Notification.Builder builder = new Notification.Builder(this) .setContentTitle("qBittorrent") .setContentText("Torrent(s) completed") @@ -1913,21 +1836,6 @@ protected void notifyCompleted(HashMap completedTorrents) { notificationManager.notify(0, notification); -// // Notify individually and remove form completed list -// Iterator it = notify.entrySet().iterator(); -// while (it.hasNext()) { -// -// HashMap.Entry pairs = (HashMap.Entry) it.next(); -// -// Torrent t = (Torrent) pairs.getValue(); -// -// Log.i("Completed", t.getFile() + " - completed"); -// -// // Remove it -// notify.remove(pairs.getKey()); -// -// it.remove(); // avoids a ConcurrentModificationException -// } } private void saveLastState(String state) { @@ -2033,13 +1941,6 @@ private void selectItem(int position) { } - // if (fragment != null || listFragment != null || contentFragment != - // null) { - // // FragmentManager fragmentManager = getFragmentManager(); - // // fragmentManager.beginTransaction() - // // .replace(R.id.content_frame, fragment).commit(); - - if (position < 6) { drawerList.setItemChecked(position, true); drawerList.setSelection(position); @@ -2062,31 +1963,20 @@ public void swipeRefresh() { public void refreshSwipeLayout() { - Log.d("Debug", "Swipe 2!"); - listViewRefreshing = true; if (AboutFragment.mSwipeRefreshLayout != null) { AboutFragment.mSwipeRefreshLayout.setRefreshing(true); - }else{ - Log.d("Debug", "AboutFragment.mSwipeRefreshLayout is NULL"); - } if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(true); com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(false); - }else{ - Log.d("Debug", "ItemstFragment.mSwipeRefreshLayout is NULL"); - } if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(true); - }else{ - Log.d("Debug", "TorrentDetailsFragment.mSwipeRefreshLayout is NULL"); - } } @@ -2107,21 +1997,12 @@ protected String[] doInBackground(Void... params) { String cookie = ""; String api = ""; - -// Log.i("qBittorrentCookie =>", "qBittorrentCookie"); - try { - cookie = jParser.getNewCookie(); -// api = jParser.getApiVersion(); - - } catch (JSONParserStatusCodeException e) { + } + catch (JSONParserStatusCodeException e) { httpStatusCode = e.getCode(); - -// Log.i("qBittorrentCookie", "httpStatusCode: " + httpStatusCode); -// Log.e("qBittorrentCookie", e.toString()); - } if (cookie == null) { @@ -2133,9 +2014,6 @@ protected String[] doInBackground(Void... params) { api = ""; } -// -// Log.i("qBittorrentCookie", "COOKIE: " + ">" + cookie + "<"); -// Log.i("qBittorrentCookie", "API: >" + api + "<"); return new String[]{cookie, api}; @@ -2143,8 +2021,6 @@ protected String[] doInBackground(Void... params) { @Override protected void onPostExecute(String[] result) { - Log.i("qBittorrentCookie", "httpStatusCode:" + httpStatusCode); - MainActivity.cookie = result[0]; @@ -2172,7 +2048,6 @@ protected String doInBackground(String... params) { // Get values from preferences getSettings(); - // Creating new JSON Parser com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); @@ -2195,7 +2070,8 @@ protected String doInBackground(String... params) { @Override protected void onPostExecute(String result) { -// Log.i("httpStatusCode", "" + httpStatusCode); + + // Handle HTTP status code if (httpStatusCode == 1) { Toast.makeText(getApplicationContext(), R.string.error1, Toast.LENGTH_SHORT).show(); @@ -2207,7 +2083,6 @@ protected void onPostExecute(String result) { Toast.makeText(getApplicationContext(), R.string.error401, Toast.LENGTH_LONG).show(); httpStatusCode = 0; return; - } if (httpStatusCode == 403) { @@ -2272,7 +2147,6 @@ protected void onPostExecute(String result) { // Needed to refresh after a "resume all" and see the changes delay = 3; - } if ("increasePrio".equals(result)) { @@ -2310,7 +2184,6 @@ protected void onPostExecute(String result) { } } - if ("recheckSelected".equals(result)) { messageId = R.string.torrentsRecheck; } @@ -2329,7 +2202,6 @@ protected void onPostExecute(String result) { // Refresh refreshAfterCommand(delay); } - } } @@ -2343,7 +2215,6 @@ protected Torrent[] doInBackground(String... params) { boolean sequentialDownload = false; boolean firstLastPiecePrio = false; - Torrent[] torrents = null; // Get settings @@ -2351,7 +2222,6 @@ protected Torrent[] doInBackground(String... params) { try { - // Creating new JSON Parser jParser = new com.lgallardo.qbittorrentclient.JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); @@ -2384,13 +2254,13 @@ protected Torrent[] doInBackground(String... params) { downloadSpeed = json.getString(TAG_DLSPEED); uploadSpeed = json.getString(TAG_UPSPEED); - if (qb_version.equals("3.2.x")) { size = Common.calculateSize(size); eta = Common.secondsToEta(eta); downloadSpeed = Common.calculateSize(downloadSpeed) + "/s"; uploadSpeed = Common.calculateSize(uploadSpeed) + "/s"; + try { sequentialDownload = json.getBoolean(TAG_SEQDL); } catch (Exception e) { @@ -2403,7 +2273,6 @@ protected Torrent[] doInBackground(String... params) { } catch (Exception e) { firstLastPiecePrio = false; } - } torrents[i] = new Torrent(name, size, state, hash, info, ratio, progress, leechs, seeds, priority, eta, downloadSpeed, uploadSpeed, sequentialDownload, firstLastPiecePrio); @@ -2423,7 +2292,13 @@ protected Torrent[] doInBackground(String... params) { torrents[i].setDownloaded(size); } - // Info +// // Info free +// torrents[i].setInfo(torrents[i].getDownloaded() + " " + Character.toString('\u2193') + " " + torrents[i].getDownloadSpeed() + " " +// + Character.toString('\u2191') + " " + torrents[i].getUploadSpeed() + " " + Character.toString('\u2022') + " " +// + torrents[i].getRatio() + " " + Character.toString('\u2022') + " " + progress + " " + Character.toString('\u2022') + " " +// + torrents[i].getEta()); + + // Info pro torrents[i].setInfo(torrents[i].getDownloaded() + " " + Character.toString('\u2193') + " " + torrents[i].getDownloadSpeed() + " " + Character.toString('\u2191') + " " + torrents[i].getUploadSpeed() + " " + Character.toString('\u2022') + " " + torrents[i].getRatio() + " " + Character.toString('\u2022') + " " + torrents[i].getEta()); @@ -2452,6 +2327,8 @@ protected void onPostExecute(Torrent[] result) { Toast.makeText(getApplicationContext(), R.string.connection_error, Toast.LENGTH_SHORT).show(); + // Handle HTTP status code + if (httpStatusCode == 1) { Toast.makeText(getApplicationContext(), R.string.error1, Toast.LENGTH_SHORT).show(); httpStatusCode = 0; @@ -2474,18 +2351,8 @@ protected void onPostExecute(Torrent[] result) { Toast.makeText(getApplicationContext(), R.string.error403, Toast.LENGTH_SHORT).show(); httpStatusCode = 0; - } -// Log.i("httpStatusCode", "" + httpStatusCode); - -// // Set App title -// setTitle(R.string.app_shortname); -// -// // Uncheck any item on the drawer menu -// for (int i = 0; i < drawerList.getCount(); i++) { -// drawerList.setItemChecked(i, false); -// } } else { @@ -2573,7 +2440,6 @@ protected void onPostExecute(Torrent[] result) { Collections.sort(torrentsFiltered, new TorrentUploadSpeedComparator(reverse_order)); } - // Get names (delete in background method) MainActivity.names = new String[torrentsFiltered.size()]; MainActivity.lines = new Torrent[torrentsFiltered.size()]; @@ -2584,7 +2450,6 @@ protected void onPostExecute(Torrent[] result) { uploadCount = 0; downloadCount = 0; - try { Torrent torrentToUpdate = null; @@ -2597,9 +2462,7 @@ protected void onPostExecute(Torrent[] result) { MainActivity.lines[i] = torrent; if (torrent.getHash().equals(com.lgallardo.qbittorrentclient.TorrentDetailsFragment.hashToUpdate)) { - torrentToUpdate = torrent; - } uploadSpeedCount += (int) Common.humanSizeToBytes(torrent.getUploadSpeed()); @@ -2613,7 +2476,6 @@ protected void onPostExecute(Torrent[] result) { downloadCount = downloadCount + 1; } - } // Update torrent list @@ -2636,7 +2498,6 @@ protected void onPostExecute(Torrent[] result) { Log.e("Debug", "IllegalStateException: " + le.toString()); } - // Create the about fragment aboutFragment = new AboutFragment(); @@ -2647,7 +2508,6 @@ protected void onPostExecute(Torrent[] result) { // Got some results if (torrentsFiltered.size() > 0) { - // Set headerInfo TextView uploadSpeedTextView = (TextView) findViewById(R.id.uploadSpeed); TextView downloadSpeedTextView = (TextView) findViewById(R.id.downloadSpeed); @@ -2667,8 +2527,6 @@ protected void onPostExecute(Torrent[] result) { //Set first and second fragments if (findViewById(R.id.fragment_container) != null) { - Log.d("Debug", "fragment_container"); - // Set where is the second container firstFragment.setSecondFragmentContainer(R.id.content_frame); @@ -2709,8 +2567,6 @@ protected void onPostExecute(Torrent[] result) { } else { - Log.d("Debug", "one_frame"); - // Set where is the second container firstFragment.setSecondFragmentContainer(R.id.one_frame); @@ -2721,7 +2577,6 @@ protected void onPostExecute(Torrent[] result) { if (fragmentManager.findFragmentByTag("firstFragment") instanceof com.lgallardo.qbittorrentclient.TorrentDetailsFragment) { - com.lgallardo.qbittorrentclient.TorrentDetailsFragment detailsFragment = (com.lgallardo.qbittorrentclient.TorrentDetailsFragment) fragmentManager.findFragmentByTag("firstFragment"); if (torrentToUpdate != null) { @@ -2739,8 +2594,8 @@ protected void onPostExecute(Torrent[] result) { } } } - - } else { + } + else { // No results // myadapter = null; @@ -2794,30 +2649,6 @@ protected void onPostExecute(Torrent[] result) { fragmentManager.popBackStack(); } } - - -// String[] emptyList = new String[]{getString(R.string.no_results)}; -// firstFragment.setListAdapter(new ArrayAdapter(MainActivity.this, R.layout.no_items_found, R.id.no_results, emptyList)); -// -// -// // Set the second fragments container -// if (findViewById(R.id.fragment_container) != null) { -// firstFragment.setSecondFragmentContainer(R.id.content_frame); -// fragmentTransaction.replace(R.id.list_frame, firstFragment, "firstFragment"); -// fragmentTransaction.replace(R.id.content_frame, aboutFragment, "secondFragment"); -// -// } else { -// firstFragment.setSecondFragmentContainer(R.id.one_frame); -// fragmentTransaction.replace(R.id.one_frame, firstFragment, "firstFragment"); -// -// -// // Reset back button stack -// for (int i = 0; i < fragmentManager.getBackStackEntryCount(); ++i) { -// fragmentManager.popBackStack(); -// } -// -// } - } // Commit @@ -2827,9 +2658,6 @@ protected void onPostExecute(Torrent[] result) { Log.e("ADAPTER", e.toString()); } - - Log.d("Debug"," qBittorrentTask - post execute completed"); - // Clear serch field searchField = ""; @@ -2855,7 +2683,6 @@ protected void onPostExecute(Torrent[] result) { listViewRefreshing = false; - } } @@ -2939,6 +2766,8 @@ protected void onPostExecute(String result) { Toast.makeText(getApplicationContext(), R.string.connection_error, Toast.LENGTH_SHORT).show(); + // Handle HTTP status code + if (httpStatusCode == 1) { Toast.makeText(getApplicationContext(), R.string.error1, Toast.LENGTH_SHORT).show(); httpStatusCode = 0; @@ -2947,7 +2776,6 @@ protected void onPostExecute(String result) { if (httpStatusCode == 401) { Toast.makeText(getApplicationContext(), R.string.error401, Toast.LENGTH_LONG).show(); httpStatusCode = 0; - } if (httpStatusCode == 403) { @@ -2959,7 +2787,6 @@ protected void onPostExecute(String result) { // Get new Cookie cookie = ""; new qBittorrentCookie().execute(); - } } @@ -2979,11 +2806,11 @@ protected void onPostExecute(String result) { // Do nothing } - } } } + // Drawer classes private class DrawerItemClickListener implements ListView.OnItemClickListener { @Override @@ -2992,7 +2819,4 @@ public void onItemClick(AdapterView parent, View view, int position, long id) } } - - } - From 9a2c559c29ffd428c5fe45b2bf257f83513c0a1e Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Wed, 27 May 2015 00:52:20 -0430 Subject: [PATCH 19/26] * Verified code for TorrentDetailsFragment. Not yet unified! --- .../TorrentDetailsFragment.java | 160 +++++++++----- .../app/src/free/res/layout/activity_main.xml | 15 +- .../TorrentDetailsFragment.java | 200 +++++++++--------- 3 files changed, 205 insertions(+), 170 deletions(-) diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java index 4c87f8e6..dc9d8ff1 100644 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java @@ -15,6 +15,7 @@ import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; +import android.support.v4.widget.SwipeRefreshLayout; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; @@ -38,48 +39,47 @@ 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 = ""; - - static String hashToUpdate; - - String url; - private String qbQueryString = "query"; - private Torrent torrent; - - 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_TOTAL_DOWNLOADED = "tot|al_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"; + static ContentFile[] files; + static Tracker[] trackers; + static String[] names, trackerNames; + + // 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 = ""; + + static String hashToUpdate; + + String url; + int position; + JSONObject json2; // Adapters myFileAdapter fileAdpater; myTrackerAdapter trackerAdapter; myPropertyAdapter propertyAdapter; + private String qbQueryString = "query"; + private Torrent torrent; + public static SwipeRefreshLayout mSwipeRefreshLayout; + private com.lgallardo.qbittorrentclient.RefreshListener refreshListener; + + // TODO: Unify free & Pro private AdView adView; - private View rootView; +// private View rootView; public TorrentDetailsFragment() { } @@ -88,10 +88,6 @@ public void setPosition(int position) { this.position = position; } - public int getPosition() { - return this.position; - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -100,21 +96,35 @@ public void onCreate(Bundle 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); - if (MainActivity.qb_version.equals("3.2.x")) { + View rootView; + + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { rootView = inflater.inflate(R.layout.torrent_details, container, false); } else { rootView = inflater.inflate(R.layout.torrent_details_old, container, false); + } + + // Get Refresh Listener + refreshListener = (com.lgallardo.qbittorrentclient.RefreshListener) getActivity(); + mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.details_refresh_layout); + + if(mSwipeRefreshLayout != null) { + mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + refreshListener.swipeRefresh(); + } + }); + } + // Hide herderInfo and title in phone's view + if (getActivity().findViewById(R.id.one_frame) != null) { + com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.GONE); + ((com.lgallardo.qbittorrentclient.MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false); } savePath = ""; @@ -134,7 +144,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa if (savedInstanceState != null) { // Get saved values - name = savedInstanceState.getString("torrentDetailName", ""); size = savedInstanceState.getString("torrentDetailSize", ""); hash = savedInstanceState.getString("torrentDetailHash", ""); @@ -150,8 +159,22 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa downloaded = savedInstanceState.getString("torrentDetailDownloaded", ""); hashToUpdate = hash; + // TODO: Unify free & Pro +// int index = progress.indexOf("."); +// +// if (index == -1) { +// index = progress.indexOf(","); +// +// if (index == -1) { +// index = progress.length(); +// } +// } +// +// percentage = progress.substring(0, index); + } else { + // Get values from current activity name = this.torrent.getFile(); size = this.torrent.getSize(); hash = this.torrent.getHash(); @@ -167,6 +190,20 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa downloadSpeed = this.torrent.getDownloadSpeed(); downloaded = this.torrent.getDownloaded(); hashToUpdate = hash; + + // TODO: Unify free & Pro +// int index = this.torrent.getProgress().indexOf("."); +// +// if (index == -1) { +// index = this.torrent.getProgress().indexOf(","); +// +// if (index == -1) { +// index = this.torrent.getProgress().length(); +// } +// } +// +// percentage = this.torrent.getProgress().substring(0, index); + } TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName); @@ -174,13 +211,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa 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 priorityTextView = (TextView) rootView.findViewById(R.id.torrentPriority); 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 downloadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentDownloadSpeed); CheckBox sequentialDownloadCheckBox; CheckBox firstLAstPiecePrioCheckBox; @@ -198,7 +235,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa downloadSpeedTextView.setText(downloadSpeed); uploadSpeedTextView.setText(uploadSpeed); - if (MainActivity.qb_version.equals("3.2.x")) { + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { sequentialDownloadCheckBox = (CheckBox) rootView.findViewById(R.id.torrentSequentialDownload); firstLAstPiecePrioCheckBox = (CheckBox) rootView.findViewById(R.id.torrentFirstLastPiecePrio); @@ -206,11 +243,22 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa firstLAstPiecePrioCheckBox.setChecked(this.torrent.getisFirstLastPiecePrio()); } - - // Set status icon +// downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); +// uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); +// +// // Set Downloaded vs Total size +// sizeTextView.setText(downloaded + " / " + size); +// +// // Set progress bar +// ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1); +// TextView percentageTV = (TextView) rootView.findViewById(R.id.percentage); +// +// progressBar.setProgress(Integer.parseInt(percentage)); +// percentageTV.setText(percentage + "%"); nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.checking, 0, 0, 0); + // Set status icon if ("pausedUP".equals(state) || "pausedDL".equals(state)) { nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.paused, 0, 0, 0); } @@ -235,16 +283,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.queued, 0, 0, 0); } - if ("checkingDL".equals(state) || "checkingUP".equals(state)) { nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_recheck, 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}); @@ -253,7 +295,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa qBittorrentTrackers qt = new qBittorrentTrackers(); qt.execute(new View[]{rootView}); - // get general info in background + // Get general info in background qBittorrentGeneralInfoTask qgit = new qBittorrentGeneralInfoTask(); qgit.execute(new View[]{rootView}); @@ -261,6 +303,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa Log.e("Debug", "TorrentDetailsFragment - onCreateView: " + e.toString()); } + // TODO: Unify free & Pro // Load banner loadBanner(); @@ -269,9 +312,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa public void updateDetails(Torrent torrent) { - try { + // Hide herderInfo in phone's view + if (getActivity().findViewById(R.id.one_frame) != null) { + com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.GONE); + } + // Get values from current activity name = torrent.getFile(); size = torrent.getSize(); @@ -312,7 +359,6 @@ public void updateDetails(Torrent torrent) { View rootView = detailsFragment.getView(); - TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName); TextView ratioTextView = (TextView) rootView.findViewById(R.id.torrentRatio); TextView priorityTextView = (TextView) rootView.findViewById(R.id.torrentPriority); @@ -389,10 +435,10 @@ public void updateDetails(Torrent torrent) { } - // Show progressBar - if (MainActivity.progressBar != null) { - MainActivity.progressBar.setVisibility(View.VISIBLE); - } +// // Show progressBar +// if (MainActivity.progressBar != null) { +// MainActivity.progressBar.setVisibility(View.VISIBLE); +// } // Get Content files in background qBittorrentContentFile qcf = new qBittorrentContentFile(); @@ -842,10 +888,10 @@ protected void onPostExecute(View[] rootViews) { Log.e("TorrentFragment:", e.toString()); } - // Hide progressBar - if (MainActivity.progressBar != null) { - MainActivity.progressBar.setVisibility(View.INVISIBLE); - } +// // Hide progressBar +// if (MainActivity.progressBar != null) { +// MainActivity.progressBar.setVisibility(View.INVISIBLE); +// } } diff --git a/qBittorrentClient/app/src/free/res/layout/activity_main.xml b/qBittorrentClient/app/src/free/res/layout/activity_main.xml index f98c8780..86b35420 100644 --- a/qBittorrentClient/app/src/free/res/layout/activity_main.xml +++ b/qBittorrentClient/app/src/free/res/layout/activity_main.xml @@ -18,23 +18,18 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:background="?windowBackground"> + android:background="?backgroundSelector"> - + + diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java index 85574ef7..a0b32f7b 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java @@ -49,9 +49,11 @@ public class TorrentDetailsFragment extends Fragment { 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"; + static ContentFile[] files; static Tracker[] trackers; static String[] names, trackerNames; + // Torrent variables String name, info, hash, ratio, size, state, leechs, seeds, progress, priority, savePath, creationDate, comment, totalWasted, totalUploaded, totalDownloaded, timeElapsed, nbConnections, shareRatio, uploadRateLimit, downloadRateLimit, downloaded, eta, downloadSpeed, uploadSpeed, @@ -62,97 +64,24 @@ public class TorrentDetailsFragment extends Fragment { String url; int position; JSONObject json2; + // Adapters myFileAdapter fileAdpater; myTrackerAdapter trackerAdapter; myPropertyAdapter propertyAdapter; + private String qbQueryString = "query"; private Torrent torrent; public static SwipeRefreshLayout mSwipeRefreshLayout; private com.lgallardo.qbittorrentclient.RefreshListener refreshListener; + // TODO: Unify free & Pro +// private AdView adView; +// private View rootView; public TorrentDetailsFragment() { } - /** - * * - * 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 = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED); - - //Log.i("Height","desiredWidth: "+desiredWidth); - - - int totalHeight = 0; - - View view = null; - - for (int i = 0; i < listAdapter.getCount(); i++) { - - long numOfLines = 1; - view = listAdapter.getView(i, view, listView); - - if (i == 0) { - view.setLayoutParams(new LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT)); - } - - view.measure(desiredWidth, MeasureSpec.UNSPECIFIED); - - TextView file = (TextView) view.findViewById(R.id.file); - TextView info = (TextView) view.findViewById(R.id.info); - - if (view.getMeasuredWidth() > desiredWidth) { - - double viewWidthLong = Double.valueOf(view.getMeasuredWidth()); - double desiredWidthLong = Double.valueOf(desiredWidth); - - //Log.i("Height", "viewWidthLong: " + viewWidthLong); - //Log.i("Height", "desiredWidthLong: " + desiredWidthLong); - - - numOfLines = Math.round(viewWidthLong / desiredWidthLong) + 1; - - - totalHeight += file.getMeasuredHeight() * numOfLines + info.getMeasuredHeight(); - - } else { - totalHeight += view.getMeasuredHeight(); - } - - //Log.i("Height", "numOfLines: " + numOfLines); - - //Log.i("Height", "getMeasuredHeight: " + view.getMeasuredHeight()); - //Log.i("Height", "getMeasuredWidth: " + view.getMeasuredWidth()); - - } - - LayoutParams params = listView.getLayoutParams(); - - params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); - - - //Log.i("Height","height: "+params.height); - - - listView.setLayoutParams(params); - listView.requestLayout(); - - } - - public int getPosition() { - return this.position; - } - public void setPosition(int position) { this.position = position; } @@ -172,11 +101,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa View rootView; if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { - rootView = inflater.inflate(R.layout.torrent_details, container, false); } else { rootView = inflater.inflate(R.layout.torrent_details_old, container, false); - } // Get Refresh Listener @@ -187,9 +114,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { - Log.d("Debug", "Swipe!"); refreshListener.swipeRefresh(); - } }); } @@ -200,7 +125,6 @@ public void onRefresh() { ((com.lgallardo.qbittorrentclient.MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false); } - savePath = ""; creationDate = ""; comment = ""; @@ -218,7 +142,6 @@ public void onRefresh() { if (savedInstanceState != null) { // Get saved values - name = savedInstanceState.getString("torrentDetailName", ""); size = savedInstanceState.getString("torrentDetailSize", ""); hash = savedInstanceState.getString("torrentDetailHash", ""); @@ -232,9 +155,9 @@ public void onRefresh() { uploadSpeed = savedInstanceState.getString("torrentDetailUploadSpeed", ""); downloadSpeed = savedInstanceState.getString("torrentDetailDownloadSpeed", ""); downloaded = savedInstanceState.getString("torrentDetailDownloaded", ""); - hashToUpdate = hash; + // TODO: Unify free & Pro int index = progress.indexOf("."); if (index == -1) { @@ -247,8 +170,6 @@ public void onRefresh() { percentage = progress.substring(0, index); - // return rootView; - } else { // Get values from current activity @@ -265,9 +186,9 @@ public void onRefresh() { uploadSpeed = this.torrent.getUploadSpeed(); downloadSpeed = this.torrent.getDownloadSpeed(); downloaded = this.torrent.getDownloaded(); - hashToUpdate = hash; + // TODO: Unify free & Pro int index = this.torrent.getProgress().indexOf("."); if (index == -1) { @@ -285,13 +206,12 @@ public void onRefresh() { TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName); TextView sizeTextView = (TextView) rootView.findViewById(R.id.downloadedVsTotal); TextView ratioTextView = (TextView) rootView.findViewById(R.id.torrentRatio); - TextView priorityTextView = (TextView) rootView.findViewById(R.id.torrentPriority); + TextView progressTextView = (TextView) rootView.findViewById(R.id.torrentProgress); TextView stateTextView = (TextView) rootView.findViewById(R.id.torrentState); + TextView priorityTextView = (TextView) rootView.findViewById(R.id.torrentPriority); TextView leechsTextView = (TextView) rootView.findViewById(R.id.torrentLeechs); TextView seedsTextView = (TextView) rootView.findViewById(R.id.torrentSeeds); - TextView progressTextView = (TextView) rootView.findViewById(R.id.torrentProgress); TextView hashTextView = (TextView) rootView.findViewById(R.id.torrentHash); - TextView etaTextView = (TextView) rootView.findViewById(R.id.eta); TextView uploadSpeedTextView = (TextView) rootView.findViewById(R.id.uploadSpeed); TextView downloadSpeedTextView = (TextView) rootView.findViewById(R.id.DownloadSpeed); @@ -300,14 +220,17 @@ public void onRefresh() { CheckBox firstLAstPiecePrioCheckBox; nameTextView.setText(name); +// sizeTextView.setText(size); ratioTextView.setText(ratio); stateTextView.setText(state); leechsTextView.setText(leechs); seedsTextView.setText(seeds); progressTextView.setText(progress); hashTextView.setText(hash); - priorityTextView.setText(priority); etaTextView.setText(eta); + priorityTextView.setText(priority); +// downloadSpeedTextView.setText(downloadSpeed); +// uploadSpeedTextView.setText(uploadSpeed); if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { sequentialDownloadCheckBox = (CheckBox) rootView.findViewById(R.id.torrentSequentialDownload); @@ -317,7 +240,6 @@ public void onRefresh() { firstLAstPiecePrioCheckBox.setChecked(this.torrent.getisFirstLastPiecePrio()); } - downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); @@ -333,6 +255,7 @@ public void onRefresh() { nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.error, 0, 0, 0); + // Set status icon if ("pausedUP".equals(state) || "pausedDL".equals(state)) { nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.paused, 0, 0, 0); } @@ -361,12 +284,6 @@ public void onRefresh() { nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_recheck, 0, 0, 0); } - -// // Show progressBar -// if (com.lgallardo.qbittorrentclient.MainActivity.progressBar != null) { -// com.lgallardo.qbittorrentclient.MainActivity.progressBar.setVisibility(View.VISIBLE); -// } - // Get Content files in background qBittorrentContentFile qcf = new qBittorrentContentFile(); qcf.execute(new View[]{rootView}); @@ -380,16 +297,18 @@ public void onRefresh() { qgit.execute(new View[]{rootView}); } catch (Exception e) { - Log.e("Debug", "TorrentDetailsFragment - onCreateView: " + e.toString()); } + // TODO: Unify free & Pro +// // Load banner +// loadBanner(); + return rootView; } public void updateDetails(Torrent torrent) { - try { // Hide herderInfo in phone's view @@ -431,13 +350,12 @@ public void updateDetails(Torrent torrent) { if (getActivity().findViewById(R.id.one_frame) != null) { detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("firstFragment"); - }else{ + } else{ detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("secondFragment"); } View rootView = detailsFragment.getView(); - TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName); TextView sizeTextView = (TextView) rootView.findViewById(R.id.downloadedVsTotal); TextView ratioTextView = (TextView) rootView.findViewById(R.id.torrentRatio); @@ -1098,4 +1016,80 @@ public View getView(int position, View convertView, ViewGroup parent) { 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 = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED); + + //Log.i("Height","desiredWidth: "+desiredWidth); + + + int totalHeight = 0; + + View view = null; + + for (int i = 0; i < listAdapter.getCount(); i++) { + + long numOfLines = 1; + view = listAdapter.getView(i, view, listView); + + if (i == 0) { + view.setLayoutParams(new LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT)); + } + + view.measure(desiredWidth, MeasureSpec.UNSPECIFIED); + + TextView file = (TextView) view.findViewById(R.id.file); + TextView info = (TextView) view.findViewById(R.id.info); + + if (view.getMeasuredWidth() > desiredWidth) { + + double viewWidthLong = Double.valueOf(view.getMeasuredWidth()); + double desiredWidthLong = Double.valueOf(desiredWidth); + + //Log.i("Height", "viewWidthLong: " + viewWidthLong); + //Log.i("Height", "desiredWidthLong: " + desiredWidthLong); + + + numOfLines = Math.round(viewWidthLong / desiredWidthLong) + 1; + + + totalHeight += file.getMeasuredHeight() * numOfLines + info.getMeasuredHeight(); + + } else { + totalHeight += view.getMeasuredHeight(); + } + + //Log.i("Height", "numOfLines: " + numOfLines); + + //Log.i("Height", "getMeasuredHeight: " + view.getMeasuredHeight()); + //Log.i("Height", "getMeasuredWidth: " + view.getMeasuredWidth()); + + } + + LayoutParams params = listView.getLayoutParams(); + + params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); + + + //Log.i("Height","height: "+params.height); + + + listView.setLayoutParams(params); + listView.requestLayout(); + + } + } From ffb62a06b62d8e2cc56d8c59015e60645a75dcc2 Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Wed, 27 May 2015 18:06:44 -0430 Subject: [PATCH 20/26] * Code rearrenged in odert to unify TorrentDetailsFragment.java * Fixed activity_main.xml and torrent_details.xml for Google Material Design --- qBittorrentClient/app/build.gradle | 1 - .../TorrentDetailsFragment.java | 121 ++++++++---------- .../app/src/free/res/layout/activity_main.xml | 8 +- .../src/free/res/layout/torrent_details.xml | 30 +++-- .../TorrentDetailsFragment.java | 65 +++------- .../app/src/pro/res/layout/activity_main.xml | 3 +- .../src/pro/res/layout/torrent_details.xml | 2 +- 7 files changed, 99 insertions(+), 131 deletions(-) diff --git a/qBittorrentClient/app/build.gradle b/qBittorrentClient/app/build.gradle index dcf816b0..ddbd0101 100644 --- a/qBittorrentClient/app/build.gradle +++ b/qBittorrentClient/app/build.gradle @@ -52,7 +52,6 @@ android { } dependencies { - compile 'com.android.support:support-v4:21.0.0' compile 'com.android.support:appcompat-v7:21.0.0' compile 'com.android.support:recyclerview-v7:21.0.0' diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java index dc9d8ff1..3cf2483e 100644 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java @@ -23,6 +23,7 @@ import android.view.View; import android.view.View.MeasureSpec; import android.view.ViewGroup; +import android.view.ViewGroup.LayoutParams; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.LinearLayout; @@ -45,7 +46,7 @@ public class TorrentDetailsFragment extends Fragment { 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 = "tot|al_downloaded"; + 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"; @@ -179,11 +180,10 @@ public void onRefresh() { size = this.torrent.getSize(); hash = this.torrent.getHash(); ratio = this.torrent.getRatio(); - progress = this.torrent.getProgress(); state = this.torrent.getState(); leechs = this.torrent.getLeechs(); seeds = this.torrent.getSeeds(); - hash = this.torrent.getHash(); + progress = this.torrent.getProgress(); priority = this.torrent.getPriority(); eta = this.torrent.getEta(); uploadSpeed = this.torrent.getUploadSpeed(); @@ -243,6 +243,7 @@ public void onRefresh() { firstLAstPiecePrioCheckBox.setChecked(this.torrent.getisFirstLastPiecePrio()); } + // TODO: Unify free & Pro // downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); // uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); // @@ -256,7 +257,7 @@ public void onRefresh() { // progressBar.setProgress(Integer.parseInt(percentage)); // percentageTV.setText(percentage + "%"); - nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.checking, 0, 0, 0); + nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.error, 0, 0, 0); // Set status icon if ("pausedUP".equals(state) || "pausedDL".equals(state)) { @@ -360,6 +361,7 @@ public void updateDetails(Torrent torrent) { View rootView = detailsFragment.getView(); TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName); +// TextView sizeTextView = (TextView) rootView.findViewById(R.id.downloadedVsTotal); TextView ratioTextView = (TextView) rootView.findViewById(R.id.torrentRatio); TextView priorityTextView = (TextView) rootView.findViewById(R.id.torrentPriority); TextView stateTextView = (TextView) rootView.findViewById(R.id.torrentState); @@ -385,7 +387,7 @@ public void updateDetails(Torrent torrent) { priorityTextView.setText(priority); etaTextView.setText(eta); - if (MainActivity.qb_version.equals("3.2.x")) { + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { sequentialDownloadCheckBox = (CheckBox) rootView.findViewById(R.id.torrentSequentialDownload); firstLAstPiecePrioCheckBox = (CheckBox) rootView.findViewById(R.id.torrentFirstLastPiecePrio); @@ -393,10 +395,16 @@ public void updateDetails(Torrent torrent) { firstLAstPiecePrioCheckBox.setChecked(torrent.getisFirstLastPiecePrio()); } - + // TODO: Unify free & Pro +// downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); +// uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); downloadSpeedTextView.setText(downloadSpeed); uploadSpeedTextView.setText(uploadSpeed); + // TODO: Unify free & Pro +// // Set Downloaded vs Total size +// sizeTextView.setText(downloaded + " / " + size); + // Set progress bar ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1); TextView percentageTV = (TextView) rootView.findViewById(R.id.percentage); @@ -434,12 +442,6 @@ public void updateDetails(Torrent torrent) { nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_recheck, 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}); @@ -487,16 +489,15 @@ public void onListItemClick(ListView parent, View v, int position, long id) { 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_refresh).setVisible(true); + if (getActivity().findViewById(R.id.one_frame) != null) { + menu.findItem(R.id.action_refresh).setVisible(false); + }else{ + menu.findItem(R.id.action_refresh).setVisible(true); + } if (getActivity().findViewById(R.id.one_frame) != null) { menu.findItem(R.id.action_sort_menu).setVisible(false); @@ -523,10 +524,11 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.findItem(R.id.action_search).setVisible(true); } - if (MainActivity.qb_version.equals("3.2.x")) { + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { menu.findItem(R.id.action_firts_last_piece_prio).setVisible(true); menu.findItem(R.id.action_sequential_download).setVisible(true); - } else { + } + else { menu.findItem(R.id.action_firts_last_piece_prio).setVisible(false); menu.findItem(R.id.action_sequential_download).setVisible(false); } @@ -534,6 +536,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { } } + // TODO: Unify free & Pro // Load Banner public void loadBanner() { @@ -551,7 +554,6 @@ public void setTorrent(Torrent torrent) { this.torrent = torrent; } - // // Here is where the action happens private class qBittorrentContentFile extends AsyncTask { @@ -562,15 +564,15 @@ private class qBittorrentContentFile extends AsyncTask { protected View[] doInBackground(View... rootViews) { // Get torrent's files - if (MainActivity.qb_version.equals("2.x")) { + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("2.x")) { qbQueryString = "json"; } - if (MainActivity.qb_version.equals("3.1.x")) { + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.1.x")) { qbQueryString = "json"; } - if (MainActivity.qb_version.equals("3.2.x")) { + if (com.lgallardo.qbittorrentclient. MainActivity.qb_version.equals("3.2.x")) { qbQueryString = "query"; } @@ -582,10 +584,10 @@ protected View[] doInBackground(View... rootViews) { try { - JSONParser jParser = new JSONParser(MainActivity.hostname, MainActivity.subfolder, MainActivity.protocol, MainActivity.port, - MainActivity.username, MainActivity.password, MainActivity.connection_timeout, MainActivity.data_timeout); + com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(com.lgallardo.qbittorrentclient.MainActivity.hostname, com.lgallardo.qbittorrentclient.MainActivity.subfolder, com.lgallardo.qbittorrentclient.MainActivity.protocol, com.lgallardo.qbittorrentclient.MainActivity.port, + com.lgallardo.qbittorrentclient.MainActivity.username, com.lgallardo.qbittorrentclient.MainActivity.password, com.lgallardo.qbittorrentclient.MainActivity.connection_timeout, com.lgallardo.qbittorrentclient.MainActivity.data_timeout); - jParser.setCookie(MainActivity.cookie); + jParser.setCookie(com.lgallardo.qbittorrentclient.MainActivity.cookie); JSONArray jArray = jParser.getJSONArrayFromUrl(url + hash); @@ -598,13 +600,13 @@ protected View[] doInBackground(View... rootViews) { 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); + name = json.getString(com.lgallardo.qbittorrentclient.MainActivity.TAG_NAME); + size = json.getString(com.lgallardo.qbittorrentclient.MainActivity.TAG_SIZE).replace(",", "."); + progress = json.getDouble(com.lgallardo.qbittorrentclient.MainActivity.TAG_PROGRESS); + priority = json.getInt(com.lgallardo.qbittorrentclient.MainActivity.TAG_PRIORITY); - if (MainActivity.qb_version.equals("3.2.x")) { - size = Common.calculateSize(json.getString(MainActivity.TAG_SIZE)).replace(",", "."); + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { + size = Common.calculateSize(json.getString(com.lgallardo.qbittorrentclient.MainActivity.TAG_SIZE)).replace(",", "."); } files[i] = new ContentFile(name, size, progress, priority); @@ -656,28 +658,29 @@ private class qBittorrentTrackers extends AsyncTask { protected View[] doInBackground(View... rootViews) { // Get torrent's trackers - if (MainActivity.qb_version.equals("2.x")) { + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("2.x")) { qbQueryString = "json"; } - if (MainActivity.qb_version.equals("3.1.x")) { + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.1.x")) { qbQueryString = "json"; } - if (MainActivity.qb_version.equals("3.2.x")) { + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { qbQueryString = "query"; } url = qbQueryString + "/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); + com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(com.lgallardo.qbittorrentclient.MainActivity.hostname, com.lgallardo.qbittorrentclient.MainActivity.subfolder, com.lgallardo.qbittorrentclient.MainActivity.protocol, com.lgallardo.qbittorrentclient.MainActivity.port, + com.lgallardo.qbittorrentclient.MainActivity.username, com.lgallardo.qbittorrentclient.MainActivity.password, com.lgallardo.qbittorrentclient.MainActivity.connection_timeout, com.lgallardo.qbittorrentclient.MainActivity.data_timeout); - jParser.setCookie(MainActivity.cookie); + jParser.setCookie(com.lgallardo.qbittorrentclient.MainActivity.cookie); JSONArray jArray = jParser.getJSONArrayFromUrl(url + hash); @@ -690,7 +693,7 @@ protected View[] doInBackground(View... rootViews) { JSONObject json = jArray.getJSONObject(i); - url = json.getString(TAG_URL); + url = json.getString(com.lgallardo.qbittorrentclient.MainActivity.TAG_URL); trackers[i] = new Tracker(url); trackerNames[i] = url; @@ -744,15 +747,15 @@ private class qBittorrentGeneralInfoTask extends AsyncTask { protected View[] doInBackground(View... rootViews) { // Get torrent's extra info - if (MainActivity.qb_version.equals("2.x")) { + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("2.x")) { qbQueryString = "json"; } - if (MainActivity.qb_version.equals("3.1.x")) { + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.1.x")) { qbQueryString = "json"; } - if (MainActivity.qb_version.equals("3.2.x")) { + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { qbQueryString = "query"; } @@ -760,10 +763,10 @@ protected View[] doInBackground(View... rootViews) { try { - JSONParser jParser = new JSONParser(MainActivity.hostname, MainActivity.subfolder, MainActivity.protocol, MainActivity.port, - MainActivity.username, MainActivity.password, MainActivity.connection_timeout, MainActivity.data_timeout); + com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(com.lgallardo.qbittorrentclient.MainActivity.hostname, com.lgallardo.qbittorrentclient.MainActivity.subfolder, com.lgallardo.qbittorrentclient.MainActivity.protocol, com.lgallardo.qbittorrentclient.MainActivity.port, + com.lgallardo.qbittorrentclient.MainActivity.username, com.lgallardo.qbittorrentclient.MainActivity.password, com.lgallardo.qbittorrentclient.MainActivity.connection_timeout, com.lgallardo.qbittorrentclient.MainActivity.data_timeout); - jParser.setCookie(MainActivity.cookie); + jParser.setCookie(com.lgallardo.qbittorrentclient.MainActivity.cookie); json2 = jParser.getJSONFromUrl(url + hash); @@ -817,7 +820,7 @@ protected View[] doInBackground(View... rootViews) { values[10] = json2.getString(TAG_DOWNLOAD_LIMIT); - if (MainActivity.qb_version.equals("3.2.x")) { + if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { // Creation date values[1] = Common.unixTimestampToDate(json2.getString(TAG_CREATION_DATE)); @@ -884,15 +887,9 @@ protected void onPostExecute(View[] rootViews) { } } catch (Exception e) { - // TODO Auto-generated catch block Log.e("TorrentFragment:", e.toString()); } -// // Hide progressBar -// if (MainActivity.progressBar != null) { -// MainActivity.progressBar.setVisibility(View.INVISIBLE); -// } - } } @@ -905,7 +902,6 @@ class myPropertyAdapter extends ArrayAdapter { 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; @@ -916,7 +912,6 @@ public myPropertyAdapter(Context context, String[] labels, String[] values) { @Override public int getCount() { - // TODO Auto-generated method stub} return (labels != null) ? labels.length : 0; } @@ -942,7 +937,6 @@ class myFileAdapter extends ArrayAdapter { 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; @@ -953,7 +947,6 @@ public myFileAdapter(Context context, String[] filesNames, ContentFile[] files) @Override public int getCount() { - // TODO Auto-generated method stub} return (filesNames != null) ? filesNames.length : 0; } @@ -997,7 +990,6 @@ class myTrackerAdapter extends ArrayAdapter { 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; @@ -1008,7 +1000,6 @@ public myTrackerAdapter(Context context, String[] trackersNames, Tracker[] track @Override public int getCount() { - // TODO Auto-generated method stub} return (trackersNames != null) ? trackersNames.length : 0; } @@ -1045,11 +1036,10 @@ public static void setListViewHeightBasedOnChildren(ListView listView) { for (int i = 0; i < listAdapter.getCount(); i++) { long numOfLines = 1; - view = listAdapter.getView(i, view, listView); if (i == 0) { - view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT)); + view.setLayoutParams(new LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT)); } view.measure(desiredWidth, MeasureSpec.UNSPECIFIED); @@ -1062,23 +1052,17 @@ public static void setListViewHeightBasedOnChildren(ListView listView) { double viewWidthLong = Double.valueOf(view.getMeasuredWidth()); double desiredWidthLong = Double.valueOf(desiredWidth); - //Log.i("Height", "viewWidthLong: " + viewWidthLong); - //Log.i("Height", "desiredWidthLong: " + desiredWidthLong); - - numOfLines = Math.round(viewWidthLong / desiredWidthLong) + 1; - totalHeight += file.getMeasuredHeight() * numOfLines + info.getMeasuredHeight(); } else { totalHeight += view.getMeasuredHeight(); } - } - ViewGroup.LayoutParams params = listView.getLayoutParams(); + LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); @@ -1087,5 +1071,4 @@ public static void setListViewHeightBasedOnChildren(ListView listView) { } - } diff --git a/qBittorrentClient/app/src/free/res/layout/activity_main.xml b/qBittorrentClient/app/src/free/res/layout/activity_main.xml index 86b35420..6543e4a4 100644 --- a/qBittorrentClient/app/src/free/res/layout/activity_main.xml +++ b/qBittorrentClient/app/src/free/res/layout/activity_main.xml @@ -20,7 +20,6 @@ android:orientation="vertical" android:background="?backgroundSelector"> - @@ -31,7 +30,12 @@ android:layout_height="wrap_content" android:gravity="end" android:orientation="horizontal" - android:paddingBottom="5dp"> + android:paddingTop="2dp" + android:paddingBottom="2dp" + android:background="?dropShadowBackground" + android:elevation="1dp" + android:layout_below="@+id/app_bar" + > - + xmlns:android="http://schemas.android.com/apk/res/android"> + android:orientation="vertical" + android:background="?windowBackground"> - \ No newline at end of file + \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java index a0b32f7b..84ec0f65 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java @@ -202,7 +202,6 @@ public void onRefresh() { percentage = this.torrent.getProgress().substring(0, index); } - TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName); TextView sizeTextView = (TextView) rootView.findViewById(R.id.downloadedVsTotal); TextView ratioTextView = (TextView) rootView.findViewById(R.id.torrentRatio); @@ -240,6 +239,7 @@ public void onRefresh() { firstLAstPiecePrioCheckBox.setChecked(this.torrent.getisFirstLastPiecePrio()); } + // TODO: Unify free & Pro downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); @@ -391,10 +391,13 @@ public void updateDetails(Torrent torrent) { firstLAstPiecePrioCheckBox.setChecked(torrent.getisFirstLastPiecePrio()); } - + // TODO: Unify free & Pro downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); +// downloadSpeedTextView.setText(downloadSpeed); +// uploadSpeedTextView.setText(uploadSpeed); + // TODO: Unify free & Pro // Set Downloaded vs Total size sizeTextView.setText(downloaded + " / " + size); @@ -435,12 +438,6 @@ public void updateDetails(Torrent torrent) { nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_recheck, 0, 0, 0); } - -// // Show progressBar -// if (com.lgallardo.qbittorrentclient.MainActivity.progressBar != null) { -// com.lgallardo.qbittorrentclient.MainActivity.progressBar.setVisibility(View.VISIBLE); -// } - // Get Content files in background qBittorrentContentFile qcf = new qBittorrentContentFile(); qcf.execute(new View[]{rootView}); @@ -488,12 +485,6 @@ public void onListItemClick(ListView parent, View v, int position, long id) { 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_resume_all).setVisible(false); menu.findItem(R.id.action_pause_all).setVisible(false); menu.findItem(R.id.action_add).setVisible(false); @@ -541,6 +532,20 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { } } + // TODO: Unify free & Pro +// // 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); +// +// } + public void setTorrent(Torrent torrent) { this.torrent = torrent; } @@ -553,6 +558,7 @@ private class qBittorrentContentFile extends AsyncTask { int priority; protected View[] doInBackground(View... rootViews) { + // Get torrent's files if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("2.x")) { qbQueryString = "json"; @@ -880,11 +886,6 @@ protected void onPostExecute(View[] rootViews) { Log.e("TorrentFragment:", e.toString()); } -// // Hide progressBar -// if (com.lgallardo.qbittorrentclient.MainActivity.progressBar != null) { -// com.lgallardo.qbittorrentclient.MainActivity.progressBar.setVisibility(View.INVISIBLE); -// } - } } @@ -897,7 +898,6 @@ class myPropertyAdapter extends ArrayAdapter { 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; @@ -908,7 +908,6 @@ public myPropertyAdapter(Context context, String[] labels, String[] values) { @Override public int getCount() { - // TODO Auto-generated method stub} return (labels != null) ? labels.length : 0; } @@ -934,7 +933,6 @@ class myFileAdapter extends ArrayAdapter { 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; @@ -945,7 +943,6 @@ public myFileAdapter(Context context, String[] filesNames, ContentFile[] files) @Override public int getCount() { - // TODO Auto-generated method stub} return (filesNames != null) ? filesNames.length : 0; } @@ -989,7 +986,6 @@ class myTrackerAdapter extends ArrayAdapter { 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; @@ -1000,7 +996,6 @@ public myTrackerAdapter(Context context, String[] trackersNames, Tracker[] track @Override public int getCount() { - // TODO Auto-generated method stub} return (trackersNames != null) ? trackersNames.length : 0; } @@ -1017,7 +1012,6 @@ public View getView(int position, View convertView, ViewGroup parent) { } } - /** * * * Method for Setting the Height of the ListView dynamically. Hack to fix @@ -1032,12 +1026,7 @@ public static void setListViewHeightBasedOnChildren(ListView listView) { return; int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED); - - //Log.i("Height","desiredWidth: "+desiredWidth); - - int totalHeight = 0; - View view = null; for (int i = 0; i < listAdapter.getCount(); i++) { @@ -1059,34 +1048,20 @@ public static void setListViewHeightBasedOnChildren(ListView listView) { double viewWidthLong = Double.valueOf(view.getMeasuredWidth()); double desiredWidthLong = Double.valueOf(desiredWidth); - //Log.i("Height", "viewWidthLong: " + viewWidthLong); - //Log.i("Height", "desiredWidthLong: " + desiredWidthLong); - - numOfLines = Math.round(viewWidthLong / desiredWidthLong) + 1; - totalHeight += file.getMeasuredHeight() * numOfLines + info.getMeasuredHeight(); } else { totalHeight += view.getMeasuredHeight(); } - //Log.i("Height", "numOfLines: " + numOfLines); - - //Log.i("Height", "getMeasuredHeight: " + view.getMeasuredHeight()); - //Log.i("Height", "getMeasuredWidth: " + view.getMeasuredWidth()); - } LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); - - //Log.i("Height","height: "+params.height); - - listView.setLayoutParams(params); listView.requestLayout(); diff --git a/qBittorrentClient/app/src/pro/res/layout/activity_main.xml b/qBittorrentClient/app/src/pro/res/layout/activity_main.xml index ed0aea3b..0edf1bd7 100644 --- a/qBittorrentClient/app/src/pro/res/layout/activity_main.xml +++ b/qBittorrentClient/app/src/pro/res/layout/activity_main.xml @@ -32,7 +32,8 @@ android:paddingTop="2dp" android:paddingBottom="2dp" android:background="?dropShadowBackground" - android:elevation="1dp"> + android:elevation="1dp" + > Date: Thu, 28 May 2015 00:16:41 -0430 Subject: [PATCH 21/26] * Gladle files updated --- qBittorrentClient/app/build.gradle | 12 ++++++------ qBittorrentClient/build.gradle | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/qBittorrentClient/app/build.gradle b/qBittorrentClient/app/build.gradle index ddbd0101..ae1a5d00 100644 --- a/qBittorrentClient/app/build.gradle +++ b/qBittorrentClient/app/build.gradle @@ -8,7 +8,7 @@ android { defaultConfig { applicationId 'com.lgallardo.qbittorrentclient' minSdkVersion 14 - targetSdkVersion 21 + targetSdkVersion 22 archivesBaseName = "qBittorrentClient_v" + versionName } @@ -52,11 +52,11 @@ android { } dependencies { - compile 'com.android.support:support-v4:21.0.0' - compile 'com.android.support:appcompat-v7:21.0.0' - compile 'com.android.support:recyclerview-v7:21.0.0' - compile 'com.android.support:cardview-v7:21.0.0' - compile 'com.google.android.gms:play-services:7.0.0' + compile 'com.android.support:support-v4:22.1.1' + compile 'com.android.support:appcompat-v7:22.1.1' + compile 'com.android.support:recyclerview-v7:22.1.1' + compile 'com.android.support:cardview-v7:22.1.1' + compile 'com.google.android.gms:play-services:7.3.0' compile files('libs/httpcore-4.3.2.jar') compile files('libs/httpmime-4.3.5.jar') } diff --git a/qBittorrentClient/build.gradle b/qBittorrentClient/build.gradle index 833eee9a..88d246d4 100644 --- a/qBittorrentClient/build.gradle +++ b/qBittorrentClient/build.gradle @@ -4,7 +4,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.1.0' + classpath 'com.android.tools.build:gradle:1.2.3' } } From c5e64ce99dd32909c75e1860a119e89110ab47d7 Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Thu, 28 May 2015 11:37:50 -0430 Subject: [PATCH 22/26] * Fixed autoscroll when updating torrent details (disable listview focus in scrollview) * Torrent details adaptation for Google Materia Desing --- .../TorrentDetailsFragment.java | 2 + .../src/free/res/layout/torrent_details.xml | 27 +++++++------ .../free/res/layout/torrent_details_old.xml | 38 +++++++++++++------ .../TorrentDetailsFragment.java | 2 + 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java index 3cf2483e..b088402c 100644 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java @@ -637,6 +637,8 @@ protected void onPostExecute(View[] rootViews) { ListView lv = (ListView) rootView.findViewById(R.id.theList); + lv.setFocusable(false); + lv.setAdapter(fileAdpater); setListViewHeightBasedOnChildren(lv); diff --git a/qBittorrentClient/app/src/free/res/layout/torrent_details.xml b/qBittorrentClient/app/src/free/res/layout/torrent_details.xml index 0cadef35..3caae98c 100644 --- a/qBittorrentClient/app/src/free/res/layout/torrent_details.xml +++ b/qBittorrentClient/app/src/free/res/layout/torrent_details.xml @@ -9,10 +9,10 @@ Luis M. Gallardo D. --> + android:layout_height="wrap_content"> + android:background="?windowBackground" + android:orientation="vertical"> + android:textSize="20sp" /> @@ -299,8 +298,8 @@ android:id="@+id/torrentSequentialDownloadLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/torrent_details_torrent_sequential" - android:layout_gravity="center" /> + android:layout_gravity="center" + android:text="@string/torrent_details_torrent_sequential" /> @@ -323,8 +322,8 @@ android:id="@+id/torrentFirstLastPiecePrioLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/torrent_details_torrent_first_last_piece_first" - android:layout_gravity="center" /> + android:layout_gravity="center" + android:text="@string/torrent_details_torrent_first_last_piece_first" /> @@ -356,9 +355,9 @@ @@ -405,9 +404,9 @@ @@ -448,9 +447,9 @@ diff --git a/qBittorrentClient/app/src/free/res/layout/torrent_details_old.xml b/qBittorrentClient/app/src/free/res/layout/torrent_details_old.xml index 1b692887..a9d0e5d9 100644 --- a/qBittorrentClient/app/src/free/res/layout/torrent_details_old.xml +++ b/qBittorrentClient/app/src/free/res/layout/torrent_details_old.xml @@ -8,17 +8,22 @@ Contributors: Luis M. Gallardo D. --> - + android:layout_height="wrap_content"> + + + android:textSize="20sp" /> + \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java index 84ec0f65..61c902c3 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java @@ -633,6 +633,8 @@ protected void onPostExecute(View[] rootViews) { ListView lv = (ListView) rootView.findViewById(R.id.theList); + lv.setFocusable(false); + lv.setAdapter(fileAdpater); setListViewHeightBasedOnChildren(lv); From 819df8600ce6b0e44e6e3762ce9928db926c81e6 Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Thu, 28 May 2015 18:22:04 -0430 Subject: [PATCH 23/26] * TorrentDetails.java modified to unify free & pro versions --- .../qbittorrentclient/MainActivity.java | 22 ++- .../qbittorrentclient/SettingsActivity.java | 4 +- .../TorrentDetailsFragment.java | 127 ++++++++-------- .../MainActivity.java | 27 +++- .../TorrentDetailsFragment.java | 136 ++++++++++-------- .../pro/res/layout-large/torrent_details.xml | 8 +- .../res/layout-large/torrent_details_old.xml | 8 +- .../res/layout-sw600dp/torrent_details.xml | 8 +- .../layout-sw600dp/torrent_details_old.xml | 8 +- .../app/src/pro/res/layout/activity_main.xml | 8 ++ .../src/pro/res/layout/torrent_details.xml | 37 ++++- .../pro/res/layout/torrent_details_old.xml | 36 ++++- 12 files changed, 274 insertions(+), 155 deletions(-) diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java index 78043950..9fb5900a 100644 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java @@ -24,6 +24,8 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; @@ -209,6 +211,9 @@ public class MainActivity extends ActionBarActivity implements RefreshListener { private boolean isSearchOpened = false; private EditText editSearch; + // Packge info + public static String packageName; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -1737,9 +1742,9 @@ protected void getSettings() { // Get connection and data timeouts try { - connection_timeout = Integer.parseInt(sharedPrefs.getString("connection_timeout", "5")); + connection_timeout = Integer.parseInt(sharedPrefs.getString("connection_timeout", "10")); } catch (NumberFormatException e) { - connection_timeout = 5; + connection_timeout = 20; } try { @@ -1769,6 +1774,19 @@ protected void getSettings() { header = sharedPrefs.getBoolean("header", true); + // Get packge info + PackageInfo pInfo = null; + try { + pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + + // Get package name + packageName = pInfo.packageName; + + Log.d("Debug", "Package name:" + packageName); + } // Get Options diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/SettingsActivity.java b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/SettingsActivity.java index b5208bd8..2bd305c7 100644 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/SettingsActivity.java +++ b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/SettingsActivity.java @@ -185,8 +185,8 @@ public void getQBittorrentServerValues(String value) { refresh_period.setSummary(refresh_period.getEntry()); - connection_timeout.setText(sharedPrefs.getString("connection_timeout" + value, "5")); - data_timeout.setText(sharedPrefs.getString("data_timeout" + value, "8")); + connection_timeout.setText(sharedPrefs.getString("connection_timeout" + value, "10")); + data_timeout.setText(sharedPrefs.getString("data_timeout" + value, "20")); if (sortBy.getEntry() == null) { sortBy.setValueIndex(1); diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java index b088402c..15ab894e 100644 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java @@ -78,9 +78,8 @@ public class TorrentDetailsFragment extends Fragment { public static SwipeRefreshLayout mSwipeRefreshLayout; private com.lgallardo.qbittorrentclient.RefreshListener refreshListener; - // TODO: Unify free & Pro + // AdView for ads private AdView adView; -// private View rootView; public TorrentDetailsFragment() { } @@ -160,18 +159,20 @@ public void onRefresh() { downloaded = savedInstanceState.getString("torrentDetailDownloaded", ""); hashToUpdate = hash; - // TODO: Unify free & Pro -// int index = progress.indexOf("."); -// -// if (index == -1) { -// index = progress.indexOf(","); -// -// if (index == -1) { -// index = progress.length(); -// } -// } -// -// percentage = progress.substring(0, index); + // Only for Pro version + if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { + int index = progress.indexOf("."); + + if (index == -1) { + index = progress.indexOf(","); + + if (index == -1) { + index = progress.length(); + } + } + + percentage = progress.substring(0, index); + } } else { @@ -191,19 +192,20 @@ public void onRefresh() { downloaded = this.torrent.getDownloaded(); hashToUpdate = hash; - // TODO: Unify free & Pro -// int index = this.torrent.getProgress().indexOf("."); -// -// if (index == -1) { -// index = this.torrent.getProgress().indexOf(","); -// -// if (index == -1) { -// index = this.torrent.getProgress().length(); -// } -// } -// -// percentage = this.torrent.getProgress().substring(0, index); + // Only for Pro version + if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { + int index = this.torrent.getProgress().indexOf("."); + if (index == -1) { + index = this.torrent.getProgress().indexOf(","); + + if (index == -1) { + index = this.torrent.getProgress().length(); + } + } + + percentage = this.torrent.getProgress().substring(0, index); + } } TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName); @@ -223,7 +225,6 @@ public void onRefresh() { CheckBox firstLAstPiecePrioCheckBox; nameTextView.setText(name); - sizeTextView.setText(size); ratioTextView.setText(ratio); stateTextView.setText(state); leechsTextView.setText(leechs); @@ -232,8 +233,6 @@ public void onRefresh() { hashTextView.setText(hash); etaTextView.setText(eta); priorityTextView.setText(priority); - downloadSpeedTextView.setText(downloadSpeed); - uploadSpeedTextView.setText(uploadSpeed); if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { sequentialDownloadCheckBox = (CheckBox) rootView.findViewById(R.id.torrentSequentialDownload); @@ -243,19 +242,30 @@ public void onRefresh() { firstLAstPiecePrioCheckBox.setChecked(this.torrent.getisFirstLastPiecePrio()); } - // TODO: Unify free & Pro -// downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); -// uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); -// -// // Set Downloaded vs Total size -// sizeTextView.setText(downloaded + " / " + size); -// -// // Set progress bar -// ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1); -// TextView percentageTV = (TextView) rootView.findViewById(R.id.percentage); -// -// progressBar.setProgress(Integer.parseInt(percentage)); -// percentageTV.setText(percentage + "%"); + // Only for Pro version + if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { + downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); + uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); + + // Set Downloaded vs Total size + sizeTextView.setText(downloaded + " / " + size); + + // Set progress bar + ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1); + TextView percentageTV = (TextView) rootView.findViewById(R.id.percentage); + + progressBar.setProgress(Integer.parseInt(percentage)); + percentageTV.setText(percentage + "%"); + } else { + sizeTextView.setText(size); + downloadSpeedTextView.setText(downloadSpeed); + uploadSpeedTextView.setText(uploadSpeed); + } + + sizeTextView.setText(size); + downloadSpeedTextView.setText(downloadSpeed); + uploadSpeedTextView.setText(uploadSpeed); + } nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.error, 0, 0, 0); @@ -304,9 +314,10 @@ public void onRefresh() { Log.e("Debug", "TorrentDetailsFragment - onCreateView: " + e.toString()); } - // TODO: Unify free & Pro - // Load banner - loadBanner(); + if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclient")) { + // Load banner + loadBanner(); + } return rootView; } @@ -395,15 +406,18 @@ public void updateDetails(Torrent torrent) { firstLAstPiecePrioCheckBox.setChecked(torrent.getisFirstLastPiecePrio()); } - // TODO: Unify free & Pro -// downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); -// uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); - downloadSpeedTextView.setText(downloadSpeed); - uploadSpeedTextView.setText(uploadSpeed); + // Only for Pro version + if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { + downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); + uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); + + // Set Downloaded vs Total size + sizeTextView.setText(downloaded + " / " + size); - // TODO: Unify free & Pro -// // Set Downloaded vs Total size -// sizeTextView.setText(downloaded + " / " + size); + }else { + downloadSpeedTextView.setText(downloadSpeed); + uploadSpeedTextView.setText(uploadSpeed); + } // Set progress bar ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1); @@ -536,12 +550,11 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { } } - // TODO: Unify free & Pro - // Load Banner + // Load Banner method public void loadBanner() { // Get the adView. - adView = (AdView) getActivity().findViewById(R.id.adView); + adView = (AdView) getActivity().findViewById(com.lgallardo.qbittorrentclient.R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); @@ -644,7 +657,6 @@ protected void onPostExecute(View[] rootViews) { setListViewHeightBasedOnChildren(lv); } catch (Exception e) { - // TODO Auto-generated catch block Log.e("Content2", e.toString()); } @@ -732,7 +744,6 @@ protected void onPostExecute(View[] rootViews) { } } catch (Exception e) { - // TODO Auto-generated catch block Log.e("Trackers", e.toString()); } diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index 2b3f61b9..96bedab8 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -24,6 +24,8 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; @@ -207,6 +209,9 @@ public class MainActivity extends ActionBarActivity implements RefreshListener { private boolean isSearchOpened = false; private EditText editSearch; + // Packge info + public static String packageName; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -1746,9 +1751,9 @@ protected void getSettings() { // Get connection and data timeouts try { - connection_timeout = Integer.parseInt(sharedPrefs.getString("connection_timeout", "5")); + connection_timeout = Integer.parseInt(sharedPrefs.getString("connection_timeout", "10")); } catch (NumberFormatException e) { - connection_timeout = 5; + connection_timeout = 20; } try { @@ -1778,6 +1783,19 @@ protected void getSettings() { header = sharedPrefs.getBoolean("header", true); + // Get packge info + PackageInfo pInfo = null; + try { + pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + + // Get package name + packageName = pInfo.packageName; + + Log.d("Debug", "Package name:" + packageName); + } // Get Options @@ -2520,11 +2538,13 @@ protected void onPostExecute(Torrent[] result) { headerInfo.setVisibility(View.GONE); } + Log.d("Debug", "uploadSpeedCount: " + uploadSpeedCount); + uploadSpeedTextView.setText(Character.toString('\u2191') + " " + Common.calculateSize("" + uploadSpeedCount) + "/s " + "(" + uploadCount + ")"); downloadSpeedTextView.setText(Character.toString('\u2193') + " " + Common.calculateSize("" + downloadSpeedCount) + "/s " + "(" + downloadCount + ")"); - //Set first and second fragments + //Set first and seco nd fragments if (findViewById(R.id.fragment_container) != null) { // Set where is the second container @@ -2656,6 +2676,7 @@ protected void onPostExecute(Torrent[] result) { } catch (Exception e) { Log.e("ADAPTER", e.toString()); +// e.printStackTrace(); } // Clear serch field diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java index 61c902c3..4f0664f8 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java @@ -32,6 +32,9 @@ import android.widget.ProgressBar; import android.widget.TextView; +import com.google.android.gms.ads.AdRequest; +import com.google.android.gms.ads.AdView; + import org.json.JSONArray; import org.json.JSONObject; @@ -72,12 +75,11 @@ public class TorrentDetailsFragment extends Fragment { private String qbQueryString = "query"; private Torrent torrent; - public static SwipeRefreshLayout mSwipeRefreshLayout; + public static SwipeRefreshLayout mSwipeRefreshLayout; private com.lgallardo.qbittorrentclient.RefreshListener refreshListener; - // TODO: Unify free & Pro -// private AdView adView; -// private View rootView; + // AdView for ads + private AdView adView; public TorrentDetailsFragment() { } @@ -157,18 +159,20 @@ public void onRefresh() { downloaded = savedInstanceState.getString("torrentDetailDownloaded", ""); hashToUpdate = hash; - // TODO: Unify free & Pro - int index = progress.indexOf("."); - - if (index == -1) { - index = progress.indexOf(","); + // Only for Pro version + if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { + int index = progress.indexOf("."); if (index == -1) { - index = progress.length(); + index = progress.indexOf(","); + + if (index == -1) { + index = progress.length(); + } } - } - percentage = progress.substring(0, index); + percentage = progress.substring(0, index); + } } else { @@ -188,22 +192,24 @@ public void onRefresh() { downloaded = this.torrent.getDownloaded(); hashToUpdate = hash; - // TODO: Unify free & Pro - int index = this.torrent.getProgress().indexOf("."); - - if (index == -1) { - index = this.torrent.getProgress().indexOf(","); + // Only for Pro version + if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { + int index = this.torrent.getProgress().indexOf("."); if (index == -1) { - index = this.torrent.getProgress().length(); + index = this.torrent.getProgress().indexOf(","); + + if (index == -1) { + index = this.torrent.getProgress().length(); + } } - } - percentage = this.torrent.getProgress().substring(0, index); + percentage = this.torrent.getProgress().substring(0, index); + } } TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName); - TextView sizeTextView = (TextView) rootView.findViewById(R.id.downloadedVsTotal); + 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); @@ -211,15 +217,14 @@ public void onRefresh() { 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.eta); - TextView uploadSpeedTextView = (TextView) rootView.findViewById(R.id.uploadSpeed); - TextView downloadSpeedTextView = (TextView) rootView.findViewById(R.id.DownloadSpeed); + TextView etaTextView = (TextView) rootView.findViewById(R.id.torrentEta); + TextView uploadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentUploadSpeed); + TextView downloadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentDownloadSpeed); CheckBox sequentialDownloadCheckBox; CheckBox firstLAstPiecePrioCheckBox; nameTextView.setText(name); -// sizeTextView.setText(size); ratioTextView.setText(ratio); stateTextView.setText(state); leechsTextView.setText(leechs); @@ -228,8 +233,6 @@ public void onRefresh() { hashTextView.setText(hash); etaTextView.setText(eta); priorityTextView.setText(priority); -// downloadSpeedTextView.setText(downloadSpeed); -// uploadSpeedTextView.setText(uploadSpeed); if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { sequentialDownloadCheckBox = (CheckBox) rootView.findViewById(R.id.torrentSequentialDownload); @@ -239,19 +242,25 @@ public void onRefresh() { firstLAstPiecePrioCheckBox.setChecked(this.torrent.getisFirstLastPiecePrio()); } - // TODO: Unify free & Pro - downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); - uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); + // Only for Pro version + if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { + downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); + uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); - // Set Downloaded vs Total size - sizeTextView.setText(downloaded + " / " + size); + // Set Downloaded vs Total size + sizeTextView.setText(downloaded + " / " + size); - // Set progress bar - ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1); - TextView percentageTV = (TextView) rootView.findViewById(R.id.percentage); + // Set progress bar + ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1); + TextView percentageTV = (TextView) rootView.findViewById(R.id.percentage); - progressBar.setProgress(Integer.parseInt(percentage)); - percentageTV.setText(percentage + "%"); + progressBar.setProgress(Integer.parseInt(percentage)); + percentageTV.setText(percentage + "%"); + } else { + sizeTextView.setText(size); + downloadSpeedTextView.setText(downloadSpeed); + uploadSpeedTextView.setText(uploadSpeed); + } nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.error, 0, 0, 0); @@ -300,9 +309,10 @@ public void onRefresh() { Log.e("Debug", "TorrentDetailsFragment - onCreateView: " + e.toString()); } - // TODO: Unify free & Pro -// // Load banner -// loadBanner(); + if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclient")) { + // Load banner + loadBanner(); + } return rootView; } @@ -391,15 +401,18 @@ public void updateDetails(Torrent torrent) { firstLAstPiecePrioCheckBox.setChecked(torrent.getisFirstLastPiecePrio()); } - // TODO: Unify free & Pro - downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); - uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); -// downloadSpeedTextView.setText(downloadSpeed); -// uploadSpeedTextView.setText(uploadSpeed); + // Only for Pro version + if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { + downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); + uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); + + // Set Downloaded vs Total size + sizeTextView.setText(downloaded + " / " + size); - // TODO: Unify free & Pro - // Set Downloaded vs Total size - sizeTextView.setText(downloaded + " / " + size); + }else { + downloadSpeedTextView.setText(downloadSpeed); + uploadSpeedTextView.setText(uploadSpeed); + } // Set progress bar ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1); @@ -532,19 +545,18 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { } } - // TODO: Unify free & Pro -// // 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); -// -// } + // Load Banner method + 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); + + } public void setTorrent(Torrent torrent) { this.torrent = torrent; @@ -640,7 +652,6 @@ protected void onPostExecute(View[] rootViews) { setListViewHeightBasedOnChildren(lv); } catch (Exception e) { - // TODO Auto-generated catch block Log.e("Content2", e.toString()); } @@ -728,7 +739,6 @@ protected void onPostExecute(View[] rootViews) { } } catch (Exception e) { - // TODO Auto-generated catch block Log.e("Trackers", e.toString()); } diff --git a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details.xml b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details.xml index 840ee67b..a0d6bba3 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details.xml @@ -72,7 +72,7 @@ android:orientation="vertical"> + + + + android:orientation="horizontal"> + + + + + + + + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout/torrent_details_old.xml b/qBittorrentClient/app/src/pro/res/layout/torrent_details_old.xml index d4a4b241..00af40ac 100644 --- a/qBittorrentClient/app/src/pro/res/layout/torrent_details_old.xml +++ b/qBittorrentClient/app/src/pro/res/layout/torrent_details_old.xml @@ -6,7 +6,7 @@ http://www.gnu.org/licenses/gpl.html Contributors: - Luis M. Gallardo D. - initial implementation + Luis M. Gallardo D. --> + + + + + + + + + + \ No newline at end of file From f265183d5de7d007047cd6e86da79f5695510efe Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Fri, 29 May 2015 18:06:02 -0430 Subject: [PATCH 24/26] * Modified timeout defaults for flawless connections * Fixed refresh behaviour * Fixed authentication errors * Fixed icon behavior in toolbar when pressing back button * Google Material Design adaptation for free version * Fixed contextual bar to show more actions * TorrentDetails.java unified --- qBittorrentClient/app/build.gradle | 8 +- .../qbittorrentclient/MainActivity.java | 158 ++- .../qbittorrentclient/SettingsActivity.java | 6 +- .../qbittorrentclient/TorrentListAdapter.java | 14 +- .../app/src/free/res/layout-large/row.xml | 31 +- .../free/res/layout-large/torrent_details.xml | 8 + .../res/layout-large/torrent_details_old.xml | 8 + .../app/src/free/res/layout-sw600dp/row.xml | 23 +- .../res/layout-sw600dp/torrent_details.xml | 8 + .../layout-sw600dp/torrent_details_old.xml | 8 + .../app/src/free/res/layout/row.xml | 36 +- .../src/free/res/layout/torrent_details.xml | 7 + .../free/res/layout/torrent_details_old.xml | 7 +- .../qbittorrentclient/AboutFragment.java | 4 +- .../qbittorrentclient/ItemstFragment.java | 3 +- .../qbittorrentclient/JSONParser.java | 45 +- .../TorrentDetailsFragment.java | 89 +- .../res/menu/main_contextual_action_bar.xml | 30 +- .../app/src/main/res/values/colors_dark.xml | 2 +- .../MainActivity.java | 187 +-- .../SettingsActivity.java | 5 +- .../TorrentDetailsFragment.java | 1082 ----------------- .../app/src/pro/res/layout-large/row.xml | 2 +- .../pro/res/layout-large/torrent_details.xml | 27 +- .../res/layout-large/torrent_details_old.xml | 27 +- .../app/src/pro/res/layout-sw600dp/row.xml | 4 +- .../res/layout-sw600dp/torrent_details.xml | 26 +- .../layout-sw600dp/torrent_details_old.xml | 27 +- .../app/src/pro/res/layout/row.xml | 4 +- .../src/pro/res/layout/torrent_details.xml | 5 +- .../pro/res/layout/torrent_details_old.xml | 3 +- 31 files changed, 519 insertions(+), 1375 deletions(-) rename qBittorrentClient/app/src/{free => main}/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java (87%) delete mode 100644 qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java diff --git a/qBittorrentClient/app/build.gradle b/qBittorrentClient/app/build.gradle index ae1a5d00..20c9ff0f 100644 --- a/qBittorrentClient/app/build.gradle +++ b/qBittorrentClient/app/build.gradle @@ -22,18 +22,18 @@ android { productFlavors { pro { applicationId 'com.lgallardo.qbittorrentclientpro' - versionName '4.0.0' + versionName '4.1.0' minSdkVersion 14 targetSdkVersion 21 - versionCode 400 + versionCode 410 archivesBaseName = "qBittorrentClient_v" + versionName } free { applicationId "com.lgallardo.qbittorrentclient" - versionName '4.0.0' + versionName '4.1.0' minSdkVersion 14 targetSdkVersion 21 - versionCode 400 + versionCode 410 archivesBaseName = "qBittorrentClient_v" + versionName } } diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java index 9fb5900a..654b3691 100644 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/MainActivity.java @@ -444,6 +444,13 @@ public void onDrawerOpened(View drawerView) { } + // Search bar in Material Design + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + mSearchAction = menu.findItem(R.id.action_search); + return super.onPrepareOptionsMenu(menu); + } + // Set selection and title on drawer public void setSelectionAndTitle(String state) { // Set selection according to last state @@ -495,7 +502,6 @@ public void onDestroy() { super.onDestroy(); } - @Override public void onResume() { super.onResume(); @@ -507,9 +513,9 @@ public void onResume() { FragmentManager fm = getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); - if (fm.getBackStackEntryCount() == 0 && fm.findFragmentById(R.id.one_frame) instanceof ItemstFragment) { + if (fm.getBackStackEntryCount() == 0 && fm.findFragmentById(R.id.one_frame) instanceof com.lgallardo.qbittorrentclient.ItemstFragment) { - ItemstFragment fragment = (ItemstFragment) fm.findFragmentById(R.id.one_frame); + com.lgallardo.qbittorrentclient.ItemstFragment fragment = (com.lgallardo.qbittorrentclient.ItemstFragment) fm.findFragmentById(R.id.one_frame); if (fragment.getListView().getCount() == 0) { @@ -533,17 +539,19 @@ public void onResume() { } } - } catch (Exception e) { + } + catch (Exception e) { } } -// @Override -// public void onPause() { -// super.onPause(); -// activityIsVisible = false; -// } + @Override + public void onPause() { + super.onPause(); + activityIsVisible = false; + } + // TODO: Unify free & pro // Load Banner public void loadBanner() { @@ -653,6 +661,11 @@ public void onBackPressed() { } if (findViewById(R.id.one_frame) != null) { + + getSupportActionBar().setDisplayShowTitleEnabled(true); + MainActivity.drawerToggle.setDrawerIndicatorEnabled(true); + MainActivity.drawerToggle.setToolbarNavigationClickListener(ItemstFragment.originalListener); + if (headerInfo != null) { if (header) { headerInfo.setVisibility(View.VISIBLE); @@ -760,6 +773,19 @@ private void handleIntent(Intent intent) { refreshCurrent(); } + + try { + if (intent.getStringExtra("from").equals("NotifierService")) { + + drawerList.setItemChecked(2, true); + setTitle(navigationDrawerItemTitles[2]); + refresh("completed"); + + } + } + catch (NullPointerException npe) { + + } } private void addTorrentByIntent(Intent intent) { @@ -810,7 +836,6 @@ public boolean onCreateOptionsMenu(Menu menu) { // return true; - getMenuInflater().inflate(R.menu.main, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); @@ -1743,14 +1768,25 @@ protected void getSettings() { // Get connection and data timeouts try { connection_timeout = Integer.parseInt(sharedPrefs.getString("connection_timeout", "10")); + + // New default value to make it work with qBittorrent 3.2.x + if(connection_timeout < 10){ + connection_timeout = 10; + } } catch (NumberFormatException e) { - connection_timeout = 20; + connection_timeout = 10; } try { - data_timeout = Integer.parseInt(sharedPrefs.getString("data_timeout", "8")); + data_timeout = Integer.parseInt(sharedPrefs.getString("data_timeout", "20")); + + // New default value to make it work with qBittorrent 3.2.x + if(data_timeout< 20){ + data_timeout = 20; + } + } catch (NumberFormatException e) { - data_timeout = 8; + data_timeout = 20; } sortby = sharedPrefs.getString("sortby", "NULL"); @@ -1785,8 +1821,6 @@ protected void getSettings() { // Get package name packageName = pInfo.packageName; - Log.d("Debug", "Package name:" + packageName); - } // Get Options @@ -1942,6 +1976,11 @@ private void selectItem(int position) { openSettings(); break; case 8: + // TODO: Unify free & pro + // Get Pro version + getPRO(); + break; + case 9: openHelp(); break; default: @@ -1963,33 +2002,69 @@ private void selectItem(int position) { @Override public void swipeRefresh() { - // Set the refresh layout (refresh icon, etc) - refreshSwipeLayout(); - // Actually refresh data - refreshCurrent(); - } + if (hostname.equals("")) { + genericOkDialog(R.string.info, R.string.about_help1); + disableRefreshSwipeLayout(); - public void refreshSwipeLayout() { + } else { + + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); + // Actually refresh data + refreshCurrent(); - listViewRefreshing = true; + } + + } + public void disableRefreshSwipeLayout(){ - if (AboutFragment.mSwipeRefreshLayout != null) { - AboutFragment.mSwipeRefreshLayout.setRefreshing(true); + if (com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.setRefreshing(false); + com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.clearAnimation(); + com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.setEnabled(true); } if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { - com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(true); - com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(false); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(false); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.clearAnimation(); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(true); } if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { - com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(true); + com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(false); + com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.clearAnimation(); + com.lgallardo.qbittorrentclient.TorrentDetailsFragment .mSwipeRefreshLayout.setEnabled(true); + } + + listViewRefreshing = false; + } + + + public void refreshSwipeLayout() { + + if (!hostname.equals("")) { + + listViewRefreshing = true; + + if (AboutFragment.mSwipeRefreshLayout != null) { + AboutFragment.mSwipeRefreshLayout.setRefreshing(true); + } + + if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(true); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(false); + } + + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(true); + } } } + // Here is where the action happens private class qBittorrentCookie extends AsyncTask { @Override @@ -1998,7 +2073,6 @@ protected String[] doInBackground(Void... params) { // Get values from preferences getSettings(); - // Creating new JSON Parser com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); @@ -2006,11 +2080,9 @@ protected String[] doInBackground(Void... params) { String api = ""; try { - cookie = jParser.getNewCookie(); } catch (JSONParserStatusCodeException e) { - httpStatusCode = e.getCode(); } @@ -2069,7 +2141,6 @@ protected String doInBackground(String... params) { } catch (JSONParserStatusCodeException e) { httpStatusCode = e.getCode(); - Log.e("JSONParserStatusCode", e.toString()); } @@ -2369,8 +2440,8 @@ protected void onPostExecute(Torrent[] result) { if (qb_version.equals("3.2.x")) { torrentsFiltered = new ArrayList(Arrays.asList(result)); - } else { + } else { torrentsFiltered = new ArrayList(); @@ -2607,7 +2678,6 @@ protected void onPostExecute(Torrent[] result) { else { // No results -// myadapter = null; myadapter.setNames(null); myadapter.setData(null); @@ -2672,26 +2742,8 @@ protected void onPostExecute(Torrent[] result) { } - if (com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout != null) { - com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.setRefreshing(false); - com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.clearAnimation(); - com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.setEnabled(true); - } - - if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { - com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(false); - com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.clearAnimation(); - com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(true); - } - - if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { - com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(false); - com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.clearAnimation(); - com.lgallardo.qbittorrentclient.TorrentDetailsFragment .mSwipeRefreshLayout.setEnabled(true); - } - - listViewRefreshing = false; - + // Disable refreshSwipeLayout + disableRefreshSwipeLayout(); } } diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/SettingsActivity.java b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/SettingsActivity.java index 2bd305c7..b6963992 100644 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/SettingsActivity.java +++ b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/SettingsActivity.java @@ -34,7 +34,6 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer private EditTextPreference port; private EditTextPreference username; private EditTextPreference password; - private CheckBoxPreference old_version; private String currentServerValue; private CheckBoxPreference auto_refresh; @@ -55,6 +54,10 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer @Override protected void onCreate(Bundle savedInstanceState) { + + // Set Theme + this.setTheme(R.style.Theme_Light); + super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); @@ -67,7 +70,6 @@ protected void onCreate(Bundle savedInstanceState) { port = (EditTextPreference) findPreference("port"); username = (EditTextPreference) findPreference("username"); password = (EditTextPreference) findPreference("password"); -// old_version = (CheckBoxPreference) findPreference("old_version"); auto_refresh = (CheckBoxPreference) findPreference("auto_refresh"); refresh_period = (ListPreference) findPreference("refresh_period"); connection_timeout = (EditTextPreference) findPreference("connection_timeout"); diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentListAdapter.java b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentListAdapter.java index de9c94a6..f639d37a 100644 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentListAdapter.java +++ b/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentListAdapter.java @@ -14,12 +14,11 @@ class TorrentListAdapter extends ArrayAdapter { + private static HashMap mSelection = new HashMap(); private String[] torrentsNames; private Torrent[] torrentsData; private Context context; - private static HashMap mSelection = new HashMap(); - public TorrentListAdapter(Context context, String[] torrentsNames, Torrent[] torrentsData) { super(context, R.layout.row, R.id.file, torrentsNames); @@ -54,7 +53,6 @@ public View getView(int position, View convertView, ViewGroup parent) { TextView name = (TextView) row.findViewById(R.id.file); name.setText(file); - TextView info = (TextView) row.findViewById(R.id.info); info.setText("" + torrentsData[position].getInfo()); @@ -153,14 +151,14 @@ public void setNames(String[] names) { this.torrentsNames = names; } - public void setData(Torrent[] data) { - this.torrentsData = data; - } - public Torrent[] getData() { return this.torrentsData; } + public void setData(Torrent[] data) { + this.torrentsData = data; + } + @Override public boolean isEnabled(int position) { if (areAllItemsEnabled()) { @@ -172,7 +170,7 @@ public boolean isEnabled(int position) { @Override public boolean areAllItemsEnabled() { - if (torrentsData != null) { + if (torrentsData != null && !com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.isRefreshing()) { return true; } else { return false; diff --git a/qBittorrentClient/app/src/free/res/layout-large/row.xml b/qBittorrentClient/app/src/free/res/layout-large/row.xml index 4da94a0a..faa76674 100644 --- a/qBittorrentClient/app/src/free/res/layout-large/row.xml +++ b/qBittorrentClient/app/src/free/res/layout-large/row.xml @@ -1,4 +1,5 @@ - + + diff --git a/qBittorrentClient/app/src/free/res/layout-large/torrent_details_old.xml b/qBittorrentClient/app/src/free/res/layout-large/torrent_details_old.xml index 8d007091..4c9087f0 100644 --- a/qBittorrentClient/app/src/free/res/layout-large/torrent_details_old.xml +++ b/qBittorrentClient/app/src/free/res/layout-large/torrent_details_old.xml @@ -413,6 +413,14 @@ + + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/free/res/layout-sw600dp/row.xml b/qBittorrentClient/app/src/free/res/layout-sw600dp/row.xml index 116a259b..c509e269 100644 --- a/qBittorrentClient/app/src/free/res/layout-sw600dp/row.xml +++ b/qBittorrentClient/app/src/free/res/layout-sw600dp/row.xml @@ -17,8 +17,9 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" - android:paddingLeft="10dp" - android:paddingRight="10dp"> + android:paddingRight="10dp" + android:paddingTop="10dp" + android:background="?backgroundSelector" > @@ -45,12 +46,18 @@ android:textSize="15sp" android:textStyle="bold" /> - + android:orientation="horizontal"> + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details.xml b/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details.xml index 60e963b4..bbbee313 100644 --- a/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details.xml +++ b/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details.xml @@ -457,6 +457,14 @@ + + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details_old.xml b/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details_old.xml index 38d49f5e..9f7b109f 100644 --- a/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details_old.xml +++ b/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details_old.xml @@ -412,6 +412,14 @@ + + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/free/res/layout/row.xml b/qBittorrentClient/app/src/free/res/layout/row.xml index 996ea7cc..9b0c3d6f 100644 --- a/qBittorrentClient/app/src/free/res/layout/row.xml +++ b/qBittorrentClient/app/src/free/res/layout/row.xml @@ -1,4 +1,5 @@ - + android:orientation="horizontal" > + android:paddingTop="5dp" + android:paddingBottom="5dp" + android:background="?backgroundSelector"> + android:orientation="vertical" > - + android:orientation="horizontal" > + + + diff --git a/qBittorrentClient/app/src/free/res/layout/torrent_details.xml b/qBittorrentClient/app/src/free/res/layout/torrent_details.xml index 3caae98c..cd19d62b 100644 --- a/qBittorrentClient/app/src/free/res/layout/torrent_details.xml +++ b/qBittorrentClient/app/src/free/res/layout/torrent_details.xml @@ -464,6 +464,13 @@ + + + diff --git a/qBittorrentClient/app/src/free/res/layout/torrent_details_old.xml b/qBittorrentClient/app/src/free/res/layout/torrent_details_old.xml index a9d0e5d9..426a7a42 100644 --- a/qBittorrentClient/app/src/free/res/layout/torrent_details_old.xml +++ b/qBittorrentClient/app/src/free/res/layout/torrent_details_old.xml @@ -419,7 +419,12 @@ - + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/AboutFragment.java b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/AboutFragment.java index 441b162f..4fd9680a 100644 --- a/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/AboutFragment.java +++ b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/AboutFragment.java @@ -56,7 +56,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa mSwipeRefreshLayout.setColorSchemeColors(R.color.primary, R.color.primary_dark, R.color.primary_text); - mSwipeRefreshLayout.setRefreshing(true); + if(!MainActivity.hostname.equals("")) { + mSwipeRefreshLayout.setRefreshing(true); + } isFragmentFirstLoaded = false; } diff --git a/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/ItemstFragment.java b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/ItemstFragment.java index e9200843..bc1c4e77 100644 --- a/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/ItemstFragment.java +++ b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/ItemstFragment.java @@ -36,7 +36,7 @@ public class ItemstFragment extends ListFragment { TorrentDetailsFragment detailsFragment; private RecyclerView recyclerView; private RefreshListener refreshListener; - private View.OnClickListener originalListener; + public static View.OnClickListener originalListener; public static SwipeRefreshLayout mSwipeRefreshLayout; @@ -117,6 +117,7 @@ public void onItemCheckedStateChanged(ActionMode mode, int position, long id, bo // Set title with number of items selected mode.setTitle("" + nr); + } @Override diff --git a/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java index 838133d5..c7d933ff 100644 --- a/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java +++ b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/JSONParser.java @@ -102,7 +102,7 @@ public void setCookie(String cookie) { public JSONObject getJSONFromUrl(String url) throws JSONParserStatusCodeException { // if server is publish in a subfolder, fix url - if (subfolder != null && subfolder != "") { + if (subfolder != null && !subfolder.equals("")) { url = subfolder + "/" + url; } @@ -150,7 +150,6 @@ public JSONObject getJSONFromUrl(String url) throws JSONParserStatusCodeExceptio HttpGet httpget = new HttpGet(url); if (this.cookie != null) { - httpget.setHeader("Cookie", this.cookie); } @@ -213,7 +212,7 @@ public JSONObject getJSONFromUrl(String url) throws JSONParserStatusCodeExceptio public JSONArray getJSONArrayFromUrl(String url) throws JSONParserStatusCodeException { // if server is published in a subfolder, fix url - if (subfolder != null && subfolder != "") { + if (subfolder != null && !subfolder.equals("")) { url = subfolder + "/" + url; } @@ -259,7 +258,6 @@ public JSONArray getJSONArrayFromUrl(String url) throws JSONParserStatusCodeExce httpget.setHeader("Cookie", this.cookie); } - httpResponse = httpclient.execute(targetHost, httpget); StatusLine statusLine = httpResponse.getStatusLine(); @@ -442,7 +440,7 @@ public void postCommand(String command, String hash) throws JSONParserStatusCode // if server is publish in a subfolder, fix url - if (subfolder != null && subfolder != "") { + if (subfolder != null && !subfolder.equals("")) { url = subfolder + "/" + url; } @@ -609,11 +607,8 @@ public DefaultHttpClient getNewHttpClient() { ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); - Log.e("Debug", "JSON - getNewHttpClient NO error"); - return new DefaultHttpClient(ccm, params); } catch (Exception e) { - Log.e("Debug", "JSON - getNewHttpClient error"); return new DefaultHttpClient(); } } @@ -625,7 +620,7 @@ public String getNewCookie() throws JSONParserStatusCodeException { String url = "login"; // if server is publish in a subfolder, fix url - if (subfolder != null && subfolder != "") { + if (subfolder != null && !subfolder.equals("")) { url = subfolder + "/" + url; } @@ -647,7 +642,7 @@ public String getNewCookie() throws JSONParserStatusCodeException { // Set http parameters HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); - HttpProtocolParams.setUserAgent(httpParameters,"qBittorrent for Android"); + HttpProtocolParams.setUserAgent(httpParameters, "qBittorrent for Android"); HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(httpParameters, HTTP.UTF_8); @@ -665,7 +660,9 @@ public String getNewCookie() throws JSONParserStatusCodeException { // // httpclient.getCredentialsProvider().setCredentials(authScope, credentials); - url = protocol + "://" + hostname + ":" + port +"/" +url; + + + url = protocol + "://" + hostname + ":" + port + "/" +url; HttpPost httpget = new HttpPost(url); @@ -681,9 +678,7 @@ public String getNewCookie() throws JSONParserStatusCodeException { HttpResponse response = httpclient.execute(targetHost, httpget); - HttpEntity entity = response.getEntity(); - -// Log.i("Cookies", "Login form get: " + response.getStatusLine()); + HttpEntity entity = response.getEntity( ); StatusLine statusLine = response.getStatusLine(); @@ -692,25 +687,11 @@ public String getNewCookie() throws JSONParserStatusCodeException { if (mStatusCode == 200) { // Save cookie - - -// Log.i("Cookies", "Initial set of cookies"); - List cookies = httpclient.getCookieStore().getCookies(); - if (cookies.isEmpty()) { -// Log.i("Cookies", "None"); - - } else { - - -// Log.i("Cookies", "Cookie=>" + cookies.get(0).toString()); - // Save cookie + if (!cookies.isEmpty()) { cookieString = cookies.get(0).getName() + "=" + cookies.get(0).getValue() + "; domain=" + cookies.get(0).getDomain(); - cookieString = cookies.get(0).getName() + "=" + cookies.get(0).getValue(); - - } } @@ -727,7 +708,7 @@ public String getNewCookie() throws JSONParserStatusCodeException { } catch (Exception e) { -// Log.i("Cookies", "Exception " + e.toString()); + Log.e("Debug", "Exception " + e.toString()); } if (cookieString == null) { @@ -744,7 +725,7 @@ public String getApiVersion() throws JSONParserStatusCodeException { String url = "/version/api"; // if server is publish in a subfolder, fix url - if (subfolder != null && subfolder != "") { + if (subfolder != null && !subfolder.equals("")) { url = subfolder + "/" + url; } @@ -785,8 +766,6 @@ public String getApiVersion() throws JSONParserStatusCodeException { HttpResponse response = httpclient.execute(targetHost, httpget); HttpEntity entity = response.getEntity(); -// Log.i("APIVer", "API Ver Status: " + response.getStatusLine()); - StatusLine statusLine = response.getStatusLine(); int mStatusCode = statusLine.getStatusCode(); diff --git a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java similarity index 87% rename from qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java rename to qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java index 15ab894e..246078b7 100644 --- a/qBittorrentClient/app/src/free/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java +++ b/qBittorrentClient/app/src/main/java/com/lgallardo/qbittorrentclient/TorrentDetailsFragment.java @@ -76,7 +76,7 @@ public class TorrentDetailsFragment extends Fragment { private String qbQueryString = "query"; private Torrent torrent; public static SwipeRefreshLayout mSwipeRefreshLayout; - private com.lgallardo.qbittorrentclient.RefreshListener refreshListener; + private RefreshListener refreshListener; // AdView for ads private AdView adView; @@ -102,14 +102,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa View rootView; - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { + if (MainActivity.qb_version.equals("3.2.x")) { rootView = inflater.inflate(R.layout.torrent_details, container, false); } else { rootView = inflater.inflate(R.layout.torrent_details_old, container, false); } // Get Refresh Listener - refreshListener = (com.lgallardo.qbittorrentclient.RefreshListener) getActivity(); + refreshListener = (RefreshListener) getActivity(); mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.details_refresh_layout); if(mSwipeRefreshLayout != null) { @@ -123,8 +123,8 @@ public void onRefresh() { // Hide herderInfo and title in phone's view if (getActivity().findViewById(R.id.one_frame) != null) { - com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.GONE); - ((com.lgallardo.qbittorrentclient.MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false); + MainActivity.headerInfo.setVisibility(View.GONE); + ((MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false); } savePath = ""; @@ -160,7 +160,7 @@ public void onRefresh() { hashToUpdate = hash; // Only for Pro version - if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { + if(MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { int index = progress.indexOf("."); if (index == -1) { @@ -193,7 +193,7 @@ public void onRefresh() { hashToUpdate = hash; // Only for Pro version - if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { + if(MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { int index = this.torrent.getProgress().indexOf("."); if (index == -1) { @@ -234,7 +234,7 @@ public void onRefresh() { etaTextView.setText(eta); priorityTextView.setText(priority); - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { + if (MainActivity.qb_version.equals("3.2.x")) { sequentialDownloadCheckBox = (CheckBox) rootView.findViewById(R.id.torrentSequentialDownload); firstLAstPiecePrioCheckBox = (CheckBox) rootView.findViewById(R.id.torrentFirstLastPiecePrio); @@ -243,7 +243,7 @@ public void onRefresh() { } // Only for Pro version - if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { + if(MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); @@ -262,11 +262,6 @@ public void onRefresh() { uploadSpeedTextView.setText(uploadSpeed); } - sizeTextView.setText(size); - downloadSpeedTextView.setText(downloadSpeed); - uploadSpeedTextView.setText(uploadSpeed); - } - nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.error, 0, 0, 0); // Set status icon @@ -314,7 +309,7 @@ public void onRefresh() { Log.e("Debug", "TorrentDetailsFragment - onCreateView: " + e.toString()); } - if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclient")) { + if(MainActivity.packageName.equals("com.lgallardo.qbittorrentclient")) { // Load banner loadBanner(); } @@ -328,7 +323,7 @@ public void updateDetails(Torrent torrent) { // Hide herderInfo in phone's view if (getActivity().findViewById(R.id.one_frame) != null) { - com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.GONE); + MainActivity.headerInfo.setVisibility(View.GONE); } // Get values from current activity @@ -372,7 +367,7 @@ public void updateDetails(Torrent torrent) { View rootView = detailsFragment.getView(); TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName); -// TextView sizeTextView = (TextView) rootView.findViewById(R.id.downloadedVsTotal); + TextView sizeTextView = (TextView) rootView.findViewById(R.id.downloadedVsTotal); TextView ratioTextView = (TextView) rootView.findViewById(R.id.torrentRatio); TextView priorityTextView = (TextView) rootView.findViewById(R.id.torrentPriority); TextView stateTextView = (TextView) rootView.findViewById(R.id.torrentState); @@ -398,7 +393,7 @@ public void updateDetails(Torrent torrent) { priorityTextView.setText(priority); etaTextView.setText(eta); - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { + if (MainActivity.qb_version.equals("3.2.x")) { sequentialDownloadCheckBox = (CheckBox) rootView.findViewById(R.id.torrentSequentialDownload); firstLAstPiecePrioCheckBox = (CheckBox) rootView.findViewById(R.id.torrentFirstLastPiecePrio); @@ -407,7 +402,7 @@ public void updateDetails(Torrent torrent) { } // Only for Pro version - if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { + if(MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); @@ -538,7 +533,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.findItem(R.id.action_search).setVisible(true); } - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { + if (MainActivity.qb_version.equals("3.2.x")) { menu.findItem(R.id.action_firts_last_piece_prio).setVisible(true); menu.findItem(R.id.action_sequential_download).setVisible(true); } @@ -554,7 +549,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void loadBanner() { // Get the adView. - adView = (AdView) getActivity().findViewById(com.lgallardo.qbittorrentclient.R.id.adView); + adView = (AdView) getActivity().findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); @@ -577,15 +572,15 @@ private class qBittorrentContentFile extends AsyncTask { protected View[] doInBackground(View... rootViews) { // Get torrent's files - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("2.x")) { + if (MainActivity.qb_version.equals("2.x")) { qbQueryString = "json"; } - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.1.x")) { + if (MainActivity.qb_version.equals("3.1.x")) { qbQueryString = "json"; } - if (com.lgallardo.qbittorrentclient. MainActivity.qb_version.equals("3.2.x")) { + if (MainActivity.qb_version.equals("3.2.x")) { qbQueryString = "query"; } @@ -597,10 +592,10 @@ protected View[] doInBackground(View... rootViews) { try { - com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(com.lgallardo.qbittorrentclient.MainActivity.hostname, com.lgallardo.qbittorrentclient.MainActivity.subfolder, com.lgallardo.qbittorrentclient.MainActivity.protocol, com.lgallardo.qbittorrentclient.MainActivity.port, - com.lgallardo.qbittorrentclient.MainActivity.username, com.lgallardo.qbittorrentclient.MainActivity.password, com.lgallardo.qbittorrentclient.MainActivity.connection_timeout, com.lgallardo.qbittorrentclient.MainActivity.data_timeout); + JSONParser jParser = new JSONParser(MainActivity.hostname, MainActivity.subfolder, MainActivity.protocol, MainActivity.port, + MainActivity.username, MainActivity.password, MainActivity.connection_timeout, MainActivity.data_timeout); - jParser.setCookie(com.lgallardo.qbittorrentclient.MainActivity.cookie); + jParser.setCookie(MainActivity.cookie); JSONArray jArray = jParser.getJSONArrayFromUrl(url + hash); @@ -613,13 +608,13 @@ protected View[] doInBackground(View... rootViews) { JSONObject json = jArray.getJSONObject(i); - name = json.getString(com.lgallardo.qbittorrentclient.MainActivity.TAG_NAME); - size = json.getString(com.lgallardo.qbittorrentclient.MainActivity.TAG_SIZE).replace(",", "."); - progress = json.getDouble(com.lgallardo.qbittorrentclient.MainActivity.TAG_PROGRESS); - priority = json.getInt(com.lgallardo.qbittorrentclient.MainActivity.TAG_PRIORITY); + 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); - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { - size = Common.calculateSize(json.getString(com.lgallardo.qbittorrentclient.MainActivity.TAG_SIZE)).replace(",", "."); + if (MainActivity.qb_version.equals("3.2.x")) { + size = Common.calculateSize(json.getString(MainActivity.TAG_SIZE)).replace(",", "."); } files[i] = new ContentFile(name, size, progress, priority); @@ -672,15 +667,15 @@ private class qBittorrentTrackers extends AsyncTask { protected View[] doInBackground(View... rootViews) { // Get torrent's trackers - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("2.x")) { + if (MainActivity.qb_version.equals("2.x")) { qbQueryString = "json"; } - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.1.x")) { + if (MainActivity.qb_version.equals("3.1.x")) { qbQueryString = "json"; } - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { + if (MainActivity.qb_version.equals("3.2.x")) { qbQueryString = "query"; } @@ -691,10 +686,10 @@ protected View[] doInBackground(View... rootViews) { try { - com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(com.lgallardo.qbittorrentclient.MainActivity.hostname, com.lgallardo.qbittorrentclient.MainActivity.subfolder, com.lgallardo.qbittorrentclient.MainActivity.protocol, com.lgallardo.qbittorrentclient.MainActivity.port, - com.lgallardo.qbittorrentclient.MainActivity.username, com.lgallardo.qbittorrentclient.MainActivity.password, com.lgallardo.qbittorrentclient.MainActivity.connection_timeout, com.lgallardo.qbittorrentclient.MainActivity.data_timeout); + JSONParser jParser = new JSONParser(MainActivity.hostname, MainActivity.subfolder, MainActivity.protocol, MainActivity.port, + MainActivity.username, MainActivity.password, MainActivity.connection_timeout, MainActivity.data_timeout); - jParser.setCookie(com.lgallardo.qbittorrentclient.MainActivity.cookie); + jParser.setCookie(MainActivity.cookie); JSONArray jArray = jParser.getJSONArrayFromUrl(url + hash); @@ -707,7 +702,7 @@ protected View[] doInBackground(View... rootViews) { JSONObject json = jArray.getJSONObject(i); - url = json.getString(com.lgallardo.qbittorrentclient.MainActivity.TAG_URL); + url = json.getString(MainActivity.TAG_URL); trackers[i] = new Tracker(url); trackerNames[i] = url; @@ -760,15 +755,15 @@ private class qBittorrentGeneralInfoTask extends AsyncTask { protected View[] doInBackground(View... rootViews) { // Get torrent's extra info - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("2.x")) { + if (MainActivity.qb_version.equals("2.x")) { qbQueryString = "json"; } - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.1.x")) { + if (MainActivity.qb_version.equals("3.1.x")) { qbQueryString = "json"; } - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { + if (MainActivity.qb_version.equals("3.2.x")) { qbQueryString = "query"; } @@ -776,10 +771,10 @@ protected View[] doInBackground(View... rootViews) { try { - com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(com.lgallardo.qbittorrentclient.MainActivity.hostname, com.lgallardo.qbittorrentclient.MainActivity.subfolder, com.lgallardo.qbittorrentclient.MainActivity.protocol, com.lgallardo.qbittorrentclient.MainActivity.port, - com.lgallardo.qbittorrentclient.MainActivity.username, com.lgallardo.qbittorrentclient.MainActivity.password, com.lgallardo.qbittorrentclient.MainActivity.connection_timeout, com.lgallardo.qbittorrentclient.MainActivity.data_timeout); + JSONParser jParser = new JSONParser(MainActivity.hostname, MainActivity.subfolder, MainActivity.protocol, MainActivity.port, + MainActivity.username, MainActivity.password, MainActivity.connection_timeout, MainActivity.data_timeout); - jParser.setCookie(com.lgallardo.qbittorrentclient.MainActivity.cookie); + jParser.setCookie(MainActivity.cookie); json2 = jParser.getJSONFromUrl(url + hash); @@ -833,7 +828,7 @@ protected View[] doInBackground(View... rootViews) { values[10] = json2.getString(TAG_DOWNLOAD_LIMIT); - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { + if (MainActivity.qb_version.equals("3.2.x")) { // Creation date values[1] = Common.unixTimestampToDate(json2.getString(TAG_CREATION_DATE)); diff --git a/qBittorrentClient/app/src/main/res/menu/main_contextual_action_bar.xml b/qBittorrentClient/app/src/main/res/menu/main_contextual_action_bar.xml index e0a2fa31..8b71345c 100644 --- a/qBittorrentClient/app/src/main/res/menu/main_contextual_action_bar.xml +++ b/qBittorrentClient/app/src/main/res/menu/main_contextual_action_bar.xml @@ -1,75 +1,75 @@ - + \ No newline at end of file diff --git a/qBittorrentClient/app/src/main/res/values/colors_dark.xml b/qBittorrentClient/app/src/main/res/values/colors_dark.xml index 73de1080..94fd1ce6 100644 --- a/qBittorrentClient/app/src/main/res/values/colors_dark.xml +++ b/qBittorrentClient/app/src/main/res/values/colors_dark.xml @@ -4,7 +4,7 @@ #455A64 #CFD8DC #9E9E9E - #212121 + #CFD8DC #727272 #FFFFFF #B6B6B6 diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java index 96bedab8..f22e8214 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/MainActivity.java @@ -1,13 +1,15 @@ -/******************************************************************************* +/** + * **************************************************************************** * Copyright (c) 2014 Luis M. Gallardo D.. * All rights reserved. This program and the accompanying materials * 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. - ******************************************************************************/ + * Luis M. Gallardo D. + * **************************************************************************** + */ package com.lgallardo.qbittorrentclient; import android.app.AlarmManager; @@ -449,7 +451,6 @@ public boolean onPrepareOptionsMenu(Menu menu) { return super.onPrepareOptionsMenu(menu); } - // Set selection and title on drawer public void setSelectionAndTitle(String state) { // Set selection according to last state @@ -538,17 +539,28 @@ public void onResume() { } } - - } catch (Exception e) { + } + catch (Exception e) { } + } + @Override + public void onPause() { + super.onPause(); + activityIsVisible = false; } -// @Override -// public void onPause() { -// super.onPause(); -// activityIsVisible = false; + // TODO: Unify free & pro +// // Load Banner +// public void loadBanner() { +// +// // Look up the AdView as a resource and load a request. +// adView = (AdView) this.findViewById(R.id.adView); +// AdRequest adRequest = new AdRequest.Builder().build(); +// +// // Start loading the ad in the background. +// adView.loadAd(adRequest); // } @Override @@ -649,6 +661,11 @@ public void onBackPressed() { } if (findViewById(R.id.one_frame) != null) { + + getSupportActionBar().setDisplayShowTitleEnabled(true); + MainActivity.drawerToggle.setDrawerIndicatorEnabled(true); + MainActivity.drawerToggle.setToolbarNavigationClickListener(ItemstFragment.originalListener); + if (headerInfo != null) { if (header) { headerInfo.setVisibility(View.VISIBLE); @@ -706,7 +723,7 @@ private void refresh(String state) { genericOkDialog(R.string.info, R.string.about_help1); } else { - // Execute the task in background + // Execute the task in background qBittorrentTask qtt = new qBittorrentTask(); qtt.execute(params); @@ -765,10 +782,10 @@ private void handleIntent(Intent intent) { refresh("completed"); } - } catch (NullPointerException npe) { - } + catch (NullPointerException npe) { + } } private void addTorrentByIntent(Intent intent) { @@ -819,7 +836,6 @@ public boolean onCreateOptionsMenu(Menu menu) { // return true; - getMenuInflater().inflate(R.menu.main, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); @@ -834,7 +850,7 @@ public boolean onCreateOptionsMenu(Menu menu) { return true; } - public void popBackStackPhoneView(){ + public void popBackStackPhoneView() { getFragmentManager().popBackStack(); headerInfo.setVisibility(View.VISIBLE); } @@ -1205,10 +1221,10 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } - if (requestCode == GETPRO_CODE) { - // Now it can be refreshed - canrefresh = true; - } +// if (requestCode == GETPRO_CODE) { +// // Now it can be refreshed +// canrefresh = true; +// } if (requestCode == HELP_CODE) { // Now it can be refreshed @@ -1405,7 +1421,7 @@ public void pauseAllTorrents() { if (qb_version.equals("3.2.x")) { qtc.execute(new String[]{"pauseAll", null}); } - else{ + else { qtc.execute(new String[]{"pauseall", null}); } } @@ -1416,7 +1432,7 @@ public void resumeAllTorrents() { if (qb_version.equals("3.2.x")) { qtc.execute(new String[]{"resumeAll", null}); - }else{ + } else { qtc.execute(new String[]{"resumeall", null}); } } @@ -1752,14 +1768,25 @@ protected void getSettings() { // Get connection and data timeouts try { connection_timeout = Integer.parseInt(sharedPrefs.getString("connection_timeout", "10")); + + // New default value to make it work with qBittorrent 3.2.x + if (connection_timeout < 10) { + connection_timeout = 10; + } } catch (NumberFormatException e) { - connection_timeout = 20; + connection_timeout = 10; } try { - data_timeout = Integer.parseInt(sharedPrefs.getString("data_timeout", "8")); + data_timeout = Integer.parseInt(sharedPrefs.getString("data_timeout", "20")); + + // New default value to make it work with qBittorrent 3.2.x + if (data_timeout < 20) { + data_timeout = 20; + } + } catch (NumberFormatException e) { - data_timeout = 8; + data_timeout = 20; } sortby = sharedPrefs.getString("sortby", "NULL"); @@ -1794,8 +1821,6 @@ protected void getSettings() { // Get package name packageName = pInfo.packageName; - Log.d("Debug", "Package name:" + packageName); - } // Get Options @@ -1972,29 +1997,64 @@ private void selectItem(int position) { @Override public void swipeRefresh() { - // Set the refresh layout (refresh icon, etc) - refreshSwipeLayout(); - // Actually refresh data - refreshCurrent(); - } + if (hostname.equals("")) { + genericOkDialog(R.string.info, R.string.about_help1); + disableRefreshSwipeLayout(); - public void refreshSwipeLayout() { + } else { + + // Set the refresh layout (refresh icon, etc) + refreshSwipeLayout(); + // Actually refresh data + refreshCurrent(); + + } - listViewRefreshing = true; + } + public void disableRefreshSwipeLayout(){ - if (AboutFragment.mSwipeRefreshLayout != null) { - AboutFragment.mSwipeRefreshLayout.setRefreshing(true); + if (com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.setRefreshing(false); + com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.clearAnimation(); + com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.setEnabled(true); } if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { - com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(true); - com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(false); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(false); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.clearAnimation(); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(true); } if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { - com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(true); + com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(false); + com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.clearAnimation(); + com.lgallardo.qbittorrentclient.TorrentDetailsFragment .mSwipeRefreshLayout.setEnabled(true); + } + + listViewRefreshing = false; + } + + + public void refreshSwipeLayout() { + + if (!hostname.equals("")) { + + listViewRefreshing = true; + + if (AboutFragment.mSwipeRefreshLayout != null) { + AboutFragment.mSwipeRefreshLayout.setRefreshing(true); + } + + if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(true); + com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(false); + } + + if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { + com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(true); + } } } @@ -2008,23 +2068,21 @@ protected String[] doInBackground(Void... params) { // Get values from preferences getSettings(); - // Creating new JSON Parser com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(hostname, subfolder, protocol, port, username, password, connection_timeout, data_timeout); - String cookie = ""; + String newCookie = ""; String api = ""; try { - cookie = jParser.getNewCookie(); + newCookie = jParser.getNewCookie(); - } - catch (JSONParserStatusCodeException e) { + } catch (JSONParserStatusCodeException e) { httpStatusCode = e.getCode(); } - if (cookie == null) { - cookie = ""; + if (newCookie == null) { + newCookie = ""; } @@ -2033,7 +2091,7 @@ protected String[] doInBackground(Void... params) { } - return new String[]{cookie, api}; + return new String[]{newCookie, api}; } @@ -2078,7 +2136,6 @@ protected String doInBackground(String... params) { } catch (JSONParserStatusCodeException e) { httpStatusCode = e.getCode(); - Log.e("JSONParserStatusCode", e.toString()); } @@ -2103,7 +2160,7 @@ protected void onPostExecute(String result) { return; } - if (httpStatusCode == 403) { + if (httpStatusCode == 403 || httpStatusCode == 404) { if (qb_version.equals("3.2.x")) { @@ -2357,7 +2414,7 @@ protected void onPostExecute(Torrent[] result) { httpStatusCode = 0; } - if (httpStatusCode == 403) { + if (httpStatusCode == 403 || httpStatusCode == 404) { if (qb_version.equals("3.2.x")) { @@ -2538,13 +2595,11 @@ protected void onPostExecute(Torrent[] result) { headerInfo.setVisibility(View.GONE); } - Log.d("Debug", "uploadSpeedCount: " + uploadSpeedCount); - uploadSpeedTextView.setText(Character.toString('\u2191') + " " + Common.calculateSize("" + uploadSpeedCount) + "/s " + "(" + uploadCount + ")"); downloadSpeedTextView.setText(Character.toString('\u2193') + " " + Common.calculateSize("" + downloadSpeedCount) + "/s " + "(" + downloadCount + ")"); - //Set first and seco nd fragments + //Set first and second fragments if (findViewById(R.id.fragment_container) != null) { // Set where is the second container @@ -2618,7 +2673,6 @@ protected void onPostExecute(Torrent[] result) { else { // No results -// myadapter = null; myadapter.setNames(null); myadapter.setData(null); @@ -2676,7 +2730,6 @@ protected void onPostExecute(Torrent[] result) { } catch (Exception e) { Log.e("ADAPTER", e.toString()); -// e.printStackTrace(); } // Clear serch field @@ -2684,26 +2737,8 @@ protected void onPostExecute(Torrent[] result) { } - if (com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout != null) { - com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.setRefreshing(false); - com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.clearAnimation(); - com.lgallardo.qbittorrentclient.AboutFragment.mSwipeRefreshLayout.setEnabled(true); - } - - if (com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout != null) { - com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setRefreshing(false); - com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.clearAnimation(); - com.lgallardo.qbittorrentclient.ItemstFragment.mSwipeRefreshLayout.setEnabled(true); - } - - if (com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout != null) { - com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.setRefreshing(false); - com.lgallardo.qbittorrentclient.TorrentDetailsFragment.mSwipeRefreshLayout.clearAnimation(); - com.lgallardo.qbittorrentclient.TorrentDetailsFragment .mSwipeRefreshLayout.setEnabled(true); - } - - listViewRefreshing = false; - + // Disable refreshSwipeLayout + disableRefreshSwipeLayout(); } } @@ -2799,7 +2834,7 @@ protected void onPostExecute(String result) { httpStatusCode = 0; } - if (httpStatusCode == 403) { + if (httpStatusCode == 403 || httpStatusCode == 404) { Toast.makeText(getApplicationContext(), R.string.error403, Toast.LENGTH_SHORT).show(); httpStatusCode = 0; diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/SettingsActivity.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/SettingsActivity.java index 3e439f7e..023e11e4 100644 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/SettingsActivity.java +++ b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/SettingsActivity.java @@ -52,7 +52,6 @@ public class SettingsActivity extends PreferenceActivity implements android.cont @Override protected void onCreate(Bundle savedInstanceState) { - // Set Theme this.setTheme(R.style.Theme_Light); @@ -173,8 +172,8 @@ public void getQBittorrentServerValues(String value) { refresh_period.setSummary(refresh_period.getEntry()); - connection_timeout.setText(sharedPrefs.getString("connection_timeout" + value, "5")); - data_timeout.setText(sharedPrefs.getString("data_timeout" + value, "8")); + connection_timeout.setText(sharedPrefs.getString("connection_timeout" + value, "10")); + data_timeout.setText(sharedPrefs.getString("data_timeout" + value, "20")); if (sortBy.getEntry() == null) { sortBy.setValueIndex(1); diff --git a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java b/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java deleted file mode 100644 index 4f0664f8..00000000 --- a/qBittorrentClient/app/src/pro/java/com.lgallardo.qbittorrentclient/TorrentDetailsFragment.java +++ /dev/null @@ -1,1082 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Luis M. Gallardo D.. - * All rights reserved. This program and the accompanying materials - * 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. - ******************************************************************************/ -package com.lgallardo.qbittorrentclient; - -import android.app.Fragment; -import android.app.FragmentManager; -import android.content.Context; -import android.os.AsyncTask; -import android.os.Bundle; -import android.support.v4.widget.SwipeRefreshLayout; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.View; -import android.view.View.MeasureSpec; -import android.view.ViewGroup; -import android.view.ViewGroup.LayoutParams; -import android.widget.ArrayAdapter; -import android.widget.CheckBox; -import android.widget.LinearLayout; -import android.widget.ListAdapter; -import android.widget.ListView; -import android.widget.ProgressBar; -import android.widget.TextView; - -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 { - - // 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"; - - static ContentFile[] files; - static Tracker[] trackers; - static String[] names, trackerNames; - - // Torrent variables - String name, info, hash, ratio, size, state, leechs, seeds, progress, priority, savePath, creationDate, comment, totalWasted, totalUploaded, - totalDownloaded, timeElapsed, nbConnections, shareRatio, uploadRateLimit, downloadRateLimit, downloaded, eta, downloadSpeed, uploadSpeed, - percentage = ""; - - static String hashToUpdate; - - String url; - int position; - JSONObject json2; - - // Adapters - myFileAdapter fileAdpater; - myTrackerAdapter trackerAdapter; - myPropertyAdapter propertyAdapter; - - private String qbQueryString = "query"; - private Torrent torrent; - public static SwipeRefreshLayout mSwipeRefreshLayout; - private com.lgallardo.qbittorrentclient.RefreshListener refreshListener; - - // AdView for ads - private AdView adView; - - public TorrentDetailsFragment() { - } - - public void setPosition(int position) { - this.position = position; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - - @Override - 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; - - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { - rootView = inflater.inflate(R.layout.torrent_details, container, false); - } else { - rootView = inflater.inflate(R.layout.torrent_details_old, container, false); - } - - // Get Refresh Listener - refreshListener = (com.lgallardo.qbittorrentclient.RefreshListener) getActivity(); - mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.details_refresh_layout); - - if(mSwipeRefreshLayout != null) { - mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - refreshListener.swipeRefresh(); - } - }); - } - - // Hide herderInfo and title in phone's view - if (getActivity().findViewById(R.id.one_frame) != null) { - com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.GONE); - ((com.lgallardo.qbittorrentclient.MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(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", ""); - hashToUpdate = hash; - - // Only for Pro version - if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { - int index = progress.indexOf("."); - - if (index == -1) { - index = progress.indexOf(","); - - if (index == -1) { - index = progress.length(); - } - } - - percentage = progress.substring(0, index); - } - - } else { - - // Get values from current activity - name = this.torrent.getFile(); - size = this.torrent.getSize(); - hash = this.torrent.getHash(); - ratio = this.torrent.getRatio(); - state = this.torrent.getState(); - leechs = this.torrent.getLeechs(); - seeds = this.torrent.getSeeds(); - progress = this.torrent.getProgress(); - priority = this.torrent.getPriority(); - eta = this.torrent.getEta(); - uploadSpeed = this.torrent.getUploadSpeed(); - downloadSpeed = this.torrent.getDownloadSpeed(); - downloaded = this.torrent.getDownloaded(); - hashToUpdate = hash; - - // Only for Pro version - if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { - int index = this.torrent.getProgress().indexOf("."); - - if (index == -1) { - index = this.torrent.getProgress().indexOf(","); - - if (index == -1) { - index = this.torrent.getProgress().length(); - } - } - - percentage = this.torrent.getProgress().substring(0, index); - } - } - - 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 priorityTextView = (TextView) rootView.findViewById(R.id.torrentPriority); - 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 uploadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentUploadSpeed); - TextView downloadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentDownloadSpeed); - - CheckBox sequentialDownloadCheckBox; - CheckBox firstLAstPiecePrioCheckBox; - - nameTextView.setText(name); - ratioTextView.setText(ratio); - stateTextView.setText(state); - leechsTextView.setText(leechs); - seedsTextView.setText(seeds); - progressTextView.setText(progress); - hashTextView.setText(hash); - etaTextView.setText(eta); - priorityTextView.setText(priority); - - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { - sequentialDownloadCheckBox = (CheckBox) rootView.findViewById(R.id.torrentSequentialDownload); - firstLAstPiecePrioCheckBox = (CheckBox) rootView.findViewById(R.id.torrentFirstLastPiecePrio); - - sequentialDownloadCheckBox.setChecked(this.torrent.getSequentialDownload()); - firstLAstPiecePrioCheckBox.setChecked(this.torrent.getisFirstLastPiecePrio()); - } - - // Only for Pro version - if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { - downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); - uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); - - // Set Downloaded vs Total size - sizeTextView.setText(downloaded + " / " + size); - - // Set progress bar - ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1); - TextView percentageTV = (TextView) rootView.findViewById(R.id.percentage); - - progressBar.setProgress(Integer.parseInt(percentage)); - percentageTV.setText(percentage + "%"); - } else { - sizeTextView.setText(size); - downloadSpeedTextView.setText(downloadSpeed); - uploadSpeedTextView.setText(uploadSpeed); - } - - nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.error, 0, 0, 0); - - // Set status icon - 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); - } - - if ("checkingDL".equals(state) || "checkingUP".equals(state)) { - nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_recheck, 0, 0, 0); - } - - // 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) { - Log.e("Debug", "TorrentDetailsFragment - onCreateView: " + e.toString()); - } - - if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclient")) { - // Load banner - loadBanner(); - } - - return rootView; - } - - public void updateDetails(Torrent torrent) { - - try { - - // Hide herderInfo in phone's view - if (getActivity().findViewById(R.id.one_frame) != null) { - com.lgallardo.qbittorrentclient.MainActivity.headerInfo.setVisibility(View.GONE); - } - - // Get values from current activity - name = torrent.getFile(); - size = torrent.getSize(); - hash = torrent.getHash(); - ratio = torrent.getRatio(); - state = torrent.getState(); - leechs = torrent.getLeechs(); - seeds = torrent.getSeeds(); - progress = torrent.getProgress(); - priority = torrent.getPriority(); - eta = torrent.getEta(); - uploadSpeed = torrent.getUploadSpeed(); - downloadSpeed = torrent.getDownloadSpeed(); - downloaded = torrent.getDownloaded(); - - int index = torrent.getProgress().indexOf("."); - - if (index == -1) { - index = torrent.getProgress().indexOf(","); - - if (index == -1) { - index = torrent.getProgress().length(); - } - } - - percentage = torrent.getProgress().substring(0, index); - - - FragmentManager fragmentManager = getFragmentManager(); - - TorrentDetailsFragment detailsFragment = null; - - if (getActivity().findViewById(R.id.one_frame) != null) { - detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("firstFragment"); - } else{ - detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("secondFragment"); - } - - View rootView = detailsFragment.getView(); - - TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName); - TextView sizeTextView = (TextView) rootView.findViewById(R.id.downloadedVsTotal); - TextView ratioTextView = (TextView) rootView.findViewById(R.id.torrentRatio); - TextView priorityTextView = (TextView) rootView.findViewById(R.id.torrentPriority); - 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 progressTextView = (TextView) rootView.findViewById(R.id.torrentProgress); - TextView hashTextView = (TextView) rootView.findViewById(R.id.torrentHash); - - TextView etaTextView = (TextView) rootView.findViewById(R.id.eta); - TextView uploadSpeedTextView = (TextView) rootView.findViewById(R.id.uploadSpeed); - TextView downloadSpeedTextView = (TextView) rootView.findViewById(R.id.DownloadSpeed); - - CheckBox sequentialDownloadCheckBox; - CheckBox firstLAstPiecePrioCheckBox; - - nameTextView.setText(name); - ratioTextView.setText(ratio); - stateTextView.setText(state); - leechsTextView.setText(leechs); - seedsTextView.setText(seeds); - progressTextView.setText(progress); - hashTextView.setText(hash); - priorityTextView.setText(priority); - etaTextView.setText(eta); - - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { - sequentialDownloadCheckBox = (CheckBox) rootView.findViewById(R.id.torrentSequentialDownload); - firstLAstPiecePrioCheckBox = (CheckBox) rootView.findViewById(R.id.torrentFirstLastPiecePrio); - - sequentialDownloadCheckBox.setChecked(torrent.getSequentialDownload()); - firstLAstPiecePrioCheckBox.setChecked(torrent.getisFirstLastPiecePrio()); - } - - // Only for Pro version - if(com.lgallardo.qbittorrentclient.MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) { - downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed); - uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed); - - // Set Downloaded vs Total size - sizeTextView.setText(downloaded + " / " + size); - - }else { - downloadSpeedTextView.setText(downloadSpeed); - uploadSpeedTextView.setText(uploadSpeed); - } - - // Set progress bar - ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1); - TextView percentageTV = (TextView) rootView.findViewById(R.id.percentage); - - progressBar.setProgress(Integer.parseInt(percentage)); - percentageTV.setText(percentage + "%"); - - nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.error, 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); - } - - if ("checkingDL".equals(state) || "checkingUP".equals(state)) { - nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_recheck, 0, 0, 0); - } - - // 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) { - - Log.e("Debug", "TorrentDetailsFragment - onCreateView: " + e.toString()); - } - - } - - @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) { - - 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); - - if (getActivity().findViewById(R.id.one_frame) != null) { - menu.findItem(R.id.action_refresh).setVisible(false); - }else{ - menu.findItem(R.id.action_refresh).setVisible(true); - } - - if (getActivity().findViewById(R.id.one_frame) != null) { - menu.findItem(R.id.action_sort_menu).setVisible(false); - }else{ - menu.findItem(R.id.action_sort_menu).setVisible(true); - } - - menu.findItem(R.id.action_resume).setVisible(true); - menu.findItem(R.id.action_pause).setVisible(true); - menu.findItem(R.id.action_priority_menu).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_max_prio).setVisible(true); - menu.findItem(R.id.action_min_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); - menu.findItem(R.id.action_recheck).setVisible(true); - - if (getActivity().findViewById(R.id.one_frame) != null) { - menu.findItem(R.id.action_search).setVisible(false); - }else{ - menu.findItem(R.id.action_search).setVisible(true); - } - - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { - menu.findItem(R.id.action_firts_last_piece_prio).setVisible(true); - menu.findItem(R.id.action_sequential_download).setVisible(true); - } - else{ - menu.findItem(R.id.action_firts_last_piece_prio).setVisible(false); - menu.findItem(R.id.action_sequential_download).setVisible(false); - } - - } - } - - // Load Banner method - 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); - - } - - public void setTorrent(Torrent torrent) { - this.torrent = torrent; - } - - // // 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 files - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("2.x")) { - qbQueryString = "json"; - } - - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.1.x")) { - qbQueryString = "json"; - } - - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { - qbQueryString = "query"; - } - - - url = qbQueryString + "/propertiesFiles/"; - - files = null; - names = null; - - try { - - com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(com.lgallardo.qbittorrentclient.MainActivity.hostname, com.lgallardo.qbittorrentclient.MainActivity.subfolder, com.lgallardo.qbittorrentclient.MainActivity.protocol, com.lgallardo.qbittorrentclient.MainActivity.port, - com.lgallardo.qbittorrentclient.MainActivity.username, com.lgallardo.qbittorrentclient.MainActivity.password, com.lgallardo.qbittorrentclient.MainActivity.connection_timeout, com.lgallardo.qbittorrentclient.MainActivity.data_timeout); - - jParser.setCookie(com.lgallardo.qbittorrentclient.MainActivity.cookie); - - 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(com.lgallardo.qbittorrentclient.MainActivity.TAG_NAME); - size = json.getString(com.lgallardo.qbittorrentclient.MainActivity.TAG_SIZE).replace(",", "."); - progress = json.getDouble(com.lgallardo.qbittorrentclient.MainActivity.TAG_PROGRESS); - priority = json.getInt(com.lgallardo.qbittorrentclient.MainActivity.TAG_PRIORITY); - - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { - size = Common.calculateSize(json.getString(com.lgallardo.qbittorrentclient.MainActivity.TAG_SIZE)).replace(",", "."); - } - - 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.setFocusable(false); - - lv.setAdapter(fileAdpater); - - setListViewHeightBasedOnChildren(lv); - - } catch (Exception e) { - 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 trackers - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("2.x")) { - qbQueryString = "json"; - } - - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.1.x")) { - qbQueryString = "json"; - } - - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { - qbQueryString = "query"; - } - - url = qbQueryString + "/propertiesTrackers/"; - - trackers = null; - trackerNames = null; - - try { - - com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(com.lgallardo.qbittorrentclient.MainActivity.hostname, com.lgallardo.qbittorrentclient.MainActivity.subfolder, com.lgallardo.qbittorrentclient.MainActivity.protocol, com.lgallardo.qbittorrentclient.MainActivity.port, - com.lgallardo.qbittorrentclient.MainActivity.username, com.lgallardo.qbittorrentclient.MainActivity.password, com.lgallardo.qbittorrentclient.MainActivity.connection_timeout, com.lgallardo.qbittorrentclient.MainActivity.data_timeout); - - jParser.setCookie(com.lgallardo.qbittorrentclient.MainActivity.cookie); - - 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(com.lgallardo.qbittorrentclient.MainActivity.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); - layout.removeAllViews(); - - for (int i = 0; i < trackerAdapter.getCount(); i++) { - View item = trackerAdapter.getView(i, null, null); - layout.addView(item); - } - - } catch (Exception e) { - 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 - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("2.x")) { - qbQueryString = "json"; - } - - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.1.x")) { - qbQueryString = "json"; - } - - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { - qbQueryString = "query"; - } - - url = qbQueryString + "/propertiesGeneral/"; - - try { - - com.lgallardo.qbittorrentclient.JSONParser jParser = new com.lgallardo.qbittorrentclient.JSONParser(com.lgallardo.qbittorrentclient.MainActivity.hostname, com.lgallardo.qbittorrentclient.MainActivity.subfolder, com.lgallardo.qbittorrentclient.MainActivity.protocol, com.lgallardo.qbittorrentclient.MainActivity.port, - com.lgallardo.qbittorrentclient.MainActivity.username, com.lgallardo.qbittorrentclient.MainActivity.password, com.lgallardo.qbittorrentclient.MainActivity.connection_timeout, com.lgallardo.qbittorrentclient.MainActivity.data_timeout); - - jParser.setCookie(com.lgallardo.qbittorrentclient.MainActivity.cookie); - - 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); - - - if (com.lgallardo.qbittorrentclient.MainActivity.qb_version.equals("3.2.x")) { - - // Creation date - values[1] = Common.unixTimestampToDate(json2.getString(TAG_CREATION_DATE)); - // Total wasted - values[3] = Common.calculateSize(json2.getString(TAG_TOTAL_WASTED)).replace(",", "."); - - // Total uploaded - values[4] = Common.calculateSize(json2.getString(TAG_TOTAL_UPLOADED)).replace(",", "."); - - // Time elapsed - values[6] = Common.secondsToEta(json2.getString(TAG_TIME_ELAPSED)); - - // Total downloaded - values[5] = Common.calculateSize(json2.getString(TAG_TOTAL_DOWNLOADED)).replace(",", "."); - - // Upload limit - values[9] = json2.getString(TAG_UPLOAD_LIMIT); - - if (!values[9].equals("-1")) { - values[9] = Common.calculateSize(values[9]) + "/s"; - } else { - values[9] = "∞"; - } - - // Download limit - values[10] = json2.getString(TAG_DOWNLOAD_LIMIT); - - if (!values[10].equals("-1")) { - values[10] = Common.calculateSize(values[10]) + "/s"; - } else { - values[10] = "∞"; - } - - } - - - } - - } 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); - layout.removeAllViews(); - - for (int i = 0; i < propertyAdapter.getCount(); i++) { - View item = propertyAdapter.getView(i, null, null); - layout.addView(item); - } - - } catch (Exception e) { - Log.e("TorrentFragment:", e.toString()); - } - - } - - } - - // My custom adapters - class myPropertyAdapter extends ArrayAdapter { - - private String[] labels; - private String[] values; - private Context context; - - public myPropertyAdapter(Context context, String[] labels, String[] values) { - super(context, R.layout.property_row, R.id.label, values); - - this.context = context; - this.labels = labels; - this.values = values; - - } - - @Override - public int getCount() { - 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) { - super(context, R.layout.contentfile_row, R.id.file, filesNames); - - this.context = context; - this.filesNames = filesNames; - this.files = files; - - } - - @Override - public int getCount() { - 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) { - super(context, R.layout.tracker_row, R.id.tracker, trackersNames); - - this.context = context; - this.trackersNames = trackersNames; - this.trackers = trackers; - - } - - @Override - public int getCount() { - 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 = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED); - int totalHeight = 0; - View view = null; - - for (int i = 0; i < listAdapter.getCount(); i++) { - - long numOfLines = 1; - view = listAdapter.getView(i, view, listView); - - if (i == 0) { - view.setLayoutParams(new LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT)); - } - - view.measure(desiredWidth, MeasureSpec.UNSPECIFIED); - - TextView file = (TextView) view.findViewById(R.id.file); - TextView info = (TextView) view.findViewById(R.id.info); - - if (view.getMeasuredWidth() > desiredWidth) { - - double viewWidthLong = Double.valueOf(view.getMeasuredWidth()); - double desiredWidthLong = Double.valueOf(desiredWidth); - - numOfLines = Math.round(viewWidthLong / desiredWidthLong) + 1; - - totalHeight += file.getMeasuredHeight() * numOfLines + info.getMeasuredHeight(); - - } else { - totalHeight += view.getMeasuredHeight(); - } - - } - - LayoutParams params = listView.getLayoutParams(); - - params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); - - listView.setLayoutParams(params); - listView.requestLayout(); - - } - -} diff --git a/qBittorrentClient/app/src/pro/res/layout-large/row.xml b/qBittorrentClient/app/src/pro/res/layout-large/row.xml index 1c00b55a..d4b7a6fa 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/row.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/row.xml @@ -7,7 +7,7 @@ http://www.gnu.org/licenses/gpl.html Contributors: - Luis M. Gallardo D. - initial implementation + Luis M. Gallardo D. --> - + + + + + + + + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml index 387264cf..e73d89ed 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml @@ -443,7 +443,32 @@ android:orientation="vertical"> - + + + + + + + + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout-sw600dp/row.xml b/qBittorrentClient/app/src/pro/res/layout-sw600dp/row.xml index 8e13bee0..a9f83d45 100644 --- a/qBittorrentClient/app/src/pro/res/layout-sw600dp/row.xml +++ b/qBittorrentClient/app/src/pro/res/layout-sw600dp/row.xml @@ -19,7 +19,7 @@ android:orientation="horizontal" android:paddingRight="10dp" android:paddingTop="10dp" - android:background="?backgroundSelector"> + android:background="?backgroundSelector" > - + + + + + + + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml b/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml index 6bdf8d17..d23809c9 100644 --- a/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml +++ b/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml @@ -443,7 +443,32 @@ android:orientation="vertical"> - + + + + + + + + + + \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout/row.xml b/qBittorrentClient/app/src/pro/res/layout/row.xml index 495f47d9..84dca8f5 100644 --- a/qBittorrentClient/app/src/pro/res/layout/row.xml +++ b/qBittorrentClient/app/src/pro/res/layout/row.xml @@ -12,8 +12,7 @@ + android:orientation="horizontal" > + android:visibility="gone"/> - - + \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout/torrent_details_old.xml b/qBittorrentClient/app/src/pro/res/layout/torrent_details_old.xml index 00af40ac..86149210 100644 --- a/qBittorrentClient/app/src/pro/res/layout/torrent_details_old.xml +++ b/qBittorrentClient/app/src/pro/res/layout/torrent_details_old.xml @@ -467,8 +467,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone"/> - - + \ No newline at end of file From 2af2574aa89a7e4625f4083f28256750a20a4ee0 Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Fri, 29 May 2015 18:40:51 -0430 Subject: [PATCH 25/26] * Fixed swipe refresh issues for tablet in fre version --- .../src/free/res/layout-large/activity_main.xml | 12 ++++-------- .../res/layout-large/activity_main_original.xml | 12 ++++++------ .../src/free/res/layout-large/torrent_details.xml | 2 -- .../free/res/layout-large/torrent_details_old.xml | 13 ++++++------- .../app/src/free/res/layout-sw600dp/about.xml | 11 ++++++----- .../free/res/layout-sw600dp/torrent_details.xml | 13 ++++++------- .../res/layout-sw600dp/torrent_details_old.xml | 14 +++++++------- .../app/src/free/res/layout/torrent_details.xml | 2 -- .../app/src/pro/res/layout-large/activity_main.xml | 2 -- .../src/pro/res/layout-large/torrent_details.xml | 1 - .../pro/res/layout-large/torrent_details_old.xml | 1 - .../src/pro/res/layout-sw600dp/torrent_details.xml | 1 - .../pro/res/layout-sw600dp/torrent_details_old.xml | 1 - .../app/src/pro/res/layout/torrent_details.xml | 1 - .../app/src/pro/res/layout/torrent_details_old.xml | 1 - 15 files changed, 35 insertions(+), 52 deletions(-) diff --git a/qBittorrentClient/app/src/free/res/layout-large/activity_main.xml b/qBittorrentClient/app/src/free/res/layout-large/activity_main.xml index bbe42f65..2c38caf6 100644 --- a/qBittorrentClient/app/src/free/res/layout-large/activity_main.xml +++ b/qBittorrentClient/app/src/free/res/layout-large/activity_main.xml @@ -29,19 +29,15 @@ ads:adUnitId="ca-app-pub-1035265933040074/6449288097" android:gravity="bottom" /> - + diff --git a/qBittorrentClient/app/src/free/res/layout-large/activity_main_original.xml b/qBittorrentClient/app/src/free/res/layout-large/activity_main_original.xml index a32498a5..bfe7d266 100644 --- a/qBittorrentClient/app/src/free/res/layout-large/activity_main_original.xml +++ b/qBittorrentClient/app/src/free/res/layout-large/activity_main_original.xml @@ -8,17 +8,17 @@ Contributors: Luis M. Gallardo D. --> - + android:paddingLeft="10dp" + xmlns:android="http://schemas.android.com/apk/res/android"> - \ No newline at end of file + \ No newline at end of file diff --git a/qBittorrentClient/app/src/free/res/layout-large/torrent_details.xml b/qBittorrentClient/app/src/free/res/layout-large/torrent_details.xml index ab29ced2..092b8ff1 100644 --- a/qBittorrentClient/app/src/free/res/layout-large/torrent_details.xml +++ b/qBittorrentClient/app/src/free/res/layout-large/torrent_details.xml @@ -456,14 +456,12 @@ android:orientation="vertical"> - - diff --git a/qBittorrentClient/app/src/free/res/layout-large/torrent_details_old.xml b/qBittorrentClient/app/src/free/res/layout-large/torrent_details_old.xml index 4c9087f0..78313e0c 100644 --- a/qBittorrentClient/app/src/free/res/layout-large/torrent_details_old.xml +++ b/qBittorrentClient/app/src/free/res/layout-large/torrent_details_old.xml @@ -412,15 +412,14 @@ android:orientation="vertical"> + + - - - \ No newline at end of file diff --git a/qBittorrentClient/app/src/free/res/layout-sw600dp/about.xml b/qBittorrentClient/app/src/free/res/layout-sw600dp/about.xml index 75a2078d..2fce0aff 100644 --- a/qBittorrentClient/app/src/free/res/layout-sw600dp/about.xml +++ b/qBittorrentClient/app/src/free/res/layout-sw600dp/about.xml @@ -8,10 +8,11 @@ Contributors: Luis M. Gallardo D. --> - + - \ No newline at end of file + \ No newline at end of file diff --git a/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details.xml b/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details.xml index bbbee313..a3b26da1 100644 --- a/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details.xml +++ b/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details.xml @@ -456,15 +456,14 @@ android:orientation="vertical"> + + - - - \ No newline at end of file diff --git a/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details_old.xml b/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details_old.xml index 9f7b109f..20d944b8 100644 --- a/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details_old.xml +++ b/qBittorrentClient/app/src/free/res/layout-sw600dp/torrent_details_old.xml @@ -411,14 +411,14 @@ android:orientation="vertical"> - - - + + + diff --git a/qBittorrentClient/app/src/free/res/layout/torrent_details.xml b/qBittorrentClient/app/src/free/res/layout/torrent_details.xml index cd19d62b..5f3bb5d0 100644 --- a/qBittorrentClient/app/src/free/res/layout/torrent_details.xml +++ b/qBittorrentClient/app/src/free/res/layout/torrent_details.xml @@ -470,8 +470,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone"/> - - diff --git a/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml b/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml index aed3dbae..1b966b52 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/activity_main.xml @@ -24,8 +24,6 @@ android:id="@+id/app_bar" layout="@layout/app_bar" /> - - - \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml index e73d89ed..0a375202 100644 --- a/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml +++ b/qBittorrentClient/app/src/pro/res/layout-large/torrent_details_old.xml @@ -468,7 +468,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone"/> - \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details.xml b/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details.xml index b0fd6c53..307c63fc 100644 --- a/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details.xml +++ b/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details.xml @@ -514,7 +514,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone"/> - \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml b/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml index d23809c9..5c689593 100644 --- a/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml +++ b/qBittorrentClient/app/src/pro/res/layout-sw600dp/torrent_details_old.xml @@ -468,7 +468,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone"/> - \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout/torrent_details.xml b/qBittorrentClient/app/src/pro/res/layout/torrent_details.xml index 28cebb43..cfd3583b 100644 --- a/qBittorrentClient/app/src/pro/res/layout/torrent_details.xml +++ b/qBittorrentClient/app/src/pro/res/layout/torrent_details.xml @@ -515,7 +515,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone"/> - \ No newline at end of file diff --git a/qBittorrentClient/app/src/pro/res/layout/torrent_details_old.xml b/qBittorrentClient/app/src/pro/res/layout/torrent_details_old.xml index 86149210..11c83d39 100644 --- a/qBittorrentClient/app/src/pro/res/layout/torrent_details_old.xml +++ b/qBittorrentClient/app/src/pro/res/layout/torrent_details_old.xml @@ -467,7 +467,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone"/> - \ No newline at end of file From 04c9a54042ab533008d31ed85df57f2552edd834 Mon Sep 17 00:00:00 2001 From: Luis Gallardo Date: Fri, 29 May 2015 23:24:07 -0430 Subject: [PATCH 26/26] * Fixed dark theme for tablets in free version --- .../app/src/free/res/layout-large/activity_main.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qBittorrentClient/app/src/free/res/layout-large/activity_main.xml b/qBittorrentClient/app/src/free/res/layout-large/activity_main.xml index 2c38caf6..c945a83d 100644 --- a/qBittorrentClient/app/src/free/res/layout-large/activity_main.xml +++ b/qBittorrentClient/app/src/free/res/layout-large/activity_main.xml @@ -18,7 +18,9 @@ android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal"> + android:orientation="horizontal" + android:background="?windowBackground"> +