This file contains hidden or 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
class FeedAdapterOld(var items: List<FeedItem> = listOf()) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { | |
override fun getItemViewType(position: Int): Int { | |
return when(items[position]) { | |
is FeedPostItem -> ITEM_POST_ID | |
is FeedStandardItem -> ITEM_STANDARD_ID | |
else -> -1 | |
} | |
} |
This file contains hidden or 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
class FeedAdapterOld(var items: List<FeedItem> = listOf()) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { | |
override fun getItemViewType(position: Int): Int { | |
return when(items[position]) { | |
is FeedPostItem -> ITEM_POST_ID | |
is FeedStandardItem -> ITEM_STANDARD_ID | |
is FeedStoryItem -> ITEM_STORY_ID | |
else -> -1 | |
} | |
} |
This file contains hidden or 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
class GenericAdapter<T>(var items: List<T>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { | |
private val delegateManager = AdapterDelegateManager<T>() | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | |
return delegateManager.onCreateViewHolder(parent, viewType) | |
} | |
override fun getItemCount(): Int { | |
return items.size |
This file contains hidden or 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
class AdapterDelegateManager<T> { | |
private val delegates = mutableListOf<AdapterDelegate<T>>() | |
fun addDelegate(delegate: AdapterDelegate<T>) { | |
delegates.add(delegate) | |
} | |
fun getItemViewType(items: List<T>, position: Int): Int { | |
delegates.forEachIndexed { index, it -> if (it.isForViewType(items, position)) return index } |
This file contains hidden or 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
interface AdapterDelegate <T> { | |
fun isForViewType(items: List<T>, position: Int): Boolean | |
fun onCreateViewHolder(parent: ViewGroup): RecyclerView.ViewHolder | |
fun onBindViewHolder(items: List<T>, position: Int, holder: RecyclerView.ViewHolder) | |
} |
This file contains hidden or 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
v.img_icon.run { | |
when(data[i].permissionTypeId){ | |
1 -> setImageDrawable(ContextCompat.getDrawable(c, R.drawable.ic_plus)) | |
2 -> setImageDrawable(ContextCompat.getDrawable(c, R.drawable.ic_permission_green)) | |
3 -> setImageDrawable(ContextCompat.getDrawable(c, R.drawable.ic_clock_orange)) | |
} | |
} | |
v.tv_status.run{ | |
when(data[i].statusId){ |
This file contains hidden or 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
if (data[i].value != null) { | |
Glide.with(c).load(data[i].value).apply( | |
RequestOptions() | |
.placeholder(R.drawable.loading) | |
.fitCenter() | |
).into(myViewHolder.itemView.img_thumbnail) | |
myViewHolder.itemView.img_thumbnail.setOnClickListener { | |
var i = Intent(c, ImageActivity::class.java) | |
i.putExtra(SharedKey.App.ID, data[myViewHolder.adapterPosition].value) |
This file contains hidden or 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
private fun doUpload(fileToUpload: MultipartBody.Part) { | |
uploadJob = CoroutineScope(Dispatchers.IO).launch { | |
val result = Request.uploadImg(baseContext, fileToUpload) | |
withContext(Dispatchers.Main) { | |
if (result.result == true) onSucceed(result) | |
} | |
} | |
} |
This file contains hidden or 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
object Request{ | |
suspend fun login(context:Context, email:String, password:String, token:String):UserModel?{ | |
val api = getApiService(context) | |
val request = api.login(email, password, token) | |
return try{ | |
return request.await().body()!! | |
}catch (e: Exception){ | |
Log.e("TAG", "Login Failed" + e.message) | |
null | |
} |