Add code input dialog
This commit is contained in:
parent
c69f0578a1
commit
553d04df8e
@ -6,23 +6,12 @@
|
|||||||
<type value="RUNNING_DEVICE_TARGET" />
|
<type value="RUNNING_DEVICE_TARGET" />
|
||||||
<deviceKey>
|
<deviceKey>
|
||||||
<Key>
|
<Key>
|
||||||
<type value="VIRTUAL_DEVICE_PATH" />
|
<type value="SERIAL_NUMBER" />
|
||||||
<value value="$USER_HOME$/.android/avd/Pixel_2_API_21.avd" />
|
<value value="R38N50464FV" />
|
||||||
</Key>
|
</Key>
|
||||||
</deviceKey>
|
</deviceKey>
|
||||||
</Target>
|
</Target>
|
||||||
</runningDeviceTargetSelectedWithDropDown>
|
</runningDeviceTargetSelectedWithDropDown>
|
||||||
<targetSelectedWithDropDown>
|
<timeTargetWasSelectedWithDropDown value="2023-06-23T14:25:11.126839955Z" />
|
||||||
<Target>
|
|
||||||
<type value="QUICK_BOOT_TARGET" />
|
|
||||||
<deviceKey>
|
|
||||||
<Key>
|
|
||||||
<type value="VIRTUAL_DEVICE_PATH" />
|
|
||||||
<value value="$USER_HOME$/.android/avd/Pixel_2_API_21.avd" />
|
|
||||||
</Key>
|
|
||||||
</deviceKey>
|
|
||||||
</Target>
|
|
||||||
</targetSelectedWithDropDown>
|
|
||||||
<timeTargetWasSelectedWithDropDown value="2023-06-23T13:56:20.858216724Z" />
|
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -7,6 +7,7 @@ import android.media.MediaPlayer;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
@ -42,6 +43,12 @@ public class IntroActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
binding.videoView.setOnCompletionListener(mp -> openMainActivity());
|
binding.videoView.setOnCompletionListener(mp -> openMainActivity());
|
||||||
|
|
||||||
|
binding.videoView.setOnErrorListener((MediaPlayer mp, int what, int extra) -> {
|
||||||
|
Toast.makeText(this, "Failed to play video", Toast.LENGTH_LONG).show();
|
||||||
|
openMainActivity();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
setContentView(binding.getRoot());
|
setContentView(binding.getRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,11 +2,16 @@ package com.cringe_studios.cringe_authenticator;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.renderscript.ScriptGroup;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.ListAdapter;
|
||||||
|
import android.widget.SimpleAdapter;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.activity.result.ActivityResultLauncher;
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
@ -22,6 +27,8 @@ import androidx.navigation.ui.AppBarConfiguration;
|
|||||||
import androidx.navigation.ui.NavigationUI;
|
import androidx.navigation.ui.NavigationUI;
|
||||||
|
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.ActivityMainBinding;
|
import com.cringe_studios.cringe_authenticator.databinding.ActivityMainBinding;
|
||||||
|
import com.cringe_studios.cringe_authenticator.databinding.DialogInputCodeChoiceBinding;
|
||||||
|
import com.cringe_studios.cringe_authenticator.databinding.DialogInputCodeTotpBinding;
|
||||||
import com.cringe_studios.cringe_authenticator.fragment.DynamicFragment;
|
import com.cringe_studios.cringe_authenticator.fragment.DynamicFragment;
|
||||||
import com.cringe_studios.cringe_authenticator.fragment.HomeFragment;
|
import com.cringe_studios.cringe_authenticator.fragment.HomeFragment;
|
||||||
import com.cringe_studios.cringe_authenticator.fragment.MenuFragment;
|
import com.cringe_studios.cringe_authenticator.fragment.MenuFragment;
|
||||||
@ -29,6 +36,8 @@ import com.cringe_studios.cringe_authenticator.fragment.SettingsFragment;
|
|||||||
import com.cringe_studios.cringe_authenticator.scanner.QRScannerActivity;
|
import com.cringe_studios.cringe_authenticator.scanner.QRScannerActivity;
|
||||||
import com.cringe_studios.cringe_authenticator.scanner.QRScannerContract;
|
import com.cringe_studios.cringe_authenticator.scanner.QRScannerContract;
|
||||||
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
||||||
|
import com.cringe_studios.cringe_authenticator_library.OTPAlgorithm;
|
||||||
|
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
@ -91,7 +100,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).build();
|
appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).build();
|
||||||
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
|
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
|
||||||
|
|
||||||
binding.fab.setOnClickListener(view -> NavigationUtil.navigate(this, MenuFragment.class, null));
|
binding.fabMenu.setOnClickListener(view -> NavigationUtil.navigate(this, MenuFragment.class, null));
|
||||||
|
binding.fabScan.setOnClickListener(view -> scanCode());
|
||||||
|
binding.fabInput.setOnClickListener(view -> inputCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -146,12 +157,63 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
NavigationUtil.navigate(this, SettingsFragment.class, null);
|
NavigationUtil.navigate(this, SettingsFragment.class, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scanCode(View view) {
|
public void scanCode() {
|
||||||
Log.i("AMOGUS", "Scan");
|
|
||||||
Intent intent = new Intent(this, QRScannerActivity.class);
|
|
||||||
startQRCodeScan.launch(null);
|
startQRCodeScan.launch(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void inputCode() {
|
||||||
|
DialogInputCodeChoiceBinding binding = DialogInputCodeChoiceBinding.inflate(getLayoutInflater());
|
||||||
|
|
||||||
|
String[] options = new String[2];
|
||||||
|
options[0] = OTPType.TOTP.getFriendlyName() + " (TOTP)";
|
||||||
|
options[1] = OTPType.HOTP.getFriendlyName() + " (HOTP)";
|
||||||
|
|
||||||
|
AlertDialog dialog = new AlertDialog.Builder(this)
|
||||||
|
.setTitle("Select Code Type")
|
||||||
|
.setView(binding.getRoot())
|
||||||
|
.setNegativeButton("Cancel", (view, which) -> {})
|
||||||
|
.create();
|
||||||
|
|
||||||
|
binding.codeTypes.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, options));
|
||||||
|
binding.codeTypes.setOnItemClickListener((AdapterView<?> parent, View view, int position, long id) -> {
|
||||||
|
switch(position) {
|
||||||
|
case 0:
|
||||||
|
showTOTPDialog();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
showHOTPDialog();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
showTOTPDialog();
|
||||||
|
dialog.dismiss();
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showTOTPDialog() {
|
||||||
|
DialogInputCodeTotpBinding binding = DialogInputCodeTotpBinding.inflate(getLayoutInflater());
|
||||||
|
binding.inputAlgorithm.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, OTPAlgorithm.values()));
|
||||||
|
binding.inputDigits.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, new Integer[]{6, 7, 8, 9, 10, 11, 12}));
|
||||||
|
showCodeDialog(binding.getRoot(), () -> {
|
||||||
|
// TODO: handle input
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showHOTPDialog() {
|
||||||
|
DialogInputCodeTotpBinding binding = DialogInputCodeTotpBinding.inflate(getLayoutInflater());
|
||||||
|
showCodeDialog(binding.getRoot(), () -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showCodeDialog(View view, Runnable ok) {
|
||||||
|
new AlertDialog.Builder(this)
|
||||||
|
.setTitle("Input Code")
|
||||||
|
.setView(view)
|
||||||
|
.setPositiveButton("Ok", (btnView, which) -> ok.run())
|
||||||
|
.setNegativeButton("Cancel", (btnView, which) -> {})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
public void addGroup(MenuItem item) {
|
public void addGroup(MenuItem item) {
|
||||||
EditText t = new EditText(this);
|
EditText t = new EditText(this);
|
||||||
new AlertDialog.Builder(this)
|
new AlertDialog.Builder(this)
|
||||||
|
@ -38,12 +38,11 @@
|
|||||||
android:layout_gravity="bottom|end"
|
android:layout_gravity="bottom|end"
|
||||||
android:layout_marginEnd="@dimen/fab_margin"
|
android:layout_marginEnd="@dimen/fab_margin"
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:onClick="scanCode"
|
|
||||||
app:srcCompat="@drawable/baseline_qr_code_scanner_24"
|
app:srcCompat="@drawable/baseline_qr_code_scanner_24"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/fab"
|
android:id="@+id/fab_menu"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom|end"
|
android:layout_gravity="bottom|end"
|
||||||
|
17
app/src/main/res/layout/dialog_input_code_choice.xml
Normal file
17
app/src/main/res/layout/dialog_input_code_choice.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout 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_height="match_parent"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/code_types"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:listitem="@android:layout/test_list_item" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
47
app/src/main/res/layout/dialog_input_code_totp.xml
Normal file
47
app/src/main/res/layout/dialog_input_code_totp.xml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="10dp">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/input_name"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:inputType="text"
|
||||||
|
android:hint="Name" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/input_secret"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:inputType="text"
|
||||||
|
android:hint="Secret" />
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/input_algorithm"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="10dp"
|
||||||
|
android:paddingBottom="10dp" />
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/input_digits"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="10dp"
|
||||||
|
android:paddingBottom="10dp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/input_period"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:inputType="number"
|
||||||
|
android:hint="Period"
|
||||||
|
android:autofillHints="" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user