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)
|
|
|
|
|
2022-07-17 20:49:55 +05:30
|
|
|
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()
|
2022-07-17 20:49:55 +05:30
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|