ShareImageDialogFragment.java 7.84 KB
package com.bitstrips.imoji.browser.fragments;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bitstrips.imoji.ImojiApplication;
import com.bitstrips.imoji.analytics.Action;
import com.bitstrips.imoji.analytics.AnalyticsHelper;
import com.bitstrips.imoji.analytics.AnalyticsWrapper;
import com.bitstrips.imoji.analytics.Category;
import com.bitstrips.imoji.analytics.LegacyAnalyticsService;
import com.bitstrips.imoji.models.Sticker;
import com.bitstrips.imoji.ui.ResolveInfosSorter;
import com.bitstrips.imoji.util.FileUtil;
import com.bitstrips.imoji.util.PreferenceUtils;
import com.bitstrips.imoji.util.ShareUtils;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;

public class ShareImageDialogFragment
  extends DialogFragment
{
  public static final String ANALYTICS_KEY = "ShareImageDialogFragment.analytics.wrapper";
  public static final String FILE_PATH_KEY = "filePath";
  public static final String INTENT_KEY = "intent";
  public static final String SAVE_BUTTON_TAG = "save";
  public static final String STICKER_KEY = "sticker";
  public static final String TAG = "ShareImageDialog";
  Sticker j;
  @Inject
  FileUtil k;
  @Inject
  PreferenceUtils l;
  @Inject
  LegacyAnalyticsService m;
  private Intent o;
  private String p;
  private OnShareListener q;
  
  static
  {
    if (!ShareImageDialogFragment.class.desiredAssertionStatus()) {}
    for (boolean bool = true;; bool = false)
    {
      n = bool;
      return;
    }
  }
  
  protected View createButton(LayoutInflater paramLayoutInflater, String paramString, Drawable paramDrawable)
  {
    paramLayoutInflater = paramLayoutInflater.inflate(2130903201, null);
    ((ImageView)paramLayoutInflater.findViewById(2131689935)).setImageDrawable(paramDrawable);
    ((TextView)paramLayoutInflater.findViewById(2131689936)).setText(paramString);
    return paramLayoutInflater;
  }
  
  protected View createShareToAppButton(LayoutInflater paramLayoutInflater, ResolveInfo paramResolveInfo)
  {
    String str2 = paramResolveInfo.loadLabel(getActivity().getPackageManager()).toString();
    final String str1 = paramResolveInfo.activityInfo.packageName;
    paramLayoutInflater = createButton(paramLayoutInflater, str2, paramResolveInfo.loadIcon(getActivity().getPackageManager()));
    paramLayoutInflater.setTag(str1);
    paramLayoutInflater.setOnClickListener(new View.OnClickListener()
    {
      public final void onClick(View paramAnonymousView)
      {
        ShareImageDialogFragment.this.l.increaseShareImageAppPriority(str1);
        ShareImageDialogFragment localShareImageDialogFragment = ShareImageDialogFragment.this;
        String str = str1;
        paramAnonymousView = null;
        if (localShareImageDialogFragment.getArguments().getSerializable("ShareImageDialogFragment.analytics.wrapper") != null) {
          paramAnonymousView = (AnalyticsWrapper)localShareImageDialogFragment.getArguments().getSerializable("ShareImageDialogFragment.analytics.wrapper");
        }
        Object localObject = paramAnonymousView;
        if (paramAnonymousView == null) {
          localObject = new AnalyticsWrapper().labelForImojiShare(localShareImageDialogFragment.j, "search");
        }
        AnalyticsHelper.sendShareEvents(localShareImageDialogFragment.m, str, (AnalyticsWrapper)localObject, localShareImageDialogFragment.l, Category.CLICK, Action.SHARE);
        ShareImageDialogFragment.this.shareToApp(str1);
        ShareImageDialogFragment.this.notifyShare();
        ShareImageDialogFragment.this.dismiss();
      }
    });
    return paramLayoutInflater;
  }
  
  protected void notifyShare()
  {
    if (this.q != null) {
      this.q.onShare(this.j);
    }
  }
  
  public void onAttach(Context paramContext)
  {
    super.onAttach(paramContext);
    if ((paramContext instanceof OnShareListener)) {
      this.q = ((OnShareListener)paramContext);
    }
  }
  
  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    ((ImojiApplication)getContext().getApplicationContext()).inject(this);
    this.o = ((Intent)getArguments().get("intent"));
    this.j = ((Sticker)getArguments().getSerializable("sticker"));
    this.p = getArguments().getString("filePath");
    setStyle(2, 16973836);
  }
  
  public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
  {
    getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(getResources().getColor(2131624117)));
    paramViewGroup = paramLayoutInflater.inflate(2130903202, paramViewGroup, false);
    if ((!n) && (paramViewGroup == null)) {
      throw new AssertionError();
    }
    paramViewGroup.findViewById(2131689938).setOnClickListener(new View.OnClickListener()
    {
      public final void onClick(View paramAnonymousView)
      {
        ShareImageDialogFragment.this.dismiss();
      }
    });
    ((ImageView)paramViewGroup.findViewById(2131689792)).setImageURI(Uri.parse(this.p));
    paramBundle = (LinearLayout)paramViewGroup.findViewById(2131689940);
    Object localObject = getActivity().getResources().getStringArray(2131296258);
    localObject = this.l.getShareImagePackagePriorityMap((String[])localObject);
    localObject = ResolveInfosSorter.sort(getActivity().getPackageManager().queryIntentActivities(this.o, 0), (Map)localObject).iterator();
    while (((Iterator)localObject).hasNext()) {
      paramBundle.addView(createShareToAppButton(paramLayoutInflater, (ResolveInfo)((Iterator)localObject).next()));
    }
    localObject = getResources().getDrawable(2130837742);
    paramLayoutInflater = createButton(paramLayoutInflater, getResources().getString(2131231022), (Drawable)localObject);
    paramLayoutInflater.setTag("save");
    paramLayoutInflater.setOnClickListener(new View.OnClickListener()
    {
      public final void onClick(View paramAnonymousView)
      {
        if (ShareImageDialogFragment.a(ShareImageDialogFragment.this) != null) {
          ShareImageDialogFragment.a(ShareImageDialogFragment.this).onRequestStoragePermissions();
        }
      }
    });
    paramBundle.addView(paramLayoutInflater);
    return paramViewGroup;
  }
  
  public void onDetach()
  {
    super.onDetach();
    this.q = null;
  }
  
  public void onWritePermission(boolean paramBoolean)
  {
    if (paramBoolean)
    {
      notifyShare();
      this.p = this.k.saveImoji(this.p);
      MediaScannerConnection.scanFile(getActivity(), new String[] { this.p }, new String[] { "image/png" }, null);
      Toast.makeText(getActivity(), 2131231024, 1).show();
      if ((getActivity() != null) && (!getActivity().isFinishing()) && (!isDetached())) {
        dismissAllowingStateLoss();
      }
    }
  }
  
  protected void shareToApp(String paramString)
  {
    ShareUtils.intentForApp(this.o, paramString);
    startActivity(this.o);
  }
  
  public static abstract interface OnShareListener
  {
    public abstract void onRequestStoragePermissions();
    
    public abstract void onShare(Sticker paramSticker);
  }
}


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