forked from AniFOSS/CloudStream-3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
268 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 80 additions & 12 deletions
92
app/src/main/java/com/lagradost/cloudstream3/syncproviders/OAuth2Interface.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/lagradost/cloudstream3/ui/settings/AccountAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.lagradost.cloudstream3.ui.settings | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import androidx.core.view.isVisible | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.lagradost.cloudstream3.R | ||
import com.lagradost.cloudstream3.syncproviders.OAuth2Interface | ||
import com.lagradost.cloudstream3.utils.UIHelper.setImage | ||
|
||
class AccountClickCallback(val action: Int, val view : View, val card: OAuth2Interface.LoginInfo) | ||
|
||
class AccountAdapter( | ||
val cardList: List<OAuth2Interface.LoginInfo>, | ||
val layout: Int = R.layout.account_single, | ||
private val clickCallback: (AccountClickCallback) -> Unit | ||
) : | ||
RecyclerView.Adapter<RecyclerView.ViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | ||
return CardViewHolder( | ||
LayoutInflater.from(parent.context).inflate(layout, parent, false), clickCallback | ||
) | ||
} | ||
|
||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { | ||
when (holder) { | ||
is CardViewHolder -> { | ||
holder.bind(cardList[position]) | ||
} | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return cardList.size | ||
} | ||
|
||
override fun getItemId(position: Int): Long { | ||
return cardList[position].accountIndex.toLong() | ||
} | ||
|
||
class CardViewHolder | ||
constructor(itemView: View, private val clickCallback: (AccountClickCallback) -> Unit) : | ||
RecyclerView.ViewHolder(itemView) { | ||
private val pfp: ImageView = itemView.findViewById(R.id.account_profile_picture)!! | ||
private val accountName: TextView = itemView.findViewById(R.id.account_name)!! | ||
|
||
fun bind(card: OAuth2Interface.LoginInfo) { | ||
// just in case name is null account index will show, should never happened | ||
accountName.text = card.name ?: "%s %d".format(accountName.context.getString(R.string.account), card.accountIndex) | ||
if(card.profilePicture.isNullOrEmpty()) { | ||
pfp.isVisible = false | ||
} else { | ||
pfp.isVisible = true | ||
pfp.setImage(card.profilePicture) | ||
} | ||
|
||
itemView.setOnClickListener { | ||
clickCallback.invoke(AccountClickCallback(0, itemView, card)) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.