<commit_before>package com.pennapps.labs.pennmobile


import android.content.SharedPreferences
import android.os.Bundle
import android.preference.PreferenceManager
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentTransaction
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.CookieManager
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.Toast
import com.pennapps.labs.pennmobile.api.Labs
import com.pennapps.labs.pennmobile.classes.GSRBookingResult
import kotlinx.android.synthetic.main.fragment_huntsman_gsrlogin.*
import retrofit.Callback
import retrofit.RetrofitError
import retrofit.client.Response


class HuntsmanGSRLogin : Fragment() {

    // gsr details
    private lateinit var gsrID: String
    private lateinit var gsrLocationCode: String
    private lateinit var startTime: String
    private lateinit var endTime: String

    private lateinit var mLabs: Labs

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mLabs = MainActivity.getLabsInstance()
        arguments?.let {arguments ->
            gsrID = arguments.getString("gsrID")
            gsrLocationCode = arguments.getString("gsrLocationCode")
            startTime = arguments.getString("startTime")
            endTime = arguments.getString("endTime")
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        // Inflate the layout for this fragment
        val v = inflater.inflate(R.layout.fragment_huntsman_gsrlogin, container, false)
        return v
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        val sp = PreferenceManager.getDefaultSharedPreferences(activity)
        val sessionid = sp.getString(getString(R.string.huntsmanGSR_SessionID), "")
        // load Huntsman website if no sessionid
        if (sessionid.isEmpty()) {
            loadWebpage()
        } else {
            bookHuntsmanGSR(sessionid)
        }
    }

    private fun loadWebpage() {
        // Get the web view settings instance
        webViewGSR.webViewClient = object : WebViewClient() {

            // Called every time a URL finishes loading, not just when the first URL finishes loading
            override fun onPageFinished(view : WebView, url : String) {
                // extract sessionid after user logs in
                if (url == "https://apps.wharton.upenn.edu/gsr/") {
                    var sessionid = ""
                    val cookies = CookieManager.getInstance().getCookie(url).split(";")
                    for (cookie in cookies){
                        if (cookie.take(11) == " sessionid=") {
                            sessionid = cookie.substring(11)
                            break
                        }
                    }

                    // save sessionid in shared preferences
                    activity?.let { activity ->
                        Log.d("@@@@ activity", "storing sessionid " + sessionid)
                        val sp = PreferenceManager.getDefaultSharedPreferences(activity)
                        val editor = sp.edit()
                        editor.putString(getString(R.string.huntsmanGSR_SessionID), sessionid)
                        editor.apply()
                    }
                    Log.d("@@@@@", "booking GSR for $gsrLocationCode now, $startTime - $endTime")
                    bookHuntsmanGSR(sessionid)
                }
            }
        }
        webViewGSR.loadUrl("https://apps.wharton.upenn.edu/gsr/")
    }<commit_msg>midnight booking bug fixed<commit_after>package com.pennapps.labs.pennmobile


import android.content.SharedPreferences
import android.os.Bundle
import android.preference.PreferenceManager
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentTransaction
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.CookieManager
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.Toast
import com.pennapps.labs.pennmobile.api.Labs
import com.pennapps.labs.pennmobile.classes.GSRBookingResult
import kotlinx.android.synthetic.main.fragment_huntsman_gsrlogin.*
import retrofit.Callback
import retrofit.RetrofitError
import retrofit.client.Response


class HuntsmanGSRLogin : Fragment() {

    // gsr details
    private lateinit var gsrID: String
    private lateinit var gsrLocationCode: String
    private lateinit var startTime: String
    private lateinit var endTime: String

    private lateinit var mLabs: Labs

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mLabs = MainActivity.getLabsInstance()
        arguments?.let {arguments ->
            gsrID = arguments.getString("gsrID")
            gsrLocationCode = arguments.getString("gsrLocationCode")
            startTime = arguments.getString("startTime")
            endTime = arguments.getString("endTime")
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        // Inflate the layout for this fragment
        val v = inflater.inflate(R.layout.fragment_huntsman_gsrlogin, container, false)
        return v
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        val sp = PreferenceManager.getDefaultSharedPreferences(activity)
        val sessionid = sp.getString(getString(R.string.huntsmanGSR_SessionID), "")
        // load Huntsman website if no sessionid
        if (sessionid.isEmpty()) {
            loadWebpage()
        } else {
            bookHuntsmanGSR(sessionid)
        }
    }

    private fun loadWebpage() {
        // Get the web view settings instance
        webViewGSR.webViewClient = object : WebViewClient() {

            // Called every time a URL finishes loading, not just when the first URL finishes loading
            override fun onPageFinished(view : WebView, url : String) {
                // extract sessionid after user logs in
                if (url == "https://apps.wharton.upenn.edu/gsr/") {
                    var sessionid = ""
                    val cookies = CookieManager.getInstance().getCookie(url).split(";")
                    for (cookie in cookies){
                        if (cookie.take(11) == " sessionid=") {
                            sessionid = cookie.substring(11)
                            break
                        }
                    }

                    // save sessionid in shared preferences
                    activity?.let { activity ->
                        Log.d("@@@@ activity", "storing sessionid " + sessionid)
                        val sp = PreferenceManager.getDefaultSharedPreferences(activity)
                        val editor = sp.edit()
                        editor.putString(getString(R.string.huntsmanGSR_SessionID), sessionid)
                        editor.apply()
                    }
                    Log.d("@@@@@", "booking GSR for $gsrLocationCode now, $startTime - $endTime")
                    if (startTime.substring(9,13) == "2330") {
                        Log.d("@@@@@", startTime.substring(4,8))
                        val newDay = endTime[7] + 1
                        var newEndTime = endTime.substring(0,7) + newDay + endTime.substring(8,endTime.length)
                        endTime = newEndTime
                    }
                    bookHuntsmanGSR(sessionid)
                    Log.d("@@@@@", "booking GSR for $gsrLocationCode now, $startTime - $endTime")
                }
            }
        }
        webViewGSR.loadUrl("https://apps.wharton.upenn.edu/gsr/")
    }
{'fraction_non_alphanumeric': 0.08838669177652228, 'fraction_numerical': 0.0032642812303829254, 'mean_word_length': 2.092391304347826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, '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': '2894569', 'n_tokens_mistral': 2141, 'n_tokens_neox': 2016, 'n_words': 467}