From ee019dd687cf189c84e6d146c1868bc279cc4d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sun, 17 May 2020 17:19:59 +0200 Subject: [PATCH] Move managers.KillerManager to AppKillerManager --- .../MainActivity.java | 30 ++++++++--------- .../KillerManager.kt => AppKillerManager.kt} | 5 +-- .../NoActionFoundException.kt | 2 +- .../ui/DialogKillerManagerBuilder.java | 32 +++++++++---------- .../utils/KillerManagerUtils.java | 16 +++++----- 5 files changed, 43 insertions(+), 42 deletions(-) rename appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/{managers/KillerManager.kt => AppKillerManager.kt} (96%) rename appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/{managers => exceptions}/NoActionFoundException.kt (68%) diff --git a/app/src/main/java/com/thelittlefireman/appkillermanager_exemple/MainActivity.java b/app/src/main/java/com/thelittlefireman/appkillermanager_exemple/MainActivity.java index ef7da5f..6e19368 100644 --- a/app/src/main/java/com/thelittlefireman/appkillermanager_exemple/MainActivity.java +++ b/app/src/main/java/com/thelittlefireman/appkillermanager_exemple/MainActivity.java @@ -8,8 +8,8 @@ import androidx.appcompat.widget.AppCompatCheckBox; -import com.thelittlefireman.appkillermanager.managers.KillerManager; -import com.thelittlefireman.appkillermanager.managers.NoActionFoundException; +import com.thelittlefireman.appkillermanager.AppKillerManager; +import com.thelittlefireman.appkillermanager.exceptions.NoActionFoundException; import com.thelittlefireman.appkillermanager.ui.DialogKillerManagerBuilder; import timber.log.Timber; @@ -22,7 +22,7 @@ public class MainActivity extends Activity { Button notificationManagerButton; AppCompatCheckBox mAppCompatCheckBoxByDialog; - KillerManager.Action currentAction = null; + AppKillerManager.Action currentAction = null; @@ -45,12 +45,12 @@ protected void onCreate(final Bundle savedInstanceState) { powerSavingManagerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - currentAction = KillerManager.Action.ACTION_POWER_SAVING; + currentAction = AppKillerManager.Action.ACTION_POWER_SAVING; if (mAppCompatCheckBoxByDialog.isChecked()) { startDialog(currentAction); } else { try { - KillerManager.doActionPowerSaving(MainActivity.this); + AppKillerManager.doActionPowerSaving(MainActivity.this); } catch (NoActionFoundException e) { Timber.e(e); } @@ -60,12 +60,12 @@ public void onClick(View v) { autoStartManagerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - currentAction = KillerManager.Action.ACTION_AUTO_START; + currentAction = AppKillerManager.Action.ACTION_AUTO_START; if (mAppCompatCheckBoxByDialog.isChecked()) { startDialog(currentAction); } else { try { - KillerManager.doActionAutoStart(MainActivity.this); + AppKillerManager.doActionAutoStart(MainActivity.this); } catch (NoActionFoundException e) { Timber.e(e); } @@ -75,12 +75,12 @@ public void onClick(View v) { notificationManagerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - currentAction = KillerManager.Action.ACTION_NOTIFICATIONS; + currentAction = AppKillerManager.Action.ACTION_NOTIFICATIONS; if (mAppCompatCheckBoxByDialog.isChecked()) { startDialog(currentAction); } else { try { - KillerManager.doActionNotification(MainActivity.this); + AppKillerManager.doActionNotification(MainActivity.this); } catch (NoActionFoundException e) { Timber.e(e); } @@ -88,14 +88,14 @@ public void onClick(View v) { } }); - if (KillerManager.isDeviceSupported()) { + if (AppKillerManager.isDeviceSupported()) { isDeviceSupported.setText("Is supported: true"); - deviceName.setText("Device name: ".concat(KillerManager.getDevice().getManufacturer().toString())); + deviceName.setText("Device name: ".concat(AppKillerManager.getDevice().getManufacturer().toString())); } } - public void startDialog(KillerManager.Action action) { + public void startDialog(AppKillerManager.Action action) { try { new DialogKillerManagerBuilder(this).setAction(action).show(); @@ -112,12 +112,12 @@ public void startDialog(KillerManager.Action action) { public void onResume() { super.onResume(); - if (currentAction == KillerManager.Action.ACTION_AUTO_START) { + if (currentAction == AppKillerManager.Action.ACTION_AUTO_START) { // may show dalog to ask the user about the result of action // and store the result in preference - } else if (currentAction == KillerManager.Action.ACTION_NOTIFICATIONS) { + } else if (currentAction == AppKillerManager.Action.ACTION_NOTIFICATIONS) { - } else if (currentAction == KillerManager.Action.ACTION_POWER_SAVING) { + } else if (currentAction == AppKillerManager.Action.ACTION_POWER_SAVING) { } // dont forget to nullify current action diff --git a/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/managers/KillerManager.kt b/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/AppKillerManager.kt similarity index 96% rename from appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/managers/KillerManager.kt rename to appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/AppKillerManager.kt index 5b97644..2ac605f 100644 --- a/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/managers/KillerManager.kt +++ b/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/AppKillerManager.kt @@ -1,13 +1,14 @@ -package com.thelittlefireman.appkillermanager.managers +package com.thelittlefireman.appkillermanager import android.content.Context import android.content.Intent import com.thelittlefireman.appkillermanager.devices.* +import com.thelittlefireman.appkillermanager.exceptions.NoActionFoundException import com.thelittlefireman.appkillermanager.utils.ActionsUtils import com.thelittlefireman.appkillermanager.utils.SystemUtils import timber.log.Timber -object KillerManager { +object AppKillerManager { enum class Action { ACTION_AUTO_START, diff --git a/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/managers/NoActionFoundException.kt b/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/exceptions/NoActionFoundException.kt similarity index 68% rename from appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/managers/NoActionFoundException.kt rename to appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/exceptions/NoActionFoundException.kt index 5eca523..5fae165 100644 --- a/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/managers/NoActionFoundException.kt +++ b/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/exceptions/NoActionFoundException.kt @@ -1,3 +1,3 @@ -package com.thelittlefireman.appkillermanager.managers +package com.thelittlefireman.appkillermanager.exceptions class NoActionFoundException internal constructor(message: String? = "Intent couldn't find action") : Exception(message) diff --git a/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/ui/DialogKillerManagerBuilder.java b/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/ui/DialogKillerManagerBuilder.java index 484b62a..8e088b3 100644 --- a/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/ui/DialogKillerManagerBuilder.java +++ b/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/ui/DialogKillerManagerBuilder.java @@ -14,8 +14,8 @@ import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.MaterialDialog; import com.thelittlefireman.appkillermanager.R; -import com.thelittlefireman.appkillermanager.managers.KillerManager; -import com.thelittlefireman.appkillermanager.managers.NoActionFoundException; +import com.thelittlefireman.appkillermanager.AppKillerManager; +import com.thelittlefireman.appkillermanager.exceptions.NoActionFoundException; import com.thelittlefireman.appkillermanager.utils.KillerManagerUtils; import timber.log.Timber; @@ -31,7 +31,7 @@ public class DialogKillerManagerBuilder { private OnNoActionFoundException onNoActionFoundException; private UnAvailableActionException unAvailableActionException; private UnSupportedDeviceException onUnSupportedDevice; - private KillerManager.Action mAction; + private AppKillerManager.Action mAction; private boolean enableDontShowAgain = true; private String titleMessage; private String contentMessage; @@ -57,7 +57,7 @@ public DialogKillerManagerBuilder(Context context) { mContext = context; } - public DialogKillerManagerBuilder setAction(KillerManager.Action action) { + public DialogKillerManagerBuilder setAction(AppKillerManager.Action action) { mAction = action; return this; } @@ -130,17 +130,17 @@ public void build() throws NullPointerException { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { try { - if (mAction == KillerManager.Action.ACTION_AUTO_START) { + if (mAction == AppKillerManager.Action.ACTION_AUTO_START) { if (mContext != null) { - KillerManager.doActionAutoStart(mContext); + AppKillerManager.doActionAutoStart(mContext); } - } else if (mAction == KillerManager.Action.ACTION_NOTIFICATIONS) { + } else if (mAction == AppKillerManager.Action.ACTION_NOTIFICATIONS) { if (mContext != null) { - KillerManager.doActionNotification(mContext); + AppKillerManager.doActionNotification(mContext); } - } else if (mAction == KillerManager.Action.ACTION_POWER_SAVING) { + } else if (mAction == AppKillerManager.Action.ACTION_POWER_SAVING) { if (mContext != null) { - KillerManager.doActionPowerSaving(mContext); + AppKillerManager.doActionPowerSaving(mContext); } } } catch (NoActionFoundException e) { @@ -167,7 +167,7 @@ public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) builder.title(titleMessage); } else { if (mContext != null) { - builder.title(mContext.getString(R.string.dialog_title_notification, KillerManager.getDevice().getManufacturer().toString())); + builder.title(mContext.getString(R.string.dialog_title_notification, AppKillerManager.getDevice().getManufacturer().toString())); } } @@ -186,7 +186,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { private boolean isActionAvailable() { if (mContext != null) { - return KillerManager.isActionAvailable(mContext, mAction); + return AppKillerManager.isActionAvailable(mContext, mAction); } return false; } @@ -205,7 +205,7 @@ public DialogKillerManagerBuilder setDontShowAgain(boolean enable) { public void show() throws NullPointerException, UnAvailableActionException, UnSupportedDeviceException { build(); - if (!KillerManager.isDeviceSupported()) { + if (!AppKillerManager.isDeviceSupported()) { Timber.tag(this.getClass().getName()).i("Device not in the list no need to show the dialog"); throw new UnSupportedDeviceException(); } @@ -258,13 +258,13 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { int helpImageRes = 0; switch (mAction) { case ACTION_AUTO_START: - helpImageRes = KillerManager.getDevice().getHelpImageAutoStart(); + helpImageRes = AppKillerManager.getDevice().getHelpImageAutoStart(); break; case ACTION_POWER_SAVING: - helpImageRes = KillerManager.getDevice().getHelpImagePowerSaving(); + helpImageRes = AppKillerManager.getDevice().getHelpImagePowerSaving(); break; case ACTION_NOTIFICATIONS: - helpImageRes = KillerManager.getDevice().getHelpImageNotification(); + helpImageRes = AppKillerManager.getDevice().getHelpImageNotification(); break; } diff --git a/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/utils/KillerManagerUtils.java b/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/utils/KillerManagerUtils.java index d3c28f7..de554e3 100644 --- a/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/utils/KillerManagerUtils.java +++ b/appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/utils/KillerManagerUtils.java @@ -3,7 +3,7 @@ import android.content.Context; import android.content.SharedPreferences; -import com.thelittlefireman.appkillermanager.managers.KillerManager; +import com.thelittlefireman.appkillermanager.AppKillerManager; import static android.content.Context.MODE_PRIVATE; @@ -22,7 +22,7 @@ private static SharedPreferences getSharedPreferences(Context mContext) { * @param action * @param enable */ - public static void setDontShowAgain(Context mContext, KillerManager.Action action, boolean enable) { + public static void setDontShowAgain(Context mContext, AppKillerManager.Action action, boolean enable) { final SharedPreferences.Editor editor = getSharedPreferences(mContext).edit(); editor.putBoolean(DONT_SHOW_AGAIN + action.toString(), enable); editor.apply(); @@ -31,18 +31,18 @@ public static void setDontShowAgain(Context mContext, KillerManager.Action actio public static void setAllDontShowAgain(Context mContext, boolean enable) { final SharedPreferences.Editor editor = getSharedPreferences(mContext).edit(); - for (KillerManager.Action action : KillerManager.Action.values()) { + for (AppKillerManager.Action action : AppKillerManager.Action.values()) { editor.putBoolean(DONT_SHOW_AGAIN + action.toString(), enable); } editor.apply(); } - public static boolean isDontShowAgain(Context mContext, KillerManager.Action action) { + public static boolean isDontShowAgain(Context mContext, AppKillerManager.Action action) { return getSharedPreferences(mContext).getBoolean(DONT_SHOW_AGAIN + action.toString(), false); } public static boolean isAllDontShowAgain(Context context) { - for (KillerManager.Action action : KillerManager.Action.values()) { + for (AppKillerManager.Action action : AppKillerManager.Action.values()) { if (!isDontShowAgain(context, action)) { return false; } @@ -51,7 +51,7 @@ public static boolean isAllDontShowAgain(Context context) { } public static boolean isAnyDontShowAgain(Context context) { - for (KillerManager.Action action : KillerManager.Action.values()) { + for (AppKillerManager.Action action : AppKillerManager.Action.values()) { if (isDontShowAgain(context, action)) { return true; } @@ -59,14 +59,14 @@ public static boolean isAnyDontShowAgain(Context context) { return false; } - public static void updateIsActionDone(Context context, KillerManager.Action action, boolean b) { + public static void updateIsActionDone(Context context, AppKillerManager.Action action, boolean b) { final SharedPreferences.Editor editor = getSharedPreferences(context).edit(); editor.putBoolean(IS_DONE + action.toString(), b); editor.apply(); } - public static boolean isActionDone(Context context, KillerManager.Action action) { + public static boolean isActionDone(Context context, AppKillerManager.Action action) { final SharedPreferences prfs = getSharedPreferences(context); return prfs.getBoolean(IS_DONE + action.toString(), false); }