导航菜单

页面标题

页面副标题

Rilo v2.0.21 - SudGameViewModel.java 源代码

正在查看: Rilo v2.0.21 应用的 SudGameViewModel.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.vdx.sud;

import android.app.Activity;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import androidx.lifecycle.MutableLiveData;
import com.stripe.android.model.PaymentMethodOptionsParams;
import com.stripe.android.stripe3ds2.transactions.MessageExtension;
import com.truecaller.android.sdk.network.ProfileService;
import com.truecaller.android.sdk.network.VerificationService;
import com.vdx.sud.BaseGameViewModel;
import com.vdx.sud.SudGameViewModel;
import com.vdx.sud.constants.Constants;
import com.vdx.sud.model.DataCallback;
import com.vdx.sud.model.LoadingScreen;
import com.vdx.sud.utils.SystemUtils;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.json.JSONObject;
import tech.sud.mgp.SudMGPWrapper.model.GameConfigModel;
import tech.sud.mgp.SudMGPWrapper.model.GameViewInfoModel;
import tech.sud.mgp.SudMGPWrapper.state.SudMGPMGState;
import tech.sud.mgp.core.ISudFSMStateHandle;
import timber.log.Timber;

public class SudGameViewModel extends BaseGameViewModel {
    public static final boolean GAME_IS_TEST_ENV = false;
    private DataCallback dataCallback;
    public GameViewInfoModel.GameViewRectModel gameViewRectModel;
    public String userId = "";
    public String sessionToken = "";
    public String languageCode = "en-US";
    public final MutableLiveData<View> gameViewLiveData = new MutableLiveData<>();
    private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    private boolean isPingUpdateInProgress = false;

    @Override
    protected boolean isTestEnv() {
        return false;
    }

    @Override
    protected void getCode(Activity activity, String str, String str2, BaseGameViewModel.GameGetCodeListener gameGetCodeListener) {
        OkHttpClient okHttpClient = new OkHttpClient();
        String packageName = (activity == null || activity.getPackageName() == null) ? "" : activity.getPackageName();
        okHttpClient.newCall(new Request.Builder().url("https://prod.myfriendapp.in:9090/game/sud/get-code").get().addHeader(ProfileService.KEY_REQUEST_HEADER, "Bearer " + this.sessionToken).header("app-version", String.valueOf(SystemUtils.getVersionCode())).header("PackageId", packageName).build()).enqueue(new AnonymousClass1(gameGetCodeListener));
    }

    class AnonymousClass1 implements Callback {
        final BaseGameViewModel.GameGetCodeListener val$listener;

        AnonymousClass1(BaseGameViewModel.GameGetCodeListener gameGetCodeListener) {
            this.val$listener = gameGetCodeListener;
        }

        public void onFailure(Call call, IOException iOException) {
            Handler handler = SudGameViewModel.this.handler;
            BaseGameViewModel.GameGetCodeListener gameGetCodeListener = this.val$listener;
            Objects.requireNonNull(gameGetCodeListener);
            handler.post(new SudGameViewModel$1$$ExternalSyntheticLambda0(gameGetCodeListener));
            SudGameViewModel.this.handler.post(new Runnable() {
                @Override
                public final void run() {
                    SudGameViewModel.AnonymousClass1.lambda$onFailure$0();
                }
            });
        }

        static void lambda$onFailure$0() {
            new LoadingScreen(false);
        }

        public void onResponse(Call call, Response response) {
            try {
                String string = ((ResponseBody) Objects.requireNonNull(response.body())).string();
                Log.e("TAG", "onResponse: " + string);
                JSONObject jSONObject = new JSONObject(string);
                final int i2 = jSONObject.getInt("ret_code");
                final String string2 = jSONObject.getJSONObject(MessageExtension.FIELD_DATA).getString(PaymentMethodOptionsParams.Blik.PARAM_CODE);
                SudGameViewModel.this.handler.postDelayed(new Runnable() {
                    @Override
                    public final void run() {
                        SudGameViewModel.AnonymousClass1.this.m1106lambda$onResponse$1$comvdxsudSudGameViewModel$1();
                    }
                }, 1000L);
                Handler handler = SudGameViewModel.this.handler;
                final BaseGameViewModel.GameGetCodeListener gameGetCodeListener = this.val$listener;
                handler.post(new Runnable() {
                    @Override
                    public final void run() {
                        SudGameViewModel.AnonymousClass1.lambda$onResponse$2(i2, gameGetCodeListener, string2);
                    }
                });
            } catch (Exception e2) {
                Log.e("TAG", "onResponse: Error " + e2);
                Handler handler2 = SudGameViewModel.this.handler;
                BaseGameViewModel.GameGetCodeListener gameGetCodeListener2 = this.val$listener;
                Objects.requireNonNull(gameGetCodeListener2);
                handler2.post(new SudGameViewModel$1$$ExternalSyntheticLambda0(gameGetCodeListener2));
                SudGameViewModel.this.handler.post(new Runnable() {
                    @Override
                    public final void run() {
                        SudGameViewModel.AnonymousClass1.this.m1107lambda$onResponse$3$comvdxsudSudGameViewModel$1();
                    }
                });
            }
        }

        void m1106lambda$onResponse$1$comvdxsudSudGameViewModel$1() {
            SudGameViewModel.this.updateData(new LoadingScreen(false));
        }

        static void lambda$onResponse$2(int i2, BaseGameViewModel.GameGetCodeListener gameGetCodeListener, String str) {
            if (i2 == 0) {
                gameGetCodeListener.onSuccess(str);
            } else {
                gameGetCodeListener.onFailed();
            }
        }

        void m1107lambda$onResponse$3$comvdxsudSudGameViewModel$1() {
            SudGameViewModel.this.updateData(new LoadingScreen(false));
        }
    }

    @Override
    protected String getAppId() {
        return Constants.SudMGP_APP_ID;
    }

    @Override
    protected String getAppKey() {
        return Constants.SudMGP_APP_KEY;
    }

    @Override
    protected String getLanguageCode() {
        return this.languageCode;
    }

    @Override
    protected void getGameRect(GameViewInfoModel gameViewInfoModel) {
        GameViewInfoModel.GameViewRectModel gameViewRectModel = this.gameViewRectModel;
        if (gameViewRectModel != null) {
            gameViewInfoModel.view_game_rect = gameViewRectModel;
        }
    }

    public GameConfigModel getGameConfigModel() {
        return this.gameConfigModel;
    }

    @Override
    protected void onAddGameView(View view) {
        this.gameViewLiveData.setValue(view);
    }

    @Override
    protected void onRemoveGameView() {
        this.gameViewLiveData.setValue((Object) null);
    }

    public void notifyAPPCommonSelfInV2(boolean z, int i2, boolean z2, int i3) {
        this.sudFSTAPPDecorator.notifyAPPCommonSelfInV2(z, i2, z2, i3);
    }

    public void onGameMGCommonGameState(ISudFSMStateHandle iSudFSMStateHandle, SudMGPMGState.MGCommonGameState mGCommonGameState) {
        super.onGameMGCommonGameState(iSudFSMStateHandle, mGCommonGameState);
    }

    public void onGameMGCommonGameSettle(ISudFSMStateHandle iSudFSMStateHandle, SudMGPMGState.MGCommonGameSettle mGCommonGameSettle) {
        super.onGameMGCommonGameSettle(iSudFSMStateHandle, mGCommonGameSettle);
        Log.e("TAG", "onGameMGCommonGameSettle: settle " + iSudFSMStateHandle + " mode " + mGCommonGameSettle);
        updateData(mGCommonGameSettle);
    }

    public void onGameMGCommonAlert(ISudFSMStateHandle iSudFSMStateHandle, SudMGPMGState.MGCommonAlert mGCommonAlert) {
        super.onGameMGCommonAlert(iSudFSMStateHandle, mGCommonAlert);
        updateData(mGCommonAlert);
    }

    public void setDataCallback(DataCallback dataCallback) {
        this.dataCallback = dataCallback;
    }

    public void updateData(Object obj) {
        DataCallback dataCallback = this.dataCallback;
        if (dataCallback != null) {
            dataCallback.onDataChanged(obj);
        }
    }

    @Override
    protected String getUserId() {
        return this.userId;
    }

