mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-19 21:39:18 +00:00
Merge branch 'timer-timing'
This commit is contained in:
commit
555a0d673a
2 changed files with 26 additions and 30 deletions
|
@ -30,18 +30,8 @@ import me.impy.aegis.helpers.ItemClickListener;
|
||||||
public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.KeyProfileHolder> implements RVHAdapter {
|
public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.KeyProfileHolder> implements RVHAdapter {
|
||||||
private ArrayList<KeyProfile> mKeyProfiles;
|
private ArrayList<KeyProfile> mKeyProfiles;
|
||||||
private final List<KeyProfileHolder> lstHolders;
|
private final List<KeyProfileHolder> lstHolders;
|
||||||
|
private Timer timer;
|
||||||
private Handler mHandler = new Handler();
|
private Handler uiHandler;
|
||||||
private Runnable updateRemainingTimeRunnable = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
synchronized (lstHolders) {
|
|
||||||
for (KeyProfileHolder holder : lstHolders) {
|
|
||||||
holder.updateCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemMove(int fromPosition, int toPosition) {
|
public boolean onItemMove(int fromPosition, int toPosition) {
|
||||||
|
@ -54,7 +44,6 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
|
||||||
remove(position);
|
remove(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Helper functions you might want to implement to make changes in the list as an event is fired
|
// Helper functions you might want to implement to make changes in the list as an event is fired
|
||||||
private void remove(int position) {
|
private void remove(int position) {
|
||||||
mKeyProfiles.remove(position);
|
mKeyProfiles.remove(position);
|
||||||
|
@ -119,19 +108,8 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
|
||||||
public KeyProfileAdapter(ArrayList<KeyProfile> keyProfiles) {
|
public KeyProfileAdapter(ArrayList<KeyProfile> keyProfiles) {
|
||||||
mKeyProfiles = keyProfiles;
|
mKeyProfiles = keyProfiles;
|
||||||
lstHolders = new ArrayList<>();
|
lstHolders = new ArrayList<>();
|
||||||
|
timer = new Timer();
|
||||||
startUpdateTimer();
|
uiHandler = new Handler();
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
// 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)
|
// Replace the contents of a view (invoked by the layout manager)
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(KeyProfileHolder holder, int position) {
|
public void onBindViewHolder(final KeyProfileHolder holder, int position) {
|
||||||
holder.setData(mKeyProfiles.get(position));
|
holder.setData(mKeyProfiles.get(position));
|
||||||
synchronized (lstHolders) {
|
|
||||||
lstHolders.add(holder);
|
|
||||||
}
|
|
||||||
holder.updateCode();
|
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)
|
// Return the size of your dataset (invoked by the layout manager)
|
||||||
|
|
|
@ -43,6 +43,11 @@ public class KeyInfo implements Serializable {
|
||||||
|
|
||||||
private KeyInfo() { }
|
private KeyInfo() { }
|
||||||
|
|
||||||
|
public long getMillisTillNextRotation() {
|
||||||
|
long p = period * 1000;
|
||||||
|
return p - (System.currentTimeMillis() % p);
|
||||||
|
}
|
||||||
|
|
||||||
public static KeyInfo FromURL(String s) throws Exception {
|
public static KeyInfo FromURL(String s) throws Exception {
|
||||||
final Uri url = Uri.parse(s);
|
final Uri url = Uri.parse(s);
|
||||||
if (!url.getScheme().equals("otpauth")) {
|
if (!url.getScheme().equals("otpauth")) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue