|
@@ -9,18 +9,17 @@ import android.app.role.RoleManager
|
|
|
import android.content.ContentValues
|
|
|
import android.content.Intent
|
|
|
import android.os.Build
|
|
|
-import android.os.Bundle
|
|
|
import android.provider.Telephony
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
-import androidx.fragment.app.Fragment
|
|
|
import androidx.lifecycle.ViewModelProvider
|
|
|
import com.blankj.utilcode.util.AppUtils
|
|
|
import com.blankj.utilcode.util.PermissionUtils
|
|
|
import com.blankj.utilcode.util.TimeUtils
|
|
|
import com.blankj.utilcode.util.ToastUtils
|
|
|
+import com.hx.utils.application.base.BaseFragment
|
|
|
import com.hx.utils.application.databinding.FragmentSmsBinding
|
|
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
@@ -29,25 +28,17 @@ import kotlinx.coroutines.delay
|
|
|
import kotlinx.coroutines.launch
|
|
|
import java.util.Calendar
|
|
|
|
|
|
-class SmsFragment : Fragment() {
|
|
|
- private var _binding: FragmentSmsBinding? = null
|
|
|
- private val binding get() = _binding!!
|
|
|
- private lateinit var smsViewModel: SmsViewModel
|
|
|
-
|
|
|
- override fun onCreateView(
|
|
|
- inflater: LayoutInflater,
|
|
|
- container: ViewGroup?,
|
|
|
- savedInstanceState: Bundle?
|
|
|
- ): View {
|
|
|
- _binding = FragmentSmsBinding.inflate(inflater, container, false)
|
|
|
- val root: View = binding.root
|
|
|
- smsViewModel = ViewModelProvider(this)[SmsViewModel::class.java]
|
|
|
- binding.loading.visibility = View.GONE
|
|
|
+class SmsFragment : BaseFragment<FragmentSmsBinding, SmsViewModel>() {
|
|
|
+
|
|
|
+ override fun setupViewModel() {
|
|
|
+ viewModel = ViewModelProvider(this)[SmsViewModel::class.java]
|
|
|
+ }
|
|
|
|
|
|
- smsViewModel.showTime.observe(viewLifecycleOwner) {
|
|
|
+ override fun setupView() {
|
|
|
+ binding.loading.visibility = View.GONE
|
|
|
+ viewModel.showTime.observe(viewLifecycleOwner) {
|
|
|
binding.time.setText(it)
|
|
|
}
|
|
|
-
|
|
|
binding.insertMms.setOnClickListener {
|
|
|
val smsPackageName = Telephony.Sms.getDefaultSmsPackage(context)
|
|
|
val currentPackageName = context?.packageName
|
|
@@ -99,22 +90,22 @@ class SmsFragment : Fragment() {
|
|
|
}
|
|
|
|
|
|
binding.radioGroup.setOnCheckedChangeListener { _, checkedId ->
|
|
|
- smsViewModel.read.value = binding.radioButton1.id == checkedId
|
|
|
+ viewModel.read.value = binding.radioButton1.id == checkedId
|
|
|
}
|
|
|
|
|
|
(activity as? AppCompatActivity)?.supportActionBar?.title = arguments?.getString("data")
|
|
|
- return root
|
|
|
}
|
|
|
|
|
|
+ override fun setupBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentSmsBinding {
|
|
|
+ return FragmentSmsBinding.inflate(inflater, container, false)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
override fun onStart() {
|
|
|
super.onStart()
|
|
|
getPermissions()
|
|
|
}
|
|
|
|
|
|
- override fun onDestroyView() {
|
|
|
- super.onDestroyView()
|
|
|
- _binding = null
|
|
|
- }
|
|
|
|
|
|
fun getPermissions() {
|
|
|
val permissions = listOf(SEND_SMS, RECEIVE_SMS, READ_SMS).toTypedArray()
|
|
@@ -144,9 +135,9 @@ class SmsFragment : Fragment() {
|
|
|
try {
|
|
|
val values = ContentValues().apply {
|
|
|
put(Telephony.Sms.ADDRESS, binding.name.text.toString())
|
|
|
- put(Telephony.Sms.DATE, smsViewModel.time.value)
|
|
|
- put(Telephony.Sms.DATE_SENT, smsViewModel.time.value?.minus(5000))
|
|
|
- put(Telephony.Sms.READ, smsViewModel.read.value)
|
|
|
+ put(Telephony.Sms.DATE, viewModel.time.value)
|
|
|
+ put(Telephony.Sms.DATE_SENT, viewModel.time.value?.minus(5000))
|
|
|
+ put(Telephony.Sms.READ, viewModel.read.value)
|
|
|
put(Telephony.Sms.TYPE, 1)
|
|
|
put(Telephony.Sms.BODY, binding.message.text.toString())
|
|
|
put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_INBOX)
|
|
@@ -155,8 +146,8 @@ class SmsFragment : Fragment() {
|
|
|
|
|
|
binding.name.text.clear()
|
|
|
binding.message.text.clear()
|
|
|
- smsViewModel.time.postValue(0)
|
|
|
- smsViewModel.showTime.postValue("")
|
|
|
+ viewModel.time.postValue(0)
|
|
|
+ viewModel.showTime.postValue("")
|
|
|
|
|
|
} catch (e: Exception) {
|
|
|
e.message?.let {
|
|
@@ -196,8 +187,8 @@ class SmsFragment : Fragment() {
|
|
|
}
|
|
|
|
|
|
private fun handleSelectedTimestamp(timestamp: Long, showTxt: String) {
|
|
|
- smsViewModel.time.postValue(timestamp)
|
|
|
- smsViewModel.showTime.postValue(showTxt)
|
|
|
+ viewModel.time.postValue(timestamp)
|
|
|
+ viewModel.showTime.postValue(showTxt)
|
|
|
|
|
|
|
|
|
}
|