use of org.shadowice.flocke.andotp.Database.Entry in project andOTP by andOTP.
the class EntriesCardAdapter method onCreateViewHolder.
@Override
@NonNull
public EntryViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.component_card, viewGroup, false);
EntryViewHolder viewHolder = new EntryViewHolder(context, itemView, settings.getTapToReveal());
viewHolder.setCallback(new EntryViewHolder.Callback() {
@Override
public void onMoveEventStart() {
if (callback != null)
callback.onMoveEventStart();
}
@Override
public void onMoveEventStop() {
if (callback != null)
callback.onMoveEventStop();
}
@Override
public void onMenuButtonClicked(View parentView, int position) {
showPopupMenu(parentView, position);
}
@Override
public void onCopyButtonClicked(String text, int position) {
copyToClipboard(text);
updateLastUsed(position, getRealIndex(position));
}
@Override
public void onTap(final int position) {
if (settings.getTapToReveal()) {
final Entry entry = displayedEntries.get(position);
final int realIndex = entries.indexOf(entry);
if (entry.isVisible()) {
hideEntry(entry);
} else {
entries.get(realIndex).setHideTask(new Runnable() {
@Override
public void run() {
hideEntry(entry);
}
});
taskHandler.postDelayed(entries.get(realIndex).getHideTask(), settings.getTapToRevealTimeout() * 1000);
entry.setVisible(true);
notifyItemChanged(position);
}
}
}
@Override
public void onCounterTapped(int position) {
Entry entry = displayedEntries.get(position);
Entry realEntry = entries.get(getRealIndex(position));
long counter = entry.getCounter() + 1;
entry.setCounter(counter);
entry.updateOTP();
notifyItemChanged(position);
realEntry.setCounter(counter);
realEntry.updateOTP();
DatabaseHelper.saveDatabase(context, entries, encryptionKey);
}
@Override
public void onCounterLongPressed(int position) {
setCounter(position);
}
});
return viewHolder;
}
use of org.shadowice.flocke.andotp.Database.Entry in project andOTP by andOTP.
the class EntriesCardAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull EntryViewHolder entryViewHolder, int i) {
Entry entry = displayedEntries.get(i);
entryViewHolder.updateValues(entry);
if (entry.getType() == Entry.OTPType.TOTP || entry.getType() == Entry.OTPType.STEAM) {
if (entry.hasNonDefaultPeriod())
entryViewHolder.showCustomPeriod(entry.getPeriod());
else
entryViewHolder.hideCustomPeriod();
}
entryViewHolder.setLabelSize(settings.getLabelSize());
if (settings.getThumbnailVisible()) {
entryViewHolder.setThumbnailSize(settings.getThumbnailSize());
}
entryViewHolder.setLabelScroll(settings.getScrollLabel());
}
use of org.shadowice.flocke.andotp.Database.Entry in project andOTP by andOTP.
the class EntriesCardAdapter method editEntryTags.
public void editEntryTags(final int pos) {
final int realPos = getRealIndex(pos);
final Entry entry = entries.get(realPos);
HashMap<String, Boolean> tagsHashMap = new HashMap<>();
for (String tag : entry.getTags()) {
tagsHashMap.put(tag, true);
}
for (String tag : getTags()) {
if (!tagsHashMap.containsKey(tag))
tagsHashMap.put(tag, false);
}
final TagsAdapter tagsAdapter = new TagsAdapter(context, tagsHashMap);
final Callable tagsCallable = new Callable() {
@Override
public Object call() throws Exception {
entries.get(realPos).setTags(tagsAdapter.getActiveTags());
DatabaseHelper.saveDatabase(context, entries, encryptionKey);
List<String> inUseTags = getTags();
HashMap<String, Boolean> tagsHashMap = new HashMap<>();
for (String tag : tagsFilterAdapter.getTags()) {
if (inUseTags.contains(tag))
tagsHashMap.put(tag, false);
}
for (String tag : tagsFilterAdapter.getActiveTags()) {
if (inUseTags.contains(tag))
tagsHashMap.put(tag, true);
}
for (String tag : getTags()) {
if (inUseTags.contains(tag))
if (!tagsHashMap.containsKey(tag))
tagsHashMap.put(tag, true);
}
tagsFilterAdapter.setTags(tagsHashMap);
filterByTags(tagsFilterAdapter.getActiveTags());
return null;
}
};
TagsDialog.show(context, tagsAdapter, tagsCallable, tagsCallable);
}
use of org.shadowice.flocke.andotp.Database.Entry in project andOTP by andOTP.
the class EncryptedBackupBroadcastReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
Settings settings = new Settings(context);
if (settings.isEncryptedBackupBroadcastEnabled()) {
if (!canSaveBackup(context))
return;
Uri savePath = Tools.buildUri(settings.getBackupDir(), FileHelper.backupFilename(context, Constants.BackupType.ENCRYPTED));
String password = settings.getBackupPasswordEnc();
if (password.isEmpty()) {
NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_toast_crypt_password_not_set);
return;
}
SecretKey encryptionKey = null;
if (settings.getEncryption() == Constants.EncryptionType.KEYSTORE) {
encryptionKey = KeyStoreHelper.loadEncryptionKeyFromKeyStore(context, false);
} else {
NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_receiver_custom_encryption_failed);
return;
}
if (Tools.isExternalStorageWritable()) {
ArrayList<Entry> entries = DatabaseHelper.loadDatabase(context, encryptionKey);
String plain = DatabaseHelper.entriesToString(entries);
try {
SecretKey key = EncryptionHelper.generateSymmetricKeyFromPassword(password);
byte[] encrypted = EncryptionHelper.encrypt(key, plain.getBytes(StandardCharsets.UTF_8));
FileHelper.writeBytesToFile(context, savePath, encrypted);
NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_SUCCESS, R.string.backup_receiver_title_backup_success, savePath.getPath());
} catch (Exception e) {
e.printStackTrace();
NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_toast_export_failed);
}
} else {
NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_toast_storage_not_accessible);
}
} else {
NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_receiver_encrypted_disabled);
}
}
use of org.shadowice.flocke.andotp.Database.Entry in project andOTP by andOTP.
the class DatabaseHelper method stringToEntries.
public static ArrayList<Entry> stringToEntries(String data) {
ArrayList<Entry> entries = new ArrayList<>();
try {
JSONArray json = new JSONArray(data);
for (int i = 0; i < json.length(); i++) {
Entry entry = new Entry(json.getJSONObject(i));
entries.add(entry);
}
} catch (Exception error) {
error.printStackTrace();
}
return entries;
}
Aggregations