mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-04-04 23:53:51 -04:00
Generate catima.app share links
This commit is contained in:
@@ -60,13 +60,16 @@
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<!-- Accepts URIs that begin with "https://github.com/brarcher/loyalty-card-locker/” -->
|
||||
<!-- Listen to known card sharing URIs -->
|
||||
<data android:scheme="https"
|
||||
android:host="@string/intent_import_card_from_url_host"
|
||||
android:pathPrefix="@string/intent_import_card_from_url_path_prefix" />
|
||||
android:host="@string/intent_import_card_from_url_host_catima_app"
|
||||
android:pathPrefix="@string/intent_import_card_from_url_path_prefix_catima_app" />
|
||||
<data android:scheme="https"
|
||||
android:host="@string/intent_import_card_from_url_host_old"
|
||||
android:pathPrefix="@string/intent_import_card_from_url_path_prefix_old" />
|
||||
android:host="@string/intent_import_card_from_url_host_thelastproject"
|
||||
android:pathPrefix="@string/intent_import_card_from_url_path_prefix_thelastproject" />
|
||||
<data android:scheme="https"
|
||||
android:host="@string/intent_import_card_from_url_host_brarcher"
|
||||
android:pathPrefix="@string/intent_import_card_from_url_path_prefix_brarcher" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
|
||||
@@ -29,25 +29,31 @@ public class ImportURIHelper {
|
||||
private static final String HEADER_COLOR = DBHelper.LoyaltyCardDbIds.HEADER_COLOR;
|
||||
|
||||
private final Context context;
|
||||
private final String host;
|
||||
private final String path;
|
||||
private final String oldHost;
|
||||
private final String oldPath;
|
||||
private final String[] hosts = new String[3];
|
||||
private final String[] paths = new String[3];
|
||||
private final String shareText;
|
||||
private final String shareMultipleText;
|
||||
|
||||
public ImportURIHelper(Context context) {
|
||||
this.context = context;
|
||||
host = context.getResources().getString(R.string.intent_import_card_from_url_host);
|
||||
path = context.getResources().getString(R.string.intent_import_card_from_url_path_prefix);
|
||||
oldHost = "brarcher.github.io";
|
||||
oldPath = "/loyalty-card-locker/share";
|
||||
hosts[0] = context.getResources().getString(R.string.intent_import_card_from_url_host_catima_app);
|
||||
paths[0] = context.getResources().getString(R.string.intent_import_card_from_url_path_prefix_catima_app);
|
||||
hosts[1] = context.getResources().getString(R.string.intent_import_card_from_url_host_thelastproject);
|
||||
paths[1] = context.getResources().getString(R.string.intent_import_card_from_url_path_prefix_thelastproject);
|
||||
hosts[2] = context.getResources().getString(R.string.intent_import_card_from_url_host_brarcher);
|
||||
paths[2] = context.getResources().getString(R.string.intent_import_card_from_url_path_prefix_brarcher);
|
||||
shareText = context.getResources().getString(R.string.intent_import_card_from_url_share_text);
|
||||
shareMultipleText = context.getResources().getString(R.string.intent_import_card_from_url_share_multiple_text);
|
||||
}
|
||||
|
||||
private boolean isImportUri(Uri uri) {
|
||||
return (uri.getHost().equals(host) && uri.getPath().equals(path)) || (uri.getHost().equals(oldHost) && uri.getPath().equals(oldPath));
|
||||
for (int i = 0; i < hosts.length; i++) {
|
||||
if (uri.getHost().equals(hosts[i]) && uri.getPath().equals(paths[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public LoyaltyCard parse(Uri uri) throws InvalidObjectException {
|
||||
@@ -137,8 +143,8 @@ public class ImportURIHelper {
|
||||
protected Uri toUri(LoyaltyCard loyaltyCard) throws UnsupportedEncodingException {
|
||||
Uri.Builder uriBuilder = new Uri.Builder();
|
||||
uriBuilder.scheme("https");
|
||||
uriBuilder.authority(host);
|
||||
uriBuilder.path(path);
|
||||
uriBuilder.authority(hosts[0]);
|
||||
uriBuilder.path(paths[0]);
|
||||
|
||||
// Use fragment instead of QueryParameter to not leak this data to the server
|
||||
StringBuilder fragment = new StringBuilder();
|
||||
|
||||
@@ -109,10 +109,12 @@
|
||||
<string name="sharedpreference_privacy_policy_shown" translatable="false">sharedpreference_privacy_policy_shown</string>
|
||||
|
||||
<string name="intent_import_card_from_url_share_text">I want to share a card with you</string>
|
||||
<string name="intent_import_card_from_url_host" translatable="false">thelastproject.github.io</string>
|
||||
<string name="intent_import_card_from_url_path_prefix" translatable="false">/Catima/share</string>
|
||||
<string name="intent_import_card_from_url_host_old" translatable="false">brarcher.github.io</string>
|
||||
<string name="intent_import_card_from_url_path_prefix_old" translatable="false">/loyalty-card-locker/share</string>
|
||||
<string name="intent_import_card_from_url_host_catima_app" translatable="false">catima.app</string>
|
||||
<string name="intent_import_card_from_url_path_prefix_catima_app" translatable="false">/share</string>
|
||||
<string name="intent_import_card_from_url_host_thelastproject" translatable="false">thelastproject.github.io</string>
|
||||
<string name="intent_import_card_from_url_path_prefix_thelastproject" translatable="false">/Catima/share</string>
|
||||
<string name="intent_import_card_from_url_host_brarcher" translatable="false">brarcher.github.io</string>
|
||||
<string name="intent_import_card_from_url_path_prefix_brarcher" translatable="false">/loyalty-card-locker/share</string>
|
||||
<string name="importSuccessful">Card data imported</string>
|
||||
<string name="exportSuccessful">Card data exported</string>
|
||||
|
||||
|
||||
@@ -109,9 +109,10 @@ public class ImportURITest {
|
||||
@Test
|
||||
public void failToParseBadData()
|
||||
{
|
||||
String[] urls = new String[2];
|
||||
String[] urls = new String[3];
|
||||
urls[0] = "https://brarcher.github.io/loyalty-card-locker/share?stare=store¬e=note&cardid=12345&barcodetype=ITF&headercolor=-416706";
|
||||
urls[1] = "https://thelastproject.github.io/Catima/share#stare%3Dstore%26note%3Dnote%26balance%3D0%26cardid%3D12345%26barcodetype%3DITF%26headercolor%3D-416706";
|
||||
urls[2] = "https://catima.app/share#stare%3Dstore%26note%3Dnote%26balance%3D0%26cardid%3D12345%26barcodetype%3DITF%26headercolor%3D-416706";
|
||||
|
||||
for (String url : urls) {
|
||||
try {
|
||||
@@ -126,9 +127,10 @@ public class ImportURITest {
|
||||
|
||||
@Test
|
||||
public void parseAdditionalUnforeseenData() {
|
||||
String[] urls = new String[2];
|
||||
String[] urls = new String[3];
|
||||
urls[0] = "https://brarcher.github.io/loyalty-card-locker/share?store=store¬e=note&cardid=12345&barcodetype=ITF&headercolor=-416706&headertextcolor=-1¬foreseen=no";
|
||||
urls[1] = "https://thelastproject.github.io/Catima/share#store%3Dstore%26note%3Dnote%26balance%3D0%26cardid%3D12345%26barcodetype%3DITF%26headercolor%3D-416706%26notforeseen%3Dno";
|
||||
urls[2] = "https://catima.app/share#store%3Dstore%26note%3Dnote%26balance%3D0%26cardid%3D12345%26barcodetype%3DITF%26headercolor%3D-416706%26notforeseen%3Dno";
|
||||
|
||||
for (String url : urls) {
|
||||
LoyaltyCard parsedCard = null;
|
||||
|
||||
Reference in New Issue
Block a user