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

dev_android 싱크 main #555

Merged
merged 1 commit into from
Nov 8, 2023
Merged
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
6 changes: 5 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />

<application
android:name=".NaagaApplication"
Expand Down
6 changes: 0 additions & 6 deletions android/app/src/main/java/com/now/naaga/NaagaApplication.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.now.naaga

import android.app.Application
import androidx.appcompat.app.AppCompatDelegate
import com.kakao.sdk.common.KakaoSdk
import com.now.naaga.data.local.AuthDataSource
import com.now.naaga.data.local.DefaultAuthDataSource
Expand All @@ -14,11 +13,6 @@ class NaagaApplication : Application() {
super.onCreate()
initKakaoSdk()
initDataSources()
disableDarkMode()
}

private fun disableDarkMode() {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}

private fun initKakaoSdk() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class AuthInterceptor : Interceptor {
private const val AUTH_KEY = "Authorization"
private const val AUTH_REFRESH_KEY = "refreshToken"

private const val AUTH_REFRESH_PATH = "/auth/refresh"
private const val AUTH_REFRESH_PATH = "auth/refresh"

private const val BEARER = "Bearer "

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.now.naaga.databinding.ActivityAdventureDetailBinding
import com.now.naaga.presentation.adventuredetail.viewpager.ViewPagerAdapter
import com.now.naaga.presentation.uimodel.model.LetterUiModel
import com.now.naaga.util.extension.repeatOnStarted
import com.now.naaga.util.extension.showSnackbarWithEvent
import com.now.naaga.util.extension.showShortSnackbarWithEvent
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down Expand Up @@ -66,7 +66,7 @@ class AdventureDetailActivity : AppCompatActivity(), AnalyticsDelegate by Defaul
}

