Skip to content

Commit

Permalink
notification added
Browse files Browse the repository at this point in the history
  • Loading branch information
W3-Aziz committed Dec 17, 2018
1 parent 0e2a545 commit 2fffcd0
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .idea/assetWizardSettings.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/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'androidx.navigation.safeargs'


android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class MainActivity : AppCompatActivity(), NavController.OnNavigatedListener {
navController = navHostFragment.navController

navController.addOnNavigatedListener(this)

}

override fun onSupportNavigateUp(): Boolean {
Expand All @@ -40,6 +41,7 @@ class MainActivity : AppCompatActivity(), NavController.OnNavigatedListener {

override fun onNavigated(controller: NavController, destination: NavDestination) {
val title = destination.label
Log.e("Item_list", "destination "+title )
supportActionBar!!.title = title
if(title!!.equals("Chat") || title!!.equals("Profile image")){
toggleBottomView(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SplashActivity : AppCompatActivity(){
private fun gotoNextPage(){
onUiThread(1000,{
startActivity<MainActivity>()
overridePendingTransition(R.anim.slide_to_left, R.anim.slide_to_left)
//overridePendingTransition(R.anim.slide_to_left, R.anim.slide_to_left)
finish()
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.*
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.w3engineers.jitpackbottomnav.R
import com.w3engineers.jitpackbottomnav.util.NotificationUtil


/*
Expand Down Expand Up @@ -40,10 +41,15 @@ class ProfileImageFragment : Fragment() {

override fun onOptionsItemSelected(item: MenuItem?): Boolean {
return when (item?.itemId) {
R.id.share_menu->{
Toast.makeText(activity,"Share menu", Toast.LENGTH_SHORT).show()
R.id.share_menu -> {
Toast.makeText(activity, "Share menu", Toast.LENGTH_SHORT).show()
return true
} else -> super.onOptionsItemSelected(item)
}
R.id.notify_menu -> {
NotificationUtil.showNotification()
return true
}
else -> super.onOptionsItemSelected(item)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class HistoryViewModel : ViewModel() {
// val message = messageBox.query().equal(Message_.friendsId, it.userId).build().find(1, 1)

fun getUserLiveData(): List<User> {
val customerIds = userBox.query().build().findIds();
//messageBox.query().`in`(Message_.id, customerIds).filter { }

val users = userBox.all
val history = ArrayList<User>()
for (user: User in users) {
Expand All @@ -45,7 +48,6 @@ class HistoryViewModel : ViewModel() {
history.add(user)
}
}

return history
}

Expand All @@ -60,7 +62,6 @@ class HistoryViewModel : ViewModel() {
.find(1, 1)
if (messsage != null && messsage.size > 0) {
user.lastMessage = messsage.get(0).message

}
return user
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ class HomeFragment : BaseFragment(), ItemClickListener<User> {
}
else -> {
val bundle = Bundle()
Log.e("user_id", "User id ="+item.userId)
bundle.putParcelable("user", item)
Navigation.findNavController(view!!).navigate(R.id.open_profile, bundle)
Navigation.findNavController(view!!).navigate(R.id.open_chat_page, bundle)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.w3engineers.jitpackbottomnav.util

import android.os.Bundle
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.navigation.NavDeepLinkBuilder
import androidx.navigation.Navigation
import com.w3engineers.jitpackbottomnav.App
import com.w3engineers.jitpackbottomnav.R
import com.w3engineers.jitpackbottomnav.data.model.User
import com.w3engineers.jitpackbottomnav.data.model.User_
import com.w3engineers.jitpackbottomnav.fragment.home.HomeFragmentDirections


/*
* ****************************************************************************
* * Created by : Md. Azizul Islam on 12/17/2018 at 12:43 PM.
* * Email : azizul@w3engineers.com
* *
* * Purpose:
* *
* * Last edited by : Md. Azizul Islam on 12/17/2018.
* *
* * Last Reviewed by : <Reviewer Name> on <mm/dd/yy>
* ****************************************************************************
*/

object NotificationUtil {

fun showNotification() {
val user = App.getBoxStore().boxFor(User::class.java).all
/*
val args = Bundle().apply {
putParcelable("user", user.get(0))
}
*/

// Prepare the pending intent, while specifying the graph and destination
val pendingIndent = NavDeepLinkBuilder(App.getContext())
.setGraph(R.navigation.bottom_nav_graph)
.setDestination(R.id.fragment_chat)
.setArguments(HomeFragmentDirections.openChatPage(user.get(0)).arguments)
.createPendingIntent()


// Create notification instance
val notification = NotificationCompat.Builder(App.getContext(), "navigation")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Explicit deep link")
.setContentText("Clicking on this notification will take you to the destination fragment")
.setContentIntent(pendingIndent)
.setAutoCancel(true)
.build()

// Display notification
NotificationManagerCompat.from(App.getContext()).notify(10, notification)
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_notifications.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFAFA"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.9,2 2,2zM18,16v-5c0,-3.07 -1.63,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.64,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2zM16,17L8,17v-6c0,-2.48 1.51,-4.5 4,-4.5s4,2.02 4,4.5v6z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/menu/menu_profile_img.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
android:icon="@drawable/ic_share"
android:title="Share"
app:showAsAction="always"/>

<item android:id="@+id/notify_menu"
android:icon="@drawable/ic_notifications"
android:title="Share"
app:showAsAction="always"/>
</menu>
6 changes: 5 additions & 1 deletion app/src/main/res/navigation/bottom_nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:label="Home"
tools:layout="@layout/fragment_home">

<action android:id="@+id/open_profile"
<action android:id="@+id/open_chat_page"
app:destination="@id/fragment_chat"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
Expand Down Expand Up @@ -50,6 +50,10 @@
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"/>
<argument
android:name="user"
app:nullable="true"
app:argType="com.w3engineers.jitpackbottomnav.data.model.User"/>
</fragment>

<fragment
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
classpath 'android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha04'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down

0 comments on commit 2fffcd0

Please sign in to comment.