본문 바로가기

프로그래밍 일반/안드로이드

firebase chatting관련

https://corikachu.github.io/articles/android/firebase/android-firebase-realtime-chatting-app

 

 

[Android] Firebase의 Realtime Database로 간단한 채팅 앱 만들기 | Corikachu

Firebase의 Realtime Database로 채팅 어플리케이션을 만들어 봅시다.

corikachu.github.io

 

 

 

https://stackoverflow.com/questions/51336198/no-virtual-method-zzbqoz-in-class-lcom-google-firebase-firebaseapp-or-its-sup/51336393

버젼관련 버그도 존재한다. 주의하자. 버젼을 firebase 똑같은 것으로 셋팅해야한다.

 

 

https://docko.tistory.com/entry/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-%EC%8A%A4%ED%8A%9C%EB%94%94%EC%98%A4-minSdkVersion-%EC%98%A4%EB%A5%98-%ED%95%B4%EA%B2%B0%EB%B0%A9%EB%B2%95

생겼던 버그 -최신 버젼으로 맞추자.

 

 

    //①. Firebase의 데이터 위치를 참조하기 위한 객체이다.
    private FirebaseDatabase mFirebaseDatabase;
    private DatabaseReference mDatabaseReference;


    //리싸이클러 뷰 등장이요. 뷰를 전부다 넣는다.`    
    RecyclerView recyclerView;
    EditText editText;
    Button button;

    //리싸이클러뷰에 셋팅할 채팅 아답터이다.
    ChatAdapter chatAdapter;

    private ChildEventListener mChildEventListener;
    private ArrayAdapter<String> mAdapter;

    private ListView mListView;

    private EditText mEdtMessage;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat);
        recyclerView = findViewById(R.id.recyclerView);
        editText = findViewById(R.id.editText);
        button = findViewById(R.id.send);

        //리싸이클러뷰에 할당할 채팅 아답터이다.
        LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);
        chatAdapter = new ChatAdapter();
        recyclerView.setAdapter(chatAdapter);


        mFirebaseDatabase = FirebaseDatabase.getInstance();
        mDatabaseReference = mFirebaseDatabase.getReference();

        final String username = "고길동";
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ChatData chatData = new ChatData(username, editText.getText().toString());
                mDatabaseReference.child("message").push().setValue(chatData);
                editText.setText("");
            }
        });


        mDatabaseReference.child("message").addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                ChatData chatData = dataSnapshot.getValue(ChatData.class);
                chatAdapter.addItem(chatData);
                chatAdapter.notifyDataSetChanged();
            }

            @Override
            public void onChildChanged(DataSnapshot dataSnapshot, String s) {

            }

            @Override
            public void onChildRemoved(DataSnapshot dataSnapshot) {

            }

            @Override
            public void onChildMoved(DataSnapshot dataSnapshot, String s) {

            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }

 

 

 

class ChatAdapter extends RecyclerView.Adapter<ViewHolder> {

    //자료가 추가되는 핵심적인 부분... 채팅매시지가 오기 때문에
    //ArrayList는 채팅메시지형식이 되어야 한다.
    ArrayList<ChatData> items = new ArrayList<>();


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
        View itemView = inflater.inflate(R.layout.msg_item, viewGroup, false);

        return new ViewHolder(itemView);
    }



    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {

        ChatData item = items.get(i);

        viewHolder.setItem(item);
    }

    @Override
    public int getItemCount() {
        return items.size();
    }

    public void addItem(ChatData item){
        items.add(item);
    }
    public void removeItem(ChatData item){
        items.remove(item);
    }
    public void setItems(ArrayList<ChatData> items){
        this.items = items;
    }

}

 

 

 

 

 

 

 

 

 

 

 

https://code.tutsplus.com/tutorials/how-to-create-an-android-chat-app-using-firebase--cms-27397

 

How to Create an Android Chat App Using Firebase

With Firebase, creating real-time social applications is a walk in the park. And the best thing about it: you don't have to write a single line of server-side code.In this tutorial, I'll show you...

code.tutsplus.com

 

 

new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class,

        R.layout.message, FirebaseDatabase.getInstance().getReference()) {

 

FirebaseListAdapter을 사용한다

 

 

 

https://steemit.com/utopian-io/@programminghub/using-firebase-database-to-create-a-chat-application-in-android-part-vi

 

Using Firebase Database to create a chat application in Android : Part VI — Steemit

What will I learn? Defining the structure of our chat messages in firebase database Creating an adapter to… by programminghub

steemit.com

체크~!!!!!!!!!!!!! 이꾸요잇~~~~~~~~~~~~~~~~~

 

 

https://anhana.tistory.com/5?category=701004

 

Android Firebase Chat(4) : Authentication

안녕하세요!. 하나아빠 입니다ㅎㅎ 이번 포스팅은 Android Firebase Authentication 기능을 활용하여 프로젝트에 구글로그인 기능을 연결할 건데요 생각보다 어렵지 않으지만 소스량이 많아졌으니 천천히 따라오시..

anhana.tistory.com

 

https://kutar37.tistory.com/entry/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-%EC%B1%84%ED%8C%85%EC%95%B1-%EB%A7%8C%EB%93%A4%EA%B8%B0-ListView-Adapter

 

안드로이드 채팅앱 만들기 (ListView, Adapter)

안드로이드 채팅앱 만들기 (ListView, Adapter) 우리가 생각하는 카카오톡같은 채팅앱을 구현하기 위해서는 Adapter와 ListView를 사용해야 한다. (ListView는 AdapterView에, AdapterView는 다시 ViewGroup에 속..

kutar37.tistory.com

https://lktprogrammer.tistory.com/190