Skip to content

Commit

Permalink
Merge pull request #153 from DimensionSrl/feature/event-deeplink
Browse files Browse the repository at this point in the history
Event deep link from notification
  • Loading branch information
RudiThoeni authored Dec 18, 2024
2 parents ef92bd2 + 64dea5f commit 7209e8e
Show file tree
Hide file tree
Showing 17 changed files with 416 additions and 237 deletions.
8 changes: 0 additions & 8 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SPDX-License-Identifier: CC0-1.0
package="it.bz.noi.community">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<queries>
<intent>
<action android:name="android.intent.action.DIAL" />
Expand Down
57 changes: 51 additions & 6 deletions app/src/main/java/it/bz/noi/community/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
package it.bz.noi.community

import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.PersistableBundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.asLiveData
Expand All @@ -20,19 +24,17 @@ import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import it.bz.noi.community.ui.onboarding.OnboardingActivity.Companion.LOGOUT_REQUEST
import it.bz.noi.community.databinding.ActivityMainBinding
import it.bz.noi.community.data.repository.AccountsManager
import it.bz.noi.community.databinding.ActivityMainBinding
import it.bz.noi.community.notifications.MessagingService
import it.bz.noi.community.oauth.AuthManager
import it.bz.noi.community.oauth.AuthStateStatus
import it.bz.noi.community.notifications.MessagingService
import it.bz.noi.community.storage.getWelcomeUnderstood
import it.bz.noi.community.ui.WebViewFragment
import it.bz.noi.community.ui.onboarding.OnboardingActivity
import it.bz.noi.community.ui.onboarding.OnboardingActivity.Companion.LOGOUT_REQUEST
import it.bz.noi.community.utils.Utils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import net.openid.appauth.AuthorizationException

