Fixes the 2 csv files being created on export, in Downloads
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest
|
||||||
package="com.drip">
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
package="com.drip"
|
||||||
|
>
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||||
@@ -36,9 +39,11 @@
|
|||||||
android:grantUriPermissions="true"
|
android:grantUriPermissions="true"
|
||||||
android:exported="false">
|
android:exported="false">
|
||||||
<meta-data
|
<meta-data
|
||||||
|
tools:replace="android:resource"
|
||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
android:resource="@xml/filepaths" />
|
android:resource="@xml/filepaths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
|
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
|
||||||
android:value="drip-notification"/>
|
android:value="drip-notification"/>
|
||||||
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
|
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<external-path name="Downloads" path="Download/" />
|
<external-path name="Downloads" path="Download/" />
|
||||||
|
<root-path name="root" path="" />
|
||||||
|
<files-path
|
||||||
|
name="files-path"
|
||||||
|
path="." /> <!-- Used to access into application data files -->
|
||||||
</paths>
|
</paths>
|
||||||
@@ -1,13 +1,20 @@
|
|||||||
import Share from 'react-native-share'
|
import Share from 'react-native-share'
|
||||||
|
|
||||||
|
import { getCycleDaysSortedByDate } from '../../db'
|
||||||
import getDataAsCsvDataUri from '../../lib/import-export/export-to-csv'
|
import getDataAsCsvDataUri from '../../lib/import-export/export-to-csv'
|
||||||
import alertError from './alert-error'
|
import alertError from './alert-error'
|
||||||
import { settings } from '../../i18n/en/settings'
|
import { settings } from '../../i18n/en/settings'
|
||||||
|
import RNFS from 'react-native-fs'
|
||||||
|
|
||||||
export default async function openShareDialogAndExport() {
|
export default async function exportData() {
|
||||||
let data
|
let data
|
||||||
const labels = settings.export
|
const labels = settings.export
|
||||||
|
const cycleDaysByDate = getCycleDaysSortedByDate()
|
||||||
|
|
||||||
|
if (!cycleDaysByDate.length) return alertError(labels.errors.noData)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = getDataAsCsvDataUri()
|
data = getDataAsCsvDataUri(cycleDaysByDate)
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return alertError(labels.errors.noData)
|
return alertError(labels.errors.noData)
|
||||||
}
|
}
|
||||||
@@ -17,13 +24,17 @@ export default async function openShareDialogAndExport() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const path = RNFS.DocumentDirectoryPath + '/data.csv'
|
||||||
|
await RNFS.writeFile(path, data)
|
||||||
|
|
||||||
await Share.open({
|
await Share.open({
|
||||||
title: labels.title,
|
title: labels.title,
|
||||||
url: data,
|
url: `file://${path}`,
|
||||||
subject: labels.subject,
|
subject: labels.subject,
|
||||||
type: 'text/csv',
|
type: 'text/csv',
|
||||||
showAppsToView: true
|
showAppsToView: true
|
||||||
})
|
})
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
return alertError(labels.errors.problemSharing)
|
return alertError(labels.errors.problemSharing)
|
||||||
|
|||||||
@@ -1,19 +1,8 @@
|
|||||||
import objectPath from 'object-path'
|
import objectPath from 'object-path'
|
||||||
import { Base64 } from 'js-base64'
|
|
||||||
import { getCycleDaysSortedByDate } from '../../db'
|
|
||||||
import getColumnNamesForCsv from './get-csv-column-names'
|
import getColumnNamesForCsv from './get-csv-column-names'
|
||||||
|
|
||||||
export default function makeDataURI() {
|
|
||||||
const cycleDaysSortedByDate = getCycleDaysSortedByDate()
|
|
||||||
if (!cycleDaysSortedByDate.length) return null
|
|
||||||
|
|
||||||
const csv = transformToCsv(cycleDaysSortedByDate)
|
export default function transformToCsv(cycleDays) {
|
||||||
const encoded = Base64.encodeURI(csv)
|
|
||||||
// this is the MIME type android/libcore/MimeUtils expects, so we oblige
|
|
||||||
return `data:text/comma-separated-values;base64,${encoded}`
|
|
||||||
}
|
|
||||||
|
|
||||||
function transformToCsv(cycleDays) {
|
|
||||||
const columnNames = getColumnNamesForCsv()
|
const columnNames = getColumnNamesForCsv()
|
||||||
const rows = cycleDays
|
const rows = cycleDays
|
||||||
.map(day => {
|
.map(day => {
|
||||||
@@ -23,7 +12,6 @@ function transformToCsv(cycleDays) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.map(row => row.join(','))
|
.map(row => row.join(','))
|
||||||
|
|
||||||
rows.unshift(columnNames.join(','))
|
rows.unshift(columnNames.join(','))
|
||||||
return rows.join('\n')
|
return rows.join('\n')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user