mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-21 14:29:13 +00:00
Added list and adapter to handle profiles
This commit is contained in:
parent
ac1c2cf7df
commit
873299a224
7 changed files with 195 additions and 30 deletions
12
app/src/main/java/me/impy/aegis/KeyProfile.java
Normal file
12
app/src/main/java/me/impy/aegis/KeyProfile.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package me.impy.aegis;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import me.impy.aegis.crypto.KeyInfo;
|
||||
|
||||
public class KeyProfile implements Serializable {
|
||||
public String Name;
|
||||
public String Icon;
|
||||
public String Code;
|
||||
public KeyInfo KeyInfo;
|
||||
}
|
56
app/src/main/java/me/impy/aegis/KeyProfileAdapter.java
Normal file
56
app/src/main/java/me/impy/aegis/KeyProfileAdapter.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
package me.impy.aegis;
|
||||
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.security.Key;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.KeyProfileHolder> {
|
||||
private ArrayList<KeyProfile> mKeyProfiles;
|
||||
|
||||
public static class KeyProfileHolder extends RecyclerView.ViewHolder {
|
||||
TextView profileName;
|
||||
TextView profileCode;
|
||||
|
||||
KeyProfileHolder(View itemView) {
|
||||
super(itemView);
|
||||
profileName = (TextView) itemView.findViewById(R.id.profile_name);
|
||||
profileCode = (TextView) itemView.findViewById(R.id.profile_code);
|
||||
}
|
||||
}
|
||||
|
||||
// Provide a suitable constructor (depends on the kind of dataset)
|
||||
public KeyProfileAdapter(ArrayList<KeyProfile> keyProfiles) {
|
||||
mKeyProfiles = keyProfiles;
|
||||
}
|
||||
|
||||
// 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(KeyProfileHolder holder, int position) {
|
||||
holder.profileName.setText(mKeyProfiles.get(position).Name);
|
||||
holder.profileCode.setText(mKeyProfiles.get(position).Code);
|
||||
}
|
||||
|
||||
// Return the size of your dataset (invoked by the layout manager)
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mKeyProfiles.size();
|
||||
}
|
||||
}
|
|
@ -1,22 +1,29 @@
|
|||
package me.impy.aegis;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.inputmethodservice.Keyboard;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import me.impy.aegis.crypto.KeyInfo;
|
||||
import me.impy.aegis.crypto.OTP;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
static final int GET_KEYINFO = 1;
|
||||
TextView tvTotp;
|
||||
RecyclerView rvKeyProfiles;
|
||||
KeyProfileAdapter mKeyProfileAdapter;
|
||||
ArrayList<KeyProfile> mKeyProfiles;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -34,7 +41,14 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
tvTotp = (TextView) findViewById(R.id.textView2);
|
||||
mKeyProfiles = new ArrayList<>();
|
||||
|
||||
rvKeyProfiles = (RecyclerView) findViewById(R.id.rvKeyProfiles);
|
||||
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
|
||||
rvKeyProfiles.setLayoutManager(mLayoutManager);
|
||||
|
||||
mKeyProfileAdapter = new KeyProfileAdapter(mKeyProfiles);
|
||||
rvKeyProfiles.setAdapter(mKeyProfileAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,16 +57,20 @@ public class MainActivity extends AppCompatActivity {
|
|||
if (requestCode == GET_KEYINFO) {
|
||||
// Make sure the request was successful
|
||||
if (resultCode == RESULT_OK) {
|
||||
KeyInfo info = (KeyInfo)data.getSerializableExtra("Keyinfo");
|
||||
KeyProfile keyProfile = (KeyProfile)data.getSerializableExtra("KeyProfile");
|
||||
|
||||
String otp;
|
||||
try {
|
||||
otp = OTP.generateOTP(info);
|
||||
otp = OTP.generateOTP(keyProfile.KeyInfo);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
tvTotp.setText(otp);
|
||||
|
||||
keyProfile.Code = otp;
|
||||
mKeyProfiles.add(keyProfile);
|
||||
mKeyProfileAdapter.notifyDataSetChanged();
|
||||
//TODO: do something with the result.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ public class ScannerActivity extends Activity implements ZXingScannerView.Result
|
|||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
handleDummyResult();
|
||||
|
||||
mScannerView = new ZXingScannerView(this); // Programmatically initialize the scanner view
|
||||
setContentView(mScannerView); // Set the scanner view as the content view
|
||||
mScannerView.setFormats(getSupportedFormats());
|
||||
|
@ -47,6 +49,29 @@ public class ScannerActivity extends Activity implements ZXingScannerView.Result
|
|||
mScannerView.stopCamera(); // Stop camera on pause
|
||||
}
|
||||
|
||||
public void handleDummyResult() {
|
||||
// Do something with the result here
|
||||
//Toast.makeText(this, rawResult.getText(), Toast.LENGTH_SHORT).show();
|
||||
|
||||
try {
|
||||
KeyInfo info = KeyInfo.FromURL("otpauth://totp/ACME%20Co:john@example.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ");
|
||||
KeyProfile keyProfile = new KeyProfile();
|
||||
keyProfile.KeyInfo = info;
|
||||
keyProfile.Name = info.getLabel();
|
||||
|
||||
Intent resultIntent = new Intent();
|
||||
resultIntent.putExtra("KeyProfile", keyProfile);
|
||||
|
||||
setResult(Activity.RESULT_OK, resultIntent);
|
||||
finish();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// If you would like to resume scanning, call this method below:
|
||||
//mScannerView.resumeCameraPreview(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleResult(Result rawResult) {
|
||||
// Do something with the result here
|
||||
|
@ -54,8 +79,12 @@ public class ScannerActivity extends Activity implements ZXingScannerView.Result
|
|||
|
||||
try {
|
||||
KeyInfo info = KeyInfo.FromURL(rawResult.getText());
|
||||
KeyProfile keyProfile = new KeyProfile();
|
||||
keyProfile.KeyInfo = info;
|
||||
keyProfile.Name = info.getLabel();
|
||||
|
||||
Intent resultIntent = new Intent();
|
||||
resultIntent.putExtra("Keyinfo", info);
|
||||
resultIntent.putExtra("KeyProfile", keyProfile);
|
||||
|
||||
setResult(Activity.RESULT_OK, resultIntent);
|
||||
finish();
|
||||
|
@ -71,16 +100,12 @@ public class ScannerActivity extends Activity implements ZXingScannerView.Result
|
|||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case 1: {
|
||||
|
||||
// If request is cancelled, the result arrays are empty.
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
|
||||
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
|
||||
mScannerView.startCamera(); // Start camera on resume
|
||||
} else {
|
||||
|
||||
// permission denied, boo! Disable the
|
||||
// functionality that depends on this permission.
|
||||
Toast.makeText(ScannerActivity.this, "Permission denied to get access to the camera", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -67,7 +67,7 @@ public class KeyInfo implements Serializable {
|
|||
// provider info used to disambiguate accounts
|
||||
// these parameters are not required but I don't want them to be null either
|
||||
String issuer = url.getQueryParameter("issuer");
|
||||
String label = url.getQueryParameter("label");
|
||||
String label = url.getPath();
|
||||
info.issuer = issuer != null ? issuer : "";
|
||||
info.label = label != null ? label : "";
|
||||
|
||||
|
|
|
@ -21,9 +21,15 @@
|
|||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@android:drawable/ic_dialog_email" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
|
@ -34,22 +40,13 @@
|
|||
tools:context="me.impy.aegis.MainActivity"
|
||||
tools:showIn="@layout/activity_main">
|
||||
|
||||
<TextView
|
||||
android:text="TextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/textView2"
|
||||
android:textSize="24sp"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_centerHorizontal="true"/>
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/rvKeyProfiles"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@android:drawable/ic_dialog_email" />
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
57
app/src/main/res/layout/card_keyprofile.xml
Normal file
57
app/src/main/res/layout/card_keyprofile.xml
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_margin="5dp"
|
||||
android:layout_height="wrap_content"
|
||||
card_view:cardCornerRadius="4dp"
|
||||
android:id="@+id/cv">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:layout_alignParentBottom="false"
|
||||
android:layout_alignParentTop="false"
|
||||
android:layout_alignWithParentIfMissing="false"
|
||||
android:gravity="bottom"
|
||||
android:id="@+id/relativeLayout"
|
||||
android:layout_alignParentStart="false"
|
||||
android:layout_alignEnd="@+id/imageView">
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/profile_name"
|
||||
android:text="Post title"
|
||||
android:textSize="20sp"
|
||||
android:layout_alignStart="@+id/profile_code" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="Medium Text"
|
||||
android:id="@+id/profile_code"
|
||||
android:layout_below="@+id/profile_name"
|
||||
android:layout_alignParentStart="true" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
</LinearLayout>
|
Loading…
Add table
Reference in a new issue