Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee9646b6 authored by George Lin's avatar George Lin
Browse files

Convert wallpaper preference to Kotlin (2/3)

Test: Build success
Bug: 307819582
Flag: NONE
Change-Id: Id26e88873e80732e522b01ffa148dd4c3d367216
parent 463f9e2a
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -13,25 +13,26 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.customization.module;
package com.android.customization.module

import com.android.wallpaper.module.WallpaperPreferences;
import com.android.wallpaper.module.WallpaperPreferences

public interface CustomizationPreferences extends WallpaperPreferences {
interface CustomizationPreferences : WallpaperPreferences {
    fun getSerializedCustomThemes(): String?

    String KEY_CUSTOM_THEME= "themepicker_custom_theme";
    String KEY_VISITED_PREFIX = "themepicker_visited_";
    String KEY_THEMED_ICON_ENABLED = "themepicker_themed_icon_enabled";
    fun storeCustomThemes(serializedCustomThemes: String)

    String getSerializedCustomThemes();
    fun getTabVisited(id: String): Boolean

    void storeCustomThemes(String serializedCustomThemes);
    fun setTabVisited(id: String)

    boolean getTabVisited(String id);
    fun getThemedIconEnabled(): Boolean

    void setTabVisited(String id);
    fun setThemedIconEnabled(enabled: Boolean)

    boolean getThemedIconEnabled();

    void setThemedIconEnabled(boolean enabled);
    companion object {
        const val KEY_CUSTOM_THEME = "themepicker_custom_theme"
        const val KEY_VISITED_PREFIX = "themepicker_visited_"
        const val KEY_THEMED_ICON_ENABLED = "themepicker_themed_icon_enabled"
    }
}
+56 −0
Original line number Diff line number Diff line
@@ -13,65 +13,44 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.customization.testing;
package com.android.customization.module

import android.content.Context;
import android.content.Context
import com.android.wallpaper.module.DefaultWallpaperPreferences

import com.android.customization.module.CustomizationPreferences;
import com.android.customization.module.DefaultCustomizationPreferences;
import com.android.wallpaper.testing.TestWallpaperPreferences;
open class DefaultCustomizationPreferences(context: Context) :
    DefaultWallpaperPreferences(context), CustomizationPreferences {

import dagger.hilt.android.qualifiers.ApplicationContext;

import java.util.HashSet;
import java.util.Set;

import javax.inject.Inject;
import javax.inject.Singleton;

/**
 * Test implementation of {@link DefaultCustomizationPreferences}.
 */
@Singleton
public class TestDefaultCustomizationPreferences extends TestWallpaperPreferences implements
        CustomizationPreferences {

    private String mCustomThemes;
    private final Set<String> mTabVisited = new HashSet<>();
    private boolean mThemedIconEnabled = false;

    @Inject
    public TestDefaultCustomizationPreferences(@ApplicationContext Context context) {
        super();
    }

    @Override
    public String getSerializedCustomThemes() {
        return mCustomThemes;
    override fun getSerializedCustomThemes(): String? {
        return sharedPrefs.getString(CustomizationPreferences.KEY_CUSTOM_THEME, null)
    }

    @Override
    public void storeCustomThemes(String serializedCustomThemes) {
        mCustomThemes = serializedCustomThemes;
    override fun storeCustomThemes(serializedCustomThemes: String) {
        sharedPrefs
            .edit()
            .putString(CustomizationPreferences.KEY_CUSTOM_THEME, serializedCustomThemes)
            .apply()
    }

    @Override
    public boolean getTabVisited(String id) {
        return mTabVisited.contains(id);
    override fun getTabVisited(id: String): Boolean {
        return sharedPrefs.getBoolean(CustomizationPreferences.KEY_VISITED_PREFIX + id, false)
    }

    @Override
    public void setTabVisited(String id) {
        mTabVisited.add(id);
    override fun setTabVisited(id: String) {
        sharedPrefs
            .edit()
            .putBoolean(CustomizationPreferences.KEY_VISITED_PREFIX + id, true)
            .apply()
    }

    @Override
    public boolean getThemedIconEnabled() {
        return mThemedIconEnabled;
    override fun getThemedIconEnabled(): Boolean {
        return sharedPrefs.getBoolean(CustomizationPreferences.KEY_THEMED_ICON_ENABLED, false)
    }

    @Override
    public void setThemedIconEnabled(boolean enabled) {
        mThemedIconEnabled = enabled;
    override fun setThemedIconEnabled(enabled: Boolean) {
        sharedPrefs
            .edit()
            .putBoolean(CustomizationPreferences.KEY_THEMED_ICON_ENABLED, enabled)
            .apply()
    }
}
+14 −7
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ constructor(
            .setWallpaperIdHash(preferences.getHomeWallpaperIdHash())
            .setLockWallpaperCategoryHash(preferences.getLockCategoryHash())
            .setLockWallpaperIdHash(preferences.getLockWallpaperIdHash())
            .setEffectIdHash(getIdHashCode(preferences.homeWallpaperEffects))
            .setEffectIdHash(preferences.getHomeWallpaperEffectsIdHash())
            .log()
    }

@@ -235,28 +235,35 @@ constructor(

    /** If not set, the output hash is 0. */
    private fun WallpaperPreferences.getHomeCategoryHash(): Int {
        return getIdHashCode(homeWallpaperCollectionId)
        return getIdHashCode(getHomeWallpaperCollectionId())
    }

    /** If not set, the output hash is 0. */
    private fun WallpaperPreferences.getHomeWallpaperIdHash(): Int {
        val remoteId = homeWallpaperRemoteId
        val wallpaperId = if (!TextUtils.isEmpty(remoteId)) remoteId else homeWallpaperServiceName
        val remoteId = getHomeWallpaperRemoteId()
        val wallpaperId =
            if (!TextUtils.isEmpty(remoteId)) remoteId else getHomeWallpaperServiceName()
        return getIdHashCode(wallpaperId)
    }

    /** If not set, the output hash is 0. */
    private fun WallpaperPreferences.getLockCategoryHash(): Int {
        return getIdHashCode(lockWallpaperCollectionId)
        return getIdHashCode(getLockWallpaperCollectionId())
    }

    /** If not set, the output hash is 0. */
    private fun WallpaperPreferences.getLockWallpaperIdHash(): Int {
        val remoteId = lockWallpaperRemoteId
        val wallpaperId = if (!TextUtils.isEmpty(remoteId)) remoteId else lockWallpaperServiceName
        val remoteId = getLockWallpaperRemoteId()
        val wallpaperId =
            if (!TextUtils.isEmpty(remoteId)) remoteId else getLockWallpaperServiceName()
        return getIdHashCode(wallpaperId)
    }

    /** If not set, the output hash is 0. */
    private fun WallpaperPreferences.getHomeWallpaperEffectsIdHash(): Int {
        return getIdHashCode(getHomeWallpaperEffects())
    }

    private fun getIdHashCode(id: String?): Int {
        return id?.hashCode() ?: 0
    }
+55 −0
Original line number Diff line number Diff line
@@ -13,47 +13,43 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.customization.module;
package com.android.customization.testing

import android.content.Context;
import com.android.customization.module.CustomizationPreferences
import com.android.wallpaper.testing.TestWallpaperPreferences
import javax.inject.Inject
import javax.inject.Singleton

import com.android.wallpaper.module.DefaultWallpaperPreferences;
/** Test implementation of [CustomizationPreferences]. */
@Singleton
open class TestDefaultCustomizationPreferences @Inject constructor() :
    TestWallpaperPreferences(), CustomizationPreferences {

public class DefaultCustomizationPreferences extends DefaultWallpaperPreferences
        implements CustomizationPreferences {
    private var customThemes: String? = null
    private val tabVisited: MutableSet<String> = HashSet()
    private var themedIconEnabled = false

    public DefaultCustomizationPreferences(Context context) {
        super(context);
    override fun getSerializedCustomThemes(): String? {
        return customThemes
    }


    @Override
    public String getSerializedCustomThemes() {
        return mSharedPrefs.getString(KEY_CUSTOM_THEME, null);
    }

    @Override
    public void storeCustomThemes(String serializedCustomThemes) {
        mSharedPrefs.edit().putString(KEY_CUSTOM_THEME, serializedCustomThemes).apply();
    override fun storeCustomThemes(serializedCustomThemes: String) {
        customThemes = serializedCustomThemes
    }

    @Override
    public boolean getTabVisited(String id) {
        return mSharedPrefs.getBoolean(KEY_VISITED_PREFIX + id, false);
    override fun getTabVisited(id: String): Boolean {
        return tabVisited.contains(id)
    }

    @Override
    public void setTabVisited(String id) {
        mSharedPrefs.edit().putBoolean(KEY_VISITED_PREFIX + id, true).apply();
    override fun setTabVisited(id: String) {
        tabVisited.add(id)
    }

    @Override
    public boolean getThemedIconEnabled() {
        return mSharedPrefs.getBoolean(KEY_THEMED_ICON_ENABLED, false);
    override fun getThemedIconEnabled(): Boolean {
        return themedIconEnabled
    }

    @Override
    public void setThemedIconEnabled(boolean enabled) {
        mSharedPrefs.edit().putBoolean(KEY_THEMED_ICON_ENABLED, enabled).apply();
    override fun setThemedIconEnabled(enabled: Boolean) {
        themedIconEnabled = enabled
    }
}
Loading