FeedbackActivity.java 20.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
package net.hockeyapp.android;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.NotificationManager;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import java.lang.ref.WeakReference;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import net.hockeyapp.android.adapters.MessagesAdapter;
import net.hockeyapp.android.objects.ErrorObject;
import net.hockeyapp.android.objects.Feedback;
import net.hockeyapp.android.objects.FeedbackMessage;
import net.hockeyapp.android.objects.FeedbackResponse;
import net.hockeyapp.android.objects.FeedbackUserDataElement;
import net.hockeyapp.android.tasks.ParseFeedbackTask;
import net.hockeyapp.android.tasks.SendFeedbackTask;
import net.hockeyapp.android.utils.AsyncTaskUtils;
import net.hockeyapp.android.utils.HockeyLog;
import net.hockeyapp.android.utils.PrefsUtil;
import net.hockeyapp.android.utils.Util;
import net.hockeyapp.android.views.AttachmentListView;
import net.hockeyapp.android.views.AttachmentView;

public class FeedbackActivity
  extends Activity
  implements View.OnClickListener
{
  public static final String EXTRA_INITIAL_ATTACHMENTS = "initialAttachments";
  public static final String EXTRA_INITIAL_USER_EMAIL = "initialUserEmail";
  public static final String EXTRA_INITIAL_USER_NAME = "initialUserName";
  public static final String EXTRA_URL = "url";
  private String A;
  private String a;
  private String b;
  private Context c;
  private TextView d;
  private EditText e;
  private EditText f;
  private EditText g;
  private EditText h;
  private Button i;
  private Button j;
  private Button k;
  private Button l;
  private ScrollView m;
  private LinearLayout n;
  private ListView o;
  private SendFeedbackTask p;
  private Handler q;
  private ParseFeedbackTask r;
  private Handler s;
  private List<Uri> t;
  private String u;
  private ErrorObject v;
  private MessagesAdapter w;
  private ArrayList<FeedbackMessage> x;
  private boolean y;
  private boolean z;
  
  private void a()
  {
    this.A = PrefsUtil.getInstance().getFeedbackTokenFromPrefs(this);
    if ((this.A == null) || (this.y))
    {
      configureFeedbackView(false);
      return;
    }
    configureFeedbackView(true);
    a(this.u, null, null, null, null, null, this.A, this.q, true);
  }
  
  private void a(EditText paramEditText, int paramInt)
  {
    paramEditText.setError(getString(paramInt));
    enableDisableSendFeedbackButton(true);
  }
  
  private void a(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, List<Uri> paramList, String paramString6, Handler paramHandler, boolean paramBoolean)
  {
    this.p = new SendFeedbackTask(this.c, paramString1, paramString2, paramString3, paramString4, paramString5, paramList, paramString6, paramHandler, paramBoolean);
    AsyncTaskUtils.execute(this.p);
  }
  
  protected void configureFeedbackView(boolean paramBoolean)
  {
    this.m = ((ScrollView)findViewById(R.id.wrapper_feedback_scroll));
    this.n = ((LinearLayout)findViewById(R.id.wrapper_messages));
    this.o = ((ListView)findViewById(R.id.list_feedback_messages));
    if (paramBoolean)
    {
      this.n.setVisibility(0);
      this.m.setVisibility(8);
      this.d = ((TextView)findViewById(R.id.label_last_updated));
      this.k = ((Button)findViewById(R.id.button_add_response));
      this.k.setOnClickListener(this);
      this.l = ((Button)findViewById(R.id.button_refresh));
      this.l.setOnClickListener(this);
      return;
    }
    this.n.setVisibility(8);
    this.m.setVisibility(0);
    this.e = ((EditText)findViewById(R.id.input_name));
    this.f = ((EditText)findViewById(R.id.input_email));
    this.g = ((EditText)findViewById(R.id.input_subject));
    this.h = ((EditText)findViewById(R.id.input_message));
    Object localObject;
    if (!this.z)
    {
      localObject = PrefsUtil.getInstance().getNameEmailFromPrefs(this.c);
      if (localObject == null) {
        break label394;
      }
      localObject = ((String)localObject).split("\\|");
      if ((localObject != null) && (localObject.length >= 2))
      {
        this.e.setText(localObject[0]);
        this.f.setText(localObject[1]);
        if (localObject.length >= 3)
        {
          this.g.setText(localObject[2]);
          this.h.requestFocus();
        }
      }
      else
      {
        this.z = true;
      }
    }
    else
    {
      this.h.setText("");
      if (PrefsUtil.getInstance().getFeedbackTokenFromPrefs(this.c) == null) {
        break label479;
      }
      this.g.setVisibility(8);
    }
    for (;;)
    {
      localObject = (ViewGroup)findViewById(R.id.wrapper_attachments);
      ((ViewGroup)localObject).removeAllViews();
      if (this.t == null) {
        break label490;
      }
      Iterator localIterator = this.t.iterator();
      while (localIterator.hasNext()) {
        ((ViewGroup)localObject).addView(new AttachmentView(this, (ViewGroup)localObject, (Uri)localIterator.next(), true));
      }
      this.g.requestFocus();
      break;
      label394:
      this.e.setText(this.a);
      this.f.setText(this.b);
      this.g.setText("");
      if (TextUtils.isEmpty(this.a))
      {
        this.e.requestFocus();
        break;
      }
      if (TextUtils.isEmpty(this.b))
      {
        this.f.requestFocus();
        break;
      }
      this.g.requestFocus();
      break;
      label479:
      this.g.setVisibility(0);
    }
    label490:
    this.j = ((Button)findViewById(R.id.button_attachment));
    this.j.setOnClickListener(this);
    registerForContextMenu(this.j);
    this.i = ((Button)findViewById(R.id.button_send));
    this.i.setOnClickListener(this);
  }
  
  public void enableDisableSendFeedbackButton(boolean paramBoolean)
  {
    if (this.i != null) {
      this.i.setEnabled(paramBoolean);
    }
  }
  
  @SuppressLint({"InflateParams"})
  public View getLayoutView()
  {
    return getLayoutInflater().inflate(R.layout.hockeyapp_activity_feedback, null);
  }
  
  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    if (paramInt2 != -1) {}
    do
    {
      do
      {
        do
        {
          do
          {
            return;
            if (paramInt1 != 2) {
              break;
            }
            paramIntent = paramIntent.getData();
          } while (paramIntent == null);
          localObject = (ViewGroup)findViewById(R.id.wrapper_attachments);
          ((ViewGroup)localObject).addView(new AttachmentView(this, (ViewGroup)localObject, paramIntent, true));
          return;
          if (paramInt1 != 1) {
            break;
          }
          paramIntent = paramIntent.getData();
        } while (paramIntent == null);
        try
        {
          localObject = new Intent(this, PaintActivity.class);
          ((Intent)localObject).putExtra("imageUri", paramIntent);
          startActivityForResult((Intent)localObject, 3);
          return;
        }
        catch (ActivityNotFoundException paramIntent)
        {
          HockeyLog.error("HockeyApp", "Paint activity not declared!", paramIntent);
          return;
        }
      } while (paramInt1 != 3);
      paramIntent = (Uri)paramIntent.getParcelableExtra("imageUri");
    } while (paramIntent == null);
    Object localObject = (ViewGroup)findViewById(R.id.wrapper_attachments);
    ((ViewGroup)localObject).addView(new AttachmentView(this, (ViewGroup)localObject, paramIntent, true));
  }
  
  public void onClick(View paramView)
  {
    int i1 = paramView.getId();
    if (i1 == R.id.button_send) {
      if (!Util.isConnectedToNetwork(this)) {
        Toast.makeText(this, R.string.hockeyapp_error_no_network_message, 1).show();
      }
    }
    do
    {
      return;
      enableDisableSendFeedbackButton(false);
      if (this.h != null) {
        ((InputMethodManager)getSystemService("input_method")).hideSoftInputFromWindow(this.h.getWindowToken(), 0);
      }
      paramView = PrefsUtil.getInstance().getFeedbackTokenFromPrefs(this.c);
      String str1 = this.e.getText().toString().trim();
      String str2 = this.f.getText().toString().trim();
      String str3 = this.g.getText().toString().trim();
      String str4 = this.h.getText().toString().trim();
      if (TextUtils.isEmpty(str3))
      {
        this.g.setVisibility(0);
        a(this.g, R.string.hockeyapp_feedback_validate_subject_error);
        return;
      }
      if ((FeedbackManager.getRequireUserName() == FeedbackUserDataElement.REQUIRED) && (TextUtils.isEmpty(str1)))
      {
        a(this.e, R.string.hockeyapp_feedback_validate_name_error);
        return;
      }
      if ((FeedbackManager.getRequireUserEmail() == FeedbackUserDataElement.REQUIRED) && (TextUtils.isEmpty(str2)))
      {
        a(this.f, R.string.hockeyapp_feedback_validate_email_empty);
        return;
      }
      if (TextUtils.isEmpty(str4))
      {
        a(this.h, R.string.hockeyapp_feedback_validate_text_error);
        return;
      }
      if ((FeedbackManager.getRequireUserEmail() == FeedbackUserDataElement.REQUIRED) && (!Util.isValidEmail(str2)))
      {
        a(this.f, R.string.hockeyapp_feedback_validate_email_error);
        return;
      }
      PrefsUtil.getInstance().saveNameEmailSubjectToPrefs(this.c, str1, str2, str3);
      ArrayList localArrayList = ((AttachmentListView)findViewById(R.id.wrapper_attachments)).getAttachments();
      a(this.u, str1, str2, str3, str4, localArrayList, paramView, this.q, false);
      return;
      if (i1 == R.id.button_attachment)
      {
        if (((ViewGroup)findViewById(R.id.wrapper_attachments)).getChildCount() >= 3)
        {
          Toast.makeText(this, "3", 0).show();
          return;
        }
        openContextMenu(paramView);
        return;
      }
      if (i1 == R.id.button_add_response)
      {
        configureFeedbackView(false);
        this.y = true;
        return;
      }
    } while (i1 != R.id.button_refresh);
    a(this.u, null, null, null, null, null, PrefsUtil.getInstance().getFeedbackTokenFromPrefs(this.c), this.q, true);
  }
  
  public boolean onContextItemSelected(MenuItem paramMenuItem)
  {
    switch (paramMenuItem.getItemId())
    {
    default: 
      return super.onContextItemSelected(paramMenuItem);
    }
    int i1 = paramMenuItem.getItemId();
    if (i1 == 2)
    {
      paramMenuItem = new Intent();
      paramMenuItem.setType("*/*");
      paramMenuItem.setAction("android.intent.action.GET_CONTENT");
      startActivityForResult(Intent.createChooser(paramMenuItem, getString(R.string.hockeyapp_feedback_select_file)), 2);
      return true;
    }
    if (i1 == 1)
    {
      paramMenuItem = new Intent();
      paramMenuItem.setType("image/*");
      paramMenuItem.setAction("android.intent.action.GET_CONTENT");
      startActivityForResult(Intent.createChooser(paramMenuItem, getString(R.string.hockeyapp_feedback_select_picture)), 1);
      return true;
    }
    return false;
  }
  
  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(getLayoutView());
    setTitle(getString(R.string.hockeyapp_feedback_title));
    this.c = this;
    Object localObject1 = getIntent().getExtras();
    if (localObject1 != null)
    {
      this.u = ((Bundle)localObject1).getString("url");
      this.a = ((Bundle)localObject1).getString("initialUserName");
      this.b = ((Bundle)localObject1).getString("initialUserEmail");
      localObject1 = ((Bundle)localObject1).getParcelableArray("initialAttachments");
      if (localObject1 != null)
      {
        this.t = new ArrayList();
        int i2 = localObject1.length;
        int i1 = 0;
        while (i1 < i2)
        {
          Object localObject2 = localObject1[i1];
          this.t.add((Uri)localObject2);
          i1 += 1;
        }
      }
    }
    if (paramBundle != null)
    {
      this.z = paramBundle.getBoolean("feedbackViewInitialized");
      this.y = paramBundle.getBoolean("inSendFeedback");
    }
    for (;;)
    {
      ((NotificationManager)getSystemService("notification")).cancel(2);
      this.q = new a(this);
      this.s = new b(this);
      a();
      return;
      this.y = false;
      this.z = false;
    }
  }
  
  public void onCreateContextMenu(ContextMenu paramContextMenu, View paramView, ContextMenu.ContextMenuInfo paramContextMenuInfo)
  {
    super.onCreateContextMenu(paramContextMenu, paramView, paramContextMenuInfo);
    paramContextMenu.add(0, 2, 0, getString(R.string.hockeyapp_feedback_attach_file));
    paramContextMenu.add(0, 1, 0, getString(R.string.hockeyapp_feedback_attach_picture));
  }
  
  protected Dialog onCreateDialog(int paramInt)
  {
    switch (paramInt)
    {
    default: 
      return null;
    }
    new AlertDialog.Builder(this).setMessage(getString(R.string.hockeyapp_dialog_error_message)).setCancelable(false).setTitle(getString(R.string.hockeyapp_dialog_error_title)).setIcon(17301543).setPositiveButton(getString(R.string.hockeyapp_dialog_positive_button), new DialogInterface.OnClickListener()
    {
      public final void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
        FeedbackActivity.a(FeedbackActivity.this, null);
        paramAnonymousDialogInterface.cancel();
      }
    }).create();
  }
  
  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    if (paramInt == 4)
    {
      if (this.y)
      {
        this.y = false;
        a();
      }
      for (;;)
      {
        return true;
        finish();
      }
    }
    return super.onKeyDown(paramInt, paramKeyEvent);
  }
  
  protected void onPrepareDialog(int paramInt, Dialog paramDialog)
  {
    switch (paramInt)
    {
    default: 
      return;
    }
    paramDialog = (AlertDialog)paramDialog;
    if (this.v != null)
    {
      paramDialog.setMessage(this.v.getMessage());
      return;
    }
    paramDialog.setMessage(getString(R.string.hockeyapp_feedback_generic_error));
  }
  
  protected void onRestoreInstanceState(Bundle paramBundle)
  {
    if (paramBundle != null)
    {
      ViewGroup localViewGroup = (ViewGroup)findViewById(R.id.wrapper_attachments);
      Iterator localIterator = paramBundle.getParcelableArrayList("attachments").iterator();
      while (localIterator.hasNext())
      {
        Uri localUri = (Uri)localIterator.next();
        if (!this.t.contains(localUri)) {
          localViewGroup.addView(new AttachmentView(this, localViewGroup, localUri, true));
        }
      }
      this.z = paramBundle.getBoolean("feedbackViewInitialized");
    }
    super.onRestoreInstanceState(paramBundle);
  }
  
  public Object onRetainNonConfigurationInstance()
  {
    if (this.p != null) {
      this.p.detach();
    }
    return this.p;
  }
  
  protected void onSaveInstanceState(Bundle paramBundle)
  {
    paramBundle.putParcelableArrayList("attachments", ((AttachmentListView)findViewById(R.id.wrapper_attachments)).getAttachments());
    paramBundle.putBoolean("feedbackViewInitialized", this.z);
    paramBundle.putBoolean("inSendFeedback", this.y);
    super.onSaveInstanceState(paramBundle);
  }
  
  protected void onSendFeedbackResult(boolean paramBoolean) {}
  
  protected void onStop()
  {
    super.onStop();
    if (this.p != null) {
      this.p.detach();
    }
  }
  
  static final class a
    extends Handler
  {
    private final WeakReference<FeedbackActivity> a;
    
    public a(FeedbackActivity paramFeedbackActivity)
    {
      this.a = new WeakReference(paramFeedbackActivity);
    }
    
    public final void handleMessage(Message paramMessage)
    {
      boolean bool = false;
      ErrorObject localErrorObject = new ErrorObject();
      final FeedbackActivity localFeedbackActivity = (FeedbackActivity)this.a.get();
      if (localFeedbackActivity == null) {
        return;
      }
      Object localObject;
      String str;
      if ((paramMessage != null) && (paramMessage.getData() != null))
      {
        localObject = paramMessage.getData();
        paramMessage = ((Bundle)localObject).getString("feedback_response");
        str = ((Bundle)localObject).getString("feedback_status");
        localObject = ((Bundle)localObject).getString("request_type");
        if ((((String)localObject).equals("send")) && ((paramMessage == null) || (Integer.parseInt(str) != 201))) {
          localErrorObject.setMessage(localFeedbackActivity.getString(R.string.hockeyapp_feedback_send_generic_error));
        }
      }
      for (;;)
      {
        FeedbackActivity.a(localFeedbackActivity, localErrorObject);
        if (!bool) {
          localFeedbackActivity.runOnUiThread(new Runnable()
          {
            public final void run()
            {
              localFeedbackActivity.enableDisableSendFeedbackButton(true);
              localFeedbackActivity.showDialog(0);
            }
          });
        }
        localFeedbackActivity.onSendFeedbackResult(bool);
        return;
        if ((((String)localObject).equals("fetch")) && (str != null) && ((Integer.parseInt(str) == 404) || (Integer.parseInt(str) == 422)))
        {
          FeedbackActivity.f(localFeedbackActivity);
          bool = true;
        }
        else if (paramMessage != null)
        {
          FeedbackActivity.a(localFeedbackActivity, paramMessage, (String)localObject);
          bool = true;
        }
        else
        {
          localErrorObject.setMessage(localFeedbackActivity.getString(R.string.hockeyapp_feedback_send_network_error));
          continue;
          localErrorObject.setMessage(localFeedbackActivity.getString(R.string.hockeyapp_feedback_send_generic_error));
        }
      }
    }
  }
  
  static final class b
    extends Handler
  {
    private final WeakReference<FeedbackActivity> a;
    
    public b(FeedbackActivity paramFeedbackActivity)
    {
      this.a = new WeakReference(paramFeedbackActivity);
    }
    
    public final void handleMessage(Message paramMessage)
    {
      final FeedbackActivity localFeedbackActivity = (FeedbackActivity)this.a.get();
      if (localFeedbackActivity == null) {
        return;
      }
      FeedbackActivity.a(localFeedbackActivity, new ErrorObject());
      int i;
      if ((paramMessage != null) && (paramMessage.getData() != null))
      {
        paramMessage = (FeedbackResponse)paramMessage.getData().getSerializable("parse_feedback_response");
        if (paramMessage != null) {
          if (paramMessage.getStatus().equalsIgnoreCase("success"))
          {
            if (paramMessage.getToken() == null) {
              break label126;
            }
            PrefsUtil.getInstance().saveFeedbackTokenToPrefs(localFeedbackActivity, paramMessage.getToken());
            FeedbackActivity.a(localFeedbackActivity, paramMessage);
            FeedbackActivity.g(localFeedbackActivity);
            i = 1;
          }
        }
      }
      for (;;)
      {
        if (i == 0) {
          localFeedbackActivity.runOnUiThread(new Runnable()
          {
            public final void run()
            {
              localFeedbackActivity.showDialog(0);
            }
          });
        }
        localFeedbackActivity.enableDisableSendFeedbackButton(true);
        return;
        i = 0;
        continue;
        label126:
        i = 1;
        continue;
        i = 0;
      }
    }
  }
}


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