Add some Swoon blessed packs.

This commit is contained in:
Greyson Parrelli
2020-02-10 15:29:15 -05:00
parent 7ecb50a3fe
commit 66a668f55b
6 changed files with 126 additions and 10 deletions

View File

@@ -12,6 +12,7 @@ import org.greenrobot.eventbus.ThreadMode;
import org.thoughtcrime.securesms.jobmanager.JobManager;
import org.thoughtcrime.securesms.jobs.Argon2TestJob;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.stickers.BlessedPacks;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.VersionTracker;
@@ -39,7 +40,7 @@ public class ApplicationMigrations {
private static final int LEGACY_CANONICAL_VERSION = 455;
public static final int CURRENT_VERSION = 9;
public static final int CURRENT_VERSION = 10;
private static final class Version {
static final int LEGACY = 1;
@@ -51,6 +52,7 @@ public class ApplicationMigrations {
static final int CACHED_ATTACHMENTS = 7;
static final int STICKERS_LAUNCH = 8;
static final int TEST_ARGON2 = 9;
static final int SWOON_STICKERS = 10;
}
/**
@@ -199,6 +201,10 @@ public class ApplicationMigrations {
jobs.put(Version.TEST_ARGON2, new Argon2TestMigrationJob());
}
if (lastSeenVersion < Version.SWOON_STICKERS) {
jobs.put(Version.SWOON_STICKERS, new StickerAdditionMigrationJob(BlessedPacks.SWOON_HANDS, BlessedPacks.SWOON_FACES));
}
return jobs;
}

View File

@@ -0,0 +1,82 @@
package org.thoughtcrime.securesms.migrations;
import androidx.annotation.NonNull;
import com.annimon.stream.Stream;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.jobmanager.Data;
import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.jobmanager.JobManager;
import org.thoughtcrime.securesms.jobs.StickerPackDownloadJob;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.stickers.BlessedPacks;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Migration job for installing new blessed packs as references. This means that the packs will
* show up in the list as available blessed packs, but they *won't* be auto-installed.
*/
public class StickerAdditionMigrationJob extends MigrationJob {
public static final String KEY = "StickerInstallMigrationJob";
private static String TAG = Log.tag(StickerAdditionMigrationJob.class);
private static final String KEY_PACKS = "packs";
private final List<BlessedPacks.Pack> packs;
StickerAdditionMigrationJob(@NonNull BlessedPacks.Pack... packs) {
this(new Parameters.Builder().build(), Arrays.asList(packs));
}
private StickerAdditionMigrationJob(@NonNull Parameters parameters, @NonNull List<BlessedPacks.Pack> packs) {
super(parameters);
this.packs = packs;
}
@Override
public boolean isUiBlocking() {
return false;
}
@Override
public @NonNull String getFactoryKey() {
return KEY;
}
@Override
public @NonNull Data serialize() {
String[] packsRaw = Stream.of(packs).map(BlessedPacks.Pack::toJson).toArray(String[]::new);
return new Data.Builder().putStringArray(KEY_PACKS, packsRaw).build();
}
@Override
public void performMigration() {
JobManager jobManager = ApplicationDependencies.getJobManager();
for (BlessedPacks.Pack pack : packs) {
Log.i(TAG, "Installing reference for blessed pack: " + pack.getPackId());
jobManager.add(StickerPackDownloadJob.forReference(pack.getPackId(), pack.getPackKey()));
}
}
@Override
boolean shouldRetry(@NonNull Exception e) {
return false;
}
public static class Factory implements Job.Factory<StickerAdditionMigrationJob> {
@Override
public @NonNull StickerAdditionMigrationJob create(@NonNull Parameters parameters, @NonNull Data data) {
String[] raw = data.getStringArray(KEY_PACKS);
List<BlessedPacks.Pack> packs = Stream.of(raw).map(BlessedPacks.Pack::fromJson).toList();
return new StickerAdditionMigrationJob(parameters, packs);
}
}
}