diff options
| author | George Zacharia <george.zcharia@gmail.com> | 2023-07-02 14:33:47 +0530 |
|---|---|---|
| committer | George Zacharia <george.zcharia@gmail.com> | 2023-07-02 14:33:47 +0530 |
| commit | 913b11dfd2b52e445c773838c766f0d4f8ba0d05 (patch) | |
| tree | adb07f584833593bad6fca5495927c276ceef531 /src/com/android/customization/model/grid/LauncherGridOptionsProvider.java | |
| parent | b2d9a4961b3804f79c151630421d480846fd0176 (diff) | |
| parent | cc6f666d7c0bc3b6927f6e9e3c7e46123be6263d (diff) | |
Merge tag 'android-13.0.0_r52' of https://android.googlesource.com/platform/packages/apps/ThemePicker into HEADHEADt13.0
Android 13.0.0 Release 52 (TQ3A.230605.012)
Change-Id: I2cea11fa2f1f02fbd3c9d21cfc1697a79d42a5b7
Diffstat (limited to 'src/com/android/customization/model/grid/LauncherGridOptionsProvider.java')
| -rw-r--r-- | src/com/android/customization/model/grid/LauncherGridOptionsProvider.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/com/android/customization/model/grid/LauncherGridOptionsProvider.java b/src/com/android/customization/model/grid/LauncherGridOptionsProvider.java index fd403631..4e775c62 100644 --- a/src/com/android/customization/model/grid/LauncherGridOptionsProvider.java +++ b/src/com/android/customization/model/grid/LauncherGridOptionsProvider.java @@ -19,12 +19,17 @@ import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.content.res.Resources; +import android.database.ContentObserver; import android.database.Cursor; +import android.net.Uri; import android.os.Bundle; +import android.os.Handler; import android.view.SurfaceView; import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; import com.android.customization.model.ResourceConstants; import com.android.wallpaper.R; @@ -53,6 +58,7 @@ public class LauncherGridOptionsProvider { private final Context mContext; private final PreviewUtils mPreviewUtils; private List<GridOption> mOptions; + private OptionChangeLiveData mLiveData; public LauncherGridOptionsProvider(Context context, String authorityMetadataKey) { mPreviewUtils = new PreviewUtils(context, authorityMetadataKey); @@ -117,4 +123,52 @@ public class LauncherGridOptionsProvider { return mContext.getContentResolver().update(mPreviewUtils.getUri(DEFAULT_GRID), values, null, null); } + + /** + * Returns an observable that receives a new value each time that the grid options are changed. + * Do not call if {@link #areGridsAvailable()} returns false + */ + public LiveData<Object> getOptionChangeObservable( + @Nullable Handler handler) { + if (mLiveData == null) { + mLiveData = new OptionChangeLiveData( + mContext, mPreviewUtils.getUri(DEFAULT_GRID), handler); + } + + return mLiveData; + } + + private static class OptionChangeLiveData extends MutableLiveData<Object> { + + private final ContentResolver mContentResolver; + private final Uri mUri; + private final ContentObserver mContentObserver; + + OptionChangeLiveData( + Context context, + Uri uri, + @Nullable Handler handler) { + mContentResolver = context.getContentResolver(); + mUri = uri; + mContentObserver = new ContentObserver(handler) { + @Override + public void onChange(boolean selfChange) { + postValue(new Object()); + } + }; + } + + @Override + protected void onActive() { + mContentResolver.registerContentObserver( + mUri, + /* notifyForDescendants= */ true, + mContentObserver); + } + + @Override + protected void onInactive() { + mContentResolver.unregisterContentObserver(mContentObserver); + } + } } |
