Skip to content

Commit 5ab415e

Browse files
author
Alexandre Saddour
committed
Use Dimelo.consumeReceivedRemoteNotification in order to display sample notifications
+ clean
1 parent c8bd1f4 commit 5ab415e

File tree

4 files changed

+46
-81
lines changed

4 files changed

+46
-81
lines changed

DimeloSampleApp/app/src/main/java/com/dimelo/sampleapp/NotificationDisplayer.java

-44
This file was deleted.

DimeloSampleApp/app/src/main/java/com/dimelo/sampleapp/chats/TabBank.java

+6-14
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,28 @@
55
import android.support.annotation.Nullable;
66
import android.support.v4.app.Fragment;
77
import android.support.v4.app.FragmentTransaction;
8-
import android.util.DisplayMetrics;
9-
import android.util.TypedValue;
108
import android.view.LayoutInflater;
119
import android.view.View;
1210
import android.view.ViewGroup;
1311
import android.widget.ViewFlipper;
1412

1513
import com.dimelo.dimelosdk.main.Chat;
16-
import com.dimelo.sampleapp.DimeloWrap;
14+
import com.dimelo.dimelosdk.main.Dimelo;
1715
import com.dimelo.sampleapp.R;
1816

1917
public class TabBank extends Fragment implements SampleDimeloTab {
2018
private Chat mDimeloChat;
21-
ViewFlipper mViewFlipper;
19+
private ViewFlipper mViewFlipper;
20+
2221
@Override
2322
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
24-
View v = inflater.inflate(R.layout.tab_bank,container,false);
25-
return v;
23+
return inflater.inflate(R.layout.tab_bank,container,false);
2624
}
2725

2826
@Override
2927
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
3028
super.onViewCreated(view, savedInstanceState);
31-
mDimeloChat = DimeloWrap.getDimelo().newChatFragment();
29+
mDimeloChat = Dimelo.getInstance().newChatFragment();
3230
FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
3331
fragmentTransaction.add(R.id.chat_bank_container, mDimeloChat);
3432
fragmentTransaction.commit();
@@ -46,11 +44,6 @@ public void onClick(View v) {
4644
customize();
4745
}
4846

49-
public int dpToPixel(float dp){
50-
DisplayMetrics displayMetrics = mViewFlipper.getResources().getDisplayMetrics();
51-
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, displayMetrics);
52-
}
53-
5447
private void customize(){
5548

5649
Chat.Customization customisation = mDimeloChat.getCustomization();
@@ -70,10 +63,9 @@ private void customize(){
7063

7164
customisation.systemMessageBackgroundColor = Color.WHITE;
7265
customisation.systemMessageTextColor = Color.WHITE;
73-
7466
customisation.dateTextColor = Color.WHITE;
7567

76-
customisation.apply(); // Always call apply to register your changes
68+
customisation.apply();
7769
}
7870

7971
@Override

DimeloSampleApp/app/src/main/java/com/dimelo/sampleapp/chats/TabStart.java

+37-19
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@
88
import android.view.View;
99
import android.view.ViewGroup;
1010

11-
import com.dimelo.sampleapp.DimeloWrap;
12-
import com.dimelo.sampleapp.NotificationDisplayer;
11+
import com.dimelo.dimelosdk.main.Dimelo;
1312
import com.dimelo.sampleapp.R;
1413

14+
import org.json.JSONException;
15+
import org.json.JSONObject;
16+
17+
import java.util.Date;
1518
import java.util.Random;
19+
import java.util.UUID;
1620

1721
public class TabStart extends Fragment implements SampleDimeloTab {
1822

1923
Random random;
2024

2125
@Override
2226
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
23-
View v =inflater.inflate(R.layout.tab_start,container,false);
24-
return v;
27+
return inflater.inflate(R.layout.tab_start, container, false);
2528
}
2629

2730
@Override
@@ -30,7 +33,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
3033

3134
random = new Random();
3235

33-
Fragment dimeloChat = DimeloWrap.getDimelo().newChatFragment();
36+
Fragment dimeloChat = Dimelo.getInstance().newChatFragment();
3437

3538
FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
3639
fragmentTransaction.add(R.id.chat_start_container, dimeloChat);
@@ -39,39 +42,54 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
3942
setListeners(view);
4043
}
4144

