Android/app/src/main/java/io/github/project_travel_mate/utilities/CurrencyActivity.java
private void convertCurrency() {
        // to fetch weather forecast by city name
        String uri = API_LINK_V2 + "get-currency-conversion-rate/" + first_country_short + "/" + second_country_short;
        Log.v("EXECUTING", uri);

        mDialog.show();
        //Set up client
        OkHttpClient client = new OkHttpClient();
        //Execute request
        Request request = new Request.Builder()
                .header("Authorization", "Token " + mToken)
                .url(uri)
                .build();

        //Setup callback
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                mDialog.hide();
                mHandler.post(() -> {
                    Log.e("Request Failed", "Message : " + e.getMessage());
                    cancelAnimation();
                    networkError();
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                final String jsonResponse = Objects.requireNonNull(response.body()).string();
                mHandler.post(() -> {
                    mDialog.hide();
                    if (response.isSuccessful()) {
                        try {
                            JSONObject result = new JSONObject(jsonResponse);
                            if (result.getString("result") != null) {
                                Double conversion = Double.parseDouble(result.getString("result"));
                                result_textview.setText(Double.toString(conversion * from_amount));
                            }
                            //cancel the loading animation once the data is fetched
                            cancelAnimation();

                        } catch (JSONException e) {
                            e.printStackTrace();
                            //display no data error animation
                            emptyListAnimation();
                        }
                    } else {
                        //display animation for no data returned from the API call
                        emptyListAnimation();
                    }
                });
            }
        });
    }
/**
     * Convert currency
     * and set result to result_textview
     */
Convert currency
and set result to result_textview
Convert currency and set result to result_textview
private void convertCurrency() {
        String uri = API_LINK_V2 + "get-currency-conversion-rate/" + first_country_short + "/" + second_country_short;
        Log.v("EXECUTING", uri);
        mDialog.show();
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .header("Authorization", "Token " + mToken)
                .url(uri)
                .build();
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                mDialog.hide();
                mHandler.post(() -> {
                    Log.e("Request Failed", "Message : " + e.getMessage());
                    cancelAnimation();
                    networkError();
                });
            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                final String jsonResponse = Objects.requireNonNull(response.body()).string();
                mHandler.post(() -> {
                    mDialog.hide();
                    if (response.isSuccessful()) {
                        try {
                            JSONObject result = new JSONObject(jsonResponse);
                            if (result.getString("result") != null) {
                                Double conversion = Double.parseDouble(result.getString("result"));
                                result_textview.setText(Double.toString(conversion * from_amount));
                            }
                            cancelAnimation();
                        } catch (JSONException e) {
                            e.printStackTrace();
                            emptyListAnimation();
                        }
                    } else {
                        emptyListAnimation();
                    }
                });
            }
        });
    }
private void convertCurrency ( ) { String uri = API_LINK_V2 + "get-currency-conversion-rate/" + first_country_short + "/" + second_country_short ; Log . v ( "EXECUTING" , uri ) ; mDialog . show ( ) ; OkHttpClient client = new OkHttpClient ( ) ; Request request = new Request . Builder ( ) . header ( "Authorization" , "Token " + mToken ) . url ( uri ) . build ( ) ; client . newCall ( request ) . enqueue ( new Callback ( ) { @ Override public void onFailure ( Call call , IOException e ) { mDialog . hide ( ) ; mHandler . post ( ( ) -> { Log . e ( "Request Failed" , "Message : " + e . getMessage ( ) ) ; cancelAnimation ( ) ; networkError ( ) ; } ) ; } @ Override public void onResponse ( Call call , Response response ) throws IOException { final String jsonResponse = Objects . requireNonNull ( response . body ( ) ) . string ( ) ; mHandler . post ( ( ) -> { mDialog . hide ( ) ; if ( response . isSuccessful ( ) ) { try { JSONObject result = new JSONObject ( jsonResponse ) ; if ( result . getString ( "result" ) != null ) { Double conversion = Double . parseDouble ( result . getString ( "result" ) ) ; result_textview . setText ( Double . toString ( conversion * from_amount ) ) ; } cancelAnimation ( ) ; } catch ( JSONException e ) { e . printStackTrace ( ) ; emptyListAnimation ( ) ; } } else { emptyListAnimation ( ) ; } } ) ; } } ) ; }
Convert currency
 and set result to result_textview
Convert currency and set result to result_textview
// to fetch weather forecast by city name //Set up client //Execute request //Setup callback //cancel the loading animation once the data is fetched //display no data error animation //display animation for no data returned from the API call