diff options
author | ByteHamster <info@bytehamster.com> | 2024-01-04 17:55:23 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2024-01-04 18:16:36 +0100 |
commit | 3410d79eb21c3966505b09f7f39246170f416bb6 (patch) | |
tree | cb045c28f11e4f69791ea7591f9e168a2ec561ff | |
parent | b2ea588b5479c7e1aa0b40932c9734f5389258db (diff) | |
download | AntennaPod-3410d79eb21c3966505b09f7f39246170f416bb6.zip |
Increase timeout of Echo images
-rw-r--r-- | ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoActivity.java | 63 | ||||
-rw-r--r-- | ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/FinalShareScreen.java | 22 |
2 files changed, 57 insertions, 28 deletions
diff --git a/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoActivity.java b/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoActivity.java index 2989cc748..69ce8373a 100644 --- a/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoActivity.java +++ b/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoActivity.java @@ -12,7 +12,6 @@ import android.net.Uri; import android.os.Bundle; import android.text.format.DateFormat; import android.util.Log; -import android.util.Pair; import android.view.KeyEvent; import android.view.View; import androidx.annotation.NonNull; @@ -70,6 +69,7 @@ public class EchoActivity extends AppCompatActivity { private long timeTouchDown; private long timeLastFrame; private Disposable disposable; + private Disposable disposableFavorite; private long totalTime = 0; private int totalActivePodcasts = 0; @@ -80,7 +80,8 @@ public class EchoActivity extends AppCompatActivity { private long queueSecondsLeft = 0; private long timeBetweenReleaseAndPlay = 0; private long oldestDate = 0; - private final ArrayList<Pair<String, Drawable>> favoritePods = new ArrayList<>(); + private final ArrayList<String> favoritePodNames = new ArrayList<>(); + private final ArrayList<Drawable> favoritePodImages = new ArrayList<>(); @SuppressLint("ClickableViewAccessibility") @Override @@ -179,6 +180,9 @@ public class EchoActivity extends AppCompatActivity { if (disposable != null) { disposable.dispose(); } + if (disposableFavorite != null) { + disposableFavorite.dispose(); + } } private void loadScreen(int screen, boolean force) { @@ -288,7 +292,7 @@ public class EchoActivity extends AppCompatActivity { viewBinding.largeLabel.setText(""); viewBinding.belowLabel.setText(""); viewBinding.smallLabel.setText(""); - currentDrawable = new FinalShareScreen(this, favoritePods); + currentDrawable = new FinalShareScreen(this, favoritePodNames, favoritePodImages); break; default: // Keep } @@ -340,25 +344,11 @@ public class EchoActivity extends AppCompatActivity { Collections.sort(statisticsData.feedTime, (item1, item2) -> Long.compare(item2.timePlayed, item1.timePlayed)); - favoritePods.clear(); + favoritePodNames.clear(); for (int i = 0; i < 5 && i < statisticsData.feedTime.size(); i++) { - BitmapDrawable cover = new BitmapDrawable(getResources(), (Bitmap) null); - try { - final int size = SHARE_SIZE / 3; - final int radius = (i == 0) ? (size / 16) : (size / 8); - cover = new BitmapDrawable(getResources(), Glide.with(this) - .asBitmap() - .load(statisticsData.feedTime.get(i).feed.getImageUrl()) - .apply(new RequestOptions() - .fitCenter() - .transform(new RoundedCorners(radius))) - .submit(size, size) - .get(1, TimeUnit.SECONDS)); - } catch (Exception e) { - e.printStackTrace(); - } - favoritePods.add(new Pair<>(statisticsData.feedTime.get(i).feed.getTitle(), cover)); + favoritePodNames.add(statisticsData.feedTime.get(i).feed.getTitle()); } + loadFavoritePodImages(statisticsData); totalActivePodcasts = 0; playedActivePodcasts = 0; @@ -407,4 +397,37 @@ public class EchoActivity extends AppCompatActivity { .subscribe(result -> loadScreen(currentScreen, true), error -> Log.e(TAG, Log.getStackTraceString(error))); } + + void loadFavoritePodImages(DBReader.StatisticsResult statisticsData) { + if (disposableFavorite != null) { + disposableFavorite.dispose(); + } + disposableFavorite = Observable.fromCallable( + () -> { + favoritePodImages.clear(); + for (int i = 0; i < 5 && i < statisticsData.feedTime.size(); i++) { + BitmapDrawable cover = new BitmapDrawable(getResources(), (Bitmap) null); + try { + final int size = SHARE_SIZE / 3; + final int radius = (i == 0) ? (size / 16) : (size / 8); + cover = new BitmapDrawable(getResources(), Glide.with(this) + .asBitmap() + .load(statisticsData.feedTime.get(i).feed.getImageUrl()) + .apply(new RequestOptions() + .fitCenter() + .transform(new RoundedCorners(radius))) + .submit(size, size) + .get(5, TimeUnit.SECONDS)); + } catch (Exception e) { + Log.d(TAG, "Loading cover: " + e.getMessage()); + } + favoritePodImages.add(cover); + } + return statisticsData; + }) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(result -> { }, + error -> Log.e(TAG, Log.getStackTraceString(error))); + } } diff --git a/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/FinalShareScreen.java b/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/FinalShareScreen.java index 16503b577..bf8e7eeea 100644 --- a/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/FinalShareScreen.java +++ b/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/FinalShareScreen.java @@ -7,7 +7,6 @@ import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Typeface; import android.graphics.drawable.Drawable; -import android.util.Pair; import androidx.appcompat.content.res.AppCompatResources; import androidx.core.content.res.ResourcesCompat; import de.danoeh.antennapod.ui.echo.EchoActivity; @@ -22,16 +21,19 @@ public class FinalShareScreen extends BubbleScreen { private final String heading; private final String year; private final Drawable logo; - private final ArrayList<Pair<String, Drawable>> favoritePods; + private final ArrayList<String> favoritePodNames; + private final ArrayList<Drawable> favoritePodImages; private final Typeface typefaceNormal; private final Typeface typefaceBold; - public FinalShareScreen(Context context, ArrayList<Pair<String, Drawable>> favoritePods) { + public FinalShareScreen(Context context, + ArrayList<String> favoritePodNames, ArrayList<Drawable> favoritePodImages) { super(context); this.heading = context.getString(R.string.echo_share_heading); this.logo = AppCompatResources.getDrawable(context, R.drawable.echo); + this.favoritePodNames = favoritePodNames; + this.favoritePodImages = favoritePodImages; this.year = String.valueOf(EchoActivity.RELEASE_YEAR); - this.favoritePods = favoritePods; typefaceNormal = ResourcesCompat.getFont(context, R.font.sarabun_regular); typefaceBold = ResourcesCompat.getFont(context, R.font.sarabun_semi_bold); paintTextMain = new Paint(); @@ -57,7 +59,7 @@ public class FinalShareScreen extends BubbleScreen { paintTextMain.setTextAlign(Paint.Align.LEFT); float fontSizePods = innerBoxSize / 18; // First one only float textY = innerBoxY + 0.62f * innerBoxSize; - for (int i = 0; i < favoritePods.size(); i++) { + for (int i = 0; i < favoritePodNames.size(); i++) { float coverSize = (i == 0) ? (0.4f * innerBoxSize) : (0.2f * innerBoxSize); float coverX = COVER_POSITIONS[i][0]; float coverY = COVER_POSITIONS[i][1]; @@ -71,12 +73,16 @@ public class FinalShareScreen extends BubbleScreen { logo1Pos.inset((int) (0.003f * innerBoxSize), (int) (0.003f * innerBoxSize)); Rect pos = new Rect(); logo1Pos.round(pos); - favoritePods.get(i).second.setBounds(pos); - favoritePods.get(i).second.draw(canvas); + if (favoritePodImages.size() > i) { + favoritePodImages.get(i).setBounds(pos); + favoritePodImages.get(i).draw(canvas); + } else { + canvas.drawText(" ...", pos.left, pos.centerY(), paintTextMain); + } paintTextMain.setTextSize(fontSizePods); canvas.drawText((i + 1) + ".", innerBoxX, textY, paintTextMain); - canvas.drawText(favoritePods.get(i).first, innerBoxX + 0.055f * innerBoxSize, textY, paintTextMain); + canvas.drawText(favoritePodNames.get(i), innerBoxX + 0.055f * innerBoxSize, textY, paintTextMain); fontSizePods = innerBoxSize / 24; // Starting with second text is smaller textY += 1.3f * fontSizePods; paintTextMain.setTypeface(typefaceNormal); |