コード例 #1
0
  private void onUploadSuccess() {
    logger.info("Uploaded {}", getFilePath());

    Uri filePath = getFilePath();
    BehaviorSubject<UploadStatus> old = UploadStatusObservables.removeSubject(filePath);
    if (old == null) {
      logger.warn("Strange, old status observable is null, while shouldn't ever be.");
    }

    finish();
    startActivity(ThanksActivity.createIntent(this));
  }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_upload_status);

    choiceFormat = new ChoiceFormat(getString(R.string.rate_choice));
    rateNumberFormat = new DecimalFormat(getString(R.string.rate_number_format));

    progressBar = (ProgressBar) findViewById(R.id.progress_bar);
    progressPercent = (TextView) findViewById(R.id.progress_percent);
    uploadRate = (TextView) findViewById(R.id.upload_rate);

    Uri filePath = getFilePath();

    setTitle(getString(R.string.uploading_s, filePath.getLastPathSegment()));

    // First-time start.
    if (UploadStatusObservables.getObservable(filePath) == null && savedInstanceState == null) {
      logger.info("Uploading {}", filePath);

      progressBar.setIndeterminate(true);

      UploadStatusObservables.createSubject(filePath);

      Bundle extras = checkNotNull(getIntent().getExtras());
      if (extras.getBoolean(EXTRA_START_SERVICE, true)) {
        String contentType =
            checkNotNull(
                extras.getString(EXTRA_CONTENT_TYPE), EXTRA_CONTENT_TYPE + " extra is null");
        Intent finishedIntent = checkNotNull((Intent) extras.getParcelable(EXTRA_FINISHED_INTENT));

        Intent serviceIntent =
            UploadService.createMyIntent(this, filePath, contentType, getIntent(), finishedIntent);
        startService(serviceIntent);
      }
    } else {
      logger.info("There's already upload of the same file in progress: {}", filePath);
    }
  }
コード例 #3
0
  @Override
  protected void onStart() {
    super.onStart();

    Uri filePath = getFilePath();

    Observable<UploadStatus> uploadStatusObservable =
        UploadStatusObservables.getObservable(filePath);
    if (uploadStatusObservable == null) {
      // Upload have finished.
      onUploadSuccess();
    } else {
      uploadStatusObservable
          // Upload progress events come in big chunks, throttle them a little.
          .debounce(50, TimeUnit.MILLISECONDS)
          .observeOn(AndroidSchedulers.mainThread())
          .subscribe(statusObserver);
    }
  }