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

채팅 버그 수정 #163

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.swsnack.catchhouse.adapter.bindingadapter;

import androidx.annotation.RequiresApi;
import androidx.databinding.BindingAdapter;
import android.net.Uri;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Build;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
Expand All @@ -25,6 +27,7 @@

public class ChattingDataBinding {

@RequiresApi(api = Build.VERSION_CODES.N)
@BindingAdapter({"setChattingList"})
public static void setList(RecyclerView recyclerView, List<Chatting> chattingList) {
ChattingListAdapter chattingListAdapter = (ChattingListAdapter) recyclerView.getAdapter();
Expand All @@ -37,7 +40,7 @@ public static void setList(RecyclerView recyclerView, List<Chatting> chattingLis
return;
}

List<Chatting> orderedList = DataConverter.reOrderedListByTimeStamp(chattingList);
List<Chatting> orderedList = DataConverter.sortByTimeStamp(chattingList);
chattingListAdapter.setList(orderedList);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.swsnack.catchhouse.adapter.chattingadapter;


import com.swsnack.catchhouse.adapter.BaseDiffUtil;
import com.swsnack.catchhouse.data.model.Chatting;
import com.swsnack.catchhouse.data.model.Message;

import java.util.List;

Expand All @@ -12,13 +12,13 @@ public class ChattingDiffUtil extends BaseDiffUtil<Chatting> {
super(mOldList, mNewList);
}

@Override
public boolean areItemsTheSame(int oldListIndex, int newListIndex) {
return mOldList.get(oldListIndex).getRoomUid().equals(mNewList.get(newListIndex).getRoomUid());
}

@Override
public boolean areContentsTheSame(int oldMessageIndex, int newMessageIndex) {
if (mOldList.get(oldMessageIndex).getMessages() != null && mNewList.get(newMessageIndex).getMessages() != null) {
List<Message> oldMessages = mOldList.get(oldMessageIndex).getMessages();
List<Message> newMessages = mNewList.get(newMessageIndex).getMessages();
return oldMessages.get(oldMessages.size() -1).equals(newMessages.get(newMessages.size() -1));
}
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.swsnack.catchhouse.adapter.chattingadapter;

import android.content.Context;
import androidx.annotation.NonNull;
import com.google.android.material.snackbar.Snackbar;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.google.android.material.snackbar.Snackbar;
import com.swsnack.catchhouse.R;
import com.swsnack.catchhouse.adapter.BaseRecyclerViewAdapter;
import com.swsnack.catchhouse.data.model.Chatting;
Expand All @@ -17,6 +15,10 @@

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;

public class ChattingListAdapter extends BaseRecyclerViewAdapter<Chatting, ChattingListItemHolder> {

private ChattingViewModel mChattingViewModel;
Expand Down Expand Up @@ -59,7 +61,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi

ItemChattingListBinding binding = ((ChattingListItemHolder) holder).getBinding();
binding.setChattingData(arrayList.get(position));
mChattingViewModel.getUser(position,
mChattingViewModel.getUser(arrayList.get(position).getUsers(),
binding::setUserData,
error -> Snackbar.make(binding.getRoot(), R.string.snack_failed_load_list, Snackbar.LENGTH_SHORT).show());

Expand All @@ -83,4 +85,4 @@ public void setList(List<Chatting> newChattingList) {
this.arrayList = newChattingList;
result.dispatchUpdatesTo(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.swsnack.catchhouse.adapter.chattingadapter;

import com.swsnack.catchhouse.databinding.ItemChattingListBinding;

import androidx.annotation.NonNull;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.swsnack.catchhouse.databinding.ItemChattingListBinding;

public class ChattingListItemHolder extends RecyclerView.ViewHolder implements LifecycleOwner {

private ItemChattingListBinding mBinding;
Expand Down
25 changes: 2 additions & 23 deletions app/src/main/java/com/swsnack/catchhouse/data/db/AppDataCache.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
package com.swsnack.catchhouse.data.db;

import com.swsnack.catchhouse.data.model.Room;
public interface AppDataCache<T>{

import java.util.HashMap;
int getCacheItemSize();

public class AppDataCache {

private static AppDataCache INSTANCE;
private HashMap<Room, Long> mRecentRoomCache;

public static AppDataCache getInstance() {
if(INSTANCE == null) {
synchronized (AppDataCache.class) {
INSTANCE = new AppDataCache();
}
}
return INSTANCE;
}

private AppDataCache() {
mRecentRoomCache = new HashMap<>();
}

public HashMap<Room, Long> getRecentRoomCache() {
return mRecentRoomCache;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.swsnack.catchhouse.AppApplication;
import com.swsnack.catchhouse.data.entity.FavoriteRoomEntity;
import com.swsnack.catchhouse.data.entity.SellRoomEntity;
import com.swsnack.catchhouse.repository.room.local.FavoriteRoomDao;
import com.swsnack.catchhouse.repository.room.local.SellRoomDao;
import com.swsnack.catchhouse.repository.room.local.TypeConverter;
import com.swsnack.catchhouse.data.source.favoriteroom.FavoriteRoomDao;
import com.swsnack.catchhouse.data.source.room.local.SellRoomDao;
import com.swsnack.catchhouse.data.source.room.local.TypeConverter;

import androidx.room.Database;
import androidx.room.Room;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.swsnack.catchhouse.data.entity;

import com.swsnack.catchhouse.repository.room.local.TypeConverter;
import com.swsnack.catchhouse.data.source.room.local.TypeConverter;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.swsnack.catchhouse.data.entity;


import com.swsnack.catchhouse.repository.room.local.TypeConverter;
import com.swsnack.catchhouse.data.source.room.local.TypeConverter;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.swsnack.catchhouse.data.model;

import androidx.annotation.Nullable;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import androidx.annotation.Nullable;

public class Chatting implements Serializable {

private String roomUid;
Expand Down Expand Up @@ -45,13 +45,14 @@ public boolean equals(Object obj) {
return this.roomUid.equals(((Chatting) obj).getRoomUid());
}

@Override
public int hashCode() {
return roomUid.hashCode();
}

@Nullable
public List<Message> getMessages() {
return messages;
}

public void setMessages(List<Message> messages) {
this.messages = messages;
}
}

20 changes: 10 additions & 10 deletions app/src/main/java/com/swsnack/catchhouse/data/model/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ public String getContent() {
return content;
}

public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}

public void setSendUuid(String sendUuid) {
this.sendUuid = sendUuid;
}

public void setContent(String content) {
this.content = content;
}

@Override
public boolean equals(Object obj) {
if(!(obj instanceof Message)) {
return false;
return false;
}
return this.timestamp.equals(((Message) obj).getTimestamp());
Message compareObj = (Message) obj;
return this.timestamp.equals(((Message) obj).getTimestamp()) &&
this.sendUuid.equals(compareObj.getSendUuid()) &&
this.content.equals(compareObj.content);
}

@Override
public int hashCode() {
return timestamp.hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.swsnack.catchhouse.repository.chatting;
package com.swsnack.catchhouse.data.source.chatting;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.swsnack.catchhouse.repository.chatting.remote;
package com.swsnack.catchhouse.data.source.chatting.remote;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseException;
Expand All @@ -13,7 +13,7 @@
import com.swsnack.catchhouse.firebase.DBListValueHelper;
import com.swsnack.catchhouse.repository.OnFailedListener;
import com.swsnack.catchhouse.repository.OnSuccessListener;
import com.swsnack.catchhouse.repository.chatting.ChattingDataSource;
import com.swsnack.catchhouse.data.source.chatting.ChattingDataSource;

import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.swsnack.catchhouse.repository.room.local;
package com.swsnack.catchhouse.data.source.favoriteroom;

import com.swsnack.catchhouse.data.entity.FavoriteRoomEntity;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.swsnack.catchhouse.repository.room.local;
package com.swsnack.catchhouse.data.source.favoriteroom;

import com.google.firebase.auth.FirebaseAuth;
import com.swsnack.catchhouse.data.db.AppDatabase;
Expand All @@ -13,21 +13,21 @@

import androidx.annotation.Nullable;

public class FavoriteRoomImpl implements FavoriteRoomDataSource {
public class FavoriteRoomDaoImpl implements FavoriteRoomDataSource {

private static FavoriteRoomImpl INSTANCE;
private static FavoriteRoomDaoImpl INSTANCE;
private FavoriteRoomDao mRoomDao;

public static FavoriteRoomImpl getInstance() {
public static FavoriteRoomDaoImpl getInstance() {
if (INSTANCE == null) {
synchronized (FavoriteRoomImpl.class) {
INSTANCE = new FavoriteRoomImpl();
synchronized (FavoriteRoomDaoImpl.class) {
INSTANCE = new FavoriteRoomDaoImpl();
}
}
return INSTANCE;
}

private FavoriteRoomImpl() {
private FavoriteRoomDaoImpl() {
mRoomDao = AppDatabase.getInstance().getRoomDataAccessor();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.swsnack.catchhouse.repository.room.local;
package com.swsnack.catchhouse.data.source.favoriteroom;

import com.swsnack.catchhouse.data.model.Room;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.swsnack.catchhouse.repository.room.local;
package com.swsnack.catchhouse.data.source.favoriteroom;

import android.os.AsyncTask;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.swsnack.catchhouse.repository.location;
package com.swsnack.catchhouse.data.source.location;

import com.swsnack.catchhouse.data.model.Address;
import com.swsnack.catchhouse.repository.OnFailedListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.swsnack.catchhouse.repository.location.remote;
package com.swsnack.catchhouse.data.source.location.remote;

import com.firebase.geofire.GeoFire;
import com.firebase.geofire.GeoLocation;
import com.google.firebase.database.FirebaseDatabase;
import com.swsnack.catchhouse.data.model.Address;
import com.swsnack.catchhouse.repository.OnFailedListener;
import com.swsnack.catchhouse.repository.OnSuccessListener;
import com.swsnack.catchhouse.repository.location.LocationDataSource;
import com.swsnack.catchhouse.data.source.location.LocationDataSource;

import androidx.annotation.NonNull;

Expand Down
Loading