felocsss 1 éve
szülő
commit
bb5e5013c0

+ 44 - 0
app/build.gradle

@@ -1,5 +1,6 @@
 plugins {
     id 'com.android.application'
+    id 'org.jetbrains.kotlin.android'
 }
 
 android {
@@ -44,4 +45,47 @@ dependencies {
     implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
     implementation 'androidx.test.espresso:espresso-core:3.5.1'
     implementation 'androidx.test.ext:junit:1.1.5'
+    //Base implementation
+    implementation 'androidx.core:core-ktx:1.10.1'
+    implementation 'androidx.appcompat:appcompat:1.6.1'
+    implementation 'com.google.android.material:material:1.9.0'
+    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
+    testImplementation 'junit:junit:4.13.2'
+    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
+    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
+    //Splash Screen
+    implementation("androidx.core:core-splashscreen:1.0.1")
+    // Navigation Component
+    implementation 'androidx.navigation:navigation-fragment-ktx:2.6.0'
+    implementation 'androidx.navigation:navigation-ui-ktx:2.6.0'
+    // Room components
+    // Lifecycle components
+    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
+    implementation "androidx.lifecycle:lifecycle-common-java8:2.6.1"
+    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1"
+    // Kotlin components
+    //implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.21"
+    api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1"
+    api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1"
+    //Swipe and refresh
+    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01"
+    //XMPP libs
+    implementation "org.igniterealtime.smack:smack-android:4.4.0"
+    // Optional for XMPPTCPConnection
+    implementation "org.igniterealtime.smack:smack-tcp:4.4.0"
+    // Optional for XMPP-IM (RFC 6121) support (Roster, Threaded Chats, …)
+    implementation "org.igniterealtime.smack:smack-im:4.4.0"
+    // Optional for XMPP extensions support
+    implementation "org.igniterealtime.smack:smack-extensions:4.4.0"
+    //circular
+    implementation 'com.github.rahatarmanahmed:circularprogressview:2.5.0'
+    //Coil for convert url to image
+    implementation "io.coil-kt:coil:2.4.0"
+    //Preference
+    implementation 'androidx.preference:preference:1.2.0'
+
+}
+
+configurations {
+    all*.exclude group: 'xpp3', module: 'xpp3'
 }

+ 165 - 0
app/src/main/java/com/sharix/sportsmanfriend/repository/XMPPRepository.kt

@@ -0,0 +1,165 @@
+package com.sharix.sportsmanfriend.repository
+
+import android.os.StrictMode
+import android.util.Log
+import androidx.lifecycle.MutableLiveData
+import org.jivesoftware.smack.AbstractXMPPConnection
+import org.jivesoftware.smack.packet.Message
+import org.jivesoftware.smack.tcp.XMPPTCPConnection
+import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration
+import org.jivesoftware.smackx.mam.MamManager
+import org.jivesoftware.smackx.muc.MultiUserChat
+import org.jivesoftware.smackx.muc.MultiUserChatManager
+import org.jxmpp.jid.EntityBareJid
+import org.jxmpp.jid.impl.JidCreate
+import org.jxmpp.jid.parts.Resourcepart
+import java.net.InetAddress
+import java.net.URL
+
+class XMPPRepository {
+    private val TAG:String = XMPPRepository::class.java.simpleName
+    private lateinit var connection: AbstractXMPPConnection
+    private var manager: MultiUserChatManager? = null
+    private var myJid: EntityBareJid = JidCreate.entityBareFrom("test@msg.sharix-app.org")
+    var muc: MultiUserChat? = null
+    private var listMessage: ArrayList<Message>? = null
+    var messagesLiveData = MutableLiveData<ArrayList<Message>>().apply {
+        value = arrayListOf()
+    }
+    var messageRoom1 = MutableLiveData<ArrayList<Message>>().apply {
+        value = arrayListOf()
+    }
+    var messageRoom2 = MutableLiveData<ArrayList<Message>>().apply {
+        value = arrayListOf()
+    }
+    var messageRoom3 = MutableLiveData<ArrayList<Message>>().apply {
+        value = arrayListOf()
+    }
+    init {
+        try {
+            val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
+            StrictMode.setThreadPolicy(policy)
+            val urlIP = URL("https://" + myJid.domain)
+            val ip = InetAddress.getByName(urlIP.host)
+            val config: XMPPTCPConnectionConfiguration = XMPPTCPConnectionConfiguration.builder()
+                .setXmppDomain(myJid.domain.toString())
+                .setHost(ip.hostAddress)
+                .build()
+            connection = XMPPTCPConnection(config)
+            Log.e(TAG, "XMPP repos init")
+        }catch (e: Exception){
+            Log.e(TAG, e.message.toString())
+        }
+
+    }
+
+    fun login(jid:String, password:String){
+        try {
+            myJid = JidCreate.entityBareFrom(jid)
+            connect()
+            connection.login(
+                myJid.toString().split("@")[0],
+                password
+            )
+            manager = MultiUserChatManager.getInstanceFor(connection)
+            Log.i(TAG, "XMPP successfully login")
+        }catch (e: Exception){
+            Log.e(TAG, e.message.toString())
+        }
+
+    }
+    fun messageListener(room: String, message_count: Int, idRoom: Int = 0) {
+        try {
+            muc = connectToRoom(room)
+            listMessage = getRoomMessage(message_count, muc!!)
+            messagesLiveData.value = listMessage!!
+            muc!!.addMessageListener {
+                if(!it.body.isNullOrEmpty()){
+                    listMessage!!.add(it)
+                    Log.e(TAG, idRoom.toString())
+                    when (idRoom) {
+                        0 -> messagesLiveData.postValue(listMessage)
+                        1 -> messageRoom1.postValue(listMessage)
+                        2 -> messageRoom2.postValue(listMessage)
+                        3 -> messageRoom3.postValue(listMessage)
+                    }
+                }
+            }
+            Log.i(TAG, "XMPP successfully add message listener")
+        }catch (e: Exception){
+            Log.e(TAG, e.message.toString())
+        }
+    }
+    fun removeAllListener(rooms: ArrayList<String>){
+        try {
+            for (room in rooms){
+                muc = connectToRoom(room)
+                listMessage = getRoomMessage(0, muc!!)
+                messagesLiveData.value = listMessage!!
+                muc!!.removeMessageListener {  }
+                //muc!!.addMessageListener {}
+            }
+
+            Log.i(TAG, "XMPP successfully add message listener")
+        }catch (e: Exception){
+            Log.e(TAG, e.message.toString())
+        }
+    }
+    fun sendMessage(msg: String){
+        try {
+            muc!!.sendMessage(msg)
+            Log.i(TAG, "XMPP successfully send message")
+        }catch (e: Exception){
+            Log.e(TAG, e.message.toString())
+        }
+    }
+    fun connect(){
+        try {
+            if(!connection.isConnected){
+                connection.connect()
+            }
+            Log.i(TAG, "XMPP successfully connected")
+        }catch (e: Exception){
+            Log.e(TAG, e.message.toString())
+        }
+    }
+    fun connectToRoom(room: String) : MultiUserChat?{
+
+        return try {
+            val room = JidCreate.entityBareFrom(room)
+            val muc: MultiUserChat = manager!!.getMultiUserChat(room)
+            val nickname = Resourcepart.from(myJid.toString())
+            return if(!muc.isJoined){
+                Log.i(TAG, "XMPP successfully connect to Room")
+                muc.join(nickname)
+                muc
+            }else{
+                Log.i(TAG, "XMPP error connect to Room")
+                muc
+            }
+        }catch (e: Exception){
+            Log.e(TAG, e.message.toString())
+            null
+        }
+    }
+    private fun getRoomMessage(message_count: Int, muc_conn: MultiUserChat):ArrayList<Message>? {
+        return try {
+            val mamManager = MamManager.getInstanceFor(muc_conn)
+            val mamQueryArgs = MamManager.MamQueryArgs.builder()
+                .setResultPageSizeTo(message_count)
+                .queryLastPage()
+                .build()
+            val mamQuery = mamManager.queryArchive(mamQueryArgs)
+            var arr = arrayListOf<Message>()
+            arr.addAll(mamQuery.messages)
+            arr
+        } catch (e: Exception) {
+            Log.e(TAG, e.message.toString())
+            null
+        }
+    }
+
+    fun logout() {
+        connection.disconnect()
+    }
+}

+ 2 - 2
app/src/main/java/com/sharix/sportsmanfriend/view/MainActivity.java

@@ -14,10 +14,10 @@ import com.sharix.sportsmanfriend.OnBackPressedListener;
 import com.sharix.sportsmanfriend.R;
 import com.sharix.sportsmanfriend.databinding.ActivityMainBinding;
 import com.sharix.sportsmanfriend.view.fragments.CalendarFragment;
-import com.sharix.sportsmanfriend.view.fragments.ChatsFragment;
 import com.sharix.sportsmanfriend.view.fragments.CreateEventFragment;
 import com.sharix.sportsmanfriend.view.fragments.MapFragment;
 import com.sharix.sportsmanfriend.view.fragments.MoreFragment;
+import com.sharix.sportsmanfriend.view.fragments.SupportFragment;
 
 import org.osmdroid.config.Configuration;
 
@@ -28,7 +28,7 @@ public class MainActivity extends AppCompatActivity implements OnBackPressedList
     MapFragment mapFragment = new MapFragment();
     CalendarFragment calendarFragment = new CalendarFragment();
     CreateEventFragment createEventFragment = new CreateEventFragment();
-    ChatsFragment chatsFragment = new ChatsFragment();
+    SupportFragment chatsFragment = new SupportFragment();
     MoreFragment moreFragment = new MoreFragment();
 
     @Override

+ 0 - 20
app/src/main/java/com/sharix/sportsmanfriend/view/fragments/ChatFragment.java

@@ -1,20 +0,0 @@
-package com.sharix.sportsmanfriend.view.fragments;
-
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-import androidx.fragment.app.Fragment;
-
-import com.sharix.sportsmanfriend.R;
-
-public class ChatFragment extends Fragment {
-
-    @Override
-    public View onCreateView(LayoutInflater inflater, ViewGroup container,
-                             Bundle savedInstanceState) {
-
-        return inflater.inflate(R.layout.fragment_chat, container, false);
-    }
-}

+ 134 - 0
app/src/main/java/com/sharix/sportsmanfriend/view/fragments/ChatFragment.kt

@@ -0,0 +1,134 @@
+package com.sharix.sportsmanfriend.view.fragments
+
+import android.annotation.SuppressLint
+import android.app.ActionBar
+import android.content.SharedPreferences
+import android.os.Bundle
+import android.speech.tts.TextToSpeech
+import android.util.Log
+import android.view.Gravity
+import androidx.fragment.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.LinearLayout
+import android.widget.ScrollView
+import android.widget.TextView
+import androidx.lifecycle.ViewModelProvider
+import androidx.lifecycle.lifecycleScope
+import com.sharix.sportsmanfriend.R
+import com.sharix.sportsmanfriend.databinding.FragmentChat2Binding
+import com.sharix.sportsmanfriend.view.MainActivity
+import com.sharix.sportsmanfriend.viewmodel.XMPPViewModel
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import java.util.*
+
+
+class ChatFragment : Fragment(),TextToSpeech.OnInitListener {
+    private lateinit var xmppViewModel: XMPPViewModel
+    private var _binding: FragmentChat2Binding? = null
+    private val binding get() = _binding!!
+    private var pref: SharedPreferences? = null
+    private var tts: TextToSpeech? = null
+    private val TAG: String = ChatFragment::class.java.simpleName
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        tts = TextToSpeech(context, this)
+    }
+    override fun onCreateView(
+        inflater: LayoutInflater, container: ViewGroup?,
+        savedInstanceState: Bundle?
+    ): View? {
+        _binding = FragmentChat2Binding.inflate(inflater, container, false)
+
+        xmppViewModel = ViewModelProvider(this@ChatFragment)[XMPPViewModel::class.java]
+
+//        pref = activity?.getSharedPreferences(UsefullFunctions.PREFXMPP, Service.MODE_PRIVATE)
+//        val jid = pref?.getString("jid", "!")
+//        val pass = pref?.getString("pass", "!")
+        val jid = "test@msg.sharix-app.org"
+        val pass = "test1234@"
+        var room = activity?.intent?.getStringExtra("room") ?: "testbot@chat.msg.sharix-app.org"
+        //var intent = Intent(activity, XMPPListener::class.java)
+        //activity?.startService(intent)
+        //(activity as MainActivity).supportActionBar?.title = activity?.intent?.getStringExtra("room_name") ?: "Чат"
+        //binding.cpvLoader.visibility = View.VISIBLE
+        if(xmppViewModel.message.value.isNullOrEmpty()){
+            val value = lifecycleScope.launch(Dispatchers.Main) {
+                xmppViewModel.login(jid!!, pass!!, room)
+                Log.e("MAIN", "Out from corutine")
+            }
+            value.invokeOnCompletion {
+                Log.e("MAIN", value.toString())
+                //binding.cpvLoader.visibility = View.GONE
+                generateMessage(jid!!)
+            }
+        }else{
+            //binding.cpvLoader.visibility = View.GONE
+            generateMessage(jid!!)
+        }
+        binding.sendBtn.setOnClickListener {
+            xmppViewModel.sendMessage(binding.messageEditText.text.toString())
+            binding.messageEditText.text.clear()
+        }
+
+        return binding.root
+    }
+
+    //@SuppressLint("UseCompatLoadingForDrawables", "RtlHardcoded")
+    fun generateMessage(login: String) {
+        xmppViewModel.message.observe(viewLifecycleOwner){
+            //binding.messageContainer.removeAllViews()
+            for(item in it){
+//                var rectangle = TextView(context)
+//                rectangle.width = 300
+//                rectangle.height = 300
+//                rectangle.background = context?.getDrawable(R.drawable.white_border)
+//                binding.messageContainer.addView(rectangle)
+                var message = TextView(context)
+                val params = LinearLayout.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT)
+                //params.setMargins(10, 20, 10, 10)
+                context?.let { it1 -> message.setTextColor(it1.getColor(R.color.black)) }
+                //print(item.from)
+                if(item.from.toString().split("/")[1] == login) {
+                    params.setMargins(200, 20, 10, 10)
+                    message.background = context?.getDrawable(R.drawable.white_border)
+                    params.gravity = Gravity.RIGHT
+                    message.layoutParams = params
+                }else{
+                    params.setMargins(10, 20, 200, 10)
+                    message.background = context?.getDrawable(R.drawable.white_border)
+                    message.layoutParams = params
+                    //message.setOnClickListener { tts!!.speak(item.body.toString(), TextToSpeech.QUEUE_FLUSH, null, "Not supported") }
+                }
+                message.text = item.body.toString()
+                binding.messageContainer.addView(message)
+                scrollToBottom()
+                Log.e("XMPP", item.body)
+
+            }
+        }
+
+    }
+    private fun scrollToBottom(){
+        binding.chatScroll.post {
+            binding.chatScroll.fullScroll(ScrollView.FOCUS_DOWN)
+        }
+    }
+
+    override fun onInit(p0: Int) {
+
+        if (p0 == TextToSpeech.SUCCESS) {
+            val result = tts!!.setLanguage(Locale("ru"))
+
+            if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
+                Log.e("TTS","The Language not supported!")
+            } else {
+                Log.e("TTS","Supported!")
+            }
+        }else{
+            Log.e("TTS", "some error $p0")
+        }
+    }
+}

+ 0 - 42
app/src/main/java/com/sharix/sportsmanfriend/view/fragments/ChatsFragment.java

@@ -1,42 +0,0 @@
-package com.sharix.sportsmanfriend.view.fragments;
-
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.LinearLayout;
-
-import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentManager;
-import androidx.fragment.app.FragmentTransaction;
-
-import com.sharix.sportsmanfriend.R;
-
-public class ChatsFragment extends Fragment {
-
-    private LinearLayout chat;
-    private View view;
-
-    @Override
-    public View onCreateView(LayoutInflater inflater, ViewGroup container,
-                             Bundle savedInstanceState) {
-        view =  inflater.inflate(R.layout.fragment_chats, container, false);
-
-        chat = view.findViewById(R.id.supportChat);
-
-        addClickEventToAllViews();
-
-        return view;
-    }
-
-    private void addClickEventToAllViews() {
-        chat.setOnClickListener(v -> {
-            FragmentManager fragmentManager = requireActivity().getSupportFragmentManager();
-            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
-            ChatFragment myFragment = new ChatFragment();
-            fragmentTransaction.replace(R.id.frameWindow, myFragment);
-            fragmentTransaction.addToBackStack(null);
-            fragmentTransaction.commit();
-        });
-    }
-}

+ 2 - 3
app/src/main/java/com/sharix/sportsmanfriend/view/fragments/ProfileFragment.java

