@ -14,7 +14,6 @@ import androidx.recyclerview.widget.RecyclerView;
import com.amulyakhare.textdrawable.TextDrawable ;
import com.amulyakhare.textdrawable.TextDrawable ;
import com.beemdevelopment.aegis.R ;
import com.beemdevelopment.aegis.R ;
import com.beemdevelopment.aegis.vault.VaultEntry ;
import com.beemdevelopment.aegis.helpers.TextDrawableHelper ;
import com.beemdevelopment.aegis.helpers.TextDrawableHelper ;
import com.beemdevelopment.aegis.helpers.ThemeHelper ;
import com.beemdevelopment.aegis.helpers.ThemeHelper ;
import com.beemdevelopment.aegis.helpers.UiRefresher ;
import com.beemdevelopment.aegis.helpers.UiRefresher ;
@ -22,6 +21,7 @@ import com.beemdevelopment.aegis.otp.HotpInfo;
import com.beemdevelopment.aegis.otp.OtpInfo ;
import com.beemdevelopment.aegis.otp.OtpInfo ;
import com.beemdevelopment.aegis.otp.SteamInfo ;
import com.beemdevelopment.aegis.otp.SteamInfo ;
import com.beemdevelopment.aegis.otp.TotpInfo ;
import com.beemdevelopment.aegis.otp.TotpInfo ;
import com.beemdevelopment.aegis.vault.VaultEntry ;
import com.bumptech.glide.Glide ;
import com.bumptech.glide.Glide ;
import com.bumptech.glide.load.engine.DiskCacheStrategy ;
import com.bumptech.glide.load.engine.DiskCacheStrategy ;
@ -37,6 +37,9 @@ public class EntryHolder extends RecyclerView.ViewHolder {
private VaultEntry _entry ;
private VaultEntry _entry ;
private ImageView _buttonRefresh ;
private ImageView _buttonRefresh ;
private RelativeLayout _description ;
private RelativeLayout _description ;
private final ImageView _selected ;
private final Handler _selectedHandler ;
private boolean _hidden ;
private boolean _hidden ;
@ -46,6 +49,9 @@ public class EntryHolder extends RecyclerView.ViewHolder {
private UiRefresher _refresher ;
private UiRefresher _refresher ;
private Handler _animationHandler ;
private Handler _animationHandler ;
private Animation _scaleIn ;
private Animation _scaleOut ;
public EntryHolder ( final View view ) {
public EntryHolder ( final View view ) {
super ( view ) ;
super ( view ) ;
@ -58,12 +64,17 @@ public class EntryHolder extends RecyclerView.ViewHolder {
_description = view . findViewById ( R . id . description ) ;
_description = view . findViewById ( R . id . description ) ;
_profileDrawable = view . findViewById ( R . id . ivTextDrawable ) ;
_profileDrawable = view . findViewById ( R . id . ivTextDrawable ) ;
_buttonRefresh = view . findViewById ( R . id . buttonRefresh ) ;
_buttonRefresh = view . findViewById ( R . id . buttonRefresh ) ;
_selected = view . findViewById ( R . id . ivSelected ) ;
_selectedHandler = new Handler ( ) ;
_progressBar = view . findViewById ( R . id . progressBar ) ;
_progressBar = view . findViewById ( R . id . progressBar ) ;
int primaryColorId = view . getContext ( ) . getResources ( ) . getColor ( R . color . colorPrimary ) ;
int primaryColorId = view . getContext ( ) . getResources ( ) . getColor ( R . color . colorPrimary ) ;
_progressBar . getProgressDrawable ( ) . setColorFilter ( primaryColorId , PorterDuff . Mode . SRC_IN ) ;
_progressBar . getProgressDrawable ( ) . setColorFilter ( primaryColorId , PorterDuff . Mode . SRC_IN ) ;
_view . setBackground ( _view . getContext ( ) . getResources ( ) . getDrawable ( R . color . card_background ) ) ;
_view . setBackground ( _view . getContext ( ) . getResources ( ) . getDrawable ( R . color . card_background ) ) ;
_scaleIn = AnimationUtils . loadAnimation ( view . getContext ( ) , R . anim . item_scale_in ) ;
_scaleOut = AnimationUtils . loadAnimation ( view . getContext ( ) , R . anim . item_scale_out ) ;
_refresher = new UiRefresher ( new UiRefresher . Listener ( ) {
_refresher = new UiRefresher ( new UiRefresher . Listener ( ) {
@Override
@Override
public void onRefresh ( ) {
public void onRefresh ( ) {
@ -76,7 +87,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
@Override
@Override
public long getMillisTillNextRefresh ( ) {
public long getMillisTillNextRefresh ( ) {
return ( ( TotpInfo ) _entry . getInfo ( ) ) . getMillisTillNextRotation ( ) ;
return ( ( TotpInfo ) _entry . getInfo ( ) ) . getMillisTillNextRotation ( ) ;
}
}
} ) ;
} ) ;
}
}
@ -85,6 +96,10 @@ public class EntryHolder extends RecyclerView.ViewHolder {
_entry = entry ;
_entry = entry ;
_hidden = hidden ;
_hidden = hidden ;
_selected . clearAnimation ( ) ;
_selected . setVisibility ( View . GONE ) ;
_selectedHandler . removeCallbacksAndMessages ( null ) ;
// only show the progress bar if there is no uniform period and the entry type is TotpInfo
// only show the progress bar if there is no uniform period and the entry type is TotpInfo
setShowProgress ( showProgress ) ;
setShowProgress ( showProgress ) ;
@ -148,6 +163,7 @@ public class EntryHolder extends RecyclerView.ViewHolder {
public void setFocused ( boolean focused ) {
public void setFocused ( boolean focused ) {
if ( focused ) {
if ( focused ) {
_selected . setVisibility ( View . VISIBLE ) ;
_view . setBackgroundColor ( ThemeHelper . getThemeColor ( R . attr . cardBackgroundFocused , _view . getContext ( ) . getTheme ( ) ) ) ;
_view . setBackgroundColor ( ThemeHelper . getThemeColor ( R . attr . cardBackgroundFocused , _view . getContext ( ) . getTheme ( ) ) ) ;
} else {
} else {
_view . setBackgroundColor ( ThemeHelper . getThemeColor ( R . attr . cardBackground , _view . getContext ( ) . getTheme ( ) ) ) ;
_view . setBackgroundColor ( ThemeHelper . getThemeColor ( R . attr . cardBackground , _view . getContext ( ) . getTheme ( ) ) ) ;
@ -155,6 +171,17 @@ public class EntryHolder extends RecyclerView.ViewHolder {
_view . setSelected ( focused ) ;
_view . setSelected ( focused ) ;
}
}
public void setFocusedAndAnimate ( boolean focused ) {
setFocused ( focused ) ;
if ( focused ) {
_selected . startAnimation ( _scaleIn ) ;
} else {
_selected . startAnimation ( _scaleOut ) ;
_selectedHandler . postDelayed ( ( ) - > _selected . setVisibility ( View . GONE ) , 150 ) ;
}
}
public void destroy ( ) {
public void destroy ( ) {
_refresher . destroy ( ) ;
_refresher . destroy ( ) ;
}
}