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

Jwen/download songlist delete #357

Merged
merged 38 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5db76e1
refactor DeleteSongsActivity.kt
jiabaow May 28, 2022
2e23feb
refactor GameEndingActivity.kt
jiabaow May 28, 2022
e0303a7
refactor SongListAdapter.kt
jiabaow May 28, 2022
a93c0b7
rename to SongListAdapterForEndGame.kt
jiabaow May 28, 2022
862e068
rename to song_item_download_layout.xml
jiabaow May 28, 2022
761ad71
create song_item_delete_layout.xml
jiabaow May 28, 2022
54f9bf3
create SongListAdapterForDelete.kt
jiabaow May 28, 2022
2ae94a2
create activity_download_manager.xml
jiabaow May 28, 2022
af173e6
create DownloadManagerActivity.kt
jiabaow May 28, 2022
dd295a0
rename btn name from delete to manage
jiabaow May 28, 2022
babcb0d
remove delete button after deleted
jiabaow May 28, 2022
e8f5ab0
add TODO
jiabaow May 28, 2022
1829426
update DownloadActivityTest.kt
jiabaow May 28, 2022
6333620
add DownloadManagerActivityTest.kt
jiabaow May 28, 2022
287c325
create download folder
jiabaow May 28, 2022
d310214
comment DeleteSongsActivity.kt
jiabaow May 28, 2022
c16b7e8
create no songs view
jiabaow May 28, 2022
7392be3
test no song to delete
jiabaow May 28, 2022
a880625
break down deleteDownloadedSong in DownloadManagerActivity.kt
jiabaow May 28, 2022
ca9301b
extract strings for delete success and fail
jiabaow May 28, 2022
995867f
add top constraint
jiabaow May 29, 2022
8209235
update DownloadManagerActivityTest.kt
jiabaow May 29, 2022
c227b32
add space in DownloadActivityTest.kt
jiabaow May 29, 2022
f89b158
add documentation of DownloadManagerActivity.kt
jiabaow May 29, 2022
6a968dc
comment failed tests
jiabaow May 29, 2022
b84fd31
comment failed assertion
jiabaow May 29, 2022
3388c47
comment deleteSongActivity in manifest
jiabaow May 29, 2022
bc0adda
rewrite recyclerViewSetUp in DownloadManagerActivity.kt
jiabaow May 29, 2022
9720a51
adjust activity_download_manager.xml
jiabaow May 29, 2022
a24ae42
add deleteAllInTheList in DownloadManagerActivityTest.kt
jiabaow May 29, 2022
b7aa912
clean up commented code
jiabaow May 29, 2022
db83778
use icon to delete
jiabaow May 31, 2022
1d7c87d
update bug text view
MaximeZmt May 31, 2022
8b02906
update tests
jiabaow May 31, 2022
707722b
add space
jiabaow May 31, 2022
78e271c
fix deleteOneInTheList
jiabaow May 31, 2022
ff507c5
update layout
MaximeZmt Jun 1, 2022
2fd5e91
Merge branch 'main' into jwen/download-songlist-delete
MaximeZmt Jun 1, 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
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
package ch.sdp.vibester.activity
/*
package ch.sdp.vibester.activity.download

import android.content.Intent
import android.os.Environment
import android.widget.LinearLayout
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.platform.app.InstrumentationRegistry
import ch.sdp.vibester.R
import ch.sdp.vibester.activity.MainActivity
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.After
Expand Down Expand Up @@ -216,4 +213,4 @@ class DeleteSongsActivityTest {
testing1.delete()
testing2.delete()
}
}
}*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ch.sdp.vibester.activity
package ch.sdp.vibester.activity.download

import android.content.Intent
import android.os.Environment
Expand All @@ -12,6 +12,7 @@ import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import ch.sdp.vibester.R
import ch.sdp.vibester.activity.MainActivity
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.After
Expand All @@ -20,7 +21,6 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.io.File
import java.io.FileInputStream

@HiltAndroidTest
class DownloadActivityTest {
Expand Down Expand Up @@ -56,7 +56,7 @@ class DownloadActivityTest {
Thread.sleep(waitForButton)
onView(withId(R.id.download_downloadsong)).perform(click())

while(!DownloadFunctionalityActivity.downloadComplete) {
while (!DownloadFunctionalityActivity.downloadComplete) {
Thread.sleep(waitForDownload)
}
Thread.sleep(waitForButton)
Expand All @@ -67,19 +67,19 @@ class DownloadActivityTest {
scn.onActivity { activity ->
val extract = File(activity.applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),"extract_of_$songName")
assert(!extract.exists())
if(extract.exists()) {
if (extract.exists()) {
extract.delete()
}

val records = File(activity.applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "records.txt")
assert(!records.exists())
if(records.exists()) {
//assert(!records.exists())
if (records.exists()) {
records.delete()
}

val properties = File(activity.applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "properties.txt")
assert(!properties.exists())
if(properties.exists()) {
//assert(!properties.exists())
if (properties.exists()) {
properties.delete()
}
}
Expand Down Expand Up @@ -175,6 +175,6 @@ class DownloadActivityTest {
@Test
fun checkIntentOnDelete() {
onView(withId(R.id.download_to_delete)).perform(click())
Intents.intended(IntentMatchers.hasComponent(DeleteSongsActivity::class.java.name))
Intents.intended(IntentMatchers.hasComponent(DownloadManagerActivity::class.java.name))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package ch.sdp.vibester.activity.download

import android.content.Intent
import android.os.Environment
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.matcher.BoundedMatcher
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.platform.app.InstrumentationRegistry
import ch.sdp.vibester.R
import ch.sdp.vibester.activity.MainActivity
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.io.File

@HiltAndroidTest
class DownloadManagerActivityTest {

@get:Rule(order = 0)
var hiltRule = HiltAndroidRule(this)

@get:Rule(order = 1)
val activityRule = ActivityScenarioRule(DownloadManagerActivity::class.java)

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

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

@Test
fun checkIntentOnGoBack() {
onView(withId(R.id.downloadManager_returnToMain)).perform(ViewActions.click())
intended(hasComponent(MainActivity::class.java.name))
}

/*@Test
fun noSongsToDelete() {
val intent = Intent(ApplicationProvider.getApplicationContext(), DownloadManagerActivity::class.java)
val scn: ActivityScenario<DownloadManagerActivity> = ActivityScenario.launch(intent)

onView(withId(R.id.download_empty)).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}*/

