Skip to content

Commit

Permalink
Merge pull request #10 from muak/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
muak authored Jun 4, 2020
2 parents ee93681 + d0808d6 commit 397c754
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## files generated by popular Visual Studio add-ons.

.vs/
mono_crash.*

# User-specific files
*.suo
Expand Down
2 changes: 1 addition & 1 deletion AiForms.Dialogs.Android/AiForms.Dialogs.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AiForms.Dialogs.Abstractions\AiForms.Dialogs.Abstractions.csproj">
<Project>{7FAEA2AA-1832-4CAF-B0BA-4501F377269D}</Project>
<Project>{0BDF7090-FE73-49E6-B554-B2DA240768BB}</Project>
<Name>AiForms.Dialogs.Abstractions</Name>
</ProjectReference>
</ItemGroup>
Expand Down
10 changes: 6 additions & 4 deletions AiForms.Dialogs.Android/DefaultLoading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ public async Task StartAsync(Func<IProgress<double>, Task> action, string messag

public void Show(string message = null, bool isCurrentScope = false)
{
IsDialogShownTcs = new TaskCompletionSource<bool>();
OnceInitializeAction?.Invoke();

var payload = new LoadingDialogPayload(ContentView);
var payload = new LoadingDialogPayload(ContentView,IsDialogShownTcs);

var bundle = new Bundle();
bundle.PutSerializable(LoadingDialogPayload.PayloadKey, payload);
Expand All @@ -56,7 +57,8 @@ public void Show(string message = null, bool isCurrentScope = false)
}

public void Hide()
{
{

if (Progress != null)
{
Progress.ProgressChanged -= ProgressAction;
Expand All @@ -70,9 +72,9 @@ public void Hide()

Task.Run(async () =>
{
// Wait a bit for ensuring that the dialog is created.
// Wait for ensuring that the dialog is created.
// Because it sometimes crashes or freezes when executing a very short process.
await Task.Delay(50);
await IsDialogShownTcs.Task;
var dialog = FragmentManager.FindFragmentByTag<LoadingPlatformDialog>(LoadingImplementation.LoadingDialogTag);
dialog?.Dismiss();
ContentView.RemoveFromParent();
Expand Down
16 changes: 0 additions & 16 deletions AiForms.Dialogs.Android/DialogImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ namespace AiForms.Dialogs
[Android.Runtime.Preserve(AllMembers = true)]
public class DialogImplementation : IDialog
{
public static readonly string ExtraDialogTag = "ExtraDialog";
internal ExtraPlatformDialog ExtraDialog;
FragmentManager FragmentManager => Dialogs.FragmentManager;

public DialogImplementation()
{
ExtraDialog = new ExtraPlatformDialog();
}

public IReusableDialog Create<TView>(object viewModel = null) where TView : DialogView
Expand All @@ -30,8 +25,6 @@ public IReusableDialog Create(DialogView view, object viewModel = null)

public async Task<bool> ShowAsync<TView>(object viewModel = null) where TView : DialogView
{
if (IsRunning()) return false;

using (var dlg = Create<TView>(viewModel))
{
return await dlg.ShowAsync();
Expand All @@ -40,19 +33,10 @@ public async Task<bool> ShowAsync<TView>(object viewModel = null) where TView :

public async Task<bool> ShowAsync(DialogView view, object viewModel = null)
{
if (IsRunning()) return false;

using (var dlg = Create(view, viewModel))
{
return await dlg.ShowAsync();
}
}

bool IsRunning()
{
var dialog = Dialogs.FragmentManager.FindFragmentByTag<ExtraPlatformDialog>(DialogImplementation.ExtraDialogTag);
return dialog != null;
}

}
}
5 changes: 5 additions & 0 deletions AiForms.Dialogs.Android/ExtraPlatformDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class ExtraPlatformDialog : Android.App.DialogFragment
DialogView _dialogView;
ViewGroup _contentView;

public ExtraPlatformDialog() { }

// System Required!
public ExtraPlatformDialog(IntPtr handle, JniHandleOwnership transfer) :base(handle,transfer) { }

public override Android.App.Dialog OnCreateDialog(Bundle savedInstanceState)
{
base.OnCreateDialog(savedInstanceState);
Expand Down
2 changes: 2 additions & 0 deletions AiForms.Dialogs.Android/LoadingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class LoadingBase:IDisposable

protected ViewGroup ContentView;

protected TaskCompletionSource<bool> IsDialogShownTcs;

public LoadingBase(LoadingPlatformDialog loadingDialog)
{
PlatformDialog = loadingDialog;
Expand Down
8 changes: 6 additions & 2 deletions AiForms.Dialogs.Android/LoadingDialogPayload.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AiForms.Dialogs.Abstractions;
using System.Threading.Tasks;
using AiForms.Dialogs.Abstractions;
using Android.Views;
using Java.IO;

Expand All @@ -10,11 +11,13 @@ public class LoadingDialogPayload : Java.Lang.Object, ISerializable
public static readonly string PayloadKey = "loadingDialogPayload";
public LoadingView LoadingView { get; set; }
public ViewGroup ContentView { get; set; }
public TaskCompletionSource<bool> IsShownTcs { get; set; }

public LoadingDialogPayload(ViewGroup contentView, LoadingView loadingView = null)
public LoadingDialogPayload(ViewGroup contentView, TaskCompletionSource<bool> tcs, LoadingView loadingView = null)
{
LoadingView = loadingView;
ContentView = contentView;
IsShownTcs = tcs;
}

protected override void Dispose(bool disposing)
Expand All @@ -23,6 +26,7 @@ protected override void Dispose(bool disposing)
{
LoadingView = null;
ContentView = null;
IsShownTcs = null;
}
base.Dispose(disposing);
}
Expand Down
11 changes: 10 additions & 1 deletion AiForms.Dialogs.Android/LoadingPlatformDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public override Android.App.Dialog OnCreateDialog(Bundle savedInstanceState)

_loadingView = payload.LoadingView;
_contentView = payload.ContentView;
var isShowTcs = payload.IsShownTcs;

payload.Dispose();

Expand All @@ -36,7 +37,15 @@ public override Android.App.Dialog OnCreateDialog(Bundle savedInstanceState)

DestroyTcs = new TaskCompletionSource<bool>();

return dialog;
try
{

return dialog;
}
finally
{
isShowTcs.SetResult(true);
}
}

public override void OnStart()
Expand Down
25 changes: 14 additions & 11 deletions AiForms.Dialogs.Android/ReusableDialog.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using AiForms.Dialogs.Abstractions;
using Android.App;
Expand All @@ -16,18 +17,18 @@ namespace AiForms.Dialogs
[Android.Runtime.Preserve(AllMembers = true)]
public class ReusableDialog:Java.Lang.Object, IReusableDialog, View.IOnKeyListener
{
DialogImplementation _extraDialog;
ExtraPlatformDialog _platformDialog => _extraDialog.ExtraDialog;
ExtraPlatformDialog _platformDialog;
FragmentManager FragmentManager => Dialogs.FragmentManager;
DialogView _dlgView;
IVisualElementRenderer _renderer;
ViewGroup _contentView;
Action OnceInitializeAction;
Guid _guid;

public ReusableDialog(DialogView view)
{
_dlgView = view;
_extraDialog = Dialog.Instance as DialogImplementation;
_dlgView = view;
_guid = Guid.NewGuid();

// Because the process can't be executed until application completely loads,
// set the action here to execute later on.
Expand Down Expand Up @@ -125,7 +126,7 @@ void Initialize()

public async Task<bool> ShowAsync()
{
var dialog = FragmentManager.FindFragmentByTag<ExtraPlatformDialog>(DialogImplementation.ExtraDialogTag);
var dialog = FragmentManager.FindFragmentByTag<ExtraPlatformDialog>(_guid.ToString());
if (dialog != null)
{
return false;
Expand All @@ -148,7 +149,7 @@ async void complete(object sender, EventArgs e)
_dlgView.RunDismissalAnimation();
await Dismiss();
tcs.SetResult(true);
};
}

_dlgView.DialogNotifierInternal.Canceled += cancel;
_dlgView.DialogNotifierInternal.Completed += complete;
Expand All @@ -157,8 +158,9 @@ async void complete(object sender, EventArgs e)
var payload = new ExtraDialogPayload(_dlgView,_contentView);
var bundle = new Bundle();
bundle.PutSerializable("extraDialogPayload", payload);
_platformDialog = new ExtraPlatformDialog();
_platformDialog.Arguments = bundle;
_platformDialog.Show(FragmentManager, DialogImplementation.ExtraDialogTag);
_platformDialog.Show(FragmentManager, _guid.ToString());

try
{
Expand All @@ -171,6 +173,7 @@ async void complete(object sender, EventArgs e)
_dlgView.TearDown();
payload.Dispose();
bundle.Dispose();

}
}

Expand All @@ -190,16 +193,14 @@ protected override void Dispose(bool disposing)
if (!_renderer.View.IsDisposed())
{
_renderer.View.Dispose();
}
}

_contentView.Dispose();
_contentView = null;

_renderer.Dispose();
_renderer = null;

_extraDialog = null;

OnceInitializeAction = null;
}
base.Dispose(disposing);
Expand Down Expand Up @@ -256,9 +257,11 @@ void handler(object sender, Animation.AnimationEndEventArgs e)
await tcs.Task;
anim.AnimationEnd -= handler;

var dialog = FragmentManager.FindFragmentByTag<ExtraPlatformDialog>(DialogImplementation.ExtraDialogTag);
var dialog = FragmentManager.FindFragmentByTag<ExtraPlatformDialog>(_guid.ToString());
dialog.Dismiss();
_contentView.RemoveFromParent();
_platformDialog.Dispose();
_platformDialog = null;

await Task.Delay(250); // wait for a bit time until the dialog is completely released.
}
Expand Down
7 changes: 4 additions & 3 deletions AiForms.Dialogs.Android/ReusableLoading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ public async Task StartAsync(Func<IProgress<double>, Task> action, bool isCurren

void ShowInner()
{
IsDialogShownTcs = new TaskCompletionSource<bool>();
OnceInitializeAction?.Invoke();

var payload = new LoadingDialogPayload(ContentView, _loadingView);
var payload = new LoadingDialogPayload(ContentView,IsDialogShownTcs, _loadingView);

var bundle = new Bundle();
bundle.PutSerializable(LoadingDialogPayload.PayloadKey, payload);
Expand All @@ -95,9 +96,9 @@ public void Hide()

Task.Run(async () =>
{
// Wait a bit for ensuring that the dialog is created.
// Wait for ensuring that the dialog is created.
// Because it sometimes crashes or freezes when executing a very short process.
await Task.Delay(50);
await IsDialogShownTcs.Task;
var dialog = FragmentManager.FindFragmentByTag<LoadingPlatformDialog>(LoadingImplementation.LoadingDialogTag);
dialog?.Dismiss();
ContentView.RemoveFromParent();
Expand Down
6 changes: 3 additions & 3 deletions Sample/Sample.iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>Sample</string>
<string>Dialogs</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
Expand Down Expand Up @@ -39,8 +39,8 @@
<key>XSAppIconAssets</key>
<string>Resources/Images.xcassets/AppIcons.appiconset</string>
<key>CFBundleName</key>
<string>Sample</string>
<string>Dialogs</string>
<key>CFBundleIdentifier</key>
<string>jp.kamusoft.sample</string>
<string>jp.kamusoft.dialogs</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Sample/Sample/ViewModels/DialogTestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ string GetHAlignString()

string GetVAlignString()
{
switch (HorizontalLayoutAlignment)
switch (VerticalLayoutAlignment)
{
case LayoutAlignment.Start:
return "Top";
Expand Down
38 changes: 19 additions & 19 deletions Sample/Sample/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ public MainPageViewModel(MyIndicatorView myIndicatorView)
var loadingFlg = false;
LoadingCommand.Subscribe(async _ =>
{
Loading.Instance.Show();
await Task.Delay(1);
Loading.Instance.Hide();

//await Loading.Instance.StartAsync(async progress => {
// //await Task.Delay(1);
// progress.Report(0d);
// for (var i = 0; i < 100; i++)
// {
// if (i == 50)
// {
// Loading.Instance.SetMessage("Soon...");
// }
// await Task.Delay(50);
// progress.Report((i + 1) * 0.01d);
// }
//},null,loadingFlg).ConfigureAwait(false);
//Loading.Instance.Show();
//await Task.Delay(1);
//Loading.Instance.Hide();

await Loading.Instance.StartAsync(async progress => {
//await Task.Delay(1);
progress.Report(0d);
for (var i = 0; i < 100; i++)
{
if (i == 50)
{
Loading.Instance.SetMessage("Soon...");
}
await Task.Delay(25);
progress.Report((i + 1) * 0.01d);
}
},null,loadingFlg).ConfigureAwait(false);

loadingFlg = !loadingFlg;
});
Expand All @@ -83,11 +83,11 @@ public MainPageViewModel(MyIndicatorView myIndicatorView)
});
await customLoading.StartAsync(async p =>
{
//await Task.Delay(1);
await Task.Delay(1);
p.Report(0d);
for (var i = 0; i < 100; i++)
{
await Task.Delay(50);
await Task.Delay(25);
p.Report((i + 1) * 0.01d);
}
});
Expand Down
Loading

0 comments on commit 397c754

Please sign in to comment.