// Path: library/src/main/java/rxreddit/util/RxRedditUtil.java
// public class RxRedditUtil {
// 
//     /**
//      * Returns a string formed from a random UUID
//      */
//     public static String getRandomString() {
//         return UUID.randomUUID().toString();
//     }
// 
//     /**
//      * Generates a proper user agent string from the provided parameters
//      *
//      * @param platform    Platform for which application is being developed
//      * @param pkgName     Package name for the application
//      * @param versionName Version of the application
//      * @param username    reddit username of the application developer
//      * @return Formatted user agent string
//      */
//     public static String getUserAgent(
//             String platform, String pkgName, String versionName, String username) {
//         return String.format("%s:%s:%s (by /u/%s)", platform, pkgName, versionName, username);
//     }
// 
//     public static Map<String, String> getQueryParametersFromUrl(String url)
//             throws IllegalArgumentException {
//         if (url == null) throw new IllegalArgumentException("url == null");
//         URI uri = URI.create(url);
//         String query = uri.getQuery();
//         if (query == null) return Collections.emptyMap();
//         String[] params = query.split("&");
//         Map<String, String> paramMap = new HashMap<>();
//         int mid;
//         for (String param : params) {
//             mid = param.indexOf('=');
//             if (mid != -1) paramMap.put(param.substring(0, mid), param.substring(mid + 1));
//         }
//         return paramMap;
//     }
// 
//     public static <T> Observable<T> responseToBody(Response<T> response) {
//         if (!response.isSuccessful()) {
//             return Observable.error(new HttpException(response));
//         }
//         return Observable.just(response.body());
//     }
// 
//     public static <T> Observable<Response<T>> checkResponse(Response<T> response) {
//         if (!response.isSuccessful()) {
//             return Observable.error(new HttpException(response));
//         }
//         return Observable.just(response);
//     }
// }
// 
// Path: android/src/main/java/rxreddit/android/SignInActivity.java
// public static final String EXTRA_CALLBACK_URL = "rxreddit.android.EXTRA_CALLBACK_URL";


import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import java.util.Map;
import rxreddit.util.RxRedditUtil;
import static android.app.Activity.RESULT_OK;
import static rxreddit.android.SignInActivity.EXTRA_CALLBACK_URL;
package rxreddit.android;





public class SignInFragment extends Fragment {

    private static final String ARG_AUTH_URL = "ARG_AUTH_URL";

    private String authorizationUrl;
    private String redirectUri;
    private WebView webView;

    public static SignInFragment newInstance(String url) {
        Bundle args = new Bundle();
        args.putString(ARG_AUTH_URL, url);
        SignInFragment fragment = new SignInFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRetainInstance(true);
        setHasOptionsMenu(true);

        Bundle args = getArguments();
        authorizationUrl = args.getString(ARG_AUTH_URL);
// Path: library/src/main/java/rxreddit/util/RxRedditUtil.java
// public class RxRedditUtil {
// 
//     /**
//      * Returns a string formed from a random UUID
//      */
//     public static String getRandomString() {
//         return UUID.randomUUID().toString();
//     }
// 
//     /**
//      * Generates a proper user agent string from the provided parameters
//      *
//      * @param platform    Platform for which application is being developed
//      * @param pkgName     Package name for the application
//      * @param versionName Version of the application
//      * @param username    reddit username of the application developer
//      * @return Formatted user agent string
//      */
//     public static String getUserAgent(
//             String platform, String pkgName, String versionName, String username) {
//         return String.format("%s:%s:%s (by /u/%s)", platform, pkgName, versionName, username);
//     }
// 
//     public static Map<String, String> getQueryParametersFromUrl(String url)
//             throws IllegalArgumentException {
//         if (url == null) throw new IllegalArgumentException("url == null");
//         URI uri = URI.create(url);
//         String query = uri.getQuery();
//         if (query == null) return Collections.emptyMap();
//         String[] params = query.split("&");
//         Map<String, String> paramMap = new HashMap<>();
//         int mid;
//         for (String param : params) {
//             mid = param.indexOf('=');
//             if (mid != -1) paramMap.put(param.substring(0, mid), param.substring(mid + 1));
//         }
//         return paramMap;
//     }
// 
//     public static <T> Observable<T> responseToBody(Response<T> response) {
//         if (!response.isSuccessful()) {
//             return Observable.error(new HttpException(response));
//         }
//         return Observable.just(response.body());
//     }
// 
//     public static <T> Observable<Response<T>> checkResponse(Response<T> response) {
//         if (!response.isSuccessful()) {
//             return Observable.error(new HttpException(response));
//         }
//         return Observable.just(response);
//     }
// }
// 
// Path: android/src/main/java/rxreddit/android/SignInActivity.java
// public static final String EXTRA_CALLBACK_URL = "rxreddit.android.EXTRA_CALLBACK_URL";


// Path: android/src/main/java/rxreddit/android/SignInFragment.java
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import java.util.Map;
import rxreddit.util.RxRedditUtil;
import static android.app.Activity.RESULT_OK;
import static rxreddit.android.SignInActivity.EXTRA_CALLBACK_URL;

package rxreddit.android;





public class SignInFragment extends Fragment {

    private static final String ARG_AUTH_URL = "ARG_AUTH_URL";

    private String authorizationUrl;
    private String redirectUri;
    private WebView webView;

    public static SignInFragment newInstance(String url) {
        Bundle args = new Bundle();
        args.putString(ARG_AUTH_URL, url);
        SignInFragment fragment = new SignInFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRetainInstance(true);
        setHasOptionsMenu(true);

        Bundle args = getArguments();
        authorizationUrl = args.getString(ARG_AUTH_URL);
        Map<String, String> params = RxRedditUtil.getQueryParametersFromUrl(authorizationUrl);