Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Kamila/lastfm_genre_api #86

Merged
merged 63 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
2a0bd81
LastfmApi.kt: functions to retrieve songs by tag and by chart
kamilababayeva Mar 15, 2022
e6389a6
GenreTemporary.kt: basic activity with three button for genre
kamilababayeva Mar 15, 2022
1647f5f
MainActivity.kt: make profile button for genre activity
kamilababayeva Mar 15, 2022
61f3f24
SongsList.kt: retrieve songs by tag/chart from json
kamilababayeva Mar 15, 2022
202d502
activity_genre_temporary: simple activity with button for genre
kamilababayeva Mar 15, 2022
83a8c67
lastfmApiTest.kt: two test for errors
kamilababayeva Mar 15, 2022
2269c05
AndroidManifest.xml: add genretemporary activity to xml
kamilababayeva Mar 15, 2022
8e0c735
SongsListTest.kt: fix the argument
kamilababayeva Mar 15, 2022
b6828bd
SongsListTest.kt: add test to check songslist
kamilababayeva Mar 15, 2022
f3ec60d
SongsListTest.kt: fix the error
kamilababayeva Mar 15, 2022
61f5df8
mainactivity: fix the test for genres
kamilababayeva Mar 15, 2022
11db875
GenreTemporaryTest: check the layout
kamilababayeva Mar 15, 2022
70b8d9f
Update GenreTemporaryTest.kt
kamilababayeva Mar 15, 2022
ea440c8
fix naming
kamilababayeva Mar 15, 2022
6a0d0fc
GenderTemporaryTest.kt: working on the test
kamilababayeva Mar 15, 2022
f7c5f6c
move ApiCallback for lastm and Itunes to separate class
kamilababayeva Mar 15, 2022
3719192
LastfmApi.kt: remove repetition
kamilababayeva Mar 15, 2022
0242592
small fixes
kamilababayeva Mar 15, 2022
a0eb548
fix the parameters inside querySongsList
kamilababayeva Mar 15, 2022
637a9fc
LastfmApiTest.kt: add the test
kamilababayeva Mar 15, 2022
5a5d6d8
GenreTemporaryTest.kt: remove unnecassary check
kamilababayeva Mar 15, 2022
3d88f27
Merge branch 'main' into kamila/genres_api
kamilababayeva Mar 15, 2022
6db9e73
testing purposes
kamilababayeva Mar 15, 2022
d82cec7
lastfmapi: small change
kamilababayeva Mar 15, 2022
deff6d9
LastfmApiTest.kt: fix the naming
kamilababayeva Mar 15, 2022
88f4eaf
SongsList.kt: modifying function for testing
kamilababayeva Mar 15, 2022
584da36
try testing function
kamilababayeva Mar 15, 2022
4712e0b
SongList: remove the changed back
kamilababayeva Mar 16, 2022
6371706
Refactor: rename the variables and functions
kamilababayeva Mar 16, 2022
b532220
GenreTemporary: add onclick buttons
kamilababayeva Mar 16, 2022
601b905
LastfmHelper.kt: function two randomize songs
kamilababayeva Mar 16, 2022
23b0f03
SongList.kt: refactoring
kamilababayeva Mar 16, 2022
02a8ca3
GenreTemporary.kt: add function to set listview
kamilababayeva Mar 16, 2022
e8f7ad4
LastfmHelper: fix the lastfm bug, add tests
kamilababayeva Mar 16, 2022
dbdb810
move lastfmapitest to correct directory
kamilababayeva Mar 16, 2022
bcbd503
GenreTemporary: remove the test
kamilababayeva Mar 16, 2022
9a729c2
remove unnecassary imports
kamilababayeva Mar 16, 2022
6c6fe19
stuck using musixmatch api
jiabaow Mar 13, 2022
2741853
show lyric using Lyrics.ovh
jiabaow Mar 13, 2022
f8505a2
refactor LyricsOVHApiInterface.kt and add tests
jiabaow Mar 15, 2022
346a2e7
refactor MainActivity.kt
jiabaow Mar 15, 2022
3fab81d
delete scoreboard on MainActivity.kt
jiabaow Mar 15, 2022
67479d9
remove profile in MainActivity.kt and test LyricButton
jiabaow Mar 15, 2022
7b84f21
adjust api waiting time
jiabaow Mar 15, 2022
fc79268
adjust waiting time
jiabaow Mar 15, 2022
00067e7
clean up
jiabaow Mar 15, 2022
264ce18
add documentation
jiabaow Mar 15, 2022
1a372bc
adjust waiting time
jiabaow Mar 16, 2022
f518338
AndroidManifest.xml: add genretemporary activity to xml
kamilababayeva Mar 15, 2022
2151998
Main: add button for Genre, add test for Genre
kamilababayeva Mar 16, 2022
61e9072
Merge branch 'main' into kamila/genres_api
kamilababayeva Mar 16, 2022
11f75e2
fix the function name
kamilababayeva Mar 16, 2022
cd5b69f
LastfmHelper.kt: combine two lists before random pick
kamilababayeva Mar 16, 2022
414997d
add documentation
kamilababayeva Mar 16, 2022
4c6ecc8
Merge branch 'main' into kamila/genres_api
kamilababayeva Mar 17, 2022
854c5c8
Add documentation
kamilababayeva Mar 17, 2022
e24d1fc
Fix the elements namins, add few tests
kamilababayeva Mar 17, 2022
c0dc275
Merge branch 'main' into kamila/genres_api
kamilababayeva Mar 17, 2022
48c7f02
LyricTemporaryTest.kt: increase waiting time
kamilababayeva Mar 17, 2022
3b7ce4c
trying to add some extrac hecks
kamilababayeva Mar 17, 2022
0138cfd
refactor + remove checks
kamilababayeva Mar 17, 2022
5ffc2f6
fix wrong merge
kamilababayeva Mar 17, 2022
dcb4e45
Merge branch 'main' into kamila/genres_api
kamilababayeva Mar 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions app/src/androidTest/java/ch/sdp/vibester/GenreTemporaryTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package ch.sdp.vibester

