package com.dmc.callcrm.ui import android.content.Intent import android.os.Bundle import android.provider.Settings import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.core.app.NotificationManagerCompat import com.dmc.callcrm.R /** * Shows whether "Notification access" is granted (required for * WhatsAppCallListenerService to detect calls) and deep-links to the * one settings screen that can actually grant it — this permission has no * normal runtime-prompt equivalent. */ class WhatsAppCallSetupActivity : AppCompatActivity() { private lateinit var statusText: TextView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_whatsapp_call_setup) statusText = findViewById(R.id.statusText) findViewById(R.id.btnOpenSettings).setOnClickListener { startActivity(Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)) } } override fun onResume() { super.onResume() refreshStatus() } private fun refreshStatus() { val enabled = NotificationManagerCompat.getEnabledListenerPackages(this).contains(packageName) if (enabled) { statusText.setBackgroundColor(0xFFDCFCE7.toInt()) statusText.setTextColor(0xFF166534.toInt()) statusText.text = "✅ Notification access is granted — WhatsApp calls will be logged." } else { statusText.setBackgroundColor(0xFFFEE2E2.toInt()) statusText.setTextColor(0xFF991B1B.toInt()) statusText.text = "⚠ Notification access is NOT granted yet. Tap below to enable it, then find \"DMC Call CRM\" in the list and turn it on." } } }