Skip to content

Commit

Permalink
Fix: styling, catch errors in multimode play timeRunnable, catch erro…
Browse files Browse the repository at this point in the history
…rs int socket communication
  • Loading branch information
Jack-Chagarr committed Nov 8, 2023
1 parent 1f4d8a7 commit 74e0853
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ public void onClick(View v) {
int timePickerCurrentHour = time_picker.getCurrentHour();
int timePickerCurrentMinute = time_picker.getCurrentMinute();

Duration duration = Duration.ofHours(numberPickerHour.getValue()).plusMinutes(numberPickerMinute.getValue());
//Duration duration = Duration.ofHours(0).plusMinutes(0).plusSeconds(8);
//Duration duration = Duration.ofHours(numberPickerHour.getValue()).plusMinutes(numberPickerMinute.getValue());
Duration duration = Duration.ofHours(0).plusMinutes(0).plusSeconds(8);
LocalDate today = LocalDate.now();
LocalDateTime startTime = LocalDateTime.of(today, LocalTime.of(timePickerCurrentHour, timePickerCurrentMinute));
// 현재 시간보다 선택한 시간이 느린 경우 하루 뒤로 설정
LocalDateTime now = LocalDateTime.now();
if (startTime.isBefore(now)) {
startTime = startTime.plusDays(1);
}
//RoomCreateInfo roomInfo = new RoomCreateInfo(groupName, 0, LocalDateTime.now().plusSeconds(5), numRunners, duration);
RoomCreateInfo roomInfo = new RoomCreateInfo(groupName, 0, startTime, numRunners, duration);
RoomCreateInfo roomInfo = new RoomCreateInfo(groupName, 0, LocalDateTime.now().plusSeconds(5), numRunners, duration);
//RoomCreateInfo roomInfo = new RoomCreateInfo(groupName, 0, startTime, numRunners, duration);
new SendRoomInfoTask().execute(roomInfo); //소켓에 연결하여 패킷 전송

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public void run() {
} else {
String formattedTime = String.format(Locale.getDefault(), "%02d:%02d:%02d",
hours, minutes, seconds);
timePresentContentTextView.setText(formattedTime);
if (timePresentContentTextView != null)
timePresentContentTextView.setText(formattedTime);
}
}
if (isFinished == 0) {
Expand Down Expand Up @@ -323,21 +324,21 @@ public void updateTop3UserDistance(UserDistance[] userDistances) { // 화면에
if (top3UserDistance.length >= 1) {
goldNickNameTextView.setText(top3UserDistance[0].getUser().getNickName());
goldDistance = top3UserDistance[0].getDistance();
String goldDistanceString = String.format("%.3fkm", goldDistance);
String goldDistanceString = String.format("%.2fkm", goldDistance);
goldDistanceTextView.setText(goldDistanceString);

if (top3UserDistance.length >= 2) {

silverNickNameTextView.setText(top3UserDistance[1].getUser().getNickName());
double silverDistance = top3UserDistance[1].getDistance();
String silverDistanceString = String.format("%.3fkm", silverDistance);
String silverDistanceString = String.format("%.2fkm", silverDistance);
silverDistanceTextView.setText(silverDistanceString);

if (top3UserDistance.length >= 3) {

bronzeNickNameTextView.setText(top3UserDistance[2].getUser().getNickName());
double bronzeDistance = top3UserDistance[2].getDistance();
String bronzeDistanceString = String.format("%.3fkm", bronzeDistance);
String bronzeDistanceString = String.format("%.2fkm", bronzeDistance);
bronzeDistanceTextView.setText(bronzeDistanceString);
}
}
Expand All @@ -346,7 +347,7 @@ public void updateTop3UserDistance(UserDistance[] userDistances) { // 화면에
int progress = 0;
if (goldDistance != 0) {
progress = (int) ((int) distance / goldDistance) * 100;
}
} else progress = 100;
progressBar.setProgress(progress);

}
Expand All @@ -355,7 +356,7 @@ public void updateTop3UserDistance(UserDistance[] userDistances) { // 화면에
public void onResume() {
super.onResume();
//아래 코드에서 resume때 result fragment로 가는 이유?
transitionToRusultFragment();
transitionToResultFragment();
// socketListenerThread = (SocketListenerThread) getArguments().getSerializable("socketListenerThread"); //waitFragment의 socketListenrThread객체 가져와서 이어서 사용

Log.d("response", "start play screen");
Expand Down Expand Up @@ -413,7 +414,7 @@ public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response)
} catch (IOException e) {
throw new RuntimeException(e);
}
transitionToRusultFragment();
transitionToResultFragment();
}

}
Expand Down Expand Up @@ -509,7 +510,7 @@ public void setSendDataHandler(Handler sendDataHandler) {
this.sendDataHandler = sendDataHandler;
}

