mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 22:12:55 +00:00
Order is now getting saved properly
Also enabled Java 8
This commit is contained in:
parent
036dd2b2cb
commit
22524136a7
7 changed files with 106 additions and 25 deletions
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -37,7 +37,7 @@
|
||||||
<ConfirmationsSetting value="0" id="Add" />
|
<ConfirmationsSetting value="0" id="Add" />
|
||||||
<ConfirmationsSetting value="0" id="Remove" />
|
<ConfirmationsSetting value="0" id="Remove" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|
|
@ -10,6 +10,9 @@ android {
|
||||||
targetSdkVersion 24
|
targetSdkVersion 24
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
|
jackOptions {
|
||||||
|
enabled true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
@ -17,6 +20,10 @@ android {
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
compileOptions {
|
||||||
|
targetCompatibility 1.8
|
||||||
|
sourceCompatibility 1.8
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package me.impy.aegis;
|
package me.impy.aegis;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.security.Key;
|
||||||
|
|
||||||
import me.impy.aegis.crypto.KeyInfo;
|
import me.impy.aegis.crypto.KeyInfo;
|
||||||
|
|
||||||
|
@ -9,5 +10,15 @@ public class KeyProfile implements Serializable {
|
||||||
public String Icon;
|
public String Icon;
|
||||||
public String Code;
|
public String Code;
|
||||||
public KeyInfo Info;
|
public KeyInfo Info;
|
||||||
|
public int Order;
|
||||||
public int ID;
|
public int ID;
|
||||||
|
|
||||||
|
|
||||||
|
public int compareTo(KeyProfile another) {
|
||||||
|
if (this.Order>another.Order){
|
||||||
|
return -1;
|
||||||
|
}else{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package me.impy.aegis;
|
||||||
|
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -16,11 +17,13 @@ import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
import me.impy.aegis.crypto.OTP;
|
import me.impy.aegis.crypto.OTP;
|
||||||
|
import me.impy.aegis.db.Database;
|
||||||
import me.impy.aegis.helpers.ItemTouchHelperAdapter;
|
import me.impy.aegis.helpers.ItemTouchHelperAdapter;
|
||||||
|
|
||||||
public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.KeyProfileHolder> implements ItemTouchHelperAdapter {
|
public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.KeyProfileHolder> implements ItemTouchHelperAdapter {
|
||||||
|
@ -52,28 +55,46 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
|
||||||
public void onItemMove(int firstPosition, int secondPosition) {
|
public void onItemMove(int firstPosition, int secondPosition) {
|
||||||
Collections.swap(mKeyProfiles, firstPosition, secondPosition);
|
Collections.swap(mKeyProfiles, firstPosition, secondPosition);
|
||||||
notifyItemMoved(firstPosition, secondPosition);
|
notifyItemMoved(firstPosition, secondPosition);
|
||||||
|
|
||||||
|
mKeyProfiles.get(firstPosition).Order = secondPosition;
|
||||||
|
adjustOrder(secondPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void adjustOrder(int startPosition)
|
||||||
|
{
|
||||||
|
Comparator<KeyProfile> comparator = new Comparator<KeyProfile>() {
|
||||||
|
@Override
|
||||||
|
public int compare(KeyProfile keyProfile, KeyProfile t1) {
|
||||||
|
return keyProfile.Order - t1.Order;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for(int i = startPosition; i < mKeyProfiles.size(); i++)
|
||||||
|
{
|
||||||
|
mKeyProfiles.get(i).Order = i + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new views (invoked by the layout manager)
|
// Create new views (invoked by the layout manager)
|
||||||
@Override
|
|
||||||
public KeyProfileHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
||||||
// create a new view
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_keyprofile, parent, false);
|
|
||||||
// set the view's size, margins, paddings and layout parameters
|
|
||||||
|
|
||||||
KeyProfileHolder vh = new KeyProfileHolder(v);
|
|
||||||
return vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replace the contents of a view (invoked by the layout manager)
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(final KeyProfileHolder holder, int position) {
|
|
||||||
holder.setData(mKeyProfiles.get(position));
|
|
||||||
holder.updateCode();
|
|
||||||
lstHolders.add(holder);
|
|
||||||
|
|
||||||
timer.schedule(new TimerTask() {
|
|
||||||
@Override
|
@Override
|
||||||
|
public KeyProfileHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
// create a new view
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_keyprofile, parent, false);
|
||||||
|
// set the view's size, margins, paddings and layout parameters
|
||||||
|
|
||||||
|
KeyProfileHolder vh = new KeyProfileHolder(v);
|
||||||
|
return vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace the contents of a view (invoked by the layout manager)
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(final KeyProfileHolder holder, int position) {
|
||||||
|
holder.setData(mKeyProfiles.get(position));
|
||||||
|
holder.updateCode();
|
||||||
|
lstHolders.add(holder);
|
||||||
|
|
||||||
|
timer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
uiHandler.post(new Runnable() {
|
uiHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -23,6 +23,8 @@ import android.widget.Toast;
|
||||||
import com.yarolegovich.lovelydialog.LovelyTextInputDialog;
|
import com.yarolegovich.lovelydialog.LovelyTextInputDialog;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
import me.impy.aegis.crypto.CryptoUtils;
|
import me.impy.aegis.crypto.CryptoUtils;
|
||||||
import me.impy.aegis.crypto.OTP;
|
import me.impy.aegis.crypto.OTP;
|
||||||
|
@ -111,7 +113,14 @@ public class MainActivity extends AppCompatActivity {
|
||||||
touchHelper.attachToRecyclerView(rvKeyProfiles);
|
touchHelper.attachToRecyclerView(rvKeyProfiles);
|
||||||
|
|
||||||
rvKeyProfiles.setAdapter(mKeyProfileAdapter);
|
rvKeyProfiles.setAdapter(mKeyProfileAdapter);
|
||||||
|
Comparator<KeyProfile> comparator = new Comparator<KeyProfile>() {
|
||||||
|
@Override
|
||||||
|
public int compare(KeyProfile keyProfile, KeyProfile t1) {
|
||||||
|
return keyProfile.Order - t1.Order;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Collections.sort(mKeyProfiles, comparator);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (KeyProfile profile : database.getKeys()) {
|
for (KeyProfile profile : database.getKeys()) {
|
||||||
mKeyProfiles.add(profile);
|
mKeyProfiles.add(profile);
|
||||||
|
@ -149,6 +158,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyProfile.Order = mKeyProfiles.size() + 1;
|
||||||
keyProfile.Code = otp;
|
keyProfile.Code = otp;
|
||||||
mKeyProfiles.add(keyProfile);
|
mKeyProfiles.add(keyProfile);
|
||||||
mKeyProfileAdapter.notifyDataSetChanged();
|
mKeyProfileAdapter.notifyDataSetChanged();
|
||||||
|
@ -162,12 +172,41 @@ public class MainActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void adjustOrder(int startPosition)
|
||||||
|
{
|
||||||
|
Comparator<KeyProfile> comparator = new Comparator<KeyProfile>() {
|
||||||
|
@Override
|
||||||
|
public int compare(KeyProfile keyProfile, KeyProfile t1) {
|
||||||
|
return keyProfile.Order - t1.Order;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for(int i = startPosition; i < mKeyProfiles.size(); i++)
|
||||||
|
{
|
||||||
|
mKeyProfiles.get(i).Order = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
setPreferredTheme();
|
setPreferredTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
for(int i = 0; i < mKeyProfiles.size(); i++)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
database.updateKey(mKeyProfiles.get(i));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
|
|
|
@ -6,6 +6,7 @@ import net.sqlcipher.Cursor;
|
||||||
import net.sqlcipher.database.SQLiteDatabase;
|
import net.sqlcipher.database.SQLiteDatabase;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import me.impy.aegis.KeyProfile;
|
import me.impy.aegis.KeyProfile;
|
||||||
|
@ -43,8 +44,8 @@ public class Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateKey(KeyProfile profile) throws Exception {
|
public void updateKey(KeyProfile profile) throws Exception {
|
||||||
db.execSQL("update otp set name=? url=? where id=?",
|
db.execSQL("update otp set name=?, url=?, 'order'=? where id=?",
|
||||||
new Object[]{ profile.Name, profile.Info.getURL(), profile.ID });
|
new Object[]{ profile.Name, profile.Info.getURL(), profile.Order, profile.ID });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeKey(KeyProfile profile) {
|
public void removeKey(KeyProfile profile) {
|
||||||
|
@ -53,19 +54,20 @@ public class Database {
|
||||||
|
|
||||||
public List<KeyProfile> getKeys() throws Exception {
|
public List<KeyProfile> getKeys() throws Exception {
|
||||||
List<KeyProfile> list = new ArrayList<>();
|
List<KeyProfile> list = new ArrayList<>();
|
||||||
Cursor cursor = db.rawQuery("select * from otp", null);
|
Cursor cursor = db.rawQuery("select * from otp order by 'order' desc", null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
KeyProfile profile = new KeyProfile();
|
KeyProfile profile = new KeyProfile();
|
||||||
profile.ID = cursor.getInt(cursor.getColumnIndexOrThrow("id"));
|
profile.ID = cursor.getInt(cursor.getColumnIndexOrThrow("id"));
|
||||||
profile.Name = cursor.getString(cursor.getColumnIndexOrThrow("name"));
|
profile.Name = cursor.getString(cursor.getColumnIndexOrThrow("name"));
|
||||||
|
profile.Order = cursor.getInt(cursor.getColumnIndexOrThrow("order"));
|
||||||
String url = cursor.getString(cursor.getColumnIndexOrThrow("url"));
|
String url = cursor.getString(cursor.getColumnIndexOrThrow("url"));
|
||||||
profile.Info = KeyInfo.FromURL(url);
|
profile.Info = KeyInfo.FromURL(url);
|
||||||
|
|
||||||
list.add(profile);
|
list.add(profile);
|
||||||
}
|
}
|
||||||
|
Collections.sort(list, (a, b) -> b.compareTo(a));
|
||||||
return list;
|
return list;
|
||||||
} finally {
|
} finally {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
|
|
@ -18,7 +18,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||||
"create table otp (" +
|
"create table otp (" +
|
||||||
"id integer primary key autoincrement, " +
|
"id integer primary key autoincrement, " +
|
||||||
"name varchar not null, " +
|
"name varchar not null, " +
|
||||||
"url varchar not null)";
|
"url varchar not null, " +
|
||||||
|
"'order' integer)";
|
||||||
|
|
||||||
public DatabaseHelper(Context context, String filename) {
|
public DatabaseHelper(Context context, String filename) {
|
||||||
super(context, filename, null, Version);
|
super(context, filename, null, Version);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue