<정리> 명함 앱 만들기 3일차
✔ 요약
실제 스마트폰과 안드로이드 스튜디오를 와이파이로 사이에 두고 연결해서 무선으로 프로젝트를 실행하고 디버깅 해볼 수 있는 세팅 완료
레이아웃 수정 및 클린 아키텍처를 적용하기 위한 모듈 추가 생성
1. adb 무선 연결
처음에 할 때는 다음과 같이 하면 된다.
가장 먼저 스마트폰에서 내부 IP를 알 수 있는 앱을 다운받아 내부 IP를 확인한다.
스마트폰을 컴퓨터와 USB선으로 연결한다.
C:\Users\(사용자)\AppData\Local\Android\Sdk\platform-tools 이 위치에서 git bash를 열어 다음 명령어들을 친다.
./adb tcpip 5555
포트번호 설정하는 명령어
./adb connect (앱에서 확인한 내부 IP):5555
연결하는 명령어
이렇게 하고 나면 안드로이드 스튜디오에서 연결된 선이 없는데도 연결한 스마트폰 기종을 선택할 수 있게 된다.
처음이 아닌 경우에는 따로 포트번호를 설정할 필요가 없는 거 같다.
바로 연결하는 명령어를 치니까 연결이 되더라
사실 그냥 다시 명령어 칠 필요가 없이 계속 유지가 될 줄 알았는데 그거는 아닌 거 같다.
찾아보니까 컴퓨터나 스마트폰이 재부팅되는 경우에는 연결이 끊어진다고 한다.
컴퓨터가 재부팅되는 경우에는 연결하는 명령어만 치면 되고 스마트폰이 재부팅되는 경우에는 처음 과정부터 다시 쭉 해야한다고 한다.
2. QR 코드 스캔 화면 레이아웃 수정
아래에 스캔 후 가져올 명함 영역을 확실하게 잡아놓고 나머지 영역을 전부 DecoratedBarcodeView가 차지하도록 했다.
<?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="match_parent"
tools:context=".ui.scan.QRFragment">
<com.journeyapps.barcodescanner.DecoratedBarcodeView
android:id="@+id/dbv_qr_scanner"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/constraintLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:zxing_scanner_layout="@layout/zxing_barcode_scanner" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="180dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:id="@+id/iv_business_card"
android:layout_width="270dp"
android:layout_height="150dp"
android:background="@color/purple_700"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
3. DecoratedBarcodeView 커스텀
DecoratedBarcodeView는 커스텀하려면 app:zxing_scanner_layout 속성에 layout xml 파일을 넣어서 해야한다.
그리고 그 layout xml 파일의 가장 상위 태그는 최상위 요소를 제공하는 더미 태그인 merge다.
BarcodeView에서는 인식 영역의 크기를 정해줬고
ViewfinderView에서는 인식 영역 바깥 쪽 배경색과 인식 영역에 나오던 선과 점을 조절해줬다.
TextView에서는 원래 안내 문구가 나오지만 딱히 의미가 없어서 지워놨다.
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.journeyapps.barcodescanner.BarcodeView
android:id="@+id/zxing_barcode_surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:zxing_framing_rect_width="250dp"
app:zxing_framing_rect_height="250dp"/>
<com.journeyapps.barcodescanner.ViewfinderView
android:id="@+id/zxing_viewfinder_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:zxing_possible_result_points="#00000000"
app:zxing_viewfinder_laser_visibility="false"
app:zxing_viewfinder_mask="#60FFFFFF"/>
<TextView
android:id="@+id/zxing_status_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="@color/zxing_transparent"
android:text=""
android:textColor="@color/zxing_status_text"/>
</merge>
4. 클린 아키텍처 구조 설정
클린 아키텍처를 구성하기 위해 https://heegs.tistory.com/61 이 곳을 참고하여 진행했다.
그런데 모듈을 생성만 하고 실행을 시켜보려는데 계속 에러가 뜨면서 뭐가 문제인지 찾는 시간을 가졌다.
상당한 시간을 헛발질 하다가 알게 된건 라이브러리 모듈로 만들어야하는데 앱 모듈로 만들어서 같은 이름을 가진 라이브러리의 충돌이 발생한 거였다.
뭔가 실행시킬때마다 .build 패키지가 만들어지는 것부터 이상했다.
그래도 원인을 알고 수정해서 모듈을 추가하는 것까지 완료했다.
그리고 나서는 각 모듈에 필요한 패키지들을 일단 추가해놨다.
data 모듈에는 api, database, mapper, model, repository, utils를,
domain 모듈에는 model, repository, usecase를,
presentation 모듈에는 base, di, item, type, ui, utils를 추가했다.
지금은 아직 presentation 모듈만 건드리고 있는 중이다.
앞으로 db를 만지거나 api를 건드리기 시작하면 다른 모듈을 순차적으로 사용할 거 같다.
그리고 di도 hilt로 적용해보려고 한다.
내배캠 최종 프로젝트로 만든 거에서 di를 구성하려고 하니까 너무 복잡해서 손을 뗐는데 이렇게 처음부터 한다면 충분히 가능할 거 같다.
이제 다음 스텝으로 할거는 바로 사용자 인증 기능이다.
만들까 말까 했는데 필요한 과정이라고 판단해서 앱 기능들을 사용하려고 할 때 로그인을 유도하는 것으로 해서 구현하려고 한다.
로그인 기능은 일단 Firebase를 이용하려고 하고 최종적으로는 다양한 소셜 로그인까지 지원하고 싶다...!
로그인 기능이 기본적으로 된다면 storage에 명함을 올리는 걸 할 거다!!