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
10 changes: 10 additions & 0 deletions Week08/OneStone/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.idea/
*.iml
.gradle
/local.properties
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions Week08/OneStone/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
82 changes: 82 additions & 0 deletions Week08/OneStone/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.hilt.android)
alias(libs.plugins.legacy.kapt)
alias(libs.plugins.kotlin.compose)
}

apply(plugin = "androidx.navigation.safeargs.kotlin")

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

buildFeatures {
viewBinding = true
compose = true
}

defaultConfig {
applicationId = "com.example.umc10th"
minSdk = 33
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)
implementation(libs.androidx.navigation.fragment.ktx)
implementation(libs.androidx.navigation.ui.ktx)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.ui.tooling.preview)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
implementation("com.google.code.gson:gson:2.10.1")
implementation("androidx.datastore:datastore-preferences:1.1.1")

implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")

implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0")
implementation(libs.hilt.android)
debugImplementation(libs.androidx.ui.tooling)
kapt(libs.hilt.android.compiler)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.material3)
debugImplementation(libs.androidx.compose.ui.tooling)

}
21 changes: 21 additions & 0 deletions Week08/OneStone/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.umc10th

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.umc10th", appContext.packageName)
}
}
30 changes: 30 additions & 0 deletions Week08/OneStone/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name=".MyApplication"
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.UMC10th"
android:usesCleartextTraffic="true">
<activity
android:name=".ui.splash.SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.main.MainActivity"
android:exported="true" />
</application>

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

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class MyApplication : Application(){

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package com.example.umc10th.data.local

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import androidx.datastore.preferences.core.Preferences
import com.example.umc10th.R
import com.example.umc10th.data.model.Product
import com.example.umc10th.data.model.PurchaseProduct
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import kotlinx.coroutines.flow.first
import kotlin.collections.listOf


val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "ex_name")

val PRODUCTS_KEY = stringPreferencesKey("products_key")

val PURCHASE_PRODUCTS_KEY = stringPreferencesKey("purchase_products_key")
private val gson = Gson()
private val productImageResIds = setOf(R.drawable.shoes1, R.drawable.shoes2)
private val purchaseProductImageResIds = setOf(
R.drawable.socks1,
R.drawable.socks2,
R.drawable.shoes1,
R.drawable.shoes2
)

suspend fun saveProducts(context: Context, Products: List<Product>) {

val jsonString = gson.toJson(Products)
context.dataStore.edit { settings ->
settings[PRODUCTS_KEY] = jsonString
}
}

fun getProducts(context: Context): Flow<List<Product>> {
return context.dataStore.data.map { preferences ->
val jsonString = preferences[PRODUCTS_KEY] ?: "[]"
val type = object : TypeToken<List<Product>>() {}.type
gson.fromJson(jsonString, type)
}
}



suspend fun savePurchaseProducts(context: Context, Products: List<PurchaseProduct>) {

val jsonString = gson.toJson(Products)
context.dataStore.edit { settings ->
settings[PURCHASE_PRODUCTS_KEY] = jsonString
}
}

