我正在将一个 java 类翻译成 C#,但是,我不确定我是否正确地完成了它。在我下面的代码中,应该调用 RewardRequestListener 的 OnFinishedEvent,但是,它永远不会遇到断点或记录任何内容。
这是我的Java:
private RequestListener<Resource> mRequestListener = new RequestListener<Resource>() {
@Override
public void onFinished(Kiip manager, Resource response) {
if (response != null) {
if (mRewardActionToggle.isChecked()) {
manager.showResource(response);
} else {
toast("Reward Queued");
mResources.add(response);
}
} else {
toast("No Reward");
}
}
@Override
public void onError(Kiip manager, KiipException error) {
toast("error (" + error.getCode() + ") " + error.getMessage());
}
};
这是我的 C#:
private static readonly string TAG = "example";
private Button mUnlockAchievement, mSaveLeaderboard, mShowNotification, mShowFullscreen, mGetActivePromos, mNewActivity;
private EditText mAchievementId, mLeaderboardId;
private static ToggleButton mPositionToggle, mRewardActionToggle;
private List<ME.Kiip.Api.Resource> mResources = new List<ME.Kiip.Api.Resource>();
private RewardRequestListener mRewardsListener;
private ActivePromosRequestListener mActivePromosListener;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
mRewardsListener = new RewardRequestListener(this);
}
class RewardRequestListener : Kiip.IRequestListener
{
ExampleActivity example = new ExampleActivity();
public RewardRequestListener(ExampleActivity example)
{
this.example = example;
}
public void OnError(Kiip p0, KiipException p1)
{
example.toast("error (" + p1.Code + ") " + p1.Message);
}
public void OnFinished(Kiip p0, Java.Lang.Object p1)
{
ME.Kiip.Api.Resource response = p1 as ME.Kiip.Api.Resource;
if (response != null)
{
if (mRewardActionToggle.Checked)
{
p0.ShowResource(response);
}
else
{
example.mResources.Add(response);
}
}
else
{
example.toast("No Reward");
}
}
public IntPtr Handle { get; set; }
public void Dispose()
{
}
}
public void OnClick(View v)
{
Kiip manager = Kiip.Instance;
switch (v.Id)
{
case Resource.Id.unlockAchievement:
manager.UnlockAchievement(mAchievementId.Text, mRewardsListener);
break;
}
}