Skip to content

Commit

Permalink
Restored Glide to load attachments images into widget
Browse files Browse the repository at this point in the history
It is actually a process runned into a parallel thread so I don't know why it broke. Actually I've also added some (currentyl) unused code to async load uri into the RemoteViews compoment, just in case...
  • Loading branch information
federicoiosue committed Nov 5, 2019
1 parent a58ca47 commit 71b8db0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
VERSION_NAME=6.0.3
VERSION_CODE=277
VERSION_CODE=278
PACKAGE=it.feio.android.omninotes
MIN_SDK=16
TARGET_SDK=28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.text.TextUtils;
import android.widget.RemoteViews;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.AppWidgetTarget;
import it.feio.android.omninotes.OmniNotes;
import it.feio.android.omninotes.R;
import it.feio.android.omninotes.helpers.AttachmentsHelper;
import it.feio.android.omninotes.models.Attachment;
import it.feio.android.simplegallery.util.BitmapUtils;
import java.util.concurrent.ExecutionException;
import org.apache.commons.io.FilenameUtils;


Expand All @@ -47,7 +54,16 @@ public static Bitmap getBitmapFromAttachment (Context mContext, Attachment mAtta
mAttachment.getUri().getPath();

if (AttachmentsHelper.typeOf(mAttachment, MIME_TYPE_VIDEO, MIME_TYPE_IMAGE, MIME_TYPE_SKETCH)) {
bmp = BitmapUtils.getThumbnail(mContext, FileProviderHelper.getShareableUri(mAttachment), width, height);
try {
bmp = Glide.with(OmniNotes.getAppContext()).asBitmap()
.apply(new RequestOptions()
.centerCrop()
.error(R.drawable.attachment_broken))
.load(mAttachment.getUri())
.submit(width, height).get();
} catch (NullPointerException | InterruptedException | ExecutionException e) {
bmp = null;
}

} else if (MIME_TYPE_AUDIO.equals(mAttachment.getMime_type())) {
bmp = ThumbnailUtils.extractThumbnail(
Expand All @@ -69,6 +85,29 @@ public static Bitmap getBitmapFromAttachment (Context mContext, Attachment mAtta
return bmp;
}

public static void loadAttachmentIntoWidget (Attachment mAttachment, AppWidgetTarget awt) {
mAttachment.getUri().getPath();

RequestBuilder<Bitmap> builder = Glide.with(OmniNotes.getAppContext()).asBitmap()
.apply(new RequestOptions()
.centerCrop()
.error(R.drawable.attachment_broken));

if (AttachmentsHelper.typeOf(mAttachment, MIME_TYPE_VIDEO, MIME_TYPE_IMAGE, MIME_TYPE_SKETCH)) {
builder = builder.load(mAttachment.getUri());
} else if (MIME_TYPE_AUDIO.equals(mAttachment.getMime_type())) {
builder = builder.load(R.raw.play);
} else if (MIME_TYPE_FILES.equals(mAttachment.getMime_type())) {
if (MIME_TYPE_CONTACT_EXT.equals(FilenameUtils.getExtension(mAttachment.getName()))) {
builder = builder.load(R.raw.vcard);
} else {
builder = builder.load(R.raw.files);
}
}

builder.into(awt);
}


public static Uri getThumbnailUri (Context mContext, Attachment mAttachment) {
Uri uri = mAttachment.getUri();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ public RemoteViews getViewAt (int position) {

if (!note.isLocked() && showThumbnails && !note.getAttachmentsList().isEmpty()) {
Attachment mAttachment = note.getAttachmentsList().get(0);
// AppWidgetTarget awt = new AppWidgetTarget(app, R.id.attachmentThumbnail, row, appWidgetId) {
// @Override
// public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
// super.onResourceReady(resource, transition);
// }
// };
// BitmapHelper.loadAttachmentIntoWidget(mAttachment, awt);
Bitmap bmp = BitmapHelper.getBitmapFromAttachment(app, mAttachment, WIDTH, HEIGHT);
row.setBitmap(R.id.attachmentThumbnail, "setImageBitmap", bmp);
row.setInt(R.id.attachmentThumbnail, "setVisibility", View.VISIBLE);
Expand Down

0 comments on commit 71b8db0

Please sign in to comment.