An Android Library for in-app switching between environment variables

Overview

android-env-picker

An Android Library for in-app switching between environment variables.

Central use case is picking a desired endpoint for backend communication, but more complex data can be handled as well. The app will restart after making a change.

Architecture

All data is persisted via SharedPreferences. The method of serialization can be customized.

Usage

Advanced Usage

In case multiple String values need to be saved per entry, the MultiEntry class is a good solution. Usage is similar to SimpleEntry above. Alternatively, a custom data class can be chosen as Entry implementation.

Endpoint(name, fields[0], fields[1], fields[2]) }, // how to serialize it using Gson, you can use any serialization method you like { entry -> Gson().toJson(entry) }, // and how to deserialize it { str -> Gson().fromJson(str, Endpoint::class.java) } ), // which Endpoints should be available per default? defaultEndpoints, // which endpoint should be active initially? defaultEndpoints[0] ), context ) // Initialization is done at this point. Now how to use the EnvPicker? // get current endpoint URL val currentlyActiveEndpointUrl = endpointPicker.getActiveEntry(context)?.url // change active endpoint endpointPicker.setActiveEntry(defaultEndpoints[1], context) // update endpoints list endpointPicker.setEntries( defaultEndpoints + Endpoint("Other", "another.url.com", "", ""), context ) // show management UI endpointPicker.startEnvPickerActivity(context) // or handle the fragment yourself fragmentManager .beginTransaction() .add(endpointPicker.createFragment(), "endpointPicker") .commit() ">
// define a custom data class with arbitrarily many fields of any type
data class Endpoint(
    override val name: String,
    val url: String,
    val user: String,
    val password: String
) : Entry, Serializable {
    override val fields: List<String>
        get() = listOf(url, user, password)

    override val summary: String
        get() = url
}

val defaultEndpoints =
    listOf(
        Endpoint("Live", "some.endpoint.org", "", ""),
        Endpoint("Dev", "dev.some.endpoint.org", "devUser", "secret")
    )

val endpointPicker = envPicker(
    Config(
        "endpoints", // used as sharedPrefs key
        "Choose Endpoint", // displayed as fragment title
        EntryDescription(
            // these will be displayed as TextEdit titles in the UI and need to correspond to the
            // length of the fields property defined in the custom data class
            listOf("URL", "User", "Password"),
            // how to create an Endpoint
            { name, fields -> Endpoint(name, fields[0], fields[1], fields[2]) },
            // how to serialize it using Gson, you can use any serialization method you like
            { entry -> Gson().toJson(entry) },
            // and how to deserialize it
            { str -> Gson().fromJson(str, Endpoint::class.java) }
        ),
        // which Endpoints should be available per default?
        defaultEndpoints,
        // which endpoint should be active initially?
        defaultEndpoints[0]
    ),
    context
)

// Initialization is done at this point. Now how to use the EnvPicker?

// get current endpoint URL
val currentlyActiveEndpointUrl = endpointPicker.getActiveEntry(context)?.url

// change active endpoint
endpointPicker.setActiveEntry(defaultEndpoints[1], context)

// update endpoints list
endpointPicker.setEntries(
    defaultEndpoints + Endpoint("Other", "another.url.com", "", ""),
    context
)

// show management UI
endpointPicker.startEnvPickerActivity(context)

// or handle the fragment yourself
fragmentManager
    .beginTransaction()
    .add(endpointPicker.createFragment(), "endpointPicker")
    .commit()

Maintainers

  • leonbusse
