mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Fixed large uploads issue
This commit is contained in:
parent
0b5fb6d7b0
commit
1e032e6bdf
9 changed files with 94 additions and 47 deletions
|
|
@ -23,6 +23,11 @@ public abstract class ContributionDao {
|
||||||
@Query("SELECT * FROM contribution WHERE state = -1 ORDER BY media_dateUploaded DESC")
|
@Query("SELECT * FROM contribution WHERE state = -1 ORDER BY media_dateUploaded DESC")
|
||||||
abstract DataSource.Factory<Integer, Contribution> fetchContributionsWithStateCompleted();
|
abstract DataSource.Factory<Integer, Contribution> fetchContributionsWithStateCompleted();
|
||||||
|
|
||||||
|
@Query("SELECT * FROM contribution WHERE state IN (2, 3, 4) ORDER BY media_dateUploaded DESC")
|
||||||
|
abstract DataSource.Factory<Integer, Contribution> fetchContributionsWithStateInProgress();
|
||||||
|
|
||||||
|
@Query("SELECT * FROM contribution WHERE state = 1 ORDER BY media_dateUploaded DESC")
|
||||||
|
abstract DataSource.Factory<Integer, Contribution> fetchContributionsWithStateFailed();
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
public abstract void saveSynchronous(Contribution contribution);
|
public abstract void saveSynchronous(Contribution contribution);
|
||||||
|
|
|
||||||
|
|
@ -686,7 +686,7 @@ public class ContributionsFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateUploadsIcon(int pendingCount, int errorCount) {
|
public void updatePendingIcon(int pendingCount) {
|
||||||
if (pendingUploadsCountTextView != null){
|
if (pendingUploadsCountTextView != null){
|
||||||
if (pendingCount != 0){
|
if (pendingCount != 0){
|
||||||
pendingUploadsCountTextView.setVisibility(View.VISIBLE);
|
pendingUploadsCountTextView.setVisibility(View.VISIBLE);
|
||||||
|
|
@ -694,14 +694,18 @@ public class ContributionsFragment
|
||||||
}else {
|
}else {
|
||||||
pendingUploadsCountTextView.setVisibility(View.INVISIBLE);
|
pendingUploadsCountTextView.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateErrorIcon(int errorCount) {
|
||||||
|
if (uploadsErrorTextView != null){
|
||||||
if (errorCount != 0){
|
if (errorCount != 0){
|
||||||
uploadsErrorTextView.setVisibility(View.VISIBLE);
|
uploadsErrorTextView.setVisibility(View.VISIBLE);
|
||||||
uploadsErrorTextView.setText(String.valueOf(errorCount));
|
uploadsErrorTextView.setText(String.valueOf(errorCount));
|
||||||
}else {
|
}else {
|
||||||
uploadsErrorTextView.setVisibility(View.GONE);
|
uploadsErrorTextView.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver;
|
||||||
import androidx.recyclerview.widget.RecyclerView.ItemAnimator;
|
import androidx.recyclerview.widget.RecyclerView.ItemAnimator;
|
||||||
import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener;
|
import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener;
|
||||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||||
import fr.free.nrw.commons.CommonsApplication;
|
|
||||||
import fr.free.nrw.commons.Media;
|
import fr.free.nrw.commons.Media;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.Utils;
|
import fr.free.nrw.commons.Utils;
|
||||||
|
|
@ -43,14 +42,12 @@ import fr.free.nrw.commons.profile.ProfileActivity;
|
||||||
import fr.free.nrw.commons.utils.DialogUtil;
|
import fr.free.nrw.commons.utils.DialogUtil;
|
||||||
import fr.free.nrw.commons.utils.SystemThemeUtils;
|
import fr.free.nrw.commons.utils.SystemThemeUtils;
|
||||||
import fr.free.nrw.commons.utils.ViewUtil;
|
import fr.free.nrw.commons.utils.ViewUtil;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import fr.free.nrw.commons.wikidata.model.WikiSite;
|
import fr.free.nrw.commons.wikidata.model.WikiSite;
|
||||||
import timber.log.Timber;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -217,22 +214,15 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
||||||
|
|
||||||
contributionsListPresenter.setup(userName,
|
contributionsListPresenter.setup(userName,
|
||||||
Objects.equals(sessionManager.getUserName(), userName));
|
Objects.equals(sessionManager.getUserName(), userName));
|
||||||
contributionsListPresenter.getTotalContribution(userName);
|
contributionsListPresenter.getPendingContributions(userName);
|
||||||
contributionsListPresenter.totalContributionList.observe(getViewLifecycleOwner(), list -> {
|
contributionsListPresenter.pendingContributionList.observe(getViewLifecycleOwner(), list -> {
|
||||||
uploadErrorCount = 0;
|
pendingUploadsCount = list.size();
|
||||||
pendingUploadsCount = 0;
|
callback.updatePendingIcon(pendingUploadsCount);
|
||||||
for (int i = 0; i< list.size(); i++){
|
});
|
||||||
if (list.get(i) != null){
|
contributionsListPresenter.getFailedContributions(userName);
|
||||||
if (list.get(i).getState() != Contribution.STATE_COMPLETED){
|
contributionsListPresenter.failedContributionList.observe(getViewLifecycleOwner(), list -> {
|
||||||
if (list.get(i).getState() == Contribution.STATE_FAILED){
|
uploadErrorCount = list.size();
|
||||||
uploadErrorCount++;
|
callback.updateErrorIcon(uploadErrorCount);
|
||||||
}else {
|
|
||||||
pendingUploadsCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
callback.updateUploadsIcon(pendingUploadsCount, uploadErrorCount);
|
|
||||||
});
|
});
|
||||||
contributionsListPresenter.contributionList.observe(getViewLifecycleOwner(), list -> {
|
contributionsListPresenter.contributionList.observe(getViewLifecycleOwner(), list -> {
|
||||||
contributionsSize = list.size();
|
contributionsSize = list.size();
|
||||||
|
|
@ -515,6 +505,8 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
||||||
// Notify the viewpager that number of items have changed.
|
// Notify the viewpager that number of items have changed.
|
||||||
void viewPagerNotifyDataSetChanged();
|
void viewPagerNotifyDataSetChanged();
|
||||||
|
|
||||||
void updateUploadsIcon(int pendingCount, int errorCount);
|
void updatePendingIcon(int pendingCount);
|
||||||
|
|
||||||
|
void updateErrorIcon(int errorCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,8 @@ public class ContributionsListPresenter implements UserActionListener {
|
||||||
private final ContributionsRemoteDataSource contributionsRemoteDataSource;
|
private final ContributionsRemoteDataSource contributionsRemoteDataSource;
|
||||||
|
|
||||||
LiveData<PagedList<Contribution>> contributionList;
|
LiveData<PagedList<Contribution>> contributionList;
|
||||||
LiveData<PagedList<Contribution>> totalContributionList;
|
LiveData<PagedList<Contribution>> pendingContributionList;
|
||||||
|
LiveData<PagedList<Contribution>> failedContributionList;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ContributionsListPresenter(
|
ContributionsListPresenter(
|
||||||
|
|
@ -90,7 +91,7 @@ public class ContributionsListPresenter implements UserActionListener {
|
||||||
contributionBoundaryCallback.dispose();
|
contributionBoundaryCallback.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void getTotalContribution(String userName) {
|
void getPendingContributions(String userName) {
|
||||||
final PagedList.Config pagedListConfig =
|
final PagedList.Config pagedListConfig =
|
||||||
(new PagedList.Config.Builder())
|
(new PagedList.Config.Builder())
|
||||||
.setPrefetchDistance(50)
|
.setPrefetchDistance(50)
|
||||||
|
|
@ -99,13 +100,31 @@ public class ContributionsListPresenter implements UserActionListener {
|
||||||
boolean shouldSetBoundaryCallback;
|
boolean shouldSetBoundaryCallback;
|
||||||
contributionBoundaryCallback.setUserName(userName);
|
contributionBoundaryCallback.setUserName(userName);
|
||||||
shouldSetBoundaryCallback = true;
|
shouldSetBoundaryCallback = true;
|
||||||
factory = repository.fetchContributions();
|
factory = repository.fetchInProgressContributions();
|
||||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
||||||
pagedListConfig);
|
pagedListConfig);
|
||||||
if (shouldSetBoundaryCallback) {
|
if (shouldSetBoundaryCallback) {
|
||||||
livePagedListBuilder.setBoundaryCallback(contributionBoundaryCallback);
|
livePagedListBuilder.setBoundaryCallback(contributionBoundaryCallback);
|
||||||
}
|
}
|
||||||
totalContributionList = livePagedListBuilder.build();
|
pendingContributionList = livePagedListBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
void getFailedContributions(String userName) {
|
||||||
|
final PagedList.Config pagedListConfig =
|
||||||
|
(new PagedList.Config.Builder())
|
||||||
|
.setPrefetchDistance(50)
|
||||||
|
.setPageSize(10).build();
|
||||||
|
Factory<Integer, Contribution> factory;
|
||||||
|
boolean shouldSetBoundaryCallback;
|
||||||
|
contributionBoundaryCallback.setUserName(userName);
|
||||||
|
shouldSetBoundaryCallback = true;
|
||||||
|
factory = repository.fetchFailedContributions();
|
||||||
|
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
||||||
|
pagedListConfig);
|
||||||
|
if (shouldSetBoundaryCallback) {
|
||||||
|
livePagedListBuilder.setBoundaryCallback(contributionBoundaryCallback);
|
||||||
|
}
|
||||||
|
failedContributionList = livePagedListBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,14 @@ class ContributionsLocalDataSource {
|
||||||
return contributionDao.fetchContributionsWithStateCompleted();
|
return contributionDao.fetchContributionsWithStateCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Factory<Integer, Contribution> getInProgressContributions() {
|
||||||
|
return contributionDao.fetchContributionsWithStateInProgress();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Factory<Integer, Contribution> getFailedContributions() {
|
||||||
|
return contributionDao.fetchContributionsWithStateFailed();
|
||||||
|
}
|
||||||
|
|
||||||
public Single<List<Long>> saveContributions(final List<Contribution> contributions) {
|
public Single<List<Long>> saveContributions(final List<Contribution> contributions) {
|
||||||
final List<Contribution> contributionList = new ArrayList<>();
|
final List<Contribution> contributionList = new ArrayList<>();
|
||||||
for(final Contribution contribution: contributions) {
|
for(final Contribution contribution: contributions) {
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,14 @@ public class ContributionsRepository {
|
||||||
return localDataSource.getCompletedContributions();
|
return localDataSource.getCompletedContributions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Factory<Integer, Contribution> fetchInProgressContributions() {
|
||||||
|
return localDataSource.getInProgressContributions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Factory<Integer, Contribution> fetchFailedContributions() {
|
||||||
|
return localDataSource.getFailedContributions();
|
||||||
|
}
|
||||||
|
|
||||||
public Single<List<Long>> save(List<Contribution> contributions) {
|
public Single<List<Long>> save(List<Contribution> contributions) {
|
||||||
return localDataSource.saveContributions(contributions);
|
return localDataSource.saveContributions(contributions);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,25 +87,22 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContr
|
||||||
|
|
||||||
fun initRecyclerView() {
|
fun initRecyclerView() {
|
||||||
binding.failedUploadsRecyclerView.setLayoutManager(LinearLayoutManager(this.context))
|
binding.failedUploadsRecyclerView.setLayoutManager(LinearLayoutManager(this.context))
|
||||||
pendingUploadsPresenter!!.setup(
|
pendingUploadsPresenter!!.getFailedContributions(userName)
|
||||||
userName,
|
pendingUploadsPresenter!!.failedContributionList.observe(
|
||||||
sessionManager!!.userName == userName
|
|
||||||
)
|
|
||||||
pendingUploadsPresenter!!.totalContributionList.observe(
|
|
||||||
viewLifecycleOwner
|
viewLifecycleOwner
|
||||||
) { list: PagedList<Contribution?> ->
|
) { list: PagedList<Contribution?> ->
|
||||||
contributionsList = ArrayList()
|
contributionsList = ArrayList()
|
||||||
list.forEach {
|
list.forEach {
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
if (it.state == Contribution.STATE_FAILED) {
|
contributionsList.add(it)
|
||||||
contributionsList.add(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (contributionsList.size == 0) {
|
if (list.size == 0) {
|
||||||
|
uploadProgressActivity.setErrorIconsVisibility(false)
|
||||||
binding.nofailedTextView.visibility = View.VISIBLE
|
binding.nofailedTextView.visibility = View.VISIBLE
|
||||||
binding.failedUplaodsLl.visibility = View.GONE
|
binding.failedUplaodsLl.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
|
uploadProgressActivity.setErrorIconsVisibility(true)
|
||||||
binding.nofailedTextView.visibility = View.GONE
|
binding.nofailedTextView.visibility = View.GONE
|
||||||
binding.failedUplaodsLl.visibility = View.VISIBLE
|
binding.failedUplaodsLl.visibility = View.VISIBLE
|
||||||
val adapter = FailedUploadsAdapter(contributionsList, this)
|
val adapter = FailedUploadsAdapter(contributionsList, this)
|
||||||
|
|
|
||||||
|
|
@ -131,18 +131,13 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (failedUploads == 0){
|
if (contributionsSize == 0) {
|
||||||
uploadProgressActivity.setErrorIconsVisibility(false)
|
|
||||||
}else{
|
|
||||||
uploadProgressActivity.setErrorIconsVisibility(true)
|
|
||||||
}
|
|
||||||
if (contributionsList.size == 0) {
|
|
||||||
binding.nopendingTextView.visibility = View.VISIBLE
|
binding.nopendingTextView.visibility = View.VISIBLE
|
||||||
binding.pendingUplaodsLl.visibility = View.GONE
|
binding.pendingUplaodsLl.visibility = View.GONE
|
||||||
uploadProgressActivity.hidePendingIcons()
|
uploadProgressActivity.hidePendingIcons()
|
||||||
} else {
|
} else {
|
||||||
if (totalUploads == 0){
|
if (totalUploads == 0){
|
||||||
totalUploads = contributionsList.size
|
totalUploads = contributionsSize
|
||||||
binding.progressBarPending.max = totalUploads
|
binding.progressBarPending.max = totalUploads
|
||||||
}
|
}
|
||||||
binding.nopendingTextView.visibility = View.GONE
|
binding.nopendingTextView.visibility = View.GONE
|
||||||
|
|
@ -167,9 +162,9 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
||||||
newContributionList.addAll(listOfRemoved)
|
newContributionList.addAll(listOfRemoved)
|
||||||
val adapter = PendingUploadsAdapter(newContributionList, this)
|
val adapter = PendingUploadsAdapter(newContributionList, this)
|
||||||
binding.pendingUploadsRecyclerView.setAdapter(adapter)
|
binding.pendingUploadsRecyclerView.setAdapter(adapter)
|
||||||
binding.progressTextView.setText((totalUploads-contributionsList.size).toString() + "/" + totalUploads + " uploaded")
|
binding.progressTextView.setText((totalUploads-contributionsSize).toString() + "/" + totalUploads + " uploaded")
|
||||||
binding.progressBarPending.progress = totalUploads-contributionsList.size
|
binding.progressBarPending.progress = totalUploads-contributionsSize
|
||||||
if (pausedOrQueuedUploads == contributionsList.size) {
|
if (pausedOrQueuedUploads == contributionsSize) {
|
||||||
uploadProgressActivity.setPausedIcon(true)
|
uploadProgressActivity.setPausedIcon(true)
|
||||||
}else{
|
}else{
|
||||||
uploadProgressActivity.setPausedIcon(false)
|
uploadProgressActivity.setPausedIcon(false)
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ public class PendingUploadsPresenter implements UserActionListener {
|
||||||
private final ContributionsRemoteDataSource contributionsRemoteDataSource;
|
private final ContributionsRemoteDataSource contributionsRemoteDataSource;
|
||||||
|
|
||||||
LiveData<PagedList<Contribution>> totalContributionList;
|
LiveData<PagedList<Contribution>> totalContributionList;
|
||||||
|
LiveData<PagedList<Contribution>> failedContributionList;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PendingUploadsPresenter(
|
PendingUploadsPresenter(
|
||||||
|
|
@ -81,7 +82,7 @@ public class PendingUploadsPresenter implements UserActionListener {
|
||||||
} else {
|
} else {
|
||||||
contributionBoundaryCallback.setUserName(userName);
|
contributionBoundaryCallback.setUserName(userName);
|
||||||
shouldSetBoundaryCallback = true;
|
shouldSetBoundaryCallback = true;
|
||||||
factory = repository.fetchContributions();
|
factory = repository.fetchInProgressContributions();
|
||||||
}
|
}
|
||||||
|
|
||||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory, pagedListConfig);
|
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory, pagedListConfig);
|
||||||
|
|
@ -92,6 +93,24 @@ public class PendingUploadsPresenter implements UserActionListener {
|
||||||
totalContributionList = livePagedListBuilder.build();
|
totalContributionList = livePagedListBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getFailedContributions(String userName) {
|
||||||
|
final PagedList.Config pagedListConfig =
|
||||||
|
(new PagedList.Config.Builder())
|
||||||
|
.setPrefetchDistance(50)
|
||||||
|
.setPageSize(10).build();
|
||||||
|
Factory<Integer, Contribution> factory;
|
||||||
|
boolean shouldSetBoundaryCallback;
|
||||||
|
contributionBoundaryCallback.setUserName(userName);
|
||||||
|
shouldSetBoundaryCallback = true;
|
||||||
|
factory = repository.fetchFailedContributions();
|
||||||
|
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
||||||
|
pagedListConfig);
|
||||||
|
if (shouldSetBoundaryCallback) {
|
||||||
|
livePagedListBuilder.setBoundaryCallback(contributionBoundaryCallback);
|
||||||
|
}
|
||||||
|
failedContributionList = livePagedListBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttachView(@NonNull View view) {
|
public void onAttachView(@NonNull View view) {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue