Skip to content

Commit

Permalink
Move managers.KillerManager to AppKillerManager
Browse files Browse the repository at this point in the history
  • Loading branch information
mklkj committed May 17, 2020
1 parent 965fcb9 commit ee019dd
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +22,7 @@ public class MainActivity extends Activity {
Button notificationManagerButton;
AppCompatCheckBox mAppCompatCheckBoxByDialog;

KillerManager.Action currentAction = null;
AppKillerManager.Action currentAction = null;



Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -75,27 +75,27 @@ 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);
}
}
}
});

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();
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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()));
}
}

Expand All @@ -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;
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -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;
}
Expand All @@ -51,22 +51,22 @@ 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;
}
}
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);
}
Expand Down

0 comments on commit ee019dd

Please sign in to comment.