mirror of https://github.com/readrops/Readrops.git
Add a progress bar in the folder layout to represent the number of feeds by folder out of the max number of feeds
This commit is contained in:
parent
eca546bea7
commit
aa26886894
|
@ -21,6 +21,7 @@ import java.util.List;
|
|||
public class FoldersAdapter extends ListAdapter<FolderWithFeedCount, FoldersAdapter.FolderViewHolder> {
|
||||
|
||||
private ManageFoldersListener listener;
|
||||
private int totalFeedCount;
|
||||
|
||||
public FoldersAdapter(ManageFoldersListener listener) {
|
||||
super(DIFF_CALLBACK);
|
||||
|
@ -28,6 +29,9 @@ public class FoldersAdapter extends ListAdapter<FolderWithFeedCount, FoldersAdap
|
|||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void setTotalFeedCount(int totalFeedCount) {
|
||||
this.totalFeedCount = totalFeedCount;
|
||||
}
|
||||
|
||||
private static final DiffUtil.ItemCallback<FolderWithFeedCount> DIFF_CALLBACK = new DiffUtil.ItemCallback<FolderWithFeedCount>() {
|
||||
@Override
|
||||
|
@ -59,13 +63,10 @@ public class FoldersAdapter extends ListAdapter<FolderWithFeedCount, FoldersAdap
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull FolderViewHolder holder, int position, @NonNull List<Object> payloads) {
|
||||
if (payloads.size() > 0) {
|
||||
FolderWithFeedCount folder = (FolderWithFeedCount) payloads.get(0);
|
||||
if (!payloads.isEmpty()) {
|
||||
FolderWithFeedCount folderWithFeedCount = (FolderWithFeedCount) payloads.get(0);
|
||||
|
||||
holder.binding.folderName.setText(folder.getFolder().getName());
|
||||
|
||||
int stringRes = folder.getFeedCount() > 1 ? R.string.feeds_number : R.string.feed_number;
|
||||
holder.binding.folderFeedsCount.setText(holder.itemView.getContext().getString(stringRes, String.valueOf(folder.getFeedCount())));
|
||||
holder.bind(folderWithFeedCount);
|
||||
} else
|
||||
onBindViewHolder(holder, position);
|
||||
|
||||
|
@ -73,18 +74,10 @@ public class FoldersAdapter extends ListAdapter<FolderWithFeedCount, FoldersAdap
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull FolderViewHolder holder, int position) {
|
||||
FolderWithFeedCount folder = getItem(position);
|
||||
FolderWithFeedCount folderWithFeedCount = getItem(position);
|
||||
|
||||
holder.binding.folderName.setText(folder.getFolder().getName());
|
||||
|
||||
int stringRes = folder.getFeedCount() > 1 ? R.string.feeds_number : R.string.feed_number;
|
||||
holder.binding.folderFeedsCount.setText(holder.itemView.getContext().getString(stringRes, String.valueOf(folder.getFeedCount())));
|
||||
|
||||
holder.itemView.setOnClickListener(v -> listener.onClick(folder.getFolder()));
|
||||
}
|
||||
|
||||
public Folder getFolder(int position) {
|
||||
return getItem(position).getFolder();
|
||||
holder.bind(folderWithFeedCount);
|
||||
holder.itemView.setOnClickListener(v -> listener.onClick(folderWithFeedCount.getFolder()));
|
||||
}
|
||||
|
||||
public interface ManageFoldersListener {
|
||||
|
@ -100,5 +93,15 @@ public class FoldersAdapter extends ListAdapter<FolderWithFeedCount, FoldersAdap
|
|||
|
||||
this.binding = binding;
|
||||
}
|
||||
|
||||
private void bind(FolderWithFeedCount folderWithFeedCount) {
|
||||
binding.folderName.setText(folderWithFeedCount.getFolder().getName());
|
||||
|
||||
int stringRes = folderWithFeedCount.getFeedCount() > 1 ? R.string.feeds_number : R.string.feed_number;
|
||||
binding.folderFeedsCount.setText(itemView.getContext().getString(stringRes, String.valueOf(folderWithFeedCount.getFeedCount())));
|
||||
|
||||
binding.folderProgressBar.setMax(totalFeedCount);
|
||||
binding.folderProgressBar.setProgress(folderWithFeedCount.getFeedCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import com.readrops.readropslibrary.utils.ConflictException;
|
|||
import com.readrops.readropslibrary.utils.UnknownFormatException;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
import static com.readrops.app.utils.ReadropsKeys.ACCOUNT;
|
||||
|
@ -68,10 +69,28 @@ public class FoldersFragment extends Fragment {
|
|||
viewModel = ViewModelProviders.of(this).get(ManageFeedsFoldersViewModel.class);
|
||||
|
||||
viewModel.setAccount(account);
|
||||
viewModel.getFeedCountByAccount()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new DisposableSingleObserver<Integer>() {
|
||||
@Override
|
||||
public void onSuccess(Integer feedCount) {
|
||||
adapter.setTotalFeedCount(feedCount);
|
||||
getFoldersWithFeedCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Utils.showSnackbar(binding.foldersRoot, e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getFoldersWithFeedCount() {
|
||||
viewModel.getFoldersWithFeedCount().observe(this, folders -> {
|
||||
adapter.submitList(folders);
|
||||
|
||||
if (folders.size() > 0) {
|
||||
if (!folders.isEmpty()) {
|
||||
binding.foldersEmptyList.setVisibility(View.GONE);
|
||||
} else {
|
||||
binding.foldersEmptyList.setVisibility(View.VISIBLE);
|
||||
|
|
|
@ -85,4 +85,8 @@ public class ManageFeedsFoldersViewModel extends AndroidViewModel {
|
|||
public Completable deleteFeed(Feed feed) {
|
||||
return repository.deleteFeed(feed);
|
||||
}
|
||||
|
||||
public Single<Integer> getFeedCountByAccount() {
|
||||
return db.feedDao().getFeedCount(account.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:padding="8dp">
|
||||
android:paddingTop="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/folder_name"
|
||||
|
@ -23,6 +23,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_toStartOf="@id/folder_feeds_count"
|
||||
tools:text="Folder 1" />
|
||||
|
||||
|
@ -32,8 +33,21 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginEnd="8dp"
|
||||
tools:text="15 feeds" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/folder_progress_bar"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="4dp"
|
||||
android:layout_below="@id/folder_name"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginTop="6dp"
|
||||
android:background="@android:color/transparent"
|
||||
tools:max="100"
|
||||
tools:progress="50" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
|
Loading…
Reference in New Issue