Skip to content

Commit

Permalink
For #22: implement share action
Browse files Browse the repository at this point in the history
Base implementation. Contact and other specific implementations yet to be added.
  • Loading branch information
czlucius committed Jan 19, 2022
1 parent 54c92c0 commit 100a175
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/czlucius/scan/objects/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,6 +63,7 @@ public class Type {

private Type(List<Action> actions, String typeName, int typeInt) {
actions.add(0, CopyAction.getInstance());
actions.add(1, ShareAction.getInstance());
this.actions = actions;
this.typeName = typeName;
this.typeInt = typeInt;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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);
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/com/czlucius/scan/objects/data/Contact.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package com.czlucius.scan.objects.data;


import android.content.Intent;

import androidx.annotation.NonNull;

import com.czlucius.scan.App;
Expand Down Expand Up @@ -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();
}


}
12 changes: 12 additions & 0 deletions app/src/main/java/com/czlucius/scan/objects/data/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package com.czlucius.scan.objects.data;

import android.content.Intent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

Expand All @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_round_share_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92s2.92,-1.31 2.92,-2.92 -1.31,-2.92 -2.92,-2.92z"/>
</vector>

0 comments on commit 100a175

Please sign in to comment.