diff --git a/app/src/main/java/com/czlucius/scan/objects/Type.java b/app/src/main/java/com/czlucius/scan/objects/Type.java index 60e8760..290ce78 100644 --- a/app/src/main/java/com/czlucius/scan/objects/Type.java +++ b/app/src/main/java/com/czlucius/scan/objects/Type.java @@ -34,6 +34,7 @@ import com.czlucius.scan.objects.actions.EmailAction; import com.czlucius.scan.objects.actions.CallPhoneAction; import com.czlucius.scan.objects.actions.SMSAction; +import com.czlucius.scan.objects.actions.ShareAction; import com.czlucius.scan.objects.actions.URLAction; import com.czlucius.scan.objects.actions.ViewLocationAction; import com.czlucius.scan.objects.data.Contact; @@ -62,6 +63,7 @@ public class Type { private Type(List actions, String typeName, int typeInt) { actions.add(0, CopyAction.getInstance()); + actions.add(1, ShareAction.getInstance()); this.actions = actions; this.typeName = typeName; this.typeInt = typeInt; diff --git a/app/src/main/java/com/czlucius/scan/objects/actions/ShareAction.java b/app/src/main/java/com/czlucius/scan/objects/actions/ShareAction.java new file mode 100644 index 0000000..e8e570f --- /dev/null +++ b/app/src/main/java/com/czlucius/scan/objects/actions/ShareAction.java @@ -0,0 +1,47 @@ +/* + * Code Scanner. An android app to scan and create codes(barcodes, QR codes, etc) + * Copyright (C) 2021 Lucius Chee Zihan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.czlucius.scan.objects.actions; + +import android.content.Context; +import android.content.Intent; + +import androidx.annotation.Nullable; + +import com.czlucius.scan.App; +import com.czlucius.scan.R; +import com.czlucius.scan.objects.data.Data; + +public class ShareAction extends Action { + private static Action INSTANCE; + private ShareAction() { + super(App.getStringGlobal(R.string.share, "Share"), R.drawable.ic_round_share_24); + } + public static Action getInstance() { + if (INSTANCE == null) { + INSTANCE = new ShareAction(); + } + return INSTANCE; + } + + @Override + public void performAction(Context context, Data data) { + Intent intent = data.constructShareIntent(); + context.startActivity(intent); + } +} diff --git a/app/src/main/java/com/czlucius/scan/objects/data/Contact.java b/app/src/main/java/com/czlucius/scan/objects/data/Contact.java index 2dedce4..1380cca 100644 --- a/app/src/main/java/com/czlucius/scan/objects/data/Contact.java +++ b/app/src/main/java/com/czlucius/scan/objects/data/Contact.java @@ -19,6 +19,8 @@ package com.czlucius.scan.objects.data; +import android.content.Intent; + import androidx.annotation.NonNull; import com.czlucius.scan.App; @@ -198,5 +200,15 @@ public boolean isEmpty() { && urls.length == 0; } + @Override + public Intent constructShareIntent() { + // TODO ---------------------------------------------------------- + // The standard way to share this is just by sharing the VCF(VCard contact) file + // A lot of contact apps (Google Contacts, Samsung Contacts, Simple Contacts from F-Droid do this + // Just create the VCard from the data, then write it to a file (.vcf), then share it like how you share the QR code image + + return super.constructShareIntent(); + } + } diff --git a/app/src/main/java/com/czlucius/scan/objects/data/Data.java b/app/src/main/java/com/czlucius/scan/objects/data/Data.java index 3374a90..9773d05 100644 --- a/app/src/main/java/com/czlucius/scan/objects/data/Data.java +++ b/app/src/main/java/com/czlucius/scan/objects/data/Data.java @@ -18,6 +18,8 @@ package com.czlucius.scan.objects.data; +import android.content.Intent; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -31,6 +33,16 @@ public abstract class Data { public abstract boolean isEmpty(); + public Intent constructShareIntent() + { + Intent sendIntent = new Intent(); + sendIntent.setAction(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_TEXT, getStringRepresentation()); + sendIntent.setType("text/plain"); + + return sendIntent; + } + public String getSummary() { return getStringRepresentation(); diff --git a/app/src/main/res/drawable/ic_round_share_24.xml b/app/src/main/res/drawable/ic_round_share_24.xml new file mode 100644 index 0000000..17f4f4a --- /dev/null +++ b/app/src/main/res/drawable/ic_round_share_24.xml @@ -0,0 +1,10 @@ + + +