Merge branch 'timer-timing'

pull/41/head
Impyy 9 years ago
commit 555a0d673a

@ -30,18 +30,8 @@ import me.impy.aegis.helpers.ItemClickListener;
public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.KeyProfileHolder> implements RVHAdapter {
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();
}
}
}
};
private Timer timer;
private Handler uiHandler;
@Override
public boolean onItemMove(int fromPosition, int toPosition) {
@ -54,7 +44,6 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
remove(position);
}
// Helper functions you might want to implement to make changes in the list as an event is fired
private void remove(int position) {
mKeyProfiles.remove(position);
@ -119,19 +108,8 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
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);
timer = new Timer();
uiHandler = new Handler();
}
// Create new views (invoked by the layout manager)
@ -147,12 +125,25 @@ 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) {
public void onBindViewHolder(final KeyProfileHolder holder, int position) {
holder.setData(mKeyProfiles.get(position));
synchronized (lstHolders) {
lstHolders.add(holder);
}
holder.updateCode();
lstHolders.add(holder);
timer.schedule(new TimerTask() {
@Override
public void run() {
uiHandler.post(new Runnable() {
@Override
public void run() {
// check if this key profile still exists
if (lstHolders.contains(holder)) {
holder.updateCode();
}
}
});
}
}, holder.keyProfile.KeyInfo.getMillisTillNextRotation(), holder.keyProfile.KeyInfo.getPeriod() * 1000);
}
// Return the size of your dataset (invoked by the layout manager)

@ -43,6 +43,11 @@ public class KeyInfo implements Serializable {
private KeyInfo() { }
public long getMillisTillNextRotation() {
long p = period * 1000;
return p - (System.currentTimeMillis() % p);
}
public static KeyInfo FromURL(String s) throws Exception {
final Uri url = Uri.parse(s);
if (!url.getScheme().equals("otpauth")) {

Loading…
Cancel
Save