Skip to content

Commit 3ff86ca

Browse files
authored
Merge pull request #4 from SSUMC-9th/berr/#2
Berr/2주차 과제
2 parents 1b3e03f + defae44 commit 3ff86ca

File tree

17 files changed

+1025
-40
lines changed

17 files changed

+1025
-40
lines changed

.idea/deviceManager.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ android {
170170
}
171171
buildFeatures {
172172
compose = true
173+
viewBinding = true
173174
}
174175
composeOptions {
175176
kotlinCompilerExtensionVersion = "1.5.1"

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<category android:name="android.intent.category.LAUNCHER" />
2424
</intent-filter>
2525
</activity>
26+
<activity android:name="com.example.umc_9th.SongActivity" />
2627
</application>
2728

2829
</manifest>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.example.umc_9th
2+
3+
import android.content.Intent
4+
import android.os.Bundle
5+
import android.view.LayoutInflater
6+
import android.view.View
7+
import android.view.ViewGroup
8+
import android.widget.ImageView
9+
import android.widget.LinearLayout
10+
import android.widget.TextView
11+
import androidx.fragment.app.Fragment
12+
import umc.study.umc_8th.R
13+
14+
15+
class HomeFragment : Fragment() {
16+
17+
override fun onCreateView(
18+
inflater: LayoutInflater, container: ViewGroup?,
19+
savedInstanceState: Bundle?
20+
): View? {
21+
val view = inflater.inflate(R.layout.fragment_home, container, false)
22+
23+
val mainActivity = activity as? MainActivity
24+
25+
// song1
26+
val song1Title = view.findViewById<TextView>(R.id.song1_title)
27+
val song1Artist = view.findViewById<TextView>(R.id.song1_artist)
28+
val song1Album = view.findViewById<ImageView>(R.id.song1_album)
29+
val song1Layout = view.findViewById<LinearLayout>(R.id.song1_container)
30+
31+
song1Layout.setOnClickListener {
32+
val intent = Intent(requireContext(), SongActivity::class.java)
33+
intent.putExtra("title", song1Title.text.toString())
34+
intent.putExtra("artist", song1Artist.text.toString())
35+
intent.putExtra("albumResId", R.drawable.img_album_exp)
36+
mainActivity?.songActivityLauncher?.launch(intent)
37+
}
38+
39+
// song2
40+
val song2Title = view.findViewById<TextView>(R.id.song2_title)
41+
val song2Artist = view.findViewById<TextView>(R.id.song2_artist)
42+
val song2Album = view.findViewById<ImageView>(R.id.song2_album)
43+
val song2Layout = view.findViewById<LinearLayout>(R.id.song2_container)
44+
45+
song2Layout.setOnClickListener {
46+
val intent = Intent(requireContext(), SongActivity::class.java)
47+
intent.putExtra("title", song2Title.text.toString())
48+
intent.putExtra("artist", song2Artist.text.toString())
49+
intent.putExtra("albumResId", R.drawable.img_album_exp2)
50+
mainActivity?.songActivityLauncher?.launch(intent)
51+
}
52+
53+
// song3
54+
val song3Title = view.findViewById<TextView>(R.id.song3_title)
55+
val song3Artist = view.findViewById<TextView>(R.id.song3_artist)
56+
val song3Album = view.findViewById<ImageView>(R.id.song3_album)
57+
val song3Layout = view.findViewById<LinearLayout>(R.id.song3_container)
58+
59+
song3Layout.setOnClickListener {
60+
val intent = Intent(requireContext(), SongActivity::class.java)
61+
intent.putExtra("title", song3Title.text.toString())
62+
intent.putExtra("artist", song3Artist.text.toString())
63+
intent.putExtra("albumResId", R.drawable.img_album_exp3)
64+
mainActivity?.songActivityLauncher?.launch(intent)
65+
}
66+
67+
return view
68+
}
69+
}
Lines changed: 76 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,86 @@
11
package com.example.umc_9th
22

3+
import android.app.Activity.RESULT_OK
4+
import android.content.Intent
35
import android.os.Bundle
4-
import androidx.activity.ComponentActivity
5-
import androidx.activity.compose.setContent
6-
import androidx.activity.enableEdgeToEdge
7-
import androidx.compose.foundation.layout.fillMaxSize
8-
import androidx.compose.foundation.layout.padding
9-
import androidx.compose.material3.Scaffold
10-
import androidx.compose.material3.Text
11-
import androidx.compose.runtime.Composable
12-
import androidx.compose.ui.Modifier
13-
import androidx.compose.ui.tooling.preview.Preview
14-
import com.example.umc_9th.ui.theme.UMC_9thTheme
15-
16-
class MainActivity : ComponentActivity() {
6+
import android.view.LayoutInflater
7+
import android.view.View
8+
import android.view.ViewGroup
9+
import android.widget.Button
10+
import android.widget.ImageView
11+
import android.widget.LinearLayout
12+
import android.widget.TextView
13+
import android.widget.Toast
14+
import androidx.activity.result.contract.ActivityResultContracts
15+
import androidx.appcompat.app.AppCompatActivity
16+
import androidx.fragment.app.Fragment
17+
import com.google.android.material.bottomnavigation.BottomNavigationView
18+
import umc.study.umc_8th.R
19+
import umc.study.umc_8th.databinding.ActivityMainBinding
20+
21+
class ExploreFragment : Fragment(R.layout.fragment_explore)
22+
class SearchFragment : Fragment(R.layout.fragment_search)
23+
class LibraryFragment : Fragment(R.layout.fragment_locker)
24+
class MainActivity : AppCompatActivity() {
25+
26+
private lateinit var binding: ActivityMainBinding
27+
28+
val songActivityLauncher = registerForActivityResult(
29+
ActivityResultContracts.StartActivityForResult()
30+
) { result ->
31+
if (result.resultCode == RESULT_OK) {
32+
val title = result.data?.getStringExtra("title")
33+
val artist = result.data?.getStringExtra("artist")
34+
val albumResId = result.data?.getIntExtra("albumResId", R.drawable.btn_textbox_close)
35+
36+
binding.miniPlayerTitle.text = title
37+
binding.miniPlayerArtist.text = artist
38+
albumResId?.let {
39+
binding.miniPlayerAlbum.setImageResource(it)
40+
binding.miniPlayerAlbum.tag = it
41+
}
42+
}
43+
}
44+
1745
override fun onCreate(savedInstanceState: Bundle?) {
1846
super.onCreate(savedInstanceState)
19-
enableEdgeToEdge()
20-
setContent {
21-
UMC_9thTheme {
22-
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
23-
Greeting(
24-
name = "Android",
25-
modifier = Modifier.padding(innerPadding)
26-
)
27-
}
47+
binding = ActivityMainBinding.inflate(layoutInflater)
48+
setContentView(binding.root)
49+
50+
if (savedInstanceState == null) {
51+
supportFragmentManager.beginTransaction()
52+
.replace(R.id.container, HomeFragment())
53+
.commit()
54+
}
55+
56+
binding.bottomNavigationView.setOnItemSelectedListener { item ->
57+
val selectedFragment: Fragment = when (item.itemId) {
58+
R.id.bottom_homeButton -> HomeFragment()
59+
R.id.bottom_lookButton -> ExploreFragment()
60+
R.id.bottom_searchButton -> SearchFragment()
61+
R.id.bottom_lockerButton -> LibraryFragment()
62+
else -> HomeFragment()
2863
}
64+
65+
supportFragmentManager.beginTransaction()
66+
.replace(R.id.container, selectedFragment)
67+
.commit()
68+
69+
true
2970
}
30-
}
31-
}
3271

33-
@Composable
34-
fun Greeting(name: String, modifier: Modifier = Modifier) {
35-
Text(
36-
text = "Hello $name!",
37-
modifier = modifier
38-
)
39-
}
72+
binding.gotoSong.setOnClickListener {
73+
val title = binding.miniPlayerTitle.text.toString()
74+
val artist = binding.miniPlayerArtist.text.toString()
75+
val albumResId = binding.miniPlayerAlbum.tag as? Int
76+
77+
val intent = Intent(this, SongActivity::class.java).apply {
78+
putExtra("title", title)
79+
putExtra("artist", artist)
80+
putExtra("albumResId", albumResId)
81+
}
82+
songActivityLauncher.launch(intent)
83+
}
4084

41-
@Preview(showBackground = true)
42-
@Composable
43-
fun GreetingPreview() {
44-
UMC_9thTheme {
45-
Greeting("Android")
4685
}
47-
}
86+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.example.umc_9th
2+
3+
import android.content.Intent
4+
import android.os.Bundle
5+
import android.widget.Button
6+
import android.widget.ImageButton
7+
import android.widget.ImageView
8+
import android.widget.LinearLayout
9+
import android.widget.TextView
10+
import androidx.appcompat.app.AppCompatActivity
11+
import umc.study.umc_8th.R
12+
13+
class SongActivity : AppCompatActivity() {
14+
override fun onCreate(savedInstanceState: Bundle?) {
15+
super.onCreate(savedInstanceState)
16+
setContentView(R.layout.activity_song)
17+
18+
val title = intent.getStringExtra("title")
19+
val artist = intent.getStringExtra("artist")
20+
val albumResId = intent.getIntExtra("albumResId", R.drawable.btn_textbox_close)
21+
findViewById<TextView>(R.id.song_title).text = title
22+
findViewById<TextView>(R.id.song_artist).text = artist
23+
findViewById<ImageView>(R.id.song_album_image).setImageResource(albumResId)
24+
25+
findViewById<ImageButton>(R.id.song_drop_button).setOnClickListener {
26+
val resultIntent = Intent()
27+
resultIntent.putExtra("title", title)
28+
resultIntent.putExtra("artist", artist)
29+
resultIntent.putExtra("albumResId", albumResId)
30+
setResult(RESULT_OK, resultIntent)
31+
finish()
32+
}
33+
34+
}
35+
}
36+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
<corners android:radius="10dp" />
5+
</shape>

0 commit comments

Comments
 (0)