From 37fabe1bc3385fbd24e721163e13f32b19d03eeb Mon Sep 17 00:00:00 2001 From: Joseph Reeve Date: Fri, 22 Sep 2017 09:40:39 +0100 Subject: [PATCH] A few changes as per Julian's comments --- .../downloader/DownloadService.java | 19 ++++++++++--------- .../zim_manager/ZimManageActivity.java | 6 ++++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/downloader/DownloadService.java b/app/src/main/java/org/kiwix/kiwixmobile/downloader/DownloadService.java index d44b6eff7..7cf7ef06f 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/downloader/DownloadService.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/downloader/DownloadService.java @@ -58,6 +58,7 @@ public class DownloadService extends Service { private static String SD_CARD; // 1024 / 100 private static final double BOOK_SIZE_OFFSET = 10.24; + private static final String KIWIX_TAG = "kiwixdownloadservice"; public static String KIWIX_ROOT; public static final int PLAY = 1; public static final int PAUSE = 2; @@ -111,14 +112,14 @@ public class DownloadService extends Service { if (intent.hasExtra(NOTIFICATION_ID)) { log += intent.getIntExtra(NOTIFICATION_ID, -3); } - Log.d("kiwixdownloadservice", log); + Log.d(KIWIX_TAG, log); if (intent.hasExtra(NOTIFICATION_ID) && intent.getAction().equals(ACTION_STOP)) { stopDownload(intent.getIntExtra(NOTIFICATION_ID, 0)); return START_NOT_STICKY; } if (intent.hasExtra(NOTIFICATION_ID) && (intent.getAction().equals(ACTION_PAUSE))) { if (KiwixMobileActivity.wifiOnly && !NetworkUtils.isWiFi(getApplicationContext())) { - Log.i("kiwixdownloadservice", "Not connected to WiFi, and wifiOnly is enabled"); + Log.i(KIWIX_TAG, "Not connected to WiFi, and wifiOnly is enabled"); startActivity(new Intent(this, ZimManageActivity.class).setAction(ACTION_NO_WIFI).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); this.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); } else { @@ -134,7 +135,7 @@ public class DownloadService extends Service { KIWIX_ROOT = checkWritable(KIWIX_ROOT); - Log.i("kiwixdownloadservice", "Using Kiwix Root: " + KIWIX_ROOT); + Log.d(KIWIX_TAG, "Using KIWIX_ROOT: " + KIWIX_ROOT); notificationTitle = intent.getExtras().getString(DownloadIntent.DOWNLOAD_ZIM_TITLE); LibraryNetworkEntity.Book book = (LibraryNetworkEntity.Book) intent.getSerializableExtra("Book"); @@ -180,7 +181,7 @@ public class DownloadService extends Service { } public void stopDownload(int notificationID) { - Log.i("kiwixdownloadservice", "Stopping ZIM Download"); + Log.i(KIWIX_TAG, "Stopping ZIM Download for notificationID: " + notificationID); downloadStatus.put(notificationID, CANCEL); synchronized (pauseLock) { pauseLock.notify(); @@ -223,7 +224,7 @@ public class DownloadService extends Service { } public void pauseDownload(int notificationID) { - Log.i("kiwixdownloadservice", "Pausing ZIM Download"); + Log.i(KIWIX_TAG, "Pausing ZIM Download for notificationID: " + notificationID); downloadStatus.put(notificationID, PAUSE); notification.get(notificationID).mActions.get(0).title = getString(R.string.download_play); notification.get(notificationID).mActions.get(0).icon = R.drawable.ic_play_arrow_black_24dp; @@ -236,7 +237,7 @@ public class DownloadService extends Service { } public boolean playDownload(int notificationID) { - Log.i("kiwixdownloadservice", "Starting ZIM Download"); + Log.i(KIWIX_TAG, "Starting ZIM Download for notificationID: " + notificationID); downloadStatus.put(notificationID, PLAY); synchronized (pauseLock) { pauseLock.notify(); @@ -468,7 +469,7 @@ public class DownloadService extends Service { } catch (Exception e) { // Retry on network error attempts++; - Log.d("kiwixdownloadservice", "Download Attempt Failed [" + attempts + "] times", e); + Log.d(KIWIX_TAG, "Download Attempt Failed [" + attempts + "] times", e); try { Thread.sleep(1000 * attempts); // The more unsuccessful attempts the longer the wait } catch (InterruptedException ex) { @@ -481,8 +482,8 @@ public class DownloadService extends Service { } // If download is canceled clean up else remove .part from file name if (downloadStatus.get(chunk.getNotificationID()) == CANCEL) { - Log.i("kiwixdownloadservice", "Download Cancelled, deleting .part file"); String path = file.getPath(); + Log.i(KIWIX_TAG, "Download Cancelled, deleting file: " + path); if (path.substring(path.length() - 8).equals("zim.part")) { path = path.substring(0, path.length() - 5); FileUtils.deleteZimFile(path); @@ -491,7 +492,7 @@ public class DownloadService extends Service { FileUtils.deleteZimFile(path); } } else { - Log.i("kiwixdownloadservice", "Download completed, renaming file (.zim.part -> .zim)"); + Log.i(KIWIX_TAG, "Download completed, renaming file ([" + file.getPath() + "] -> .zim)"); file.renameTo(new File(file.getPath().replace(".part", ""))); } // Mark chunk status as downloaded diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.java b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.java index 213da6a92..29f52b22d 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/zim_manager/ZimManageActivity.java @@ -71,6 +71,8 @@ public class ZimManageActivity extends AppCompatActivity { public SearchView searchView; + private static String KIWIX_TAG = "kiwix"; + @Override protected void onCreate(Bundle savedInstanceState) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); @@ -84,7 +86,7 @@ public class ZimManageActivity extends AppCompatActivity { if (DownloadService.ACTION_NO_WIFI.equals(getIntent().getAction())) { DownloadFragment.showNoWiFiWarning(this, () -> {}); - Log.i("kiwix", "No WiFi, showing warning"); + Log.i(KIWIX_TAG, "No WiFi, showing warning"); } // Create the adapter that will return a fragment for each of the three @@ -117,7 +119,7 @@ public class ZimManageActivity extends AppCompatActivity { } }); - Log.i("kiwik", "ZimManageActivity successfully bootstrapped"); + Log.i(KIWIX_TAG, "ZimManageActivity successfully bootstrapped"); } private void updateMenu(int position) {