LibreTube/app/src/main/java/com/github/libretube/dialogs/LogoutDialog.kt

40 lines
1.4 KiB
Kotlin
Raw Normal View History

2022-07-01 13:49:00 +05:30
package com.github.libretube.dialogs
import android.app.Dialog
import android.os.Bundle
import android.widget.Toast
import androidx.fragment.app.DialogFragment
import com.github.libretube.R
import com.github.libretube.databinding.DialogLogoutBinding
2022-07-02 21:53:24 +05:30
import com.github.libretube.preferences.PreferenceHelper
2022-07-04 12:25:52 +05:30
import com.github.libretube.util.ThemeHelper
2022-07-01 13:49:00 +05:30
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class LogoutDialog : DialogFragment() {
private val TAG = "LogoutDialog"
private lateinit var binding: DialogLogoutBinding
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return activity?.let {
val builder = MaterialAlertDialogBuilder(it)
binding = DialogLogoutBinding.inflate(layoutInflater)
val user = PreferenceHelper.getUsername()
2022-07-01 13:49:00 +05:30
binding.user.text =
binding.user.text.toString() + " (" + user + ")"
binding.logout.setOnClickListener {
Toast.makeText(context, R.string.loggedout, Toast.LENGTH_SHORT).show()
PreferenceHelper.setToken("")
2022-07-01 13:49:00 +05:30
dialog?.dismiss()
2022-07-08 17:56:00 +05:30
activity?.recreate()
2022-07-01 13:49:00 +05:30
}
2022-07-04 12:25:52 +05:30
binding.title.text = ThemeHelper.getStyledAppName(requireContext())
2022-07-01 13:49:00 +05:30
builder.setView(binding.root)
builder.create()
} ?: throw IllegalStateException("Activity cannot be null")
}
}