|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package me.impy.aegis;
|
|
|
|
|
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.support.v7.widget.CardView;
|
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
@ -7,27 +8,79 @@ import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import java.security.Key;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Timer;
|
|
|
|
|
import java.util.TimerTask;
|
|
|
|
|
|
|
|
|
|
public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.KeyProfileHolder> {
|
|
|
|
|
import me.impy.aegis.crypto.OTP;
|
|
|
|
|
|
|
|
|
|
public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.KeyProfileHolder> {
|
|
|
|
|
private ArrayList<KeyProfile> mKeyProfiles;
|
|
|
|
|
private final List<KeyProfileHolder> lstHolders;
|
|
|
|
|
|
|
|
|
|
private Handler mHandler = new Handler();
|
|
|
|
|
private Runnable updateRemainingTimeRunnable = new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
synchronized (lstHolders) {
|
|
|
|
|
for (KeyProfileHolder holder : lstHolders) {
|
|
|
|
|
holder.updateCode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static class KeyProfileHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
TextView profileName;
|
|
|
|
|
TextView profileCode;
|
|
|
|
|
KeyProfile keyProfile;
|
|
|
|
|
|
|
|
|
|
KeyProfileHolder(View itemView) {
|
|
|
|
|
super(itemView);
|
|
|
|
|
profileName = (TextView) itemView.findViewById(R.id.profile_name);
|
|
|
|
|
profileCode = (TextView) itemView.findViewById(R.id.profile_code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setData(KeyProfile profile) {
|
|
|
|
|
this.keyProfile = profile;
|
|
|
|
|
profileName.setText(profile.Name);
|
|
|
|
|
profileCode.setText(profile.Code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateCode() {
|
|
|
|
|
if (this.keyProfile == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String otp = "";
|
|
|
|
|
try {
|
|
|
|
|
otp = OTP.generateOTP(this.keyProfile.KeyInfo);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
profileCode.setText(otp.substring(0, 3) + " " + otp.substring(3));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Provide a suitable constructor (depends on the kind of dataset)
|
|
|
|
|
public KeyProfileAdapter(ArrayList<KeyProfile> keyProfiles) {
|
|
|
|
|
mKeyProfiles = keyProfiles;
|
|
|
|
|
lstHolders = new ArrayList<>();
|
|
|
|
|
startUpdateTimer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void startUpdateTimer() {
|
|
|
|
|
Timer timer = new Timer();
|
|
|
|
|
timer.schedule(new TimerTask() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
mHandler.post(updateRemainingTimeRunnable);
|
|
|
|
|
}
|
|
|
|
|
//TODO: Replace delay with seconds that are left
|
|
|
|
|
}, 0, 5000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create new views (invoked by the layout manager)
|
|
|
|
@ -44,8 +97,11 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
|
|
|
|
|
// Replace the contents of a view (invoked by the layout manager)
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindViewHolder(KeyProfileHolder holder, int position) {
|
|
|
|
|
holder.profileName.setText(mKeyProfiles.get(position).Name);
|
|
|
|
|
holder.profileCode.setText(mKeyProfiles.get(position).Code);
|
|
|
|
|
holder.setData(mKeyProfiles.get(position));
|
|
|
|
|
synchronized (lstHolders) {
|
|
|
|
|
lstHolders.add(holder);
|
|
|
|
|
}
|
|
|
|
|
holder.updateCode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return the size of your dataset (invoked by the layout manager)
|
|
|
|
|