Skip to content

Commit

Permalink
Delete folder on series removal
Browse files Browse the repository at this point in the history
Try open folder on series folder path press
  • Loading branch information
Leapward-Koex committed Oct 1, 2022
1 parent bb2fe2d commit c679da3
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 29 deletions.
21 changes: 21 additions & 0 deletions HelperFunctions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -132,6 +137,22 @@ export const deleteFileIfExists = (filePath: string) => {
});
};

export const deleteFolder = (folderPath: string) => {
return new Promise<boolean>((resolve) => {
FilePathModuleTyped.deleteFolder(folderPath, (success) =>
resolve(success),
);
});
};

export const openFolder = (folderPath: string) => {
return new Promise<boolean>((resolve) => {
FilePathModuleTyped.openFolder(folderPath, (success) =>
resolve(success),
);
});
};

export const ensureFolderExists = (folderPath: string) => {
return new Promise<boolean>((resolve) => {
FilePathModuleTyped.ensureFolderExists(folderPath, (success) =>
Expand Down
24 changes: 24 additions & 0 deletions android/app/src/main/java/com/yorha/FilePathModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
78 changes: 49 additions & 29 deletions components/settingsPageComponents/SavedShowLocationSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 (
Expand All @@ -128,7 +137,7 @@ export const SavedShowLocationSettings = () => {
}
return savedShowPaths?.shows.map((show, index) => {
return (
<View
<TouchableRipple
key={index}
style={{
position: 'relative',
Expand All @@ -141,36 +150,47 @@ export const SavedShowLocationSettings = () => {
? colors.subsPleaseLight3
: colors.subsPleaseDark1,
}}
onPress={() => openFolder(show.showPath)}
>
<View style={{ width: width - 120 }}>
<Text
style={Object.assign({ fontSize: 20 }, textStyle)}
>
{show.showName}
</Text>
</View>
<View style={{ marginLeft: 10, marginTop: 5 }}>
<Text
style={Object.assign({ fontSize: 16 }, textStyle)}
<View>
<View style={{ width: width - 120 }}>
<Text
style={Object.assign(
{ fontSize: 20 },
textStyle,
)}
>
{show.showName}
</Text>
</View>
<View style={{ marginLeft: 10, marginTop: 5 }}>
<Text
style={Object.assign(
{ fontSize: 16 },
textStyle,
)}
>
{show.showPath}
</Text>
</View>
<Button
mode="text"
compact
color={colors.tertiary}
onPress={() => onShowRemovePress(show)}
style={{ position: 'absolute', right: 4, top: 4 }}
>
{show.showPath}
</Text>
<Icon
name="trash-can-outline"
size={20}
color={colors.tertiary}
/>
<Text style={{ color: colors.tertiary }}>
Remove
</Text>
</Button>
</View>
<Button
mode="text"
compact
color={colors.tertiary}
onPress={() => removeShowFromSavedPaths(show.showName)}
style={{ position: 'absolute', right: 4, top: 4 }}
>
<Icon
name="trash-can-outline"
size={20}
color={colors.tertiary}
/>
<Text style={{ color: colors.tertiary }}>Remove</Text>
</Button>
</View>
</TouchableRipple>
);
});
};
Expand Down

0 comments on commit c679da3

Please sign in to comment.