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.toTrackDetailsList() = this.map { TrackDetails( title = it.name.toString(), diff --git a/app/src/main/java/com/shabinder/spotiflyer/ui/youtube/YoutubeFragment.kt b/app/src/main/java/com/shabinder/spotiflyer/ui/youtube/YoutubeFragment.kt index 1a9baa08..03cb626f 100755 --- a/app/src/main/java/com/shabinder/spotiflyer/ui/youtube/YoutubeFragment.kt +++ b/app/src/main/java/com/shabinder/spotiflyer/ui/youtube/YoutubeFragment.kt @@ -22,31 +22,37 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.lifecycle.ViewModelProvider +import androidx.navigation.fragment.navArgs +import com.github.kiulian.downloader.YoutubeDownloader import com.shabinder.spotiflyer.downloadHelper.YTDownloadHelper import com.shabinder.spotiflyer.models.DownloadStatus import com.shabinder.spotiflyer.models.spotify.Source 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 YoutubeFragment : BaseFragment() { +private const val sampleDomain2 = "youtu.be" +private const val sampleDomain1 = "youtube.com" - override lateinit var baseViewModel: BaseViewModel +@AndroidEntryPoint +class YoutubeFragment : TrackListFragment() { + + @Inject lateinit var ytDownloader: YoutubeDownloader + override lateinit var viewModel: YoutubeViewModel override lateinit var adapter : TrackListAdapter override var source: Source = Source.YouTube - private val viewModel: YoutubeViewModel - get() = baseViewModel as YoutubeViewModel - private val sampleDomain2 = "youtu.be" - private val sampleDomain1 = "youtube.com" + override val args: YoutubeFragmentArgs by navArgs() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { super.onCreateView(inflater, container, savedInstanceState) - baseViewModel = ViewModelProvider(this).get(YoutubeViewModel::class.java) - adapter = TrackListAdapter(viewModel) + this.viewModel = ViewModelProvider(this).get(YoutubeViewModel::class.java) + adapter = TrackListAdapter(this.viewModel) binding.trackList.adapter = adapter val args = YoutubeFragmentArgs.fromBundle(requireArguments()) @@ -60,7 +66,7 @@ class YoutubeFragment : BaseFragment() { if(link.contains("playlist",true) || link.contains("list",true)){ // Given Link is of a Playlist val playlistId = link.substringAfter("?list=").substringAfter("&list=").substringBefore("&") - viewModel.getYTPlaylist(playlistId,ytDownloader) + this.viewModel.getYTPlaylist(playlistId,ytDownloader) }else{//Given Link is of a Video var searchId = "error" if(link.contains(sampleDomain1,true) ){ @@ -70,7 +76,7 @@ class YoutubeFragment : BaseFragment() { searchId = link.substringAfterLast("/","error") } if(searchId != "error") { - viewModel.getYTTrack(searchId,ytDownloader) + this.viewModel.getYTTrack(searchId,ytDownloader) }else{showMessage("Your Youtube Link is not of a Video!!")} } @@ -87,10 +93,10 @@ class YoutubeFragment : BaseFragment() { rotateAnim(binding.downloadingFab) - for (track in viewModel.trackList.value?: listOf()){ + for (track in this.viewModel.trackList.value?: listOf()){ 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!") diff --git a/app/src/main/java/com/shabinder/spotiflyer/ui/youtube/YoutubeViewModel.kt b/app/src/main/java/com/shabinder/spotiflyer/ui/youtube/YoutubeViewModel.kt index 467442bf..e3e0e242 100755 --- a/app/src/main/java/com/shabinder/spotiflyer/ui/youtube/YoutubeViewModel.kt +++ b/app/src/main/java/com/shabinder/spotiflyer/ui/youtube/YoutubeViewModel.kt @@ -27,8 +27,8 @@ import com.shabinder.spotiflyer.database.DownloadRecord import com.shabinder.spotiflyer.models.DownloadStatus import com.shabinder.spotiflyer.models.TrackDetails import com.shabinder.spotiflyer.models.spotify.Source -import com.shabinder.spotiflyer.utils.BaseViewModel import com.shabinder.spotiflyer.utils.Provider.defaultDir +import com.shabinder.spotiflyer.utils.TrackListViewModel import com.shabinder.spotiflyer.utils.finalOutputDir import com.shabinder.spotiflyer.utils.removeIllegalChars import com.shabinder.spotiflyer.utils.showMessage @@ -37,7 +37,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.io.File -class YoutubeViewModel @ViewModelInject constructor(val databaseDAO: DatabaseDAO) : BaseViewModel(){ +class YoutubeViewModel @ViewModelInject constructor(val databaseDAO: DatabaseDAO) : TrackListViewModel(){ /* * YT Album Art Schema * HI-RES Url: https://i.ytimg.com/vi/$searchId/maxresdefault.jpg" diff --git a/app/src/main/java/com/shabinder/spotiflyer/utils/BaseFragment.kt b/app/src/main/java/com/shabinder/spotiflyer/utils/TrackListFragment.kt similarity index 72% rename from app/src/main/java/com/shabinder/spotiflyer/utils/BaseFragment.kt rename to app/src/main/java/com/shabinder/spotiflyer/utils/TrackListFragment.kt index b9695857..60e4bd56 100644 --- a/app/src/main/java/com/shabinder/spotiflyer/utils/BaseFragment.kt +++ b/app/src/main/java/com/shabinder/spotiflyer/utils/TrackListFragment.kt @@ -26,35 +26,27 @@ import android.util.Log 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.github.kiulian.downloader.YoutubeDownloader +import androidx.navigation.NavArgs import com.shabinder.spotiflyer.R import com.shabinder.spotiflyer.SharedViewModel import com.shabinder.spotiflyer.databinding.TrackListFragmentBinding import com.shabinder.spotiflyer.models.DownloadStatus import com.shabinder.spotiflyer.models.TrackDetails 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 dagger.hilt.android.AndroidEntryPoint -import javax.inject.Inject -@AndroidEntryPoint -abstract class BaseFragment : Fragment() { +abstract class TrackListFragment : Fragment() { - @Inject open lateinit var youtubeMusicApi: YoutubeMusicApi - @Inject open lateinit var ytDownloader: YoutubeDownloader - @Inject open lateinit var gaanaInterface: GaanaInterface - open lateinit var sharedViewModel: SharedViewModel - open lateinit var binding: TrackListFragmentBinding - abstract var baseViewModel: BaseViewModel - abstract var adapter: TrackListAdapter - abstract var source: Source + protected lateinit var sharedViewModel: SharedViewModel + protected lateinit var binding: TrackListFragmentBinding + protected abstract var viewModel: VM + protected abstract var adapter: TrackListAdapter + protected abstract var source: Source private var intentFilter: IntentFilter? = null private var updateUIReceiver: BroadcastReceiver? = null + protected abstract val args:NavArgs override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -66,7 +58,7 @@ abstract class BaseFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - binding = DataBindingUtil.inflate(inflater,R.layout.track_list_fragment, container, false) + binding = TrackListFragmentBinding.inflate(inflater,container,false) return binding.root } @@ -74,11 +66,12 @@ abstract class BaseFragment : Fragment() { super.onViewCreated(view, savedInstanceState) initializeLiveDataObservers() } + /** *Live Data Observers **/ - open fun initializeLiveDataObservers() { - baseViewModel.trackList.observe(viewLifecycleOwner, { + private fun initializeLiveDataObservers() { + viewModel.trackList.observe(viewLifecycleOwner, { if (it.isNotEmpty()){ Log.i("GaanaFragment","TrackList Updated") adapter.submitList(it, source) @@ -86,16 +79,16 @@ abstract class BaseFragment : Fragment() { } }) - baseViewModel.coverUrl.observe(viewLifecycleOwner, { + viewModel.coverUrl.observe(viewLifecycleOwner, { if(it!="Loading") bindImage(binding.coverImage,it, source) }) - baseViewModel.title.observe(viewLifecycleOwner, { + viewModel.title.observe(viewLifecycleOwner, { binding.titleView.text = it }) } - open fun initializeBroadcast() { + private fun initializeBroadcast() { intentFilter = IntentFilter() intentFilter?.addAction("track_download_completed") @@ -105,13 +98,13 @@ abstract class BaseFragment : Fragment() { if (intent != null){ val trackDetails = intent.getParcelableExtra("track") trackDetails?.let { - val position: Int = baseViewModel.trackList.value?.map { it.title }?.indexOf(trackDetails.title) ?: -1 + val position: Int = viewModel.trackList.value?.map { it.title }?.indexOf(trackDetails.title) ?: -1 Log.i("Track","Download Completed Intent :$position") if(position != -1) { - val track = baseViewModel.trackList.value?.get(position) + val track = viewModel.trackList.value?.get(position) track?.let{ it.downloaded = DownloadStatus.Downloaded - baseViewModel.trackList.value?.set(position, it) + viewModel.trackList.value?.set(position, it) adapter.notifyItemChanged(position) checkIfAllDownloaded() } @@ -133,8 +126,8 @@ abstract class BaseFragment : Fragment() { requireActivity().unregisterReceiver(updateUIReceiver) } - open fun checkIfAllDownloaded() { - if(!baseViewModel.trackList.value!!.any { it.downloaded != DownloadStatus.Downloaded }){ + private fun checkIfAllDownloaded() { + if(!viewModel.trackList.value!!.any { it.downloaded != DownloadStatus.Downloaded }){ //All Tracks Downloaded binding.btnDownloadAll.visibility = View.GONE binding.downloadingFab.apply{ diff --git a/app/src/main/java/com/shabinder/spotiflyer/utils/BaseViewModel.kt b/app/src/main/java/com/shabinder/spotiflyer/utils/TrackListViewModel.kt similarity index 97% rename from app/src/main/java/com/shabinder/spotiflyer/utils/BaseViewModel.kt rename to app/src/main/java/com/shabinder/spotiflyer/utils/TrackListViewModel.kt index c70a2223..1ab33bd8 100644 --- a/app/src/main/java/com/shabinder/spotiflyer/utils/BaseViewModel.kt +++ b/app/src/main/java/com/shabinder/spotiflyer/utils/TrackListViewModel.kt @@ -25,7 +25,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job -abstract class BaseViewModel:ViewModel() { +abstract class TrackListViewModel:ViewModel() { abstract var folderType:String abstract var subFolder:String open val trackList = MutableLiveData>() diff --git a/app/src/main/res/drawable/gradient.xml b/app/src/main/res/drawable/gradient.xml index 6177f9f4..b152852d 100755 --- a/app/src/main/res/drawable/gradient.xml +++ b/app/src/main/res/drawable/gradient.xml @@ -16,7 +16,8 @@ ~ along with this program. If not, see . --> - + + . --> - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/download_record_item.xml b/app/src/main/res/layout/download_record_item.xml index d301d54e..2324b2de 100755 --- a/app/src/main/res/layout/download_record_item.xml +++ b/app/src/main/res/layout/download_record_item.xml @@ -17,89 +17,81 @@ ~ along with this program. If not, see . --> - - - - + - + - + - - - + - + - + - - + diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index 101b59cd..ee29bb7f 100755 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -16,39 +16,36 @@ ~ along with this program. If not, see . --> - + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/mainActivity" + android:layout_width="match_parent" + android:layout_height="match_parent"> + - - + android:layout_height="0dp" + app:defaultNavHost="true" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:navGraph="@navigation/navigation" + tools:ignore="FragmentTagUsage" /> - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/main_fragment.xml b/app/src/main/res/layout/main_fragment.xml index 40240e42..07f71c93 100755 --- a/app/src/main/res/layout/main_fragment.xml +++ b/app/src/main/res/layout/main_fragment.xml @@ -15,47 +15,40 @@ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see . --> - + + app:layout_constraintTop_toBottomOf="@+id/linkSearch" + tools:ignore="UnusedAttribute" /> + android:contentDescription="Open Download History Button" + app:srcCompat="@drawable/ic_history"/> + app:layout_constraintTop_toBottomOf="@id/appLogo" + /> - - - + android:padding="6dp" + app:layout_constraintHorizontal_chainStyle="packed" + app:layout_constraintStart_toStartOf="@+id/appSubTitle" + app:layout_constraintTop_toBottomOf="@+id/appSubTitle"/> + android:contentDescription="Open Github App Button" + app:layout_constraintVertical_chainStyle="packed"/> + android:contentDescription="Open LinkedIN App Button" + app:layout_constraintTop_toBottomOf="@+id/btn_github_spotify"/> - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/track_list_fragment.xml b/app/src/main/res/layout/track_list_fragment.xml index 7ea750a8..dfdfc714 100755 --- a/app/src/main/res/layout/track_list_fragment.xml +++ b/app/src/main/res/layout/track_list_fragment.xml @@ -16,16 +16,16 @@ ~ along with this program. If not, see . --> - - + diff --git a/app/src/main/res/layout/track_list_item.xml b/app/src/main/res/layout/track_list_item.xml index aa9de8b6..ba3a0c59 100755 --- a/app/src/main/res/layout/track_list_item.xml +++ b/app/src/main/res/layout/track_list_item.xml @@ -16,97 +16,84 @@ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see . --> + - - - - - - - + android:contentDescription="Track Image" + android:scaleType="centerInside" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/artist" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:srcCompat="@drawable/ic_song_placeholder" /> - + - - - + - + - + - - - - + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 2824d54a..a4088d8b 100755 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -20,10 +20,12 @@ #FC5C7D #CE1CFF - #799BFF + #9AB3FF #FFFFFF #99FFFFFF #000000 - + #121212 + #4BB543 + #FF9494 \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 1801bfbb..c3b734c0 100755 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -19,12 +19,22 @@ + + + + +