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

[PC-550] 지인 차단 기능 추가 #59

Merged
merged 2 commits into from
Feb 10, 2025
Merged

Conversation

tgyuuAn
Copy link
Member

@tgyuuAn tgyuuAn commented Feb 9, 2025

1. ⭐️ 변경된 내용

  • 지인 차단 UI 추가
  • 지인 차단 API 연결

2. 🖼️ 스크린샷(선택)

2025-02-10.3.24.04.mov

3. 💡 알게된 부분

  • 주소록에 있는 전화번호를 가져오는 로직
private fun readContactPhoneNumbers(context: Context): List<String> {
    val phoneNumbers = mutableListOf<String>()

    val contentResolver = context.contentResolver
    val uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI
    val projection = arrayOf(ContactsContract.CommonDataKinds.Phone.NUMBER)

    contentResolver.query(uri, projection, null, null, null)?.use { cursor ->
        val numberIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)
        while (cursor.moveToNext()) {
            val phoneNumber = cursor.getString(numberIndex)
                .replace(Regex("[^0-9]"), "")
            if (phoneNumber.isNotBlank()) {
                phoneNumbers.add(phoneNumber)
            }
        }
    }

    return phoneNumbers.distinct()
}



기본적으로 전화번호부 데이터는 디바이스 내의 정보에서 가져오는 것이기 때문에 contentResolver 사용

val contentResolver = context.contentResolver



아래 Uri가 뜻하는 것은 contentResolver를 이용하여 어떤 데이터에 접근하려는 것인지를 뜻함.

여기서 갤러리, 미디어 파일, 앱 정보 등에 접근 가능한데 우리는 주소록에 접근해야하기 때문에 아래 URI 사용.

(이는 프레임워크딴에서 제공하는 사전에 정의된 Uri임)

val uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI



그리고 contentResolver로부터 얻는 데이터들은 아래와 같은 projection에 담겨져서 내려옴.

Proejction이란 데이터베이스에 열(column)을 뜻하는 단어임

(행을 Tuple이라고 표현하거나 table을 Relation이라고 표현하는 것과 비슷)

val projection = arrayOf(ContactsContract.CommonDataKinds.Phone.NUMBER)



마지막으로 아래 로직은,

contentResolver에서 나오는 데이터들은 cursor라는 객체에 담겨져서 내려오는데,

이는 우리가 페이징을 쓰는 것처럼 전체 데이터를 한번에 받는 것이 아니라 조금씩 효율적으로 내려받기 위해서 이런식으로 사용.

    contentResolver.query(uri, projection, null, null, null)?.use { cursor ->
        val numberIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)
        while (cursor.moveToNext()) {
            val phoneNumber = cursor.getString(numberIndex)
                .replace(Regex("[^0-9]"), "")
            if (phoneNumber.isNotBlank()) {
                phoneNumbers.add(phoneNumber)
            }
        }
    }

연락처 제공자 공식문서

@tgyuuAn tgyuuAn added UI/UX 🎨 디자인 시스템, 디자인 리소스 관련 코드 🎨 기능 ⚒️ 새로운 기능 구현 ⚒️ 리뷰 원해요🔥 피어의 리뷰를 기다리는 ing.. 🔥 새롭게 알게 됨 📖 프로젝트를 진행하며 새롭게 알게된 부분 📖 ㅌㄱ태규 ☀️ 훗날 크게될 ENFP 남성, tgyuuAn labels Feb 9, 2025
@tgyuuAn tgyuuAn requested a review from sksowk156 February 9, 2025 18:27
@tgyuuAn tgyuuAn self-assigned this Feb 9, 2025
@tgyuuAn tgyuuAn marked this pull request as ready for review February 9, 2025 18:35
@sksowk156 sksowk156 added 머지 해도될듯염🌟 현재 코드를 기존 코드에 합쳐도 될 것 같다라고 판단..! 🌟 and removed 리뷰 원해요🔥 피어의 리뷰를 기다리는 ing.. 🔥 labels Feb 10, 2025
@sksowk156
Copy link
Contributor

아하 그렇군요 태규님 덕분에 contentResolver에 대해 조금 알게되었습니다 감사해요! 고생하셨습니다~~

@tgyuuAn tgyuuAn merged commit b6a5eaa into develop Feb 10, 2025
1 check passed
@tgyuuAn tgyuuAn deleted the feature/tgyuu/PC-550 branch February 10, 2025 05:06
@tgyuuAn
Copy link
Member Author

tgyuuAn commented Feb 10, 2025

아하 그렇군요 태규님 덕분에 contentResolver에 대해 조금 알게되었습니다 감사해요! 고생하셨습니다~~

예앚~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UI/UX 🎨 디자인 시스템, 디자인 리소스 관련 코드 🎨 ㅌㄱ태규 ☀️ 훗날 크게될 ENFP 남성, tgyuuAn 기능 ⚒️ 새로운 기능 구현 ⚒️ 머지 해도될듯염🌟 현재 코드를 기존 코드에 합쳐도 될 것 같다라고 판단..! 🌟 새롭게 알게 됨 📖 프로젝트를 진행하며 새롭게 알게된 부분 📖
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants