Skip to content

Commit

Permalink
Minor clean
Browse files Browse the repository at this point in the history
  • Loading branch information
kwsch committed Aug 8, 2021
1 parent 1754c68 commit 410ce5f
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 98 deletions.
13 changes: 5 additions & 8 deletions PKHeX.Android/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
using System;
using Acr.UserDialogs;
using Acr.UserDialogs;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace PKHeX.Droid
{
[Activity(Label = "PKHeX", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
UserDialogs.Init(this);

base.OnCreate(savedInstanceState);

global::Xamarin.Forms.Forms.SetFlags("Shell_Experimental", "Visual_Experimental", "CollectionView_Experimental", "FastRenderers_Experimental");
Xamarin.Forms.Forms.SetFlags("Shell_Experimental", "Visual_Experimental", "CollectionView_Experimental", "FastRenderers_Experimental");
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
Xamarin.Forms.Forms.Init(this, savedInstanceState);
ZXing.Net.Mobile.Forms.Android.Platform.Init();
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

Expand Down
1 change: 0 additions & 1 deletion PKHeX.Android/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;

Expand Down
4 changes: 2 additions & 2 deletions PKHeX.Drawing/ImageUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public static SKBitmap LayerImage(SKBitmap baseLayer, SKBitmap overLayer, int x,
return overLayer;
var img = baseLayer.Copy();
var rect = new SKRect(x, y, overLayer.Width + x, overLayer.Height + y);
using (var gr = new SKCanvas(img))
gr.DrawBitmap(overLayer, rect);
using var gr = new SKCanvas(img);
gr.DrawBitmap(overLayer, rect);
return img;
}

Expand Down
27 changes: 12 additions & 15 deletions PKHeX.Drawing/QRBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,18 @@ public static string GetQRMessage(PKM pkm)
public static SKBitmap GetQR(PKM pkm, int dim = 365)
{
string content = GetQRMessage(pkm);
using (var generator = new QRCodeGenerator())
{
// Generate QrCode
var qr = generator.CreateQrCode(content, ECCLevel.H);

// Render to canvas
var info = new SKImageInfo(dim, dim);
using (var surface = SKSurface.Create(info))
{
var canvas = surface.Canvas;
canvas.Render(qr, info.Width, info.Height);

return SKBitmap.Decode(surface.Snapshot().Encode().AsStream());
}
}
using var generator = new QRCodeGenerator();

// Generate QrCode
var qr = generator.CreateQrCode(content, ECCLevel.H);

// Render to canvas
var info = new SKImageInfo(dim, dim);
using var surface = SKSurface.Create(info);
var canvas = surface.Canvas;
canvas.Render(qr, info.Width, info.Height);

return SKBitmap.Decode(surface.Snapshot().Encode().AsStream());
}
}
}
2 changes: 1 addition & 1 deletion PKHeX.Drawing/SpriteName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static string GetResourceStringSprite(int species, int form, int gender,
}

/// <summary>
/// Species that show their default Species sprite regardless of current <see cref="PKM.AltForm"/>
/// Species that show their default Species sprite regardless of current <see cref="PKM.Form"/>
/// </summary>
private static readonly HashSet<int> SpeciesDefaultFormSprite = new HashSet<int>
{
Expand Down
7 changes: 1 addition & 6 deletions PKHeX.Mobile/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace PKHeX
namespace PKHeX
{
public partial class AppShell : Xamarin.Forms.Shell
{
Expand Down
26 changes: 1 addition & 25 deletions PKHeX.Mobile/Logic/BindingUtil.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
using System.Collections.Generic;
using System.Linq;

using PKHeX.Core;

namespace PKHeX.Mobile.Logic
namespace PKHeX.Mobile.Logic
{
public static class BindingUtil
{
/// <summary>
/// Binding with a struct-based item works fine on Windows Forms, but others require an actual object (class) reference.
/// </summary>
/// <param name="list">Input list</param>
/// <returns>Wrapped list</returns>
public static ComboObject[] Convert(this IEnumerable<ComboItem> list) => list.Select(z => new ComboObject(z)).ToArray();

public static int GetValue(object val)
{
if (val is int i)
return i;
return int.TryParse(val as string, out int v) ? v : 0;
}
}

public class ComboObject
{
public string Text { get; set; }
public int Value { get; set; }

public ComboObject(ComboItem item)
{
Text = item.Text;
Value = item.Value;
}
}
}
1 change: 1 addition & 0 deletions PKHeX.Mobile/PKHeX.Mobile.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
15 changes: 7 additions & 8 deletions PKHeX.Mobile/ViewModels/ComboSource.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System.Collections.Generic;
using PKHeX.Core;
using PKHeX.Mobile.Logic;

namespace PKHeX.ViewModels
{
public class ComboSource
{
public IReadOnlyList<ComboObject> SpeciesList { get; } = GameInfo.FilteredSources.Species.Convert();
public IReadOnlyList<ComboObject> MoveList { get; } = GameInfo.FilteredSources.Moves.Convert();
public IReadOnlyList<ComboObject> ItemList { get; } = GameInfo.FilteredSources.Items.Convert();
public IReadOnlyList<ComboObject> NatureList { get; } = GameInfo.FilteredSources.Natures.Convert();
public IReadOnlyList<ComboObject> Versions { get; } = GameInfo.FilteredSources.Games.Convert();
public IReadOnlyList<ComboObject> Balls { get; } = GameInfo.FilteredSources.Balls.Convert();
public IReadOnlyList<ComboItem> SpeciesList { get; } = GameInfo.FilteredSources.Species;
public IReadOnlyList<ComboItem> MoveList { get; } = GameInfo.FilteredSources.Moves;
public IReadOnlyList<ComboItem> ItemList { get; } = GameInfo.FilteredSources.Items;
public IReadOnlyList<ComboItem> NatureList { get; } = GameInfo.FilteredSources.Natures;
public IReadOnlyList<ComboItem> Versions { get; } = GameInfo.FilteredSources.Games;
public IReadOnlyList<ComboItem> Balls { get; } = GameInfo.FilteredSources.Balls;
}
}
}
6 changes: 3 additions & 3 deletions PKHeX.Mobile/ViewModels/LoadableViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace PKHeX.ViewModels
{
public class LoadableViewModel : BaseViewModel
{
public ObservableCollection<LoadableSAV> Saves { get; set; } = new ObservableCollection<LoadableSAV>();
public ObservableCollection<LoadableSAV> Saves { get; set; } = new();
public ObservableCollection<LoadableSAV> Filtered { get; set; }

public ICommand SearchCommand => new Command<string>(SearchItems);
Expand All @@ -22,10 +22,10 @@ private void SearchItems(string query)
else
{
var filteredItems = Saves
.Where(bear => bear.File.Metadata.FileName.IndexOf(query, System.StringComparison.OrdinalIgnoreCase) >= 0)
.Where(bear => bear.File.Metadata.FileName is { } s && s.IndexOf(query, System.StringComparison.OrdinalIgnoreCase) >= 0)
.ToList();
Filtered = new ObservableCollection<LoadableSAV>(filteredItems);
}
}
}
}
}
15 changes: 7 additions & 8 deletions PKHeX.Mobile/ViewModels/PKMViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.ObjectModel;
using PKHeX.Core;
using PKHeX.Mobile.Logic;
using SkiaSharp.Views.Forms;
using Xamarin.Forms;

Expand Down Expand Up @@ -65,8 +64,8 @@ private void RefreshForms()

private void RefreshAbilities()
{
var list = GameInfo.FilteredSources.GetAbilityList(Data).Convert();
Abilities = new ObservableCollection<ComboObject>(list);
var list = GameInfo.FilteredSources.GetAbilityList(Data);
Abilities = new ObservableCollection<ComboItem>(list);
}

public SaveFileViewModel SVM { get; }
Expand All @@ -77,10 +76,10 @@ private void RefreshAbilities()
public FeatureFlags FeatureFlags { get; private set; }
public PersonalInfo Personal { get; private set; }

public ObservableCollection<ComboObject> MetLocations { get; set; }
public ObservableCollection<ComboObject> EggLocations { get; set; }
public ObservableCollection<ComboItem> MetLocations { get; set; }
public ObservableCollection<ComboItem> EggLocations { get; set; }

public ObservableCollection<ComboObject> Abilities { get; set; }
public ObservableCollection<ComboItem> Abilities { get; set; }
public ObservableCollection<string> Forms { get; set; }

public string PKMTitle => GetProgramTitle(Data);
Expand Down Expand Up @@ -417,8 +416,8 @@ private void SetAbilityList()

private void RefreshMetLocations()
{
MetLocations = new ObservableCollection<ComboObject>(GameInfo.GetLocationList((GameVersion)version, Data.Format).Convert());
EggLocations = new ObservableCollection<ComboObject>(GameInfo.GetLocationList((GameVersion)version, Data.Format, true).Convert());
MetLocations = new ObservableCollection<ComboItem>(GameInfo.GetLocationList((GameVersion)version, Data.Format));
EggLocations = new ObservableCollection<ComboItem>(GameInfo.GetLocationList((GameVersion)version, Data.Format, true));
}

private static string GetProgramTitle(PKM pkm)
Expand Down
4 changes: 2 additions & 2 deletions PKHeX.Mobile/ViewModels/SaveFileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public PKM Selected
get => selected;
set
{
if (selected == value)
if (ReferenceEquals(selected, value))
return;
selected = value;
}
Expand All @@ -94,7 +94,7 @@ public string ShowdownText {
}
}

