MoreHomeActivity re-arrangements of sizes in layout.
Notifications activity, adapter - dummy data
This commit is contained in:
@@ -35,6 +35,7 @@ import com.woka.home.BottomNavigation.Companion.MY_LIST
|
||||
import com.woka.home.fragments.Home1Fragment
|
||||
import com.woka.home.fragments.Home2Fragment
|
||||
import com.woka.home.fragments.MyListFragment
|
||||
import com.woka.home.notifications.NotificationsActivity
|
||||
import com.woka.home.sidebar.aboutwoka.AboutActivity
|
||||
import com.woka.home.sidebar.faqs.FaqActivity
|
||||
import com.woka.home.sidebar.profile.UserProfileActivity
|
||||
@@ -264,6 +265,11 @@ class HomeActivity : WokaBaseActivity(),
|
||||
|
||||
private fun clickEvents() {
|
||||
binding.apply {
|
||||
|
||||
notifications.setOnClickListener {
|
||||
startActivity(Intent(this@HomeActivity, NotificationsActivity::class.java))
|
||||
}
|
||||
|
||||
sideMenu.setOnClickListener {
|
||||
homeDrawer.openDrawer(GravityCompat.END)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.woka.home.notifications
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.AsyncDifferConfig
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
||||
import com.woka.databinding.NotificationViewHolderBinding
|
||||
import com.woka.home.notifications.models.NotificationData
|
||||
import java.text.SimpleDateFormat
|
||||
import java.time.LocalDate
|
||||
import java.time.temporal.ChronoUnit
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
class NotificationAdapter(config: AsyncDifferConfig<NotificationData>): ListAdapter<NotificationData, NotificationAdapter.NotificationViewHolder>(config) {
|
||||
|
||||
companion object{
|
||||
private val DIFF_UTIL = object : DiffUtil.ItemCallback<NotificationData>(){
|
||||
override fun areItemsTheSame(
|
||||
oldItem: NotificationData,
|
||||
newItem: NotificationData
|
||||
): Boolean = oldItem.id == newItem.id
|
||||
|
||||
override fun areContentsTheSame(
|
||||
oldItem: NotificationData,
|
||||
newItem: NotificationData
|
||||
): Boolean = oldItem == newItem
|
||||
}
|
||||
|
||||
private val DIFF_CONFIG = AsyncDifferConfig.Builder(DIFF_UTIL)
|
||||
.setBackgroundThreadExecutor(Executors.newSingleThreadExecutor())
|
||||
.build()
|
||||
}
|
||||
|
||||
constructor(): this(DIFF_CONFIG)
|
||||
|
||||
inner class NotificationViewHolder(val binding: NotificationViewHolderBinding): ViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NotificationViewHolder {
|
||||
return NotificationViewHolder(
|
||||
NotificationViewHolderBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent, false
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: NotificationViewHolder, position: Int) {
|
||||
val notification = getItem(position)
|
||||
notification.updated_at?.let {
|
||||
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'", Locale.getDefault())
|
||||
.parse(it)?.let { notificationDate ->
|
||||
val today = Calendar.getInstance()
|
||||
|
||||
val dayDiffs = (today.time.time - notificationDate.time)/(24 * 60 * 60 * 1000)
|
||||
val daysTxt = "$dayDiffs days ago"
|
||||
holder.binding.daysTxt.text = daysTxt
|
||||
}
|
||||
|
||||
holder.binding.bodyTxt.text = notification.title
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.woka.home.notifications
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import com.woka.R
|
||||
import com.woka.databinding.ActivityNotificationsBinding
|
||||
import com.woka.home.notifications.models.NotificationData
|
||||
import com.woka.utils.WokaBaseActivity
|
||||
|
||||
class NotificationsActivity : WokaBaseActivity() {
|
||||
|
||||
private lateinit var binding: ActivityNotificationsBinding
|
||||
|
||||
private lateinit var adapter: NotificationAdapter
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
binding = ActivityNotificationsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
|
||||
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
||||
insets
|
||||
}
|
||||
|
||||
adapter = NotificationAdapter()
|
||||
|
||||
initViews()
|
||||
|
||||
adapter.submitList(listOf(
|
||||
NotificationData(
|
||||
created_at = "2024-05-31T10:44:09.000000Z",
|
||||
description = "2024-05-31T10:44:09.000000Z",
|
||||
id = 1,
|
||||
image = null,
|
||||
is_read = 1,
|
||||
link = null,
|
||||
post_type = 2,
|
||||
title = "New Episode has been added toBang Bang Bang",
|
||||
type = "type",
|
||||
updated_at = "2024-05-31T10:44:09.000000Z",
|
||||
user_id = 1
|
||||
),
|
||||
NotificationData(
|
||||
created_at = "2024-05-31T10:44:09.000000Z",
|
||||
description = "2024-05-31T10:44:09.000000Z",
|
||||
id = 2,
|
||||
image = null,
|
||||
is_read = 1,
|
||||
link = null,
|
||||
post_type = 2,
|
||||
title = "New Episode has been added toBang Bang Bang",
|
||||
type = "type",
|
||||
updated_at = "2024-06-01T10:44:09.000000Z",
|
||||
user_id = 1
|
||||
)
|
||||
))
|
||||
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
binding.apply {
|
||||
rvNotifications.adapter = adapter
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.woka.home.notifications.models
|
||||
|
||||
data class NotificationData(
|
||||
val created_at: String?,
|
||||
val description: String?,
|
||||
val id: Int?,
|
||||
val image: String?,
|
||||
val is_read: Int?,
|
||||
val link: Any?,
|
||||
val post_type: Int?,
|
||||
val title: String?,
|
||||
val type: String?,
|
||||
val updated_at: String?,
|
||||
val user_id: Int?
|
||||
)
|
||||
@@ -76,7 +76,7 @@ class WokaSongsAdapter(context: Context): RecyclerView.Adapter<WokaSongsAdapter.
|
||||
|
||||
val lastPosition = currentPlayingPos
|
||||
currentPlayingPos = -1
|
||||
notifyItemChanged(lastPosition, PLAY_BACK_CHANGED)
|
||||
notifyItemChanged(lastPosition)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class WokaSongsAdapter(context: Context): RecyclerView.Adapter<WokaSongsAdapter.
|
||||
|
||||
val lastPosition = currentPlayingPos
|
||||
currentPlayingPos = -1
|
||||
notifyItemChanged(lastPosition, PLAY_BACK_CHANGED)
|
||||
notifyItemChanged(lastPosition)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,11 @@ class WokaSongsAdapter(context: Context): RecyclerView.Adapter<WokaSongsAdapter.
|
||||
progressBar.hide()
|
||||
}
|
||||
}
|
||||
else -> super.onBindViewHolder(holder, position, payloads)
|
||||
else -> {
|
||||
playBtn.show()
|
||||
playBtn.setImageResource(R.drawable.ic_play)
|
||||
progressBar.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user