Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
0xRe1nk0 committed Oct 1, 2024
1 parent e2aaef0 commit 5693b77
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
3 changes: 0 additions & 3 deletions OsmAnd/src/net/osmand/plus/activities/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ public void onCreate(Bundle savedInstanceState) {
app.getAidlApi().onCreateMapActivity(this);

lockHelper.setLockUIAdapter(this);
lockHelper.addLockScreenListener(this);
keyEventHelper.setMapActivity(this);
mIsDestroyed = false;
if (mapViewWithLayers != null) {
Expand Down Expand Up @@ -559,7 +558,6 @@ protected void onResume() {
return;
}
importHelper.setUiActivity(this);
lockHelper.setMapActivity(this);

long time = System.currentTimeMillis();
FragmentManager fragmentManager = getSupportFragmentManager();
Expand Down Expand Up @@ -964,7 +962,6 @@ protected void onDestroy() {
mapViewWithLayers.onDestroy();
}
lockHelper.setLockUIAdapter(null);
lockHelper.removeLockScreenListener();
keyEventHelper.setMapActivity(null);
extendedMapActivity.onDestroy(this);

Expand Down
46 changes: 17 additions & 29 deletions OsmAnd/src/net/osmand/plus/helpers/LockHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public class LockHelper implements SensorEventListener, StateChangedListener<App

private final Handler uiHandler;
private final OsmandApplication app;
@Nullable
private MapActivity mapActivity;
private CommonPreference<Integer> turnScreenOnTime;
private CommonPreference<Boolean> turnScreenOnSensor;
private CommonPreference<Boolean> useSystemScreenTimeout;
Expand Down Expand Up @@ -78,6 +76,7 @@ public LockHelper(OsmandApplication app) {
turnScreenOnPowerButton = settings.TURN_SCREEN_ON_POWER_BUTTON;
turnScreenOnNavigationInstructions = settings.TURN_SCREEN_ON_NAVIGATION_INSTRUCTIONS;

settings.APPLICATION_MODE.addListener(this);
lockRunnable = this::lock;
voiceMessageListener = new VoiceMessageListener() {
@Override
Expand Down Expand Up @@ -136,14 +135,6 @@ public void lock() {
}
}

public void toggleLockScreen(){
lockScreen = !lockScreen;
}

public boolean isScreenLocked(){
return lockScreen;
}

private void timedUnlock(long millis) {
uiHandler.removeCallbacks(lockRunnable);
if (wakeLock == null) {
Expand Down Expand Up @@ -227,29 +218,30 @@ public void setLockUIAdapter(@Nullable LockUIAdapter adapter) {
* LockScreenAction part
*/

public void addLockScreenListener(@Nullable MapActivity mapActivity) {
setMapActivity(mapActivity);
app.getSettings().APPLICATION_MODE.addListener(this);

public void toggleLockScreen() {
lockScreen = !lockScreen;
}

public boolean isScreenLocked() {
return lockScreen;
}

public void removeLockScreenListener() {
app.getSettings().APPLICATION_MODE.removeListener(this);
public void unlockScreen() {
lockScreen = false;
}

@Override
public void stateChanged(ApplicationMode mode) {
if (mapActivity != null) {
List<QuickActionButtonState> buttonStates = app.getMapButtonsHelper().getButtonsStates();
ApplicationMode currentMode = app.getSettings().getApplicationMode();
LockHelper lockHelper = app.getLockHelper();

if (lastApplicationMode != currentMode && lockHelper.isScreenLocked()) {
if (!hasLockScreenAction(buttonStates)) {
lockHelper.toggleLockScreen();
}
List<QuickActionButtonState> buttonStates = app.getMapButtonsHelper().getButtonsStates();
ApplicationMode currentMode = app.getSettings().getApplicationMode();

if (isScreenLocked() && lastApplicationMode != currentMode) {
if (!hasLockScreenAction(buttonStates)) {
unlockScreen();
}
lastApplicationMode = currentMode;
}
lastApplicationMode = currentMode;
}

private boolean hasLockScreenAction(@NonNull List<QuickActionButtonState> mapButtonStates) {
Expand All @@ -266,10 +258,6 @@ private boolean hasLockScreenAction(@NonNull List<QuickActionButtonState> mapBut
return false;
}

public void setMapActivity(@Nullable MapActivity mapActivity) {
this.mapActivity = mapActivity;
}

public GestureDetector getLockGestureDetector(@NonNull MapActivity mapActivity) {
if (gestureDetector == null) {
gestureDetector = LockGestureDetector.getDetector(mapActivity);
Expand Down

0 comments on commit 5693b77

Please sign in to comment.