All Projects β†’ kernel0x β†’ kmpapp

kernel0x / kmpapp

Licence: other
πŸ‘¨β€πŸ’» Kotlin Mobile Multiplatform App (Android & iOS). One Code To Rule Them All. MVVM, DI (Kodein), coroutines, livedata, ktor, serialization, mockk, detekt, ktlint, jacoco

Programming Languages

kotlin
9241 projects
swift
15916 projects
shell
77523 projects

Projects that are alternatives of or similar to kmpapp

Kodein Di
Painless Kotlin Dependency Injection
Stars: ✭ 2,692 (+7817.65%)
Mutual labels:  kodein, ktor, kotlin-multiplatform
Lastik
Kotlin Multiplatform + Jetpack Compose pet project, based on www.last.fm/api (in development)
Stars: ✭ 37 (+8.82%)
Mutual labels:  kodein, ktor, kotlin-multiplatform
MultiplatformPlayground
Kotlin Multiplatform project in Jetpack Compose & SwiftUI with shared ViewModel layer and File upload
Stars: ✭ 72 (+111.76%)
Mutual labels:  ktor, kotlin-multiplatform
Dagger-Hilt-MVVM
Sample app that demonstrates the usage of Dagger Hilt with Kotlin & MVVM
Stars: ✭ 62 (+82.35%)
Mutual labels:  mvvm-architecture, livedata
kfsm
Finite State Machine in Kotlin
Stars: ✭ 76 (+123.53%)
Mutual labels:  kotlin-multiplatform, kotlin-mpp
Simple-Notes-Kotlin-App
✍️ Simple Note Making App use mvvm architecture , dagger , coroutines and navigation component. Features includes πŸ—’οΈ create , edit and ❌ delete notes
Stars: ✭ 40 (+17.65%)
Mutual labels:  mvvm-architecture, livedata
RestaurantsExplorer
Android application build with MVVM Pattern, using Zomato API to enable search cities arround the world and display the city restaurants on a map.
Stars: ✭ 32 (-5.88%)
Mutual labels:  mvvm-architecture, livedata
Kodein-Log
Multiplatform lightweight logging library.
Stars: ✭ 25 (-26.47%)
Mutual labels:  kodein, kotlin-multiplatform
automock
A library for testing classes with auto mocking capabilities using jest-mock-extended
Stars: ✭ 26 (-23.53%)
Mutual labels:  mock, unit-test
KTAndroidArchitecture
A Kotlin android architecture with Google Architecture Components
Stars: ✭ 33 (-2.94%)
Mutual labels:  mvvm-architecture, livedata
Sunset-hadith
Islamic app written with Kotlin, using KTOR + coroutines + flow + MVVM + Android Jetpack + Navigation component. Old version using RxJava + Retrofit + OKHttp
Stars: ✭ 26 (-23.53%)
Mutual labels:  ktor, livedata
Chat-App-Android
Chat app based on the MVVM architecture using Kotlin, ViewModel, LiveData, DataBinding and more.
Stars: ✭ 70 (+105.88%)
Mutual labels:  mvvm-architecture, livedata
KParser
Kotlin Multiplatform Arithmatic Parser
Stars: ✭ 32 (-5.88%)
Mutual labels:  kotlin-multiplatform, kotlin-mpp
xrm-mock-generator
πŸ“– Β Generates a mock Xrm.Page object. Commonly used by xrm-mock to test Dynamics 365 client-side customisations.
Stars: ✭ 15 (-55.88%)
Mutual labels:  mock, unit-test
Scout
Scout is a kotlin multiplatform application that allows users to search and save games to lists to be browsed later.
Stars: ✭ 28 (-17.65%)
Mutual labels:  ktor, kotlin-multiplatform
Fflib Apex Mocks
An Apex mocking framework for true unit testing in Salesforce, with Stub API support
Stars: ✭ 253 (+644.12%)
Mutual labels:  mock, unit-test
mockingbird
🐦 Decorator Powered TypeScript Library for Creating Mocks
Stars: ✭ 70 (+105.88%)
Mutual labels:  mock, unit-test
Sheasy
This an Android App that helps you share/manage your files on your Android Device through a WebInterface in the Browser - Built with Ktor and Kotlin-React
Stars: ✭ 34 (+0%)
Mutual labels:  ktor, kotlin-multiplatform
local-data-api
Data API for local, you can write unittest for AWS Aurora Serverless's Data API
Stars: ✭ 99 (+191.18%)
Mutual labels:  mock, ktor
xrm-mock
πŸ“š A fake implementation of the Xrm object model. Written in TypeScript against @types/xrm definitions.
Stars: ✭ 64 (+88.24%)
Mutual labels:  mock, unit-test

