enrecipes/app/components/settings/CTSettings.vue

162 lines
4.3 KiB
Vue
Raw Normal View History

2021-05-25 14:32:53 +00:00
<template>
2021-06-15 11:04:42 +00:00
<Page @loaded="pgLoad" actionBarHidden="true">
<RGridLayout :rtl="RTL" rows="*, auto" columns="auto, *">
2021-05-25 14:32:53 +00:00
<OptionsList title="Settings" :items="items" />
2021-06-15 11:04:42 +00:00
<GridLayout row="1" class="appbar rtl" rows="*" columns="auto, *">
2021-06-20 17:54:47 +00:00
<Button class="ico end" :text="icon.back" @tap="$navigateBack()" />
2021-05-25 14:32:53 +00:00
</GridLayout>
2021-06-18 12:52:03 +00:00
<Label rowSpan="2" class="edge hal rtl" @swipe="swipeBack" />
<Label
rowSpan="2"
colSpan="2"
class="edge har rtl f"
@swipe="swipeBack"
/>
2021-06-15 11:04:42 +00:00
</RGridLayout>
2021-05-25 14:32:53 +00:00
</Page>
</template>
<script>
2021-06-15 11:04:42 +00:00
import {
Observable,
Device,
Application,
ApplicationSettings,
Utils,
} from "@nativescript/core";
2021-05-25 14:32:53 +00:00
import { mapState, mapActions } from "vuex";
import { localize } from "@nativescript/localize";
import OptionsList from "../sub/OptionsList";
import Action from "../modals/Action";
import * as utils from "~/shared/utils";
export default {
components: { OptionsList },
computed: {
2021-06-18 18:37:01 +00:00
...mapState(["icon", "timerD", "timerS", "timerV", "RTL"]),
2021-05-25 14:32:53 +00:00
items() {
let options = [
{
type: "list",
icon: "sound",
2021-06-15 11:04:42 +00:00
rtl: 0,
2021-05-25 14:32:53 +00:00
title: "tmrSnd",
2021-06-18 18:37:01 +00:00
subTitle: this.timerS.title,
2021-05-25 14:32:53 +00:00
action: this.showSoundsList,
},
{
type: "switch",
icon: "vibrate",
2021-06-15 11:04:42 +00:00
rtl: 0,
2021-05-25 14:32:53 +00:00
title: "tmrvbrt",
2021-06-18 18:37:01 +00:00
checked: !!this.timerV,
2021-05-25 14:32:53 +00:00
action: this.toggleTimerVibrate,
},
];
let openSettings = [
{
type: "list",
icon: "sound",
2021-06-15 11:04:42 +00:00
rtl: 0,
2021-05-25 14:32:53 +00:00
title: "notifSetg",
subTitle: null,
action: this.openNotificationChannelSettings,
},
];
let list = this.channelExists() ? openSettings : options;
return [
{},
{
type: "list",
icon: "delay",
2021-06-15 11:04:42 +00:00
rtl: 0,
2021-05-25 14:32:53 +00:00
title: "dlyDur",
2021-06-15 11:04:42 +00:00
subTitle:
2021-06-18 18:37:01 +00:00
this.delayList[this.delayList.findIndex((e) => e.n == this.timerD)]
.l,
2021-05-25 14:32:53 +00:00
action: this.showDelayList,
},
...list,
{},
];
},
2021-06-15 11:04:42 +00:00
delayList() {
return [
...Array.from(Array(4), (_, x) => x + 1),
...Array.from(Array(6), (_, x) => (x + 1) * 5),
].map((e) => {
return {
2021-06-18 18:37:01 +00:00
l: `${this.localeN(e)} ${localize(e > 1 ? "minutes" : "minute")}`,
2021-06-15 11:04:42 +00:00
n: e,
};
});
},
2021-05-25 14:32:53 +00:00
},
methods: {
2021-06-18 18:37:01 +00:00
...mapActions(["setTD", "setTS", "setTV"]),
2021-06-15 11:04:42 +00:00
pgLoad({ object }) {
2021-05-25 14:32:53 +00:00
object.bindingContext = new Observable();
2021-06-15 11:04:42 +00:00
ApplicationSettings.setNumber("isTimer", 2);
2021-05-25 14:32:53 +00:00
},
showDelayList() {
this.$showModal(Action, {
props: {
title: "dlyDur",
2021-06-15 11:04:42 +00:00
list: this.delayList.map((e) => e.l),
2021-06-18 18:37:01 +00:00
selected: this.delayList.findIndex((e) => e.n == this.timerD),
2021-05-25 14:32:53 +00:00
},
2021-06-15 11:04:42 +00:00
}).then(
(res) =>
res &&
2021-06-18 18:37:01 +00:00
this.setTD(
2021-06-15 11:04:42 +00:00
this.delayList[this.delayList.findIndex((e) => e.l == res)].n
)
);
2021-05-25 14:32:53 +00:00
},
showSoundsList() {
let getTones = utils.getTones();
this.$showModal(Action, {
props: {
title: "tmrSnd",
list: getTones.tones.map((e) => e.title),
2021-06-18 12:52:03 +00:00
selected: getTones.tones.findIndex(
2021-06-18 18:37:01 +00:00
(e) => e.title == this.timerS.title
2021-06-18 12:52:03 +00:00
),
2021-05-25 14:32:53 +00:00
},
}).then(
(tone) =>
tone &&
2021-06-18 18:37:01 +00:00
tone !== this.timerS.title &&
this.setTS(getTones.tones.filter((e) => e.title === tone)[0])
2021-05-25 14:32:53 +00:00
);
},
toggleTimerVibrate() {
2021-06-18 18:37:01 +00:00
this.setTV(!this.timerV | 0);
2021-05-25 14:32:53 +00:00
},
openNotificationChannelSettings() {
const ctx = Application.android.context;
const Settings = android.provider.Settings;
const Intent = android.content.Intent;
let intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(
Settings.EXTRA_APP_PACKAGE,
Application.android.packageName
);
intent.putExtra(Settings.EXTRA_CHANNEL_ID, "cta");
intent.setFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(intent);
},
channelExists() {
if (Device.sdkVersion * 1 >= 26) {
const ctx = Utils.ad.getApplicationContext();
const NotifySrv = ctx.getSystemService(
android.content.Context.NOTIFICATION_SERVICE
);
return NotifySrv.getNotificationChannel("cta");
}
return null;
},
},
};
</script>