Skip to content

Commit

Permalink
Merge pull request #93 from Team-Umbba/feat/#92
Browse files Browse the repository at this point in the history
[Feat/#92] 카카오톡 공유 메세지 커스텀
  • Loading branch information
ss99x2002 authored Jul 20, 2023
2 parents 449b774 + 4e13e7f commit d46a428
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 16 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ dependencies {
// Kakaologin
implementation 'com.kakao.sdk:v2-user:2.11.0'
implementation 'com.kakao.sdk:v2-share:2.11.0'
implementation "com.kakao.sdk:v2-link:2.4.2"

// EncryptedSharedPreferences
implementation "androidx.security:security-crypto:1.0.0"

// Splash
implementation 'androidx.core:core-splashscreen:1.0.0'
implementation "androidx.core:core-splashscreen:1.0.0"
}
16 changes: 15 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools"
package="com.sopt.umbba_android">

<queries>
<package android:name="com.kakao.talk" />
</queries>

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.INTERNET" />
Expand Down Expand Up @@ -79,6 +84,15 @@
android:name=".presentation.MainActivity"
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" />

<!-- "kakao${YOUR_NATIVE_APP_KEY}://kakaolink" 형식의 앱 실행 스킴을 설정하는데 사용 -->
<data android:host="kakaolink"
android:scheme="kakao${NATIVE_APP_KEY}" />
</intent-filter>
</activity>

<service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ data class InviteCodeResponseDto(
data class ParentChildData(
@SerialName("parentchild_id")
val parentChildId: Long,
@SerialName("is_match_finish")
val isMatchFinish: Boolean,
@SerialName("parentchild_users")
val parentChildUsers: List<UsersData>,
@SerialName("parentchild_relation")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package com.sopt.umbba_android.presentation.home

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.fragment.app.viewModels
import coil.load
import com.google.android.gms.tasks.OnCompleteListener
import com.google.firebase.messaging.FirebaseMessaging
import com.sopt.umbba_android.R
import com.sopt.umbba_android.data.model.response.HomeCaseResponseDto
import com.sopt.umbba_android.data.model.response.HomeResponseDto
import com.sopt.umbba_android.databinding.FragmentHomeBinding
import com.sopt.umbba_android.presentation.home.viewmodel.HomeViewModel
import com.sopt.umbba_android.presentation.qna.NoOpponentDialogFragment
Expand All @@ -29,9 +24,10 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home
}
private fun setClickEvent(responseCaseDto: HomeCaseResponseDto.HomeCaseData) {
binding.btnAnswer.setOnClickListener {
viewModel.getResponseCase()
when (responseCaseDto.responseCase) {
1 -> startActivity(Intent(requireActivity(), QuestionAnswerActivity::class.java))
2 -> showInviteDialog(responseCaseDto.inviteCode.toString())
2 -> showInviteDialog(responseCaseDto.inviteUserName.toString(), responseCaseDto.inviteCode.toString())
3 -> showNoOpponentDialog()
}
}
Expand All @@ -46,8 +42,8 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home
}
}

private fun showInviteDialog(inviteCode: String) {
InviteCodeDialogFragment(inviteCode).show(
private fun showInviteDialog(inviteUserName: String, inviteCode: String) {
InviteCodeDialogFragment(inviteUserName, inviteCode).show(
requireActivity().supportFragmentManager,
"InviteCodeDialogFragment"
)
Expand All @@ -71,4 +67,9 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home
}
)
}

override fun onResume() {
super.onResume()
viewModel.getResponseCase()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@ import android.content.Context.CLIPBOARD_SERVICE
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.Toast
import androidx.core.content.ContextCompat.getSystemService
import androidx.fragment.app.DialogFragment
import com.google.android.material.snackbar.Snackbar
import com.kakao.sdk.share.ShareClient
import com.kakao.sdk.template.model.Button
import com.kakao.sdk.template.model.Content
import com.kakao.sdk.template.model.FeedTemplate
import com.kakao.sdk.template.model.Link
import com.sopt.umbba_android.R
import com.sopt.umbba_android.databinding.FragmentInviteCodeDialogBinding

class InviteCodeDialogFragment(private val inviteCode: String) : DialogFragment() {
class InviteCodeDialogFragment(private val inviteUserName: String, private val inviteCode: String) : DialogFragment() {

private var _binding: FragmentInviteCodeDialogBinding? = null
private val binding get() = requireNotNull(_binding) { "InviteCodeDialogFragment is null" }
Expand All @@ -36,6 +43,7 @@ class InviteCodeDialogFragment(private val inviteCode: String) : DialogFragment(
closeDialog()
setBackgroundDesign()
setInviteCodeText(inviteCode)
sendInviteCodeWithKakao(inviteUserName, inviteCode)
}

private fun closeDialog() {
Expand All @@ -62,6 +70,47 @@ class InviteCodeDialogFragment(private val inviteCode: String) : DialogFragment(
}
}

private fun sendInviteCodeWithKakao(inviteUserName: String, inviteCode: String) {
binding.btnSendInvitation.setOnClickListener {
val defaultFeed = FeedTemplate(
content = Content(
title = "${inviteUserName}으로부터 초대가 왔어요. \\n초대 코드 : $inviteCode",
description = "과거로 떠나 함께 추억을 나누고, \\n공감대를 형성해보세요.",
imageUrl = "https://github.com/Team-Umbba/Umbba-iOS/assets/75068759/64ba7265-9148-4f06-8235-de5f4030e92f",
link = Link(
webUrl = "https://developers.kakao.com",
mobileWebUrl = "https://developers.kakao.com"
)
),
buttons = listOf(
Button(
"초대 받기",
Link(
androidExecutionParams = mapOf("key1" to "value1", "key2" to "value2"),
iosExecutionParams = mapOf("key1" to "value1", "key2" to "value2")
)
)
)
)

if (ShareClient.instance.isKakaoTalkSharingAvailable(requireContext())) {
ShareClient.instance.shareDefault(requireContext(), defaultFeed) { sharingResult, error ->
if (error != null) {
Log.e("yeonjin", "카카오톡 공유 실패", error)
} else if (sharingResult != null) {
Log.e("yeonjin", "카카오톡 공유 성공 ${sharingResult.intent}")
startActivity(sharingResult.intent)

Log.w("yeonjin", "Warning Msg: ${sharingResult.warningMsg}")
Log.w("yeonjin", "Argument Msg: ${sharingResult.argumentMsg}")
}
}
} else {
Snackbar.make(binding.root, "카카오톡을 설치해주세요.", Snackbar.LENGTH_SHORT).show()
}
}
}

override fun onResume() {
super.onResume()
dialog?.window?.setLayout(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HomeViewModel(private val homeRepositoryImpl: HomeRepositoryImpl) : ViewMo
private var _topicTitle = MutableLiveData<String>()
val topicTitle:LiveData<String> = _topicTitle

private fun getHomeData() {
fun getHomeData() {
viewModelScope.launch {
homeRepositoryImpl.getHomeData()
.onSuccess { response ->
Expand All @@ -37,7 +37,7 @@ class HomeViewModel(private val homeRepositoryImpl: HomeRepositoryImpl) : ViewMo
}
}

private fun getResponseCase() {
fun getResponseCase() {
viewModelScope.launch {
homeRepositoryImpl.getResponseCase()
.onSuccess { response ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_lo

// 자동로그인
private fun setAutoLogin() {
//토큰이 저장되어 있다면
//액세스 토큰이 저장되어 있다면
Log.e("yeonjin", "setAutoLogin")
Log.e("yeonjin", "sharedPreference : ${SharedPreferences.getString(USER_TOKEN)}")
if (!SharedPreferences.getString(USER_TOKEN).isNullOrBlank()) {
Expand All @@ -99,7 +99,13 @@ class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_lo
Log.e("yeonjin", "viewmodel gettokenresult")
viewModel.getTokenResult.observe(this) { response ->
setUserInfo(response.accessToken)
goAgreePrivacyUseActivity()
if (SharedPreferences.getOnboardingBoolean(DID_USER_CLEAR_ONBOARD)
&& SharedPreferences.getInviteCodeBoolean(DID_USER_CLEAR_INVITE_CODE)
) {
goMainActivity()
} else {
goAgreePrivacyUseActivity()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SplashActivity : BindingActivity<ActivitySplashBinding>(R.layout.activity_

private fun loadSplashScreen() {
lifecycleScope.launch {
delay(1500L)
delay(1400L)
goLoginActivity()
}
}
Expand Down

0 comments on commit d46a428

Please sign in to comment.