Skip to content
This repository has been archived by the owner on Dec 17, 2023. It is now read-only.

Commit

Permalink
Keep trying to connect to the Google Now Feed after onAttachedToWindow
Browse files Browse the repository at this point in the history
amirzaidi committed Apr 14, 2018
1 parent 73af23d commit 0637b4e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/com/google/android/apps/nexuslauncher/NexusLauncher.java
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.graphics.ColorUtils;
import android.view.Menu;
import android.view.View;
@@ -51,6 +52,7 @@ public NexusLauncher(NexusLauncherActivity activity) {

class NexusLauncherCallbacks implements LauncherCallbacks, SharedPreferences.OnSharedPreferenceChangeListener, WallpaperColorInfo.OnChangeListener {
private SmartspaceView mSmartspace;
private final FeedReconnector mFeedReconnector = new FeedReconnector();

private ItemInfoUpdateReceiver getUpdateReceiver() {
if (mItemInfoUpdateReceiver == null) {
@@ -96,6 +98,7 @@ public void onActivityResult(final int n, final int n2, final Intent intent) {

public void onAttachedToWindow() {
mClient.onAttachedToWindow();
mFeedReconnector.start();
}

public void onCreate(final Bundle bundle) {
@@ -153,6 +156,7 @@ public void onDestroy() {
}

public void onDetachedFromWindow() {
mFeedReconnector.stop();
mClient.onDetachedFromWindow();
}

@@ -297,6 +301,36 @@ public void onExtractedColorsChanged(WallpaperColorInfo wallpaperColorInfo) {

mClient.redraw(mUiInformation);
}

class FeedReconnector implements Runnable {
private final static int MAX_RETRIES = 10;
private final static int RETRY_DELAY_MS = 500;

private final Handler mHandler = new Handler();
private int mFeedConnectionTries;

void start() {
stop();
mFeedConnectionTries = 0;
mHandler.post(this);
}

void stop() {
mHandler.removeCallbacks(this);
}

@Override
public void run() {
if (Utilities.getPrefs(mLauncher).getBoolean(SettingsActivity.ENABLE_MINUS_ONE_PREF, true) &&
!mClient.mDestroyed &&
mClient.mLayoutParams != null &&
!mOverlay.mAttached &&
mFeedConnectionTries++ < MAX_RETRIES) {
mClient.exchangeConfig();
mHandler.postDelayed(this, RETRY_DELAY_MS);
}
}
}
}

public static int primaryColor(WallpaperColorInfo wallpaperColorInfo, Context context, int alpha) {

0 comments on commit 0637b4e

Please sign in to comment.