Пример #1
0
 private void SprayCam_SprayDeleted(ISpray spray)
 {
     DestroyListElement(spray);
     PositionListElements();
     UpdateListContentHeight();
     DeactivateHiddenListElements();
 }
Пример #2
0
    public void ShareSprayAsImage(ISpray spray)
    {
        Debug.Log("Share spray as Image");

        viewManager.ShowFacebookShareBackground();
        nativeShare.ShareImage(spray.Path);

        if (SprayShared != null)
        {
            SprayShared(spray, true);
        }
    }
Пример #3
0
    // Upload specific spray to drive
    IEnumerator UploadImageCoroutine(ISpray spray)
    {
        DriveUploadResult driveUploadResult = new DriveUploadResult
        {
            failed       = true,
            failedReason = "No result",
            failureType  = DriveFailureType.GenericFailure,
            fileId       = null,
        };

        ;

        yield return(driveReceiver.UploadCoroutine(driveFolderName, spray.DriveFileName, spray.Path, (DriveUploadResult result) =>
        {
            driveUploadResult.failed = result.failed;
            driveUploadResult.failedReason = result.failedReason;
            driveUploadResult.failureType = result.failureType;
            driveUploadResult.fileId = result.fileId;
        }));


        if (driveUploadResult.failed)
        {
            Debug.LogError("Spray drive upload failed, but at least we got notified in Unity: " + driveUploadResult);
            googleAnalytics.LogEvent("Spray", "Share error", "Spray drive upload failed, but at least we got notified in Unity: " + driveUploadResult, 1);

            switch (driveUploadResult.failureType)
            {
            case DriveFailureType.DrivePermissionIssue:
                viewManager.ShowAccountProhibited();
                break;

            case DriveFailureType.NoConnection:
                viewManager.ShowBadConnection(true);
                break;

            case DriveFailureType.AuthCanceled:
                viewManager.ShowDriveAuthFailed(true);
                break;

            default:
                // generic error handling for now
                viewManager.ShowUploadFailed(true);
                break;
            }
        }
        else
        {
            spray.DriveFileId = driveUploadResult.fileId;
            yield return(GetShareLink(spray, driveUploadResult.fileId));
        }
    }
Пример #4
0
 private void LinkShareOrAuthConfirm(ISpray spray)
 {
     if (!sprayCam.forceAuthConfirm && PlayerPrefs.GetInt("GoogleAuthConfirmed") == 1)
     {
         Debug.Log("LinkShareOrAuthConfirm() PlayerPrefs == " + PlayerPrefs.GetInt("GoogleAuthConfirmed"));
         shareChoiceSpray = spray;
         StartCoroutine(sprayCam.ShareSprayAsLink(spray));             // let ShareSprayAsLink handle the view changes
     }
     else
     {
         Debug.Log("LinkShareOrAuthConfirm() No account access!");
         // we need to warning user about google account access
         ShowView(authConfirmView, ShowMode.PushView);
     }
 }
Пример #5
0
    public void EditSpray(ISpray spray)
    {
        Debug.Log("Editing spray as new spray");
        CleanupWipTexture();
        inWIP = true;
        if (currentSpray != spray)
        {
            spray.LoadTexture();
            cameraCapture.LoadImage(spray.Texture);
            spray.UnloadTexture();

            googleAnalytics.LogEvent("Spray", "Edit Spray", spray.Id.ToString(), 1);
        }
        currentSpray = null;
    }
Пример #6
0
    private void CreateListElement(ISpray spray)
    {
        spray.OrderChanged += Spray_OrderChanged;

        GameObject go = Instantiate(listElementPrefab);

        go.name = "Photo Id " + spray.Id;
        go.SetActive(false);

        LibraryListElement elem = go.GetComponent <LibraryListElement>();

        elem.spray             = spray;
        elem.libraryController = this;

        // use the ScrollRect as the vertical drag handler
        LockedDragHandler lockedDragHandler = elem.GetComponent <LockedDragHandler>();

        lockedDragHandler.verticalEventReceiver = scrollRect.GetComponent <LockedDragForwarder>();

        int x = PhotoIO.GetThumbnailX(spray.Id);
        int y = PhotoIO.GetThumbnailY(spray.Id);

        // we need to deal with the half texel offset, but this creates a 1 pixel discontinuity, since the atan2 edge should overlap
        Vector4 texParams = new Vector4(x * PhotoIO.ThumbnailSizeX + PhotoIO.HalfPixel,
                                        y * PhotoIO.ThumbnailSizeY + PhotoIO.HalfPixel,
                                        PhotoIO.PanoScalingX * PhotoIO.ThumbnailSizeX,
                                        PhotoIO.PanoScalingY * PhotoIO.ThumbnailSizeY);

        // set the spray texture
        elem.sprayCanvas.material = Instantiate(elem.sprayCanvas.material);         // clone material for unique _TexParams
        elem.sprayCanvas.material.SetVector("_TexParams", texParams);
        elem.sprayCanvas.texture = PhotoIO.thumbnails;

        // set the label text
        elem.labelText.text = spray.Label;

        // anchor the list element to the content rect
        elem.scrollTransform.SetParent(contentRoot);
        elem.scrollTransform.offsetMin        = new Vector2(0, elem.scrollTransform.offsetMin.y);
        elem.scrollTransform.offsetMax        = new Vector2(0, elem.scrollTransform.offsetMax.y);
        elem.scrollTransform.anchoredPosition = new Vector2(0, 0);
        elem.scrollTransform.localScale       = Vector3.one;

        elem.DrawerPeeked += LibraryListElement_DrawerPeeked;
        elem.DrawerOpened += LibraryListElement_DrawerOpened;

        elementLookup[spray.Id] = elem;
    }
