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.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

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

public class set_user_list extends AppCompatActivity {
    ListView listView,listView2;
    String[] user;
    String findin,findout;
    Intent intent = new Intent();
    int x,x2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_user_list);
        listView = (ListView)findViewById(R.id.list_item3);
        listView2 = (ListView)findViewById(R.id.list_u);
        List list = new ArrayList();
        List list2 = new ArrayList();
        List list3 = new ArrayList();

        File txt = new File(Environment.getExternalStorageDirectory() + "/Park_JY/JiaYiCityPatrolPeople.txt");
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(txt)));
            while((findin = reader.readLine()) != null){
                findout = findin;
                user = findout.split("\n");
                for(int i = 0; i < user.length; i++){
                    list.add(user[i]);
                }

            }
            reader.close();
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
        for(int j = 0; j < list.size()/2; j++){
            list2.add(list.get(j).toString());
        }
        for(int k = list.size()/2; k < list.size(); k++){
            list3.add(list.get(k).toString());
        }

        ArrayAdapter adapter = new ArrayAdapter(this,R.layout.skin_user_list_text,R.id.textView43,list2);
        ArrayAdapter adapter2 = new ArrayAdapter(this,R.layout.skin_user_list_text,R.id.textView43,list3);
        listView.setAdapter(adapter);
        listView2.setAdapter(adapter2);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String name = (String)listView.getItemAtPosition(position);
                intent.setClass(set_user_list.this,Setting.class);
                intent.putExtra("USER",name);
                startActivity(intent);
                finish();
            }
        });
        listView2.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String name = (String)listView2.getItemAtPosition(position);
                intent.setClass(set_user_list.this,Setting.class);
                intent.putExtra("USER",name);
                startActivity(intent);
                finish();
            }
        });
    }
}
