Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
App Lounge
Commits
43999e36
Commit
43999e36
authored
Jan 29, 2019
by
Nihar Thakkar
Browse files
Show updates screen when notification is clicked
parent
132dc400
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/foundation/e/apps/MainActivity.kt
View file @
43999e36
...
...
@@ -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
)
...
...
app/src/main/java/foundation/e/apps/updates/UpdatesNotifier.kt
View file @
43999e36
...
...
@@ -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
...
...
app/src/main/java/foundation/e/apps/utils/Constants.kt
View file @
43999e36
...
...
@@ -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"
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment