This commit is contained in:
Bnyro 2022-06-25 18:11:11 +02:00
parent 47c65ebfe8
commit c410c7c88f
3 changed files with 25 additions and 20 deletions

View File

@ -3,7 +3,6 @@ package com.github.libretube.dialogs
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.util.TypedValue
import android.widget.Button
import android.widget.EditText
@ -16,8 +15,6 @@ import com.github.libretube.R
import com.github.libretube.obj.DeleteUserRequest
import com.github.libretube.util.RetrofitInstance
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import retrofit2.HttpException
import java.io.IOException
class DeleteAccountDialog : DialogFragment() {
private val TAG = "DeleteAccountDialog"
@ -27,7 +24,11 @@ class DeleteAccountDialog : DialogFragment() {
return activity?.let {
val builder = MaterialAlertDialogBuilder(it)
val inflater = requireActivity().layoutInflater
val view = inflater.inflate(R.layout.dialog_login, null)
val view = inflater.inflate(R.layout.dialog_delete_account, null)
view.findViewById<Button>(R.id.cancel_button).setOnClickListener {
dialog?.dismiss()
}
password = view.findViewById(R.id.delete_password)
view.findViewById<Button>(R.id.delete_account_confirm).setOnClickListener {
@ -60,18 +61,8 @@ class DeleteAccountDialog : DialogFragment() {
val response = try {
RetrofitInstance.api.deleteAccount(token, DeleteUserRequest(password))
} catch (e: IOException) {
println(e)
Log.e(TAG, "IOException, you might not have internet connection")
Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT).show()
return@launchWhenCreated
} catch (e: HttpException) {
Log.e(TAG, "HttpException, unexpected response")
Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show()
return@launchWhenCreated
} catch (e: Exception) {
Log.e(TAG, "dafaq?$e")
return@launchWhenCreated
e.printStackTrace()
}
Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show()
logout()

View File

@ -22,6 +22,7 @@ import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import com.github.libretube.R
import com.github.libretube.dialogs.CustomInstanceDialog
import com.github.libretube.dialogs.DeleteAccountDialog
import com.github.libretube.dialogs.LoginDialog
import com.github.libretube.requireMainActivityRestart
import com.github.libretube.util.RetrofitInstance
@ -59,8 +60,8 @@ class InstanceSettings : PreferenceFragmentCompat() {
val jsonObject = JSONTokener(json).nextValue() as JSONObject
Log.e(TAG, jsonObject.getJSONArray("subscriptions").toString())
for (
i in 0 until jsonObject.getJSONArray("subscriptions")
.length()
i in 0 until jsonObject.getJSONArray("subscriptions")
.length()
) {
var url =
jsonObject.getJSONArray("subscriptions").getJSONObject(i)
@ -113,6 +114,9 @@ class InstanceSettings : PreferenceFragmentCompat() {
val topBarTextView = activity?.findViewById<TextView>(R.id.topBar_textView)
topBarTextView?.text = getString(R.string.instance)
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
val token = sharedPref?.getString("token", "")
val instance = findPreference<ListPreference>("selectInstance")
// fetchInstance()
initCustomInstances()
@ -150,10 +154,19 @@ class InstanceSettings : PreferenceFragmentCompat() {
true
}
val deleteAccount = findPreference<Preference>("delete_account")
deleteAccount?.setOnPreferenceClickListener {
if (token != "") {
val newFragment = DeleteAccountDialog()
newFragment.show(childFragmentManager, "DeleteAccountDialog")
} else {
Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT).show()
}
true
}
val importFromYt = findPreference<Preference>("import_from_yt")
importFromYt?.setOnPreferenceClickListener {
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
val token = sharedPref?.getString("token", "")!!
// check StorageAccess
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Log.d("myz", "" + Build.VERSION.SDK_INT)

View File

@ -5,7 +5,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:paddingVertical="5dp" >
<ImageButton
android:id="@+id/back_imageButton"