package ai.pai.client.views;

import android.app.Activity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.common.utils.TimeUtils;
import com.android.views.popup.BasePopupWindow;

import ai.pai.client.R;
import ai.pai.client.db.Preferences;
import ai.pai.client.utils.PhotoLoader;


public class GatherInfoPopup extends BasePopupWindow {

    private View popupView;
    private ImageView gatherMap;
    private TextView gatherInfoText;
    private Activity context;


    public GatherInfoPopup(Activity context) {
        super(context);
        this.context = context;
        init();
    }

    @Override
    protected Animation getShowAnimation() {
        return getDefaultScaleAnimation();
    }

    @Override
    protected View getClickToDismissView() {
        return popupView.findViewById(R.id.click_to_dismiss);
    }

    @Override
    public View getPopupView() {
        popupView = LayoutInflater.from(mContext).inflate(R.layout.pop_gather_info, null);
        gatherInfoText = (TextView) popupView.findViewById(R.id.tv_gather_info);
        gatherMap = (ImageView) popupView.findViewById(R.id.iv_gather_map);
        return popupView;
    }

    private void init(){
        String time = TimeUtils.getGatherTimeStr(Preferences.getInstance(context).getGatherTime());
        if(time.length()==0){
            time = context.getString(R.string.gather_no_time);
        }
        String location = Preferences.getInstance(context).getTourGatherLocation();
        if(location.length()==0){
            location = context.getString(R.string.gather_no_location);
        }
        gatherInfoText.setText(context.getString(R.string.gather_info,time ,location));
        if(!TextUtils.isEmpty(Preferences.getInstance(context).getGatherMap())){
            PhotoLoader.getInstance(context).displayImage(Preferences.getInstance(context).getGatherMap(),gatherMap);
            gatherMap.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View v) {
                    new FullScreenImgPopup(context,Preferences.getInstance(context).getGatherMap()).showPopupWindow();
                }
            });
        }else{
            gatherMap.setVisibility(View.GONE);
        }
    }

    @Override
    public View getAnimaView() {
        return popupView.findViewById(R.id.popup_anima);
    }


}
