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

[FEAT/#100] 여행 입장 뷰 / 카카오톡 공유 구현 #143

Merged
merged 5 commits into from
Jan 16, 2024
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
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,6 @@ dependencies {

KakaoDependencies.run {
implementation(user)
implementation(share)
}
}
13 changes: 11 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,17 @@

<activity
android:name="com.going.presentation.entertrip.createtrip.finish.FinishTripActivity"
android:exported="false"
android:screenOrientation="portrait" />
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:host="kakaolink"
android:scheme="kakao${NATIVE_APP_KEY}" />
</intent-filter>
</activity>

<activity
android:name="com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity"
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,5 @@ object FirebaseDependencies {

object KakaoDependencies {
const val user = "com.kakao.sdk:v2-user:${Versions.kakaoVersion}"
const val share = "com.kakao.sdk:v2-share:${Versions.kakaoVersion}"
}
1 change: 1 addition & 0 deletions presentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ dependencies {

KakaoDependencies.run {
implementation(user)
implementation(share)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@ class BottomSheetDateContentFragment(val viewModel: CreateTripViewModel, val isS

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

destroyToast()
initFinishBtnClickListener()
}


private fun destroyToast() {
dialog?.setOnDismissListener {
binding.tvErrorToast.visibility = View.GONE
}
}

private fun sendDateInfo() {
if (isStart) {
viewModel.startYear.value = binding.dpCreateTripDate.year
Expand All @@ -41,6 +50,7 @@ class BottomSheetDateContentFragment(val viewModel: CreateTripViewModel, val isS
binding.btnCreateTripFinish.setOnSingleClickListener {
sendDateInfo()
if (viewModel.isStartDateAvailable.value == true && viewModel.isEndDateAvailable.value == true) {

val calendar = Calendar.getInstance()

calendar.set(Calendar.YEAR, viewModel.startYear.value ?: 0)
Expand All @@ -53,13 +63,20 @@ class BottomSheetDateContentFragment(val viewModel: CreateTripViewModel, val isS
calendar.set(Calendar.DAY_OF_MONTH, viewModel.endDay.value ?: 0)
val endDate = calendar.time

if (startDate.before(endDate)) {
if (startDate.before(endDate) || startDate.equals(endDate)) {
viewModel.checkStartDateAvailable()
viewModel.checkEndDateAvailable()
dismiss()
} else {
viewModel.startYear.value = null
viewModel.endYear.value = null
viewModel.checkStartDateAvailable()
viewModel.checkEndDateAvailable()
Comment on lines +71 to +74
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반복되는 친구는 스코프로 묶어보아요~


binding.viewBlank.visibility = View.VISIBLE
binding.tvErrorToast.visibility = View.VISIBLE
Handler(Looper.getMainLooper()).postDelayed({
binding.tvErrorToast.visibility = View.INVISIBLE
binding.tvErrorToast.visibility = View.GONE
}, 2000)
}
} else {
Expand All @@ -68,3 +85,6 @@ class BottomSheetDateContentFragment(val viewModel: CreateTripViewModel, val isS
}
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class CreateTripViewModel : ViewModel() {
checkTripAvailable()
} else {
isStartDateAvailable.value = false
checkTripAvailable()
}
}

Expand All @@ -58,6 +59,8 @@ class CreateTripViewModel : ViewModel() {
checkTripAvailable()
} else {
isEndDateAvailable.value = false
checkTripAvailable()

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.going.presentation.entertrip.createtrip.finish

import android.content.ActivityNotFoundException
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
Expand All @@ -13,17 +14,23 @@ import com.going.presentation.entertrip.invitetrip.finish.InviteFinishActivity.C
import com.going.presentation.entertrip.invitetrip.finish.InviteFinishActivity.Companion.TRIP_FORMAT
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.DAY
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.END
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.INVITE_CODE
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.START
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.TITLE
import com.going.presentation.util.initOnBackPressedListener
import com.going.ui.base.BaseActivity
import com.going.ui.extension.setOnSingleClickListener
import com.kakao.sdk.auth.Constants.CODE
import com.kakao.sdk.common.util.KakaoCustomTabsClient
import com.kakao.sdk.share.ShareClient
import com.kakao.sdk.share.WebSharerClient
import timber.log.Timber


class FinishTripActivity :
BaseActivity<ActivityFinishTripBinding>(R.layout.activity_finish_trip) {

private var inviteCode: String = ""
private var title: String = ""

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -46,7 +53,51 @@ class FinishTripActivity :

private fun initSendCodeBtnClickListener() {
binding.btnFinishTripSendCode.setOnSingleClickListener {
// TODO : 카카오톡으로 초대코드 보내기
startKakaoInvite(this)
}
}

private fun startKakaoInvite(context: Context) {
val test = HashMap<String, String>()
test.put("KEY", inviteCode)
test.put("NAME", title)
Comment on lines +62 to +63
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 키값들도 const val로 두면 더 좋을 것 같아요~!


if (ShareClient.instance.isKakaoTalkSharingAvailable(context)) {
ShareClient.instance.shareCustom(
context,
TEMPLATE_ID.toLong(),
hashMapOf(
"KEY" to inviteCode,
"NAME" to title
)
) { sharingResult, error ->
if (error != null) {
Timber.tag(TAG_SHARE).e(error, getString(R.string.invite_error_kakao))
} else if (sharingResult != null) {
startActivity(sharingResult.intent)
}
}
} else {
val sharerUrl =
WebSharerClient.instance.makeCustomUrl(
TEMPLATE_ID.toLong(),
hashMapOf(
"KEY" to inviteCode,
"NAME" to title
)
)
try {
KakaoCustomTabsClient.openWithDefault(context, sharerUrl)
return
} catch (error: UnsupportedOperationException) {
Timber.tag(TAG_SHARE).e(error, getString(R.string.invite_error_browser))
}
try {
KakaoCustomTabsClient.open(context, sharerUrl)
return
} catch (error: ActivityNotFoundException) {
Timber.tag(TAG_SHARE).e(error, getString(R.string.invite_error_browser))
}
}
}

Expand All @@ -62,15 +113,15 @@ class FinishTripActivity :

private fun getTripInfo() {
if (intent != null) {
val title = intent.getStringExtra(TITLE)
title = intent.getStringExtra(TITLE) ?: ""
val start = intent.getStringExtra(START)
val end = intent.getStringExtra(END)
val code = intent.getStringExtra(CODE)
inviteCode = intent.getStringExtra(INVITE_CODE) ?: ""
val day = intent.getIntExtra(DAY, 0)

binding.tvFinishTripName.text = title
binding.tvFinishTripDay.text = String.format(DATE_FORMAT, start, end)
binding.tvInviteCode.text = code
binding.tvInviteCode.text = inviteCode

if (day > 0) {
binding.tvFinishTripDayLeft.text = String.format(D_DAY_FORMAT, day)
Expand All @@ -79,4 +130,11 @@ class FinishTripActivity :
}
}
}

companion object {
const val TAG_SHARE = "recommendInvite"
const val TEMPLATE_ID = 102829
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import com.going.presentation.entertrip.createtrip.choosedate.CreateTripActivity
import com.going.presentation.entertrip.createtrip.choosedate.CreateTripActivity.Companion.START_MONTH
import com.going.presentation.entertrip.createtrip.choosedate.CreateTripActivity.Companion.START_YEAR
import com.going.presentation.entertrip.createtrip.finish.FinishTripActivity
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.CODE
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.DAY
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.END
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.INVITE_CODE
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.START
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.TITLE
import com.going.presentation.entertrip.preferencetag.PreferenceTagAdapter
Expand Down Expand Up @@ -58,6 +58,7 @@ class EnterPreferenceActivity :
initStartBtnClickListener()
getCreateTripInfo()
observeEnterPreferenceListState()

}

private fun initAdapter() {
Expand Down Expand Up @@ -107,7 +108,7 @@ class EnterPreferenceActivity :
putExtra(TITLE, state.data.title)
putExtra(START, state.data.startDate)
putExtra(END, state.data.endDate)
putExtra(CODE, state.data.code)
putExtra(INVITE_CODE, state.data.code)
putExtra(DAY, state.data.day)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class EnterTripActivity : BaseActivity<ActivityEnterTripBinding>(R.layout.activi
const val TITLE = "title"
const val START = "start"
const val END = "end"
const val CODE = "code"
const val INVITE_CODE = "code"
const val DAY = "day"
}
}
3 changes: 1 addition & 2 deletions presentation/src/main/res/layout/activity_create_trip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white_000"
tools:context=".entertrip.createtrip.choosedate.CreateTripActivity">
tools:context=".entertrip.invitetrip.invitecode.CreateTripActivity">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/tb_create_trip"
Expand Down Expand Up @@ -98,7 +98,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp"
android:text="@{@string/counter(viewModel.nameLength, viewModel.MAX_TRIP_LEN)}"
android:textColor="@color/gray_200"
app:layout_constraintEnd_toEndOf="@id/et_create_trip_name"
Expand Down
5 changes: 5 additions & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,9 @@
<string name="check_friends_preference_5_left">알차게</string>
<string name="check_friends_preference_5_right">여유롭게</string>

<!--kakao-link-share-->
<string name = "invite_error_kakao"> 카카오톡 초대코드 오류 </string>
<string name = "invite_error_browser"> 브라우저 오류 </string>


</resources>