parent
3882a95b65
commit
2a78d2e556
|
@ -538,6 +538,26 @@ export default function SettingsPage() {
|
||||||
</Button>
|
</Button>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Export sets as CSV",
|
||||||
|
renderItem: (name: string) => (
|
||||||
|
<Button
|
||||||
|
style={{ alignSelf: "flex-start" }}
|
||||||
|
onPress={async () => {
|
||||||
|
const result = await check(
|
||||||
|
PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE
|
||||||
|
);
|
||||||
|
if (result === RESULTS.DENIED || result === RESULTS.BLOCKED) {
|
||||||
|
await request(PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE);
|
||||||
|
}
|
||||||
|
await NativeModules.BackupModule.exportToCSV();
|
||||||
|
toast("Exported sets as CSV.");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{name}
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Import database",
|
name: "Import database",
|
||||||
renderItem: (name: string) => (
|
renderItem: (name: string) => (
|
||||||
|
|
|
@ -85,8 +85,8 @@ android {
|
||||||
applicationId "com.massive"
|
applicationId "com.massive"
|
||||||
minSdkVersion rootProject.ext.minSdkVersion
|
minSdkVersion rootProject.ext.minSdkVersion
|
||||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||||
versionCode 36220
|
versionCode 36221
|
||||||
versionName "2.5"
|
versionName "2.6"
|
||||||
}
|
}
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
release {
|
release {
|
||||||
|
@ -125,6 +125,7 @@ dependencies {
|
||||||
implementation("com.facebook.react:react-android")
|
implementation("com.facebook.react:react-android")
|
||||||
implementation 'androidx.documentfile:documentfile:1.0.1'
|
implementation 'androidx.documentfile:documentfile:1.0.1'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||||
|
implementation 'com.opencsv:opencsv:5.5.2'
|
||||||
implementation project(':react-native-sqlite-storage')
|
implementation project(':react-native-sqlite-storage')
|
||||||
implementation project(':react-native-vector-icons')
|
implementation project(':react-native-vector-icons')
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
|
import com.facebook.react.bridge.Promise
|
||||||
import com.facebook.react.bridge.ReactApplicationContext
|
import com.facebook.react.bridge.ReactApplicationContext
|
||||||
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
||||||
import com.facebook.react.bridge.ReactMethod
|
import com.facebook.react.bridge.ReactMethod
|
||||||
|
@ -73,6 +74,18 @@ class BackupModule constructor(context: ReactApplicationContext?) :
|
||||||
alarmMgr.cancel(pendingIntent)
|
alarmMgr.cancel(pendingIntent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactMethod()
|
||||||
|
fun exportToCSV(promise: Promise) {
|
||||||
|
try {
|
||||||
|
val db = DatabaseHelper(reactApplicationContext)
|
||||||
|
db.exportToCSV()
|
||||||
|
promise.resolve("Export successful!")
|
||||||
|
}
|
||||||
|
catch (e: Exception) {
|
||||||
|
promise.reject("ERROR", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
reactApplicationContext.registerReceiver(copyReceiver, IntentFilter(COPY_BROADCAST))
|
reactApplicationContext.registerReceiver(copyReceiver, IntentFilter(COPY_BROADCAST))
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,10 @@ package com.massive
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.database.sqlite.SQLiteDatabase
|
import android.database.sqlite.SQLiteDatabase
|
||||||
import android.database.sqlite.SQLiteOpenHelper
|
import android.database.sqlite.SQLiteOpenHelper
|
||||||
|
import android.os.Environment
|
||||||
|
import com.opencsv.CSVWriter
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileWriter
|
||||||
|
|
||||||
class DatabaseHelper(context: Context) :
|
class DatabaseHelper(context: Context) :
|
||||||
SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) {
|
SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) {
|
||||||
|
@ -11,6 +15,32 @@ class DatabaseHelper(context: Context) :
|
||||||
private const val DATABASE_VERSION = 1
|
private const val DATABASE_VERSION = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun exportToCSV() {
|
||||||
|
val exportDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
|
||||||
|
if (!exportDir.exists()) {
|
||||||
|
exportDir.mkdirs()
|
||||||
|
}
|
||||||
|
|
||||||
|
val file = File(exportDir, "gym_sets.csv")
|
||||||
|
file.createNewFile()
|
||||||
|
|
||||||
|
val csvWrite = CSVWriter(FileWriter(file))
|
||||||
|
val db = this.readableDatabase
|
||||||
|
val cursor = db.rawQuery("SELECT * FROM sets", null)
|
||||||
|
csvWrite.writeNext(cursor.columnNames)
|
||||||
|
|
||||||
|
while(cursor.moveToNext()) {
|
||||||
|
val arrStr = arrayOfNulls<String>(cursor.columnCount)
|
||||||
|
for(i in 0 until cursor.columnCount) {
|
||||||
|
arrStr[i] = cursor.getString(i)
|
||||||
|
}
|
||||||
|
csvWrite.writeNext(arrStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
csvWrite.close()
|
||||||
|
cursor.close()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(db: SQLiteDatabase) {
|
override fun onCreate(db: SQLiteDatabase) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "massive",
|
"name": "massive",
|
||||||
"version": "2.5",
|
"version": "2.6",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "GPL-3.0-only",
|
"license": "GPL-3.0-only",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Reference in New Issue