mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
commit
0319762e3f
@ -0,0 +1,85 @@
|
||||
package com.github.libretube.dialogs
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.util.TypedValue
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.core.text.HtmlCompat
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.obj.DeleteUserRequest
|
||||
import com.github.libretube.util.RetrofitInstance
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class DeleteAccountDialog : DialogFragment() {
|
||||
private val TAG = "DeleteAccountDialog"
|
||||
lateinit var username: EditText
|
||||
lateinit var password: EditText
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return activity?.let {
|
||||
val builder = MaterialAlertDialogBuilder(it)
|
||||
val inflater = requireActivity().layoutInflater
|
||||
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 {
|
||||
if (password.text.toString() != "") {
|
||||
deleteAccount(password.text.toString())
|
||||
} else {
|
||||
Toast.makeText(context, R.string.empty, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
val typedValue = TypedValue()
|
||||
this.requireActivity().theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true)
|
||||
val hexColor = String.format("#%06X", (0xFFFFFF and typedValue.data))
|
||||
val appName = HtmlCompat.fromHtml(
|
||||
"Libre<span style='color:$hexColor';>Tube</span>",
|
||||
HtmlCompat.FROM_HTML_MODE_COMPACT
|
||||
)
|
||||
view.findViewById<TextView>(R.id.title).text = appName
|
||||
|
||||
builder.setView(view)
|
||||
builder.create()
|
||||
} ?: throw IllegalStateException("Activity cannot be null")
|
||||
}
|
||||
|
||||
private fun deleteAccount(password: String) {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
val token = sharedPref?.getString("token", "")!!
|
||||
|
||||
val response = try {
|
||||
RetrofitInstance.api.deleteAccount(token, DeleteUserRequest(password))
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show()
|
||||
logout()
|
||||
dialog?.dismiss()
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
private fun logout() {
|
||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
val token = sharedPref?.getString("token", "")
|
||||
if (token != "") {
|
||||
with(sharedPref!!.edit()) {
|
||||
putString("token", "")
|
||||
apply()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.github.libretube.obj
|
||||
|
||||
data class DeleteUserRequest(
|
||||
var password: String? = null
|
||||
)
|
@ -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
|
||||
@ -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)
|
||||
|
@ -2,6 +2,7 @@ package com.github.libretube.util
|
||||
|
||||
import com.github.libretube.obj.Channel
|
||||
import com.github.libretube.obj.CommentsPage
|
||||
import com.github.libretube.obj.DeleteUserRequest
|
||||
import com.github.libretube.obj.Instances
|
||||
import com.github.libretube.obj.Login
|
||||
import com.github.libretube.obj.Message
|
||||
@ -86,6 +87,12 @@ interface PipedApi {
|
||||
@POST("register")
|
||||
suspend fun register(@Body login: Login): Token
|
||||
|
||||
@POST("user/delete")
|
||||
suspend fun deleteAccount(
|
||||
@Header("Authorization") token: String,
|
||||
@Body password: DeleteUserRequest
|
||||
): Message
|
||||
|
||||
@GET("feed")
|
||||
suspend fun getFeed(@Query("authToken") token: String?): List<StreamItem>
|
||||
|
||||
|
@ -5,15 +5,17 @@
|
||||
|
||||
<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"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="6dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginVertical="10dp"
|
||||
android:backgroundTint="@android:color/transparent"
|
||||
android:background="?android:selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_arrow_back" />
|
||||
|
||||
<TextView
|
||||
@ -21,7 +23,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings"
|
||||
android:layout_marginLeft="14dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:textSize="20sp"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
|
46
app/src/main/res/layout/dialog_delete_account.xml
Normal file
46
app/src/main/res/layout/dialog_delete_account.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/app_name"
|
||||
android:gravity="center"
|
||||
android:layout_margin="10dp"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout style="@style/CustomDialogTextInputLayout">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/delete_password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/password"
|
||||
android:inputType="text"
|
||||
android:padding="12dp" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="right">
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancel_button"
|
||||
android:text="@string/cancel"
|
||||
style="@style/CustomDialogButton" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/delete_account_confirm"
|
||||
android:text="@string/deleteAccount"
|
||||
style="@style/CustomDialogButton" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -26,8 +26,6 @@
|
||||
android:textSize="27sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<View style="@style/HorizontalLine" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/website"
|
||||
style="@style/AboutItem">
|
||||
@ -45,8 +43,6 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View style="@style/HorizontalLine" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/contributing"
|
||||
style="@style/AboutItem">
|
||||
@ -64,8 +60,6 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View style="@style/HorizontalLine" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/authors"
|
||||
style="@style/AboutItem">
|
||||
@ -83,8 +77,6 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View style="@style/HorizontalLine" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/piped"
|
||||
style="@style/AboutItem">
|
||||
@ -102,8 +94,6 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View style="@style/HorizontalLine" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/donate"
|
||||
style="@style/AboutItem">
|
||||
@ -121,8 +111,6 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View style="@style/HorizontalLine" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/license"
|
||||
style="@style/AboutItem">
|
||||
|
@ -43,7 +43,7 @@
|
||||
<string name="unknown_error">Network error.</string>
|
||||
<string name="error">Something went wrong.</string>
|
||||
<string name="empty">You have to enter a username and password.</string>
|
||||
<string name="notgmail">This is for a LibreTube account.</string>
|
||||
<string name="notgmail">This is for a Piped account.</string>
|
||||
<string name="defres">Default video resolution</string>
|
||||
<string name="grid">Grid columns</string>
|
||||
<string name="emptyList">Nothing here.</string>
|
||||
@ -203,4 +203,8 @@
|
||||
<string name="clonePlaylist">Clone playlist</string>
|
||||
<string name="reset">Restore defaults</string>
|
||||
<string name="reset_message">Are you sure? This will log you out and reset all your settings!</string>
|
||||
<string name="deleteAccount">Delete account</string>
|
||||
<string name="deleteAccount_summary">Delete your Piped account</string>
|
||||
<string name="account">Account</string>
|
||||
<string name="restore">Restore</string>
|
||||
</resources>
|
||||
|
@ -13,15 +13,19 @@
|
||||
app:title="@string/instances" />
|
||||
|
||||
<Preference
|
||||
android:icon="@drawable/ic_add_instance"
|
||||
app:key="customInstance"
|
||||
app:title="@string/customInstance"
|
||||
app:summary="@string/customInstance_summary"
|
||||
android:icon="@drawable/ic_add_instance" />
|
||||
app:title="@string/customInstance" />
|
||||
|
||||
<Preference
|
||||
android:icon="@drawable/ic_trash"
|
||||
app:key="clearCustomInstances"
|
||||
app:title="@string/clear_customInstances"
|
||||
android:icon="@drawable/ic_trash" />
|
||||
app:title="@string/clear_customInstances" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/account">
|
||||
|
||||
<Preference
|
||||
android:icon="@drawable/ic_login_filled"
|
||||
@ -29,6 +33,16 @@
|
||||
app:key="login_register"
|
||||
app:title="@string/login_register" />
|
||||
|
||||
<Preference
|
||||
android:icon="@drawable/ic_reset"
|
||||
android:summary="@string/deleteAccount_summary"
|
||||
app:key="delete_account"
|
||||
app:title="@string/deleteAccount" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/restore">
|
||||
|
||||
<Preference
|
||||
android:icon="@drawable/ic_upload"
|
||||
android:summary="@string/import_from_yt_summary"
|
||||
|
Loading…
Reference in New Issue
Block a user