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

Jwen/put download back #373

Merged
merged 10 commits into from
Jun 9, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ import androidx.test.espresso.action.ViewActions
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
Expand Down Expand Up @@ -51,12 +48,6 @@ class DownloadManagerActivityTest {
Intents.release()
}

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

@Test
fun seeExistingSongs() {
val context = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.R
import ch.sdp.vibester.activity.BuzzerSetupActivity
import ch.sdp.vibester.activity.ChoosePartyRoomActivity
import ch.sdp.vibester.activity.download.DownloadActivity
import ch.sdp.vibester.activity.game.LyricsBelongGameActivity
import ch.sdp.vibester.activity.game.TypingGameActivity
import ch.sdp.vibester.api.InternetState
Expand Down Expand Up @@ -70,6 +71,13 @@ class GameSetupFragmentTest {
onView(withId(R.id.game_setup_has_internet)).check(matches(withText("Internet is off")))
}

@Test
fun checkDownloadBtnClick() {
onView(withId(R.id.download)).perform(click())

intended(hasComponent(DownloadActivity::class.java.name))
}

@Test
fun returnFromGenreToGame() {
InternetState.forceOnline()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import androidx.test.espresso.action.ViewActions.scrollTo
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.runners.AndroidJUnit4
import ch.sdp.vibester.R
import ch.sdp.vibester.activity.download.DownloadManagerActivity
import ch.sdp.vibester.auth.FireBaseAuthenticator
import ch.sdp.vibester.database.DataGetter
import ch.sdp.vibester.database.ImageGetter
Expand Down Expand Up @@ -297,6 +300,24 @@ class MyProfileFragmentTest {
onView(withId(R.id.username)).check(matches(withText("Lalisa Bon")))
}

@Test
fun checkMyMusicGoToDownloadManager() {
val inputProfile = User( "Lalisa Bon", R.string.test_profile_image.toString(), "[email protected]", 12, 8)
val ctx = ApplicationProvider.getApplicationContext() as Context

createMockDataGetter(inputProfile)
createMockAuthenticator()
createMockImageGetter()

launchFragmentInHiltContainer<MyProfileFragment>(
themeResId = R.style.AppTheme
)

onView(withId(R.id.profile_localSongs)).perform(click())

intended(hasComponent(DownloadManagerActivity::class.java.name))
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ package ch.sdp.vibester.activity.download

import android.os.Bundle
import android.os.Environment
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.children
import androidx.core.widget.NestedScrollView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import ch.sdp.vibester.R
import ch.sdp.vibester.helper.Helper
import ch.sdp.vibester.model.SongListAdapterForDelete
import ch.sdp.vibester.user.OnItemClickListener
import com.google.android.material.floatingactionbutton.FloatingActionButton
import java.io.*

/**
Expand All @@ -30,9 +26,6 @@ class DownloadManagerActivity : AppCompatActivity(), OnItemClickListener {

setContentView(R.layout.activity_download_manager)

val returnBtn = findViewById<FloatingActionButton>(R.id.downloadManager_returnToMain)
Helper().setReturnToMainListener(returnBtn, this)

setUpRecyclerView()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatButton
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.Fragment
import ch.sdp.vibester.R
import ch.sdp.vibester.activity.BuzzerSetupActivity
import ch.sdp.vibester.activity.ChoosePartyRoomActivity
import ch.sdp.vibester.activity.download.DownloadActivity
import ch.sdp.vibester.activity.game.LyricsBelongGameActivity
import ch.sdp.vibester.activity.game.TypingGameActivity
import ch.sdp.vibester.api.InternetState
Expand Down Expand Up @@ -59,7 +61,12 @@ class GameSetupFragment : Fragment(R.layout.fragment_layout_game_setup), Adapter
setGenreListeners()
setGameModeListeners()

vmGameSetup.view.findViewById<Button>(R.id.difficulty_proceed).setOnClickListener{ proceedGame() }
vmGameSetup.view.findViewById<Button>(R.id.difficulty_proceed).setOnClickListener { proceedGame() }
vmGameSetup.view.findViewById<AppCompatButton>(R.id.download).setOnClickListener {
val newIntent = Intent(activity, DownloadActivity::class.java)
startActivity(newIntent)
}

vmGameSetup.view.findViewById<Button>(R.id.game_setup_has_internet).setOnClickListener { updateInternet(vmGameSetup.view.findViewById(R.id.game_setup_has_internet)) }

updateInternet(vmGameSetup.view.findViewById<Button>(R.id.game_setup_has_internet))
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/ch/sdp/vibester/fragment/MyProfileFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import ch.sdp.vibester.R
import ch.sdp.vibester.activity.PublicProfileActivity
import ch.sdp.vibester.activity.download.DownloadManagerActivity
import ch.sdp.vibester.auth.FireBaseAuthenticator
import ch.sdp.vibester.database.DataGetter
import ch.sdp.vibester.database.ImageGetter
Expand Down Expand Up @@ -89,6 +90,7 @@ class MyProfileFragment : Fragment(R.layout.activity_profile), OnItemClickListen
setChangeImageBtnListener()
setLogOutBtnListener()
setShowQrCodeBtnListener()
setLocalMusicBtnListener()
}

private fun setViewsVisibility() {
Expand Down Expand Up @@ -116,6 +118,14 @@ class MyProfileFragment : Fragment(R.layout.activity_profile), OnItemClickListen
}
}

private fun setLocalMusicBtnListener() {
val local = vmMyProfile.view.findViewById<Button>(R.id.profile_localSongs)
local.setOnClickListener {
val newIntent = Intent(activity, DownloadManagerActivity::class.java)
startActivity(newIntent)
}
}

/**
* Generic listener for the change profile picture.
* NOTES: we need to set both for both the cases where the user profile image is displayed or not
Expand Down
15 changes: 0 additions & 15 deletions app/src/main/res/layout/activity_download_manager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,6 @@
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</androidx.core.widget.NestedScrollView>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/downloadManager_returnToMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="40dp"
android:layout_marginBottom="40dp"
android:backgroundTint="@color/light_coral"
android:clickable="true"
android:src="@android:drawable/ic_menu_revert"
app:borderWidth="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<TextView
android:id="@+id/download_empty"
android:layout_width="wrap_content"
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/res/layout/activity_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
android:id="@+id/total_games_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@id/menu_profile_layout"
Expand All @@ -102,6 +101,7 @@
android:id="@+id/profile_total_games"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:background="@drawable/table_shape">

<TableRow
Expand Down Expand Up @@ -129,8 +129,15 @@
android:textColor="#000"
android:textSize="16sp" />
</TableRow>

</TableLayout>

<Button
android:id="@+id/profile_localSongs"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:backgroundTint="@color/cg_blue"
android:layout_marginStart="16dp"
android:text="@string/profile_my_music" />
</LinearLayout>

<LinearLayout
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/layout/fragment_layout_game_setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/squared_button"
android:backgroundTint="@color/cg_blue"
android:elevation="10dp"
android:stateListAnimator="@null"
android:text="Download"
android:textColor="@color/white"
android:translationZ="10dp" />

<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>

<Space
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<string name="profile_following">Following</string>
<string name="test_profile_image">bit.ly/3IUnyAF</string>
<string name="profile_username">Profile Username</string>
<string name="profile_my_music">My Music</string>

<!-- ScoreBoard -->
<string name="scoreboard">S C O R E B O A R D</string>
Expand Down