enrecipes/app/components/Settings.vue

164 lines
4.6 KiB
Vue
Raw Normal View History

2020-09-15 11:10:16 +00:00
<template>
2020-10-14 19:32:32 +00:00
<Page>
<ActionBar :flat="viewIsScrolled ? false : true">
<!-- Settings Actionbar -->
<GridLayout rows="*" columns="auto, *" class="actionBarContainer">
<Label
class="bx leftAction"
:text="icon.menu"
automationText="Menu"
@tap="showDrawer"
col="0"
/>
<Label class="title orkm" :text="title" col="1" />
</GridLayout>
</ActionBar>
<ScrollView scrollBarIndicatorVisible="false">
<StackLayout class="main-container">
<Label text="Interface" class="group-header" />
2020-09-15 11:10:16 +00:00
2020-10-14 19:32:32 +00:00
<StackLayout
orientation="horizontal"
class="option"
@tap="selectThemes"
>
<Label verticalAlignment="center" class="bx" :text="icon.theme" />
<StackLayout>
<Label text="Theme" class="option-title" />
<Label :text="themeName" class="option-info" textWrap="true" />
</StackLayout>
</StackLayout>
2020-09-15 11:10:16 +00:00
2020-10-14 19:32:32 +00:00
<StackLayout class="hr m-10"></StackLayout>
2020-09-15 11:10:16 +00:00
2020-10-14 19:32:32 +00:00
<Label text="Backup/Restore" class="group-header" />
<StackLayout
orientation="horizontal"
class="option"
@tap="selectBackupDir"
>
<Label verticalAlignment="center" class="bx" :text="icon.folder" />
<StackLayout>
<Label text="EnRecipes Backup Directory" class="option-title" />
<Label text="/storage/emulated/0/EnRecipes" class="option-info" />
</StackLayout>
</StackLayout>
<StackLayout orientation="horizontal" class="option" @tap="backupData">
<Label class="bx" :text="icon.backup" />
<Label text="Backup Data" class="option-title" />
</StackLayout>
<StackLayout orientation="horizontal" class="option" @tap="restoreData">
<Label class="bx" :text="icon.restore" />
<Label text="Restore Data" class="option-title" />
</StackLayout>
2020-09-15 11:10:16 +00:00
</StackLayout>
2020-10-14 19:32:32 +00:00
</ScrollView>
</Page>
2020-09-15 11:10:16 +00:00
</template>
<script>
import { Menu } from "nativescript-menu"
import * as permissions from "nativescript-permissions"
2020-10-14 19:32:32 +00:00
import * as application from "tns-core-modules/application"
import { getString, setString } from "application-settings"
import Theme from "@nativescript/theme"
import { mapState, mapActions } from "vuex"
2020-09-15 11:10:16 +00:00
export default {
2020-10-14 19:32:32 +00:00
props: ["highlight", "viewIsScrolled", "showDrawer", "title"],
2020-09-15 11:10:16 +00:00
data() {
return {
2020-10-14 19:32:32 +00:00
interface: {
theme: {
title: "Theme",
subTitle: "Light",
icon: "\ued09",
},
2020-09-15 11:10:16 +00:00
},
2020-10-14 19:32:32 +00:00
backupRestore: [
{
title: "EnRecipes Backup Directory",
subTitle: "/storage/emulated/0/EnRecipes",
icon: "\ued7c",
},
{
title: "Backup Data",
subTitle: null,
icon: "\uee48",
},
{
title: "Restore Data",
subTitle: null,
icon: "\ueadc",
},
],
2020-09-15 11:10:16 +00:00
themeName: "Light",
2020-10-14 19:32:32 +00:00
themesArray: ["Light", "Dark"],
2020-09-15 11:10:16 +00:00
}
},
2020-10-14 19:32:32 +00:00
computed: {
...mapState(["icon"]),
},
2020-09-15 11:10:16 +00:00
methods: {
selectThemes(args) {
2020-09-15 18:04:33 +00:00
this.highlight(args)
2020-09-15 11:10:16 +00:00
let btn = args.object
Menu.popup({
view: btn,
actions: this.themesArray,
})
.then((action) => {
2020-10-14 19:32:32 +00:00
this.interface.theme.subTitle = this.themeName = action.title
console.log(this.themeName)
setString("application-theme", action.title)
Theme.toggleMode()
2020-09-15 11:10:16 +00:00
})
.catch(console.log)
},
selectBackupDir(args) {
2020-09-15 18:04:33 +00:00
this.highlight(args)
2020-09-15 11:10:16 +00:00
let btn = args.object
permissions
.requestPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
.then(() => {
alert("select backup directory")
})
.catch(() => {
console.log("Uh oh, no permissions - plan B time!")
})
},
backupData(args) {
let btn = args.object
2020-09-15 18:04:33 +00:00
this.highlight(args)
2020-09-15 11:10:16 +00:00
permissions
.requestPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
.then(() => {
alert("Backup successful!")
})
.catch(() => {
console.log("Uh oh, no permissions - plan B time!")
})
},
restoreData(args) {
let btn = args.object
2020-09-15 18:04:33 +00:00
this.highlight(args)
2020-09-15 11:10:16 +00:00
permissions
.requestPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
.then(() => {
alert("Restore successful!")
})
.catch(() => {
console.log("Uh oh, no permissions - plan B time!")
})
},
},
2020-10-14 19:32:32 +00:00
created() {
this.interface.theme.subTitle = this.themeName = getString(
"application-theme",
"Light"
)
},
2020-09-15 11:10:16 +00:00
}
</script>