Fix code loading, Fix OTP move
This commit is contained in:
parent
658c0eab7d
commit
d589025de9
@ -159,7 +159,10 @@ public class MainActivity extends BaseActivity {
|
|||||||
if(fragment instanceof GroupFragment) {
|
if(fragment instanceof GroupFragment) {
|
||||||
GroupFragment frag = (GroupFragment) fragment;
|
GroupFragment frag = (GroupFragment) fragment;
|
||||||
getMenuInflater().inflate(frag.isEditing() ? R.menu.menu_otps_edit : R.menu.menu_otps, menu);
|
getMenuInflater().inflate(frag.isEditing() ? R.menu.menu_otps_edit : R.menu.menu_otps, menu);
|
||||||
if(frag.isEditing() && frag.hasSelectedMultipleItems()) menu.removeItem(R.id.action_edit_otp);
|
if(frag.isEditing() && frag.hasSelectedMultipleItems()) {
|
||||||
|
menu.removeItem(R.id.action_view_otp);
|
||||||
|
menu.removeItem(R.id.action_edit_otp);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public class GroupFragment extends NamedFragment {
|
|||||||
|
|
||||||
groupID = requireArguments().getString(GroupFragment.BUNDLE_GROUP);
|
groupID = requireArguments().getString(GroupFragment.BUNDLE_GROUP);
|
||||||
|
|
||||||
otpListAdapter = new OTPListAdapter(requireContext(), binding.itemList);
|
otpListAdapter = new OTPListAdapter(requireContext(), binding.itemList, this::saveOTPs);
|
||||||
binding.itemList.setAdapter(otpListAdapter);
|
binding.itemList.setAdapter(otpListAdapter);
|
||||||
|
|
||||||
loadOTPs();
|
loadOTPs();
|
||||||
@ -67,7 +67,7 @@ public class GroupFragment extends NamedFragment {
|
|||||||
handler.postDelayed(refreshCodes, 1000L);
|
handler.postDelayed(refreshCodes, 1000L);
|
||||||
};
|
};
|
||||||
|
|
||||||
handler.post(refreshCodes);
|
handler.postDelayed(refreshCodes, 1000L);
|
||||||
|
|
||||||
return binding.getRoot();
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
@ -124,11 +124,6 @@ public class GroupFragment extends NamedFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addOTP() {
|
|
||||||
// TODO
|
|
||||||
requireActivity().openOptionsMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void viewOTP() {
|
public void viewOTP() {
|
||||||
if(!otpListAdapter.isEditing()) return;
|
if(!otpListAdapter.isEditing()) return;
|
||||||
|
|
||||||
|
@ -38,14 +38,19 @@ public class OTPListAdapter extends RecyclerView.Adapter<OTPListItem> {
|
|||||||
|
|
||||||
private Handler handler;
|
private Handler handler;
|
||||||
|
|
||||||
|
private Runnable saveOTPs;
|
||||||
|
|
||||||
private boolean editing;
|
private boolean editing;
|
||||||
|
|
||||||
public OTPListAdapter(Context context, RecyclerView recyclerView) {
|
public OTPListAdapter(Context context, RecyclerView recyclerView, Runnable saveOTPs) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.recyclerView = recyclerView;
|
this.recyclerView = recyclerView;
|
||||||
this.inflater = LayoutInflater.from(context);
|
this.inflater = LayoutInflater.from(context);
|
||||||
this.items = new ArrayList<>();
|
this.items = new ArrayList<>();
|
||||||
this.handler = new Handler(Looper.getMainLooper());
|
this.handler = new Handler(Looper.getMainLooper());
|
||||||
|
this.saveOTPs = saveOTPs;
|
||||||
|
|
||||||
|
attachTouchHelper(recyclerView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -62,6 +67,12 @@ public class OTPListAdapter extends RecyclerView.Adapter<OTPListItem> {
|
|||||||
holder.setOTPData(data);
|
holder.setOTPData(data);
|
||||||
holder.setSelected(false);
|
holder.setSelected(false);
|
||||||
|
|
||||||
|
try {
|
||||||
|
holder.getBinding().otpCode.setText(OTPListItem.formatCode(data.getPin()));
|
||||||
|
} catch (OTPException e) {
|
||||||
|
DialogUtil.showErrorDialog(context, context.getString(R.string.otp_add_error, e.getMessage() != null ? e.getMessage() : e.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
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.INVISIBLE);
|
holder.getBinding().progress.setVisibility(data.getType() == OTPType.TOTP ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
|
||||||
@ -172,7 +183,7 @@ public class OTPListAdapter extends RecyclerView.Adapter<OTPListItem> {
|
|||||||
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
|
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
|
||||||
Collections.swap(items, viewHolder.getAdapterPosition(), target.getAdapterPosition());
|
Collections.swap(items, viewHolder.getAdapterPosition(), target.getAdapterPosition());
|
||||||
notifyItemMoved(viewHolder.getAdapterPosition(), target.getAdapterPosition());
|
notifyItemMoved(viewHolder.getAdapterPosition(), target.getAdapterPosition());
|
||||||
//saveGroups.run();
|
saveOTPs.run();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user