diff --git a/app/src/androidTest/java/com/github/orkest/ShareSongTest.kt b/app/src/androidTest/java/com/github/orkest/ShareSongTest.kt index 77af3f32..4f2a5d9c 100644 --- a/app/src/androidTest/java/com/github/orkest/ShareSongTest.kt +++ b/app/src/androidTest/java/com/github/orkest/ShareSongTest.kt @@ -4,11 +4,27 @@ import com.github.orkest.domain.Authorization import org.junit.Test import android.content.Intent import android.util.Log +import androidx.compose.foundation.layout.Column +import androidx.compose.material.Button +import androidx.compose.material.Text +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.junit4.createAndroidComposeRule +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onNodeWithText +import androidx.core.content.ContextCompat.startActivity import androidx.lifecycle.Lifecycle +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.intent.Intents import androidx.test.espresso.intent.matcher.IntentMatchers.* +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.rules.ActivityScenarioRule import com.github.orkest.data.Constants +import com.github.orkest.ui.feed.CreatePost +import com.github.orkest.ui.sharing.Share import com.github.orkest.ui.sharing.SharingComposeActivity import org.junit.After import org.junit.Before @@ -79,6 +95,10 @@ class SpotifyAuthorizationTest { + + + + } diff --git a/app/src/androidTest/java/com/github/orkest/newShareTest.kt b/app/src/androidTest/java/com/github/orkest/newShareTest.kt new file mode 100644 index 00000000..5305fac9 --- /dev/null +++ b/app/src/androidTest/java/com/github/orkest/newShareTest.kt @@ -0,0 +1,77 @@ +package com.github.orkest + +import androidx.compose.foundation.layout.Column +import androidx.compose.material.Button +import androidx.compose.material.Text +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import org.junit.Rule +import org.junit.Test + +class newShareTest { + @get:Rule + var composeTestRule = createComposeRule() + + @Test + fun verifyShareWithFriendButton() { + // Verify that the "Share with a friend" button is displayed + composeTestRule.setContent { + Column { + Text(text = "Share with a friend or publish a post?") + val context = LocalContext.current + Button(onClick = { + // share with a friend + + + }) { + Text(text = "Share with a friend") + } + Button(onClick = { + + }) { + Text(text = "Publish a post") + } + } + } + composeTestRule.onNodeWithText("Share with a friend or publish a post?").assertIsDisplayed() + composeTestRule.onNodeWithText("Share with a friend").assertIsDisplayed() + composeTestRule.onNodeWithText("Publish a post").assertIsDisplayed() + + composeTestRule.onNodeWithText("Publish a post").performClick() + + + } + + @Test + fun verifyPostButton() { + // Verify that the "Share with a friend" button is displayed + composeTestRule.setContent { + Column { + Text(text = "Share with a friend or publish a post?") + val context = LocalContext.current + Button(onClick = { + // share with a friend + + + }) { + Text(text = "Share with a friend") + } + Button(onClick = { + + }) { + Text(text = "Publish a post") + } + } + } + composeTestRule.onNodeWithText("Share with a friend or publish a post?").assertIsDisplayed() + composeTestRule.onNodeWithText("Share with a friend").assertIsDisplayed() + composeTestRule.onNodeWithText("Publish a post").assertIsDisplayed() + + composeTestRule.onNodeWithText("Share with a friend").performClick() + + + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9f26d2ba..ca122c24 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -105,9 +105,15 @@ - + + - \ No newline at end of file + diff --git a/app/src/main/java/com/github/orkest/ui/sharing/Share.kt b/app/src/main/java/com/github/orkest/ui/sharing/Share.kt new file mode 100644 index 00000000..70da0c18 --- /dev/null +++ b/app/src/main/java/com/github/orkest/ui/sharing/Share.kt @@ -0,0 +1,117 @@ +package com.github.orkest.ui.sharing + +import android.annotation.SuppressLint +import android.app.AlertDialog +import android.content.Intent +import android.os.Bundle +import android.os.Looper +import android.util.Log +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material.Button +import androidx.compose.material.MaterialTheme +import androidx.compose.material.OutlinedTextField +import androidx.compose.material.Surface +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.core.os.bundleOf +import com.github.orkest.data.Constants +import com.github.orkest.data.Providers +import com.github.orkest.domain.FireStoreDatabaseAPI +import com.github.orkest.ui.CreateProfilePreview +import com.github.orkest.ui.feed.CreatePost +import com.github.orkest.ui.search.SearchUserView +import com.github.orkest.ui.search.SearchViewModel +import com.github.orkest.ui.theme.OrkestTheme + +class Share : ComponentActivity() { + + private var spotifySongID: String = String() // spotify song ID + + @SuppressLint("MutableCollectionMutableState") + override fun onCreate(savedInstanceState: Bundle?) { + + super.onCreate(savedInstanceState) + + // get the spotify song ID + spotifySongID = intent.getStringExtra("songID").toString() + + + // ----------------- Compose UI ----------------- + setContent { + OrkestTheme { + // A surface container using the 'background' color from the theme + Surface( + modifier = Modifier.fillMaxSize(), + color = MaterialTheme.colors.background + ) { + UserSelection() + } + } + } + } + + + @Composable + fun UserSelection() { + val viewModel = SearchViewModel() + var text by remember { mutableStateOf("search User") } + var list by remember { mutableStateOf(mutableListOf("")) } + /* + viewModel.searchUserInDatabase(text).thenAccept { + list = it.map { user -> user.username }.toMutableList() + } + + */ + //Show all the followers of the CURRENT_LOGGED_USER + FireStoreDatabaseAPI().fetchFollowList(Constants.CURRENT_LOGGED_USER, false).thenAccept { + list = it + } + + + + Column(modifier = Modifier.fillMaxSize()) + { + Text("Select a user to share with") + // search bar + OutlinedTextField( + value = text, + onValueChange = { + text = it + }) + // list of users + LazyColumn { + items(list) { username -> + // create an intent + val context = LocalContext.current + + // send username and name of the song + Log.d("STORING", "Song name: ${SharingComposeActivity.songName}") + val intent = Intent(context, PlaylistActivity::class.java) + intent.putExtras( + bundleOf( + "songName" to SharingComposeActivity.songName, + "songArtist" to SharingComposeActivity.songArtist, + "songID" to spotifySongID, + "senderUsername" to Constants.CURRENT_LOGGED_USER, + "receiverUsername" to username + ) + ) + CreateProfilePreview(username, intent) + + } + } + } + } +} + diff --git a/app/src/main/java/com/github/orkest/ui/sharing/SharingActivity.kt b/app/src/main/java/com/github/orkest/ui/sharing/SharingActivity.kt index 71f1cff1..b9548eb3 100644 --- a/app/src/main/java/com/github/orkest/ui/sharing/SharingActivity.kt +++ b/app/src/main/java/com/github/orkest/ui/sharing/SharingActivity.kt @@ -12,25 +12,19 @@ import androidx.activity.result.ActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items +import androidx.compose.material.Button import androidx.compose.material.MaterialTheme -import androidx.compose.material.OutlinedTextField import androidx.compose.material.Surface import androidx.compose.material.Text import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext -import androidx.core.os.bundleOf import com.github.orkest.data.Constants import com.github.orkest.data.Providers import com.github.orkest.domain.Authorization.Companion.getLoginActivityTokenIntent import com.github.orkest.domain.Authorization.Companion.requestUserAuthorization import com.github.orkest.domain.FireStoreDatabaseAPI -import com.github.orkest.ui.CreateProfilePreview -import com.github.orkest.ui.MainActivity -import com.github.orkest.ui.search.SearchUserView -import com.github.orkest.ui.search.SearchViewModel +import com.github.orkest.ui.feed.CreatePost import com.github.orkest.ui.theme.OrkestTheme import com.spotify.sdk.android.auth.AuthorizationClient import com.spotify.sdk.android.auth.AuthorizationResponse @@ -147,12 +141,35 @@ class SharingComposeActivity : ComponentActivity() { modifier = Modifier.fillMaxSize(), color = MaterialTheme.colors.background ) { - UserSelection() + // ask the user if he wants to share with a friend of publish a post + Column { + Text(text = "Share with a friend or publish a post?") + val context = LocalContext.current + Button(onClick = { + // share with a friend + + val intent = Intent(context, Share::class.java) + intent.putExtra("songID", spotifySongID) + startActivity(intent) + finish() + }) { + Text(text = "Share with a friend") + } + Button(onClick = { + // publish a post + val intent = Intent(context, CreatePost::class.java) + startActivity(intent) + finish() + }) { + Text(text = "Publish a post") + } + } } } } } + /** * This function is used to connect to the Spotify API and get the song name * @@ -272,53 +289,58 @@ class SharingComposeActivity : ComponentActivity() { } -@Composable -fun UserSelection(){ - val viewModel = SearchViewModel() - var text by remember { mutableStateOf("search User") } - var list by remember { mutableStateOf(mutableListOf("")) } - /* - viewModel.searchUserInDatabase(text).thenAccept { - list = it.map { user -> user.username }.toMutableList() - } - - */ - //Show all the followers of the CURRENT_LOGGED_USER - FireStoreDatabaseAPI().fetchFollowList(Constants.CURRENT_LOGGED_USER,false).thenAccept { - list = it - } - Column(modifier = Modifier.fillMaxSize()) - { - Text("Select a user to share with") - // search bar - OutlinedTextField( - value = text , - onValueChange = { - text = it - } ) - // list of users - LazyColumn{ - items(list){ username -> - // create an intent - val context = LocalContext.current - - // send username and name of the song - Log.d("STORING", "Song name: $songName") - val intent = Intent(context, PlaylistActivity::class.java) - intent.putExtras( - bundleOf( - "songName" to songName, - "songArtist" to songArtist, - "songID" to spotifySongID, - "senderUsername" to Constants.CURRENT_LOGGED_USER, - "receiverUsername" to username - ) - ) - CreateProfilePreview(username, intent) - } - } - } - } +//@Composable +//fun UserSelection(){ +// val viewModel = SearchViewModel() +// var text by remember { mutableStateOf("search User") } +// var list by remember { mutableStateOf(mutableListOf("")) } +// /* +// viewModel.searchUserInDatabase(text).thenAccept { +// list = it.map { user -> user.username }.toMutableList() +// } +// +// */ +// //Show all the followers of the CURRENT_LOGGED_USER +// FireStoreDatabaseAPI().fetchFollowList(Constants.CURRENT_LOGGED_USER,false).thenAccept { +// list = it +// } +// +// +// +// Column(modifier = Modifier.fillMaxSize()) +// { +// Text("Select a user to share with") +// // search bar +// OutlinedTextField( +// value = text , +// onValueChange = { +// text = it +// } ) +// // list of users +// LazyColumn{ +// items(list){ username -> +// // create an intent +// val context = LocalContext.current +// +// // send username and name of the song +// Log.d("STORING", "Song name: $songName") +// val intent = Intent(context, PlaylistActivity::class.java) +// intent.putExtras( +// bundleOf( +// "songName" to songName, +// "songArtist" to songArtist, +// "songID" to spotifySongID, +// "senderUsername" to Constants.CURRENT_LOGGED_USER, +// "receiverUsername" to username +// ) +// ) +// CreateProfilePreview(username, intent) +// +// } +// } +// } +// } +// }