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

37 lines
1.2 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-09-08 21:59:00 +05:30
import com.github.libretube.util.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 lateinit var binding: DialogLogoutBinding
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
2022-08-26 12:45:48 +05:30
binding = DialogLogoutBinding.inflate(layoutInflater)
2022-07-01 13:49:00 +05:30
2022-08-26 12:45:48 +05:30
val user = PreferenceHelper.getUsername()
2022-07-01 13:49:00 +05:30
2022-08-26 12:45:48 +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("")
dialog?.dismiss()
activity?.recreate()
}
2022-07-01 13:49:00 +05:30
2022-08-26 12:45:48 +05:30
binding.title.text = ThemeHelper.getStyledAppName(requireContext())
2022-07-01 13:49:00 +05:30
2022-08-26 12:45:48 +05:30
return MaterialAlertDialogBuilder(requireContext())
.setView(binding.root)
.show()
2022-07-01 13:49:00 +05:30
}
}