Improve progressbar style
This commit is contained in:
parent
5689fef568
commit
8c483b1885
@ -2,6 +2,8 @@ package com.readrops.app.activities;
|
|||||||
|
|
||||||
import android.arch.lifecycle.ViewModelProviders;
|
import android.arch.lifecycle.ViewModelProviders;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
@ -234,30 +236,7 @@ public class MainActivity extends AppCompatActivity implements SimpleCallback, S
|
|||||||
public void onRefresh() {
|
public void onRefresh() {
|
||||||
Log.d(TAG, "syncing started");
|
Log.d(TAG, "syncing started");
|
||||||
|
|
||||||
viewModel.getFeedCount()
|
presync(null);
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe(new SingleObserver<Integer>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSubscribe(Disposable d) {
|
|
||||||
syncProgressLayout.setVisibility(View.VISIBLE);
|
|
||||||
syncProgressBar.setProgress(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSuccess(Integer integer) {
|
|
||||||
feedNb = integer;
|
|
||||||
sync(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Throwable e) {
|
|
||||||
Toast.makeText(getApplicationContext(), "error on getting feeds number", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayAddFeedDialog(View view) {
|
public void displayAddFeedDialog(View view) {
|
||||||
@ -287,13 +266,38 @@ public class MainActivity extends AppCompatActivity implements SimpleCallback, S
|
|||||||
|
|
||||||
if (feeds != null && feeds.size() > 0) {
|
if (feeds != null && feeds.size() > 0) {
|
||||||
refreshLayout.setRefreshing(true);
|
refreshLayout.setRefreshing(true);
|
||||||
sync(feeds);
|
presync(feeds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void presync(List<Feed> feeds) {
|
||||||
|
viewModel.getFeedCount()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(new SingleObserver<Integer>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(Disposable d) {
|
||||||
|
syncProgressLayout.setVisibility(View.VISIBLE);
|
||||||
|
syncProgressBar.setProgress(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Integer integer) {
|
||||||
|
feedNb = integer;
|
||||||
|
sync(feeds);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
Toast.makeText(getApplicationContext(), "error on getting feeds number", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void sync(List<Feed> feeds) {
|
private void sync(List<Feed> feeds) {
|
||||||
viewModel.sync(feeds)
|
viewModel.sync(feeds)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
@ -307,12 +311,12 @@ public class MainActivity extends AppCompatActivity implements SimpleCallback, S
|
|||||||
@Override
|
@Override
|
||||||
public void onNext(Feed feed) {
|
public void onNext(Feed feed) {
|
||||||
syncProgress.setText(getString(R.string.updating_feed, feed.getName()));
|
syncProgress.setText(getString(R.string.updating_feed, feed.getName()));
|
||||||
feedCount++;
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
syncProgressBar.setProgress((feedCount * 100) / feedNb, true);
|
syncProgressBar.setProgress((feedCount * 100) / feedNb, true);
|
||||||
} else
|
} else
|
||||||
syncProgressBar.setProgress((feedCount * 100) / feedNb);
|
syncProgressBar.setProgress((feedCount * 100) / feedNb);
|
||||||
|
|
||||||
|
feedCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -323,7 +327,11 @@ public class MainActivity extends AppCompatActivity implements SimpleCallback, S
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComplete() {
|
public void onComplete() {
|
||||||
syncProgressBar.setProgress(0);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||||
|
syncProgressBar.setProgress(100, true);
|
||||||
|
else
|
||||||
|
syncProgressBar.setProgress(100);
|
||||||
|
|
||||||
syncProgressLayout.setVisibility(View.GONE);
|
syncProgressLayout.setVisibility(View.GONE);
|
||||||
refreshLayout.setRefreshing(false);
|
refreshLayout.setRefreshing(false);
|
||||||
adapter.submitList(newItems);
|
adapter.submitList(newItems);
|
||||||
|
@ -55,8 +55,9 @@
|
|||||||
android:id="@+id/sync_progress_bar"
|
android:id="@+id/sync_progress_bar"
|
||||||
style="?android:attr/progressBarStyleHorizontal"
|
style="?android:attr/progressBarStyleHorizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="4dp"
|
||||||
android:layout_below="@id/sync_progress_feeds_layout"
|
android:layout_below="@id/sync_progress_feeds_layout"
|
||||||
|
android:layout_margin="0dp"
|
||||||
android:max="100" />
|
android:max="100" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user