Skip to content

Commit

Permalink
V2.9
Browse files Browse the repository at this point in the history
Backup database
  • Loading branch information
woheller69 committed Apr 10, 2024
1 parent 54396b0 commit 62b7198
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This work is licensed under GPLv3
- At first start it downloads the BirdNet TFLite library from [whoBird-TFlite](https://github.com/woheller69/whoBIRD-TFlite), which is published under CC BY NC SA 4.0 license
- Label files from BirdNET are used under GPL 3.0 with [permission from the author](https://github.com/woheller69/whoBIRD/issues/1)
- It uses code from [Tensorflow](https://www.tensorflow.org/lite/examples) examples, published under [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0.html)
- It uses Zip4j (https://github.com/srikanth-lingala/zip4j) which is licensed under Apache License Version 2.0

# OTHER APPS

Expand Down
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.woheller69.whobird"
minSdk 30
targetSdk 33
versionCode 28
versionName "2.8"
versionCode 29
versionName "2.9"
}

aaptOptions {
Expand Down Expand Up @@ -52,4 +52,5 @@ dependencies {
implementation "org.tensorflow:tensorflow-lite:2.6.0"
implementation 'androidx.preference:preference:1.2.0'
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'net.lingala.zip4j:zip4j:2.9.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.os.Environment
import android.view.Gravity
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.webkit.WebSettings
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.google.android.material.snackbar.Snackbar
import net.lingala.zip4j.ZipFile
import net.lingala.zip4j.exception.ZipException
import org.tensorflow.lite.examples.soundclassifier.databinding.ActivityMainBinding
import java.io.File
import java.util.Objects

class MainActivity : AppCompatActivity() {

Expand Down Expand Up @@ -173,7 +180,41 @@ class MainActivity : AppCompatActivity() {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/woheller69/whobird")))
return true
}
R.id.action_backup -> {
performBackup()
return true
}
else -> return super.onOptionsItemSelected(item)
}
}

fun performBackup() {
val extStorage: File
val intData: File
intData = File(
Environment.getDataDirectory().toString() + "//data//" + this.packageName + "//databases//"
)
extStorage = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)
val filesBackup = resources.getString(R.string.app_name) + ".zip"
val dbBackup = File(extStorage, filesBackup)
val builder = AlertDialog.Builder(this)
builder.setMessage(resources.getString(R.string.backup_database) + " -> " + dbBackup.toString())
builder.setPositiveButton(R.string.dialog_OK_button) { dialog, whichButton ->
if (dbBackup.exists()) {
if (!dbBackup.delete()) {
Toast.makeText(this, resources.getString(R.string.toast_delete), Toast.LENGTH_LONG)
.show()
}
}
try {
ZipFile(dbBackup).addFolder(intData)
} catch (e: ZipException) {
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show()
}
}
builder.setNegativeButton(R.string.dialog_NO_button) { dialog, whichButton -> dialog.cancel() }
val dialog = builder.create()
dialog.show()
Objects.requireNonNull(dialog.window)?.setGravity(Gravity.BOTTOM)
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
android:icon="@drawable/ic_info_24dp"
app:showAsAction="always"
tools:ignore="MenuTitle" />

<item
android:id="@+id/action_backup"
android:title="@string/backup_database" />
</menu>
2 changes: 2 additions & 0 deletions app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
<string name="clear_db">Pozorování smazána</string>
<string name="detailed_list">Podrobný seznam</string>
<string name="delete">Vymazat?</string>
<string name="backup_database">Backup</string>
<string name="toast_delete">Please delete file and try again</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
<string name="clear_db">Beobachtungen gelöscht</string>
<string name="detailed_list">Detaillierte Liste</string>
<string name="delete">Löschen?</string>

<string name="backup_database">Sichern</string>
<string name="toast_delete">Bitte die Datei zuerst löschen und erneut versuchen</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<string name="clear_db">Observaciones borradas</string>
<string name="detailed_list">Lista detallada</string>
<string name="delete">¿Borrar?</string>

<string name="backup_database">Backup</string>
<string name="toast_delete">Please delete file and try again</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
<string name="clear_db">Les observations ont été supprimées</string>
<string name="detailed_list">Liste détaillée</string>
<string name="delete">Supprimer?</string>
<string name="backup_database">Backup</string>
<string name="toast_delete">Please delete file and try again</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
<string name="clear_db">Obserwacje usunięte</string>
<string name="detailed_list">Szczegółowa lista</string>
<string name="delete">Usuwać?</string>
<string name="backup_database">Backup</string>
<string name="toast_delete">Please delete file and try again</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values-sv/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<string name="clear_db">Observationer borttagna</string>
<string name="detailed_list">Detaljerad lista</string>
<string name="delete">Radera?</string>

<string name="backup_database">Backup</string>
<string name="toast_delete">Please delete file and try again</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
<string name="clear_db">Gözlemler silindi</string>
<string name="detailed_list">Ayrıntılı liste</string>
<string name="delete">Silmek?</string>

<string name="backup_database">Yedekleme</string>
<string name="toast_delete">Lütfen dosyayı silin ve tekrar deneyin</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<string name="clear_db">Observations deleted</string>
<string name="detailed_list">Detailed list</string>
<string name="delete">Delete?</string>

<string name="backup_database">Backup</string>
<string name="toast_delete">Please delete file and try again</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<item name="colorOnSurface">@color/gray700</item>
<item name="colorSecondary">@color/gray400</item>
<item name="colorSurface">@color/gray800</item>
<item name="popupMenuBackground">@color/gray400</item>
</style>
</resources>
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/29.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Option for database backup

0 comments on commit 62b7198

Please sign in to comment.