Commit f355b68f by Minhan Jeong

매개변수 추가

parent 395ab83b
...@@ -136,9 +136,9 @@ ...@@ -136,9 +136,9 @@
mEntryActivity = new EntryActivity(this); mEntryActivity = new EntryActivity(this);
} }
public void AndroidThunkJava_QueryProducts() public void AndroidThunkJava_QueryProducts(String[] productIds)
{ {
mEntryActivity.QueryProducts(); mEntryActivity.QueryProducts(productIds);
} }
public void AndroidThunkJava_Payment(String productId) public void AndroidThunkJava_Payment(String productId)
......
...@@ -68,36 +68,50 @@ public class EntryActivity extends AppCompatActivity ...@@ -68,36 +68,50 @@ public class EntryActivity extends AppCompatActivity
}); });
} }
public void QueryProducts() public void QueryProducts(String[] ids)
{ {
List<String> productIds = new ArrayList<String>(); List<String> productIds = new ArrayList<String>();
productIds.add("rmvw2021_coin_1"); for (int i = 0; i < ids.length; i++)
productIds.add("rmvw2021_coin_2"); {
productIds.add("rmvw2021_coin_3"); productIds.add(ids[i]);
productIds.add("rmvw2021_coin_4"); }
productIds.add("rmvw2021_coin_5");
productIds.add("rmvw2021_coin_6");
IapRequestHelper.obtainProductInfo(mClient, productIds, IapClient.PriceType.IN_APP_CONSUMABLE, new IapApiCallback<ProductInfoResult>() { IapRequestHelper.obtainProductInfo(mClient, productIds, IapClient.PriceType.IN_APP_CONSUMABLE, new IapApiCallback<ProductInfoResult>() {
@Override @Override
public void onSuccess(ProductInfoResult result) { public void onSuccess(ProductInfoResult result) {
Log.i(TAG, "QueryProductsobtainProductInfo, success"); Log.i(TAG, "QueryProductsobtainProductInfo, success");
if (result == null) { if (result == null) {
nativeQueryProductsResult(false); nativeQueryProductsResult(false, null, null, null);
return; return;
} }
if (result.getProductInfoList() != null) { if (result.getProductInfoList() != null) {
ArrayList<String> productIds = new ArrayList<String>();
ArrayList<String> prices = new ArrayList<String>();
ArrayList<String> currencyCodes = new ArrayList<String>();
consumableProducts = result.getProductInfoList(); consumableProducts = result.getProductInfoList();
Log.i(TAG, "consumableProducts->" + consumableProducts.toArray().length); Log.i(TAG, "consumableProducts->" + consumableProducts.toArray().length);
for (int i = 0; i < consumableProducts.toArray().length; i++)
{
ProductInfo productInfo = consumableProducts.get(i);
productIds.add(productInfo.getProductId());
prices.add(productInfo.getPrice());
currencyCodes.add(productInfo.getCurrency());
}
nativeQueryProductsResult(true, productIds.toArray(new String[productIds.size()]), prices.toArray(new String[prices.size()]), currencyCodes.toArray(new String[currencyCodes.size()]));
}
else
{
nativeQueryProductsResult(true, null, null, null);
} }
nativeQueryProductsResult(true);
} }
@Override @Override
public void onFail(Exception e) { public void onFail(Exception e) {
Log.e(TAG, "QueryProducts->obtainProductInfo: " + e.getMessage()); Log.e(TAG, "QueryProducts->obtainProductInfo: " + e.getMessage());
ExceptionHandle.handle(mActivity, e); ExceptionHandle.handle(mActivity, e);
nativeQueryProductsResult(false); nativeQueryProductsResult(false, null, null, null);
} }
}); });
} }
...@@ -248,6 +262,6 @@ public class EntryActivity extends AppCompatActivity ...@@ -248,6 +262,6 @@ public class EntryActivity extends AppCompatActivity
} }
public native void nativeGetIapClientResult(boolean success); public native void nativeGetIapClientResult(boolean success);
public native void nativeQueryProductsResult(boolean success); public native void nativeQueryProductsResult(boolean success, String[] productIds, String[] priceTexts, String[] currencyCodes);
public native void nativePaymentResult(String purchaseToken, String productId); public native void nativePaymentResult(String purchaseToken, String productId);
} }
\ No newline at end of file
...@@ -100,29 +100,63 @@ UHmsQueryProducts::~UHmsQueryProducts() ...@@ -100,29 +100,63 @@ UHmsQueryProducts::~UHmsQueryProducts()
} }
} }
UHmsQueryProducts* UHmsQueryProducts::QueryProducts() UHmsQueryProducts* UHmsQueryProducts::QueryProducts(const TArray<FString>& ProductIds)
{ {
UHmsQueryProducts* BPNode = NewObject<UHmsQueryProducts>(); UHmsQueryProducts* BPNode = NewObject<UHmsQueryProducts>();
BPNode->ProductIds = ProductIds;
s_hmsQueryProductses.insert(BPNode); s_hmsQueryProductses.insert(BPNode);
return BPNode; return BPNode;
} }
#if PLATFORM_ANDROID #if PLATFORM_ANDROID
static void ReqQueryProducts() static void ReqQueryProducts(const TArray<FString>& ProductIds)
{ {
if (JNIEnv* Env = FAndroidApplication::GetJavaEnv()) if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
{ {
static jmethodID QueryProductsMethod = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_QueryProducts", "()V", false); static jmethodID QueryProductsMethod = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_QueryProducts", "([Ljava/lang/String;)V", false);
if (QueryProductsMethod) if (QueryProductsMethod)
{ {
UE_LOG(LogTemp, Log, TEXT("Find AndroidThunkJava_QueryProducts")); UE_LOG(LogTemp, Log, TEXT("Find AndroidThunkJava_QueryProducts"));
FJavaWrapper::CallVoidMethod(Env, FJavaWrapper::GameActivityThis, QueryProductsMethod);
auto jProductIds = NewScopedJavaObject(Env, (jobjectArray)Env->NewObjectArray(ProductIds.Num(), FJavaWrapper::JavaStringClass, nullptr));
for (uint32 Param = 0; Param < ProductIds.Num(); Param++)
{
auto StringValue = FJavaHelper::ToJavaString(Env, ProductIds[Param]);
Env->SetObjectArrayElement(*jProductIds, Param, *StringValue);
}
FJavaWrapper::CallVoidMethod(Env, FJavaWrapper::GameActivityThis, QueryProductsMethod, *jProductIds);
} }
} }
} }
__attribute__((visibility("default"))) extern "C" void Java_com_Plugins_HuaweiSDK_activity_EntryActivity_nativeQueryProductsResult(JNIEnv* jenv, jobject thiz, jboolean success) __attribute__((visibility("default"))) extern "C" void Java_com_Plugins_HuaweiSDK_activity_EntryActivity_nativeQueryProductsResult(JNIEnv* jenv, jobject thiz, jboolean success, jobjectArray productIds, jobjectArray priceTexts, jobjectArray currencyCodes)
{ {
TArray<FHmsIapProductInfo> ProductInformations;
if ((bool)success)
{
jsize NumProducts = jenv->GetArrayLength(productIds);
jsize NumPriceTexts = jenv->GetArrayLength(priceTexts);
jsize NumCurrencyCodes = jenv->GetArrayLength(currencyCodes);
ensure((NumProducts == NumPriceTexts) && (NumProducts == NumCurrencyCodes));
for (jsize Idx = 0; Idx < NumProducts; Idx++)
{
FHmsIapProductInfo NewProductInfo;
NewProductInfo.ProductId = FJavaHelper::FStringFromLocalRef(jenv, (jstring)jenv->GetObjectArrayElement(productIds, Idx));
NewProductInfo.PriceText = FJavaHelper::FStringFromLocalRef(jenv, (jstring)jenv->GetObjectArrayElement(priceTexts, Idx));
NewProductInfo.CurrencyCode = FJavaHelper::FStringFromLocalRef(jenv, (jstring)jenv->GetObjectArrayElement(currencyCodes, Idx));
ProductInformations.Add(NewProductInfo);
UE_LOG(LogTemp, Log, TEXT("ProductId : %s, PriceText : %s, CurrencyCode : %s"),
*NewProductInfo.ProductId,
*NewProductInfo.PriceText,
*NewProductInfo.CurrencyCode);
}
}
DECLARE_CYCLE_STAT(TEXT("FSimpleDelegateGraphTask.Java_com_Plugins_HuaweiSDK_activity_EntryActivity_nativeQueryProductsResult"), STAT_FSimpleDelegateGraphTask_Java_com_Plugins_HuaweiSDK_activity_EntryActivity_nativeQueryProductsResult, STATGROUP_TaskGraphTasks); DECLARE_CYCLE_STAT(TEXT("FSimpleDelegateGraphTask.Java_com_Plugins_HuaweiSDK_activity_EntryActivity_nativeQueryProductsResult"), STAT_FSimpleDelegateGraphTask_Java_com_Plugins_HuaweiSDK_activity_EntryActivity_nativeQueryProductsResult, STATGROUP_TaskGraphTasks);
FSimpleDelegateGraphTask::CreateAndDispatchWhenReady( FSimpleDelegateGraphTask::CreateAndDispatchWhenReady(
FSimpleDelegateGraphTask::FDelegate::CreateLambda([=]() FSimpleDelegateGraphTask::FDelegate::CreateLambda([=]()
...@@ -132,14 +166,14 @@ __attribute__((visibility("default"))) extern "C" void Java_com_Plugins_HuaweiSD ...@@ -132,14 +166,14 @@ __attribute__((visibility("default"))) extern "C" void Java_com_Plugins_HuaweiSD
UHmsQueryProducts* hmsQueryProducts = NewObject<UHmsQueryProducts>(); UHmsQueryProducts* hmsQueryProducts = NewObject<UHmsQueryProducts>();
for (std::set<UHmsQueryProducts*>::iterator it = s_hmsQueryProductses.begin(); it != s_hmsQueryProductses.end(); it++) for (std::set<UHmsQueryProducts*>::iterator it = s_hmsQueryProductses.begin(); it != s_hmsQueryProductses.end(); it++)
{ {
(*it)->OnComplete.Broadcast(true); (*it)->OnComplete.Broadcast(true, ProductInformations);
} }
} }
else else
{ {
for (std::set<UHmsQueryProducts*>::iterator it = s_hmsQueryProductses.begin(); it != s_hmsQueryProductses.end(); it++) for (std::set<UHmsQueryProducts*>::iterator it = s_hmsQueryProductses.begin(); it != s_hmsQueryProductses.end(); it++)
{ {
(*it)->OnComplete.Broadcast(false); (*it)->OnComplete.Broadcast(false, ProductInformations);
} }
} }
...@@ -155,7 +189,7 @@ __attribute__((visibility("default"))) extern "C" void Java_com_Plugins_HuaweiSD ...@@ -155,7 +189,7 @@ __attribute__((visibility("default"))) extern "C" void Java_com_Plugins_HuaweiSD
void UHmsQueryProducts::Activate() void UHmsQueryProducts::Activate()
{ {
#if PLATFORM_ANDROID #if PLATFORM_ANDROID
ReqQueryProducts(); ReqQueryProducts(ProductIds);
#endif #endif
} }
......
...@@ -21,6 +21,12 @@ struct FHmsIapProductInfo ...@@ -21,6 +21,12 @@ struct FHmsIapProductInfo
UPROPERTY(BlueprintReadWrite, Category=ProductInfo) UPROPERTY(BlueprintReadWrite, Category=ProductInfo)
FString ProductId; FString ProductId;
UPROPERTY(BlueprintReadWrite, Category=ProductInfo)
FString PriceText;
UPROPERTY(BlueprintReadWrite, Category=ProductInfo)
FString CurrencyCode;
}; };
USTRUCT(BlueprintType) USTRUCT(BlueprintType)
...@@ -58,7 +64,7 @@ public: ...@@ -58,7 +64,7 @@ public:
#pragma endregion #pragma endregion
#pragma region QueryProducts #pragma region QueryProducts
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FQueryProducts, bool, IsSuccess); DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FQueryProducts, bool, IsSuccess, const TArray<FHmsIapProductInfo>&, AvailablePurchaes);
UCLASS() UCLASS()
class HUAWEISDK_API UHmsQueryProducts : public UBlueprintAsyncActionBase class HUAWEISDK_API UHmsQueryProducts : public UBlueprintAsyncActionBase
{ {
...@@ -69,13 +75,15 @@ public: ...@@ -69,13 +75,15 @@ public:
~UHmsQueryProducts(); ~UHmsQueryProducts();
UFUNCTION(BlueprintCallable, meta=(BlueprintInternalUseOnly="true"), Category="HuaweiIap") UFUNCTION(BlueprintCallable, meta=(BlueprintInternalUseOnly="true"), Category="HuaweiIap")
static UHmsQueryProducts* QueryProducts(); static UHmsQueryProducts* QueryProducts(const TArray<FString>& ProductIds);
virtual void Activate() override; virtual void Activate() override;
UPROPERTY(BlueprintAssignable) UPROPERTY(BlueprintAssignable)
FQueryProducts OnComplete; FQueryProducts OnComplete;
private:
TArray<FString> ProductIds;
}; };
#pragma endregion #pragma endregion
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment