package com.salvadordalvik.fastlibrary;

import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.volley.VolleyError;
import com.salvadordalvik.fastlibrary.request.FastRequest;
import com.salvadordalvik.fastlibrary.request.FastVolley;

import uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh;
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout;
import uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener;

/**
 * FastLib
 * Created by Matthew Shepard on 11/17/13.
 */
public abstract class FastDialogFragment extends DialogFragment implements FastRequest.FastStatusCallback, OnRefreshListener {
    private int layoutId;

    public FastDialogFragment(int layoutId) {
        super();
        this.layoutId = layoutId;
    }

    public abstract void viewCreated(View frag, Bundle savedInstanceState);
    public abstract void refreshData(boolean pullToRefresh);

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View frag = inflater.inflate(layoutId, container, false);
        return frag;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        viewCreated(view, savedInstanceState);
    }

    protected void queueRequest(FastRequest request){
        FastVolley.queueRequest(request, this);
    }

    @Override
    public void onSuccess(FastRequest request) {
    }

    @Override
    public void onFailure(FastRequest request, VolleyError error) {
    }

    @Override
    public void onRefreshStarted(View view) {
        refreshData(true);
    }

    public void invalidateOptionsMenu() {
        Activity activity = getActivity();
        if(activity != null){
            activity.invalidateOptionsMenu();
        }
    }
}

@@ -63,16 +63,43 @@
 tivity;%0A
+import android.app.Dialog;%0A
 import a
@@ -929,16 +929,26 @@
 layoutId
+, titleRes
 ;%0A%0A    p
@@ -1061,133 +1061,532 @@
 lic 
-abstract void viewCreated(View frag, Bundle savedInstanceState);%0A    public abstract void refreshData(boolean pullToRefresh);
+FastDialogFragment(int layoutId, int titleRes) %7B%0A        super();%0A        this.layoutId = layoutId;%0A        this.titleRes = titleRes;%0A    %7D%0A%0A    public abstract void viewCreated(View frag, Bundle savedInstanceState);%0A    public abstract void refreshData(boolean pullToRefresh);%0A%0A    @Override%0A    public Dialog onCreateDialog(Bundle savedInstanceState) %7B%0A        Dialog dialog = super.onCreateDialog(savedInstanceState);%0A        if(titleRes %3E 0)%7B%0A            dialog.setTitle(titleRes);%0A        %7D%0A        return dialog;%0A    %7D
 %0A%0A  
@@ -2526,11 +2526,263 @@
  %7D%0A    %7D
+%0A%0A    protected void setTitle(int titleRes) %7B%0A        setTitle(getString(titleRes));%0A    %7D%0A%0A    protected void setTitle(String title) %7B%0A        Dialog dialog = getDialog();%0A        if(dialog != null)%7B%0A            dialog.setTitle(title);%0A        %7D%0A    %7D
 %0A%7D%0A

Add setTitle to dialog fragment.