Move some files
This commit is contained in:
parent
d0858d127a
commit
5925674826
@ -1,7 +1,5 @@
|
|||||||
package com.cringe_studios.cringe_authenticator;
|
package com.cringe_studios.cringe_authenticator;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -9,12 +7,10 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.activity.result.ActivityResultLauncher;
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
import androidx.activity.result.contract.ActivityResultContract;
|
|
||||||
import androidx.activity.result.contract.ActivityResultContracts;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.biometric.BiometricPrompt;
|
import androidx.biometric.BiometricPrompt;
|
||||||
@ -26,15 +22,14 @@ 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.FragmentDynamicBinding;
|
|
||||||
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;
|
||||||
import com.cringe_studios.cringe_authenticator.fragment.SettingsFragment;
|
import com.cringe_studios.cringe_authenticator.fragment.SettingsFragment;
|
||||||
|
import com.cringe_studios.cringe_authenticator.scanner.QRScannerActivity;
|
||||||
|
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.util.SettingsUtil;
|
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
|
||||||
import com.cringe_studios.cringe_authenticator_library.OTPType;
|
|
||||||
import com.google.android.material.color.utilities.DynamicColor;
|
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
@ -73,10 +68,16 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
launchApp();
|
launchApp();
|
||||||
|
|
||||||
startQRCodeScan = registerForActivityResult(new QRScannerContract(), obj -> {
|
startQRCodeScan = registerForActivityResult(new QRScannerContract(), obj -> {
|
||||||
|
if(obj == null) { // Got some error TODO: show error message
|
||||||
|
Toast.makeText(this, "Failed to scan code", Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Fragment fragment = NavigationUtil.getCurrentFragment(this);
|
Fragment fragment = NavigationUtil.getCurrentFragment(this);
|
||||||
if(fragment instanceof DynamicFragment) {
|
if(fragment instanceof DynamicFragment) {
|
||||||
DynamicFragment frag = (DynamicFragment) fragment;
|
DynamicFragment frag = (DynamicFragment) fragment;
|
||||||
SettingsUtil.addOTP(getSharedPreferences("groups", MODE_PRIVATE), frag.getGroupName(), obj);
|
SettingsUtil.addOTP(getSharedPreferences(DynamicFragment.GROUPS_PREFS_NAME, MODE_PRIVATE), frag.getGroupName(), obj);
|
||||||
|
frag.loadOTPs();
|
||||||
}
|
}
|
||||||
Log.i("AMOGUS", "Actually got something bruh" + obj);
|
Log.i("AMOGUS", "Actually got something bruh" + obj);
|
||||||
});
|
});
|
||||||
|
@ -3,6 +3,7 @@ package com.cringe_studios.cringe_authenticator.fragment;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -13,22 +14,28 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import com.cringe_studios.cringe_authenticator.OTPData;
|
import com.cringe_studios.cringe_authenticator.OTPData;
|
||||||
import com.cringe_studios.cringe_authenticator.R;
|
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.AuthenticateTotpBinding;
|
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.FragmentDynamicBinding;
|
import com.cringe_studios.cringe_authenticator.databinding.FragmentDynamicBinding;
|
||||||
|
import com.cringe_studios.cringe_authenticator.databinding.OtpCodeBinding;
|
||||||
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
||||||
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
|
||||||
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
|
import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.cringe_studios.cringe_authenticator_library.OTP;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DynamicFragment extends Fragment {
|
public class DynamicFragment extends Fragment {
|
||||||
|
|
||||||
|
public static final String
|
||||||
|
GROUPS_PREFS_NAME = "groups",
|
||||||
|
BUNDLE_GROUP = "group";
|
||||||
|
|
||||||
private String groupName;
|
private String groupName;
|
||||||
|
|
||||||
private FragmentDynamicBinding binding;
|
private FragmentDynamicBinding binding;
|
||||||
|
|
||||||
|
private Handler handler;
|
||||||
|
|
||||||
|
private Runnable refreshCodes;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -39,7 +46,7 @@ public class DynamicFragment extends Fragment {
|
|||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
binding = FragmentDynamicBinding.inflate(inflater, container, false);
|
binding = FragmentDynamicBinding.inflate(inflater, container, false);
|
||||||
|
|
||||||
groupName = requireArguments().getString("group");
|
groupName = requireArguments().getString(DynamicFragment.BUNDLE_GROUP);
|
||||||
|
|
||||||
/*String[] totps = new String[]{"Code 1", "Code 2", groupName};
|
/*String[] totps = new String[]{"Code 1", "Code 2", groupName};
|
||||||
for(String totp : totps) {
|
for(String totp : totps) {
|
||||||
@ -52,18 +59,31 @@ public class DynamicFragment extends Fragment {
|
|||||||
|
|
||||||
FabUtil.showFabs(getActivity());
|
FabUtil.showFabs(getActivity());
|
||||||
|
|
||||||
|
refreshCodes = () -> {
|
||||||
|
for(int i = 0; i < binding.itemList.getChildCount(); i++) {
|
||||||
|
View v = binding.itemList.getChildAt(i);
|
||||||
|
OTP otp = (OTP) v.getTag();
|
||||||
|
otp.getPin();
|
||||||
|
}
|
||||||
|
handler.postDelayed(refreshCodes, 1000L);
|
||||||
|
};
|
||||||
|
|
||||||
|
handler.post(refreshCodes);
|
||||||
|
|
||||||
return binding.getRoot();
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadOTPs() {
|
public void loadOTPs() {
|
||||||
SharedPreferences prefs = getActivity().getSharedPreferences("groups", Context.MODE_PRIVATE);
|
SharedPreferences prefs = getActivity().getSharedPreferences(DynamicFragment.GROUPS_PREFS_NAME, Context.MODE_PRIVATE);
|
||||||
List<OTPData> data = SettingsUtil.getOTPs(prefs, groupName);
|
List<OTPData> data = SettingsUtil.getOTPs(prefs, groupName);
|
||||||
Log.i("AMOGUS", "OTPS: " + data);
|
Log.i("AMOGUS", "OTPS: " + data);
|
||||||
|
|
||||||
|
binding.itemList.removeAllViews();
|
||||||
for(OTPData otp : data) {
|
for(OTPData otp : data) {
|
||||||
AuthenticateTotpBinding itemBinding = AuthenticateTotpBinding.inflate(getLayoutInflater());
|
OtpCodeBinding itemBinding = OtpCodeBinding.inflate(getLayoutInflater());
|
||||||
itemBinding.displayName.setText(otp.getName());
|
itemBinding.label.setText(otp.getName());
|
||||||
itemBinding.totpCode.setText(otp.toOTP().getPin());
|
itemBinding.otpCode.setText(otp.toOTP().getPin());
|
||||||
|
itemBinding.getRoot().setTag(otp.toOTP());
|
||||||
binding.itemList.addView(itemBinding.getRoot());
|
binding.itemList.addView(itemBinding.getRoot());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,6 +94,12 @@ public class DynamicFragment extends Fragment {
|
|||||||
this.binding = null;
|
this.binding = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
handler.removeCallbacks(refreshCodes);
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
public String getGroupName() {
|
public String getGroupName() {
|
||||||
return groupName;
|
return groupName;
|
||||||
}
|
}
|
||||||
|
@ -29,16 +29,16 @@ public class MenuFragment extends Fragment {
|
|||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
binding = FragmentMenuBinding.inflate(inflater);
|
binding = FragmentMenuBinding.inflate(inflater);
|
||||||
|
|
||||||
String[] items = {"a", "b"};
|
|
||||||
|
|
||||||
SharedPreferences pr = getContext().getSharedPreferences("menu", Context.MODE_PRIVATE);
|
SharedPreferences pr = getContext().getSharedPreferences("menu", Context.MODE_PRIVATE);
|
||||||
|
|
||||||
|
String[] items = {"a", "b"};
|
||||||
|
|
||||||
for(String item : items) {
|
for(String item : items) {
|
||||||
MenuItemBinding itemBinding = MenuItemBinding.inflate(inflater);
|
MenuItemBinding itemBinding = MenuItemBinding.inflate(inflater);
|
||||||
itemBinding.button.setText(item);
|
itemBinding.button.setText(item);
|
||||||
itemBinding.button.setOnClickListener(view -> {
|
itemBinding.button.setOnClickListener(view -> {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("tab", item);
|
bundle.putString(DynamicFragment.BUNDLE_GROUP, item);
|
||||||
NavigationUtil.navigate(this, DynamicFragment.class, bundle);
|
NavigationUtil.navigate(this, DynamicFragment.class, bundle);
|
||||||
});
|
});
|
||||||
itemBinding.button.setOnLongClickListener(view -> {
|
itemBinding.button.setOnLongClickListener(view -> {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.cringe_studios.cringe_authenticator;
|
package com.cringe_studios.cringe_authenticator.scanner;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -24,6 +24,7 @@ import androidx.camera.lifecycle.ProcessCameraProvider;
|
|||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
|
||||||
|
import com.cringe_studios.cringe_authenticator.OTPData;
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.ActivityQrScannerBinding;
|
import com.cringe_studios.cringe_authenticator.databinding.ActivityQrScannerBinding;
|
||||||
import com.cringe_studios.cringe_authenticator_library.OTP;
|
import com.cringe_studios.cringe_authenticator_library.OTP;
|
||||||
import com.cringe_studios.cringe_authenticator_library.OTPAlgorithm;
|
import com.cringe_studios.cringe_authenticator_library.OTPAlgorithm;
|
||||||
@ -120,6 +121,8 @@ public class QRScannerActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(code == null) return;
|
||||||
|
|
||||||
Uri uri = Uri.parse(code.getRawValue());
|
Uri uri = Uri.parse(code.getRawValue());
|
||||||
Log.i("AMOGUS", code.getRawValue());
|
Log.i("AMOGUS", code.getRawValue());
|
||||||
Log.i("AMOGUS", uri.getHost());
|
Log.i("AMOGUS", uri.getHost());
|
||||||
@ -180,7 +183,7 @@ public class QRScannerActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void success(OTPData data) {
|
private void success(@NonNull OTPData data) {
|
||||||
Intent result = new Intent();
|
Intent result = new Intent();
|
||||||
result.putExtra("data", data);
|
result.putExtra("data", data);
|
||||||
setResult(Activity.RESULT_OK, result);
|
setResult(Activity.RESULT_OK, result);
|
||||||
@ -188,8 +191,7 @@ public class QRScannerActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void error(String errorMessage) {
|
private void error(String errorMessage) {
|
||||||
Intent result = new Intent();
|
setResult(Activity.RESULT_CANCELED, null);
|
||||||
setResult(Activity.RESULT_CANCELED, result);
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.cringe_studios.cringe_authenticator;
|
package com.cringe_studios.cringe_authenticator.scanner;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -8,6 +8,8 @@ import androidx.activity.result.contract.ActivityResultContract;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.cringe_studios.cringe_authenticator.OTPData;
|
||||||
|
|
||||||
public class QRScannerContract extends ActivityResultContract<Void, OTPData> {
|
public class QRScannerContract extends ActivityResultContract<Void, OTPData> {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -17,7 +19,7 @@ public class QRScannerContract extends ActivityResultContract<Void, OTPData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OTPData parseResult(int result, @Nullable Intent intent) {
|
public @Nullable OTPData parseResult(int result, @Nullable Intent intent) {
|
||||||
if(result != Activity.RESULT_OK || intent == null) {
|
if(result != Activity.RESULT_OK || intent == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
@ -2,6 +2,8 @@ package com.cringe_studios.cringe_authenticator.util;
|
|||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.cringe_studios.cringe_authenticator.OTPData;
|
import com.cringe_studios.cringe_authenticator.OTPData;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
@ -18,7 +20,7 @@ public class SettingsUtil {
|
|||||||
return Arrays.asList(GSON.fromJson(currentOTPs, OTPData[].class));
|
return Arrays.asList(GSON.fromJson(currentOTPs, OTPData[].class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addOTP(SharedPreferences prefs, String group, OTPData data) {
|
public static void addOTP(SharedPreferences prefs, String group, @NonNull OTPData data) {
|
||||||
List<OTPData> otps = new ArrayList<>(getOTPs(prefs, group));
|
List<OTPData> otps = new ArrayList<>(getOTPs(prefs, group));
|
||||||
otps.add(data);
|
otps.add(data);
|
||||||
|
|
||||||
|
@ -11,15 +11,15 @@
|
|||||||
android:padding="5dp"
|
android:padding="5dp"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/displayName"
|
android:id="@+id/label"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="My TOTP"
|
android:text="My OTP"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/totpCode"
|
android:id="@+id/otpCode"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="000000"
|
android:text="000000"
|
Loading…
Reference in New Issue
Block a user