Skip to content

Commit cacb75b

Browse files
committed
fix(local-notifications): getIcon
1 parent 8c8e74b commit cacb75b

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

packages/local-notifications/index.android.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,39 @@ export class LocalNotificationsImpl extends LocalNotificationsCommon implements
3535

3636
switch (interval) {
3737
default:
38-
case 'second': multiplier = 1000; break;
39-
case 'minute': multiplier = android.app.AlarmManager.INTERVAL_HOUR / 60; break;
40-
case 'hour': multiplier = android.app.AlarmManager.INTERVAL_HOUR; break;
41-
case 'day': multiplier = android.app.AlarmManager.INTERVAL_DAY; break;
42-
case 'week': multiplier = android.app.AlarmManager.INTERVAL_DAY * 7; break;
38+
case 'second':
39+
multiplier = 1000;
40+
break;
41+
case 'minute':
42+
multiplier = android.app.AlarmManager.INTERVAL_HOUR / 60;
43+
break;
44+
case 'hour':
45+
multiplier = android.app.AlarmManager.INTERVAL_HOUR;
46+
break;
47+
case 'day':
48+
multiplier = android.app.AlarmManager.INTERVAL_DAY;
49+
break;
50+
case 'week':
51+
multiplier = android.app.AlarmManager.INTERVAL_DAY * 7;
52+
break;
4353
// close enough
44-
case 'month': multiplier = android.app.AlarmManager.INTERVAL_DAY * 31; break;
45-
case 'quarter': multiplier = android.app.AlarmManager.INTERVAL_DAY * 31 * 3; break;
46-
case 'year': multiplier = android.app.AlarmManager.INTERVAL_DAY * 365; break;
54+
case 'month':
55+
multiplier = android.app.AlarmManager.INTERVAL_DAY * 31;
56+
break;
57+
case 'quarter':
58+
multiplier = android.app.AlarmManager.INTERVAL_DAY * 31 * 3;
59+
break;
60+
case 'year':
61+
multiplier = android.app.AlarmManager.INTERVAL_DAY * 365;
62+
break;
4763
}
4864

4965
return Math.abs(ticks) * multiplier;
5066
}
5167

5268
private static getIcon(context: any /* android.content.Context */, resources: any, iconLocation?: string): string {
5369
const packageName: string = context.getApplicationInfo().packageName;
54-
return (iconLocation && iconLocation.indexOf(Utils.RESOURCE_PREFIX) === 0 && resources.getIdentifier(iconLocation.substr(Utils.RESOURCE_PREFIX.length), 'drawable', packageName)) || (LocalNotificationsImpl.IS_GTE_LOLLIPOP && resources.getIdentifier('ic_stat_notify_silhouette', 'drawable', packageName)) || resources.getIdentifier('ic_stat_notify', 'drawable', packageName) || context.getApplicationInfo().icon;
70+
return (iconLocation && typeof iconLocation === 'string' && iconLocation.indexOf(Utils.RESOURCE_PREFIX) === 0 && resources.getIdentifier(iconLocation.substr(Utils.RESOURCE_PREFIX.length), 'drawable', packageName)) || (LocalNotificationsImpl.IS_GTE_LOLLIPOP && resources.getIdentifier('ic_stat_notify_silhouette', 'drawable', packageName)) || resources.getIdentifier('ic_stat_notify', 'drawable', packageName) || context.getApplicationInfo().icon;
5571
}
5672

5773
private static cancelById(id: number): void {
@@ -198,10 +214,8 @@ export class LocalNotificationsImpl extends LocalNotificationsCommon implements
198214
for (let n in scheduleOptions) {
199215
const triggers: Array<Record<string, any>> = [];
200216
const options = LocalNotificationsImpl.merge(scheduleOptions[n], LocalNotificationsImpl.defaults);
201-
const [ interval, ticks ] = (!!options.interval) && (options.interval.constructor === Object)
202-
? Object.entries(options.interval || {}).shift() as [ScheduleInterval, number] || []
203-
: [ options.interval ] as [ ScheduleInterval ]
204-
217+
const [interval, ticks] = !!options.interval && options.interval.constructor === Object ? (Object.entries(options.interval || {}).shift() as [ScheduleInterval, number]) || [] : ([options.interval] as [ScheduleInterval]);
218+
205219
LocalNotificationsImpl.ensureID(options);
206220

207221
options.atTime = options.at ? options.at.getTime() : -1;
@@ -230,15 +244,15 @@ export class LocalNotificationsImpl extends LocalNotificationsCommon implements
230244
triggers.push(optionsClone);
231245
}
232246

233-
triggers.forEach(trigger => registerNotification(trigger, context, scheduledIds));
247+
triggers.forEach((trigger) => registerNotification(trigger, context, scheduledIds));
234248
}
235249

236250
return scheduledIds;
237251
} catch (ex) {
238252
console.log('Error in LocalNotifications.schedule: ' + ex);
239253
throw ex;
240254
}
241-
255+
242256
function registerNotification(options: Record<string, any>, context: globalAndroid.content.Context, register: Array<number>) {
243257
com.telerik.localnotifications.LocalNotificationsPlugin.scheduleNotification(new org.json.JSONObject(JSON.stringify(options)), context);
244258
register.push(options.id);

packages/local-notifications/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/local-notifications",
3-
"version": "6.2.0",
3+
"version": "6.2.1",
44
"description": "The Local Notifications plugin allows your app to show notifications when the app is not running.",
55
"main": "index",
66
"typings": "index.d.ts",

0 commit comments

Comments
 (0)