Get rid of the code change listener to fix the serializability of KeyProfile

This commit is contained in:
Alexander Bakker 2018-02-13 19:42:04 +01:00
parent 6e68d79816
commit 6672c18399
3 changed files with 7 additions and 19 deletions

View file

@ -13,7 +13,6 @@ import me.impy.aegis.helpers.TextDrawableHelper;
public class KeyProfile implements Serializable {
private String _code;
private DatabaseEntry _entry;
private Listener _listener;
public KeyProfile() {
this(new DatabaseEntry());
@ -23,10 +22,6 @@ public class KeyProfile implements Serializable {
_entry = entry;
}
public void setListener(Listener listener) {
_listener = listener;
}
public DatabaseEntry getEntry() {
return _entry;
}
@ -40,17 +35,10 @@ public class KeyProfile implements Serializable {
} catch (Exception e) {
throw new UndeclaredThrowableException(e);
}
if (_listener != null) {
_listener.onRefreshCode(_code);
}
return _code;
}
public TextDrawable getDrawable() {
return TextDrawableHelper.generate(getEntry().getName());
}
public interface Listener {
void onRefreshCode(String code);
}
}

View file

@ -58,6 +58,7 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileHolder> im
for (KeyProfile profile : _keyProfiles) {
profile.refreshCode();
}
notifyDataSetChanged();
}
private KeyProfile getKeyByID(long id) {

View file

@ -11,7 +11,7 @@ import android.widget.TextView;
import com.amulyakhare.textdrawable.TextDrawable;
public class KeyProfileHolder extends RecyclerView.ViewHolder implements KeyProfile.Listener {
public class KeyProfileHolder extends RecyclerView.ViewHolder {
private TextView _profileName;
private TextView _profileCode;
private TextView _profileIssuer;
@ -34,14 +34,12 @@ public class KeyProfileHolder extends RecyclerView.ViewHolder implements KeyProf
public void setData(KeyProfile profile, boolean showIssuer) {
if (profile == null) {
_profile.setListener(null);
_profile = null;
_running = false;
return;
}
_profile = profile;
profile.setListener(this);
_profileName.setText(profile.getEntry().getName());
_profileCode.setText(profile.getCode());
_profileIssuer.setText("");
@ -59,20 +57,21 @@ public class KeyProfileHolder extends RecyclerView.ViewHolder implements KeyProf
}
_running = true;
_profile.refreshCode();
refreshCode();
_uiHandler.postDelayed(new Runnable() {
@Override
public void run() {
if (_running) {
_profile.refreshCode();
refreshCode();
_uiHandler.postDelayed(this, _profile.getEntry().getInfo().getMillisTillNextRotation());
}
}
}, _profile.getEntry().getInfo().getMillisTillNextRotation());
}
@Override
public void onRefreshCode(String otp) {
public void refreshCode() {
String otp = _profile.refreshCode();
// reset the progress bar
int maxProgress = _progressBar.getMax();
_progressBar.setProgress(maxProgress);