45+
private void sendNotificationExample(String message){
46+
JSONObject notif = new JSONObject();
47+
try {
48+
notif.put("t", "m");
49+
notif.put("uuid", UUID.randomUUID().toString());
50+
notif.put("d", new Date().getTime() / 1000);
51+
notif.put("tr", true);
52+
} catch (JSONException e) {
53+
e.printStackTrace();
54+
}
55+
56+
Bundle payload = new Bundle();
57+
payload.putString("appdata", notif.toString());
58+
payload.putString("dimelo", "1.0");
59+
payload.putString("alert", message);
60+
Dimelo.consumeReceivedRemoteNotification(getActivity(), payload, null);
61+
}
62+
63+
4264
private void setListeners(final View root){
4365
root.findViewById(R.id.open_full_screen).setOnClickListener(new View.OnClickListener() {
4466
@Override
4567
public void onClick(View v) {
46-
DimeloWrap.getDimelo().openChatActivity(getActivity());
68+
Dimelo.getInstance().openChatActivity(getActivity());
4769
}
4870
});
4971
root.findViewById(R.id.short_notif).setOnClickListener(new View.OnClickListener() {
5072
@Override
5173
public void onClick(View v) {
52-
String[] messages = {"Hi!", "Hello", "What's up?", "Thanks!", "Kthanxbye", "Thank you!", "OMG, REALLY?", "I don't think so.", "Maybe tomorrow.", "How about next Tuesday?", "This weekend is fine by me.", "Slightly longer message to be displayed as a non-truncated one."};
53-
NotificationDisplayer.show(root.getContext(), messages[random.nextInt(messages.length - 1)]);
74+
String[] messages = {"Hi!", "Hello", "What's up?", "Thanks!", "Kthanxbye", "Thank you!", "OMG, REALLY?", "I don't think so.", "Maybe tomorrow.", "How about next Tuesday?", "This weekend is fine by me.", "Slightly longer message to be displayed as a non-truncated one."};
75+
sendNotificationExample(messages[random.nextInt(messages.length - 1)]);
5476
}
5577
});
5678

5779
root.findViewById(R.id.long_notif).setOnClickListener(new View.OnClickListener() {
5880
@Override
5981
public void onClick(View v) {
60-
String[] messages = {
61-
"In order to activate your account, please follow these simple steps:\n1. Go to www.mybank.example.com.\n2. Click Personal Account.\n3. Find Activate Your Account button on the left of the screen.\n4. Click it and live happily everafter.",
62-
"We are glad to hear from you. One of the available agents will swiftly contact you to respond to your inquiry. Thank you!",
63-
"Unfortunately, time is over. We cannot support this conversation longer. Please leave this chat and try to solve your problem on your own. Thank you for your understanding.",
64-
"This is a rather long message intended to be truncated when displayed on the lock screen. We hope you understand our intention here.",
65-
"Once upon a time there was a little bear-the-pooh who was searching for a pot of honey everywhere."};
66-
NotificationDisplayer.show(root.getContext(), messages[random.nextInt(messages.length - 1)]);
82+
String[] messages = {
83+
"In order to activate your account, please follow these simple steps:\n1. Go to www.mybank.example.com.\n2. Click Personal Account.\n3. Find Activate Your Account button on the left of the screen.\n4. Click it and live happily everafter.",
84+
"We are glad to hear from you. One of the available agents will swiftly contact you to respond to your inquiry. Thank you!",
85+
"Unfortunately, time is over. We cannot support this conversation longer. Please leave this chat and try to solve your problem on your own. Thank you for your understanding.",
86+
"This is a rather long message intended to be truncated when displayed on the lock screen. We hope you understand our intention here.",
87+
"Once upon a time there was a little bear-the-pooh who was searching for a pot of honey everywhere."};
88+
sendNotificationExample(messages[random.nextInt(messages.length - 1)]);
6789
}
6890
});
6991
}
7092

71-
private void customize(){
72-
73-
}
74-
7593
@Override
7694
public boolean isChatDisplayed(){
7795
return false;

DimeloSampleApp/app/src/main/java/com/dimelo/sampleapp/chats/TabSupport.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,22 @@
1010
import android.view.ViewGroup;
1111

1212
import com.dimelo.dimelosdk.main.Chat;
13-
import com.dimelo.sampleapp.DimeloWrap;
13+
import com.dimelo.dimelosdk.main.Dimelo;
1414
import com.dimelo.sampleapp.R;
1515

1616
public class TabSupport extends Fragment implements SampleDimeloTab {
1717
Chat mDimeloChat;
1818

1919
@Override
2020
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
21-
View v = inflater.inflate(R.layout.tab_support,container,false);
22-
return v;
21+
return inflater.inflate(R.layout.tab_support,container,false);
2322
}
2423

2524
@Override
2625
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
2726
super.onViewCreated(view, savedInstanceState);
2827

29-
mDimeloChat = DimeloWrap.getDimelo().newChatFragment();
28+
mDimeloChat = Dimelo.getInstance().newChatFragment();
3029
FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
3130
fragmentTransaction.add(R.id.chat_support_container, mDimeloChat);
3231
fragmentTransaction.commit();

0 commit comments

Comments
 (0)