@@ -1,13 +1,12 @@
 package com.sharix.sportsmanfriend.view.fragments;
 
 import android.os.Bundle;
-
-import androidx.fragment.app.Fragment;
-
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 
+import androidx.fragment.app.Fragment;
+
 import com.sharix.sportsmanfriend.R;
 
 public class ProfileFragment extends Fragment {

+ 102 - 0
app/src/main/java/com/sharix/sportsmanfriend/view/fragments/SupportFragment.kt

@@ -0,0 +1,102 @@
+package com.sharix.sportsmanfriend.view.fragments
+
+import android.content.SharedPreferences
+import android.os.Bundle
+import android.util.Log
+import androidx.fragment.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.lifecycle.ViewModelProvider
+import androidx.lifecycle.lifecycleScope
+import androidx.navigation.fragment.findNavController
+import com.sharix.sportsmanfriend.R
+import com.sharix.sportsmanfriend.databinding.FragmentSupportBinding
+import com.sharix.sportsmanfriend.viewmodel.XMPPViewModel
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+
+class SupportFragment : Fragment() {
+    private lateinit var xmppViewModel: XMPPViewModel
+    private var _binding: FragmentSupportBinding? = null
+    private val binding get() = _binding!!
+    private var pref: SharedPreferences? = null
+
+    override fun onCreateView(
+        inflater: LayoutInflater, container: ViewGroup?,
+        savedInstanceState: Bundle?
+    ): View? {
+        _binding = FragmentSupportBinding.inflate(inflater, container, false)
+//        activity?.stopService(Intent(context, XMPPListener::class.java))
+        xmppViewModel = ViewModelProvider(this@SupportFragment)[XMPPViewModel::class.java]
+        //pref = activity?.getSharedPreferences(UsefullFunctions.PREFXMPP, Service.MODE_PRIVATE)
+//        val jid = pref?.getString("jid", "!")
+//        val pass = pref?.getString("pass", "!")
+//        val room1 = pref?.getString("room1", "!")
+//        val room2 = pref?.getString("room2", "!")
+//        val room3 = pref?.getString("room3", "!")
+        val jid = "test@msg.sharix-app.org"
+        val pass = "test1234@"
+        val room1 = "testbot@chat.msg.sharix-app.org"
+        val room2 = "general@chat.msg.sharix-app.org"
+        val room3 = "order001@chat.msg.sharix-app.org"
+        if(xmppViewModel.roomMessage1.value.isNullOrEmpty()
+            || xmppViewModel.roomMessage2.value.isNullOrEmpty()
+            || xmppViewModel.roomMessage3.value.isNullOrEmpty()){
+            val value = lifecycleScope.launch(Dispatchers.Main) {
+                xmppViewModel.addRoomListener(jid!!, pass!!,
+                    arrayListOf(room1!!, room2!!, room3!!))
+                Log.e("MAIN", "Out from corutine")
+            }
+            value.invokeOnCompletion {
+                Log.e("MAIN", value.toString())
+                roomsSetClickListeners(room1!!, room2!!, room3!!)
+                addRoomListeners()
+            }
+        }
+
+
+        return binding.root
+    }
+    private fun roomsSetClickListeners(room1:String, room2:String, room3:String){
+        binding.supportChat.setOnClickListener {
+            activity?.intent?.putExtra("room", room1)
+            activity?.intent?.putExtra("room_name", "Чат службы техподдержки")
+            loadFragment(ChatFragment())
+        }
+        binding.serviceBot.setOnClickListener {
+            activity?.intent?.putExtra("room", room2)
+            activity?.intent?.putExtra("room_name", "Чат сервисного бота")
+            loadFragment(ChatFragment())
+        }
+        binding.providerChat.setOnClickListener {
+            activity?.intent?.putExtra("room", room3)
+            activity?.intent?.putExtra("room_name", "Чат поставщика услуг")
+            loadFragment(ChatFragment())
+        }
+    }
+    private fun addRoomListeners(){
+        xmppViewModel.roomMessage1.observe(viewLifecycleOwner){
+            for(item in it){
+                binding.supportLastMsg.text = item.body
+            }
+        }
+        xmppViewModel.roomMessage2.observe(viewLifecycleOwner){
+            for(item in it){
+                binding.serviceBotLastMsg.text = item.body
+            }
+        }
+        xmppViewModel.roomMessage3.observe(viewLifecycleOwner){
+            for(item in it){
+                binding.providerLastMsg.text = item.body
+            }
+        }
+    }
+
+    private fun loadFragment(fragment: Fragment){
+        val transaction = activity?.supportFragmentManager?.beginTransaction()
+        transaction?.replace(R.id.frameWindow, fragment)
+        transaction?.disallowAddToBackStack()
+        transaction?.commit()
+    }
+}

+ 46 - 0
app/src/main/java/com/sharix/sportsmanfriend/viewmodel/XMPPViewModel.kt

@@ -0,0 +1,46 @@
+package com.sharix.sportsmanfriend.viewmodel
+
+import android.app.Application
+import android.util.Log
+import androidx.lifecycle.AndroidViewModel
+import androidx.lifecycle.LiveData
+import com.sharix.sportsmanfriend.repository.XMPPRepository
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.async
+import kotlinx.coroutines.withContext
+import org.jivesoftware.smack.packet.Message
+
+class XMPPViewModel(application: Application) : AndroidViewModel(application) {
+    private val xmppRepository: XMPPRepository = XMPPRepository()
+    val message: LiveData<ArrayList<Message>> get() = xmppRepository.messagesLiveData
+    val roomMessage1: LiveData<ArrayList<Message>> get() = xmppRepository.messageRoom1
+    val roomMessage2: LiveData<ArrayList<Message>> get() = xmppRepository.messageRoom2
+    val roomMessage3: LiveData<ArrayList<Message>> get() = xmppRepository.messageRoom3
+    suspend fun login(jid: String, password: String, room: String){
+        GlobalScope.async {
+            //xmppRepository.connect()
+            xmppRepository.login(jid, password)
+            withContext(Dispatchers.Main){
+                xmppRepository.messageListener(room, 20)
+            }
+        }.await()
+    }
+    suspend fun addRoomListener(jid: String, password: String, rooms: ArrayList<String>){
+        GlobalScope.async {
+            //xmppRepository.connect()
+            xmppRepository.login(jid, password)
+            withContext(Dispatchers.Main){
+                var count = 1
+                for(room in rooms){
+                    Log.e("XMPP", count.toString())
+                    xmppRepository.messageListener(room, 1, count)
+                    count += 1
+                }
+            }
+        }.await()
+    }
+    fun sendMessage(msg: String) {
+        xmppRepository.sendMessage(msg)
+    }
+}

+ 21 - 20
app/src/main/res/layout/fragment_chat.xml → app/src/main/res/layout/fragment_chat2.xml

@@ -4,35 +4,35 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    style="@style/AppBack"
     tools:context=".view.fragments.ChatFragment">
 
     <ScrollView
         android:id="@+id/chatScroll"
         android:layout_width="match_parent"
         android:layout_height="0dp"
-        app:layout_constraintBottom_toTopOf="parent"
+        app:layout_constraintBottom_toTopOf="@+id/linearLayout2"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent">
 
         <LinearLayout
             android:id="@+id/messageContainer"
-            android:orientation="vertical"
-            android:padding="10sp"
             android:layout_width="match_parent"
-            android:layout_height="match_parent">
+            android:layout_height="wrap_content"
+            android:orientation="vertical"
+            android:padding="10sp">
 
-            <com.github.rahatarmanahmed.cpv.CircularProgressView
+            <!--<com.github.rahatarmanahmed.cpv.CircularProgressView
                 android:id="@+id/cpv_loader"
                 android:layout_width="40sp"
                 android:layout_height="40sp"
-                android:layout_marginTop="16dp"
                 android:layout_gravity="center"
+                android:layout_marginTop="16dp"
                 android:visibility="gone"
-                app:cpv_color="@color/MainColor"
                 app:cpv_animAutostart="true"
-                app:cpv_indeterminate="true"
-                />
+                app:cpv_color="@color/MainColor"
+                app:cpv_indeterminate="true" />-->
         </LinearLayout>
     </ScrollView>
 
@@ -47,31 +47,32 @@
 
         <EditText
             android:id="@+id/messageEditText"
-            android:layout_width="wrap_content"
             style="@style/Input"
-            android:padding="10dp"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
             android:layout_marginStart="15sp"
             android:layout_marginEnd="15sp"
+            android:layout_weight="0.1"
             android:hint="Send message..."
             android:inputType="textMultiLine"
-            android:layout_height="wrap_content"
-            android:layout_weight="0.1" />
+            android:padding="10dp" />
 
         <androidx.cardview.widget.CardView
-            app:cardCornerRadius="100dp"
             android:layout_width="wrap_content"
-            android:elevation="100dp"
+            android:layout_height="wrap_content"
             android:layout_marginEnd="15sp"
             android:layout_marginBottom="15sp"
-            android:layout_height="wrap_content">
+            android:elevation="100dp"
+            app:cardCornerRadius="100dp">
+
             <ImageView
                 android:id="@+id/sendBtn"
-                android:src="@drawable/ic_sport_icon"
-                android:padding="5sp"
-                android:paddingStart="10sp"
-                android:background="@color/MainColor"
                 android:layout_width="40sp"
                 android:layout_height="40sp"
+                android:background="@color/MainColor"
+                android:padding="5sp"
+                android:paddingStart="10sp"
+                android:src="@drawable/ic_sport_icon"
                 app:tint="@color/white" />
         </androidx.cardview.widget.CardView>
 

+ 1 - 3
app/src/main/res/layout/fragment_chats.xml → app/src/main/res/layout/fragment_support.xml

@@ -4,7 +4,7 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    tools:context=".view.fragments.ChatsFragment">
+    tools:context=".view.fragments.SupportFragment">
 
     <androidx.constraintlayout.widget.ConstraintLayout
         android:layout_width="match_parent"
@@ -17,8 +17,6 @@
             android:layout_height="wrap_content"
             android:layout_gravity="center_vertical"
             android:text="Chats"
-            android:layout_marginStart="15dp"
-            android:layout_marginTop="15dp"
             app:layout_constraintStart_toStartOf="parent"
             app:layout_constraintTop_toTopOf="parent" />
 

+ 1 - 0
app/src/main/res/values/colors.xml

@@ -3,6 +3,7 @@
     <color name="purple_200">#FFBB86FC</color>
     <color name="purple_500">#FF6200EE</color>
     <color name="purple_700">#FF3700B3</color>
+    <color name="red">#FF0000</color>
     <color name="teal_200">#FF03DAC5</color>
     <color name="teal_700">#FF018786</color>
     <color name="black">#FF000000</color>

+ 1 - 0
build.gradle

@@ -2,4 +2,5 @@
 plugins {
     id 'com.android.application' version '7.3.0' apply false
     id 'com.android.library' version '7.3.0' apply false
+    id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
 }