summaryrefslogtreecommitdiff
path: root/ui/echo/src/main/java/de
diff options
context:
space:
mode:
Diffstat (limited to 'ui/echo/src/main/java/de')
-rw-r--r--ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/EchoActivity.java94
-rw-r--r--ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/FinalShareScreen.java44
-rw-r--r--ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/WavesScreen.java38
3 files changed, 135 insertions, 41 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 50b34b6e3..758eaeac7 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
@@ -10,8 +10,8 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
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;
@@ -35,6 +35,7 @@ import de.danoeh.antennapod.ui.echo.screens.FinalShareScreen;
import de.danoeh.antennapod.ui.echo.screens.RotatingSquaresScreen;
import de.danoeh.antennapod.ui.echo.screens.StripesScreen;
import de.danoeh.antennapod.ui.echo.screens.WaveformScreen;
+import de.danoeh.antennapod.ui.echo.screens.WavesScreen;
import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
@@ -53,6 +54,7 @@ import java.util.Locale;
import java.util.concurrent.TimeUnit;
public class EchoActivity extends AppCompatActivity {
+ public static final int RELEASE_YEAR = 2023;
private static final String TAG = "EchoActivity";
private static final int NUM_SCREENS = 7;
private static final int SHARE_SIZE = 1000;
@@ -67,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;
@@ -77,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
@@ -134,7 +138,7 @@ public class EchoActivity extends AppCompatActivity {
new ShareCompat.IntentBuilder(this)
.setType("image/png")
.addStream(fileUri)
- .setText(getString(R.string.echo_share, 2023))
+ .setText(getString(R.string.echo_share, RELEASE_YEAR))
.setChooserTitle(R.string.share_file_label)
.startChooser();
} catch (Exception e) {
@@ -176,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) {
@@ -190,7 +197,7 @@ public class EchoActivity extends AppCompatActivity {
switch (currentScreen) {
case 0:
viewBinding.aboveLabel.setText(R.string.echo_intro_your_year);
- viewBinding.largeLabel.setText(String.format(getEchoLanguage(), "%d", 2023));
+ viewBinding.largeLabel.setText(String.format(getEchoLanguage(), "%d", RELEASE_YEAR));
viewBinding.belowLabel.setText(R.string.echo_intro_in_podcasts);
viewBinding.smallLabel.setText(R.string.echo_intro_locally);
currentDrawable = new BubbleScreen(this);
@@ -207,20 +214,27 @@ public class EchoActivity extends AppCompatActivity {
viewBinding.largeLabel.setText(String.format(getEchoLanguage(), "%d", queueSecondsLeft / 3600));
viewBinding.belowLabel.setText(getResources().getQuantityString(
R.plurals.echo_queue_hours_waiting, queueNumEpisodes, queueNumEpisodes));
- int daysUntil2024 = Math.max(356 - Calendar.getInstance().get(Calendar.DAY_OF_YEAR) + 1, 1);
- long secondsPerDay = queueSecondsLeft / daysUntil2024;
+ Calendar dec31 = Calendar.getInstance();
+ dec31.set(Calendar.DAY_OF_MONTH, 31);
+ dec31.set(Calendar.MONTH, Calendar.DECEMBER);
+ int daysUntilNextYear = Math.max(1,
+ dec31.get(Calendar.DAY_OF_YEAR) - Calendar.getInstance().get(Calendar.DAY_OF_YEAR) + 1);
+ long secondsPerDay = queueSecondsLeft / daysUntilNextYear;
String timePerDay = Converter.getDurationStringLocalized(
getLocalizedResources(this, getEchoLanguage()), secondsPerDay * 1000, true);
double hoursPerDay = (double) (secondsPerDay / 3600);
+ int nextYear = RELEASE_YEAR + 1;
if (hoursPerDay < 1.5) {
viewBinding.aboveLabel.setText(R.string.echo_queue_title_clean);
- viewBinding.smallLabel.setText(getString(R.string.echo_queue_hours_clean, timePerDay, 2024));
+ viewBinding.smallLabel.setText(
+ getString(R.string.echo_queue_hours_clean, timePerDay, nextYear));
} else if (hoursPerDay <= 24) {
viewBinding.aboveLabel.setText(R.string.echo_queue_title_many);
- viewBinding.smallLabel.setText(getString(R.string.echo_queue_hours_normal, timePerDay, 2024));
+ viewBinding.smallLabel.setText(
+ getString(R.string.echo_queue_hours_normal, timePerDay, nextYear));
} else {
viewBinding.aboveLabel.setText(R.string.echo_queue_title_many);
- viewBinding.smallLabel.setText(getString(R.string.echo_queue_hours_much, timePerDay, 2024));
+ viewBinding.smallLabel.setText(getString(R.string.echo_queue_hours_much, timePerDay, nextYear));
}
currentDrawable = new StripesScreen(this);
break;
@@ -257,13 +271,14 @@ public class EchoActivity extends AppCompatActivity {
viewBinding.smallLabel.setText(getString(R.string.echo_hoarder_comment_clean,
percentagePlayed, totalActivePodcasts));
}
- currentDrawable = new StripesScreen(this);
+ currentDrawable = new WavesScreen(this);
break;
case 5:
viewBinding.aboveLabel.setText("");
viewBinding.largeLabel.setText(R.string.echo_thanks_large);
if (oldestDate < jan1()) {
- SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM yyyy", getEchoLanguage());
+ String skeleton = DateFormat.getBestDateTimePattern(getEchoLanguage(), "MMMM yyyy");
+ SimpleDateFormat dateFormat = new SimpleDateFormat(skeleton, getEchoLanguage());
String dateFrom = dateFormat.format(new Date(oldestDate));
viewBinding.belowLabel.setText(getString(R.string.echo_thanks_we_are_glad_old, dateFrom));
} else {
@@ -277,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
}
@@ -312,7 +327,7 @@ public class EchoActivity extends AppCompatActivity {
date.set(Calendar.MILLISECOND, 0);
date.set(Calendar.DAY_OF_MONTH, 1);
date.set(Calendar.MONTH, 0);
- date.set(Calendar.YEAR, 2023);
+ date.set(Calendar.YEAR, RELEASE_YEAR);
return date.getTimeInMillis();
}
@@ -329,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;
@@ -396,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 87b9cbd53..4af8941d0 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,9 +7,9 @@ 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;
import de.danoeh.antennapod.ui.echo.R;
import java.util.ArrayList;
@@ -19,16 +19,21 @@ public class FinalShareScreen extends BubbleScreen {
private final Paint paintTextMain;
private final Paint paintCoverBorder;
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.favoritePods = favoritePods;
+ this.favoritePodNames = favoritePodNames;
+ this.favoritePodImages = favoritePodImages;
+ this.year = String.valueOf(EchoActivity.RELEASE_YEAR);
typefaceNormal = ResourcesCompat.getFont(context, R.font.sarabun_regular);
typefaceBold = ResourcesCompat.getFont(context, R.font.sarabun_semi_bold);
paintTextMain = new Paint();
@@ -49,12 +54,11 @@ public class FinalShareScreen extends BubbleScreen {
paintTextMain.setTextSize(headingSize);
canvas.drawText(heading, innerBoxX + 0.5f * innerBoxSize, innerBoxY + headingSize, paintTextMain);
paintTextMain.setTextSize(0.12f * innerBoxSize);
- canvas.drawText("2023", innerBoxX + 0.8f * innerBoxSize, innerBoxY + 0.25f * innerBoxSize, paintTextMain);
+ canvas.drawText(year, innerBoxX + 0.8f * innerBoxSize, innerBoxY + 0.25f * innerBoxSize, paintTextMain);
- 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];
@@ -68,12 +72,20 @@ 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.setTextAlign(Paint.Align.CENTER);
paintTextMain.setTextSize(fontSizePods);
- canvas.drawText((i + 1) + ".", innerBoxX, textY, paintTextMain);
- canvas.drawText(favoritePods.get(i).first, innerBoxX + 0.055f * innerBoxSize, textY, paintTextMain);
+ final float numberWidth = 0.06f * innerBoxSize;
+ canvas.drawText((i + 1) + ".", innerBoxX + numberWidth / 2, textY, paintTextMain);
+ paintTextMain.setTextAlign(Paint.Align.LEFT);
+ String ellipsizedTitle = ellipsize(favoritePodNames.get(i), paintTextMain, innerBoxSize - numberWidth);
+ canvas.drawText(ellipsizedTitle, innerBoxX + numberWidth, textY, paintTextMain);
fontSizePods = innerBoxSize / 24; // Starting with second text is smaller
textY += 1.3f * fontSizePods;
paintTextMain.setTypeface(typefaceNormal);
@@ -86,4 +98,14 @@ public class FinalShareScreen extends BubbleScreen {
(int) (innerBoxY + innerBoxSize));
logo.draw(canvas);
}
+
+ String ellipsize(String string, Paint paint, float maxWidth) {
+ if (paint.measureText(string) <= maxWidth) {
+ return string;
+ }
+ while (paint.measureText(string + "…") > maxWidth || string.endsWith(" ")) {
+ string = string.substring(0, string.length() - 1);
+ }
+ return string + "…";
+ }
}
diff --git a/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/WavesScreen.java b/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/WavesScreen.java
new file mode 100644
index 000000000..eb521f0a2
--- /dev/null
+++ b/ui/echo/src/main/java/de/danoeh/antennapod/ui/echo/screens/WavesScreen.java
@@ -0,0 +1,38 @@
+package de.danoeh.antennapod.ui.echo.screens;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import androidx.annotation.NonNull;
+
+public class WavesScreen extends BaseScreen {
+ protected static final int NUM_PARTICLES = 10;
+
+ public WavesScreen(Context context) {
+ super(context);
+ paintParticles.setStyle(Paint.Style.STROKE);
+ for (int i = 0; i < NUM_PARTICLES; i++) {
+ particles.add(new Particle(0, 0, 1.0f * i / NUM_PARTICLES, 0));
+ }
+ }
+
+ @Override
+ public void draw(@NonNull Canvas canvas) {
+ paintParticles.setStrokeWidth(0.05f * getBounds().height());
+ super.draw(canvas);
+ }
+
+ @Override
+ protected void drawParticle(@NonNull Canvas canvas, Particle p, float width, float height,
+ float innerBoxX, float innerBoxY, float innerBoxSize) {
+ canvas.drawCircle(width / 2, 1.1f * height, (float) (p.positionZ * 1.2f * height), paintParticles);
+ }
+
+ @Override
+ protected void particleTick(Particle p, long timeSinceLastFrame) {
+ p.positionZ += 0.00005 * timeSinceLastFrame;
+ if (p.positionZ > 1f) {
+ p.positionZ -= 1f;
+ }
+ }
+}