diff --git a/app/src/apiNougat/java/foundation/e/blisslauncher/core/Preferences.java b/app/src/apiNougat/java/foundation/e/blisslauncher/core/Preferences.java index 11d140491ffc2da9d648c7a61384390b1ddda18d..46407efd6b6859ca8e1fbdb5dfa503ba83d36c92 100644 --- a/app/src/apiNougat/java/foundation/e/blisslauncher/core/Preferences.java +++ b/app/src/apiNougat/java/foundation/e/blisslauncher/core/Preferences.java @@ -52,6 +52,9 @@ public class Preferences { private static final String CURRENT_MIGRATION_VERSION = "current_migration_version"; + private static final String ADDED_ECLOUD_WIDGET = "added_ecloud_widget"; + private static final String ADDED_PRIVACY_WIDGET = "added_privacy_widget"; + private Preferences() { } @@ -360,4 +363,20 @@ public class Preferences { Context context) { return getPrefs(context).getBoolean(ENABLE_LOCATION, false); } + + public static void setAddedEcloudWidget(Context context) { + getPrefs(context).edit().putBoolean(ADDED_ECLOUD_WIDGET, true).apply(); + } + + public static boolean getAddedEcloudWidget(Context context) { + return getPrefs(context).getBoolean(ADDED_ECLOUD_WIDGET, false); + } + + public static void setAddedPrivacyWidget(Context context) { + getPrefs(context).edit().putBoolean(ADDED_PRIVACY_WIDGET, true).apply(); + } + + public static boolean getAddedPrivacyWidget(Context context) { + return getPrefs(context).getBoolean(ADDED_PRIVACY_WIDGET, false); + } } diff --git a/app/src/apiOreo/java/foundation/e/blisslauncher/core/Preferences.java b/app/src/apiOreo/java/foundation/e/blisslauncher/core/Preferences.java index b437ef44201aef62338c7c612f15e55cd8bea98a..b7372124d3c15356695bdc2825de2d23609fd220 100644 --- a/app/src/apiOreo/java/foundation/e/blisslauncher/core/Preferences.java +++ b/app/src/apiOreo/java/foundation/e/blisslauncher/core/Preferences.java @@ -52,6 +52,9 @@ public class Preferences { private static final String CURRENT_MIGRATION_VERSION = "current_migration_version"; + private static final String ADDED_ECLOUD_WIDGET = "added_ecloud_widget"; + private static final String ADDED_PRIVACY_WIDGET = "added_privacy_widget"; + private Preferences() { } @@ -360,4 +363,20 @@ public class Preferences { Context context) { return getPrefs(context).getBoolean(ENABLE_LOCATION, false); } + + public static void setAddedEcloudWidget(Context context) { + getPrefs(context).edit().putBoolean(ADDED_ECLOUD_WIDGET, true).apply(); + } + + public static boolean getAddedEcloudWidget(Context context) { + return getPrefs(context).getBoolean(ADDED_ECLOUD_WIDGET, false); + } + + public static void setAddedPrivacyWidget(Context context) { + getPrefs(context).edit().putBoolean(ADDED_PRIVACY_WIDGET, true).apply(); + } + + public static boolean getAddedPrivacyWidget(Context context) { + return getPrefs(context).getBoolean(ADDED_PRIVACY_WIDGET, false); + } } diff --git a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java index 5cd9910eafefc543ef364c51d495231dabc187b6..0f0e1fb30b8f9bab46de54517a5ef6bdbb7eca69 100755 --- a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java @@ -314,6 +314,7 @@ public class LauncherActivity extends AppCompatActivity implements startService(notificationServiceIntent); createOrUpdateIconGrid(); + addDefaultWidgets(); } private void setupViews() { @@ -390,6 +391,31 @@ public class LauncherActivity extends AppCompatActivity implements ); } + private void addDefaultWidgets() { + if (!Preferences.getAddedEcloudWidget(this)) { + ComponentName provider = new ComponentName("foundation.e.drive", "foundation.e.drive.widgets.EDriveWidget"); + if (allocateAndBindWidget(provider)) { + Preferences.setAddedEcloudWidget(this); + } + } + + if (!Preferences.getAddedPrivacyWidget(this)) { + ComponentName provider = new ComponentName("foundation.e.privacycentralapp.e", "foundation.e.privacycentralapp.Widget"); + if (allocateAndBindWidget(provider)) { + Preferences.setAddedPrivacyWidget(this); + } + } + } + + private boolean allocateAndBindWidget(ComponentName provider) { + int appWidgetId = mAppWidgetHost.allocateAppWidgetId(); + if (!mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, provider)) { + mAppWidgetHost.deleteAppWidgetId(appWidgetId); + return false; + } + return true; + } + private void prepareBroadcastReceivers() { timeChangedReceiver = TimeChangeBroadcastReceiver.register(this); managedProfileReceiver = ManagedProfileBroadcastReceiver.register(this);