mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-22 23:09:13 +00:00
Added timers to update
This commit is contained in:
parent
2cd0e2660e
commit
a8179865d6
2 changed files with 74 additions and 15 deletions
|
@ -1,5 +1,6 @@
|
||||||
package me.impy.aegis;
|
package me.impy.aegis;
|
||||||
|
|
||||||
|
import android.os.Handler;
|
||||||
import android.support.v7.widget.CardView;
|
import android.support.v7.widget.CardView;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -7,27 +8,79 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.security.Key;
|
import java.security.Key;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
import me.impy.aegis.crypto.OTP;
|
||||||
|
|
||||||
public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.KeyProfileHolder> {
|
public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.KeyProfileHolder> {
|
||||||
private ArrayList<KeyProfile> mKeyProfiles;
|
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 {
|
public static class KeyProfileHolder extends RecyclerView.ViewHolder {
|
||||||
TextView profileName;
|
TextView profileName;
|
||||||
TextView profileCode;
|
TextView profileCode;
|
||||||
|
KeyProfile keyProfile;
|
||||||
|
|
||||||
KeyProfileHolder(View itemView) {
|
KeyProfileHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
profileName = (TextView) itemView.findViewById(R.id.profile_name);
|
profileName = (TextView) itemView.findViewById(R.id.profile_name);
|
||||||
profileCode = (TextView) itemView.findViewById(R.id.profile_code);
|
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)
|
// Provide a suitable constructor (depends on the kind of dataset)
|
||||||
public KeyProfileAdapter(ArrayList<KeyProfile> keyProfiles) {
|
public KeyProfileAdapter(ArrayList<KeyProfile> keyProfiles) {
|
||||||
mKeyProfiles = 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)
|
// 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)
|
// Replace the contents of a view (invoked by the layout manager)
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(KeyProfileHolder holder, int position) {
|
public void onBindViewHolder(KeyProfileHolder holder, int position) {
|
||||||
holder.profileName.setText(mKeyProfiles.get(position).Name);
|
holder.setData(mKeyProfiles.get(position));
|
||||||
holder.profileCode.setText(mKeyProfiles.get(position).Code);
|
synchronized (lstHolders) {
|
||||||
|
lstHolders.add(holder);
|
||||||
|
}
|
||||||
|
holder.updateCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the size of your dataset (invoked by the layout manager)
|
// Return the size of your dataset (invoked by the layout manager)
|
||||||
|
|
|
@ -18,27 +18,30 @@
|
||||||
android:layout_alignWithParentIfMissing="false"
|
android:layout_alignWithParentIfMissing="false"
|
||||||
android:gravity="bottom"
|
android:gravity="bottom"
|
||||||
android:id="@+id/relativeLayout"
|
android:id="@+id/relativeLayout"
|
||||||
android:layout_alignParentStart="false"
|
android:layout_alignParentStart="false">
|
||||||
android:layout_alignEnd="@+id/imageView">
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/profile_name"
|
|
||||||
android:text="Post title"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:layout_alignStart="@+id/profile_code" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:text="Medium Text"
|
android:text="Medium Text"
|
||||||
android:id="@+id/profile_code"
|
android:id="@+id/profile_code"
|
||||||
android:layout_below="@+id/profile_name"
|
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_alignParentLeft="true"/>
|
android:layout_alignParentLeft="true"
|
||||||
|
android:textSize="36sp"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/profile_name"
|
||||||
|
android:text="Post title"
|
||||||
|
android:layout_below="@+id/profile_code"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentStart="true"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue