package tw.jiunjiun.apb.shuttle;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import tw.jiunjiun.apb.shuttle.curl.APB_API;
import tw.jiunjiun.apb.shuttle.parser.ParserBus;

import static tw.jiunjiun.apb.shuttle.curl.APB_API.KIND_NOW;

/**
 * Created by jiun on 2015/2/22.
 */
public class IndexFragment extends Fragment {
    private static final String TAG = "IndexFragment";
    private ParserBus mParserBus;

    private TextView depart, details;

    /**
     * Returns a new instance of this fragment for the given section
     * number.
     */
    public static IndexFragment newInstance() {
        IndexFragment fragment = new IndexFragment();
        return fragment;
    }

    public IndexFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View mView = inflater.inflate(R.layout.fragment_index, container, false);
        mView = initView(mView);
        return mView;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        ((MainActivity) activity).onSectionAttached(0);
    }

    @Override
    public void onStart() {
        super.onStart();
        new APB_API(mHandler, KIND_NOW);
    }

    private View initView(View mView) {
        depart  = (TextView) mView.findViewById(R.id.depart);
        details = (TextView) mView.findViewById(R.id.details);
        return mView;
    }

    private void setupView() {
        depart.setText(mParserBus.depart);
        details.setText(mParserBus.full_note);
    }

    Handler mHandler = new Handler(){
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case KIND_NOW:
                    mParserBus = new ParserBus(msg.obj.toString());
                    setupView();
                    break;
            }
            super.handleMessage(msg);
        }
    };
}

@@ -269,16 +269,81 @@
 wGroup;%0A
+import android.widget.Button;%0Aimport android.widget.ImageButton;%0A
 import a
@@ -366,16 +366,16 @@
 xtView;%0A
-
 %0Aimport 
@@ -522,16 +522,78 @@
 IND_NOW;
+%0Aimport static tw.jiunjiun.apb.shuttle.curl.APB_API.KIND_NEXT;
 %0A%0A/**%0A *
@@ -759,24 +759,54 @@
 ParserBus;%0A%0A
+    private int NextNum = 0;%0A%0A
     private 
@@ -830,16 +830,99 @@
 details;
+%0A    private ImageButton logo;%0A    private Button paginate_previous, paginate_next;
 %0A%0A    /*
@@ -1912,16 +1912,1207 @@
 etails);
+%0A%0A        logo   = (ImageButton) mView.findViewById(R.id.logo);%0A        paginate_previous = (Button) mView.findViewById(R.id.paginate_previous);%0A        paginate_next     = (Button) mView.findViewById(R.id.paginate_next);%0A%0A%0A        logo.setOnClickListener(new View.OnClickListener() %7B%0A            @Override%0A            public void onClick(View v) %7B%0A                new APB_API(mHandler, KIND_NOW);%0A                NextNum = 0;%0A                paginate_previous.setVisibility(View.GONE);%0A            %7D%0A        %7D);%0A%0A        paginate_previous.setOnClickListener(new View.OnClickListener() %7B%0A            @Override%0A            public void onClick(View v) %7B%0A                NextNum--;%0A                if(NextNum == 0) paginate_previous.setVisibility(View.GONE);%0A                new APB_API(mHandler, KIND_NEXT, new int%5B%5D%7BNextNum%7D);%0A            %7D%0A        %7D);%0A%0A        paginate_next.setOnClickListener(new View.OnClickListener() %7B%0A            @Override%0A            public void onClick(View v) %7B%0A                NextNum++;%0A                if(NextNum == 1) paginate_previous.setVisibility(View.VISIBLE);%0A                new APB_API(mHandler, KIND_NEXT, new int%5B%5D%7BNextNum%7D);%0A            %7D%0A        %7D);%0A%0A
 %0A       
@@ -3376,24 +3376,24 @@
 msg.what) %7B%0A
-
             
@@ -3411,16 +3411,48 @@
 ND_NOW:%0A
+                case KIND_NEXT:%0A
         

完成網頁版的首頁 - 除了 touch 手勢