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

REFACTOR/xml 04 서버통신 #16

Open
wants to merge 25 commits into
base: develop-xml
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
975a331
[Del] : 파일 삭제
hyoeunjoo May 24, 2024
505b669
[feat] : 데이터 구조 변경
hyoeunjoo May 24, 2024
edb7692
[mod] : Friend 데이터 구조 변경
hyoeunjoo May 24, 2024
45e1a01
[mod] : HomeFragment 구조 변경
hyoeunjoo May 24, 2024
afc9148
[mod] : Login ViewModel 분리
hyoeunjoo May 24, 2024
d6c1422
[CHORE] : 코드 정리
hyoeunjoo May 24, 2024
f996c6e
[MOD] : Dto 구조 변경
hyoeunjoo May 24, 2024
804bf83
[MOD] : 파일 구조 변경
hyoeunjoo May 24, 2024
d17144f
[MOD] : mbti를 phone으로 변경
hyoeunjoo May 24, 2024
7449c36
[FEAT] : SignUp ViewModel 분리
hyoeunjoo May 24, 2024
cf5d656
[FEAT] : USER 데이터 구조 변경
hyoeunjoo May 24, 2024
b1fd230
[CHORE] : 코드 정리
hyoeunjoo May 24, 2024
d5b0160
[CHORE] : 코드 정리
hyoeunjoo May 30, 2024
9caf82f
[CHORE] : 코드 정리
hyoeunjoo May 30, 2024
276c39b
[CHORE] : 코드 정리
hyoeunjoo May 30, 2024
d67b3cd
[Mod] : MutableLiveData로 변경
hyoeunjoo May 30, 2024
2f25711
[add] : FriendBaseUrl 추가
hyoeunjoo Jun 27, 2024
63b6d4f
[feat] : friend list를 담을 item 생성
hyoeunjoo Jun 27, 2024
7fb5a64
[feat] : friend list DTO 생성
hyoeunjoo Jun 27, 2024
4cc3752
[feat] : search fragment
hyoeunjoo Jun 27, 2024
172002c
[mod] : 코드 수정
hyoeunjoo Jun 27, 2024
6a5d222
[feat] : Friend List Adapter 생성 및 적용
hyoeunjoo Jun 27, 2024
ceecbf9
[feat] : Friend List Service, ServiceImpl
hyoeunjoo Jun 27, 2024
0c51730
[feat] : SearchFragment에 붙이기
hyoeunjoo Jun 27, 2024
08df996
[mod] : clean architecture 적용
hyoeunjoo Jun 27, 2024
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
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ android {

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "String", "AUTH_BASE_URL", properties["base.url"]
buildConfigField "String", "FRIEND_BASE_URL", properties["friend.base.url"]

}