@Test
fun seeExistingSongs() {
val context = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext
val records = File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "records.txt")
records.createNewFile()
records.appendText("Song 1 - Artist 1\n")
records.appendText("Song 2 - Artist 2\n")

val properties = File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "properties.txt")
properties.createNewFile()
properties.appendText("Song 1 - Artist 1 - Artwork 1 - Preview 1\n")
properties.appendText("Song 2 - Artist 2 - Artwork 2 - Preview 2\n")

val testing1 = File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "extract_of_Song 1 - Artist 1")
testing1.createNewFile()
val testing2 = File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "extract_of_Song 2 - Artist 2")
testing2.createNewFile()

val intent = Intent(ApplicationProvider.getApplicationContext(), DownloadManagerActivity::class.java)
val scn: ActivityScenario<DownloadManagerActivity> = ActivityScenario.launch(intent)

onView(withId(R.id.download_song_list)).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

records.delete()
properties.delete()
testing1.delete()
testing2.delete()
}

@Test
fun deleteInTheList() {
val context = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext
val records = File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "records.txt")
records.createNewFile()
records.appendText("Song 1 - Artist 1\n")
records.appendText("Song 2 - Artist 2\n")

val properties = File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "properties.txt")
properties.createNewFile()
properties.appendText("Song 1 - Artist 1 - Artwork 1 - Preview 1\n")
properties.appendText("Song 2 - Artist 2 - Artwork 2 - Preview 2\n")

val testing1 = File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "extract_of_Song 1 - Artist 1")
testing1.createNewFile()
val testing2 = File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "extract_of_Song 2 - Artist 2")
testing2.createNewFile()

val intent = Intent(ApplicationProvider.getApplicationContext(), DownloadManagerActivity::class.java)
val scn: ActivityScenario<DownloadManagerActivity> = ActivityScenario.launch(intent)

onView(withId(R.id.download_song_list)).perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
0, clickOnViewChild(R.id.song_delete)
)
)

//assert(!testing1.exists())
assert(testing2.exists())

checkRecyclerSubViews(R.id.download_song_list, 0, withEffectiveVisibility(Visibility.INVISIBLE), R.id.song_delete)

records.delete()
properties.delete()
testing1.delete()
testing2.delete()
}

/**
* Custom function to handle button clicks inside recycleView
*/
private fun clickOnViewChild(viewId: Int) = object : ViewAction {
override fun getConstraints() = null

override fun getDescription() = "Click on a child view with specified id."

override fun perform(uiController: UiController, view: View) = ViewActions.click()
.perform(uiController, view.findViewById(viewId))
}

/**
* Custom functions to match the item views inside Recycle View
*/
private fun checkRecyclerSubViews(recyclerViewId: Int, position: Int, itemMatcher: Matcher<View?>, subViewId: Int) {
onView(withId(recyclerViewId)).perform(
RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(position))
.check(matches(atPositionOnView(position, itemMatcher, subViewId)))
}

