Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Answering Questions, & Questioning Answers

Saamer Mansoor saamerm

💭
Answering Questions, & Questioning Answers
View GitHub Profile
@saamerm
saamerm / JokeService.swift
Created Dec 1, 2021
Simplest way to make an API call in Swift
View JokeService.swift
import Foundation
private actor JokeServiceStore {
func load() async throws -> String {
let (data, _) = try await URLSession.shared.data(from: URL(string:"https://api.chucknorris.io/jokes/random")!)
let decodedResponse = try? JSONDecoder().decode(Joke.self, from: data)
return decodedResponse?.value ?? ""
}
}
class JokeService: ObservableObject {
View Steps to Migrate MVVMCross using PCL.txt
### Steps to perform migration of MvvmCross using PCL
(primarily done is Visual Studio for Mac)
This tutorial migrates
- PCL .Net solution to .NetStandard,
- MvvmCross 5 solution to MvvmCross 7.1,
- Android to AndroidX
#### The beginning
1. Create a new repository, with a Migration suffix
2. Inside it, create a New Blank Native Xamarin Template
@saamerm
saamerm / LeaderboardAPI.js
Last active Apr 3, 2021
Free and universal leaderboard/scoreboard for Games using Google Sheets
View LeaderboardAPI.js
// Note: For this to work, you just need to put your spreadsheet ID here in lines 26 and 43 and follow this tutorial https://medium.com/@prototypemakers/simplest-universal-free-game-leaderboard-with-google-sheets-5ab548db009f
// to see the steps for implementing this
// POST and GET API Entry points
// ------------
function doPost(request){
var requestObject = JSON.parse(request.postData.contents);
var result = processPostRequest(requestObject);
return ContentService
@saamerm
saamerm / IconSwitchService.cs
Created Dec 5, 2020
iOS Native Service that is connected to the Xamarin.Forms in order to progr.ammatically switch the App Icon after user installation. This is useful for allowing the user to personalize their app
View IconSwitchService.cs
using System.Threading.Tasks;
using AppIconUpdater.iOS;
using Xamarin.Forms;
using ui = UIKit.UIApplication;
[assembly: Dependency(typeof(IconSwitchService))]
namespace {YourNamespace}.iOS
{
public class IconSwitchService : IIconSwitchService
{
public async Task SwitchAppIconAsync(string iconName)
@saamerm
saamerm / AndroidAudioRecordingPlaybackService.cs
Created Dec 3, 2020
Sample Audio Recording service used for a Xamarin Forms application to record & play audio even if the user goes to the background. I expected to inherit from Android's Service, but I didn't need to do that
View AndroidAudioRecordingPlaybackService.cs
using Android;
using Android.App;
using Android.Media;
using Android.OS;
using Java.IO;
[assembly: Xamarin.Forms.Dependency(typeof(BackgroundRecord.Droid.AudioRecordingService))]
[assembly: UsesPermission(Manifest.Permission.RecordAudio)]
[assembly: UsesPermission(Manifest.Permission.ReadExternalStorage)]
[assembly: UsesPermission(Manifest.Permission.WriteExternalStorage)]
@saamerm
saamerm / TimeTrackingService.cs
Created Nov 30, 2020
Backgrounding service sample for Android
View TimeTrackingService.cs
using System;
using System.Timers;
using Android.App;
using Android.Content;
using Android.OS;
namespace SampleBackgroundServices.Droid
{
public class TimeTrackingService : Service
{
@saamerm
saamerm / InAppReviewService.cs
Last active Sep 21, 2020
Native service for an in-app review to display on Android, using the new v1.8 Play Core Library binding for Xamarin
View InAppReviewService.cs
[assembly: Xamarin.Forms.Dependency(typeof(NAMESPACE.Droid.InAppReviewService))]
namespace NAMESPACE.Droid
{
public class InAppReviewService : IInAppReview
{
public void LaunchReview()
{
#if DEBUG
// FakeReviewManager does not interact with the Play Store, so no UI is shown
// and no review is performed. Useful for unit tests.
@saamerm
saamerm / MvxLayoutInflater.cs
Last active Nov 20, 2020
MvvmCross 5.2.1 MvxLayoutInflater.cs containing fixes to MvxLayoutInflater.cs from MvvmCross 6.4.1. Check the 4 steps mentioned in the commented code on the top for steps on how to implement this.
View MvxLayoutInflater.cs
/* Steps:
1. Change the targetframework of your android project to Android 10 or above
2. Then add this file to your project either in one file or separate files.
3. Change the namespace from App.Droid to your Android project's namespace.
4. Then in all activities that inherit MvxAppCompatActivity or MvxActivity, add this override and build:
protected override void AttachBaseContext(Context @base)
{
base.AttachBaseContext(MvxContextWrapper2.Wrap(@base, this));
}
*/
@saamerm
saamerm / ButtonPressed.cs
Created Jul 5, 2020
Button Pressed Function on
View ButtonPressed.cs
var client = new HttpClient();
var model = new FeedbackModel()
{
Name = NameEntry.Text,
Phone = PhoneEntry.Text,
Email = EmailEntry.Text,
Feedback = FeedbackEntry.Text
};
var uri = "{WebAppUrl}";
var jsonString = JsonConvert.SerializeObject(model);
@saamerm
saamerm / MainPage.xaml
Created Jul 5, 2020
Feedback form Xaml code for Xamarin
View MainPage.xaml
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" x:Class="XamarinGoogleSheetsDB.MainPage"
BackgroundColor="LightGray">
<StackLayout HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Padding="40" WidthRequest="400">
<Label Text="FEEDBACK" FontAttributes="Bold" FontSize="Title"/>
<Entry x:Name="NameEntry" Placeholder="Name" ReturnType="Next" />
<Entry x:Name="EmailEntry" Placeholder="Email" ReturnType="Next" Keyboard="Email" />