|
29 | 29 | import android.util.Log; |
30 | 30 | import android.util.SparseBooleanArray; |
31 | 31 | import android.view.Gravity; |
| 32 | +import android.view.LayoutInflater; |
32 | 33 | import android.view.View; |
33 | 34 | import android.view.ViewGroup; |
| 35 | +import android.view.inputmethod.EditorInfo; |
34 | 36 | import android.widget.Button; |
| 37 | +import android.widget.EditText; |
35 | 38 | import android.widget.LinearLayout; |
36 | 39 | import android.widget.ScrollView; |
37 | 40 | import android.widget.TextView; |
|
40 | 43 | import com.google.android.material.bottomsheet.BottomSheetDialog; |
41 | 44 | import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
42 | 45 | import com.google.android.material.progressindicator.LinearProgressIndicator; |
| 46 | +import com.google.android.material.textfield.TextInputLayout; |
43 | 47 |
|
44 | 48 | import java.io.File; |
45 | 49 | import java.util.ArrayList; |
@@ -287,9 +291,100 @@ private void startSending(ArrayList<Integer> itemIndices) { |
287 | 291 | messages.add(new Message(phoneNumber, content)); |
288 | 292 | } |
289 | 293 |
|
290 | | - MessageService.startSending(this, messages, DataModel.getSubId(), SettingManager.getDelay(), SettingManager.isRandomizeDelay()); |
291 | | - showProgressDialog(); |
| 294 | + // Start sensitive word check process |
| 295 | + checkAndSendMessages(messages, 0); |
292 | 296 | } |
| 297 | + |
| 298 | + /** |
| 299 | + * Recursively check messages for sensitive words and prompt user for action if found. |
| 300 | + * @param messages The list of messages to send |
| 301 | + * @param index The current index being checked |
| 302 | + */ |
| 303 | + private void checkAndSendMessages(List<Message> messages, int index) { |
| 304 | + // Skip already-null (skipped) messages |
| 305 | + while (index < messages.size() && messages.get(index) == null) { |
| 306 | + index++; |
| 307 | + } |
| 308 | + |
| 309 | + if (index >= messages.size()) { |
| 310 | + // All messages checked, filter out nulls and send |
| 311 | + List<Message> validMessages = new ArrayList<>(); |
| 312 | + for (Message m : messages) { |
| 313 | + if (m != null) { |
| 314 | + validMessages.add(m); |
| 315 | + } |
| 316 | + } |
| 317 | + if (validMessages.isEmpty()) { |
| 318 | + ToastUtil.show(this, R.string.sending_completed); |
| 319 | + return; |
| 320 | + } |
| 321 | + MessageService.startSending(this, validMessages, DataModel.getSubId(), SettingManager.getDelay(), SettingManager.isRandomizeDelay()); |
| 322 | + showProgressDialog(); |
| 323 | + return; |
| 324 | + } |
| 325 | + |
| 326 | + Message message = messages.get(index); |
| 327 | + List<String> sensitiveWords = top.yztz.msggo.util.SensitiveWordUtil.findAll(message.getContent()); |
| 328 | + |
| 329 | + if (sensitiveWords.isEmpty()) { |
| 330 | + // No sensitive words, proceed to next message |
| 331 | + checkAndSendMessages(messages, index + 1); |
| 332 | + } else { |
| 333 | + // Sensitive words detected, show dialog |
| 334 | + final int currentIndex = index; |
| 335 | + String wordsDisplay = TextUtils.join(", ", sensitiveWords); |
| 336 | + |
| 337 | + new MaterialAlertDialogBuilder(this) |
| 338 | + .setTitle(getString(R.string.sensitive_word_detected_title)) |
| 339 | + .setMessage(getString(R.string.sensitive_word_detected_msg, currentIndex + 1, wordsDisplay)) |
| 340 | + .setCancelable(false) |
| 341 | + .setPositiveButton(getString(R.string.skip_message), (dialog, which) -> { |
| 342 | + // Skip this message |
| 343 | + messages.set(currentIndex, null); |
| 344 | + checkAndSendMessages(messages, currentIndex + 1); |
| 345 | + }) |
| 346 | + .setNeutralButton(getString(R.string.edit_message), (dialog, which) -> { |
| 347 | + // Show edit dialog |
| 348 | + showEditMessageDialog(messages, currentIndex); |
| 349 | + }) |
| 350 | + .setNegativeButton(getString(R.string.cancel_send), (dialog, which) -> { |
| 351 | + // Cancel entire sending process |
| 352 | + ToastUtil.show(this, getString(R.string.sending_cancelled)); |
| 353 | + }) |
| 354 | + .show(); |
| 355 | + } |
| 356 | + } |
| 357 | + |
| 358 | + /** |
| 359 | + * Show a dialog to edit the message content. Re-checks for sensitive words after saving. |
| 360 | + */ |
| 361 | + private void showEditMessageDialog(List<Message> messages, int index) { |
| 362 | + Message message = messages.get(index); |
| 363 | + |
| 364 | + View dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null); |
| 365 | + TextInputLayout container = dialogView.findViewById(R.id.edit_text_container); |
| 366 | + |
| 367 | + EditText editText = dialogView.findViewById(R.id.edit_text); |
| 368 | + editText.setText(message.getContent()); |
| 369 | + editText.setSelection(editText.getText().length()); |
| 370 | + |
| 371 | + new MaterialAlertDialogBuilder(this) |
| 372 | + .setTitle(getString(R.string.edit_sensitive_message_title)) |
| 373 | + .setView(dialogView) |
| 374 | + .setCancelable(false) |
| 375 | + .setPositiveButton(getString(R.string.save), (dialog, which) -> { |
| 376 | + String newContent = editText.getText().toString(); |
| 377 | + messages.set(index, new Message(message.getPhone(), newContent)); |
| 378 | + // Re-check this message |
| 379 | + checkAndSendMessages(messages, index); |
| 380 | + }) |
| 381 | + .setNegativeButton(getString(R.string.cancel), (dialog, which) -> { |
| 382 | + // Go back to the check dialog |
| 383 | + checkAndSendMessages(messages, index); |
| 384 | + }) |
| 385 | + .show(); |
| 386 | + } |
| 387 | + |
293 | 388 |
|
294 | 389 | private void showProgressDialog() { |
295 | 390 | if (progressDialog == null) { |
@@ -404,7 +499,7 @@ private void observeSending() { |
404 | 499 | tvProgressTitle.setText(getString(R.string.sending)); |
405 | 500 | progressDialog.setCancelable(false); |
406 | 501 | progressDialog.setCanceledOnTouchOutside(false); |
407 | | - btnCancel.setText(getString(R.string.cancel)); |
| 502 | + btnCancel.setText(getString(R.string.cancel_send)); |
408 | 503 | break; |
409 | 504 | } |
410 | 505 | } |
|
0 commit comments