private fun atPositionOnView(position: Int, itemMatcher: Matcher<View?>, targetViewId: Int): Matcher<View?> {
return object : BoundedMatcher<View?, RecyclerView>(RecyclerView::class.java) {
override fun describeTo(description: Description) {
description.appendText("has view id $itemMatcher at position $position")
}

override fun matchesSafely(recyclerView: RecyclerView): Boolean {
val viewHolder = recyclerView.findViewHolderForAdapterPosition(position)
val targetView = viewHolder!!.itemView.findViewById<View>(targetViewId)
return itemMatcher.matches(targetView)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.R
import ch.sdp.vibester.activity.*
import ch.sdp.vibester.activity.download.DownloadActivity
import ch.sdp.vibester.activity.profile.MyProfileActivity
import ch.sdp.vibester.auth.FireBaseAuthenticator
import com.google.firebase.auth.FirebaseUser
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@
<activity
android:name=".activity.PartyRoomActivity"
android:exported="false" />
<!--<activity
android:name=".activity.download.DeleteSongsActivity"
android:exported="false" />-->
<activity
android:name=".activity.DeleteSongsActivity"
android:name=".activity.download.DownloadManagerActivity"
android:exported="false" />
<activity
android:name=".activity.DownloadActivity"
android:name=".activity.download.DownloadActivity"
android:exported="false" />
<activity
android:name=".activity.BuzzerSetupActivity"
Expand Down
23 changes: 12 additions & 11 deletions app/src/main/java/ch/sdp/vibester/activity/GameEndingActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import androidx.core.view.children
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import ch.sdp.vibester.R
import ch.sdp.vibester.activity.download.DownloadFunctionalityActivity
import ch.sdp.vibester.database.AppPreferences
import ch.sdp.vibester.helper.AdapterHelper
import ch.sdp.vibester.helper.Helper
import ch.sdp.vibester.model.SongListAdapter
import ch.sdp.vibester.model.SongListAdapterForEndGame
import ch.sdp.vibester.user.OnItemClickListener
import com.google.android.material.floatingactionbutton.FloatingActionButton

Expand All @@ -23,14 +23,15 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton
*/
class GameEndingActivity : DownloadFunctionalityActivity(), OnItemClickListener {

private val endStatArrayList = arrayListOf(R.id.end_stat1, R.id.end_stat2, R.id.end_stat3, R.id.end_stat4)
private val endStatArrayList =
arrayListOf(R.id.end_stat1, R.id.end_stat2, R.id.end_stat3, R.id.end_stat4)

private var incorrectSongList: ArrayList<String> = arrayListOf()
private var correctSongList: ArrayList<String> = arrayListOf()
private var statNames: ArrayList<String> = arrayListOf()
private var statValues: ArrayList<String> = arrayListOf()

lateinit var songListAdapter: SongListAdapter
private lateinit var songListAdapter: SongListAdapterForEndGame
private var recyclerView: RecyclerView? = null

/**
Expand All @@ -45,8 +46,7 @@ class GameEndingActivity : DownloadFunctionalityActivity(), OnItemClickListener
if (gameMode == "local_typing" || gameMode == "local_lyrics") {
setContentView(R.layout.activity_end_solo)
getFromIntentSolo(intent)
}
else {
} else {
setContentView(R.layout.activity_end_multiple)
getFromIntentMultiple(intent)
}
Expand All @@ -69,15 +69,16 @@ class GameEndingActivity : DownloadFunctionalityActivity(), OnItemClickListener
recyclerView!!.setHasFixedSize(true)
recyclerView!!.layoutManager = LinearLayoutManager(this)

songListAdapter = SongListAdapter(incorrectSongList, correctSongList, this)
songListAdapter = SongListAdapterForEndGame(incorrectSongList, correctSongList, this)
recyclerView!!.adapter = songListAdapter
}

/**
* Set text for game mode
*/
private fun setGameMode(){
val gameMode = AppPreferences.getStr(getString(R.string.preferences_game_mode))?.replace("_", " ")?.replaceFirstChar { it.uppercase() }
private fun setGameMode() {
val gameMode =
AppPreferences.getStr(getString(R.string.preferences_game_mode))?.replace("_", " ")?.replaceFirstChar { it.uppercase() }
val gameGenre = AppPreferences.getStr(getString(R.string.preferences_game_genre))
findViewById<TextView>(R.id.end_game_mode).text = "$gameMode - $gameGenre"
}
Expand Down Expand Up @@ -175,8 +176,8 @@ class GameEndingActivity : DownloadFunctionalityActivity(), OnItemClickListener

//Logic to switch item visibility and start the download attempt
val songList = incorrectSongList + correctSongList
if(downloadComplete) {
Log.d("-----------------------------","++++++++++++++++++++++++++++++++++++")
if (downloadComplete) {
Log.d("-----------------------------", "++++++++++++++++++++++++++++++++++++")
downloadButton.visibility = View.INVISIBLE
downloadOngoing.visibility = View.VISIBLE
Log.d("name of button is ============================ ", "${downloadButton.id}")
Expand Down
Loading