package io.github.mikolasan.petprojectnavigator;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import static io.github.mikolasan.petprojectnavigator.Tools.createTaskIntent;

public class TaskListActivity extends Fragment {

    PetDatabase petDatabase;
    private PetDataLoader<PetTaskLoader> activityDataLoader;

    private void initView(Context context, View v) {
        final ListView list = (ListView) v.findViewById(R.id.task_full_view);
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = createTaskIntent(context, list, i);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtra("status", TaskActivity.STATUS_EDIT);
                startActivity(intent);
            }
        });
        try {
            activityDataLoader = new PetDataLoader<>(context, new PetTaskLoader(context, petDatabase), list);
            Bundle args = new Bundle();
            args.putBoolean("all_projects", true);
            getLoaderManager().initLoader(PetDataLoader.tasksActivityId, args, activityDataLoader);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }

    public void applyQuery(String query) {
        Bundle args = new Bundle();
        args.putString("query", query);
        args.putBoolean("all_projects", true);
        getLoaderManager().restartLoader(PetDataLoader.tasksActivityId, args, activityDataLoader);
    }

    @Override
    public void onAttach(Context context){
        super.onAttach(context);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        petDatabase = PetDatabase.getOpenedInstance();
    }

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

    @Override
    public void onResume() {
        super.onResume();
        Bundle args = new Bundle();
        args.putBoolean("all_projects", true);
        getLoaderManager().restartLoader(PetDataLoader.tasksActivityId, args, activityDataLoader);
    }
}

@@ -1281,184 +1281,23 @@
     
-Bundle args = new Bundle();%0A            args.putBoolean(%22all_projects%22, true);%0A            getLoaderManager().initLoader(PetDataLoader.tasksActivityId, args, activityDataLoader
+initLoader(null
 );%0A 
@@ -1520,143 +1520,93 @@
     
-args.putBoolean(%22all_projects%22, true
+restartLoader(args
 );%0A    
+%7D%0A%0A
     
-getLoaderManager().restartLoader(PetDataLoader.tasksActivityId, args, activityData
+public void updateList() %7B%0A        restart
 Loader
+(null
 );%0A 
@@ -2270,38 +2270,149 @@
 sume();%0A        
-Bundle
+restartLoader(null);%0A    %7D%0A%0A    private Bundle checkLoaderArgs(Bundle args) %7B%0A        if (args == null) %7B%0A           
  args = new Bund
@@ -2409,32 +2409,42 @@
 = new Bundle();%0A
+        %7D%0A
         args.put
@@ -2470,24 +2470,293 @@
 ts%22, true);%0A
+        return args;%0A    %7D%0A%0A    private void initLoader(Bundle args) %7B%0A        getLoaderManager().initLoader(PetDataLoader.tasksActivityId,%0A                checkLoaderArgs(args),%0A                activityDataLoader);%0A    %7D%0A%0A    private void restartLoader(Bundle args) %7B%0A
         getL
@@ -2818,14 +2818,63 @@
 yId,
- args,
+%0A                checkLoaderArgs(args),%0A               
  act

Update task list