<commit_before>// Copyright (c) Wireclub Media Inc. All Rights Reserved. See License.md in the project root for license information.

namespace Wireclub.iOS

open System
open System.Drawing
open System.Threading
open System.Collections.Generic
open System.Collections.Concurrent
open MonoTouch.Foundation
open MonoTouch.UIKit
open Wireclub.Boundary
open Wireclub.Boundary.Chat
open Wireclub.Boundary.Models
open Routes

module WebView =
    let navigateDelegate = {
        new UIWebViewDelegate() with
        override this.ShouldStartLoad (view, request, navigationType) =
            if navigationType = UIWebViewNavigationType.LinkClicked then
                let uri = new Uri(request.Url.AbsoluteString)
                Navigation.navigate (uri.ToString()) None
                false
            else
                true
    }

    let setupWebView (webView:UIWebView, url:string) =
            webView.LoadRequest(new NSUrlRequest(new NSUrl(url)))

            webView.ShouldStartLoad <- UIWebLoaderControl(fun webView request navigationType ->
                if request.Url.ToString() = url && request.Headers.Keys |> Array.exists ((=) (NSObject.FromObject "x-auth-token")) = false then

                    let headers = new NSMutableDictionary (request.Headers)
                    headers.SetValueForKey(NSObject.FromObject (Api.userToken), new NSString("x-auth-token"))
                    let request = request.MutableCopy () :?> NSMutableUrlRequest

                    request.Headers <- headers
                    webView.LoadRequest request
                    false
                else
                    true
            )

            webView.LoadFinished.Add(fun _ ->
                webView.Delegate <- navigateDelegate
                webView.SetBodyBackgroundColor (colorToCss Utility.grayLightAccent)
            )

        
type UserBaseViewController (handle:nativeint) =
    inherit UIViewController (handle)

    member val User: Entity option = None with get, set


[<Register ("UserFeedViewController")>]
type UserFeedViewController (handle:nativeint) as controller =
    inherit UserBaseViewController (handle)

    [<Outlet>]
    member val WebView: UIWebView = null with get, set

    override this.ViewDidLoad () =
        base.ViewDidLoad ()

        match this.User with
        | Some user -> WebView.setupWebView(this.WebView, Api.baseUrl + "/users/" + controller.User.Value.Slug)
        | _ -> ()

[<Register ("UserGalleryViewController")>]
type UserGalleryViewController (handle:nativeint) as controller =
    inherit UserBaseViewController (handle)

    [<Outlet>]
    member val WebView: UIWebView = null with get, set

    override this.ViewDidLoad () =
        base.ViewDidLoad ()

        match this.User with
        | Some user -> WebView.setupWebView(this.WebView, Api.baseUrl + "/users/" + controller.User.Value.Slug + "/pictures")
        | _ -> ()

[<Register ("UserBlogViewController")>]
type UserBlogViewController (handle:nativeint) as controller =
    inherit UserBaseViewController (handle)

    [<Outlet>]
    member val WebView: UIWebView = null with get, set

    override this.ViewDidLoad () =
        base.ViewDidLoad ()

        match this.User with
        | Some user -> WebView.setupWebView(this.WebView, Api.baseUrl + "/users/" + controller.User.Value.Slug + "/blog")
        | _ -> ()


