mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
recommendation country set from settings suport added
This commit is contained in:
parent
0036df6e12
commit
f7510d7eae
@ -27,6 +27,7 @@ import 'package:spotube/models/Logger.dart';
|
|||||||
import 'package:spotube/models/generated_secrets.dart';
|
import 'package:spotube/models/generated_secrets.dart';
|
||||||
import 'package:spotube/provider/Auth.dart';
|
import 'package:spotube/provider/Auth.dart';
|
||||||
import 'package:spotube/provider/SpotifyDI.dart';
|
import 'package:spotube/provider/SpotifyDI.dart';
|
||||||
|
import 'package:spotube/provider/UserPreferences.dart';
|
||||||
|
|
||||||
List<String> spotifyScopes = [
|
List<String> spotifyScopes = [
|
||||||
"playlist-modify-public",
|
"playlist-modify-public",
|
||||||
@ -47,6 +48,9 @@ class Home extends HookConsumerWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, ref) {
|
Widget build(BuildContext context, ref) {
|
||||||
Auth auth = ref.watch(authProvider);
|
Auth auth = ref.watch(authProvider);
|
||||||
|
String recommendationMarket = ref.watch(userPreferencesProvider.select(
|
||||||
|
(value) => (value.recommendationMarket),
|
||||||
|
));
|
||||||
|
|
||||||
final pagingController =
|
final pagingController =
|
||||||
usePagingController<int, Category>(firstPageKey: 0);
|
usePagingController<int, Category>(firstPageKey: 0);
|
||||||
@ -67,9 +71,11 @@ class Home extends HookConsumerWidget {
|
|||||||
|
|
||||||
final listener = useCallback((int pageKey) async {
|
final listener = useCallback((int pageKey) async {
|
||||||
final spotify = ref.read(spotifyProvider);
|
final spotify = ref.read(spotifyProvider);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Page<Category> categories =
|
Page<Category> categories = await spotify.categories
|
||||||
await spotify.categories.list(country: "US").getPage(15, pageKey);
|
.list(country: recommendationMarket)
|
||||||
|
.getPage(15, pageKey);
|
||||||
|
|
||||||
final items = categories.items!.toList();
|
final items = categories.items!.toList();
|
||||||
if (pageKey == 0) {
|
if (pageKey == 0) {
|
||||||
@ -88,7 +94,7 @@ class Home extends HookConsumerWidget {
|
|||||||
pagingController.error = e;
|
pagingController.error = e;
|
||||||
logger.e("pagingController.addPageRequestListener", e, stack);
|
logger.e("pagingController.addPageRequestListener", e, stack);
|
||||||
}
|
}
|
||||||
}, []);
|
}, [recommendationMarket]);
|
||||||
|
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
if (localStorage == null) return null;
|
if (localStorage == null) return null;
|
||||||
|
@ -9,6 +9,7 @@ import 'package:spotube/components/Settings/SettingsHotkeyTile.dart';
|
|||||||
import 'package:spotube/components/Shared/Hyperlink.dart';
|
import 'package:spotube/components/Shared/Hyperlink.dart';
|
||||||
import 'package:spotube/components/Shared/PageWindowTitleBar.dart';
|
import 'package:spotube/components/Shared/PageWindowTitleBar.dart';
|
||||||
import 'package:spotube/models/LocalStorageKeys.dart';
|
import 'package:spotube/models/LocalStorageKeys.dart';
|
||||||
|
import 'package:spotube/models/SpotifyMarkets.dart';
|
||||||
import 'package:spotube/provider/Auth.dart';
|
import 'package:spotube/provider/Auth.dart';
|
||||||
import 'package:spotube/provider/ThemeProvider.dart';
|
import 'package:spotube/provider/ThemeProvider.dart';
|
||||||
import 'package:spotube/provider/UserPreferences.dart';
|
import 'package:spotube/provider/UserPreferences.dart';
|
||||||
@ -142,6 +143,26 @@ class Settings extends HookConsumerWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
const Text("Market Place (Recommendation Country)"),
|
||||||
|
DropdownButton(
|
||||||
|
value: preferences.recommendationMarket,
|
||||||
|
items: spotifyMarkets
|
||||||
|
.map((country) => (DropdownMenuItem(
|
||||||
|
child: Text(country),
|
||||||
|
value: country,
|
||||||
|
)))
|
||||||
|
.toList(),
|
||||||
|
onChanged: (value) {
|
||||||
|
if (value == null) return;
|
||||||
|
preferences.setRecommendationMarket(value as String);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
if (auth.isAnonymous)
|
if (auth.isAnonymous)
|
||||||
Wrap(
|
Wrap(
|
||||||
spacing: 20,
|
spacing: 20,
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:collection/collection.dart';
|
|
||||||
import 'package:spotify/spotify.dart';
|
import 'package:spotify/spotify.dart';
|
||||||
import 'package:youtube_explode_dart/youtube_explode_dart.dart';
|
import 'package:youtube_explode_dart/youtube_explode_dart.dart';
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
abstract class LocalStorageKeys {
|
abstract class LocalStorageKeys {
|
||||||
|
static String recommendationMarket = 'recommendation_market';
|
||||||
static String clientId = 'client_id';
|
static String clientId = 'client_id';
|
||||||
static String clientSecret = 'client_secret';
|
static String clientSecret = 'client_secret';
|
||||||
static String accessToken = 'access_token';
|
static String accessToken = 'access_token';
|
||||||
|
186
lib/models/SpotifyMarkets.dart
Normal file
186
lib/models/SpotifyMarkets.dart
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
final spotifyMarkets = [
|
||||||
|
"AD",
|
||||||
|
"AE",
|
||||||
|
"AG",
|
||||||
|
"AL",
|
||||||
|
"AM",
|
||||||
|
"AO",
|
||||||
|
"AR",
|
||||||
|
"AT",
|
||||||
|
"AU",
|
||||||
|
"AZ",
|
||||||
|
"BA",
|
||||||
|
"BB",
|
||||||
|
"BD",
|
||||||
|
"BE",
|
||||||
|
"BF",
|
||||||
|
"BG",
|
||||||
|
"BH",
|
||||||
|
"BI",
|
||||||
|
"BJ",
|
||||||
|
"BN",
|
||||||
|
"BO",
|
||||||
|
"BR",
|
||||||
|
"BS",
|
||||||
|
"BT",
|
||||||
|
"BW",
|
||||||
|
"BY",
|
||||||
|
"BZ",
|
||||||
|
"CA",
|
||||||
|
"CD",
|
||||||
|
"CG",
|
||||||
|
"CH",
|
||||||
|
"CI",
|
||||||
|
"CL",
|
||||||
|
"CM",
|
||||||
|
"CO",
|
||||||
|
"CR",
|
||||||
|
"CV",
|
||||||
|
"CW",
|
||||||
|
"CY",
|
||||||
|
"CZ",
|
||||||
|
"DE",
|
||||||
|
"DJ",
|
||||||
|
"DK",
|
||||||
|
"DM",
|
||||||
|
"DO",
|
||||||
|
"DZ",
|
||||||
|
"EC",
|
||||||
|
"EE",
|
||||||
|
"EG",
|
||||||
|
"ES",
|
||||||
|
"FI",
|
||||||
|
"FJ",
|
||||||
|
"FM",
|
||||||
|
"FR",
|
||||||
|
"GA",
|
||||||
|
"GB",
|
||||||
|
"GD",
|
||||||
|
"GE",
|
||||||
|
"GH",
|
||||||
|
"GM",
|
||||||
|
"GN",
|
||||||
|
"GQ",
|
||||||
|
"GR",
|
||||||
|
"GT",
|
||||||
|
"GW",
|
||||||
|
"GY",
|
||||||
|
"HK",
|
||||||
|
"HN",
|
||||||
|
"HR",
|
||||||
|
"HT",
|
||||||
|
"HU",
|
||||||
|
"ID",
|
||||||
|
"IE",
|
||||||
|
"IL",
|
||||||
|
"IN",
|
||||||
|
"IQ",
|
||||||
|
"IS",
|
||||||
|
"IT",
|
||||||
|
"JM",
|
||||||
|
"JO",
|
||||||
|
"JP",
|
||||||
|
"KE",
|
||||||
|
"KG",
|
||||||
|
"KH",
|
||||||
|
"KI",
|
||||||
|
"KM",
|
||||||
|
"KN",
|
||||||
|
"KR",
|
||||||
|
"KW",
|
||||||
|
"KZ",
|
||||||
|
"LA",
|
||||||
|
"LB",
|
||||||
|
"LC",
|
||||||
|
"LI",
|
||||||
|
"LK",
|
||||||
|
"LR",
|
||||||
|
"LS",
|
||||||
|
"LT",
|
||||||
|
"LU",
|
||||||
|
"LV",
|
||||||
|
"LY",
|
||||||
|
"MA",
|
||||||
|
"MC",
|
||||||
|
"MD",
|
||||||
|
"ME",
|
||||||
|
"MG",
|
||||||
|
"MH",
|
||||||
|
"MK",
|
||||||
|
"ML",
|
||||||
|
"MN",
|
||||||
|
"MO",
|
||||||
|
"MR",
|
||||||
|
"MT",
|
||||||
|
"MU",
|
||||||
|
"MV",
|
||||||
|
"MW",
|
||||||
|
"MX",
|
||||||
|
"MY",
|
||||||
|
"MZ",
|
||||||
|
"NA",
|
||||||
|
"NE",
|
||||||
|
"NG",
|
||||||
|
"NI",
|
||||||
|
"NL",
|
||||||
|
"NO",
|
||||||
|
"NP",
|
||||||
|
"NR",
|
||||||
|
"NZ",
|
||||||
|
"OM",
|
||||||
|
"PA",
|
||||||
|
"PE",
|
||||||
|
"PG",
|
||||||
|
"PH",
|
||||||
|
"PK",
|
||||||
|
"PL",
|
||||||
|
"PS",
|
||||||
|
"PT",
|
||||||
|
"PW",
|
||||||
|
"PY",
|
||||||
|
"QA",
|
||||||
|
"RO",
|
||||||
|
"RS",
|
||||||
|
"RU",
|
||||||
|
"RW",
|
||||||
|
"SA",
|
||||||
|
"SB",
|
||||||
|
"SC",
|
||||||
|
"SE",
|
||||||
|
"SG",
|
||||||
|
"SI",
|
||||||
|
"SK",
|
||||||
|
"SL",
|
||||||
|
"SM",
|
||||||
|
"SN",
|
||||||
|
"SR",
|
||||||
|
"ST",
|
||||||
|
"SV",
|
||||||
|
"SZ",
|
||||||
|
"TD",
|
||||||
|
"TG",
|
||||||
|
"TH",
|
||||||
|
"TJ",
|
||||||
|
"TL",
|
||||||
|
"TN",
|
||||||
|
"TO",
|
||||||
|
"TR",
|
||||||
|
"TT",
|
||||||
|
"TV",
|
||||||
|
"TW",
|
||||||
|
"TZ",
|
||||||
|
"UA",
|
||||||
|
"UG",
|
||||||
|
"US",
|
||||||
|
"UY",
|
||||||
|
"UZ",
|
||||||
|
"VC",
|
||||||
|
"VE",
|
||||||
|
"VN",
|
||||||
|
"VU",
|
||||||
|
"WS",
|
||||||
|
"XK",
|
||||||
|
"ZA",
|
||||||
|
"ZM",
|
||||||
|
"ZW"
|
||||||
|
];
|
@ -10,12 +10,14 @@ import 'package:spotube/models/Logger.dart';
|
|||||||
import 'package:spotube/models/generated_secrets.dart';
|
import 'package:spotube/models/generated_secrets.dart';
|
||||||
|
|
||||||
class UserPreferences extends ChangeNotifier {
|
class UserPreferences extends ChangeNotifier {
|
||||||
|
String recommendationMarket;
|
||||||
String geniusAccessToken;
|
String geniusAccessToken;
|
||||||
HotKey? nextTrackHotKey;
|
HotKey? nextTrackHotKey;
|
||||||
HotKey? prevTrackHotKey;
|
HotKey? prevTrackHotKey;
|
||||||
HotKey? playPauseHotKey;
|
HotKey? playPauseHotKey;
|
||||||
UserPreferences({
|
UserPreferences({
|
||||||
required this.geniusAccessToken,
|
required this.geniusAccessToken,
|
||||||
|
required this.recommendationMarket,
|
||||||
this.nextTrackHotKey,
|
this.nextTrackHotKey,
|
||||||
this.prevTrackHotKey,
|
this.prevTrackHotKey,
|
||||||
this.playPauseHotKey,
|
this.playPauseHotKey,
|
||||||
@ -43,6 +45,9 @@ class UserPreferences extends ChangeNotifier {
|
|||||||
SharedPreferences localStorage = await SharedPreferences.getInstance();
|
SharedPreferences localStorage = await SharedPreferences.getInstance();
|
||||||
String? accessToken =
|
String? accessToken =
|
||||||
localStorage.getString(LocalStorageKeys.geniusAccessToken);
|
localStorage.getString(LocalStorageKeys.geniusAccessToken);
|
||||||
|
|
||||||
|
recommendationMarket =
|
||||||
|
localStorage.getString(LocalStorageKeys.recommendationMarket) ?? 'US';
|
||||||
geniusAccessToken = accessToken != null && accessToken.isNotEmpty
|
geniusAccessToken = accessToken != null && accessToken.isNotEmpty
|
||||||
? accessToken
|
? accessToken
|
||||||
: getRandomElement(lyricsSecrets);
|
: getRandomElement(lyricsSecrets);
|
||||||
@ -79,6 +84,14 @@ class UserPreferences extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setRecommendationMarket(String country) {
|
||||||
|
recommendationMarket = country;
|
||||||
|
SharedPreferences.getInstance().then((value) {
|
||||||
|
value.setString(LocalStorageKeys.recommendationMarket, country);
|
||||||
|
notifyListeners();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void setGeniusAccessToken(String token) {
|
void setGeniusAccessToken(String token) {
|
||||||
geniusAccessToken = token;
|
geniusAccessToken = token;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@ -118,5 +131,6 @@ class UserPreferences extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final userPreferencesProvider =
|
final userPreferencesProvider = ChangeNotifierProvider(
|
||||||
ChangeNotifierProvider((_) => UserPreferences(geniusAccessToken: ""));
|
(_) => UserPreferences(geniusAccessToken: "", recommendationMarket: 'US'),
|
||||||
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user