Skip to content
Merged

Dev #299

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
Empty file.
10 changes: 10 additions & 0 deletions app/src/main/java/com/afkanerd/deku/DefaultSMS/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.afkanerd.deku.DefaultSMS

import android.Manifest
import android.annotation.SuppressLint
import android.app.Activity
import android.app.ComponentCaller
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.os.ParcelFileDescriptor
import android.provider.Telephony
import android.text.Layout
import android.util.Log
import android.widget.Toast
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
Expand Down Expand Up @@ -64,6 +67,7 @@ import java.io.InputStreamReader
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.input.key.type
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.style.LineHeightStyle
Expand Down Expand Up @@ -107,6 +111,12 @@ class MainActivity : AppCompatActivity(){
}
}

override fun onNewIntent(intent: Intent, caller: ComponentCaller) {
super.onNewIntent(intent, caller)
this.intent = intent
navController.navigate(HomeScreen)
}

private fun checkLoadNatives() {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
if(sharedPreferences.getBoolean(getString(R.string.configs_load_natives), false)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.provider.BlockedNumberContract
import android.provider.ContactsContract
import android.provider.Telephony
import android.text.InputType
import android.util.Log
import android.widget.Toast
import androidx.activity.compose.BackHandler
import androidx.activity.result.contract.ActivityResultContracts
Expand Down Expand Up @@ -213,21 +214,34 @@ fun processIntents(
): Triple<String?, String?, String?>?{
if(intent.action != null &&
((intent.action == Intent.ACTION_SENDTO) || (intent.action == Intent.ACTION_SEND))) {
val text = if(intent.hasExtra("sms_body")) intent.getStringExtra("sms_body")
else if(intent.hasExtra("android.intent.extra.TEXT")) {
intent.getStringExtra("android.intent.extra.TEXT")
} else ""

val sendToString = intent.dataString
val text = if(intent.hasExtra("sms_body")) intent.getStringExtra("sms_body") else ""
if (sendToString != null &&
(sendToString.contains("smsto:") || sendToString.contains("sms:"))

if ((
sendToString != null &&
(sendToString.contains("smsto:") ||
sendToString.contains("sms:"))) ||
intent.hasExtra("address")
) {
val address = Helpers.getFormatCompleteNumber(sendToString, defaultRegion)

val address = Helpers.getFormatCompleteNumber(
if(intent.hasExtra("address")) intent.getStringExtra("address")
else sendToString, defaultRegion)

val threadId =
ThreadedConversationsHandler.get(context, address)
.thread_id

return Triple(address, threadId, text)
}
}
else if(intent.hasExtra("address")) {
var text = ""
var text = if(intent.hasExtra("android.intent.extra.TEXT"))
intent.getStringExtra("android.intent.extra.TEXT") else ""

val address = intent.getStringExtra("address")
val threadId = intent.getStringExtra("thread_id")
return Triple(address, threadId, text)
Expand Down Expand Up @@ -510,12 +524,14 @@ fun ThreadConversationLayout(
val context = LocalContext.current

intent?.let {
// conversationsViewModel.text = ""
val defaultRegion = if(inPreviewMode) "cm" else Helpers.getUserCountry(context)
processIntents(context, intent, defaultRegion)?.let {
intent.apply {
removeExtra("address")
removeExtra("thread_id")
removeExtra("sms_body")
removeExtra("android.intent.extra.TEXT")
data = null
}
it.first?.let{ address ->
Expand All @@ -534,7 +550,6 @@ fun ThreadConversationLayout(
}
}
}
conversationsViewModel.text = ""

val counts by conversationsViewModel.getCount(context).observeAsState(null)

Expand Down