From b2ff5141338951dc6416c5c4d74908c0238a19ad Mon Sep 17 00:00:00 2001 From: Geunwoo Kim Date: Thu, 12 Oct 2023 13:32:45 +0900 Subject: [PATCH 01/11] Feat: Add RoomList UI and CreateRoomModal UI --- android/RunUsAndroid/app/build.gradle | 1 + .../ui/multi_mode/MultiModeAdapter.java | 61 ++++++++++++++++++ .../ui/multi_mode/MultiModeFragment.java | 64 ++++++++++++++----- .../multi_mode/RoomCreateModalFragment.java | 33 ++++++++++ .../res/layout/create_room_modal_layout.xml | 56 ++++++++++++++++ .../main/res/layout/fragment_multi_mode.xml | 30 +++++---- .../src/main/res/layout/room_item_layout.xml | 17 +++++ 7 files changed, 234 insertions(+), 28 deletions(-) create mode 100644 android/RunUsAndroid/app/src/main/java/com/example/runusandroid/ui/multi_mode/MultiModeAdapter.java create mode 100644 android/RunUsAndroid/app/src/main/java/com/example/runusandroid/ui/multi_mode/RoomCreateModalFragment.java create mode 100644 android/RunUsAndroid/app/src/main/res/layout/create_room_modal_layout.xml create mode 100644 android/RunUsAndroid/app/src/main/res/layout/room_item_layout.xml diff --git a/android/RunUsAndroid/app/build.gradle b/android/RunUsAndroid/app/build.gradle index 7cdb95c8..2b63ae84 100644 --- a/android/RunUsAndroid/app/build.gradle +++ b/android/RunUsAndroid/app/build.gradle @@ -42,6 +42,7 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2' implementation 'androidx.navigation:navigation-fragment:2.7.4' implementation 'androidx.navigation:navigation-ui:2.7.4' + implementation 'androidx.recyclerview:recyclerview:latest_version' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' diff --git a/android/RunUsAndroid/app/src/main/java/com/example/runusandroid/ui/multi_mode/MultiModeAdapter.java b/android/RunUsAndroid/app/src/main/java/com/example/runusandroid/ui/multi_mode/MultiModeAdapter.java new file mode 100644 index 00000000..fae5f9d5 --- /dev/null +++ b/android/RunUsAndroid/app/src/main/java/com/example/runusandroid/ui/multi_mode/MultiModeAdapter.java @@ -0,0 +1,61 @@ +package com.example.runusandroid.ui.multi_mode; + +import android.content.res.ColorStateList; +import android.graphics.Color; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.runusandroid.R; + +import java.util.List; +import java.util.Random; + +public class MultiModeAdapter extends RecyclerView.Adapter { + + private List items; + + private int getRandomColor() { + Random rnd = new Random(); + return Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); + } + + public MultiModeAdapter(List items) { + this.items = items; + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.room_item_layout, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + int color = getRandomColor(); + Button button = holder.itemView.findViewById(R.id.textViewItem); + button.setBackgroundTintList(ColorStateList.valueOf(color)); + String item = items.get(position); + holder.textView.setText(item); + } + + @Override + public int getItemCount() { + return items.size(); + } + + public static class ViewHolder extends RecyclerView.ViewHolder { + public TextView textView; + + public ViewHolder(@NonNull View itemView) { + super(itemView); + textView = itemView.findViewById(R.id.textViewItem); + } + } +} diff --git a/android/RunUsAndroid/app/src/main/java/com/example/runusandroid/ui/multi_mode/MultiModeFragment.java b/android/RunUsAndroid/app/src/main/java/com/example/runusandroid/ui/multi_mode/MultiModeFragment.java index 5ba1ad5a..346e16f5 100644 --- a/android/RunUsAndroid/app/src/main/java/com/example/runusandroid/ui/multi_mode/MultiModeFragment.java +++ b/android/RunUsAndroid/app/src/main/java/com/example/runusandroid/ui/multi_mode/MultiModeFragment.java @@ -1,37 +1,69 @@ package com.example.runusandroid.ui.multi_mode; +import android.app.Dialog; +import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; +import android.view.Window; +import android.widget.Button; -import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; -import androidx.lifecycle.ViewModelProvider; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; -import com.example.runusandroid.databinding.FragmentMultiModeBinding; +import com.example.runusandroid.R; + +import java.util.Arrays; +import java.util.List; public class MultiModeFragment extends Fragment { - private FragmentMultiModeBinding binding; + private Button createRoomButton; + + private void showModal(Context context) { + Dialog dialog = new Dialog(context); + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // 타이틀 없애기 + dialog.setContentView(R.layout.create_room_modal_layout); // 모달에 사용할 레이아웃 지정 + + // 모달 외부 클릭 시 모달 닫기 + dialog.setCanceledOnTouchOutside(true); + + // 모달에 있는 버튼 등의 클릭 리스너도 여기에 설정 가능 + + dialog.show(); + } + + public MultiModeFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_multi_mode, container, false); + + RecyclerView recyclerView = view.findViewById(R.id.recyclerView); + List items = Arrays.asList("Item 1", "Item 2", "Item 3", "item 4", "item 5"); + MultiModeAdapter adapter = new MultiModeAdapter(items); - public View onCreateView(@NonNull LayoutInflater inflater, - ViewGroup container, Bundle savedInstanceState) { - MultiModeViewModel multiModeViewModel = - new ViewModelProvider(this).get(MultiModeViewModel.class); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + recyclerView.setAdapter(adapter); - binding = FragmentMultiModeBinding.inflate(inflater, container, false); - View root = binding.getRoot(); + createRoomButton = view.findViewById(R.id.createRoomButton); + createRoomButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showModal(v.getContext()); + } + }); - final TextView textView = binding.textMultimode; - multiModeViewModel.getText().observe(getViewLifecycleOwner(), textView::setText); - return root; + return view; } @Override public void onDestroyView() { super.onDestroyView(); - binding = null; } -} \ No newline at end of file +} diff --git a/android/RunUsAndroid/app/src/main/java/com/example/runusandroid/ui/multi_mode/RoomCreateModalFragment.java b/android/RunUsAndroid/app/src/main/java/com/example/runusandroid/ui/multi_mode/RoomCreateModalFragment.java new file mode 100644 index 00000000..a9277d84 --- /dev/null +++ b/android/RunUsAndroid/app/src/main/java/com/example/runusandroid/ui/multi_mode/RoomCreateModalFragment.java @@ -0,0 +1,33 @@ +package com.example.runusandroid.ui.multi_mode; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.fragment.app.DialogFragment; + +public class RoomCreateModalFragment extends DialogFragment { + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + + builder.setTitle("Modal Title") + .setMessage("This is a modal dialog.") + .setPositiveButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // actions on OK + } + }) + .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // actions on Cancel + } + }); + return builder.create(); + } + +} diff --git a/android/RunUsAndroid/app/src/main/res/layout/create_room_modal_layout.xml b/android/RunUsAndroid/app/src/main/res/layout/create_room_modal_layout.xml new file mode 100644 index 00000000..b75723e6 --- /dev/null +++ b/android/RunUsAndroid/app/src/main/res/layout/create_room_modal_layout.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + +