2023-04-05 14:37:50 +08:00
|
|
|
import { NavigationNative, React } from "@vendetta/metro/common";
|
2023-02-12 18:18:46 +08:00
|
|
|
import { storage } from "@vendetta/plugin";
|
|
|
|
|
import { useProxy } from "@vendetta/storage";
|
2023-02-12 20:31:51 +08:00
|
|
|
import { getAssetIDByName } from "@vendetta/ui/assets";
|
2023-02-12 18:18:46 +08:00
|
|
|
import { Forms } from "@vendetta/ui/components";
|
2023-02-12 22:48:12 +08:00
|
|
|
import { showToast } from "@vendetta/ui/toasts";
|
2023-02-12 18:18:46 +08:00
|
|
|
|
2023-02-12 20:31:51 +08:00
|
|
|
import { currentSettings } from ".";
|
2023-02-12 21:32:36 +08:00
|
|
|
import Constants from "./constants";
|
2023-02-15 15:04:37 +08:00
|
|
|
import { initialize } from "./utils";
|
2023-02-12 20:31:51 +08:00
|
|
|
|
2023-04-05 14:37:50 +08:00
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import { ScrollView, Text, TouchableOpacity } from "react-native";
|
|
|
|
|
|
2023-02-12 22:48:12 +08:00
|
|
|
const { FormInput, FormDivider, FormSwitchRow, FormText, FormIcon } = Forms;
|
2023-02-12 16:33:21 +08:00
|
|
|
|
2023-02-13 20:47:20 +08:00
|
|
|
function UpdateButton() {
|
|
|
|
|
async function onPressCallback() {
|
|
|
|
|
for (const key in storage) {
|
2023-02-13 21:51:43 +08:00
|
|
|
if (storage[key] === false || storage[key]) {
|
2023-02-13 20:47:20 +08:00
|
|
|
currentSettings[key] = storage[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("Applying settings...");
|
|
|
|
|
await initialize();
|
|
|
|
|
showToast("Settings updated!", getAssetIDByName("Check"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <TouchableOpacity onPress={onPressCallback}>
|
2023-02-13 21:48:12 +08:00
|
|
|
<FormText style={{ marginRight: 12 }}>UPDATE</FormText>
|
2023-02-13 20:47:20 +08:00
|
|
|
</TouchableOpacity>;
|
|
|
|
|
|
|
|
|
|
}
|
2023-02-15 15:04:37 +08:00
|
|
|
|
2023-02-12 16:33:21 +08:00
|
|
|
export default function Settings() {
|
2023-04-05 17:43:33 +08:00
|
|
|
const settings = useProxy(storage) as LFMSettings;
|
2023-02-12 18:18:46 +08:00
|
|
|
const navigation = NavigationNative.useNavigation();
|
|
|
|
|
|
2023-04-05 14:37:50 +08:00
|
|
|
useEffect(() => {
|
2023-02-12 18:18:46 +08:00
|
|
|
navigation.setOptions({
|
2023-02-13 00:41:37 +08:00
|
|
|
title: "Last.fm Configuration",
|
2023-02-13 20:47:20 +08:00
|
|
|
headerRight: UpdateButton
|
2023-02-12 18:18:46 +08:00
|
|
|
});
|
|
|
|
|
}, []);
|
|
|
|
|
|
2023-02-12 16:33:21 +08:00
|
|
|
return (
|
2023-02-12 18:18:46 +08:00
|
|
|
<ScrollView>
|
|
|
|
|
<FormInput
|
2023-02-12 20:31:51 +08:00
|
|
|
value={settings.appName || undefined}
|
2023-02-12 18:18:46 +08:00
|
|
|
onChangeText={(value: string) => settings.appName = value.trim()}
|
2023-02-12 20:31:51 +08:00
|
|
|
title="Discord Application Name"
|
2023-02-12 21:32:36 +08:00
|
|
|
placeholder={Constants.DEFAULT_APP_NAME}
|
2023-02-12 18:18:46 +08:00
|
|
|
returnKeyType="done"
|
|
|
|
|
/>
|
|
|
|
|
<FormDivider />
|
2023-02-12 20:31:51 +08:00
|
|
|
<FormInput required
|
|
|
|
|
value={settings.username || undefined}
|
2023-02-12 18:18:46 +08:00
|
|
|
onChangeText={(value: string) => settings.username = value.trim()}
|
2023-02-12 20:31:51 +08:00
|
|
|
title="Last.fm username"
|
|
|
|
|
helpText={!settings.username && <Text style={{ color: "#FF0000" }}>{"This field is required!"}</Text>}
|
2023-02-12 18:18:46 +08:00
|
|
|
placeholder="wumpus123"
|
|
|
|
|
returnKeyType="done"
|
|
|
|
|
/>
|
|
|
|
|
<FormDivider />
|
2023-02-13 21:48:12 +08:00
|
|
|
<FormInput
|
|
|
|
|
value={settings.timeInterval}
|
2023-04-07 22:02:32 +08:00
|
|
|
onChangeText={(value: string) => settings.timeInterval = value}
|
2023-02-13 21:48:12 +08:00
|
|
|
title="Update interval (in seconds)"
|
|
|
|
|
placeholder={Constants.DEFAULT_TIME_INTERVAL.toString()}
|
|
|
|
|
keyboardType="numeric"
|
|
|
|
|
returnKeyType="done"
|
|
|
|
|
/>
|
|
|
|
|
<FormDivider />
|
2023-02-12 18:18:46 +08:00
|
|
|
<FormSwitchRow
|
|
|
|
|
label="Show time elapsed"
|
|
|
|
|
subLabel="Show the time elapsed since the song started playing"
|
2023-02-12 20:31:51 +08:00
|
|
|
leading={<FormIcon source={getAssetIDByName("clock")} />}
|
2023-02-12 18:18:46 +08:00
|
|
|
value={settings.showTimestamp}
|
|
|
|
|
onValueChange={(value: boolean) => settings.showTimestamp = value}
|
|
|
|
|
/>
|
|
|
|
|
<FormDivider />
|
|
|
|
|
<FormSwitchRow
|
|
|
|
|
label="Set status as listening"
|
|
|
|
|
subLabel='Set your status as "Listening to" instead of "Playing"'
|
2023-02-12 20:31:51 +08:00
|
|
|
leading={<FormIcon source={getAssetIDByName("ic_headset_neutral")} />}
|
2023-02-12 18:18:46 +08:00
|
|
|
value={settings.listeningTo}
|
|
|
|
|
onValueChange={(value: boolean) => settings.listeningTo = value}
|
|
|
|
|
/>
|
|
|
|
|
<FormDivider />
|
2023-03-16 21:47:54 +08:00
|
|
|
<FormSwitchRow
|
|
|
|
|
label="Hide when Spotify is running"
|
|
|
|
|
subLabel="Hide the status when a Spotify activity is detected"
|
|
|
|
|
leading={<FormIcon source={getAssetIDByName("img_account_sync_spotify_light_and_dark")} />}
|
|
|
|
|
value={settings.ignoreSpotify}
|
|
|
|
|
onValueChange={(value: boolean) => settings.ignoreSpotify = value}
|
|
|
|
|
/>
|
|
|
|
|
<FormDivider />
|
2023-02-12 18:18:46 +08:00
|
|
|
<FormSwitchRow
|
|
|
|
|
label="Verbose logging"
|
|
|
|
|
subLabel="Log more information to the console for debugging purposes"
|
2023-02-13 20:47:20 +08:00
|
|
|
leading={<FormIcon source={getAssetIDByName("pencil")} />}
|
2023-02-12 18:18:46 +08:00
|
|
|
value={settings.verboseLogging}
|
|
|
|
|
onValueChange={(value: boolean) => settings.verboseLogging = value}
|
|
|
|
|
/>
|
|
|
|
|
</ScrollView>
|
2023-02-12 22:48:12 +08:00
|
|
|
);
|
2023-02-12 16:33:21 +08:00
|
|
|
}
|