private void transitionToRusultFragment() {
private void transitionToResultFragment() {
if (userDistances != null) {
Bundle bundle = new Bundle();
bundle.putSerializable("room", selectedRoom);
Expand Down Expand Up @@ -593,6 +594,9 @@ protected void onPostExecute(Boolean success) {
super.onPostExecute(success);
if (success) {
Log.d("SendfinishedPacket", "Packet sent successfully!");
timeHandler.removeCallbacks(timeRunnable);
sendDataHandler.removeCallbacks(sendDataRunnable);


} else {
Log.d("SendfinishedPacket", "Failed to send packet!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.example.runusandroid.R;

import java.io.ObjectOutputStream;
import java.util.Locale;

import MultiMode.MultiModeRoom;
import MultiMode.MultiModeUser;
Expand All @@ -43,7 +44,9 @@ public class MultiModeResultFragment extends Fragment {
TextView bronzeNickNameTextView;
ProgressBar progressBar;
Button playLeaveButton;
TextView distanceResultContentTextView; //API 사용해서 구한 나의 현재 이동 거리
SocketListenerThread socketListenerThread = MultiModeWaitFragment.socketListenerThread;
private TextView timeResultContentTextView;

@Nullable
@Override
Expand All @@ -61,6 +64,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
bronzeDistanceTextView = view.findViewById(R.id.bronze_distance);
progressBar = view.findViewById(R.id.linear_progress_bar);
playLeaveButton = view.findViewById(R.id.result_leaveButton);
distanceResultContentTextView = view.findViewById(R.id.distance_present_content);
timeResultContentTextView = view.findViewById(R.id.time_present_content);


}

Expand Down Expand Up @@ -90,20 +96,20 @@ public void updateTop3UserDistance(UserDistance[] userDistances) { // 화면에
if (top3UserDistance.length >= 1) {
goldNickNameTextView.setText(top3UserDistance[0].getUser().getNickName());
goldDistance = top3UserDistance[0].getDistance();
String goldDistanceString = String.format("%.3fkm", goldDistance);
String goldDistanceString = String.format("%.2fkm", goldDistance);
goldDistanceTextView.setText(goldDistanceString);

if (top3UserDistance.length >= 2) {

silverNickNameTextView.setText(top3UserDistance[1].getUser().getNickName());
double silverDistance = top3UserDistance[1].getDistance();
String silverDistanceString = String.format("%.3fkm", silverDistance);
String silverDistanceString = String.format("%.2fkm", silverDistance);
silverDistanceTextView.setText(silverDistanceString);

if (top3UserDistance.length >= 3) {
bronzeNickNameTextView.setText(top3UserDistance[2].getUser().getNickName());
double bronzeDistance = top3UserDistance[2].getDistance();
String bronzeDistanceString = String.format("%.3fkm", bronzeDistance);
String bronzeDistanceString = String.format("%.2fkm", bronzeDistance);
bronzeDistanceTextView.setText(bronzeDistanceString);
}
}
Expand All @@ -123,6 +129,16 @@ public void onResume() {
UserDistance[] top3UserDistance = (UserDistance[]) getArguments().getSerializable("top3UserDistance");
updateTop3UserDistance(top3UserDistance);
distance = (float) getArguments().getSerializable("userDistance");
distanceResultContentTextView.setText(String.format(Locale.getDefault(), "%.2f" + "km", distance));
long seconds = selectedRoom.getDuration().getSeconds();
long hours = seconds / 3600;
long minutes = (seconds % 3600) / 60;
seconds = seconds % 60;

// "00:00:00" 형태의 문자열로 변환
String formattedDuration = String.format("%02d:%02d:%02d", hours, minutes, seconds);

timeResultContentTextView.setText(formattedDuration);
Log.d("response", "here is room result screen");


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ public void run() {
public void run() {
try {
Log.d("response", "got packet and try to save group history");
playFragment.saveGroupHistoryData(packet.getTop3UserDistance());
List<UserDistance> temp = packet.getListTop3UserDistance();
UserDistance[] userDistances = temp.toArray(new UserDistance[temp.size()]);
playFragment.saveGroupHistoryData(userDistances);
} catch (JSONException e) {
throw new RuntimeException(e);
}
Expand All @@ -148,7 +150,9 @@ public void run() {
Bundle bundle = new Bundle();
bundle.putSerializable("room", selectedRoom);
//bundle.putSerializable("socketListenerThread", SocketListenerThread.this);
playFragment.userDistances = packet.getTop3UserDistance();
List<UserDistance> temp = packet.getListTop3UserDistance();
UserDistance[] userDistances = temp.toArray(new UserDistance[temp.size()]);
playFragment.userDistances = userDistances;
// bundle.putSerializable("top3UserDistance", packet.getTop3UserDistance());
// bundle.putSerializable("userDistance", playFragment.distance);
Log.d("response", "go to room result screen");
Expand All @@ -159,7 +163,7 @@ public void run() {
}
// NavController navController = Navigation.findNavController(playFragment.requireView());
// navController.navigate(R.id.navigation_multi_room_result, bundle);
Log.d("response", packet.getTop3UserDistance() + " ");
//Log.d("response", packet.getTop3UserDistance() + " ");
Log.d("response", resultFragment + "");

// resultFragment.updateTop3UserDistance(packet.getTop3UserDistance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@

<TextView
android:id="@+id/multi_room_wait_start_time"
android:layout_width="127dp"
android:layout_width="140dp"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="32dp"
android:fontFamily="@font/pretendardregular"
android:gravity="center_vertical"
android:lineSpacingExtra="-37sp"
android:text="21:30"
android:text="21:39"
android:textAppearance="@style/multi_room_wait_start_time"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/multi_room_wait_title"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified android/SocketServer/out/production/SocketServer/Server.class
Binary file not shown.
9 changes: 6 additions & 3 deletions android/SocketServer/src/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ private void sendResultToRoomOwner(int protocol, MultiModeRoom room) throws IOEx
break;
}
}
Packet updateTop3Packet = new Packet(protocol, top3UserDistance);
List<UserDistance> lTop3UserDistances = new ArrayList<UserDistance>(Arrays.asList(top3UserDistance));
System.out.println(lTop3UserDistances);
Packet updateTop3Packet = new Packet(protocol, lTop3UserDistances, 0);

ObjectOutputStream oos = room.getRoomOwnerOos();
if (oos != null ){
Expand All @@ -206,7 +208,8 @@ private void sendResultTop3Users(int protocol, MultiModeRoom room, long groupHis
for(int i = 0; i < top3UserDistance.length; i++){
System.out.println("user " + i + " : " + top3UserDistance[0].getUser().getNickName() + " , distance : " + top3UserDistance[0].getDistance());
}
Packet updateTop3Packet = new Packet(protocol, top3UserDistance, groupHistoryId);
List<UserDistance> lTop3UserDistances = new ArrayList<UserDistance>(Arrays.asList(top3UserDistance));
Packet updateTop3Packet = new Packet(protocol, lTop3UserDistances, (int) groupHistoryId);
broadcastToRoomUsers(room, updateTop3Packet);
}

Expand All @@ -231,7 +234,7 @@ private void broadcastToRoomUsers(MultiModeRoom room, Packet packet) {
System.out.println("user " + i + " : " + packet.getListTop3UserDistance().get(i).getUser().getNickName() + " , distance : " + packet.getListTop3UserDistance().get(i).getDistance());
}
}else if(packet.getProtocol() == Protocol.CLOSE_GAME){
System.out.println("!!!send close room packet " + packet.getProtocol() + " 1st user is " + packet.getTop3UserDistance()[0].getUser().getNickName());
//System.out.println("!!!send close room packet " + packet.getProtocol() + " 1st user is " + packet.getTop3UserDistance()[0].getUser().getNickName());
}
for(int i=0; i<oosList.size(); i++){
ObjectOutputStream oos = oosList.get(i);
Expand Down

0 comments on commit 74e0853

Please sign in to comment.