Skip to content

Commit 1be7172

Browse files
committed
Fixes for database update
1 parent 559da4d commit 1be7172

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

app/src/main/java/net/hunnor/dict/android/activity/database/DatabaseActivity.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,17 @@ public void onReceive(Context context, Intent intent) {
8787
}
8888
};
8989

90+
Log.d(TAG, "Registering broadcast receiver");
9091
ContextCompat.registerReceiver(this, receiver,
9192
new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE),
92-
ContextCompat.RECEIVER_NOT_EXPORTED);
93+
ContextCompat.RECEIVER_EXPORTED);
9394

9495
}
9596

9697
private void receiveBroadcast(Intent intent) {
9798

9899
String action = intent.getAction();
100+
Log.d(TAG, "Broadcast received: " + action);
99101
if (!DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
100102
return;
101103
}
@@ -115,15 +117,24 @@ private void receiveBroadcast(Intent intent) {
115117
try (Cursor cursor = downloadManager.query(query)) {
116118
if (cursor.moveToFirst()) {
117119
int statusColumnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
118-
if (DownloadManager.STATUS_SUCCESSFUL == cursor.getInt(statusColumnIndex)) {
120+
int status = cursor.getInt(statusColumnIndex);
121+
Log.d(TAG, "Download status: " + status);
122+
if (DownloadManager.STATUS_SUCCESSFUL == status) {
119123
int localUriColumnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI);
120124
if (localUriColumnIndex >= 0) {
121125
String uriString = cursor.getString(localUriColumnIndex);
122126
Uri uri = Uri.parse(uriString);
127+
Log.d(TAG, "Download successful, URI: " + uriString);
123128
getViewModel().setProgressReport(getString(R.string.database_update_extract_start));
124129
startExtractTask(uri);
125130
}
131+
} else if (DownloadManager.STATUS_FAILED == status) {
132+
int reasonColumnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
133+
int reason = cursor.getInt(reasonColumnIndex);
134+
Log.e(TAG, "Download failed, reason: " + reason);
126135
}
136+
} else {
137+
Log.w(TAG, "Download cursor empty for ID: " + activeDownloadId);
127138
}
128139
} catch (Exception e) {
129140
Log.e(TAG, e.getMessage(), e);
@@ -306,8 +317,10 @@ public void checkLocalFilesCallback(Long localDate, Long localSize) {
306317

307318
public void doDownload(View view) {
308319

320+
Log.d(TAG, "doDownload called");
309321
String externalStorageState = Environment.getExternalStorageState();
310322
if (!Environment.MEDIA_MOUNTED.equals(externalStorageState)) {
323+
Log.e(TAG, "External storage not mounted: " + externalStorageState);
311324
return;
312325
}
313326

@@ -332,13 +345,10 @@ public void doDownload(View view) {
332345
}
333346
}
334347

335-
File externalFilesDir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
336-
File downloadFile = new File(externalFilesDir, INDEX_FILE);
337-
Uri uri = Uri.fromFile(downloadFile);
338-
339348
Request request = new Request(Uri.parse(INDEX_URL));
340-
request.setDestinationUri(uri);
349+
request.setDestinationInExternalFilesDir(this, Environment.DIRECTORY_DOWNLOADS, INDEX_FILE);
341350
long queueId = downloadManager.enqueue(request);
351+
Log.d(TAG, "Download enqueued, ID: " + queueId);
342352
model.setActiveDownloadId(queueId);
343353

344354
AppCompatImageView icon = findViewById(R.id.database_block_progress_icon);

app/src/main/java/net/hunnor/dict/android/task/ExtractTask.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.net.Uri;
66
import android.os.AsyncTask;
77
import android.os.Environment;
8+
import android.util.Log;
89

910
import net.hunnor.dict.android.activity.database.DatabaseActivity;
1011
import net.hunnor.dict.android.activity.main.MainActivity;
@@ -33,6 +34,7 @@ public ExtractTask(Activity activity, StorageService storageService) {
3334
@Override
3435
protected ExtractTaskStatus doInBackground(Uri... uris) {
3536

37+
Log.d("ExtractTask", "Starting extraction");
3638
ExtractTaskStatus status = ExtractTaskStatus.E_EXCEPTION_IO;
3739

3840
if (uris == null || uris.length == 0) {
@@ -75,6 +77,7 @@ protected ExtractTaskStatus doInBackground(Uri... uris) {
7577
@Override
7678
protected void onPostExecute(ExtractTaskStatus status) {
7779

80+
Log.d("ExtractTask", "Extraction finished with status: " + status);
7881
final Activity activity = activityWeakReference.get();
7982

8083
if (MainActivity.class.isAssignableFrom(activity.getClass())) {

0 commit comments

Comments
 (0)