    public void canStartGame(Activity activity, BaseGameViewModel.GameGetCodeListener gameGetCodeListener) {
        new OkHttpClient().newCall(new Request.Builder().url("https://prod.myfriendapp.in:9090/game/ludo/get-ongoing-game").get().addHeader(ProfileService.KEY_REQUEST_HEADER, "Bearer " + this.sessionToken).header("app-version", String.valueOf(SystemUtils.getVersionCode())).header("PackageId", activity.getPackageName()).build()).enqueue(new AnonymousClass2(gameGetCodeListener));
    }

    class AnonymousClass2 implements Callback {
        final BaseGameViewModel.GameGetCodeListener val$listener;

        AnonymousClass2(BaseGameViewModel.GameGetCodeListener gameGetCodeListener) {
            this.val$listener = gameGetCodeListener;
        }

        public void onFailure(Call call, IOException iOException) {
            Handler handler = SudGameViewModel.this.handler;
            BaseGameViewModel.GameGetCodeListener gameGetCodeListener = this.val$listener;
            Objects.requireNonNull(gameGetCodeListener);
            handler.post(new SudGameViewModel$1$$ExternalSyntheticLambda0(gameGetCodeListener));
            SudGameViewModel.this.handler.post(new Runnable() {
                @Override
                public final void run() {
                    SudGameViewModel.AnonymousClass2.lambda$onFailure$0();
                }
            });
        }

        static void lambda$onFailure$0() {
            new LoadingScreen(false);
        }

        public void onResponse(Call call, Response response) {
            try {
                Timber.e("Response Code Ludo  %s", new Object[]{Integer.valueOf(response.code())});
                if (response.isSuccessful()) {
                    if (response.body() != null) {
                        final String string = response.body().string();
                        if (!string.isEmpty()) {
                            Handler handler = SudGameViewModel.this.handler;
                            final BaseGameViewModel.GameGetCodeListener gameGetCodeListener = this.val$listener;
                            handler.post(new Runnable() {
                                @Override
                                public final void run() {
                                    BaseGameViewModel.GameGetCodeListener.this.onSuccess(string);
                                }
                            });
                        } else {
                            Handler handler2 = SudGameViewModel.this.handler;
                            BaseGameViewModel.GameGetCodeListener gameGetCodeListener2 = this.val$listener;
                            Objects.requireNonNull(gameGetCodeListener2);
                            handler2.post(new SudGameViewModel$1$$ExternalSyntheticLambda0(gameGetCodeListener2));
                        }
                    } else {
                        Timber.e("Response Code Ludo Null", new Object[0]);
                        Handler handler3 = SudGameViewModel.this.handler;
                        BaseGameViewModel.GameGetCodeListener gameGetCodeListener3 = this.val$listener;
                        Objects.requireNonNull(gameGetCodeListener3);
                        handler3.post(new SudGameViewModel$1$$ExternalSyntheticLambda0(gameGetCodeListener3));
                    }
                } else {
                    Handler handler4 = SudGameViewModel.this.handler;
                    BaseGameViewModel.GameGetCodeListener gameGetCodeListener4 = this.val$listener;
                    Objects.requireNonNull(gameGetCodeListener4);
                    handler4.post(new SudGameViewModel$1$$ExternalSyntheticLambda0(gameGetCodeListener4));
                }
            } catch (Exception e2) {
                Timber.e(e2, "Response Code Ludo Error ", new Object[0]);
                Handler handler5 = SudGameViewModel.this.handler;
                BaseGameViewModel.GameGetCodeListener gameGetCodeListener5 = this.val$listener;
                Objects.requireNonNull(gameGetCodeListener5);
                handler5.post(new SudGameViewModel$1$$ExternalSyntheticLambda0(gameGetCodeListener5));
                SudGameViewModel.this.handler.post(new Runnable() {
                    @Override
                    public final void run() {
                        SudGameViewModel.AnonymousClass2.this.m1108lambda$onResponse$2$comvdxsudSudGameViewModel$2();
                    }
                });
            }
        }

        void m1108lambda$onResponse$2$comvdxsudSudGameViewModel$2() {
            SudGameViewModel.this.updateData(new LoadingScreen(false));
        }
    }

    void resign(Activity activity, String str) {
        new OkHttpClient().newCall(new Request.Builder().url("https://prod.myfriendapp.in:9090/game/ludo/resign-match").post(new FormBody.Builder().add("gameRoomId", str).build()).addHeader(ProfileService.KEY_REQUEST_HEADER, "Bearer " + this.sessionToken).header("app-version", String.valueOf(SystemUtils.getVersionCode())).header("PackageId", activity.getPackageName()).build()).enqueue(new Callback() {
            public void onFailure(Call call, IOException iOException) {
            }

            public void onResponse(Call call, Response response) {
                try {
                    Timber.e("Response Code Ludo  %s", new Object[]{Integer.valueOf(response.code())});
                    if (response.isSuccessful()) {
                        if (response.body() != null) {
                            Timber.e("Resign success", new Object[0]);
                        } else {
                            Timber.e("Response Code Ludo Null", new Object[0]);
                        }
                    }
                } catch (Exception e2) {
                    Timber.e(e2, "Response Code Ludo Error ", new Object[0]);
                }
            }
        });
    }

    public void startPingUpdateScheduler(final Activity activity, final Long l, final String str) {
        this.scheduler.scheduleWithFixedDelay(new Runnable() {
            @Override
            public final void run() {
                SudGameViewModel.this.m1105lambda$startPingUpdateScheduler$0$comvdxsudSudGameViewModel(activity, l, str);
            }
        }, 0L, 2L, TimeUnit.SECONDS);
    }

    void m1105lambda$startPingUpdateScheduler$0$comvdxsudSudGameViewModel(Activity activity, Long l, String str) {
        if (this.isPingUpdateInProgress) {
            return;
        }
        this.isPingUpdateInProgress = true;
        updatePing(activity, l, str);
    }

    private void updatePing(Activity activity, Long l, String str) {
        Response execute;
        OkHttpClient okHttpClient = new OkHttpClient();
        String packageName = activity.getPackageName();
        Request.Builder builder = new Request.Builder().url("https://prod.myfriendapp.in:9090/streamer-user-game/ping?entityId=" + l + "&entityType=" + str).get();
        StringBuilder sb = new StringBuilder();
        sb.append("Bearer ");
        sb.append(this.sessionToken);
        Request build = builder.addHeader(ProfileService.KEY_REQUEST_HEADER, sb.toString()).header("app-version", String.valueOf(SystemUtils.getVersionCode())).header("PackageId", packageName).build();
        try {
            try {
                execute = okHttpClient.newCall(build).execute();
            } catch (IOException e2) {
                Timber.e(e2, "Ping update API call failed", new Object[0]);
            }
            try {
                Timber.e("Response Code Ludo  %s", new Object[]{Integer.valueOf(execute.code())});
                if (!execute.isSuccessful()) {
                    Timber.e("Error in updating ping: %s", new Object[]{execute.message()});
                } else if (execute.body() != null) {
                    String extractStatusFromResponse = extractStatusFromResponse(execute.body().string());
                    Timber.e("Game status from response: %s", new Object[]{extractStatusFromResponse});
                    if (!"STARTED".equals(extractStatusFromResponse)) {
                        Timber.e("Status is no longer 'STARTED'. Stopping ping update process.", new Object[0]);
                        stopPingUpdateScheduler();
                    }
                } else {
                    Timber.e("Response body is null.", new Object[0]);
                }
                if (execute != null) {
                    execute.close();
                }
            } catch (Throwable th) {
                if (execute != null) {
                    try {
                        execute.close();
                    } catch (Throwable th2) {
                        th.addSuppressed(th2);
                    }
                }
                throw th;
            }
        } finally {
            this.isPingUpdateInProgress = false;
        }
    }

    private String extractStatusFromResponse(String str) {
        try {
            return new JSONObject(str).optString(VerificationService.JSON_KEY_STATUS, "");
        } catch (Exception e2) {
            Timber.e(e2, "Error parsing response body to extract status", new Object[0]);
            return "";
        }
    }

    public void stopPingUpdateScheduler() {
        if (this.scheduler.isShutdown()) {
            return;
        }
        this.scheduler.shutdown();
        Timber.e("Ping update scheduler has been stopped.", new Object[0]);
    }
}