fun getPurchaseProducts(context: Context): Flow<List<PurchaseProduct>> {
return context.dataStore.data.map { preferences ->
val jsonString = preferences[PURCHASE_PRODUCTS_KEY] ?: "[]"
val type = object : TypeToken<List<PurchaseProduct>>() {}.type
gson.fromJson(jsonString, type)
}
}
suspend fun initializeProducts(context: Context) {
val currentProducts = getProducts(context).first()

val defaultProducts = listOf(
Product(R.drawable.shoes1, "Air Jordan XXXVI", "Men's Shoes", "US$185", id = 1),
Product(R.drawable.shoes2, "Nike Air Force 1 '07", "Women's Shoes", "US$115", id = 2),
Product(R.drawable.shoes1, "Air Jordan XXXVI", "Men's Shoes", "US$185", id = 3),
Product(R.drawable.shoes2, "Nike Air Force 1 '07", "Women's Shoes", "US$115", id = 4),
Product(R.drawable.shoes1, "Air Jordan XXXVI", "Men's Shoes", "US$185", id = 5),
Product(R.drawable.shoes2, "Nike Air Force 1 '07", "Women's Shoes", "US$115", id = 6),
Product(R.drawable.shoes1, "Air Jordan XXXVI", "Men's Shoes", "US$185", id = 7),
Product(R.drawable.shoes2, "Nike Air Force 1 '07", "Women's Shoes", "US$115", id = 8),
Product(R.drawable.shoes1, "Air Jordan XXXVI", "Men's Shoes", "US$185", id = 9),
Product(R.drawable.shoes2, "Nike Air Force 1 '07", "Women's Shoes", "US$115", id = 10),
Product(R.drawable.shoes1, "Air Jordan XXXVI", "Men's Shoes", "US$185", id = 11),
Product(R.drawable.shoes2, "Nike Air Force 1 '07", "Women's Shoes", "US$115", id = 12),
Product(R.drawable.shoes1, "Air Jordan XXXVI", "Men's Shoes", "US$185", id = 13),
Product(R.drawable.shoes2, "Nike Air Force 1 '07", "Women's Shoes", "US$115", id = 14),
Product(R.drawable.shoes1, "Air Jordan XXXVI", "Men's Shoes", "US$185", id = 15),
Product(R.drawable.shoes2, "Nike Air Force 1 '07", "Women's Shoes", "US$115", id = 16),
Product(R.drawable.shoes1, "Air Jordan XXXVI", "Men's Shoes", "US$185", id = 17),
Product(R.drawable.shoes2, "Nike Air Force 1 '07", "Women's Shoes", "US$115", id = 18),
Product(R.drawable.shoes1, "Air Jordan XXXVI", "Men's Shoes", "US$185", id = 19),
Product(R.drawable.shoes2, "Nike Air Force 1 '07", "Women's Shoes", "US$115", id = 20)
)
val currentProductIds = currentProducts.map { it.id }
val hasValidProducts = currentProducts.isNotEmpty() &&
currentProducts.all { it.imageResId in productImageResIds && it.id > 0 } &&
currentProductIds.distinct().size == currentProductIds.size
if (hasValidProducts) return
saveProducts(context, defaultProducts)
}



