package com.dailystudio.app.fragment;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.ContextCompat;

public abstract class AbsLoaderFragment<T> extends BaseIntentFragment implements LoaderCallbacks<T> {
    
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		getLoaderManager().initLoader(getLoaderId(), createLoaderArguments(), this);
	}
	
	public void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		
		restartLoader();
	}
	
	public void restartLoader() {
		getLoaderManager().restartLoader(getLoaderId(), createLoaderArguments(), this);
	}

	protected int getEmptyViewId() {
		return android.R.id.empty;
	}

	public boolean isPermissionGranted(String permission){
		return (ContextCompat.checkSelfPermission(getContext(),
				permission) == PackageManager.PERMISSION_GRANTED);
	}

	abstract protected int getLoaderId();
	abstract protected Bundle createLoaderArguments();

}

@@ -131,16 +131,61 @@
 Bundle;%0A
+import android.support.v4.app.LoaderManager;%0A
 import a
@@ -287,16 +287,60 @@
 ompat;%0A%0A
+import com.dailystudio.development.Logger;%0A%0A
 public a
@@ -560,31 +560,88 @@
 e);%0A
-%09%09
 %0A%09%09
-getLoaderManager()
+LoaderManager ldMgr = getLoaderManagerSafe();%0A%09%09if (ldMgr != null) %7B%0A%09%09%09ldMgr
 .ini
@@ -695,16 +695,20 @@
  this);%0A
+%09%09%7D%0A
 %09%7D%0A%09%0A%09pu
@@ -839,86 +839,445 @@
 %7B%0A%09%09
-getLoaderManager().restartLoader(getLoaderId(), createLoaderArguments(), this)
+LoaderManager ldMgr = getLoaderManagerSafe();%0A%09%09if (ldMgr != null) %7B%0A%09%09%09ldMgr.restartLoader(getLoaderId(), createLoaderArguments(), this);%0A%09%09%7D%0A%09%7D%0A%0A%09private LoaderManager getLoaderManagerSafe() %7B%0A%09%09LoaderManager loaderManager;%0A%0A%09%09try %7B%0A%09%09%09loaderManager = getLoaderManager();%0A%0A%09%09%7D catch (IllegalStateException e) %7B%0A%09%09%09Logger.warn(%22could not get loader manager: %25s%22,%0A%09%09%09%09%09e.toString());%0A%0A%09%09%09loaderManager = null;%0A%09%09%7D%0A%0A%09%09return loaderManager
 ;%0A%09%7D

fix potential crash issue in AbsLoaderFragment;