/** Wrapper for sending the report to NS servers. */
  private void startSendReport() {
    if (isFinishing()) {
      return;
    }

    String reportText = reportContent.getText().toString();
    if (reportText.length() <= 0) {
      SparkleHelper.makeSnackbar(view, getString(R.string.report_blank));
      return;
    }

    AlertDialog.Builder dialogBuilder =
        new AlertDialog.Builder(this, RaraHelper.getThemeMaterialDialog(this));
    dialogBuilder
        .setTitle(R.string.report_confirm)
        .setPositiveButton(R.string.report_send_confirm, dialogListener)
        .setNegativeButton(R.string.explore_negative, null)
        .show();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_report);

    // Either get data from intent or restore state
    if (getIntent() != null) {
      if (getIntent().getData() != null) {
        targetId = Integer.valueOf(getIntent().getData().getHost());
        type = REPORT_TYPE_TASK;
      } else {
        targetId = getIntent().getIntExtra(REPORT_ID, 0);
        targetName = SparkleHelper.getNameFromId(getIntent().getStringExtra(REPORT_USER));
        type = getIntent().getIntExtra(REPORT_TYPE, REPORT_TYPE_TASK);
      }
    }
    if (savedInstanceState != null) {
      targetId = savedInstanceState.getInt(REPORT_ID);
      targetName = savedInstanceState.getString(REPORT_USER);
      type = savedInstanceState.getInt(REPORT_TYPE);
      categoryHolder = savedInstanceState.getInt(REPORT_CATEGORY, CATEGORY_NONE);
      contentHolder = savedInstanceState.getString(REPORT_CONTENT);
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_report);
    setToolbar(toolbar);

    mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.report_refresher);
    mSwipeRefreshLayout.setColorSchemeResources(RaraHelper.getThemeRefreshColours(this));
    mSwipeRefreshLayout.setEnabled(false);

    dialogListener =
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            mSwipeRefreshLayout.post(
                new Runnable() {
                  @Override
                  public void run() {
                    mSwipeRefreshLayout.setRefreshing(true);
                    sendReport();
                  }
                });
          }
        };

    view = findViewById(R.id.report_main);
    targetHolder = (RelativeLayout) findViewById(R.id.report_target_holder);
    reportTarget = (TextView) findViewById(R.id.report_target);
    reportCategoryHolder = (CardView) findViewById(R.id.report_category_holder);
    reportCategorySelect = (RadioGroup) findViewById(R.id.report_category);
    reportContent = (AppCompatEditText) findViewById(R.id.report_content);

    targetHolder.setVisibility(View.VISIBLE);
    reportCategoryHolder.setVisibility(View.VISIBLE);

    // If replying to mod mail, use this message instead
    if (type == REPORT_TYPE_TASK) {
      reportTarget.setText(
          String.format(Locale.US, getString(R.string.report_mod_reply), targetId));
      reportCategoryHolder.setVisibility(View.GONE);
    } else {
      String reportType = "";
      switch (type) {
        case REPORT_TYPE_RMB:
          reportType = getString(R.string.report_rmb_post);
          break;
        case REPORT_TYPE_TELEGRAM:
          reportType = getString(R.string.report_telegram);
          break;
        default:
          targetHolder.setVisibility(View.GONE);
          break;
      }
      reportTarget.setText(
          String.format(
              Locale.US, getString(R.string.report_target), reportType, targetId, targetName));
    }

    if (categoryHolder != CATEGORY_NONE) {
      reportCategorySelect.check(categoryHolder);
    }

    if (contentHolder != null && contentHolder.length() > 0) {
      reportContent.setText(contentHolder);
    }
  }