diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f81dfa912..fbb64b0c9 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -4,6 +4,7 @@
package="org.koitharu.kotatsu">
+
@@ -43,7 +44,9 @@
android:name=".ui.reader.SimpleSettingsActivity"
android:label="@string/settings" />
-
+
diff --git a/app/src/main/java/org/koitharu/kotatsu/ui/common/dialog/CheckBoxAlertDialog.kt b/app/src/main/java/org/koitharu/kotatsu/ui/common/dialog/CheckBoxAlertDialog.kt
new file mode 100644
index 000000000..5257e4926
--- /dev/null
+++ b/app/src/main/java/org/koitharu/kotatsu/ui/common/dialog/CheckBoxAlertDialog.kt
@@ -0,0 +1,84 @@
+package org.koitharu.kotatsu.ui.common.dialog
+
+import android.annotation.SuppressLint
+import android.content.Context
+import android.content.DialogInterface
+import android.view.LayoutInflater
+import androidx.annotation.DrawableRes
+import androidx.annotation.StringRes
+import androidx.appcompat.app.AlertDialog
+import com.google.android.material.checkbox.MaterialCheckBox
+import org.koitharu.kotatsu.R
+
+class CheckBoxAlertDialog private constructor(private val delegate: AlertDialog) :
+ DialogInterface by delegate {
+
+ fun show() = delegate.show()
+
+ class Builder(context: Context) {
+
+ @SuppressLint("InflateParams")
+ private val view = LayoutInflater.from(context)
+ .inflate(R.layout.dialog_checkbox, null, false)
+ private val checkBox = view.findViewById(android.R.id.checkbox)
+
+ private val delegate = AlertDialog.Builder(context)
+ .setView(view)
+
+ fun setTitle(@StringRes titleResId: Int): Builder {
+ delegate.setTitle(titleResId)
+ return this
+ }
+
+ fun setTitle(title: CharSequence): Builder {
+ delegate.setTitle(title)
+ return this
+ }
+
+ fun setMessage(@StringRes messageId: Int): Builder {
+ delegate.setMessage(messageId)
+ return this
+ }
+
+ fun setMessage(message: CharSequence): Builder {
+ delegate.setMessage(message)
+ return this
+ }
+
+ fun setCheckBoxText(@StringRes textId: Int): Builder {
+ checkBox.setText(textId)
+ return this
+ }
+
+ fun setCheckBoxChecked(isChecked: Boolean): Builder {
+ checkBox.isChecked = isChecked
+ return this
+ }
+
+ fun setIcon(@DrawableRes iconId: Int): Builder {
+ delegate.setIcon(iconId)
+ return this
+ }
+
+ fun setPositiveButton(
+ @StringRes textId: Int,
+ listener: (DialogInterface, Boolean) -> Unit
+ ): Builder {
+ delegate.setPositiveButton(textId) { dialog, _ ->
+ listener(dialog, checkBox.isChecked)
+ }
+ return this
+ }
+
+ fun setNegativeButton(
+ @StringRes textId: Int,
+ listener: DialogInterface.OnClickListener? = null
+ ): Builder {
+ delegate.setNegativeButton(textId, listener)
+ return this
+ }
+
+ fun create() = CheckBoxAlertDialog(delegate.create())
+
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/org/koitharu/kotatsu/ui/download/DownloadService.kt b/app/src/main/java/org/koitharu/kotatsu/ui/download/DownloadService.kt
index 3d70c8d39..1ac2f5e60 100644
--- a/app/src/main/java/org/koitharu/kotatsu/ui/download/DownloadService.kt
+++ b/app/src/main/java/org/koitharu/kotatsu/ui/download/DownloadService.kt
@@ -2,7 +2,9 @@ package org.koitharu.kotatsu.ui.download
import android.content.Context
import android.content.Intent
+import android.net.ConnectivityManager
import android.webkit.MimeTypeMap
+import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import coil.Coil
import coil.api.get
@@ -13,11 +15,14 @@ import kotlinx.coroutines.withContext
import okhttp3.OkHttpClient
import okhttp3.Request
import org.koin.core.inject
+import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.local.PagesCache
import org.koitharu.kotatsu.core.model.Manga
+import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.domain.MangaProviderFactory
import org.koitharu.kotatsu.domain.local.MangaZip
import org.koitharu.kotatsu.ui.common.BaseService
+import org.koitharu.kotatsu.ui.common.dialog.CheckBoxAlertDialog
import org.koitharu.kotatsu.utils.CacheUtils
import org.koitharu.kotatsu.utils.ext.await
import org.koitharu.kotatsu.utils.ext.retryUntilSuccess
@@ -144,12 +149,34 @@ class DownloadService : BaseService() {
private const val EXTRA_CHAPTERS_IDS = "chapters_ids"
fun start(context: Context, manga: Manga, chaptersIds: Collection? = null) {
- val intent = Intent(context, DownloadService::class.java)
- intent.putExtra(EXTRA_MANGA, manga)
- if (chaptersIds != null) {
- intent.putExtra(EXTRA_CHAPTERS_IDS, chaptersIds.toLongArray())
+ confirmDataTransfer(context) {
+ val intent = Intent(context, DownloadService::class.java)
+ intent.putExtra(EXTRA_MANGA, manga)
+ if (chaptersIds != null) {
+ intent.putExtra(EXTRA_CHAPTERS_IDS, chaptersIds.toLongArray())
+ }
+ ContextCompat.startForegroundService(context, intent)
+ }
+ }
+
+ private fun confirmDataTransfer(context: Context, callback: () -> Unit) {
+ val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
+ val settings = AppSettings(context)
+ if (cm.isActiveNetworkMetered && settings.isTrafficWarningEnabled) {
+ CheckBoxAlertDialog.Builder(context)
+ .setTitle(R.string.warning)
+ .setMessage(R.string.network_consumption_warning)
+ .setCheckBoxText(R.string.dont_ask_again)
+ .setCheckBoxChecked(false)
+ .setNegativeButton(android.R.string.cancel, null)
+ .setPositiveButton(R.string._continue) { _, doNotAsk ->
+ settings.isTrafficWarningEnabled = !doNotAsk
+ callback()
+ }.create()
+ .show()
+ } else {
+ callback()
}
- ContextCompat.startForegroundService(context, intent)
}
}
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/dialog_checkbox.xml b/app/src/main/res/layout/dialog_checkbox.xml
new file mode 100644
index 000000000..b4b938045
--- /dev/null
+++ b/app/src/main/res/layout/dialog_checkbox.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/constants.xml b/app/src/main/res/values/constants.xml
index 458e2f298..4da0270d3 100644
--- a/app/src/main/res/values/constants.xml
+++ b/app/src/main/res/values/constants.xml
@@ -3,6 +3,7 @@
list_mode
theme
sources_order
+ traffic_warning
pages_cache_clear
grid_size
reader_switchers
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9fed4ea23..a92474ab5 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -91,4 +91,8 @@
Switch pages
Taps on edges
Volume buttons
+ Continue
+ Warning
+ This operation may consume a lot of network traffic
+ Don`t ask again
\ No newline at end of file