Optimize imports, Add code timeout bar
This commit is contained in:
parent
002475d1b3
commit
8e6bc903c1
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<targetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="QUICK_BOOT_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="$USER_HOME$/.android/avd/Pixel_2_API_33.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</targetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2023-06-26T17:29:55.573199337Z" />
|
||||
</component>
|
||||
</project>
|
@ -1,8 +1,6 @@
|
||||
package com.cringe_studios.cringe_authenticator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
@ -18,8 +18,6 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.biometric.BiometricPrompt;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
|
||||
import com.cringe_studios.cringe_authenticator.databinding.ActivityMainBinding;
|
||||
import com.cringe_studios.cringe_authenticator.databinding.DialogInputCodeChoiceBinding;
|
||||
@ -37,7 +35,6 @@ import com.cringe_studios.cringe_authenticator_library.OTPAlgorithm;
|
||||
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@ -105,6 +102,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
binding.fabMenu.setOnClickListener(view -> NavigationUtil.navigate(this, MenuFragment.class, null));
|
||||
binding.fabScan.setOnClickListener(view -> scanCode());
|
||||
binding.fabInput.setOnClickListener(view -> inputCode());
|
||||
|
||||
NavigationUtil.navigate(this, HomeFragment.class, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,6 +72,10 @@ public class OTPData implements Serializable {
|
||||
this.counter = getOTP().getCounter();
|
||||
}
|
||||
|
||||
public long getNextDueTime() {
|
||||
return getOTP().getNextDueTime();
|
||||
}
|
||||
|
||||
public String validate() {
|
||||
try {
|
||||
getOTP();
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.cringe_studios.cringe_authenticator.fragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@ -11,7 +9,6 @@ import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.cringe_studios.cringe_authenticator.OTPData;
|
||||
import com.cringe_studios.cringe_authenticator.databinding.FragmentDynamicBinding;
|
||||
@ -19,6 +16,7 @@ import com.cringe_studios.cringe_authenticator.otplist.OTPListAdapter;
|
||||
import com.cringe_studios.cringe_authenticator.otplist.OTPListItem;
|
||||
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
||||
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
|
||||
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -62,12 +60,7 @@ public class DynamicFragment extends NamedFragment {
|
||||
|
||||
handler = new Handler(Looper.getMainLooper());
|
||||
refreshCodes = () -> {
|
||||
for(int i = 0; i < binding.itemList.getChildCount(); i++) {
|
||||
OTPListItem vh = (OTPListItem) binding.itemList.findViewHolderForAdapterPosition(i);
|
||||
if(vh == null) continue;
|
||||
vh.getBinding().otpCode.setText(vh.getOTPData().getPin());
|
||||
}
|
||||
|
||||
refreshCodes();
|
||||
handler.postDelayed(refreshCodes, 1000L);
|
||||
};
|
||||
|
||||
@ -89,6 +82,19 @@ public class DynamicFragment extends NamedFragment {
|
||||
otpListAdapter.add(data);
|
||||
}
|
||||
|
||||
public void refreshCodes() {
|
||||
for(int i = 0; i < binding.itemList.getChildCount(); i++) {
|
||||
OTPListItem vh = (OTPListItem) binding.itemList.findViewHolderForAdapterPosition(i);
|
||||
if(vh == null) continue;
|
||||
vh.getBinding().otpCode.setText(vh.getOTPData().getPin());
|
||||
|
||||
if(vh.getOTPData().getType() == OTPType.TOTP) {
|
||||
long timeDiff = vh.getOTPData().getNextDueTime() - System.currentTimeMillis() / 1000;
|
||||
vh.getBinding().progress.setProgress((int) ((1 - ((double) timeDiff / vh.getOTPData().getPeriod())) * 100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
@ -6,7 +6,6 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.cringe_studios.cringe_authenticator.databinding.FragmentHomeBinding;
|
||||
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.cringe_studios.cringe_authenticator.fragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
@ -10,14 +8,9 @@ import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.cringe_studios.cringe_authenticator.OTPData;
|
||||
import com.cringe_studios.cringe_authenticator.databinding.FragmentMenuBinding;
|
||||
import com.cringe_studios.cringe_authenticator.databinding.MenuItemBinding;
|
||||
import com.cringe_studios.cringe_authenticator.grouplist.GroupListAdapter;
|
||||
import com.cringe_studios.cringe_authenticator.grouplist.GroupListItem;
|
||||
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
||||
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
||||
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
|
||||
|
@ -1,8 +1,6 @@
|
||||
package com.cringe_studios.cringe_authenticator.fragment;
|
||||
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -11,22 +9,11 @@ import android.widget.ArrayAdapter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.cringe_studios.cringe_authenticator.R;
|
||||
import com.cringe_studios.cringe_authenticator.databinding.FragmentSettingsBinding;
|
||||
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
||||
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class SettingsFragment extends NamedFragment {
|
||||
|
||||
private FragmentSettingsBinding binding;
|
||||
|
@ -1,24 +1,17 @@
|
||||
package com.cringe_studios.cringe_authenticator.grouplist;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.util.Consumer;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.cringe_studios.cringe_authenticator.OTPData;
|
||||
import com.cringe_studios.cringe_authenticator.databinding.MenuItemBinding;
|
||||
import com.cringe_studios.cringe_authenticator.fragment.DynamicFragment;
|
||||
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
||||
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -1,8 +1,5 @@
|
||||
package com.cringe_studios.cringe_authenticator.grouplist;
|
||||
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -44,6 +45,7 @@ public class OTPListAdapter extends RecyclerView.Adapter<OTPListItem> {
|
||||
|
||||
holder.setOTPData(data);
|
||||
holder.getBinding().label.setText(holder.getOTPData().getName());
|
||||
holder.getBinding().progress.setVisibility(holder.getOTPData().getType() == OTPType.TOTP ? View.VISIBLE : View.GONE);
|
||||
|
||||
holder.getBinding().getRoot().setOnClickListener(view -> {
|
||||
if(data.getType() != OTPType.HOTP) return;
|
||||
@ -52,6 +54,7 @@ public class OTPListAdapter extends RecyclerView.Adapter<OTPListItem> {
|
||||
view.setClickable(false);
|
||||
Toast.makeText(view.getContext(), "Generated new code", Toast.LENGTH_LONG).show();
|
||||
data.incrementCounter();
|
||||
holder.getBinding().otpCode.setText(data.getPin());
|
||||
handler.postDelayed(() -> view.setClickable(true), 5000);
|
||||
});
|
||||
}
|
||||
|
@ -29,8 +29,6 @@ import androidx.core.content.ContextCompat;
|
||||
import com.cringe_studios.cringe_authenticator.OTPData;
|
||||
import com.cringe_studios.cringe_authenticator.databinding.ActivityQrScannerBinding;
|
||||
import com.cringe_studios.cringe_authenticator.util.OTPParser;
|
||||
import com.cringe_studios.cringe_authenticator_library.OTPAlgorithm;
|
||||
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.mlkit.vision.barcode.BarcodeScanner;
|
||||
import com.google.mlkit.vision.barcode.BarcodeScanning;
|
||||
|
@ -2,7 +2,6 @@ package com.cringe_studios.cringe_authenticator.urihandler;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.cringe_studios.cringe_authenticator.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
@ -11,12 +10,12 @@ import androidx.fragment.app.FragmentManager;
|
||||
import com.cringe_studios.cringe_authenticator.R;
|
||||
import com.cringe_studios.cringe_authenticator.fragment.NamedFragment;
|
||||
|
||||
import kotlin.Suppress;
|
||||
|
||||
public class NavigationUtil {
|
||||
|
||||
// TODO: check if this still works after changes
|
||||
|
||||
public static void navigate(AppCompatActivity activity, Class<? extends NamedFragment> fragmentClass, Bundle args) {
|
||||
FragmentManager manager = activity.getSupportFragmentManager().getPrimaryNavigationFragment().getChildFragmentManager();
|
||||
FragmentManager manager = activity.getSupportFragmentManager();
|
||||
NamedFragment fragment = instantiateFragment(manager, fragmentClass, args);
|
||||
|
||||
ActionBar bar = activity.getSupportActionBar();
|
||||
@ -45,7 +44,7 @@ public class NavigationUtil {
|
||||
}
|
||||
|
||||
public static Fragment getCurrentFragment(AppCompatActivity activity) {
|
||||
return getCurrentFragment(activity.getSupportFragmentManager().getPrimaryNavigationFragment().getChildFragmentManager());
|
||||
return getCurrentFragment(activity.getSupportFragmentManager());
|
||||
}
|
||||
|
||||
public static Fragment getCurrentFragment(Fragment currentFragment) {
|
||||
|
@ -16,8 +16,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import kotlinx.coroutines.flow.SharedFlow;
|
||||
|
||||
public class SettingsUtil {
|
||||
|
||||
public static final Map<String, Integer> THEMES;
|
||||
|
@ -5,7 +5,7 @@
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<fragment
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/nav_host_fragment_content_main"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="0dp"
|
||||
@ -14,6 +14,5 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:navGraph="@navigation/nav_graph" />
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -21,4 +21,12 @@
|
||||
android:text="000000"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="100" />
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user