Comments
  • Add templates for issues and PRs

    Add templates for issues and PRs

    Templates are a useful tool to make sure issues have all the information that is required to implement the bugfix/feature request and Pull Requests fulfill all the requirements for a merge into the main branch.

    opened by leonbusse 1
  • Simplify library interface using reflection

    Simplify library interface using reflection

    Description

    This change overhauls the entire lib making use of reflection in order to simplify its usage. The configuration and initialization of an EnvPicker now becomes somewhat more straight forward. No meta info about custom fields needs to be passed in a list any longer, instead most of this information can be inferred. The desired label for each entry is now defined via annotation.

    Type of change

    • [x] New feature (non-breaking change which adds functionality)
    • [x] Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • [x] This change requires a documentation update

    Checklist:

    • [x] My code follows the style guidelines of this project
    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] I have made corresponding changes to the documentation
    • [x] My changes generate no new warnings
    • [x] I have added tests that prove my fix is effective or that my feature works
    • [x] New and existing unit tests pass locally with my changes
    opened by leonbusse 0
  • Theming and dark mode

    Theming and dark mode

    Description

    Colors from activity theme are used throughout lib and sample now. The sample app defines light and dark mode palettes.

    Fixes #20, #21

    Type of change

    • [ ] New feature (non-breaking change which adds functionality)
    opened by leonbusse 0
  • Run tests on CI

    Run tests on CI

    Description

    Build and test the code whenever a PR against master is created or changes are merged into master.

    Type of change

    Please delete options that are not relevant.

    • [ ] CI update
    opened by leonbusse 0
  • Update README

    Update README

    Description

    Update the README to include instruction on setting it up as well as outlining simple and advanced use cases. The tests covering the sample code are updated along with it.

    Type of change

    • [ ] Documentation update
    opened by leonbusse 0
  • chore: Automate release from Sonatype staging repo

    chore: Automate release from Sonatype staging repo

    Description

    Instead of manually closing and releasing the Sonatype staging repository with each release, this will happen automatically as part of the publishing pipeline.

    Type of change

    • [ ] CI enhancement
    opened by leonbusse 0
  • Add templates for issues and PRs #5

    Add templates for issues and PRs #5

    Description

    Added templates for issues and PRs in this repository. They are located in the .github/ directory.

    Fixes #5

    Type of change

    • [ ] Repository configuration
    opened by leonbusse 0
  • Use DSL for library setup

    Use DSL for library setup

    Implement a DSL to be used in place of instantiating a Config object on library initialization.

    Something like

    envPicker {
        key = "uniqueKey"
        fragmentTitle = "Choose Endpoint!"
        fieldNames = listOf("URL", "User", "Password")
        defaultEntries = /* ... */
        defaultActiveEntry = /* ... */
        context = context
    }
    
    enhancement 
    opened by leonbusse 0
  • Add field validation

    Add field validation

    Add the option of adding a validation function to a FieldDescription.

    Possible use case: Making sure an URL contains the segments that are necessary. E.g. no scheme, but a valid host.

    enhancement 
    opened by leonbusse 0
Releases(v0.2.0)
  • v0.2.0(May 1, 2022)

    What's Changed

    • chore: Automate release from Sonatype staging repo by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/15
    • Run tests on CI by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/18
    • Update README by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/16
    • Add tests for MultiEntry usage by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/19
    • Theming and dark mode by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/22
    • Simplify library interface using reflection by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/23

    Full Changelog: https://github.com/bayerischer-rundfunk/android-env-picker/compare/v0.1.0...v0.2.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Oct 26, 2021)

    A preliminary version of the library. Testing the publishing pipeline.

    What's Changed

    • Version 1.0 by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/1
    • Restructure into multi-module project by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/2
    • Multi-module restructure and basic OSS setup by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/4
    • chore: Add the Publish workflow by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/3
    • Add templates for issues and PRs #5 by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/6
    • Add contribution guidelines #7 by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/8
    • Support non string fields #10 by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/11
    • Add scripts for publishing to Sonatype OSS repository by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/12
    • Release 0.1.0 by @leonbusse in https://github.com/bayerischer-rundfunk/android-env-picker/pull/13

    New Contributors

    • @leonbusse made their first contribution in https://github.com/bayerischer-rundfunk/android-env-picker/pull/1

    Full Changelog: https://github.com/bayerischer-rundfunk/android-env-picker/commits/v0.1.0

    Source code(tar.gz)
    Source code(zip)
Owner
Bayerischer Rundfunk
Bayerischer Rundfunk is a public-service radio and television broadcaster, based in Munich, capital city of the Free State of Bavaria in Germany.
Bayerischer Rundfunk
OSGeo4A is a build environment to cross-compile opensource GIS software for android devices

OSGeo4A This provides a set of scripts to build opensource geo tools for Android. This is Experimental Dependencies instructions you need a JDK v8 or

OPENGIS.ch 31 Aug 5, 2022
Termux - an Android terminal application and Linux environment

