Skip to content

Commit

Permalink
incognito notification (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush2622 authored Jan 14, 2024
1 parent e7631e0 commit a0b6956
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/src/main/java/ani/dantotsu/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.*
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/ani/dantotsu/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class MainActivity : AppCompatActivity() {

}

notification(this)

var doubleBackToExitPressedOnce = false
onBackPressedDispatcher.addCallback(this) {
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/ani/dantotsu/home/NoInternet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit a0b6956

Please sign in to comment.