Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ANDROAPP-2474] Import/Export database #3503

Merged
merged 19 commits into from
Mar 8, 2024
Prev Previous commit
Next Next commit
fix download for android < 10
Signed-off-by: Pablo <[email protected]>
Balcan committed Mar 7, 2024
commit ac0f0f4a3920b2f365f6a48c222599adf32e73b5
Original file line number Diff line number Diff line change
@@ -194,7 +194,7 @@ private void shareDB(ExportDbModel fileData) {
private void downloadDB(ExportDbModel fileData) {
new FileHandler().copyAndOpen(fileData.getFile(), fileLiveData -> {
fileLiveData.observe(getViewLifecycleOwner(), file -> {
Toast.makeText(requireContext(), R.string.downloaded_confirm, Toast.LENGTH_SHORT).show();
Toast.makeText(requireContext(), R.string.database_export_downloaded, Toast.LENGTH_SHORT).show();
presenter.onExportEnd();
});
return null;
39 changes: 24 additions & 15 deletions app/src/main/java/org/dhis2/usescases/settings/ui/ExportOption.kt
Original file line number Diff line number Diff line change
@@ -51,20 +51,20 @@ fun ExportOption(
label = "import content",
) { targetState ->

Row(
modifier = Modifier
.fillMaxWidth()
.height(72.dp)
.padding(
start = if (displayProgress) 16.dp else 72.dp,
top = 16.dp,
end = 16.dp,
bottom = 16.dp,
),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = if (displayProgress) Arrangement.Center else spacedBy(16.dp),
) {
if (targetState.not()) {
if (targetState.not()) {
Row(
modifier = Modifier
.fillMaxWidth()
.height(72.dp)
.padding(
start = 72.dp,
top = 16.dp,
end = 16.dp,
bottom = 16.dp,
),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = if (displayProgress) Arrangement.Center else spacedBy(16.dp),
) {
Button(
modifier = Modifier.weight(1f),
onClick = onDownload,
@@ -92,7 +92,16 @@ fun ExportOption(
)
},
)
} else {
}
} else {
Row(
modifier = Modifier
.fillMaxWidth()
.height(72.dp)
.padding(16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = if (displayProgress) Arrangement.Center else spacedBy(16.dp),
) {
ProgressIndicator(type = ProgressIndicatorType.CIRCULAR)
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -963,4 +963,5 @@
<string name="timeline">Timeline</string>
<string name="clear_search">Clear search</string>
<string name="optional">Optional</string>
<string name="database_export_downloaded">Database downloaded</string>
</resources>
23 changes: 17 additions & 6 deletions commons/src/main/java/org/dhis2/commons/data/FileHandler.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.dhis2.commons.data

import android.graphics.Bitmap
import android.os.Build
import android.os.Environment
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
@@ -43,10 +44,20 @@ class FileHandler {
return sourceFile.copyTo(destinationDirectory, true)
}

private fun getDownloadDirectory(outputFileName: String) = File(
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS,
),
"dhis2" + File.separator + outputFileName,
)
private fun getDownloadDirectory(outputFileName: String) = if (Build.VERSION.SDK_INT >= 29) {
File(
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS,
),
"dhis2" + File.separator + outputFileName,
)
} else {
File.createTempFile(
"copied_",
outputFileName,
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS,
),
)
}
}