Skip to content

Commit

Permalink
Merge pull request #3 from OneSignalDevelopers/login-functions
Browse files Browse the repository at this point in the history
Add Login and logout functions
  • Loading branch information
iAmWillShepherd authored Jun 13, 2023
2 parents 5e59803 + 4597c6b commit 3e5493f
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 151 deletions.
49 changes: 35 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
# System files
**/.DS_Store

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Log/OS Files
*.log

# Android Studio generated files and folders
captures/
.externalNativeBuild/
.cxx/
*.apk
output.json

# IntelliJ
*.iml
.idea/
misc.xml
deploymentTargetDropDown.xml
render.experimental.xml

# Keystore files
*.jks
*.keystore

# Google Services (e.g. APIs or Firebase)
google-services.json

# Android Profiling
*.hprof
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/compiler.xml

This file was deleted.

17 changes: 0 additions & 17 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

18 changes: 0 additions & 18 deletions .idea/gradle.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/kotlinc.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/misc.xml

This file was deleted.

43 changes: 23 additions & 20 deletions app/src/main/java/com/onesignal/sample/android/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,29 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
findViewById<Button>(R.id.enable_push).setOnClickListener(
{
OneSignal.User.pushSubscription.optIn()
}
)
findViewById<Button>(R.id.disable_push).setOnClickListener(
{
OneSignal.User.pushSubscription.optOut()
}
)
findViewById<Button>(R.id.prompt_push).setOnClickListener(
{
OneSignal.InAppMessages.addTrigger("show_push_permission_prompt", "1")
}
)
findViewById<Button>(R.id.present_iam).setOnClickListener(
{
OneSignal.InAppMessages.addTrigger("show_sample_iam", "1")
}
)

findViewById<Button>(R.id.login).setOnClickListener {
OneSignal.login("USER_ID")
}

findViewById<Button>(R.id.logout).setOnClickListener {
OneSignal.logout()
}

findViewById<Button>(R.id.enable_push).setOnClickListener {
OneSignal.User.pushSubscription.optIn()
}

findViewById<Button>(R.id.disable_push).setOnClickListener {
OneSignal.User.pushSubscription.optOut()
}

findViewById<Button>(R.id.prompt_push).setOnClickListener {
OneSignal.InAppMessages.addTrigger("show_push_permission_prompt", "1")
}

findViewById<Button>(R.id.present_iam).setOnClickListener {
OneSignal.InAppMessages.addTrigger("show_sample_iam", "1")
}
}
}
114 changes: 60 additions & 54 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,70 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/enable_push"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
android:text="Enable Push"
app:layout_constraintBottom_toTopOf="@+id/disable_push"
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent">

<Button
android:id="@+id/disable_push"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
android:text="Disable Push"
app:layout_constraintBottom_toTopOf="@+id/prompt_push"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/enable_push" />
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login" />

<Button
android:id="@+id/prompt_push"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
android:text="Prompt Push Permission"
app:layout_constraintBottom_toTopOf="@+id/present_iam"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/disable_push" />
<Button
android:id="@+id/logout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Logout" />

<Button
android:id="@+id/present_iam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
android:text="Present In-App Message"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/disable_push" />
<Button
android:id="@+id/enable_push"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
android:text="Enable Push" />

<Button
android:id="@+id/disable_push"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
android:text="Disable Push" />

<Button
android:id="@+id/prompt_push"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
android:text="Prompt Push Permission" />

<Button
android:id="@+id/present_iam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
android:text="Present In-App Message" />
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.0.1' apply false
id 'com.android.library' version '8.0.1' apply false
id 'com.android.application' version '8.0.2' apply false
id 'com.android.library' version '8.0.2' apply false
id 'org.jetbrains.kotlin.android' version '1.8.21' apply false
}

0 comments on commit 3e5493f

Please sign in to comment.