Skip to content

Instantly share code, notes, and snippets.

View felipeslongo's full-sized avatar
🌴
Having Fun With Threads

Felipe de Souza Longo felipeslongo

🌴
Having Fun With Threads
View GitHub Profile
@felipeslongo
felipeslongo / AdapterView.ItemClickEventArgs+GetItem.cs
Created April 10, 2019 17:59
Gets the selected/clicked item
using Android.Widget;
using Java.Lang;
namespace App.Droid.Extensions
{
/// <summary>
/// Extension method GetItem for <see cref="AdapterView.ItemClickEventArgs"/>
/// </summary>
/// <seealso cref="https://stackoverflow.com/questions/4819813/how-to-get-text-from-autocomplete-textview-android"/>
public static class AdapterView_ItemClickEventArgs_GetItem
using System.Globalization;
using System.Linq;
using System.Text;
namespace Core.Extensions
{
public static class String_RemoveDiacritics
{
public static string RemoveDiacritics(this string @this)
=> string.Concat(
@felipeslongo
felipeslongo / StringCaseInsensitiveUnaccented.cs
Created April 12, 2019 17:50
Encapsulates a string that is case insensitive and dont care about accents
using Core.Extensions;
namespace Core.ValueTypes
{
public class StringCaseInsensitiveUnaccented
{
public static bool Compare(string a, string b)
=> a.RemoveDiacritics().ToUpper().Equals(b.RemoveDiacritics().ToUpper());
}
}
@felipeslongo
felipeslongo / CancellationTokenSourceRenew
Last active April 24, 2019 16:44
Utility to renew a cancellation token correctly
using System.Threading;
namespace Core.Extensions
{
public static class CancellationTokenSourceRenew
{
public static CancellationTokenSource Renew(this CancellationTokenSource @this)
{
Cancel(@this);
return new CancellationTokenSource();
using System;
using UIKit;
namespace App.iOS.Extensions
{
public static class UIViewController_AddSearchController
{
public static UISearchController AddSearchController(this UIViewController @this)
{
var searchController = new UISearchController(null as UIViewController);
Task pendingTask = null; // pending session
CancellationTokenSource cts = null; // CTS for pending session
// SpellcheckAsync is called by the client app on the UI thread
public async Task<bool> SpellcheckAsync(CancellationToken token)
{
// SpellcheckAsync can be re-entered
var previousCts = this.cts;
var newCts = CancellationTokenSource.CreateLinkedTokenSource(token);
this.cts = newCts;
@felipeslongo
felipeslongo / EditText+SetupClearButtonWithAction.cs
Last active April 23, 2019 16:22
Setup a clear icon that when clicked executes que action provided
using System;
using Android.Text;
using Android.Views;
using Android.Widget;
using App.Droid.Utils;
namespace App.Droid.Extensions
{
/// <summary>
///
using System;
using Android.Graphics.Drawables;
using Android.Views;
using Android.Widget;
namespace App.Droid.Utils
{
public static class TextViewDrawableTouchEventHandler
{
const int DrawableLeft = 0;
@felipeslongo
felipeslongo / UIViewController+AdicionarBarraDeBusca.cs
Last active April 25, 2019 18:14
Adiciona barra de busca em qualquer versão do IOS
using System;
using App.iOS.Utils;
using UIKit;
namespace App.iOS.Extensions
{
//https://stackoverflow.com/questions/48007690/issue-with-uisearchcontroller-in-uitableview-on-ios-11
//https://stackoverflow.com/questions/28326269/uisearchbar-presented-by-uisearchcontroller-in-table-header-view-animates-too-fa?rq=1
public static class UIViewController_AdicionarBarraDeBusca
{
@felipeslongo
felipeslongo / UITableView+AtribuirTableHeaderView.cs
Last active April 25, 2019 18:01
Garante que o table header view vai ser redimensionado corretamente para encapsular a view atribuida
using UIKit;
namespace App.iOS.Extensions
{
//https://stackoverflow.com/questions/5484493/changing-the-height-of-a-tableheaderview-hides-the-cells/5764819#5764819
public static class UITableViewAtribuirTableHeaderView
{
private static bool VersaoIosBugadaQueNaoAtualizaOTamanhoCorretamenteDoTableHeaderView =>
!UIDevice.CurrentDevice.CheckSystemVersion(9, 0);