class MainActivity : AppCompatActivity() {
Expand All @@ -45,6 +47,17 @@ class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (intent.hasExtra("deep_link")) {
val deepLink = intent.getStringExtra("deep_link")
if (deepLink != null) {
val uri = Uri.parse(deepLink)
startActivity(Intent(Intent.ACTION_VIEW).apply { data = uri })
finish()
return
}
}

window.navigationBarColor = resources.getColor(R.color.background_color, theme)

binding = ActivityMainBinding.inflate(layoutInflater)
Expand Down Expand Up @@ -78,7 +91,7 @@ class MainActivity : AppCompatActivity() {
setupActionBarWithNavController(navController, appBarConfiguration)
binding.navView.setupWithNavController(navController)

navController.addOnDestinationChangedListener { controller, destination, arguments ->
navController.addOnDestinationChangedListener { _, destination, arguments ->
when (destination.id) {
R.id.navigation_more -> {
supportActionBar?.hide()
Expand Down Expand Up @@ -144,6 +157,38 @@ class MainActivity : AppCompatActivity() {
MessagingService.registrationToken()
}
subscribeToNewsTopic(Utils.getPreferredNoiNewsTopic())

checkNotificationPermission()
}

/**
* Very crude solution to quick add notification permission.
*/
private fun checkNotificationPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (ActivityCompat.checkSelfPermission(
this,
android.Manifest.permission.POST_NOTIFICATIONS
) != PackageManager.PERMISSION_GRANTED
) {
ActivityCompat.requestPermissions(
this,
arrayOf(android.Manifest.permission.POST_NOTIFICATIONS),
0
)
}
}
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == 0 && grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Notification permission granted")
}
}

private fun subscribeToNewsTopic(preferredNewsTopic: String) {
Expand Down
18 changes: 14 additions & 4 deletions app/src/main/java/it/bz/noi/community/SplashScreenActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,20 @@ class SplashScreenActivity : AppCompatActivity() {

private fun goToMainActivity() {
if (isFinishing) return
startActivity(Intent(this, MainActivity::class.java).apply {
putExtra(MainActivity.EXTRA_SHOW_WELCOME, runBlocking { !getWelcomeUnderstood() })
})
finish()
if (intent.hasExtra("deep_link")) {
val deepLink = Uri.parse(intent.getStringExtra("deep_link"))
startActivity(Intent(this, MainActivity::class.java).apply {
setData(deepLink)
flags = Intent.FLAG_ACTIVITY_NEW_TASK
putExtra(MainActivity.EXTRA_SHOW_WELCOME, false)
})
finish()
} else {
startActivity(Intent(this, MainActivity::class.java).apply {
putExtra(MainActivity.EXTRA_SHOW_WELCOME, runBlocking { !getWelcomeUnderstood() })
})
finish()
}
}

private fun goToOnboardingActivity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ interface OpendatahubApiService {
@Query("publishedon") publishedOn: String? = "noi-communityapp",
): EventsResponse

@GET("v1/EventShort/Detail/{id}")
@GET("v1/EventShort/{id}")
suspend fun getEventDetails(
@Path("id") eventID: String,
): Event

/*@GET("v1/EventShort/Detail/{id}")
suspend fun getEventDetails(
@Path("id") eventID: String,
@Query("optimizedates") optimizeDates: Boolean = true,
): EventDetailsResponse
): EventDetailsResponse*/

@GET("v1/EventShort/RoomMapping")
suspend fun getRoomMapping(
Expand Down
95 changes: 51 additions & 44 deletions app/src/main/java/it/bz/noi/community/data/models/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,60 @@

package it.bz.noi.community.data.models

import android.os.Parcelable
import androidx.annotation.Keep
import com.google.gson.annotations.SerializedName
import java.util.*
import kotlinx.parcelize.Parcelize
import java.util.Date


data class EventsResponse(
@SerializedName("Items")
val events: List<Event>
) {
data class Event(
@SerializedName("Id")
val eventId: String? = null,
@SerializedName("EventDescription")
val name: String? = null,
@SerializedName("EventDescriptionEN")
val nameEN: String? = null,
@SerializedName("EventDescriptionIT")
val nameIT: String? = null,
@SerializedName("EventDescriptionDE")
val nameDE: String? = null,
@SerializedName("EventTextEN")
val descriptionEN: String? = null,
@SerializedName("EventTextIT")
val descriptionIT: String? = null,
@SerializedName("EventTextDE")
val descriptionDE: String? = null,
@SerializedName("AnchorVenue")
val location: String? = null,
@SerializedName("Display5")
val eventOrganizer: String? = null,
@SerializedName("CompanyName")
val eventOrganizerFallback: String? = null,
@SerializedName("StartDate")
val startDate: Date,
@SerializedName("EndDate")
val endDate: Date,
@SerializedName("TechnologyFields")
val technologyFields: List<String>? = null,
@SerializedName("ImageGallery")
val imageGallery: List<ImageGallery>? = null,
@SerializedName("AnchorVenueRoomMapping")
val roomName: String? = null,
@SerializedName("WebAddress")
val webAddress: String? = null
) {
data class ImageGallery(
@SerializedName("ImageUrl")
val imageUrl: String? = null
)
}
}
)

@Keep
@Parcelize
data class Event(
@SerializedName("Id")
val eventId: String? = null,
@SerializedName("EventDescription")
val name: String? = null,
@SerializedName("EventDescriptionEN")
val nameEN: String? = null,
@SerializedName("EventDescriptionIT")
val nameIT: String? = null,
@SerializedName("EventDescriptionDE")
val nameDE: String? = null,
@SerializedName("EventTextEN")
val descriptionEN: String? = null,
@SerializedName("EventTextIT")
val descriptionIT: String? = null,
@SerializedName("EventTextDE")
val descriptionDE: String? = null,
@SerializedName("AnchorVenue")
val location: String? = null,
@SerializedName("Display5")
val eventOrganizer: String? = null,
@SerializedName("CompanyName")
val eventOrganizerFallback: String? = null,
@SerializedName("StartDate")
val startDate: Date,
@SerializedName("EndDate")
val endDate: Date,
@SerializedName("TechnologyFields")
val technologyFields: List<String>? = null,
@SerializedName("ImageGallery")
val imageGallery: List<ImageGallery>? = null,
@SerializedName("AnchorVenueRoomMapping")
val roomName: String? = null,
@SerializedName("WebAddress")
val webAddress: String? = null
) : Parcelable {
@Keep
@Parcelize
data class ImageGallery(
@SerializedName("ImageUrl")
val imageUrl: String? = null
) : Parcelable
}
Loading

0 comments on commit 7209e8e

Please sign in to comment.