Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix spinner keeps spinning #2194

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions app/src/main/java/fr/neamar/kiss/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -626,32 +626,37 @@ public void displayClearOnInput() {
}
}

public void displayLoader(Boolean display) {
int animationDuration = getResources().getInteger(
android.R.integer.config_longAnimTime);
public void displayLoader(boolean display) {
if (!display) {
// Do not display animation if launcher button is already visible
if (launcherButton.getVisibility() != View.VISIBLE) {
launcherButton.setVisibility(View.VISIBLE);

// Do not display animation if launcher button is already visible
if (!display && launcherButton.getVisibility() == View.INVISIBLE) {
launcherButton.setVisibility(View.VISIBLE);

// Animate transition from loader to launch button
int animationDuration = getResources().getInteger(
android.R.integer.config_longAnimTime);

// Animate transition from loader to launch button
launcherButton.animate()
.alpha(1f)
.setDuration(animationDuration)
.setListener(null);
loaderSpinner.animate()
.alpha(0f)
.setDuration(animationDuration)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
loaderSpinner.setVisibility(View.GONE);
}
});
}
} else {
launcherButton.animate().cancel();
launcherButton.setAlpha(0);
launcherButton.animate()
.alpha(1f)
.setDuration(animationDuration)
.setListener(null);
loaderSpinner.animate()
.alpha(0f)
.setDuration(animationDuration)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
loaderSpinner.setVisibility(View.GONE);
loaderSpinner.setAlpha(1);
}
});
} else if (display) {
launcherButton.setVisibility(View.INVISIBLE);

loaderSpinner.animate().cancel();
loaderSpinner.setAlpha(1);
loaderSpinner.setVisibility(View.VISIBLE);
}
}
Expand All @@ -660,7 +665,7 @@ public void onFavoriteChange() {
forwarderManager.onFavoriteChange();
}

public void displayKissBar(Boolean display) {
public void displayKissBar(boolean display) {
this.displayKissBar(display, true);
}

Expand Down
23 changes: 20 additions & 3 deletions app/src/main/java/fr/neamar/kiss/searcher/Searcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,30 @@ protected void onPreExecute() {
displayActivityLoader();
}

void displayActivityLoader() {
protected void displayActivityLoader() {
MainActivity activity = activityWeakReference.get();
if (activity == null)
return;

activity.displayLoader(true);
}

private void hideActivityLoader(MainActivity activity) {
// Loader should still be displayed until all the providers have finished loading
activity.displayLoader(!KissApplication.getApplication(activity).getDataHandler().allProvidersHaveLoaded);
}

@Override
protected void onPostExecute(Void param) {
if (isCancelled()) {
return;
}

MainActivity activity = activityWeakReference.get();
if (activity == null)
return;

// Loader should still be displayed until all the providers have finished loading
activity.displayLoader(!KissApplication.getApplication(activity).getDataHandler().allProvidersHaveLoaded);
hideActivityLoader(activity);

if (this.processedPojos.isEmpty()) {
activity.adapter.clear();
Expand All @@ -120,6 +128,15 @@ protected void onPostExecute(Void param) {
Log.v(TAG, "Time to run query `" + query + "` on " + getClass().getSimpleName() + " to completion: " + time + "ms");
}

@Override
protected void onCancelled(Void unused) {
MainActivity activity = activityWeakReference.get();
if (activity == null)
return;

hideActivityLoader(activity);
}

public void setRefresh(boolean refresh) {
isRefresh = refresh;
}
Expand Down