/*
 * Copyright (c) 2014 Personal-Health-Monitoring-System
 *
 * 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 com.cse3310.phms.ui.cards;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import com.cse3310.phms.R;
import com.cse3310.phms.model.EStorage;
import it.gmariotti.cardslib.library.internal.Card;


/**
 * Created by Owner on 4/15/14.
 */
public class UrlCard extends Card {
    private EStorage mUrlInfo;
    private String mTitle;
    private String mSubtitle;
    private ImageButton mButton;
    protected View.OnClickListener mBtnClickListener;


    public UrlCard(Context context, EStorage urlInfo) {
        super(context, R.layout.card_inner_url);
        mUrlInfo = urlInfo;
        System.out.println(urlInfo.getTitle());
    }

    @Override
    public void setupInnerViewElements(ViewGroup parent, View view) {
        TextView title = (TextView) view.findViewById(R.id.card_inner_txt_title);
        TextView subTitle = (TextView) view.findViewById(R.id.card_inner_txt_sub);
        ImageButton mButton = (ImageButton) view.findViewById(R.id.card_inner_img_btn);

        title.setText(mUrlInfo.getTitle());
        subTitle.setText(mUrlInfo.getUrl());

        mButton.setClickable(true);
        mButton.setOnClickListener(mBtnClickListener);
    }

    public void setTitle(String title) {
        super.setTitle(title);
        this.mTitle = title;
    }

    public void setSubTitle(String subTitle) {
        this.mSubtitle = subTitle;
    }

    public void setBtnClickListener(View.OnClickListener mBtnClickListener) {
        this.mBtnClickListener = mBtnClickListener;
    }

    public EStorage getUrlInfo() {
        return mUrlInfo;
    }
}


@@ -680,16 +680,47 @@
 ontext;%0A
+import android.content.Intent;%0A
 import a
@@ -902,16 +902,149 @@
 torage;%0A
+import com.cse3310.phms.ui.activities.WebViewActivity;%0Aimport com.cse3310.phms.ui.utils.Events;%0Aimport de.greenrobot.event.EventBus;%0A
 import i
@@ -1200,153 +1200,8 @@
 fo;%0A
-    private String mTitle;%0A    private String mSubtitle;%0A    private ImageButton mButton;%0A    protected View.OnClickListener mBtnClickListener;%0A%0A
 %0A   
@@ -1342,47 +1342,87 @@
     
-System.out.println(urlInfo.getTitle());
+setSwipeable(true);%0A        setTitle(mUrlInfo.getTitle()); // use for searching
 %0A   
@@ -1924,19 +1924,26 @@
 istener(
-mBt
+new View.O
 nClickLi
@@ -1952,87 +1952,151 @@
 ener
-);
+() %7B
 %0A    
-%7D%0A%0A    public void setTitle(String title) %7B%0A        super.setTitle(title
+        @Override%0A            public void onClick(View v) %7B%0A                Intent intent = new Intent(mContext, WebViewActivity.class
 );%0A 
@@ -2106,152 +2106,156 @@
     
-this.mTitle = title
+        intent.putExtra(%22urlpass%22, mUrlInfo.getUrl())
 ;%0A    
-%7D%0A%0A
     
-public void setSubTitle(String subTitle) %7B%0A        this.mSubtitle = subTitle;%0A    %7D%0A%0A    public void setBtnClick
+        mContext.startActivity(intent);%0A            %7D%0A        %7D);%0A%0A        setOnSwipe
 List
@@ -2259,36 +2259,35 @@
 istener(
-View.OnClick
+new OnSwipe
 Listener
  mBtnCli
@@ -2278,34 +2278,84 @@
 Listener
- mBtnClickListener
+() %7B%0A            @Override%0A            public void onSwipe(Card card
 ) %7B%0A    
@@ -2362,50 +2362,119 @@
     
-this.mBtnClickListener = mBtnClickListener
+        EventBus.getDefault().postSticky(new Events.RemoveUrlCardEvent(UrlCard.this));%0A            %7D%0A        %7D)
 ;%0A  
@@ -2474,24 +2474,25 @@
  %7D);%0A    %7D%0A%0A
+%0A
     public E

fix search crash for EStorage