mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Category-specific auto download (#701)
* Category-specific auto download
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							3be9881997
						
					
				
				
					commit
					68c4116327
				
			| @@ -57,6 +57,9 @@ class LibraryUpdateService : Service() { | ||||
|      */ | ||||
|     val preferences: PreferencesHelper by injectLazy() | ||||
|  | ||||
|     /** | ||||
|      * Download Manager | ||||
|      */ | ||||
|     val downloadManager: DownloadManager by injectLazy() | ||||
|  | ||||
|     /** | ||||
| @@ -216,7 +219,7 @@ class LibraryUpdateService : Service() { | ||||
|                         .filter { it.category in categoriesToUpdate } | ||||
|                         .distinctBy { it.id } | ||||
|             else | ||||
|                 db.getFavoriteMangas().executeAsBlocking().distinctBy { it.id } | ||||
|                 db.getLibraryMangas().executeAsBlocking().distinctBy { it.id } | ||||
|         } | ||||
|  | ||||
|         if (!intent.getBooleanExtra(UPDATE_DETAILS, false) && preferences.updateOnlyNonCompleted()) { | ||||
| @@ -238,8 +241,16 @@ class LibraryUpdateService : Service() { | ||||
|     fun updateChapterList(mangaToUpdate: List<Manga>): Observable<Manga> { | ||||
|         // Initialize the variables holding the progress of the updates. | ||||
|         val count = AtomicInteger(0) | ||||
|         // List containing new updates | ||||
|         val newUpdates = ArrayList<Manga>() | ||||
|         // list containing failed updates | ||||
|         val failedUpdates = ArrayList<Manga>() | ||||
|         // List containing categories that get included in downloads. | ||||
|         val categoriesToDownload = preferences.downloadNewCategories().getOrDefault().map(String::toInt) | ||||
|         // Boolean to determine if user wants to automatically download new chapters. | ||||
|         val downloadNew = preferences.downloadNew().getOrDefault() | ||||
|         // Boolean to determine if DownloadManager has downloads | ||||
|         var hasDownloads = false | ||||
|  | ||||
|         // Emit each manga and update it sequentially. | ||||
|         return Observable.from(mangaToUpdate) | ||||
| @@ -254,10 +265,13 @@ class LibraryUpdateService : Service() { | ||||
|                                 Pair(emptyList<Chapter>(), emptyList<Chapter>()) | ||||
|                             } | ||||
|                             // Filter out mangas without new chapters (or failed). | ||||
|                             .filter { pair -> pair.first.size > 0 } | ||||
|                             .filter { pair -> pair.first.isNotEmpty() } | ||||
|                             .doOnNext { | ||||
|                                 if (preferences.downloadNew()) { | ||||
|                                     downloadChapters(manga, it.first) | ||||
|                                 if (downloadNew) { | ||||
|                                     if (categoriesToDownload.isEmpty() || manga.category in categoriesToDownload) { | ||||
|                                         downloadChapters(manga, it.first) | ||||
|                                         hasDownloads = true | ||||
|                                     } | ||||
|                                 } | ||||
|                             } | ||||
|                             // Convert to the manga that contains new chapters. | ||||
| @@ -277,8 +291,10 @@ class LibraryUpdateService : Service() { | ||||
|                         cancelNotification() | ||||
|                     } else { | ||||
|                         showResultNotification(newUpdates, failedUpdates) | ||||
|                         if (preferences.downloadNew()) { | ||||
|                             DownloadService.start(this) | ||||
|                         if (downloadNew) { | ||||
|                             if (hasDownloads) { | ||||
|                                 DownloadService.start(this) | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|   | ||||
| @@ -93,6 +93,8 @@ class PreferenceKeys(context: Context) { | ||||
|  | ||||
|     val downloadNew = context.getString(R.string.pref_download_new_key) | ||||
|  | ||||
|     val downloadNewCategories = context.getString(R.string.pref_download_new_categories_key) | ||||
|  | ||||
|     fun sourceUsername(sourceId: Long) = "pref_source_username_$sourceId" | ||||
|  | ||||
|     fun sourcePassword(sourceId: Long) = "pref_source_password_$sourceId" | ||||
|   | ||||
| @@ -142,7 +142,9 @@ class PreferencesHelper(val context: Context) { | ||||
|  | ||||
|     fun hiddenCatalogues() = rxPrefs.getStringSet("hidden_catalogues", emptySet()) | ||||
|  | ||||
|     fun downloadNew() = prefs.getBoolean(keys.downloadNew, false) | ||||
|     fun downloadNew() = rxPrefs.getBoolean(keys.downloadNew, false) | ||||
|  | ||||
|     fun downloadNewCategories() = rxPrefs.getStringSet(keys.downloadNewCategories, emptySet()) | ||||
|  | ||||
|     fun lang() = prefs.getString(keys.lang, "") | ||||
|  | ||||
|   | ||||
| @@ -19,10 +19,12 @@ import com.nononsenseapps.filepicker.FilePickerActivity | ||||
| import com.nononsenseapps.filepicker.FilePickerFragment | ||||
| import com.nononsenseapps.filepicker.LogicHandler | ||||
| import eu.kanade.tachiyomi.R | ||||
| import eu.kanade.tachiyomi.data.database.DatabaseHelper | ||||
| import eu.kanade.tachiyomi.data.preference.PreferencesHelper | ||||
| import eu.kanade.tachiyomi.data.preference.getOrDefault | ||||
| import eu.kanade.tachiyomi.util.inflate | ||||
| import eu.kanade.tachiyomi.util.plusAssign | ||||
| import net.xpece.android.support.preference.MultiSelectListPreference | ||||
| import uy.kohesive.injekt.injectLazy | ||||
| import java.io.File | ||||
|  | ||||
| @@ -41,8 +43,12 @@ class SettingsDownloadsFragment : SettingsFragment() { | ||||
|  | ||||
|     private val preferences: PreferencesHelper by injectLazy() | ||||
|  | ||||
|     private val db: DatabaseHelper by injectLazy() | ||||
|  | ||||
|     val downloadDirPref: Preference by bindPref(R.string.pref_download_directory_key) | ||||
|  | ||||
|     val downloadCategory: MultiSelectListPreference by bindPref(R.string.pref_download_new_categories_key) | ||||
|  | ||||
|     override fun onViewCreated(view: View, savedState: Bundle?) { | ||||
|         super.onViewCreated(view, savedState) | ||||
|  | ||||
| @@ -92,6 +98,29 @@ class SettingsDownloadsFragment : SettingsFragment() { | ||||
|                         dir.createFile(".nomedia") | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|         subscriptions += preferences.downloadNew().asObservable() | ||||
|                 .subscribe { downloadCategory.isVisible = it } | ||||
|  | ||||
|         val dbCategories = db.getCategories().executeAsBlocking() | ||||
|         downloadCategory.apply { | ||||
|             entries = dbCategories.map { it.name }.toTypedArray() | ||||
|             entryValues = dbCategories.map { it.id.toString() }.toTypedArray() | ||||
|         } | ||||
|  | ||||
|         subscriptions += preferences.downloadNewCategories().asObservable() | ||||
|                 .subscribe { | ||||
|                     val selectedCategories = it | ||||
|                             .mapNotNull { id -> dbCategories.find { it.id == id.toInt() } } | ||||
|                             .sortedBy { it.order } | ||||
|  | ||||
|                     val summary = if (selectedCategories.isEmpty()) | ||||
|                         getString(R.string.all) | ||||
|                     else | ||||
|                         selectedCategories.joinToString { it.name } | ||||
|  | ||||
|                     downloadCategory.summary = summary | ||||
|                 } | ||||
|     } | ||||
|  | ||||
|     fun getExternalFilesDirs(): List<File> { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user