Skip to content

Commit 7d90fd4

Browse files
1) Add try catch where is needed and handle unconditional exception.
3) New Sdk version is 2.3.21
1 parent 1df2fa3 commit 7d90fd4

File tree

10 files changed

+214
-135
lines changed

10 files changed

+214
-135
lines changed

Diff for: app/src/main/java/com/onefeed/sdk/sample/DemoActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void onClick(View view) {
104104
demoNotification.put("story_id", "60496");
105105
// demoNotification.put("noid", "10001");
106106
demoNotification.put("story_title", "20 DC Characters Who Could Easily Defeat Thanos");
107-
demoNotification.put("cover_image", "https://cdn.geeksmate.io/71629/20-DC-Characters-Who-Could-Defeat-Thanos-41.jpeg");
107+
demoNotification.put("cover_image", "https://dwybwpx76p5im.cloudfront.net/71629/20-DC-Characters-Who-Could-Defeat-Thanos-41.jpeg");
108108
demoNotification.put("story_url", "https://www.geeksmate.io/dc-characters-defeat-thanos-seconds-71629?utm_source=SDK&utm_medium=noti&utm_campaign=38237-campaign&utm_hash=108_71629&noid=5385987&sdk_aid=108");
109109

110110
demoNotification.put("id", "400");

Diff for: onefeedsdk/src/main/java/com/onefeedsdk/app/Constant.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@
77
* Time: 18:10
88
*/
99

10+
1011
public interface Constant {
1112

1213
String BASE_URL = "https://api.wittyfeed.com/Sdk/";
1314
//String BASE_URL = "http://192.168.2.31/services/Sdk/";
1415
String ERROR_TRACKING_URL = "https://apptrackerr.onefeed.ai/";
1516
String ERROR_TRACKING = "apptrackerr";
1617

17-
String HOME_FEED = "home_feed_v5";
18-
//String HOME_FEED = "home_feed_v5_testpage";
18+
//String HOME_FEED = "home_feed_v5";
19+
String HOME_FEED = "home_feed_v5_testpage";
1920
String SEARCH_FEED = "search_v5";
2021
String SEARCH_BY_APP = "search_v5_1";
2122

2223
String TRACKING_URL = "https://apptrack.onefeed.ai/";
2324
String TRACKING = "apptrack";
25+
String STORY_TRACKING = "storytrack";
26+
String DEViCE_TRACKING = "devicetrack";
2427
String TOKEN_UPDATE = "fetchFcmToken";
2528

2629
String SEARCH_CARD = "SEARCH_CARD";

Diff for: onefeedsdk/src/main/java/com/onefeedsdk/app/OneFeedSdk.java

+42-21
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.os.Bundle;
1111
import android.support.annotation.NonNull;
1212
import android.support.annotation.Nullable;
13+
import android.text.TextUtils;
1314
import android.util.Log;
1415

1516
import com.birbit.android.jobqueue.JobManager;
@@ -45,7 +46,7 @@
4546
public class OneFeedSdk {
4647

4748
private static final String PREF_DEFAULT = "share-app-pref";
48-
public final String VERSION = "2.3.21";
49+
public final String VERSION = "2.3.22";
4950
public static final String WATER_FALL = "Waterfall";
5051
public static final String H_List = "H-List";
5152
public static final String V_List = "V-List";
@@ -154,13 +155,17 @@ private void initRest() {
154155
}
155156

156157
private void initJobManager() {
157-
Configuration configuration = new Configuration.Builder(context)
158-
.minConsumerCount(1)
159-
.maxConsumerCount(3)
160-
.loadFactor(3)
161-
.consumerKeepAlive(120)
162-
.build();
163-
jobManager = new JobManager(configuration);
158+
try {
159+
Configuration configuration = new Configuration.Builder(context)
160+
.minConsumerCount(1)
161+
.maxConsumerCount(3)
162+
.loadFactor(3)
163+
.consumerKeepAlive(120)
164+
.build();
165+
jobManager = new JobManager(configuration);
166+
}catch (Exception e){
167+
168+
}
164169
}
165170

166171
private void initRuntimeStore() {
@@ -251,7 +256,12 @@ public void setTopicSubscription() {
251256
}
252257

253258
public String getOldTopicSubscribe() {
254-
return OneFeedSdk.getInstance().getDefaultAppSharedPreferences().getString(Constant.TOPIC, "");
259+
try {
260+
return OneFeedSdk.getInstance().getDefaultAppSharedPreferences().getString(Constant.TOPIC, "");
261+
} catch (Exception e) {
262+
log.error(e.getMessage());
263+
return "";
264+
}
255265
}
256266

257267
public String getCustomTopic() {
@@ -263,13 +273,16 @@ public void setCustomTopic(String customTopic) {
263273
}
264274

265275
private void initializeSdk() {
266-
267-
//Initialize feed
268-
OneFeedSdk.getInstance().getJobManager().addJobInBackground(new GetHomeFeedJob(false, 0));
269-
270-
//Tracking
271-
OneFeedSdk.getInstance().getJobManager().addJobInBackground(
272-
new PostUserTrackingJob(Constant.SDK_INITIALISED, Constant.APP_INIT));
276+
try {
277+
//Initialize feed
278+
OneFeedSdk.getInstance().getJobManager().addJobInBackground(new GetHomeFeedJob(false, 0));
279+
280+
//Tracking
281+
OneFeedSdk.getInstance().getJobManager().addJobInBackground(
282+
new PostUserTrackingJob(Constant.SDK_INITIALISED, Constant.APP_INIT));
283+
}catch (Exception e){
284+
log.error(e.getMessage());
285+
}
273286
}
274287

275288
private void startService() {
@@ -287,16 +300,24 @@ private void startService() {
287300

288301
//Search Api for user
289302
public void searchStoriesByKeyword(@NonNull String keyword, @NonNull AddResponseListener listener) {
290-
OneFeedSdk.getInstance().jobManager
291-
.addJobInBackground(new GetSearchFeedJob(keyword, listener));
303+
304+
try {
305+
OneFeedSdk.getInstance().jobManager
306+
.addJobInBackground(new GetSearchFeedJob(keyword, listener));
307+
}catch (Exception e){
308+
log.error(e.getMessage());
309+
}
292310
}
293311

294312

295313
//Call Api for taking User Interest
296314
public void setUserInterests(String category, String userAction, String token, @NonNull AddResponseListener listener) {
297-
298-
OneFeedSdk.getInstance().jobManager
299-
.addJobInBackground(new PostUserInterestsJob(Constant.USER_INTERESTS, userAction, category, token, listener));
315+
try {
316+
OneFeedSdk.getInstance().jobManager
317+
.addJobInBackground(new PostUserInterestsJob(Constant.USER_INTERESTS, userAction, category, token, listener));
318+
}catch (Exception e){
319+
log.error(e.getMessage());
320+
}
300321
}
301322

302323
private void getInstallAppInfo() {

Diff for: onefeedsdk/src/main/java/com/onefeedsdk/job/PostTokenUpdateJob.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ public void onRun() throws Throwable {
5757
responseListener.success();
5858
}
5959
} else {
60-
OneFeedSdk.getInstance().getJobManager().addJobInBackground(new PostUserTrackingJob(Constant.SDK_ERROR, s.getResponse()));
60+
OneFeedSdk.getInstance().getJobManager().addJobInBackground(new PostErrorTrackingJob("TokenUpdate", s.getResponse()));
6161
}
6262
} catch (Exception e) {
6363

64-
OneFeedSdk.getInstance().getJobManager().addJobInBackground(new PostUserTrackingJob(Constant.SDK_ERROR, e.getMessage()));
6564
//Error Tracking
6665
OneFeedSdk.getInstance().getJobManager().addJobInBackground(new PostErrorTrackingJob("TokenUpdate", e.getMessage()));
6766

Diff for: onefeedsdk/src/main/java/com/onefeedsdk/job/PostUserTrackingJob.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public PostUserTrackingJob(String type, String resource) {
4242
if (Constant.SDK_INITIALISED.equalsIgnoreCase(type)) {
4343
String oldToken = OneFeedSdk.getInstance().getDefaultAppSharedPreferences().getString(Constant.TOKEN, "");
4444
model.setToken(oldToken);
45-
}else if(Constant.SDK_ERROR.equalsIgnoreCase(type)){
45+
} else if (Constant.SDK_ERROR.equalsIgnoreCase(type)) {
4646
model.setAction("FCM Update");
4747
}
4848
}
@@ -56,7 +56,7 @@ public PostUserTrackingJob(String type, String resource, String s) {
5656
model = new TrackingModel();
5757
if (Constant.SEARCH_VIEWED.equalsIgnoreCase(type)) {
5858
model.setSearchString(s);
59-
}else {
59+
} else {
6060
model.setStoryId(s);
6161
}
6262
}
@@ -111,7 +111,22 @@ public void onAdded() {
111111
public void onRun() throws Throwable {
112112
try {
113113

114-
Call<String> call = OneFeedSdk.getInstance().getApiFactory().getTrackingApi().userTracking(model);
114+
Call<String> call = null;
115+
if (Constant.SDK_INITIALISED.equalsIgnoreCase(type)
116+
|| Constant.SIM_CHANGE.equalsIgnoreCase(type)
117+
|| Constant.PLUG_IN.equalsIgnoreCase(type) || Constant.PLUG_OUT.equalsIgnoreCase(type)
118+
|| Constant.HEAD_SET_IN.equalsIgnoreCase(type) || Constant.HEAD_SET_OUT.equalsIgnoreCase(type)
119+
|| Constant.SCREEN_UNLOCK.equalsIgnoreCase(type) || Constant.APP_LIST.equalsIgnoreCase(type)) {
120+
121+
call = OneFeedSdk.getInstance().getApiFactory().getTrackingApi().deviceTracking(model);
122+
} else if (Constant.STORY_OPENED.equalsIgnoreCase(type)) {
123+
124+
call = OneFeedSdk.getInstance().getApiFactory().getTrackingApi().storyTracking(model);
125+
} else {
126+
127+
call = OneFeedSdk.getInstance().getApiFactory().getTrackingApi().userTracking(model);
128+
}
129+
//call = OneFeedSdk.getInstance().getApiFactory().getTrackingApi().userTracking(model);
115130
String result = call.execute().body();
116131
Log.e("Tracking - " + type, result);
117132

Diff for: onefeedsdk/src/main/java/com/onefeedsdk/notification/NotificationHelper.java

+57-43
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.content.Context;
88
import android.content.Intent;
99
import android.graphics.Bitmap;
10+
import android.graphics.drawable.Drawable;
1011
import android.media.Ringtone;
1112
import android.media.RingtoneManager;
1213
import android.net.Uri;
@@ -92,6 +93,12 @@ protected void onPostExecute(String aVoid) {
9293
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
9394
sendNotification(context, activity, model, resource, icon);
9495
}
96+
97+
@Override
98+
public void onLoadFailed(@Nullable Drawable errorDrawable) {
99+
super.onLoadFailed(errorDrawable);
100+
sendNotification(context, activity, model, null, icon);
101+
}
95102
});
96103
}
97104
}.execute();
@@ -100,51 +107,58 @@ public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? sup
100107
}
101108

102109
public static void sendNotification(Context context, Class activity, NotificationModel data, Bitmap myBitmap, int icon) {
103-
104-
Intent intent = new Intent(context, NotificationOpenActivity.class);
105-
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
106-
intent.putExtra(Constant.NOTIFICATION, true);
107-
intent.putExtra(Constant.ACTIVITY, activity);
108-
intent.putExtra(Constant.MODEL, data);
109-
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 /* Request code */, intent,
110-
PendingIntent.FLAG_ONE_SHOT);
111-
112-
OneFeedSdk.getInstance().getJobManager().addJobInBackground(
113-
new PostUserTrackingJob(Constant.NOTIFICATION_RECEIVED, Constant.NOTIFICATION, data.getStoryId(), data.getNoId()));
114-
115-
String channelId = "DEFAULT";
116-
NotificationCompat.Builder notificationBuilder =
117-
new NotificationCompat.Builder(context, channelId)
118-
.setSmallIcon(icon)
119-
.setContentTitle(data.getTitle())
120-
.setContentText(data.getBody())
121-
.setLargeIcon(myBitmap)
122-
.setStyle(new NotificationCompat.BigPictureStyle()
123-
.bigPicture(myBitmap))
124-
.setAutoCancel(true)
125-
.setDefaults(Notification.DEFAULT_SOUND)
126-
.setContentIntent(pendingIntent);
127-
128-
// Since android Oreo notification channel is needed.
129-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
130-
NotificationChannel channel = new NotificationChannel(channelId,
131-
"Channel human readable title",
132-
NotificationManager.IMPORTANCE_DEFAULT);
133-
notificationManager.createNotificationChannel(channel);
134-
}
135110
try {
136-
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
137-
Ringtone r = RingtoneManager.getRingtone(context, notification);
138-
r.play();
139-
} catch (Exception e) {
140-
e.printStackTrace();
141-
}
142-
int noId = 0;
143-
try{
144-
noId = Integer.parseInt(data.getNoId());
111+
Intent intent = new Intent(context, NotificationOpenActivity.class);
112+
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
113+
intent.putExtra(Constant.NOTIFICATION, true);
114+
intent.putExtra(Constant.ACTIVITY, activity);
115+
intent.putExtra(Constant.MODEL, data);
116+
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 /* Request code */, intent,
117+
PendingIntent.FLAG_ONE_SHOT);
118+
119+
OneFeedSdk.getInstance().getJobManager().addJobInBackground(
120+
new PostUserTrackingJob(Constant.NOTIFICATION_RECEIVED, Constant.NOTIFICATION, data.getStoryId(), data.getNoId()));
121+
122+
String channelId = "DEFAULT";
123+
NotificationCompat.Builder notificationBuilder =
124+
new NotificationCompat.Builder(context, channelId)
125+
.setSmallIcon(icon)
126+
.setContentTitle(data.getTitle())
127+
.setContentText(data.getBody())
128+
.setAutoCancel(true)
129+
.setDefaults(Notification.DEFAULT_SOUND)
130+
.setContentIntent(pendingIntent);
131+
132+
if (myBitmap != null) {
133+
notificationBuilder.setLargeIcon(myBitmap);
134+
notificationBuilder.setStyle(new NotificationCompat.BigPictureStyle()
135+
.bigPicture(myBitmap));
136+
}
137+
138+
139+
// Since android Oreo notification channel is needed.
140+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
141+
NotificationChannel channel = new NotificationChannel(channelId,
142+
"Channel human readable title",
143+
NotificationManager.IMPORTANCE_DEFAULT);
144+
notificationManager.createNotificationChannel(channel);
145+
}
146+
try {
147+
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
148+
Ringtone r = RingtoneManager.getRingtone(context, notification);
149+
r.play();
150+
} catch (Exception e) {
151+
e.printStackTrace();
152+
}
153+
int noId = 0;
154+
try {
155+
noId = Integer.parseInt(data.getNoId());
156+
} catch (Exception e) {
157+
noId = (int) SystemClock.currentThreadTimeMillis();
158+
}
159+
notificationManager.notify(noId/* ID of notification */, notificationBuilder.build());
145160
}catch (Exception e){
146-
noId = (int) SystemClock.currentThreadTimeMillis();
161+
147162
}
148-
notificationManager.notify(noId/* ID of notification */, notificationBuilder.build());
149163
}
150164
}

