@@ -9,7 +9,6 @@ import android.content.pm.PackageManager
9
9
import android.net.Uri
10
10
import android.provider.CallLog
11
11
import android.provider.ContactsContract
12
- import android.util.TypedValue
13
12
import android.view.Gravity
14
13
import android.view.LayoutInflater
15
14
import android.view.View
@@ -22,12 +21,12 @@ import androidx.core.content.ContextCompat
22
21
import androidx.recyclerview.widget.RecyclerView
23
22
import com.addev.listaspam.R
24
23
import com.addev.listaspam.util.CallLogEntry
25
- import com.addev.listaspam.util.SpamUtils
26
24
import com.addev.listaspam.util.addNumberToWhitelist
27
25
import com.addev.listaspam.util.removeSpamNumber
28
26
import com.addev.listaspam.util.removeWhitelistNumber
29
27
import com.addev.listaspam.util.saveSpamNumber
30
28
import java.text.SimpleDateFormat
29
+ import java.util.Locale
31
30
32
31
class CallLogAdapter (
33
32
private val context : Context ,
@@ -41,12 +40,18 @@ class CallLogAdapter(
41
40
}
42
41
43
42
companion object {
44
- // URLs
45
43
const val GOOGLE_URL_TEMPLATE = " https://www.google.com/search?q=%s"
46
44
const val REPORT_URL_TEMPLATE = " https://www.listaspam.com/busca.php?Telefono=%s#denuncia"
47
45
}
48
46
49
- private val formatter = SimpleDateFormat (" dd/MM/yyyy HH:mm:ss" )
47
+ private val locale = Locale .getDefault()
48
+
49
+ private val formatter: SimpleDateFormat = if (locale.language == " en" ) {
50
+ SimpleDateFormat (" MM/dd/yyyy hh:mm:ss a" , locale)
51
+ } else {
52
+ SimpleDateFormat (" dd/MM/yyyy HH:mm:ss" , locale)
53
+ }
54
+
50
55
private var onItemChangedListener: OnItemChangedListener ? = null
51
56
52
57
override fun onCreateViewHolder (parent : ViewGroup , viewType : Int ): CallLogViewHolder {
@@ -56,7 +61,11 @@ class CallLogAdapter(
56
61
57
62
override fun onBindViewHolder (holder : CallLogViewHolder , position : Int ) {
58
63
val callLog = callLogs[position]
59
- holder.bind(callLog, blockedNumbers.contains(callLog.number), whitelistNumbers.contains(callLog.number))
64
+ holder.bind(
65
+ callLog,
66
+ blockedNumbers.contains(callLog.number),
67
+ whitelistNumbers.contains(callLog.number)
68
+ )
60
69
}
61
70
62
71
override fun getItemCount (): Int = callLogs.size
@@ -93,14 +102,36 @@ class CallLogAdapter(
93
102
actionTextView.text = action
94
103
95
104
if (callLog.type == CallLog .Calls .BLOCKED_TYPE ) {
96
- actionTextView.setTextColor(ContextCompat .getColor(context, android.R .color.holo_red_light))
105
+ actionTextView.setTextColor(
106
+ ContextCompat .getColor(
107
+ context,
108
+ android.R .color.holo_red_light
109
+ )
110
+ )
97
111
} else {
98
- actionTextView.setTextColor(ContextCompat .getColor(context, android.R .color.darker_gray))
112
+ actionTextView.setTextColor(
113
+ ContextCompat .getColor(
114
+ context,
115
+ android.R .color.darker_gray
116
+ )
117
+ )
99
118
}
100
119
101
120
when {
102
- isBlocked -> numberTextView.setTextColor(ContextCompat .getColor(context, android.R .color.holo_red_light))
103
- isWhitelisted -> numberTextView.setTextColor(ContextCompat .getColor(context, android.R .color.holo_blue_dark))
121
+ isBlocked -> numberTextView.setTextColor(
122
+ ContextCompat .getColor(
123
+ context,
124
+ android.R .color.holo_red_light
125
+ )
126
+ )
127
+
128
+ isWhitelisted -> numberTextView.setTextColor(
129
+ ContextCompat .getColor(
130
+ context,
131
+ android.R .color.holo_blue_dark
132
+ )
133
+ )
134
+
104
135
else -> {
105
136
numberTextView.setTextColor(ContextCompat .getColor(context, R .color.textColor))
106
137
}
@@ -110,10 +141,16 @@ class CallLogAdapter(
110
141
overflowMenuButton.visibility = View .GONE
111
142
return
112
143
}
113
-
144
+
114
145
overflowMenuButton.visibility = View .VISIBLE
115
146
overflowMenuButton.setOnClickListener {
116
- val popupMenu = PopupMenu (itemView.context, overflowMenuButton, Gravity .NO_GRAVITY , android.R .attr.popupMenuStyle, R .style.PopupMenuStyle )
147
+ val popupMenu = PopupMenu (
148
+ itemView.context,
149
+ overflowMenuButton,
150
+ Gravity .NO_GRAVITY ,
151
+ android.R .attr.popupMenuStyle,
152
+ R .style.PopupMenuStyle
153
+ )
117
154
popupMenu.inflate(R .menu.item_actions)
118
155
119
156
setDynamicTitles(popupMenu, isBlocked, isWhitelisted)
@@ -124,10 +161,12 @@ class CallLogAdapter(
124
161
searchAction(number)
125
162
true
126
163
}
164
+
127
165
R .id.report_action -> {
128
166
reportAction(number)
129
167
true
130
168
}
169
+
131
170
R .id.whitelist_action -> {
132
171
if (isWhitelisted) {
133
172
removeWhitelistNumber(context, number)
@@ -137,6 +176,7 @@ class CallLogAdapter(
137
176
onItemChangedListener?.onItemChanged(number)
138
177
true
139
178
}
179
+
140
180
R .id.block_action -> {
141
181
if (isBlocked) {
142
182
removeSpamNumber(context, number)
@@ -146,6 +186,7 @@ class CallLogAdapter(
146
186
onItemChangedListener?.onItemChanged(number)
147
187
true
148
188
}
189
+
149
190
else -> false
150
191
}
151
192
}
@@ -181,9 +222,15 @@ class CallLogAdapter(
181
222
}
182
223
183
224
private fun getContactName (context : Context , phoneNumber : String ): String? {
184
- if (ContextCompat .checkSelfPermission(context, Manifest .permission.READ_CONTACTS ) == PackageManager .PERMISSION_GRANTED ) {
225
+ if (ContextCompat .checkSelfPermission(
226
+ context,
227
+ Manifest .permission.READ_CONTACTS
228
+ ) == PackageManager .PERMISSION_GRANTED
229
+ ) {
185
230
val contentResolver = context.contentResolver
186
- val uri = ContactsContract .PhoneLookup .CONTENT_FILTER_URI .buildUpon().appendPath(phoneNumber).build()
231
+ val uri =
232
+ ContactsContract .PhoneLookup .CONTENT_FILTER_URI .buildUpon().appendPath(phoneNumber)
233
+ .build()
187
234
val projection = arrayOf(ContactsContract .PhoneLookup .DISPLAY_NAME )
188
235
189
236
contentResolver.query(uri, projection, null , null , null )?.use { cursor ->
0 commit comments