suspend fun initializePurchaseProducts(context: Context) {
val currentProducts = getPurchaseProducts(context).first()

val defaultPurchaseProducts = listOf(
PurchaseProduct(1, R.drawable.socks1, false, "Nike Everyday Plus Cushioned", "Training Ankle Socks (6 Pairs)", "5 Colours", "US\$10"),
PurchaseProduct(2, R.drawable.socks2, false, "Nike Elite Crew", "Basketball Socks", "7 Colours","US\$16"),
PurchaseProduct(3, R.drawable.shoes1, true,"Nike Air Force 1 '07", "Women's Shoes", "5 Colours", "US\$115"),
PurchaseProduct(4, R.drawable.shoes2, true, "Jordan ENike Air Force 1 '07ssentials", "Men's Shoes", "2 Colours","US\$115"),
PurchaseProduct(5, R.drawable.socks1, false, "Nike Everyday Plus Cushioned", "Training Ankle Socks (6 Pairs)", "5 Colours", "US\$10"),
PurchaseProduct(6, R.drawable.socks2, false, "Nike Elite Crew", "Basketball Socks", "7 Colours","US\$16"),
PurchaseProduct(7, R.drawable.shoes1, true,"Nike Air Force 1 '07", "Women's Shoes", "5 Colours", "US\$115"),
PurchaseProduct(8, R.drawable.shoes2, true, "Jordan ENike Air Force 1 '07ssentials", "Men's Shoes", "2 Colours","US\$115"),
PurchaseProduct(9, R.drawable.socks1, false, "Nike Everyday Plus Cushioned", "Training Ankle Socks (6 Pairs)", "5 Colours", "US\$10"),
PurchaseProduct(10, R.drawable.socks2, false, "Nike Elite Crew", "Basketball Socks", "7 Colours","US\$16"),
PurchaseProduct(11, R.drawable.shoes1, true,"Nike Air Force 1 '07", "Women's Shoes", "5 Colours", "US\$115"),
PurchaseProduct(12, R.drawable.shoes2, true, "Jordan ENike Air Force 1 '07ssentials", "Men's Shoes", "2 Colours","US\$115"),
PurchaseProduct(13, R.drawable.socks1, false, "Nike Everyday Plus Cushioned", "Training Ankle Socks (6 Pairs)", "5 Colours", "US\$10"),
PurchaseProduct(14, R.drawable.shoes1, true,"Nike Air Force 1 '07", "Women's Shoes", "5 Colours", "US\$115"),
PurchaseProduct(15, R.drawable.shoes2, true, "Jordan ENike Air Force 1 '07ssentials", "Men's Shoes", "2 Colours","US\$115"),
PurchaseProduct(16, R.drawable.socks1, false, "Nike Everyday Plus Cushioned", "Training Ankle Socks (6 Pairs)", "5 Colours", "US\$10"),
PurchaseProduct(17, R.drawable.socks2, false, "Nike Elite Crew", "Basketball Socks", "7 Colours","US\$16"),
PurchaseProduct(18, R.drawable.shoes1, true,"Nike Air Force 1 '07", "Women's Shoes", "5 Colours", "US\$115"),
PurchaseProduct(19, R.drawable.shoes2, true, "Jordan ENike Air Force 1 '07ssentials", "Men's Shoes", "2 Colours","US\$115"),
PurchaseProduct(20, R.drawable.socks1, false, "Nike Everyday Plus Cushioned", "Training Ankle Socks (6 Pairs)", "5 Colours", "US\$10"),
PurchaseProduct(21, R.drawable.socks2, false, "Nike Elite Crew", "Basketball Socks", "7 Colours","US\$16"),
PurchaseProduct(22, R.drawable.shoes1, true,"Nike Air Force 1 '07", "Women's Shoes", "5 Colours", "US\$115"),
PurchaseProduct(23, R.drawable.shoes2, true, "Jordan ENike Air Force 1 '07ssentials", "Men's Shoes", "2 Colours","US\$115"),
)
if (currentProducts.isNotEmpty() && currentProducts.all { it.imageResId in purchaseProductImageResIds }) return
savePurchaseProducts(context, defaultPurchaseProducts)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.umc10th.data.model

import android.graphics.Bitmap

data class FollowingProfile(
val id: Int,
val avatarBitmap: Bitmap
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.umc10th.data.model

import androidx.annotation.DrawableRes

data class Product(
val imageResId: Int,
val name: String,
val description: String,
val price: String,
val id: Int = 0
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.umc10th.data.model

import androidx.annotation.DrawableRes

data class PurchaseProduct(
val id: Int,
val imageResId: Int,
val isBest: Boolean,
val title: String,
val description: String,
val colornum: String,
val price: String,
var isWishlisted: Boolean = false
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.umc10th.data.model

import com.google.gson.annotations.SerializedName

data class ReqResUsersResponse(
val page: Int,
@SerializedName("per_page")
val perPage: Int,
val total: Int,
@SerializedName("total_pages")
val totalPages: Int,
val data: List<ReqResUser>
)

data class ReqResUser(
val id: Int,
val email: String,
@SerializedName("first_name")
val firstName: String,
@SerializedName("last_name")
val lastName: String,
val avatar: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.umc10th.data.remote

import com.example.umc10th.data.model.ReqResUsersResponse
import retrofit2.http.GET

interface ReqResApiService {
@GET("api/users")
suspend fun getUsers(): ReqResUsersResponse

@GET("api/users/23")
suspend fun getMissingUser(): ReqResUsersResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.umc10th.data.remote

object ReqResDebugConfig {
val forceHttpErrorCode: Int? = null // null : ์ •์ƒ์ž‘๋™, 400 : ๋‚ด์ž˜๋ชป ํ† ์ŠคํŠธ๋ฉ”์„ธ์ง€, 500 : ๋‹ˆ์ž˜๋ชป ํ† ์ŠคํŠธ๋ฉ”์„ธ์ง€
}
Loading