SmartClient is a library that contains the default implementations to idenify a client.

Overview

Smart Client

SmartClient is a library that contains the default implementations to idenify a client.

## How to use? It's easy to setup and use. Just call the setup method of SmartClient in onCreate method of your application class.

class SampleApp : Application() {
    override fun onCreate() {
        super.onCreate()
        SmartClient.setup(this)
    }
}

Smart Client provides the following information.

val clientId: String // An identifier for the client
val sessionId: String // An identifier for the current client session.
val isEmulator: Boolean // Provides if the device is an emulator or not
val isRooted: Boolean // Provides if the devices is rooted or not
val time: Long // Device current time in milis
val lang: String // Device language
val type: Device.Type // Type of the Device: Phone or tablet
val osVersion: Int // Device's os version.
val brand: String // Brand of the device
val model: String // Model of the device

or you can get all these device specific information (and with extras) in a mutable map with calling generateHeaders() of the SmartClient.

How to customize?

SmartClient allows you to customize some of the default implementations.

Customizing Device Property Implementations

By default for device specific implementations, SmartClient uses it's own Device interface implementation CurrentDevice.

interface Device {
    val isDeviceEmulator: Boolean
    val isDeviceRooted: Boolean
    val deviceTime: Long
    val deviceLang: String
    val osVersion: Int
    val brand: String
    val model: String

    val rootChecker: RootChecker

    fun provideDeviceType(): Type

    enum class Type {
        PHONE, TABLET
    }
}

To customize the device specific implementations like root checking, finding the type of device or checking if it's emulator or not vs. you can implement Device interface by your own and pass it to the setup method of SmartClient

Please visit the util package to check the implementations of root checking and emulator checking. Please note that, these implementaions may have the improvement areas or may need a totally different approach to give the healty results for all type of devies or os versions. Contributions are always welcome!

### Customizing Local Data implementations By default for saving and retrieving data from local, SmartClient uses it's own LocalDataSource implementation DefaultLocalDataSource

/*
 * LocalDataSource
 * Contains the local data operation definitions.
 */
interface LocalDataSource {
    // Returns the client id
    fun getClientId(): String?

    // Saves the generated client id
    fun saveClientId(clientId: String)
}

To customize saving and retrieving client id logic you can pass your own LocalDataSource implementation to the setup method of SmartClient

### Customizing Id Generations By default for generating the Id's (client id and session id) SmartClient uses it's own default implementations.

typealias ClientIdGenerator = () -> String
typealias SessionIdGenerator = () -> String

val defaultClientIdGenerator: ClientIdGenerator = {
    UUID.randomUUID().toString()
}

val defaultSessionIdGenerator: SessionIdGenerator = {
    UUID.randomUUID().toString()
}

For changing the id creationg logic, you can pass your own ClientIdGenerator or SessionIdGenerator implementations to the setup method of SmartClient

### Cutomizing Headers SmartClient provides the device information (with some extra information) as Mutable Map with generateHeaders() method for adding these information to the api request headrs easily.

By default SmartClient uses it's own key map for headsrs while generating the map.

open class DefaultHeaderKeys(
    override val contentTypeKey: String = "Content-Type",
    override val acceptKey: String = "Accept",
    override val deviceLocaleKey: String = "x-device-locale",
    override val deviceBrandKey: String = "x-device-brand",
    override val deviceModelKey: String = "x-device-model",
    override val deviceOsKey: String = "x-device-os",
    override val deviceOsTypeKey: String = "x-device-os-type",
    override val channelKey: String = "x-channel",
    override val deviceTypeKey: String = "x-device-type",
    override val isEmulatorKey: String = "x-app-is-emulator",
    override val isRootedKey: String = "x-is-rooted",
    override val timeStampKey: String = "x-timestamp",
    override val clientIdKey: String = "x-client-id",
    override val sessionIdKey: String = "x-session-id"
) : HeaderKeyMap

To change the keys or use a totally different keymap, you extend DefaultHeaderKeys class or implement HeaderKeyMap and pass it to the setup method of SmartClient

Dependency

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
dependencies {
          implementation 'com.github.savepopulation:smart-client:1.0.0'	
}

License

 Copyright 2022 Taylan SABIRCAN

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
You might also like...
An app for developers which contains more than 2.4k+ resources , with 1.2k+ free public API documentation
An app for developers which contains more than 2.4k+ resources , with 1.2k+ free public API documentation

ResourceUp We often spend a lot of time finding good resources to get started with our project right? ResourceUp aims to provide all useful resources

A mobile application that contains up-to-date information about the latest earthquakes in Turkey, scientific explanations about earthquakes, and Turkey's earthquake map.
A mobile application that contains up-to-date information about the latest earthquakes in Turkey, scientific explanations about earthquakes, and Turkey's earthquake map.

