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
Kamila/lastfm_genre_api #86
Merged
Merged
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 e6389a6
GenreTemporary.kt: basic activity with three button for genre
kamilababayeva 1647f5f
MainActivity.kt: make profile button for genre activity
kamilababayeva 61f3f24
SongsList.kt: retrieve songs by tag/chart from json
kamilababayeva 202d502
activity_genre_temporary: simple activity with button for genre
kamilababayeva 83a8c67
lastfmApiTest.kt: two test for errors
kamilababayeva 2269c05
AndroidManifest.xml: add genretemporary activity to xml
kamilababayeva 8e0c735
SongsListTest.kt: fix the argument
kamilababayeva b6828bd
SongsListTest.kt: add test to check songslist
kamilababayeva f3ec60d
SongsListTest.kt: fix the error
kamilababayeva 61f5df8
mainactivity: fix the test for genres
kamilababayeva 11db875
GenreTemporaryTest: check the layout
kamilababayeva 70b8d9f
Update GenreTemporaryTest.kt
kamilababayeva ea440c8
fix naming
kamilababayeva 6a0d0fc
GenderTemporaryTest.kt: working on the test
kamilababayeva f7c5f6c
move ApiCallback for lastm and Itunes to separate class
kamilababayeva 3719192
LastfmApi.kt: remove repetition
kamilababayeva 0242592
small fixes
kamilababayeva a0eb548
fix the parameters inside querySongsList
kamilababayeva 637a9fc
LastfmApiTest.kt: add the test
kamilababayeva 5a5d6d8
GenreTemporaryTest.kt: remove unnecassary check
kamilababayeva 3d88f27
Merge branch 'main' into kamila/genres_api
kamilababayeva 6db9e73
testing purposes
kamilababayeva d82cec7
lastfmapi: small change
kamilababayeva deff6d9
LastfmApiTest.kt: fix the naming
kamilababayeva 88f4eaf
SongsList.kt: modifying function for testing
kamilababayeva 584da36
try testing function
kamilababayeva 4712e0b
SongList: remove the changed back
kamilababayeva 6371706
Refactor: rename the variables and functions
kamilababayeva b532220
GenreTemporary: add onclick buttons
kamilababayeva 601b905
LastfmHelper.kt: function two randomize songs
kamilababayeva 23b0f03
SongList.kt: refactoring
kamilababayeva 02a8ca3
GenreTemporary.kt: add function to set listview
kamilababayeva e8f7ad4
LastfmHelper: fix the lastfm bug, add tests
kamilababayeva dbdb810
move lastfmapitest to correct directory
kamilababayeva bcbd503
GenreTemporary: remove the test
kamilababayeva 9a729c2
remove unnecassary imports
kamilababayeva 6c6fe19
stuck using musixmatch api
jiabaow 2741853
show lyric using Lyrics.ovh
jiabaow f8505a2
refactor LyricsOVHApiInterface.kt and add tests
jiabaow 346a2e7
refactor MainActivity.kt
jiabaow 3fab81d
delete scoreboard on MainActivity.kt
jiabaow 67479d9
remove profile in MainActivity.kt and test LyricButton
jiabaow 7b84f21
adjust api waiting time
jiabaow fc79268
adjust waiting time
jiabaow 00067e7
clean up
jiabaow 264ce18
add documentation
jiabaow 1a372bc
adjust waiting time
jiabaow f518338
AndroidManifest.xml: add genretemporary activity to xml
kamilababayeva 2151998
Main: add button for Genre, add test for Genre
kamilababayeva 61e9072
Merge branch 'main' into kamila/genres_api
kamilababayeva 11f75e2
fix the function name
kamilababayeva cd5b69f
LastfmHelper.kt: combine two lists before random pick
kamilababayeva 414997d
add documentation
kamilababayeva 4c6ecc8
Merge branch 'main' into kamila/genres_api
kamilababayeva 854c5c8
Add documentation
kamilababayeva e24d1fc
Fix the elements namins, add few tests
kamilababayeva c0dc275
Merge branch 'main' into kamila/genres_api
kamilababayeva 48c7f02
LyricTemporaryTest.kt: increase waiting time
kamilababayeva 3b7ce4c
trying to add some extrac hecks
kamilababayeva 0138cfd
refactor + remove checks
kamilababayeva 5ffc2f6
fix wrong merge
kamilababayeva dcb4e45
Merge branch 'main' into kamila/genres_api
kamilababayeva 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
76 changes: 76 additions & 0 deletions
76
app/src/androidTest/java/ch/sdp/vibester/GenreTemporaryTest.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,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()) | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
app/src/androidTest/java/ch/sdp/vibester/api/LastfmApiTest.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,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
24
app/src/androidTest/java/ch/sdp/vibester/api/LastfmHelperTest.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,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
53
app/src/androidTest/java/ch/sdp/vibester/model/SongListTest.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,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("") | ||
} | ||
|
||
} |
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,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> |
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,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 | ||
|
||
/** | ||
* 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?) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} | ||
|
||
} |
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.
Some javadoc to describe the class would be great. Maybe the method too.
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.
Then it's temporary so not mandatory