Skip to content

Commit

Permalink
Improve code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
revanmj committed Dec 15, 2018
1 parent 2bfc570 commit 7a01011
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,6 @@ public static void showNotification(Context context, String code, String sender)
// Instert space in the middle of the code (if 6 digits or longer) for better readability
code = insertSpaceInTheMiddle(code);

/*// Prepare formatted string with notification content text
String lineFormat = sender + ": %s";
int lineParamStartPos = lineFormat.indexOf("%s");
if (lineParamStartPos < 0) {
throw new InvalidParameterException("Something's wrong with your string! LINT could have caught that.");
}
String lineFormatted = String.format(lineFormat, code);
// Adding bold to the OTP
Spannable sb = new SpannableString(lineFormatted);
sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), lineParamStartPos, lineParamStartPos + code.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);*/

// Accent color for L/M/N
int color = ContextCompat.getColor(context, R.color.colorPrimary);

Expand Down Expand Up @@ -120,6 +108,7 @@ public static void showNotification(Context context, String code, String sender)
boolean heads_up = settings.getBoolean(SharedSettings.KEY_HEADSUP_NOTIFICATIONS, false);
if (heads_up && Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
// Silent sound needed for heads up notifications to work
mBuilder.setSound(Uri.parse("android.resource://pl.revanmj.smspasswordnotifier/" + R.raw.silent));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ public void onReceive(Context context, Intent intent) {
final Bundle bundle = intent.getExtras();

if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(intent.getAction())) {
// Just in case some OEM allowed this broadcast to be sent,
// but restricted access to its extras
// Just in case some OEM allowed this broadcast to be sent without permission being granted
if (ContextCompat.checkSelfPermission(context, Manifest.permission.RECEIVE_SMS)
!= PackageManager.PERMISSION_GRANTED) {
Log.e(LOG_TAG, "We've got a broadcast, yet permission is not granted!");
Log.e(LOG_TAG, "We've got SMS broadcast, yet permission is not granted!");
return;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
MessageProcessor.showNotification(mActivity, "123456", "ExampleSender");
return false;
});
// Hide test notification option from release builds
if (!BuildConfig.DEBUG) {
getPreferenceScreen().removePreference(testNoti);
}
Expand All @@ -113,6 +114,8 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
MY_PERMISSIONS_REQUEST_RECEIVE_SMS);
}
}
// Use system notification settings when on Oreo or higher
// and hide internal settings in such case
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
SwitchPreferenceCompat headsUpSwitch = (SwitchPreferenceCompat) findPreference("headsup_notifications");
getPreferenceScreen().removePreference(headsUpSwitch);
Expand Down Expand Up @@ -165,6 +168,7 @@ public static void showPermissionExplanaition(Activity activity) {
new String[]{Manifest.permission.RECEIVE_SMS},
MY_PERMISSIONS_REQUEST_RECEIVE_SMS);
});
// Close app if permission is not granted
builder.setNegativeButton(R.string.button_exit, (dialogInterface, i) -> {
dialogInterface.dismiss();
activity.finish();
Expand Down

0 comments on commit 7a01011

Please sign in to comment.