Merge pull request #6859 from ByteHamster/echo-tweaks

This commit is contained in:
ByteHamster 2024-01-10 17:12:31 -05:00 committed by GitHub
commit 6e2a8b86a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 86 additions and 38 deletions

View File

@ -34,11 +34,7 @@ public class EchoSection extends Fragment {
viewBinding = HomeSectionEchoBinding.inflate(inflater);
viewBinding.titleLabel.setText(getString(R.string.antennapod_echo_year, EchoActivity.RELEASE_YEAR));
viewBinding.echoButton.setOnClickListener(v -> startActivity(new Intent(getContext(), EchoActivity.class)));
viewBinding.closeButton.setOnClickListener(v -> {
getContext().getSharedPreferences(HomeFragment.PREF_NAME, Context.MODE_PRIVATE)
.edit().putInt(HomeFragment.PREF_HIDE_ECHO, EchoActivity.RELEASE_YEAR).apply();
((MainActivity) getActivity()).loadFragment(HomeFragment.TAG, null);
});
viewBinding.closeButton.setOnClickListener(v -> hideThisYear());
updateVisibility();
return viewBinding.getRoot();
}
@ -70,8 +66,18 @@ public class EchoSection extends Fragment {
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(totalTime -> viewBinding.getRoot()
.setVisibility((totalTime >= 3600 * 10) ? View.VISIBLE : View.GONE),
Throwable::printStackTrace);
.subscribe(totalTime -> {
boolean shouldShow = (totalTime >= 3600 * 10);
viewBinding.getRoot().setVisibility(shouldShow ? View.VISIBLE : View.GONE);
if (!shouldShow) {
hideThisYear();
}
}, Throwable::printStackTrace);
}
void hideThisYear() {
getContext().getSharedPreferences(HomeFragment.PREF_NAME, Context.MODE_PRIVATE)
.edit().putInt(HomeFragment.PREF_HIDE_ECHO, EchoActivity.RELEASE_YEAR).apply();
((MainActivity) getActivity()).loadFragment(HomeFragment.TAG, null);
}
}

View File

@ -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)));
}
}

View File

@ -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();
@ -54,10 +56,9 @@ public class FinalShareScreen extends BubbleScreen {
paintTextMain.setTextSize(0.12f * innerBoxSize);
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];
@ -71,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);
@ -89,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 + "";
}
}