Skip to content
Merged
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
15 changes: 15 additions & 0 deletions week03/mission/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions week03/mission/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
51 changes: 51 additions & 0 deletions week03/mission/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
plugins {
alias(libs.plugins.android.application)
}

android {
namespace = "com.example.umc_10th_android_paul_week02"
compileSdk {
version = release(36) {
minorApiLevel = 1
}
}

viewBinding {
enable = true
}

defaultConfig {
applicationId = "com.example.umc_10th_android_paul_week02"
minSdk = 24
targetSdk = 36
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
}
21 changes: 21 additions & 0 deletions week03/mission/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.umc_10th_android_paul_week02

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.umc_10th_android_paul_week02", appContext.packageName)
}
}
25 changes: 25 additions & 0 deletions week03/mission/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.UMC_10th_Android_Paul_week02">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.umc_10th_android_paul_week02

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
class CartFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_cart, container, false)

val btnOrder = view.findViewById<Button>(R.id.btn_order)

btnOrder?.setOnClickListener {
(activity as? MainActivity)?.changeTab(R.id.nav_shop)
}
return view
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.example.umc_10th_android_paul_week02

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.umc_10th_android_paul_week02.databinding.FragmentHomeBinding
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Locale
import java.util.TimeZone

class HomeFragment : Fragment() {

private var _binding: FragmentHomeBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentHomeBinding.inflate(inflater, container, false)

val currentTime = Calendar.getInstance().time
val dateFormat = SimpleDateFormat("M월 d일 E요일", Locale.KOREAN)
dateFormat.timeZone = TimeZone.getTimeZone("Asia/Seoul")
binding.tvDate.text = dateFormat.format(currentTime)

val homeProductList = arrayListOf(
HomeProduct(R.drawable.shoe_jordan_36, "Air Jordan XXXVI", "US$185"),
HomeProduct(R.drawable.shoe_jordan_01, "Air Jordan 1 Mid", "US$125"),
HomeProduct(R.drawable.shoe_airforce_01, "Nike Air Force 1 '07", "US$115")
)

val homeAdapter = HomeProductAdapter(homeProductList)
binding.rvHomeProduct.adapter = homeAdapter
binding.rvHomeProduct.layoutManager = LinearLayoutManager(
requireContext(),
LinearLayoutManager.HORIZONTAL,
false
)

return binding.root
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.umc_10th_android_paul_week02

data class HomeProduct(
val imageRes: Int, // R.drawable.신발이미지
val title: String, // "Air Jordan XXXVI"
val price: String // "US$185"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.umc_10th_android_paul_week02

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.umc_10th_android_paul_week02.databinding.ItemHomeProductBinding

class HomeProductAdapter(private val productList: ArrayList<HomeProduct>) :
RecyclerView.Adapter<HomeProductAdapter.ViewHolder>() {

inner class ViewHolder(val binding: ItemHomeProductBinding) :
RecyclerView.ViewHolder(binding.root)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding = ItemHomeProductBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return ViewHolder(binding)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val product = productList[position]

holder.binding.ivProduct.setImageResource(product.imageRes)
holder.binding.tvTitle.text = product.title
holder.binding.tvPrice.text = product.price
}

override fun getItemCount(): Int = productList.size
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.example.umc_10th_android_paul_week02

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.google.android.material.bottomnavigation.BottomNavigationView

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val bottomNav = findViewById<BottomNavigationView>(R.id.bottom_navigation)

// 1. 앱을 처음 켰을 때 나올 첫 화면 설정 (홈 화면)
if (savedInstanceState == null) {
replaceFragment(HomeFragment())
}

// 2. 하단 바 버튼을 눌렀을 때 동작 설정
bottomNav.setOnItemSelectedListener { item ->
when (item.itemId) {
R.id.nav_home -> {
replaceFragment(HomeFragment())
true
}
R.id.nav_shop -> {
replaceFragment(ShopFragment())
true
}
R.id.nav_wish -> {
replaceFragment(WishlistFragment())
true
}
R.id.nav_cart -> {
replaceFragment(CartFragment())
true
}
R.id.nav_profile -> {
replaceFragment(ProfileFragment())
true
}
else -> false
}
}
}

// 3. 화면(Fragment)을 교체하는 함수 정의
private fun replaceFragment(fragment: Fragment) {
supportFragmentManager.beginTransaction()
.replace(R.id.main_container, fragment) // activity_main.xml의 FrameLayout ID
.commit()
}

fun changeTab(itemId: Int) {
val bottomNav = findViewById<BottomNavigationView>(R.id.bottom_navigation)
bottomNav.selectedItemId = itemId
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.umc_10th_android_paul_week02

data class Product(
val imageRes: Int,
val title: String,
val description: String,
val price: String,
var isLiked: Boolean = false
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.umc_10th_android_paul_week02

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

class ProfileFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// 프로필 레이아웃 파일과 연결
return inflater.inflate(R.layout.fragment_profile, container, false)
}
}
Loading
Loading