feat(ui): show account name and image on main settings page (#1001)

This commit is contained in:
IndusAryan 2024-04-22 20:18:54 +05:30 committed by GitHub
parent 4399a612df
commit 0744189020
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 57 additions and 17 deletions

View file

@ -1,13 +1,13 @@
package com.lagradost.cloudstream3.ui.settings package com.lagradost.cloudstream3.ui.settings
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.core.view.children import androidx.core.view.children
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams import androidx.core.view.updateLayoutParams
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.preference.Preference import androidx.preference.Preference
@ -18,12 +18,14 @@ import com.lagradost.cloudstream3.BuildConfig
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.databinding.MainSettingsBinding import com.lagradost.cloudstream3.databinding.MainSettingsBinding
import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.syncproviders.AccountManager
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers
import com.lagradost.cloudstream3.ui.home.HomeFragment import com.lagradost.cloudstream3.ui.home.HomeFragment
import com.lagradost.cloudstream3.ui.result.txt import com.lagradost.cloudstream3.ui.result.txt
import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR
import com.lagradost.cloudstream3.ui.settings.Globals.TV import com.lagradost.cloudstream3.ui.settings.Globals.TV
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
import com.lagradost.cloudstream3.utils.DataStoreHelper
import com.lagradost.cloudstream3.utils.UIHelper import com.lagradost.cloudstream3.utils.UIHelper
import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper
import com.lagradost.cloudstream3.utils.UIHelper.navigate import com.lagradost.cloudstream3.utils.UIHelper.navigate
@ -133,7 +135,6 @@ class SettingsFragment : Fragment() {
val localBinding = MainSettingsBinding.inflate(inflater, container, false) val localBinding = MainSettingsBinding.inflate(inflater, container, false)
binding = localBinding binding = localBinding
return localBinding.root return localBinding.root
//return inflater.inflate(R.layout.main_settings, container, false)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -141,21 +142,44 @@ class SettingsFragment : Fragment() {
activity?.navigate(id, Bundle()) activity?.navigate(id, Bundle())
} }
// used to debug leaks showToast(activity,"${VideoDownloadManager.downloadStatusEvent.size} : ${VideoDownloadManager.downloadProgressEvent.size}") /** used to debug leaks
showToast(activity,"${VideoDownloadManager.downloadStatusEvent.size} :
${VideoDownloadManager.downloadProgressEvent.size}") **/
for (syncApi in accountManagers) { fun hasProfilePictureFromAccountManagers(accountManagers: List<AccountManager>): Boolean {
val login = syncApi.loginInfo() for (syncApi in accountManagers) {
val pic = login?.profilePicture ?: continue val login = syncApi.loginInfo()
if (binding?.settingsProfilePic?.setImage( val pic = login?.profilePicture ?: continue
pic,
errorImageDrawable = HomeFragment.errorProfilePic if (binding?.settingsProfilePic?.setImage(
) == true pic,
) { errorImageDrawable = HomeFragment.errorProfilePic
binding?.settingsProfileText?.text = login.name ) == true
binding?.settingsProfile?.isVisible = true ) {
break binding?.settingsProfileText?.text = login.name
return true // sync profile exists
}
} }
return false // not syncing
} }
// display local account information if not syncing
if (!hasProfilePictureFromAccountManagers(accountManagers)) {
val activity = activity ?: return
val currentAccount = try {
DataStoreHelper.accounts.firstOrNull {
it.keyIndex == DataStoreHelper.selectedKeyIndex
} ?: activity.let { DataStoreHelper.getDefaultAccount(activity) }
} catch (t: IllegalStateException) {
Log.e("AccountManager", "Activity not found", t)
null
}
binding?.settingsProfilePic?.setImage(currentAccount?.image)
binding?.settingsProfileText?.text = currentAccount?.name
}
binding?.apply { binding?.apply {
listOf( listOf(
settingsGeneral to R.id.action_navigation_global_to_navigation_settings_general, settingsGeneral to R.id.action_navigation_global_to_navigation_settings_general,

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@android:color/white">
<item>
<shape android:shape="oval">
<stroke
android:width="2dp"
android:color="?attr/white" />
<corners android:radius="10dp" />
</shape>
</item>
</ripple>

View file

@ -24,7 +24,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:padding="20dp" android:padding="20dp"
android:visibility="gone"
tools:visibility="visible"> tools:visibility="visible">
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
@ -36,7 +35,11 @@
android:id="@+id/settings_profile_pic" android:id="@+id/settings_profile_pic"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:ignore="ContentDescription" /> android:scaleType="centerCrop"
android:foreground="@drawable/rounded_outline"
tools:src="@drawable/profile_bg_orange"
android:contentDescription="@string/account"/>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
<TextView <TextView
@ -50,7 +53,7 @@
android:textColor="?attr/textColor" android:textColor="?attr/textColor"
android:textSize="18sp" android:textSize="18sp"
android:textStyle="normal" android:textStyle="normal"
tools:text="Hello world" /> tools:text="Quick Brown Fox" />
</LinearLayout> </LinearLayout>
<TextView <TextView