Skip to content

Commit b99fbd3

Browse files
committed
add in app report feature via API and add donate button
1 parent e195daf commit b99fbd3

File tree

9 files changed

+231
-19
lines changed

9 files changed

+231
-19
lines changed

app/src/main/java/com/addev/listaspam/MainActivity.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class MainActivity : AppCompatActivity(), CallLogAdapter.OnItemChangedListener {
5050
private const val GITHUB_USER = "adamff-dev"
5151
private const val GITHUB_REPO = "spam-call-blocker-app"
5252
private const val ABOUT_LINK = "https://github.com/$GITHUB_USER/$GITHUB_REPO"
53+
private const val DONATE_LINK = "https://buymeacoffee.com/rsiztb3"
54+
5355
}
5456

5557
override fun onCreate(savedInstanceState: Bundle?) {
@@ -85,6 +87,12 @@ class MainActivity : AppCompatActivity(), CallLogAdapter.OnItemChangedListener {
8587
true
8688
}
8789

90+
R.id.donate -> {
91+
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(DONATE_LINK))
92+
this.startActivity(intent)
93+
true
94+
}
95+
8896
R.id.test_number -> {
8997
showNumberInputDialog()
9098
true
@@ -119,7 +127,8 @@ class MainActivity : AppCompatActivity(), CallLogAdapter.OnItemChangedListener {
119127
if (getTellowsApiCountry(this) != null) return
120128

121129
val systemCountry = Locale.getDefault().country.lowercase()
122-
val supportedCountries = resources.getStringArray(R.array.entryvalues_region_preference).toSet()
130+
val supportedCountries =
131+
resources.getStringArray(R.array.entryvalues_region_preference).toSet()
123132

124133
val finalCountry = if (supportedCountries.contains(systemCountry)) systemCountry else "us"
125134
setTellowsApiCountry(this, finalCountry)

app/src/main/java/com/addev/listaspam/adapter/CallLogAdapter.kt

Lines changed: 128 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.addev.listaspam.adapter
22

33
import android.Manifest
4+
import android.app.AlertDialog
45
import android.content.ClipData
56
import android.content.ClipboardManager
67
import android.content.Context
@@ -13,18 +14,28 @@ import android.view.Gravity
1314
import android.view.LayoutInflater
1415
import android.view.View
1516
import android.view.ViewGroup
17+
import android.widget.EditText
1618
import android.widget.ImageButton
1719
import android.widget.PopupMenu
20+
import android.widget.ProgressBar
21+
import android.widget.RadioButton
1822
import android.widget.TextView
1923
import android.widget.Toast
2024
import androidx.core.content.ContextCompat
2125
import androidx.recyclerview.widget.RecyclerView
2226
import com.addev.listaspam.R
27+
import com.addev.listaspam.util.ApiUtils
2328
import com.addev.listaspam.util.CallLogEntry
2429
import com.addev.listaspam.util.addNumberToWhitelist
30+
import com.addev.listaspam.util.getListaSpamApiLang
31+
import com.addev.listaspam.util.getTellowsApiCountry
2532
import com.addev.listaspam.util.removeSpamNumber
2633
import com.addev.listaspam.util.removeWhitelistNumber
2734
import com.addev.listaspam.util.saveSpamNumber
35+
import kotlinx.coroutines.CoroutineScope
36+
import kotlinx.coroutines.Dispatchers
37+
import kotlinx.coroutines.launch
38+
import kotlinx.coroutines.withContext
2839
import java.text.SimpleDateFormat
2940
import java.util.Locale
3041

@@ -41,7 +52,8 @@ class CallLogAdapter(
4152

4253
companion object {
4354
const val GOOGLE_URL_TEMPLATE = "https://www.google.com/search?q=%s"
44-
const val REPORT_URL_TEMPLATE = "https://www.listaspam.com/busca.php?Telefono=%s#denuncia"
55+
const val LISTA_SPAM_URL_TEMPLATE = "https://www.listaspam.com/busca.php?Telefono=%s"
56+
const val UNKNOWN_PHONE_URL_TEMPLATE = "https://www.unknownphone.com/phone/%s"
4557
}
4658

4759
private val locale = Locale.getDefault()
@@ -162,8 +174,18 @@ class CallLogAdapter(
162174
true
163175
}
164176

165-
R.id.report_action -> {
166-
reportAction(number)
177+
R.id.open_report_alert -> {
178+
openReportAlert(number)
179+
true
180+
}
181+
182+
R.id.open_in_lista_spam_action -> {
183+
openInListaSpam(number)
184+
true
185+
}
186+
187+
R.id.open_in_unknown_phone_action -> {
188+
openInUnknownPhone(number)
167189
true
168190
}
169191

@@ -254,8 +276,14 @@ class CallLogAdapter(
254276
).show()
255277
}
256278

257-
private fun reportAction(number: String) {
258-
val url = String.format(REPORT_URL_TEMPLATE, number)
279+
private fun openInListaSpam(number: String) {
280+
val url = String.format(LISTA_SPAM_URL_TEMPLATE, number)
281+
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
282+
context.startActivity(intent)
283+
}
284+
285+
private fun openInUnknownPhone(number: String) {
286+
val url = String.format(UNKNOWN_PHONE_URL_TEMPLATE, number)
259287
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
260288
context.startActivity(intent)
261289
}
@@ -269,4 +297,99 @@ class CallLogAdapter(
269297
fun setOnItemChangedListener(listener: OnItemChangedListener) {
270298
this.onItemChangedListener = listener
271299
}
300+
301+
private fun openReportAlert(number: String) {
302+
val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_report, null)
303+
val messageEditText = dialogView.findViewById<EditText>(R.id.messageEditText)
304+
val spamRadio = dialogView.findViewById<RadioButton>(R.id.radioSpam)
305+
val noSpamRadio = dialogView.findViewById<RadioButton>(R.id.radioNoSpam)
306+
307+
messageEditText.hint = context.getString(R.string.report_hint)
308+
spamRadio.text = context.getString(R.string.report_spam)
309+
noSpamRadio.text = context.getString(R.string.report_not_spam)
310+
311+
AlertDialog.Builder(context)
312+
.setTitle(context.getString(R.string.report_title))
313+
.setView(dialogView)
314+
.setPositiveButton(context.getString(R.string.accept), null)
315+
.setNegativeButton(context.getString(R.string.cancel), null)
316+
.create()
317+
.also { alertDialog ->
318+
alertDialog.setOnShowListener {
319+
val button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE)
320+
button.setOnClickListener {
321+
val message = messageEditText.text.toString().trim()
322+
val wordCount = message.split("\\s+".toRegex()).size
323+
val charCount = message.replace("\\s".toRegex(), "").length
324+
325+
if (wordCount < 2 || charCount < 10) {
326+
messageEditText.error =
327+
context.getString(R.string.report_validation_message)
328+
return@setOnClickListener
329+
}
330+
331+
if (!spamRadio.isChecked && !noSpamRadio.isChecked) {
332+
Toast.makeText(
333+
context,
334+
context.getString(R.string.report_radio_validation),
335+
Toast.LENGTH_SHORT
336+
).show()
337+
return@setOnClickListener
338+
}
339+
340+
val progressBar = dialogView.findViewById<ProgressBar>(R.id.progressBar)
341+
progressBar.visibility = View.VISIBLE
342+
button.isEnabled = false // Disable button to prevent duplicate submissions
343+
344+
// Launch background work
345+
CoroutineScope(Dispatchers.IO).launch {
346+
val reportedTo = mutableListOf<String>()
347+
348+
getListaSpamApiLang(context)?.let {
349+
if (ApiUtils.reportToUnknownPhone(
350+
number,
351+
message,
352+
spamRadio.isChecked,
353+
it
354+
)
355+
) {
356+
reportedTo.add("UnknownPhone")
357+
}
358+
}
359+
360+
getTellowsApiCountry(context)?.let {
361+
if (ApiUtils.reportToTellows(
362+
number,
363+
message,
364+
spamRadio.isChecked,
365+
it
366+
)
367+
) {
368+
reportedTo.add("Tellows")
369+
}
370+
}
371+
372+
val reportMessage = if (reportedTo.isNotEmpty()) {
373+
context.getString(R.string.report_success_prefix) + " " + reportedTo.joinToString(
374+
context.getString(R.string.report_title)
375+
)
376+
} else {
377+
context.getString(R.string.report_failure)
378+
}
379+
380+
// Switch to main thread to show Toast and dismiss dialog
381+
withContext(Dispatchers.Main) {
382+
progressBar.visibility = View.GONE
383+
button.isEnabled = true
384+
Toast.makeText(context, reportMessage, Toast.LENGTH_SHORT).show()
385+
alertDialog.dismiss()
386+
}
387+
}
388+
}
389+
}
390+
}
391+
.show()
392+
}
393+
394+
272395
}

app/src/main/java/com/addev/listaspam/util/ApiUtils.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.addev.listaspam.util
22

3-
import android.util.Log
43
import okhttp3.FormBody
54
import okhttp3.HttpUrl
65
import okhttp3.OkHttpClient

app/src/main/res/layout/activity_settings.xml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

3-
<LinearLayout
4-
xmlns:android="http://schemas.android.com/apk/res/android"
3+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
54
android:layout_width="match_parent"
65
android:layout_height="match_parent"
76
android:orientation="vertical">
87

98
<LinearLayout
109
android:layout_width="match_parent"
1110
android:layout_height="wrap_content"
12-
android:orientation="vertical"
13-
android:layout_margin="16dp">
11+
android:layout_margin="16dp"
12+
android:orientation="vertical">
1413

1514
<Button
1615
android:id="@+id/btn_export"
1716
android:layout_width="match_parent"
1817
android:layout_height="wrap_content"
19-
android:text="@string/export_config"
18+
android:drawablePadding="8dp"
2019
android:icon="@drawable/ic_export"
21-
android:drawablePadding="8dp" />
20+
android:text="@string/export_config" />
2221

2322
<Button
2423
android:id="@+id/btn_import"
2524
android:layout_width="match_parent"
2625
android:layout_height="wrap_content"
27-
android:text="@string/import_config"
2826
android:layout_marginTop="16dp"
27+
android:drawablePadding="8dp"
2928
android:icon="@drawable/ic_import"
30-
android:drawablePadding="8dp" />
29+
android:text="@string/import_config" />
3130
</LinearLayout>
3231

3332
<FrameLayout
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="wrap_content"
5+
android:orientation="vertical"
6+
android:padding="20dp">
7+
8+
<EditText
9+
android:id="@+id/messageEditText"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:hint="@string/report_hint"
13+
android:inputType="textMultiLine"
14+
android:minLines="3" />
15+
16+
<RadioGroup
17+
android:id="@+id/radioGroup"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:layout_marginTop="16dp"
21+
android:orientation="horizontal">
22+
23+
<RadioButton
24+
android:id="@+id/radioSpam"
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:text="@string/report_spam" />
28+
29+
<RadioButton
30+
android:id="@+id/radioNoSpam"
31+
android:layout_width="wrap_content"
32+
android:layout_height="wrap_content"
33+
android:text="@string/report_not_spam" />
34+
</RadioGroup>
35+
36+
<ProgressBar
37+
android:id="@+id/progressBar"
38+
style="?android:attr/progressBarStyleLarge"
39+
android:layout_width="wrap_content"
40+
android:layout_height="wrap_content"
41+
android:layout_gravity="center"
42+
android:visibility="gone" />
43+
</LinearLayout>

app/src/main/res/menu/item_actions.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
android:id="@+id/search_action"
55
android:title="@string/search_in_google" />
66
<item
7-
android:id="@+id/report_action"
8-
android:title="@string/report_in_listaspam_com" />
7+
android:id="@+id/open_report_alert"
8+
android:title="@string/report_title" />
9+
<item
10+
android:id="@+id/open_in_lista_spam_action"
11+
android:title="@string/open_in_lista_spam_com" />
12+
<item
13+
android:id="@+id/open_in_unknown_phone_action"
14+
android:title="@string/open_in_unknown_phone_com" />
915
<item
1016
android:id="@+id/block_action"
1117
android:title="@string/block" />

app/src/main/res/menu/menu.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
<item
77
android:id="@+id/action_about"
88
android:title="@string/about" />
9+
<item
10+
android:id="@+id/donate"
11+
android:title="@string/donate" />
912
<item
1013
android:id="@+id/test_number"
1114
android:title="@string/test_number" />

app/src/main/res/values-es/strings.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<!-- Preferences -->
3232
<string name="action_settings">Ajustes</string>
3333
<string name="about">Acerca de</string>
34+
<string name="donate">Hacer donación</string>
3435

3536
<!-- Preferences Sections -->
3637
<string name="pref_category_general_blocking">General</string>
@@ -81,7 +82,8 @@
8182
<string name="pref_show_notification_summary">Mostrar una notificación cuando se bloquee una llamada</string>
8283

8384
<!-- Call item actions -->
84-
<string name="report_in_listaspam_com">Reportar en ListaSpam</string>
85+
<string name="open_in_lista_spam_com">Abrir en ListaSpam</string>
86+
<string name="open_in_unknown_phone_com">Abrir en UnknownPhone</string>
8587
<string name="search_in_google">Buscar en Google</string>
8688
<string name="block">Bloquear</string>
8789
<string name="add_to_whitelist">Añadir a lista blanca</string>
@@ -107,4 +109,17 @@
107109
<!-- Updates -->
108110
<string name="update_available_title">Actualización disponible</string>
109111
<string name="update_available_message">Hay una nueva versión: %1$s\n¿Quiere descargarla ahora?</string>
112+
113+
<!-- Reports -->
114+
<string name="report_title">Reportar número</string>
115+
<string name="report_hint">Describe el motivo</string>
116+
<string name="report_spam">Es spam</string>
117+
<string name="report_not_spam">NO es spam</string>
118+
<string name="accept">Enviar</string>
119+
<string name="cancel">Cancelar</string>
120+
<string name="report_validation_message">Debe contener al menos 2 palabras y 5 letras.</string>
121+
<string name="report_radio_validation">Selecciona si es spam o no.</string>
122+
<string name="report_success_prefix">Reporte enviado a</string>
123+
<string name="and">y</string>
124+
<string name="report_failure">No se pudo enviar el reporte</string>
110125
</resources>

0 commit comments

Comments
 (0)