Commit 43999e36 authored by Nihar Thakkar's avatar Nihar Thakkar
Browse files

Show updates screen when notification is clicked

parent 132dc400
......@@ -44,6 +44,8 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
currentFragmentId = if (savedInstanceState != null &&
savedInstanceState.containsKey(CURRENTLY_SELECTED_FRAGMENT_KEY)) {
savedInstanceState.getInt(CURRENTLY_SELECTED_FRAGMENT_KEY)
} else if (intent.hasExtra(Constants.UPDATES_NOTIFICATION_CLICK_EXTRA)) {
R.id.menu_updates
} else {
R.id.menu_home
}
......@@ -101,6 +103,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
}
private fun showFragment(fragment: Fragment) {
bottom_navigation_view.menu.findItem(currentFragmentId).isChecked = true
supportFragmentManager
.beginTransaction()
.replace(R.id.frame_layout, fragment)
......
......@@ -3,10 +3,13 @@ package foundation.e.apps.updates
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.support.v4.app.NotificationCompat
import android.support.v4.app.NotificationManagerCompat
import foundation.e.apps.MainActivity
import foundation.e.apps.R
import foundation.e.apps.utils.Constants
......@@ -35,9 +38,19 @@ class UpdatesNotifier {
notificationBuilder.setContentText(context.getString(R.string.updates_notification_text,
Constants.MANUALLY_INSTALL_UPDATES))
}
notificationBuilder.setContentIntent(getClickIntent(context))
notificationBuilder.setAutoCancel(true)
return notificationBuilder.build()
}
private fun getClickIntent(context: Context): PendingIntent {
val intent = Intent(context, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
putExtra(Constants.UPDATES_NOTIFICATION_CLICK_EXTRA, true)
}
return PendingIntent.getActivity(context, 0, intent, 0)
}
private fun createNotificationChannel(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val importance = NotificationManager.IMPORTANCE_DEFAULT
......
......@@ -35,4 +35,5 @@ object Constants {
const val UPDATES_NOTIFICATION_CHANNEL_TITLE = "App updates"
const val AUTOMATICALLY_INSTALL_UPDATES = "will"
const val MANUALLY_INSTALL_UPDATES = "will not"
const val UPDATES_NOTIFICATION_CLICK_EXTRA = "updates_notification_click_extra"
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment