package org.forestguardian.View.Fragments;

import android.app.Fragment;
import android.content.Context;
import android.location.Location;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.design.widget.FloatingActionButton;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;

import org.forestguardian.Helpers.GeoHelper;
import org.forestguardian.Helpers.IContants;
import org.forestguardian.R;

import java.io.IOException;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by emma on 30/04/17.
 */
public class DefaultMapInteractionFragment extends Fragment implements IContants{

    public interface OnDefaultInteractionListener {
        void addReport();
        void centerOnLocation();
        void changeBasemap(String basemapURL);
    }

    private OnDefaultInteractionListener mListener;

    @BindView(R.id.add_report_btn) FloatingActionButton mAddReportBtn;
    @BindView(R.id.center_location_btn) FloatingActionButton mCenterLocationBtn;
    @BindView(R.id.currentLocationTextView) TextView mCurrentLocationText;
    @BindView(R.id.fab_temperature) ImageButton mTemperatureMapButton;
    @BindView(R.id.fab_wind) ImageButton mWindMapButton;
    @BindView(R.id.fab_precipitation) ImageButton mPrecipitationMapButton;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.map_bottom_default, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onAttach(final Context context) {
        super.onAttach(context);
    }

    @OnClick(R.id.add_report_btn)
    public void onAddReportBtnClick(){
        if ( mListener != null ){
            mListener.addReport();
        }
    }

    @OnClick(R.id.center_location_btn)
    public void onCenterLocationClick(){
        if ( mListener != null ){
            mListener.centerOnLocation();
        }
    }

    @OnClick(R.id.fab_temperature)
    public void onTemperatureMapClick() {
        if ( mListener != null ) {
            mListener.changeBasemap(TEMPERATURE_BASEMAP);
        }
    }

    @OnClick(R.id.fab_wind)
    public void onWindMapClick() {
        if ( mListener != null ) {
            mListener.changeBasemap(WIND_BASEMAP);
        }
    }

    @OnClick(R.id.fab_precipitation)
    public void onPrecipitationMapClick() {
        if ( mListener != null ) {
            mListener.changeBasemap(FIRE_BASEMAP);
        }
    }

    public OnDefaultInteractionListener getListener() {
        return mListener;
    }

    public void setListener(final OnDefaultInteractionListener pListener) {
        mListener = pListener;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    public void setCurrentLocation(String locationText) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                final String tmpLocationText = locationText;
                if (getActivity() != null) {
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                                setLocationLabelText(tmpLocationText);
                            }
                    });
                }
            }
        }).start();
    }

    public void setLocationLabelText(String message) {
        if (mCurrentLocationText != null) {
            mCurrentLocationText.setText(message);
        }
    }
}

@@ -3116,106 +3116,8 @@
 ) %7B%0A
-        new Thread(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A        
     
@@ -3165,24 +3165,16 @@
 onText;%0A
-        
         
@@ -3198,32 +3198,24 @@
  != null) %7B%0A
-        
             
@@ -3275,24 +3275,16 @@
         
-        
 @Overrid
@@ -3285,24 +3285,16 @@
 verride%0A
-        
         
@@ -3426,32 +3426,36 @@
   %7D%0A            
+%7D);%0A
         %7D);%0A    
@@ -3451,62 +3451,8 @@
    %7D
-);%0A                %7D%0A            %7D%0A        %7D).start();
 %0A   

Remove unneeded thread