Use progress circle

This commit is contained in:
MrLetsplay 2023-07-25 19:42:02 +02:00
parent 94a8994d40
commit 1049b4e48a
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
5 changed files with 48 additions and 13 deletions

View File

@ -142,7 +142,8 @@ public class GroupFragment extends NamedFragment {
if(vh.getOTPData().getType() == OTPType.TOTP) { if(vh.getOTPData().getType() == OTPType.TOTP) {
long timeDiff = vh.getOTPData().getNextDueTime() - System.currentTimeMillis() / 1000; long timeDiff = vh.getOTPData().getNextDueTime() - System.currentTimeMillis() / 1000;
vh.getBinding().progress.setProgress((int) ((1 - ((double) timeDiff / vh.getOTPData().getPeriod())) * 100)); double progress = 1 - ((double) timeDiff / vh.getOTPData().getPeriod());
vh.getBinding().progress.setImageLevel((int) (progress * 10_000));
} }
} }
} }

View File

@ -55,7 +55,7 @@ public class OTPListAdapter extends RecyclerView.Adapter<OTPListItem> {
holder.setOTPData(data); holder.setOTPData(data);
holder.getBinding().label.setText(String.format("%s%s", data.getIssuer() == null || data.getIssuer().isEmpty() ? "" : data.getIssuer() + ": ", data.getName())); holder.getBinding().label.setText(String.format("%s%s", data.getIssuer() == null || data.getIssuer().isEmpty() ? "" : data.getIssuer() + ": ", data.getName()));
holder.getBinding().progress.setVisibility(data.getType() == OTPType.TOTP ? View.VISIBLE : View.GONE); holder.getBinding().progress.setVisibility(data.getType() == OTPType.TOTP ? View.VISIBLE : View.INVISIBLE);
holder.getBinding().getRoot().setOnClickListener(view -> { holder.getBinding().getRoot().setOnClickListener(view -> {
if(data.getType() != OTPType.HOTP) return; if(data.getType() != OTPType.HOTP) return;

View File

@ -127,6 +127,7 @@ public class DialogUtil {
binding.inputDigits.setEnabled(!view); binding.inputDigits.setEnabled(!view);
binding.inputName.setEnabled(!view); binding.inputName.setEnabled(!view);
binding.inputIssuer.setEnabled(!view);
binding.inputSecret.setEnabled(!view); binding.inputSecret.setEnabled(!view);
binding.inputCounter.setEnabled(!view); binding.inputCounter.setEnabled(!view);
binding.inputChecksum.setEnabled(!view); binding.inputChecksum.setEnabled(!view);
@ -180,6 +181,7 @@ public class DialogUtil {
} }
public static void showViewCodeDialog(LayoutInflater inflater, @NonNull OTPData initialData, Runnable back) { public static void showViewCodeDialog(LayoutInflater inflater, @NonNull OTPData initialData, Runnable back) {
// TODO: use better dialogs
switch(initialData.getType()) { switch(initialData.getType()) {
case HOTP: showHOTPDialog(inflater, initialData, d -> {}, back, true); break; case HOTP: showHOTPDialog(inflater, initialData, d -> {}, back, true); break;
case TOTP: showTOTPDialog(inflater, initialData, d -> {}, back, true); break; case TOTP: showTOTPDialog(inflater, initialData, d -> {}, back, true); break;

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:toDegrees="270">
<shape
android:shape="ring"
android:innerRadius="0dp"
android:thickness="10dp"
android:useLevel="true">
<gradient
android:angle="0"
android:endColor="?attr/colorTheme1"
android:startColor="?attr/colorTheme1"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
@ -14,19 +15,32 @@
android:textAlignment="center" android:textAlignment="center"
android:textSize="16sp"/> android:textSize="16sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp">
<Space
android:layout_width="30dp"
android:layout_height="30dp" />
<TextView <TextView
android:id="@+id/otpCode" android:id="@+id/otpCode"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="000000" android:text="000000"
android:textAlignment="center" android:textAlignment="center"
android:textSize="20sp" /> android:textSize="20sp"
android:layout_weight="1" />
<ProgressBar <ImageView
android:id="@+id/progress" android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal" android:layout_width="30dp"
android:layout_width="match_parent" android:layout_height="30dp"
android:layout_height="wrap_content" app:srcCompat="@drawable/progress_circle" />
android:max="100" />
</LinearLayout>
</LinearLayout> </LinearLayout>