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 : 알림 권한 설정 다이어로그 #226

Merged
merged 7 commits into from
Apr 2, 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
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
<activity
android:name=".ui.view.main.MainActivity"
android:exported="false"
android:windowSoftInputMode="adjustPan" />
<!-- Firebase Cloud Messaging -->
android:windowSoftInputMode="adjustPan" /> <!-- Firebase Cloud Messaging -->
<service
android:name=".service.FCMService"
android:exported="false">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.dongyang.android.youdongknowme.ui.view.setting

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.net.Uri
import android.provider.Settings
import androidx.core.content.ContextCompat
import com.dongyang.android.youdongknowme.R
import com.dongyang.android.youdongknowme.databinding.ActivityOnboardingPermissionBinding
import com.dongyang.android.youdongknowme.standard.base.BaseActivity
import com.dongyang.android.youdongknowme.ui.view.main.MainActivity
import com.dongyang.android.youdongknowme.ui.view.setting.SettingViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel


Comment on lines 12 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

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

두 줄 공백은 나중에 코드 리팩할 때 하나 씩 확인하면서 지워가면 좋을 것 같네용

class OnboardingPermissionActivity :
BaseActivity<ActivityOnboardingPermissionBinding, SettingViewModel>() {

Expand Down Expand Up @@ -50,10 +47,10 @@ class OnboardingPermissionActivity :
// 알림 권한이 허용 상태
setPermissionSwitch(true)
} else {

// 알림 권한이 미허용 상태
val intent =
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).setData(Uri.parse("package:" + this.packageName))
startActivity(intent)
val dialog = DialogPermission(getString(R.string.dialog_permission_title), getString(R.string.dialog_permission_content), this.packageName)
dialog.show(supportFragmentManager, "CustomDialog")
}
} else {
// 온보딩 알림 스위치 비활성화
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.dongyang.android.youdongknowme.ui.view.setting

import android.app.Activity
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import android.os.Build
import androidx.core.content.ContextCompat
import com.dongyang.android.youdongknowme.R
import com.dongyang.android.youdongknowme.databinding.FragmentSettingBinding
import com.dongyang.android.youdongknowme.standard.base.BaseFragment
Expand Down Expand Up @@ -60,6 +64,7 @@ class SettingFragment : BaseFragment<FragmentSettingBinding, SettingViewModel>()
viewModel.getUserTopic()

binding.switchSettingUniversityAlarm.setOnCheckedChangeListener { compoundButton, _ ->
checkPermission()
if (compoundButton.isChecked) {
if (topics.isNotEmpty()) {
viewModel.updateUserTopic(topics)
Expand All @@ -70,6 +75,7 @@ class SettingFragment : BaseFragment<FragmentSettingBinding, SettingViewModel>()
}

binding.switchSettingDepartmentAlarm.setOnCheckedChangeListener { compoundButton, _ ->
checkPermission()
if (compoundButton.isChecked) {
if (department.isNotEmpty()) {
viewModel.updateUserDepartment(department)
Expand Down Expand Up @@ -111,6 +117,24 @@ class SettingFragment : BaseFragment<FragmentSettingBinding, SettingViewModel>()
}
}

fun checkPermission(){
Copy link
Collaborator

Choose a reason for hiding this comment

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

외부에서도 사용이 되는 메서드인가용 ?

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (PackageManager.PERMISSION_DENIED == ContextCompat.checkSelfPermission(
requireContext(), Manifest.permission.POST_NOTIFICATIONS
)
) {
// 알림 권한 설정 미허용
viewModel.setIsAccessDepartAlarm(false)
viewModel.setIsAccessUniversityAlarm(false)
binding.switchSettingUniversityAlarm.isChecked = false
binding.switchSettingDepartmentAlarm.isChecked = false

val dialog = DialogPermission(getString(R.string.dialog_permission_title), getString(R.string.dialog_permission_content), requireContext().packageName)
dialog.show(parentFragmentManager, "CustomDialog")
}
}
}

private fun getAppVersion(): String {
val packageManager =
requireContext().packageManager.getPackageInfo(requireContext().packageName, 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.dongyang.android.youdongknowme.ui.view.setting

import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import com.dongyang.android.youdongknowme.databinding.DialogPermissionBinding

class DialogPermission(val title: String, val content: String, val pacakageName: String) : DialogFragment() {
private var _binding: DialogPermissionBinding? = null
private val binding get() = _binding!!

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = DialogPermissionBinding.inflate(inflater, container, false)
val view = binding.root

// 레이아웃 배경을 투명하게
dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))

// 제목, 내용 설정
binding.customTvTitle.text = title
binding.customTvContent.text = content

// 취소 버튼
binding.customTvBtn1.setOnClickListener {
dismiss()
}
// 확인 버튼
binding.customTvBtn2.setOnClickListener {
val intent =
Comment on lines +26 to +36
Copy link
Collaborator

Choose a reason for hiding this comment

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

나중에 로직 분리하면 좋을 것 같아요!
그리고 onViewCreated 와 onCreatedView에서도 알아보심 좋을 듯 합니다 << 프레그먼트 생명주기

Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).setData(Uri.parse("package:$pacakageName"))
startActivity(intent)
dismiss()
}

return view
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
65 changes: 65 additions & 0 deletions app/src/main/res/layout/dialog_permission.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:backgroundTint="@color/white"
android:background="@drawable/bg_stroke_gray300_radius_2dp">

<TextView
android:id="@+id/customTvTitle"
Copy link
Collaborator

Choose a reason for hiding this comment

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

id 컨벤션이 다른 것 같아요

style="@style/PretendardBold20"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="24dp"
android:text="제목"
Copy link
Collaborator

Choose a reason for hiding this comment

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

xml에서 위치를 확인하고 싶은 것이라면
hint:text="제목"
을 사용하시면 되구 사용하지 않는 text값은 지워줍시다용

android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/customTvContent"
style="@style/PretendardMedium16"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="20dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="20dp"
android:text="내용"
android:textAlignment="center"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/customTvTitle" />

<TextView
android:id="@+id/customTvBtn1"
style="@style/PretendardSemiBold16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="28dp"
android:layout_marginBottom="20dp"
android:text="취소"
Copy link
Collaborator

Choose a reason for hiding this comment

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

그리고 string 추출도 !!

android:textColor="@color/blue300"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/customTvBtn2"
app:layout_constraintTop_toBottomOf="@+id/customTvContent" />

<TextView
android:id="@+id/customTvBtn2"
style="@style/PretendardSemiBold16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="30dp"
android:layout_marginBottom="20dp"
android:text="설정 화면 이동"
android:textColor="@color/blue300"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,8 @@
<!-- toast message -->
<string name="toast_msg_keyword">하나 이상의 키워드를 선택해주세요.</string>
<string name="toast_msg_department">정확한 학과명을 기입해주세요.</string>

<!-- permission dialog -->
<string name="dialog_permission_title">기기 알림이 꺼져있습니다.</string>
<string name="dialog_permission_content"><![CDATA[알림 설정(DMforU 설정 > 개인정보 보호 > 알림)을 활성화해야 공지 사항에 대한 키워드를 받을 수 있습니다.]]></string>
</resources>
Loading