This commit is contained in:
Sujal-Gupta-SG 2025-01-26 21:05:52 +05:30
parent df37f48eff
commit 91174778b5
3 changed files with 4 additions and 45 deletions

View file

@ -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;
void fetchContributions() {
contributionBoundaryCallback.refreshList(() -> Unit.INSTANCE);
}
return Unit.INSTANCE;
});
}
}

View file

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

View file

@ -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