Termux application Termux is an Android terminal application and Linux environment. Note that this repository is for the app itself (the user interfac

Termux 18.4k Jan 3, 2023
Warscape core library. Includes common models for sharing between platforms.

warscope-core This repository uses for sharing common models between backend and frontend sides. Implementation $version available at top of README.md

Warscape 5 Oct 8, 2021
Sample app demonstrating interop between Jetpack Compose and the Android UI toolkit, including SurfaceView

Wake Me Up Wake Me Up is a sample app showcased in the Google I/O 2021 Developer Keynote that demonstrates interoperability between Jetpack Compose an

Romain Guy 174 Dec 5, 2022
Endoscope lets you to stream live video between android devices over Wi-Fi! 📱📲

Endoscope - RTSP live video streamer for android devices via Wi-Fi. Project is no longer supported. Alternative solution is under development. Stay tu

Przemek 640 Dec 21, 2022
Sync DND state between Android phone and watch

DNDSync This App was developed to enable Do Not Disturb (DND) synchronization between my Pixel phone and the Galaxy Watch 4 since this option was only

rhaeus 57 Jan 5, 2023
An android application that provides simple communication between bluetooth enabled devices using LoRa for intermidiate data transfer

LoRa and bluetooth communication An android application that provides simple communication between bluetooth enabled devices using LoRa for intermidia

Erling Mathias Staff 2 May 4, 2022
Communicating between Wear OS and Android device using the OpWear module and a sample of displaying real-time camera on the watch and sending commands to the mobile by Wear OS.

OpWear-Cam Communicating between Wear OS and Android device using the OpWear module and a sample of displaying real-time camera on the watch and sendi

AmirHosseinAghajari 6 Nov 8, 2022
Pass parameters safely and quickly between activities or fragments.

Bracer Pass parameters safely and quickly between activities or fragments. Read this in other languages: 中文, English, Change Log Prepare Add the JitPa

Season 57 Jan 3, 2023
An application for converting between units

currency-converter This is an Android Based Application for helping users convert between currencies. The project is part of our Android Jam Series La

MMU CIT CLUB 2 Nov 5, 2021
Link previews between JetBrains Space and Slack

slack-unfurls This is the application for providing link previews between Slack and Space in both directions. It provides link previews for Slack mess

JetBrains 5 Sep 8, 2022
The platform for time-management by pomodoro technique between team.

❗️ Moved to tomadoro organization. ?? Pomodoro The platform for time-management by pomodoro technique between team with lot of customization. Pomodoro

Vadim Yaroschuk 8 Dec 8, 2022
Library to change Android launcher App Icon and App Name programmatically !

AppIconNameChanger Change Android App launcher Icon and App Name programmatically ! Download Demo APK from HERE Kindly use the following links to use

Prabhakar Thota 587 Dec 29, 2022
Food Recipe App is an app for collecting most of food recipe in one app

Food Recipe App is an app for collecting most of food recipe in one app

Heba Elsaid 10 Dec 25, 2022
Arjun Naik 1 Apr 16, 2022
Show worldwide headline. API/Glide library/recycler view/volley library/kotlin/xml/ chrome custom tabs

Show worldwide headline. API/Glide library/recycler view/volley library/kotlin/xml/ chrome custom tabs. -> you can click on headline and it will open an article of that news in the app(no need to go to chrome or any browser)

SUMIT KUMAR 5 Nov 28, 2022
A music picker library for React Native. Provides access to the system's UI for selecting songs from the phone's music library.

Expo Music Picker A music picker library for React Native. Provides access to the system's UI for selecting songs from the phone's music library. Supp

Bartłomiej Klocek 60 Dec 29, 2022
:movie_camera: Movie discovery app showcasing Android best practices with Google's recommended architecture: MVVM + Repository + Offline support + Android Architecture Components + Paging library & Retrofit2.

Popular Movies Stage 1 + Stage 2 Discover the most popular and top rated movies playing. Movies data fetched using themoviedb.org API. ✨ Screenshots M

Yassin AJDI 189 Nov 26, 2022
Utility Android app for generating color palettes of images using the Palette library. Written in Kotlin.

Palette Helper is a simple utility app made to generate color palettes of images using Google's fantastic Palette library. It's mostly a for-fun pet p

Zac Sweers 154 Nov 18, 2022