mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-30 22:02:57 -08:00
Assign algorithm dynamically
This commit is contained in:
1 parent
7aeb51813c
commit
fbf3dec421
4 files changed
+22
-18
No files matched your search
@@ -27,7 +27,6 @@ import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.crypto.engine.CipherEngine;
|
||||
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
|
||||
import com.kunzisoft.keepass.database.exception.InvalidDBException;
|
||||
import com.kunzisoft.keepass.database.exception.InvalidPasswordException;
|
||||
@@ -226,17 +225,15 @@ public class Database {
|
||||
}
|
||||
|
||||
public void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException {
|
||||
|
||||
if (uri.getScheme().equals("file")) {
|
||||
String filename = uri.getPath();
|
||||
File tempFile = new File(filename + ".tmp");
|
||||
FileOutputStream fos = new FileOutputStream(tempFile);
|
||||
//BufferedOutputStream bos = new BufferedOutputStream(fos);
|
||||
|
||||
//PwDbV3Output pmo = new PwDbV3Output(pm, bos, App.getCalendar());
|
||||
PwDbOutput pmo = PwDbOutput.getInstance(pm, fos);
|
||||
pmo.output();
|
||||
//bos.flush();
|
||||
//bos.close();
|
||||
if (pmo != null)
|
||||
pmo.output();
|
||||
fos.close();
|
||||
|
||||
// Force data to disk before continuing
|
||||
@@ -253,16 +250,18 @@ public class Database {
|
||||
}
|
||||
}
|
||||
else {
|
||||
OutputStream os;
|
||||
OutputStream os = null;
|
||||
try {
|
||||
os = ctx.getContentResolver().openOutputStream(uri);
|
||||
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
|
||||
if (pmo != null)
|
||||
pmo.output();
|
||||
} catch (Exception e) {
|
||||
throw new IOException("Failed to store database.");
|
||||
} finally {
|
||||
if (os != null)
|
||||
os.close();
|
||||
}
|
||||
|
||||
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
|
||||
pmo.output();
|
||||
os.close();
|
||||
}
|
||||
mUri = uri;
|
||||
}
|
||||
|
||||
+3
-5
@@ -10,7 +10,6 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.database.PwEncryptionAlgorithm;
|
||||
@@ -21,7 +20,6 @@ import java.util.List;
|
||||
|
||||
public class DatabaseAlgorithmPreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat {
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private AlgorithmAdapter algorithmAdapter;
|
||||
private PwEncryptionAlgorithm algorithmSelected;
|
||||
|
||||
@@ -40,7 +38,7 @@ public class DatabaseAlgorithmPreferenceDialogFragmentCompat extends DatabaseSav
|
||||
protected void onBindDialogView(View view) {
|
||||
super.onBindDialogView(view);
|
||||
|
||||
recyclerView = view.findViewById(R.id.pref_dialog_list);
|
||||
RecyclerView recyclerView = view.findViewById(R.id.pref_dialog_list);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
algorithmAdapter = new AlgorithmAdapter();
|
||||
recyclerView.setAdapter(algorithmAdapter);
|
||||
@@ -61,7 +59,7 @@ public class DatabaseAlgorithmPreferenceDialogFragmentCompat extends DatabaseSav
|
||||
private List<PwEncryptionAlgorithm> algorithms;
|
||||
private PwEncryptionAlgorithm algorithmUsed;
|
||||
|
||||
public AlgorithmAdapter() {
|
||||
AlgorithmAdapter() {
|
||||
this.inflater = LayoutInflater.from(getContext());
|
||||
this.algorithms = new ArrayList<>();
|
||||
this.algorithmUsed = null;
|
||||
@@ -141,7 +139,7 @@ public class DatabaseAlgorithmPreferenceDialogFragmentCompat extends DatabaseSav
|
||||
if (getAlgorithmSelected() != null) {
|
||||
PwEncryptionAlgorithm newAlgorithm = getAlgorithmSelected();
|
||||
PwEncryptionAlgorithm oldAlgorithm = database.getEncryptionAlgorithm();
|
||||
database.assignDescription(newAlgorithm.getName(getResources()));
|
||||
database.assignEncryptionAlgorithm(newAlgorithm);
|
||||
|
||||
Handler handler = new Handler();
|
||||
setAfterSaveDatabase(new AfterDescriptionSave(getContext(), handler, newAlgorithm, oldAlgorithm));
|
||||
|
||||
+8
-2
@@ -25,7 +25,13 @@ public abstract class InputPreferenceDialogFragmentCompat extends PreferenceDial
|
||||
}
|
||||
|
||||
public void setExplanationText(String explanationText) {
|
||||
if (textExplanationView != null && explanationText != null)
|
||||
this.textExplanationView.setText(explanationText);
|
||||
if (textExplanationView != null)
|
||||
if (explanationText != null && !explanationText.isEmpty()) {
|
||||
textExplanationView.setText(explanationText);
|
||||
textExplanationView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
textExplanationView.setText(explanationText);
|
||||
textExplanationView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:visibility="gone"
|
||||
style="@style/KeepassDXStyle.TextAppearance.SmallTitle"/>
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/pref_dialog_list"
|
||||
|
||||
Reference in new issue
Block a user