[<Register ("UserViewController")>]
type UserViewController (handle:nativeint) =
    inherit UITableViewController (handle)

    let mutable isBlocked = false
    let mutable isFriend = false
    let mutable image = Image.placeholderMale 

    member val Entity: Entity option = None with get, set

    [<Outlet>]
    member val ImageView: UIView = null with get, set

    [<Outlet>]
    member val ChatButton: UIButton = null with get, set

    [<Outlet>]
    member val BlockButton: UIButton = null with get, set

    [<Outlet>]
    member val FriendButton: UIButton = null with get, set

    [<Outlet>]
    member val UnblockButton: UIButton = null with get, set

    [<Outlet>]
    member val UnfriendButton: UIButton = null with get, set

    [<Outlet>]
    member val ProfileLabel: UILabel = null with get, set

    [<Outlet>]
    member val LocationLabel: UILabel = null with get, set

    override this.ViewDidLoad () =
        base.ViewDidLoad ()
   
        this.AutomaticallyAdjustsScrollViewInsets <- false

        match this.Entity with
        | Some user -> 
            this.NavigationItem.Title <- user.Label
            Image.loadImageWithContinuation (App.imageUrl user.Image 320)  Image.placeholder (fun i _ ->
                image <- i
                let imageView = new UIImageView(image)
                for view in this.ImageView.Subviews do view.RemoveFromSuperview ()
                this.ImageView.Add imageView
                this.TableView.ReloadRows([| NSIndexPath.FromRowSection(0, 0) |], UITableViewRowAnimation.None)
            )

            this.TableView.ReloadData()

            this.ChatButton.TouchUpInside.Add(fun _ ->            <commit_msg>Fixed a bug where the placeholder was massive<commit_after>// Copyright (c) Wireclub Media Inc. All Rights Reserved. See License.md in the project root for license information.

namespace Wireclub.iOS

open System
open System.Drawing
open System.Threading
open System.Collections.Generic
open System.Collections.Concurrent
open MonoTouch.Foundation
open MonoTouch.UIKit
open Wireclub.Boundary
open Wireclub.Boundary.Chat
open Wireclub.Boundary.Models
open Routes

module WebView =
    let navigateDelegate = {
        new UIWebViewDelegate() with
        override this.ShouldStartLoad (view, request, navigationType) =
            if navigationType = UIWebViewNavigationType.LinkClicked then
                let uri = new Uri(request.Url.AbsoluteString)
                Navigation.navigate (uri.ToString()) None
                false
            else
                true
    }

    let setupWebView (webView:UIWebView, url:string) =
            webView.LoadRequest(new NSUrlRequest(new NSUrl(url)))

            webView.ShouldStartLoad <- UIWebLoaderControl(fun webView request navigationType ->
                if request.Url.ToString() = url && request.Headers.Keys |> Array.exists ((=) (NSObject.FromObject "x-auth-token")) = false then

                    let headers = new NSMutableDictionary (request.Headers)
                    headers.SetValueForKey(NSObject.FromObject (Api.userToken), new NSString("x-auth-token"))
                    let request = request.MutableCopy () :?> NSMutableUrlRequest

                    request.Headers <- headers
                    webView.LoadRequest request
                    false
                else
                    true
            )

            webView.LoadFinished.Add(fun _ ->
                webView.Delegate <- navigateDelegate
                webView.SetBodyBackgroundColor (colorToCss Utility.grayLightAccent)
            )

        
type UserBaseViewController (handle:nativeint) =
    inherit UIViewController (handle)

    member val User: Entity option = None with get, set


[<Register ("UserFeedViewController")>]
type UserFeedViewController (handle:nativeint) as controller =
    inherit UserBaseViewController (handle)

    [<Outlet>]
    member val WebView: UIWebView = null with get, set

    override this.ViewDidLoad () =
        base.ViewDidLoad ()

        match this.User with
        | Some user -> WebView.setupWebView(this.WebView, Api.baseUrl + "/users/" + controller.User.Value.Slug)
        | _ -> ()

[<Register ("UserGalleryViewController")>]
type UserGalleryViewController (handle:nativeint) as controller =
    inherit UserBaseViewController (handle)

    [<Outlet>]
    member val WebView: UIWebView = null with get, set

    override this.ViewDidLoad () =
        base.ViewDidLoad ()

        match this.User with
        | Some user -> WebView.setupWebView(this.WebView, Api.baseUrl + "/users/" + controller.User.Value.Slug + "/pictures")
        | _ -> ()

[<Register ("UserBlogViewController")>]
type UserBlogViewController (handle:nativeint) as controller =
    inherit UserBaseViewController (handle)

    [<Outlet>]
    member val WebView: UIWebView = null with get, set

    override this.ViewDidLoad () =
        base.ViewDidLoad ()

        match this.User with
        | Some user -> WebView.setupWebView(this.WebView, Api.baseUrl + "/users/" + controller.User.Value.Slug + "/blog")
        | _ -> ()


[<Register ("UserViewController")>]
type UserViewController (handle:nativeint) =
    inherit UITableViewController (handle)

    let mutable isBlocked = false
    let mutable isFriend = false
    let mutable image = Image.placeholderMale 

    member val Entity: Entity option = None with get, set

    [<Outlet>]
    member val ImageView: UIView = null with get, set

    [<Outlet>]
    member val ChatButton: UIButton = null with get, set

    [<Outlet>]
    member val BlockButton: UIButton = null with get, set

    [<Outlet>]
    member val FriendButton: UIButton = null with get, set

    [<Outlet>]
    member val UnblockButton: UIButton = null with get, set

    [<Outlet>]
    member val UnfriendButton: UIButton = null with get, set

    [<Outlet>]
    member val ProfileLabel: UILabel = null with get, set

    [<Outlet>]
    member val LocationLabel: UILabel = null with get, set

    static member val Placeholder = lazy Image.resize (new SizeF (320.0f, 320.0f)) Image.placeholder

    override this.ViewDidLoad () =
        base.ViewDidLoad ()
   
        this.AutomaticallyAdjustsScrollViewInsets <- false

        match this.Entity with
        | Some user -> 
            this.NavigationItem.Title <- user.Label
            Image.loadImageWithContinuation (App.imageUrl user.Image 320)  UserViewController.Placeholder.Value (fun i _ ->
                image <- i
                let imageView = new UIImageView(image)
                for view in this.ImageView.Subviews do view.RemoveFromSuperview ()
                this.ImageView.Add imageView
                this.TableView.ReloadRows([| NSIndexPath.FromRowSection(0, 0) |], UITableViewRowAnimation.None)
            )

            this.TableView.ReloadData()

            this.ChatButton.TouchUpInside.Add(fun _ ->            
{'fraction_non_alphanumeric': 0.08925958443078724, 'fraction_numerical': 0.001755926251097454, 'mean_word_length': 2.5037593984962405, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 59, 'https://': 0, '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': '469588', 'n_tokens_mistral': 2885, 'n_tokens_neox': 2663, 'n_words': 748}