This repository has been archived by the owner on Jan 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Jwen/show lyric #84
Merged
Merged
Jwen/show lyric #84
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0f2e9ac
stuck using musixmatch api
jiabaow a5838d7
show lyric using Lyrics.ovh
jiabaow ba0edb0
refactor LyricsOVHApiInterface.kt and add tests
jiabaow f7f508e
refactor MainActivity.kt
jiabaow d0d1fd3
delete scoreboard on MainActivity.kt
jiabaow 3d4287a
remove profile in MainActivity.kt and test LyricButton
jiabaow 4f31ce1
adjust api waiting time
jiabaow 0a6b8b5
merge main into
jiabaow f891b05
adjust waiting time
jiabaow 8293b6c
clean up
jiabaow 1c0aca4
add documentation
jiabaow c399a02
adjust waiting time
jiabaow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
app/src/androidTest/java/ch/sdp/vibester/LyricTemporaryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package ch.sdp.vibester | ||
|
||
import android.content.Intent | ||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions.* | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.espresso.matcher.ViewMatchers.withText | ||
import ch.sdp.vibester.api.LyricsOVHApiInterface | ||
import org.hamcrest.CoreMatchers.containsString | ||
import org.hamcrest.CoreMatchers.equalTo | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.junit.Test | ||
|
||
class LyricTemporaryTest { | ||
@Test | ||
fun canGetLyricsFromAPI() { | ||
val service = LyricsOVHApiInterface.create("https://api.lyrics.ovh/") | ||
val lyric = service.getLyrics("Imagine Dragons", "Believer").execute() | ||
assertThat(lyric.body().lyrics, equalTo("First things first\r\n" + | ||
"I'm say all the words inside my head\r\n" + | ||
"I'm fired up and tired of the way that things have been, oh-ooh\r\n" + | ||
"The way that things have been, oh-ooh\r\nSecond thing second\r\n" + | ||
"Don't you tell me what you think that I can be\n\n" + | ||
"I'm the one at the sail, I'm the master of my sea, oh-ooh\n\n" + | ||
"The master of my sea, oh-ooh\n\n\n\nI was broken from a young age\n\n" + | ||
"Taking my sulkin to the masses\n\nWrite down my poems for the few\n\n" + | ||
"That looked at me took to me, shook to me, feeling me\n\n" + | ||
"Singing from heart ache from the pain\n\nTake up my message from the veins\n\n" + | ||
"Speaking my lesson from the brain\n\nSeeing the beauty through the...\n\n\n\n" + | ||
"Pain!\n\nYou made me a, you made me a believer, believer\n\nPain!" + | ||
"\n\nYou break me down, you build me up, believer, believer\n\nPain!\n\n" + | ||
"I let the bullets fly, oh let them rain\n\nMy life, my love, my drive, it came from...\n\n" + | ||
"Pain!\n\nYou made me a, you made me a believer, believer\n\n\n\n" + | ||
"Third things third\n\nSend a prayer to the ones up above\n\n" + | ||
"All the hate that you've heard has turned your spirit to a dove, oh-ooh\n\n" + | ||
"Your spirit up above, oh-ooh\n\n\n\nI was choking in the crowd\n\nLiving my brain up in the cloud\n\n" + | ||
"Falling like ashes to the ground\n\nHoping my feelings, they would drown\n\n" + | ||
"But they never did, ever lived, ebbing and flowing\n\nInhibited, limited\n\n" + | ||
"Till it broke up and it rained down\n\nIt rained down, like...\n\n\n\nPain!\n\n" + | ||
"You made me a, you made me a believer, believer\n\nPain!\n\n" + | ||
"You break me down, you build me up, believer, believer\n\nPain!\n\n" + | ||
"I let the bullets fly, oh let them rain\n\nMy life, my love, my drive, they came from...\n\n" + | ||
"Pain!\n\nYou made me a, you made me a believer, believer\n\n\n\nLast things last\n\n" + | ||
"By the grace of the fire and the flames\n\nYou're the face of the future, you're the blood in my veins, oh-ooh\n\n" + | ||
"The blood in my veins, oh-ooh\n\nBut they never did, ever lived, ebbing and flowing\n\nInhibited, limited\n\n" + | ||
"Till it broke up and it rained down\n\nIt rained down, like...\n\n\n\nPain!" + | ||
"\n\nYou made me a, you made me a believer, believer\n\nPain!\n\n" + | ||
"You break me down, you build me up, believer, believer\n\nPain!\n\n" + | ||
"I let the bullets fly, oh let them rain\n\nMy life, my love, my drive, they came from...\n\n" + | ||
"Pain!\n\nYou made me a, you made me a believer, believer")) | ||
} | ||
|
||
@Test | ||
fun lyricTemporaryTest() { | ||
val inputArtistName = "Imagine Dragons" | ||
val inputTrackName = "Believer" | ||
val intent = Intent( | ||
ApplicationProvider.getApplicationContext(), LyricTemporary::class.java | ||
) | ||
val scn: ActivityScenario<GreetingActivity> = ActivityScenario.launch(intent) | ||
onView(withId(R.id.artistForLyric)).perform(typeText(inputArtistName), closeSoftKeyboard()) | ||
onView(withId(R.id.trackForLyric)).perform(typeText(inputTrackName), closeSoftKeyboard()) | ||
onView(withId(R.id.validateForLyric)).perform(click()) | ||
Thread.sleep(1500) // wait for API response | ||
onView(withId(R.id.lyricBody)).check(matches(withText(containsString("First things first")))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,56 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="ch.sdp.vibester"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> | ||
|
||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.MyApplication"> | ||
<activity | ||
android:name="ch.sdp.vibester.GamescreenActivity" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".profile.ProfileSetup" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".MusicTemporary" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".GameSetupScreen" | ||
android:exported="false" /> | ||
<activity android:name=".scoreboard.ScoreBoardActivity" | ||
android:theme="@style/AppTheme.NoActionBar" /> | ||
<activity | ||
android:name=".WelcomeScreen" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".Register" | ||
android:exported="true" /> | ||
<activity | ||
android:name=".GreetingActivity" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="ch.sdp.vibester"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> | ||
|
||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:usesCleartextTraffic="true" | ||
android:theme="@style/Theme.MyApplication"> | ||
<activity | ||
android:name="ch.sdp.vibester.GamescreenActivity" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".profile.ProfileSetup" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".MusicTemporary" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".LyricTemporary" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".GameSetupScreen" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".scoreboard.ScoreBoardActivity" | ||
android:theme="@style/AppTheme.NoActionBar" /> | ||
<activity | ||
android:name=".WelcomeScreen" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".Register" | ||
android:exported="true" /> | ||
<activity | ||
android:name=".GreetingActivity" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package ch.sdp.vibester | ||
|
||
import android.os.Bundle | ||
import android.text.method.ScrollingMovementMethod | ||
import android.widget.Button | ||
import android.widget.EditText | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AppCompatActivity | ||
import ch.sdp.vibester.api.LyricsOVHApiInterface | ||
import ch.sdp.vibester.model.Lyric | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
|
||
|
||
class LyricTemporary: AppCompatActivity() { | ||
private val baseUrl = "https://api.lyrics.ovh/" | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_lyric_temporary) | ||
|
||
val artistName = findViewById<EditText>(R.id.artistForLyric) | ||
|
||
val trackName = findViewById<EditText>(R.id.trackForLyric) | ||
|
||
val btnValidate = findViewById<Button>(R.id.validateForLyric) | ||
|
||
val textViewLyric = findViewById<TextView>(R.id.lyricBody) | ||
textViewLyric.movementMethod = ScrollingMovementMethod() | ||
|
||
btnValidate.setOnClickListener { | ||
val service = LyricsOVHApiInterface.create(baseUrl) | ||
|
||
val call = service.getLyrics(artistName.text.toString(), trackName.text.toString()) | ||
call.enqueue(object: Callback<Lyric>{ | ||
override fun onFailure(call: Call<Lyric>?, t: Throwable?) {} | ||
|
||
override fun onResponse(call: Call<Lyric>?, response: Response<Lyric>?) { | ||
if (response != null) { | ||
textViewLyric.text = response.body().lyrics | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/ch/sdp/vibester/api/LyricsOVHApiInterface.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package ch.sdp.vibester.api | ||
|
||
import ch.sdp.vibester.model.Lyric | ||
import retrofit2.Call | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import retrofit2.http.GET | ||
import retrofit2.http.Path | ||
|
||
interface LyricsOVHApiInterface { | ||
jiabaow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* Given the name of the artist and the title of the track | ||
* return a Call<Lyric> contains the lyric of the track | ||
*/ | ||
@GET("v1/{artist}/{title}") | ||
fun getLyrics(@Path("artist") artist: String, @Path("title") title: String): Call<Lyric> | ||
|
||
companion object { | ||
/** | ||
* @param baseUrl base url of the api | ||
* return an instance of the api interface | ||
*/ | ||
fun create(baseUrl:String): LyricsOVHApiInterface { | ||
val retrofit = Retrofit.Builder() | ||
.baseUrl(baseUrl) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
return retrofit.create(LyricsOVHApiInterface::class.java) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ch.sdp.vibester.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
|
||
class Lyric { | ||
@SerializedName("lyrics") | ||
var lyrics: String? = null | ||
|
||
//not used | ||
//@SerializedName("error") | ||
//var error: String? = null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think the logic of fetching data should be left in activity or moved somewhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that way will be more consistent with the existing code we have, but from all the examples I have seen using retrofit they all put it like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also fetching data. I did not use retrofit, I used okhttp3 and android.net.uri to build uri. I followed Maxime's logic in ItunesMusicApi.kt. He has created a class for fetching data with callbacks in it. So, when there was a click on the button, he just called this class to fetch data. I am not saying it is correct, but I liked that there is some separation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can keep the way you did!