mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 13:23:58 +01:00
updated
This commit is contained in:
parent
df37f48eff
commit
91174778b5
3 changed files with 4 additions and 45 deletions
|
|
@ -129,25 +129,11 @@ public class ContributionsListPresenter implements UserActionListener {
|
|||
});
|
||||
}
|
||||
|
||||
private long lastKnownIdentifier ; // Declare and initialize
|
||||
|
||||
/**
|
||||
* Check for new contributions by comparing the latest contribution identifier.
|
||||
*/
|
||||
void checkForNewContributions() {
|
||||
|
||||
// Set the username before fetching contributions
|
||||
contributionsRemoteDataSource.setUserName(sessionManager.getUserName());
|
||||
|
||||
contributionsRemoteDataSource.fetchLatestContributionIdentifier(latestIdentifier -> {
|
||||
Timber.d("Latest identifier: %s", latestIdentifier);
|
||||
Timber.d("Last known identifier: %s", lastKnownIdentifier);
|
||||
if (latestIdentifier != null && !latestIdentifier.equals(lastKnownIdentifier)) {
|
||||
lastKnownIdentifier = latestIdentifier;
|
||||
contributionBoundaryCallback.refreshList(() -> Unit.INSTANCE);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
void fetchContributions() {
|
||||
contributionBoundaryCallback.refreshList(() -> Unit.INSTANCE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -73,33 +73,6 @@ constructor(
|
|||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the latest contribution identifier only
|
||||
*/
|
||||
fun fetchLatestContributionIdentifier(callback: (Long?) -> Unit) {
|
||||
if (userName.isNullOrEmpty()) {
|
||||
Timber.e("Failed to fetch latest contribution: userName is null or empty")
|
||||
return
|
||||
}
|
||||
Timber.d("Fetching latest contribution identifier for user: $userName")
|
||||
|
||||
compositeDisposable.add(
|
||||
mediaClient.getMediaListForUser(userName!!)
|
||||
.map { mediaList ->
|
||||
mediaList.firstOrNull()?.pageId // Extract the first contribution's pageId as Long
|
||||
}
|
||||
.subscribeOn(ioThreadScheduler)
|
||||
.subscribe({ latestIdentifier ->
|
||||
if (latestIdentifier != null) {
|
||||
callback(latestIdentifier.toLong())
|
||||
}
|
||||
}) { error: Throwable ->
|
||||
Timber.e("Failed to fetch latest contribution identifier: %s", error.message)
|
||||
callback(null)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fun dispose() {
|
||||
compositeDisposable.dispose()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -463,7 +463,7 @@ public class MainActivity extends BaseActivity
|
|||
v.startAnimation(rotateAnimation);
|
||||
|
||||
// Trigger refresh logic
|
||||
contributionsListPresenter.checkForNewContributions();
|
||||
contributionsListPresenter.fetchContributions();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -495,7 +495,7 @@ public class MainActivity extends BaseActivity
|
|||
|
||||
retryAllFailedUploads();
|
||||
// Background check for new contributions
|
||||
contributionsListPresenter.checkForNewContributions();
|
||||
contributionsListPresenter.fetchContributions();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue