From fe2dedf7058b9073dcad0c6ee123c9ac95aa8cff Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 4 Apr 2022 10:51:47 +0700 Subject: [PATCH 1/5] Add ecloud and privacy widget by default --- .../e/blisslauncher/core/Preferences.java | 19 ++++++++++++++ .../features/launcher/LauncherActivity.java | 26 +++++++++++++++++++ 2 files changed, 45 insertions(+) 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 b437ef4420..b7372124d3 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 5cd9910eaf..1488184d6d 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.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); -- GitLab From 96703a02d260f649a235051b3beb695fa3da0406 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 4 Apr 2022 11:11:36 +0700 Subject: [PATCH 2/5] Add widget preferences to Nougat sourceset --- .../e/blisslauncher/core/Preferences.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 11d140491f..46407efd6b 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); + } } -- GitLab From ab4f171e25021b33240a1acbbd9c6d8b11c6ed8b Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 4 Apr 2022 21:05:18 +0700 Subject: [PATCH 3/5] Fix privacy widget package name --- .../e/blisslauncher/features/launcher/LauncherActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1488184d6d..5c518c3481 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 @@ -400,7 +400,7 @@ public class LauncherActivity extends AppCompatActivity implements } if (!Preferences.getAddedPrivacyWidget(this)) { - ComponentName provider = new ComponentName("foundation.e.privacycentralapp.e", "foundation.e.privacycentralapp.widget.Widget"); + ComponentName provider = new ComponentName("foundation.e.privacycentralapp", "foundation.e.privacycentralapp.widget.Widget"); if (allocateAndBindWidget(provider)) { Preferences.setAddedPrivacyWidget(this); } -- GitLab From a626d32d1a98fb182eaf00813d0d4fb3a2b15826 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 4 Apr 2022 21:10:51 +0700 Subject: [PATCH 4/5] Revert "Fix privacy widget package name" This reverts commit ab4f171e25021b33240a1acbbd9c6d8b11c6ed8b. --- .../e/blisslauncher/features/launcher/LauncherActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5c518c3481..1488184d6d 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 @@ -400,7 +400,7 @@ public class LauncherActivity extends AppCompatActivity implements } if (!Preferences.getAddedPrivacyWidget(this)) { - ComponentName provider = new ComponentName("foundation.e.privacycentralapp", "foundation.e.privacycentralapp.widget.Widget"); + ComponentName provider = new ComponentName("foundation.e.privacycentralapp.e", "foundation.e.privacycentralapp.widget.Widget"); if (allocateAndBindWidget(provider)) { Preferences.setAddedPrivacyWidget(this); } -- GitLab From 550f2e0f9ff2c6e0e92132df56df693b552f550a Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 4 Apr 2022 21:48:59 +0700 Subject: [PATCH 5/5] Fix privacy widget component name --- .../e/blisslauncher/features/launcher/LauncherActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1488184d6d..0f0e1fb30b 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 @@ -400,7 +400,7 @@ public class LauncherActivity extends AppCompatActivity implements } if (!Preferences.getAddedPrivacyWidget(this)) { - ComponentName provider = new ComponentName("foundation.e.privacycentralapp.e", "foundation.e.privacycentralapp.widget.Widget"); + ComponentName provider = new ComponentName("foundation.e.privacycentralapp.e", "foundation.e.privacycentralapp.Widget"); if (allocateAndBindWidget(provider)) { Preferences.setAddedPrivacyWidget(this); } -- GitLab