Kotlin Mobile Multiplatform App (Android & iOS)

One Code To Rule Them All. Application example using Kotlin Multiplatform and MVVM pattern for both platforms.

Is used:

  • layered clean architecture
  • DI (Kodein)
  • coroutines
  • livedata
  • ktor
  • serialization
  • mockk
  • detekt, ktlint
  • unit tests and jacoco

Presentation layer (Android & iOS)

On both platforms (Android and iOS), we only need to implement an observer in which to process states. Further implementation on Android (Kotlin) and iOS (Swift):

Android

class MainActivity : AppCompatActivity() {

  private lateinit var viewModel: IndexesViewModel
  private var adapter: IndexesAdapter = IndexesAdapter { viewModel.getQuote(it.ticker) }

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    recycler.adapter = adapter

    viewModel = ViewModelProviders.of(this).get(IndexesViewModel::class.java)
    observeViewState()

    viewModel.getMajorIndexes()
  }

  private fun observeViewState() {
    viewModel.getViewData.addObserver { updateViewState(it) }
  }

  private fun updateViewState(state: IndexesViewState) = runOnUiThread {
    when (state) {
      is Loading -> {
        Toast.makeText(this, "Loading...", Toast.LENGTH_SHORT).show()
      }
      is Error -> {
        Toast.makeText(this, state.message, Toast.LENGTH_LONG).show()
      }
      is ShowMajorIndexes -> {
        adapter.items = state.indexes
      }
      is ShowQuote -> {
        Toast.makeText(this, state.quote.dayLow + " - " + state.quote.dayHigh, Toast.LENGTH_LONG).show()
      }
    }
  }
}

iOS

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    
    @IBOutlet weak var tableView: UITableView!
    
    private var viewModel: IndexesViewModel!
    
    internal var indexes: [Index] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableView.dataSource = self
        tableView.delegate = self
        
        viewModel = IndexesViewModel()
        observeViewState()
        
        viewModel.getMajorIndexes()
    }
    
    func observeViewState() {
        viewModel.getViewData.addObserver { (state) in
            self.updateViewState(state: state as! IndexesViewState)
        }
    }
    
    func updateViewState(state: IndexesViewState) {
        switch state {
        case is Loading:
            view.displayToast("Loading...")
        case is Error:
            view.displayToast("Error")
        case is ShowMajorIndexes:
            let successState = state as! ShowMajorIndexes
            update(list: successState.indexes)
        case is ShowQuote:
            let successState = state as! ShowQuote
            view.displayToast(successState.quote.dayLow + " - " + successState.quote.dayHigh)
        default: break
        }
    }
    
    ...

    deinit {
        viewModel.onCleared()
    }
}

Presentation Layer - ViewModels (Shared Code)

This layer is shared by Android and iOS, and this is developed on Kotlin. Here is where we have to call the different use-cases of the domain layer. To make the call async we are using kotlin coroutines and flow.

class IndexesViewModel : BaseViewModel() {

  private val getIndexesUseCase by Injector.instance<GetIndexesUseCase>()
  private val getQuoteUseCase by Injector.instance<GetQuoteUseCase>()

  var getViewData = MutableLiveData<IndexesViewState>(Empty)

  fun getMajorIndexes() = launchInMain {
    getIndexesUseCase()
      .onStart { getViewData.postValue(Loading) }
      .flowOnBackground()
      .catch { getViewData.postValue(Error("Something went wrong")) }
      .collect { getViewData.postValue(ShowMajorIndexes(it)) }
  }

  fun getQuote(symbol: String) = launchInMain {
    getQuoteUseCase.invoke(symbol)
      .onStart { getViewData.postValue(Loading) }
      .flowOnBackground()
      .catch { getViewData.postValue(Error("Something went wrong")) }
      .collect { getViewData.postValue(ShowQuote(it)) }
  }
}

Domain Layer β€” Models & UseCases (Shared Code)

In this layer, we defining the models and all the use cases that we need for our application.

Data Layer β€” Repository Pattern (Shared Code)

For this layer we are using a repository pattern. We defining the entity models and all source of our data

For networking we are using Ktor and for JSON deserialisation Kotlinx serialization.

Running unit tests

  • Android test: ./gradlew testDebugUnitTest
  • Common test on iOS (need run Simulator iPhone 8): ./gradlew iosUnitTest

Running the app

To run the application use the same tools you use in Android and iOS. Just open the project with Intellj/Android Studio for the Android project and XCode for the iOS one.

Screenshots

Android iOS
android-app ios-app
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].