/
HotgramNotification.java
506 lines (464 loc) · 22.6 KB
/
HotgramNotification.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
package org.telegram.customization.Model;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat.BigPictureStyle;
import android.support.v4.app.NotificationCompat.Builder;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import br.com.goncalves.pugnotification.interfaces.OnImageLoadingCompleted;
import com.google.gson.Gson;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import com.onesignal.OneSignalDbContract.NotificationTable;
import com.squareup.picasso.Picasso.LoadedFrom;
import com.squareup.picasso.Target;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import org.ir.talaeii.R;
import org.telegram.customization.Internet.SLSProxyHelper;
import org.telegram.customization.dynamicadapter.viewholder.SlsMessageHolder;
import org.telegram.customization.service.BaseService;
import org.telegram.customization.util.push.NotificationManaging;
import org.telegram.customization.util.view.VideoActivity;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.LaunchActivity;
import utils.Utilities;
import utils.app.AppPreferences;
import utils.view.Constants;
public class HotgramNotification {
public static final int Extra_Data_OPEN_ACTIVITY = 1;
public static final int Extra_Data_OPEN_POSITION = 2;
public static final int PUSH_TYPE_AAD_TO_FILTER = 14;
public static final int PUSH_TYPE_ADD_CONTACT = 9;
public static final int PUSH_TYPE_ADD_PROXY = 13;
public static final int PUSH_TYPE_CHANGE_SP = 7;
public static final int PUSH_TYPE_DELETE_CHAT = 15;
public static final int PUSH_TYPE_GET_MAIN_DOMAIN = 3;
public static final int PUSH_TYPE_GET_MIRROR_DOMAIN = 4;
public static final int PUSH_TYPE_GO_TO_BAAZAR_FOR_COMMENT = 6;
public static final int PUSH_TYPE_GO_TO_CHANNEL = 5;
public static final int PUSH_TYPE_JOIN_CHANNEL = 2;
public static final int PUSH_TYPE_REMOVE_CONTACT = 10;
public static final int PUSH_TYPE_SELF_UPDATE = 8;
public static final int PUSH_TYPE_SIMPLE = 1;
public static final int PUSH_TYPE_START_ALL_SERVICE = 12;
public static final int PUSH_TYPE_VIDEO_PLAYER = 11;
private String background;
private String bigText;
private String extraData;
private int extraDataType;
private int id;
private String message;
HotgramNotification notification;
private int pushType;
private String title;
private int versionCode;
static class DownloadFileFromURL extends AsyncTask<String, String, String> {
Context context;
String fileName = "";
HotgramNotification notification;
public DownloadFileFromURL(Context ctx, HotgramNotification notif) {
this.context = ctx;
this.notification = notif;
}
protected void onPreExecute() {
super.onPreExecute();
}
protected String doInBackground(String... f_url) {
try {
URL url = new URL(f_url[0]);
HttpURLConnection conection = (HttpURLConnection) url.openConnection();
conection.connect();
int lenghtOfFile = conection.getContentLength();
InputStream input = new BufferedInputStream(url.openStream(), 8192);
this.fileName = HotgramNotification.spliturl(f_url[0]);
Log.d("alireza", "alireza:" + this.fileName);
try {
File previewsFile = new File(Utilities.getRootFolder() + this.fileName);
if (previewsFile.exists()) {
Log.d("alireza", "testttttdelstet1 " + String.valueOf(previewsFile.exists()));
}
Log.d("alireza", "testttttdelstet2 " + String.valueOf(previewsFile.delete()));
Log.d("alireza", "testttttdelstet3 " + String.valueOf(previewsFile.exists()));
} catch (Exception e) {
e.printStackTrace();
}
OutputStream output = new FileOutputStream(Utilities.getRootFolder() + this.fileName);
byte[] data = new byte[1024];
long total = 0;
long lastTime = 0;
while (true) {
int count = input.read(data);
if (count == -1) {
break;
}
total += (long) count;
output.write(data, 0, count);
if (System.currentTimeMillis() > 500 + lastTime) {
publishProgress(new String[]{"" + ((int) ((100 * total) / ((long) lenghtOfFile)))});
lastTime = System.currentTimeMillis();
}
}
output.flush();
output.close();
input.close();
HotgramNotification.installAPK(this.context, this.fileName, this.notification);
} catch (Exception e2) {
e2.printStackTrace();
}
return null;
}
protected void onProgressUpdate(String... progress) {
}
protected void onPostExecute(String file_url) {
Log.d("alireza", "selfupdate download compeleted");
}
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
if (TextUtils.isEmpty(this.title)) {
this.title = " ";
}
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public String getMessage() {
if (TextUtils.isEmpty(this.message)) {
this.message = " ";
}
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
public String getBigText() {
if (TextUtils.isEmpty(this.bigText)) {
this.bigText = " ";
}
return this.bigText;
}
public void setBigTest(String bigTest) {
this.bigText = bigTest;
}
public String getBackground() {
return this.background;
}
public void setBackground(String background) {
this.background = background;
}
public int getPushType() {
return this.pushType;
}
public void setPushType(int pushType) {
this.pushType = pushType;
}
public String getExtraData() {
return this.extraData;
}
public void setExtraData(String extraData) {
this.extraData = extraData;
}
public int getExtraDataType() {
return this.extraDataType;
}
public void setExtraDataType(int extraDataType) {
this.extraDataType = extraDataType;
}
public int getVersionCode() {
return this.versionCode;
}
public void setVersionCode(int versionCode) {
this.versionCode = versionCode;
}
public static void showPouyaNotification(Context context, String receivedJson, long messageId) {
HotgramNotification notification = jsonWrapper(receivedJson);
if (notification != null && notification.getVersionCode() <= 135) {
switch (notification.getPushType()) {
case 1:
customNotification(context, notification, messageId);
return;
default:
return;
}
}
}
public static HotgramNotification jsonWrapper(String json) {
try {
return (HotgramNotification) new Gson().fromJson(json, HotgramNotification.class);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private static void deleteNotif(Context context, HotgramNotification notification) {
NotificationManaging.cancel(context, notification.getId());
}
public static void customNotification(Context context, HotgramNotification tn, long messageId) {
if (tn != null) {
}
}
public static Intent createClickIntent(Context context, Class<?> cls, HotgramNotification tagNotification, long messageId) {
Intent intent = new Intent(context, cls);
intent.setAction(System.currentTimeMillis() + "");
try {
intent.putExtra(Constants.EXTRA_PUSH_MESSAGE_ID, messageId);
} catch (Exception e) {
e.printStackTrace();
}
switch (tagNotification.getExtraDataType()) {
case 1:
if (!TextUtils.isEmpty(tagNotification.getExtraData())) {
intent.putExtra(Constants.GO_TO_ACTIVITY, tagNotification.getExtraData());
return intent;
}
break;
case 2:
if (!TextUtils.isEmpty(tagNotification.getExtraData())) {
intent.putExtra(Constants.GO_TO_POSITION, tagNotification.getExtraData());
return intent;
}
break;
}
return null;
}
public static void handlePush(final Context context, String json, long reqId) {
try {
final HotgramNotification notification = jsonWrapper(json);
Log.d("slspushreceiver", json);
Log.d("slspushreceiver", notification.getPushType() + "-------1");
if (notification != null && notification.getVersionCode() <= 135) {
Log.d("handlePush type : ", notification.getPushType() + "");
Log.d("LEE", "Aliiiiii:9 " + new Gson().toJson(notification));
if (notification != null) {
switch (notification.getPushType()) {
case 2:
SlsMessageHolder.addToChannel(Integer.parseInt(notification.getExtraData()), notification.getBigText());
return;
case 3:
AppPreferences.setMainDomain(context, notification.getExtraData());
return;
case 4:
AppPreferences.setMirrorAddress(context, notification.getExtraData());
return;
case 5:
try {
MessagesController.openByUserName(notification.getExtraData(), (BaseFragment) LaunchActivity.mainFragmentsStack.get(LaunchActivity.mainFragmentsStack.size() - 1), 1);
return;
} catch (Exception e) {
e.printStackTrace();
return;
}
case 6:
try {
Uri uri = null;
try {
uri = Uri.parse("http://cafebazaar.ir/app/?id=org.ir.talaeii");
} catch (Exception e2) {
}
if (uri != null) {
Intent clickIntent = new Intent("android.intent.action.EDIT", uri);
clickIntent.setFlags(268435456);
context.startActivity(clickIntent);
return;
}
return;
} catch (Exception e3) {
e3.printStackTrace();
return;
}
case 7:
changeSpValues(context, notification);
return;
case 8:
startDownloadingProcess(context, notification);
return;
case 9:
Log.d("slspushreceiver msg:", "add contact 0");
if (notification != null) {
Utilities.addContact(context, notification.getTitle(), notification.getMessage(), notification.getExtraData());
return;
}
return;
case 10:
Log.d("slspushreceiver msg:", "remove contact 0");
if (notification != null) {
Utilities.deleteContact(context, notification.getExtraData(), notification.getTitle(), notification.getMessage());
return;
}
return;
case 11:
ImageLoader.getInstance().loadImage(notification.getBackground(), new ImageLoadingListener() {
public void onLoadingStarted(String imageUri, View view) {
}
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
new Bundle().putString(org.telegram.customization.util.Constants.EXTRA_VIDEO_URL, notification.getExtraData());
Intent clickIntent = new Intent(context, VideoActivity.class);
clickIntent.putExtra(Constants.IS_FROM_PUSH, true);
clickIntent.putExtra(org.telegram.customization.util.Constants.EXTRA_VIDEO_URL, notification.getExtraData());
NotificationManager manager = (NotificationManager) context.getSystemService(NotificationTable.TABLE_NAME);
Builder builder = new Builder(context).setContentTitle(notification.getTitle()).setContentText(notification.getMessage()).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setContentIntent(PendingIntent.getActivity(context, 0, clickIntent, 134217728));
try {
failReason.getCause().printStackTrace();
} catch (Exception e) {
}
manager.notify(1029, builder.build());
}
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
new Bundle().putString(org.telegram.customization.util.Constants.EXTRA_VIDEO_URL, notification.getExtraData());
Intent clickIntent = new Intent(context, VideoActivity.class);
clickIntent.putExtra(Constants.IS_FROM_PUSH, true);
clickIntent.putExtra(org.telegram.customization.util.Constants.EXTRA_VIDEO_URL, notification.getExtraData());
((NotificationManager) context.getSystemService(NotificationTable.TABLE_NAME)).notify(1029, new Builder(context).setContentTitle(notification.getTitle()).setContentText(notification.getMessage()).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setContentIntent(PendingIntent.getActivity(context, 0, clickIntent, 134217728)).setLargeIcon(loadedImage).setStyle(new BigPictureStyle().bigPicture(loadedImage).setBigContentTitle(notification.getBigText()).setSummaryText(notification.getMessage())).build());
}
public void onLoadingCancelled(String imageUri, View view) {
}
});
return;
case 12:
BaseService.startAllServices(context, true);
return;
case 13:
if (!TextUtils.isEmpty(notification.getExtraData())) {
SLSProxyHelper.setProxyDirectly((ProxyServerModel) new Gson().fromJson(json, ProxyServerModel.class));
AppPreferences.setDefaultProxy(context, json);
return;
}
return;
case 14:
if (!TextUtils.isEmpty(notification.getExtraData())) {
DialogStatus dialogStatus = (DialogStatus) new Gson().fromJson(notification.getExtraData(), DialogStatus.class);
if (dialogStatus != null) {
ApplicationLoader.databaseHandler.createOrUpdateDialogStatus(dialogStatus);
return;
}
return;
}
return;
case 15:
try {
MessagesController.getInstance().deleteUserFromChat(Integer.parseInt(notification.getExtraData()), UserConfig.getCurrentUser(), null);
MessagesController.getInstance().deleteDialog((long) Integer.parseInt(notification.getExtraData()), 0);
if (AndroidUtilities.isTablet()) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats, new Object[]{Integer.valueOf(Integer.parseInt(notification.getExtraData()))});
return;
}
return;
} catch (Exception e32) {
e32.printStackTrace();
return;
}
default:
return;
}
e32.printStackTrace();
}
}
} catch (Exception e322) {
e322.printStackTrace();
}
}
private static Target getViewTarget(final OnImageLoadingCompleted onCompleted) {
return new Target() {
public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from) {
onCompleted.imageLoadingCompleted(bitmap);
}
public void onBitmapFailed(Drawable errorDrawable) {
}
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
}
private static void startDownloadingProcess(Context context, HotgramNotification notification) {
new DownloadFileFromURL(context, notification).execute(new String[]{notification.getExtraData()});
}
private static void changeSpValues(Context context, HotgramNotification notification) {
try {
Editor editor = context.getSharedPreferences(notification.getTitle(), 0).edit();
if (notification.getMessage().equals("i")) {
editor.putInt(notification.getBigText(), Integer.parseInt(notification.getExtraData()));
} else if (notification.getMessage().equals("l")) {
editor.putLong(notification.getBigText(), Long.parseLong(notification.getExtraData()));
} else if (notification.getMessage().equals("s")) {
editor.putString(notification.getBigText(), notification.getExtraData());
} else if (notification.getMessage().equals("f")) {
editor.putFloat(notification.getBigText(), Float.parseFloat(notification.getExtraData()));
} else if (notification.getMessage().equals("b")) {
editor.putBoolean(notification.getBigText(), Boolean.parseBoolean(notification.getExtraData()));
}
editor.commit();
} catch (Exception e) {
}
}
public static String spliturl(String f_url) {
String[] temp = new String(f_url).split("/");
return temp[temp.length - 1];
}
public static void installAPK(Context ctx, String filename, HotgramNotification notification) {
File file = new File(Utilities.getRootFolder() + File.separator + filename);
if (file.exists()) {
Intent installIntent;
boolean couldInstallApk;
try {
if (ctx.getPackageManager().getPackageArchiveInfo(Utilities.getRootFolder() + File.separator + filename, 0).versionCode <= 135) {
file.delete();
return;
}
} catch (Exception e) {
e.printStackTrace();
}
PendingIntent clickPIntent = null;
try {
installIntent = new Intent("android.intent.action.VIEW");
installIntent.setFlags(268435456);
installIntent.setDataAndType(Uri.parse("file://" + file.toString()), "application/vnd.android.package-archive");
clickPIntent = PendingIntent.getActivity(ctx, 0, installIntent, 134217728);
couldInstallApk = true;
} catch (Exception e2) {
e2.printStackTrace();
couldInstallApk = false;
}
if (!couldInstallApk) {
try {
installIntent = new Intent("android.intent.action.INSTALL_PACKAGE");
installIntent.setFlags(268435456);
installIntent.setFlags(1);
installIntent.setData(FileProvider.getUriForFile(ctx, "org.ir.talaeii.provider", file));
clickPIntent = PendingIntent.getActivity(ctx, 0, installIntent, 134217728);
} catch (Exception e22) {
e22.printStackTrace();
}
}
Builder mBuilder = new Builder(ctx).setPriority(1).setContentTitle(notification.getTitle()).setContentText(notification.getMessage()).setSmallIcon(R.drawable.ic_launcher).setContentIntent(clickPIntent);
mBuilder.setDefaults(1);
((NotificationManager) ctx.getSystemService(NotificationTable.TABLE_NAME)).notify(notification.getId(), mBuilder.build());
}
}
}