added something
idk lol lmao dead
This commit is contained in:
@@ -80,12 +80,19 @@ public class AppLock {
|
||||
* @return true if the user is enrolled in locking and the last successful unlock happened more than the default lock duration ago
|
||||
*/
|
||||
public static boolean isUnlockRequired(Context context) {
|
||||
int minutes = context.getResources()
|
||||
.getInteger(AndroidUtils.getIdentifier("applock__activity_lock_reenable_minutes", "integer"));
|
||||
int minutes = Integer.parseInt(getPinCodeTime(context));
|
||||
|
||||
if (minutes < 1) {
|
||||
minutes = 1;
|
||||
}
|
||||
|
||||
return isUnlockRequired(context, TimeUnit.MINUTES.toMillis(minutes));
|
||||
}
|
||||
|
||||
public static String getPinCodeTime(Context context) {
|
||||
return context.getSharedPreferences(PREFS, 0).getString("pincode_time", "15");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the user is enrolled in locking and the last successful unlock happened more than lastSuccessValidMs ago
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,7 @@ package ru.vtosters.lite.ui;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.InputType;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
@@ -334,6 +335,52 @@ public class PreferenceFragmentUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static Preference addEditTextValPreference(
|
||||
PreferenceScreen screen,
|
||||
String key,
|
||||
CharSequence title,
|
||||
CharSequence defval,
|
||||
onPreferenceTextValueChangeListener editTextPrefChangeListener
|
||||
) {
|
||||
return addPreference(screen, key, title, null, null, preference -> {
|
||||
LinearLayout linearLayout = new LinearLayout(screen.getContext());
|
||||
|
||||
final EditText editText = new EditText(screen.getContext());
|
||||
editText.setText(PreferenceManager.getDefaultSharedPreferences(screen.getContext()).getString(key, ""));
|
||||
editText.setHint(title);
|
||||
editText.setTextColor(ThemesUtils.getTextAttr());
|
||||
editText.setHintTextColor(ThemesUtils.getSTextAttr());
|
||||
editText.setText(defval);
|
||||
|
||||
editText.setBackgroundTintList(ThemesUtils.getAccenedColorStateList());
|
||||
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
editText.setTransformationMethod(null);
|
||||
|
||||
linearLayout.addView(editText);
|
||||
editText.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
ViewGroup.MarginLayoutParams margin = ((ViewGroup.MarginLayoutParams) editText.getLayoutParams());
|
||||
margin.setMargins(AndroidUtils.dp2px(20f), 0, AndroidUtils.dp2px(20f), 0);
|
||||
editText.setLayoutParams(margin);
|
||||
|
||||
new VkAlertDialog.Builder(screen.getContext())
|
||||
.setTitle(title)
|
||||
.setView(linearLayout)
|
||||
.setPositiveButton("OK", (dialog, which) -> {
|
||||
boolean change = editTextPrefChangeListener.onChanged(preference, editText.getText().toString());
|
||||
if (!change)
|
||||
return;
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(screen.getContext())
|
||||
.edit()
|
||||
.putString(key, editText.getText().toString())
|
||||
.apply();
|
||||
})
|
||||
.show();
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
public interface onPreferenceTextValueChangeListener {
|
||||
boolean onChanged(Preference preference, String newValue);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.guardanis.applock.AppLock;
|
||||
import com.guardanis.applock.activities.LockCreationActivity;
|
||||
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
|
||||
|
||||
import ru.vtosters.lite.ui.PreferenceFragmentUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
public class PinFragment extends MaterialPreferenceToolbarFragment {
|
||||
@SuppressLint("CommitPrefEdits")
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
@@ -40,5 +40,17 @@ public class PinFragment extends MaterialPreferenceToolbarFragment {
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
PreferenceFragmentUtils.addEditTextValPreference(
|
||||
getPreferenceScreen(),
|
||||
"",
|
||||
"Время для автоблокировки",
|
||||
AppLock.getPinCodeTime(requireContext()),
|
||||
((preference, o) -> {
|
||||
AppLock.getInstance(requireContext()).getPreferences().edit().putString("pincode_time", o).apply();
|
||||
AndroidUtils.sendToast("Сохранено");
|
||||
return true;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user