diff --git a/HelperFunctions/index.ts b/HelperFunctions/index.ts index 9b123e3..eaa632c 100644 --- a/HelperFunctions/index.ts +++ b/HelperFunctions/index.ts @@ -84,6 +84,11 @@ interface FilePathModuleInterface { filePath: string, callback: (success: boolean) => void, ): void; + deleteFolder( + folderPath: string, + callback: (success: boolean) => void, + ): void; + openFolder(folderPath: string, callback: (success: boolean) => void): void; ensureFolderExists( folderPath: string, callback: (success: boolean) => void, @@ -132,6 +137,22 @@ export const deleteFileIfExists = (filePath: string) => { }); }; +export const deleteFolder = (folderPath: string) => { + return new Promise((resolve) => { + FilePathModuleTyped.deleteFolder(folderPath, (success) => + resolve(success), + ); + }); +}; + +export const openFolder = (folderPath: string) => { + return new Promise((resolve) => { + FilePathModuleTyped.openFolder(folderPath, (success) => + resolve(success), + ); + }); +}; + export const ensureFolderExists = (folderPath: string) => { return new Promise((resolve) => { FilePathModuleTyped.ensureFolderExists(folderPath, (success) => diff --git a/android/app/src/main/java/com/yorha/FilePathModule.java b/android/app/src/main/java/com/yorha/FilePathModule.java index cbcba52..5bf5ade 100644 --- a/android/app/src/main/java/com/yorha/FilePathModule.java +++ b/android/app/src/main/java/com/yorha/FilePathModule.java @@ -131,6 +131,30 @@ public void deleteFileIfExists(final String filePath, Callback callBack) { } } + @ReactMethod + public void openFolder(final String folderPath, Callback callBack) { + Intent intent = new Intent(Intent.ACTION_PICK); + + intent.setDataAndType(Uri.parse(folderPath), "*/*"); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + getReactApplicationContext().startActivity(intent); + } + + @ReactMethod + public void deleteFolder(final String fileOrDirectoryPath, Callback callBack) { + deleteRecursive(new File(fileOrDirectoryPath)); + callBack.invoke(true); + } + + private void deleteRecursive(File fileOrDirectory) { + if (fileOrDirectory.exists() && fileOrDirectory.isDirectory()) { + for (File child : fileOrDirectory.listFiles()) { + deleteRecursive(child); + } + } + fileOrDirectory.delete(); + } + @ReactMethod public void ensureFolderExists(final String folderPath, Callback callBack) { File file = new File(folderPath); diff --git a/components/settingsPageComponents/SavedShowLocationSettings.tsx b/components/settingsPageComponents/SavedShowLocationSettings.tsx index 6b6ec8c..f1788c5 100644 --- a/components/settingsPageComponents/SavedShowLocationSettings.tsx +++ b/components/settingsPageComponents/SavedShowLocationSettings.tsx @@ -10,7 +10,7 @@ import { useTheme, } from 'react-native-paper'; import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs'; -import { promiseEach } from '../../HelperFunctions'; +import { deleteFolder, openFolder, promiseEach } from '../../HelperFunctions'; import { ReleasesTab } from '../ReleasesTab'; import { WatchListTab } from '../WatchListTab'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; @@ -105,6 +105,15 @@ export const SavedShowLocationSettings = () => { await Storage.setItem(StorageKeys.ShowPaths, { shows: filteredShows }); }; + const onShowRemovePress = async (show: { + showName: string; + showPath: string; + }) => { + removeShowFromSavedPaths(show.showName); + // if setting + await deleteFolder(show.showPath); + }; + const getShowPaths = () => { if (savedShowPaths?.shows.length === 0) { return ( @@ -128,7 +137,7 @@ export const SavedShowLocationSettings = () => { } return savedShowPaths?.shows.map((show, index) => { return ( - { ? colors.subsPleaseLight3 : colors.subsPleaseDark1, }} + onPress={() => openFolder(show.showPath)} > - - - {show.showName} - - - - + + + {show.showName} + + + + + {show.showPath} + + + - - + ); }); };