Make it easier to migrate Echo to a new year (#6803)

Also, add a new screen background
This commit is contained in:
ByteHamster 2023-12-13 22:40:51 +01:00 committed by GitHub
parent 3852d50f92
commit db88dc10e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 16 deletions

View File

@ -21,6 +21,7 @@ import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentContainerView; import androidx.fragment.app.FragmentContainerView;
import de.danoeh.antennapod.ui.echo.EchoActivity;
import de.danoeh.antennapod.ui.home.sections.EchoSection; import de.danoeh.antennapod.ui.home.sections.EchoSection;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.Subscribe;
@ -104,10 +105,10 @@ public class HomeFragment extends Fragment implements Toolbar.OnMenuItemClickLis
addSection(new AllowNotificationsSection()); addSection(new AllowNotificationsSection());
} }
} }
if (Calendar.getInstance().get(Calendar.MONTH) == Calendar.DECEMBER if (Calendar.getInstance().get(Calendar.YEAR) == EchoActivity.RELEASE_YEAR
&& Calendar.getInstance().get(Calendar.YEAR) == 2023 && Calendar.getInstance().get(Calendar.MONTH) == Calendar.DECEMBER
&& Calendar.getInstance().get(Calendar.DAY_OF_MONTH) >= 10 && Calendar.getInstance().get(Calendar.DAY_OF_MONTH) >= 10
&& prefs.getInt(PREF_HIDE_ECHO, 0) != 2023) { && prefs.getInt(PREF_HIDE_ECHO, 0) != EchoActivity.RELEASE_YEAR) {
addSection(new EchoSection()); addSection(new EchoSection());
} }

View File

@ -32,11 +32,11 @@ public class EchoSection extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
viewBinding = HomeSectionEchoBinding.inflate(inflater); viewBinding = HomeSectionEchoBinding.inflate(inflater);
viewBinding.titleLabel.setText(getString(R.string.antennapod_echo_year, 2023)); viewBinding.titleLabel.setText(getString(R.string.antennapod_echo_year, EchoActivity.RELEASE_YEAR));
viewBinding.echoButton.setOnClickListener(v -> startActivity(new Intent(getContext(), EchoActivity.class))); viewBinding.echoButton.setOnClickListener(v -> startActivity(new Intent(getContext(), EchoActivity.class)));
viewBinding.closeButton.setOnClickListener(v -> { viewBinding.closeButton.setOnClickListener(v -> {
getContext().getSharedPreferences(HomeFragment.PREF_NAME, Context.MODE_PRIVATE) getContext().getSharedPreferences(HomeFragment.PREF_NAME, Context.MODE_PRIVATE)
.edit().putInt(HomeFragment.PREF_HIDE_ECHO, 2023).apply(); .edit().putInt(HomeFragment.PREF_HIDE_ECHO, EchoActivity.RELEASE_YEAR).apply();
((MainActivity) getActivity()).loadFragment(HomeFragment.TAG, null); ((MainActivity) getActivity()).loadFragment(HomeFragment.TAG, null);
}); });
updateVisibility(); updateVisibility();
@ -51,7 +51,7 @@ public class EchoSection extends Fragment {
date.set(Calendar.MILLISECOND, 0); date.set(Calendar.MILLISECOND, 0);
date.set(Calendar.DAY_OF_MONTH, 1); date.set(Calendar.DAY_OF_MONTH, 1);
date.set(Calendar.MONTH, 0); date.set(Calendar.MONTH, 0);
date.set(Calendar.YEAR, 2023); date.set(Calendar.YEAR, EchoActivity.RELEASE_YEAR);
return date.getTimeInMillis(); return date.getTimeInMillis();
} }

View File

