diff --git a/app/build.gradle b/app/build.gradle index 35a615a..4a7e74d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,14 +10,13 @@ android { applicationId "ir.fanap.chattestapp" minSdkVersion 17 targetSdkVersion 28 - versionCode 1 - versionName "1.0" + versionCode 2 + versionName "0.1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.setUseSupportLibrary(true) multiDexEnabled true vectorDrawables.useSupportLibrary = true - } buildTypes { release { @@ -77,11 +76,16 @@ dependencies { // kapt "com.google.dagger:dagger-compiler:2.16" implementation 'com.wang.avi:library:2.1.3' implementation 'com.github.javafaker:javafaker:0.17.2' - implementation 'com.fanap.podchat:podchat:0.4.2.0' + + //Chat SDK + implementation 'com.fanap.podchat:podchat:0.4.2.4' + implementation 'com.android.support:cardview-v7:28.0.0' implementation 'com.android.support:design:28.0.0' // implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:support-v4:28.0.0' implementation 'com.google.code.gson:gson:2.2.4' + + implementation 'com.sendbird.sdk:sendbird-android-sdk:3.0.95' } diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/LogListener.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/LogListener.kt deleted file mode 100644 index c447984..0000000 --- a/app/src/main/java/ir/fanap/chattestapp/application/ui/LogListener.kt +++ /dev/null @@ -1,6 +0,0 @@ -package ir.fanap.chattestapp.application.ui - -interface LogListener { - fun onLogEvent(log: String) {} - -} \ No newline at end of file diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/MainActivity.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/MainActivity.kt index e7d7365..6a28d59 100644 --- a/app/src/main/java/ir/fanap/chattestapp/application/ui/MainActivity.kt +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/MainActivity.kt @@ -1,22 +1,61 @@ package ir.fanap.chattestapp.application.ui +import android.Manifest +import android.arch.lifecycle.ViewModelProvider +import android.arch.lifecycle.ViewModelProviders +import android.content.Intent +import android.content.pm.PackageManager import android.support.v7.app.AppCompatActivity import android.os.Bundle -import android.support.design.widget.BottomSheetBehavior +import android.os.Handler +import android.support.v4.app.ActivityCompat +import android.support.v4.content.ContextCompat import android.support.v4.view.ViewPager +import android.util.Log +import android.widget.Toast +import ir.fanap.chattestapp.BuildConfig import ir.fanap.chattestapp.R import kotlinx.android.synthetic.main.activity_main_bubble.* -class MainActivity : AppCompatActivity() { +class MainActivity : AppCompatActivity(), TestListener { + + private val REQUEST_CODE: Int = 1 + private var doubleBackToExitPressedOnce: Boolean = false + private lateinit var mainViewModel: MainViewModel + private val TOKEN = "5fb88da4c6914d07a501a76d68a62363" + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main_bubble) + + mainViewModel =ViewModelProviders.of(this).get(MainViewModel::class.java) + + setupViewPager() + + val permission = ContextCompat.checkSelfPermission( + this, + Manifest.permission.READ_EXTERNAL_STORAGE + ) + + if (permission != PackageManager.PERMISSION_GRANTED) { + makeRequest() + } + } + + override fun connectActivity() { + super.connectActivity() + mainViewModel.connect( + BuildConfig.SOCKET_ADDRESS, BuildConfig.APP_ID, BuildConfig.SERVER_NAME + , TOKEN, BuildConfig.SSO_HOST, BuildConfig.PLATFORM_HOST, BuildConfig.FILE_SERVER, null + ) + } + + private fun setupViewPager() { val titles = arrayOf("chat", "Function", "Log") val viewPager: ViewPager = findViewById(R.id.view_pager) val pagerAdapter = PagerAdapter(supportFragmentManager, titles) -// supportFragmentManager.beginTransaction().add(LogFragment.newInstance(), "LogFragment").commit() viewPager.adapter = pagerAdapter viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { override fun onPageScrollStateChanged(state: Int) { @@ -36,11 +75,49 @@ class MainActivity : AppCompatActivity() { viewPager.offscreenPageLimit = 2 } + private fun makeRequest() { + val permissions = arrayOf( + Manifest.permission.READ_EXTERNAL_STORAGE + , Manifest.permission.INTERNET + , Manifest.permission.WRITE_EXTERNAL_STORAGE + ) + ActivityCompat.requestPermissions( + this, permissions, + REQUEST_CODE + ) + + } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + when (requestCode) { + REQUEST_CODE -> { + + if (grantResults.isEmpty() || grantResults[0] != PackageManager.PERMISSION_GRANTED) { + + Log.i("Chat", "Permission has been denied by user") + } else { + Log.i("Chat", "Permission has been granted by user") + } + } + } + } + // override fun onBackPressed() { -// val fragment: LogFragment = supportFragmentManager.findFragmentByTag("LogFragment") as LogFragment -// (fragment as? IOnBackPressed)?.onBackPressed()?.not()?.let { -// super.onBackPressed() -// } + if (doubleBackToExitPressedOnce) { + super.onBackPressed() + return + } + + this.doubleBackToExitPressedOnce = true + Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show() + + Handler().postDelayed(Runnable { doubleBackToExitPressedOnce = false }, 2000) + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + } } diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/MainViewModel.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/MainViewModel.kt index 665664a..c0b1cbb 100644 --- a/app/src/main/java/ir/fanap/chattestapp/application/ui/MainViewModel.kt +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/MainViewModel.kt @@ -4,6 +4,8 @@ import android.app.Application import android.arch.lifecycle.AndroidViewModel import android.content.Context import android.net.Uri +import android.os.Handler +import android.os.Looper import android.support.v4.app.FragmentActivity import com.fanap.podchat.ProgressHandler import com.fanap.podchat.chat.Chat @@ -12,15 +14,19 @@ import com.fanap.podchat.mainmodel.Invitee import com.fanap.podchat.mainmodel.ResultDeleteMessage import com.fanap.podchat.model.* import com.fanap.podchat.requestobject.* +import ir.fanap.chattestapp.application.ui.log.LogListener +import ir.fanap.chattestapp.application.ui.upload.UploadListener import rx.subjects.PublishSubject import java.util.* + class MainViewModel(application: Application) : AndroidViewModel(application) { private var chat: Chat = Chat.init(application) private lateinit var testListener: TestListener + private lateinit var uploadListener: UploadListener + private lateinit var logListener: LogListener var observable: PublishSubject = PublishSubject.create() - var observableLog: PublishSubject = PublishSubject.create() init { chat.isLoggable(true) @@ -38,17 +44,18 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { override fun onNewMessage(content: String?, response: ChatResponse?) { super.onNewMessage(content, response) testListener.onNewMessage(response) - } override fun onError(content: String?, OutPutError: ErrorOutPut?) { super.onError(content, OutPutError) testListener.onError(OutPutError) + uploadListener.onError(OutPutError) } override fun onCreateThread(content: String?, response: ChatResponse?) { super.onCreateThread(content, response) testListener.onCreateThread(response) + uploadListener.onCreateThread(response) } override fun onContactAdded(content: String?, response: ChatResponse?) { @@ -69,6 +76,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { override fun onGetContacts(content: String?, response: ChatResponse?) { super.onGetContacts(content, response) testListener.onGetContact(response) + uploadListener.onGetContact(response) } override fun onGetBlockList(content: String?, response: ChatResponse?) { @@ -78,7 +86,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { override fun OnLogEvent(log: String) { super.OnLogEvent(log) - testListener.onLogEvent(log) + logListener.onLogEvent(log) } override fun onUpdateContact(content: String?, response: ChatResponse?) { @@ -93,12 +101,16 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { override fun onSent(content: String?, response: ChatResponse?) { super.onSent(content, response) + testListener.onSent(response) + + uploadListener.onSent(response) } override fun onGetThread(content: String?, thread: ChatResponse?) { super.onGetThread(content, thread) testListener.onGetThread(thread) + uploadListener.onGetThreadU() } override fun onSeen(content: String?, response: ChatResponse?) { @@ -106,6 +118,19 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { testListener.onSeen(response) } + override fun onUploadFile(content: String?, response: ChatResponse?) { + super.onUploadFile(content, response) + testListener.onUploadFile(response) + uploadListener.onUploadFile(response) + } + + override fun onUploadImageFile(content: String?, response: ChatResponse?) { + super.onUploadImageFile(content, response) + testListener.onUploadImageFile(response) + uploadListener.onUploadImageFile(response) + + } + override fun onDeliver(content: String?, response: ChatResponse?) { super.onDeliver(content, response) testListener.onDeliver(response) @@ -150,24 +175,26 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { super.onGetHistory(content, response) testListener.onGetHistory(response) } - }) } + fun setLogListener(logListener: LogListener) { + this.logListener = logListener + } + fun setTestListener(testListener: TestListener) { this.testListener = testListener } + fun setUploadListener(uploadListener: UploadListener) { + this.uploadListener = uploadListener + } + fun connect( socketAddress: String, appId: String, severName: String, token: String, ssoHost: String, platformHost: String, fileServer: String, typeCode: String? ) { chat.connect(socketAddress, appId, severName, token, ssoHost, platformHost, fileServer, typeCode) - chat.addListener(object : ChatListener { - override fun onUserInfo(content: String?, response: ChatResponse?) { - super.onUserInfo(content, response) - } - }) } fun uploadFile(requestUploadFile: RequestUploadFile): String { @@ -191,7 +218,10 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { return chat.sendFileMessage(requestFileMessage, objects) } - fun replyWithFile(requestReplyMessage: RequestReplyFileMessage, objects: ProgressHandler.sendFileMessage): String { + fun replyFileMessage( + requestReplyMessage: RequestReplyFileMessage, + objects: ProgressHandler.sendFileMessage + ): String { return chat.replyFileMessage(requestReplyMessage, objects) } @@ -260,7 +290,6 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { return chat.removeContact(requestRemoveContact) } - fun blockContact(requestBlock: RequestBlock): String { return chat.block(requestBlock, null) } @@ -308,4 +337,5 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { fun getParticipant(requestThreadParticipant: RequestThreadParticipant): String { return chat.getThreadParticipants(requestThreadParticipant, null) } -} \ No newline at end of file +} + diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/PagerAdapter.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/PagerAdapter.kt index a8957d4..3443be2 100644 --- a/app/src/main/java/ir/fanap/chattestapp/application/ui/PagerAdapter.kt +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/PagerAdapter.kt @@ -2,13 +2,15 @@ package ir.fanap.chattestapp.application.ui import android.support.v4.app.Fragment import android.support.v4.app.FragmentManager -import android.support.v4.app.FragmentPagerAdapter import android.support.v4.app.FragmentStatePagerAdapter -import ir.fanap.chattestapp.application.ui.chat.ChatFragment +import ir.fanap.chattestapp.application.ui.upload.UploadFragment import ir.fanap.chattestapp.application.ui.function.FunctionFragment import ir.fanap.chattestapp.application.ui.log.LogFragment -class PagerAdapter(fragmentManager: FragmentManager, private val pageTitles: Array) : +class PagerAdapter( + fragmentManager: FragmentManager, + private val pageTitles: Array +) : FragmentStatePagerAdapter(fragmentManager) { override fun getCount(): Int { @@ -22,7 +24,7 @@ class PagerAdapter(fragmentManager: FragmentManager, private val pageTitles: Arr when(position){ 0 -> return FunctionFragment.newInstance() 1 -> return LogFragment.newInstance() - 2 -> return ChatFragment.newInstance() + 2 -> return UploadFragment.newInstance() } return null } @@ -30,5 +32,4 @@ class PagerAdapter(fragmentManager: FragmentManager, private val pageTitles: Arr override fun getPageTitle(position: Int): CharSequence? { return pageTitles[position] } - } \ No newline at end of file diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/TestListener.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/TestListener.kt index a5b5530..fb3a5e8 100644 --- a/app/src/main/java/ir/fanap/chattestapp/application/ui/TestListener.kt +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/TestListener.kt @@ -10,7 +10,9 @@ interface TestListener { fun onCreateThread(response: ChatResponse?) {} fun onBlock(chatResponse: ChatResponse?) {} fun onUnBlock(response: ChatResponse?) {} - fun onGetThread(chatResponse: ChatResponse?) {} + fun onGetThread(chatResponse: ChatResponse?) { + + } fun onError(chatResponse: ErrorOutPut?) {} fun onRemoveContact(response: ChatResponse?) {} fun onBlockList(response: ChatResponse?) {} @@ -65,4 +67,19 @@ interface TestListener { } + + fun onUploadFile(response: ChatResponse?) { + + + } + + fun onUploadImageFile(response: ChatResponse?) { + + + } + + fun onChatState(state: String?) { + + } + fun connectActivity(){} } \ No newline at end of file diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/chat/ChatFragment.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/chat/ChatFragment.kt deleted file mode 100644 index cef6705..0000000 --- a/app/src/main/java/ir/fanap/chattestapp/application/ui/chat/ChatFragment.kt +++ /dev/null @@ -1,403 +0,0 @@ -package ir.fanap.chattestapp.application.ui.chat - -import android.os.Bundle -import android.support.v4.app.Fragment -import android.support.v7.widget.AppCompatImageView -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import ir.fanap.chattestapp.R -import android.animation.Animator -import android.arch.lifecycle.ViewModelProvider -import android.content.Context -import android.content.Intent -import android.net.Uri -import android.os.Build -import android.provider.MediaStore -import android.support.design.circularreveal.CircularRevealCompat -import android.support.design.circularreveal.cardview.CircularRevealCardView -import android.support.v4.content.ContextCompat -import android.view.animation.AccelerateDecelerateInterpolator -import android.widget.ProgressBar -import android.widget.TextView -import android.widget.Toast -import com.fanap.podchat.ProgressHandler -import com.fanap.podchat.mainmodel.Contact -import com.fanap.podchat.mainmodel.Invitee -import com.fanap.podchat.mainmodel.RequestThreadInnerMessage -import com.fanap.podchat.model.* -import com.fanap.podchat.requestobject.* -import com.fanap.podchat.util.ThreadType -import com.github.javafaker.Faker -import ir.fanap.chattestapp.application.ui.MainViewModel -import ir.fanap.chattestapp.application.ui.TestListener -import ir.fanap.chattestapp.application.ui.util.ConstantMsgType -import java.util.ArrayList - -class ChatFragment : Fragment(), TestListener { - private lateinit var atach_file: AppCompatImageView - private lateinit var mainViewModel: MainViewModel - private var fucCallback: HashMap = hashMapOf() - private val REQUEST_TAKE_PHOTO = 0 - private val REQUEST_SELECT_IMAGE_IN_ALBUM = 1 - private lateinit var contextFrag: Context - private var imageUrl: Uri? = null - private lateinit var txtViewFileMsg: TextView - private lateinit var txtViewUploadFile: TextView - private lateinit var txtViewUploadImage: TextView - private lateinit var txtViewReplyFileMsg: TextView - private lateinit var imageView_tickOne: AppCompatImageView - private lateinit var imageView_tickTwo: AppCompatImageView - private lateinit var imageView_tickThree: AppCompatImageView - private lateinit var imageView_tickFour: AppCompatImageView - private lateinit var prgressbarUploadImg: ProgressBar - private lateinit var buttonUploadImage: AppCompatImageView - - - private val faker: Faker = Faker() - - companion object { - fun newInstance(): ChatFragment { - return ChatFragment() - } - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - } - - override fun onAttach(context: Context?) { - super.onAttach(context) - contextFrag = context!! - } - - /*private void circularRevealFromMiddle(@NonNull final T circularRevealWidget) { - circularRevealWidget.post(new Runnable() { - @Override - public void run() { - int viewWidth = circularRevealWidget.getWidth(); - int viewHeight = circularRevealWidget.getHeight(); - - int viewDiagonal = (int) Math.sqrt(viewWidth * viewWidth + viewHeight * viewHeight); - - final AnimatorSet animatorSet = new AnimatorSet(); - animatorSet.playTogether( - CircularRevealCompat.createCircularReveal(circularRevealWidget, viewWidth / 2, viewHeight / 2, 10, viewDiagonal / 2), - ObjectAnimator.ofArgb(circularRevealWidget, CircularRevealWidget.CircularRevealScrimColorProperty.CIRCULAR_REVEAL_SCRIM_COLOR, Color.RED, Color.TRANSPARENT)); - - animatorSet.setDuration(5000); - animatorSet.start(); - } - }); -}*/ - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - val view = inflater.inflate(R.layout.fragment_chat, container, false) - val cicuralCard: CircularRevealCardView = view.findViewById(R.id.ccv_attachment_reveal) - val appCompatImageView_gallery: AppCompatImageView = view.findViewById(R.id.appCompatImageView_gallery) - imageView_tickOne = view.findViewById(R.id.checkBox_Send_File_Msg) - imageView_tickTwo = view.findViewById(R.id.checkBox_Upload_File) - imageView_tickThree = view.findViewById(R.id.checkBox_Reply_File_Msg) - imageView_tickFour = view.findViewById(R.id.checkBox_ufil) - - buttonUploadImage = view.findViewById(R.id.buttonUploadImage) - - txtViewFileMsg = view.findViewById(R.id.TxtViewFileMsg) - txtViewUploadFile = view.findViewById(R.id.TxtViewUploadFile) - txtViewUploadImage = view.findViewById(R.id.TxtViewUploadImage) - txtViewReplyFileMsg = view.findViewById(R.id.TxtViewReplyFileMsg) - - prgressbarUploadImg = view.findViewById(R.id.progress_UploadImage) - - txtViewFileMsg.setOnClickListener { fileMsg() } - txtViewUploadFile.setOnClickListener { uploadFile() } - buttonUploadImage.setOnClickListener { - // uploadImage() - uploadImageProgress() - } - txtViewReplyFileMsg.setOnClickListener { replyFileMsg() } - - - val appCmpImgViewFolder: AppCompatImageView = view.findViewById(R.id.appCompatImageView_folder) - - appCompatImageView_gallery.setOnClickListener { - selectImageInAlbum() - } - var isOpen = false - atach_file = view.findViewById(R.id.atach_file) - atach_file.setOnClickListener { - - if (!isOpen) { - - val x = cicuralCard.left - val y = cicuralCard.bottom - - val startRadius = 0 - val endRadius = Math.hypot(cicuralCard.width.toDouble(), cicuralCard.height.toDouble()) - - val anim: Animator = - CircularRevealCompat.createCircularReveal( - cicuralCard, - x.toFloat(), - y.toFloat(), - startRadius.toFloat(), - endRadius.toFloat() - ) - anim.interpolator = AccelerateDecelerateInterpolator() -// cicuralCard.visibility = View.VISIBLE - anim.duration = 50000 - anim.start() - - isOpen = true - - } else { - - val x = cicuralCard.left - val y = cicuralCard.bottom - - val endRadius = Math.max(cicuralCard.width, cicuralCard.height) - val startRadius = 0 - - - val anim: Animator = - CircularRevealCompat.createCircularReveal( - cicuralCard, - x.toFloat(), - y.toFloat(), - startRadius.toFloat(), - endRadius.toFloat() - ) - anim.addListener(object : Animator.AnimatorListener { - override fun onAnimationStart(p0: Animator?) { - - } - - override fun onAnimationCancel(p0: Animator?) { - } - - override fun onAnimationRepeat(p0: Animator?) { - } - - override fun onAnimationEnd(p0: Animator?) { -// cicuralCard.visibility = View.GONE - } - }) - anim.interpolator = AccelerateDecelerateInterpolator() - anim.duration = 50000 - anim.start() - isOpen = false - } - } - return view - } - - override fun onSent(response: ChatResponse?) { - super.onSent(response) - if (fucCallback[ConstantMsgType.REPLY_MESSAGE_ID] == response?.uniqueId) { - val messageId = response?.result?.messageId - val threadId = fucCallback[ConstantMsgType.REPLY_MESSAGE_THREAD_ID] - val replyFileMessage = RequestReplyFileMessage - .Builder("this is replyMessage", threadId?.toLong()!!, messageId!!, imageUrl, activity) - .build() - fucCallback[ConstantMsgType.REPLY_FILE_MESSAGE] = mainViewModel - .replyWithFile(replyFileMessage, object : ProgressHandler.sendFileMessage { - override fun onFinishImage(json: String?, chatResponse: ChatResponse?) { - super.onFinishImage(json, chatResponse) - imageView_tickFour.setImageResource(R.drawable.ic_round_done_all_24px) - imageView_tickFour.setColorFilter(ContextCompat.getColor(activity!!, R.color.colorPrimary)) - } - - override fun onProgressUpdate( - uniqueId: String?, - bytesSent: Int, - totalBytesSent: Int, - totalBytesToSend: Int - ) { - super.onProgressUpdate(uniqueId, bytesSent, totalBytesSent, totalBytesToSend) - - } - }) - } - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - mainViewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(activity!!.application) - .create(MainViewModel::class.java) - - mainViewModel.setTestListener(this) - } - - override fun onGetContact(response: ChatResponse?) { - super.onGetContact(response) - if (fucCallback[ConstantMsgType.SEND_FILE_MESSAGE] == response?.uniqueId) { - handleSendFileMsg(response!!.result.contacts) - } - - if (fucCallback[ConstantMsgType.REPLY_FILE_MESSAGE] == response?.uniqueId) { - handleReplyFileMessage(response!!.result.contacts) - } - } - - override fun onError(chatResponse: ErrorOutPut?) { - super.onError(chatResponse) - activity?.runOnUiThread { - Toast.makeText(activity, chatResponse?.errorMessage, Toast.LENGTH_LONG).show() - } - } - - override fun onCreateThread(response: ChatResponse?) { - super.onCreateThread(response) - if (fucCallback[ConstantMsgType.SEND_FILE_MESSAGE] == response?.uniqueId) { - val requestFileMessage = RequestFileMessage.Builder(activity, response!!.result.thread.id, imageUrl).build() - mainViewModel.sendFileMessage(requestFileMessage, object : ProgressHandler.sendFileMessage { - override fun onFinishImage(json: String?, chatResponse: ChatResponse?) { - super.onFinishImage(json, chatResponse) - imageView_tickOne.setImageResource(R.drawable.ic_round_done_all_24px) - imageView_tickOne.setColorFilter(ContextCompat.getColor(activity!!, R.color.colorPrimary)) - } - }) - } - - if ((fucCallback[ConstantMsgType.REPLY_MESSAGE_THREAD_ID] == response?.uniqueId)) { - val threadId = response?.result?.thread?.id - fucCallback[ConstantMsgType.REPLY_MESSAGE_THREAD_ID] = threadId.toString() - } - } - - private fun handleReplyFileMessage(contactList: ArrayList) { - if (contactList != null) { - var choose = 0 - for (contact: Contact in contactList) { - if (contact.isHasUser) { - choose++ - if (choose == 1) { - val contactId = contact.id - - val inviteList = ArrayList() - inviteList.add(Invitee(contactId, 1)) - val requestThreadInnerMessage = - RequestThreadInnerMessage.Builder().message(faker.music().genre()).build() - val requestCreateThread: RequestCreateThread = - RequestCreateThread.Builder(0, inviteList) - .message(requestThreadInnerMessage) - .build() - val uniqueId = mainViewModel.createThreadWithMessage(requestCreateThread) - fucCallback[ConstantMsgType.REPLY_MESSAGE_THREAD_ID] = uniqueId!![0] - fucCallback[ConstantMsgType.REPLY_MESSAGE_ID] = uniqueId[1] - } - break - } - } - } - } - - private fun handleSendFileMsg(contactList: ArrayList) { - - if (contactList != null) { - var choose = 0 - for (contact: Contact in contactList) { - if (contact.isHasUser) { - choose++ - if (choose == 1) { - val contactId = contact.id - - val inviteList = ArrayList() - inviteList.add(Invitee(contactId, 1)) - - val list = Array(1) { Invitee(inviteList[0].id, 2) } - - val uniqueId = mainViewModel.createThread( - ThreadType.Constants.NORMAL, list, "nothing", "" - , "", "" - ) - fucCallback[ConstantMsgType.SEND_FILE_MESSAGE] = uniqueId - } - break - } - } - } - } - - private fun fileMsg() { - - val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() - val uniqueId = mainViewModel.getContact(requestGetContact) - fucCallback[ConstantMsgType.SEND_FILE_MESSAGE] = uniqueId -// mainViewModel.sendFileMessage() - - } - - fun uploadFile() { - if (imageUrl != null) { - - val requestUploadFile = RequestUploadFile.Builder(activity, imageUrl).build() - mainViewModel.uploadFile(requestUploadFile) - } - } - - //Chat needs update - fun uploadImage() { - if (!imageUrl.toString().isEmpty()) { - mainViewModel.uploadImage(activity, imageUrl!!) - } - } - - fun uploadImageProgress() { -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { -// prgressbarUploadImg.setProgress(100, true) -// } - - - if (!imageUrl.toString().isEmpty()) { -// prgressbarUploadImg.max = 100 -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { -// prgressbarUploadImg.setProgress(10, true) -// } - prgressbarUploadImg.incrementProgressBy(10) - mainViewModel.uploadImageProgress(contextFrag, activity, imageUrl, object : ProgressHandler.onProgress { - override fun onProgressUpdate( - uniqueId: String?, - bytesSent: Int, - totalBytesSent: Int, - totalBytesToSend: Int - ) { - super.onProgressUpdate(uniqueId, bytesSent, totalBytesSent, totalBytesToSend) -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { -// prgressbarUploadImg.setProgress(bytesSent, true) -// } - prgressbarUploadImg.incrementProgressBy(bytesSent) - } - - override fun onFinish(imageJson: String?, chatResponse: ChatResponse?) { - super.onFinish(imageJson, chatResponse) -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { -// prgressbarUploadImg.setProgress(50, true) -// } - prgressbarUploadImg.incrementProgressBy(100) - - } - }) - } - } - - fun replyFileMsg() { - val requestGetContact = RequestGetContact.Builder().build() - fucCallback[ConstantMsgType.REPLY_FILE_MESSAGE] = mainViewModel.getContact(requestGetContact) - } - - fun selectImageInAlbum() { - val i = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI) - startActivityForResult(i, REQUEST_SELECT_IMAGE_IN_ALBUM) - } - - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - if (data != null) { - if (REQUEST_SELECT_IMAGE_IN_ALBUM == requestCode) { - imageUrl = data.data - } - } - } -} - diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/function/FunctionAdapter.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/function/FunctionAdapter.kt index 38b7d4f..7045f2f 100644 --- a/app/src/main/java/ir/fanap/chattestapp/application/ui/function/FunctionAdapter.kt +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/function/FunctionAdapter.kt @@ -33,66 +33,28 @@ class FunctionAdapter( viewHolder.buttonRun.tag = position viewHolder.buttonLog.tag = position - if (methods[position].methodNameFlag == true) { - - context.runOnUiThread { - viewHolder.checkBox.setImageResource(R.drawable.ic_round_done_all_24px) - } - - viewHolder.checkBox.setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary)) + if (methods[position].pending) { + viewHolder.progress_method.visibility = View.VISIBLE } else { - viewHolder.checkBox - .setImageResource(R.drawable.ic_done_black_24dp) - viewHolder.checkBox.setColorFilter(ContextCompat.getColor(context, R.color.grey_light)) + viewHolder.progress_method.visibility = View.GONE } + if (methods[position].methodNameFlag != null && methods[position].methodNameFlag == true) { - if (methods[position].funcOneFlag == true) { - viewHolder.checkBoxOne - .setImageResource(R.drawable.ic_round_done_all_24px) - - viewHolder.checkBoxOne - .setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary)) - } else { - viewHolder.checkBoxOne - .setImageResource(R.drawable.ic_done_black_24dp) - } - - - if (methods[position].funcTwoFlag == true) { - viewHolder.checkBoxSec - .setImageResource(R.drawable.ic_round_done_all_24px) - - viewHolder.checkBoxSec - .setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary)) - } else { - viewHolder.checkBoxSec - .setImageResource(R.drawable.ic_done_black_24dp) - } - - if (methods[position].funcThreeFlag == true) { - viewHolder.checkBoxThird - .setImageResource(R.drawable.ic_round_done_all_24px) + context.runOnUiThread { - viewHolder.checkBoxThird - .setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary)) + viewHolder.buttonLog.setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary)) + } } else { - viewHolder.checkBoxThird - .setImageResource(R.drawable.ic_done_black_24dp) + context.runOnUiThread { + viewHolder.buttonLog.setColorFilter(ContextCompat.getColor(context, R.color.grey_log_color)) + } } - if (methods[position].funcFourFlag == true) { - viewHolder.checkBoxFourth - .setImageResource(R.drawable.ic_round_done_all_24px) - - viewHolder.checkBoxFourth - .setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary)) - } else { - viewHolder.checkBoxFourth - .setImageResource(R.drawable.ic_done_black_24dp) + if (methods[position].error) { + viewHolder.buttonLog.setColorFilter(ContextCompat.getColor(context, R.color.colorAccent)) } - if (!viewHolder.textViewFuncOne.text.isEmpty()) { viewHolder.checkBoxOne.visibility = View.VISIBLE viewHolder.textViewFuncOne.visibility = View.VISIBLE @@ -149,12 +111,9 @@ class FunctionAdapter( this.pos = position } - final inner class ViewHolder(itemView: View, viewHolderListener: ViewHolderListener) : + inner class ViewHolder(itemView: View, viewHolderListener: ViewHolderListener) : RecyclerView.ViewHolder(itemView) { -// override fun onClick(v: View?) { -// val position = v?.getTag() as Int -// setPos(position) -// } + val textViewFuncOne: TextView = itemView.findViewById(R.id.textView_FunOne) val textViewFuncTwo: TextView = itemView.findViewById(R.id.textView_FunTwo) @@ -166,7 +125,7 @@ class FunctionAdapter( val checkBoxSec: AppCompatImageView = itemView.findViewById(R.id.imageView_tickSec) val checkBoxThird: AppCompatImageView = itemView.findViewById(R.id.imageView_tickThird) val checkBoxFourth: AppCompatImageView = itemView.findViewById(R.id.imageView_tickFourth) - val buttonLog : AppCompatImageView = itemView.findViewById(R.id.imgView_log) + val buttonLog: AppCompatImageView = itemView.findViewById(R.id.imgView_log) val buttonRun: AppCompatImageView = itemView.findViewById(R.id.buttonRun) val progress_method = itemView.findViewById(R.id.progress_method) as ProgressBar diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/function/FunctionFragment.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/function/FunctionFragment.kt index 0dde790..0151ad3 100644 --- a/app/src/main/java/ir/fanap/chattestapp/application/ui/function/FunctionFragment.kt +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/function/FunctionFragment.kt @@ -1,6 +1,6 @@ package ir.fanap.chattestapp.application.ui.function -import android.arch.lifecycle.ViewModelProvider +import android.arch.lifecycle.ViewModelProviders import android.content.Context import android.os.Bundle import android.support.constraint.ConstraintLayout @@ -30,27 +30,63 @@ import ir.fanap.chattestapp.application.ui.MainViewModel import ir.fanap.chattestapp.bussines.model.Method import ir.fanap.chattestapp.application.ui.TestListener import ir.fanap.chattestapp.application.ui.util.ConstantMsgType +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.ADD_CONTACT +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.ADD_PARTICIPANT +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.ADD_PARTICIPANT_ID +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.BLOCK_CONTACT +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.BLOCK_LIST +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.CREATE_THREAD +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.CREATE_THREAD_CHANNEL +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.CREATE_THREAD_CHANNEL_GROUP +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.CREATE_THREAD_NORMAL +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.CREATE_THREAD_PUBLIC_GROUP import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.CREATE_THREAD_WITH_FORW_MSG +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.CREATE_THREAD_WITH_FORW_MSG_CONTCT_ID +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.CREATE_THREAD_WITH_FORW_MSG_ID +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.CREATE_THREAD_WITH_MSG +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.DELETE_MESSAGE +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.EDIT_MESSAGE +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.EMPTY_ERROR_LOG +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.ERROR +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.FORWARD_MESSAGE +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.GET_CONTACT import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.GET_HISTORY +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.GET_PARTICIPANT +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.GET_THREAD +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.LEAVE_THREAD +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.MUTE_THREAD +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.REMOVE_CONTACT +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.REMOVE_PARTICIPANT +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.REMOVE_PARTICIPANT_ID +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.REPLY_MESSAGE +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.SEND_MESSAGE +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.SUCCESSFUL +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.UNBLOCK_CONTACT +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.UNMUTE_THREAD +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.UPDATE_CONTACT import ir.fanap.chattestapp.application.ui.util.MethodList.Companion.methodFuncFour import ir.fanap.chattestapp.application.ui.util.MethodList.Companion.methodFuncOne import ir.fanap.chattestapp.application.ui.util.MethodList.Companion.methodFuncThree import ir.fanap.chattestapp.application.ui.util.MethodList.Companion.methodFuncTwo import ir.fanap.chattestapp.application.ui.util.MethodList.Companion.methodNames +import ir.fanap.chattestapp.bussines.model.CallBackMethod +import ir.fanap.chattestapp.bussines.model.FunctionStatus import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers -import java.util.ArrayList +import java.util.* class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestListener { private lateinit var buttonConect: Button + private lateinit var button_show_detail: Button private lateinit var switchCompat_sandBox: SwitchCompat - private lateinit var recyclerView: RecyclerView + private lateinit var recyclerViewFunction: RecyclerView + private lateinit var recyclerView_response: RecyclerView private lateinit var mainViewModel: MainViewModel private lateinit var appCompatImageView_noResponse: AppCompatImageView private lateinit var txtView_noResponse: TextView - - + private lateinit var scrollView_log: ScrollView + private var chatStates: Boolean? = false private lateinit var avLoadingIndicatorView: AVLoadingIndicatorView private lateinit var linearLayoutManager: LinearLayoutManager private lateinit var recyclerViewSmooth: RecyclerView.SmoothScroller @@ -58,7 +94,7 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis private lateinit var bottomSheetLog: BottomSheetBehavior private var gson: Gson = GsonBuilder().setPrettyPrinting().create() private var methods: MutableList = mutableListOf() - private var fucCallback: HashMap = hashMapOf() + private var funcCallback: HashMap = hashMapOf() private lateinit var textView_state: TextView private lateinit var textView_log: TextView private lateinit var functionAdapter: FunctionAdapter @@ -66,45 +102,115 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis private val faker: Faker = Faker() private val TOKEN = "5fb88da4c6914d07a501a76d68a62363" private val SANDB_TOKEN = "8c4617792bf54aad92f6c6467e3a31f7" + private lateinit var subMethods: MutableList - //TODO change to CallBackMethod - /**/ companion object { - fun newInstance(): FunctionFragment { return FunctionFragment() } } - override fun onLogClicked(clickedViewHolder: FunctionAdapter.ViewHolder) { - var position = clickedViewHolder.adapterPosition - if (textView_log.text.isEmpty()) { - appCompatImageView_noResponse.visibility = View.VISIBLE - txtView_noResponse.visibility = View.VISIBLE - }else{ - appCompatImageView_noResponse.visibility = View.GONE - txtView_noResponse.visibility = View.GONE + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) + + mainViewModel = activity.run { ViewModelProviders.of(this!!).get(MainViewModel::class.java) } + mainViewModel.setTestListener(this) + + mainViewModel.observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) + .subscribe { + textView_state.text = it + if (it == "CHAT_READY") { + chatStates = true + avLoadingIndicatorView.visibility = View.GONE + textView_state.setTextColor( + ContextCompat.getColor(activity?.applicationContext!!, R.color.green_active) + ) + } + } + } + + private fun connect() { + avLoadingIndicatorView.visibility = View.VISIBLE + + if (sandbox) { + + //sandBox + mainViewModel.connect( + BuildConfig.SANDB_SOCKET_ADDRESS, + BuildConfig.APP_ID, + BuildConfig.SERVER_NAME + , + SANDB_TOKEN, + BuildConfig.SANDB_SSO_HOST, + BuildConfig.SANDB_PLATFORM_HOST, + BuildConfig.SANDB_FILE_SERVER, + null + ) + } else { + + //Local + mainViewModel.connect( + BuildConfig.SOCKET_ADDRESS, BuildConfig.APP_ID, BuildConfig.SERVER_NAME + , TOKEN, BuildConfig.SSO_HOST, BuildConfig.PLATFORM_HOST, BuildConfig.FILE_SERVER, null + ) +// mainViewModel.connect( +// "ws://172.16.110.131:8003/ws", BuildConfig.APP_ID, "chat-server2" +// , TOKEN, BuildConfig.SSO_HOST, BuildConfig.PLATFORM_HOST, BuildConfig.FILE_SERVER, null +// ) } + } + override fun onLogClicked(clickedViewHolder: FunctionAdapter.ViewHolder) { + val position = clickedViewHolder.adapterPosition bottomSheetLog.state = BottomSheetBehavior.STATE_EXPANDED - when (position) { - 0 -> { -// -// if (bottomSheetLog.state != null) { -// Toast.makeText(activity, bottomSheetLog.state.toString(), Toast.LENGTH_SHORT).show() + + subMethods = methods[position].funcStatusList!! + val responseAdapter = ResponseAdapter(subMethods) + recyclerView_response.adapter = responseAdapter + + if (methods[position].log != null && !methods[position].log?.isEmpty()!!) { + textView_log.text = methods[position].log +// when (position) { +// 0 -> { // } - } - 1 -> { - textView_log.text = methods[position].log - } +// 1 -> { +// textView_log.text = methods[position].log +// } +// 2 -> { +// textView_log.text = methods[position].log +// } +// } + } + if (subMethods.size >= 1) { + appCompatImageView_noResponse.visibility = View.GONE + txtView_noResponse.visibility = View.GONE + + recyclerView_response.visibility = View.VISIBLE + } else { + recyclerView_response.visibility = View.GONE + appCompatImageView_noResponse.visibility = View.VISIBLE + txtView_noResponse.visibility = View.VISIBLE } + if (textView_log.text.isEmpty()) { + appCompatImageView_noResponse.visibility = View.VISIBLE + txtView_noResponse.visibility = View.VISIBLE + + scrollView_log.visibility = View.GONE + + } else { + appCompatImageView_noResponse.visibility = View.GONE + txtView_noResponse.visibility = View.GONE + + scrollView_log.visibility = View.VISIBLE + } } override fun onIconClicked(clickedViewHolder: FunctionAdapter.ViewHolder) { - var position = clickedViewHolder.adapterPosition + val position = clickedViewHolder.adapterPosition when (position) { 0 -> { createThread() @@ -170,7 +276,7 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis createThreadWithForwMessage() } 21 -> { - getPartitipant() + getThreadParticipant() } } } @@ -182,69 +288,105 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view: View = inflater.inflate(R.layout.fragment_function, container, false) initView(view) + val buttonClose = view.findViewById(R.id.button_close) as Button - val button_close = view.findViewById(R.id.button_close) as Button + bottomSheetSetup(buttonClose) - bottomSheetLog = BottomSheetBehavior.from(bottom_sheet_log) - bottomSheetLog.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { - override fun onSlide(view: View, p1: Float) { - - } - - override fun onStateChanged(p0: View, state: Int) { - when (state) { - BottomSheetBehavior.STATE_HIDDEN -> { - - } - BottomSheetBehavior.STATE_EXPANDED -> { -// textView_state.text = "close" - } - - } - } + setupMethodRecyclerView() + setupSubMethodRecyclerView() + buttonConect.setOnClickListener { connect() } + switchCompat_sandBox.setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener { buttonView, isChecked -> + sandbox = true }) - button_close.setOnClickListener { - if (bottomSheetLog.state != BottomSheetBehavior.STATE_COLLAPSED) { - bottomSheetLog.state = BottomSheetBehavior.STATE_COLLAPSED + button_show_detail.setOnClickListener { + activity?.runOnUiThread { + recyclerView_response.visibility = View.GONE + button_show_detail.visibility = View.GONE + scrollView_log.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT } } + return view + } - recyclerView.setHasFixedSize(true) + private fun setupMethodRecyclerView() { + recyclerViewFunction.setHasFixedSize(true) linearLayoutManager = LinearLayoutManager(context) - recyclerView.layoutManager = linearLayoutManager + recyclerViewFunction.layoutManager = linearLayoutManager recyclerViewSmooth = object : LinearSmoothScroller(activity) { override fun getVerticalSnapPreference(): Int { - return LinearSmoothScroller.SNAP_TO_START + return SNAP_TO_START } } for (i in 0..21) { val method = Method() + val mutableList = arrayListOf() method.methodName = methodNames[i] method.funcOne = methodFuncOne[i] method.funcTwo = methodFuncTwo[i] method.funcThree = methodFuncThree[i] method.funcFour = methodFuncFour[i] + val functionStatus = FunctionStatus() + functionStatus.errorLog = "" + functionStatus.methodName = "" + functionStatus.status = "" + method.funcStatusList = mutableList methods.add(method) } functionAdapter = FunctionAdapter(this.activity!!, methods, this) - recyclerView.adapter = functionAdapter + recyclerViewFunction.adapter = functionAdapter + } - recyclerView.childCount - buttonConect.setOnClickListener { connect() } - switchCompat_sandBox.setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener { buttonView, isChecked -> - sandbox = true + private fun bottomSheetSetup(button_close: Button) { + bottomSheetLog = BottomSheetBehavior.from(bottom_sheet_log) + bottomSheetLog.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { + override fun onSlide(view: View, p1: Float) { + + } + + override fun onStateChanged(p0: View, state: Int) { + when (state) { + BottomSheetBehavior.STATE_HIDDEN -> { + textView_log.text = "" + } + BottomSheetBehavior.STATE_EXPANDED -> { + // textView_state.text = "close" + } + BottomSheetBehavior.STATE_COLLAPSED -> { + textView_log.text = "" + } + } + } }) - return view + button_close.setOnClickListener { + if (bottomSheetLog.state != BottomSheetBehavior.STATE_COLLAPSED) { + bottomSheetLog.state = BottomSheetBehavior.STATE_COLLAPSED + textView_log.text = "" + activity.runCatching { + scrollView_log.layoutParams.height = 0 + recyclerView_response.visibility = View.VISIBLE + button_show_detail.visibility = View.VISIBLE + } + } + } + } + + private fun setupSubMethodRecyclerView() { + + recyclerView_response.setHasFixedSize(true) + val linearLayoutMngResponse = LinearLayoutManager(context) + recyclerView_response.layoutManager = linearLayoutMngResponse } private fun initView(view: View) { buttonConect = view.findViewById(R.id.button_Connect) - recyclerView = view.findViewById(R.id.recyclerV_funcFrag) + button_show_detail = view.findViewById(R.id.button_show_detail) + recyclerViewFunction = view.findViewById(R.id.recyclerV_funcFrag) + recyclerView_response = view.findViewById(R.id.recyclerView_response) textView_state = view.findViewById(R.id.textView_state) switchCompat_sandBox = view.findViewById(R.id.switchCompat_sandBox) avLoadingIndicatorView = view.findViewById(R.id.AVLoadingIndicatorView) @@ -252,21 +394,17 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis textView_log = view.findViewById(R.id.textView_log) appCompatImageView_noResponse = view.findViewById(R.id.appCompatImageView_noResponse) txtView_noResponse = view.findViewById(R.id.TxtView_noResponse) - + scrollView_log = view.findViewById(R.id.scrollView_log) } - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) - mainViewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(activity!!.application) - .create(MainViewModel::class.java) -// .of(this).get(MainViewModel::class.java) - mainViewModel.setTestListener(this) - mainViewModel.observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe { - textView_state.text = it + override fun onChatState(state: String?) { + super.onChatState(state) + activity?.runOnUiThread { + textView_state.text = state - if (it.equals("CHAT_READY")) { + if (state.equals("CHAT_READY")) { + chatStates = true avLoadingIndicatorView.visibility = View.GONE textView_state.setTextColor( ContextCompat.getColor(activity?.applicationContext!!, R.color.green_active) @@ -275,29 +413,37 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis } } + private fun createThreadWithMessage() { + + } + private fun getHistory() { val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() val uniqueId = mainViewModel.getContact(requestGetContact) - fucCallback[ConstantMsgType.GET_HISTORY] = uniqueId + val position = 19 + + changeIconSend(position, ConstantMsgType.GET_HISTORY, uniqueId) } private fun editMessage() { val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() val uniqueId = mainViewModel.getContact(requestGetContact) - fucCallback[ConstantMsgType.EDIT_MESSAGE] = uniqueId + val position = 18 + changeIconSend(position, ConstantMsgType.EDIT_MESSAGE, uniqueId) } private fun deleteMessage() { val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() val uniqueId = mainViewModel.getContact(requestGetContact) - fucCallback[ConstantMsgType.DELETE_MESSAGE] = uniqueId + val position = 17 + changeIconSend(position, ConstantMsgType.DELETE_MESSAGE, uniqueId) } override fun onBlockList(response: ChatResponse?) { super.onBlockList(response) - var position = 5 - changeIconReceive(position) - methods[position].methodNameFlag = true + val position = 5 + updateMethodList(position, SUCCESSFUL, "", BLOCK_LIST) + changeIconReceive(position, response!!) } override fun onError(chatResponse: ErrorOutPut?) { @@ -306,74 +452,93 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis Toast.makeText(activity, chatResponse?.errorMessage, Toast.LENGTH_LONG).show() } val uniqueId = chatResponse?.uniqueId - if (uniqueId == fucCallback[ConstantMsgType.ADD_CONTACT]) { - fucCallback[uniqueId] + + if (funcCallback.containsKey(uniqueId)) { + val position = funcCallback[uniqueId]?.position + val methodName = funcCallback[uniqueId]?.method + val errorLog = gson.toJson(chatResponse) + methods[position!!].error = true + if (methodName != null && position != null) { + updateMethodList(position, ERROR, errorLog, methodName) + } + activity?.runOnUiThread { - val viewHolder: RecyclerView.ViewHolder = recyclerView.getChildViewHolder(recyclerView.getChildAt(3)) - viewHolder.itemView.findViewById(R.id.checkBox_ufil) - .setColorFilter(ContextCompat.getColor(activity!!, R.color.colorAccent)) + val viewHolder: RecyclerView.ViewHolder? = + recyclerViewFunction.findViewHolderForAdapterPosition(position!!) + viewHolder?.itemView?.findViewById(R.id.progress_method)?.visibility = View.GONE + + viewHolder?.itemView?.findViewById(R.id.imgView_log) + ?.setColorFilter(ContextCompat.getColor(activity!!, R.color.colorAccent)) } } } override fun onUnBlock(response: ChatResponse?) { super.onUnBlock(response) - val position = 6 - if (fucCallback[ConstantMsgType.UNBLOCK_CONTACT] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.UNBLOCK_CONTACT) - - changeIconReceive(position) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.UNBLOCK_CONTACT) { + val position = 6 + funcCallback.remove(response?.uniqueId) + updateMethodList(position, SUCCESSFUL, "", UNBLOCK_CONTACT) + changeIconReceive(position, response!!) } } override fun onGetThread(chatResponse: ChatResponse?) { super.onGetThread(chatResponse) - - if (fucCallback[ConstantMsgType.GET_THREAD] == chatResponse?.uniqueId) { + if (funcCallback[chatResponse?.uniqueId]?.method == ConstantMsgType.GET_THREAD) { + funcCallback.remove(ConstantMsgType.GET_THREAD) val position = 4 - fucCallback.remove(ConstantMsgType.GET_THREAD) - changeIconReceive(position) - methods[4].methodNameFlag = true + changeIconReceive(position, chatResponse!!) + updateMethodList(position, SUCCESSFUL, "", GET_THREAD) } - if (fucCallback[ConstantMsgType.SEND_MESSAGE] == chatResponse?.uniqueId) { + + if (funcCallback[chatResponse?.uniqueId]?.method == ConstantMsgType.SEND_MESSAGE) { + val position = 8 + updateMethodList(position, SUCCESSFUL, "", GET_THREAD) + if (chatResponse?.result?.threads?.size!! > 0) { - fucCallback.remove(ConstantMsgType.SEND_MESSAGE) + funcCallback.remove(ConstantMsgType.SEND_MESSAGE) val threadId = chatResponse.result.threads[0].id val requestMessage = RequestMessage.Builder(faker.lorem().paragraph(), threadId).build() - fucCallback[ConstantMsgType.SEND_MESSAGE] = mainViewModel.sendTextMsg(requestMessage) + + val uniqueId = mainViewModel.sendTextMsg(requestMessage) + addToCallBack(ConstantMsgType.SEND_MESSAGE, uniqueId, 8) + } else { val requestGetContact = RequestGetContact.Builder().build() - fucCallback.remove(ConstantMsgType.SEND_MESSAGE) - fucCallback[ConstantMsgType.SEND_MESSAGE] = mainViewModel.getContact(requestGetContact) + funcCallback.remove(ConstantMsgType.SEND_MESSAGE) + val uniqueId = mainViewModel.getContact(requestGetContact) + funcCallback[uniqueId]?.method = ConstantMsgType.SEND_MESSAGE } } } + //TODO delete message method has been changed on CHAT SDK override fun onDeleteMessage(response: ChatResponse?) { super.onDeleteMessage(response) - if (fucCallback[ConstantMsgType.DELETE_MESSAGE] == response?.uniqueId) { + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.DELETE_MESSAGE) { val position = 17 - changeIconReceive(position) - methods[position].methodNameFlag = true + changeIconReceive(position, response!!) + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, DELETE_MESSAGE) } } override fun onEditedMessage(response: ChatResponse?) { super.onEditedMessage(response) - if (fucCallback[ConstantMsgType.EDIT_MESSAGE] == response?.uniqueId) { + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.EDIT_MESSAGE) { val position = 18 - changeIconReceive(position) - methods[position].methodNameFlag = true + changeIconReceive(position, response!!) + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, EDIT_MESSAGE) } } override fun onSent(response: ChatResponse?) { super.onSent(response) - //TODO create Thread with forward message should changed - if (fucCallback[ConstantMsgType.CREATE_THREAD_WITH_FORW_MSG_ID] == response?.uniqueId) { + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.CREATE_THREAD_WITH_FORW_MSG) { val forwardMsgId = response?.result?.messageId - val contactId = fucCallback[ConstantMsgType.CREATE_THREAD_WITH_FORW_MSG_CONTCT_ID] + val contactId = funcCallback[ConstantMsgType.CREATE_THREAD_WITH_FORW_MSG_CONTCT_ID]?.method val inviteList = ArrayList() inviteList.add(Invitee(contactId!!.toLong(), 1)) @@ -385,59 +550,82 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis RequestCreateThread.Builder(0, inviteList) .message(requestThreadInnerMessage) .build() - val uniqueId = mainViewModel.createThreadWithMessage(requestCreateThread) - fucCallback[ConstantMsgType.DELETE_MESSAGE_ID] = uniqueId!![1] + val position = 20 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, SEND_MESSAGE) + val uniqueId = mainViewModel.createThreadWithMessage(requestCreateThread) + addToCallBack(CREATE_THREAD_WITH_FORW_MSG_ID, uniqueId?.get(0)!!, position) } - if (fucCallback[ConstantMsgType.EDIT_MESSAGE_ID] == response?.uniqueId) { - val requestEditMessage = RequestEditMessage.Builder("this is edit ", response!!.result.messageId).build() - fucCallback[ConstantMsgType.EDIT_MESSAGE] = mainViewModel.editMessage(requestEditMessage) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.EDIT_MESSAGE) { + val position = 18 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, SEND_MESSAGE) + val requestEditMessage = RequestEditMessage.Builder( + "this is edit ", response!!.result.messageId + ).build() + + val uniqueId = mainViewModel.editMessage(requestEditMessage) + addToCallBack(ConstantMsgType.EDIT_MESSAGE, uniqueId, position) } - if (fucCallback[ConstantMsgType.DELETE_MESSAGE_ID] == response?.uniqueId) { -// val requestDeleteMessage = RequestDeleteMessage.Builder(response!!.result.messageId).build() -// fucCallback[ConstantMsgType.DELETE_MESSAGE] = mainViewModel.deleteMessage(requestDeleteMessage) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.DELETE_MESSAGE) { + val position = 17 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, SEND_MESSAGE) + + val mutableList = mutableListOf() + mutableList.add(response?.result?.messageId!!) + val requestDeleteMessage = RequestDeleteMessage.Builder() + .messageIds(mutableList as ArrayList?).build() + val uniqueId = mainViewModel.deleteMessage(requestDeleteMessage) + addToCallBack(DELETE_MESSAGE, uniqueId, position) } - if (fucCallback[ConstantMsgType.REPLY_MESSAGE] == response?.uniqueId) { + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.REPLY_MESSAGE) { val position = 13 - changeIconReceive(position) - methods[position].methodNameFlag = true - } + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, SEND_MESSAGE) - if (fucCallback[ConstantMsgType.REPLY_MESSAGE_ID] == response?.uniqueId) { val messageId = response?.result?.messageId - val threadId = fucCallback[ConstantMsgType.REPLY_MESSAGE_THREAD_ID] + val threadId = response?.result?.conversationId val replyMessage = - RequestReplyMessage.Builder("this is replyMessage", threadId?.toLong()!!, messageId!!).build() - fucCallback[ConstantMsgType.REPLY_MESSAGE] = mainViewModel.replyMessage(replyMessage) - val position = 13 - changeIconSend(position) + RequestReplyMessage.Builder("this is replyMessage", threadId!!, messageId!!).build() + + val uniqueId = mainViewModel.replyMessage(replyMessage) + addToCallBack(ConstantMsgType.REPLY_MESSAGE_ID, uniqueId, position) } - if (fucCallback[ConstantMsgType.FORWARD_MESSAGE] == response?.uniqueId) { - val position = 12 - changeSecondIconReceive(position) - methods[position].funcOneFlag = true + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.REPLY_MESSAGE_ID) { + val position = 13 + if (response != null) { + changeIconReceive(position, response) + } + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, REPLY_MESSAGE) } - if (fucCallback[ConstantMsgType.FORWARD_MESSAGE_ID] == response?.uniqueId) { + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.FORWARD_MESSAGE) { + val position = 12 + funcCallback.remove(response?.uniqueId) + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, SEND_MESSAGE) val messageIds = ArrayList() messageIds.add(response?.result?.messageId!!) - val threadId = fucCallback[ConstantMsgType.FORWARD_MESSAGE_THREAD_ID] - val requestForwardMessage = RequestForwardMessage.Builder(threadId!!.toLong(), messageIds).build() - fucCallback[ConstantMsgType.FORWARD_MESSAGE] = mainViewModel.forwardMessage(requestForwardMessage)[0] + val threadId = response.result.conversationId + val requestForwardMessage = RequestForwardMessage.Builder(threadId, messageIds).build() + val uniqueId = mainViewModel.forwardMessage(requestForwardMessage)[0] + + addToCallBack(ConstantMsgType.FORWARD_MESSAGE_ID, uniqueId, position) + } + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.FORWARD_MESSAGE_ID) { val position = 12 - changeIconSend(position) + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, FORWARD_MESSAGE) + changeIconReceive(position, response!!) } - if (fucCallback[ConstantMsgType.SEND_MESSAGE] == response?.uniqueId) { + //onSent + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.SEND_MESSAGE) { val position = 8 - changeSecondIconReceive(position) - methods[position].funcOneFlag = true + changeIconReceive(position, response!!) + updateMethodList(position, SUCCESSFUL, "", SEND_MESSAGE) } } @@ -455,19 +643,31 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis methods[position].funcThreeFlag = true } + override fun onNewMessage(response: ChatResponse?) { + super.onNewMessage(response) + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.FORWARD_MESSAGE_ID) { + + val position = 12 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, FORWARD_MESSAGE) + changeIconReceive(position, response!!) + } + } + override fun onLeaveThread(response: ChatResponse?) { super.onLeaveThread(response) val position = 14 - changeIconReceive(position) - methods[position].methodNameFlag = true + if (response != null) { + changeIconReceive(position, response) + } + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, LEAVE_THREAD) } override fun onUpdateContact(response: ChatResponse?) { super.onUpdateContact(response) - if (fucCallback[ConstantMsgType.UPDATE_CONTACT] == response?.uniqueId) { + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.UPDATE_CONTACT) { val position = 7 - changeIconReceive(position) - methods[position].methodNameFlag = true + changeIconReceive(position, response!!) } } @@ -476,216 +676,319 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis * */ override fun onBlock(chatResponse: ChatResponse?) { super.onBlock(chatResponse) - if (fucCallback[ConstantMsgType.BLOCK_CONTACT] == chatResponse?.uniqueId) { + if (funcCallback[chatResponse?.uniqueId]?.method == ConstantMsgType.BLOCK_CONTACT) { val position = 2 - - changeIconReceive(position) + changeIconReceive(position, chatResponse!!) methods[position].methodNameFlag = true + updateMethodList(position!!, SUCCESSFUL, EMPTY_ERROR_LOG, BLOCK_CONTACT) + + //Un block the contact that has been blocked val id = chatResponse?.result?.contact?.id if (id != null) { - val requestUnBlock = RequestUnBlock.Builder(id).build() + val requestUnBlock = RequestUnBlock.Builder().contactId(id).build() mainViewModel.unBlock(requestUnBlock) } } - if (fucCallback[ConstantMsgType.UNBLOCK_CONTACT] == chatResponse?.uniqueId) { - fucCallback.remove(ConstantMsgType.UNBLOCK_CONTACT) + if (funcCallback[chatResponse?.uniqueId]?.method == ConstantMsgType.UNBLOCK_CONTACT) { + funcCallback.remove(ConstantMsgType.UNBLOCK_CONTACT) val contactId = chatResponse?.result?.contact?.id + updateMethodList(6, SUCCESSFUL, "", BLOCK_CONTACT) + if (contactId != null) { - val requestUnBlock = RequestUnBlock.Builder(contactId).build() - fucCallback[ConstantMsgType.UNBLOCK_CONTACT] = mainViewModel.unBlock(requestUnBlock) + val requestUnBlock = RequestUnBlock.Builder().contactId(contactId).build() + val uniqueId = mainViewModel.unBlock(requestUnBlock) + + addToCallBack(UNBLOCK_CONTACT, uniqueId, 6) } } } override fun onAddContact(response: ChatResponse?) { super.onAddContact(response) - if (fucCallback[ConstantMsgType.ADD_CONTACT] == response?.uniqueId) { + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.ADD_CONTACT) { val position = 3 - changeIconReceive(position) - methods[position].methodNameFlag = true + changeIconReceive(position, response!!) + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, ADD_CONTACT) - var id = response?.result?.contact?.id + val id = response.result?.contact?.id if (id != null) { val requestRemoveContact = RequestRemoveContact.Builder(id).build() mainViewModel.removeContact(requestRemoveContact) } } - if (fucCallback[ConstantMsgType.REMOVE_CONTACT] == response?.uniqueId) { - var id = response?.result?.contact?.id + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.REMOVE_CONTACT) { + val position = 9 + + updateMethodList(position, SUCCESSFUL, "", ADD_CONTACT) + + val id = response?.result?.contact?.id if (id != null) { - fucCallback.remove(ConstantMsgType.REMOVE_CONTACT) + funcCallback.remove(ConstantMsgType.REMOVE_CONTACT) val requestRemoveContact = RequestRemoveContact.Builder(id).build() - fucCallback[ConstantMsgType.REMOVE_CONTACT] = mainViewModel.removeContact(requestRemoveContact) - val position = 9 - changeIconSend(position) + val uniqueId = mainViewModel.removeContact(requestRemoveContact) + addToCallBack(REMOVE_CONTACT, uniqueId, position) } } } + private fun updateResponse() {} + override fun onMuteThread(response: ChatResponse?) { super.onMuteThread(response) - if (fucCallback[ConstantMsgType.MUTE_THREAD] == response?.uniqueId) { + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.MUTE_THREAD) { val position = 15 - changeIconReceive(position) - methods[position].methodNameFlag = true + changeIconReceive(position, response!!) + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, ConstantMsgType.MUTE_THREAD) } } override fun onUnmuteThread(response: ChatResponse?) { super.onUnmuteThread(response) - if (fucCallback[ConstantMsgType.UNMUTE_THREAD] == response?.uniqueId) { + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.UNMUTE_THREAD) { val position = 16 - changeIconReceive(position) - methods[position].methodNameFlag = true + changeIconReceive(position, response!!) + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, ConstantMsgType.UNMUTE_THREAD) } } override fun onGetHistory(response: ChatResponse?) { super.onGetHistory(response) - if (fucCallback[ConstantMsgType.GET_HISTORY] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.GET_HISTORY) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.GET_HISTORY) { + funcCallback.remove(ConstantMsgType.GET_HISTORY) val position = 19 - changeIconReceive(position) + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, GET_HISTORY) + changeIconReceive(position, response!!) } } override fun onGetThreadParticipant(response: ChatResponse?) { super.onGetThreadParticipant(response) val position = 21 - changeIconReceive(position) + changeIconReceive(position, response!!) + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, GET_PARTICIPANT) } override fun onCreateThread(response: ChatResponse?) { super.onCreateThread(response) - if (fucCallback[ConstantMsgType.GET_PARTICIPANT] == response?.uniqueId) { + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.GET_PARTICIPANT) { val threadId = response!!.result.thread.id val requestThreadParticipant = RequestThreadParticipant.Builder(threadId).build() - mainViewModel.getParticipant(requestThreadParticipant) + val uniqueId = mainViewModel.getParticipant(requestThreadParticipant) + val position = 21 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, CREATE_THREAD) + addToCallBack(ConstantMsgType.GET_PARTICIPANT, uniqueId, position) } - if (fucCallback[ConstantMsgType.CREATE_THREAD_WITH_FORW_MSG] == response?.uniqueId) { + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.CREATE_THREAD_PUBLIC_GROUP) { + funcCallback.remove(ConstantMsgType.CREATE_THREAD_PUBLIC_GROUP) + val position = 0 + updateMethodList(position, SUCCESSFUL, "", CREATE_THREAD_PUBLIC_GROUP) + } + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.CREATE_THREAD_WITH_MSG) { + funcCallback.remove(ConstantMsgType.CREATE_THREAD_WITH_MSG) + val position = 0 + updateMethodList(position, SUCCESSFUL, "", CREATE_THREAD_WITH_MSG) + } + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.CREATE_THREAD_NORMAL) { + funcCallback.remove(ConstantMsgType.CREATE_THREAD_NORMAL) + val position = 0 + updateMethodList(position, SUCCESSFUL, "", CREATE_THREAD_NORMAL) + changeIconReceive(position, response!!) + } + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.CREATE_THREAD_CHANNEL) { + funcCallback.remove(ConstantMsgType.CREATE_THREAD_CHANNEL) + val position = 0 + updateMethodList(position, SUCCESSFUL, "", CREATE_THREAD_CHANNEL) + } + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.CREATE_THREAD_CHANNEL_GROUP) { + funcCallback.remove(ConstantMsgType.CREATE_THREAD_CHANNEL_GROUP) + val position = 0 + updateMethodList(position, SUCCESSFUL, "", CREATE_THREAD_CHANNEL_GROUP) + } + + + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.CREATE_THREAD_WITH_FORW_MSG) { val threadId = response!!.result.thread.id val requestMessage = RequestMessage.Builder("this is message for create thread with forward message", threadId) .build() - fucCallback[ConstantMsgType.CREATE_THREAD_WITH_FORW_MSG_ID] = mainViewModel.sendTextMsg(requestMessage) + val uniqueId = mainViewModel.sendTextMsg(requestMessage) + val position = 20 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, CREATE_THREAD) + addToCallBack(CREATE_THREAD_WITH_FORW_MSG, uniqueId, position) } - if (fucCallback[ConstantMsgType.GET_HISTORY] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.GET_HISTORY) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.CREATE_THREAD_WITH_FORW_MSG_ID) { + val position = 20 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, ConstantMsgType.CREATE_THREAD_WITH_FORW_MSG) + changeIconReceive(position, response!!) + } + + //onCreateThread + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.GET_HISTORY) { + val position = 19 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, CREATE_THREAD) + funcCallback.remove(ConstantMsgType.GET_HISTORY) val threadId = response!!.result.thread.id val requestGetHistory = RequestGetHistory.Builder(threadId).build() - fucCallback[ConstantMsgType.GET_HISTORY] = mainViewModel.getHistory(requestGetHistory) + val uniqueId = mainViewModel.getHistory(requestGetHistory) + addToCallBack(ConstantMsgType.GET_HISTORY, uniqueId, position) } - if (fucCallback[ConstantMsgType.UNMUTE_THREAD] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.UNMUTE_THREAD) + //onCreateThread + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.UNMUTE_THREAD) { + funcCallback.remove(ConstantMsgType.UNMUTE_THREAD) val threadId = response!!.result.thread.id - val requestMuteThread = RequestMuteThread.Builder(threadId).build() - fucCallback[ConstantMsgType.UNMUTE_THREAD] = mainViewModel.unMuteThread(requestMuteThread) + val requestMuteThread = RequestMuteThread.Builder().threadId(threadId).build() + val uniqueId = mainViewModel.unMuteThread(requestMuteThread) + val position = 16 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, ConstantMsgType.UNMUTE_THREAD) + addToCallBack(ConstantMsgType.UNMUTE_THREAD, uniqueId, position) } - if (fucCallback[ConstantMsgType.MUTE_THREAD] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.MUTE_THREAD) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.MUTE_THREAD) { + funcCallback.remove(ConstantMsgType.MUTE_THREAD) val threadId = response!!.result.thread.id - val requestMuteThread = RequestMuteThread.Builder(threadId).build() - fucCallback[ConstantMsgType.MUTE_THREAD] = mainViewModel.muteThread(requestMuteThread) + val requestMuteThread = RequestMuteThread.Builder().threadId(threadId).build() + val uniqueId = mainViewModel.muteThread(requestMuteThread) + val position = 15 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, ConstantMsgType.CREATE_THREAD) + addToCallBack(ConstantMsgType.MUTE_THREAD, uniqueId, position) } - if (fucCallback[ConstantMsgType.CREATE_THREAD] == response?.uniqueId) { + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.CREATE_THREAD) { val position = 0 changeIconReceive(position) methods[position].methodNameFlag = true } - if (fucCallback[ConstantMsgType.CREATE_THREAD_CHANNEL] == response?.uniqueId) { + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.CREATE_THREAD_CHANNEL) { val position = 0 changeSecondIconReceive(position) methods[position].funcOneFlag = true } - if (fucCallback[ConstantMsgType.CREATE_THREAD_CHANNEL_GROUP] == response?.uniqueId) { + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.CREATE_THREAD_CHANNEL_GROUP) { val position = 0 changeThirdIconReceive(position) methods[position].funcTwoFlag = true } - if (fucCallback[ConstantMsgType.CREATE_THREAD_PUBLIC_GROUP] == response?.uniqueId) { + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.CREATE_THREAD_PUBLIC_GROUP) { val position = 0 changeFourthIconReceive(position) methods[position].funcThreeFlag = true } - if (fucCallback[ConstantMsgType.LEAVE_THREAD] == response?.uniqueId) { + //Create Thread + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.LEAVE_THREAD) { val threadId = response?.result?.thread?.id - val requeLeaveThread = RequestLeaveThread.Builder(threadId!!.toLong()).build() - fucCallback[ConstantMsgType.LEAVE_THREAD] = mainViewModel.leaveThread(requeLeaveThread) val position = 14 - changeIconSend(position) + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, CREATE_THREAD) + funcCallback.remove(response?.uniqueId) + val requeLeaveThread = RequestLeaveThread.Builder(threadId!!.toLong()).build() + val uniqueId = mainViewModel.leaveThread(requeLeaveThread) + addToCallBack(ConstantMsgType.LEAVE_THREAD, uniqueId, position) } - if (fucCallback[ConstantMsgType.FORWARD_MESSAGE] == response?.uniqueId) { + //Create Thread + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.FORWARD_MESSAGE) { val threadId = response?.result?.thread?.id - fucCallback[ConstantMsgType.FORWARD_MESSAGE_THREAD_ID] = threadId.toString() + val position = 12 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, CREATE_THREAD) + + val requestMessage = RequestMessage.Builder("this is msg for forward", threadId!!).build() + val uniqueId = mainViewModel.sendTextMsg(requestMessage) + funcCallback.remove(response.uniqueId) + addToCallBack(ConstantMsgType.FORWARD_MESSAGE, uniqueId, position) + } + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.REPLY_MESSAGE) { + funcCallback.remove(response?.uniqueId) + val threadId = response?.result?.thread?.id + val position = 13 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, CREATE_THREAD) + + val requestMessage = RequestMessage.Builder("send msg for reply", threadId!!).build() + val uniqueId = mainViewModel.sendTextMsg(requestMessage) + addToCallBack(ConstantMsgType.REPLY_MESSAGE, uniqueId, position) } - if (fucCallback[ConstantMsgType.REPLY_MESSAGE_THREAD_ID] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.REPLY_MESSAGE_THREAD_ID) + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.DELETE_MESSAGE) { + funcCallback.remove(response?.uniqueId) val threadId = response?.result?.thread?.id - fucCallback[ConstantMsgType.REPLY_MESSAGE_THREAD_ID] = threadId.toString() + val position = 17 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, CREATE_THREAD) + + val requestMessage = RequestMessage.Builder("send msg for delete msg", threadId!!).build() + val uniqueId = mainViewModel.sendTextMsg(requestMessage) + addToCallBack(ConstantMsgType.DELETE_MESSAGE, uniqueId, position) + } + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.EDIT_MESSAGE) { + funcCallback.remove(response?.uniqueId) + val threadId = response?.result?.thread?.id + val position = 17 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, CREATE_THREAD) + + val requestMessage = RequestMessage.Builder("send msg for edit msg", threadId!!).build() + val uniqueId = mainViewModel.sendTextMsg(requestMessage) + addToCallBack(ConstantMsgType.EDIT_MESSAGE, uniqueId, position) } - if (fucCallback[ConstantMsgType.ADD_PARTICIPANT] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.ADD_PARTICIPANT) - var participantId = fucCallback["ADD_PARTICIPANT_ID"] + //Create Thread + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.ADD_PARTICIPANT) { + val position = 10 + updateMethodList(position, SUCCESSFUL, "", CREATE_THREAD) + funcCallback.remove(ConstantMsgType.ADD_PARTICIPANT) + val participantId = funcCallback[ADD_PARTICIPANT_ID]?.method val partId = participantId?.toLong() val threadId = response?.result?.thread?.id if (partId != null && threadId != null) { val contactIdList: MutableList = mutableListOf() contactIdList.add(partId) val requestAddParticipants = RequestAddParticipants.Builder(threadId, contactIdList).build() - mainViewModel.addParticipant(requestAddParticipants) - fucCallback.remove("ADD_PARTICIPANT_ID") + val uniqueId = mainViewModel.addParticipant(requestAddParticipants) + addToCallBack(ADD_PARTICIPANT, uniqueId, position) + funcCallback.remove("ADD_PARTICIPANT_ID") } } - } - private fun connect() { - avLoadingIndicatorView.visibility = View.VISIBLE - if (sandbox) { + //Create Thread + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.REMOVE_PARTICIPANT) { + val position = 11 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, CREATE_THREAD) - //sandBox - mainViewModel.connect( - BuildConfig.SANDB_SOCKET_ADDRESS, - BuildConfig.APP_ID, - BuildConfig.SERVER_NAME - , - SANDB_TOKEN, - BuildConfig.SANDB_SSO_HOST, - BuildConfig.SANDB_PLATFORM_HOST, - BuildConfig.SANDB_FILE_SERVER, - null - ) - } else { + funcCallback.remove(ConstantMsgType.REMOVE_PARTICIPANT) + val participantId = funcCallback[REMOVE_PARTICIPANT_ID]?.method + val partId = participantId?.toLong() + val threadId = response?.result?.thread?.id - //Local -// mainViewModel.connect( -// BuildConfig.SOCKET_ADDRESS, BuildConfig.APP_ID, BuildConfig.SERVER_NAME -// , TOKEN, BuildConfig.SSO_HOST, BuildConfig.PLATFORM_HOST, BuildConfig.FILE_SERVER, null -// ) - mainViewModel.connect( - "ws://172.16.110.131:8003/ws", BuildConfig.APP_ID, "chat-server2" - , TOKEN, BuildConfig.SSO_HOST, BuildConfig.PLATFORM_HOST, BuildConfig.FILE_SERVER, null - ) + if (partId != null && threadId != null) { + val contactIdList: MutableList = mutableListOf() + contactIdList.add(partId) + val requestAddParticipants = RequestAddParticipants.Builder(threadId, contactIdList).build() + val uniqueId = mainViewModel.addParticipant(requestAddParticipants) + addToCallBack(REMOVE_PARTICIPANT, uniqueId, position) + } } } private fun changeFourthIconReceive(position: Int) { activity?.runOnUiThread { if (view != null) { - val viewHolder: RecyclerView.ViewHolder = recyclerView.findViewHolderForAdapterPosition(position)!! + val viewHolder: RecyclerView.ViewHolder = + recyclerViewFunction.findViewHolderForAdapterPosition(position)!! viewHolder.itemView.findViewById(R.id.imageView_tickFourth) .setImageResource(R.drawable.ic_round_done_all_24px) @@ -698,7 +1001,8 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis private fun changeThirdIconReceive(position: Int) { activity?.runOnUiThread { if (view != null) { - val viewHolder: RecyclerView.ViewHolder = recyclerView.findViewHolderForAdapterPosition(position)!! + val viewHolder: RecyclerView.ViewHolder = + recyclerViewFunction.findViewHolderForAdapterPosition(position)!! viewHolder.itemView.findViewById(R.id.imageView_tickThird) .setImageResource(R.drawable.ic_round_done_all_24px) @@ -708,11 +1012,11 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis } } - private fun changeSecondIconReceive(position: Int) { activity?.runOnUiThread { if (view != null) { - val viewHolder: RecyclerView.ViewHolder = recyclerView.findViewHolderForAdapterPosition(position)!! + val viewHolder: RecyclerView.ViewHolder = + recyclerViewFunction.findViewHolderForAdapterPosition(position)!! viewHolder.itemView.findViewById(R.id.imageView_tickFirst) .setImageResource(R.drawable.ic_round_done_all_24px) @@ -724,9 +1028,10 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis override fun onRemoveContact(response: ChatResponse?) { super.onRemoveContact(response) - if (fucCallback[ConstantMsgType.REMOVE_CONTACT] == response?.uniqueId) { + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.REMOVE_CONTACT) { val position = 9 - changeIconReceive(position) + changeIconReceive(position, response!!) + updateMethodList(position, SUCCESSFUL, "", REMOVE_CONTACT) } } @@ -734,121 +1039,175 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis super.onGetContact(response) val contactList = response?.result?.contacts - if (fucCallback[ConstantMsgType.GET_PARTICIPANT] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.GET_PARTICIPANT) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.GET_PARTICIPANT) { + val position = 21 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + funcCallback.remove(ConstantMsgType.GET_PARTICIPANT) handleGetParticipant(contactList) } - if (fucCallback[CREATE_THREAD_WITH_FORW_MSG] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.GET_HISTORY) + if (funcCallback[response?.uniqueId]?.method == CREATE_THREAD_WITH_FORW_MSG) { + val position = 20 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + funcCallback.remove(ConstantMsgType.GET_HISTORY) handleCrtThreadForwMsg(contactList) } - if (fucCallback[GET_HISTORY] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.GET_HISTORY) + //onGetContact + if (funcCallback[response?.uniqueId]?.method == GET_HISTORY) { + val position = funcCallback[response?.uniqueId]?.position + updateMethodList(position!!, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + funcCallback.remove(ConstantMsgType.GET_HISTORY) handleGetHistory(contactList) } - if (fucCallback[ConstantMsgType.EDIT_MESSAGE] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.DELETE_MESSAGE) + //onGetContact + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.EDIT_MESSAGE) { + val position = 18 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + funcCallback.remove(ConstantMsgType.DELETE_MESSAGE) handleEditMessage(contactList) } - if (fucCallback[ConstantMsgType.DELETE_MESSAGE] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.DELETE_MESSAGE) + //onGetContact + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.DELETE_MESSAGE) { + val position = 17 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + funcCallback.remove(ConstantMsgType.DELETE_MESSAGE) handleDeleteMessage(contactList) } - if (fucCallback[ConstantMsgType.UNMUTE_THREAD] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.UNMUTE_THREAD) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.UNMUTE_THREAD) { + val position = 16 + funcCallback.remove(ConstantMsgType.UNMUTE_THREAD) handleUnmuteThread(contactList) } - if (fucCallback[ConstantMsgType.MUTE_THREAD] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.MUTE_THREAD) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.MUTE_THREAD) { + val position = 15 + funcCallback.remove(ConstantMsgType.MUTE_THREAD) handleMuteThread(contactList) } - if (fucCallback[ConstantMsgType.LEAVE_THREAD] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.LEAVE_THREAD) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.LEAVE_THREAD) { + val position = funcCallback[response?.uniqueId]?.position + updateMethodList(position!!, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + funcCallback.remove(ConstantMsgType.LEAVE_THREAD) handleLeaveThread(contactList) } - if (fucCallback[ConstantMsgType.REPLY_MESSAGE] == response?.uniqueId) { + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.REPLY_MESSAGE) { + val position = 13 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + funcCallback.remove(response?.uniqueId) handleReplyMessage(contactList) } - if (fucCallback[ConstantMsgType.SEND_MESSAGE] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.SEND_MESSAGE) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.SEND_MESSAGE) { + val position = funcCallback[response?.uniqueId]?.position + updateMethodList(position!!, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + funcCallback.remove(ConstantMsgType.SEND_MESSAGE) handleSendMessageResponse(contactList) } - if (fucCallback[ConstantMsgType.CREATE_THREAD] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.CREATE_THREAD) + //onGetContact + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.CREATE_THREAD) { + val position = funcCallback[response?.uniqueId]?.position + updateMethodList(position!!, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + funcCallback.remove(ConstantMsgType.CREATE_THREAD) handleGetThreadResponse(contactList) } - if (fucCallback[ConstantMsgType.GET_CONTACT] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.GET_CONTACT) - val position = 1 - changeIconReceive(position) - methods[position].methodNameFlag = true - var json = gson.toJson(response?.result) - methods[position].log = json + + //onGetContact + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.GET_CONTACT) { + val position = funcCallback[response?.uniqueId]?.position + updateMethodList(position!!, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + changeIconReceive(position, response!!) } - if (fucCallback[ConstantMsgType.BLOCK_CONTACT] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.BLOCK_CONTACT) + //onGetContact + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.BLOCK_CONTACT) { + + val position = funcCallback[response?.uniqueId]?.position + updateMethodList(position!!, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) handleBlockContact(contactList) } - if (fucCallback[ConstantMsgType.UPDATE_CONTACT] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.UPDATE_CONTACT) + //onGetContact + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.UPDATE_CONTACT) { + val position = funcCallback[response?.uniqueId]?.position + updateMethodList(position!!, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + funcCallback.remove(ConstantMsgType.UPDATE_CONTACT) handleUpdateContact(contactList) } - if (fucCallback[ConstantMsgType.UNBLOCK_CONTACT] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.UNBLOCK_CONTACT) + //onGetContact + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.UNBLOCK_CONTACT) { + val position = funcCallback[response?.uniqueId]?.position + updateMethodList(position!!, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + funcCallback.remove(ConstantMsgType.UNBLOCK_CONTACT) handleUnBlockContact(contactList) } - if (fucCallback[ConstantMsgType.ADD_PARTICIPANT] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.ADD_PARTICIPANT) + + //onGetContact + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.ADD_PARTICIPANT) { + val position = funcCallback[response?.uniqueId]?.position + updateMethodList(position!!, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + funcCallback.remove(ConstantMsgType.ADD_PARTICIPANT) handleAddParticipant(contactList) } - if (fucCallback[ConstantMsgType.REMOVE_PARTICIPANT] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.REMOVE_PARTICIPANT) + + //onGetContact + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.REMOVE_PARTICIPANT) { + val position = 11 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + funcCallback.remove(ConstantMsgType.REMOVE_PARTICIPANT) handleRemoveParticipant(contactList) } - if (fucCallback[ConstantMsgType.FORWARD_MESSAGE] == response?.uniqueId) { - fucCallback.remove(ConstantMsgType.FORWARD_MESSAGE) + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.FORWARD_MESSAGE) { + val position = 12 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + funcCallback.remove(ConstantMsgType.FORWARD_MESSAGE) handleForward(contactList) - // CREATE WITH MSSAGE CONTACT - // STORE THE MESSAGE ID - // + } } + private fun updateMethodList( + position: Int, + status: String, + errorLog: String, + methodName: String + ) { + + val functionStatus = FunctionStatus() + functionStatus.status = status + functionStatus.methodName = methodName + functionStatus.errorLog = errorLog + methods[position].funcStatusList?.add(functionStatus) + + } + private fun handleGetParticipant(contactList: ArrayList?) { if (contactList != null) { - var choose = 0 for (contact: Contact in contactList) { if (contact.isHasUser) { - if (choose == 2) { - val contactId = contact.id - val inviteList = ArrayList() - inviteList.add(Invitee(contactId, 1)) + val contactId = contact.id - val list = Array(1) { Invitee(inviteList[0].id, 2) } + val inviteList = ArrayList() + inviteList.add(Invitee(contactId, 1)) - val uniqueId = mainViewModel.createThread( - ThreadType.Constants.NORMAL, list, "nothing", "" - , "", "" - ) + val list = Array(1) { Invitee(inviteList[0].id, 2) } - fucCallback[ConstantMsgType.GET_PARTICIPANT] = uniqueId - break - } - choose++ + val uniqueId = mainViewModel.createThread( + ThreadType.Constants.NORMAL, list, "nothing", "" + , "", "" + ) + val position = 21 + addToCallBack(ConstantMsgType.GET_PARTICIPANT, uniqueId, position) + break } } } @@ -860,29 +1219,25 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis * */ private fun handleCrtThreadForwMsg(contactList: ArrayList?) { if (contactList != null) { - var choose = 0 for (contact: Contact in contactList) { if (contact.isHasUser) { - if (choose == 2) { - val contactId = contact.id - val inviteList = ArrayList() - inviteList.add(Invitee(contactId, 1)) + val contactId = contact.id - val list = Array(1) { Invitee(inviteList[0].id, 2) } + val inviteList = ArrayList() + inviteList.add(Invitee(contactId, 1)) - val uniqueId = mainViewModel.createThread( - ThreadType.Constants.NORMAL, list, "nothing", "" - , "", "" - ) + val list = Array(1) { Invitee(inviteList[0].id, 2) } - fucCallback[ConstantMsgType.CREATE_THREAD_WITH_FORW_MSG] = uniqueId - break - } - if (choose == 1) { - fucCallback[ConstantMsgType.CREATE_THREAD_WITH_FORW_MSG_CONTCT_ID] = contact.id.toString() - } - choose++ + val uniqueId = mainViewModel.createThread( + ThreadType.Constants.NORMAL, list, "nothing", "" + , "", "" + ) + + val position = 20 + addToCallBack(ConstantMsgType.CREATE_THREAD_WITH_FORW_MSG, uniqueId, position) + addToCallBack(contactId.toString(), CREATE_THREAD_WITH_FORW_MSG_CONTCT_ID, position) + break } } } @@ -899,12 +1254,12 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis val userId = contact.userId val inviteList = Array(1) { Invitee(contactId, 2) } inviteList[0].id = contactId - + val position = 19 val uniqueId = mainViewModel.createThread( ThreadType.Constants.NORMAL, inviteList, "", "" , "", "" ) - fucCallback[ConstantMsgType.GET_HISTORY] = uniqueId + addToCallBack(ConstantMsgType.GET_HISTORY, uniqueId, position) break } choose++ @@ -923,16 +1278,16 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis if (choose == 1) { val contactId = contact.id - val inviteList = ArrayList() - inviteList.add(Invitee(contactId, 1)) - val requestThreadInnerMessage = - RequestThreadInnerMessage.Builder().message(faker.music().genre()).build() - val requestCreateThread: RequestCreateThread = - RequestCreateThread.Builder(0, inviteList) - .message(requestThreadInnerMessage) - .build() - val uniqueId = mainViewModel.createThreadWithMessage(requestCreateThread) - fucCallback[ConstantMsgType.DELETE_MESSAGE_ID] = uniqueId!![1] + val position = 118 + + val inviteList = Array(1) { Invitee(contactId, 2) } + inviteList[0].id = contactId + val uniqueId = mainViewModel.createThread( + ThreadType.Constants.PUBLIC_GROUP, inviteList, "nothing", "" + , "", "" + ) + + addToCallBack(ConstantMsgType.EDIT_MESSAGE, uniqueId, position) } break } @@ -950,18 +1305,19 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis if (choose == 1) { val contactId = contact.id - val inviteList = ArrayList() - inviteList.add(Invitee(contactId, 1)) - val requestThreadInnerMessage = - RequestThreadInnerMessage.Builder().message(faker.music().genre()).build() - val requestCreateThread: RequestCreateThread = - RequestCreateThread.Builder(0, inviteList) - .message(requestThreadInnerMessage) - .build() - val uniqueId = mainViewModel.createThreadWithMessage(requestCreateThread) - fucCallback[ConstantMsgType.DELETE_MESSAGE_ID] = uniqueId!![1] + val position = 14 + + val inviteList = Array(1) { Invitee(contactId, 2) } + inviteList[0].id = contactId + val uniqueId = mainViewModel.createThread( + ThreadType.Constants.PUBLIC_GROUP, inviteList, "nothing", "" + , "", "" + ) + + addToCallBack(ConstantMsgType.DELETE_MESSAGE, uniqueId, position) + + break } - break } } } @@ -978,12 +1334,12 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis val userId = contact.userId val inviteList = Array(1, { i -> Invitee(contactId, 5) }) inviteList[0].id = contactId - + val position = 16 val uniqueId = mainViewModel.createThread( ThreadType.Constants.NORMAL, inviteList, "", "" , "", "" ) - fucCallback[ConstantMsgType.UNMUTE_THREAD] = uniqueId + addToCallBack(UNMUTE_THREAD, uniqueId, position) break } } @@ -999,7 +1355,7 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis choose++ if (choose == 2) { val contactId = contact.id - + val position = 15 val inviteList = Array(1, { i -> Invitee(contactId, 2) }) inviteList[0].id = contactId @@ -1007,7 +1363,8 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis ThreadType.Constants.NORMAL, inviteList, "", "" , "", "" ) - fucCallback[ConstantMsgType.MUTE_THREAD] = uniqueId + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + addToCallBack(MUTE_THREAD, uniqueId, position) break } } @@ -1021,18 +1378,18 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis if (contact.isHasUser) { val contactId = contact.id - val inviteList = ArrayList() - inviteList.add(Invitee(contactId, 1)) - val requestThreadInnerMessage = - RequestThreadInnerMessage.Builder().message(faker.music().genre()).build() - val requestCreateThread: RequestCreateThread = - RequestCreateThread.Builder(0, inviteList) - .message(requestThreadInnerMessage) - .build() - val uniqueId = mainViewModel.createThreadWithMessage(requestCreateThread) - if (uniqueId?.get(0) != null) { - fucCallback[ConstantMsgType.LEAVE_THREAD] = uniqueId[0] - } + val position = 14 + + + val inviteList = Array(1) { Invitee(contactId, 2) } + inviteList[0].id = contactId + val uniqueId = mainViewModel.createThread( + ThreadType.Constants.PUBLIC_GROUP, inviteList, "nothing", "" + , "", "" + ) + + addToCallBack(ConstantMsgType.LEAVE_THREAD, uniqueId, position) + break } } @@ -1045,17 +1402,23 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis if (contact.isHasUser) { val contactId = contact.id - val inviteList = ArrayList() - inviteList.add(Invitee(contactId, 1)) - val requestThreadInnerMessage = - RequestThreadInnerMessage.Builder().message(faker.music().genre()).build() - val requestCreateThread: RequestCreateThread = - RequestCreateThread.Builder(0, inviteList) - .message(requestThreadInnerMessage) - .build() - val uniqueId = mainViewModel.createThreadWithMessage(requestCreateThread) - fucCallback[ConstantMsgType.REPLY_MESSAGE_THREAD_ID] = uniqueId!![0] - fucCallback[ConstantMsgType.REPLY_MESSAGE_ID] = uniqueId[1] +// val inviteList = ArrayList() +// inviteList.add(Invitee(contactId, 1)) +// val requestThreadInnerMessage = +// RequestThreadInnerMessage.Builder().message(faker.music().genre()).build() +// val requestCreateThread: RequestCreateThread = +// RequestCreateThread.Builder(0, inviteList) +// .message(requestThreadInnerMessage) +// .build() +// val uniqueId = mainViewModel.createThreadWithMessage(requestCreateThread) + val inviteList = Array(1) { Invitee(contactId, 2) } + inviteList[0].id = contactId + val position = 13 + val uniqueId = mainViewModel.createThread( + ThreadType.Constants.PUBLIC_GROUP, inviteList, "nothing", "" + , "", "" + ) + addToCallBack(ConstantMsgType.REPLY_MESSAGE, uniqueId, position) break } } @@ -1064,9 +1427,39 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis override fun onThreadAddParticipant(response: ChatResponse?) { super.onThreadAddParticipant(response) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.ADD_PARTICIPANT) { + val position = 10 + updateMethodList(position, SUCCESSFUL, "", ADD_PARTICIPANT) + changeIconReceive(position, response!!) + } + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.REMOVE_PARTICIPANT) { + val position = 11 + updateMethodList(position, SUCCESSFUL, "", ADD_PARTICIPANT) + + val threadId = response?.result?.thread?.id + val participantId = funcCallback[REMOVE_PARTICIPANT_ID]?.method + val mutableList = mutableListOf() + mutableList.add(participantId!!.toLong()) + val requestRemoveParticipants = + RequestRemoveParticipants.Builder(threadId!!, mutableList).build() + + val uniqueId = mainViewModel.removeParticipant(requestRemoveParticipants) + funcCallback.remove(response.uniqueId) + addToCallBack(REMOVE_PARTICIPANT, uniqueId, position) + } + } + + override fun onThreadRemoveParticipant(response: ChatResponse?) { + super.onThreadRemoveParticipant(response) + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.REMOVE_PARTICIPANT) { + val position = 11 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, REMOVE_PARTICIPANT) + if (response != null) { + changeIconReceive(position, response) + } + } - val position = 10 - changeIconReceive(position) } private fun handleForward(contactList: ArrayList?) { @@ -1074,18 +1467,16 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis for (contact: Contact in contactList) { if (contact.isHasUser) { val contactId = contact.id + val position = 12 - val inviteList = ArrayList() - inviteList.add(Invitee(contactId, 1)) - val requestThreadInnerMessage = - RequestThreadInnerMessage.Builder().message(faker.music().genre()).build() - val requestCreateThread: RequestCreateThread = - RequestCreateThread.Builder(0, inviteList) - .message(requestThreadInnerMessage) - .build() - val uniqueId = mainViewModel.createThreadWithMessage(requestCreateThread) - fucCallback[ConstantMsgType.FORWARD_MESSAGE] = uniqueId!![0] - fucCallback[ConstantMsgType.FORWARD_MESSAGE_ID] = uniqueId[1] + val inviteList = Array(1) { Invitee(contactId, 2) } + inviteList[0].id = contactId + + val uniqueId = mainViewModel.createThread( + ThreadType.Constants.NORMAL, inviteList, "nothing", "" + , "", "" + ) + addToCallBack(ConstantMsgType.FORWARD_MESSAGE, uniqueId, position) break } } @@ -1099,17 +1490,19 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis if (contact.isHasUser) { val contactId = contact.id - val inviteList = Array(1, { i -> Invitee(contactId, 2) }) + val inviteList = Array(1) { Invitee(contactId, 2) } inviteList[0].id = contactId val uniqueId = mainViewModel.createThread( ThreadType.Constants.PUBLIC_GROUP, inviteList, "nothing", "" , "", "" ) - fucCallback[ConstantMsgType.ADD_PARTICIPANT] = uniqueId + val position = 10 + addToCallBack(ADD_PARTICIPANT, uniqueId, position) + choose++ if (choose == 2) { - fucCallback["ADD_PARTICIPANT_ID"] = contactId.toString() + addToCallBack(contactId.toString(), ADD_PARTICIPANT_ID, position) break } } @@ -1125,8 +1518,10 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis .email(faker.lordOfTheRings().character() + "@Gmail.com") .cellphoneNumber(faker.phoneNumber().cellPhone()) .build() - fucCallback[ConstantMsgType.REMOVE_CONTACT] = mainViewModel.addContacts(requestAddContact) + val uniqueId = mainViewModel.addContacts(requestAddContact) + val position = 9 + changeIconSend(position, REMOVE_CONTACT, uniqueId) } private fun handleSendMessageResponse(contactList: ArrayList?) { @@ -1144,7 +1539,8 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis .message(requestThreadInnerMessage) .build() val uniqueId = mainViewModel.createThreadWithMessage(requestCreateThread) - fucCallback[ConstantMsgType.SEND_MESSAGE] = uniqueId!![0] + + funcCallback[uniqueId!![0]]?.method = ConstantMsgType.SEND_MESSAGE break } } @@ -1161,10 +1557,9 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis if (contact.isHasUser) { val contactId = contact.id - val requestBlock = RequestBlock.Builder(contactId).build() + val requestBlock = RequestBlock.Builder().contactId(contactId).build() val uniqueId = mainViewModel.blockContact(requestBlock) - fucCallback[ConstantMsgType.UNBLOCK_CONTACT] = uniqueId - + addToCallBack(ConstantMsgType.UNBLOCK_CONTACT, uniqueId, 6) break } } @@ -1189,8 +1584,9 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis .build() val uniqueId = mainViewModel.updateContact(requestUpdateContact) - fucCallback[ConstantMsgType.UPDATE_CONTACT] = uniqueId - changeIconSend(7) + addToCallBack(ConstantMsgType.UPDATE_CONTACT, uniqueId, 7) +// funcCallback[uniqueId]?.method = ConstantMsgType.UPDATE_CONTACT +// changeIconSend(7, ConstantMsgType.UPDATE_CONTACT, uniqueId) break } } @@ -1204,19 +1600,29 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis if (contact.isHasUser) { val contactId = contact.id - val requestBlock = RequestBlock.Builder(contactId).build() + val requestBlock = RequestBlock.Builder().contactId(contactId).build() val uniqueId = mainViewModel.blockContact(requestBlock) - fucCallback[ConstantMsgType.BLOCK_CONTACT] = uniqueId - changeIconSend(2) + +// funcCallback[uniqueId]?.method = ConstantMsgType.BLOCK_CONTACT + addToCallBack(ConstantMsgType.BLOCK_CONTACT, uniqueId, 2) +// changeIconSend(2, ConstantMsgType.BLOCK_CONTACT, uniqueId) break } } } } - private fun getPartitipant() { + private fun addToCallBack(methodName: String, uniqueId: String, position: Int) { + + val callBackMethod = CallBackMethod(methodName, position) + funcCallback[uniqueId] = callBackMethod + } + + private fun getThreadParticipant() { val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() - fucCallback[ConstantMsgType.GET_PARTICIPANT] = mainViewModel.getContact(requestGetContact) + val uniqueId = mainViewModel.getContact(requestGetContact) + val position = 21 + changeIconSend(position, ConstantMsgType.GET_PARTICIPANT, uniqueId) } //Get Thread @@ -1225,48 +1631,49 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis // Then send Message to that thread private fun sendTextMsg() { val requestThread = RequestThread.Builder().build() - fucCallback[ConstantMsgType.SEND_MESSAGE] = mainViewModel.getThread(requestThread) -// val requestMessage = RequestMessage.Builder() -// mainViewModel.sendTextMsg()ConstantMsgType.UNBLOCK_CONTACT + val uniqueId = mainViewModel.getThread(requestThread) + changeIconSend(8, ConstantMsgType.SEND_MESSAGE, uniqueId) } - private fun unMuteThread() { val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() - fucCallback[ConstantMsgType.UNMUTE_THREAD] = mainViewModel.getContact(requestGetContact) + val uniqueId = mainViewModel.getContact(requestGetContact) val position = 16 - changeIconSend(position) -// val requestMuteThread = RequestMuteThread.Builder(threadId).build() -// mainViewModel.unMuteThread(requestMuteThread) + changeIconSend(position, ConstantMsgType.UNMUTE_THREAD, uniqueId) } private fun muteThread() { val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() - fucCallback[ConstantMsgType.MUTE_THREAD] = mainViewModel.getContact(requestGetContact) + val uniqueId = mainViewModel.getContact(requestGetContact) val position = 15 - changeIconSend(position) + changeIconSend(position, ConstantMsgType.MUTE_THREAD, uniqueId) } private fun leaveThread() { val requestGetContact = RequestGetContact.Builder().build() - fucCallback[ConstantMsgType.LEAVE_THREAD] = mainViewModel.getContact(requestGetContact) + val uniqueId = mainViewModel.getContact(requestGetContact) + + val position = 14 + changeIconSend(position, ConstantMsgType.LEAVE_THREAD, uniqueId) } private fun removeParticipant() { - val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() - fucCallback[ConstantMsgType.REMOVE_PARTICIPANT] = mainViewModel.getContact(requestGetContact) + val uniqueId = mainViewModel.getContact(requestGetContact) + funcCallback[uniqueId]?.method = ConstantMsgType.REMOVE_PARTICIPANT val position = 11 - changeIconSend(position) + changeIconSend(position, ConstantMsgType.REMOVE_PARTICIPANT, uniqueId) } private fun blockContact() { val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() val uniqueId = mainViewModel.getContact(requestGetContact) - fucCallback[ConstantMsgType.BLOCK_CONTACT] = uniqueId + val position = 2 + + changeIconSend(position, BLOCK_CONTACT, uniqueId) } private fun addContact() { @@ -1276,18 +1683,21 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis .firstName(faker.name()?.firstName()) .lastName(faker.name()?.lastName()) .build() - val uniqueId = mainViewModel.addContacts(requestAddContact) - fucCallback[ConstantMsgType.ADD_CONTACT] = uniqueId + lateinit var uniqueId: String + activity?.runOnUiThread { + uniqueId = mainViewModel.addContacts(requestAddContact) + } + val position = 3 - changeIconSend(position) + changeIconSend(position, ConstantMsgType.ADD_CONTACT, uniqueId) } private fun getContact() { val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() val uniqueId = mainViewModel.getContact(requestGetContact) - fucCallback[ConstantMsgType.GET_CONTACT] = uniqueId var position = 1 - changeIconSend(position) + + changeIconSend(position, GET_CONTACT, uniqueId) } private fun createThread() { @@ -1297,14 +1707,17 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() val uniqueId = mainViewModel.getContact(requestGetContact) - fucCallback[ConstantMsgType.CREATE_THREAD] = uniqueId - changeIconSend(0) + funcCallback[uniqueId]?.method = ConstantMsgType.CREATE_THREAD + changeIconSend(0, CREATE_THREAD, uniqueId) } - + //TODO here private fun createThreadWithForwMessage() { val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() - fucCallback[ConstantMsgType.CREATE_THREAD_WITH_FORW_MSG] = mainViewModel.getContact(requestGetContact) + val uniqueId = mainViewModel.getContact(requestGetContact) + val position = 20 + changeIconSend(position, CREATE_THREAD_WITH_FORW_MSG, uniqueId) +// funcCallback[uniqueId]?.method = ConstantMsgType.CREATE_THREAD_WITH_FORW_MSG } private fun createThreadOwnerGroup(inviteList: ArrayList) { @@ -1315,7 +1728,8 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis ThreadType.Constants.OWNER_GROUP, list, "nothing", "" , "", "" ) - fucCallback[ConstantMsgType.CREATE_THREAD_OWNER_GROUP] = uniqueId + val position = 0 + addToCallBack(ConstantMsgType.CREATE_THREAD_OWNER_GROUP, uniqueId, position) } private fun createThreadPublicGroup(inviteList: ArrayList) { @@ -1325,7 +1739,8 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis ThreadType.Constants.PUBLIC_GROUP, list, "nothing", "" , "", "" ) - fucCallback[ConstantMsgType.CREATE_THREAD_PUBLIC_GROUP] = uniqueId + val position = 0 + addToCallBack(ConstantMsgType.CREATE_THREAD_PUBLIC_GROUP, uniqueId, position) } private fun createThreadChannelGroup(inviteList: ArrayList) { @@ -1335,8 +1750,8 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis ThreadType.Constants.CHANNEL_GROUP, list, "nothing", "" , "", "" ) - fucCallback[ConstantMsgType.CREATE_THREAD_CHANNEL_GROUP] = uniqueId - + val position = 0 + addToCallBack(ConstantMsgType.CREATE_THREAD_CHANNEL_GROUP, uniqueId, position) } private fun createThreadChannel(inviteList: ArrayList) { @@ -1346,26 +1761,32 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis ThreadType.Constants.CHANNEL, list, "nothing", "" , "", "" ) - fucCallback[ConstantMsgType.CREATE_THREAD_CHANNEL] = uniqueId + val position = 0 + addToCallBack(ConstantMsgType.CREATE_THREAD_CHANNEL, uniqueId, position) } - private fun handleRemoveParticipant(contactList: ArrayList?) { if (contactList != null) { + var choose = 0 for (contact: Contact in contactList) { if (contact.isHasUser) { + val position = 11 val contactId = contact.id - val inviteList = ArrayList() - inviteList.add(Invitee(contactId, 1)) - val requestThreadInnerMessage = - RequestThreadInnerMessage.Builder().message(faker.music().genre()).build() - val requestCreateThread: RequestCreateThread = - RequestCreateThread.Builder(0, inviteList) - .message(requestThreadInnerMessage) - .build() -// val uniqueId = mainViewModel.createThread(requestCreateThread) -// fucCallback[ConstantMsgType.CREATE_THREAD] = uniqueId - break + + val inviteList = Array(1) { Invitee(contactId, 2) } + inviteList[0].id = contactId + + val uniqueId = mainViewModel.createThread( + ThreadType.Constants.PUBLIC_GROUP, inviteList, "nothing", "" + , "", "" + ) + + addToCallBack(REMOVE_PARTICIPANT, uniqueId, position) + choose++ + if (choose == 2) { + addToCallBack(contactId.toString(), ConstantMsgType.REMOVE_PARTICIPANT_ID, position) + break + } } } } @@ -1397,8 +1818,9 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis .message(requestThreadInnerMessage) .build() val uniqueId = mainViewModel.createThreadWithMessage(requestCreateThread) - fucCallback[ConstantMsgType.CREATE_THREAD] = uniqueId!![0] + funcCallback[uniqueId!![0]]?.method = ConstantMsgType.CREATE_THREAD_WITH_MSG + createThread(inviteList) createThreadChannel(inviteList) createThreadChannelGroup(inviteList) createThreadOwnerGroup(inviteList) @@ -1409,31 +1831,46 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis } } + private fun createThread(inviteList: ArrayList) { + val list = Array(1, { i -> Invitee(inviteList[0].id, 2) }) + + val uniqueId = mainViewModel.createThread( + ThreadType.Constants.NORMAL, list, "nothing", "" + , "", "" + ) + val position = 0 + addToCallBack(ConstantMsgType.CREATE_THREAD_NORMAL, uniqueId, position) + } + private fun unBlockContact() { // get Contact - // block contact with 3 params - // + + val position = 6 val requestGetContact = RequestGetContact.Builder().build() - fucCallback[ConstantMsgType.UNBLOCK_CONTACT] = mainViewModel.getContact(requestGetContact) + val uniqueId = mainViewModel.getContact(requestGetContact) + changeIconSend(position, ConstantMsgType.UNBLOCK_CONTACT, uniqueId) } private fun updateContact() { val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() - fucCallback[ConstantMsgType.UPDATE_CONTACT] = mainViewModel.getContact(requestGetContact) + val uniqueId = mainViewModel.getContact(requestGetContact) +// funcCallback[mainViewModel.getContact(requestGetContact)]?.method = ConstantMsgType.UPDATE_CONTACT val position = 7 - changeIconSend(position) + changeIconSend(position, UPDATE_CONTACT, uniqueId) } private fun getBlockList() { val requestBlockList = RequestBlockList.Builder().build() - mainViewModel.getBlockList(requestBlockList) + val uniqueId = mainViewModel.getBlockList(requestBlockList) + val position = 5 + changeIconSend(position, ConstantMsgType.BLOCK_LIST, uniqueId) } private fun getThread() { val requestThread = RequestThread.Builder().build() - fucCallback[ConstantMsgType.GET_THREAD] = mainViewModel.getThread(requestThread) + val uniqueId = mainViewModel.getThread(requestThread) val position = 4 - changeIconSend(position) + changeIconSend(position, ConstantMsgType.GET_THREAD, uniqueId) } private fun scroll(position: Int) { @@ -1442,26 +1879,45 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis } private fun changeIconReceive(position: Int) { + + + activity?.runOnUiThread { + val viewHolder: RecyclerView.ViewHolder? = recyclerViewFunction.findViewHolderForAdapterPosition(position) + viewHolder?.itemView?.findViewById(R.id.progress_method)?.visibility = View.GONE + viewHolder?.itemView?.findViewById(R.id.imgView_log) + ?.setColorFilter(ContextCompat.getColor(activity!!, R.color.colorPrimary)) + + } + } + + private fun changeIconReceive(position: Int, log: ChatResponse) { methods[position].methodNameFlag = true + methods[position].pending = false + val jsonString = gson.toJson(log) + methods[position].log = jsonString + activity?.runOnUiThread { - val viewHolder: RecyclerView.ViewHolder? = recyclerView.findViewHolderForAdapterPosition(position) + val viewHolder: RecyclerView.ViewHolder? = recyclerViewFunction.findViewHolderForAdapterPosition(position) viewHolder?.itemView?.findViewById(R.id.progress_method)?.visibility = View.GONE -// viewHolder?.itemView?.findViewById(R.id.checkBox_ufil) -// ?.setImageResource(R.drawable.ic_round_done_all_24px) -// viewHolder?.itemView?.findViewById(R.id.checkBox_ufil) -// ?.setColorFilter(ContextCompat.getColor(activity!!, R.color.colorPrimary)) + viewHolder?.itemView?.findViewById(R.id.imgView_log) + ?.setColorFilter(ContextCompat.getColor(activity!!, R.color.colorPrimary)) + } } /* visibility of progress bar*/ - private fun changeIconSend(position: Int) { - activity?.runOnUiThread { + private fun changeIconSend(position: Int, methodName: String, uniqueId: String) { + if (this.chatStates!!) { + val callBackMethod = CallBackMethod(methodName, position) + funcCallback[uniqueId] = callBackMethod + methods[position].pending = true - val viewHolder: RecyclerView.ViewHolder = recyclerView.findViewHolderForAdapterPosition(position)!! - viewHolder.itemView.findViewById(R.id.progress_method).visibility = View.VISIBLE + activity?.runOnUiThread { -// viewHolder.itemView.findViewById(R.id.checkBox_ufil) -// .setImageResource(R.drawable.ic_round_done_all_24px) + val viewHolder: RecyclerView.ViewHolder = + recyclerViewFunction.findViewHolderForAdapterPosition(position)!! + viewHolder.itemView.findViewById(R.id.progress_method).visibility = View.VISIBLE + } } } /* @@ -1472,34 +1928,25 @@ class FunctionFragment : Fragment(), FunctionAdapter.ViewHolderListener, TestLis private fun addParticipant() { val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() - fucCallback[ConstantMsgType.ADD_PARTICIPANT] = mainViewModel.getContact(requestGetContact) + val uniqueId = mainViewModel.getContact(requestGetContact) val position = 10 - changeIconSend(position) + changeIconSend(position, ConstantMsgType.ADD_PARTICIPANT, uniqueId) } + //TODO its not working private fun forwardMessage() { val requestGetContact = RequestGetContact.Builder().build() - fucCallback[ConstantMsgType.FORWARD_MESSAGE] = mainViewModel.getContact(requestGetContact) - - - //get contact - //createThread with message with that first contact - //createThread with second contact - - //forward the message from first thread to second thread - - // if the sent type come then its sent - + val uniqueId = mainViewModel.getContact(requestGetContact) + val position = 12 + changeIconSend(position, ConstantMsgType.FORWARD_MESSAGE, uniqueId) } private fun replyMessage() { val requestGetContact = RequestGetContact.Builder().build() - fucCallback[ConstantMsgType.REPLY_MESSAGE] = mainViewModel.getContact(requestGetContact) - - //getContact - //CreateThread with message - //get that message id and thread id and call reply Message + val uniqueId = mainViewModel.getContact(requestGetContact) + val position = 13 + changeIconSend(position, ConstantMsgType.REPLY_MESSAGE, uniqueId) } } diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/function/ResponseAdapter.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/function/ResponseAdapter.kt new file mode 100644 index 0000000..d7efb22 --- /dev/null +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/function/ResponseAdapter.kt @@ -0,0 +1,43 @@ +package ir.fanap.chattestapp.application.ui.function + +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import ir.fanap.chattestapp.R +import ir.fanap.chattestapp.bussines.model.FunctionStatus + +class ResponseAdapter( + private val subMethods: MutableList +) : + RecyclerView.Adapter() { + + override fun onCreateViewHolder(viewGroup: ViewGroup, p1: Int): ViewHolder { + val v = LayoutInflater.from(viewGroup.context) + .inflate(R.layout.item_function, viewGroup, false) + return ViewHolder(v) + } + + inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val textView_function: TextView = itemView.findViewById(R.id.textView_function) + val textView_item_function_state: TextView = itemView.findViewById(R.id.textView_item_function_state) + val txtView_error_log: TextView = itemView.findViewById(R.id.txtView_error_log) + } + + override fun getItemCount(): Int { + return subMethods.size + } + + override fun onBindViewHolder(viewHolder: ResponseAdapter.ViewHolder, position: Int) { + + viewHolder.textView_function.text = subMethods[position].methodName + viewHolder.textView_item_function_state.text = subMethods[position].status + if (!subMethods[position].errorLog.isBlank()) { + viewHolder.txtView_error_log.text = subMethods[position].errorLog + viewHolder.txtView_error_log.visibility = View.VISIBLE + }else{ + viewHolder.txtView_error_log.visibility = View.GONE + } + } +} \ No newline at end of file diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/log/LogFragment.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/log/LogFragment.kt index 52057b6..6e09269 100644 --- a/app/src/main/java/ir/fanap/chattestapp/application/ui/log/LogFragment.kt +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/log/LogFragment.kt @@ -2,6 +2,7 @@ package ir.fanap.chattestapp.application.ui.log import android.app.SearchManager import android.arch.lifecycle.ViewModelProvider +import android.arch.lifecycle.ViewModelProviders import android.os.Bundle import android.support.design.widget.FloatingActionButton import android.support.v4.app.Fragment @@ -16,11 +17,14 @@ import ir.fanap.chattestapp.application.ui.MainViewModel import ir.fanap.chattestapp.application.ui.TestListener import kotlinx.android.synthetic.main.fragment_log.* import android.content.Context +import com.fanap.podchat.model.ChatResponse +import com.fanap.podchat.model.ResultThreads +import com.google.gson.Gson +import com.google.gson.GsonBuilder import ir.fanap.chattestapp.application.ui.IOnBackPressed -class LogFragment : Fragment(), TestListener,IOnBackPressed { - +class LogFragment : Fragment(), LogListener,IOnBackPressed { private lateinit var mainViewModel: MainViewModel private var logs: MutableList = mutableListOf() @@ -69,9 +73,8 @@ class LogFragment : Fragment(), TestListener,IOnBackPressed { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - mainViewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(activity!!.application) - .create(MainViewModel::class.java) - mainViewModel.setTestListener(this) + mainViewModel = activity.run { ViewModelProviders.of(this!!).get(MainViewModel::class.java) } + mainViewModel.setLogListener(this) setHasOptionsMenu(true) } @@ -125,6 +128,4 @@ class LogFragment : Fragment(), TestListener,IOnBackPressed { logAdapter.notifyDataSetChanged() } } - - } \ No newline at end of file diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/log/LogListener.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/log/LogListener.kt new file mode 100644 index 0000000..4699248 --- /dev/null +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/log/LogListener.kt @@ -0,0 +1,5 @@ +package ir.fanap.chattestapp.application.ui.log + +interface LogListener{ + fun onLogEvent(log: String){} +} \ No newline at end of file diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/upload/UploadAdapter.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/upload/UploadAdapter.kt new file mode 100644 index 0000000..aba0f6f --- /dev/null +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/upload/UploadAdapter.kt @@ -0,0 +1,207 @@ +package ir.fanap.chattestapp.application.ui.upload + +import android.support.v4.app.FragmentActivity +import android.support.v4.content.ContextCompat +import android.support.v7.widget.AppCompatImageView +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ProgressBar +import android.widget.TextView +import ir.fanap.chattestapp.R +import ir.fanap.chattestapp.bussines.model.Method + +class UploadAdapter( + private val context: FragmentActivity, + private val methods: MutableList, + viewHolderListener1: UploadViewHListener) : RecyclerView.Adapter() { + + override fun onBindViewHolder(viewHolder: ViewHolderUpload, position: Int) { + viewHolder.txtViewMethod.text = methods[position].methodName + viewHolder.textViewFuncOne.text = methods[position].funcOne + viewHolder.textViewFuncTwo.text = methods[position].funcTwo + viewHolder.textViewFuncThree.text = methods[position].funcThree + viewHolder.textViewFuncFour.text = methods[position].funcFour + viewHolder.buttonRun.tag = position + viewHolder.buttonLog.tag = position + + if (methods[position].pending) { + viewHolder.progress_method.visibility = View.VISIBLE + } else { + viewHolder.progress_method.visibility = View.GONE + } + + if (methods[position].methodNameFlag == true) { + + context.runOnUiThread { + } + + viewHolder.buttonLog.setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary)) + } else { + viewHolder.buttonLog.setColorFilter(ContextCompat.getColor(context, R.color.grey_log_color)) + } + + if (methods[position].error) { + viewHolder.buttonLog.setColorFilter(ContextCompat.getColor(context, R.color.colorAccent)) + } else { + viewHolder.buttonLog.setColorFilter(ContextCompat.getColor(context, R.color.grey_log_color)) + } + + + if (methods[position].funcOneFlag == true) { + viewHolder.checkBoxOne + .setImageResource(R.drawable.ic_round_done_all_24px) + + viewHolder.checkBoxOne + .setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary)) + } else { + viewHolder.checkBoxOne + .setImageResource(R.drawable.ic_done_black_24dp) + } + + + if (methods[position].funcTwoFlag == true) { + viewHolder.checkBoxSec + .setImageResource(R.drawable.ic_round_done_all_24px) + + viewHolder.checkBoxSec + .setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary)) + } else { + viewHolder.checkBoxSec + .setImageResource(R.drawable.ic_done_black_24dp) + } + + if (methods[position].funcThreeFlag == true) { + viewHolder.checkBoxThird + .setImageResource(R.drawable.ic_round_done_all_24px) + + viewHolder.checkBoxThird + .setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary)) + } else { + viewHolder.checkBoxThird + .setImageResource(R.drawable.ic_done_black_24dp) + } + + if (methods[position].funcFourFlag == true) { + viewHolder.checkBoxFourth + .setImageResource(R.drawable.ic_round_done_all_24px) + + viewHolder.checkBoxFourth + .setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary)) + } else { + viewHolder.checkBoxFourth + .setImageResource(R.drawable.ic_done_black_24dp) + } + + if (!viewHolder.textViewFuncOne.text.isEmpty()) { + viewHolder.checkBoxOne.visibility = View.VISIBLE + viewHolder.textViewFuncOne.visibility = View.VISIBLE + } else { + viewHolder.checkBoxOne.visibility = View.GONE + viewHolder.textViewFuncOne.visibility = View.GONE + } + if (!viewHolder.textViewFuncTwo.text.isEmpty()) { + viewHolder.checkBoxSec.visibility = View.VISIBLE + viewHolder.textViewFuncTwo.visibility = View.VISIBLE + } else { + viewHolder.checkBoxSec.visibility = View.GONE + viewHolder.textViewFuncTwo.visibility = View.GONE + } + + if (!viewHolder.textViewFuncThree.text.isEmpty()) { + viewHolder.checkBoxThird.visibility = View.VISIBLE + viewHolder.textViewFuncThree.visibility = View.VISIBLE + } else { + viewHolder.checkBoxThird.visibility = View.GONE + viewHolder.textViewFuncThree.visibility = View.GONE + } + + if (!viewHolder.textViewFuncFour.text.isEmpty()) { + viewHolder.checkBoxFourth.visibility = View.VISIBLE + viewHolder.textViewFuncFour.visibility = View.VISIBLE + } else { + viewHolder.checkBoxFourth.visibility = View.GONE + viewHolder.textViewFuncFour.visibility = View.GONE + } + + } + + override fun onCreateViewHolder(viewGroup: ViewGroup, position: Int): ViewHolderUpload { + val v = LayoutInflater.from(viewGroup.context) + .inflate(R.layout.item_method, viewGroup, false) + return ViewHolderUpload(v, viewHolderListener) + } + + private val viewHolderListener: UploadViewHListener = viewHolderListener1 + private var pos: Int? = null + + override fun getItemViewType(position: Int): Int { + return super.getItemViewType(position) + } + +// fun tik(context: Context, viewHolder: ViewHolder) { +// viewHolder.checkBox.setColorFilter(context.resources.getColor(R.color.colorPrimary)) +// } + + override fun getItemId(position: Int): Long { + return super.getItemId(position) + } + + override fun getItemCount(): Int { + return methods.size + } + + fun getPosition(): Int? { + return pos + } + + fun setPos(position: Int) { + this.pos = position + } + + inner class ViewHolderUpload(itemView: View, viewHolderListener: UploadViewHListener) : + RecyclerView.ViewHolder(itemView) { + + + val textViewFuncOne: TextView = itemView.findViewById(R.id.textView_FunOne) + val textViewFuncTwo: TextView = itemView.findViewById(R.id.textView_FunTwo) + val textViewFuncThree: TextView = itemView.findViewById(R.id.textView_FunThree) + val textViewFuncFour: TextView = itemView.findViewById(R.id.textView_FunFour) + val txtViewMethod: TextView = itemView.findViewById(R.id.textView_method) + val checkBox: AppCompatImageView = itemView.findViewById(R.id.checkBox_test) + val checkBoxOne: AppCompatImageView = itemView.findViewById(R.id.imageView_tickFirst) + val checkBoxSec: AppCompatImageView = itemView.findViewById(R.id.imageView_tickSec) + val checkBoxThird: AppCompatImageView = itemView.findViewById(R.id.imageView_tickThird) + val checkBoxFourth: AppCompatImageView = itemView.findViewById(R.id.imageView_tickFourth) + val buttonLog: AppCompatImageView = itemView.findViewById(R.id.imgView_log) + val buttonRun: AppCompatImageView = itemView.findViewById(R.id.buttonRun) + + val progress_method = itemView.findViewById(R.id.progress_method) as ProgressBar + + init { + buttonRun.setOnClickListener(View.OnClickListener { + viewHolderListener.onIconClicked(this) + }) + + buttonLog.setOnClickListener { + viewHolderListener.onLogClicked(this) + } + } + } + +// override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder { +// val v = LayoutInflater.from(viewGroup.context) +// .inflate(R.layout.item_method, viewGroup, false) +// return ViewHolder(v, viewHolderListener) +// } + + interface UploadViewHListener { + fun onIconClicked(clickedViewHolder: ViewHolderUpload) + fun onLogClicked(clickedViewHolder: ViewHolderUpload) + } + + interface ICheckChangeListener { + fun onItemMethodChecked(position: Int, value: Boolean) + } +} \ No newline at end of file diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/upload/UploadFragment.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/upload/UploadFragment.kt new file mode 100644 index 0000000..2f25a6e --- /dev/null +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/upload/UploadFragment.kt @@ -0,0 +1,572 @@ +package ir.fanap.chattestapp.application.ui.upload + +import android.os.Bundle +import android.support.v4.app.Fragment +import android.support.v7.widget.AppCompatImageView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import ir.fanap.chattestapp.R +import android.arch.lifecycle.ViewModelProviders +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.provider.MediaStore +import android.support.constraint.ConstraintLayout +import android.support.design.widget.BottomSheetBehavior +import android.support.v4.content.ContextCompat +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.widget.Button +import android.widget.ProgressBar +import android.widget.TextView +import android.widget.Toast +import com.fanap.podchat.ProgressHandler +import com.fanap.podchat.mainmodel.Contact +import com.fanap.podchat.mainmodel.Invitee +import com.fanap.podchat.model.* +import com.fanap.podchat.requestobject.* +import com.fanap.podchat.util.ThreadType +import com.github.javafaker.Faker +import com.google.gson.Gson +import com.google.gson.GsonBuilder +import ir.fanap.chattestapp.application.ui.MainViewModel +import ir.fanap.chattestapp.application.ui.function.ResponseAdapter +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.CREATE_THREAD +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.EMPTY_ERROR_LOG +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.GET_CONTACT +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.REPLY_FILE_MESSAGE +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.REPLY_FILE_MESSAGE_UPLOADED +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.SEND_FILE_MESSAGE +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.SEND_MESSAGE +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.SUCCESSFUL +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.UPLOAD_FILE +import ir.fanap.chattestapp.application.ui.util.ConstantMsgType.Companion.UPLOAD_IMAGE +import ir.fanap.chattestapp.application.ui.util.UploadList +import ir.fanap.chattestapp.bussines.model.CallBackMethod +import ir.fanap.chattestapp.bussines.model.FunctionStatus +import ir.fanap.chattestapp.bussines.model.Method +import kotlinx.android.synthetic.main.bottom_sheet_log.* +import java.util.ArrayList + +class UploadFragment : Fragment(), UploadListener, UploadAdapter.UploadViewHListener { + + private lateinit var atach_file: AppCompatImageView + private lateinit var mainViewModel: MainViewModel + private val REQUEST_TAKE_PHOTO = 0 + private val REQUEST_SELECT_IMAGE_IN_ALBUM = 1 + private lateinit var contextFrag: Context + private var imageUrl: Uri? = null + private var methods: MutableList = mutableListOf() + private lateinit var subMethods: MutableList + private lateinit var bottom_sheet_log: ConstraintLayout + private lateinit var bottomSheetLog: BottomSheetBehavior + private lateinit var textView_log: TextView + private var funcCallback: HashMap = hashMapOf() + private var chatStates: Boolean? = false + private var gson: Gson = GsonBuilder().setPrettyPrinting().create() + private lateinit var txtView_noResponse: TextView + + private lateinit var recyclerViewResponse: RecyclerView + private lateinit var recyclerViewUpload: RecyclerView + private val faker: Faker = Faker() + + companion object { + fun newInstance(): UploadFragment { + return UploadFragment() + } + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + } + + override fun onAttach(context: Context?) { + super.onAttach(context) + contextFrag = context!! + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + mainViewModel = activity.run { ViewModelProviders.of(this!!).get(MainViewModel::class.java) } + mainViewModel.setUploadListener(this) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + val view = inflater.inflate(R.layout.fragment_upload, container, false) + val appCompatImageView_gallery: AppCompatImageView = view.findViewById(R.id.appCompatImageView_gallery) + +// mainViewModel.chatStateObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) +// .subscribe { +// if (it.equals("CHAT_READY")) { +// chatStates = true +// } +// } + initView(view) + val buttonClose = view.findViewById(R.id.button_close) as Button + + bottomSheetSetup(buttonClose) + + setupUploadRecyclerView(view) + setupSubMethodRecyclerView(view) + + val appCmpImgViewFolder: AppCompatImageView = view.findViewById(R.id.appCompatImageView_folder) + appCompatImageView_gallery.setOnClickListener { + selectImageInAlbum() + } + return view + } + + private fun setupSubMethodRecyclerView(view: View) { + recyclerViewResponse = view.findViewById(R.id.recyclerView_response) + + recyclerViewResponse.setHasFixedSize(true) + val linearLayoutMngResponse = LinearLayoutManager(context) + recyclerViewResponse.layoutManager = linearLayoutMngResponse + } + + private fun setupUploadRecyclerView(view: View) { + + for (i in 0..3) { + val method = Method() + val mutableList = arrayListOf() + method.methodName = UploadList.methodNames[i] + method.funcOne = UploadList.methodFuncOne[i] + method.funcTwo = UploadList.methodFuncTwo[i] + method.funcThree = UploadList.methodFuncThree[i] + method.funcFour = UploadList.methodFuncFour[i] + val functionStatus = FunctionStatus() + functionStatus.errorLog = "" + functionStatus.methodName = "" + functionStatus.status = "" + method.funcStatusList = mutableList + methods.add(method) + } + + val uploadAdapter = UploadAdapter(this.activity!!, methods, this) + recyclerViewUpload.adapter = uploadAdapter + recyclerViewUpload.setHasFixedSize(true) + val linearLayoutManager = LinearLayoutManager(context) + recyclerViewUpload.layoutManager = linearLayoutManager + } + + override fun onUploadFile(response: ChatResponse?) { + super.onUploadFile(response) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.UPLOAD_FILE) { + funcCallback.remove(response?.uniqueId) + val position = 2 + changeIconReceive(position, response!!) + } + } + + override fun onUploadImageFile(response: ChatResponse?) { + super.onUploadImageFile(response) + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.SEND_FILE_MESSAGE) { + + } + + if (funcCallback[response?.uniqueId]?.method == UPLOAD_IMAGE) { + funcCallback.remove(response?.uniqueId) + val position = 3 + changeIconReceive(position, response!!) + } + } + + override fun onIconClicked(clickedViewHolder: UploadAdapter.ViewHolderUpload) { + val position = clickedViewHolder.adapterPosition + when (position) { + 0 -> { + sendFileMessage() + } + 1 -> { + sendReplyFileMessage() + } + 2 -> { + uploadFile() + } + 3 -> { + uploadImage() + } + } + } + + override fun onLogClicked(clickedViewHolder: UploadAdapter.ViewHolderUpload) { + val position = clickedViewHolder.adapterPosition + + bottomSheetLog.state = BottomSheetBehavior.STATE_EXPANDED + + subMethods = methods[position].funcStatusList!! + val responseAdapter = ResponseAdapter(subMethods) + recyclerView_response.adapter = responseAdapter + if (methods[position].log != null && !methods[position].log?.isEmpty()!!) { + textView_log.text = methods[position].log +// when (position) { +// 0 -> { +// +// } +// 1 -> { +// textView_log.text = methods[position].log +// } +// 2 -> { +// textView_log.text = methods[position].log +// } +/// +// } + } + + if (subMethods.size >= 1) { + + appCompatImageView_noResponse.visibility = View.GONE + txtView_noResponse.visibility = View.GONE + + recyclerView_response.visibility = View.VISIBLE + } else { + recyclerView_response.visibility = View.GONE + appCompatImageView_noResponse.visibility = View.VISIBLE + txtView_noResponse.visibility = View.VISIBLE + } + + if (textView_log.text.isEmpty()) { + appCompatImageView_noResponse.visibility = View.VISIBLE + txtView_noResponse.visibility = View.VISIBLE + + scrollView_log.visibility = View.GONE + + } else { + appCompatImageView_noResponse.visibility = View.GONE + txtView_noResponse.visibility = View.GONE + + scrollView_log.visibility = View.VISIBLE + } + } + + private fun initView(view: View) { + bottom_sheet_log = view.findViewById(R.id.bottom_sheet_log) + textView_log = view.findViewById(R.id.textView_log) + recyclerViewUpload = view.findViewById(R.id.recyclerV_upload) + txtView_noResponse = view.findViewById(R.id.TxtView_noResponse) + } + + override fun onSent(response: ChatResponse?) { + super.onSent(response) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.SEND_FILE_MESSAGE) { + funcCallback.remove(response?.uniqueId) + val position = 0 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG,SEND_FILE_MESSAGE) + changeIconReceive(position, response!!) + } + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.REPLY_FILE_MESSAGE_UPLOADED) { + funcCallback.remove(response?.uniqueId) + val position = 1 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, REPLY_FILE_MESSAGE) + changeIconReceive(position, response!!) + } + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.REPLY_FILE_MESSAGE) { + val position = 1 + funcCallback.remove(response?.uniqueId) + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, SEND_MESSAGE) + val requestFileMessage = RequestReplyFileMessage + .Builder( + "This is reply", response?.result?.conversationId!! + , response.result.messageId + , imageUrl, activity + ) + .build() + val uniqueId = mainViewModel.replyFileMessage(requestFileMessage, object : ProgressHandler.sendFileMessage { + override fun onFinishImage(json: String?, chatResponse: ChatResponse?) { + super.onFinishImage(json, chatResponse) + + } + }) + addToCallBack(REPLY_FILE_MESSAGE_UPLOADED, uniqueId, position) + } + } + + override fun onGetContact(response: ChatResponse?) { + super.onGetContact(response) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.SEND_FILE_MESSAGE) { + val position = 0 + updateMethodList( + position, + ConstantMsgType.SUCCESSFUL, + ConstantMsgType.EMPTY_ERROR_LOG, + ConstantMsgType.GET_CONTACT + ) + handleSendFileMsg(response!!.result.contacts) + } + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.REPLY_FILE_MESSAGE) { + val position = 1 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, GET_CONTACT) + handleReplyFileMessage(response!!.result.contacts) + } + } + + override fun onError(chatResponse: ErrorOutPut?) { + super.onError(chatResponse) + activity?.runOnUiThread { + Toast.makeText(activity, chatResponse?.errorMessage, Toast.LENGTH_LONG).show() + } + } + + override fun onCreateThread(response: ChatResponse?) { + super.onCreateThread(response) + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.SEND_FILE_MESSAGE) { + val position = 0 + updateMethodList( + position, + ConstantMsgType.SUCCESSFUL, + ConstantMsgType.EMPTY_ERROR_LOG, + ConstantMsgType.CREATE_THREAD + ) + val requestFileMessage = + RequestFileMessage.Builder(activity, response!!.result.thread.id, imageUrl).build() + val uniqueId = mainViewModel.sendFileMessage(requestFileMessage, object : ProgressHandler.sendFileMessage { + override fun onFinishImage(json: String?, chatResponse: ChatResponse?) { + super.onFinishImage(json, chatResponse) + changeIconReceive(position, chatResponse!!) + updateMethodList( + position, + ConstantMsgType.SUCCESSFUL, + ConstantMsgType.EMPTY_ERROR_LOG, + ConstantMsgType.UPLOAD_IMAGE + ) + } + }) + addToCallBack(ConstantMsgType.SEND_FILE_MESSAGE, uniqueId, position) + } + + if (funcCallback[response?.uniqueId]?.method == ConstantMsgType.REPLY_FILE_MESSAGE) { + val position = 1 + updateMethodList(position, SUCCESSFUL, EMPTY_ERROR_LOG, CREATE_THREAD) + funcCallback.remove(response?.uniqueId) + val threadId = response?.result?.thread?.id + val requestMessage = + RequestMessage.Builder("this is message for test reply file message", threadId!!) + .build() + val uniqueId = mainViewModel.sendTextMsg(requestMessage) + addToCallBack(ConstantMsgType.REPLY_FILE_MESSAGE, uniqueId, position) + } + } + + override fun onGetThread(chatResponse: ChatResponse?) { + super.onGetThread(chatResponse) + } + + private fun updateMethodList( + position: Int, + status: String, + errorLog: String, + methodName: String + ) { + + val functionStatus = FunctionStatus() + functionStatus.status = status + functionStatus.methodName = methodName + functionStatus.errorLog = errorLog + methods[position].funcStatusList?.add(functionStatus) + } + + private fun bottomSheetSetup(button_close: Button) { + bottomSheetLog = BottomSheetBehavior.from(bottom_sheet_log) + bottomSheetLog.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { + override fun onSlide(view: View, p1: Float) { + + } + + override fun onStateChanged(p0: View, state: Int) { + when (state) { + BottomSheetBehavior.STATE_HIDDEN -> { + textView_log.text = "" + } + BottomSheetBehavior.STATE_EXPANDED -> { + // textView_state.text = "close" + } + BottomSheetBehavior.STATE_COLLAPSED -> { + textView_log.text = "" + } + } + } + + }) + + button_close.setOnClickListener { + if (bottomSheetLog.state != BottomSheetBehavior.STATE_COLLAPSED) { + bottomSheetLog.state = BottomSheetBehavior.STATE_COLLAPSED + textView_log.text = "" + } + } + } + + /* visibility of progress bar*/ + private fun changeIconSend(position: Int, methodName: String, uniqueId: String) { + val callBackMethod = CallBackMethod(methodName, position) + funcCallback[uniqueId] = callBackMethod + methods[position].pending = true + + activity?.runOnUiThread { + + val viewHolder: RecyclerView.ViewHolder = + recyclerViewUpload.findViewHolderForAdapterPosition(position)!! + viewHolder.itemView.findViewById(R.id.progress_method).visibility = View.VISIBLE + } + } + + private fun changeIconReceive(position: Int, log: ChatResponse) { + methods[position].methodNameFlag = true + methods[position].pending = false + val jsonString = gson.toJson(log) + methods[position].log = jsonString + + activity?.runOnUiThread { + val viewHolder: RecyclerView.ViewHolder? = recyclerViewUpload.findViewHolderForAdapterPosition(position) + viewHolder?.itemView?.findViewById(R.id.progress_method)?.visibility = View.GONE + viewHolder?.itemView?.findViewById(R.id.imgView_log) + ?.setColorFilter(ContextCompat.getColor(activity!!, R.color.colorPrimary)) + + } + } + + private fun addToCallBack(methodName: String, uniqueId: String, position: Int) { + + val callBackMethod = CallBackMethod(methodName, position) + funcCallback[uniqueId] = callBackMethod + } + + //Get Contact + private fun handleReplyFileMessage(contactList: ArrayList) { + if (contactList != null) { + for (contact: Contact in contactList) { + if (contact.isHasUser) { + + val contactId = contact.id + + val inviteList = ArrayList() + inviteList.add(Invitee(contactId, 1)) + + val list = Array(1) { Invitee(inviteList[0].id, 2) } + + val uniqueId = mainViewModel.createThread( + ThreadType.Constants.NORMAL, list, "nothing", "" + , "", "" + ) + val position = 1 + addToCallBack(REPLY_FILE_MESSAGE, uniqueId, position) + break + } + } + } + } + + private fun handleSendFileMsg(contactList: ArrayList) { + + if (contactList != null) { + for (contact: Contact in contactList) { + if (contact.isHasUser) { + + val contactId = contact.id + + val inviteList = ArrayList() + inviteList.add(Invitee(contactId, 1)) + + val list = Array(1) { Invitee(inviteList[0].id, 2) } + + val uniqueId = mainViewModel.createThread( + ThreadType.Constants.NORMAL, list, "nothing", "" + , "", "" + ) + val position = 0 + addToCallBack(ConstantMsgType.SEND_FILE_MESSAGE, uniqueId, position) + break + } + } + } + } + + private fun sendFileMessage() { + + val requestGetContact: RequestGetContact = RequestGetContact.Builder().build() + val uniqueId = mainViewModel.getContact(requestGetContact) + val position = 0 + changeIconSend(position, ConstantMsgType.SEND_FILE_MESSAGE, uniqueId) + } + + private fun uploadFile() { + if (imageUrl != null) { + + val requestUploadFile = RequestUploadFile.Builder(activity, imageUrl).build() + val uniqueId = mainViewModel.uploadFile(requestUploadFile) + val position = 2 + changeIconSend(position, UPLOAD_FILE, uniqueId) + } + } + + //Chat needs update + private fun uploadImage() { + if (!imageUrl.toString().isEmpty()) { + val uniqueId = mainViewModel.uploadImage(activity, imageUrl!!) + val position = 3 + changeIconSend(position, UPLOAD_IMAGE, uniqueId) + } + } + + private fun uploadImageProgress() { + + if (!imageUrl.toString().isEmpty()) { + + mainViewModel.uploadImageProgress(contextFrag, activity, imageUrl, object : ProgressHandler.onProgress { + override fun onProgressUpdate( + uniqueId: String?, + bytesSent: Int, + totalBytesSent: Int, + totalBytesToSend: Int + ) { + super.onProgressUpdate(uniqueId, bytesSent, totalBytesSent, totalBytesToSend) + activity?.runOnUiThread { + // textView_progress_UploadImage.text = bytesSent.toString() + } + } + + override fun onFinish(imageJson: String?, chatResponse: ChatResponse?) { + super.onFinish(imageJson, chatResponse) + activity?.runOnUiThread { + // textView_progress_UploadImage.text = "100 % " +// textView_progress_UploadImage.setTextColor( + ContextCompat.getColor( + activity!!, + R.color.green_active + ) + + } + } + }) + } + } + + private fun sendReplyFileMessage() { + val requestGetContact = RequestGetContact.Builder().build() + val uniqueId = mainViewModel.getContact(requestGetContact) + val position = 1 + changeIconSend(position, ConstantMsgType.REPLY_FILE_MESSAGE, uniqueId) + } + + private fun selectImageInAlbum() { + val i = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI) + startActivityForResult(i, REQUEST_SELECT_IMAGE_IN_ALBUM) + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (data != null) { + if (REQUEST_SELECT_IMAGE_IN_ALBUM == requestCode) { + imageUrl = data.data + } + } + } +} + diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/upload/UploadListener.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/upload/UploadListener.kt new file mode 100644 index 0000000..6281fd4 --- /dev/null +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/upload/UploadListener.kt @@ -0,0 +1,86 @@ +package ir.fanap.chattestapp.application.ui.upload + +import com.fanap.podchat.mainmodel.ResultDeleteMessage +import com.fanap.podchat.model.* + +interface UploadListener { + + fun onGetThreadU() {} + + fun onGetContact(response: ChatResponse?) {} + fun onAddContact(response: ChatResponse?) {} + fun onCreateThread(response: ChatResponse?) {} + fun onBlock(chatResponse: ChatResponse?) {} + fun onUnBlock(response: ChatResponse?) {} + fun onGetThread(chatResponse: ChatResponse?) { + + } + fun onError(chatResponse: ErrorOutPut?) {} + fun onRemoveContact(response: ChatResponse?) {} + fun onBlockList(response: ChatResponse?) {} + fun onLogEvent(log: String) {} + fun onUpdateContact(response: ChatResponse?) {} + fun onSent(response: ChatResponse?) {} + fun onSeen(response: ChatResponse?) {} + fun onDeliver(response: ChatResponse?) {} + fun onThreadRemoveParticipant(response: ChatResponse?) { + } + + fun onThreadAddParticipant(response: ChatResponse?) { + + } + + fun onLeaveThread(response: ChatResponse?) { + + + } + + fun onUnmuteThread(response: ChatResponse?) { + + + } + + fun onMuteThread(response: ChatResponse?) { + + + } + + fun onDeleteMessage(response: ChatResponse?) { + + + } + + fun onEditedMessage(response: ChatResponse?) { + + + } + + fun onGetHistory(response: ChatResponse?) { + + + } + + fun onNewMessage(response: ChatResponse?) { + + + } + + fun onGetThreadParticipant(response: ChatResponse?) { + + + } + + fun onUploadFile(response: ChatResponse?) { + + + } + + fun onUploadImageFile(response: ChatResponse?) { + + + } + + fun onChatState(state: String?) { + + } +} diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/util/ConstantMsgType.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/util/ConstantMsgType.kt index d5490f2..3f3bdc8 100644 --- a/app/src/main/java/ir/fanap/chattestapp/application/ui/util/ConstantMsgType.kt +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/util/ConstantMsgType.kt @@ -20,6 +20,7 @@ class ConstantMsgType { const val CREATE_THREAD_OWNER_GROUP = "CREATE_THREAD_OWNER_GROUP" const val REMOVE_PARTICIPANT = "REMOVE_PARTICIPANT" const val ADD_PARTICIPANT = "ADD_PARTICIPANT" + const val ADD_PARTICIPANT_ID = "ADD_PARTICIPANT_ID" const val FORWARD_MESSAGE = "FORWARD_MESSAGE" const val FORWARD_MESSAGE_ID = "FORWARD_MESSAGE_ID" const val FORWARD_MESSAGE_THREAD_ID = "FORWARD_MESSAGE_ID" @@ -40,6 +41,16 @@ class ConstantMsgType { const val CREATE_THREAD_WITH_FORW_MSG_CONTCT_ID = "CREATE_THREAD_WITH_FORW_MSG_CONTCT_ID" const val CREATE_THREAD_WITH_FORW_MSG_ID = "CREATE_THREAD_WITH_FORW_MSG_ID" const val GET_PARTICIPANT = "GET_PARTICIPANT" + const val BLOCK_LIST = "BLOCK_LIST" + const val SUCCESSFUL = "SUCCESSFUL" + const val ERROR = "ERROR" + const val EMPTY_ERROR_LOG = "" + const val REMOVE_PARTICIPANT_ID = "REMOVE_PARTICIPANT_ID" + const val UPLOAD_IMAGE = "UPLOAD_IMAGE" + const val UPLOAD_FILE = "UPLOAD_FILE" + const val REPLY_FILE_MESSAGE_UPLOADED = "REPLY_FILE_MESSAGE_UPLOADED" + const val CREATE_THREAD_WITH_MSG = "CREATE_THREAD_WITH_MSG" + const val CREATE_THREAD_NORMAL = "CREATE_THREAD_NORMAL" } @StringDef( @@ -73,6 +84,10 @@ class ConstantMsgType { CREATE_THREAD_WITH_FORW_MSG, CREATE_THREAD_WITH_FORW_MSG_ID, GET_PARTICIPANT, + ADD_PARTICIPANT_ID, + BLOCK_LIST, + REMOVE_PARTICIPANT_ID, + REPLY_FILE_MESSAGE_UPLOADED, DELETE_MESSAGE ) diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/util/MethodList.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/util/MethodList.kt index 1c9f4cb..8eba70a 100644 --- a/app/src/main/java/ir/fanap/chattestapp/application/ui/util/MethodList.kt +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/util/MethodList.kt @@ -5,7 +5,7 @@ class MethodList { companion object { val methodNames: MutableList = arrayListOf( - "0 Create Thread with message(NORMAL)", + "0 Create Thread ", "1 get Contact", "2 Block Contact", "3 Add Contact", @@ -32,7 +32,7 @@ class MethodList { val methodFuncOne: MutableList = arrayListOf( - "CHANNEL",//0 + "",//0 "",//1 "",//2 "",//3 @@ -40,11 +40,11 @@ class MethodList { "",//5 "",//6 "",//7 - "8 sent",//8 + "",//8 "",//9 "",//10 "",//11 - "onSent",//12 + "",//12 "",//13 "",//14 "",//15 @@ -52,13 +52,13 @@ class MethodList { "",//17 "",//18 "",//19 - "onSent", + "", ""//21 ) val methodFuncTwo: MutableList = arrayListOf( - "CHANNEL_GROUP",//0 + "",//0 "",//1 "",//2 "",//3 @@ -66,7 +66,7 @@ class MethodList { "",//5 "",//6 "",//7 - "8 deliver",//8 + "",//8 "",//9 "",//10 "",//11 @@ -84,7 +84,7 @@ class MethodList { val methodFuncThree: MutableList = arrayListOf( - "PUBLIC_GROUP",//0 + "",//0 "",//1 "",//2 "",//3 @@ -92,7 +92,7 @@ class MethodList { "",//5 "",//6 "",//7 - "8 seen", + "", "",//9 "",//10 "",//11 @@ -110,7 +110,7 @@ class MethodList { val methodFuncFour: MutableList = arrayListOf( - "OWNER_GROUP",//0 + "",//0 "",//1 "",//2 "",//3 diff --git a/app/src/main/java/ir/fanap/chattestapp/application/ui/util/UploadList.kt b/app/src/main/java/ir/fanap/chattestapp/application/ui/util/UploadList.kt new file mode 100644 index 0000000..5f102ac --- /dev/null +++ b/app/src/main/java/ir/fanap/chattestapp/application/ui/util/UploadList.kt @@ -0,0 +1,45 @@ +package ir.fanap.chattestapp.application.ui.util + +class UploadList{ + companion object { + val methodNames: MutableList = + arrayListOf( + "0 Send file message", + "1 Reply file message", + "2 upload file", + "3 upload image" + ) + + val methodFuncOne: MutableList = + arrayListOf( + "",//0 + "",//1 + "",//2 + "" + ) + + val methodFuncTwo: MutableList = + arrayListOf( + "",//0 + "",//1 + "",//2 + "" + ) + + val methodFuncThree: MutableList = + arrayListOf( + "",//0 + "",//1 + "",//2 + "" + ) + + val methodFuncFour: MutableList = + arrayListOf( + "",//0 + "",//1 + "",//2 + "" + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/ir/fanap/chattestapp/bussines/model/CallBackMethod.kt b/app/src/main/java/ir/fanap/chattestapp/bussines/model/CallBackMethod.kt index 62ff6dd..c31646a 100644 --- a/app/src/main/java/ir/fanap/chattestapp/bussines/model/CallBackMethod.kt +++ b/app/src/main/java/ir/fanap/chattestapp/bussines/model/CallBackMethod.kt @@ -1,7 +1,8 @@ package ir.fanap.chattestapp.bussines.model -public class CallBackMethod { - var uniqueId: String? = null - var position: Int? = null + class CallBackMethod(var method: String, var position: Int) { +// var uniqueId: String? = null +// var method: String? = null +// var position: Int? = null } \ No newline at end of file diff --git a/app/src/main/java/ir/fanap/chattestapp/bussines/model/FunctionStatus.kt b/app/src/main/java/ir/fanap/chattestapp/bussines/model/FunctionStatus.kt new file mode 100644 index 0000000..8381ad6 --- /dev/null +++ b/app/src/main/java/ir/fanap/chattestapp/bussines/model/FunctionStatus.kt @@ -0,0 +1,7 @@ +package ir.fanap.chattestapp.bussines.model + +class FunctionStatus { + lateinit var errorLog: String + lateinit var methodName: String + lateinit var status: String +} \ No newline at end of file diff --git a/app/src/main/java/ir/fanap/chattestapp/bussines/model/Method.kt b/app/src/main/java/ir/fanap/chattestapp/bussines/model/Method.kt index 92bd4a8..025cd02 100644 --- a/app/src/main/java/ir/fanap/chattestapp/bussines/model/Method.kt +++ b/app/src/main/java/ir/fanap/chattestapp/bussines/model/Method.kt @@ -1,8 +1,9 @@ package ir.fanap.chattestapp.bussines.model -import android.widget.CheckBox +import com.github.javafaker.Bool -class Method() { + +class Method { lateinit var methodName: String var funcOne: String? = null @@ -18,11 +19,10 @@ class Method() { var log :String? = null - var response:Boolean? = null + var funcStatusList : MutableList? = null - var methodNameImage: Int? = null + var pending :Boolean = false - var desc: String? = null - lateinit var checkBox: CheckBox + var error :Boolean = false } \ No newline at end of file diff --git a/app/src/main/res/layout/bottom_sheet_log.xml b/app/src/main/res/layout/bottom_sheet_log.xml index aa813ff..7795994 100644 --- a/app/src/main/res/layout/bottom_sheet_log.xml +++ b/app/src/main/res/layout/bottom_sheet_log.xml @@ -4,45 +4,51 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/bottom_sheet_log" android:layout_width="match_parent" - android:background="@color/white" + android:background="@color/log_color" + android:fillViewport="true" app:layout_behavior="android.support.design.widget.BottomSheetBehavior" app:behavior_peekHeight="0dp" android:layout_height="match_parent"> - + + + + + + + + - + tools:text="this is first log"/> - - - - - - - - - - - - - - - - - - +