package com.cuongnd.wpibannerweb;

import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TextView;

import com.cuongnd.wpibannerweb.helper.ConnectionManager;
import com.cuongnd.wpibannerweb.helper.SessionManager;
import com.cuongnd.wpibannerweb.simpleparser.AdvisorParser;
import com.cuongnd.wpibannerweb.simpleparser.CardBalanceParser;
import com.cuongnd.wpibannerweb.simpleparser.MailboxParser;

/**
 * Created by Cuong Nguyen on 5/10/2015.
 */
public class DashboardFragment extends Fragment {

    public static final String EXTRA_USERNAME = "username";
    private static final String DIALOG_CONTENT = "content";

    private ConnectionManager connectionManager;

    private ImageView imageProfile;
    private TextView textName;
    private TextView textWpiId;
    private ImageButton buttonBalance;
    private ImageButton buttonMailbox;
    private ImageButton buttonAdvisor;
    private ImageButton buttonGrade;
    private TableLayout tableInfo;

    private TextView textTest;

    public static DashboardFragment newInstance(String username) {
        Bundle args = new Bundle();
        args.putString(EXTRA_USERNAME, username);

        DashboardFragment fragment = new DashboardFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        SessionManager sm = SessionManager.getInstance(getActivity().getApplicationContext());
        sm.checkStatus();

        connectionManager = ConnectionManager.getInstance();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_dashboard, container, false);

        imageProfile = (ImageView) v.findViewById(R.id.image_profile);

        textName = (TextView) v.findViewById(R.id.text_name);
        textName.setText(SessionManager.getInstance(getActivity().getApplicationContext())
                .getUserName());

        textWpiId = (TextView) v.findViewById(R.id.text_wpiid);

        buttonBalance = (ImageButton) v.findViewById(R.id.button_balance);
        buttonBalance.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showContentDialog(CardBalanceParser.PAGE_NAME);
            }
        });

        buttonMailbox = (ImageButton) v.findViewById(R.id.button_mailbox);
        buttonMailbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showContentDialog(MailboxParser.PAGE_NAME);
            }
        });

        buttonAdvisor = (ImageButton) v.findViewById(R.id.button_advisor);
        buttonAdvisor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showContentDialog(AdvisorParser.PAGE_NAME);
            }
        });

        buttonGrade = (ImageButton) v.findViewById(R.id.button_grade);
        buttonGrade.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        // TODO: make width equal height
        tableInfo = (TableLayout) v.findViewById(R.id.table_info);

        return v;
    }

    private void showContentDialog(String pageName) {
        FragmentManager fm = getActivity().getFragmentManager();
        ContentFragment fragment = ContentFragment.newInstance(pageName);
        fragment.show(fm, DIALOG_CONTENT);
    }

}

@@ -89,24 +89,55 @@
 entManager;%0A
+import android.content.Intent;%0A
 import andro
@@ -383,66 +383,8 @@
 w;%0A%0A
-import com.cuongnd.wpibannerweb.helper.ConnectionManager;%0A
 impo
@@ -856,332 +856,30 @@
 ate 
-ConnectionManager connectionManager;%0A%0A    private ImageView imageProfile;%0A    private TextView textName;%0A    private TextView textWpiId;%0A    private ImageButton buttonBalance;%0A    private ImageButton buttonMailbox;%0A    private ImageButton buttonAdvisor;%0A    private ImageButton buttonGrade;%0A    private TableLayout tableInfo
+ImageView imageProfile
 ;%0A%0A 
@@ -1433,69 +1433,8 @@
 );%0A%0A
-        connectionManager = ConnectionManager.getInstance();%0A
     
@@ -1709,32 +1709,41 @@
 file);%0A%0A        
+TextView 
 textName = (Text
@@ -1909,24 +1909,33 @@
 );%0A%0A        
+TextView 
 textWpiId = 
@@ -1979,32 +1979,44 @@
 piid);%0A%0A        
+ImageButton 
 buttonBalance = 
@@ -2291,32 +2291,44 @@
    %7D);%0A%0A        
+ImageButton 
 buttonMailbox = 
@@ -2599,32 +2599,44 @@
    %7D);%0A%0A        
+ImageButton 
 buttonAdvisor = 
@@ -2907,32 +2907,44 @@
    %7D);%0A%0A        
+ImageButton 
 buttonGrade = (I
@@ -3122,16 +3122,129 @@
 ew v) %7B%0A
+                Intent i = new Intent(getActivity(), FinalGradeActivity.class);%0A                startActivity(i);
 %0A       
@@ -3312,16 +3312,28 @@
         
+TableLayout 
 tableInf

Make variables local