mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Clean up and fix a couple of bugs in the otp update process
This commit is contained in:
parent
181cdc4c2e
commit
49a31551a0
3 changed files with 36 additions and 21 deletions
|
@ -13,6 +13,7 @@ android {
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
debug {
|
debug {
|
||||||
|
minifyEnabled false
|
||||||
applicationIdSuffix ".debug"
|
applicationIdSuffix ".debug"
|
||||||
}
|
}
|
||||||
release {
|
release {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package me.impy.aegis;
|
package me.impy.aegis;
|
||||||
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -13,12 +12,10 @@ import me.impy.aegis.helpers.ItemTouchHelperAdapter;
|
||||||
|
|
||||||
public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileHolder> implements ItemTouchHelperAdapter {
|
public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileHolder> implements ItemTouchHelperAdapter {
|
||||||
private ArrayList<KeyProfile> _keyProfiles;
|
private ArrayList<KeyProfile> _keyProfiles;
|
||||||
private Handler _uiHandler;
|
|
||||||
private static Listener _listener;
|
private static Listener _listener;
|
||||||
|
|
||||||
public KeyProfileAdapter(Listener listener) {
|
public KeyProfileAdapter(Listener listener) {
|
||||||
_keyProfiles = new ArrayList<>();
|
_keyProfiles = new ArrayList<>();
|
||||||
_uiHandler = new Handler();
|
|
||||||
_listener = listener;
|
_listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +72,7 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileHolder> im
|
||||||
public void onBindViewHolder(final KeyProfileHolder holder, int position) {
|
public void onBindViewHolder(final KeyProfileHolder holder, int position) {
|
||||||
final KeyProfile profile = _keyProfiles.get(position);
|
final KeyProfile profile = _keyProfiles.get(position);
|
||||||
holder.setData(profile);
|
holder.setData(profile);
|
||||||
holder.updateCode();
|
holder.startUpdateLoop();
|
||||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -90,15 +87,6 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileHolder> im
|
||||||
return _listener.onLongKeyProfileClick(_keyProfiles.get(position));
|
return _listener.onLongKeyProfileClick(_keyProfiles.get(position));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_uiHandler.postDelayed(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (holder.updateCode()) {
|
|
||||||
_uiHandler.postDelayed(this, profile.getEntry().getInfo().getPeriod() * 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, profile.getEntry().getInfo().getMillisTillNextRotation());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,6 +2,7 @@ package me.impy.aegis;
|
||||||
|
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -22,6 +23,9 @@ public class KeyProfileHolder extends RecyclerView.ViewHolder {
|
||||||
private ProgressBar _progressBar;
|
private ProgressBar _progressBar;
|
||||||
private View _itemView;
|
private View _itemView;
|
||||||
|
|
||||||
|
private Handler _uiHandler;
|
||||||
|
private boolean _running = false;
|
||||||
|
|
||||||
KeyProfileHolder(final View itemView) {
|
KeyProfileHolder(final View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
_itemView = itemView;
|
_itemView = itemView;
|
||||||
|
@ -30,17 +34,17 @@ public class KeyProfileHolder extends RecyclerView.ViewHolder {
|
||||||
_profileIssuer = itemView.findViewById(R.id.profile_issuer);
|
_profileIssuer = itemView.findViewById(R.id.profile_issuer);
|
||||||
_profileDrawable = itemView.findViewById(R.id.ivTextDrawable);
|
_profileDrawable = itemView.findViewById(R.id.ivTextDrawable);
|
||||||
_progressBar = itemView.findViewById(R.id.progressBar);
|
_progressBar = itemView.findViewById(R.id.progressBar);
|
||||||
|
_uiHandler = new Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setData(KeyProfile profile) {
|
public void setData(KeyProfile profile) {
|
||||||
if ((_keyProfile = profile) == null) {
|
if ((_keyProfile = profile) == null) {
|
||||||
|
_running = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_profileName.setText(profile.getEntry().getName());
|
_profileName.setText(profile.getEntry().getName());
|
||||||
_profileCode.setText(profile.getCode());
|
_profileCode.setText(profile.getCode());
|
||||||
|
|
||||||
// So that we can have text in the designer without showing it to our user
|
|
||||||
_profileIssuer.setText("");
|
_profileIssuer.setText("");
|
||||||
|
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(_itemView.getContext());
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(_itemView.getContext());
|
||||||
|
@ -51,17 +55,39 @@ public class KeyProfileHolder extends RecyclerView.ViewHolder {
|
||||||
_profileDrawable.setImageDrawable(generateTextDrawable(profile));
|
_profileDrawable.setImageDrawable(generateTextDrawable(profile));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateCode() {
|
public void startUpdateLoop() {
|
||||||
_progressBar.setProgress(1000);
|
if (_running) {
|
||||||
if (_keyProfile == null) {
|
return;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
_running = true;
|
||||||
|
|
||||||
|
updateCode();
|
||||||
|
_uiHandler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (_running) {
|
||||||
|
updateCode();
|
||||||
|
_uiHandler.postDelayed(this, _keyProfile.getEntry().getInfo().getMillisTillNextRotation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, _keyProfile.getEntry().getInfo().getMillisTillNextRotation());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean updateCode() {
|
||||||
|
// reset the progress bar
|
||||||
|
int maxProgress = _progressBar.getMax();
|
||||||
|
_progressBar.setProgress(maxProgress);
|
||||||
|
|
||||||
|
// refresh the code
|
||||||
String otp = _keyProfile.refreshCode();
|
String otp = _keyProfile.refreshCode();
|
||||||
_profileCode.setText(otp.substring(0, 3) + " " + otp.substring(3));
|
_profileCode.setText(otp.substring(0, 3) + " " + otp.substring(3));
|
||||||
|
|
||||||
|
// calculate the progress the bar should start at
|
||||||
long millisTillRotation = _keyProfile.getEntry().getInfo().getMillisTillNextRotation();
|
long millisTillRotation = _keyProfile.getEntry().getInfo().getMillisTillNextRotation();
|
||||||
long period = _keyProfile.getEntry().getInfo().getPeriod() * 1000;
|
long period = _keyProfile.getEntry().getInfo().getPeriod() * maxProgress;
|
||||||
int currentProgress = 1000 - (int) ((((double) period - millisTillRotation) / period) * 1000);
|
int currentProgress = maxProgress - (int) ((((double) period - millisTillRotation) / period) * maxProgress);
|
||||||
|
|
||||||
|
// start progress animation
|
||||||
ObjectAnimator animation = ObjectAnimator.ofInt(_progressBar, "progress", currentProgress, 0);
|
ObjectAnimator animation = ObjectAnimator.ofInt(_progressBar, "progress", currentProgress, 0);
|
||||||
animation.setDuration(millisTillRotation);
|
animation.setDuration(millisTillRotation);
|
||||||
animation.setInterpolator(new LinearInterpolator());
|
animation.setInterpolator(new LinearInterpolator());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue