Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is/feature/kotlin version update #345

Merged
merged 6 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'com.google.gms.google-services'

id 'com.google.dagger.hilt.android'
}

def localProperties = new Properties()
Expand Down Expand Up @@ -169,7 +167,7 @@ dependencies {

testImplementation "org.slf4j:slf4j-nop:1.7.36"

testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:1.9.10"


// Testing - Instrumentation
Expand Down
114 changes: 70 additions & 44 deletions app/src/main/java/com/telnyx/webrtc/sdk/ui/CallInstanceFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import android.media.ToneGenerator
import android.media.ToneGenerator.*
import android.os.Bundle
import android.os.SystemClock
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.davidmiguel.numberkeyboard.NumberKeyboard
import com.davidmiguel.numberkeyboard.NumberKeyboardListener
import com.telnyx.webrtc.sdk.R
import com.telnyx.webrtc.sdk.databinding.FragmentCallInstanceBinding
import com.telnyx.webrtc.sdk.model.SocketMethod
import com.telnyx.webrtc.sdk.verto.receive.*
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_call_instance.*
import java.util.*


Expand All @@ -32,11 +33,24 @@ lateinit var mainViewModel: MainViewModel
* Use the [CallInstanceFragment.newInstance] factory method to
* create an instance of this fragment.
*/
class CallInstanceFragment : Fragment(R.layout.fragment_call_instance), NumberKeyboardListener {
class CallInstanceFragment : Fragment(), NumberKeyboardListener {
private var callId: UUID? = null
private var _binding: FragmentCallInstanceBinding? = null

private val binding get() = _binding!!

private val toneGenerator = ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100)

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentCallInstanceBinding.inflate(inflater, container, false)
val view = binding.root
return view
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
arguments?.let {
Expand All @@ -53,63 +67,75 @@ class CallInstanceFragment : Fragment(R.layout.fragment_call_instance), NumberKe
private fun setUpOngoingCallButtons() {

//Handle call option observers
mainViewModel.getCallState()?.observe(this.viewLifecycleOwner, { value ->
requireActivity().call_state_text_value.text = value.name
})
mainViewModel.getIsMuteStatus()?.observe(this.viewLifecycleOwner, { value ->
if (!value) {
mute_button_id.setImageResource(R.drawable.ic_mic_off)
} else {
mute_button_id.setImageResource(R.drawable.ic_mic)
mainViewModel.getCallState()?.observe(this.viewLifecycleOwner) { value ->
(requireActivity() as MainActivity).callStateTextValue?.text = value.name
}
mainViewModel.getIsMuteStatus()?.observe(this.viewLifecycleOwner) { value ->
binding.apply {
if (!value) {
muteButtonId.setImageResource(R.drawable.ic_mic_off)
} else {
muteButtonId.setImageResource(R.drawable.ic_mic)
}
}
})
}

mainViewModel.getIsOnHoldStatus()?.observe(this.viewLifecycleOwner, { value ->
if (!value) {
hold_button_id.setImageResource(R.drawable.ic_hold)
} else {
hold_button_id.setImageResource(R.drawable.ic_play)
mainViewModel.getIsOnHoldStatus()?.observe(this.viewLifecycleOwner) { value ->
binding.apply {
if (!value) {
holdButtonId.setImageResource(R.drawable.ic_hold)
} else {
holdButtonId.setImageResource(R.drawable.ic_play)
}
}
})
}

mainViewModel.getIsOnLoudSpeakerStatus()?.observe(this.viewLifecycleOwner, { value ->
if (!value) {
loud_speaker_button_id.setImageResource(R.drawable.ic_loud_speaker_off)
} else {
loud_speaker_button_id.setImageResource(R.drawable.ic_loud_speaker)
mainViewModel.getIsOnLoudSpeakerStatus()?.observe(this.viewLifecycleOwner) { value ->
binding.apply {
if (!value) {
loudSpeakerButtonId.setImageResource(R.drawable.ic_loud_speaker_off)
} else {
loudSpeakerButtonId.setImageResource(R.drawable.ic_loud_speaker)
}
}
})
}

onTimerStart()

end_call_id.setOnClickListener {
onEndCall()
}
mute_button_id.setOnClickListener {
mainViewModel.onMuteUnmutePressed()
}
hold_button_id.setOnClickListener {
mainViewModel.onHoldUnholdPressed(callId!!)
}
loud_speaker_button_id.setOnClickListener {
mainViewModel.onLoudSpeakerPressed()
}
dial_pad_button_id.setOnClickListener {
dialpad_section_id.visibility = View.VISIBLE
val numberKeyboard = view?.findViewById<NumberKeyboard>(R.id.dialpad_id)
numberKeyboard?.setListener(this)
binding.apply {
endCallId.setOnClickListener {
onEndCall()
}
muteButtonId.setOnClickListener {
mainViewModel.onMuteUnmutePressed()
}
holdButtonId.setOnClickListener {
mainViewModel.onHoldUnholdPressed(callId!!)
}
loudSpeakerButtonId.setOnClickListener {
mainViewModel.onLoudSpeakerPressed()
}
dialPadButtonId.setOnClickListener {
dialpadSectionId.root.visibility = View.VISIBLE
val numberKeyboard = view?.findViewById<NumberKeyboard>(R.id.dialpad_id)
numberKeyboard?.setListener(this@CallInstanceFragment)
}
}


}

private fun onEndCall() {
mainViewModel.endCall(callId!!)
call_timer_id.stop()
binding.callTimerId.stop()
parentFragmentManager.beginTransaction().remove(this@CallInstanceFragment).commit();
}

private fun onTimerStart() {
call_timer_id.base = SystemClock.elapsedRealtime()
call_timer_id.start()
binding.apply {
callTimerId.base = SystemClock.elapsedRealtime()
callTimerId.start()
}
}

private fun observeSocketResponses() {
Expand Down Expand Up @@ -204,6 +230,6 @@ class CallInstanceFragment : Fragment(R.layout.fragment_call_instance), NumberKe
}

override fun onRightAuxButtonClicked() {
dialpad_section_id.visibility = View.INVISIBLE
binding.dialpadSectionId.root.visibility = View.INVISIBLE
}
}
Loading
Loading