Skip to content

Commit

Permalink
[messages] more straightforward starting/stopping of Send worker
Browse files Browse the repository at this point in the history
  • Loading branch information
capcom6 committed Feb 29, 2024
1 parent 5319679 commit 6e5c0b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ class MessagesService(
private val countryCode: String? =
(context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager).networkCountryIso

init {
fun start() {
SendMessagesWorker.start(context)
}

fun stop() {
SendMessagesWorker.stop(context)
}

fun enqueueMessage(request: SendRequest) {
if (getMessage(request.message.id) != null) {
Log.d(this.javaClass.name, "Message already exists: ${request.message.id}")
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/me/capcom/smsgateway/ui/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import me.capcom.smsgateway.databinding.FragmentSettingsBinding
import me.capcom.smsgateway.helpers.SettingsHelper
import me.capcom.smsgateway.modules.gateway.events.DeviceRegisteredEvent
import me.capcom.smsgateway.modules.localserver.events.IPReceivedEvent
import me.capcom.smsgateway.modules.messages.MessagesService
import org.koin.android.ext.android.inject

class HomeFragment : Fragment() {
Expand All @@ -40,6 +41,7 @@ class HomeFragment : Fragment() {
private val binding get() = _binding!!

private val settingsHelper: SettingsHelper by inject()
private val messagesSvc: MessagesService by inject()

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
Expand Down Expand Up @@ -177,10 +179,12 @@ class HomeFragment : Fragment() {
} else {
App.instance.localServerModule.stop(requireContext())
App.instance.gatewayModule.stop(requireContext())
messagesSvc.stop()
}
}

private fun start() {
messagesSvc.start()
App.instance.gatewayModule.start(requireContext())
App.instance.localServerModule.start(requireContext())
}
Expand Down

0 comments on commit 6e5c0b4

Please sign in to comment.