switchFontType method

Future<void> switchFontType({
  1. required int fontIndex,
})

تبديل نوع الخط وتحميله إذا لم يكن محملاً من قبل

Switch font type and download it if not already downloaded

Implementation

Future<void> switchFontType({required int fontIndex}) async {
  // إعادة التحقق من حالة التحميل من التخزين
  // Re-check download status from storage
  final storageValue =
      GetStorage().read<bool>(_StorageConstants().isDownloadedCodeV4Fonts);
  state.isFontDownloaded.value = storageValue ?? false;

  // التحقق مما إذا كان الخط المطلوب هو نفس الخط الحالي
  // Check if the requested font is the same as the current font
  if (state.fontsSelected.value == fontIndex &&
      (fontIndex == 0 || state.isFontDownloaded.value)) {
    log('Font is already selected', name: 'QuranGetters');
    return;
  }

  // إذا كان الخط هو الخط الافتراضي (0)، فقط قم بتعيينه
  // If the font is the default font (0), just set it
  if (fontIndex == 0) {
    state.fontsSelected.value = fontIndex;
    GetStorage().write(_StorageConstants().fontsSelected, fontIndex);
    Get.forceAppUpdate();
    log('Default font selected', name: 'QuranGetters');
    return;
  }

  // إذا كان الخط محملاً بالفعل، قم بتعيينه
  // If the font is already downloaded, just set it
  if (state.isFontDownloaded.value) {
    state.fontsSelected.value = fontIndex;
    GetStorage().write(_StorageConstants().fontsSelected, fontIndex);
    update(['fontsSelected']);
    Get.forceAppUpdate();
    log('Downloaded font selected', name: 'QuranGetters');
    return;
  }

  // إذا كان الخط غير محمل، قم بتحميله أولاً ثم تعيينه
  // If the font is not downloaded, download it first then set it

  state.fontsSelected.value = fontIndex;
  GetStorage().write(_StorageConstants().fontsSelected, fontIndex);
  update(['fontsSelected', 'fontsDownloadingProgress']);
  Get.forceAppUpdate();
  log('Font downloaded and selected', name: 'QuranGetters');
}