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

[Week6] XML 필수 과제 #15

Open
wants to merge 13 commits into
base: develop-xml
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
27 changes: 25 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.plugin.serialization'
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

android {
namespace 'com.sopt.now'
compileSdk 34
Expand All @@ -15,6 +19,8 @@ android {
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "String", "AUTH_BASE_URL", properties["base.url"]
buildConfigField "String", "FOLLOWER_URL", properties["follower.url"]
}

buildTypes {
Expand All @@ -32,21 +38,38 @@ android {
}
buildFeatures {
viewBinding true
buildConfig true
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.core:core-ktx:1.13.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

// Lifecycle Viewmodel
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0'

// Fragment && Activity
implementation 'androidx.fragment:fragment-ktx:1.6.2'
implementation 'androidx.activity:activity-ktx:1.8.2'
implementation 'androidx.activity:activity-ktx:1.9.0'

// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1'
implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0'

// OKHttp
implementation platform('com.squareup.okhttp3:okhttp-bom:4.10.0')
implementation 'com.squareup.okhttp3:okhttp'
implementation 'com.squareup.okhttp3:logging-interceptor'

// Glide
implementation 'com.github.bumptech.glide:glide:4.13.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.0'
}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<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:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -11,9 +12,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NOWSOPTAndroid"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".ui.login.LoginActivity"
android:name=".ui.signIn.SignInActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sopt.now.data
package com.sopt.now.data.model

import androidx.annotation.DrawableRes

Expand All @@ -12,7 +12,7 @@ sealed class ItemData {


data class Friend(
@DrawableRes val profileImage: Int?,
val profileImage: String?,
val name: String,
val description: String?,
) : ItemData()
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/sopt/now/data/model/RequestSignInDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sopt.now.data.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestSignInDto(
@SerialName("authenticationId")
val authenticationId: String,
@SerialName("password")
val password: String,
)
16 changes: 16 additions & 0 deletions app/src/main/java/com/sopt/now/data/model/RequestSignUpDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.sopt.now.data.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestSignUpDto(
@SerialName("authenticationId")
val authenticationId: String,
@SerialName("password")
val password: String,
@SerialName("nickname")
val nickname: String,
@SerialName("phone")
val phone: String,
)
24 changes: 24 additions & 0 deletions app/src/main/java/com/sopt/now/data/model/ResponseInfoDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.sopt.now.data.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseInfoDto(
@SerialName("code")
val code: Int,
@SerialName("message")
val message: String,
@SerialName("data")
val data: UserInfo,
)

@Serializable
data class UserInfo(
@SerialName("authenticationId")
val authenticationId: String,
@SerialName("nickname")
val nickname: String,
@SerialName("phone")
val phone: String,
)
12 changes: 12 additions & 0 deletions app/src/main/java/com/sopt/now/data/model/ResponseSignInDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sopt.now.data.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseSignInDto(
@SerialName("code")
val code: Int,
@SerialName("message")
val message: String,
)
12 changes: 12 additions & 0 deletions app/src/main/java/com/sopt/now/data/model/ResponseSignUpDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sopt.now.data.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseSignUpDto(
@SerialName("code")
val code: Int,
@SerialName("message")
val message: String,
)
29 changes: 29 additions & 0 deletions app/src/main/java/com/sopt/now/data/model/ResponseUserDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.sopt.now.data.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class UserDataResponse(
val page: Int,
@SerialName("per_page") val perPage: Int,
val total: Int,
@SerialName("total_pages") val totalPages: Int,
val data: List<UserData>,
val support: Support,
)

@Serializable
data class UserData(
val id: Int,
val email: String,
@SerialName("first_name") val firstName: String,
@SerialName("last_name") val lastName: String,
val avatar: String,
)

@Serializable
data class Support(
val url: String,
val text: String,
)
6 changes: 6 additions & 0 deletions app/src/main/java/com/sopt/now/data/model/SignInState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.sopt.now.data.model

data class SignInState(
val isSuccess: Boolean,
val message: String,
)
6 changes: 6 additions & 0 deletions app/src/main/java/com/sopt/now/data/model/SignUpState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.sopt.now.data.model

data class SignUpState(
val isSuccess: Boolean,
val message: String,
)
42 changes: 42 additions & 0 deletions app/src/main/java/com/sopt/now/data/module/ApiFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.sopt.now.data.module

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.sopt.now.compose.BuildConfig
import com.sopt.now.data.network.AuthService
import com.sopt.now.data.network.FollowerService
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.create

object ApiFactory {
private const val BASE_URL: String = BuildConfig.AUTH_BASE_URL
private const val FOLLOWER_URL: String = BuildConfig.FOLLOWER_URL

private val interceptorClient = OkHttpClient().newBuilder()
.addInterceptor(AuthInterceptor()).build()

val baseRetrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.client(interceptorClient)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.build()
}

val followerRetrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl(FOLLOWER_URL)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.build()
}

inline fun <reified T> createBaseRetrofit(): T = baseRetrofit.create()
inline fun <reified T> createFollowerRetrofit(): T = followerRetrofit.create()
}

object ServicePool {
val authService = ApiFactory.createBaseRetrofit<AuthService>()
val followerService = ApiFactory.createFollowerRetrofit<FollowerService>()
}
17 changes: 17 additions & 0 deletions app/src/main/java/com/sopt/now/data/module/AuthInterceptor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sopt.now.data.module

import okhttp3.Interceptor
import okhttp3.Response

class AuthInterceptor : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {
val originalRequest = chain.request()

val newRequest = originalRequest.newBuilder()
.addHeader("memberId", "495")
.build()

return chain.proceed(newRequest)
}
}
27 changes: 27 additions & 0 deletions app/src/main/java/com/sopt/now/data/network/AuthService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.sopt.now.data.network

import com.sopt.now.data.model.RequestSignInDto
import com.sopt.now.data.model.RequestSignUpDto
import com.sopt.now.data.model.ResponseInfoDto
import com.sopt.now.data.model.ResponseSignInDto
import com.sopt.now.data.model.ResponseSignUpDto
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST

interface AuthService {
@POST("member/join")
fun signUp(
@Body request: RequestSignUpDto,
): Call<ResponseSignUpDto>

@POST("member/login")
fun signIn(
@Body request: RequestSignInDto,
): Call<ResponseSignInDto>

@GET("member/info")
fun memberInfo(
): Call<ResponseInfoDto>
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/sopt/now/data/network/FollowerService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.sopt.now.data.network

import com.sopt.now.data.model.UserDataResponse
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Query

interface FollowerService {
@GET("/api/users")
fun getUserList(
@Query("page") page: Int,
): Call<UserDataResponse>
}
10 changes: 7 additions & 3 deletions app/src/main/java/com/sopt/now/ui/adapter/ItemAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.sopt.now.data.ItemData
import com.bumptech.glide.Glide
import com.sopt.now.data.model.ItemData
import com.sopt.now.databinding.ItemFriendBinding
import com.sopt.now.databinding.ItemMyProfileBinding

Expand Down Expand Up @@ -47,9 +48,12 @@ class ItemAdapter(private val items: MutableList<ItemData>) : RecyclerView.Adapt
}

is ItemData.Friend -> {
(holder as FriendViewHolder).profileImage.setImageResource(item.profileImage!!)
holder.name.text = item.name
(holder as FriendViewHolder).name.text = item.name
holder.description.text = item.description
Glide.with(holder.profileImage.context)
.load(item.profileImage)
.into(holder.profileImage)

holder.itemView.setOnClickListener {
itemClick?.onItemClick(it, position)
}
Expand Down
Loading