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/#92] 카카오톡 공유 메세지 커스텀 #93

Merged
merged 6 commits into from
Jul 20, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
[Feat/#92] 카카오톡으로 보낼 메세지 커스텀 및 함수 추가
  • Loading branch information
yeoncheong committed Jul 20, 2023
commit 4e13e7f449b64cfef7d6e54a41556225b6e2956e
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
@@ -32,7 +27,7 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home
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()
}
}
@@ -47,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"
)
Original file line number Diff line number Diff line change
@@ -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" }
@@ -36,6 +43,7 @@ class InviteCodeDialogFragment(private val inviteCode: String) : DialogFragment(
closeDialog()
setBackgroundDesign()
setInviteCodeText(inviteCode)
sendInviteCodeWithKakao(inviteUserName, inviteCode)
}

private fun closeDialog() {
@@ -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(