mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-04-30 04:43:18 +00:00
Add catalog settings management in HomeScreen for improved catalog loading
This commit is contained in:
parent
60cfdaf049
commit
5f8bb8948d
1 changed files with 76 additions and 61 deletions
|
|
@ -62,6 +62,10 @@ import homeStyles, { sharedStyles } from '../styles/homeStyles';
|
||||||
import { useTheme } from '../contexts/ThemeContext';
|
import { useTheme } from '../contexts/ThemeContext';
|
||||||
import type { Theme } from '../contexts/ThemeContext';
|
import type { Theme } from '../contexts/ThemeContext';
|
||||||
import * as ScreenOrientation from 'expo-screen-orientation';
|
import * as ScreenOrientation from 'expo-screen-orientation';
|
||||||
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
const CATALOG_SETTINGS_KEY = 'catalog_settings';
|
||||||
|
|
||||||
// Define interfaces for our data
|
// Define interfaces for our data
|
||||||
interface Category {
|
interface Category {
|
||||||
|
|
@ -415,6 +419,10 @@ const HomeScreen = () => {
|
||||||
try {
|
try {
|
||||||
const addons = await catalogService.getAllAddons();
|
const addons = await catalogService.getAllAddons();
|
||||||
|
|
||||||
|
// Load catalog settings to check which catalogs are enabled
|
||||||
|
const catalogSettingsJson = await AsyncStorage.getItem(CATALOG_SETTINGS_KEY);
|
||||||
|
const catalogSettings = catalogSettingsJson ? JSON.parse(catalogSettingsJson) : {};
|
||||||
|
|
||||||
// Create placeholder array with proper order and track indices
|
// Create placeholder array with proper order and track indices
|
||||||
const catalogPlaceholders: (CatalogContent | null)[] = [];
|
const catalogPlaceholders: (CatalogContent | null)[] = [];
|
||||||
const catalogPromises: Promise<void>[] = [];
|
const catalogPromises: Promise<void>[] = [];
|
||||||
|
|
@ -423,76 +431,83 @@ const HomeScreen = () => {
|
||||||
for (const addon of addons) {
|
for (const addon of addons) {
|
||||||
if (addon.catalogs) {
|
if (addon.catalogs) {
|
||||||
for (const catalog of addon.catalogs) {
|
for (const catalog of addon.catalogs) {
|
||||||
const currentIndex = catalogIndex;
|
// Check if this catalog is enabled (default to true if no setting exists)
|
||||||
catalogPlaceholders.push(null); // Reserve position
|
const settingKey = `${addon.id}:${catalog.type}:${catalog.id}`;
|
||||||
|
const isEnabled = catalogSettings[settingKey] ?? true;
|
||||||
|
|
||||||
const catalogPromise = (async () => {
|
// Only load enabled catalogs
|
||||||
try {
|
if (isEnabled) {
|
||||||
const addonManifest = await stremioService.getInstalledAddonsAsync();
|
const currentIndex = catalogIndex;
|
||||||
const manifest = addonManifest.find((a: any) => a.id === addon.id);
|
catalogPlaceholders.push(null); // Reserve position
|
||||||
if (!manifest) return;
|
|
||||||
|
|
||||||
const metas = await stremioService.getCatalog(manifest, catalog.type, catalog.id, 1);
|
const catalogPromise = (async () => {
|
||||||
if (metas && metas.length > 0) {
|
try {
|
||||||
const items = metas.map((meta: any) => ({
|
const addonManifest = await stremioService.getInstalledAddonsAsync();
|
||||||
id: meta.id,
|
const manifest = addonManifest.find((a: any) => a.id === addon.id);
|
||||||
type: meta.type,
|
if (!manifest) return;
|
||||||
name: meta.name,
|
|
||||||
poster: meta.poster,
|
|
||||||
posterShape: meta.posterShape,
|
|
||||||
banner: meta.background,
|
|
||||||
logo: meta.logo,
|
|
||||||
imdbRating: meta.imdbRating,
|
|
||||||
year: meta.year,
|
|
||||||
genres: meta.genres,
|
|
||||||
description: meta.description,
|
|
||||||
runtime: meta.runtime,
|
|
||||||
released: meta.released,
|
|
||||||
trailerStreams: meta.trailerStreams,
|
|
||||||
videos: meta.videos,
|
|
||||||
directors: meta.director,
|
|
||||||
creators: meta.creator,
|
|
||||||
certification: meta.certification
|
|
||||||
}));
|
|
||||||
|
|
||||||
let displayName = catalog.name;
|
const metas = await stremioService.getCatalog(manifest, catalog.type, catalog.id, 1);
|
||||||
const contentType = catalog.type === 'movie' ? 'Movies' : 'TV Shows';
|
if (metas && metas.length > 0) {
|
||||||
if (!displayName.toLowerCase().includes(contentType.toLowerCase())) {
|
const items = metas.map((meta: any) => ({
|
||||||
displayName = `${displayName} ${contentType}`;
|
id: meta.id,
|
||||||
|
type: meta.type,
|
||||||
|
name: meta.name,
|
||||||
|
poster: meta.poster,
|
||||||
|
posterShape: meta.posterShape,
|
||||||
|
banner: meta.background,
|
||||||
|
logo: meta.logo,
|
||||||
|
imdbRating: meta.imdbRating,
|
||||||
|
year: meta.year,
|
||||||
|
genres: meta.genres,
|
||||||
|
description: meta.description,
|
||||||
|
runtime: meta.runtime,
|
||||||
|
released: meta.released,
|
||||||
|
trailerStreams: meta.trailerStreams,
|
||||||
|
videos: meta.videos,
|
||||||
|
directors: meta.director,
|
||||||
|
creators: meta.creator,
|
||||||
|
certification: meta.certification
|
||||||
|
}));
|
||||||
|
|
||||||
|
let displayName = catalog.name;
|
||||||
|
const contentType = catalog.type === 'movie' ? 'Movies' : 'TV Shows';
|
||||||
|
if (!displayName.toLowerCase().includes(contentType.toLowerCase())) {
|
||||||
|
displayName = `${displayName} ${contentType}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const catalogContent = {
|
||||||
|
addon: addon.id,
|
||||||
|
type: catalog.type,
|
||||||
|
id: catalog.id,
|
||||||
|
name: displayName,
|
||||||
|
items
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(`[HomeScreen] Loaded catalog: ${displayName} at position ${currentIndex} (${items.length} items)`);
|
||||||
|
|
||||||
|
// Update the catalog at its specific position
|
||||||
|
setCatalogs(prevCatalogs => {
|
||||||
|
const newCatalogs = [...prevCatalogs];
|
||||||
|
newCatalogs[currentIndex] = catalogContent;
|
||||||
|
return newCatalogs;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
const catalogContent = {
|
console.error(`[HomeScreen] Failed to load ${catalog.name} from ${addon.name}:`, error);
|
||||||
addon: addon.id,
|
} finally {
|
||||||
type: catalog.type,
|
setLoadedCatalogCount(prev => prev + 1);
|
||||||
id: catalog.id,
|
|
||||||
name: displayName,
|
|
||||||
items
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log(`[HomeScreen] Loaded catalog: ${displayName} at position ${currentIndex} (${items.length} items)`);
|
|
||||||
|
|
||||||
// Update the catalog at its specific position
|
|
||||||
setCatalogs(prevCatalogs => {
|
|
||||||
const newCatalogs = [...prevCatalogs];
|
|
||||||
newCatalogs[currentIndex] = catalogContent;
|
|
||||||
return newCatalogs;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
})();
|
||||||
console.error(`[HomeScreen] Failed to load ${catalog.name} from ${addon.name}:`, error);
|
|
||||||
} finally {
|
|
||||||
setLoadedCatalogCount(prev => prev + 1);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
catalogPromises.push(catalogPromise);
|
catalogPromises.push(catalogPromise);
|
||||||
catalogIndex++;
|
catalogIndex++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
totalCatalogsRef.current = catalogIndex;
|
totalCatalogsRef.current = catalogIndex;
|
||||||
console.log(`[HomeScreen] Starting to load ${catalogIndex} catalogs progressively...`);
|
console.log(`[HomeScreen] Starting to load ${catalogIndex} enabled catalogs progressively...`);
|
||||||
|
|
||||||
// Initialize catalogs array with proper length
|
// Initialize catalogs array with proper length
|
||||||
setCatalogs(new Array(catalogIndex).fill(null));
|
setCatalogs(new Array(catalogIndex).fill(null));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue