From 735f7c270e60493ef40a013eb6e053cc3e07265b Mon Sep 17 00:00:00 2001 From: shabinder Date: Wed, 22 Jul 2020 11:34:08 +0530 Subject: [PATCH] Made All Long Running Calls Asynchronous(Coroutines deployed!) --- .idea/dictionaries/shabinder.xml | 1 + .idea/misc.xml | 3 + app/build.gradle | 7 +- app/src/main/AndroidManifest.xml | 5 + .../musicForEveryone/MainActivity.kt | 84 ++++++-- .../musicForEveryone/SharedViewModel.kt | 22 +- .../downloadHelper/DownloadHelper.kt | 69 ++++--- .../fragments/MainFragment.kt | 97 +++++---- .../recyclerView/TrackListAdapter.kt | 23 ++- .../musicForEveryone/utils/BindingAdapter.kt | 18 +- .../utils/SpotifyNewService.kt | 33 ++- ...ext_backdround.xml => text_background.xml} | 0 app/src/main/res/layout/main_activity.xml | 21 +- app/src/main/res/layout/main_fragment.xml | 195 ++++++++++-------- app/src/main/res/layout/track_list_item.xml | 122 ++++------- 15 files changed, 407 insertions(+), 293 deletions(-) rename app/src/main/res/drawable/{text_backdround.xml => text_background.xml} (100%) diff --git a/.idea/dictionaries/shabinder.xml b/.idea/dictionaries/shabinder.xml index 841adff3..fb809d5a 100644 --- a/.idea/dictionaries/shabinder.xml +++ b/.idea/dictionaries/shabinder.xml @@ -1,6 +1,7 @@ + moshi musicforeveryone musicplaceholder shabinder diff --git a/.idea/misc.xml b/.idea/misc.xml index 7bfef59d..344c5192 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,8 @@ + + + diff --git a/app/build.gradle b/app/build.gradle index d142aded..249a185c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -68,9 +68,14 @@ dependencies { implementation 'com.google.apis:google-api-services-youtube:v3-rev180-1.22.0' implementation 'com.google.oauth-client:google-oauth-client:1.22.0' implementation 'com.spotify.android:auth:1.1.0' - implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.squareup.okhttp3:okhttp:4.8.0' + implementation 'com.squareup.retrofit2:retrofit:2.9.0' + implementation "com.squareup.moshi:moshi:1.9.3" + implementation "com.squareup.moshi:moshi-kotlin:1.9.3" + implementation "com.squareup.retrofit2:converter-moshi:2.9.0" + + implementation 'com.github.sealedtx:java-youtube-downloader:2.2.2' implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 964bb325..835a5de3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -21,6 +21,11 @@ android:theme="@style/AppTheme"> + + + + + diff --git a/app/src/main/java/com/shabinder/musicForEveryone/MainActivity.kt b/app/src/main/java/com/shabinder/musicForEveryone/MainActivity.kt index dd2075d8..f08f5700 100644 --- a/app/src/main/java/com/shabinder/musicForEveryone/MainActivity.kt +++ b/app/src/main/java/com/shabinder/musicForEveryone/MainActivity.kt @@ -6,43 +6,52 @@ import android.content.Context import android.content.Intent import android.os.Build import android.os.Bundle -import android.os.StrictMode import android.util.Log import androidx.appcompat.app.AppCompatActivity import androidx.databinding.DataBindingUtil +import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import com.github.kiulian.downloader.YoutubeDownloader import com.shabinder.musicForEveryone.databinding.MainActivityBinding +import com.shabinder.musicForEveryone.downloadHelper.DownloadHelper import com.shabinder.musicForEveryone.utils.SpotifyNewService import com.shabinder.musicForEveryone.utils.YoutubeInterface import com.spotify.sdk.android.authentication.AuthenticationClient import com.spotify.sdk.android.authentication.AuthenticationRequest import com.spotify.sdk.android.authentication.AuthenticationResponse import com.spotify.sdk.android.authentication.LoginActivity +import com.squareup.moshi.Moshi +import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import kaaes.spotify.webapi.android.SpotifyApi import kaaes.spotify.webapi.android.SpotifyService -import retrofit.RestAdapter +import kotlinx.coroutines.launch +import okhttp3.Interceptor +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.Response +import retrofit2.Retrofit +import retrofit2.converter.moshi.MoshiConverterFactory -class MainActivity : AppCompatActivity() { +class MainActivity : AppCompatActivity() ,DownloadHelper{ private lateinit var binding: MainActivityBinding var ytDownloader : YoutubeDownloader? = null + var spotifyExtra : SpotifyNewService? = null var downloadManager : DownloadManager? = null val REDIRECT_URI = "musicforeveryone://callback" val CLIENT_ID:String = "694d8bf4f6ec420fa66ea7fb4c68f89d" -// val musicDirectory = File(this.filesDir?.absolutePath + "/Music/") - var message :String ="" var token :String ="" var spotify: SpotifyService? = null lateinit var sharedViewModel: SharedViewModel + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = DataBindingUtil.setContentView(this,R.layout.main_activity) sharedViewModel = ViewModelProvider(this).get(SharedViewModel::class.java) - val policy = - StrictMode.ThreadPolicy.Builder().permitAll().build() - StrictMode.setThreadPolicy(policy) +// val policy = +// StrictMode.ThreadPolicy.Builder().permitAll().build() +// StrictMode.setThreadPolicy(policy) //TODO Use Coroutines if(spotify==null){ authenticateSpotify() @@ -59,7 +68,14 @@ class MainActivity : AppCompatActivity() { downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager sharedViewModel.downloadManager = downloadManager - + if (intent?.action == Intent.ACTION_SEND) { + if ("text/plain" == intent.type) { + intent.getStringExtra(Intent.EXTRA_TEXT)?.let { + Log.i("Intent Received",it) + sharedViewModel.intentString = it + } + } + } } @@ -85,13 +101,21 @@ class MainActivity : AppCompatActivity() { spotify = api.service sharedViewModel.spotify = api.service //Initiate Processes In Main Fragment - val me = spotify?.me?.display_name - sharedViewModel.userName.value = me - Log.i("Network",me!!) + + sharedViewModel.uiScope.launch { + val me = spotifyExtra?.getMe()?.display_name + sharedViewModel.userName.value = me + Log.i("Network",me!!) + } + + sharedViewModel.userName.observe(this, Observer { + binding.message.text = it + }) } + + AuthenticationResponse.Type.ERROR -> { Log.i("Network",response.error.toString()) - } else -> { } @@ -103,17 +127,33 @@ class MainActivity : AppCompatActivity() { * Adding my own new Spotify Web Api Requests! * */ private fun implementSpotifyExtra() { - val restAdapter = RestAdapter.Builder() - .setEndpoint(SpotifyApi.SPOTIFY_WEB_API_ENDPOINT) - .setRequestInterceptor { request -> - request.addHeader( - "Authorization", - "Bearer $token" - ) + + val httpClient: OkHttpClient.Builder = OkHttpClient.Builder() + + httpClient.addInterceptor(object : Interceptor { + override fun intercept(chain: Interceptor.Chain): Response { + val request: Request = + chain.request().newBuilder().addHeader( + "Authorization", + "Bearer $token" + ).build() + return chain.proceed(request) + } + }) + + val moshi = Moshi.Builder() + .add(KotlinJsonAdapterFactory()) .build() - val spotifyExtra = restAdapter.create(SpotifyNewService::class.java) + val retrofit: Retrofit = + Retrofit.Builder() + .baseUrl("https://api.spotify.com/v1/") + .client(httpClient.build()) + .addConverterFactory(MoshiConverterFactory.create(moshi)) + .build() + + spotifyExtra = retrofit.create(SpotifyNewService::class.java) sharedViewModel.spotifyExtra = spotifyExtra } @@ -129,7 +169,7 @@ class MainActivity : AppCompatActivity() { private fun authenticateSpotify() { val builder = AuthenticationRequest.Builder(CLIENT_ID,AuthenticationResponse.Type.TOKEN,REDIRECT_URI) - .setShowDialog(true) + .setShowDialog(false) .setScopes(arrayOf("user-read-private","streaming","user-read-email","user-modify-playback-state","user-top-read","user-library-modify","user-read-currently-playing","user-library-read","user-read-recently-played")) val request: AuthenticationRequest = builder.build() AuthenticationClient.openLoginActivity(this, LoginActivity.REQUEST_CODE, request) diff --git a/app/src/main/java/com/shabinder/musicForEveryone/SharedViewModel.kt b/app/src/main/java/com/shabinder/musicForEveryone/SharedViewModel.kt index 597cbf5b..a25b9dbb 100644 --- a/app/src/main/java/com/shabinder/musicForEveryone/SharedViewModel.kt +++ b/app/src/main/java/com/shabinder/musicForEveryone/SharedViewModel.kt @@ -9,8 +9,12 @@ import kaaes.spotify.webapi.android.SpotifyService import kaaes.spotify.webapi.android.models.Album import kaaes.spotify.webapi.android.models.Playlist import kaaes.spotify.webapi.android.models.Track +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job class SharedViewModel : ViewModel() { + var intentString = "" var accessToken:String = "" var userName = MutableLiveData().apply { value = "Placeholder" } var spotify :SpotifyService? = null @@ -18,15 +22,23 @@ class SharedViewModel : ViewModel() { var ytDownloader : YoutubeDownloader? = null var downloadManager : DownloadManager? = null + var viewModelJob = Job() - fun getTrackDetails(trackLink:String): Track?{ - return spotify?.getTrack(trackLink) + val uiScope = CoroutineScope(Dispatchers.Main + viewModelJob) + + suspend fun getTrackDetails(trackLink:String): Track?{ + return spotifyExtra?.getTrack(trackLink) } - fun getAlbumDetails(albumLink:String): Album?{ - return spotify?.getAlbum(albumLink) + suspend fun getAlbumDetails(albumLink:String): Album?{ + return spotifyExtra?.getAlbum(albumLink) } - fun getPlaylistDetails(link:String): Playlist?{ + suspend fun getPlaylistDetails(link:String): Playlist?{ return spotifyExtra?.getPlaylist(link) } + + override fun onCleared() { + super.onCleared() + viewModelJob.cancel() + } } \ No newline at end of file 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 f328a9b7..49e7fee6 100644 --- a/app/src/main/java/com/shabinder/musicForEveryone/downloadHelper/DownloadHelper.kt +++ b/app/src/main/java/com/shabinder/musicForEveryone/downloadHelper/DownloadHelper.kt @@ -9,51 +9,62 @@ 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.musicForEveryone.utils.YoutubeInterface +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import java.io.File interface DownloadHelper { - fun downloadTrack(ytDownloader: YoutubeDownloader?, downloadManager: DownloadManager?, searchQuery:String){ - //@data = 1st object from YT query. - val data = YoutubeInterface.search(searchQuery)?.get(0) - if (data==null){Log.i("DownloadHelper","Youtube Request Failed!")}else{ + suspend fun downloadTrack(ytDownloader: YoutubeDownloader?, downloadManager: DownloadManager?, searchQuery:String){ - //Fetching a Video Object. - val video = ytDownloader?.getVideo(data.id) - val details = video?.details() + withContext(Dispatchers.IO){ + val downloadIdList = mutableListOf() + val data = YoutubeInterface.search(searchQuery)?.get(0) + if (data==null){Log.i("DownloadHelper","Youtube Request Failed!")}else{ - val format:Format = video?.findAudioWithQuality(AudioQuality.low)?.get(0) as Format + val video = ytDownloader?.getVideo(data.id) + //Fetching a Video Object. + val details = video?.details() - val audioUrl = format.url() + 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())} + + } - if (audioUrl != null) { - downloadFile(audioUrl,downloadManager,details?.title()?:"Error") - 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 * */ - fun downloadFile(url: String, downloadManager: DownloadManager?,title:String){ - val audioUri = Uri.parse(url) - val outputDir = File.separator + "Spotify-Downloads" +File.separator + "${removeIllegalChars(title)}.mp3" + 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 request = DownloadManager.Request(audioUri) - .setAllowedNetworkTypes( - DownloadManager.Request.NETWORK_WIFI or - DownloadManager.Request.NETWORK_MOBILE - ) - .setAllowedOverRoaming(false) - .setTitle(title) - .setDescription("Spotify Downloader Working Up here...") - .setDestinationInExternalPublicDir(Environment.DIRECTORY_MUSIC,outputDir) - .setNotificationVisibility(VISIBILITY_VISIBLE_NOTIFY_COMPLETED) - downloadManager?.enqueue(request) - Log.i("DownloadManager","Download Request Sent") + val request = DownloadManager.Request(audioUri) + .setAllowedNetworkTypes( + DownloadManager.Request.NETWORK_WIFI or + DownloadManager.Request.NETWORK_MOBILE + ) + .setAllowedOverRoaming(false) + .setTitle(title) + .setDescription("Spotify Downloader Working Up here...") + .setDestinationInExternalPublicDir(Environment.DIRECTORY_MUSIC,outputDir) + .setNotificationVisibility(VISIBILITY_VISIBLE_NOTIFY_COMPLETED) + downloadManager?.enqueue(request) + 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 b63f0721..c31905d3 100644 --- a/app/src/main/java/com/shabinder/musicForEveryone/fragments/MainFragment.kt +++ b/app/src/main/java/com/shabinder/musicForEveryone/fragments/MainFragment.kt @@ -18,6 +18,7 @@ import com.shabinder.musicForEveryone.recyclerView.TrackListAdapter import com.shabinder.musicForEveryone.utils.bindImage import kaaes.spotify.webapi.android.SpotifyService import kaaes.spotify.webapi.android.models.Track +import kotlinx.coroutines.launch class MainFragment : Fragment(),DownloadHelper { @@ -25,6 +26,7 @@ class MainFragment : Fragment(),DownloadHelper { private lateinit var sharedViewModel: SharedViewModel var spotify : SpotifyService? = null var type:String = "" + var spotifyLink = "" override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -33,13 +35,9 @@ class MainFragment : Fragment(),DownloadHelper { sharedViewModel = ViewModelProvider(this.requireActivity()).get(SharedViewModel::class.java) spotify = sharedViewModel.spotify - sharedViewModel.userName.observe(viewLifecycleOwner, Observer { - binding.message.text = it -// if(it!="Placeholder"){Snackbar.make(requireView(),"Hello, $it!", Snackbar.LENGTH_SHORT).show()} - }) binding.btnSearch.setOnClickListener { - val spotifyLink = binding.spotifyLink.text.toString() + spotifyLink = binding.spotifyLink.text.toString() val link = spotifyLink.substringAfterLast('/' , "Error").substringBefore('?') type = spotifyLink.substringBeforeLast('/' , "Error").substringAfterLast('/') @@ -49,60 +47,83 @@ class MainFragment : Fragment(),DownloadHelper { val adapter = TrackListAdapter() binding.trackList.adapter = adapter adapter.sharedViewModel = sharedViewModel - when(type){ "track" -> { - val trackObject = sharedViewModel.getTrackDetails(link) + sharedViewModel.uiScope.launch{ + val trackObject = sharedViewModel.getTrackDetails(link) - val trackList = mutableListOf() - trackList.add(trackObject!!) - adapter.totalItems = 1 - adapter.trackList = trackList - adapter.notifyDataSetChanged() + binding.imageView.visibility =View.VISIBLE - Log.i("Adapter",trackList.size.toString()) + val trackList = mutableListOf() + trackList.add(trackObject!!) + bindImage(binding.imageView, trackObject.album.images[0].url) + adapter.totalItems = 1 + adapter.trackList = trackList + adapter.notifyDataSetChanged() + Log.i("Adapter",trackList.size.toString()) + } } "album" -> { - val albumObject = sharedViewModel.getAlbumDetails(link) + sharedViewModel.uiScope.launch{ - bindImage(binding.imageView,albumObject!!.images[1].url) - binding.titleView.text = albumObject.name - binding.titleView.visibility =View.VISIBLE - binding.imageView.visibility =View.VISIBLE + val albumObject = sharedViewModel.getAlbumDetails(link) - val trackList = mutableListOf() - albumObject.tracks?.items?.forEach { trackList.add(it as Track) } - adapter.totalItems = trackList.size - adapter.trackList = trackList - adapter.notifyDataSetChanged() + binding.titleView.text = albumObject!!.name + binding.titleView.visibility =View.VISIBLE + binding.imageView.visibility =View.VISIBLE + + val trackList = mutableListOf() + albumObject.tracks?.items?.forEach { trackList.add(it as Track) } + adapter.totalItems = trackList.size + adapter.trackList = trackList + adapter.notifyDataSetChanged() + + Log.i("Adapter",trackList.size.toString()) + + bindImage(binding.imageView, albumObject.images[0].url) + } - Log.i("Adapter",trackList.size.toString()) } "playlist" -> { - val playlistObject = sharedViewModel.getPlaylistDetails(link) + sharedViewModel.uiScope.launch{ + val playlistObject = sharedViewModel.getPlaylistDetails(link) - bindImage(binding.imageView,playlistObject!!.images[0].url) - binding.titleView.text = playlistObject.name - binding.titleView.visibility =View.VISIBLE - binding.imageView.visibility =View.VISIBLE + binding.titleView.text = "${if(playlistObject!!.name.length > 18){"${playlistObject.name.subSequence(0,17)}..."}else{playlistObject.name}}" + binding.titleView.visibility =View.VISIBLE + binding.imageView.visibility =View.VISIBLE + binding.playlistOwner.visibility =View.VISIBLE + binding.playlistOwner.text = "by: ${playlistObject.owner.display_name}" + val trackList = mutableListOf() + playlistObject.tracks?.items!!.forEach { trackList.add(it.track) } + adapter.trackList = trackList.toList() + adapter.totalItems = trackList.size + adapter.notifyDataSetChanged() + + Log.i("Adapter",trackList.size.toString()) + + + bindImage(binding.imageView, playlistObject.images[0].url) + + } + + } - val trackList = mutableListOf() - playlistObject.tracks?.items!!.forEach { trackList.add(it.track) } - adapter.trackList = trackList.toList() - adapter.totalItems = trackList.size - adapter.notifyDataSetChanged() - Log.i("Adapter",trackList.size.toString()) - } "episode" -> {showToast("Implementation Pending")} "show" -> {showToast("Implementation Pending ")} } - - binding.spotifyLink.setText(link) } + binding.spotifyLink.setText(sharedViewModel.intentString) + sharedViewModel.userName.observe(viewLifecycleOwner, Observer { + //Waiting for Authentication to Finish with Spotify + if (it != "Placeholder"){ + if(sharedViewModel.intentString != ""){binding.btnSearch.performClick()} + } + }) + return binding.root } diff --git a/app/src/main/java/com/shabinder/musicForEveryone/recyclerView/TrackListAdapter.kt b/app/src/main/java/com/shabinder/musicForEveryone/recyclerView/TrackListAdapter.kt index 7e97cbfe..e89b4f58 100644 --- a/app/src/main/java/com/shabinder/musicForEveryone/recyclerView/TrackListAdapter.kt +++ b/app/src/main/java/com/shabinder/musicForEveryone/recyclerView/TrackListAdapter.kt @@ -3,7 +3,7 @@ package com.shabinder.musicForEveryone.recyclerView import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.Button +import android.widget.ImageButton import android.widget.ImageView import android.widget.TextView import androidx.recyclerview.widget.RecyclerView @@ -12,6 +12,7 @@ import com.shabinder.musicForEveryone.SharedViewModel import com.shabinder.musicForEveryone.downloadHelper.DownloadHelper import com.shabinder.musicForEveryone.utils.bindImage import kaaes.spotify.webapi.android.models.Track +import kotlinx.coroutines.launch class TrackListAdapter:RecyclerView.Adapter(),DownloadHelper { @@ -30,25 +31,25 @@ class TrackListAdapter:RecyclerView.Adapter(),Downl override fun onBindViewHolder(holder: ViewHolder, position: Int) { val item = trackList[position] + if(totalItems == 1){holder.coverImage.visibility = View.GONE}else{ + bindImage(holder.coverImage,item.album.images[0].url) + } - bindImage(holder.coverImage,item.album.images[0].url) - - holder.trackName.text = "${if(item.name.length > 22){"${item.name.subSequence(0,19)}..."}else{item.name}}" + holder.trackName.text = "${if(item.name.length > 17){"${item.name.subSequence(0,16)}..."}else{item.name}}" holder.artistName.text = "${item.artists[0]?.name?:""}..." - holder.popularity.text = item.popularity.toString() - holder.duration.text = "${item.duration_ms/1000/60} minutes, ${(item.duration_ms/1000)%60} seconds" + holder.duration.text = "${item.duration_ms/1000/60} minutes, ${(item.duration_ms/1000)%60} sec" holder.downloadBtn.setOnClickListener{ - downloadTrack(sharedViewModel.ytDownloader,sharedViewModel.downloadManager,"${item.name} ${item.artists[0].name?:""}") + sharedViewModel.uiScope.launch { + downloadTrack(sharedViewModel.ytDownloader,sharedViewModel.downloadManager,"${item.name} ${item.artists[0].name?:""}") + } } } class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){ val trackName:TextView = itemView.findViewById(R.id.track_name) val artistName:TextView = itemView.findViewById(R.id.artist) - val popularity:TextView = itemView.findViewById(R.id.popularity) val duration:TextView = itemView.findViewById(R.id.duration) - val downloadBtn:Button = itemView.findViewById(R.id.btn_download) + val downloadBtn:ImageButton = itemView.findViewById(R.id.btn_download) val coverImage:ImageView = itemView.findViewById(R.id.imageUrl) - - } + } } \ No newline at end of file diff --git a/app/src/main/java/com/shabinder/musicForEveryone/utils/BindingAdapter.kt b/app/src/main/java/com/shabinder/musicForEveryone/utils/BindingAdapter.kt index f17edd91..072b990c 100644 --- a/app/src/main/java/com/shabinder/musicForEveryone/utils/BindingAdapter.kt +++ b/app/src/main/java/com/shabinder/musicForEveryone/utils/BindingAdapter.kt @@ -10,12 +10,14 @@ import com.shabinder.musicForEveryone.R @BindingAdapter("imageUrl") fun bindImage(imgView: ImageView, imgUrl: String?) { - imgUrl?.let { - val imgUri = imgUrl.toUri().buildUpon().scheme("https").build() - Glide.with(imgView.context) - .load(imgUri) - .apply(RequestOptions() - .error(R.drawable.ic_musicplaceholder)) - .into(imgView) - } + + imgUrl?.let { + val imgUri = imgUrl.toUri().buildUpon().scheme("https").build() + Glide.with(imgView.context) + .load(imgUri) + .apply(RequestOptions() + .error(R.drawable.ic_musicplaceholder)) + .into(imgView) + } + } \ No newline at end of file diff --git a/app/src/main/java/com/shabinder/musicForEveryone/utils/SpotifyNewService.kt b/app/src/main/java/com/shabinder/musicForEveryone/utils/SpotifyNewService.kt index 63f76103..05214aee 100644 --- a/app/src/main/java/com/shabinder/musicForEveryone/utils/SpotifyNewService.kt +++ b/app/src/main/java/com/shabinder/musicForEveryone/utils/SpotifyNewService.kt @@ -1,15 +1,36 @@ package com.shabinder.musicForEveryone.utils -import kaaes.spotify.webapi.android.models.Playlist -import retrofit.http.GET -import retrofit.http.Path +import kaaes.spotify.webapi.android.models.* +import retrofit2.http.GET +import retrofit2.http.Path interface SpotifyNewService { - @GET("/playlists/{playlist_id}") - fun getPlaylist(@Path("playlist_id") playlistId: String?): Playlist? + @GET("playlists/{playlist_id}") + suspend fun getPlaylist(@Path("playlist_id") playlistId: String?): Playlist? + + @GET("tracks/{id}") + suspend fun getTrack(@Path("id") var1: String?): Track? + + @GET("albums/{id}") + suspend fun getAlbum(@Path("id") var1: String?): Album? + + @GET("me") + suspend fun getMe(): com.shabinder.musicForEveryone.utils.UserPrivate? +} -} \ No newline at end of file +data class UserPrivate( + val country:String, + var display_name: String, + val email:String, + var external_urls: Map? = null, + var followers: Followers? = null, + var href: String? = null, + var id: String? = null, + var images: List? = null, + var product:String, + var type: String? = null, + var uri: String? = null) \ No newline at end of file diff --git a/app/src/main/res/drawable/text_backdround.xml b/app/src/main/res/drawable/text_background.xml similarity index 100% rename from app/src/main/res/drawable/text_backdround.xml rename to app/src/main/res/drawable/text_background.xml diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index 1bce3398..6e5c311b 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -7,13 +7,32 @@ android:id="@+id/mainActivity" android:layout_width="match_parent" android:layout_height="match_parent"> + diff --git a/app/src/main/res/layout/main_fragment.xml b/app/src/main/res/layout/main_fragment.xml index 4ba11d8b..81cba52f 100644 --- a/app/src/main/res/layout/main_fragment.xml +++ b/app/src/main/res/layout/main_fragment.xml @@ -1,105 +1,128 @@ - + + + + + + + + + + +