package com.winworld.free_time;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.winworld.free_time.dummy.DummyContent;
import com.winworld.free_time.dummy.DummyContent.DummyItem;
import java.util.ArrayList;
import java.util.List;
public class WorkFragment extends ListFragment {
// TODO: Customize parameters
private int mColumnCount = 1;
private Context contexts;
private OnListFragmentInteractionListener mListener;
private work_deleter workDeleter;
private work_setter workSetter;
DataBaseHandler dataBaseHandler;
public static DummyItem week[] = { new DummyItem("1","monday","first day"),new DummyItem("2","tuesday","second day"),new DummyItem("3","wednesday","third day"),new DummyItem("4","thursday","fourth day"),new DummyItem("5","friday","fifth day"),new DummyItem("6","saturday","sixth day"),new DummyItem("7","sunday","seventh day")};
public String[] works = {"not received"};
public String[] one;
public String[] slotter;
public static Slot[] slots;
public static Work[] working;
int slot_updater = 0;
int work_updater = 0;
ArrayAdapter<DummyItem> adapter;
public WorkFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),android.R.layout.simple_list_item_1,works);
setListAdapter(adapter);
return super.onCreateView(inflater,container,savedInstanceState);
}
@Override
public void onAttach(Context context) {
dataBaseHandler = new DataBaseHandler(context);
workDeleter = (work_deleter)context;
workSetter = (work_setter)context;
super.onAttach(context);
if (context instanceof OnListFragmentInteractionListener) {
mListener = (OnListFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnListFragmentInteractionListener");
}
}
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
registerForContextMenu(getListView());
getListView().setBackgroundColor(getResources().getColor(android.R.color.white));
getListView().setCacheColorHint(getResources().getColor(android.R.color.white));
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnListFragmentInteractionListener {
// TODO: Update argument type and name
void onListFragmentInteraction(DummyItem item);
}
@Override
public void onListItemClick(ListView l, View v,int position,long id)
{
super.onListItemClick(l,v,position,id);
if(work_updater == 1) {
// mListener.onListFragmentInteraction(week[position]);
workDeleter.delete_work(working[position]);
}
if(slot_updater == 1)
{
// mListener.onListFragmentInteraction(week[position]);
workSetter.set_work(slots[position]);
}
}
public void update_slots(String one)
{
slot_updater = 1;
work_updater = 0;
Cursor cursor = dataBaseHandler.getSlots(one);
if(cursor.getCount() == 0)
{
Toast.makeText(getContext(),"no items in database",Toast.LENGTH_LONG).show();
}
else {
slots = new Slot[cursor.getCount()-1];
int i = 0;
cursor.moveToFirst();
slotter = new String[cursor.getCount()-1];
while (cursor.moveToNext()) {
slots[i] = new Slot(cursor.getString(0), cursor.getInt(1), cursor.getInt(2));
slotter[i] = slots[i].to_string();
i++;
}
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, slotter);
setListAdapter(arrayAdapter);
}
}
public void update_works(String one)
{
work_updater = 1;
slot_updater = 0;
Cursor cursor = dataBaseHandler.getWorks(one);
if(cursor.getCount() == 0)
{
Toast.makeText(getContext(), "no works in the database", Toast.LENGTH_SHORT).show();
}
else {
working = new Work[cursor.getCount() - 1];
cursor.moveToFirst();
int i = 0;
works = new String[cursor.getCount() - 1];
while (cursor.moveToNext()) {
working[i] = new Work(cursor.getString(0), cursor.getString(1), cursor.getInt(2), cursor.getInt(3));
works[i] = working[i].to_string();
i++;
}
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, works);
setListAdapter(arrayAdapter);
}
}
public interface work_setter{
public void set_work(Slot one);
}
public interface work_deleter{
public void delete_work(Work one);
}
}