<commit_before>/*
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package speakman.whatsshakingnz.ui.viewmodel;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.google.android.gms.maps.model.LatLng;

import speakman.whatsshakingnz.R;
import speakman.whatsshakingnz.databinding.RowEarthquakeBinding;
import speakman.whatsshakingnz.model.Earthquake;
import speakman.whatsshakingnz.model.LocalPlace;
import speakman.whatsshakingnz.utils.DistanceUtil;

/**
 * Created by Adam on 11/29/2015.
 */
@SuppressWarnings("unused")
public class EarthquakeListViewModel {

    public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        public interface OnClickListener {
            void onClick(View v, Earthquake earthquake);
        }

        public RowEarthquakeBinding binding;
        private OnClickListener clickListener;
        public ViewHolder(RowEarthquakeBinding binding, OnClickListener clickListener) {
            super(binding.getRoot());
            this.binding = binding;
            this.clickListener = clickListener;
            this.itemView.setOnClickListener(this);
        }

        public void onClick(View v) {
            this.clickListener.onClick(v, this.binding.getEarthquakeModel().getEarthquake());
        }
    }

    private Earthquake earthquake;
    public EarthquakeListViewModel(Earthquake earthquake) {
        this.earthquake = earthquake;
    }

    public Earthquake getEarthquake() {
        return earthquake;
    }

    public String getMagnitude() {
        return String.format("%.1f", earthquake.getMagnitude());
    }

    public String getLocation(Context context) {
        LatLng earthquakeLocation = new LatLng(earthquake.getLatitude(), earthquake.getLongitude());
        LocalPlace place = DistanceUtil.getClosestPlace(earthquakeLocation);
        double distance = DistanceUtil.distanceBetweenPlaces(place.location, earthquakeLocation);
        DistanceUtil.Direction direction = DistanceUtil.getDirection(place.location, earthquakeLocation);
        return context.getString(R.string.list_location_format, distance, direction.localizedName(context), place.name);
    }
}<commit_msg>Only parse data from an Earthquake once for list view model<commit_after>/*
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package speakman.whatsshakingnz.ui.viewmodel;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.google.android.gms.maps.model.LatLng;

import speakman.whatsshakingnz.R;
import speakman.whatsshakingnz.databinding.RowEarthquakeBinding;
import speakman.whatsshakingnz.model.Earthquake;
import speakman.whatsshakingnz.model.LocalPlace;
import speakman.whatsshakingnz.utils.DistanceUtil;

/**
 * Created by Adam on 11/29/2015.
 */
@SuppressWarnings("unused")
public class EarthquakeListViewModel {

    public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        public interface OnClickListener {
            void onClick(View v, Earthquake earthquake);
        }

        public RowEarthquakeBinding binding;
        private OnClickListener clickListener;
        public ViewHolder(RowEarthquakeBinding binding, OnClickListener clickListener) {
            super(binding.getRoot());
            this.binding = binding;
            this.clickListener = clickListener;
            this.itemView.setOnClickListener(this);
        }

        public void onClick(View v) {
            this.clickListener.onClick(v, this.binding.getEarthquakeModel().getEarthquake());
        }
    }

    private Earthquake earthquake;
    private LocalPlace nearestTown;
    private double distanceToNearestTown;
    private DistanceUtil.Direction directionToNearestTown;
    public EarthquakeListViewModel(Earthquake earthquake) {
        this.earthquake = earthquake;
        LatLng earthquakeLocation = new LatLng(earthquake.getLatitude(), earthquake.getLongitude());
        this.nearestTown = DistanceUtil.getClosestPlace(earthquakeLocation);
        this.distanceToNearestTown = DistanceUtil.distanceBetweenPlaces(nearestTown.location, earthquakeLocation);
        this.directionToNearestTown = DistanceUtil.getDirection(nearestTown.location, earthquakeLocation);
    }

    public Earthquake getEarthquake() {
        return earthquake;
    }

    public String getMagnitude() {
        return String.format("%.1f", earthquake.getMagnitude());
    }

    public String getLocation(Context context) {
        return context.getString(R.string.list_location_format, this.distanceToNearestTown,
                this.directionToNearestTown.localizedName(context), this.nearestTown.name);
    }
}
{'fraction_non_alphanumeric': 0.08065068493150684, 'fraction_numerical': 0.0061643835616438354, 'mean_word_length': 3.7372262773722627, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4157737', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1503, 'n_words': 404}