init
This commit is contained in:
parent
1cfde91b76
commit
9e726d0626
32
README.md
32
README.md
@ -11,9 +11,35 @@ npx cap sync
|
|||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
<docgen-index></docgen-index>
|
<docgen-index>
|
||||||
|
|
||||||
|
* [`launchPromoCodeRedemptionFlow()`](#launchpromocoderedemptionflow)
|
||||||
|
* [`isPromoCodeSupported()`](#ispromocodesupported)
|
||||||
|
|
||||||
|
</docgen-index>
|
||||||
|
|
||||||
<docgen-api>
|
<docgen-api>
|
||||||
<!-- run docgen to generate docs from the source -->
|
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
||||||
<!-- More info: https://github.com/ionic-team/capacitor-docgen -->
|
|
||||||
|
### launchPromoCodeRedemptionFlow()
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
launchPromoCodeRedemptionFlow() => Promise<{ success: boolean; message?: string; }>
|
||||||
|
```
|
||||||
|
|
||||||
|
**Returns:** <code>Promise<{ success: boolean; message?: string; }></code>
|
||||||
|
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
|
||||||
|
### isPromoCodeSupported()
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
isPromoCodeSupported() => Promise<{ supported: boolean; }>
|
||||||
|
```
|
||||||
|
|
||||||
|
**Returns:** <code>Promise<{ supported: boolean; }></code>
|
||||||
|
|
||||||
|
--------------------
|
||||||
|
|
||||||
</docgen-api>
|
</docgen-api>
|
||||||
|
@ -1,11 +1,81 @@
|
|||||||
package software.eskimo.capacitor.promocode;
|
package eskimo.software.capacitor.promocode;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class PromoCode {
|
import com.getcapacitor.JSObject;
|
||||||
|
import com.getcapacitor.Plugin;
|
||||||
|
import com.getcapacitor.PluginCall;
|
||||||
|
import com.getcapacitor.PluginMethod;
|
||||||
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
||||||
|
|
||||||
public String echo(String value) {
|
@CapacitorPlugin(name = "PromoCode")
|
||||||
Log.i("Echo", value);
|
public class PromoCode extends Plugin {
|
||||||
return value;
|
private static final String TAG = "PromoCode";
|
||||||
|
private static final int PROMO_CODE_REQUEST = 5001;
|
||||||
|
|
||||||
|
@PluginMethod
|
||||||
|
public void isPromoCodeSupported(PluginCall call) {
|
||||||
|
JSObject ret = new JSObject();
|
||||||
|
ret.put("supported", true);
|
||||||
|
call.resolve(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PluginMethod
|
||||||
|
public void launchPromoCodeRedemptionFlow(PluginCall call) {
|
||||||
|
try {
|
||||||
|
saveCall(call);
|
||||||
|
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
|
intent.setData(Uri.parse("https://play.google.com/redeem?code="));
|
||||||
|
intent.setPackage("com.android.vending");
|
||||||
|
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
|
||||||
|
Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
|
||||||
|
if (intent.resolveActivity(getContext().getPackageManager()) != null) {
|
||||||
|
getActivity().runOnUiThread(() -> {
|
||||||
|
Toast.makeText(getContext(),
|
||||||
|
"Redeem your code in Google Play. Press back to return.",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
});
|
||||||
|
|
||||||
|
startActivityForResult(call, intent, PROMO_CODE_REQUEST);
|
||||||
|
} else {
|
||||||
|
Intent webIntent = new Intent(Intent.ACTION_VIEW,
|
||||||
|
Uri.parse("https://play.google.com/redeem"));
|
||||||
|
startActivityForResult(call, webIntent, PROMO_CODE_REQUEST);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Error launching promo code flow", e);
|
||||||
|
JSObject ret = new JSObject();
|
||||||
|
ret.put("success", false);
|
||||||
|
ret.put("message", "Failed to launch promo code flow: " + e.getMessage());
|
||||||
|
call.resolve(ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.handleOnActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
|
if (requestCode == PROMO_CODE_REQUEST) {
|
||||||
|
PluginCall savedCall = getSavedCall();
|
||||||
|
if (savedCall == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSObject ret = new JSObject();
|
||||||
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
|
ret.put("success", true);
|
||||||
|
} else {
|
||||||
|
ret.put("success", false);
|
||||||
|
ret.put("message", "User canceled or redemption failed");
|
||||||
|
}
|
||||||
|
savedCall.resolve(ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,22 +0,0 @@
|
|||||||
package software.eskimo.capacitor.promocode;
|
|
||||||
|
|
||||||
import com.getcapacitor.JSObject;
|
|
||||||
import com.getcapacitor.Plugin;
|
|
||||||
import com.getcapacitor.PluginCall;
|
|
||||||
import com.getcapacitor.PluginMethod;
|
|
||||||
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
||||||
|
|
||||||
@CapacitorPlugin(name = "PromoCode")
|
|
||||||
public class PromoCodePlugin extends Plugin {
|
|
||||||
|
|
||||||
private PromoCode implementation = new PromoCode();
|
|
||||||
|
|
||||||
@PluginMethod
|
|
||||||
public void echo(PluginCall call) {
|
|
||||||
String value = call.getString("value");
|
|
||||||
|
|
||||||
JSObject ret = new JSObject();
|
|
||||||
ret.put("value", implementation.echo(value));
|
|
||||||
call.resolve(ret);
|
|
||||||
}
|
|
||||||
}
|
|
3712
package-lock.json
generated
Normal file
3712
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,4 @@
|
|||||||
export interface PromoCodePlugin {
|
export interface PromoCodePlugin {
|
||||||
echo(options: { value: string }): Promise<{ value: string }>;
|
launchPromoCodeRedemptionFlow(): Promise<{ success: boolean; message?: string }>;
|
||||||
|
isPromoCodeSupported(): Promise<{ supported: boolean }>;
|
||||||
}
|
}
|
@ -1,9 +1,8 @@
|
|||||||
import { registerPlugin } from '@capacitor/core';
|
import { registerPlugin } from '@capacitor/core';
|
||||||
|
|
||||||
import type { PromoCodePlugin } from './definitions';
|
import type { PromoCodePlugin } from './definitions';
|
||||||
|
|
||||||
const PromoCode = registerPlugin<PromoCodePlugin>('PromoCode', {
|
const PromoCode = registerPlugin<PromoCodePlugin>('PromoCode', {
|
||||||
web: () => import('./web').then((m) => new m.PromoCodeWeb()),
|
web: () => import('./web').then(m => new m.PromoCodeWeb()),
|
||||||
});
|
});
|
||||||
|
|
||||||
export * from './definitions';
|
export * from './definitions';
|
||||||
|
14
src/web.ts
14
src/web.ts
@ -3,8 +3,16 @@ import { WebPlugin } from '@capacitor/core';
|
|||||||
import type { PromoCodePlugin } from './definitions';
|
import type { PromoCodePlugin } from './definitions';
|
||||||
|
|
||||||
export class PromoCodeWeb extends WebPlugin implements PromoCodePlugin {
|
export class PromoCodeWeb extends WebPlugin implements PromoCodePlugin {
|
||||||
async echo(options: { value: string }): Promise<{ value: string }> {
|
async launchPromoCodeRedemptionFlow(): Promise<{ success: boolean; message?: string }> {
|
||||||
console.log('ECHO', options);
|
return {
|
||||||
return options;
|
success: false,
|
||||||
|
message: 'Promo code redemption is not supported on web',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async isPromoCodeSupported(): Promise<{ supported: boolean }> {
|
||||||
|
return {
|
||||||
|
supported: false,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user