tafsirDownload method

Future<void> tafsirDownload(
  1. int i
)

------------DownloadMethods------------ شرح: تحميل قاعدة بيانات التفسير أو الترجمة Explanation: Download tafsir or translation database

Implementation

Future<void> tafsirDownload(int i) async {
  Directory databasePath = await getApplicationDocumentsDirectory();
  String path;
  String fileUrl;
  if (isTafsir.value) {
    path = join(databasePath.path, tafsirAndTranslateNames[i].databaseName);
    fileUrl =
        'https://github.com/alheekmahlib/Islamic_database/raw/refs/heads/main/tafseer_database/${tafsirAndTranslateNames[i].databaseName}';
  } else {
    path = join(
        databasePath.path, '${tafsirAndTranslateNames[i].bookName}.json');
    fileUrl =
        'https://github.com/alheekmahlib/Islamic_database/raw/refs/heads/main/quran_database/translate/${tafsirAndTranslateNames[i].bookName}.json';
  }
  if (!onDownloading.value) {
    await downloadFile(path, fileUrl).then((_) async {
      onDownloadSuccess(i);
      await saveTafsirDownloadIndex(i);
      await loadTafsirDownloadIndices();
      if (isTafsir.value) {
        await handleRadioValueChanged(i);
        await fetchData(QuranCtrl.instance.state.currentPageNumber.value + 1);
      } else {
        await handleRadioValueChanged(i);
        await fetchTranslate();
      }
      update(['change_tafsir']);
    });
    log('Downloading from URL: $fileUrl', name: 'TafsirCtrl');
  }
}