mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 05:43:55 +01:00
Remove dependency on Glide, Picasso, SVG, and multidex. (#1859)
* Eliminate the use of Picasso. This gets rid of the single use of the Picasso library (which was causing the whole library to be imported and shipped) and replaces it with Glide. TODO: replace this and the other instance(s) of Glide usage with Fresco, or vice versa. * Remove dependency on Glide. This removes the dependency on Glide, as well as the SVG rendering library, whose only purpose was to display a single SVG image in the Notification activity. Unfortunately Android doesn't support SVG natively, but Echo notifications have icons that are SVG formatted. Rather than import a bunch of heavy libraries to support this single case of SVG rendering, we can simply create a few local drawables that correspond to the different types of notifications, and use them instead. * Remove multidex! Multidex is a killer of performance and should be avoided at all costs. * Remove further unused bits. * Remove final vestige of multidex.
This commit is contained in:
parent
a059a3c2ef
commit
2884bd934a
12 changed files with 50 additions and 211 deletions
|
|
@ -3,18 +3,27 @@ package fr.free.nrw.commons.widget;
|
|||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProvider;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import com.facebook.common.executors.CallerThreadExecutor;
|
||||
import com.facebook.common.references.CloseableReference;
|
||||
import com.facebook.datasource.DataSource;
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.imagepipeline.core.ImagePipeline;
|
||||
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
|
||||
import com.facebook.imagepipeline.image.CloseableImage;
|
||||
import com.facebook.imagepipeline.request.ImageRequest;
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
||||
import com.prof.rssparser.Article;
|
||||
import com.prof.rssparser.Parser;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -27,10 +36,7 @@ import fr.free.nrw.commons.R;
|
|||
*/
|
||||
public class PicOfDayAppWidget extends AppWidgetProvider {
|
||||
|
||||
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
|
||||
int appWidgetId) {
|
||||
|
||||
// Construct the RemoteViews object
|
||||
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.pic_of_day_app_widget);
|
||||
|
||||
String urlString = BuildConfig.WIKIMEDIA_API_POTD;
|
||||
|
|
@ -45,19 +51,37 @@ public class PicOfDayAppWidget extends AppWidgetProvider {
|
|||
Elements elements = document.select("img");
|
||||
String imageUrl = elements.get(0).attr("src");
|
||||
if (imageUrl != null && imageUrl.length() > 0) {
|
||||
Picasso.get().load(imageUrl).into(views, R.id.appwidget_image, new int[]{appWidgetId});
|
||||
|
||||
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(imageUrl)).build();
|
||||
ImagePipeline imagePipeline = Fresco.getImagePipeline();
|
||||
DataSource<CloseableReference<CloseableImage>> dataSource
|
||||
= imagePipeline.fetchDecodedImage(request, context);
|
||||
dataSource.subscribe(new BaseBitmapDataSubscriber() {
|
||||
@Override
|
||||
protected void onNewResultImpl(@Nullable Bitmap tempBitmap) {
|
||||
Bitmap bitmap = null;
|
||||
if (tempBitmap != null) {
|
||||
bitmap = Bitmap.createBitmap(tempBitmap.getWidth(), tempBitmap.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
canvas.drawBitmap(tempBitmap, 0f, 0f, new Paint());
|
||||
}
|
||||
views.setImageViewBitmap(R.id.appwidget_image, bitmap);
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
|
||||
// Ignore failure for now.
|
||||
}
|
||||
}, CallerThreadExecutor.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
}
|
||||
});
|
||||
|
||||
// Instruct the widget manager to update the widget
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue