导航菜单

页面标题

页面副标题

Clash Legends v0.0.1 - PlayFragment.java 源代码

正在查看: Clash Legends v0.0.1 应用的 PlayFragment.java JAVA 源代码文件

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


package com.clash.legends.ui.fragments;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.android.volley.AuthFailureError;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.clash.legends.models.BanerData;
import com.clash.legends.models.CurrentUser;
import com.clash.legends.models.GameData;
import com.clash.legends.ui.activities.AnnouncementActivity;
import com.clash.legends.ui.activities.MainActivity;
import com.clash.legends.ui.activities.MyWalletActivity;
import com.clash.legends.ui.activities.SelectedGameActivity;
import com.clash.legends.ui.adapters.GameAdapter;
import com.clash.legends.ui.adapters.TestFragmentAdapter;
import com.clash.legends.utils.KKViewPager;
import com.clash.legends.utils.LocaleHelper;
import com.clash.legends.utils.UserLocalStore;
import com.facebook.shimmer.ShimmerFrameLayout;
import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Timer;
import java.util.TimerTask;
import me.toptas.fancyshowcase.FancyShowCaseView;
import me.toptas.fancyshowcase.FocusShape;
import me.toptas.fancyshowcase.listener.DismissListener;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class PlayFragment extends Fragment {
    LinearLayout allGameLl;
    LinearLayout announcecv;
    TextView announcement;
    TextView appname;
    JSONArray arr;
    TextView balInPlay;
    CardView balance;
    List<BanerData> banerData;
    CardView completed;
    Context context;
    int currentPage = 0;
    RequestQueue dQueue;
    GameAdapter gameAdapter;
    List<GameData> gameData;
    RecyclerView gameRv;
    KKViewPager mPager;
    RequestQueue mQueue;
    private StaggeredGridLayoutManager manager;
    TextView noUpcoming;
    CardView ongoing;
    SwipeRefreshLayout pullToRefresh;
    Resources resources;
    RequestQueue sQueue;
    ShimmerFrameLayout shimer;
    SharedPreferences sp;
    TabLayout tabLayout;
    Timer timer;
    CardView upcoming;
    CurrentUser user;
    UserLocalStore userLocalStore;
    LinearLayout visiblelinear;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View root = inflater.inflate(2131558759, container, false);
        SharedPreferences sharedPreferences = requireActivity().getSharedPreferences("tabitem", 0);
        this.sp = sharedPreferences;
        final SharedPreferences.Editor editor1111 = sharedPreferences.edit();
        String pagenumber = this.sp.getString("TAB", "");
        this.gameData = new ArrayList();
        this.gameRv = root.findViewById(2131361909);
        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(3, 1);
        this.manager = staggeredGridLayoutManager;
        this.gameRv.setLayoutManager(staggeredGridLayoutManager);
        Context locale = LocaleHelper.setLocale(getContext());
        this.context = locale;
        this.resources = locale.getResources();
        this.tabLayout = root.findViewById(2131363436);
        this.visiblelinear = (LinearLayout) root.findViewById(2131363763);
        if (TextUtils.equals(pagenumber, "1")) {
            ((TabLayout.Tab) Objects.requireNonNull(this.tabLayout.getTabAt(1))).select();
        } else {
            ((TabLayout.Tab) Objects.requireNonNull(this.tabLayout.getTabAt(0))).select();
        }
        this.ongoing = root.findViewById(2131362886);
        this.upcoming = root.findViewById(2131363714);
        this.completed = root.findViewById(2131362172);
        this.ongoing.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PlayFragment.this.m41xb656b8b9(view);
            }
        });
        this.upcoming.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PlayFragment.this.m42x50f77b3a(view);
            }
        });
        this.completed.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PlayFragment.this.m43xeb983dbb(view);
            }
        });
        this.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            public void onTabSelected(TabLayout.Tab tab) {
                PlayFragment.this.gameRv.removeAllViews();
                editor1111.putString("TAB", String.valueOf(tab.getPosition()));
                editor1111.apply();
                try {
                    PlayFragment.this.gameAdapter.notifyDataSetChanged();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                PlayFragment.this.checkgame();
            }

            public void onTabUnselected(TabLayout.Tab tab) {
            }

            public void onTabReselected(TabLayout.Tab tab) {
                Log.d("tab contest re", String.valueOf(tab.getPosition()));
            }
        });
        SwipeRefreshLayout findViewById = root.findViewById(2131363102);
        this.pullToRefresh = findViewById;
        findViewById.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            public final void onRefresh() {
                PlayFragment.this.refresh();
            }
        });
        this.mPager = root.findViewById(2131362561);
        this.banerData = new ArrayList();
        ShimmerFrameLayout findViewById2 = root.findViewById(2131363330);
        this.shimer = findViewById2;
        findViewById2.showShimmer(true);
        UserLocalStore userLocalStore = new UserLocalStore(getContext());
        this.userLocalStore = userLocalStore;
        this.user = userLocalStore.getLoggedInUser();
        this.appname = (TextView) root.findViewById(2131361950);
        this.allGameLl = (LinearLayout) root.findViewById(2131361905);
        this.balInPlay = (TextView) root.findViewById(2131362012);
        CardView findViewById3 = root.findViewById(2131362008);
        this.balance = findViewById3;
        findViewById3.setEnabled(true);
        this.balInPlay.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PlayFragment.this.m44x8639003c(view);
            }
        });
        this.appname.setText(this.resources.getString(2131886168));
        this.announcement = (TextView) root.findViewById(2131361930);
        LinearLayout linearLayout = (LinearLayout) root.findViewById(2131361929);
        this.announcecv = linearLayout;
        linearLayout.setVisibility(8);
        this.announcement.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PlayFragment.this.m45x20d9c2bd(view);
            }
        });
        Announcement();
        RequestQueue newRequestQueue = Volley.newRequestQueue(getContext());
        this.mQueue = newRequestQueue;
        newRequestQueue.getCache().clear();
        this.noUpcoming = (TextView) root.findViewById(2131362869);
        ((TabLayout.Tab) Objects.requireNonNull(this.tabLayout.getTabAt(0))).setText(this.resources.getString(2131887043));
        ((TabLayout.Tab) Objects.requireNonNull(this.tabLayout.getTabAt(1))).setText(this.resources.getString(2131887005));
        this.dQueue = Volley.newRequestQueue(getContext());
        String url = this.resources.getString(2131886167) + "dashboard/" + this.user.getMemberid();
        JsonObjectRequest drequest = new JsonObjectRequest(url, null, new Response.Listener() {
            public final void onResponse(Object obj) {
                PlayFragment.this.m46xbb7a853e((JSONObject) obj);
            }
        }, new Response.ErrorListener() {
            public final void onErrorResponse(VolleyError volleyError) {
                Log.e("**VolleyError", "error" + volleyError.getMessage());
            }
        }) {
            protected Map<String, String> getParams() throws AuthFailureError {
                return super.getParams();
            }

            public Map<String, String> getHeaders() {
                Map<String, String> headers = new HashMap<>();
                CurrentUser user = PlayFragment.this.userLocalStore.getLoggedInUser();
                String token = "Bearer " + user.getToken();
                headers.put("Content-Type", "application/json");
                headers.put("Authorization", token);
                Log.d("sony", token);
                headers.put("x-localization", LocaleHelper.getPersist(PlayFragment.this.context));
                return headers;
            }
        };
        drequest.setShouldCache(false);
        this.dQueue.add(drequest);
        viewallslider();
        return root;
    }

    void m41xb656b8b9(View view) {
        Intent intent = new Intent((Context) getActivity(), (Class<?>) SelectedGameActivity.class);
        SharedPreferences sp1 = getActivity().getSharedPreferences("gameinfo", 0);
        SharedPreferences.Editor editor = sp1.edit();
        editor.putString("gametitle", this.resources.getString(2131886607));
        editor.putString("gameid", "not");
        editor.apply();
        intent.putExtra("selected_tab", 0);
        startActivity(intent);
    }

    void m42x50f77b3a(View view) {
        Intent intent = new Intent((Context) getActivity(), (Class<?>) SelectedGameActivity.class);
        SharedPreferences sp1 = getActivity().getSharedPreferences("gameinfo", 0);
        SharedPreferences.Editor editor = sp1.edit();
        editor.putString("gametitle", this.resources.getString(2131886607));
        editor.putString("gameid", "not");
        editor.apply();
        intent.putExtra("selected_tab", 1);
        startActivity(intent);
    }

    void m43xeb983dbb(View view) {
        Intent intent = new Intent((Context) getActivity(), (Class<?>) SelectedGameActivity.class);
        SharedPreferences sp1 = getActivity().getSharedPreferences("gameinfo", 0);
        SharedPreferences.Editor editor = sp1.edit();
        editor.putString("gametitle", this.resources.getString(2131886607));
        editor.putString("gameid", "not");
        editor.apply();
        intent.putExtra("selected_tab", 2);
        startActivity(intent);
    }

    void m44x8639003c(View v) {
        Intent intent = new Intent(getContext(), (Class<?>) MyWalletActivity.class);
        intent.putExtra("FROM", "PLAY");
        startActivity(intent);
    }

    void m45x20d9c2bd(View v) {
        startActivity(new Intent((Context) getActivity(), (Class<?>) AnnouncementActivity.class));
    }

    void m46xbb7a853e(JSONObject response) {
        String win;
        String joinm;
        String totalMoney;
        try {
            Log.d("dash", response.toString());
            JSONObject memobj = new JSONObject(response.getString("member"));
            if (TextUtils.equals(memobj.getString("member_status"), "0")) {
                if (!this.user.getUsername().equals("") && !this.user.getPassword().equals("")) {
                    this.userLocalStore.clearUserData();
                    Toast.makeText((Context) getActivity(), (CharSequence) this.resources.getString(2131887105), 0).show();
                    startActivity(new Intent((Context) getActivity(), (Class<?>) MainActivity.class));
                    return;
                }
                return;
            }
            String winMoney = memobj.getString("wallet_balance");
            String joinMoney = memobj.getString("join_money");
            if (TextUtils.equals(winMoney, "null")) {
                winMoney = "0";
            }
            if (TextUtils.equals(joinMoney, "null")) {
                joinMoney = "0";
            }
            if (isDouble(winMoney)) {
                win = String.format("%.2f", Double.valueOf(Double.parseDouble(winMoney)));
            } else {
                win = String.valueOf(Integer.parseInt(winMoney));
            }
            if (isDouble(joinMoney)) {
                joinm = String.format("%.2f", Double.valueOf(Double.parseDouble(joinMoney)));
            } else {
                joinm = String.valueOf(Integer.parseInt(joinMoney));
            }
            if (win.startsWith("0")) {
                if (isDouble(joinm)) {
                    totalMoney = String.valueOf(Double.parseDouble(joinm));
                } else {
                    totalMoney = String.valueOf(Integer.parseInt(joinm));
                }
            } else if (joinm.startsWith("-")) {
                if (isDouble(win)) {
                    totalMoney = String.valueOf(Double.parseDouble(win));
                } else {
                    totalMoney = String.valueOf(Integer.parseInt(win));
                }
            } else if (isDouble(win) && isDouble(joinm)) {
                totalMoney = String.valueOf(Double.parseDouble(win) + Double.parseDouble(joinm));
            } else {
                totalMoney = String.valueOf(Integer.parseInt(win) + Integer.parseInt(joinm));
            }
            if (isDouble(totalMoney)) {
                totalMoney = String.format("%.2f", Double.valueOf(Double.parseDouble(totalMoney)));
            }
            this.balInPlay.setText(totalMoney);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    boolean isDouble(String str) {
        try {
            Double.parseDouble(str);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    public void viewallgame() {
        RequestQueue newRequestQueue = Volley.newRequestQueue(getContext());
        this.mQueue = newRequestQueue;
        newRequestQueue.getCache().clear();
        String jurl = this.resources.getString(2131886167) + "all_game";
        final UserLocalStore userLocalStore = new UserLocalStore(getContext());
        JsonObjectRequest request = new JsonObjectRequest(0, jurl, null, new Response.Listener() {
            public final void onResponse(Object obj) {
                PlayFragment.this.m47lambda$viewallgame$7$comclashlegendsuifragmentsPlayFragment((JSONObject) obj);
            }
        }, new Response.ErrorListener() {
            public final void onErrorResponse(VolleyError volleyError) {
                Log.e("**VolleyError", "error" + volleyError.getMessage());
            }
        }) {
            protected Map<String, String> getParams() throws AuthFailureError {
                return super.getParams();
            }

            public Map<String, String> getHeaders() {
                Map<String, String> headers = new HashMap<>();
                CurrentUser user = userLocalStore.getLoggedInUser();
                String token = "Bearer " + user.getToken();
                headers.put("Content-Type", "application/json");
                headers.put("Authorization", token);
                Log.d("sx", token);
                headers.put("x-localization", LocaleHelper.getPersist(PlayFragment.this.context));
                return headers;
            }
        };
        request.setShouldCache(false);
        this.mQueue.add(request);
    }

    void m47lambda$viewallgame$7$comclashlegendsuifragmentsPlayFragment(JSONObject response) {
        try {
            this.arr = response.getJSONArray("all_game");
            checkgame();
            JSON_PARSE_DATA_AFTER_WEBCALL(this.arr);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                PlayFragment.this.shimer.setVisibility(8);
            }
        }, 1000L);
    }

    public void checkgame() {
        this.noUpcoming.setVisibility(8);
        this.gameRv.setVisibility(0);
        List<String> issues = new ArrayList<>();
        int list = this.arr.length();
        for (int i = 0; i < list; i++) {
            try {
                JSONObject json = this.arr.getJSONObject(i);
                if (TextUtils.equals(this.sp.getString("TAB", ""), json.getString("game_type"))) {
                    issues.add(String.valueOf(i));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (issues.isEmpty()) {
            this.gameRv.setVisibility(8);
            if (this.noUpcoming.getVisibility() != 0) {
                this.noUpcoming.setVisibility(0);
            }
        }
        issues.clear();
    }

    public void JSON_PARSE_DATA_AFTER_WEBCALL(JSONArray array) {
        for (int i = 0; i < array.length(); i++) {
            try {
                JSONObject json = array.getJSONObject(i);
                GameData data = new GameData(json.getString("game_id"), json.getString("game_name"), json.getString("game_image"), json.getString("status"), json.getString("total_upcoming_match"), json.getString("game_type"), json.getString("total_upcoming_challenge"), json.getString("package_name"), json.getString("coming_soon"));
                this.gameData.add(data);
                GameAdapter gameAdapter = new GameAdapter(getActivity(), this.gameData);
                this.gameAdapter = gameAdapter;
                gameAdapter.notifyDataSetChanged();
                this.gameRv.setAdapter(this.gameAdapter);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    public void refresh() {
        requireActivity().finish();
        requireActivity().overridePendingTransition(0, 0);
        Intent intent = requireActivity().getIntent();
        intent.putExtra("N", "1");
        requireActivity().startActivity(intent);
        requireActivity().overridePendingTransition(0, 0);
    }

    public void Announcement() {
        RequestQueue newRequestQueue = Volley.newRequestQueue(requireContext());
        this.mQueue = newRequestQueue;
        newRequestQueue.getCache().clear();
        String vurl = this.resources.getString(2131886167) + "announcement";
        final UserLocalStore userLocalStore = new UserLocalStore(requireContext());
        JsonObjectRequest request = new JsonObjectRequest(0, vurl, null, new Response.Listener() {
            public final void onResponse(Object obj) {
                PlayFragment.this.m40xad9fc369((JSONObject) obj);
            }
        }, new Response.ErrorListener() {
            public final void onErrorResponse(VolleyError volleyError) {
                Log.e("**VolleyError", "error" + volleyError.getMessage());
            }
        }) {
            protected Map<String, String> getParams() throws AuthFailureError {
                return super.getParams();
            }

            public Map<String, String> getHeaders() {
                Map<String, String> headers = new HashMap<>();
                CurrentUser user = userLocalStore.getLoggedInUser();
                String token = "Bearer " + user.getToken();
                headers.put("Content-Type", "application/json");
                headers.put("Authorization", token);
                headers.put("x-localization", LocaleHelper.getPersist(PlayFragment.this.context));
                return headers;
            }
        };
        request.setShouldCache(false);
        this.mQueue.add(request);
    }

    void m40xad9fc369(JSONObject response) {
        try {
            Log.d("announce", response.toString());
            JSONArray arr = response.getJSONArray("announcement");
            if (!TextUtils.equals(response.getString("announcement"), "[]")) {
                this.announcecv.setVisibility(8);
            } else {
                this.announcecv.setVisibility(8);
                this.announcement.setText(Html.fromHtml(this.resources.getString(2131886623)));
            }
            this.announcement.setClickable(true);
            this.announcement.setMovementMethod(LinkMovementMethod.getInstance());
            JSON_PARSE_DATA_AFTER_WEBCALLannounccement(arr);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public void viewallslider() {
        RequestQueue newRequestQueue = Volley.newRequestQueue(getActivity());
        this.sQueue = newRequestQueue;
        newRequestQueue.getCache().clear();
        String kurl = this.resources.getString(2131886167) + "slider";
        final UserLocalStore userLocalStore = new UserLocalStore(getContext());
        JsonObjectRequest srequest = new JsonObjectRequest(0, kurl, null, new Response.Listener() {
            public final void onResponse(Object obj) {
                PlayFragment.this.m48xad8ced4((JSONObject) obj);
            }
        }, new Response.ErrorListener() {
            public final void onErrorResponse(VolleyError volleyError) {
                Log.e("**VolleyError", "error" + volleyError.getMessage());
            }
        }) {
            protected Map<String, String> getParams() throws AuthFailureError {
                return super.getParams();
            }

            public Map<String, String> getHeaders() {
                Map<String, String> headers = new HashMap<>();
                CurrentUser user = userLocalStore.getLoggedInUser();
                String token = "Bearer " + user.getToken();
                headers.put("Content-Type", "application/json");
                headers.put("Authorization", token);
                headers.put("x-localization", "en");
                return headers;
            }
        };
        srequest.setShouldCache(false);
        this.sQueue.add(srequest);
        viewallgame();
    }

    void m48xad8ced4(JSONObject response) {
        try {
            Log.d("slider", response.toString());
            JSONArray arr = response.getJSONArray("slider");
            if (TextUtils.equals(response.getString("slider"), "[]")) {
                this.mPager.setVisibility(8);
                this.visiblelinear.setVisibility(0);
            } else {
                this.mPager.setVisibility(0);
                this.visiblelinear.setVisibility(8);
            }
            JSON_PARSE_DATA_AFTER_WEBCALLslider(arr);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                PlayFragment.this.shimer.setVisibility(8);
            }
        }, 1000L);
    }

    public void JSON_PARSE_DATA_AFTER_WEBCALLslider(JSONArray array) {
        this.banerData.clear();
        for (int i = 0; i < array.length(); i++) {
            try {
                JSONObject json = array.getJSONObject(i);
                BanerData data = new BanerData(json.getString("slider_id"), json.getString("slider_title"), json.getString("slider_image"), json.getString("slider_link_type"), json.getString("slider_link"), json.getString("link_id"), json.getString("game_name"));
                this.banerData.add(data);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        this.mPager.setAdapter(new TestFragmentAdapter(requireActivity().getSupportFragmentManager(), getActivity(), this.banerData));
        this.mPager.setPageMargin(40);
        this.mPager.setAnimationEnabled(true);
        this.mPager.setFadeEnabled(true);
        this.mPager.setFadeFactor(0.6f);
        final Handler handler = new Handler();
        final Runnable Update = new Runnable() {
            @Override
            public void run() {
                if (PlayFragment.this.currentPage == PlayFragment.this.banerData.size()) {
                    PlayFragment.this.currentPage = 0;
                }
                KKViewPager kKViewPager = PlayFragment.this.mPager;
                PlayFragment playFragment = PlayFragment.this;
                int i2 = playFragment.currentPage;
                playFragment.currentPage = i2 + 1;
                kKViewPager.setCurrentItem(i2, true);
            }
        };
        Timer timer = new Timer();
        this.timer = timer;
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                handler.post(Update);
            }
        }, 2000L, 2000L);
    }

    public void JSON_PARSE_DATA_AFTER_WEBCALLannounccement(JSONArray array) {
        for (int i = 0; i < array.length(); i++) {
            this.announcecv.setVisibility(0);
            try {
                JSONObject json = array.getJSONObject(i);
                this.announcement.setText(Html.fromHtml(json.getString("announcement_desc")));
                this.announcement.setClickable(true);
                this.announcement.setMovementMethod(LinkMovementMethod.getInstance());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    public FancyShowCaseView addView(View view, String title, String n) {
        FancyShowCaseView view1 = new FancyShowCaseView.Builder(getActivity()).focusOn(view).title(title).titleSize(20, 1).focusShape(FocusShape.CIRCLE).enableAutoTextPosition().roundRectRadius(10).focusBorderSize(1).showOnce(n).focusBorderColor(getActivity().getResources().getColor(2131100324)).dismissListener(new DismissListener() {
            public void onDismiss(String s) {
            }

            public void onSkipped(String s) {
            }
        }).build();
        return view1;
    }
}