Skip to content

Commit 17f6340

Browse files
committed
abstract class to share NotificationOpenedReceiver
Created abstract NotificationOpenedReceiverBase to share code between both activities. It is very unlikly the code would ever be different between them and prevents possible future mistakes of editing only one.
1 parent 8652290 commit 17f6340

File tree

3 files changed

+48
-35
lines changed

3 files changed

+48
-35
lines changed
Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Modified MIT License
33
*
4-
* Copyright 2017 OneSignal
4+
* Copyright 2021 OneSignal
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -26,20 +26,4 @@
2626
*/
2727
package com.onesignal
2828

29-
import android.app.Activity
30-
import android.content.Intent
31-
import android.os.Bundle
32-
33-
class NotificationOpenedReceiver : Activity() {
34-
override fun onCreate(savedInstanceState: Bundle?) {
35-
super.onCreate(savedInstanceState)
36-
NotificationOpenedProcessor.processFromContext(this, intent)
37-
finish()
38-
}
39-
40-
override fun onNewIntent(intent: Intent) {
41-
super.onNewIntent(intent)
42-
NotificationOpenedProcessor.processFromContext(this, getIntent())
43-
finish()
44-
}
45-
}
29+
class NotificationOpenedReceiver : NotificationOpenedReceiverBase()

OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedReceiverAndroid22AndOlder.kt

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
*/
2727
package com.onesignal
2828

29-
import android.app.Activity
30-
import android.content.Intent
31-
import android.os.Bundle
32-
3329
/**
3430
* This is the same as NotificationOpenedReceiver expect it doesn't contain
3531
* android:taskAffinity="" in it's AndroidManifest.xml entry. This is to
@@ -40,16 +36,4 @@ import android.os.Bundle
4036
* results in the app not resuming, when using reverse Activity trampoline.
4137
* Oddly enough cold starts of the app were not a problem.
4238
*/
43-
class NotificationOpenedReceiverAndroid22AndOlder : Activity() {
44-
override fun onCreate(savedInstanceState: Bundle?) {
45-
super.onCreate(savedInstanceState)
46-
NotificationOpenedProcessor.processFromContext(this, intent)
47-
finish()
48-
}
49-
50-
override fun onNewIntent(intent: Intent) {
51-
super.onNewIntent(intent)
52-
NotificationOpenedProcessor.processFromContext(this, getIntent())
53-
finish()
54-
}
55-
}
39+
class NotificationOpenedReceiverAndroid22AndOlder : NotificationOpenedReceiverBase()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2021 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
package com.onesignal
28+
29+
import android.app.Activity
30+
import android.content.Intent
31+
import android.os.Bundle
32+
33+
abstract class NotificationOpenedReceiverBase : Activity() {
34+
override fun onCreate(savedInstanceState: Bundle?) {
35+
super.onCreate(savedInstanceState)
36+
NotificationOpenedProcessor.processFromContext(this, intent)
37+
finish()
38+
}
39+
40+
override fun onNewIntent(intent: Intent) {
41+
super.onNewIntent(intent)
42+
NotificationOpenedProcessor.processFromContext(this, getIntent())
43+
finish()
44+
}
45+
}

0 commit comments

Comments
 (0)