Пример #7
0
    public void ClearWorkInProgress()
    {
        Debug.Log("Clearing Work in Progress");
        CleanupWipTexture();
        cameraCapture.Clear();
        Blank        = true;
        inWIP        = true;
        currentSpray = null;

        googleAnalytics.LogEvent("Spray", "Cleared", null, 1);

        if (WorkInProgressCleared != null)
        {
            WorkInProgressCleared();
        }
    }
Пример #8
0
 public void RestoreWipTexture()
 {
     Debug.Log("Restoring WIP");
     if (currentSpray != null)
     {
         currentSpray.UnloadTexture();
     }
     if (wipTextureBackup != null)
     {
         //Color[] colors = wipTextureBackup.GetPixels();
         cameraCapture.Clear();
         cameraCapture.LoadImage(wipTextureBackup);
     }
     Blank        = wipTextureBlank;
     inWIP        = true;
     currentSpray = null;
 }
Пример #9
0
    private void DestroyListElement(ISpray spray)
    {
        spray.OrderChanged -= Spray_OrderChanged;

        var elem = elementLookup[spray.Id];

        if (elem)
        {
            elem.DrawerPeeked -= LibraryListElement_DrawerPeeked;
            elem.DrawerOpened -= LibraryListElement_DrawerOpened;
        }

        if (elem && elem.gameObject)
        {
            Destroy(elem.gameObject);
        }

        elementLookup.Remove(spray.Id);
    }
Пример #10
0
    public ISpray SaveWorkInProgress()
    {
        Debug.Log("Saving WIP");



        int id    = cameraCapture.Save();      // automatically clears the current render texture
        var spray = new SavedSpray(id, PhotoIO.saveMap.Count - 1);

        sprays.Add(spray);
        // so we can access it after saving
        currentSpray = spray;

        googleAnalytics.LogEvent("Spray", "Save Work In Progress", spray.Id.ToString(), 1);

        if (SprayCreated != null)
        {
            SprayCreated(spray);
        }

        return(spray);
    }
Пример #11
0
    public void DeleteSpray(ISpray spray)
    {
        Debug.Log("Deleting spray");
        spray.UnloadTexture();
        sprays.Remove(spray);

        PhotoIO.DeleteImage(spray.Id);

        googleAnalytics.LogEvent("Spray", "Delete", spray.Id.ToString(), 1);
        // we need to update the spray ordering so the list view can update
        // for now just update them all, only ones that change will fire a change event
        for (int i = 0; i < sprays.Count; i++)
        {
            sprays[i].Order = i;
        }

        Blank = true;

        if (SprayDeleted != null)
        {
            SprayDeleted(spray);
        }
    }
Пример #12
0
    public void PreviewSpray(ISpray spray)
    {
        Debug.Log("Previewing spray");

        if (inWIP == true)
        {
            CleanupWipTexture();
            wipTextureBlank  = Blank;
            wipTextureBackup = cameraCapture.CopyToNewTexture();
            wipTextureBackup.Apply();
        }
        else
        {
            wipTextureBlank = false;
        }
        Blank        = false;
        inWIP        = false;
        currentSpray = spray;
        spray.LoadTexture();
        cameraCapture.LoadImage(spray.Texture);
        spray.UnloadTexture();

        googleAnalytics.LogEvent("Spray", "Preview Spray", spray.Id.ToString(), 1);
    }
