ModuleDialog in all view all sections of MyListFragment.
Syncing data by reloading latest 3 favs of the currently viewed view all.
This commit is contained in:
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -15,6 +15,5 @@
|
||||
<option name="resolveExternalAnnotations" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
<option name="offlineMode" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -70,7 +70,9 @@ import com.woka.wokagames.playerr.GamePlayerData
|
||||
import kotlinx.coroutines.launch
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Collections
|
||||
import java.util.Locale
|
||||
import kotlin.math.max
|
||||
|
||||
class MyListFragment : Fragment() {
|
||||
|
||||
@@ -84,6 +86,10 @@ class MyListFragment : Fragment() {
|
||||
private lateinit var gamesAdapter: FavGamesAdapter
|
||||
|
||||
private var webShowIntentLauncher: ActivityResultLauncher<Intent>? = null
|
||||
private var favActivityLauncher: ActivityResultLauncher<Intent>? = null
|
||||
|
||||
private var openedViewAll: PostType? = null
|
||||
private var openedViewAllCategory: String? = null
|
||||
|
||||
private lateinit var dialogBinding: DialogModuleShowerBinding
|
||||
private lateinit var moduleShowerDialog: Dialog
|
||||
@@ -173,48 +179,69 @@ class MyListFragment : Fragment() {
|
||||
|
||||
webSeriesEngViewAll.setOnClickListener {
|
||||
activity?.let { activity ->
|
||||
startActivity(Intent(activity, FavoritesActivity::class.java).apply {
|
||||
putExtra(EXTRA_FAVORITE_TITLE, getString(R.string.web_series_english))
|
||||
putExtra(EXTRA_FAVORITE_CONTENT_TYPE, ContentType.SERIES.id)
|
||||
putExtra(EXTRA_FAVORITE_WEB_SERIES_IS_ENGLISH, true)
|
||||
})
|
||||
openedViewAll = PostType.WEB_SERIES
|
||||
openedViewAllCategory = "1"
|
||||
favActivityLauncher?.launch(
|
||||
Intent(
|
||||
activity,
|
||||
FavoritesActivity::class.java
|
||||
).apply {
|
||||
putExtra(EXTRA_FAVORITE_TITLE, getString(R.string.web_series_english))
|
||||
putExtra(EXTRA_FAVORITE_CONTENT_TYPE, ContentType.SERIES.id)
|
||||
putExtra(EXTRA_FAVORITE_WEB_SERIES_IS_ENGLISH, true)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
webSeriesHinViewAll.setOnClickListener {
|
||||
activity?.let { activity ->
|
||||
startActivity(Intent(activity, FavoritesActivity::class.java).apply {
|
||||
putExtra(EXTRA_FAVORITE_TITLE, getString(R.string.web_series_hindi))
|
||||
putExtra(EXTRA_FAVORITE_CONTENT_TYPE, ContentType.SERIES.id)
|
||||
putExtra(EXTRA_FAVORITE_WEB_SERIES_IS_ENGLISH, false)
|
||||
})
|
||||
openedViewAll = PostType.WEB_SERIES
|
||||
openedViewAllCategory = "18"
|
||||
favActivityLauncher?.launch(
|
||||
Intent(
|
||||
activity,
|
||||
FavoritesActivity::class.java
|
||||
).apply {
|
||||
putExtra(EXTRA_FAVORITE_TITLE, getString(R.string.web_series_hindi))
|
||||
putExtra(EXTRA_FAVORITE_CONTENT_TYPE, ContentType.SERIES.id)
|
||||
putExtra(EXTRA_FAVORITE_WEB_SERIES_IS_ENGLISH, false)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
audioBooksViewAll.setOnClickListener {
|
||||
activity?.let { activity ->
|
||||
startActivity(Intent(activity, FavoritesActivity::class.java).apply {
|
||||
putExtra(EXTRA_FAVORITE_TITLE, getString(R.string.audio_books))
|
||||
putExtra(EXTRA_FAVORITE_CONTENT_TYPE, ContentType.AUDIO.id)
|
||||
})
|
||||
openedViewAll = PostType.AUDIO_BOOKS
|
||||
favActivityLauncher?.launch(
|
||||
Intent(activity, FavoritesActivity::class.java).apply {
|
||||
putExtra(EXTRA_FAVORITE_TITLE, getString(R.string.audio_books))
|
||||
putExtra(EXTRA_FAVORITE_CONTENT_TYPE, ContentType.AUDIO.id)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
gamesViewAll.setOnClickListener {
|
||||
activity?.let { activity ->
|
||||
startActivity(Intent(activity, FavoritesActivity::class.java).apply {
|
||||
putExtra(EXTRA_FAVORITE_TITLE, getString(R.string.games))
|
||||
putExtra(EXTRA_FAVORITE_CONTENT_TYPE, ContentType.GAME.id)
|
||||
})
|
||||
openedViewAll = PostType.GAMES
|
||||
favActivityLauncher?.launch(
|
||||
Intent(activity, FavoritesActivity::class.java).apply {
|
||||
putExtra(EXTRA_FAVORITE_TITLE, getString(R.string.games))
|
||||
putExtra(EXTRA_FAVORITE_CONTENT_TYPE, ContentType.GAME.id)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
karaokeViewAll.setOnClickListener {
|
||||
activity?.let { activity ->
|
||||
startActivity(Intent(activity, FavoritesActivity::class.java).apply {
|
||||
putExtra(EXTRA_FAVORITE_TITLE, getString(R.string.karaoke))
|
||||
putExtra(EXTRA_FAVORITE_CONTENT_TYPE, ContentType.KARAOKE_VIDEO.id)
|
||||
})
|
||||
openedViewAll = PostType.KARAOKE
|
||||
favActivityLauncher?.launch(
|
||||
Intent(activity, FavoritesActivity::class.java).apply {
|
||||
putExtra(EXTRA_FAVORITE_TITLE, getString(R.string.karaoke))
|
||||
putExtra(EXTRA_FAVORITE_CONTENT_TYPE, ContentType.KARAOKE_VIDEO.id)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,11 +249,55 @@ class MyListFragment : Fragment() {
|
||||
|
||||
private fun registerIntentLaunchers() {
|
||||
webShowIntentLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
if (it.resultCode == AppCompatActivity.RESULT_OK) {
|
||||
it.data?.getStringExtra(EXTRA_SHOW_CATEGORY)?.let { showCategory ->
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == AppCompatActivity.RESULT_OK) {
|
||||
result.data?.getStringExtra(EXTRA_SHOW_CATEGORY)?.let { showCategory ->
|
||||
onWebShowItemChanged(showCategory)
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
result?.data?.getParcelableExtra<ShowData>(EXTRA_SHOW_DATA)?.let { showData ->
|
||||
val hPos =
|
||||
webSeriesHAdapter.currentList.indexOfFirst { it.id == showData.id }
|
||||
if (hPos >= 0 && hPos < webSeriesHAdapter.currentList.size) {
|
||||
webSeriesHAdapter.currentList[hPos].likes_count = showData.likes_count
|
||||
webSeriesHAdapter.currentList[hPos].is_liked = showData.is_liked
|
||||
webSeriesHAdapter.currentList[hPos].bookmark_category_ids =
|
||||
showData.favourite_category_ids
|
||||
}
|
||||
|
||||
val ePos =
|
||||
webSeriesEAdapter.currentList.indexOfFirst { it.id == showData.id }
|
||||
if (ePos >= 0 && ePos < webSeriesEAdapter.currentList.size) {
|
||||
webSeriesEAdapter.currentList[ePos].likes_count = showData.likes_count
|
||||
webSeriesEAdapter.currentList[ePos].is_liked = showData.is_liked
|
||||
webSeriesEAdapter.currentList[hPos].bookmark_category_ids =
|
||||
showData.favourite_category_ids
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
favActivityLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
when (openedViewAll) {
|
||||
PostType.WEB_SERIES -> {
|
||||
openedViewAllCategory?.let { onWebShowItemChanged(it) }
|
||||
}
|
||||
|
||||
PostType.AUDIO_BOOKS -> {
|
||||
onAudioItemChanged()
|
||||
}
|
||||
|
||||
PostType.KARAOKE -> {
|
||||
onKaraokeChanged()
|
||||
}
|
||||
|
||||
PostType.GAMES -> {
|
||||
onGameChanged()
|
||||
}
|
||||
|
||||
null -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,7 +354,7 @@ class MyListFragment : Fragment() {
|
||||
|
||||
webSeriesEngViewAll.setVisibility(showData.size >= 3)
|
||||
} else {
|
||||
webSeriesEnglishView.hide()
|
||||
onListGotEmpty(PostType.WEB_SERIES, true)
|
||||
}
|
||||
|
||||
if (hinList.isNotEmpty()) {
|
||||
@@ -293,7 +364,7 @@ class MyListFragment : Fragment() {
|
||||
|
||||
webSeriesHinViewAll.setVisibility(showData.size >= 3)
|
||||
} else {
|
||||
webSeriesHindiView.hide()
|
||||
onListGotEmpty(PostType.WEB_SERIES, false)
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -308,11 +379,12 @@ class MyListFragment : Fragment() {
|
||||
audioBooksView.show()
|
||||
|
||||
dataLoaded = true
|
||||
audioBooksAdapter.submitList(audioData)
|
||||
// submitting a new list to over come the same list problem of list adapter
|
||||
audioBooksAdapter.submitList(ArrayList(audioData))
|
||||
|
||||
audioBooksViewAll.setVisibility(audioData.size >= 3)
|
||||
} else {
|
||||
audioBooksView.hide()
|
||||
onListGotEmpty(PostType.AUDIO_BOOKS)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -322,10 +394,11 @@ class MyListFragment : Fragment() {
|
||||
karaokeView.show()
|
||||
|
||||
dataLoaded = true
|
||||
karaokeAdapter.submitList(singKaraokeData)
|
||||
// submitting a new list to over come the same list problem of list adapter
|
||||
karaokeAdapter.submitList(ArrayList(singKaraokeData))
|
||||
karaokeViewAll.setVisibility(singKaraokeData.size >= 3)
|
||||
} else {
|
||||
karaokeView.hide()
|
||||
onListGotEmpty(PostType.KARAOKE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,10 +407,11 @@ class MyListFragment : Fragment() {
|
||||
gamesView.show()
|
||||
|
||||
dataLoaded = true
|
||||
gamesAdapter.submitList(gamesData)
|
||||
// submitting a new list to over come the same list problem of list adapter
|
||||
gamesAdapter.submitList(ArrayList(gamesData))
|
||||
gamesViewAll.setVisibility(gamesData.size >= 3)
|
||||
} else {
|
||||
gamesView.hide()
|
||||
onListGotEmpty(PostType.GAMES)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,14 +529,35 @@ class MyListFragment : Fragment() {
|
||||
ContentType.SERIES.id,
|
||||
0, 3, showCategory
|
||||
)) {
|
||||
is ApiResult.Error -> {}
|
||||
is ApiResult.Error -> {
|
||||
if (showCategory == "1") {
|
||||
onListGotEmpty(PostType.WEB_SERIES, true)
|
||||
} else if (showCategory == "18") {
|
||||
onListGotEmpty(PostType.WEB_SERIES, false)
|
||||
}
|
||||
|
||||
MyListRepository.updateSeriesList(Collections.emptyList())
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {}
|
||||
is ApiResult.Success -> {
|
||||
response.data?.result?.show_data?.let {
|
||||
if (showCategory == "1"){
|
||||
webSeriesEAdapter.submitList(it)
|
||||
}else if (showCategory == "18"){
|
||||
webSeriesHAdapter.submitList(it)
|
||||
if (showCategory == "1") {
|
||||
if (it.isNotEmpty()) {
|
||||
webSeriesEAdapter.submitList(it)
|
||||
} else {
|
||||
onListGotEmpty(PostType.WEB_SERIES, true)
|
||||
}
|
||||
|
||||
binding.webSeriesEngViewAll.setVisibility(it.size >= 3)
|
||||
} else if (showCategory == "18") {
|
||||
if (it.isNotEmpty()) {
|
||||
webSeriesHAdapter.submitList(it)
|
||||
} else {
|
||||
onListGotEmpty(PostType.WEB_SERIES, false)
|
||||
}
|
||||
|
||||
binding.webSeriesHinViewAll.setVisibility(it.size >= 3)
|
||||
}
|
||||
|
||||
MyListRepository.updateSeriesList(it)
|
||||
@@ -546,6 +641,14 @@ class MyListFragment : Fragment() {
|
||||
!like.isSelected
|
||||
)
|
||||
|
||||
audioBookData.likes_count = if (like.isSelected) {
|
||||
max(0, (audioBookData.likes_count ?: 0) - 1)
|
||||
} else {
|
||||
(audioBookData.likes_count ?: 0) + 1
|
||||
}
|
||||
|
||||
audioBookData.is_liked = !like.isSelected
|
||||
|
||||
like.isSelected = !like.isSelected
|
||||
likeCount.text = "${audioBookData.likes_count}"
|
||||
}
|
||||
@@ -562,7 +665,6 @@ class MyListFragment : Fragment() {
|
||||
)
|
||||
|
||||
fav.isSelected = !fav.isSelected
|
||||
|
||||
itemRemovedFromDialog = !fav.isSelected
|
||||
}
|
||||
|
||||
@@ -571,10 +673,10 @@ class MyListFragment : Fragment() {
|
||||
}
|
||||
|
||||
moduleShowerDialog.setOnDismissListener {
|
||||
if (itemRemovedFromDialog){
|
||||
if (itemRemovedFromDialog) {
|
||||
// item was removed at last
|
||||
onAudioItemChanged()
|
||||
}else{
|
||||
} else {
|
||||
// item was not at last removed
|
||||
MyListRepository.setLoadNewDataFlag(false)
|
||||
}
|
||||
@@ -595,11 +697,21 @@ class MyListFragment : Fragment() {
|
||||
ContentType.AUDIO.id,
|
||||
0, 3
|
||||
)) {
|
||||
is ApiResult.Error -> {}
|
||||
is ApiResult.Error -> {
|
||||
onListGotEmpty(PostType.AUDIO_BOOKS)
|
||||
MyListRepository.updateAudioList(Collections.emptyList())
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {}
|
||||
is ApiResult.Success -> {
|
||||
is ApiResult.Success -> {
|
||||
response.data?.result?.audio_data?.let {
|
||||
audioBooksAdapter.submitList(it)
|
||||
if (it.isNotEmpty()) {
|
||||
audioBooksAdapter.submitList(it)
|
||||
} else {
|
||||
onListGotEmpty(PostType.AUDIO_BOOKS)
|
||||
}
|
||||
|
||||
binding.audioBooksViewAll.setVisibility(it.size >= 3)
|
||||
|
||||
MyListRepository.updateAudioList(it)
|
||||
}
|
||||
@@ -739,9 +851,14 @@ class MyListFragment : Fragment() {
|
||||
!like.isSelected
|
||||
)
|
||||
|
||||
gameData.id?.let {
|
||||
onGameChanged(it)
|
||||
gameData.likes_count = if (like.isSelected) {
|
||||
max(0, (gameData.likes_count ?: 0) - 1)
|
||||
} else {
|
||||
(gameData.likes_count ?: 0) + 1
|
||||
}
|
||||
|
||||
gameData.is_liked = !like.isSelected
|
||||
|
||||
like.isSelected = !like.isSelected
|
||||
likeCount.text = "${gameData.likes_count}"
|
||||
}
|
||||
@@ -757,23 +874,26 @@ class MyListFragment : Fragment() {
|
||||
!fav.isSelected
|
||||
)
|
||||
|
||||
try {
|
||||
gamesAdapter.notifyItemRemoved(position)
|
||||
} catch (e: Exception) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
if (gamesAdapter.currentList.isEmpty()) {
|
||||
onListGotEmpty(PostType.GAMES)
|
||||
}
|
||||
|
||||
moduleShowerDialog.dismiss()
|
||||
fav.isSelected = !fav.isSelected
|
||||
itemRemovedFromDialog = !fav.isSelected
|
||||
}
|
||||
|
||||
close.setOnClickListener {
|
||||
moduleShowerDialog.dismiss()
|
||||
}
|
||||
|
||||
moduleShowerDialog.setOnDismissListener {
|
||||
if (itemRemovedFromDialog) {
|
||||
// item was removed at last
|
||||
onGameChanged()
|
||||
} else {
|
||||
// item was not at last removed
|
||||
MyListRepository.setLoadNewDataFlag(false)
|
||||
}
|
||||
}
|
||||
|
||||
itemRemovedFromDialog = false
|
||||
|
||||
moduleShowerDialog.show()
|
||||
}
|
||||
}
|
||||
@@ -781,11 +901,32 @@ class MyListFragment : Fragment() {
|
||||
clickHelper.upsertClickEvent(ContentType.GAME, gameData.id)
|
||||
}
|
||||
|
||||
private fun onGameChanged(id: Int) {
|
||||
// updating continue book list
|
||||
val position = gamesAdapter.currentList.indexOfFirst { it.id == id }
|
||||
if (position >= 0 && position < gamesAdapter.currentList.size) {
|
||||
gamesAdapter.notifyItemChanged(position)
|
||||
private fun onGameChanged() {
|
||||
lifecycleScope.launch {
|
||||
when (val response = UserRepository.loadMyFavList(
|
||||
ContentType.GAME.id,
|
||||
0, 3
|
||||
)) {
|
||||
is ApiResult.Error -> {
|
||||
onListGotEmpty(PostType.GAMES)
|
||||
MyListRepository.updateGameList(Collections.emptyList())
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {}
|
||||
is ApiResult.Success -> {
|
||||
response.data?.result?.game_data?.let {
|
||||
if (it.isNotEmpty()) {
|
||||
gamesAdapter.submitList(it)
|
||||
} else {
|
||||
onListGotEmpty(PostType.GAMES)
|
||||
}
|
||||
|
||||
binding.gamesViewAll.setVisibility(it.size >= 3)
|
||||
|
||||
MyListRepository.updateGameList(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -878,9 +1019,14 @@ class MyListFragment : Fragment() {
|
||||
!like.isSelected
|
||||
)
|
||||
|
||||
karaokeData.id?.let {
|
||||
onKaraokeChanged(it)
|
||||
karaokeData.likes_count = if (like.isSelected) {
|
||||
max(0, (karaokeData.likes_count ?: 0) - 1)
|
||||
} else {
|
||||
(karaokeData.likes_count ?: 0) + 1
|
||||
}
|
||||
|
||||
karaokeData.is_liked = !like.isSelected
|
||||
|
||||
like.isSelected = !like.isSelected
|
||||
likeCount.text = "${karaokeData.likes_count}"
|
||||
}
|
||||
@@ -896,23 +1042,26 @@ class MyListFragment : Fragment() {
|
||||
!fav.isSelected
|
||||
)
|
||||
|
||||
try {
|
||||
karaokeAdapter.notifyItemRemoved(position)
|
||||
} catch (e: Exception) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
if (karaokeAdapter.currentList.isEmpty()) {
|
||||
onListGotEmpty(PostType.KARAOKE)
|
||||
}
|
||||
|
||||
moduleShowerDialog.dismiss()
|
||||
fav.isSelected = !fav.isSelected
|
||||
itemRemovedFromDialog = !fav.isSelected
|
||||
}
|
||||
|
||||
close.setOnClickListener {
|
||||
moduleShowerDialog.dismiss()
|
||||
}
|
||||
|
||||
moduleShowerDialog.setOnDismissListener {
|
||||
if (itemRemovedFromDialog) {
|
||||
// item was removed at last
|
||||
onKaraokeChanged()
|
||||
} else {
|
||||
// item was not at last removed
|
||||
MyListRepository.setLoadNewDataFlag(false)
|
||||
}
|
||||
}
|
||||
|
||||
itemRemovedFromDialog = false
|
||||
|
||||
moduleShowerDialog.show()
|
||||
}
|
||||
}
|
||||
@@ -920,11 +1069,32 @@ class MyListFragment : Fragment() {
|
||||
clickHelper.upsertClickEvent(ContentType.KARAOKE_VIDEO, karaokeData.id)
|
||||
}
|
||||
|
||||
private fun onKaraokeChanged(id: Int) {
|
||||
// updating continue book list
|
||||
val position = karaokeAdapter.currentList.indexOfFirst { it.id == id }
|
||||
if (position >= 0 && position < karaokeAdapter.currentList.size) {
|
||||
karaokeAdapter.notifyItemChanged(position)
|
||||
private fun onKaraokeChanged() {
|
||||
lifecycleScope.launch {
|
||||
when (val response = UserRepository.loadMyFavList(
|
||||
ContentType.KARAOKE_VIDEO.id,
|
||||
0, 3
|
||||
)) {
|
||||
is ApiResult.Error -> {
|
||||
onListGotEmpty(PostType.KARAOKE)
|
||||
MyListRepository.updateKaraokeList(Collections.emptyList())
|
||||
}
|
||||
|
||||
is ApiResult.Loading -> {}
|
||||
is ApiResult.Success -> {
|
||||
response.data?.result?.sing_karaoke_data?.let {
|
||||
if (it.isNotEmpty()) {
|
||||
karaokeAdapter.submitList(it)
|
||||
} else {
|
||||
onListGotEmpty(PostType.KARAOKE)
|
||||
}
|
||||
|
||||
binding.karaokeViewAll.setVisibility(it.size >= 3)
|
||||
|
||||
MyListRepository.updateKaraokeList(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.woka.home.mylist
|
||||
|
||||
import com.woka.home.mylist.models.BookmarkedShowData
|
||||
import com.woka.home.mylist.models.FavAudioBookData
|
||||
import com.woka.home.mylist.models.FavGameData
|
||||
import com.woka.home.mylist.models.FavKaraokeData
|
||||
import com.woka.home.mylist.models.MyListResponse
|
||||
import com.woka.home.mylist.models.Result
|
||||
import com.woka.networking.ApiResult
|
||||
@@ -10,11 +12,11 @@ import com.woka.userdata.UserRepository
|
||||
object MyListRepository {
|
||||
|
||||
private var myFavData: MyListResponse = MyListResponse(Result(
|
||||
mutableListOf(),
|
||||
mutableListOf(),
|
||||
mutableListOf(),
|
||||
mutableListOf(),
|
||||
mutableListOf(),
|
||||
ArrayList(),
|
||||
ArrayList(),
|
||||
ArrayList(),
|
||||
ArrayList(),
|
||||
ArrayList(),
|
||||
0
|
||||
))
|
||||
|
||||
@@ -29,20 +31,6 @@ object MyListRepository {
|
||||
this.shallLoadNewData = loadNew
|
||||
}
|
||||
|
||||
fun updateSeriesList(bookmarkedShowData: MutableList<BookmarkedShowData>) {
|
||||
myFavData.result?.show_data?.clear()
|
||||
myFavData.result?.show_data?.addAll(bookmarkedShowData)
|
||||
|
||||
shallLoadNewData = false
|
||||
}
|
||||
|
||||
fun updateAudioList(bookmarkedShowData: MutableList<FavAudioBookData>) {
|
||||
myFavData.result?.audio_data?.clear()
|
||||
myFavData.result?.audio_data?.addAll(bookmarkedShowData)
|
||||
|
||||
shallLoadNewData = false
|
||||
}
|
||||
|
||||
fun clearData(){
|
||||
shallLoadNewData = true
|
||||
myFavData.result?.let {
|
||||
@@ -75,4 +63,32 @@ object MyListRepository {
|
||||
ApiResult.Success(myFavData)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateSeriesList(bookmarkedShowData: MutableList<BookmarkedShowData>) {
|
||||
myFavData.result?.show_data?.clear()
|
||||
myFavData.result?.show_data?.addAll(bookmarkedShowData)
|
||||
|
||||
shallLoadNewData = false
|
||||
}
|
||||
|
||||
fun updateAudioList(bookmarkedShowData: MutableList<FavAudioBookData>) {
|
||||
myFavData.result?.audio_data?.clear()
|
||||
myFavData.result?.audio_data?.addAll(bookmarkedShowData)
|
||||
|
||||
shallLoadNewData = false
|
||||
}
|
||||
|
||||
fun updateGameList(it: MutableList<FavGameData>) {
|
||||
myFavData.result?.game_data?.clear()
|
||||
myFavData.result?.game_data?.addAll(it)
|
||||
|
||||
shallLoadNewData = false
|
||||
}
|
||||
|
||||
fun updateKaraokeList(it: MutableList<FavKaraokeData>) {
|
||||
myFavData.result?.sing_karaoke_data?.clear()
|
||||
myFavData.result?.sing_karaoke_data?.addAll(it)
|
||||
|
||||
shallLoadNewData = false
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,11 @@ class FavAudioAdapter: ListAdapter<FavAudioBookData, FavoriteViewHolder>(DIFF_CO
|
||||
private val DIFF_UTIL = object : DiffUtil.ItemCallback<FavAudioBookData>(){
|
||||
override fun areItemsTheSame(oldItem: FavAudioBookData, newItem: FavAudioBookData): Boolean = oldItem.id == newItem.id
|
||||
override fun areContentsTheSame(oldItem: FavAudioBookData, newItem: FavAudioBookData): Boolean {
|
||||
return oldItem.title == newItem.title
|
||||
return oldItem.thumbnail_path == newItem.thumbnail_path &&
|
||||
oldItem.title == newItem.title &&
|
||||
oldItem.is_liked == newItem.is_liked &&
|
||||
oldItem.mark_as_favourite == newItem.mark_as_favourite &&
|
||||
oldItem.likes_count == newItem.likes_count
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,10 @@ class FavGamesAdapter: ListAdapter<FavGameData, FavoriteViewHolder>(DIFF_CONFIG)
|
||||
private val DIFF_UTIL = object : DiffUtil.ItemCallback<FavGameData>(){
|
||||
override fun areItemsTheSame(oldItem: FavGameData, newItem: FavGameData): Boolean = oldItem.id == newItem.id
|
||||
override fun areContentsTheSame(oldItem: FavGameData, newItem: FavGameData): Boolean {
|
||||
return oldItem.title == newItem.title &&
|
||||
return oldItem.thumbnail_path == newItem.thumbnail_path &&
|
||||
oldItem.title == newItem.title &&
|
||||
oldItem.is_liked == newItem.is_liked &&
|
||||
oldItem.mark_as_favourite == newItem.mark_as_favourite &&
|
||||
oldItem.likes_count == newItem.likes_count
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,7 @@ class WebSeriesAdapter(
|
||||
oldItem: BookmarkedShowData,
|
||||
newItem: BookmarkedShowData
|
||||
): Boolean {
|
||||
return oldItem.title == newItem.title &&
|
||||
oldItem.is_liked == newItem.is_liked &&
|
||||
oldItem.likes_count == newItem.likes_count
|
||||
return oldItem.title == newItem.title
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.woka.home.mylist.models
|
||||
|
||||
data class Result(
|
||||
val audio_data: MutableList<FavAudioBookData>?,
|
||||
val game_data: MutableList<FavGameData>?,
|
||||
val show_data: MutableList<BookmarkedShowData>?,
|
||||
val sing_karaoke_data: MutableList<FavKaraokeData>?,
|
||||
val video_data: MutableList<Any>?,
|
||||
val audio_data: ArrayList<FavAudioBookData>?,
|
||||
val game_data: ArrayList<FavGameData>?,
|
||||
val show_data: ArrayList<BookmarkedShowData>?,
|
||||
val sing_karaoke_data: ArrayList<FavKaraokeData>?,
|
||||
val video_data: ArrayList<Any>?,
|
||||
val total_records: Int?
|
||||
)
|
||||
@@ -1,21 +1,43 @@
|
||||
package com.woka.home.mylist.view.fragments
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.InsetDrawable
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.jwplayer.pub.api.media.playlists.PlaylistItem
|
||||
import com.woka.R
|
||||
import com.woka.WokaApp.Companion.userPrefs
|
||||
import com.woka.audiobooks.AudioBookRepository
|
||||
import com.woka.audiobooks.adapters.AudioBooksAdapter
|
||||
import com.woka.audiobooks.models.audiodata.AudioBookData
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.clicks.ContentType
|
||||
import com.woka.databinding.DialogModuleShowerBinding
|
||||
import com.woka.databinding.FragmentFavoritesBinding
|
||||
import com.woka.home.mylist.MyListRepository
|
||||
import com.woka.home.mylist.viewmodel.FavoriteViewModel
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.players.models.VideoPlayList
|
||||
import com.woka.players.views.PlayerActivity
|
||||
import com.woka.utils.hide
|
||||
import com.woka.utils.isNetworkConnected
|
||||
import com.woka.utils.setVisibility
|
||||
import com.woka.utils.show
|
||||
import com.woka.utils.toast
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
import kotlin.math.max
|
||||
|
||||
class FavAudioFragment : Fragment() {
|
||||
|
||||
@@ -24,19 +46,32 @@ class FavAudioFragment : Fragment() {
|
||||
|
||||
private lateinit var adapter: AudioBooksAdapter
|
||||
|
||||
private lateinit var dialogBinding: DialogModuleShowerBinding
|
||||
private lateinit var moduleShowerDialog: Dialog
|
||||
private var itemRemovedFromDialog = false
|
||||
|
||||
private val clickHelper = ClicksHelper
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
binding = FragmentFavoritesBinding.inflate(inflater, container, false)
|
||||
viewModel = ViewModelProvider(requireActivity())[FavoriteViewModel::class.java]
|
||||
adapter = AudioBooksAdapter(requireContext(), ::onBookClicked, ::onBookChanged, false){}
|
||||
adapter = AudioBooksAdapter(requireContext(), ::onAudioBookClicked, ::onBookChanged, false){}
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// dialogs
|
||||
dialogBinding = DialogModuleShowerBinding.inflate(layoutInflater)
|
||||
moduleShowerDialog = Dialog(requireContext())
|
||||
moduleShowerDialog.setContentView(dialogBinding.root)
|
||||
|
||||
initModuleShowerDialog()
|
||||
|
||||
initViews()
|
||||
|
||||
clickEvents()
|
||||
@@ -63,6 +98,31 @@ class FavAudioFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun initModuleShowerDialog() {
|
||||
try {
|
||||
val back = ColorDrawable(Color.TRANSPARENT)
|
||||
val inset = InsetDrawable(back, 50)
|
||||
moduleShowerDialog.window!!.setBackgroundDrawable(inset)
|
||||
} catch (e: Exception) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
try {
|
||||
val layoutParams = moduleShowerDialog.window!!.attributes
|
||||
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT
|
||||
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT
|
||||
moduleShowerDialog.window!!.setAttributes(layoutParams)
|
||||
} catch (e: Exception) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
dialogBinding.close.setOnClickListener {
|
||||
moduleShowerDialog.dismiss()
|
||||
|
||||
clickHelper.upsertClickEvent(ContentType.OTHERS)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setObservers(){
|
||||
viewModel.favoritesLiveData.observe(viewLifecycleOwner){
|
||||
binding.apply {
|
||||
@@ -107,13 +167,178 @@ class FavAudioFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun onBookChanged(i: Int, audioBookData: AudioBookData) {
|
||||
|
||||
}
|
||||
|
||||
private fun onBookClicked(audioBookData: AudioBookData) {
|
||||
private fun onAudioBookClicked(audioBookData: AudioBookData) {
|
||||
dialogBinding.apply {
|
||||
audioBookData.content_more_details?.let { moreDetailsList ->
|
||||
|
||||
audioBookData.thumbnail_path?.let {
|
||||
image.loadImage(it)
|
||||
}
|
||||
|
||||
fav.isSelected = audioBookData.mark_as_favourite == true
|
||||
like.isSelected = audioBookData.is_liked == true
|
||||
likeCount.text = "${audioBookData.likes_count}"
|
||||
|
||||
year.text = try {
|
||||
audioBookData.release_date?.let {
|
||||
val cal = Calendar.getInstance()
|
||||
cal.time =
|
||||
SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).parse(
|
||||
audioBookData.release_date
|
||||
)!!
|
||||
"${cal.get(Calendar.YEAR)}"
|
||||
} ?: throw Exception()
|
||||
} catch (e: Exception) {
|
||||
"${audioBookData.release_date}"
|
||||
}
|
||||
|
||||
if (moreDetailsList.isNotEmpty()) {
|
||||
|
||||
if (userPrefs?.appLanguage == "hi" && moreDetailsList.size > 1) {
|
||||
moreDetailsList[1]?.let { data ->
|
||||
title.text = data.title
|
||||
description.text = Html.fromHtml(
|
||||
data.description?.replace(
|
||||
"<br>",
|
||||
" "
|
||||
), Html.FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
}
|
||||
} else {
|
||||
moreDetailsList[0]?.let { data ->
|
||||
title.text = data.title
|
||||
description.text = Html.fromHtml(
|
||||
data.description?.replace(
|
||||
"<br>",
|
||||
" "
|
||||
), Html.FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
title.text = audioBookData.title
|
||||
description.text = Html.fromHtml(
|
||||
audioBookData.description?.replace(
|
||||
"<br>",
|
||||
" "
|
||||
), Html.FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
}
|
||||
|
||||
activity?.let {
|
||||
watchCard.backgroundTintList =
|
||||
ColorStateList.valueOf(it.getColor(R.color.audio_grad_one))
|
||||
}
|
||||
watchCard.text = getString(R.string.listen_now)
|
||||
watchCard.setOnClickListener {
|
||||
onAudioListenClicked(audioBookData)
|
||||
}
|
||||
|
||||
like.setOnClickListener {
|
||||
AudioBookRepository.likeUnLikeAudioBook(
|
||||
"${audioBookData.id}",
|
||||
!like.isSelected
|
||||
)
|
||||
|
||||
audioBookData.likes_count = if (like.isSelected) {
|
||||
max(0, (audioBookData.likes_count ?: 0) - 1)
|
||||
} else {
|
||||
(audioBookData.likes_count ?: 0) + 1
|
||||
}
|
||||
|
||||
audioBookData.is_liked = !like.isSelected
|
||||
|
||||
like.isSelected = !like.isSelected
|
||||
likeCount.text = "${audioBookData.likes_count}"
|
||||
}
|
||||
|
||||
fav.setOnClickListener {
|
||||
if (context?.isNetworkConnected() == false) {
|
||||
toast(getString(R.string.no_internet))
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
AudioBookRepository.updateFavShow(
|
||||
audioBookData,
|
||||
!fav.isSelected
|
||||
)
|
||||
|
||||
audioBookData.mark_as_favourite = !fav.isSelected
|
||||
fav.isSelected = !fav.isSelected
|
||||
itemRemovedFromDialog = !fav.isSelected
|
||||
}
|
||||
|
||||
close.setOnClickListener {
|
||||
moduleShowerDialog.dismiss()
|
||||
}
|
||||
|
||||
moduleShowerDialog.setOnDismissListener {
|
||||
if (itemRemovedFromDialog) {
|
||||
// item was removed at last
|
||||
// onAudioItemChanged()
|
||||
} else {
|
||||
// item was not at last removed
|
||||
MyListRepository.setLoadNewDataFlag(false)
|
||||
}
|
||||
}
|
||||
|
||||
itemRemovedFromDialog = false
|
||||
|
||||
moduleShowerDialog.show()
|
||||
}
|
||||
}
|
||||
|
||||
clickHelper.upsertClickEvent(ContentType.AUDIO, audioBookData.id)
|
||||
}
|
||||
|
||||
private fun onAudioListenClicked(audioBookData: AudioBookData) {
|
||||
|
||||
var url: String? = null
|
||||
var title = ""
|
||||
|
||||
audioBookData.content_more_details?.let { moreDetails ->
|
||||
if (moreDetails.isNotEmpty()) {
|
||||
if (userPrefs?.appLanguage == "hi" && moreDetails.size > 1) {
|
||||
url = moreDetails[1]?.url
|
||||
title = moreDetails[1]?.title ?: ""
|
||||
} else {
|
||||
url = moreDetails[0]?.url
|
||||
title = moreDetails[0]?.title ?: ""
|
||||
}
|
||||
} else {
|
||||
url = audioBookData.audio_url
|
||||
title = audioBookData.title ?: ""
|
||||
}
|
||||
}
|
||||
|
||||
activity?.let { activity ->
|
||||
url?.let {
|
||||
startActivity(Intent(activity, PlayerActivity::class.java).apply {
|
||||
putExtra(
|
||||
PlayerActivity.EXTRA_PLAY_LIST,
|
||||
VideoPlayList(
|
||||
ArrayList<PlaylistItem>().apply {
|
||||
add(
|
||||
PlaylistItem.Builder()
|
||||
.file(it)
|
||||
.image(it)
|
||||
.title(title)
|
||||
.build()
|
||||
)
|
||||
},
|
||||
null
|
||||
)
|
||||
)
|
||||
putExtra(PlayerActivity.EXTRA_PLAY_INDEX, 0)
|
||||
})
|
||||
|
||||
clickHelper.upsertClickEvent(ContentType.AUDIO, audioBookData.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +1,43 @@
|
||||
package com.woka.home.mylist.view.fragments
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.InsetDrawable
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.woka.R
|
||||
import com.woka.WokaApp.Companion.userPrefs
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.clicks.ContentType
|
||||
import com.woka.databinding.DialogModuleShowerBinding
|
||||
import com.woka.databinding.FragmentFavoritesBinding
|
||||
import com.woka.home.mylist.MyListRepository
|
||||
import com.woka.home.mylist.models.FavGameData
|
||||
import com.woka.home.mylist.viewmodel.FavoriteViewModel
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.utils.hide
|
||||
import com.woka.utils.isNetworkConnected
|
||||
import com.woka.utils.setVisibility
|
||||
import com.woka.utils.show
|
||||
import com.woka.utils.toast
|
||||
import com.woka.wokagames.GamesRepository
|
||||
import com.woka.wokagames.adapters.GamesAdapter
|
||||
import com.woka.wokagames.models.listing.GameData
|
||||
import com.woka.wokagames.playerr.GamePlayerActivity
|
||||
import com.woka.wokagames.playerr.GamePlayerData
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
import kotlin.math.max
|
||||
|
||||
class FavGameFragment : Fragment() {
|
||||
|
||||
@@ -24,6 +46,12 @@ class FavGameFragment : Fragment() {
|
||||
|
||||
private lateinit var adapter: GamesAdapter
|
||||
|
||||
private lateinit var dialogBinding: DialogModuleShowerBinding
|
||||
private lateinit var moduleShowerDialog: Dialog
|
||||
private var itemRemovedFromDialog = false
|
||||
|
||||
private val clickHelper = ClicksHelper
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
@@ -37,6 +65,13 @@ class FavGameFragment : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// dialogs
|
||||
dialogBinding = DialogModuleShowerBinding.inflate(layoutInflater)
|
||||
moduleShowerDialog = Dialog(requireContext())
|
||||
moduleShowerDialog.setContentView(dialogBinding.root)
|
||||
|
||||
initModuleShowerDialog()
|
||||
|
||||
initViews()
|
||||
|
||||
clickEvents()
|
||||
@@ -49,6 +84,31 @@ class FavGameFragment : Fragment() {
|
||||
|
||||
}
|
||||
|
||||
private fun initModuleShowerDialog() {
|
||||
try {
|
||||
val back = ColorDrawable(Color.TRANSPARENT)
|
||||
val inset = InsetDrawable(back, 50)
|
||||
moduleShowerDialog.window!!.setBackgroundDrawable(inset)
|
||||
} catch (e: Exception) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
try {
|
||||
val layoutParams = moduleShowerDialog.window!!.attributes
|
||||
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT
|
||||
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT
|
||||
moduleShowerDialog.window!!.setAttributes(layoutParams)
|
||||
} catch (e: Exception) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
dialogBinding.close.setOnClickListener {
|
||||
moduleShowerDialog.dismiss()
|
||||
|
||||
clickHelper.upsertClickEvent(ContentType.OTHERS)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initViews(){
|
||||
binding.apply {
|
||||
rvFavorites.adapter = adapter
|
||||
@@ -108,7 +168,138 @@ class FavGameFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun onGameClicked(gameData: GameData) {
|
||||
dialogBinding.apply {
|
||||
gameData.content_more_details?.let { moreDetailsList ->
|
||||
|
||||
gameData.thumbnail_path?.let {
|
||||
image.loadImage(it)
|
||||
}
|
||||
|
||||
fav.isSelected = gameData.mark_as_favourite == true
|
||||
like.isSelected = gameData.is_liked == true
|
||||
likeCount.text = "${gameData.likes_count}"
|
||||
|
||||
year.text = try {
|
||||
gameData.release_date?.let {
|
||||
val cal = Calendar.getInstance()
|
||||
cal.time =
|
||||
SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).parse(
|
||||
gameData.release_date
|
||||
)!!
|
||||
"${cal.get(Calendar.YEAR)}"
|
||||
} ?: throw Exception()
|
||||
} catch (e: Exception) {
|
||||
"${gameData.release_date}"
|
||||
}
|
||||
|
||||
if (moreDetailsList.isNotEmpty()) {
|
||||
|
||||
if (userPrefs?.appLanguage == "hi" && moreDetailsList.size > 1) {
|
||||
moreDetailsList[1]?.let { data ->
|
||||
title.text = data.title
|
||||
description.text = Html.fromHtml(
|
||||
data.description?.replace(
|
||||
"<br>",
|
||||
" "
|
||||
), Html.FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
}
|
||||
} else {
|
||||
moreDetailsList[0]?.let { data ->
|
||||
title.text = data.title
|
||||
description.text = Html.fromHtml(
|
||||
data.description?.replace(
|
||||
"<br>",
|
||||
" "
|
||||
), Html.FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
title.text = gameData.title
|
||||
description.text = Html.fromHtml(
|
||||
gameData.description?.replace(
|
||||
"<br>",
|
||||
" "
|
||||
), Html.FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
}
|
||||
|
||||
activity?.let {
|
||||
watchCard.backgroundTintList =
|
||||
ColorStateList.valueOf(it.getColor(R.color.game_grad_one))
|
||||
}
|
||||
watchCard.text = getString(R.string.play_now)
|
||||
watchCard.setOnClickListener {
|
||||
activity?.let { activity ->
|
||||
gameData.game_url?.let {
|
||||
startActivity(Intent(activity, GamePlayerActivity::class.java).apply {
|
||||
putExtra(
|
||||
GamePlayerActivity.EXTRA_GAME_PLAYER_DATA,
|
||||
GamePlayerData(it, gameData.screen_orientation == "Landscape")
|
||||
)
|
||||
})
|
||||
|
||||
clickHelper.upsertClickEvent(ContentType.GAME, gameData.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
like.setOnClickListener {
|
||||
GamesRepository.likeUnLikeGame(
|
||||
"${gameData.id}",
|
||||
!like.isSelected
|
||||
)
|
||||
|
||||
gameData.likes_count = if (like.isSelected) {
|
||||
max(0, (gameData.likes_count ?: 0) - 1)
|
||||
} else {
|
||||
(gameData.likes_count ?: 0) + 1
|
||||
}
|
||||
|
||||
gameData.is_liked = !like.isSelected
|
||||
|
||||
like.isSelected = !like.isSelected
|
||||
likeCount.text = "${gameData.likes_count}"
|
||||
}
|
||||
|
||||
fav.setOnClickListener {
|
||||
if (context?.isNetworkConnected() == false) {
|
||||
toast(getString(R.string.no_internet))
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
GamesRepository.updateFavShow(
|
||||
gameData,
|
||||
!fav.isSelected
|
||||
)
|
||||
|
||||
gameData.mark_as_favourite = !fav.isSelected
|
||||
fav.isSelected = !fav.isSelected
|
||||
itemRemovedFromDialog = !fav.isSelected
|
||||
}
|
||||
|
||||
close.setOnClickListener {
|
||||
moduleShowerDialog.dismiss()
|
||||
}
|
||||
|
||||
moduleShowerDialog.setOnDismissListener {
|
||||
if (itemRemovedFromDialog) {
|
||||
// item was removed at last
|
||||
// onGameChanged()
|
||||
} else {
|
||||
// item was not at last removed
|
||||
MyListRepository.setLoadNewDataFlag(false)
|
||||
}
|
||||
}
|
||||
|
||||
itemRemovedFromDialog = false
|
||||
|
||||
moduleShowerDialog.show()
|
||||
}
|
||||
}
|
||||
|
||||
clickHelper.upsertClickEvent(ContentType.GAME, gameData.id)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +1,43 @@
|
||||
package com.woka.home.mylist.view.fragments
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.InsetDrawable
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.woka.R
|
||||
import com.woka.WokaApp.Companion.userPrefs
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.clicks.ContentType
|
||||
import com.woka.databinding.DialogModuleShowerBinding
|
||||
import com.woka.databinding.FragmentFavoritesBinding
|
||||
import com.woka.home.mylist.MyListRepository
|
||||
import com.woka.home.mylist.models.FavKaraokeData
|
||||
import com.woka.home.mylist.viewmodel.FavoriteViewModel
|
||||
import com.woka.karaoke.KaraokeRepository
|
||||
import com.woka.karaoke.adapters.KaraokeAdapter
|
||||
import com.woka.karaoke.models.listing.KaraokeData
|
||||
import com.woka.karaoke.player.KaraokePlayerActivity
|
||||
import com.woka.karaoke.player.KaraokePlayerData
|
||||
import com.woka.networking.ApiResult
|
||||
import com.woka.utils.hide
|
||||
import com.woka.utils.isNetworkConnected
|
||||
import com.woka.utils.setVisibility
|
||||
import com.woka.utils.show
|
||||
import com.woka.utils.toast
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
import kotlin.math.max
|
||||
|
||||
class FavKaraokeFragment : Fragment() {
|
||||
|
||||
@@ -24,6 +46,12 @@ class FavKaraokeFragment : Fragment() {
|
||||
|
||||
private lateinit var adapter: KaraokeAdapter
|
||||
|
||||
private lateinit var dialogBinding: DialogModuleShowerBinding
|
||||
private lateinit var moduleShowerDialog: Dialog
|
||||
private var itemRemovedFromDialog = false
|
||||
|
||||
private val clickHelper = ClicksHelper
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
@@ -37,6 +65,13 @@ class FavKaraokeFragment : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// dialogs
|
||||
dialogBinding = DialogModuleShowerBinding.inflate(layoutInflater)
|
||||
moduleShowerDialog = Dialog(requireContext())
|
||||
moduleShowerDialog.setContentView(dialogBinding.root)
|
||||
|
||||
initModuleShowerDialog()
|
||||
|
||||
initViews()
|
||||
|
||||
clickEvents()
|
||||
@@ -49,6 +84,31 @@ class FavKaraokeFragment : Fragment() {
|
||||
|
||||
}
|
||||
|
||||
private fun initModuleShowerDialog() {
|
||||
try {
|
||||
val back = ColorDrawable(Color.TRANSPARENT)
|
||||
val inset = InsetDrawable(back, 50)
|
||||
moduleShowerDialog.window!!.setBackgroundDrawable(inset)
|
||||
} catch (e: Exception) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
try {
|
||||
val layoutParams = moduleShowerDialog.window!!.attributes
|
||||
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT
|
||||
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT
|
||||
moduleShowerDialog.window!!.setAttributes(layoutParams)
|
||||
} catch (e: Exception) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
dialogBinding.close.setOnClickListener {
|
||||
moduleShowerDialog.dismiss()
|
||||
|
||||
clickHelper.upsertClickEvent(ContentType.OTHERS)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initViews(){
|
||||
binding.apply {
|
||||
rvFavorites.adapter = adapter
|
||||
@@ -112,7 +172,143 @@ class FavKaraokeFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun onKaraokeClicked(karaokeData: KaraokeData) {
|
||||
dialogBinding.apply {
|
||||
karaokeData.content_more_details?.let { moreDetailsList ->
|
||||
|
||||
karaokeData.thumbnail_path?.let {
|
||||
image.loadImage(it)
|
||||
}
|
||||
|
||||
fav.isSelected = karaokeData.mark_as_favourite == true
|
||||
like.isSelected = karaokeData.is_liked == true
|
||||
likeCount.text = "${karaokeData.likes_count}"
|
||||
|
||||
year.text = try {
|
||||
karaokeData.release_date?.let {
|
||||
val cal = Calendar.getInstance()
|
||||
cal.time =
|
||||
SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).parse(
|
||||
karaokeData.release_date
|
||||
)!!
|
||||
"${cal.get(Calendar.YEAR)}"
|
||||
} ?: throw Exception()
|
||||
} catch (e: Exception) {
|
||||
"${karaokeData.release_date}"
|
||||
}
|
||||
|
||||
if (moreDetailsList.isNotEmpty()) {
|
||||
|
||||
if (userPrefs?.appLanguage == "hi" && moreDetailsList.size > 1) {
|
||||
moreDetailsList[1]?.let { data ->
|
||||
title.text = data.title
|
||||
description.text = Html.fromHtml(
|
||||
data.description?.replace(
|
||||
"<br>",
|
||||
" "
|
||||
), Html.FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
}
|
||||
} else {
|
||||
moreDetailsList[0]?.let { data ->
|
||||
title.text = data.title
|
||||
description.text = Html.fromHtml(
|
||||
data.description?.replace(
|
||||
"<br>",
|
||||
" "
|
||||
), Html.FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
title.text = karaokeData.title
|
||||
description.text = Html.fromHtml(
|
||||
karaokeData.description?.replace(
|
||||
"<br>",
|
||||
" "
|
||||
), Html.FROM_HTML_MODE_LEGACY
|
||||
)
|
||||
}
|
||||
|
||||
activity?.let {
|
||||
watchCard.backgroundTintList =
|
||||
ColorStateList.valueOf(it.getColor(R.color.game_grad_one))
|
||||
}
|
||||
watchCard.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_mic, 0, 0, 0)
|
||||
watchCard.text = getString(R.string.sing_now)
|
||||
watchCard.setOnClickListener {
|
||||
activity?.let { activity ->
|
||||
karaokeData.video_url?.let {
|
||||
startActivity(
|
||||
Intent(
|
||||
activity,
|
||||
KaraokePlayerActivity::class.java
|
||||
).apply {
|
||||
putExtra(
|
||||
KaraokePlayerActivity.EXTRA_KARAOKE_DATA,
|
||||
KaraokePlayerData(it, karaokeData.title)
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
clickHelper.upsertClickEvent(ContentType.KARAOKE_VIDEO, karaokeData.id)
|
||||
}
|
||||
|
||||
like.setOnClickListener {
|
||||
KaraokeRepository.likeUnLikeSong(
|
||||
"${karaokeData.id}",
|
||||
!like.isSelected
|
||||
)
|
||||
|
||||
karaokeData.likes_count = if (like.isSelected) {
|
||||
max(0, (karaokeData.likes_count ?: 0) - 1)
|
||||
} else {
|
||||
(karaokeData.likes_count ?: 0) + 1
|
||||
}
|
||||
|
||||
karaokeData.is_liked = !like.isSelected
|
||||
|
||||
like.isSelected = !like.isSelected
|
||||
likeCount.text = "${karaokeData.likes_count}"
|
||||
}
|
||||
|
||||
fav.setOnClickListener {
|
||||
if (context?.isNetworkConnected() == false) {
|
||||
toast(getString(R.string.no_internet))
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
KaraokeRepository.updateFavShow(
|
||||
karaokeData,
|
||||
!fav.isSelected
|
||||
)
|
||||
|
||||
karaokeData.mark_as_favourite = !fav.isSelected
|
||||
fav.isSelected = !fav.isSelected
|
||||
itemRemovedFromDialog = !fav.isSelected
|
||||
}
|
||||
|
||||
close.setOnClickListener {
|
||||
moduleShowerDialog.dismiss()
|
||||
}
|
||||
|
||||
moduleShowerDialog.setOnDismissListener {
|
||||
if (itemRemovedFromDialog) {
|
||||
// item was removed at last
|
||||
// onKaraokeChanged()
|
||||
} else {
|
||||
// item was not at last removed
|
||||
MyListRepository.setLoadNewDataFlag(false)
|
||||
}
|
||||
}
|
||||
|
||||
itemRemovedFromDialog = false
|
||||
|
||||
moduleShowerDialog.show()
|
||||
}
|
||||
}
|
||||
|
||||
clickHelper.upsertClickEvent(ContentType.KARAOKE_VIDEO, karaokeData.id)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,12 +1,17 @@
|
||||
package com.woka.home.mylist.view.fragments
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.woka.R
|
||||
import com.woka.database.helpers.ClicksHelper
|
||||
import com.woka.database.models.clicks.ContentType
|
||||
import com.woka.databinding.FragmentFavoritesBinding
|
||||
import com.woka.home.mylist.viewmodel.FavoriteViewModel
|
||||
@@ -16,6 +21,9 @@ import com.woka.utils.setVisibility
|
||||
import com.woka.utils.show
|
||||
import com.woka.webseries.adapters.WebSeriesShowAdapter
|
||||
import com.woka.webseries.models.ShowData
|
||||
import com.woka.webseries.views.WebSeriesActivity
|
||||
import com.woka.webseries.views.WebSeriesActivity.Companion.EXTRA_SHOW_CATEGORY
|
||||
import com.woka.webseries.views.WebSeriesActivity.Companion.EXTRA_SHOW_DATA
|
||||
|
||||
class FavSeriesFragment : Fragment() {
|
||||
|
||||
@@ -24,13 +32,17 @@ class FavSeriesFragment : Fragment() {
|
||||
|
||||
private lateinit var adapter: WebSeriesShowAdapter
|
||||
|
||||
private var webShowIntentLauncher: ActivityResultLauncher<Intent>? = null
|
||||
|
||||
private val clickHelper = ClicksHelper
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
binding = FragmentFavoritesBinding.inflate(inflater, container, false)
|
||||
viewModel = ViewModelProvider(requireActivity())[FavoriteViewModel::class.java]
|
||||
adapter = WebSeriesShowAdapter(requireContext(), ::onShowClicked, ::onShowCommonDataChanged, false){}
|
||||
adapter = WebSeriesShowAdapter(requireContext(), ::onWebShowClicked, ::onShowCommonDataChanged, false){}
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@@ -43,6 +55,8 @@ class FavSeriesFragment : Fragment() {
|
||||
|
||||
setObservers()
|
||||
|
||||
registerIntentLaunchers()
|
||||
|
||||
if (!viewModel.favoritesLiveData.isInitialized || viewModel.favoritesLiveData.value !is ApiResult.Success){
|
||||
viewModel.loadFavorites(ContentType.SERIES, if (viewModel.webSeriesIsEnglish) "1" else "18")
|
||||
}
|
||||
@@ -107,12 +121,35 @@ class FavSeriesFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun registerIntentLaunchers() {
|
||||
webShowIntentLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == AppCompatActivity.RESULT_OK) {
|
||||
@Suppress("DEPRECATION")
|
||||
result?.data?.getParcelableExtra<ShowData>(EXTRA_SHOW_DATA)?.let { showData ->
|
||||
val hPos = adapter.showList.indexOfFirst { it.id == showData.id }
|
||||
if (hPos >= 0 && hPos < adapter.showList.size){
|
||||
adapter.showList[hPos].likes_count = showData.likes_count
|
||||
adapter.showList[hPos].is_liked = showData.is_liked
|
||||
adapter.showList[hPos].favourite_category_ids = showData.favourite_category_ids
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun onShowCommonDataChanged(showData: ShowData, categoryId: String) {
|
||||
|
||||
}
|
||||
|
||||
private fun onShowClicked(showData: ShowData, categoryId: String) {
|
||||
// web show
|
||||
private fun onWebShowClicked(showData: ShowData, categoryId: String) {
|
||||
webShowIntentLauncher?.launch(Intent(context, WebSeriesActivity::class.java).apply {
|
||||
putExtra(EXTRA_SHOW_DATA, showData)
|
||||
putExtra(EXTRA_SHOW_CATEGORY, categoryId)
|
||||
})
|
||||
|
||||
clickHelper.upsertClickEvent(ContentType.SERIES, showData.id, categoryId)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class FavoriteViewModel : ViewModel() {
|
||||
|
||||
private val myListResponse = MyListResponse(
|
||||
Result(
|
||||
mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), 0
|
||||
ArrayList(), ArrayList(), ArrayList(), ArrayList(), ArrayList(), 0
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ class WebSeriesActivity : WokaBaseActivity() {
|
||||
companion object {
|
||||
const val EXTRA_SHOW_DATA = "extra_show_data"
|
||||
const val EXTRA_SHOW_CATEGORY = "extra_show_category"
|
||||
const val EXTRA_SHOW_ID = "extra_show_id"
|
||||
}
|
||||
|
||||
private lateinit var binding: ActivityWebSeriesBinding
|
||||
|
||||
@@ -42,6 +42,7 @@ import com.woka.webseries.models.episodedata.EpisodeData
|
||||
import com.woka.webseries.models.teaserdata.TeaserData
|
||||
import com.woka.webseries.viewmodel.WebSeriesViewModel
|
||||
import com.woka.webseries.views.WebSeriesActivity.Companion.EXTRA_SHOW_CATEGORY
|
||||
import com.woka.webseries.views.WebSeriesActivity.Companion.EXTRA_SHOW_DATA
|
||||
import kotlin.math.max
|
||||
|
||||
class WebShowFragment : Fragment(), TabLayout.OnTabSelectedListener {
|
||||
@@ -195,6 +196,11 @@ class WebShowFragment : Fragment(), TabLayout.OnTabSelectedListener {
|
||||
likeSeason.isSelected = !likeSeason.isSelected
|
||||
likeCount.text = "${showData.likes_count}"
|
||||
|
||||
activity?.setResult(RESULT_OK, Intent().apply {
|
||||
putExtra(EXTRA_SHOW_CATEGORY, if (!favSeason.isSelected) categoryId else null)
|
||||
putExtra(EXTRA_SHOW_DATA, showData)
|
||||
})
|
||||
|
||||
showDataChanged = true
|
||||
}
|
||||
|
||||
@@ -223,10 +229,13 @@ class WebShowFragment : Fragment(), TabLayout.OnTabSelectedListener {
|
||||
showData.addAsBookMark(categoryId)
|
||||
}
|
||||
|
||||
showData.mark_as_favourite = !favSeason.isSelected
|
||||
|
||||
favSeason.isSelected = !favSeason.isSelected
|
||||
|
||||
activity?.setResult(RESULT_OK, Intent().apply {
|
||||
putExtra(EXTRA_SHOW_CATEGORY, if (!favSeason.isSelected) categoryId else null)
|
||||
putExtra(EXTRA_SHOW_DATA, showData)
|
||||
})
|
||||
|
||||
showDataChanged = true
|
||||
|
||||
Reference in New Issue
Block a user