private fun showReRequestSnackbar() {
binding.root.showSnackbarWithEvent(
binding.root.showShortSnackbarWithEvent(
message = getString(R.string.snackbar_action_re_request_message),
actionTitle = getString(R.string.snackbar_action__re_request_title),
) { finish() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ class AdventureResultActivity : AppCompatActivity(), AnalyticsDelegate by Defaul

viewModel.throwable.observe(this) { throwable: DataThrowable ->
when (throwable.code) {
DataThrowable.NETWORK_THROWABLE_CODE -> { showToast(getString(R.string.network_error_message)) }
DataThrowable.NETWORK_THROWABLE_CODE -> showToast(getString(R.string.network_error_message))
}
}

viewModel.preference.observe(this) {
binding.customAdventureResultPreference.updatePreference(it.state)
binding.customAdventureResultPreference.likeCount = it.likeCount.value
binding.customAdventureResultPreference.updatePreference(it)
}
}

Expand Down Expand Up @@ -102,14 +101,15 @@ class AdventureResultActivity : AppCompatActivity(), AnalyticsDelegate by Defaul
finish()
}

binding.customAdventureResultPreference.setPreferenceClickListener {
binding.customAdventureResultPreference.setPreferenceClickListener(CLICK_INTERVAL_TIME) {
viewModel.changePreference(it)
}
}

companion object {
private const val GAME_ID = "GAME_ID"
private const val MESSAGE_IN_RESULT_TYPE_NONE = "네트워크에 문제가 생겼습니다."
private const val CLICK_INTERVAL_TIME = 500L

fun getIntentWithGameId(context: Context, gameId: Long): Intent {
return Intent(context, AdventureResultActivity::class.java).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ class AdventureResultViewModel @Inject constructor(
requireNotNull(adventureResult.value) { "adventureResult가 null입니다." }.destination.id.toInt(),
requireNotNull(preference.value) { "preference가 null입니다." }.state,
)
}.onSuccess {
// post 응답이 성공적으로 왔는데 내가 보낸 것과 다른게 온 경우. 즉 말이 안되는 경우
if (preference.value?.state != it) {
_preference.value = Preference(state = it)
}
}.onFailure {
_preference.value = preference.value?.revert()
setThrowable(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.now.domain.model.Preference
import com.now.domain.model.PreferenceState
import com.now.naaga.R
import com.now.naaga.databinding.CustomPreferenceViewBinding
Expand All @@ -13,10 +14,12 @@ class PreferenceView(context: Context, attrs: AttributeSet? = null) : Constraint
private val binding: CustomPreferenceViewBinding
private val layoutInflater = LayoutInflater.from(this.context)
private var preferenceClickListener: PreferenceClickListener? = null
var likeCount: Int = 0
private var lastClickTime = 0L
private var clickIntervalTime = 0L
private var myPreference: Preference = Preference()
set(value) {
field = value
binding.tvPreferenceLikeCount.text = value.toString()
binding.tvPreferenceLikeCount.text = value.likeCount.value.toString()
}

init {
Expand All @@ -37,10 +40,18 @@ class PreferenceView(context: Context, attrs: AttributeSet? = null) : Constraint

private fun setClickListeners() {
binding.ivPreferenceLike.setOnClickListener {
preferenceClickListener?.onClick(PreferenceState.LIKE)
singleClick(PreferenceState.LIKE)
}
binding.ivPreferenceDislike.setOnClickListener {
preferenceClickListener?.onClick(PreferenceState.DISLIKE)
singleClick(PreferenceState.DISLIKE)
}
}

private fun singleClick(state: PreferenceState) {
val current = System.currentTimeMillis()
if (current - lastClickTime > clickIntervalTime) {
lastClickTime = current
preferenceClickListener?.onClick(state)
}
}

Expand All @@ -55,12 +66,14 @@ class PreferenceView(context: Context, attrs: AttributeSet? = null) : Constraint
binding.tvPreferenceLikeCount.visibility = setVisibility(isLikeCountVisible)
}

fun setPreferenceClickListener(listener: PreferenceClickListener) {
fun setPreferenceClickListener(clickIntervalTime: Long = 0, listener: PreferenceClickListener) {
this.clickIntervalTime = clickIntervalTime
preferenceClickListener = listener
}

fun updatePreference(preferenceState: PreferenceState) {
when (preferenceState) {
fun updatePreference(preference: Preference) {
myPreference = preference
when (preference.state) {
PreferenceState.LIKE -> {
binding.ivPreferenceLike.isSelected = true
binding.ivPreferenceDislike.isSelected = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.now.naaga.presentation.onadventure.OnAdventureActivity
import com.now.naaga.presentation.setting.SettingActivity
import com.now.naaga.presentation.upload.UploadActivity
import com.now.naaga.util.extension.openSetting
import com.now.naaga.util.extension.showSnackbarWithEvent
import com.now.naaga.util.extension.showShortSnackbarWithEvent
import com.now.naaga.util.extension.showToast
import dagger.hilt.android.AndroidEntryPoint

Expand Down Expand Up @@ -116,7 +116,7 @@ class BeginAdventureActivity : AppCompatActivity(), AnalyticsDelegate by Default
}

private fun showPermissionSnackbar() {
binding.root.showSnackbarWithEvent(
binding.root.showShortSnackbarWithEvent(
message = getString(R.string.snackbar_location_message),
actionTitle = getString(R.string.snackbar_action_title),
action = { openSetting() },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package com.now.naaga.presentation.custom

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Point
import android.graphics.RectF
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.annotation.ColorInt
import androidx.appcompat.widget.AppCompatButton
import androidx.core.content.ContextCompat
import com.now.naaga.R

class GameButton(context: Context, attrs: AttributeSet? = null) : AppCompatButton(context, attrs) {
private val radius: Float
private var isClicked: Boolean = false
private var clickAction: OnClickListener? = null

@ColorInt
private val mainColor: Int

@ColorInt
val firstShadowColor: Int

@ColorInt
val middleColor: Int

@ColorInt
val secondShadowColor: Int

@ColorInt
private val bottomColor: Int

init {
context.theme.obtainStyledAttributes(
attrs,
R.styleable.GameButton,
0,
0,
).apply {
radius = getDimensionPixelSize(R.styleable.GameButton_radius, 0).toFloat()
val gameButtonColor = GameButtonColor.getColor(getInteger(R.styleable.GameButton_buttonColor, 0))
mainColor = ContextCompat.getColor(context, gameButtonColor.mainColor)
firstShadowColor = ContextCompat.getColor(context, gameButtonColor.firstShadowColor)
middleColor = ContextCompat.getColor(context, gameButtonColor.middleColor)
secondShadowColor = ContextCompat.getColor(context, gameButtonColor.secondShadowColor)
bottomColor = ContextCompat.getColor(context, gameButtonColor.bottomColor)
recycle()
}
}

private fun getPaint(color: Int) = Paint().apply {
this.color = color
}

private val ripplePaint = Paint().apply {
this.color = ContextCompat.getColor([email protected], R.color.custom_button_ripple)
}

override fun onDraw(canvas: Canvas) {
setBackgroundColor(Color.TRANSPARENT)
drawButton(canvas)
if (isClicked) drawRipple(canvas)
super.onDraw(canvas)
}

override fun onTouchEvent(event: MotionEvent): Boolean {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
isClicked = true
invalidate()
}

MotionEvent.ACTION_UP -> {
isClicked = false
invalidate()
if (isClickInsideButton(Point(event.x.toInt(), event.y.toInt()))) {
clickAction?.onClick(this)
}
}
}
return true
}

override fun setOnClickListener(l: OnClickListener?) {
clickAction = l
}

private fun isClickInsideButton(point: Point): Boolean {
val isXInside = point.x in 0..this.width
val isYInside = point.y in 0..this.height
return isXInside && isYInside
}

private fun drawRipple(canvas: Canvas) {
canvas.drawRoundRect(getBottomRect(), radius, radius, ripplePaint)
}

private fun drawButton(canvas: Canvas) {
with(canvas) {
drawRoundRect(getBottomRect(), radius, radius, getPaint(bottomColor))
drawRoundRect(getSecondShadowRect(), radius, radius, getPaint(secondShadowColor))
drawRoundRect(getMiddleRect(), radius, radius, getPaint(middleColor))
drawRoundRect(getFirstShadowRect(), radius, radius, getPaint(firstShadowColor))
drawRoundRect(getMainRect(), radius, radius, getPaint(mainColor))
}
}

// 161 x 84 (0,0)
private fun getBottomRect(): RectF {
return RectF(0f, 0f, width.toFloat(), height.toFloat())
}

// 160 x 79 (0,0)
private fun getSecondShadowRect(): RectF {
return RectF(0f, 0f, width.toFloat(), (height * 0.94).toFloat())
}

// 158 x 77 (1,1)
private fun getMiddleRect(): RectF {
val middleWidth = (width * 0.987).toFloat()
val middleHeight = (height * 0.916).toFloat()
val start = (width * 0.006).toFloat()
val end = start + middleWidth
val top = (height * 0.01).toFloat()
val bottom = top + middleHeight
return RectF(start, top, end, bottom)
}

// 155 x 72 (2,2)
private fun getFirstShadowRect(): RectF {
val width = (this.width * 0.96).toFloat()
val height = (this.height * 0.86).toFloat()
val start = (this.width * 0.018).toFloat()
val end = start + width
val top = (this.height * 0.02).toFloat()
val bottom = top + height
return RectF(start, top, end, bottom)
}

// 154 x 70 (2,2)
private fun getMainRect(): RectF {
val width = (this.width * 0.96).toFloat()
val height = (this.height * 0.83).toFloat()
val start = (this.width * 0.018).toFloat()
val end = start + width
val top = (this.height * 0.02).toFloat()
val bottom = top + height
return RectF(start, top, end, bottom)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.now.naaga.presentation.custom

import androidx.annotation.ColorRes
import com.now.naaga.R

enum class GameButtonColor(
@ColorRes val mainColor: Int,
@ColorRes val firstShadowColor: Int,
@ColorRes val middleColor: Int,
@ColorRes val secondShadowColor: Int,
@ColorRes val bottomColor: Int,
) {
YELLOW(
R.color.custom_button_yellow_main,
R.color.custom_button_yellow_first_shadow,
R.color.custom_button_yellow_middle,
R.color.custom_button_yellow_second_shadow,
R.color.custom_button_yellow_bottom,
),
BLUE(
R.color.custom_button_blue_main,
R.color.custom_button_blue_first_shadow,
R.color.custom_button_blue_middle,
R.color.custom_button_blue_second_shadow,
R.color.custom_button_blue_bottom,
), ;

companion object {
fun getColor(ordinal: Int): GameButtonColor {
return values().find { it.ordinal == ordinal } ?: YELLOW
}
}
}
Loading
Loading