Skip to content

Commit

Permalink
[MIN-44] feat: 초기 유저 정보 , 코드 POST 구현(#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
KDW03 committed Feb 9, 2023
1 parent cdefdf3 commit 6c59fd7
Show file tree
Hide file tree
Showing 36 changed files with 615 additions and 100 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {

dependencies {

api project(path: ':common-ui')

api project(path: ':story')
api project(path: ':home')
api project(path: ':setting')
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
<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>
<meta-data
android:name="android.app.lib_name"
android:value="" />
Expand Down
20 changes: 0 additions & 20 deletions app/src/main/java/com/najudoryeong/mineme/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,6 @@ class MainActivity : AppCompatActivity(), MainActivityUtil {
initAppBar()
initBottomNav()

setStartDestination(isLogin())

}


/**
* login 여부에 따른 startDestination 조작을 위해
* main graph를 가져와서 startDestination을 조작 후 변경내용을 적용한다.
* */

private fun setStartDestination(isLogin: Boolean) {
val navGraph = navController.navInflater.inflate(R.navigation.nav_main)
if (isLogin) navGraph.setStartDestination(R.id.nav_home)
else navGraph.setStartDestination(com.najudoryeong.mineme.onboarding.R.id.nav_onboarding)
navController.setGraph(navGraph, null)
}

// todo 로그인 체크 로직
private fun isLogin(): Boolean {
return true
}

private fun initBottomNav() {
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/najudoryeong/mineme/MineMeApplication.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package com.najudoryeong.mineme

import android.app.Application
import android.util.Log
import com.example.common.util.NATIVE_APP_KEY
import com.kakao.sdk.common.KakaoSdk
import com.kakao.sdk.common.util.Utility
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class MineMeApplication : Application() {
override fun onCreate() {
super.onCreate()
KakaoSdk.init(this, NATIVE_APP_KEY)
//printAppKeyHash()
}

private fun printAppKeyHash() {
val keyHash = Utility.getKeyHash(this)
Log.d("KeyHash", keyHash)
}
}
1 change: 0 additions & 1 deletion app/src/main/res/navigation/nav_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
android:id="@+id/nav_graph"
app:startDestination="@id/nav_home">
<include app:graph="@navigation/nav_home" />
<include app:graph="@navigation/nav_onboarding" />
<include app:graph="@navigation/nav_story" />
<include app:graph="@navigation/nav_setting" />
</navigation>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.najudoryeong.mineme.common_ui

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import com.najudoryeong.mineme.common_ui.databinding.DialogForPermissionBinding

class DialogForPermission(
context: Context,
private val message: String,
private val imgId: Int,
private val onClickButton: () -> Unit
) : Dialog(context){

private lateinit var binding: DialogForPermissionBinding


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DialogForPermissionBinding.inflate(layoutInflater).apply {
dialogTv.text = message
dialogIv.setImageResource(imgId)
dialogButton.setOnClickListener {
onClickButton.invoke()
dismiss()
}
}
setContentView(binding.root)

window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
}

class Builder(private val context: Context) {
private var message = ""
private var imgId = 0
private var onClickButton = {}

fun setMessage(message: String) = apply {
this.message = message
}

fun setImg(imgId: Int) = apply {
this.imgId = imgId
}

fun setOnClickButton(onClickButton: () -> Unit) = apply {
this.onClickButton = onClickButton
}

fun build() = DialogForPermission(
context,
message,
imgId,
onClickButton
)
}
}
66 changes: 66 additions & 0 deletions common-ui/src/main/res/layout/dialog_for_permission.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<androidx.cardview.widget.CardView
android:layout_width="300dp"
android:layout_height="240dp"
android:layout_margin="8dp"
app:cardCornerRadius="@dimen/dialog_radius">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="26dp">

<ImageView
android:id="@+id/dialog_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/dialog_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:gravity="center"
android:lineSpacingExtra="@dimen/basic_spacingExtra"
android:text="위치 권한 요청합니다"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/dialog_iv" />

<com.google.android.material.button.MaterialButton
android:id="@+id/dialog_button"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="17dp"
android:text="@string/confirm"
android:textSize="@dimen/basic_btn_textSize"
app:layout_constraintTop_toBottomOf="@id/dialog_tv" />

<TextView
android:id="@+id/dialog_info_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="확인을 누르시면 동의 및 다음 단계로 넘어갑니다."
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/dialog_button" />

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>

</FrameLayout>
</layout>
3 changes: 3 additions & 0 deletions common-ui/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<resources>
<dimen name="margin_normal">21dp</dimen>
<dimen name="btn_corner">21dp</dimen>
<dimen name="dialog_radius">17dp</dimen>
<dimen name="basic_spacingExtra">4sp</dimen>
<dimen name="basic_btn_textSize">17sp</dimen>
</resources>
2 changes: 1 addition & 1 deletion common-ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="app_name">mineme</string>
<string name="next">다음</string>
<string name="confirm">확인</string>
</resources>
1 change: 0 additions & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ dependencies {
// Preferences DataStore
implementation("androidx.datastore:datastore-preferences:$rootProject.dataStorePreferences_version")


api "com.kakao.sdk:v2-all:$rootProject.kakao_version"

// Hilt
Expand Down
7 changes: 7 additions & 0 deletions common/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.common.data.dto

data class CodeRequest(
val code : String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.common.data.dto

data class NullResponse(
val success: Boolean,
val data: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.common.data.dto

data class UserInfoRequest(
val nickname: String,
val birthday: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.common.data.entity

enum class ProviderType(providerType: String) {
KAKAO("KAKAO")
}
25 changes: 25 additions & 0 deletions common/src/main/java/com/example/common/data/source/UserService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.common.data.source

import com.example.common.data.dto.CodeRequest
import com.example.common.data.dto.UserInfoRequest
import com.example.common.data.dto.NullResponse
import retrofit2.http.Body
import retrofit2.http.Header
import retrofit2.http.POST

interface UserService {

@POST("api/v1/user/info")
suspend fun postUserInfo(
@Header("Authorization") token : String,
@Body userInfoRequest: UserInfoRequest
) : NullResponse


@POST("api/v1/user/code")
suspend fun postTargetCode(
@Header("Authorization") token : String,
@Body userCodeRequest: CodeRequest
) : NullResponse

}
6 changes: 6 additions & 0 deletions common/src/main/java/com/example/common/di/NetworkModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.common.di

import com.example.common.data.source.AuthService
import com.example.common.data.source.UserService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -19,5 +20,10 @@ class NetworkModule {
return retrofit.create(AuthService::class.java)
}

@Singleton
@Provides
fun provideUserService(retrofit: Retrofit): UserService {
return retrofit.create(UserService::class.java)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class DataStoreUseCase @Inject constructor(
val bearerJsonWebToken: Flow<String?> =
dataStore.data.map { preferences -> preferences[jsonWebToken_key]?.toBearerToken() }

val myCode: Flow<String?> =
dataStore.data.map { preferences -> preferences[user_code] }

val permissionNum: Flow<Int?> =
dataStore.data.map { preferences -> preferences[permission_num] }
Expand All @@ -32,6 +34,12 @@ class DataStoreUseCase @Inject constructor(
}
}

suspend fun editUserCode(userCode: String) {
dataStore.edit {
it[user_code] = userCode
}
}

suspend fun editPermissionNum(num: Int) {
dataStore.edit {
it[permission_num] = num
Expand All @@ -44,6 +52,7 @@ class DataStoreUseCase @Inject constructor(

private val jsonWebToken_key = stringPreferencesKey("JSON_WEB_TOKEN")
private val permission_num = intPreferencesKey("PERMISSION_NUM")
private val user_code = stringPreferencesKey("USER_CODE")
}

}
4 changes: 4 additions & 0 deletions home/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ android {

dependencies {

api project(path: ':common-ui')
api project(path: ':common')


// Hilt
implementation "com.google.dagger:hilt-android:$rootProject.hiltVersion"
kapt "com.google.dagger:hilt-android-compiler:$rootProject.hiltVersion"
Expand Down
3 changes: 2 additions & 1 deletion onboarding/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
defaultConfig {
minSdk 23
targetSdk 33

manifestPlaceholders["NATIVE_APP_KEY"] = "5162225c94277a85e12566f227145303"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
Expand All @@ -40,6 +40,7 @@ android {
dependencies {

api project(path: ':common-ui')
api project(path: ':common')

// Hilt
implementation "com.google.dagger:hilt-android:$rootProject.hiltVersion"
Expand Down
Loading

0 comments on commit 6c59fd7

Please sign in to comment.