mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Added some logging
This commit is contained in:
parent
61ec22a88b
commit
1fda455f88
@ -1414,9 +1414,9 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
||||
}
|
||||
}
|
||||
if (file == null) {
|
||||
Log.i(TAG_KIWIX, "Could not find file");
|
||||
return;
|
||||
}
|
||||
|
||||
finish();
|
||||
Intent zimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class);
|
||||
zimFile.setData(uri);
|
||||
@ -1428,6 +1428,8 @@ public class KiwixMobileActivity extends BaseActivity implements WebViewCallback
|
||||
String title =
|
||||
data.getStringExtra(TAG_FILE_SEARCHED).replace("<b>", "").replace("</b>", "");
|
||||
searchForTitle(title);
|
||||
} else { //TODO: Inform the User
|
||||
Log.w(TAG_KIWIX, "Unhandled search failure");
|
||||
}
|
||||
break;
|
||||
case REQUEST_PREFERENCES:
|
||||
|
@ -118,10 +118,12 @@ public class DownloadService extends Service {
|
||||
}
|
||||
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");
|
||||
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
|
||||
} else {
|
||||
toggleDownload(intent.getIntExtra(NOTIFICATION_ID, 0));
|
||||
}
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
@ -132,6 +134,8 @@ public class DownloadService extends Service {
|
||||
|
||||
KIWIX_ROOT = checkWritable(KIWIX_ROOT);
|
||||
|
||||
Log.i("kiwixdownloadservice", "Using Kiwix Root: " + KIWIX_ROOT);
|
||||
|
||||
notificationTitle = intent.getExtras().getString(DownloadIntent.DOWNLOAD_ZIM_TITLE);
|
||||
LibraryNetworkEntity.Book book = (LibraryNetworkEntity.Book) intent.getSerializableExtra("Book");
|
||||
int notificationID = book.getId().hashCode();
|
||||
@ -176,6 +180,7 @@ public class DownloadService extends Service {
|
||||
}
|
||||
|
||||
public void stopDownload(int notificationID) {
|
||||
Log.i("kiwixdownloadservice", "Stopping ZIM Download");
|
||||
downloadStatus.put(notificationID, CANCEL);
|
||||
synchronized (pauseLock) {
|
||||
pauseLock.notify();
|
||||
@ -218,6 +223,7 @@ public class DownloadService extends Service {
|
||||
}
|
||||
|
||||
public void pauseDownload(int notificationID) {
|
||||
Log.i("kiwixdownloadservice", "Pausing ZIM Download");
|
||||
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;
|
||||
@ -230,6 +236,7 @@ public class DownloadService extends Service {
|
||||
}
|
||||
|
||||
public boolean playDownload(int notificationID) {
|
||||
Log.i("kiwixdownloadservice", "Starting ZIM Download");
|
||||
downloadStatus.put(notificationID, PLAY);
|
||||
synchronized (pauseLock) {
|
||||
pauseLock.notify();
|
||||
@ -259,7 +266,8 @@ public class DownloadService extends Service {
|
||||
updateDownloadFragmentProgress(initial, notificationID);
|
||||
notificationManager.notify(notificationID, notification.get(notificationID).build());
|
||||
}
|
||||
kiwixService.getMetaLinks(url).retryWhen(errors -> errors.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS)))
|
||||
kiwixService.getMetaLinks(url)
|
||||
.retryWhen(errors -> errors.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS)))
|
||||
.subscribeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap(metaLink -> getMetaLinkContentLength(metaLink.getRelevantUrl().getValue()))
|
||||
.flatMap(pair -> Observable.from(ChunkUtils.getChunks(pair.first, pair.second, notificationID)))
|
||||
@ -288,7 +296,7 @@ public class DownloadService extends Service {
|
||||
notificationManager.notify(notificationID, notification.get(notificationID).build());
|
||||
if (progress == 0 || progress == 100) {
|
||||
// Tells android to not kill the service
|
||||
updateForeground();
|
||||
updateForeground();
|
||||
}
|
||||
updateDownloadFragmentProgress(progress, notificationID);
|
||||
if (progress == 100) {
|
||||
@ -404,6 +412,8 @@ public class DownloadService extends Service {
|
||||
|
||||
input = response.body().source();
|
||||
|
||||
Log.d("kiwixdownloadservice", "Got valid chunk");
|
||||
|
||||
long lastTime = System.currentTimeMillis();
|
||||
long lastSize = 0;
|
||||
|
||||
@ -414,8 +424,9 @@ public class DownloadService extends Service {
|
||||
break;
|
||||
}
|
||||
|
||||
if (KiwixMobileActivity.wifiOnly && !NetworkUtils.isWiFi(getApplicationContext()))
|
||||
if (KiwixMobileActivity.wifiOnly && !NetworkUtils.isWiFi(getApplicationContext())) {
|
||||
pauseDownload(chunk.getNotificationID());
|
||||
}
|
||||
|
||||
if (downloadStatus.get(chunk.getNotificationID()) == PAUSE) {
|
||||
synchronized (pauseLock) {
|
||||
@ -457,6 +468,7 @@ public class DownloadService extends Service {
|
||||
} catch (Exception e) {
|
||||
// Retry on network error
|
||||
attempts++;
|
||||
Log.d("kiwixdownloadservice", "Download Attempt Failed [" + attempts + "] times", e);
|
||||
try {
|
||||
Thread.sleep(1000 * attempts); // The more unsuccessful attempts the longer the wait
|
||||
} catch (InterruptedException ex) {
|
||||
@ -469,6 +481,7 @@ 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();
|
||||
if (path.substring(path.length() - 8).equals("zim.part")) {
|
||||
path = path.substring(0, path.length() - 5);
|
||||
@ -478,6 +491,7 @@ public class DownloadService extends Service {
|
||||
FileUtils.deleteZimFile(path);
|
||||
}
|
||||
} else {
|
||||
Log.i("kiwixdownloadservice", "Download completed, renaming file (.zim.part -> .zim)");
|
||||
file.renameTo(new File(file.getPath().replace(".part", "")));
|
||||
}
|
||||
// Mark chunk status as downloaded
|
||||
|
@ -47,6 +47,7 @@ public class FileUtils {
|
||||
if (path.substring(path.length() - 5).equals(".part")) {
|
||||
path = path.substring(0, path.length() - 5);
|
||||
}
|
||||
Log.i("kiwix", "Deleting file: " + path);
|
||||
File file = new File(path);
|
||||
if (!file.getPath().substring(file.getPath().length() - 3).equals("zim")) {
|
||||
fileloop:
|
||||
|
@ -16,6 +16,7 @@ import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@ -83,6 +84,7 @@ public class ZimManageActivity extends AppCompatActivity {
|
||||
|
||||
if (DownloadService.ACTION_NO_WIFI.equals(getIntent().getAction())) {
|
||||
DownloadFragment.showNoWiFiWarning(this, () -> {});
|
||||
Log.i("kiwix", "No WiFi, showing warning");
|
||||
}
|
||||
|
||||
// Create the adapter that will return a fragment for each of the three
|
||||
@ -114,6 +116,8 @@ public class ZimManageActivity extends AppCompatActivity {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
Log.i("kiwik", "ZimManageActivity successfully bootstrapped");
|
||||
}
|
||||
|
||||
private void updateMenu(int position) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user