CheckUpdateTaskWithUI.java 4.88 KB
package net.hockeyapp.android.tasks;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.widget.Toast;
import java.lang.ref.WeakReference;
import net.hockeyapp.android.R.string;
import net.hockeyapp.android.UpdateActivity;
import net.hockeyapp.android.UpdateManagerListener;
import net.hockeyapp.android.utils.HockeyLog;
import net.hockeyapp.android.utils.Util;
import net.hockeyapp.android.utils.VersionCache;
import org.json.JSONArray;

public class CheckUpdateTaskWithUI
  extends CheckUpdateTask
{
  private Activity a = null;
  private AlertDialog b = null;
  protected boolean mIsDialogRequired = false;
  
  public CheckUpdateTaskWithUI(WeakReference<Activity> paramWeakReference, String paramString1, String paramString2, UpdateManagerListener paramUpdateManagerListener, boolean paramBoolean)
  {
    super(paramWeakReference, paramString1, paramString2, paramUpdateManagerListener);
    if (paramWeakReference != null) {
      this.a = ((Activity)paramWeakReference.get());
    }
    this.mIsDialogRequired = paramBoolean;
  }
  
  private void a(JSONArray paramJSONArray, Boolean paramBoolean)
  {
    Object localObject1 = null;
    if (this.listener != null) {
      localObject1 = this.listener.getUpdateActivityClass();
    }
    Object localObject2 = localObject1;
    if (localObject1 == null) {
      localObject2 = UpdateActivity.class;
    }
    if (this.a != null)
    {
      localObject1 = new Intent();
      ((Intent)localObject1).setClass(this.a, (Class)localObject2);
      ((Intent)localObject1).putExtra("json", paramJSONArray.toString());
      ((Intent)localObject1).putExtra("url", getURLString("apk"));
      this.a.startActivity((Intent)localObject1);
      if (paramBoolean.booleanValue()) {
        this.a.finish();
      }
    }
    cleanUp();
  }
  
  protected void cleanUp()
  {
    super.cleanUp();
    this.a = null;
    this.b = null;
  }
  
  public void detach()
  {
    super.detach();
    this.a = null;
    if (this.b != null)
    {
      this.b.dismiss();
      this.b = null;
    }
  }
  
  protected void onPostExecute(final JSONArray paramJSONArray)
  {
    super.onPostExecute(paramJSONArray);
    if ((paramJSONArray != null) && (this.mIsDialogRequired))
    {
      if (getCachingEnabled())
      {
        HockeyLog.verbose("HockeyUpdate", "Caching is enabled. Setting version to cached one.");
        VersionCache.setVersionInfo(this.a, paramJSONArray.toString());
      }
      if ((this.a != null) && (!this.a.isFinishing())) {}
    }
    else
    {
      return;
    }
    Object localObject = new AlertDialog.Builder(this.a);
    ((AlertDialog.Builder)localObject).setTitle(R.string.hockeyapp_update_dialog_title);
    if (!this.mandatory.booleanValue())
    {
      ((AlertDialog.Builder)localObject).setMessage(R.string.hockeyapp_update_dialog_message);
      ((AlertDialog.Builder)localObject).setNegativeButton(R.string.hockeyapp_update_dialog_negative_button, new DialogInterface.OnClickListener()
      {
        public final void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
        {
          CheckUpdateTaskWithUI.this.cleanUp();
          if (CheckUpdateTaskWithUI.this.listener != null) {
            CheckUpdateTaskWithUI.this.listener.onCancel();
          }
        }
      });
      ((AlertDialog.Builder)localObject).setPositiveButton(R.string.hockeyapp_update_dialog_positive_button, new DialogInterface.OnClickListener()
      {
        public final void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
        {
          if (CheckUpdateTaskWithUI.this.getCachingEnabled()) {
            VersionCache.setVersionInfo(CheckUpdateTaskWithUI.a(CheckUpdateTaskWithUI.this), "[]");
          }
          paramAnonymousDialogInterface = new WeakReference(CheckUpdateTaskWithUI.a(CheckUpdateTaskWithUI.this));
          if ((Util.fragmentsSupported().booleanValue()) && (Util.runsOnTablet(paramAnonymousDialogInterface).booleanValue()))
          {
            CheckUpdateTaskWithUI.a(CheckUpdateTaskWithUI.this, paramJSONArray);
            return;
          }
          CheckUpdateTaskWithUI.a(CheckUpdateTaskWithUI.this, paramJSONArray, Boolean.valueOf(false));
        }
      });
      this.b = ((AlertDialog.Builder)localObject).create();
      this.b.show();
      return;
    }
    localObject = Util.getAppName(this.a);
    localObject = String.format(this.a.getString(R.string.hockeyapp_update_mandatory_toast), new Object[] { localObject });
    Toast.makeText(this.a, (CharSequence)localObject, 1).show();
    a(paramJSONArray, Boolean.valueOf(true));
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/net/hockeyapp/android/tasks/CheckUpdateTaskWithUI.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */