Skip to content

Commit

Permalink
use finish instead of exit process. (#1505)
Browse files Browse the repository at this point in the history
  • Loading branch information
IndusAryan authored Jan 23, 2025
1 parent 5691078 commit 94f012f
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import com.lagradost.cloudstream3.CommonActivity.setActivityInstance
import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.CommonActivity.updateLocale
import com.lagradost.cloudstream3.CommonActivity.updateTheme
import com.lagradost.cloudstream3.actions.temp.fcast.FcastManager
import com.lagradost.cloudstream3.databinding.ActivityMainBinding
import com.lagradost.cloudstream3.databinding.ActivityMainTvBinding
import com.lagradost.cloudstream3.databinding.BottomResultviewPreviewBinding
Expand Down Expand Up @@ -112,9 +113,6 @@ import com.lagradost.cloudstream3.ui.result.LinearListLayout
import com.lagradost.cloudstream3.ui.result.ResultViewModel2
import com.lagradost.cloudstream3.ui.result.START_ACTION_RESUME_LATEST
import com.lagradost.cloudstream3.ui.result.SyncViewModel
import com.lagradost.cloudstream3.utils.setText
import com.lagradost.cloudstream3.utils.setTextHtml
import com.lagradost.cloudstream3.utils.txt
import com.lagradost.cloudstream3.ui.search.SearchFragment
import com.lagradost.cloudstream3.ui.search.SearchResultBuilder
import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR
Expand Down Expand Up @@ -156,6 +154,7 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper
import com.lagradost.cloudstream3.utils.DataStoreHelper.accounts
import com.lagradost.cloudstream3.utils.DataStoreHelper.migrateResumeWatching
import com.lagradost.cloudstream3.utils.Event
import com.lagradost.cloudstream3.utils.ImageLoader.loadImage
import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.SnackbarHelper.showSnackbar
Expand All @@ -170,8 +169,9 @@ import com.lagradost.cloudstream3.utils.UIHelper.requestRW
import com.lagradost.cloudstream3.utils.UIHelper.toPx
import com.lagradost.cloudstream3.utils.USER_PROVIDER_API
import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API
import com.lagradost.cloudstream3.actions.temp.fcast.FcastManager
import com.lagradost.cloudstream3.utils.ImageLoader.loadImage
import com.lagradost.cloudstream3.utils.setText
import com.lagradost.cloudstream3.utils.setTextHtml
import com.lagradost.cloudstream3.utils.txt
import com.lagradost.safefile.SafeFile
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
Expand All @@ -182,7 +182,6 @@ import java.net.URLDecoder
import java.nio.charset.Charset
import kotlin.math.abs
import kotlin.math.absoluteValue
import kotlin.system.exitProcess

class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCallback {
companion object {
Expand Down Expand Up @@ -614,26 +613,24 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
@SuppressLint("ApplySharedPref") // commit since the op needs to be synchronous
private fun showConfirmExitDialog(settingsManager: SharedPreferences) {
val confirmBeforeExit = settingsManager.getInt(getString(R.string.confirm_exit_key), -1)
when(confirmBeforeExit) {
when (confirmBeforeExit) {
// AUTO - Confirm exit is shown only on TV or EMULATOR by default
-1 -> if(isLayout(PHONE)) exitProcess(0)
// DON'T SHOW
1 -> exitProcess(0)
// 0 -> SHOW
else -> { /*NO-OP : Continue*/ }
-1 -> if (isLayout(PHONE)) finish()
1 -> finish() // DON'T SHOW
else -> { /* NO - OP : Continue */ }
}

val dialogView = layoutInflater.inflate(R.layout.confirm_exit_dialog, null)
val dontShowAgainCheck: CheckBox = dialogView.findViewById(R.id.checkboxDontShowAgain)
val builder: AlertDialog.Builder = AlertDialog.Builder(this)
builder.setView(dialogView)
.setTitle(R.string.confirm_exit_dialog)
.setNegativeButton(R.string.no) { _, _ -> /*NO-OP*/}
.setNegativeButton(R.string.no) { _, _ -> /*NO-OP*/ }
.setPositiveButton(R.string.yes) { _, _ ->
if(dontShowAgainCheck.isChecked) {
if (dontShowAgainCheck.isChecked) {
settingsManager.edit().putInt(getString(R.string.confirm_exit_key), 1).commit()
}
exitProcess(0)
finish()
}

builder.show().setDefaultFocus()
Expand Down

0 comments on commit 94f012f

Please sign in to comment.