package com.alorma.github.ui.activity;

import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import android.widget.Toast;

import com.alorma.github.R;
import com.alorma.github.sdk.bean.dto.request.RepoRequestDTO;
import com.alorma.github.sdk.bean.info.RepoInfo;
import com.alorma.github.sdk.services.repo.EditRepoClient;
import com.alorma.github.ui.activity.base.BackActivity;
import com.alorma.github.ui.fragment.RepositoryManagerFragment;

/**
 * Created by a557114 on 01/08/2015.
 */
public class ManageRepositoryActivity extends BackActivity{

    private static final String REPO_INFO = "REPO_INFO";
    private static final String REQUEST_DTO = "REQUEST_DTO";

    public static final String CONTENT = "CONTENT";

    private RepositoryManagerFragment repositoryManagerFragment;

    public static Intent createIntent(Context context, RepoInfo repoInfo, RepoRequestDTO repoRequestDTO) {
        Intent intent = new Intent(context, ManageRepositoryActivity.class);

        intent.putExtra(REPO_INFO, repoInfo);
        intent.putExtra(REQUEST_DTO, repoRequestDTO);

        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.generic_toolbar);

        FragmentTransaction ft = getFragmentManager().beginTransaction();
        RepoInfo repoInfo = getIntent().getExtras().getParcelable(REPO_INFO);
        RepoRequestDTO dto = getIntent().getExtras().getParcelable(REQUEST_DTO);
        repositoryManagerFragment = RepositoryManagerFragment.newInstance(repoInfo, dto);
        ft.replace(R.id.content, repositoryManagerFragment);
        ft.commit();
    }

    @Override
    protected void close() {
        RepoRequestDTO repoRequestDTO = repositoryManagerFragment.getRepoRequestDTO();
        if (!TextUtils.isEmpty(repoRequestDTO.name))  {
            Intent data = new Intent();
            data.putExtra(CONTENT, repoRequestDTO);
            setResult(RESULT_OK, data);
            finish();
        } else {
            Toast.makeText(this, getString(R.string.edit_repo_title_cannot_empty), Toast.LENGTH_SHORT).show();
        }
    }
}

@@ -1394,24 +1394,220 @@
 _toolbar);%0A%0A
+        if (getIntent() != null && getIntent().getExtras() != null) %7B%0A            if (getIntent().getExtras().containsKey(REPO_INFO) && getIntent().getExtras().containsKey(REQUEST_DTO)) %7B%0A        
         Frag
@@ -1664,24 +1664,32 @@
 nsaction();%0A
+        
         Repo
@@ -1754,32 +1754,40 @@
 _INFO);%0A        
+  
+      
 RepoRequestDTO d
@@ -1851,16 +1851,24 @@
         
+     
+   
 reposito
@@ -1937,24 +1937,32 @@
 Info, dto);%0A
+        
         ft.r
@@ -2010,16 +2010,24 @@
 gment);%0A
+        
         
@@ -2035,24 +2035,134 @@
 t.commit();%0A
+            %7D else %7B%0A                finish();%0A            %7D%0A        %7D else %7B%0A            finish();%0A        %7D%0A
     %7D%0A%0A    @

Fix manage repository null pointer