Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add token sharing support, including Jelling support #169

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'com.android.application'

dependencies {
implementation 'com.android.support:recyclerview-v7:27.0.1'
compile 'com.google.zxing:core:3.3.0'
compile 'com.google.code.gson:gson:2.8.2'
compile 'com.squareup.picasso:picasso:2.5.2'
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
android:resizeable="true"
android:anyDensity="true" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />

<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />

Expand All @@ -53,22 +57,27 @@
/>

<activity
android:name=".add.ScanActivity"
android:name=".ScanActivity"
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"
/>

<activity
android:name=".edit.DeleteActivity"
android:name=".DeleteTokenActivity"
android:label="@string/delete_question"
android:theme="@android:style/Theme.Holo.Light.Dialog"
/>

<activity
android:name=".edit.EditActivity"
android:name=".EditTokenActivity"
android:theme="@android:style/Theme.Holo.Light.Dialog.NoActionBar"
android:windowSoftInputMode="stateVisible"
/>

<activity
android:name=".share.ShareActivity"
android:theme="@android:style/Theme.Holo.Light.Dialog.NoActionBar"
/>

<activity
android:name=".MainActivity"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.fedorahosted.freeotp.edit;
package org.fedorahosted.freeotp;

import android.app.Activity;
import android.os.Bundle;
import org.fedorahosted.freeotp.BuildConfig;

public abstract class BaseActivity extends Activity {
public abstract class BaseTokenActivity extends Activity {
public static final String EXTRA_POSITION = "position";
private int mPosition;

Expand All @@ -15,7 +15,7 @@ protected void onCreate(Bundle savedInstanceState) {
// Get the position of the token. This MUST exist.
mPosition = getIntent().getIntExtra(EXTRA_POSITION, -1);
if(BuildConfig.DEBUG && mPosition < 0)
throw new RuntimeException("Could not create BaseActivity");
throw new RuntimeException("Could not create BaseTokenActivity");
}

protected int getPosition() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
package org.fedorahosted.freeotp.edit;

import org.fedorahosted.freeotp.R;
import org.fedorahosted.freeotp.Token;
import org.fedorahosted.freeotp.TokenPersistence;
package org.fedorahosted.freeotp;

import android.os.Bundle;
import android.view.View;
Expand All @@ -11,7 +7,7 @@

import com.squareup.picasso.Picasso;

public class DeleteActivity extends BaseActivity {
public class DeleteTokenActivity extends BaseTokenActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -36,7 +32,7 @@ public void onClick(View v) {
public void onClick(View v) {
//delete the image that was copied to storage, before deleting the token
token.deleteImage();
new TokenPersistence(DeleteActivity.this).delete(getPosition());
new TokenPersistence(DeleteTokenActivity.this).delete(getPosition());
finish();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@
* limitations under the License.
*/

package org.fedorahosted.freeotp.edit;
package org.fedorahosted.freeotp;

import android.widget.Toast;

import org.fedorahosted.freeotp.R;
import org.fedorahosted.freeotp.Token;
import org.fedorahosted.freeotp.TokenPersistence;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
Expand All @@ -38,7 +34,7 @@

import com.squareup.picasso.Picasso;

public class EditActivity extends BaseActivity implements TextWatcher, View.OnClickListener {
public class EditTokenActivity extends BaseTokenActivity implements TextWatcher, View.OnClickListener {
private EditText mIssuer;
private EditText mLabel;
private ImageButton mImage;
Expand Down Expand Up @@ -120,7 +116,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
token.setImage(mImageDisplay);
}
else {
Toast.makeText(EditActivity.this, R.string.error_image_open, Toast.LENGTH_LONG).show();
Toast.makeText(EditTokenActivity.this, R.string.error_image_open, Toast.LENGTH_LONG).show();
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/org/fedorahosted/freeotp/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
import android.Manifest;
import android.widget.Toast;

import org.fedorahosted.freeotp.add.ScanActivity;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
* limitations under the License.
*/

package org.fedorahosted.freeotp.add;

import org.fedorahosted.freeotp.R;
import org.fedorahosted.freeotp.Token;
import org.fedorahosted.freeotp.TokenPersistence;
package org.fedorahosted.freeotp;

import android.app.Activity;
import android.content.BroadcastReceiver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* limitations under the License.
*/

package org.fedorahosted.freeotp.add;
package org.fedorahosted.freeotp;

import android.content.Context;
import android.content.Intent;
Expand All @@ -33,7 +33,6 @@
import io.fotoapparat.preview.FrameProcessor;

public class ScanFrameProcessor implements FrameProcessor {

private static Handler MAIN_THREAD_HANDLER = new Handler(Looper.getMainLooper());
private Reader reader;
private Context scanActivityContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* limitations under the License.
*/

package org.fedorahosted.freeotp.add;
package org.fedorahosted.freeotp;

import android.content.Context;
import android.util.AttributeSet;
Expand Down
28 changes: 11 additions & 17 deletions app/src/main/java/org/fedorahosted/freeotp/TokenAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

package org.fedorahosted.freeotp;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.database.DataSetObserver;
Expand All @@ -30,24 +28,20 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupMenu;
import android.widget.Toast;

import org.fedorahosted.freeotp.edit.DeleteActivity;
import org.fedorahosted.freeotp.edit.EditActivity;
import org.fedorahosted.freeotp.share.ShareActivity;

import java.util.HashMap;
import java.util.Map;

public class TokenAdapter extends BaseReorderableAdapter {
private final TokenPersistence mTokenPersistence;
private final LayoutInflater mLayoutInflater;
private final ClipboardManager mClipMan;
private final Map<String, TokenCode> mTokenCodes;

public TokenAdapter(Context ctx) {
mTokenPersistence = new TokenPersistence(ctx);
mLayoutInflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mClipMan = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
mTokenCodes = new HashMap<>();
registerDataSetObserver(new DataSetObserver() {
@Override
Expand Down Expand Up @@ -95,15 +89,21 @@ public boolean onMenuItemClick(MenuItem item) {
Intent i;

switch (item.getItemId()) {
case R.id.action_share:
i = new Intent(ctx, ShareActivity.class);
i.putExtra(ShareActivity.EXTRA_POSITION, position);
ctx.startActivity(i);
break;

case R.id.action_edit:
i = new Intent(ctx, EditActivity.class);
i.putExtra(EditActivity.EXTRA_POSITION, position);
i = new Intent(ctx, EditTokenActivity.class);
i.putExtra(EditTokenActivity.EXTRA_POSITION, position);
ctx.startActivity(i);
break;

case R.id.action_delete:
i = new Intent(ctx, DeleteActivity.class);
i.putExtra(DeleteActivity.EXTRA_POSITION, position);
i = new Intent(ctx, DeleteTokenActivity.class);
i.putExtra(DeleteTokenActivity.EXTRA_POSITION, position);
ctx.startActivity(i);
break;
}
Expand All @@ -123,12 +123,6 @@ public void onClick(View v) {
//save token. Image wasn't changed here, so just save it in sync
new TokenPersistence(ctx).save(token);

// Copy code to clipboard.
mClipMan.setPrimaryClip(ClipData.newPlainText(null, codes.getCurrentCode()));
Toast.makeText(v.getContext().getApplicationContext(),
R.string.code_copied,
Toast.LENGTH_SHORT).show();

mTokenCodes.put(token.getID(), codes);
((TokenLayout) v).start(token.getType(), codes, true);
}
Expand Down
Loading