app/src/main/java/com/mohammadKZ/CoronaVirus_COVID19_statistics/fragments/HomeFragment.java
private void RequestAPI() {
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url_api_2, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {

                    JSONObject jsonObject = new JSONObject(response);
                    Log.e("ERROR", "aa " + jsonObject.length());


                    country = new Country("World", jsonObject.getString("todayCases"), jsonObject.getString("cases"), jsonObject.getString("todayDeaths"),
                            jsonObject.getString("deaths"), jsonObject.getString("recovered"), jsonObject.getString("active"), jsonObject.getString("todayRecovered") , null);

                    setInfo();

                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                try {

                    Log.d("Error", "connection failed" + " ");
                    Toast.makeText(getContext(), "check the internet connection...", Toast.LENGTH_SHORT).show();
                    alertDialog();// alert for connection
                } catch (Exception eroor) {
                    eroor.getMessage();
                }
            }
        });

        requestQueue.add(stringRequest);

    }
// api request and get the info
api request and get the info
api request and get the info
private void RequestAPI() {
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url_api_2, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    Log.e("ERROR", "aa " + jsonObject.length());
                    country = new Country("World", jsonObject.getString("todayCases"), jsonObject.getString("cases"), jsonObject.getString("todayDeaths"),
                            jsonObject.getString("deaths"), jsonObject.getString("recovered"), jsonObject.getString("active"), jsonObject.getString("todayRecovered") , null);
                    setInfo();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                try {
                    Log.d("Error", "connection failed" + " ");
                    Toast.makeText(getContext(), "check the internet connection...", Toast.LENGTH_SHORT).show();
                    alertDialog();
                } catch (Exception eroor) {
                    eroor.getMessage();
                }
            }
        });
        requestQueue.add(stringRequest);
    }
private void RequestAPI ( ) { StringRequest stringRequest = new StringRequest ( Request . Method . GET , url_api_2 , new Response . Listener < String > ( ) { @ Override public void onResponse ( String response ) { try { JSONObject jsonObject = new JSONObject ( response ) ; Log . e ( "ERROR" , "aa " + jsonObject . length ( ) ) ; country = new Country ( "World" , jsonObject . getString ( "todayCases" ) , jsonObject . getString ( "cases" ) , jsonObject . getString ( "todayDeaths" ) , jsonObject . getString ( "deaths" ) , jsonObject . getString ( "recovered" ) , jsonObject . getString ( "active" ) , jsonObject . getString ( "todayRecovered" ) , null ) ; setInfo ( ) ; } catch ( JSONException e ) { e . printStackTrace ( ) ; } } } , new Response . ErrorListener ( ) { @ Override public void onErrorResponse ( VolleyError error ) { try { Log . d ( "Error" , "connection failed" + " " ) ; Toast . makeText ( getContext ( ) , "check the internet connection..." , Toast . LENGTH_SHORT ) . show ( ) ; alertDialog ( ) ; } catch ( Exception eroor ) { eroor . getMessage ( ) ; } } } ) ; requestQueue . add ( stringRequest ) ; }
api request and get the info
api request and get the info
// alert for connection