Skip to content
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
15 changes: 15 additions & 0 deletions Week2/.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 Week2/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
53 changes: 53 additions & 0 deletions Week2/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
plugins {
alias(libs.plugins.android.application)
}

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

defaultConfig {
applicationId = "com.example.week2"
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
}

buildFeatures {
viewBinding = true
}
}

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)
implementation(libs.androidx.navigation.fragment.ktx)
implementation(libs.androidx.navigation.ui.ktx)
}
21 changes: 21 additions & 0 deletions Week2/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.week2

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.week2", appContext.packageName)
}
}
25 changes: 25 additions & 0 deletions Week2/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.Week2">
<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>
23 changes: 23 additions & 0 deletions Week2/app/src/main/java/com/example/week2/BuyAllFragment.kt
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

구매하기 화면내의 탭 메뉴 구성을 아주 꼼꼼하게 직접 구현하셨네요! 수고 많으셨습니다. 😊

다만, 현재 프래그먼트와 뷰 ID 이름이 Tab1Fragment, tab1처럼 일련번호 형태로 되어 있어서, 코드를 읽을 때 어떤 카테고리인지 한눈에 파악하기가 조금 어렵습니다!

Tab1Fragment → BuyAllFragment

Tab2Fragment → BuyTopsFragment

Tab3Fragment → BuyShoesFragment

이렇게 화면의 역할(카테고리명)이 드러나게 이름을 지어주면, 나중에 탭의 순서가 바뀌거나 새로운 카테고리가 추가되어도 헷갈리지 않고 훨씬 유지보수하기 편한 코드가 됩니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.week2

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

class BuyAllFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return inflater.inflate(R.layout.fragment_buy_all, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

}
}
71 changes: 71 additions & 0 deletions Week2/app/src/main/java/com/example/week2/BuyFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.example.week2

import android.graphics.Typeface
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.example.week2.databinding.FragmentBuyBinding
import com.google.android.material.tabs.TabLayout

class BuyFragment : Fragment(R.layout.fragment_buy) {

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

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
_binding = FragmentBuyBinding.bind(view)

setupTabs()
}

private fun setupTabs() {
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.all)))
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.Shirts)))
binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.Shoes)))

replaceTabFragment(BuyAllFragment())

binding.tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
updateTabStyle(tab, true)

when (tab?.position) {
0 -> replaceTabFragment(BuyAllFragment())
1 -> replaceTabFragment(BuyTopsFragment())
2 -> replaceTabFragment(BuyShoesFragment())
}
}

override fun onTabUnselected(tab: TabLayout.Tab?) {
updateTabStyle(tab, false)
}

override fun onTabReselected(tab: TabLayout.Tab?) {}
})

updateTabStyle(binding.tabLayout.getTabAt(0), true)
}

private fun replaceTabFragment(fragment: Fragment) {
childFragmentManager.beginTransaction()
.replace(R.id.tabContent, fragment)
.commit()
}

private fun updateTabStyle(tab: TabLayout.Tab?, isBold: Boolean) {
val tabView = (binding.tabLayout.getChildAt(0) as ViewGroup).getChildAt(tab?.position ?: 0) as ViewGroup
val textView = tabView.getChildAt(1) as? TextView

textView?.let {
it.typeface = if (isBold) Typeface.DEFAULT_BOLD else Typeface.DEFAULT
}
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
23 changes: 23 additions & 0 deletions Week2/app/src/main/java/com/example/week2/BuyShoesFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.week2

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

class BuyShoesFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return inflater.inflate(R.layout.fragment_buy_shoes, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

}
}
23 changes: 23 additions & 0 deletions Week2/app/src/main/java/com/example/week2/BuyTopsFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.week2

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

class BuyTopsFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return inflater.inflate(R.layout.fragment_buy_tops, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

}
}
23 changes: 23 additions & 0 deletions Week2/app/src/main/java/com/example/week2/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.week2

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

class HomeFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return inflater.inflate(R.layout.fragment_home, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

}
}
62 changes: 62 additions & 0 deletions Week2/app/src/main/java/com/example/week2/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.example.week2
import com.example.week2.databinding.ActivityMainBinding

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import android.util.Log
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController

class MainActivity : AppCompatActivity() {
private val TAG = "LIFE_QUIZ"
private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
Log.d(TAG, "onCreate")

binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

val navHostFragment = supportFragmentManager
.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
binding.bottomBarInclude.bottomNav.setupWithNavController(navController)

ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, 0)
insets
}
}

override fun onStart() {
super.onStart()
Log.d(TAG, "onStart")
}
override fun onResume() {
super.onResume()
Log.d(TAG, "onResume")
}
override fun onPause() {
super.onPause()
Log.d(TAG, "onPause")
}
override fun onStop() {
super.onStop()
Log.d(TAG, "onStop")
}
override fun onDestroy() {
super.onDestroy()
Log.d(TAG, "onDestroy")
}
override fun onRestart() {
super.onRestart()
Log.d(TAG, "onRestart")
}
}
Loading