Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add qr sharing #2861

Merged
merged 8 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions nekoyume/Assets/Plugins/NativeShare.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions nekoyume/Assets/Plugins/NativeShare/Android.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions nekoyume/Assets/Plugins/NativeShare/Android/NSCallbackHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#if UNITY_EDITOR || UNITY_ANDROID
using System.Collections;
using UnityEngine;

namespace NativeShareNamespace
{
public class NSCallbackHelper : MonoBehaviour
{
public NativeShare.ShareResultCallback callback;

private NativeShare.ShareResult result = NativeShare.ShareResult.Unknown;
private string shareTarget = null;

private bool resultReceived;

private void Awake()
{
DontDestroyOnLoad( gameObject );
}

private void Update()
{
if( resultReceived )
{
resultReceived = false;

try
{
if( callback != null )
callback( result, shareTarget );
}
finally
{
Destroy( gameObject );
}
}
}

private IEnumerator OnApplicationFocus( bool focus )
{
if( focus )
{
// Share sheet is closed and now Unity activity is running again. Send Unknown result if OnShareCompleted wasn't called
yield return null;
resultReceived = true;
}
}

public void OnShareCompleted( int resultRaw, string shareTarget )
{
NativeShare.ShareResult shareResult = (NativeShare.ShareResult) resultRaw;

if( result == NativeShare.ShareResult.Unknown )
{
result = shareResult;
this.shareTarget = shareTarget;
}
else if( result == NativeShare.ShareResult.NotShared )
{
if( shareResult == NativeShare.ShareResult.Shared )
{
result = NativeShare.ShareResult.Shared;
this.shareTarget = shareTarget;
}
else if( shareResult == NativeShare.ShareResult.NotShared && !string.IsNullOrEmpty( shareTarget ) )
this.shareTarget = shareTarget;
}
else
{
if( shareResult == NativeShare.ShareResult.Shared && !string.IsNullOrEmpty( shareTarget ) )
this.shareTarget = shareTarget;
}

resultReceived = true;
}
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#if UNITY_EDITOR || UNITY_ANDROID
using UnityEngine;

namespace NativeShareNamespace
{
public class NSShareResultCallbackAndroid : AndroidJavaProxy
{
private readonly NSCallbackHelper callbackHelper;

public NSShareResultCallbackAndroid( NativeShare.ShareResultCallback callback ) : base( "com.yasirkula.unity.NativeShareResultReceiver" )
{
callbackHelper = new GameObject( "NSCallbackHelper" ).AddComponent<NSCallbackHelper>();
callbackHelper.callback = callback;
}

public void OnShareCompleted( int result, string shareTarget )
{
if( !callbackHelper )
{
Debug.LogWarning( "NSCallbackHelper is destroyed!" );
return;
}

callbackHelper.OnShareCompleted( result, shareTarget );
}

public bool HasManagedCallback()
{
return callbackHelper && callbackHelper.callback != null;
}
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
33 changes: 33 additions & 0 deletions nekoyume/Assets/Plugins/NativeShare/Android/NativeShare.aar.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions nekoyume/Assets/Plugins/NativeShare/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions nekoyume/Assets/Plugins/NativeShare/Editor/NSPostProcessBuild.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System.IO;
using UnityEditor;
using UnityEngine;
#if UNITY_IOS
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
#endif

namespace NativeShareNamespace
{
[System.Serializable]
public class Settings
{
private const string SAVE_PATH = "ProjectSettings/NativeShare.json";

public bool AutomatedSetup = true;
public string PhotoLibraryUsageDescription = "The app requires access to Photos to save media to it.";

private static Settings m_instance = null;
public static Settings Instance
{
get
{
if( m_instance == null )
{
try
{
if( File.Exists( SAVE_PATH ) )
m_instance = JsonUtility.FromJson<Settings>( File.ReadAllText( SAVE_PATH ) );
else
m_instance = new Settings();
}
catch( System.Exception e )
{
Debug.LogException( e );
m_instance = new Settings();
}
}

return m_instance;
}
}

public void Save()
{
File.WriteAllText( SAVE_PATH, JsonUtility.ToJson( this, true ) );
}

#if UNITY_2018_3_OR_NEWER
[SettingsProvider]
public static SettingsProvider CreatePreferencesGUI()
{
return new SettingsProvider( "Project/yasirkula/Native Share", SettingsScope.Project )
{
guiHandler = ( searchContext ) => PreferencesGUI(),
keywords = new System.Collections.Generic.HashSet<string>() { "Native", "Share", "Android", "iOS" }
};
}
#endif

#if !UNITY_2018_3_OR_NEWER
[PreferenceItem( "Native Share" )]
#endif
public static void PreferencesGUI()
{
EditorGUI.BeginChangeCheck();

Instance.AutomatedSetup = EditorGUILayout.Toggle( "Automated Setup", Instance.AutomatedSetup );

EditorGUI.BeginDisabledGroup( !Instance.AutomatedSetup );
Instance.PhotoLibraryUsageDescription = EditorGUILayout.DelayedTextField( new GUIContent( "Photo Library Usage Description", "Shown to user when they select the 'Save to Photos' option in share sheet" ), Instance.PhotoLibraryUsageDescription );
EditorGUI.EndDisabledGroup();

if( EditorGUI.EndChangeCheck() )
Instance.Save();
}
}

public class NSPostProcessBuild
{
#if UNITY_IOS
[PostProcessBuild]
public static void OnPostprocessBuild( BuildTarget target, string buildPath )
{
if( !Settings.Instance.AutomatedSetup )
return;

if( target == BuildTarget.iOS )
{
string plistPath = Path.Combine( buildPath, "Info.plist" );

PlistDocument plist = new PlistDocument();
plist.ReadFromString( File.ReadAllText( plistPath ) );

PlistElementDict rootDict = plist.root;
rootDict.SetString( "NSPhotoLibraryUsageDescription", Settings.Instance.PhotoLibraryUsageDescription );
rootDict.SetString( "NSPhotoLibraryAddUsageDescription", Settings.Instance.PhotoLibraryUsageDescription );

File.WriteAllText( plistPath, plist.WriteToString() );
}
}
#endif
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "NativeShare.Editor",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "NativeShare.Runtime"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading