Search in sources :

Example 11 with Entry

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;
}
Also used : Entry(org.shadowice.flocke.andotp.Database.Entry) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) NonNull(android.support.annotation.NonNull)

Example 12 with Entry

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());
}
Also used : Entry(org.shadowice.flocke.andotp.Database.Entry)

Example 13 with Entry

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);
}
Also used : Entry(org.shadowice.flocke.andotp.Database.Entry) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable)

Example 14 with Entry

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);
    }
}
Also used : SecretKey(javax.crypto.SecretKey) Entry(org.shadowice.flocke.andotp.Database.Entry) Uri(android.net.Uri) Settings(org.shadowice.flocke.andotp.Utilities.Settings)

Example 15 with Entry

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;
}
Also used : Entry(org.shadowice.flocke.andotp.Database.Entry) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) IOException(java.io.IOException)

Aggregations

Entry (org.shadowice.flocke.andotp.Database.Entry)19 ArrayList (java.util.ArrayList)5 SecretKey (javax.crypto.SecretKey)5 AlertDialog (android.app.AlertDialog)4 DialogInterface (android.content.DialogInterface)4 EditText (android.widget.EditText)4 View (android.view.View)3 AdapterView (android.widget.AdapterView)3 FrameLayout (android.widget.FrameLayout)3 IOException (java.io.IOException)3 Uri (android.net.Uri)2 RecyclerView (android.support.v7.widget.RecyclerView)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 ViewGroup (android.view.ViewGroup)2 GridView (android.widget.GridView)2 LinearLayout (android.widget.LinearLayout)2 File (java.io.File)2 HashMap (java.util.HashMap)2 Callable (java.util.concurrent.Callable)2