@ -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.RotatingSquaresScreen;
import de.danoeh.antennapod.ui.echo.screens.StripesScreen; import de.danoeh.antennapod.ui.echo.screens.StripesScreen;
import de.danoeh.antennapod.ui.echo.screens.WaveformScreen; import de.danoeh.antennapod.ui.echo.screens.WaveformScreen;
import de.danoeh.antennapod.ui.echo.screens.WavesScreen;
import io.reactivex.Flowable; import io.reactivex.Flowable;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
@ -53,6 +54,7 @@ import java.util.Locale;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class EchoActivity extends AppCompatActivity { public class EchoActivity extends AppCompatActivity {
public static final int RELEASE_YEAR = 2023;
private static final String TAG = "EchoActivity"; private static final String TAG = "EchoActivity";
private static final int NUM_SCREENS = 7; private static final int NUM_SCREENS = 7;
private static final int SHARE_SIZE = 1000; private static final int SHARE_SIZE = 1000;
@ -134,7 +136,7 @@ public class EchoActivity extends AppCompatActivity {
new ShareCompat.IntentBuilder(this) new ShareCompat.IntentBuilder(this)
.setType("image/png") .setType("image/png")
.addStream(fileUri) .addStream(fileUri)
.setText(getString(R.string.echo_share, 2023)) .setText(getString(R.string.echo_share, RELEASE_YEAR))
.setChooserTitle(R.string.share_file_label) .setChooserTitle(R.string.share_file_label)
.startChooser(); .startChooser();
} catch (Exception e) { } catch (Exception e) {
@ -190,7 +192,7 @@ public class EchoActivity extends AppCompatActivity {
switch (currentScreen) { switch (currentScreen) {
case 0: case 0:
viewBinding.aboveLabel.setText(R.string.echo_intro_your_year); 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.belowLabel.setText(R.string.echo_intro_in_podcasts);
viewBinding.smallLabel.setText(R.string.echo_intro_locally); viewBinding.smallLabel.setText(R.string.echo_intro_locally);
currentDrawable = new BubbleScreen(this); currentDrawable = new BubbleScreen(this);
@ -207,20 +209,23 @@ public class EchoActivity extends AppCompatActivity {
viewBinding.largeLabel.setText(String.format(getEchoLanguage(), "%d", queueSecondsLeft / 3600)); viewBinding.largeLabel.setText(String.format(getEchoLanguage(), "%d", queueSecondsLeft / 3600));
viewBinding.belowLabel.setText(getResources().getQuantityString( viewBinding.belowLabel.setText(getResources().getQuantityString(
R.plurals.echo_queue_hours_waiting, queueNumEpisodes, queueNumEpisodes)); R.plurals.echo_queue_hours_waiting, queueNumEpisodes, queueNumEpisodes));
int daysUntil2024 = Math.max(356 - Calendar.getInstance().get(Calendar.DAY_OF_YEAR) + 1, 1); int daysUntilNextYear = Math.max(356 - Calendar.getInstance().get(Calendar.DAY_OF_YEAR) + 1, 1);
long secondsPerDay = queueSecondsLeft / daysUntil2024; long secondsPerDay = queueSecondsLeft / daysUntilNextYear;
String timePerDay = Converter.getDurationStringLocalized( String timePerDay = Converter.getDurationStringLocalized(
getLocalizedResources(this, getEchoLanguage()), secondsPerDay * 1000); getLocalizedResources(this, getEchoLanguage()), secondsPerDay * 1000);
double hoursPerDay = (double) (secondsPerDay / 3600); double hoursPerDay = (double) (secondsPerDay / 3600);
int nextYear = RELEASE_YEAR + 1;
if (hoursPerDay < 1.5) { if (hoursPerDay < 1.5) {
viewBinding.aboveLabel.setText(R.string.echo_queue_title_clean); 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) { } else if (hoursPerDay <= 24) {
viewBinding.aboveLabel.setText(R.string.echo_queue_title_many); 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 { } else {
viewBinding.aboveLabel.setText(R.string.echo_queue_title_many); 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); currentDrawable = new StripesScreen(this);
break; break;
@ -257,7 +262,7 @@ public class EchoActivity extends AppCompatActivity {
viewBinding.smallLabel.setText(getString(R.string.echo_hoarder_comment_clean, viewBinding.smallLabel.setText(getString(R.string.echo_hoarder_comment_clean,
percentagePlayed, totalActivePodcasts)); percentagePlayed, totalActivePodcasts));
} }
currentDrawable = new StripesScreen(this); currentDrawable = new WavesScreen(this);
break; break;
case 5: case 5:
viewBinding.aboveLabel.setText(""); viewBinding.aboveLabel.setText("");
@ -312,7 +317,7 @@ public class EchoActivity extends AppCompatActivity {
date.set(Calendar.MILLISECOND, 0); date.set(Calendar.MILLISECOND, 0);
date.set(Calendar.DAY_OF_MONTH, 1); date.set(Calendar.DAY_OF_MONTH, 1);
date.set(Calendar.MONTH, 0); date.set(Calendar.MONTH, 0);
date.set(Calendar.YEAR, 2023); date.set(Calendar.YEAR, RELEASE_YEAR);
return date.getTimeInMillis(); return date.getTimeInMillis();
} }

View File

@ -10,6 +10,7 @@ import android.graphics.drawable.Drawable;
import android.util.Pair; import android.util.Pair;
import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.res.ResourcesCompat; import androidx.core.content.res.ResourcesCompat;
import de.danoeh.antennapod.ui.echo.EchoActivity;
import de.danoeh.antennapod.ui.echo.R; import de.danoeh.antennapod.ui.echo.R;
import java.util.ArrayList; import java.util.ArrayList;
@ -19,6 +20,7 @@ public class FinalShareScreen extends BubbleScreen {
private final Paint paintTextMain; private final Paint paintTextMain;
private final Paint paintCoverBorder; private final Paint paintCoverBorder;
private final String heading; private final String heading;
private final String year;
private final Drawable logo; private final Drawable logo;
private final ArrayList<Pair<String, Drawable>> favoritePods; private final ArrayList<Pair<String, Drawable>> favoritePods;
private final Typeface typefaceNormal; private final Typeface typefaceNormal;
@ -28,6 +30,7 @@ public class FinalShareScreen extends BubbleScreen {
super(context); super(context);
this.heading = context.getString(R.string.echo_share_heading); this.heading = context.getString(R.string.echo_share_heading);
this.logo = AppCompatResources.getDrawable(context, R.drawable.echo); this.logo = AppCompatResources.getDrawable(context, R.drawable.echo);
this.year = String.valueOf(EchoActivity.RELEASE_YEAR);
this.favoritePods = favoritePods; this.favoritePods = favoritePods;
typefaceNormal = ResourcesCompat.getFont(context, R.font.sarabun_regular); typefaceNormal = ResourcesCompat.getFont(context, R.font.sarabun_regular);
typefaceBold = ResourcesCompat.getFont(context, R.font.sarabun_semi_bold); typefaceBold = ResourcesCompat.getFont(context, R.font.sarabun_semi_bold);
@ -49,7 +52,7 @@ public class FinalShareScreen extends BubbleScreen {
paintTextMain.setTextSize(headingSize); paintTextMain.setTextSize(headingSize);
canvas.drawText(heading, innerBoxX + 0.5f * innerBoxSize, innerBoxY + headingSize, paintTextMain); canvas.drawText(heading, innerBoxX + 0.5f * innerBoxSize, innerBoxY + headingSize, paintTextMain);
paintTextMain.setTextSize(0.12f * innerBoxSize); 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); paintTextMain.setTextAlign(Paint.Align.LEFT);
float fontSizePods = innerBoxSize / 18; // First one only float fontSizePods = innerBoxSize / 18; // First one only

View File

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