From b0251b8177792894a00cc041023918cac81b43d6 Mon Sep 17 00:00:00 2001 From: Jobobby04 Date: Mon, 18 May 2020 13:00:13 -0400 Subject: [PATCH] Add support for EH Visited exported data in batch add --- .../java/exh/ui/batchadd/BatchAddPresenter.kt | 24 ++++++++++++++++++- .../main/res/layout/eh_fragment_batch_add.xml | 11 ++++----- app/src/main/res/values/strings_extra.xml | 5 ++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/exh/ui/batchadd/BatchAddPresenter.kt b/app/src/main/java/exh/ui/batchadd/BatchAddPresenter.kt index e69778eb6..521f332c8 100644 --- a/app/src/main/java/exh/ui/batchadd/BatchAddPresenter.kt +++ b/app/src/main/java/exh/ui/batchadd/BatchAddPresenter.kt @@ -1,12 +1,16 @@ package exh.ui.batchadd +import android.util.Log import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.ReplayRelay +import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import exh.GalleryAddEvent import exh.GalleryAdder import exh.metadata.nullIfBlank import kotlin.concurrent.thread +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get class BatchAddPresenter : BasePresenter() { @@ -19,7 +23,25 @@ class BatchAddPresenter : BasePresenter() { fun addGalleries(galleries: String) { eventRelay = ReplayRelay.create() - val splitGalleries = galleries.split("\n").mapNotNull { + val regex = + """[0-9]*?\.[a-z0-9]*?:""".toRegex() + val testedGalleries: String + + testedGalleries = if (regex.containsMatchIn(galleries)) { + regex.findAll(galleries).map { galleryKeys -> + val LinkParts = galleryKeys.value.split(".") + val Link = "${if (Injekt.get().enableExhentai().get()) { + "https://exhentai.org/g/" + } else { + "https://e-hentai.org/g/" + }}${LinkParts[0]}/${LinkParts[1].replace(":", "")}" + Log.d("Batch Add", Link) + Link + }.joinToString(separator = "\n") + } else { + galleries + } + val splitGalleries = testedGalleries.split("\n").mapNotNull { it.trim().nullIfBlank() } diff --git a/app/src/main/res/layout/eh_fragment_batch_add.xml b/app/src/main/res/layout/eh_fragment_batch_add.xml index ae12e9eba..6d6a7563a 100755 --- a/app/src/main/res/layout/eh_fragment_batch_add.xml +++ b/app/src/main/res/layout/eh_fragment_batch_add.xml @@ -19,7 +19,7 @@ android:id="@+id/input_title_view" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="Enter the galleries to add (separated by a new line):" + android:text="@string/eh_batch_add_title" android:textAppearance="@style/TextAppearance.Medium.Title" android:visibility="visible" app:layout_constraintLeft_toLeftOf="parent" @@ -31,7 +31,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" - android:hint="Example:\n\nhttp://e-hentai.org/g/12345/1a2b3c4e\nhttp://g.e-hentai.org/g/67890/6f7g8h9i\nhttp://exhentai.org/g/13579/1a3b5c7e\nhttps://exhentai.org/g/24680/2f4g6h8i\n" + android:hint="@string/eh_batch_add_description" android:inputType="textMultiLine" android:visibility="visible" app:layout_constraintBottom_toTopOf="@+id/btn_add_galleries" @@ -43,7 +43,7 @@ android:id="@+id/btn_add_galleries" android:layout_width="0dp" android:layout_height="wrap_content" - android:text="Add Galleries" + android:text="@string/eh_batch_add_button" android:visibility="visible" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="@+id/galleries_box" @@ -58,7 +58,7 @@ android:layout_marginTop="0dp" android:layout_marginEnd="16dp" android:layout_marginRight="0dp" - android:text="Adding galleries..." + android:text="@string/eh_batch_add_adding_galleries" android:textAppearance="@style/TextAppearance.Medium.Title" android:visibility="gone" app:layout_constraintLeft_toLeftOf="parent" @@ -71,7 +71,6 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="8dp" - android:layout_marginRight="8dp" android:layout_marginBottom="0dp" android:visibility="gone" app:layout_constraintBottom_toTopOf="@+id/progress_dismiss_btn" @@ -98,7 +97,7 @@ android:layout_marginLeft="0dp" android:layout_marginRight="0dp" android:layout_marginBottom="0dp" - android:text="Finish" + android:text="@string/eh_batch_add_finish" android:visibility="gone" app:layout_constraintBottom_toBottomOf="@+id/btn_add_galleries" app:layout_constraintHorizontal_bias="0.0" diff --git a/app/src/main/res/values/strings_extra.xml b/app/src/main/res/values/strings_extra.xml index 98d12de4d..1d953076c 100644 --- a/app/src/main/res/values/strings_extra.xml +++ b/app/src/main/res/values/strings_extra.xml @@ -99,6 +99,11 @@ Resetting the sync state can cause your next sync to be extremely slow. Collecting statistics… Saved Searches + Example:\n\nhttp://e-hentai.org/g/12345/1a2b3c4e\nhttp://g.e-hentai.org/g/67890/6f7g8h9i\nhttp://exhentai.org/g/13579/1a3b5c7e\nhttps://exhentai.org/g/24680/2f4g6h8i\n\nIt also supports E-H Visited exported data\n + Enter the galleries to add (separated by a new line): + Add Galleries + Adding galleries… + Finish See Recommendations