SearchContainerFragment.java 7.88 KB
package com.bitstrips.imoji.ui.fragments;

import android.app.SearchManager;
import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.SearchView.OnQueryTextListener;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import com.bitstrips.imoji.analytics.Action;
import com.bitstrips.imoji.analytics.AnalyticsWrapper;
import com.bitstrips.imoji.analytics.Category;
import com.bitstrips.imoji.analytics.LegacyAnalyticsService;
import com.bitstrips.imoji.analytics.SearchSource;
import com.bitstrips.imoji.browser.adapters.SearchTagsAdapter;
import com.bitstrips.imoji.browser.views.SearchTagViewHolder.OnSearchTagClickListener;
import com.bitstrips.imoji.manager.StickerPacksManager;
import com.bitstrips.imoji.models.SearchTagFactory;
import com.bitstrips.imoji.models.StickerPacks;
import com.bitstrips.imoji.search.PrefixSearchEngine;
import com.bitstrips.imoji.search.PrefixSearchEngine.Callback;
import com.bitstrips.imoji.search.SearchIndex;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;

public class SearchContainerFragment
  extends BitmojiBaseFragment
  implements SearchTagViewHolder.OnSearchTagClickListener
{
  SearchView a;
  View b;
  RecyclerView c;
  @Inject
  SearchIndex d;
  @Inject
  StickerPacksManager e;
  @Inject
  LegacyAnalyticsService f;
  private SearchSource g;
  private ImageView h;
  private PrefixSearchEngine i;
  private View.OnClickListener j = new View.OnClickListener()
  {
    public final void onClick(View paramAnonymousView)
    {
      SearchContainerFragment.this.onBackPressed();
    }
  };
  
  private void a()
  {
    this.a.post(new Runnable()
    {
      public final void run()
      {
        SearchContainerFragment.this.a.getRootView().clearFocus();
        if ((SearchContainerFragment.this.isActivityValid()) && (SearchContainerFragment.this.getActivity().getCurrentFocus() != null)) {
          SearchContainerFragment.this.getActivity().getCurrentFocus().clearFocus();
        }
      }
    });
  }
  
  private void a(String paramString, List<String> paramList, SearchSource paramSearchSource, boolean paramBoolean)
  {
    if (!isActivityValid()) {
      return;
    }
    try
    {
      getFragmentManager().popBackStack();
      paramString = SearchResultFragment.newInstance(paramString, paramList, paramSearchSource, paramBoolean);
      paramList = getFragmentManager().beginTransaction();
      paramList.replace(2131689736, paramString, "fragments.SearchResultFragment").addToBackStack("fragments.SearchResultFragment");
      paramList.commit();
      return;
    }
    catch (Exception paramString) {}
  }
  
  private void a(boolean paramBoolean)
  {
    int k = 0;
    Object localObject = this.h.getLayoutParams();
    if (paramBoolean)
    {
      ((ViewGroup.LayoutParams)localObject).width = -2;
      ((ViewGroup.LayoutParams)localObject).height = -2;
      this.h.setImageResource(2130837724);
      this.h.setLayoutParams((ViewGroup.LayoutParams)localObject);
      localObject = this.b;
      if (!paramBoolean) {
        break label79;
      }
    }
    for (;;)
    {
      ((View)localObject).setVisibility(k);
      return;
      ((ViewGroup.LayoutParams)localObject).width = 0;
      ((ViewGroup.LayoutParams)localObject).height = 0;
      this.h.setImageBitmap(null);
      break;
      label79:
      k = 8;
    }
  }
  
  public static SearchContainerFragment newInstance()
  {
    return new SearchContainerFragment();
  }
  
  public String getFragmentIdentity()
  {
    return "#search";
  }
  
  public String getFragmentSuperTag()
  {
    return null;
  }
  
  protected int getLayout()
  {
    return 2130903113;
  }
  
  protected void initSubViews(View paramView)
  {
    this.a = ((SearchView)paramView.findViewById(2131689733));
    this.b = paramView.findViewById(2131689734);
    this.c = ((RecyclerView)paramView.findViewById(2131689735));
    paramView = (SearchManager)getContext().getSystemService("search");
    this.a.setSearchableInfo(paramView.getSearchableInfo(getActivity().getComponentName()));
    a();
    this.h = ((ImageView)this.a.findViewById(2131689612));
    this.h.setOnClickListener(this.j);
    this.h.setPadding(0, 0, 0, 0);
    a(false);
    this.b.setOnClickListener(this.j);
    this.a.setInputType(65536);
    this.a.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener()
    {
      public final void onFocusChange(View paramAnonymousView, boolean paramAnonymousBoolean)
      {
        if (!paramAnonymousBoolean) {
          ((InputMethodManager)SearchContainerFragment.this.getContext().getSystemService("input_method")).hideSoftInputFromWindow(paramAnonymousView.getWindowToken(), 0);
        }
      }
    });
    a();
    this.c.setHasFixedSize(true);
  }
  
  public void onBackPressed()
  {
    this.a.setQuery("", false);
    a();
    getFragmentManager().popBackStack();
    a(false);
  }
  
  public void onClick(String paramString)
  {
    if (isActivityValid())
    {
      int k = this.d.getStickersForTag(paramString).size();
      this.f.sendEvent(Category.CLICK, Action.SEARCH, new AnalyticsWrapper().labelForSearchSubmit(paramString, k));
      onQuerySubmit(paramString, SearchSource.TAG, false);
    }
  }
  
  public void onPause()
  {
    super.onPause();
    this.a.setOnQueryTextListener(null);
  }
  
  public void onQuerySubmit(final String paramString, SearchSource paramSearchSource, final boolean paramBoolean)
  {
    if (TextUtils.isEmpty(paramString)) {
      return;
    }
    this.a.setQuery(paramString, false);
    a(true);
    a();
    this.g = paramSearchSource;
    if (paramSearchSource == SearchSource.TAG)
    {
      a(paramString, Collections.singletonList(paramString), paramSearchSource, paramBoolean);
      return;
    }
    this.i.fetchMatchingTags(paramString, new PrefixSearchEngine.Callback()
    {
      public final void onComplete(List<String> paramAnonymousList)
      {
        SearchContainerFragment.a(SearchContainerFragment.this, paramString, paramAnonymousList, SearchSource.SEARCH, paramBoolean);
      }
    });
  }
  
  public void onResume()
  {
    super.onResume();
    this.a.setOnQueryTextListener(new SearchView.OnQueryTextListener()
    {
      public final boolean onQueryTextChange(String paramAnonymousString)
      {
        SearchContainerFragment.a(SearchContainerFragment.this, paramAnonymousString.isEmpty());
        return false;
      }
      
      public final boolean onQueryTextSubmit(String paramAnonymousString)
      {
        SearchContainerFragment.this.onQuerySubmit(paramAnonymousString, SearchSource.SEARCH, false);
        return true;
      }
    });
  }
  
  public void onStart()
  {
    super.onStart();
    this.i = new PrefixSearchEngine(this.d);
    Object localObject = this.e.getStickerPacks();
    if (localObject != null)
    {
      localObject = SearchTagFactory.fromStickerPacks(((StickerPacks)localObject).get());
      if (isActivityValid())
      {
        localObject = new SearchTagsAdapter((List)localObject, this);
        this.c.setAdapter((RecyclerView.Adapter)localObject);
        this.c.setLayoutManager(new GridLayoutManager(getActivity(), 2));
      }
    }
    if (!TextUtils.isEmpty(this.a.getQuery())) {
      onQuerySubmit(String.valueOf(this.a.getQuery()), this.g, true);
    }
  }
}


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