From 0d30ad1227a28c40f796a6bc7e9f548dc2efe0f2 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 25 Jun 2022 21:26:37 +0200 Subject: [PATCH] fix delete accounts --- .../com/github/libretube/dialogs/DeleteAccountDialog.kt | 4 +++- .../com/github/libretube/preferences/InstanceSettings.kt | 8 ++++---- app/src/main/java/com/github/libretube/util/PipedApi.kt | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/github/libretube/dialogs/DeleteAccountDialog.kt b/app/src/main/java/com/github/libretube/dialogs/DeleteAccountDialog.kt index e9cb5458e..ad81fe784 100644 --- a/app/src/main/java/com/github/libretube/dialogs/DeleteAccountDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/DeleteAccountDialog.kt @@ -3,6 +3,7 @@ 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 @@ -62,7 +63,8 @@ class DeleteAccountDialog : DialogFragment() { val response = try { RetrofitInstance.api.deleteAccount(token, DeleteUserRequest(password)) } catch (e: Exception) { - e.printStackTrace() + Log.e(TAG, e.toString()) + Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT).show() return@launchWhenCreated } Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show() diff --git a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt index f1d6785b0..02e1960b0 100644 --- a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt @@ -114,9 +114,6 @@ class InstanceSettings : PreferenceFragmentCompat() { val topBarTextView = activity?.findViewById(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("selectInstance") // fetchInstance() initCustomInstances() @@ -155,8 +152,9 @@ class InstanceSettings : PreferenceFragmentCompat() { } val deleteAccount = findPreference("delete_account") - deleteAccount?.parent?.removePreference(deleteAccount) deleteAccount?.setOnPreferenceClickListener { + val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) + val token = sharedPref?.getString("token", "") if (token != "") { val newFragment = DeleteAccountDialog() newFragment.show(childFragmentManager, "DeleteAccountDialog") @@ -168,6 +166,8 @@ class InstanceSettings : PreferenceFragmentCompat() { val importFromYt = findPreference("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) diff --git a/app/src/main/java/com/github/libretube/util/PipedApi.kt b/app/src/main/java/com/github/libretube/util/PipedApi.kt index 86018af13..ca0f791a5 100644 --- a/app/src/main/java/com/github/libretube/util/PipedApi.kt +++ b/app/src/main/java/com/github/libretube/util/PipedApi.kt @@ -91,7 +91,7 @@ interface PipedApi { suspend fun deleteAccount( @Header("Authorization") token: String, @Body password: DeleteUserRequest - ): Message + ) @GET("feed") suspend fun getFeed(@Query("authToken") token: String?): List