Skip to content

Commit 83f8857

Browse files
committed
Improve code styling
* Rename variables from notif to notification * Remove unused code * Remove unused imports * Make OneSignal getter for DB
1 parent 91e241d commit 83f8857

16 files changed

+63
-79
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotification.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,18 @@ private static OneSignalNotificationBuilder getBaseOneSignalNotificationBuilder(
161161
JSONObject fcmJson = notificationJob.getJsonPayload();
162162
OneSignalNotificationBuilder oneSignalNotificationBuilder = new OneSignalNotificationBuilder();
163163

164-
NotificationCompat.Builder notifBuilder;
164+
NotificationCompat.Builder notificationBuilder;
165165
try {
166166
String channelId = NotificationChannelManager.createNotificationChannel(notificationJob);
167167
// Will throw if app is using 26.0.0-beta1 or older of the support library.
168-
notifBuilder = new NotificationCompat.Builder(currentContext, channelId);
168+
notificationBuilder = new NotificationCompat.Builder(currentContext, channelId);
169169
} catch(Throwable t) {
170-
notifBuilder = new NotificationCompat.Builder(currentContext);
170+
notificationBuilder = new NotificationCompat.Builder(currentContext);
171171
}
172172

173173
String message = fcmJson.optString("alert", null);
174174

175-
notifBuilder
175+
notificationBuilder
176176
.setAutoCancel(true)
177177
.setSmallIcon(getSmallIconId(fcmJson))
178178
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
@@ -183,40 +183,40 @@ private static OneSignalNotificationBuilder getBaseOneSignalNotificationBuilder(
183183
// Android 7.0 always displays the app title now in it's own section
184184
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N ||
185185
!fcmJson.optString("title").equals(""))
186-
notifBuilder.setContentTitle(getTitle(fcmJson));
186+
notificationBuilder.setContentTitle(getTitle(fcmJson));
187187

188188
try {
189189
BigInteger accentColor = getAccentColor(fcmJson);
190190
if (accentColor != null)
191-
notifBuilder.setColor(accentColor.intValue());
191+
notificationBuilder.setColor(accentColor.intValue());
192192
} catch (Throwable t) {} // Can throw if an old android support lib is used.
193193

194194
try {
195195
int lockScreenVisibility = NotificationCompat.VISIBILITY_PUBLIC;
196196
if (fcmJson.has("vis"))
197197
lockScreenVisibility = Integer.parseInt(fcmJson.optString("vis"));
198-
notifBuilder.setVisibility(lockScreenVisibility);
198+
notificationBuilder.setVisibility(lockScreenVisibility);
199199
} catch (Throwable t) {} // Can throw if an old android support lib is used or parse error
200200

201201
Bitmap largeIcon = getLargeIcon(fcmJson);
202202
if (largeIcon != null) {
203203
oneSignalNotificationBuilder.hasLargeIcon = true;
204-
notifBuilder.setLargeIcon(largeIcon);
204+
notificationBuilder.setLargeIcon(largeIcon);
205205
}
206206

207207
Bitmap bigPictureIcon = getBitmap(fcmJson.optString("bicon", null));
208208
if (bigPictureIcon != null)
209-
notifBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bigPictureIcon).setSummaryText(message));
209+
notificationBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bigPictureIcon).setSummaryText(message));
210210

211211
if (notificationJob.getShownTimeStamp() != null) {
212212
try {
213-
notifBuilder.setWhen(notificationJob.getShownTimeStamp() * 1_000L);
213+
notificationBuilder.setWhen(notificationJob.getShownTimeStamp() * 1_000L);
214214
} catch (Throwable t) {} // Can throw if an old android support lib is used.
215215
}
216216

217-
setAlertnessOptions(fcmJson, notifBuilder);
217+
setAlertnessOptions(fcmJson, notificationBuilder);
218218

219-
oneSignalNotificationBuilder.compatBuilder = notifBuilder;
219+
oneSignalNotificationBuilder.compatBuilder = notificationBuilder;
220220
return oneSignalNotificationBuilder;
221221
}
222222

OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationLimitManager.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,27 @@ private static String getMaxNumberOfNotificationsString() {
3636

3737
// Used to cancel the oldest notifications to make room for new notifications we are about to display
3838
// If we don't make this room users will NOT be alerted of new notifications for the app.
39-
static void clearOldestOverLimit(Context context, int notifsToMakeRoomFor) {
39+
static void clearOldestOverLimit(Context context, int notificationsToMakeRoomFor) {
4040
try {
4141
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
42-
clearOldestOverLimitStandard(context, notifsToMakeRoomFor);
42+
clearOldestOverLimitStandard(context, notificationsToMakeRoomFor);
4343
else
44-
clearOldestOverLimitFallback(context, notifsToMakeRoomFor);
44+
clearOldestOverLimitFallback(context, notificationsToMakeRoomFor);
4545
} catch(Throwable t) {
4646
// try-catch for Android 6.0.X and possibly 8.0.0 bug work around, getActiveNotifications bug
47-
clearOldestOverLimitFallback(context, notifsToMakeRoomFor);
47+
clearOldestOverLimitFallback(context, notificationsToMakeRoomFor);
4848
}
4949
}
5050

5151
// Cancel the oldest notifications based on what the Android system reports is in the shade.
5252
// This could be any notification, not just a OneSignal notification
5353
@RequiresApi(api = Build.VERSION_CODES.M)
54-
static void clearOldestOverLimitStandard(Context context, int notifsToMakeRoomFor) throws Throwable {
54+
static void clearOldestOverLimitStandard(Context context, int notificationsToMakeRoomFor) throws Throwable {
5555
StatusBarNotification[] activeNotifs = OneSignalNotificationManager.getActiveNotifications(context);
5656

57-
int notifsToClear = (activeNotifs.length - getMaxNumberOfNotificationsInt()) + notifsToMakeRoomFor;
57+
int notificationsToClear = (activeNotifs.length - getMaxNumberOfNotificationsInt()) + notificationsToMakeRoomFor;
5858
// We have enough room in the notification shade, no need to clear any notifications
59-
if (notifsToClear < 1)
59+
if (notificationsToClear < 1)
6060
return;
6161

6262
// Create SortedMap so we can sort notifications based on display time
@@ -67,16 +67,16 @@ static void clearOldestOverLimitStandard(Context context, int notifsToMakeRoomFo
6767
activeNotifIds.put(activeNotif.getNotification().when, activeNotif.getId());
6868
}
6969

70-
// Clear the oldest based on the count in notifsToClear
70+
// Clear the oldest based on the count in notificationsToClear
7171
for (Map.Entry<Long, Integer> mapData : activeNotifIds.entrySet()) {
7272
OneSignal.cancelNotification(mapData.getValue());
73-
if (--notifsToClear <= 0)
73+
if (--notificationsToClear <= 0)
7474
break;
7575
}
7676
}
7777

7878
// This cancels any notifications based on the oldest in the local SQL database
79-
static void clearOldestOverLimitFallback(Context context, int notifsToMakeRoomFor) {
79+
static void clearOldestOverLimitFallback(Context context, int notificationsToMakeRoomFor) {
8080
OneSignalDbHelper dbHelper = OneSignalDbHelper.getInstance(context);
8181

8282
Cursor cursor = null;
@@ -89,19 +89,19 @@ static void clearOldestOverLimitFallback(Context context, int notifsToMakeRoomFo
8989
null,
9090
null,
9191
OneSignalDbContract.NotificationTable._ID, // sort order, old to new
92-
getMaxNumberOfNotificationsString() + notifsToMakeRoomFor // limit
92+
getMaxNumberOfNotificationsString() + notificationsToMakeRoomFor // limit
9393
);
9494

95-
int notifsToClear = (cursor.getCount() - getMaxNumberOfNotificationsInt()) + notifsToMakeRoomFor;
95+
int notificationsToClear = (cursor.getCount() - getMaxNumberOfNotificationsInt()) + notificationsToMakeRoomFor;
9696
// We have enough room in the notification shade, no need to clear any notifications
97-
if (notifsToClear < 1)
97+
if (notificationsToClear < 1)
9898
return;
9999

100100
while (cursor.moveToNext()) {
101101
int existingId = cursor.getInt(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID));
102102
OneSignal.cancelNotification(existingId);
103103

104-
if (--notifsToClear <= 0)
104+
if (--notificationsToClear <= 0)
105105
break;
106106
}
107107
} catch (Throwable t) {

OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private static void markNotificationsConsumed(Context context, Intent intent, On
176176
boolean shouldDismissAll = OneSignal.getClearGroupSummaryClick();
177177
if (!shouldDismissAll) {
178178
/* If the open event shouldn't clear all summary notifications then the SQL query
179-
* will look for the most recent notification instead of all grouped notifs */
179+
* will look for the most recent notification instead of all grouped notifications */
180180
String mostRecentId = String.valueOf(OneSignalNotificationManager.getMostRecentNotifIdFromGroup(writableDb, summaryGroup, isGroupless));
181181
whereStr += " AND " + NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID + " = ?";
182182
whereArgs = isGroupless ?

OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationSummaryManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ private static Cursor internalUpdateSummaryNotificationAfterChildRemoved(Context
5757
null, null,
5858
NotificationTable._ID + " DESC"); // sort order, new to old);
5959

60-
int notifsInGroup = cursor.getCount();
60+
int notificationsInGroup = cursor.getCount();
6161

6262
// If all individual notifications consumed
6363
// - Remove summary notification from the shade.
6464
// - Mark summary notification as consumed.
65-
if (notifsInGroup == 0) {
65+
if (notificationsInGroup == 0) {
6666
cursor.close();
6767

6868
Integer androidNotifId = getSummaryNotificationId(db, group);
@@ -86,7 +86,7 @@ private static Cursor internalUpdateSummaryNotificationAfterChildRemoved(Context
8686
// Only a single notification now in the group
8787
// - Need to recreate a summary notification so it looks like a normal notifications since we
8888
// only have one notification now.
89-
if (notifsInGroup == 1) {
89+
if (notificationsInGroup == 1) {
9090
cursor.close();
9191
Integer androidNotifId = getSummaryNotificationId(db, group);
9292
if (androidNotifId == null)

OneSignalSDK/onesignal/src/main/java/com/onesignal/OSNotificationRestoreWorkManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static void queryAndRestoreNotificationsAndBadgeCount(
9090
StringBuilder dbQuerySelection) {
9191

9292
OneSignal.Log(OneSignal.LOG_LEVEL.INFO,
93-
"Querying DB for notifs to restore: " + dbQuerySelection.toString());
93+
"Querying DB for notifications to restore: " + dbQuerySelection.toString());
9494

9595
Cursor cursor = null;
9696
try {

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ private static void setupActivityLifecycleListener(boolean wasAppContextNull) {
718718
// Do work here that should only happen once or at the start of a new lifecycle
719719
if (wasAppContextNull) {
720720
if (outcomeEventsFactory == null)
721-
outcomeEventsFactory = new OSOutcomeEventsFactory(logger, apiClient, OneSignalDbHelper.getInstance(appContext), preferences);
721+
outcomeEventsFactory = new OSOutcomeEventsFactory(logger, apiClient, getDBHelperInstance(), preferences);
722722

723723
sessionManager.initSessionFromCache();
724724
outcomeEventsController = new OSOutcomeEventsController(sessionManager, outcomeEventsFactory);
@@ -765,11 +765,6 @@ public static boolean userProvidedPrivacyConsent() {
765765
return remoteParamController.getSavedUserConsentStatus();
766766
}
767767

768-
private static boolean isGoogleProjectNumberRemote() {
769-
return getRemoteParams() != null &&
770-
getRemoteParams().googleProjectNumber != null;
771-
}
772-
773768
private static boolean isSubscriptionStatusUninitializable() {
774769
return subscribableStatus == OSUtils.UNINITIALIZABLE_STATUS;
775770
}
@@ -819,10 +814,6 @@ private static void doSessionInit() {
819814
startRegistrationOrOnSession();
820815
}
821816

822-
private static boolean isContextActivity(Context context) {
823-
return context instanceof Activity;
824-
}
825-
826817
private static void startRegistrationOrOnSession() {
827818
if (waitingToPostStateSync)
828819
return;
@@ -2433,7 +2424,7 @@ public static void clearOneSignalNotifications() {
24332424
public void run() {
24342425
NotificationManager notificationManager = OneSignalNotificationManager.getNotificationManager(appContext);
24352426

2436-
OneSignalDbHelper dbHelper = OneSignalDbHelper.getInstance(appContext);
2427+
OneSignalDbHelper dbHelper = getDBHelperInstance();
24372428
String[] retColumn = {OneSignalDbContract.NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID};
24382429

24392430
Cursor cursor = dbHelper.query(
@@ -2483,7 +2474,7 @@ public static void cancelNotification(final int id) {
24832474
Runnable runCancelNotification = new Runnable() {
24842475
@Override
24852476
public void run() {
2486-
OneSignalDbHelper dbHelper = OneSignalDbHelper.getInstance(appContext);
2477+
OneSignalDbHelper dbHelper = getDBHelperInstance();
24872478
String whereStr = NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID + " = " + id + " AND " +
24882479
NotificationTable.COLUMN_NAME_OPENED + " = 0 AND " +
24892480
NotificationTable.COLUMN_NAME_DISMISSED + " = 0";
@@ -2533,7 +2524,7 @@ public void run() {
25332524
public void run() {
25342525
NotificationManager notificationManager = OneSignalNotificationManager.getNotificationManager(appContext);
25352526

2536-
OneSignalDbHelper dbHelper = OneSignalDbHelper.getInstance(appContext);
2527+
OneSignalDbHelper dbHelper = getDBHelperInstance();
25372528

25382529
String[] retColumn = {NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID};
25392530

@@ -2807,7 +2798,7 @@ private static boolean isDuplicateNotification(Context context, String id) {
28072798
if (id == null || "".equals(id))
28082799
return false;
28092800

2810-
OneSignalDbHelper dbHelper = OneSignalDbHelper.getInstance(context);
2801+
OneSignalDbHelper dbHelper = getDBHelperInstance();
28112802

28122803
String[] retColumn = {NotificationTable.COLUMN_NAME_NOTIFICATION_ID};
28132804
String[] whereArgs = {id};
@@ -2957,6 +2948,10 @@ static OSRemoteParamController getRemoteParamController() {
29572948
return remoteParamController;
29582949
}
29592950

2951+
static OneSignalDbHelper getDBHelperInstance() {
2952+
return OneSignalDbHelper.getInstance(appContext);
2953+
}
2954+
29602955
static OSTaskController getTaskController() {
29612956
return taskController;
29622957
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignalDbHelper.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import java.util.ArrayList;
4949
import java.util.List;
5050

51-
import static com.onesignal.outcomes.data.OutcomesDbContract.OUTCOME_EVENT_TABLE;
5251
import static com.onesignal.outcomes.data.OutcomesDbContract.SQL_CREATE_OUTCOME_ENTRIES_V1;
5352
import static com.onesignal.outcomes.data.OutcomesDbContract.SQL_CREATE_OUTCOME_ENTRIES_V3;
5453
import static com.onesignal.outcomes.data.OutcomesDbContract.SQL_CREATE_UNIQUE_OUTCOME_ENTRIES_V1;
@@ -438,10 +437,4 @@ static StringBuilder recentUninteractedWithNotificationsWhere() {
438437
return where;
439438
}
440439

441-
static void cleanOutcomeDatabaseTable(SQLiteDatabase writeableDb) {
442-
writeableDb.delete(
443-
OUTCOME_EVENT_TABLE,
444-
null,
445-
null);
446-
}
447440
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/influence/data/OSChannelTracker.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.onesignal.influence.data
22

33
import com.onesignal.OSLogger
44
import com.onesignal.OSTime
5-
import com.onesignal.OneSignal
65
import com.onesignal.influence.OSInfluenceConstants
76
import com.onesignal.influence.domain.OSInfluence
87
import com.onesignal.influence.domain.OSInfluenceChannel
@@ -11,7 +10,7 @@ import org.json.JSONArray
1110
import org.json.JSONException
1211
import org.json.JSONObject
1312

14-
abstract class OSChannelTracker internal constructor(protected var dataRepository: OSInfluenceDataRepository, var logger: OSLogger, var timeProvider: OSTime) {
13+
abstract class OSChannelTracker internal constructor(protected var dataRepository: OSInfluenceDataRepository, var logger: OSLogger, private var timeProvider: OSTime) {
1514
var influenceType: OSInfluenceType? = null
1615
var indirectIds: JSONArray? = null
1716
var directId: String? = null

OneSignalSDK/onesignal/src/main/java/com/onesignal/outcomes/data/OSOutcomeEventsCache.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.onesignal.outcomes.data
22

33
import android.content.ContentValues
44
import android.database.Cursor
5-
import android.database.sqlite.SQLiteException
65
import androidx.annotation.WorkerThread
76
import com.onesignal.OSLogger
87
import com.onesignal.OSSharedPreferences

OneSignalSDK/onesignal/src/main/java/com/onesignal/outcomes/data/OSOutcomeEventsRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package com.onesignal.outcomes.data
33
import com.onesignal.OSLogger
44
import com.onesignal.OneSignalApiResponseHandler
55
import com.onesignal.influence.domain.OSInfluence
6-
import com.onesignal.outcomes.domain.OSOutcomeEventsRepository
76
import com.onesignal.outcomes.domain.OSOutcomeEventParams
7+
import com.onesignal.outcomes.domain.OSOutcomeEventsRepository
88

99
internal abstract class OSOutcomeEventsRepository(protected val logger: OSLogger,
1010
private val outcomeEventsCache: OSOutcomeEventsCache,

0 commit comments

Comments
 (0)