mirror of
https://github.com/Shabinder/SpotiFlyer.git
synced 2024-11-25 02:14:32 +01:00
100 Max Limit Issue Fixed.
This commit is contained in:
parent
172c8d1f55
commit
923e28617a
@ -23,7 +23,6 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.databinding.DataBindingUtil
|
import androidx.databinding.DataBindingUtil
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.Observer
|
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import com.google.android.material.tabs.TabLayout
|
import com.google.android.material.tabs.TabLayout
|
||||||
import com.shabinder.spotiflyer.R
|
import com.shabinder.spotiflyer.R
|
||||||
@ -46,7 +45,8 @@ class DownloadRecordFragment : Fragment() {
|
|||||||
downloadRecordViewModel = ViewModelProvider(this).get(DownloadRecordViewModel::class.java)
|
downloadRecordViewModel = ViewModelProvider(this).get(DownloadRecordViewModel::class.java)
|
||||||
adapter = DownloadRecordAdapter()
|
adapter = DownloadRecordAdapter()
|
||||||
binding.downloadRecordList.adapter = adapter
|
binding.downloadRecordList.adapter = adapter
|
||||||
downloadRecordViewModel.downloadRecordList.observe(viewLifecycleOwner, Observer {
|
|
||||||
|
downloadRecordViewModel.downloadRecordList.observe(viewLifecycleOwner, {
|
||||||
if(it.isNotEmpty()){
|
if(it.isNotEmpty()){
|
||||||
downloadRecordViewModel.spotifyList = mutableListOf()
|
downloadRecordViewModel.spotifyList = mutableListOf()
|
||||||
downloadRecordViewModel.ytList = mutableListOf()
|
downloadRecordViewModel.ytList = mutableListOf()
|
||||||
@ -56,7 +56,6 @@ class DownloadRecordFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
if(binding.tabLayout.selectedTabPosition == 0) adapter.submitList(downloadRecordViewModel.spotifyList)
|
if(binding.tabLayout.selectedTabPosition == 0) adapter.submitList(downloadRecordViewModel.spotifyList)
|
||||||
else adapter.submitList(downloadRecordViewModel.ytList)
|
else adapter.submitList(downloadRecordViewModel.ytList)
|
||||||
// adapter.notifyDataSetChanged()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -67,7 +66,6 @@ class DownloadRecordFragment : Fragment() {
|
|||||||
if(tab?.text == "Spotify"){
|
if(tab?.text == "Spotify"){
|
||||||
adapter.submitList(downloadRecordViewModel.spotifyList)
|
adapter.submitList(downloadRecordViewModel.spotifyList)
|
||||||
} else adapter.submitList(downloadRecordViewModel.ytList)
|
} else adapter.submitList(downloadRecordViewModel.ytList)
|
||||||
// adapter.notifyDataSetChanged()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTabReselected(tab: TabLayout.Tab?) {
|
override fun onTabReselected(tab: TabLayout.Tab?) {
|
||||||
@ -75,7 +73,7 @@ class DownloadRecordFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onTabUnselected(tab: TabLayout.Tab?) {
|
override fun onTabUnselected(tab: TabLayout.Tab?) {
|
||||||
// Handle tab unselect
|
// Handle tab unselected
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -30,12 +30,13 @@ import kotlinx.coroutines.launch
|
|||||||
class DownloadRecordViewModel @ViewModelInject constructor(val databaseDAO: DatabaseDAO) :
|
class DownloadRecordViewModel @ViewModelInject constructor(val databaseDAO: DatabaseDAO) :
|
||||||
ViewModel(){
|
ViewModel(){
|
||||||
private var viewModelJob = Job()
|
private var viewModelJob = Job()
|
||||||
private val uiScope = CoroutineScope(Dispatchers.Main + viewModelJob)
|
private val uiScope = CoroutineScope(Dispatchers.Default + viewModelJob)
|
||||||
var spotifyList = mutableListOf<DownloadRecord>()
|
var spotifyList = mutableListOf<DownloadRecord>()
|
||||||
var ytList = mutableListOf<DownloadRecord>()
|
var ytList = mutableListOf<DownloadRecord>()
|
||||||
val downloadRecordList = MutableLiveData<MutableList<DownloadRecord>>().apply {
|
val downloadRecordList = MutableLiveData<MutableList<DownloadRecord>>().apply {
|
||||||
value = mutableListOf()
|
value = mutableListOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
getDownloadRecordList()
|
getDownloadRecordList()
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,9 @@ import com.shabinder.spotiflyer.SharedViewModel
|
|||||||
import com.shabinder.spotiflyer.databinding.MainFragmentBinding
|
import com.shabinder.spotiflyer.databinding.MainFragmentBinding
|
||||||
import com.shreyaspatil.easyupipayment.EasyUpiPayment
|
import com.shreyaspatil.easyupipayment.EasyUpiPayment
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@ -92,25 +95,20 @@ class MainFragment : Fragment() {
|
|||||||
**/
|
**/
|
||||||
private fun handleIntent() {
|
private fun handleIntent() {
|
||||||
sharedViewModel.intentString.observe(viewLifecycleOwner,{
|
sharedViewModel.intentString.observe(viewLifecycleOwner,{
|
||||||
//Waiting for Authentication to Finish with Spotify()Access Token Observe
|
|
||||||
if(sharedViewModel.accessToken.value != ""){
|
|
||||||
if(it != ""){
|
if(it != ""){
|
||||||
|
sharedViewModel.uiScope.launch(Dispatchers.IO) {
|
||||||
|
while (sharedViewModel.accessToken.value == "") {
|
||||||
|
//Waiting for Authentication to Finish
|
||||||
|
Thread.sleep(1000)
|
||||||
|
}
|
||||||
|
withContext(Dispatchers.Main){
|
||||||
binding.linkSearch.setText(sharedViewModel.intentString.value)
|
binding.linkSearch.setText(sharedViewModel.intentString.value)
|
||||||
binding.btnSearch.performClick()
|
binding.btnSearch.performClick()
|
||||||
sharedViewModel.intentString.value = ""
|
sharedViewModel.intentString.value = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})/*
|
|
||||||
sharedViewModel.accessToken.observe(viewLifecycleOwner, {
|
|
||||||
//Waiting for Authentication to Finish with Spotify()Access Token Observe
|
|
||||||
if (it != ""){
|
|
||||||
if(sharedViewModel.intentString != ""){
|
|
||||||
binding.linkSearch.setText(sharedViewModel.intentString)
|
|
||||||
binding.btnSearch.performClick()
|
|
||||||
sharedViewModel.intentString = ""
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,6 +108,7 @@ class SpotifyFragment : Fragment() {
|
|||||||
else{
|
else{
|
||||||
spotifyViewModel.spotifySearch(type,link)
|
spotifyViewModel.spotifySearch(type,link)
|
||||||
if(type=="album")adapterSpotify.isAlbum = true
|
if(type=="album")adapterSpotify.isAlbum = true
|
||||||
|
|
||||||
binding.btnDownloadAllSpotify.setOnClickListener {
|
binding.btnDownloadAllSpotify.setOnClickListener {
|
||||||
for (track in spotifyViewModel.trackList.value!!){
|
for (track in spotifyViewModel.trackList.value!!){
|
||||||
if(track.downloaded != "Downloaded"){
|
if(track.downloaded != "Downloaded"){
|
||||||
@ -116,6 +117,8 @@ class SpotifyFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
binding.btnDownloadAllSpotify.visibility = View.GONE
|
binding.btnDownloadAllSpotify.visibility = View.GONE
|
||||||
binding.downloadingFabSpotify.visibility = View.VISIBLE
|
binding.downloadingFabSpotify.visibility = View.VISIBLE
|
||||||
|
|
||||||
|
|
||||||
rotateAnim(binding.downloadingFabSpotify)
|
rotateAnim(binding.downloadingFabSpotify)
|
||||||
for (track in spotifyViewModel.trackList.value!!){
|
for (track in spotifyViewModel.trackList.value!!){
|
||||||
if(track.downloaded != "Downloaded"){
|
if(track.downloaded != "Downloaded"){
|
||||||
@ -123,7 +126,7 @@ class SpotifyFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
showToast("Starting Download in Few Seconds")
|
showToast("Starting Download in Few Seconds")
|
||||||
loadAllImages(spotifyViewModel.trackList.value!!)
|
spotifyViewModel.uiScope.launch(Dispatchers.Default){loadAllImages(spotifyViewModel.trackList.value!!)}
|
||||||
spotifyViewModel.uiScope.launch {
|
spotifyViewModel.uiScope.launch {
|
||||||
SpotifyDownloadHelper.downloadAllTracks(
|
SpotifyDownloadHelper.downloadAllTracks(
|
||||||
spotifyViewModel.folderType,
|
spotifyViewModel.folderType,
|
||||||
@ -212,15 +215,15 @@ class SpotifyFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkIfAllDownloaded() {
|
private fun checkIfAllDownloaded() {
|
||||||
var allDownloaded = true
|
if(!spotifyViewModel.trackList.value!!.any { it.downloaded != "Downloaded" }){
|
||||||
for (track in spotifyViewModel.trackList.value!!){
|
//All Tracks Downloaded
|
||||||
if (track.downloaded != "Downloaded")allDownloaded = false
|
|
||||||
}
|
|
||||||
if(allDownloaded){
|
|
||||||
binding.downloadingFabSpotify.setImageResource(R.drawable.ic_tick)
|
|
||||||
binding.btnDownloadAllSpotify.visibility = View.GONE
|
binding.btnDownloadAllSpotify.visibility = View.GONE
|
||||||
binding.downloadingFabSpotify.visibility = View.VISIBLE
|
binding.downloadingFabSpotify.apply{
|
||||||
binding.downloadingFabSpotify.clearAnimation()
|
setImageResource(R.drawable.ic_tick)
|
||||||
|
visibility = View.VISIBLE
|
||||||
|
clearAnimation()
|
||||||
|
keepScreenOn = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +248,7 @@ class SpotifyFragment : Fragment() {
|
|||||||
/**
|
/**
|
||||||
* Function to fetch all Images for using in mp3 tag.
|
* Function to fetch all Images for using in mp3 tag.
|
||||||
**/
|
**/
|
||||||
private fun loadAllImages(trackList: List<Track>) {
|
private suspend fun loadAllImages(trackList: List<Track>) {
|
||||||
trackList.forEach {
|
trackList.forEach {
|
||||||
val imgUrl = it.album?.images?.get(0)?.url
|
val imgUrl = it.album?.images?.get(0)?.url
|
||||||
imgUrl?.let {
|
imgUrl?.let {
|
||||||
|
@ -23,10 +23,7 @@ import androidx.lifecycle.MutableLiveData
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import com.shabinder.spotiflyer.database.DatabaseDAO
|
import com.shabinder.spotiflyer.database.DatabaseDAO
|
||||||
import com.shabinder.spotiflyer.database.DownloadRecord
|
import com.shabinder.spotiflyer.database.DownloadRecord
|
||||||
import com.shabinder.spotiflyer.models.Album
|
import com.shabinder.spotiflyer.models.*
|
||||||
import com.shabinder.spotiflyer.models.Image
|
|
||||||
import com.shabinder.spotiflyer.models.Playlist
|
|
||||||
import com.shabinder.spotiflyer.models.Track
|
|
||||||
import com.shabinder.spotiflyer.utils.SpotifyService
|
import com.shabinder.spotiflyer.utils.SpotifyService
|
||||||
import com.shabinder.spotiflyer.utils.finalOutputDir
|
import com.shabinder.spotiflyer.utils.finalOutputDir
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
@ -120,6 +117,17 @@ class SpotifyViewModel @ViewModelInject constructor(val databaseDAO: DatabaseDAO
|
|||||||
tempTrackList.add(it1)
|
tempTrackList.add(it1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var moreTracksAvailable = !playlistObject?.tracks?.next.isNullOrBlank()
|
||||||
|
|
||||||
|
while(moreTracksAvailable){
|
||||||
|
//Check For More Tracks If available
|
||||||
|
val moreTracks = getPlaylistTrackDetails(link,offset = tempTrackList.size)
|
||||||
|
moreTracks?.items?.forEach{
|
||||||
|
it.track?.let { it1 -> tempTrackList.add(it1) }
|
||||||
|
}
|
||||||
|
moreTracksAvailable = !moreTracks?.next.isNullOrBlank()
|
||||||
|
}
|
||||||
|
Log.i("Total Tracks Fetched",tempTrackList.size.toString())
|
||||||
trackList.value = tempTrackList
|
trackList.value = tempTrackList
|
||||||
title.value = playlistObject?.name
|
title.value = playlistObject?.name
|
||||||
coverUrl.value = playlistObject?.images?.get(0)!!.url!!
|
coverUrl.value = playlistObject?.images?.get(0)!!.url!!
|
||||||
@ -155,6 +163,10 @@ class SpotifyViewModel @ViewModelInject constructor(val databaseDAO: DatabaseDAO
|
|||||||
Log.i("Requesting","https://api.spotify.com/v1/playlists/$link")
|
Log.i("Requesting","https://api.spotify.com/v1/playlists/$link")
|
||||||
return spotifyService?.getPlaylist(link)
|
return spotifyService?.getPlaylist(link)
|
||||||
}
|
}
|
||||||
|
private suspend fun getPlaylistTrackDetails(link:String,offset:Int = 0,limit:Int = 100): PagingObjectPlaylistTrack?{
|
||||||
|
Log.i("Requesting","https://api.spotify.com/v1/playlists/$link/tracks?offset=$offset&limit=$limit")
|
||||||
|
return spotifyService?.getPlaylistTracks(link, offset, limit)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
|
@ -17,10 +17,7 @@
|
|||||||
|
|
||||||
package com.shabinder.spotiflyer.utils
|
package com.shabinder.spotiflyer.utils
|
||||||
|
|
||||||
import com.shabinder.spotiflyer.models.Album
|
import com.shabinder.spotiflyer.models.*
|
||||||
import com.shabinder.spotiflyer.models.Playlist
|
|
||||||
import com.shabinder.spotiflyer.models.Token
|
|
||||||
import com.shabinder.spotiflyer.models.Track
|
|
||||||
import retrofit2.http.*
|
import retrofit2.http.*
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -46,6 +43,13 @@ interface SpotifyService {
|
|||||||
@GET("playlists/{playlist_id}")
|
@GET("playlists/{playlist_id}")
|
||||||
suspend fun getPlaylist(@Path("playlist_id") playlistId: String?): Playlist
|
suspend fun getPlaylist(@Path("playlist_id") playlistId: String?): Playlist
|
||||||
|
|
||||||
|
@GET("playlists/{playlist_id}/tracks")
|
||||||
|
suspend fun getPlaylistTracks(
|
||||||
|
@Path("playlist_id") playlistId: String?,
|
||||||
|
@Query("offset") offset: Int = 0,
|
||||||
|
@Query("limit") limit: Int = 100
|
||||||
|
): PagingObjectPlaylistTrack
|
||||||
|
|
||||||
@GET("tracks/{id}")
|
@GET("tracks/{id}")
|
||||||
suspend fun getTrack(@Path("id") trackId: String?): Track
|
suspend fun getTrack(@Path("id") trackId: String?): Track
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/downloading_fab_spotify"
|
android:id="@+id/downloading_fab_spotify"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
android:keepScreenOn="true"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:backgroundTint="@color/black"
|
android:backgroundTint="@color/black"
|
||||||
android:scaleType="fitCenter"
|
android:scaleType="fitCenter"
|
||||||
|
Loading…
Reference in New Issue
Block a user