diff --git a/app/src/main/java/ani/dantotsu/Functions.kt b/app/src/main/java/ani/dantotsu/Functions.kt index a1035d0505..812e81061c 100644 --- a/app/src/main/java/ani/dantotsu/Functions.kt +++ b/app/src/main/java/ani/dantotsu/Functions.kt @@ -4,6 +4,7 @@ import android.animation.ObjectAnimator import android.annotation.SuppressLint import android.app.Activity import android.app.DatePickerDialog +import android.app.NotificationManager import android.content.ClipData import android.content.ClipboardManager import android.content.Context @@ -28,6 +29,7 @@ import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.view.animation.* import android.widget.* import androidx.appcompat.app.AppCompatDelegate +import androidx.core.app.NotificationCompat import androidx.core.content.ContextCompat.getSystemService import androidx.core.content.FileProvider import androidx.core.math.MathUtils.clamp @@ -54,6 +56,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.internal.ViewUtils import com.google.android.material.snackbar.Snackbar import com.google.firebase.crashlytics.FirebaseCrashlytics +import eu.kanade.tachiyomi.data.notification.Notifications import kotlinx.coroutines.* import nl.joery.animatedbottombar.AnimatedBottomBar import java.io.* @@ -935,6 +938,21 @@ fun checkCountry(context: Context): Boolean { else -> false } } +fun notification(context: Context){ + val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + val incognito = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getBoolean("incognito", false) + if (incognito) { + val builder = NotificationCompat.Builder(context, Notifications.CHANNEL_INCOGNITO_MODE) + .setSmallIcon(R.drawable.ic_incognito_24) + .setContentTitle("Incognito Mode") + .setContentText("Disable Incognito Mode") + .setPriority(NotificationCompat.PRIORITY_HIGH) + .setOngoing(true) + notificationManager.notify(26, builder.build()) + } else { + notificationManager.cancel(26) + } +} suspend fun View.pop() { currActivity()?.runOnUiThread { diff --git a/app/src/main/java/ani/dantotsu/MainActivity.kt b/app/src/main/java/ani/dantotsu/MainActivity.kt index 0101d30e51..ccad3a465d 100644 --- a/app/src/main/java/ani/dantotsu/MainActivity.kt +++ b/app/src/main/java/ani/dantotsu/MainActivity.kt @@ -91,6 +91,7 @@ class MainActivity : AppCompatActivity() { } + notification(this) var doubleBackToExitPressedOnce = false onBackPressedDispatcher.addCallback(this) { diff --git a/app/src/main/java/ani/dantotsu/home/NoInternet.kt b/app/src/main/java/ani/dantotsu/home/NoInternet.kt index 524aa82547..db47081fef 100644 --- a/app/src/main/java/ani/dantotsu/home/NoInternet.kt +++ b/app/src/main/java/ani/dantotsu/home/NoInternet.kt @@ -4,8 +4,11 @@ import android.content.Context import android.graphics.drawable.GradientDrawable import android.os.Build import android.os.Bundle +import android.os.Handler +import android.os.Looper import android.view.View import android.view.ViewGroup +import androidx.activity.addCallback import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.core.view.doOnAttach @@ -25,6 +28,7 @@ import ani.dantotsu.offline.OfflineFragment import ani.dantotsu.others.LangSet import ani.dantotsu.selectedOption import ani.dantotsu.settings.UserInterfaceSettings +import ani.dantotsu.snackString import ani.dantotsu.themes.ThemeManager import nl.joery.animatedbottombar.AnimatedBottomBar @@ -56,6 +60,19 @@ class NoInternet : AppCompatActivity() { } + var doubleBackToExitPressedOnce = false + onBackPressedDispatcher.addCallback(this) { + if (doubleBackToExitPressedOnce) { + finishAffinity() + } + doubleBackToExitPressedOnce = true + snackString(this@NoInternet.getString(R.string.back_to_exit)) + Handler(Looper.getMainLooper()).postDelayed( + { doubleBackToExitPressedOnce = false }, + 2000 + ) + } + binding.root.doOnAttach { initActivity(this) uiSettings = loadData("ui_settings") ?: uiSettings diff --git a/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt b/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt index 6301ab8ab6..6c06ea80fc 100644 --- a/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt +++ b/app/src/main/java/ani/dantotsu/settings/SettingsDialogFragment.kt @@ -20,6 +20,7 @@ import ani.dantotsu.home.LoginFragment import ani.dantotsu.home.MangaFragment import ani.dantotsu.home.NoInternet import ani.dantotsu.loadImage +import ani.dantotsu.notification import ani.dantotsu.offline.OfflineFragment import ani.dantotsu.openLinkInBrowser import ani.dantotsu.others.imagesearch.ImageSearchActivity @@ -84,6 +85,7 @@ class SettingsDialogFragment : BottomSheetDialogFragment() { binding.settingsIncognito.setOnCheckedChangeListener { _, isChecked -> context?.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)?.edit() ?.putBoolean("incognito", isChecked)?.apply() + notification(requireContext()) } binding.settingsExtensionSettings.setSafeOnClickListener { startActivity(Intent(activity, ExtensionsActivity::class.java))