<commit_before>package com.xamoom.android.xamoom_pingeborg_android;

import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.xamoom.android.APICallback;
import com.xamoom.android.XamoomEndUserApi;
import com.xamoom.android.mapping.Content;
import com.xamoom.android.mapping.ContentById;
import com.xamoom.android.mapping.ContentByLocationIdentifier;
import com.xamoom.android.xamoomcontentblocks.XamoomContentFragment;

import java.net.HttpURLConnection;
import java.net.URL;

import retrofit.RetrofitError;

/**
 * ArtistDetailActivity can be used to display content from the xamoom cloud.
 *
 * We use it to display content discovered with NFC.
 *
 */
public class ArtistDetailActivity extends AppCompatActivity implements XamoomContentFragment.OnXamoomContentFragmentInteractionListener {

    private ProgressBar mProgressbar;
    private String mContentId;
    private String mLocationIdentifier;

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

        //set statusbar color
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.setStatusBarColor(getResources().getColor(R.color.pingeborg_dark_yellow));
        }

        //setup toolbar
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        //setup actionbar
        final ActionBar ab = getSupportActionBar();
        if (ab != null) {
            ab.setHomeAsUpIndicator(R.drawable.ic_arrow_back_black_24dp);
            ab.setDisplayHomeAsUpEnabled(true);
            ab.setTitle(Global.getInstance().getCurrentSystemName());
        }

        //get mContentId or mLocationIdentifier from intent
        Intent myIntent = getIntent();
        mContentId = myIntent.getStringExtra(XamoomContentFragment.XAMOOM_CONTENT_ID);
        mLocationIdentifier = myIntent.getStringExtra(XamoomContentFragment.XAMOOM_LOCATION_IDENTIFIER);

        mProgressbar = (ProgressBar) findViewById(R.id.artistDetailLoadingIndicator);

        if(mContentId != null || mLocationIdentifier != null) {
            loadData(mContentId, mLocationIdentifier);
        } else {
            onNewIntent(getIntent());
        }
    }

    /**
     * Get from an NFC scan the URL and display the data.
     *
     * @param intent Intent send from system when scanning NFC
     */
    protected void onNewIntent(Intent intent) {
        final String[] url = {intent.getDataString()};

        Analytics.getInstance(this).sendEvent("App", "NFC Scan in App", "User scanned an NFC Sticker");

        if(url[0].contains("pingeb.org")) {
            Thread thread = new Thread() {
                @Override
                public void run() {
                    try {
                        //get the url redirected
                        URL url2 = new URL(url[0]);
                        HttpURLConnection ucon = (HttpURLConnection) url2.openConnection();
                        ucon.setInstanceFollowRedirects(false);
                        final String newUrl = ucon.getHeaderField("Location");
                        ucon.disconnect();

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                url[0] = newUrl;

                                Uri mUri = Uri.parse(url[0]);
                                mLocationIdentifier = mUri.getLastPathSegment();

                                loadData(mContentId, mLocationIdentifier);
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                        Toast.makeText(getApplicationContext(), getString(R.string.old_pingeborg_sticker_redirect_failure), Toast.LENGTH_LONG).show();
                    }
                }
            };
            thread.start();
        } else {
            Uri mUri = Uri.parse(url[0]);
            mLocationIdentifier = mUri.getLastPathSegment();
            loadData(mContentId, mLocationIdentifier);
        }
    }

    private void loadData(final String contentId, final String locationIdentifier) {
        //load data
        if (contentId != null) {
            if(Global.getInstance().getSavedArtists().contains(contentId)) {
                Analytics.getInstance(this).sendEvent("UX", "Open Artist Detail", "User opened artist detail activity with mContentId: " + contentId);
                XamoomEndUserApi.getInstance(this.getApplicationContext(), getResources().getString(R.string.apiKey)).getContentbyIdFull(contentId, false, false, null, true, new APICallback<ContentById>() {
                    @Override
                    public void finished(ContentById result) {
                        setupXamoomContentFrameLayout(result.getContent());
                    }

                    @Override
                    public void error(RetrofitError error) {
                        Log.e(Global.DEBUG_TAG, "Error:" + error);
                        openInBrowser(contentId, locationIdentifier);
                    }
                });
            } else {
                Analytics.getInstance(this).sendEvent("UX", "Open Artist Detail", "User opened artist detail activity with mContentId: " + contentId);
                XamoomEndUserApi.getInstance(this.getApplicationContext(), getResources().getString(R.string.apiKey)).getContentbyIdFull(contentId, false, false, null, false, new APICallback<ContentById>() {
                    @Override
                    public void finished(ContentById result) {
                        setupXamoomContentFrameLayout(result.getContent());
                    }

                    @Override
                    public void error(RetrofitError error) {
                        Log.e(Global.DEBUG_TAG, "Error:" + error);
                        openInBrowser(contentId, locationIdentifier);
                    }
                });
            }
        } else if (locationIdentifier != null) {
            Analytics.getInstance(this).sendEvent("UX", "Open Artist Detail", "User opened artist detail activity with mLocationIdentifier: " + locationIdentifier);
            XamoomEndUserApi.getInstance(this.getApplicationContext(), getResources().getString(R.string.apiKey)).getContentByLocationIdentifier(locationIdentifier, false, false, null, new APICallback<ContentByLocationIdentifier>() {
                @Override
                public void finished(ContentByLocationIdentifier result) {
                    //save artist
                    Global.getInstance().saveArtist(result.getContent().getContentId());

                    setupXamoomContentFrameLayout(result.getContent());
                }

                @Override
                public void error(RetrofitError error) {
                    Log.e(Global.DEBUG_TAG, "Error:" + error);
                    openInBrowser(contentId, locationIdentifier);
                }
            });
        } else {
            Log.w(Global.DEBUG_TAG, "There is no mContentId or mLocationIdentifier");
            finish();
        }
    }

    private void setupXamoomContentFrameLayout(Content content) {
        //hide loading indicator
        mProgressbar.setVisibility(View.GONE);

        XamoomContentFragment fragment = XamoomContentFragment.newInstance(Integer.toHexString(getResources().getColor(R.color.pingeborg_green)).substring(2), getResources().getString(R.string.apiKey));
        fragment.setContent(content);

        try {
            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(R.id.XamoomContentFrameLayout, fragment)
                    .commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }
<commit_msg>setup Global to load content<commit_after>package com.xamoom.android.xamoom_pingeborg_android;

import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.xamoom.android.APICallback;
import com.xamoom.android.XamoomEndUserApi;
import com.xamoom.android.mapping.Content;
import com.xamoom.android.mapping.ContentById;
import com.xamoom.android.mapping.ContentByLocationIdentifier;
import com.xamoom.android.xamoomcontentblocks.XamoomContentFragment;

import java.net.HttpURLConnection;
import java.net.URL;

import retrofit.RetrofitError;

/**
 * ArtistDetailActivity can be used to display content from the xamoom cloud.
 *
 * We use it to display content discovered with NFC.
 *
 */
public class ArtistDetailActivity extends AppCompatActivity implements XamoomContentFragment.OnXamoomContentFragmentInteractionListener {

    private String mContentId;
    private String mLocationIdentifier;

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

        Log.v(Global.DEBUG_TAG, "ArtistDetailActivity - onCreate");

        //set statusbar color
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.setStatusBarColor(getResources().getColor(R.color.pingeborg_dark_yellow));
        }

        //setup toolbar
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        //setup Global
        Global.getInstance().setActivity(this);

        //setup actionbar
        final ActionBar ab = getSupportActionBar();
        if (ab != null) {
            ab.setHomeAsUpIndicator(R.drawable.ic_arrow_back_black_24dp);
            ab.setDisplayHomeAsUpEnabled(true);
            ab.setTitle(Global.getInstance().getCurrentSystemName());
        }

        //get mContentId or mLocationIdentifier from intent
        Intent myIntent = getIntent();
        mContentId = myIntent.getStringExtra(XamoomContentFragment.XAMOOM_CONTENT_ID);
        mLocationIdentifier = myIntent.getStringExtra(XamoomContentFragment.XAMOOM_LOCATION_IDENTIFIER);

        if(mContentId != null || mLocationIdentifier != null) {
            loadData(mContentId, mLocationIdentifier);
        } else {
            onNewIntent(getIntent());
        }
    }

    /**
     * Get from an NFC scan the URL and display the data.
     *
     * @param intent Intent send from system when scanning NFC
     */
    protected void onNewIntent(Intent intent) {
        Log.v(Global.DEBUG_TAG, "ArtistDetailActivity - onNewIntent");
        final String[] url = {intent.getDataString()};

        Analytics.getInstance(this).sendEvent("App", "NFC Scan in App", "User scanned an NFC Sticker");

        if(url[0].contains("pingeb.org")) {
            Thread thread = new Thread() {
                @Override
                public void run() {
                    try {
                        //get the url redirected
                        URL url2 = new URL(url[0]);
                        HttpURLConnection ucon = (HttpURLConnection) url2.openConnection();
                        ucon.setInstanceFollowRedirects(false);
                        final String newUrl = ucon.getHeaderField("Location");
                        ucon.disconnect();

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                url[0] = newUrl;

                                Uri mUri = Uri.parse(url[0]);
                                mLocationIdentifier = mUri.getLastPathSegment();

                                loadData(mContentId, mLocationIdentifier);
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                        Toast.makeText(getApplicationContext(), getString(R.string.old_pingeborg_sticker_redirect_failure), Toast.LENGTH_LONG).show();
                    }
                }
            };
            thread.start();
        } else {
            Uri mUri = Uri.parse(url[0]);
            mLocationIdentifier = mUri.getLastPathSegment();
            loadData(mContentId, mLocationIdentifier);
        }
    }

    private void loadData(final String contentId, final String locationIdentifier) {
        Log.v(Global.DEBUG_TAG, "ArtistDetailActivity - loadData");
        //load data
        if (contentId != null) {
            if(Global.getInstance().getSavedArtists().contains(contentId)) {
                Analytics.getInstance(this).sendEvent("UX", "Open Artist Detail", "User opened artist detail activity with mContentId: " + contentId);
                XamoomEndUserApi.getInstance(this.getApplicationContext(), getResources().getString(R.string.apiKey)).getContentbyIdFull(contentId, false, false, null, true, new APICallback<ContentById>() {
                    @Override
                    public void finished(ContentById result) {
                        setupXamoomContentFrameLayout(result.getContent());
                    }

                    @Override
                    public void error(RetrofitError error) {
                        Log.e(Global.DEBUG_TAG, "Error:" + error);
                        openInBrowser(contentId, locationIdentifier);
                    }
                });
            } else {
                Analytics.getInstance(this).sendEvent("UX", "Open Artist Detail", "User opened artist detail activity with mContentId: " + contentId);
                XamoomEndUserApi.getInstance(this.getApplicationContext(), getResources().getString(R.string.apiKey)).getContentbyIdFull(contentId, false, false, null, false, new APICallback<ContentById>() {
                    @Override
                    public void finished(ContentById result) {
                        setupXamoomContentFrameLayout(result.getContent());
                    }

                    @Override
                    public void error(RetrofitError error) {
                        Log.e(Global.DEBUG_TAG, "Error:" + error);
                        openInBrowser(contentId, locationIdentifier);
                    }
                });
            }
        } else if (locationIdentifier != null) {
            Analytics.getInstance(this).sendEvent("UX", "Open Artist Detail", "User opened artist detail activity with mLocationIdentifier: " + locationIdentifier);
            XamoomEndUserApi.getInstance(this.getApplicationContext(), getResources().getString(R.string.apiKey)).getContentByLocationIdentifier(locationIdentifier, false, false, null, new APICallback<ContentByLocationIdentifier>() {
                @Override
                public void finished(ContentByLocationIdentifier result) {
                    //save artist
                    Log.v(Global.DEBUG_TAG, "ArtistDetailActivity - getContentByLocationIdentifier finished");
                    Global.getInstance().saveArtist(result.getContent().getContentId());
                    setupXamoomContentFrameLayout(result.getContent());
                }

                @Override
                public void error(RetrofitError error) {
                    Log.e(Global.DEBUG_TAG, "Error:" + error);
                    openInBrowser(contentId, locationIdentifier);
                }
            });
        } else {
            Log.w(Global.DEBUG_TAG, "There is no mContentId or mLocationIdentifier");
            finish();
        }
    }

    private void setupXamoomContentFrameLayout(Content content) {
        //hide loading indicator

        Log.v(Global.DEBUG_TAG, "ArtistDetailActivity - APIKey: " + getResources().getString(R.string.apiKey));

        XamoomContentFragment fragment = XamoomContentFragment.newInstance(Integer.toHexString(getResources().getColor(R.color.pingeborg_green)).substring(2), getResources().getString(R.string.apiKey));
        fragment.setContent(content);

        try {
            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(R.id.XamoomContentFrameLayout, fragment)
                    .commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

{'fraction_non_alphanumeric': 0.0920040714770414, 'fraction_numerical': 0.001470255598280932, 'mean_word_length': 2.1687869557426986, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1799671', 'n_tokens_mistral': 4519, 'n_tokens_neox': 4311, 'n_words': 855}