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)); }
@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); } }
@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); } }