<commit_before>/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.support.android.designlibdemo;

import android.app.AlertDialog;
import android.app.NotificationManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.support.android.designlibdemo.data.communications.ImageUrlView;
import com.support.android.designlibdemo.model.User;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import utils.AdoptionRequest;
import utils.BasicOwnerPetRequest;
import utils.Constants;
import utils.TransitHomeRequest;


public class PetsDetailActivity extends AppCompatActivity {
    private JSONArray object = null;
    public static final String EXTRA_NAME = "cheese_name";
    public static int IMAGE_MAX = 5;
    ImageFragmentPagerAdapter imageFragmentPagerAdapter;
    ViewPager viewPager;
    private Button buttonAdopt;
    private Button buttonTransitHome;
    private CardView contacto;
    private SharedPreferences prefs;
    private User loginUser;
    public static  String imagesItem[] = {};
    public static final String[] IMAGE_NAME = {"orange_kitten", "black_cat", "grey_cat",  "pardo_cat", "tiger_cat", "tiger_kitten"};


    /**********************************************************************************************/
    /**********************************************************************************************/

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        try {
            JSONObject object = new JSONObject(prefs.getString("userData", "{}"));
            Log.e("USER DATA DETAIL", prefs.getString("userData", "{}"));
            if (object.length() == 0) {
                Toast.makeText(getApplicationContext(), "Error cargando datos de usuario", Toast.LENGTH_SHORT).show();
                return;
            }
            this.loginUser = new User(object);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        imageFragmentPagerAdapter = new ImageFragmentPagerAdapter(getSupportFragmentManager());

        viewPager = (ViewPager) findViewById(R.id.pager);
        viewPager.setAdapter(imageFragmentPagerAdapter);

        buttonAdopt = (Button) findViewById(R.id.botonAdoptar);
        buttonAdopt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog dialogo = crearDialogo("Confirmar Adopción",
                        "Se le enviará una notificación al dueño de esta publicación para la evaluación de su solicitud",
                        true);
                dialogo.show();
            }
        });

        buttonTransitHome = (Button) findViewById(R.id.botonOfrecerHogar);
        buttonTransitHome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog dialogo = crearDialogo("Confirmar ofrecimiento de hogar de tránsito",
                        "Se le enviará una notificación al dueño de esta publicación para la evaluación de su solicitud",
                        false);
                dialogo.show();
            }
        });


        if (loginUser.getId().equals(getIntent().getStringExtra("ownerId"))) {
            Log.e("Intent transit", "el usuario es owner, no puede ofrecer transito");
            buttonAdopt.setVisibility(View.GONE);
            buttonTransitHome.setVisibility(View.GONE);
        }

        Boolean necesitaTransito = getIntent().getBooleanExtra("necesitaTransito", false);
        Log.e("Intent transit", necesitaTransito.toString());
        if (necesitaTransito == false) {
            buttonTransitHome.setVisibility(View.GONE);
        }

        contacto = (CardView) findViewById(R.id.cardContacto);
        contacto.setVisibility(View.GONE);

        Intent intent = getIntent();
        final String cheeseName = intent.getStringExtra("nombre");

        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        CollapsingToolbarLayout collapsingToolbar =
                (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
        collapsingToolbar.setTitle(cheeseName);

//        loadBackdrop();<commit_msg>Fix: ocultar boton de Ofrecer transito si tiene transitHomeUser<commit_after>/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.support.android.designlibdemo;

import android.app.AlertDialog;
import android.app.NotificationManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.support.android.designlibdemo.data.communications.ImageUrlView;
import com.support.android.designlibdemo.model.User;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import utils.AdoptionRequest;
import utils.BasicOwnerPetRequest;
import utils.Constants;
import utils.TransitHomeRequest;


public class PetsDetailActivity extends AppCompatActivity {
    private JSONArray object = null;
    public static final String EXTRA_NAME = "cheese_name";
    public static int IMAGE_MAX = 5;
    ImageFragmentPagerAdapter imageFragmentPagerAdapter;
    ViewPager viewPager;
    private Button buttonAdopt;
    private Button buttonTransitHome;
    private CardView contacto;
    private SharedPreferences prefs;
    private User loginUser;
    public static  String imagesItem[] = {};
    public static final String[] IMAGE_NAME = {"orange_kitten", "black_cat", "grey_cat",  "pardo_cat", "tiger_cat", "tiger_kitten"};


    /**********************************************************************************************/
    /**********************************************************************************************/

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        try {
            JSONObject object = new JSONObject(prefs.getString("userData", "{}"));
            Log.e("USER DATA DETAIL", prefs.getString("userData", "{}"));
            if (object.length() == 0) {
                Toast.makeText(getApplicationContext(), "Error cargando datos de usuario", Toast.LENGTH_SHORT).show();
                return;
            }
            this.loginUser = new User(object);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        imageFragmentPagerAdapter = new ImageFragmentPagerAdapter(getSupportFragmentManager());

        viewPager = (ViewPager) findViewById(R.id.pager);
        viewPager.setAdapter(imageFragmentPagerAdapter);

        buttonAdopt = (Button) findViewById(R.id.botonAdoptar);
        buttonAdopt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog dialogo = crearDialogo("Confirmar Adopción",
                        "Se le enviará una notificación al dueño de esta publicación para la evaluación de su solicitud",
                        true);
                dialogo.show();
            }
        });

        buttonTransitHome = (Button) findViewById(R.id.botonOfrecerHogar);
        buttonTransitHome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog dialogo = crearDialogo("Confirmar ofrecimiento de hogar de tránsito",
                        "Se le enviará una notificación al dueño de esta publicación para la evaluación de su solicitud",
                        false);
                dialogo.show();
            }
        });


        if (loginUser.getId().equals(getIntent().getStringExtra("ownerId"))) {
            Log.e("Intent transit", "el usuario es owner, no puede ofrecer transito");
            buttonAdopt.setVisibility(View.GONE);
            buttonTransitHome.setVisibility(View.GONE);
        }

        Boolean necesitaTransito = getIntent().getBooleanExtra("necesitaTransito", false);
        String transitHomeUser = getIntent().getStringExtra("transitHomeUser");
        Log.e("Intent transit", necesitaTransito.toString());
        if (necesitaTransito == false) {
            buttonTransitHome.setVisibility(View.GONE);
        }
        if (transitHomeUser != null){
            buttonTransitHome.setVisibility(View.GONE);
        }

        contacto = (CardView) findViewById(R.id.cardContacto);
        contacto.setVisibility(View.GONE);

        Intent intent = getIntent();
        final String cheeseName = intent.getStringExtra("nombre");

        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        CollapsingToolbarLayout collapsingToolbar =
                (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
        collapsingToolbar.setTitle(cheeseName);

//        loadBackdrop();
{'fraction_non_alphanumeric': 0.12058677274987568, 'fraction_numerical': 0.0028178352395159954, 'mean_word_length': 3.3752719361856416, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5328522', 'n_tokens_mistral': 3201, 'n_tokens_neox': 3084, 'n_words': 760}