Skip to content

Commit

Permalink
fix thread issue glide - big picture notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Reza Amuzadeh committed Jan 16, 2019
1 parent fc2a12e commit 8058172
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 62 deletions.
Binary file added .idea/caches/gradle_models.ser
Binary file not shown.
3 changes: 3 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
Button buttonSmartNotification;
Button buttonCustomNotification;

public native String stringFromJNI();

// Used to load the 'native-lib' library on application startup.
static {
System.loadLibrary("native-lib");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
4 changes: 2 additions & 2 deletions magicalnotifier/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 17
targetSdkVersion 28
versionCode 6
versionName "1.0.6"
versionCode 7
versionName "1.0.7"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.text.format.DateUtils;
import android.widget.RemoteViews;

Expand Down Expand Up @@ -340,33 +342,36 @@ private void showBigPictureNotification() {
mBuilder.setColor(color);
}

GlideApp
.with(context)
.asBitmap()
.load(bigPictureUrl)
.centerCrop()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle().bigPicture(resource);
bigPictureStyle.setSummaryText(subTitle);
mBuilder.setStyle(bigPictureStyle);

NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
NOTIFICATION_CHANNEL_NAME,
NotificationManager.IMPORTANCE_HIGH);
mNotificationManager.createNotificationChannel(channel);
mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
}

// notificationId is a unique int for each notification that you must define
mNotificationManager.notify(PublicFunctions.getNotificationID(), mBuilder.build());
}
});
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
GlideApp
.with(context).asBitmap().load(bigPictureUrl).centerCrop()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {

NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle().bigPicture(resource);
bigPictureStyle.setSummaryText(subTitle);
mBuilder.setStyle(bigPictureStyle);

NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
NOTIFICATION_CHANNEL_NAME,
NotificationManager.IMPORTANCE_HIGH);
mNotificationManager.createNotificationChannel(channel);
mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
}

// notificationId is a unique int for each notification that you must define
mNotificationManager.notify(PublicFunctions.getNotificationID(), mBuilder.build());
}
});
}
});
}

private void showBigTextNotification() {
Expand Down Expand Up @@ -459,33 +464,38 @@ private void showSmartNotification() {
}

if (bigPictureUrl != null) {
GlideApp
.with(context)
.asBitmap()
.load(bigPictureUrl)
.centerCrop()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle().bigPicture(resource);
bigPictureStyle.setSummaryText(subTitle);
mBuilder.setStyle(bigPictureStyle);

NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
NOTIFICATION_CHANNEL_NAME,
NotificationManager.IMPORTANCE_HIGH);
mNotificationManager.createNotificationChannel(channel);
mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
}

// notificationId is a unique int for each notification that you must define
mNotificationManager.notify(PublicFunctions.getNotificationID(), mBuilder.build());
}
});
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {

GlideApp
.with(context).asBitmap().load(bigPictureUrl).centerCrop()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle().bigPicture(resource);
bigPictureStyle.setSummaryText(subTitle);
mBuilder.setStyle(bigPictureStyle);

NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
NOTIFICATION_CHANNEL_NAME,
NotificationManager.IMPORTANCE_HIGH);
mNotificationManager.createNotificationChannel(channel);
mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
}

// notificationId is a unique int for each notification that you must define
mNotificationManager.notify(PublicFunctions.getNotificationID(), mBuilder.build());
}
});
}
});

} else if (bigText != null) {
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));

Expand Down

0 comments on commit 8058172

Please sign in to comment.