Mobile app developer, focusing on Android. Working at Brightec (www.brightec.co.uk). Links: www.github.com/alistairsykes www.twitter.com/SykesAlistair
Image for post
Image for post

How and where to define your user-facing strings.

Messages.properties

You’ve probably already read about the messages.properties file. It allows you to define any strings you wish to present to an end-user.

messages.properties:

To retrieve one of these strings in code you first need to get a MessageSource. This is provided via spring dependency injection.

Constructor injection:

@Service // Or some other `Component` annotation
class SomeService( private val messageSource: MessageSource )

Property injection:

@Autowired private lateinit var messageSource: MessageSource

Then you can call getMessage:

messageSource.getMessage("title.example", null, LocaleContextHolder.getLocale())

args can be provided for string replacement. For example:

messageSource.getMessage("message.hello", arrayOf("Joe Bloggs"), LocaleContextHolder.getLocale())

Internationalization

Notice above, we pass LocaleContextHolder.getLocale() as a Locale to…


Image for post
Image for post

How to use JAXWS to generate HTTP client code using the Gradle Kotlin DSL.

WSDL

WSDL (Web Services Description Language) is an XML format. It describes network services, their endpoints and the corresponding request and response formats.

WSDL is commonly used in conjunction with a SOAP (Simple Object Access Protocol) API. Soap can be thought of as a way of structuring your API. Similar to what REST (REpresentational State Transfer) is.

WSDL File

Typically, the result of using WSDL is a .wsdl file. You may have multiple files, one for each service, and these can come in handy when trying to consume an API.

Since a .wsdl file describes exactly what the API looks like, you can…


Image for post
Image for post

Using the new and improved AnimatedVectorDrawable to pause and seek your animations.

AnimatedVectorDrawable

Android SDK 21 introduced both the VectorDrawable and the AnimatedVectorDrawable. This allowed you to use vector assets within your app, and even animate them.

They’ve iterated on these since then, but AnimatedVectorDrawable was still missing something. You couldn’t manipulate and control the animation. There was no pause or seek functionality.

Core-Animation

The Android team has been hard at work backporting the framework Animator APIs. They have created a separate unbundled AndroidX library called Core-Animation.

The Animator APIs have been around for some time. But they didn’t provide the capabilities needed for this pause and seek functionality. …


Image for post
Image for post

Educating Android users can be subtle by using motion

Material Design

The material design system will be familiar to most, as one of the most widely used design systems. It’s a visual language that represents good design principles whilst allowing expressive branding.

Foundationally, it is based on the physics of the world. This makes it natural and familiar to users. It models the way objects move and how they interact with each other.

Motion

Motion can celebrate the completion of a task, delight the user, or help to drive the user through a flow. The way objects move and interact can bring a touch of class and express your brand.

You can…


Image for post
Image for post

How to implement certificate pinning in Kotlin Multiplatform using Ktor

Certificate Pinning

Pinning certificates is a common practice when interacting with remote APIs. It is the act of constraining which certificates you trust. This helps to defend against attacks on certificate authorities. It also helps combat man-in-the-middle attacks.

There is a multitude of information available about certificate pinning. Here is some to get you started:

- https://owasp.org/www-community/controls/Certificate_and_Public_Key_Pinning

- https://labs.nettitude.com/tutorials/tls-certificate-pinning-101/

- https://docs.broadcom.com/docs/certificate-pinning-en

Kotlin Multiplatform

Kotlin Multiplatform (KMP) is a way of writing cross-platform code in Kotlin. It is not about compiling all code for all platforms, and it doesn’t limit you to a subset of common APIs. …


Image for post
Image for post

How does Kotlin Multiplatform affect your development culture?

Kotlin Multiplatform

Kotlin Multiplatform (KMP) is a way of writing cross-platform code in Kotlin. It is not about compiling all code for all platforms, and it doesn’t limit you to a subset of common APIs. KMP provides mechanisms for writing platform-specific implementations for a common API.

Culture

Culture is a big focus for many companies. We want to be in and build meaningful places to work. We want to be collaborative and make things better together.

However, we also like to feel part of a community. …


Image for post
Image for post

How to write tests within Kotlin Multiplatform

Testing

Code quality is very important, and testing is a huge part of code quality. You want to ensure the code you write behaves as expected. It also needs to work under a variety of conditions.

I use the Given When Then approach to testing across all our Small, Medium and Large tests. It’s a useful way of structuring tests. I also rely on mocking within my tests. I want to ensure the only thing I am testing is the class(es) I intended.

Kotlin Multiplatform

Testing within Kotlin Multiplatform is well supported and will feel very familiar.

implementation "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"

Kotlin provides…


Image for post
Image for post

How should you structure your multiplatform project?

Kotlin Multiplatform

Kotlin Multiplatform (KMP) is a way of writing cross-platform code in Kotlin. It is not about compiling all code for all platforms, and it doesn’t limit you to a subset of common APIs. KMP provides mechanisms for writing platform-specific implementations for a common API.

Android/iOS

One of the common use-cases, and indeed my main use-case, for KMP is to share code between an Android and iOS project.

Options

With KMP you have a few different options when it comes to deciding how to structure your projects.

All in one

You can combine your Android and iOS project into one project. They would live within the…


Image for post
Image for post

Creating tooling to maintain high-quality code

Motivation

Within our team, we pride ourselves on producing great products for our clients. More than that though, we aim to produce great code.

We want our code to meet high standards of efficiency, speed and maintainability. This means we adhere to style guides and apply best practices wherever we can.

These standards even apply to our XML files.

Code Review

We use peer code reviewing as a tool for maintaining high-quality code. We look for bugs, styling mistakes and any general improvements.

Since we are human, we cannot rely on code review as a safety net which will catch everything. …


Image for post
Image for post

What is it and why have we adopted it?

Mockk is a mocking framework built for Kotlin. Like Mockito, Mockk allows you to create and stub objects within your test code.

Mocking objects allows you to test in isolation other objects. Any dependency of the object under test can be mocked to provide fixed conditions, thus ensuring specific and stable tests.

Mockito is a common framework used by Java developers and is very powerful. But it does have some annoyances when used with Kotlin. Mockk, being specifically designed for Kotlin, is a more pleasant experience.

How to use it

With Mockito this is how you mocked an object:

import static org.mockito.Mockito.mock;MyClass mockedClass…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store