AppIndexablesFactory.java 7.73 KB
package com.bitstrips.imoji.firebase;

import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import com.bitstrips.imoji.firebase.models.IndexableSticker;
import com.bitstrips.imoji.firebase.models.IndexableSticker.Builder;
import com.bitstrips.imoji.firebase.models.IndexableStickerPack;
import com.bitstrips.imoji.firebase.models.IndexableStickerPack.Builder;
import com.bitstrips.imoji.models.Sticker;
import com.bitstrips.imoji.models.StickerPack;
import com.google.firebase.appindexing.FirebaseAppIndexingException;
import com.google.firebase.appindexing.Indexable;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import javax.inject.Singleton;

@Singleton
public class AppIndexablesFactory
{
  private static final String a = AppIndexablesFactory.class.getSimpleName();
  
  private static String a(Sticker paramSticker)
  {
    return "http://bitmoji.com/browser/" + paramSticker.getTemplateId();
  }
  
  private static String a(Sticker paramSticker, @NonNull String paramString)
  {
    return String.format(paramSticker.getImageUrl(), new Object[] { paramString });
  }
  
  @VisibleForTesting
  private static List<Sticker> a(StickerPack paramStickerPack)
  {
    ArrayList localArrayList = new ArrayList();
    paramStickerPack = paramStickerPack.getStickers().iterator();
    while (paramStickerPack.hasNext())
    {
      Sticker localSticker = (Sticker)paramStickerPack.next();
      if (localSticker.isSolomoji()) {
        localArrayList.add(localSticker);
      }
    }
    return localArrayList;
  }
  
  @VisibleForTesting
  private static Map<String, HashSet<String>> a(List<StickerPack> paramList)
  {
    LinkedHashMap localLinkedHashMap = new LinkedHashMap();
    paramList = paramList.iterator();
    while (paramList.hasNext())
    {
      StickerPack localStickerPack = (StickerPack)paramList.next();
      String str1 = localStickerPack.getTitle();
      Iterator localIterator = a(localStickerPack).iterator();
      while (localIterator.hasNext())
      {
        String str2 = ((Sticker)localIterator.next()).getComicId();
        if (!localLinkedHashMap.containsKey(str2)) {
          localLinkedHashMap.put(str2, new HashSet());
        }
        if (b(localStickerPack)) {
          ((HashSet)localLinkedHashMap.get(str2)).add(str1);
        }
      }
    }
    return localLinkedHashMap;
  }
  
  @VisibleForTesting
  private static List<String> b(List<String> paramList)
  {
    LinkedHashSet localLinkedHashSet = new LinkedHashSet(paramList.size());
    Iterator localIterator = paramList.iterator();
    while (localIterator.hasNext())
    {
      String str = (String)localIterator.next();
      paramList = str;
      if (str.endsWith("*")) {
        paramList = str.substring(0, str.length() - 1);
      }
      localLinkedHashSet.add(paramList);
    }
    return new ArrayList(localLinkedHashSet);
  }
  
  private static boolean b(StickerPack paramStickerPack)
  {
    return (paramStickerPack.isVisible()) || ("popular".equals(paramStickerPack.getId()));
  }
  
