diff --git a/app/build.gradle b/app/build.gradle
index 368332d8..436d8c12 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -89,10 +89,10 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7"
implementation "androidx.room:room-runtime:2.2.5"
- implementation project(path: ':mobile-ffmpeg')
- implementation 'androidx.legacy:legacy-support-v4:1.0.0'
kapt "androidx.room:room-compiler:2.2.5"
implementation "androidx.room:room-ktx:2.2.5"
+ implementation project(path: ':mobile-ffmpeg')
+ implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation ("com.github.bumptech.glide:recyclerview-integration:4.11.0") {
transitive = true
}
diff --git a/app/src/main/java/com/shabinder/spotiflyer/database/DatabaseDAO.kt b/app/src/main/java/com/shabinder/spotiflyer/database/DatabaseDAO.kt
new file mode 100644
index 00000000..6cc02c97
--- /dev/null
+++ b/app/src/main/java/com/shabinder/spotiflyer/database/DatabaseDAO.kt
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2020 Shabinder Singh
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.shabinder.spotiflyer.database
+
+import androidx.room.*
+
+@Dao
+interface DatabaseDAO {
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ suspend fun insert(record: DownloadRecord)
+
+ @Update
+ fun update(record: DownloadRecord)
+
+ @Query("SELECT * from download_record_table ORDER BY id DESC")
+ suspend fun getRecord():List
+
+ @Query("DELETE FROM download_record_table")
+ suspend fun deleteAll()
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/shabinder/spotiflyer/database/DownloadRecord.kt b/app/src/main/java/com/shabinder/spotiflyer/database/DownloadRecord.kt
new file mode 100644
index 00000000..2f69c9e1
--- /dev/null
+++ b/app/src/main/java/com/shabinder/spotiflyer/database/DownloadRecord.kt
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2020 Shabinder Singh
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.shabinder.spotiflyer.database
+
+import android.os.Parcelable
+import androidx.room.ColumnInfo
+import androidx.room.Entity
+import androidx.room.Index
+import androidx.room.PrimaryKey
+import kotlinx.android.parcel.Parcelize
+
+@Parcelize
+@Entity(
+ tableName = "download_record_table",
+ indices = [Index(value = ["id","link"], unique = true)]
+)
+data class DownloadRecord(
+
+ @PrimaryKey(autoGenerate = true)
+ var id:Int = 0,
+
+ @ColumnInfo(name = "type")
+ var type:String,
+
+ @ColumnInfo(name = "name")
+ var name:String,
+
+ @ColumnInfo(name = "link")
+ var link:String,
+
+ @ColumnInfo(name = "coverUrl")
+ var coverUrl:String,
+
+ @ColumnInfo(name = "totalFiles")
+ var totalFiles:Int = 1,
+
+ @ColumnInfo(name = "downloaded")
+ var downloaded:Boolean=false,
+
+ @ColumnInfo(name = "directory")
+ var directory:String?=null
+):Parcelable
\ No newline at end of file
diff --git a/app/src/main/java/com/shabinder/spotiflyer/database/DownloadRecordDatabase.kt b/app/src/main/java/com/shabinder/spotiflyer/database/DownloadRecordDatabase.kt
new file mode 100644
index 00000000..17637597
--- /dev/null
+++ b/app/src/main/java/com/shabinder/spotiflyer/database/DownloadRecordDatabase.kt
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2020 Shabinder Singh
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.shabinder.spotiflyer.database
+
+import android.content.Context
+import androidx.room.Database
+import androidx.room.Room
+import androidx.room.RoomDatabase
+
+@Database(entities = [DownloadRecord::class], version = 1, exportSchema = false)
+abstract class DownloadRecordDatabase:RoomDatabase() {
+
+ abstract val databaseDAO: DatabaseDAO
+
+ companion object {
+ @Volatile
+ private var INSTANCE: DownloadRecordDatabase? = null
+
+ fun getInstance(context: Context): DownloadRecordDatabase {
+ synchronized(this) {
+ var instance = INSTANCE
+ if (instance == null) {
+ instance = Room.databaseBuilder(
+ context.applicationContext,
+ DownloadRecordDatabase::class.java,
+ "download_record_database")
+ .fallbackToDestructiveMigration()
+ .build()
+
+ INSTANCE = instance
+ }
+
+ return instance
+ }
+
+ }
+
+ }
+
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/shabinder/spotiflyer/downloadHelper/SpotifyDownloadHelper.kt b/app/src/main/java/com/shabinder/spotiflyer/downloadHelper/SpotifyDownloadHelper.kt
index 90c9cc1e..afe24cbf 100644
--- a/app/src/main/java/com/shabinder/spotiflyer/downloadHelper/SpotifyDownloadHelper.kt
+++ b/app/src/main/java/com/shabinder/spotiflyer/downloadHelper/SpotifyDownloadHelper.kt
@@ -34,10 +34,10 @@ import androidx.core.content.ContextCompat
import com.github.kiulian.downloader.YoutubeDownloader
import com.github.kiulian.downloader.model.formats.Format
import com.github.kiulian.downloader.model.quality.AudioQuality
-import com.shabinder.spotiflyer.SharedViewModel
import com.shabinder.spotiflyer.models.DownloadObject
import com.shabinder.spotiflyer.models.Track
import com.shabinder.spotiflyer.ui.spotify.SpotifyFragment
+import com.shabinder.spotiflyer.ui.spotify.SpotifyViewModel
import com.shabinder.spotiflyer.worker.ForegroundService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -49,7 +49,7 @@ object SpotifyDownloadHelper {
var context : Context? = null
var statusBar:TextView? = null
val defaultDir = Environment.DIRECTORY_MUSIC + File.separator + "SpotiFlyer" + File.separator
- var sharedViewModel:SharedViewModel? = null
+ var spotifyViewModel: SpotifyViewModel? = null
private var isBrowserLoading = false
private var total = 0
private var Processed = 0
@@ -66,9 +66,7 @@ object SpotifyDownloadHelper {
withContext(Dispatchers.Main){
total += trackList.size // Adding New Download List Count to StatusBar
trackList.forEach {
- val outputFile:String = Environment.getExternalStorageDirectory().toString() + File.separator +
- defaultDir + removeIllegalChars(type) + File.separator + (if(subFolder == null){""}else{ removeIllegalChars(subFolder) + File.separator} + removeIllegalChars(it.name!!)+".mp3")
- if(File(outputFile).exists()){//Download Already Present!!
+ if(it.downloaded == "Downloaded"){//Download Already Present!!
Processed++
}else{
if(isBrowserLoading){//WebView Busy!!
@@ -124,7 +122,7 @@ object SpotifyDownloadHelper {
}
if(youtubeList.isNotEmpty()){
val request = youtubeList[0]
- sharedViewModel!!.uiScope.launch {
+ spotifyViewModel!!.uiScope.launch {
getYTLink(request.spotifyFragment,request.type,request.subFolder,request.ytDownloader,request.searchQuery,request.track)
}
youtubeList.remove(request)
@@ -147,7 +145,7 @@ object SpotifyDownloadHelper {
fun downloadFile(subFolder: String?, type: String, track:Track, ytDownloader: YoutubeDownloader?, id: String) {
- sharedViewModel!!.uiScope.launch {
+ spotifyViewModel!!.uiScope.launch {
withContext(Dispatchers.IO) {
val video = ytDownloader?.getVideo(id)
val detail = video?.details()
diff --git a/app/src/main/java/com/shabinder/spotiflyer/downloadHelper/YTDownloadHelper.kt b/app/src/main/java/com/shabinder/spotiflyer/downloadHelper/YTDownloadHelper.kt
new file mode 100644
index 00000000..92856c54
--- /dev/null
+++ b/app/src/main/java/com/shabinder/spotiflyer/downloadHelper/YTDownloadHelper.kt
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2020 Shabinder Singh
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.shabinder.spotiflyer.downloadHelper
+
+import android.content.Context
+import android.content.Intent
+import android.os.Environment
+import android.util.Log
+import android.view.View
+import android.widget.TextView
+import androidx.core.content.ContextCompat
+import com.github.kiulian.downloader.model.formats.Format
+import com.shabinder.spotiflyer.models.DownloadObject
+import com.shabinder.spotiflyer.models.Track
+import com.shabinder.spotiflyer.worker.ForegroundService
+import java.io.File
+
+object YTDownloadHelper {
+ var context : Context? = null
+ var statusBar: TextView? = null
+
+ fun downloadFile(subFolder: String?, type: String,ytTrack: Track,format: Format?) {
+ format?.let {
+ val url:String = format.url()
+// Log.i("DHelper Link Found", url)
+ val outputFile:String = Environment.getExternalStorageDirectory().toString() + File.separator +
+ SpotifyDownloadHelper.defaultDir + SpotifyDownloadHelper.removeIllegalChars(type) + File.separator + (if(subFolder == null){""}else{ SpotifyDownloadHelper.removeIllegalChars(subFolder) + File.separator} + SpotifyDownloadHelper.removeIllegalChars(
+ ytTrack.name!!
+ ) +".m4a")
+
+ val downloadObject = DownloadObject(
+ track = ytTrack,
+ url = url,
+ outputDir = outputFile
+ )
+ Log.i("DH",outputFile)
+ startService(context!!, downloadObject)
+ statusBar?.visibility= View.VISIBLE
+ }
+ }
+
+
+
+ private fun startService(context:Context, obj: DownloadObject? = null ) {
+ val serviceIntent = Intent(context, ForegroundService::class.java)
+ serviceIntent.putExtra("object",obj)
+ ContextCompat.startForegroundService(context, serviceIntent)
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/shabinder/spotiflyer/models/Track.kt b/app/src/main/java/com/shabinder/spotiflyer/models/Track.kt
index d16e764b..9ce8893c 100644
--- a/app/src/main/java/com/shabinder/spotiflyer/models/Track.kt
+++ b/app/src/main/java/com/shabinder/spotiflyer/models/Track.kt
@@ -40,4 +40,5 @@ data class Track(
var album: Album? = null,
var external_ids: Map? = null,
var popularity: Int? = null,
- var ytCoverUrl:String? = null):Parcelable
\ No newline at end of file
+ var ytCoverUrl:String? = null,
+ var downloaded:String? = "notDownloaded"):Parcelable
\ No newline at end of file
diff --git a/app/src/main/java/com/shabinder/spotiflyer/models/YTTrack.kt b/app/src/main/java/com/shabinder/spotiflyer/models/YTTrack.kt
new file mode 100644
index 00000000..703a708b
--- /dev/null
+++ b/app/src/main/java/com/shabinder/spotiflyer/models/YTTrack.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2020 Shabinder Singh
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.shabinder.spotiflyer.models
+
+import android.os.Parcelable
+import kotlinx.android.parcel.Parcelize
+
+@Parcelize
+data class YTTrack(
+ var id:String?,
+ var title:String?,
+ var duration:Int?,
+ var author:String?,
+ var viewCount:Long?,
+ var thumbnails:List?
+):Parcelable
\ No newline at end of file
diff --git a/app/src/main/java/com/shabinder/spotiflyer/recyclerView/SpotifyTrackListAdapter.kt b/app/src/main/java/com/shabinder/spotiflyer/recyclerView/SpotifyTrackListAdapter.kt
index 09cc1167..6d97dbd1 100644
--- a/app/src/main/java/com/shabinder/spotiflyer/recyclerView/SpotifyTrackListAdapter.kt
+++ b/app/src/main/java/com/shabinder/spotiflyer/recyclerView/SpotifyTrackListAdapter.kt
@@ -20,59 +20,84 @@ package com.shabinder.spotiflyer.recyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
-import android.widget.ImageButton
-import android.widget.ImageView
-import android.widget.TextView
+import android.widget.Toast
+import androidx.recyclerview.widget.DiffUtil
+import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.shabinder.spotiflyer.R
-import com.shabinder.spotiflyer.SharedViewModel
+import com.shabinder.spotiflyer.databinding.TrackListItemBinding
+import com.shabinder.spotiflyer.downloadHelper.SpotifyDownloadHelper.context
import com.shabinder.spotiflyer.downloadHelper.SpotifyDownloadHelper.getYTLink
import com.shabinder.spotiflyer.models.Track
import com.shabinder.spotiflyer.ui.spotify.SpotifyFragment
+import com.shabinder.spotiflyer.ui.spotify.SpotifyViewModel
import com.shabinder.spotiflyer.utils.bindImage
+import com.shabinder.spotiflyer.utils.rotateAnim
import kotlinx.coroutines.launch
-class SpotifyTrackListAdapter:RecyclerView.Adapter() {
+class SpotifyTrackListAdapter: ListAdapter