Пример #13
0
    private IEnumerator GetShareLink(ISpray spray, String fileId)
    {
        if (spray.ShareSlug.Contains("http"))
        {
            //SHARE LINK HERE ------------------
            ShareLink(spray.ShareSlug);
            // ---------------------------------

            if (SprayShared != null)
            {
                SprayShared(spray, false);
            }
        }
        else
        {
            string shareLink = String.Format(shareLinkFormat, fileId);
            Debug.Log("Spray drive fileId in unity land: " + fileId + " shareLink: " + shareLink);
            string hexHash;
            using (MD5 md5 = MD5.Create()) {
                string        md5Source     = Secrets.shareSecret + shareLink;
                byte[]        encodedSource = Encoding.UTF8.GetBytes(md5Source);
                byte[]        hashBytes     = md5.ComputeHash(encodedSource);
                StringBuilder sb            = new StringBuilder();
                for (int i = 0; i < hashBytes.Length; i++)
                {
                    sb.Append(hashBytes [i].ToString("x2"));                       // 2-digit hex per byte
                }

                hexHash = sb.ToString();
            }

            // Get OAuth2 access token for google api
            string token = driveReceiver.GetAccessToken();

            Debug.Log("hex hash for sig: " + hexHash);

            WWWForm f = new WWWForm();
            f.AddField("url", shareLink);
            f.AddField("sig", hexHash);
            f.AddField("token", token);

            WWW w = new WWW(serviceUrl, f);
            yield return(w);

            if (string.IsNullOrEmpty(w.error) && !fakeLinkGenerationFailure)
            {
                Debug.Log(w.text);
                string shareUrl = w.text.Trim();

                //SHARE LINK HERE ------------------
                ShareLink(shareUrl);
                // ---------------------------------

                if (SprayShared != null)
                {
                    SprayShared(spray, false);
                }

                spray.ShareSlug = shareUrl;

                if (linkShareBehaviour == LinkShareBehaviour.OpenBrowser)
                {
                    viewManager.Back();                      // pops off 'uploading view'
                    viewManager.Back();                      // pops off the share screen
                }
            }
            else
            {
                if (fakeLinkGenerationFailure)
                {
                    Debug.LogError("Faking link generation failure");
                }
                else
                {
                    Debug.LogError(w.error);
                    Debug.LogError(w.text);
                }
                viewManager.ShowUploadFailed(true);
            }
        }
    }
Пример #14
0
 public void ShowShareChoice(ISpray spray)
 {
     // HACK: lame way to store state so we know which spray to share...
     shareChoiceSpray = spray;
     ShowView(shareChoiceView, ShowMode.PushView);
 }
Пример #15
0
    // Coroutine handling sharing a spray.
    // Checks for permissions, checks if spray is on drive already, uploads and creates share url
    public IEnumerator ShareSprayAsLink(ISpray spray)
    {
        Debug.Log("Share spray as Link");

        // Check permissions to share
        yield return(StartCoroutine(CheckSharePermissionsCoroutine()));

        Debug.Log("Permissions checked " + permissionsResult);

        if (permissionsResult == true)
        {
            // Check if file already exists
            Boolean fileExists = false;
            Debug.Log("Check drive file id " + spray.DriveFileId);

            if (spray.DriveFileId != null && spray.DriveFileId.Length > 0)
            {
                // Create a DrivePermissionsResult to sattisfy compiler
                DriveFileExistsResult driveFileExistsResult = new DriveFileExistsResult
                {
                    failed       = true,
                    exists       = false,
                    failedReason = "No result",
                    failureType  = DriveFailureType.GenericFailure,
                };

                // Check permissions on Google Drive
                yield return(driveReceiver.CheckFileId(spray.DriveFileId, (DriveFileExistsResult result) => {
                    driveFileExistsResult.failed = result.failed;
                    driveFileExistsResult.exists = result.exists;
                    driveFileExistsResult.failedReason = result.failedReason;
                    driveFileExistsResult.failureType = result.failureType;
                    driveFileExistsResult.accountName = result.accountName;
                }));

                fileExists = driveFileExistsResult.exists;

                if (driveFileExistsResult.failed)
                {
                    Debug.LogError("Spray drive check file id failed: " + driveFileExistsResult);
                    googleAnalytics.LogEvent("Spray", "Share error", "Spray drive check file id failed: " + driveFileExistsResult, 1);

                    switch (driveFileExistsResult.failureType)
                    {
                    case DriveFailureType.DrivePermissionIssue:
                        viewManager.ShowAccountProhibited();
                        break;

                    case DriveFailureType.NoConnection:
                        viewManager.ShowBadConnection(true);
                        break;

                    case DriveFailureType.AuthCanceled:
                        viewManager.ShowDriveAuthFailed(true);
                        break;

                    default:
                        // generic error handling for now
                        viewManager.ShowUploadFailed(true);
                        break;
                    }
                    fileExists = false;
                }
            }

            // Check if shareslug exists, otherwise upload
            if (spray.ShareSlug.Contains("http") && fileExists)
            {
                //SHARE LINK HERE ------------------
                ShareLink(spray.ShareSlug);
                // ---------------------------------
                if (SprayShared != null)
                {
                    SprayShared(spray, false);
                }
            }
            else
            {
                // Clear the shareslug
                spray.ShareSlug = "";

                // Upload file
                yield return(StartCoroutine(UploadImageCoroutine(spray)));
            }
        }
    }
 private void SprayCam_SprayCreated(ISpray obj)
 {
     waitingForSave = false;
 }
Пример #17
0
 private void Spray_OrderChanged(ISpray spray, int order)
 {
     PositionListElements();
 }