public ObservableRangeCollection<string> BoxNames { get; } = new ObservableRangeCollection<string>();
public ObservableRangeCollection<string> BoxNames { get; } = new();

public int CurrentBox
{
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.Mobile/Views/PKMEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:xForms="clr-namespace:Syncfusion.SfNumericTextBox.XForms;assembly=Syncfusion.SfNumericTextBox.XForms"
xmlns:comboBox="clr-namespace:Syncfusion.XForms.ComboBox;assembly=Syncfusion.SfComboBox.XForms"
xmlns:tabView="clr-namespace:Syncfusion.XForms.TabView;assembly=Syncfusion.SfTabView.XForms"
xmlns:generic="clr-namespace:System.Collections.Generic;assembly=netstandard"
xmlns:generic="clr-namespace:System.Collections.Generic;assembly=netstandard" xmlns:viewmodels="clr-namespace:PKHeX.ViewModels" x:DataType="viewmodels:PKMViewModel"
mc:Ignorable="d"
x:Class="PKHeX.Mobile.Views.PKMEditor"
Title="{Binding Title}">
Expand Down
10 changes: 8 additions & 2 deletions PKHeX.Mobile/Views/SaveEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

namespace PKHeX.Mobile.Views
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class SaveEditor : ContentPage
{
Expand Down Expand Up @@ -105,13 +103,17 @@ private void SelectBoxPKM(object sender, EventArgs e)
{
int index = Array.IndexOf(BoxSprites, (Image)sender);
var arr = VM.CurrentBoxData;
if ((uint) index >= arr.Count)
return;
UpdateSelectedPKM(arr[index]);
}

private void SelectPartyPKM(object sender, EventArgs e)
{
int index = Array.IndexOf(PartySprites, (Image)sender);
var arr = VM.PartyData;
if ((uint)index >= arr.Count)
return;
UpdateSelectedPKM(arr[index]);
}

Expand All @@ -120,6 +122,8 @@ private async void TapSpriteBox(object sender, EventArgs e)
var img = (Image)sender;
int index = Array.IndexOf(BoxSprites, (Image)sender);
var arr = VM.CurrentBoxData;
if ((uint)index >= arr.Count)
return;

await TapStoredPKM(arr, index, img).ConfigureAwait(false);
}
Expand All @@ -129,6 +133,8 @@ private async void TapSpriteParty(object sender, EventArgs e)
var img = (Image)sender;
int index = Array.IndexOf(PartySprites, (Image)sender);
var arr = VM.PartyData;
if ((uint)index >= arr.Count)
return;

await TapStoredPKM(arr, index, img).ConfigureAwait(false);
}
Expand Down
14 changes: 5 additions & 9 deletions PKHeX.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;

