Skip to content

Commit

Permalink
Deeplink notification (owlmail#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
preeti5sharon authored Jul 21, 2023
1 parent cd54a6f commit c3a99e0
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 18 deletions.
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"
android:host="mail.nitrkl.ac.in" />
</intent-filter>
</activity>

<provider
Expand Down
2 changes: 1 addition & 1 deletion auth/src/main/kotlin/github/owlmail/auth/AuthFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AuthFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
savedInstanceState: Bundle?,
): View? {
binding = FragmentAuthBinding.inflate(inflater)
return binding?.root
Expand Down
7 changes: 4 additions & 3 deletions auth/src/main/kotlin/github/owlmail/auth/AuthUseCaseImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package github.owlmail.auth

import github.owlmail.auth.api.AuthState
import github.owlmail.auth.api.AuthUseCase
import github.owlmail.core.DataStoreManager
import github.owlmail.networking.ResponseState
import github.owlmail.networking.mapToResponseState
import kotlinx.coroutines.flow.Flow
Expand All @@ -10,7 +11,7 @@ import kotlinx.coroutines.flow.first

class AuthUseCaseImpl(
private val repository: AuthRepository,
private val dataStoreManager: github.owlmail.core.DataStoreManager
private val dataStoreManager: DataStoreManager,
) : AuthUseCase {

private val loginState = MutableStateFlow<AuthState>(AuthState.UNKNOWN)
Expand Down Expand Up @@ -43,8 +44,8 @@ class AuthUseCaseImpl(

override suspend fun invoke() {
val preferences = dataStoreManager.readFromDataStore().first()
val userid = preferences[github.owlmail.core.DataStoreManager.USER_ID]
val password = preferences[github.owlmail.core.DataStoreManager.PASSWORD]
val userid = preferences[DataStoreManager.USER_ID]
val password = preferences[DataStoreManager.PASSWORD]
if (userid.isNullOrEmpty() || password.isNullOrEmpty()) {
loginState.value = AuthState.NON_AUTHENTICATED
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ class LogoutUseCaseImpl(
)
Unit
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import github.owlmail.contacts.model.ContactResponse
interface
ContactDAO {
@Query(
"select * from contact where fileAsStr like '%' || :query || '%' order by fileAsStr asc limit :limit offset :offset"
"select * from contact where fileAsStr like '%' || :query || '%' order by fileAsStr asc limit :limit offset :offset",
)
suspend fun getAllContacts(
limit: Int,
offset: Int,
query: String
query: String,
): List<ContactResponse.Body.SearchGalResponse.Cn>

@Insert(onConflict = OnConflictStrategy.REPLACE)
Expand Down
4 changes: 2 additions & 2 deletions mail/src/main/kotlin/github/owlmail/mail/HtmlTextView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class HtmlTextView @JvmOverloads constructor(
context: Context,
attributeSet: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = 0
defStyleRes: Int = 0,
) : MaterialTextView(context, attributeSet, defStyleAttr, defStyleRes) {
@Inject
lateinit var imageLoader: ImageLoader
Expand All @@ -24,7 +24,7 @@ class HtmlTextView @JvmOverloads constructor(
html,
HtmlCompat.FROM_HTML_MODE_LEGACY,
HtmlCoilImageLoader(this, imageLoader),
null
null,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class MailDatabaseDeleteUseCaseImpl(
mailDAO.deleteAllMails()
detailDAO.deleteAllMessage()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import androidx.navigation.fragment.findNavController
import dagger.hilt.android.AndroidEntryPoint
import github.owlmail.mail.MailBoxHostFragmentDirections
import github.owlmail.mail.databinding.FragmentMailBinding
import javax.inject.Inject
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import javax.inject.Inject

@AndroidEntryPoint
class MailFragment : Fragment(), OnMailClick {
Expand All @@ -26,7 +26,7 @@ class MailFragment : Fragment(), OnMailClick {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
savedInstanceState: Bundle?,
): View? {
binding = FragmentMailBinding.inflate(inflater)
return binding?.root
Expand Down Expand Up @@ -81,8 +81,8 @@ class MailFragment : Fragment(), OnMailClick {
override fun invoke(conversationUID: String?) {
findNavController().navigate(
MailBoxHostFragmentDirections.actionMailBoxHostFragmentToMailDetailFragment(
conversationUID
)
conversationUID,
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,48 @@ package github.owlmail.mail.manager

import android.app.Notification
import android.app.NotificationChannel
import android.app.PendingIntent
import android.content.Context
import android.content.Context.NOTIFICATION_SERVICE
import android.content.Intent
import android.graphics.Color
import android.os.Build
import androidx.core.app.NotificationManagerCompat
import androidx.core.net.toUri

class NotificationManager(private val context: Context) {
init {
registerNotificationChannel()
createPendingIntent()
}

private val notificationManager = NotificationManagerCompat.from(context)

fun showNotification(notificationId: Int, notification: Notification) {
notification.contentIntent = getPendingIntent()
notificationManager.notify(notificationId, notification)
}

private fun createPendingIntent() {
// Intent(context,)
private fun getPendingIntent(): PendingIntent {
val intent = Intent(Intent.ACTION_VIEW)

intent.setData("https://mail.nitrkl.ac.in/".toUri())
// Create the TaskStackBuilder
val pendingIntent =
PendingIntent.getActivity(
context,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
)
return pendingIntent
}

private fun registerNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
"owlmail_notification_id",
"owlmail_notification_channel",
android.app.NotificationManager.IMPORTANCE_DEFAULT
android.app.NotificationManager.IMPORTANCE_DEFAULT,
).apply {
lightColor = Color.BLUE
enableLights(true)
Expand Down

0 comments on commit c3a99e0

Please sign in to comment.