Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public void onClick(DialogInterface dialogInterface, int i) {
}).setNegativeButton("취소", null);
AlertDialog alert = alt_bld.create();
alert.show();

}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class AddPlaylistActivity extends AppCompatActivity {
private AddPlaylistAdapter adapter;
private ImageView left_icon;
private SearchView searchView;
private String roomCode;

private ArrayList<SearchedVideoItem> searchedItemList = new ArrayList<>();

Expand All @@ -52,6 +53,10 @@ protected void onCreate(Bundle savedInstanceState) {
left_icon = findViewById(R.id.left_icon);
searchView = findViewById(R.id.searchView);

Intent intent = getIntent();
roomCode = intent.getExtras().getString("roomCode");
System.out.println("룸코드: " + roomCode);

left_icon.setOnClickListener(new View.OnClickListener()
{
@Override
Expand Down Expand Up @@ -197,6 +202,7 @@ public void prettyPrint(Iterator<SearchResult> iteratorSearchResults, String que
data.setPublisher(listPublisher.get(i));
data.setThumbnailURL(listThumbnail.get(i));
data.setId(listId.get(i));
data.setRoomCode(roomCode);

searchedItemList.add(data);
}
Expand Down
33 changes: 10 additions & 23 deletions app/src/main/java/com/andkjyk/wetube_v0/ChatFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@


public class ChatFragment extends Fragment {
private Socket mSocket;
private Gson gson = new Gson();
private RecyclerView chatRecyclerView;
private RecyclerView.LayoutManager layoutManager;
private ChatAdapter chatAdapter;
String room_code, host_name, user_name;
int room_pos;

public ChatFragment() {
// Required empty public constructor
Expand All @@ -58,12 +56,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
}

private void init(View view){
try {
mSocket = IO.socket("http://3.37.36.38:3000/");
Log.d("SOCKET", "Connection success : " + mSocket.id());
} catch (URISyntaxException e) {
e.printStackTrace();
}

chatRecyclerView = (RecyclerView) view.findViewById(R.id.rv_chat);
chatRecyclerView.setHasFixedSize(true);
Expand Down Expand Up @@ -104,25 +96,18 @@ public void onClick(View v) {
}
});

mSocket.connect();
// socket.io 연결
((RoomActivity) getActivity()).mSocket.connect();

mSocket.on(Socket.EVENT_CONNECT, args -> {
mSocket.emit("enter", gson.toJson(new RoomData(user_name, room_code))); //room_code, room_pos 어떻게 처리할지 생각하기
});
mSocket.on("update", args -> {
// socket.io 메세지 받아오기
((RoomActivity) getActivity()).mSocket.on("update", args -> {
MessageData data = gson.fromJson(args[0].toString(), MessageData.class);
addChat(data);
if(getActivity() != null){
addChat(data);
}
});
}

@Override
public void onDestroy() {
super.onDestroy();
// 액티비티가 소멸될 때 연결을 해제, 검색액티비티에서 돌아왔을 때 채팅이 남는지 확인하고, 안남으면 수정 필요할듯?
mSocket.emit("exit", gson.toJson(new RoomData(user_name, room_code)));
mSocket.disconnect();
}

// 리사이클러뷰에 채팅 추가
private void addChat(MessageData data) {
getActivity().runOnUiThread(() -> {
Expand All @@ -141,9 +126,10 @@ private void addChat(MessageData data) {
});
}


private void sendMessage(View view) {
EditText msg = view.findViewById(R.id.editText);
mSocket.emit("newMessage", gson.toJson(new MessageData("MESSAGE",
((RoomActivity) getActivity()).mSocket.emit("newMessage", gson.toJson(new MessageData("MESSAGE",
user_name, room_code, msg.getText().toString(), System.currentTimeMillis())));
Log.d("MESSAGE", new MessageData("MESSAGE",
user_name, room_code+"", msg.getText().toString(), System.currentTimeMillis()).toString());
Expand All @@ -156,4 +142,5 @@ private void sendMessage(View view) {
private String toDate(long currentMiliis) {
return new SimpleDateFormat("a hh:mm").format(new Date(currentMiliis));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

public class PlaylistItem {

private String plVideoName, plPublisher, plVideoId, plThumbnailURL;
private String plVideoName, plPublisher, plVideoId, plThumbnailURL, plRoomCode;

public PlaylistItem(){};

public PlaylistItem(String videoName, String publisher, String videoId, String thumbnailURL){
public PlaylistItem(String videoName, String publisher, String videoId, String thumbnailURL, String roomCode){
this.plVideoName = videoName;
this.plPublisher = publisher;
this.plVideoId = videoId;
this.plThumbnailURL = thumbnailURL;
this.plRoomCode = roomCode;
}

public String getPlVideoName(){
Expand All @@ -25,6 +26,8 @@ public String getPlPublisher(){

public String getPlThumbnailURL() { return plThumbnailURL; }

public String getPlRoomCode() { return plRoomCode; }

public void setPlVideoName(String plVideoName){
this.plVideoName = plVideoName;
}
Expand All @@ -36,4 +39,6 @@ public void setPlPublisher(String plPublisher){
public void setPlVideoId(String plVideoName) { this.plVideoId = plVideoName; }

public void setPlThumbnailURL(String plThumbnailURL) { this.plThumbnailURL = plThumbnailURL; }

public void setPlRoomCode(String plRoomCode) { this.plRoomCode = plRoomCode; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class SearchedVideoItem {
private String publisher;
private String thumbnailURL;
private String id;
private String roomCode;

public String getId() {
return id;
Expand All @@ -18,6 +19,8 @@ public String getTitle() {
return title;
}

public String getRoomCode() { return roomCode; }

public void setTitle(String title) {
this.title = title;
}
Expand All @@ -37,4 +40,6 @@ public String getThumbnailURL() {
public void setThumbnailURL(String thumbnail) {
this.thumbnailURL = thumbnail;
}

public void setRoomCode(String roomCode) { this.roomCode = roomCode; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class PlaylistFragment extends Fragment {
private int ADDPLAYLIST_REQUEST_CODE = 208;

private ArrayList<PlaylistItem> plItemList = new ArrayList<>();
String roomCode;

public PlaylistFragment() {
// Required empty public constructor
Expand All @@ -45,7 +46,8 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d
String publisher = data.getStringExtra("s_publisher");
String thumbnailUrl = data.getStringExtra("s_thumbnailUrl");
String title = data.getStringExtra("s_title");
plAdapter.addItem(new PlaylistItem(title, publisher, videoId, thumbnailUrl));

plAdapter.addItem(new PlaylistItem(title, publisher, videoId, thumbnailUrl, roomCode));
plAdapter.notifyDataSetChanged();
}
}
Expand All @@ -65,7 +67,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle bundle = getArguments();
roomCode = bundle.getString("roomCode");

Intent intent = new Intent(getActivity(), AddPlaylistActivity.class);
intent.putExtra("roomCode", roomCode);
startActivityForResult(intent, ADDPLAYLIST_REQUEST_CODE);
//startActivity(intent);
}
Expand Down Expand Up @@ -124,6 +130,7 @@ private void getData(){
data.setPlPublisher(listPlPublisher.get(i));
data.setPlVideoId(listPlVideoId.get(i));
data.setPlThumbnailURL(listPlThumbnailURL.get(i));
data.setPlRoomCode(roomCode);

plItemList.add(data);
}
Expand Down
Loading