From 71e34a606664b57317a7763e9fe5a9c3c9c9ff7c Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Sun, 27 Jun 2021 09:50:16 +0900 Subject: [PATCH] switching to async storage also switching to not storing music data from api unless downloaded --- android/build.gradle | 6 ++ android/gradle.properties | 4 + package-lock.json | 95 ++++++++++++++++++++---- package.json | 1 + src/clients.ts | 2 - src/components/Settings.tsx | 27 +++---- src/components/SplashPage.tsx | 6 +- src/components/library/AlbumsTab.tsx | 41 +++++++---- src/components/library/ArtistsTab.tsx | 16 +++- src/models/music.ts | 6 +- src/models/settings.ts | 5 +- src/state/music.ts | 101 +++++++++++++++++++------- src/state/settings.ts | 31 ++------ src/storage/asyncstorage.ts | 98 +++++++++++++++++++++++++ src/storage/settings.ts | 101 +++----------------------- src/subsonic/api.ts | 10 ++- 16 files changed, 350 insertions(+), 200 deletions(-) create mode 100644 src/storage/asyncstorage.ts diff --git a/android/build.gradle b/android/build.gradle index 93232f5..00155ba 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -7,6 +7,9 @@ buildscript { compileSdkVersion = 29 targetSdkVersion = 29 ndkVersion = "20.1.5948944" + + // react-native-async-storage next + kotlinVersion = '1.4.21' } repositories { google() @@ -16,6 +19,9 @@ buildscript { classpath("com.android.tools.build:gradle:4.1.0") // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files + + // react-native-async-storage next + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" } } diff --git a/android/gradle.properties b/android/gradle.properties index d21d03f..6517885 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -26,3 +26,7 @@ android.enableJetifier=true # Version of flipper SDK to use with React Native FLIPPER_VERSION=0.75.1 + +# react-native-async-storage next +AsyncStorage_useNextStorage=true +AsyncStorage_kotlinVersion=1.4.21 diff --git a/package-lock.json b/package-lock.json index 6874156..c30a3e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "subsonify", "version": "0.0.1", "dependencies": { + "@react-native-async-storage/async-storage": "^1.15.5", "@react-native-community/masked-view": "^0.1.11", "@react-navigation/bottom-tabs": "^5.11.11", "@react-navigation/material-top-tabs": "^5.3.15", @@ -1768,6 +1769,17 @@ "node": ">=8" } }, + "node_modules/@react-native-async-storage/async-storage": { + "version": "1.15.5", + "resolved": "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-1.15.5.tgz", + "integrity": "sha512-4AYehLH39B9a8UXCMf3ieOK+G61wGMP72ikx6/XSMA0DUnvx0PgaeaT2Wyt06kTrDTy8edewKnbrbeqwaM50TQ==", + "dependencies": { + "deep-assign": "^3.0.0" + }, + "peerDependencies": { + "react-native": "^0.60.6 || ^0.61.5 || ^0.62.2 || ^0.63.2 || ^0.64.0 || 1000.0.0" + } + }, "node_modules/@react-native-community/cli": { "version": "5.0.1-alpha.2", "resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-5.0.1-alpha.2.tgz", @@ -4491,6 +4503,18 @@ "node": ">=0.10" } }, + "node_modules/deep-assign": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/deep-assign/-/deep-assign-3.0.0.tgz", + "integrity": "sha512-YX2i9XjJ7h5q/aQ/IM9PEwEnDqETAIYbggmdDB3HLTlSgo1CxPsj6pvhPG68rq6SVE0+p+6Ywsm5fTYNrYtBWw==", + "deprecated": "Check out `lodash.merge` or `merge-options` instead.", + "dependencies": { + "is-obj": "^1.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", @@ -6664,6 +6688,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-obj": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", + "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/is-plain-object": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", @@ -14558,6 +14590,14 @@ } } }, + "@react-native-async-storage/async-storage": { + "version": "1.15.5", + "resolved": "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-1.15.5.tgz", + "integrity": "sha512-4AYehLH39B9a8UXCMf3ieOK+G61wGMP72ikx6/XSMA0DUnvx0PgaeaT2Wyt06kTrDTy8edewKnbrbeqwaM50TQ==", + "requires": { + "deep-assign": "^3.0.0" + } + }, "@react-native-community/cli": { "version": "5.0.1-alpha.2", "resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-5.0.1-alpha.2.tgz", @@ -15132,7 +15172,8 @@ "@react-native-community/masked-view": { "version": "0.1.11", "resolved": "https://registry.npmjs.org/@react-native-community/masked-view/-/masked-view-0.1.11.tgz", - "integrity": "sha512-rQfMIGSR/1r/SyN87+VD8xHHzDYeHaJq6elOSCAD+0iLagXkSI2pfA0LmSXP21uw5i3em7GkkRjfJ8wpqWXZNw==" + "integrity": "sha512-rQfMIGSR/1r/SyN87+VD8xHHzDYeHaJq6elOSCAD+0iLagXkSI2pfA0LmSXP21uw5i3em7GkkRjfJ8wpqWXZNw==", + "requires": {} }, "@react-native/assets": { "version": "1.0.0", @@ -15621,7 +15662,8 @@ "version": "5.3.1", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.1.tgz", "integrity": "sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==", - "dev": true + "dev": true, + "requires": {} }, "acorn-walk": { "version": "7.2.0", @@ -15840,7 +15882,8 @@ "babel-core": { "version": "7.0.0-bridge.0", "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-7.0.0-bridge.0.tgz", - "integrity": "sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==" + "integrity": "sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==", + "requires": {} }, "babel-eslint": { "version": "10.1.0", @@ -16692,6 +16735,14 @@ "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz", "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=" }, + "deep-assign": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/deep-assign/-/deep-assign-3.0.0.tgz", + "integrity": "sha512-YX2i9XjJ7h5q/aQ/IM9PEwEnDqETAIYbggmdDB3HLTlSgo1CxPsj6pvhPG68rq6SVE0+p+6Ywsm5fTYNrYtBWw==", + "requires": { + "is-obj": "^1.0.0" + } + }, "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", @@ -17161,7 +17212,8 @@ "version": "22.4.1", "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-22.4.1.tgz", "integrity": "sha512-gcLfn6P2PrFAVx3AobaOzlIEevpAEf9chTpFZz7bYfc7pz8XRv7vuKTIE4hxPKZSha6XWKKplDQ0x9Pq8xX2mg==", - "dev": true + "dev": true, + "requires": {} }, "eslint-plugin-prettier": { "version": "3.1.2", @@ -17217,7 +17269,8 @@ "version": "4.2.0", "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.2.0.tgz", "integrity": "sha512-623WEiZJqxR7VdxFCKLI6d6LLpwJkGPYKODnkH3D7WpOG5KM8yWueBd8TLsNAetEJNF5iJmolaAKO3F8yzyVBQ==", - "dev": true + "dev": true, + "requires": {} }, "eslint-plugin-react-native": { "version": "3.11.0", @@ -18314,6 +18367,11 @@ "integrity": "sha512-RU0lI/n95pMoUKu9v1BZP5MBcZuNSVJkMkAG2dJqC4z2GlkGUNeH68SuHuBKBD/XFe+LHZ+f9BKkLET60Niedw==", "dev": true }, + "is-obj": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", + "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=" + }, "is-plain-object": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", @@ -19064,7 +19122,8 @@ "version": "1.2.2", "resolved": "https://registry.npmjs.org/jest-pnp-resolver/-/jest-pnp-resolver-1.2.2.tgz", "integrity": "sha512-olV41bKSMm8BdnuMsewT4jqlZ8+3TCARAXjZGT9jcoSnrfUnRCqnMoF9XEeoWjbzObpqF9dRhHQj0Xb9QdF6/w==", - "dev": true + "dev": true, + "requires": {} }, "jest-regex-util": { "version": "26.0.0", @@ -21277,7 +21336,8 @@ "react-native-fast-image": { "version": "8.3.4", "resolved": "https://registry.npmjs.org/react-native-fast-image/-/react-native-fast-image-8.3.4.tgz", - "integrity": "sha512-LpzAdjUphihUpVEBn5fEv5AILe55rHav0YiZroPZ1rumKDhAl4u2cG01ku2Pb7l8sayjTsNu7FuURAlXUUDsow==" + "integrity": "sha512-LpzAdjUphihUpVEBn5fEv5AILe55rHav0YiZroPZ1rumKDhAl4u2cG01ku2Pb7l8sayjTsNu7FuURAlXUUDsow==", + "requires": {} }, "react-native-fs": { "version": "2.18.0", @@ -21311,12 +21371,14 @@ "react-native-iphone-x-helper": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/react-native-iphone-x-helper/-/react-native-iphone-x-helper-1.3.1.tgz", - "integrity": "sha512-HOf0jzRnq2/aFUcdCJ9w9JGzN3gdEg0zFE4FyYlp4jtidqU03D5X7ZegGKfT1EWteR0gPBGp9ye5T5FvSWi9Yg==" + "integrity": "sha512-HOf0jzRnq2/aFUcdCJ9w9JGzN3gdEg0zFE4FyYlp4jtidqU03D5X7ZegGKfT1EWteR0gPBGp9ye5T5FvSWi9Yg==", + "requires": {} }, "react-native-linear-gradient": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/react-native-linear-gradient/-/react-native-linear-gradient-2.5.6.tgz", - "integrity": "sha512-HDwEaXcQIuXXCV70O+bK1rizFong3wj+5Q/jSyifKFLg0VWF95xh8XQgfzXwtq0NggL9vNjPKXa016KuFu+VFg==" + "integrity": "sha512-HDwEaXcQIuXXCV70O+bK1rizFong3wj+5Q/jSyifKFLg0VWF95xh8XQgfzXwtq0NggL9vNjPKXa016KuFu+VFg==", + "requires": {} }, "react-native-reanimated": { "version": "2.2.0", @@ -21332,7 +21394,8 @@ "react-native-safe-area-context": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/react-native-safe-area-context/-/react-native-safe-area-context-3.2.0.tgz", - "integrity": "sha512-k2Nty4PwSnrg9HwrYeeE+EYqViYJoOFwEy9LxL5RIRfoqxAq/uQXNGwpUg2/u4gnKpBbEPa9eRh15KKMe/VHkA==" + "integrity": "sha512-k2Nty4PwSnrg9HwrYeeE+EYqViYJoOFwEy9LxL5RIRfoqxAq/uQXNGwpUg2/u4gnKpBbEPa9eRh15KKMe/VHkA==", + "requires": {} }, "react-native-screens": { "version": "3.4.0", @@ -21345,17 +21408,20 @@ "react-native-sqlite-storage": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/react-native-sqlite-storage/-/react-native-sqlite-storage-5.0.0.tgz", - "integrity": "sha512-c1Joq3/tO1nmIcP8SkRZNolPSbfvY8uZg5lXse0TmjIPC0qHVbk96IMvWGyly1TmYCIpxpuDRc0/xCffDbYIvg==" + "integrity": "sha512-c1Joq3/tO1nmIcP8SkRZNolPSbfvY8uZg5lXse0TmjIPC0qHVbk96IMvWGyly1TmYCIpxpuDRc0/xCffDbYIvg==", + "requires": {} }, "react-native-tab-view": { "version": "2.16.0", "resolved": "https://registry.npmjs.org/react-native-tab-view/-/react-native-tab-view-2.16.0.tgz", - "integrity": "sha512-ac2DmT7+l13wzIFqtbfXn4wwfgtPoKzWjjZyrK1t+T8sdemuUvD4zIt+UImg03fu3s3VD8Wh/fBrIdcqQyZJWg==" + "integrity": "sha512-ac2DmT7+l13wzIFqtbfXn4wwfgtPoKzWjjZyrK1t+T8sdemuUvD4zIt+UImg03fu3s3VD8Wh/fBrIdcqQyZJWg==", + "requires": {} }, "react-native-track-player": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/react-native-track-player/-/react-native-track-player-1.2.7.tgz", - "integrity": "sha512-U1kA25qm398/kY6BvTojGHt4S1tYuKrJNQpXW+dA+p0B+n4LlPyoidUXfu951YM7aoisg8EmQPsevUFmcXG+cg==" + "integrity": "sha512-U1kA25qm398/kY6BvTojGHt4S1tYuKrJNQpXW+dA+p0B+n4LlPyoidUXfu951YM7aoisg8EmQPsevUFmcXG+cg==", + "requires": {} }, "react-refresh": { "version": "0.4.3", @@ -23302,7 +23368,8 @@ "ws": { "version": "7.4.6", "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", - "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==" + "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==", + "requires": {} }, "xcode": { "version": "2.1.0", diff --git a/package.json b/package.json index b1b7b58..0c379c2 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "lint": "eslint . --ext .js,.jsx,.ts,.tsx" }, "dependencies": { + "@react-native-async-storage/async-storage": "^1.15.5", "@react-native-community/masked-view": "^0.1.11", "@react-navigation/bottom-tabs": "^5.11.11", "@react-navigation/material-top-tabs": "^5.3.15", diff --git a/src/clients.ts b/src/clients.ts index c4a579d..85944d3 100644 --- a/src/clients.ts +++ b/src/clients.ts @@ -1,6 +1,4 @@ import { MusicDb } from "./storage/music"; -import { SettingsDb } from "./storage/settings"; import { SubsonicApiClient } from "./subsonic/api"; export const musicDb = new MusicDb(); -export const settingsDb = new SettingsDb(); diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx index a3aaae4..d10cdba 100644 --- a/src/components/Settings.tsx +++ b/src/components/Settings.tsx @@ -3,8 +3,8 @@ import { Button, TextInput, View, Text } from 'react-native'; import { useRecoilState } from 'recoil'; import { v4 as uuidv4 } from 'uuid'; import md5 from 'md5'; -import { musicDb, settingsDb } from '../clients'; -import { appSettingsState, serversState } from '../state/settings'; +import { musicDb } from '../clients'; +import { appSettingsState } from '../state/settings'; import { DbStorage } from '../storage/db'; import { StackScreenProps } from '@react-navigation/stack'; import { useNavigation } from '@react-navigation/core'; @@ -36,7 +36,6 @@ const DbControls = () => { return ( -