-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
bb64821
02df51a
a8d6f5f
40e4dae
02d47fd
00882d8
92e61ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
@@ -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) | ||
|
@@ -70,6 +75,7 @@ class SettingFragment : BaseFragment<FragmentSettingBinding, SettingViewModel>() | |
} | ||
|
||
binding.switchSettingDepartmentAlarm.setOnCheckedChangeListener { compoundButton, _ -> | ||
checkPermission() | ||
if (compoundButton.isChecked) { | ||
if (department.isNotEmpty()) { | ||
viewModel.updateUserDepartment(department) | ||
|
@@ -111,6 +117,24 @@ class SettingFragment : BaseFragment<FragmentSettingBinding, SettingViewModel>() | |
} | ||
} | ||
|
||
fun checkPermission(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 나중에 로직 분리하면 좋을 것 같아요! |
||
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).setData(Uri.parse("package:$pacakageName")) | ||
startActivity(intent) | ||
dismiss() | ||
} | ||
|
||
return view | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
} |
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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="제목" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. xml에서 위치를 확인하고 싶은 것이라면 |
||
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="취소" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
두 줄 공백은 나중에 코드 리팩할 때 하나 씩 확인하면서 지워가면 좋을 것 같네용