diff --git a/.idea/dictionaries/shabinder.xml b/.idea/dictionaries/shabinder.xml
index b91cbc33..82062cc1 100755
--- a/.idea/dictionaries/shabinder.xml
+++ b/.idea/dictionaries/shabinder.xml
@@ -16,6 +16,7 @@
instagram
jetbrains
kotlinx
+ linkedin
mainfragment
maxresdefault
moshi
diff --git a/app/build.gradle b/app/build.gradle
index 96594a07..7efce010 100755
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -28,7 +28,8 @@ android {
buildToolsVersion "30.0.2"
buildFeatures{
- dataBinding = true
+ //dataBinding = true
+ viewBinding = true
}
defaultConfig {
diff --git a/app/src/main/java/com/shabinder/spotiflyer/MainActivity.kt b/app/src/main/java/com/shabinder/spotiflyer/MainActivity.kt
index 9ffe9cfc..3b32e10c 100755
--- a/app/src/main/java/com/shabinder/spotiflyer/MainActivity.kt
+++ b/app/src/main/java/com/shabinder/spotiflyer/MainActivity.kt
@@ -30,7 +30,6 @@ import android.util.Log
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
-import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.NavController
import androidx.navigation.findNavController
@@ -69,12 +68,13 @@ class MainActivity : AppCompatActivity(){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ //Enabling Dark Mode
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
- binding = DataBindingUtil.setContentView(this, R.layout.main_activity)
+ binding = MainActivityBinding.inflate(layoutInflater)
+ setContentView(binding.root)
sharedViewModel = ViewModelProvider(this).get(SharedViewModel::class.java)
navController = findNavController(R.id.navHostFragment)
snackBarAnchor = binding.snackBarPosition
- //Enabling Dark Mode
authenticateSpotify()
diff --git a/app/src/main/java/com/shabinder/spotiflyer/recyclerView/TrackListAdapter.kt b/app/src/main/java/com/shabinder/spotiflyer/recyclerView/TrackListAdapter.kt
index 00695c58..a2f4905f 100755
--- a/app/src/main/java/com/shabinder/spotiflyer/recyclerView/TrackListAdapter.kt
+++ b/app/src/main/java/com/shabinder/spotiflyer/recyclerView/TrackListAdapter.kt
@@ -33,7 +33,7 @@ import com.shabinder.spotiflyer.models.spotify.Source
import com.shabinder.spotiflyer.utils.*
import kotlinx.coroutines.launch
-class TrackListAdapter(private val viewModel :BaseViewModel): ListAdapter(TrackDiffCallback()) {
+class TrackListAdapter(private val viewModel :TrackListViewModel): ListAdapter(TrackDiffCallback()) {
var source:Source =Source.Spotify
diff --git a/app/src/main/java/com/shabinder/spotiflyer/ui/downloadrecord/DownloadRecordFragment.kt b/app/src/main/java/com/shabinder/spotiflyer/ui/downloadrecord/DownloadRecordFragment.kt
index 03ac9fdb..b48311e9 100755
--- a/app/src/main/java/com/shabinder/spotiflyer/ui/downloadrecord/DownloadRecordFragment.kt
+++ b/app/src/main/java/com/shabinder/spotiflyer/ui/downloadrecord/DownloadRecordFragment.kt
@@ -21,11 +21,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
-import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.google.android.material.tabs.TabLayout
-import com.shabinder.spotiflyer.R
import com.shabinder.spotiflyer.databinding.DownloadRecordFragmentBinding
import com.shabinder.spotiflyer.models.spotify.Source
import com.shabinder.spotiflyer.recyclerView.DownloadRecordAdapter
@@ -42,7 +40,7 @@ class DownloadRecordFragment : Fragment() {
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
- binding = DataBindingUtil.inflate(inflater,R.layout.download_record_fragment,container,false)
+ binding = DownloadRecordFragmentBinding.inflate(inflater,container,false)
downloadRecordViewModel = ViewModelProvider(this).get(DownloadRecordViewModel::class.java)
adapter = DownloadRecordAdapter()
binding.downloadRecordList.adapter = adapter
diff --git a/app/src/main/java/com/shabinder/spotiflyer/ui/gaana/GaanaFragment.kt b/app/src/main/java/com/shabinder/spotiflyer/ui/gaana/GaanaFragment.kt
index b407c4f9..330e741a 100644
--- a/app/src/main/java/com/shabinder/spotiflyer/ui/gaana/GaanaFragment.kt
+++ b/app/src/main/java/com/shabinder/spotiflyer/ui/gaana/GaanaFragment.kt
@@ -23,24 +23,30 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.ViewModelProvider
+import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.SimpleItemAnimator
import com.shabinder.spotiflyer.SharedViewModel
import com.shabinder.spotiflyer.downloadHelper.DownloadHelper
import com.shabinder.spotiflyer.models.DownloadStatus
import com.shabinder.spotiflyer.models.spotify.Source
+import com.shabinder.spotiflyer.networking.GaanaInterface
+import com.shabinder.spotiflyer.networking.YoutubeMusicApi
import com.shabinder.spotiflyer.recyclerView.TrackListAdapter
import com.shabinder.spotiflyer.utils.*
+import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
+import javax.inject.Inject
-class GaanaFragment : BaseFragment() {
+@AndroidEntryPoint
+class GaanaFragment : TrackListFragment() {
- override lateinit var baseViewModel: BaseViewModel
+ @Inject lateinit var youtubeMusicApi: YoutubeMusicApi
+ @Inject lateinit var gaanaInterface: GaanaInterface
+ override lateinit var viewModel: GaanaViewModel
override lateinit var adapter: TrackListAdapter
override var source: Source = Source.Gaana
- private val viewModel:GaanaViewModel
- get() = baseViewModel as GaanaViewModel
-
+ override val args: GaanaFragmentArgs by navArgs()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
@@ -75,16 +81,16 @@ class GaanaFragment : BaseFragment() {
binding.downloadingFab.visibility = View.VISIBLE
rotateAnim(binding.downloadingFab)
- for (track in baseViewModel.trackList.value!!){
+ for (track in viewModel.trackList.value!!){
if(track.downloaded != DownloadStatus.Downloaded){
track.downloaded = DownloadStatus.Downloading
- adapter.notifyItemChanged(baseViewModel.trackList.value!!.indexOf(track))
+ adapter.notifyItemChanged(viewModel.trackList.value!!.indexOf(track))
}
}
showMessage("Processing!")
sharedViewModel.uiScope.launch(Dispatchers.Default){
val urlList = arrayListOf()
- baseViewModel.trackList.value?.forEach { urlList.add(it.albumArtURL) }
+ viewModel.trackList.value?.forEach { urlList.add(it.albumArtURL) }
//Appending Source
urlList.add("gaana")
loadAllImages(
@@ -92,12 +98,12 @@ class GaanaFragment : BaseFragment() {
urlList
)
}
- baseViewModel.uiScope.launch {
- val finalList = baseViewModel.trackList.value
+ viewModel.uiScope.launch {
+ val finalList = viewModel.trackList.value
if(finalList.isNullOrEmpty())showMessage("Not Downloading Any Song")
DownloadHelper.downloadAllTracks(
- baseViewModel.folderType,
- baseViewModel.subFolder,
+ viewModel.folderType,
+ viewModel.subFolder,
finalList ?: listOf(),
)
}
@@ -112,7 +118,7 @@ class GaanaFragment : BaseFragment() {
**/
private fun initializeAll() {
sharedViewModel = ViewModelProvider(this.requireActivity()).get(SharedViewModel::class.java)
- baseViewModel = ViewModelProvider(this).get(GaanaViewModel::class.java)
+ viewModel = ViewModelProvider(this).get(GaanaViewModel::class.java)
viewModel.gaanaInterface = gaanaInterface
adapter = TrackListAdapter(viewModel)
DownloadHelper.youtubeMusicApi = youtubeMusicApi
diff --git a/app/src/main/java/com/shabinder/spotiflyer/ui/gaana/GaanaViewModel.kt b/app/src/main/java/com/shabinder/spotiflyer/ui/gaana/GaanaViewModel.kt
index a7717422..6e81a679 100644
--- a/app/src/main/java/com/shabinder/spotiflyer/ui/gaana/GaanaViewModel.kt
+++ b/app/src/main/java/com/shabinder/spotiflyer/ui/gaana/GaanaViewModel.kt
@@ -27,15 +27,15 @@ import com.shabinder.spotiflyer.models.TrackDetails
import com.shabinder.spotiflyer.models.gaana.*
import com.shabinder.spotiflyer.models.spotify.Source
import com.shabinder.spotiflyer.networking.GaanaInterface
-import com.shabinder.spotiflyer.utils.BaseViewModel
import com.shabinder.spotiflyer.utils.Provider
+import com.shabinder.spotiflyer.utils.TrackListViewModel
import com.shabinder.spotiflyer.utils.finalOutputDir
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
-class GaanaViewModel @ViewModelInject constructor(val databaseDAO: DatabaseDAO) : BaseViewModel(){
+class GaanaViewModel @ViewModelInject constructor(val databaseDAO: DatabaseDAO) : TrackListViewModel(){
override var folderType:String = ""
override var subFolder:String = ""
diff --git a/app/src/main/java/com/shabinder/spotiflyer/ui/mainfragment/MainFragment.kt b/app/src/main/java/com/shabinder/spotiflyer/ui/mainfragment/MainFragment.kt
index 6d5af994..6ad9a9c0 100755
--- a/app/src/main/java/com/shabinder/spotiflyer/ui/mainfragment/MainFragment.kt
+++ b/app/src/main/java/com/shabinder/spotiflyer/ui/mainfragment/MainFragment.kt
@@ -25,7 +25,6 @@ import android.text.SpannableStringBuilder
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
-import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
@@ -57,7 +56,7 @@ class MainFragment : Fragment() {
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
- binding = DataBindingUtil.inflate(inflater,R.layout.main_fragment,container,false)
+ binding = MainFragmentBinding.inflate(inflater,container,false)
initializeAll()
binding.btnSearch.setOnClickListener {
if(!isOnline()){
diff --git a/app/src/main/java/com/shabinder/spotiflyer/ui/spotify/SpotifyFragment.kt b/app/src/main/java/com/shabinder/spotiflyer/ui/spotify/SpotifyFragment.kt
index 093fc854..cc7299a8 100755
--- a/app/src/main/java/com/shabinder/spotiflyer/ui/spotify/SpotifyFragment.kt
+++ b/app/src/main/java/com/shabinder/spotiflyer/ui/spotify/SpotifyFragment.kt
@@ -24,26 +24,29 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.ViewModelProvider
+import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.SimpleItemAnimator
import com.shabinder.spotiflyer.MainActivity
import com.shabinder.spotiflyer.downloadHelper.DownloadHelper
import com.shabinder.spotiflyer.models.DownloadStatus
import com.shabinder.spotiflyer.models.spotify.Source
+import com.shabinder.spotiflyer.networking.YoutubeMusicApi
import com.shabinder.spotiflyer.recyclerView.TrackListAdapter
import com.shabinder.spotiflyer.utils.*
import com.shabinder.spotiflyer.utils.Provider.mainActivity
+import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
+import javax.inject.Inject
-@Suppress("DEPRECATION")
-class SpotifyFragment : BaseFragment() {
+@AndroidEntryPoint
+class SpotifyFragment : TrackListFragment() {
- override lateinit var baseViewModel: BaseViewModel
+ @Inject lateinit var youtubeMusicApi: YoutubeMusicApi
+ override lateinit var viewModel: SpotifyViewModel
override lateinit var adapter: TrackListAdapter
override var source: Source = Source.Spotify
- private val viewModel: SpotifyViewModel
- get() = baseViewModel as SpotifyViewModel
-
+ override val args: SpotifyFragmentArgs by navArgs()
@SuppressLint("SetJavaScriptEnabled")
override fun onCreateView(
@@ -53,7 +56,7 @@ class SpotifyFragment : BaseFragment() {
super.onCreateView(inflater, container, savedInstanceState)
initializeAll()
- val spotifyLink = SpotifyFragmentArgs.fromBundle(requireArguments()).link.substringAfter("open.spotify.com/")
+ val spotifyLink = args.link.substringAfter("open.spotify.com/")
val link = spotifyLink.substringAfterLast('/', "Error").substringBefore('?')
val type = spotifyLink.substringBeforeLast('/', "Error").substringAfterLast('/')
@@ -75,7 +78,7 @@ class SpotifyFragment : BaseFragment() {
showMessage("Implementing Soon, Stay Tuned!")
}
else{
- viewModel.spotifySearch(type,link)
+ this.viewModel.spotifySearch(type,link)
binding.btnDownloadAll.setOnClickListener {
if(!isOnline()){
@@ -86,16 +89,16 @@ class SpotifyFragment : BaseFragment() {
binding.downloadingFab.visibility = View.VISIBLE
rotateAnim(binding.downloadingFab)
- for (track in viewModel.trackList.value!!){
+ for (track in this.viewModel.trackList.value!!){
if(track.downloaded != DownloadStatus.Downloaded){
track.downloaded = DownloadStatus.Downloading
- adapter.notifyItemChanged(viewModel.trackList.value!!.indexOf(track))
+ adapter.notifyItemChanged(this.viewModel.trackList.value!!.indexOf(track))
}
}
showMessage("Processing!")
sharedViewModel.uiScope.launch(Dispatchers.Default){
val urlList = arrayListOf()
- viewModel.trackList.value?.forEach { urlList.add(it.albumArtURL) }
+ this@SpotifyFragment.viewModel.trackList.value?.forEach { urlList.add(it.albumArtURL) }
//Appending Source
urlList.add("spotify")
loadAllImages(
@@ -103,7 +106,7 @@ class SpotifyFragment : BaseFragment() {
urlList
)
}
- viewModel.uiScope.launch {
+ this.viewModel.uiScope.launch {
val finalList = viewModel.trackList.value
if(finalList.isNullOrEmpty())showMessage("Not Downloading Any Song")
DownloadHelper.downloadAllTracks(
@@ -124,10 +127,10 @@ class SpotifyFragment : BaseFragment() {
* Basic Initialization
**/
private fun initializeAll() {
- baseViewModel = ViewModelProvider(this).get(SpotifyViewModel::class.java)
- adapter = TrackListAdapter(viewModel)
+ this.viewModel = ViewModelProvider(this).get(SpotifyViewModel::class.java)
+ adapter = TrackListAdapter(this.viewModel)
sharedViewModel.spotifyService.observe(viewLifecycleOwner, {
- viewModel.spotifyService = it
+ this.viewModel.spotifyService = it
})
DownloadHelper.youtubeMusicApi = youtubeMusicApi
DownloadHelper.sharedViewModel = sharedViewModel
diff --git a/app/src/main/java/com/shabinder/spotiflyer/ui/spotify/SpotifyViewModel.kt b/app/src/main/java/com/shabinder/spotiflyer/ui/spotify/SpotifyViewModel.kt
index 07c1dfc8..f6f758d7 100755
--- a/app/src/main/java/com/shabinder/spotiflyer/ui/spotify/SpotifyViewModel.kt
+++ b/app/src/main/java/com/shabinder/spotiflyer/ui/spotify/SpotifyViewModel.kt
@@ -26,15 +26,15 @@ import com.shabinder.spotiflyer.models.DownloadStatus
import com.shabinder.spotiflyer.models.TrackDetails
import com.shabinder.spotiflyer.models.spotify.*
import com.shabinder.spotiflyer.networking.SpotifyService
-import com.shabinder.spotiflyer.utils.BaseViewModel
import com.shabinder.spotiflyer.utils.Provider
+import com.shabinder.spotiflyer.utils.TrackListViewModel
import com.shabinder.spotiflyer.utils.finalOutputDir
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
-class SpotifyViewModel @ViewModelInject constructor(val databaseDAO: DatabaseDAO) : BaseViewModel(){
+class SpotifyViewModel @ViewModelInject constructor(val databaseDAO: DatabaseDAO) : TrackListViewModel(){
override var folderType:String = ""
override var subFolder:String = ""
@@ -145,6 +145,7 @@ class SpotifyViewModel @ViewModelInject constructor(val databaseDAO: DatabaseDAO
}
}
+ @Suppress("DEPRECATION")
private fun List