Diff for: onefeedsdk/src/main/java/com/onefeedsdk/rest/ApiFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private void init() {
3939

4040
// set your desired log level
4141
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
42-
logging.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BASIC : HttpLoggingInterceptor.Level.NONE);
42+
logging.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);
4343

4444
//okHttpClient
4545
okHttpClient = new OkHttpClient.Builder()

Diff for: onefeedsdk/src/main/java/com/onefeedsdk/rest/api/Api.java

+6
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ Call<FeedModel> searchByApp(@Query("keyword") String keyword,
6767
@POST(Constant.TRACKING)
6868
Call<String> userTracking(@Body TrackingModel model);
6969

70+
@POST(Constant.STORY_TRACKING)
71+
Call<String> storyTracking(@Body TrackingModel model);
72+
73+
@POST(Constant.DEViCE_TRACKING)
74+
Call<String> deviceTracking(@Body TrackingModel model);
75+
7076
@POST(Constant.ERROR_TRACKING)
7177
Call<String> errorTracking(@Body TrackingModel model);
7278
}

Diff for: onefeedsdk/src/main/java/com/onefeedsdk/ui/NotificationOpenActivity.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import com.onefeedsdk.app.Constant;
1010
import com.onefeedsdk.app.OneFeedSdk;
11+
import com.onefeedsdk.job.PostErrorTrackingJob;
1112
import com.onefeedsdk.job.PostUserTrackingJob;
1213
import com.onefeedsdk.model.NotificationModel;
1314
import com.onefeedsdk.util.Util;
@@ -62,7 +63,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
6263
Util.showCustomTabBrowserByCard(this, color, title, url, storyId, resc, isFeed);
6364
}
6465
} catch (Exception e) {
65-
66+
//Error Tracking
67+
OneFeedSdk.getInstance().getJobManager().addJobInBackground(new PostErrorTrackingJob("Notification Receive", e.getMessage()));
6668
}
6769
}
6870

0 commit comments

Comments
 (0)