채팅앱 만들기 서버 없이 DB 까지

2022. 11. 24. 09:51·project
728x90

이번에 만들어 볼 내용은 채팅앱의 기본 프레임을 짜보는 것이다.

간단하게 정리하면, 보내는 사람, 받는 사람, 이전의 대화 내용, 보낸 시간과 날짜가 나오도록 만들 것이다.

이 앱을 만드는 과정에서 사용할 DB는 SQLliteDB이다.

또한 코드의 양이 많을 것으로 예상 되어서 부분을 나누어 포스팅 할 예정이다.

 

그럼 이제 구조를 생각하면서 구현해보자.

 

구조는 일단 front부분과 back부분이 있다고 생각하면되는데, front부분은 3개의 Layout이 필요하다.

여기서 중요하게 쓰이는 View가 있는데 RecyclerView를 사용할 것이다.

RecyclerView는 여러 곳에서 잘 설명해 놓았기 때문에 짧게만 설명하겠다.

RecyclerView는 뷰를 13~15개 정도만 생성하여서 화면에서 스크롤을 올려서 사라진 View의 내용을 다음 보여줄 내용으로 수정하여 다시 보여주는 방식이다. 그래서 이름 그대로 재사용뷰인 것이다. 그렇기 때문에 list를 보여주는 뷰라고 생각해도 될 것 같다.

 

그래서 일단 입력을 받고, 그걸 보여줄 레이아웃을 정의한다.

activity_main의 코드는 아래와 같다.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:id="@+id/recyclerView"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toTopOf="@id/contentsEdit"/>
    <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/contentsEdit"
            app:layout_constraintTop_toBottomOf="@id/recyclerView"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toStartOf="@id/sendButton"/>
    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/sendButton"
            android:text="전송"
            android:enabled="false"
            android:onClick="sendAction"
            app:layout_constraintTop_toBottomOf="@id/recyclerView"
            app:layout_constraintStart_toEndOf="@id/contentsEdit"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

보여줄 부분이 있다면 이제는 보여줘야 할 내용이 있어야하지 않겠는가?

보내는 사람의 말풍선과 받는 사람의 말풍선도 디자인해보자.

 

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        xmlns:app="http://schemas.android.com/apk/res-auto">
    <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/cardView"
            app:cardCornerRadius="8dp"
            app:cardBackgroundColor="#FFF59D"
            android:layout_marginRight="128dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toTopOf="@id/datetimeText">
        <TextView android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:id="@+id/messageText"
                  android:text="안녕하세요."
                  android:padding="8dp"
                  android:ellipsize="end"
                  android:maxLines="2"
                  android:textSize="16sp"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintEnd_toEndOf="parent"
                  app:layout_constraintTop_toTopOf="parent"
                  app:layout_constraintBottom_toBottomOf="parent"/>
    </androidx.cardview.widget.CardView>

    <TextView android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/datetimeText"
              android:textSize="12sp"
              android:layout_marginRight="128dp"
              android:text="2021.11.29 16:32:12"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintTop_toBottomOf="@id/cardView"
              app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

이 코드는 받는 사람 즉, 상대방이 보내올 말풍선이다.

그 다음은 보내는 사람 즉, 사용자의 말풍선이다.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/cardView"
            app:cardCornerRadius="8dp"
            app:cardBackgroundColor="#90CAF9"
            android:layout_marginLeft="128dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toTopOf="@id/datetimeText">
        <TextView android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:id="@+id/messageText"
                  android:text="안녕하세요."
                  android:padding="8dp"
                  android:ellipsize="end"
                  android:maxLines="2"
                  android:textSize="16sp"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintEnd_toEndOf="parent"
                  app:layout_constraintTop_toTopOf="parent"
                  app:layout_constraintBottom_toBottomOf="parent"/>
    </androidx.cardview.widget.CardView>

    <TextView android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/datetimeText"
              android:textSize="12sp"
              android:text="2021.11.29 16:32:12"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintTop_toBottomOf="@id/cardView"
              app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

그럼 이제 front부분의 내용은 끝났다.

다음부분은 이제 자바를 기반으로 back부분을 구성할 것이다.

 

 

2022.11.24 - [프로젝트] - 채팅앱 만들기 서버 없이 DB 까지 - 2

 

채팅앱 만들기 서버 없이 DB 까지 - 2

2022.11.24 - [프로젝트] - 채팅앱 만들기 서버 없이 DB 까지 채팅앱 만들기 서버 없이 DB 까지 이번에 만들어 볼 내용은 채팅앱의 기본 프레임을 짜보는 것이다. 간단하게 정리하면, 보내는 사람, 받

parkjunbackend.tistory.com

 

728x90

'project' 카테고리의 다른 글

채팅앱 만들기 서버 없이 DB 까지 - 2  (0) 2022.11.24
음악재생 프로그램 만들기-1  (0) 2022.11.08
'project' 카테고리의 다른 글
  • 채팅앱 만들기 서버 없이 DB 까지 - 2
  • 음악재생 프로그램 만들기-1
Bello's
Bello's
개발하는 벨로
  • Bello's
    벨로의 개발일지
    Bello's
  • 전체
    오늘
    어제
    • 분류 전체보기 (199) N
      • 노예 일지 (7)
        • 스타트업 노예일지 (3)
      • CS 이론 (81)
        • 학과 수업 (4)
        • 알고리즘 (64)
        • 시스템 프로그래밍 (3)
        • 데이터 통신 (1)
        • 운영체제 (2)
        • 데이터베이스 (1)
      • project (3)
      • 나는 감자다. (4)
      • Spring (27)
      • 모각코 (45)
        • 절개와지조(모각코) (7)
        • 어쩌다보니 박준태가 조장이조 (11)
        • 어쩌다보니 박준태가 또 조장이조 (12)
      • LikeLion🦁 (20)
      • 캘리포니아 감자 (4)
      • OpenSource Contribute (1)
      • 우아한테크벨로 (1) N
        • 프리코스 회고록 (6)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    회고록
    DFS
    나는 감자
    누적합
    모각코
    티스토리챌린지
    BFS
    절개와지조
    감자
    자바
    타임리프
    Spring
    오블완
    뛰슈
    8기
    프리코스
    그래프 순회
    백준
    어렵다
    JPA
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
Bello's
채팅앱 만들기 서버 없이 DB 까지
상단으로

티스토리툴바