content: package com.wifi.server.utils;
  
  import android.annotation.SuppressLint;
  import android.content.Context;
  import android.content.res.Resources;
  import android.widget.Toast;
  import com.wifi.server.R;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.UnsupportedEncodingException;
  import java.net.URLDecoder;
  import java.net.URLEncoder;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.Map;
  
  public class Utils {
  
      public static void showMessage(Context context,
                                     String message) {
          Toast.makeText(context, message, Toast.LENGTH_LONG).show();
      }
  
      private static String getJSONStringFromRaw(Context context, int rawId) {
  
          InputStream content = context.getResources().openRawResource(rawId);
          BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
          String respString = "";
          try {
              String s = "";
              while ((s = buffer.readLine()) != null) {
                  respString += s;
              }
          } catch (IOException e) {
              e.printStackTrace();
          }
          return respString;
      }
  
  
      public static boolean hasExpired(Long timeStamp) {
          long currentTimeInMillis = System.currentTimeMillis();
          if(timeStamp - currentTimeInMillis <= 0) return Boolean.TRUE;
          return Boolean.FALSE;
      }
  
  
      public static String timeAgo(Context context,
                            Date date) {
          return timeAgo(context, date.getTime());
      }
  
  
      @SuppressLint("StringFormatInvalid")
      public static String timeAgo(Context context,
                            long millis) {
          long diff = new Date().getTime() - millis;
  
          Resources r = context.getResources();
  
          String prefix = r.getString(R.string.time_ago_prefix);
  //        String suffix = r.getString(R.string.time_ago_suffix);
  
          double seconds = Math.abs(diff) / 1000;
          double minutes = seconds / 60;
          double hours = minutes / 60;
          double days = hours / 24;
          double years = days / 365;
  
          String words;
  
          if (seconds < 45) {
              words = r.getString(R.string.time_ago_seconds, Math.round(seconds));
          } else if (seconds < 90) {
              words = r.getString(R.string.time_ago_minute, 1);
          } else if (minutes < 45) {
              words = r.getString(R.string.time_ago_minutes, Math.round(minutes));
          } else if (minutes < 90) {
              words = r.getString(R.string.time_ago_hour, 1);
          } else if (hours < 24) {
              words = r.getString(R.string.time_ago_hours, Math.round(hours));
          } else if (hours < 42) {
              words = r.getString(R.string.time_ago_day, 1);
          } else if (days < 30) {
              words = r.getString(R.string.time_ago_days, Math.round(days));
          } else if (days < 45) {
              words = r.getString(R.string.time_ago_month, 1);
          } else if (days < 365) {
              words = r.getString(R.string.time_ago_months, Math.round(days / 30));
          } else if (years < 1.5) {
              words = r.getString(R.string.time_ago_year, 1);
          } else {
              words = r.getString(R.string.time_ago_years, Math.round(years));
          }
  
          StringBuilder sb = new StringBuilder();
  
          if (prefix != null && prefix.length() > 0) {
              sb.append(prefix).append(" ");
          }
  
          sb.append(words);
          return sb.toString().trim();
      }
  
  
      public static String getMerchantDetails() {
          Map<String, String> merchantMap = new HashMap<>();
          merchantMap.put("amount", "155");
          merchantMap.put("orderId", "12dlkdsllkslds");
          merchantMap.put("ostaTransactionReferenceId", "sfdjfispkspdks");
          merchantMap.put("merchantTransactionReferenceId", "dfldkfofsfsp");
          merchantMap.put("partnerReferenceId", "M1234568");
  
          String jsonStr = convertMapToString(merchantMap);
          return jsonStr;
      }
  
      public static String convertMapToString(Map<String, String> map) {
          StringBuilder stringBuilder = new StringBuilder();
  
          for (String key : map.keySet()) {
              if (stringBuilder.length() > 0) {
                  stringBuilder.append("&");
              }
              String value = map.get(key);
              try {
                  stringBuilder.append((key != null ? URLEncoder.encode(key, "UTF-8") : ""));
                  stringBuilder.append("=");
                  stringBuilder.append(value != null ? URLEncoder.encode(value, "UTF-8") : "");
              } catch (UnsupportedEncodingException e) {
                  throw new RuntimeException("This method requires UTF-8 encoding support", e);
              }
          }
  
          return stringBuilder.toString();
      }
  
      public static Map<String, String> convertStringToMap(String input) {
          Map<String, String> map = new HashMap<String, String>();
  
          String[] nameValuePairs = input.split("&");
          for (String nameValuePair : nameValuePairs) {
              String[] nameValue = nameValuePair.split("=");
              try {
                  map.put(URLDecoder.decode(nameValue[0], "UTF-8"), nameValue.length > 1 ? URLDecoder.decode(
                          nameValue[1], "UTF-8") : "");
              } catch (UnsupportedEncodingException e) {
                  throw new RuntimeException("This method requires UTF-8 encoding support", e);
              }
          }
  
          return map;
      }
  }
  