URL rewrithe for cathay and improve url rewriting on the go - with error handling and so

This commit is contained in:
ligi 2014-08-23 14:25:40 +02:00
parent 0e39e4015b
commit a034592003
3 changed files with 116 additions and 29 deletions

View file

@ -536,7 +536,7 @@
</activity>
<activity android:name="org.ligi.passandroid.ui.quirk_fix.VirginAustraliaLoadActivity">
<activity android:name=".ui.quirk_fix.URLRewriteActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@ -559,6 +559,18 @@
android:pathPattern="/virginaustralia/.*"
android:scheme="http" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.cathaypacific.com"
android:pathPattern="/icheckin2/mbp.do.*"
android:scheme="https" />
</intent-filter>
</activity>
<activity android:name=".ui.quirk_fix.USAirwaysLoadActivity">

View file

@ -0,0 +1,103 @@
package org.ligi.passandroid.ui.quirk_fix;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import org.ligi.axt.AXT;
import org.ligi.passandroid.Tracker;
import org.ligi.passandroid.ui.PassImportActivity;
import java.net.URLEncoder;
public class URLRewriteActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String url = null;
if (getIntent().getData().getHost().equals("mobile.virginaustralia.com")) {
url = getVirginAustraliaURL();
} else if (getIntent().getData().getHost().equals("www.cathaypacific.com")) {
url = getCathay();
}
if (url == null) {
new AlertDialog.Builder(this)
.setTitle("Workaround failed")
.setMessage("The URL PassAndroid tried to work around failed :-( some companies just send PassBooks to Apple Devices - this was an attempt to workaround this." +
"Unfortunately it failed - perhaps there where changes on the serverside - you can open the site with your browser now - to see it in PassAndroid in future again it would help if you can send me the pass")
.setPositiveButton("Browser", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Tracker.get().trackException("URLRewrite with invalid activity", false);
AXT.at(URLRewriteActivity.this).rethrowIntentExcludingSelf();
}
})
.setNeutralButton("send", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, "PassAndroid: URLRewrite Problem");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"ligi@ligi.de"});
intent.putExtra(Intent.EXTRA_TEXT, "foo"+getIntent().getData());
intent.setType("text/plain");
startActivity(Intent.createChooser(intent, "How to send Link?"));
finish();
}
}
)
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
URLRewriteActivity.this.finish();
}
})
.show();
return;
}
final Intent intent = new Intent(this, PassImportActivity.class);
intent.setData(Uri.parse(url));
startActivity(intent);
finish();
}
private String getVirginAustraliaURL() {
final String passId = getIntent().getData().getQueryParameter("c");
Tracker.get().trackEvent("quirk_fix", "redirect_attempt", "virgin_australia", null);
if (passId == null) {
return null;
}
Tracker.get().trackEvent("quirk_fix", "redirect", "virgin_australia", null);
return "https://mobile.virginaustralia.com/boarding/pass.pkpass?key=" + URLEncoder.encode(passId);
}
private String getCathay() {
final String passId = getIntent().getData().getQueryParameter("v");
Tracker.get().trackEvent("quirk_fix", "redirect_attempt", "cathay", null);
if (passId == null) {
return null;
}
Tracker.get().trackEvent("quirk_fix", "redirect", "cathay", null);
return "https://www.cathaypacific.com/icheckin2/PassbookServlet?v=" + URLEncoder.encode(passId);
}
}

View file

@ -1,28 +0,0 @@
package org.ligi.passandroid.ui.quirk_fix;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import org.ligi.passandroid.Tracker;
import org.ligi.passandroid.ui.PassImportActivity;
import java.net.URLEncoder;
public class VirginAustraliaLoadActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final String passId = getIntent().getData().getQueryParameter("c");
final String url = "https://mobile.virginaustralia.com/boarding/pass.pkpass?key=" + URLEncoder.encode(passId);
Tracker.get().trackEvent("quirk_fix", "redirect", "virgin_australia", null);
final Intent intent = new Intent(this, PassImportActivity.class);
intent.setData(Uri.parse(url));
startActivity(intent);
finish();
}
}