diff --git a/app/src/main/java/com/h/pixeldroid/fragments/feeds/HomeRecyclerViewAdapter.kt b/app/src/main/java/com/h/pixeldroid/fragments/feeds/HomeRecyclerViewAdapter.kt deleted file mode 100644 index b8aea1da..00000000 --- a/app/src/main/java/com/h/pixeldroid/fragments/feeds/HomeRecyclerViewAdapter.kt +++ /dev/null @@ -1,79 +0,0 @@ -package com.h.pixeldroid.fragments.feeds - -import android.graphics.Typeface -import android.util.DisplayMetrics -import androidx.recyclerview.widget.RecyclerView -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.ImageView -import android.widget.TextView -import com.h.pixeldroid.R -import com.h.pixeldroid.objects.Status -import com.h.pixeldroid.utils.ImageConverter.Companion.setDefaultImage -import com.h.pixeldroid.utils.ImageConverter.Companion.setImageViewFromURL -import com.h.pixeldroid.utils.ImageConverter.Companion.setRoundImageFromURL - -/** - * [RecyclerView.Adapter] that can display a list of Posts - */ -class HomeRecyclerViewAdapter() : FeedsRecyclerViewAdapter() { - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - val view = LayoutInflater.from(parent.context) - .inflate(R.layout.post_fragment, parent, false) - context = view.context - return ViewHolder(view) - } - - /** - * Binds the different elements of the Post Model to the view holder - */ - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val post = feedContent[position] - val metrics = DisplayMetrics() - - //Limit the height of the different images - holder.profilePic?.maxHeight = metrics.heightPixels - holder.postPic.maxHeight = metrics.heightPixels - - //Set the two images - setRoundImageFromURL(holder.postView, post.getProfilePicUrl(), holder.profilePic!!) - setImageViewFromURL(holder.postView, post.getPostUrl(), holder.postPic) - - //Set the image back to a placeholder if the original is too big - if(holder.postPic.height > metrics.heightPixels) { - setDefaultImage(holder.postView, holder.postPic) - } - - //Set the the text views - holder.username.text = post.getUsername() - holder.username.setTypeface(null, Typeface.BOLD) - - holder.usernameDesc.text = post.getUsername() - holder.usernameDesc.setTypeface(null, Typeface.BOLD) - - holder.description.text = post.getDescription() - - holder.nlikes.text = post.getNLikes() - holder.nlikes.setTypeface(null, Typeface.BOLD) - - holder.nshares.text = post.getNShares() - holder.nshares.setTypeface(null, Typeface.BOLD) - } - - override fun getItemCount(): Int = feedContent.size - - /** - * Represents the posts that will be contained within the feed - */ - inner class ViewHolder(val postView: View) : RecyclerView.ViewHolder(postView) { - val profilePic : ImageView? = postView.findViewById(R.id.profilePic) - val postPic : ImageView = postView.findViewById(R.id.postPicture) - val username : TextView = postView.findViewById(R.id.username) - val usernameDesc: TextView = postView.findViewById(R.id.usernameDesc) - val description : TextView = postView.findViewById(R.id.description) - val nlikes : TextView = postView.findViewById(R.id.nlikes) - val nshares : TextView = postView.findViewById(R.id.nshares) - } -} diff --git a/app/src/main/java/com/h/pixeldroid/fragments/feeds/NotificationsRecyclerViewAdapter.kt b/app/src/main/java/com/h/pixeldroid/fragments/feeds/NotificationsRecyclerViewAdapter.kt deleted file mode 100644 index 70806951..00000000 --- a/app/src/main/java/com/h/pixeldroid/fragments/feeds/NotificationsRecyclerViewAdapter.kt +++ /dev/null @@ -1,127 +0,0 @@ -package com.h.pixeldroid.fragments.feeds - - -import android.content.Context -import android.content.Intent -import android.graphics.drawable.Drawable -import android.net.Uri -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.ImageView -import android.widget.TextView -import android.widget.Toast -import androidx.recyclerview.widget.RecyclerView -import com.bumptech.glide.Glide -import com.bumptech.glide.request.RequestOptions -import com.h.pixeldroid.PostActivity -import com.h.pixeldroid.R -import com.h.pixeldroid.objects.Status.Companion.POST_TAG -import com.h.pixeldroid.objects.Notification -import kotlinx.android.synthetic.main.fragment_notifications.view.* - -/** - * [RecyclerView.Adapter] that can display a [Notification] - */ -class NotificationsRecyclerViewAdapter: FeedsRecyclerViewAdapter() { - - private val mOnClickListener: View.OnClickListener - - init { - mOnClickListener = View.OnClickListener { v -> - val notification = v.tag as Notification - openActivity(notification) - } - } - private fun openActivity(notification: Notification){ - val intent: Intent - when (notification.type){ - Notification.NotificationType.mention, Notification.NotificationType.favourite-> { - intent = Intent(context, PostActivity::class.java) - intent.putExtra(POST_TAG, notification.status) - } - Notification.NotificationType.reblog-> { - Toast.makeText(context,"Can't see shares yet, sorry!",Toast.LENGTH_SHORT).show() - return - } - Notification.NotificationType.follow -> { - val url = notification.status?.url ?: notification.account.url - intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) - } - } - context.startActivity(intent) - } - - fun addNotifications(newNotifications: List){ - val oldSize = feedContent.size - feedContent.addAll(newNotifications) - notifyItemRangeInserted(oldSize, newNotifications.size) - } - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - val view = LayoutInflater.from(parent.context) - .inflate(R.layout.fragment_notifications, parent, false) - - context = view.context - return ViewHolder(view) - } - - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val notification = feedContent[position] - Glide.with(holder.mView).load(notification.account.avatar_static).apply(RequestOptions().circleCrop()) - .placeholder(R.drawable.ic_default_user).into(holder.avatar) - - val previewUrl = notification.status?.media_attachments?.getOrNull(0)?.preview_url - if(!previewUrl.isNullOrBlank()){ - Glide.with(holder.mView).load(previewUrl) - .placeholder(R.drawable.ic_picture_fallback).into(holder.photoThumbnail) - } else{ - holder.photoThumbnail.visibility = View.GONE - } - - setNotificationType(notification.type, notification.account.username, holder.notificationType) - - holder.postDescription.text = notification.status?.content ?: "" - - - with(holder.mView) { - tag = notification - setOnClickListener(mOnClickListener) - } - } - - private fun setNotificationType(type: Notification.NotificationType, username: String, - textView: TextView){ - val context = textView.context - val (format: String, drawable: Drawable?) = when(type) { - Notification.NotificationType.follow -> { - setNotificationTypeTextView(context, R.string.followed_notification, R.drawable.ic_follow) - } - Notification.NotificationType.mention -> { - setNotificationTypeTextView(context, R.string.mention_notification, R.drawable.ic_apenstaart) - } - - Notification.NotificationType.reblog -> { - setNotificationTypeTextView(context, R.string.shared_notification, R.drawable.ic_share) - } - - Notification.NotificationType.favourite -> { - setNotificationTypeTextView(context, R.string.liked_notification, R.drawable.ic_heart) - } - } - textView.text = format.format(username) - textView.setCompoundDrawablesWithIntrinsicBounds( - drawable,null,null,null - ) - } - private fun setNotificationTypeTextView(context: Context, format: Int, drawable: Int): Pair { - return Pair(context.getString(format), context.getDrawable(drawable)) - } - - - inner class ViewHolder(val mView: View) : RecyclerView.ViewHolder(mView) { - val notificationType: TextView = mView.notification_type - val postDescription: TextView = mView.notification_post_description - val avatar: ImageView = mView.notification_avatar - val photoThumbnail: ImageView = mView.notification_photo_thumbnail - } -}