using Foundation;
using Foundation;
using UIKit;

namespace PKHeX.iOS
Expand All @@ -11,7 +7,7 @@ namespace PKHeX.iOS
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
public class AppDelegate : Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
//
// This method is invoked when the application has loaded and is ready to run. In this
Expand All @@ -22,11 +18,11 @@ public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsAppli
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.SetFlags("Shell_Experimental", "Visual_Experimental", "CollectionView_Experimental", "FastRenderers_Experimental");
global::Xamarin.Forms.Forms.Init();
Xamarin.Forms.Forms.SetFlags("Shell_Experimental", "Visual_Experimental", "CollectionView_Experimental", "FastRenderers_Experimental");
Xamarin.Forms.Forms.Init();

Syncfusion.XForms.iOS.TabView.SfTabViewRenderer.Init();
global::ZXing.Net.Mobile.Forms.iOS.Platform.Init();
ZXing.Net.Mobile.Forms.iOS.Platform.Init();

LoadApplication(new App());

Expand Down
7 changes: 1 addition & 6 deletions PKHeX.iOS/Main.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;

using Foundation;
using UIKit;
using UIKit;

namespace PKHeX.iOS
{
Expand Down
1 change: 0 additions & 1 deletion PKHeX.iOS/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down

0 comments on commit 410ce5f

Please sign in to comment.