Recent-Earthquakes A mobile application that contains up-to-date information about the latest earthquakes in Turkey, scientific explanations about ear

Mojito is a cocktail manual, which contains recipes, images, and so on.
Mojito is a cocktail manual, which contains recipes, images, and so on.

Mojito Mojito* is a cocktail manual, which contains recipes, images, and so on. *Mojito: an alcoholic drink made with rum, lime juice, sugar, and mint

Paimondex App is an Android App that contains super mini wiki for playable characters from Genshin Impact, where you can favorite to save the character

Paimondex App is an Android App that contains super mini wiki for playable characters from Genshin Impact, where you can favorite to save the character. This could also show you the description of the each character with their talents and constellations.

This app contains an order flow for cupcakes with options for quantity, flavor, and pickup date

This app contains an order flow for cupcakes with options for quantity, flavor, and pickup date. The order details get displayed on an order summary screen and can be shared to another app to send the order.

This repo contains sample mobile apps that implement contributor design pattern

This repo contains sample mobile apps that implement contributor design pattern. This design pattern was evolved to establish clean contracts for the developers and partners in Teams Mobile code base

An unofficial Zerotier Android client patched from official client
An unofficial Zerotier Android client patched from official client

An unofficial Zerotier Android client patched from official client

MEGA Android Client - A fully-featured client to access your Cloud Storage provided by MEGA

A fully-featured client to access your Cloud Storage provided by MEGA. This document will guide you to build the application on a Linux machine with Android Studio.

A modular and portable open source XMPP client library written in Java for Android and Java (SE) VMs

Smack About Smack is an open-source, highly modular, easy to use, XMPP client library written in Java for Java SE compatible JVMs and Android. Being a

Releases(1.0.2)
Owner
Taylan Sabırcan
Mobile Chapter Head, Android, Engineer, CS
Taylan Sabırcan
Advent of Code 2021 implementations in Kotlin

advent-of-code-in-kotlin-2021 Welcome to the Advent of Code1 Kotlin project created by acrane13 using the Advent of Code Kotlin Template delivered by

null 0 Dec 20, 2021
A repository that contains various examples of how to use the telegram-bot library.

Telegram-bot templates This repository contains simple different examples of how to use the telegram-bot library. How to use All the examples are conv

Jey 3 Nov 15, 2022
It is a project that contains lessons and examples about Kotlin programming language. 🇰

Kotlin Tutorials What is Kotlin? I added the platforms it supports and great resources. You can access the article from the link below: https://medium

Halil Özel 94 Dec 22, 2022
This repo contains example code for O'Reilly's "Programming Android" by Zigured Mednieks, Laird Dornin, Blake Meike and Masumi Nakamura

This repo contains working code for the example in O'Reilly's _Programming Android, 2nd Edition_; Mednieks, Dornin, Meike, Nakamura (http://shop.orei

G. Blake Meike 214 Nov 25, 2022
This repo contains example code for O'Reilly's "Programming Android" by Zigured Mednieks, Laird Dornin, Blake Meike and Masumi Nakamura

This repo contains working code for the example in O'Reilly's _Programming Android, 2nd Edition_; Mednieks, Dornin, Meike, Nakamura (http://shop.orei

G. Blake Meike 165 Nov 11, 2022
An Open-Source repository that contains all the Android Dev and Kotlin concepts and several projects on android ranging in difficulty making this repo completely beginner-friendly.

An Open-Source repository that contains all the Android Dev and Kotlin concepts and several projects on android ranging in difficulty making this repo completely beginner-friendly. The main aim of this repository is to help students who are learning Android Development or preparing for an Android Developer role-based job.

Mimo Patra 15 Dec 29, 2022
Simple Workout App which contains list of workouts.

MAD Assignment-2 Title : Simple-Workout-App Description : Simple Android App contains list workouts and keep track of progress based on workout Build

Mihir Muchhadiya 1 Dec 5, 2021
This app contains feature barcode and QR scanner, and video recording in-app.

BarcodeQRScannerAndVideoRecord This app contains feature barcode and QR scanner, and video recording in-app. Scanner using ML Kit and CameraX. Video R

Abdullah Fahmi 1 Dec 23, 2021
Repository contains structures and methods to execute linear algebra operations (matrix multiplication etc)

LinearAlgebra Repository contains structures and methods to execute linear algebra operations (matrix multiplication etc) Matrix class Matrix implemen

null 0 Apr 27, 2022
Manganers - An application that contains the most recommended places to eat in Purwokerto

manganers adalah aplikasi yang berisikan tempat makan di Purwokerto yang paling

Rizki Rafiif 0 Feb 4, 2022