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

chat multiview 구현 #21

Open
wants to merge 1 commit 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
17 changes: 15 additions & 2 deletions app/src/main/java/com/example/testapplication/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,27 @@ import com.example.testapplication.databinding.ActivityCreateRoomLocalBinding

class ChatActivity : AppCompatActivity() {

lateinit var multiAdapter: ChatAdapter
val datas = mutableListOf<chatData>()

private lateinit var Binding: ActivityChatBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Binding = ActivityChatBinding.inflate(layoutInflater)
setContentView(Binding.root)
multiAdapter = ChatAdapter(this)
Binding.chatRecyclerView.adapter = multiAdapter

datas.apply {
add(chatData(name = "이다은", msg = "하이요", time = "22", multi_type1))
add(chatData(name = "이석민", msg = "jenny", time = "26", multi_type2))
add(chatData(name = "안하영", msg = "jhon", time = "27", multi_type1))
multiAdapter.datas = datas
multiAdapter.notifyDataSetChanged()

Binding.btnBack.setOnClickListener{
val intent2= Intent(this, MainActivity::class.java)
}
Binding.btnBack.setOnClickListener {
val intent2 = Intent(this, MainActivity::class.java)
startActivity(intent2)
finish()
}
Expand Down
17 changes: 0 additions & 17 deletions app/src/main/java/com/example/testapplication/ChatData.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class LoginActivity : AppCompatActivity() {
setContentView(binding.root)

val preferences = getSharedPreferences("userInfo", MODE_PRIVATE)

val ID = binding.loginID
val Password = binding.loginPassword

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import retrofit2.Response
import java.util.*

class MatchingTotalActivity : AppCompatActivity() {
var roomId1 = 0
var roomId2 = 0
var roomId3 = 0
var x = 0


private val api = APIS.create()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -90,20 +96,17 @@ class MatchingTotalActivity : AppCompatActivity() {
call: Call<getAllRoomInfoModel>,
response: Response<getAllRoomInfoModel>
) {
Log.d("성공", "성공")
var i = 0
val text =
"{\"activity\":1,\"date\":\"2022.12.20\",\"difficulty\":1,\"fear\":0,\"genre\":\"판타지\",\"region1\":\"강남\",\"region2\":\"건대\",\"region3\":\"상수\",\"roomID\":24,\"title\":\"동국 탈출 넘버원\"}"

Log.d("response11", response.body().toString())
var gson = GsonBuilder().create()
var sj = gson.toJson(response.body())
Log.d("json", sj)

val jsonArray =
JSONObject(sj).optJSONArray("roomInfoList")

val array = Array(jsonArray.length(), { Array(9, { "" }) })
val countarray = Array(jsonArray.length(), { IntArray(2, { 0 }) })
val countarray = Array(jsonArray.length(), {FloatArray(2, {0.0f})})
while (i < jsonArray.length()) {
val JsonObject = jsonArray.getJSONObject(i)
val roomID = JsonObject.getString("roomID").toString()
Expand All @@ -127,16 +130,19 @@ class MatchingTotalActivity : AppCompatActivity() {
array[i][8] = activity
i++
}

var j = 0;
while (j < jsonArray.length()) {
var count = 0
if (array[j][1] == useroption[0])
count++
if (array[j][2] == useroption[1])
count++
if (array[j][3] == useroption[2])
count++
var count = 0.0f
var recount = 0.0f

for(a: Int in 0..2) {
for (b: Int in 0..2) {
if (array[j][a + 1] == useroption[b])
recount++
}
}
count += (recount / 3)

if (Integer.parseInt(array[j][4]) >= Integer.parseInt(useroption[3])
&& Integer.parseInt(array[j][4]) <= Integer.parseInt(useroption[4])
)
Expand All @@ -150,24 +156,26 @@ class MatchingTotalActivity : AppCompatActivity() {
if (array[j][8] == useroption[8].toString())
count++
countarray[j][1] = count
countarray[j][0] = Integer.parseInt(array[j][0])
countarray[j][0] = array[j][0].toFloat()
Log.d("count", j.toString() + " " + count.toString())
j++
}

//countarray.sort()
//Arrays.sort(countarray, Comparator.comparingInt())


intent.putExtra("roomId", countarray[0][0].toInt())
}

override fun onFailure(call: Call<getAllRoomInfoModel>, t: Throwable) {
Log.d("failGetAllRoomInfo", "failll")
}

})

val intent = Intent(this, Recommend_list::class.java)
//intent.putExtra("roodid1", roomId1)
//intent.putExtra("roodid2", roomId2)
//intent.putExtra("roodid3", roomId3)
startActivity(intent)
finish()

}
}

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/example/testapplication/MultiMode.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.testapplication


const val multi_type1 = 1
const val multi_type2 = 2
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/testapplication/MyAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class MyAdapter(private var roomList: List<getRoomRecommendationModel.recommend

override fun onBindViewHolder(holder: RecyclerViewViewHolder, position: Int) {
holder.bind(roomList[position])

holder.itemView.setOnClickListener {
Log.d("클릭","클릭")
Log.d("roomID", roomList[position].roomID.toString())
val intent = Intent(holder.itemView?.context, MainActivity::class.java)
ContextCompat.startActivity(holder.itemView.context, intent,null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ class Recommend_list : AppCompatActivity() {
val adapter = MyAdapter(recyclerViewItems)
binding.recyclerView.adapter = adapter


Log.d("roomd1", intent.getStringExtra("roomid1").toString())

api.getRoomRecommendation(
24,31,32
//Integer.parseInt(intent.getStringExtra("roomid1").toString()),
//Integer.parseInt(intent.getStringExtra("roomid2").toString()),
//Integer.parseInt(intent.getStringExtra("roomid3").toString())

Integer.parseInt(intent.getStringExtra("roomId")), 26, 24
).enqueue(object : retrofit2.Callback<getRoomRecommendationModel> {
override fun onResponse(
call: Call<getRoomRecommendationModel>,
Expand Down
79 changes: 79 additions & 0 deletions app/src/main/java/com/example/testapplication/chatAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.example.testapplication

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class ChatAdapter(private val context: Context) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
var datas = mutableListOf<chatData>()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val view: View?
return when (viewType) {
multi_type1 -> {
view = LayoutInflater.from(parent.context).inflate(
R.layout.chat_row,
parent,
false
)
MultiViewHolder1(view)
}
else -> {
view = LayoutInflater.from(parent.context).inflate(
R.layout.chat_row_my,
parent,
false
)
MultiViewHolder2(view)
}
}
}

override fun getItemCount(): Int = datas.size

override fun getItemViewType(position: Int): Int {
return datas[position].type
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (datas[position].type) {
multi_type1 -> {
(holder as MultiViewHolder1).bind(datas[position])
holder.setIsRecyclable(false)
}
else -> {
(holder as MultiViewHolder2).bind(datas[position])
holder.setIsRecyclable(false)
}
}
}

inner class MultiViewHolder1(view: View) : RecyclerView.ViewHolder(view) {

private val Name: TextView = view.findViewById(R.id.chat_nickname)
private val Msg: TextView = view.findViewById(R.id.chat_msg)
private val Time: TextView = view.findViewById(R.id.chat_time)

fun bind(item: chatData) {
Name.text = item.name
Msg.text = item.msg
Time.text = item.time

}
}

inner class MultiViewHolder2(view: View) : RecyclerView.ViewHolder(view) {
private val Msg: TextView = view.findViewById(R.id.my_chat_msg)
private val Time: TextView = view.findViewById(R.id.my_chat_time)

fun bind(item: chatData) {
Msg.text = item.msg
Time.text = item.time

}
}
}

8 changes: 8 additions & 0 deletions app/src/main/java/com/example/testapplication/chatData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.testapplication

data class chatData(
val name : String,
val msg : String,
val time : String,
val type : Int
)
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:background="@drawable/arrow"
tools:ignore="SpeakableTextPresentCheck" />

<TextView
android:id="@+id/chatTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand All @@ -47,7 +47,6 @@
android:layout_gravity="center"
android:layout_marginTop="24dp"
android:layout_marginEnd="20dp"
android:background="@drawable/menu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@id/linearLayout"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -60,6 +59,7 @@
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="12dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toTopOf="@+id/chat_inputBox"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/res/layout/chat_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
android:id="@+id/chat_nickname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="name"
android:fontFamily="@font/pretendard"
android:text="name"
android:textAlignment="textStart" />

<FrameLayout
Expand All @@ -39,17 +39,19 @@
android:id="@+id/chat_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="message"
android:fontFamily="@font/pretendard"
android:paddingHorizontal="10dp"
android:paddingVertical="5dp"
android:text="message"
android:textColor="@color/text_main" />
</FrameLayout>

<TextView
android:id="@+id/chat_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="time"
android:fontFamily="@font/pretendard"
android:text="time"
android:textSize="10sp" />

</LinearLayout>
Expand Down
48 changes: 48 additions & 0 deletions app/src/main/res/layout/chat_row_my.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/chat_main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">

<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
<LinearLayout
android:id="@+id/chat_recieve"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="@+id/chat_text_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/chatbox_sent">

<TextView
android:id="@+id/my_chat_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="message"
android:textSize="14sp"
android:fontFamily="@font/pretendard"
android:textColor="@color/text_white" />
</FrameLayout>

<TextView
android:id="@+id/my_chat_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="time"
android:gravity="right"
android:fontFamily="@font/pretendard"
android:textSize="10sp" />

</LinearLayout>

</LinearLayout>