Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced feature for sharing #249

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions app/src/androidTest/java/com/github/orkest/ShareSongTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,6 +95,10 @@ class SpotifyAuthorizationTest {







}


Expand Down
77 changes: 77 additions & 0 deletions app/src/androidTest/java/com/github/orkest/newShareTest.kt
Original file line number Diff line number Diff line change
@@ -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()


}
}
12 changes: 9 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,15 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.profile.HelpActivity"
<activity
android:name=".ui.sharing.Share"
android:exported="true"
android:label="@string/title_activity_edit_profile"
android:theme="@style/Theme.Orkest"
android:windowSoftInputMode="adjustResize" />

<activity android:name=".ui.profile.HelpActivity"
android:exported="false" />
</application>

</manifest>
</manifest>
117 changes: 117 additions & 0 deletions app/src/main/java/com/github/orkest/ui/sharing/Share.kt
Original file line number Diff line number Diff line change
@@ -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)

}
}
}
}
}

Loading