import androidx.test.espresso.Espresso.onData
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.PerformException
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.*
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import org.hamcrest.Matchers.*
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException


class GenreTemporaryTest {

@get:Rule
val testRule = ActivityScenarioRule(
GenreTemporary::class.java
)

@Before
fun setUp() {
Intents.init()
}

@After
fun clean() {
Intents.release()
}

@Test
fun GenreLayoutIsDisplayed() {
onView(withId(R.id.rockButton)).check(matches(isDisplayed()))
onView(withId(R.id.kpopButton)).check(matches(isDisplayed()))
onView(withId(R.id.topTracksButton)).check(matches(isDisplayed()))
onView(withId(R.id.songsListView)).check(matches(isDisplayed()))
}

@get:Rule
var exception = ExpectedException.none()

@Test
fun songListIsEmpty(){
exception.expect(PerformException::class.java)
onView(withId(R.id.songsListView)).check(matches(isDisplayed()))
onData(allOf(`is`(instanceOf(String::class.java)))).atPosition(2).perform(click())
}

@Test
fun rockButtonClick() {
onView(withId(R.id.rockButton)).perform(click())
onView(withId(R.id.songsListView)).check(matches(isDisplayed()))
Thread.sleep(1000) // wait for data to fetch
onData(allOf(`is`(instanceOf(String::class.java)))).atPosition(2).perform(click())
}
@Test
fun topButtonClick() {
onView(withId(R.id.topTracksButton)).perform(click())
onView(withId(R.id.songsListView)).check(matches(isDisplayed()))
Thread.sleep(1000) // wait for data to fetch
onData(allOf(`is`(instanceOf(String::class.java)))).atPosition(2).perform(click())
}

@Test
fun kpopButtonClick() {
onView(withId(R.id.kpopButton)).perform(click())
onView(withId(R.id.songsListView)).check(matches(isDisplayed()))
Thread.sleep(1000) // wait for data to fetch
onData(allOf(`is`(instanceOf(String::class.java)))).atPosition(2).perform(click())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class LyricTemporaryTest {
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
Thread.sleep(5000) // wait for API response
onView(withId(R.id.lyricBody)).check(matches(withText(containsString("First things first"))))
}
}
7 changes: 7 additions & 0 deletions app/src/androidTest/java/ch/sdp/vibester/MainActivityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class MainActivityTest {
intended(hasComponent(WelcomeScreen::class.qualifiedName))
}

@Test
fun checkIntentOnGenre(){
onView(withId(R.id.genreButton)).perform(click())
intended(hasComponent(GenreTemporary::class.qualifiedName))
}


@Test
fun checkIntentOnLyric() {
onView(withId(R.id.lyricButton)).perform(click())
Expand Down
35 changes: 35 additions & 0 deletions app/src/androidTest/java/ch/sdp/vibester/api/LastfmApiTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ch.sdp.vibester.api

import ch.sdp.vibester.model.SongList
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertTrue
import okhttp3.OkHttpClient
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException

import java.lang.Exception

class LastfmApiTest {
private val BY_TAG = "tag.gettoptracks"

@Test
fun lastfmApiQueryWorks() {
var songListFut = LastfmApi.querySongList(OkHttpClient(), LastfmUri(method = BY_TAG, tag="rock"))
val songListObj = SongList(songListFut.get())
assertTrue(songListObj.getSongList().size > 0)
assertTrue(songListObj.getSongList().size == songListObj.getSongsPerPage().toInt())
assertEquals(songListObj.getPage(),"1")
}

@get:Rule
var exception = ExpectedException.none()

@Test
fun lastfmApiQueryError() {
exception.expect(Exception::class.java)
var songsFut = LastfmApi.querySongList(OkHttpClient(), LastfmUri(method = BY_TAG, tag="rock"), baseUrl="ThisSiteDoesNotExist" )
songsFut.get()
}

}
24 changes: 24 additions & 0 deletions app/src/androidTest/java/ch/sdp/vibester/api/LastfmHelperTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ch.sdp.vibester.api

import junit.framework.Assert.assertTrue
import org.junit.Test

class LastfmHelperTest {
private val BY_TAG = "tag.gettoptracks"
private val BY_CHART = "chart.gettoptracks"
private val GAME_SIZE = 10

@Test
fun mergeWorks(){
val listOne = listOf<String>("One","Two")
val listTwo = listOf<String>("Three", "Four")
val finalList = listOf<String>("One","Two","Three","Four")
val test = LastfmHelper.merge(listOne, listTwo)
assertTrue(test.size == finalList.size && test.containsAll(finalList) && finalList.containsAll(test));
}

@Test
fun getRandomSongListWorks(){
assertTrue(LastfmHelper.getRandomSongList(method = BY_TAG, tag = "kpop").size == GAME_SIZE)
}
}
53 changes: 53 additions & 0 deletions app/src/androidTest/java/ch/sdp/vibester/model/SongListTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ch.sdp.vibester.model

import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException

class SongListTest {

@Test
fun jsonPreviewParseCorrectText(){
val inputTxt = """
{"tracks":
{"track":[{"name":"Wonderwall","duration":"259","mbid":"31623cce-9717-4513-9d83-1b5d04e44f9b",
"url":"https://www.last.fm/music/Oasis/_/Wonderwall",
"streamable":{"#text":"0","fulltrack":"0"},
"artist":{"name":"Oasis","mbid":"ecf9f3a3-35e9-4c58-acaa-e707fba45060","url":"https://www.last.fm/music/Oasis"},
"image":[{"#text":"https://lastfm.freetls.fastly.net/i/u/34s/2a96cbd8b46e442fc41c2b86b821562f.png","size":"small"},
{"#text":"https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png","size":"medium"},
{"#text":"https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png","size":"large"},
{"#text":"https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png","size":"extralarge"}],
"@attr":{"rank":"1"}}],"@attr":{"tag":"british","page":"1","perPage":"1","totalPages":"66649","total":"66649"}}}
"""

val mySongsList = SongList(inputTxt)

val songName = "Wonderwall"
val artistName = "Oasis"
val inputSongsList = mutableListOf<String>("$songName $artistName")
val page = "1"
val songsPerPage = "1"
val totalPages = "66649"
val totalSongs = "66649"


assertEquals(inputSongsList, mySongsList.getSongList())
assertEquals(page, mySongsList.getPage())
assertEquals(songsPerPage, mySongsList.getSongsPerPage())
assertEquals(totalPages, mySongsList.getTotalPages())
assertEquals(totalSongs, mySongsList.getTotalSongs())
}

@get:Rule
var exception = ExpectedException.none()

@Test
fun jsonPreviewParseErrorText() {
exception.expect(IllegalArgumentException::class.java)
exception.expectMessage("SongsList constructor, bad argument")
SongList("")
}

}
127 changes: 65 additions & 62 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,63 +1,66 @@
<?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=".IncorrectSongsScreen"
android:exported="false" />
<activity
android:name=".GameEndingScreen"
android:exported="false" />
<activity
android:name=".games.TypingGame"
android:exported="false" />
<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>
<?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=".IncorrectSongsScreen"
android:exported="false" />
<activity
android:name=".GameEndingScreen"
android:exported="false" />
<activity
android:name=".games.TypingGame"
android:exported="false" />
<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=".GenreTemporary"
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>
46 changes: 46 additions & 0 deletions app/src/main/java/ch/sdp/vibester/GenreTemporary.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ch.sdp.vibester

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.ArrayAdapter
import android.widget.ListView
import ch.sdp.vibester.api.LastfmHelper

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some javadoc to describe the class would be great. Maybe the method too.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it's temporary so not mandatory

/**
* Activity to show the list of songs for a chosen tag
*/
class GenreTemporary : AppCompatActivity() {
private val BY_TAG = "tag.gettoptracks"
private val BY_CHART = "chart.gettoptracks"

override fun onCreate(savedInstanceState: Bundle?) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

super.onCreate(savedInstanceState)
setContentView(R.layout.activity_genre_temporary)
}

/**
* Fetch data from Lastfm and show song list in a ListView
* @param method: BY_TAG or BY_CHART (top tracks without tag)
* @param tag: tag name if method BY_TAG is chosen
*/
fun performQuery(method: String, tag: String=""){
val listSongs = findViewById<ListView>(R.id.songsListView)
val songList = LastfmHelper.getRandomSongList(method, tag)
val arr = ArrayAdapter(this, android.R.layout.simple_list_item_1 , songList)
listSongs.adapter = arr
}

fun getKpopSongList(view: View) {
performQuery(BY_TAG,"kpop")
}

fun getRockSongList(view: View) {
performQuery(BY_TAG, "rock")
}

fun getTopSongList(view: View) {
performQuery(BY_CHART)
}

}
Loading