package com.example.android.quakereport;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


public class PropertiesAdapter extends RecyclerView.Adapter<PropertiesAdapter.ViewHolder> {
        private List<Feature> list;
    private Context context;

    PropertiesAdapter(List<Feature> list) {
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        //get View
        View v = LayoutInflater.from(context)
                .inflate(R.layout.activity_earthquake_list_item, parent, false);

        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final Properties properties = list.get(position).getProperties();
        holder.itemView.setOnClickListener(view -> {
            Intent intentCallWeb = new Intent(Intent.ACTION_VIEW, Uri.parse(properties.getUrl()));
            //call activity
            context.startActivity(intentCallWeb);
        });

        holder.date.setText(EarthquakeActivity.DATE_FORMAT.format(new Date(properties.getTime())));
        holder.time.setText(new SimpleDateFormat("HH:mm").format(new Date(properties.getTime())));

        if (properties.getPlace().contains("of")) {
            String fullLocation = properties.getPlace();
            int indexDivision = fullLocation.indexOf("of") + 3;
            String region = fullLocation.substring(0, indexDivision);
            String offset = fullLocation.substring(indexDivision, fullLocation.length());
            //set TextView text
            holder.location.setText(region);
            holder.offset.setText(offset);

        } else {
            holder.offset.setText(properties.getPlace());
        }

        // Get the appropriate background color based on the current earthquake MAGNITUDE
        // Set the color on the MAGNITUDE circle
        holder.mag.setText(properties.getMag().toString());
        // Set the proper background color on the MAGNITUDE circle.
        // Fetch the background from the TextView, which is a GradientDrawable.
        GradientDrawable magnitudeCircle = (GradientDrawable) holder.mag.getBackground();
        magnitudeCircle.setColor(properties.getMagColor(context));

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView mag, location, offset, date, time;

        public ViewHolder(View itemView) {
            super(itemView);
            mag = (TextView) itemView.findViewById(R.id.magnitude);
            location = (TextView) itemView.findViewById(R.id.location);
            offset = (TextView) itemView.findViewById(R.id.offset);
            date = (TextView) itemView.findViewById(R.id.date);
            time = (TextView) itemView.findViewById(R.id.time);
        }
    }

}

@@ -216,24 +216,63 @@
 cyclerView;%0A
+import android.text.format.DateFormat;%0A
 import andro
@@ -389,66 +389,8 @@
 w;%0A%0A
-import java.text.SimpleDateFormat;%0Aimport java.util.Date;%0A
 impo
@@ -1392,55 +1392,40 @@
 ext(
-EarthquakeActivity.DATE_FORMAT.format(new Date(
+DateFormat.format(%22EEE, MMM dd%22,
 prop
@@ -1442,17 +1442,16 @@
 Time()))
-)
 ;%0A      
@@ -1476,54 +1476,37 @@
 ext(
-new SimpleDateFormat(%22HH:mm%22).format(new Date(
+DateFormat.format(%22HH:mm:ss%22,
 prop
@@ -1523,17 +1523,16 @@
 Time()))
-)
 ;%0A%0A     

add russian strings value