Skip to content

Commit 85b2bed

Browse files
committed
Option to auto lock the app immediately, based on nekohasekai commit
1 parent 6c94cde commit 85b2bed

6 files changed

Lines changed: 28 additions & 15 deletions

File tree

TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3069,7 +3069,7 @@ public static boolean needShowPasscode(boolean reset) {
30693069
FileLog.d("wasInBackground = " + wasInBackground + " appLocked = " + SharedConfig.appLocked + " autoLockIn = " + SharedConfig.autoLockIn + " lastPauseTime = " + SharedConfig.lastPauseTime + " uptime = " + uptime);
30703070
}
30713071
return SharedConfig.passcodeHash.length() > 0 && wasInBackground &&
3072-
(SharedConfig.appLocked ||
3072+
(SharedConfig.appLocked || SharedConfig.autoLockIn == 1 ||
30733073
SharedConfig.autoLockIn != 0 && SharedConfig.lastPauseTime != 0 && !SharedConfig.appLocked && (SharedConfig.lastPauseTime + SharedConfig.autoLockIn) <= uptime ||
30743074
uptime + 5 < SharedConfig.lastPauseTime);
30753075
}

TMessagesProj/src/main/java/org/telegram/ui/BubbleActivity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ public void run() {
295295
if (SharedConfig.appLocked) {
296296
AndroidUtilities.runOnUIThread(lockRunnable, 1000);
297297
} else if (SharedConfig.autoLockIn != 0) {
298-
AndroidUtilities.runOnUIThread(lockRunnable, (long) SharedConfig.autoLockIn * 1000 + 1000);
298+
if (SharedConfig.autoLockIn == 1) {
299+
AndroidUtilities.runOnUIThread(lockRunnable, 1000);
300+
} else {
301+
AndroidUtilities.runOnUIThread(lockRunnable, (long) SharedConfig.autoLockIn * 1000 + 1000);
302+
}
299303
}
300304
} else {
301305
SharedConfig.lastPauseTime = 0;

TMessagesProj/src/main/java/org/telegram/ui/ExternalActionActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ public void run() {
573573
}
574574
}
575575
};
576-
if (SharedConfig.appLocked) {
576+
if (SharedConfig.appLocked || SharedConfig.autoLockIn == 1) {
577577
AndroidUtilities.runOnUIThread(lockRunnable, 1000);
578578
} else if (SharedConfig.autoLockIn != 0) {
579579
AndroidUtilities.runOnUIThread(lockRunnable, (long) SharedConfig.autoLockIn * 1000 + 1000);

TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7354,7 +7354,7 @@ public void run() {
73547354
}
73557355
}
73567356
};
7357-
if (SharedConfig.appLocked) {
7357+
if (SharedConfig.appLocked || SharedConfig.autoLockIn == 1) {
73587358
AndroidUtilities.runOnUIThread(lockRunnable, 1000);
73597359
if (BuildVars.LOGS_ENABLED) {
73607360
FileLog.d("schedule app lock in " + 1000);

TMessagesProj/src/main/java/org/telegram/ui/PasscodeActivity.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -309,28 +309,32 @@ public boolean supportsPredictiveItemAnimations() {
309309
builder.setTitle(LocaleController.getString("AutoLock", R.string.AutoLock));
310310
final NumberPicker numberPicker = new NumberPicker(getParentActivity());
311311
numberPicker.setMinValue(0);
312-
numberPicker.setMaxValue(4);
312+
numberPicker.setMaxValue(5);
313313
if (SharedConfig.autoLockIn == 0) {
314314
numberPicker.setValue(0);
315-
} else if (SharedConfig.autoLockIn == 60) {
315+
} else if (SharedConfig.autoLockIn == 1) {
316316
numberPicker.setValue(1);
317-
} else if (SharedConfig.autoLockIn == 60 * 5) {
317+
} else if (SharedConfig.autoLockIn == 60) {
318318
numberPicker.setValue(2);
319-
} else if (SharedConfig.autoLockIn == 60 * 60) {
319+
} else if (SharedConfig.autoLockIn == 60 * 5) {
320320
numberPicker.setValue(3);
321-
} else if (SharedConfig.autoLockIn == 60 * 60 * 5) {
321+
} else if (SharedConfig.autoLockIn == 60 * 60) {
322322
numberPicker.setValue(4);
323+
} else if (SharedConfig.autoLockIn == 60 * 60 * 5) {
324+
numberPicker.setValue(5);
323325
}
324326
numberPicker.setFormatter(value -> {
325327
if (value == 0) {
326328
return LocaleController.getString("AutoLockDisabled", R.string.AutoLockDisabled);
327329
} else if (value == 1) {
328-
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", 1));
330+
return LocaleController.getString("AutoLockImmediately", R.string.AutoLockImmediately);
329331
} else if (value == 2) {
330-
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", 5));
332+
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", 1));
331333
} else if (value == 3) {
332-
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Hours", 1));
334+
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", 5));
333335
} else if (value == 4) {
336+
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Hours", 1));
337+
} else if (value == 5) {
334338
return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Hours", 5));
335339
}
336340
return "";
@@ -341,12 +345,14 @@ public boolean supportsPredictiveItemAnimations() {
341345
if (which == 0) {
342346
SharedConfig.autoLockIn = 0;
343347
} else if (which == 1) {
344-
SharedConfig.autoLockIn = 60;
348+
SharedConfig.autoLockIn = 1;
345349
} else if (which == 2) {
346-
SharedConfig.autoLockIn = 60 * 5;
350+
SharedConfig.autoLockIn = 60;
347351
} else if (which == 3) {
348-
SharedConfig.autoLockIn = 60 * 60;
352+
SharedConfig.autoLockIn = 60 * 5;
349353
} else if (which == 4) {
354+
SharedConfig.autoLockIn = 60 * 60;
355+
} else if (which == 5) {
350356
SharedConfig.autoLockIn = 60 * 60 * 5;
351357
}
352358
listAdapter.notifyItemChanged(position);
@@ -1194,6 +1200,8 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
11941200
String val;
11951201
if (SharedConfig.autoLockIn == 0) {
11961202
val = LocaleController.formatString("AutoLockDisabled", R.string.AutoLockDisabled);
1203+
} else if (SharedConfig.autoLockIn == 1) {
1204+
val = LocaleController.formatString("AutoLockImmediately", R.string.AutoLockImmediately);
11971205
} else if (SharedConfig.autoLockIn < 60 * 60) {
11981206
val = LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime, LocaleController.formatPluralString("Minutes", SharedConfig.autoLockIn / 60));
11991207
} else if (SharedConfig.autoLockIn < 60 * 60 * 24) {

TMessagesProj/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9090,4 +9090,5 @@
90909090
<string name="DisableAds">Disable Ads</string>
90919091
<string name="HidePhoneNumber">Hide Your Phone Number in Drawer</string>
90929092
<string name="LocalPremium">Telegram Local Premium</string>
9093+
<string name="AutoLockImmediately">Immediately</string>
90939094
</resources>

0 commit comments

Comments
 (0)