diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 835a5de3..64d7de01 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -36,6 +36,10 @@
android:name="com.spotify.sdk.android.authentication.LoginActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/shabinder/musicForEveryone/MainActivity.kt b/app/src/main/java/com/shabinder/musicForEveryone/MainActivity.kt
index f08f5700..0789fe4b 100644
--- a/app/src/main/java/com/shabinder/musicForEveryone/MainActivity.kt
+++ b/app/src/main/java/com/shabinder/musicForEveryone/MainActivity.kt
@@ -104,8 +104,8 @@ class MainActivity : AppCompatActivity() ,DownloadHelper{
sharedViewModel.uiScope.launch {
val me = spotifyExtra?.getMe()?.display_name
- sharedViewModel.userName.value = me
- Log.i("Network",me!!)
+ sharedViewModel.userName.value = "Logged in as: $me"
+ Log.i("Network","Hello, " + me!!)
}
sharedViewModel.userName.observe(this, Observer {
diff --git a/app/src/main/java/com/shabinder/musicForEveryone/downloadHelper/DownloadHelper.kt b/app/src/main/java/com/shabinder/musicForEveryone/downloadHelper/DownloadHelper.kt
index 49e7fee6..13126423 100644
--- a/app/src/main/java/com/shabinder/musicForEveryone/downloadHelper/DownloadHelper.kt
+++ b/app/src/main/java/com/shabinder/musicForEveryone/downloadHelper/DownloadHelper.kt
@@ -14,43 +14,49 @@ import kotlinx.coroutines.withContext
import java.io.File
interface DownloadHelper {
- suspend fun downloadTrack(ytDownloader: YoutubeDownloader?, downloadManager: DownloadManager?, searchQuery:String){
+ suspend fun downloadTrack(
+ ytDownloader: YoutubeDownloader?,
+ downloadManager: DownloadManager?,
+ searchQuery: String
+ ) {
- withContext(Dispatchers.IO){
- val downloadIdList = mutableListOf()
- val data = YoutubeInterface.search(searchQuery)?.get(0)
- if (data==null){Log.i("DownloadHelper","Youtube Request Failed!")}else{
+ withContext(Dispatchers.IO) {
+ val data = YoutubeInterface.search(searchQuery)?.get(0)
+ if (data == null) {
+ Log.i("DownloadHelper", "Youtube Request Failed!")
+ } else {
val video = ytDownloader?.getVideo(data.id)
//Fetching a Video Object.
val details = video?.details()
+ try{
+ val format: Format =
+ video?.findAudioWithQuality(AudioQuality.medium)?.get(0) as Format
+ val audioUrl = format.url()
+ Log.i("DHelper Link Found", audioUrl)
+ if (audioUrl != null) {
+ downloadFile(audioUrl, downloadManager, details!!.title())
+ } else {
+ Log.i("YT audio url is null", format.toString())
+ }
+ }catch (e:ArrayIndexOutOfBoundsException){
+ Log.i("Catch",e.toString())
+ }
- val format:Format = video?.findAudioWithQuality(AudioQuality.low)?.get(0) as Format
-
- val audioUrl = format.url()
-
- if (audioUrl != null) {
- downloadFile(audioUrl,downloadManager,details!!.title())
- Log.i("DHelper Start Download", audioUrl)
- }else{Log.i("YT audio url is null", format.toString())}
}
-
-
-// Library Inbuilt function to Save File (Need Scoped Storage Implementation)
-// val file: File = video.download( format , outputDir)
}
- //@data = 1st object from YT query.
}
/**
* Downloading Using Android Download Manager
* */
- suspend fun downloadFile(url: String, downloadManager: DownloadManager?,title:String){
- withContext(Dispatchers.IO){
+ suspend fun downloadFile(url: String, downloadManager: DownloadManager?, title: String) {
+ withContext(Dispatchers.IO) {
val audioUri = Uri.parse(url)
- val outputDir = File.separator + "Spotify-Downloads" +File.separator + "${removeIllegalChars(title)}.mp3"
+ val outputDir =
+ File.separator + "Spotify-Downloads" + File.separator + "${removeIllegalChars(title)}.mp3"
val request = DownloadManager.Request(audioUri)
.setAllowedNetworkTypes(
@@ -60,10 +66,10 @@ interface DownloadHelper {
.setAllowedOverRoaming(false)
.setTitle(title)
.setDescription("Spotify Downloader Working Up here...")
- .setDestinationInExternalPublicDir(Environment.DIRECTORY_MUSIC,outputDir)
+ .setDestinationInExternalPublicDir(Environment.DIRECTORY_MUSIC, outputDir)
.setNotificationVisibility(VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
downloadManager?.enqueue(request)
- Log.i("DownloadManager","Download Request Sent")
+ Log.i("DownloadManager", "Download Request Sent")
}
}
diff --git a/app/src/main/java/com/shabinder/musicForEveryone/fragments/MainFragment.kt b/app/src/main/java/com/shabinder/musicForEveryone/fragments/MainFragment.kt
index c31905d3..3fc56281 100644
--- a/app/src/main/java/com/shabinder/musicForEveryone/fragments/MainFragment.kt
+++ b/app/src/main/java/com/shabinder/musicForEveryone/fragments/MainFragment.kt
@@ -61,51 +61,56 @@ class MainFragment : Fragment(),DownloadHelper {
adapter.trackList = trackList
adapter.notifyDataSetChanged()
Log.i("Adapter",trackList.size.toString())
+ binding.btnDownloadAll.setOnClickListener { downloadAllTracks(trackList) }
}
}
"album" -> {
sharedViewModel.uiScope.launch{
- val albumObject = sharedViewModel.getAlbumDetails(link)
+ val albumObject = sharedViewModel.getAlbumDetails(link)
+// binding.titleView.text = albumObject!!.name
+// binding.titleView.visibility =View.VISIBLE
+ binding.imageView.visibility =View.VISIBLE
+ binding.btnDownloadAll.visibility =View.VISIBLE
+ val trackList = mutableListOf