package com.ecom.park_jy;

import android.content.Intent;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class U064 extends AppCompatActivity {
    ListView listView;
    String[] car_type, car2;
    String findin, findout;
    Intent intent = new Intent();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_u064);
        listView = (ListView) findViewById(R.id.u064_list);
        final List list = new ArrayList();
        List list2 = new ArrayList();
        File car = new File(Environment.getExternalStorageDirectory() + "/Park_JY/update_U064.txt");
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(car)));
            while ((findin = reader.readLine()) != null) {
                findout = findin;
                car_type = findout.split("\n");

                for (int i = 0; i < car_type.length; i++) {
                    list.add(car_type[i]);
                    car2 = car_type[i].split(" ");
                    if (!car_type[0].equals("0")) {
                        if (car2[12].equals("0")) {
                            list2.add(car2[0] + " " + car2[14].substring(7) + " (未開單)");
                        } else if (car2[12].equals("1")) {
                            list2.add(car2[0] + " " + car2[14].substring(7) + " (已自主開單)");
                        }
                    } else {
                        list2.add(car2[0]);
                    }
                }
            }
            reader.close();
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
        ArrayAdapter adapter = new ArrayAdapter(this, R.layout.skin_user_list_text, R.id.textView43, list2);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //String name = (String)listView.getItemAtPosition(position);
                intent.putExtra("車格", list.get(position).toString());
                //intent.putExtra("dataCount",Integer.toString(list.size()));
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }
}