buildTypes {
Expand Down Expand Up @@ -71,5 +73,8 @@ dependencies {
// define any required OkHttp artifacts without version
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9")

implementation 'com.google.android.gms:play-services-location:21.2.0'
implementation "io.coil-kt:coil:0.11.0"
}
17 changes: 8 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?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" />
<!-- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />-->

<application
android:allowBackup="true"
Expand All @@ -12,24 +14,21 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NOWSOPTAndroid"
tools:targetApi="31"
android:usesCleartextTraffic="true">
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".LoginActivity"
android:name=".presentation.MainActivity"
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=".MainActivity"
android:exported="false"></activity>
android:name=".presentation.Login.LoginActivity"
android:exported="false" />
<activity
android:name=".SignUpActivity"
android:name=".presentation.SignUpActivity"
android:exported="false" />
</application>

Expand Down
20 changes: 0 additions & 20 deletions app/src/main/java/com/sopt/now/Home/SearchFragment.kt

This file was deleted.

40 changes: 0 additions & 40 deletions app/src/main/java/com/sopt/now/LoginViewModel.kt

This file was deleted.

42 changes: 0 additions & 42 deletions app/src/main/java/com/sopt/now/SignUpViewModel.kt

This file was deleted.

121 changes: 121 additions & 0 deletions app/src/main/java/com/sopt/now/Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//package com.sopt.now
//
//import android.content.pm.PackageManager
//import android.location.Location
//import android.os.Bundle
//import android.os.PersistableBundle
//import android.widget.Toast
//import androidx.activity.result.ActivityResultLauncher
//import androidx.activity.result.contract.ActivityResultContracts
//import androidx.appcompat.app.AlertDialog
//import androidx.appcompat.app.AppCompatActivity
//import androidx.core.app.ActivityCompat
//import androidx.core.content.ContextCompat
//import com.google.android.gms.location.FusedLocationProviderClient
//import com.google.android.gms.location.LocationServices
//import com.sopt.now.databinding.ActivityLoginBinding
//import com.sopt.now.databinding.ActivityTestBinding
//
////class TestActivity : AppCompatActivity(){
//// private lateinit var binding: ActivityTestBinding
////
//// override fun onCreate(savedInstanceState: Bundle?) {
//// super.onCreate(savedInstanceState)
//// binding = ActivityTestBinding.inflate(layoutInflater)
//// setContentView(binding.root)
//// }
////}
//
//class TestActivity : AppCompatActivity() {
//
// private lateinit var binding: ActivityTestBinding
// private lateinit var fusedLocationClient: FusedLocationProviderClient
// private lateinit var requestPermissionLauncher: ActivityResultLauncher<String>
//
// override fun onCreate(savedInstanceState: Bundle?) {
// super.onCreate(savedInstanceState)
// binding = ActivityTestBinding.inflate(layoutInflater)
// setContentView(binding.root)
//
// // 위치 제공자 초기화
// fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
//
// // 권한 요청 런처 초기화
// requestPermissionLauncher =
// registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean ->
// if (isGranted) {
// // 권한이 허용된 경우 위치 정보 가져오기
// getLastKnownLocation()
// } else {
// // 권한이 거부된 경우 처리
// showPermissionDeniedMessage()
// }
// }
//
// binding.getLocationButton.setOnClickListener {
// checkPermissionAndRequestLocation()
// }
// }
//
// private fun checkPermissionAndRequestLocation() {
// when {
// ContextCompat.checkSelfPermission(
// this,
// android.Manifest.permission.ACCESS_FINE_LOCATION
// ) == PackageManager.PERMISSION_GRANTED -> {
// // 권한이 이미 허용된 경우
// getLastKnownLocation()
// }
//
// ActivityCompat.shouldShowRequestPermissionRationale(
// this,
// android.Manifest.permission.ACCESS_FINE_LOCATION
// ) -> {
// // 권한 요청 이유 설명이 필요한 경우
// showRationaleDialog()
// }
//
// else -> {
// // 권한 요청
// requestPermissionLauncher.launch(android.Manifest.permission.ACCESS_FINE_LOCATION)
// }
// }
// }
//
// private fun getLastKnownLocation() {
// if (ActivityCompat.checkSelfPermission(
// this,
// android.Manifest.permission.ACCESS_FINE_LOCATION
// ) == PackageManager.PERMISSION_GRANTED
// ) {
// fusedLocationClient.lastLocation
// .addOnSuccessListener { location: Location? ->
// // 위치 정보를 성공적으로 가져온 경우
// if (location != null) {
// binding.locationTextView.text =
// "위도: ${location.latitude}, 경도: ${location.longitude}"
// } else {
// binding.locationTextView.text = "위치 정보를 가져올 수 없습니다."
// }
// }
// }
// }
//
// private fun showRationaleDialog() {
// // 권한 요청 이유를 사용자에게 설명하는 다이얼로그 등을 표시
// // 예시: AlertDialog를 사용하여 권한 요청 이유 설명
// AlertDialog.Builder(this)
// .setTitle("권한 필요")
// .setMessage("위치 정보를 가져오려면 위치 접근 권한이 필요합니다.")
// .setPositiveButton("확인") { _, _ ->
// requestPermissionLauncher.launch(android.Manifest.permission.ACCESS_FINE_LOCATION)
// }
// .setNegativeButton("취소", null)
// .show()
// }
//
// private fun showPermissionDeniedMessage() {
// // 권한 거부 시 사용자에게 표시할 메시지
// Toast.makeText(this, "권한이 거부되었습니다. 위치 정보를 가져올 수 없습니다.", Toast.LENGTH_SHORT).show()
// }
//}
31 changes: 31 additions & 0 deletions app/src/main/java/com/sopt/now/data/AuthRepoImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.sopt.now.data

import com.sopt.now.data.api.AuthService
import com.sopt.now.data.dto.LoginDto.RequestLogInDto
import com.sopt.now.data.dto.SignUp.RequestSignUpDto
import com.sopt.now.domain.AuthRepository
import com.sopt.now.domain.model.AuthEntity
import retrofit2.Response

class AuthRepoImpl(
private val authService: AuthService,
) : AuthRepository {
override suspend fun logIn(authData: AuthEntity): Result<Response<Unit>> = runCatching {
authService.logIn(
request = RequestLogInDto(
authenticationId = authData.id,
password = authData.pw
)
)
}
override suspend fun signUp(authData: AuthEntity): Result<Response<Unit>> = runCatching {
authService.signUp(
RequestSignUpDto(
authenticationId = authData.id,
password = authData.pw,
nickname = authData.name ?: "",
phone = authData.phone ?: ""
)
)
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
package com.sopt.now.api
package com.sopt.now.data.api

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.sopt.now.BuildConfig
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit

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

private const val FRIEND_BASE_URL: String = BuildConfig.FRIEND_BASE_URL

val loggingInterceptor = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}

val client = OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.build()

val retrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.baseUrl(FRIEND_BASE_URL)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.build()
}
Expand All @@ -21,4 +34,5 @@ object ApiFactory {

object ServicePool {
val authService = ApiFactory.create<AuthService>()
val friendListService = ApiFactory.create<FriendListService>()
}
Loading