mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-10 07:48:30 -04:00
A few changes as per Julian's comments
This commit is contained in:
parent
1fda455f88
commit
37fabe1bc3
@ -58,6 +58,7 @@ public class DownloadService extends Service {
|
|||||||
private static String SD_CARD;
|
private static String SD_CARD;
|
||||||
// 1024 / 100
|
// 1024 / 100
|
||||||
private static final double BOOK_SIZE_OFFSET = 10.24;
|
private static final double BOOK_SIZE_OFFSET = 10.24;
|
||||||
|
private static final String KIWIX_TAG = "kiwixdownloadservice";
|
||||||
public static String KIWIX_ROOT;
|
public static String KIWIX_ROOT;
|
||||||
public static final int PLAY = 1;
|
public static final int PLAY = 1;
|
||||||
public static final int PAUSE = 2;
|
public static final int PAUSE = 2;
|
||||||
@ -111,14 +112,14 @@ public class DownloadService extends Service {
|
|||||||
if (intent.hasExtra(NOTIFICATION_ID)) {
|
if (intent.hasExtra(NOTIFICATION_ID)) {
|
||||||
log += intent.getIntExtra(NOTIFICATION_ID, -3);
|
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)) {
|
if (intent.hasExtra(NOTIFICATION_ID) && intent.getAction().equals(ACTION_STOP)) {
|
||||||
stopDownload(intent.getIntExtra(NOTIFICATION_ID, 0));
|
stopDownload(intent.getIntExtra(NOTIFICATION_ID, 0));
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
if (intent.hasExtra(NOTIFICATION_ID) && (intent.getAction().equals(ACTION_PAUSE))) {
|
if (intent.hasExtra(NOTIFICATION_ID) && (intent.getAction().equals(ACTION_PAUSE))) {
|
||||||
if (KiwixMobileActivity.wifiOnly && !NetworkUtils.isWiFi(getApplicationContext())) {
|
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));
|
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));
|
this.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
|
||||||
} else {
|
} else {
|
||||||
@ -134,7 +135,7 @@ public class DownloadService extends Service {
|
|||||||
|
|
||||||
KIWIX_ROOT = checkWritable(KIWIX_ROOT);
|
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);
|
notificationTitle = intent.getExtras().getString(DownloadIntent.DOWNLOAD_ZIM_TITLE);
|
||||||
LibraryNetworkEntity.Book book = (LibraryNetworkEntity.Book) intent.getSerializableExtra("Book");
|
LibraryNetworkEntity.Book book = (LibraryNetworkEntity.Book) intent.getSerializableExtra("Book");
|
||||||
@ -180,7 +181,7 @@ public class DownloadService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void stopDownload(int notificationID) {
|
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);
|
downloadStatus.put(notificationID, CANCEL);
|
||||||
synchronized (pauseLock) {
|
synchronized (pauseLock) {
|
||||||
pauseLock.notify();
|
pauseLock.notify();
|
||||||
@ -223,7 +224,7 @@ public class DownloadService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void pauseDownload(int notificationID) {
|
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);
|
downloadStatus.put(notificationID, PAUSE);
|
||||||
notification.get(notificationID).mActions.get(0).title = getString(R.string.download_play);
|
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;
|
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) {
|
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);
|
downloadStatus.put(notificationID, PLAY);
|
||||||
synchronized (pauseLock) {
|
synchronized (pauseLock) {
|
||||||
pauseLock.notify();
|
pauseLock.notify();
|
||||||
@ -468,7 +469,7 @@ public class DownloadService extends Service {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Retry on network error
|
// Retry on network error
|
||||||
attempts++;
|
attempts++;
|
||||||
Log.d("kiwixdownloadservice", "Download Attempt Failed [" + attempts + "] times", e);
|
Log.d(KIWIX_TAG, "Download Attempt Failed [" + attempts + "] times", e);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000 * attempts); // The more unsuccessful attempts the longer the wait
|
Thread.sleep(1000 * attempts); // The more unsuccessful attempts the longer the wait
|
||||||
} catch (InterruptedException ex) {
|
} 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 download is canceled clean up else remove .part from file name
|
||||||
if (downloadStatus.get(chunk.getNotificationID()) == CANCEL) {
|
if (downloadStatus.get(chunk.getNotificationID()) == CANCEL) {
|
||||||
Log.i("kiwixdownloadservice", "Download Cancelled, deleting .part file");
|
|
||||||
String path = file.getPath();
|
String path = file.getPath();
|
||||||
|
Log.i(KIWIX_TAG, "Download Cancelled, deleting file: " + path);
|
||||||
if (path.substring(path.length() - 8).equals("zim.part")) {
|
if (path.substring(path.length() - 8).equals("zim.part")) {
|
||||||
path = path.substring(0, path.length() - 5);
|
path = path.substring(0, path.length() - 5);
|
||||||
FileUtils.deleteZimFile(path);
|
FileUtils.deleteZimFile(path);
|
||||||
@ -491,7 +492,7 @@ public class DownloadService extends Service {
|
|||||||
FileUtils.deleteZimFile(path);
|
FileUtils.deleteZimFile(path);
|
||||||
}
|
}
|
||||||
} else {
|
} 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", "")));
|
file.renameTo(new File(file.getPath().replace(".part", "")));
|
||||||
}
|
}
|
||||||
// Mark chunk status as downloaded
|
// Mark chunk status as downloaded
|
||||||
|
@ -71,6 +71,8 @@ public class ZimManageActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
public SearchView searchView;
|
public SearchView searchView;
|
||||||
|
|
||||||
|
private static String KIWIX_TAG = "kiwix";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
@ -84,7 +86,7 @@ public class ZimManageActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
if (DownloadService.ACTION_NO_WIFI.equals(getIntent().getAction())) {
|
if (DownloadService.ACTION_NO_WIFI.equals(getIntent().getAction())) {
|
||||||
DownloadFragment.showNoWiFiWarning(this, () -> {});
|
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
|
// 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) {
|
private void updateMenu(int position) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user