  public static IndexablesDiff<IndexableStickerPack> generateIndexableStickerPacks(List<StickerPack> paramList, String paramString, Map<String, IndexableStickerPack> paramMap)
  {
    localArrayList1 = new ArrayList();
    localArrayList2 = new ArrayList();
    localHashSet = new HashSet(paramMap.keySet());
    paramList = paramList.iterator();
    int j;
    for (int i = 1; paramList.hasNext(); i = j)
    {
      Object localObject = (StickerPack)paramList.next();
      j = i;
      if (b((StickerPack)localObject))
      {
        ArrayList localArrayList3 = new ArrayList();
        Iterator localIterator = a((StickerPack)localObject).iterator();
        while (localIterator.hasNext())
        {
          Sticker localSticker = (Sticker)localIterator.next();
          localArrayList3.add(new IndexableSticker.Builder().fromSticker(localSticker).setGeneratedUrl(a(localSticker)).setImageUrl(a(localSticker, paramString)).build());
        }
        localObject = new IndexableStickerPack.Builder().fromStickerPack((StickerPack)localObject).setUrl(getStickerPackIndexableUrl(((StickerPack)localObject).getTitle())).setStickers(localArrayList3).build();
        if (!((IndexableStickerPack)localObject).equals((IndexableStickerPack)paramMap.get(((IndexableStickerPack)localObject).getUrl()))) {
          i = 0;
        }
        localArrayList1.add(localObject);
        localHashSet.remove(((IndexableStickerPack)localObject).getUrl());
        j = i;
      }
    }
    if (i == 0) {
      try
      {
        paramList = localArrayList1.iterator();
        while (paramList.hasNext()) {
          localArrayList2.add(((IndexableStickerPack)paramList.next()).toIndexable());
        }
        return new IndexablesDiff(localArrayList1, localArrayList2, new ArrayList(localHashSet));
      }
      catch (FirebaseAppIndexingException paramList)
      {
        throw new IllegalStateException("Failed to format sticker packs into indexables", paramList);
      }
    }
  }
  
  public static IndexablesDiff<IndexableSticker> generateIndexableStickers(List<StickerPack> paramList, String paramString, Map<String, IndexableSticker> paramMap)
  {
    localLinkedHashMap = new LinkedHashMap();
    Map localMap = a(paramList);
    localArrayList = new ArrayList();
    localHashSet = new HashSet(paramMap.keySet());
    try
    {
      paramList = paramList.iterator();
      while (paramList.hasNext())
      {
        Iterator localIterator = a((StickerPack)paramList.next()).iterator();
        while (localIterator.hasNext())
        {
          Sticker localSticker = (Sticker)localIterator.next();
          if (!localLinkedHashMap.containsKey(localSticker.getComicId()))
          {
            IndexableSticker localIndexableSticker = new IndexableSticker.Builder().fromSticker(localSticker).setGeneratedUrl(a(localSticker)).setImageUrl(a(localSticker, paramString)).setTags(b(localSticker.getTags())).setStickerPackNames(new ArrayList((Collection)localMap.get(localSticker.getComicId()))).build();
            localLinkedHashMap.put(localSticker.getComicId(), localIndexableSticker);
            if (!localIndexableSticker.equals((IndexableSticker)paramMap.get(localIndexableSticker.getGeneratedUrl()))) {
              localArrayList.add(localIndexableSticker.toIndexable());
            }
            localHashSet.remove(localIndexableSticker.getGeneratedUrl());
          }
        }
      }
      return new IndexablesDiff(new ArrayList(localLinkedHashMap.values()), localArrayList, new ArrayList(localHashSet));
    }
    catch (FirebaseAppIndexingException paramList)
    {
      throw new IllegalStateException("Failed to format stickers into indexables", paramList);
    }
  }
  
  public static String getStickerPackIndexableUrl(String paramString)
  {
    return "http://bitmoji.com/browser/section/" + paramString;
  }
  
  public static class IndexablesDiff<T extends Serializable>
  {
    private final List<T> a;
    private final List<Indexable> b;
    private final List<String> c;
    
    public IndexablesDiff(List<T> paramList, List<Indexable> paramList1, List<String> paramList2)
    {
      this.a = paramList;
      this.b = paramList1;
      this.c = paramList2;
    }
    
    public List<String> getIndexableUrlsToRemove()
    {
      return this.c;
    }
    
    public List<Indexable> getIndexablesToUpdate()
    {
      return this.b;
    }
    
    public List<T> getSerializables()
    {
      return this.a;
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/bitstrips/imoji/firebase/AppIndexablesFactory.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */