Skip to content

Commit 3e5493f

Browse files
Merge pull request #3 from OneSignalDevelopers/login-functions
Add Login and logout functions
2 parents 5e59803 + 4597c6b commit 3e5493f

File tree

11 files changed

+120
-151
lines changed

11 files changed

+120
-151
lines changed

.gitignore

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
1-
*.iml
2-
.gradle
3-
/local.properties
4-
/.idea/caches
5-
/.idea/libraries
6-
/.idea/modules.xml
7-
/.idea/workspace.xml
8-
/.idea/navEditor.xml
9-
/.idea/assetWizardSettings.xml
10-
.DS_Store
11-
/build
12-
/captures
13-
.externalNativeBuild
14-
.cxx
1+
# System files
2+
**/.DS_Store
3+
4+
# Gradle files
5+
.gradle/
6+
build/
7+
8+
# Local configuration file (sdk path, etc)
159
local.properties
10+
11+
# Log/OS Files
12+
*.log
13+
14+
# Android Studio generated files and folders
15+
captures/
16+
.externalNativeBuild/
17+
.cxx/
18+
*.apk
19+
output.json
20+
21+
# IntelliJ
22+
*.iml
23+
.idea/
24+
misc.xml
25+
deploymentTargetDropDown.xml
26+
render.experimental.xml
27+
28+
# Keystore files
29+
*.jks
30+
*.keystore
31+
32+
# Google Services (e.g. APIs or Firebase)
33+
google-services.json
34+
35+
# Android Profiling
36+
*.hprof

.idea/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.idea/.name

Lines changed: 0 additions & 1 deletion
This file was deleted.

.idea/compiler.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/deploymentTargetDropDown.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.idea/gradle.xml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.idea/kotlinc.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/misc.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

app/src/main/java/com/onesignal/sample/android/MainActivity.kt

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,29 @@ class MainActivity : AppCompatActivity() {
99
override fun onCreate(savedInstanceState: Bundle?) {
1010
super.onCreate(savedInstanceState)
1111
setContentView(R.layout.activity_main)
12-
findViewById<Button>(R.id.enable_push).setOnClickListener(
13-
{
14-
OneSignal.User.pushSubscription.optIn()
15-
}
16-
)
17-
findViewById<Button>(R.id.disable_push).setOnClickListener(
18-
{
19-
OneSignal.User.pushSubscription.optOut()
20-
}
21-
)
22-
findViewById<Button>(R.id.prompt_push).setOnClickListener(
23-
{
24-
OneSignal.InAppMessages.addTrigger("show_push_permission_prompt", "1")
25-
}
26-
)
27-
findViewById<Button>(R.id.present_iam).setOnClickListener(
28-
{
29-
OneSignal.InAppMessages.addTrigger("show_sample_iam", "1")
30-
}
31-
)
3212

13+
findViewById<Button>(R.id.login).setOnClickListener {
14+
OneSignal.login("USER_ID")
15+
}
16+
17+
findViewById<Button>(R.id.logout).setOnClickListener {
18+
OneSignal.logout()
19+
}
20+
21+
findViewById<Button>(R.id.enable_push).setOnClickListener {
22+
OneSignal.User.pushSubscription.optIn()
23+
}
24+
25+
findViewById<Button>(R.id.disable_push).setOnClickListener {
26+
OneSignal.User.pushSubscription.optOut()
27+
}
28+
29+
findViewById<Button>(R.id.prompt_push).setOnClickListener {
30+
OneSignal.InAppMessages.addTrigger("show_push_permission_prompt", "1")
31+
}
32+
33+
findViewById<Button>(R.id.present_iam).setOnClickListener {
34+
OneSignal.InAppMessages.addTrigger("show_sample_iam", "1")
35+
}
3336
}
3437
}

app/src/main/res/layout/activity_main.xml

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,64 +6,70 @@
66
android:layout_height="match_parent"
77
tools:context=".MainActivity">
88

9-
<Button
10-
android:id="@+id/enable_push"
11-
android:layout_width="wrap_content"
12-
android:layout_height="wrap_content"
13-
android:layout_marginStart="1dp"
14-
android:layout_marginTop="1dp"
15-
android:layout_marginEnd="1dp"
16-
android:layout_marginBottom="1dp"
17-
android:text="Enable Push"
18-
app:layout_constraintBottom_toTopOf="@+id/disable_push"
9+
<LinearLayout
10+
android:layout_width="0dp"
11+
android:layout_height="0dp"
12+
android:layout_marginStart="8dp"
13+
android:layout_marginTop="32dp"
14+
android:layout_marginEnd="8dp"
15+
android:layout_marginBottom="8dp"
16+
android:orientation="vertical"
17+
app:layout_constraintBottom_toBottomOf="parent"
1918
app:layout_constraintEnd_toEndOf="parent"
20-
app:layout_constraintHorizontal_bias="0.5"
2119
app:layout_constraintStart_toStartOf="parent"
22-
app:layout_constraintTop_toTopOf="parent" />
20+
app:layout_constraintTop_toTopOf="parent">
2321

24-
<Button
25-
android:id="@+id/disable_push"
26-
android:layout_width="wrap_content"
27-
android:layout_height="wrap_content"
28-
android:layout_marginStart="1dp"
29-
android:layout_marginTop="1dp"
30-
android:layout_marginEnd="1dp"
31-
android:layout_marginBottom="1dp"
32-
android:text="Disable Push"
33-
app:layout_constraintBottom_toTopOf="@+id/prompt_push"
34-
app:layout_constraintEnd_toEndOf="parent"
35-
app:layout_constraintHorizontal_bias="0.5"
36-
app:layout_constraintStart_toStartOf="parent"
37-
app:layout_constraintTop_toBottomOf="@+id/enable_push" />
22+
<Button
23+
android:id="@+id/login"
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:text="Login" />
3827

39-
<Button
40-
android:id="@+id/prompt_push"
41-
android:layout_width="wrap_content"
42-
android:layout_height="wrap_content"
43-
android:layout_marginStart="1dp"
44-
android:layout_marginTop="1dp"
45-
android:layout_marginEnd="1dp"
46-
android:layout_marginBottom="1dp"
47-
android:text="Prompt Push Permission"
48-
app:layout_constraintBottom_toTopOf="@+id/present_iam"
49-
app:layout_constraintEnd_toEndOf="parent"
50-
app:layout_constraintHorizontal_bias="0.5"
51-
app:layout_constraintStart_toStartOf="parent"
52-
app:layout_constraintTop_toBottomOf="@+id/disable_push" />
28+
<Button
29+
android:id="@+id/logout"
30+
android:layout_width="match_parent"
31+
android:layout_height="wrap_content"
32+
android:text="Logout" />
5333

54-
<Button
55-
android:id="@+id/present_iam"
56-
android:layout_width="wrap_content"
57-
android:layout_height="wrap_content"
58-
android:layout_marginStart="1dp"
59-
android:layout_marginTop="1dp"
60-
android:layout_marginEnd="1dp"
61-
android:layout_marginBottom="1dp"
62-
android:text="Present In-App Message"
63-
app:layout_constraintBottom_toBottomOf="parent"
64-
app:layout_constraintEnd_toEndOf="parent"
65-
app:layout_constraintHorizontal_bias="0.5"
66-
app:layout_constraintStart_toStartOf="parent"
67-
app:layout_constraintTop_toBottomOf="@+id/disable_push" />
34+
<Button
35+
android:id="@+id/enable_push"
36+
android:layout_width="match_parent"
37+
android:layout_height="wrap_content"
38+
android:layout_marginStart="1dp"
39+
android:layout_marginTop="1dp"
40+
android:layout_marginEnd="1dp"
41+
android:layout_marginBottom="1dp"
42+
android:text="Enable Push" />
43+
44+
<Button
45+
android:id="@+id/disable_push"
46+
android:layout_width="match_parent"
47+
android:layout_height="wrap_content"
48+
android:layout_marginStart="1dp"
49+
android:layout_marginTop="1dp"
50+
android:layout_marginEnd="1dp"
51+
android:layout_marginBottom="1dp"
52+
android:text="Disable Push" />
53+
54+
<Button
55+
android:id="@+id/prompt_push"
56+
android:layout_width="match_parent"
57+
android:layout_height="wrap_content"
58+
android:layout_marginStart="1dp"
59+
android:layout_marginTop="1dp"
60+
android:layout_marginEnd="1dp"
61+
android:layout_marginBottom="1dp"
62+
android:text="Prompt Push Permission" />
63+
64+
<Button
65+
android:id="@+id/present_iam"
66+
android:layout_width="match_parent"
67+
android:layout_height="wrap_content"
68+
android:layout_marginStart="1dp"
69+
android:layout_marginTop="1dp"
70+
android:layout_marginEnd="1dp"
71+
android:layout_marginBottom="1dp"
72+
android:text="Present In-App Message" />
73+
</LinearLayout>
6874

6975
</androidx.constraintlayout.widget.ConstraintLayout>

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
3-
id 'com.android.application' version '8.0.1' apply false
4-
id 'com.android.library' version '8.0.1' apply false
3+
id 'com.android.application' version '8.0.2' apply false
4+
id 'com.android.library' version '8.0.2' apply false
55
id 'org.jetbrains.kotlin.android' version '1.8.21' apply false
66
}

0 commit comments

Comments
 (0)