package com.xmartlabs.template.ui;

import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

import com.xmartlabs.template.R;

/**
 * Created by santiago on 31/08/15.
 */
public abstract class SingleFragmentActivity extends BaseAppCompatActivity {
  @NonNull
  protected abstract BaseFragment createFragment();

  @LayoutRes
  protected int getLayoutResId() {
    return R.layout.activity_fragment;
  }

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(getLayoutResId());

    FragmentManager fragmentManager = getSupportFragmentManager();
    Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_container);
    if (fragment == null) {
      fragment = createFragment();
    }

    fragmentManager
        .beginTransaction()
        .add(R.id.fragment_container, fragment)
        .commit();
  }
}

@@ -755,23 +755,16 @@
 Fragment
-Manager
  fragmen
@@ -768,127 +768,29 @@
 ment
-Manager = getSupportFragmentManager();%0A    Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_container
+ = getSingleFragment(
 );%0A 
@@ -859,16 +859,21 @@
     
-%7D%0A%0A    f
+  getSupportF
 ragm
@@ -882,17 +882,21 @@
 tManager
-%0A
+()%0A  
         
@@ -915,16 +915,18 @@
 ction()%0A
+  
         
@@ -973,16 +973,18 @@
         
+  
 .commit(
@@ -986,14 +986,217 @@
 mmit();%0A
+    %7D%0A  %7D%0A%0A  @Nullable%0A  protected Fragment getSingleFragment() %7B%0A    FragmentManager fragmentManager = getSupportFragmentManager();%0A    return fragmentManager.findFragmentById(R.id.fragment_container);%0A
   %7D%0A%7D%0A

Fix error when adding the fragment in single fragment activity pattern (#1)