mirror of
https://github.com/gokadzev/Musify.git
synced 2026-03-13 15:20:46 +08:00
70 lines
1.9 KiB
Dart
70 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:musify/main.dart';
|
|
import 'package:musify/utilities/common_variables.dart';
|
|
|
|
BorderRadius getItemBorderRadius(int index, int totalLength) {
|
|
const defaultRadius = BorderRadius.zero;
|
|
if (totalLength == 1) {
|
|
return commonCustomBarRadius; // Only one item
|
|
} else if (index == 0) {
|
|
return commonCustomBarRadiusFirst; // First item
|
|
} else if (index == totalLength - 1) {
|
|
return commonCustomBarRadiusLast; // Last item
|
|
}
|
|
return defaultRadius; // Default for middle items
|
|
}
|
|
|
|
Locale getLocaleFromLanguageCode(String? languageCode) {
|
|
// Early return for null case
|
|
if (languageCode == null) {
|
|
return const Locale('en');
|
|
}
|
|
|
|
// Handle codes with script parts
|
|
if (languageCode.contains('-')) {
|
|
final parts = languageCode.split('-');
|
|
final baseLanguage = parts[0];
|
|
final script = parts[1];
|
|
|
|
// Try to find exact match with script
|
|
for (final locale in appSupportedLocales) {
|
|
if (locale.languageCode == baseLanguage && locale.scriptCode == script) {
|
|
return locale;
|
|
}
|
|
}
|
|
|
|
// Fall back to base language only
|
|
return Locale(baseLanguage);
|
|
}
|
|
|
|
// Handle simple language codes
|
|
for (final locale in appSupportedLocales) {
|
|
if (locale.languageCode == languageCode) {
|
|
return locale;
|
|
}
|
|
}
|
|
|
|
// Default fallback
|
|
return const Locale('en');
|
|
}
|
|
|
|
/// Validates if a URL is a YouTube playlist URL
|
|
bool isYoutubePlaylistUrl(String url) {
|
|
final playlistRegExp = RegExp(
|
|
r'^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/.*(list=([a-zA-Z0-9_-]+)).*$',
|
|
);
|
|
return playlistRegExp.hasMatch(url);
|
|
}
|
|
|
|
/// Extracts the playlist ID from a YouTube playlist URL
|
|
String? extractYoutubePlaylistId(String url) {
|
|
if (!isYoutubePlaylistUrl(url)) {
|
|
return null;
|
|
}
|
|
|
|
final playlistIdRegExp = RegExp('[&?]list=([a-zA-Z0-9_-]+)');
|
|
final match = playlistIdRegExp.firstMatch(url);
|
|
|
|
return match?.group(1);
|
|
}
|