Skill'ler SDK entegrasyonu, flow ve paywall oluşturma, yayın öncesi denetim, placement taşıma ve daha fazlasını kapsar. Görevi kendi cümlelerinizle anlatın, ajanınız doğru skill'i seçsin.
Kullanıcının ilerlemesini bir Lottie animasyonu olarak göstermek için bu tarifi takip edin — örneğin, günlük serisini göstermek için dolan bir halka. Uygulamanız animasyonu bir özel element içinde yerel bir Lottie görünümü olarak render eder.
Başlamadan önce
Uygulamanızı Adapty Android SDK 4.4 veya sonraki bir sürüme güncelleyin. Önceki SDK sürümleri, her özel öğe için yedek içeriği gösterir.
Lottie’yi com.airbnb.android:lottie kaynağından Gradle ile uygulamanıza ekleyin.
.json formatında bir Lottie animasyonu hazırlayın ya da örnek streak_ring.json dosyasını indirin. Uygulama animasyonu baştan oynatır ve ilerlemeyle orantılı olarak durdurur; örneğin %50 için tam ortasında durur. Tam ilerlemeyi göstermek için animasyonun şu özelliklere sahip olması gerekir:
İlk karede hiç ilerleme olmamalı, son karede ise tam ilerleme gösterilmeli.
Sabit bir hız, yumuşatma (easing) olmadan. Animasyon yavaş başlayıp hızlanırsa, yarı yolda gerçek ilerlemenin yarısından daha azını gösterir.
1. Özel öğeyi ekrana ekleyin
Flow & Paywall Builder’da, bir flow ekranına özel element ekleyin ve animasyon için yapılandırın:
Type: lottie_animation.
ID: streak_ring. Bu tarifde ID, aynı zamanda animasyon dosyasının adıdır.
Height: Varsayılan Fixed yüksekliği koruyun. Animasyon, özel elementin boyutuna göre ölçeklenir.
Özel elementin içine, halkanın hareketsiz bir görüntüsünü içeren bir Image ekleyin. Kullanıcılar, uygulamanızın animasyonu oynatamayan sürümlerinde bunu yedek içerik olarak görür.
2. Animasyon dosyasını uygulamanıza ekleyin
Animasyon dosyasını uygulama modülünüzün assets klasörü olan src/main/assets dizinine koyun. Dosyayı bu klasörün kökünde tutun, bir alt klasöre koymayın.
.json uzantısı olmadan dosya adı, özel öğenin ID’siyle eşleşmelidir; örneğin streak_ring için streak_ring.json.
3. Animasyon görünümünü oluşturun
Streak için bir model ve animasyonu oynatacak bir görünüm oluşturun. Uygulamanız streak değiştiğinde modeli günceller. Görünüm modeli okuduğundan, ekran açıldığında halka mevcut streak’i gösterir:
// the streak that your app keeps up to dateclass StreakStore { val currentStreak = MutableStateFlow(0) // days in a row}@Composablefun StreakRing(animationFile: String, streakStore: StreakStore) { val composition by rememberLottieComposition(LottieCompositionSpec.Asset(animationFile)) val streak by streakStore.currentStreak.collectAsState() // 7 days fill the ring: from 0 for an empty ring to 1 for a full one val progress = minOf(streak / 7f, 1f) LottieAnimation( composition = composition, modifier = Modifier.fillMaxSize(), // scale the animation to fit the custom element clipSpec = LottieClipSpec.Progress(0f, progress), )}
clipSpec = LottieClipSpec.Progress(0f, progress) halkayı baştan progress değerine kadar bir kez doldurur. Uygulamanız streak’i zaten bir StateFlow içinde tutuyorsa, StreakStore yerine o StateFlow’u kullanın.
// the streak that your app keeps up to datepublic class StreakStore { public final MutableLiveData<Integer> currentStreak = new MutableLiveData<>(0); // days in a row}public class StreakRingView extends LottieAnimationView { private final StreakStore streakStore; private final Observer<Integer> streakObserver = streak -> { // 7 days fill the ring: from 0 for an empty ring to 1 for a full one float progress = Math.min(streak / 7f, 1f); setMinAndMaxProgress(0f, progress); playAnimation(); }; public StreakRingView(Context context, String animationFile, StreakStore streakStore) { super(context); this.streakStore = streakStore; setAnimation(animationFile); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); streakStore.currentStreak.observeForever(streakObserver); } @Override protected void onDetachedFromWindow() { streakStore.currentStreak.removeObserver(streakObserver); super.onDetachedFromWindow(); }}
setMinAndMaxProgress(0f, progress) ve playAnimation() fonksiyonları halkayı bir kez, boştan progress değerine kadar doldurur. Uygulamanız streak’i zaten bir LiveData içinde tutuyorsa, StreakStore yerine o LiveData’yı kullanın.
4. Animasyonu özel elemente bağla
Uygulama genelindeki resolver’ınıza, streak modeli için bir özellik ekleyin. Ardından lottie_animation Type’ı ve streak_ring ID’si için animasyon view’ını döndürün. Vurgulanan satırlar eklenecek veya değiştirilecek kısımları göstermektedir. Uygulamanızda henüz uygulama genelinde bir resolver yoksa tüm kodu kopyalayabilirsiniz:
class CustomElementsResolver( context: Context, private val streakStore: StreakStore,) : AdaptyCustomElementsResolver { // the animation files in the assets folder, listed once private val animationFiles: Set<String> = try { context.assets.list("").orEmpty().toSet() } catch (e: IOException) { emptySet() // no list of files: every Lottie element shows the fallback } override fun resolve(type: String, id: String): AdaptyCustomElementContent? = when (type) { "lottie_animation" -> { // the ID names the animation file, such as streak_ring.json val file = "$id.json" when { file !in animationFiles -> null // no file for this ID: show the fallback id == "streak_ring" -> AdaptyCustomElementContent.compose { StreakRing(file, streakStore) } // the other animations of your resolver else -> null } } // the other Types of your resolver else -> null }}
assets klasöründe ID için dosya yoksa, resolver null döndürür ve kullanıcılar yedek içeriği görür. Resolver’ınız zaten her animasyon dosyası için bir view döndürüyorsa, ID streak_ring olmadığında null yerine o view’ı döndürün. Bu sayede kullanıcılar diğer lottie_animation özel elementlerinizin animasyonlarını görmeye devam eder.
public class CustomElementsResolver implements AdaptyCustomElementsResolver { private final StreakStore streakStore; // the animation files in the assets folder, listed once private final Set<String> animationFiles = new HashSet<>(); public CustomElementsResolver(Context context, StreakStore streakStore) { this.streakStore = streakStore; try { String[] files = context.getAssets().list(""); if (files != null) { animationFiles.addAll(Arrays.asList(files)); } } catch (IOException e) { // no list of files: every Lottie element shows the fallback } } @Override public AdaptyCustomElementContent resolve(String type, String id) { if (type.equals("lottie_animation")) { // the ID names the animation file, such as streak_ring.json String file = id + ".json"; if (!animationFiles.contains(file)) { return null; // no file for this ID: show the fallback } if (id.equals("streak_ring")) { return AdaptyCustomElementContent.view( (context, elementContext) -> new StreakRingView(context, file, streakStore) ); } // the other animations of your resolver return null; } // the other Types of your resolver return null; }}
assets klasöründe ilgili ID için dosya yoksa, resolver null döndürür ve kullanıcılar yedek içeriği görür. Resolver’ınız zaten her animasyon dosyası için bir view döndürüyorsa, ID streak_ring olmadığında null yerine o view’ı döndürün. Bu sayede kullanıcılar diğer lottie_animation özel elementlerinizin animasyonlarını görmeye devam eder.
Streak modeliyle resolver’ı oluşturun ve uygulama genelinde geçerli resolver olarak ayarlayın. AdaptyUI.setCustomElementsResolver fonksiyonunu, örneğin uygulama başlangıcında, bir kez çağırın:
class App : Application() { // the streak model that your app updates val streakStore = StreakStore() // keep this instance: a resolver for one flow can reuse it // lazy: the context isn't attached yet while App is constructed val customElementsResolver by lazy { CustomElementsResolver(this, streakStore) } override fun onCreate() { super.onCreate() AdaptyUI.setCustomElementsResolver(customElementsResolver) }}
public class App extends Application { // the streak model that your app updates private final StreakStore streakStore = new StreakStore(); // keep this instance: a resolver for one flow can reuse it private CustomElementsResolver customElementsResolver; @Override public void onCreate() { super.onCreate(); customElementsResolver = new CustomElementsResolver(this, streakStore); AdaptyUI.setCustomElementsResolver(customElementsResolver); } public StreakStore getStreakStore() { return streakStore; } public CustomElementsResolver getCustomElementsResolver() { return customElementsResolver; }}
5. Cihazda test etme
Flow & Paywall Builder, uygulama kodunuzu çalıştıramadığından canvas yalnızca yedek içeriği gösterir. Animasyonu önizlemek için:
Flow’u yayınlayın. Önbelleğe alınmış sürüm yerine en son yayınlanan sürümü görmek için cihazı bir test cihazı olarak kaydedin.
Resolver’ı içeren bir uygulama derlemesi çalıştırın. Streak’i 0 güne ayarlayın, ekranı açın ve halkının boş kaldığını doğrulayın. 4 ve 7 gün ile tekrarlayın ve halkının her değere kadar dolduğunu doğrulayın.
Yedek içeriği test etmek için animasyon dosyasını derlemeden kaldırın ve ekranı tekrar açın.
Animasyon yerine neden yedek göründüğünü öğrenmek için Android kılavuzunun Cihazda test etme bölümündeki talimatları izleyin.