Skip to main content

Questions tagged [kotlin]

Kotlin is a statically typed programming language that compiles to JVM bytecode, JavaScript, or native binaries.

Filter by
Sorted by
Tagged with
2 votes
2 answers
58 views

LFU cache in Kotlin

I've been working on the classic LFU (Least Frequently Used) cache running in O(1) time problem lately and, as a student, I kind of struggled with the algorithms I found online. I got most of the idea ...
NicolaM94's user avatar
1 vote
1 answer
82 views

Kotlin Compose authentication with Google and Facebook using a CircularProgressIndicator for UI loading

I had this problem: https://stackoverflow.com/questions/78528358/how-to-prevent-circularprogressindicator-from-freezing-during-authentication-in Now after fixing it, I want to make sure that this is ...
Cipri's user avatar
  • 11
4 votes
1 answer
67 views

Calculating a weight from a tag using kotlin

I'm not really happy with the below solution. Background is that I am receiving results from a graphql query that includes tags, and I want to translate these tags into weights and save those results ...
isic5's user avatar
  • 85
3 votes
1 answer
115 views

Logic to check if app was launched for the first time using DataStore

I have written a dummy code to check if an app was launched for the time using DataStore. It is working however i want to know if this can be optimised and i also observed a small glitch initially ...
dev4Life's user avatar
5 votes
1 answer
89 views

Compose Grid With Lists

I have created a Grid out of using the new concept of List in Kotlin. I'm open to any feed back to how this code could be improved. It functions as expected and I'm happy with the results. ...
xxxVxxxlinux's user avatar
2 votes
1 answer
68 views

Handling View State & Side Effects with Lifecycle Awareness in Jetpack Compose MVI Composable

I'm working on a stateful Jetpack Compose composable that follows the MVI architecture. I'm using collectAsStateWithLifecycle() to observe the view state from a view model, but I'm unsure about the ...
Android Developer's user avatar
2 votes
1 answer
107 views

Turn List<Either<A, B>> into Either<A, List<B>>

I'm trying to integrate Arrow-kt's Either into an application that needs to parse and validate filter input. This input is a comma separated list of criteria. ...
t3chb0t's user avatar
  • 44.3k
1 vote
0 answers
72 views

Dialog manager for Compose dialogs

I needed something that would help me keep dialogs in my Jetpack Compose desktop application under control and without dozens of *Visible variables etc, so I ...
t3chb0t's user avatar
  • 44.3k
5 votes
2 answers
252 views

Kotlin: scoped functions with try/catch support

I'm working with Kotlin for some time. Compared to Java it's more concise. Still it has some legacy inherited from Java. For example the try-catch-construct. Though it has been upgraded from a ...
LuCio's user avatar
  • 183
3 votes
1 answer
62 views

Recursive item recipe creation

I was trying to write code that would get as input a recipe consisting of item materials and would create all possible recipes that could be used to create craftable of the recipe. The Recipe is ...
Barracuda's user avatar
  • 131
3 votes
1 answer
97 views

Solve the snake cube puzzle

I wrote a solver for the snake cube puzzle. The solver can be easily adapted to arbitrary snakes. Since the program takes only a few seconds to run, I didn't care to optimize for speed, instead I ...
Roland Illig's user avatar
  • 21.3k
5 votes
3 answers
658 views

Mapping named parameters to indices for PreparedStatement

I needed something to map named SQL parameters into indices for JDBC queries so I wrote the ParameterMap class that takes an SQL query, searchers for parameters ...
t3chb0t's user avatar
  • 44.3k
1 vote
0 answers
86 views

Import large Excel files directly from XML streams into an SQLite database

I've got some pretty large Excel files with nearly 1M rows that are almost impossible to open and work with in Excel anymore that I'm migrating into a database. Desipte this these files will stick ...
t3chb0t's user avatar
  • 44.3k
2 votes
1 answer
87 views

TicTacToe OOP approach in Kotlin

I wrote a terminal-based TicTacToe game in Kotlin to practice both Kotlin and OOP. Any feedback on structure and code would be appreciated. Board.kt ...
random_letter's user avatar
3 votes
3 answers
268 views

Kotlin call API and store JSON files locally

I'm new to Kotlin and wanted to give this mini project a try. Please let me know if you have any improvements in mind. I'm thinking error handling, structuring the module, is there too much going on ...
random_letter's user avatar
1 vote
0 answers
57 views

Architecting my Compose UI

I have designed a layout that includes recipe details and three CTAs in the app bar to share, delete, and edit recipes. I need feedback regarding the architecture of my Compose UI. ...
Android Developer's user avatar
1 vote
1 answer
115 views

Simple Kotlin Bingo Class

This is a simple class in Kotlin that handles three basic Bingo-related functionalities: Specifying the numbers, generating a card, and calling one random element. Additionally, it should support an ...
Aaron Liu's user avatar
  • 131
9 votes
2 answers
966 views

Swift-function which counts the letters, numbers, spaces, special chars in a given string

Task description: Write a function, which counts the letters, spaces, number and special characters in string. My implementation: ...
michael.zech's user avatar
  • 4,358
1 vote
1 answer
203 views

Lock-free implementation of getAndUpdate() using atomic CAS (Compare-And-Swap) operation

We have the following class written in Kotlin Native with the new Memory Manager (which doesn't require to freeze objects): ...
Volo's user avatar
  • 111
4 votes
3 answers
325 views

Word-guessing game

The objective of the game is to guess a five-lettered word in five guesses or less. When the user (player) enters a word, the application will inform the user whether their guess was correct or not. ...
Brad's user avatar
  • 41
4 votes
2 answers
1k views

Given an EAN-8 or an EAN-13 code, tell if that code is valid

I have the requirement to validate product codes which include EAN-8, EAN-13 and UPC-A encoded as EAN-13. I have implemented a use-case to perform this check by comparing the actual check digit with ...
Droidman's user avatar
  • 153
7 votes
1 answer
209 views

Loading-content-error implementation for a tiny Kotlin library

I have a sealed interface that I use in pretty much every one of my Android projects. It implements the loading-content-error pattern, often called a Resource, <...
Eva's user avatar
  • 1,115
1 vote
0 answers
64 views

Learning Jetpack Compose: TabBar with Paging Screens

I'm piecewise reimplementing an existing iOS app. My initial go at it visually looks like this: I'm looking for any feedback on more idiomatic ways to implement what I've done. There's a couple of ...
Travis Griggs's user avatar
2 votes
1 answer
46 views

Remove inputted keys separated by spaces from map and output the resulting map, including alias recognition

I'm looking to integrate Kotlin idioms (including code style) and maybe better performance. I wonder if there's a better way to do line 17 (the str.split(' ') one). ...
Aaron Liu's user avatar
  • 131
2 votes
1 answer
389 views

Android: Navigation with Hilt + Jetpack Compose

The project is simple: Login screen and a forgot password screen. You can navigate from Login to ForgotPassword. I feel like I overcomplicated things, but I don't know if (and how) it can be ...
Simon's user avatar
  • 245
1 vote
0 answers
263 views

Jetpack Compose: Items-list with Item-Details-view

The app is based upon an exercise from a Udemy-course. The purpose is to become familiar with LazyColumns. I've enhanced the exercise with a Details-view and a navigation between LazyColumn and ...
michael.zech's user avatar
  • 4,358
0 votes
1 answer
437 views

Assert MockMvc response by using Kotlin DSL

I build web application using Kotlin and Spring Boot, I use MockMvc to write integration test. I'm not satisfied how assertion looks like, here is typical assertion: ...
Mateusz's user avatar
  • 113
3 votes
0 answers
147 views

Advent of Code 2021 Day 19

I am taking advantage of the recent layoffs to teach myself Kotlin. I am a career Java programmer, I've touched Kotlin before but not actively, and not for a few years. I wrote it all in one file ...
durron597's user avatar
  • 918
1 vote
0 answers
40 views

Kotlin JSR 310 validation annotation

So, I am trying to implement an annotation in Kotlin, and it works, but I definitely feel like I could do a lot better. Below is the code and some areas I think could be improved. The purpose of this ...
Christian Bongiorno's user avatar
2 votes
1 answer
109 views

Splitting a list in Kotlin

I want to split a list (as if splitting a string by a delimiter), ideally in a functional style, and was surprised how hard it seems to be. Or maybe my code is just unnecessarily complicated? ...
Felix Dombek's user avatar
  • 1,081
4 votes
3 answers
402 views

Removing repeating rows and columns from 2d array

This is a real problem I had to fix recently. Imagine having generic array where you can have duplicate columns and rows. You want to remove those duplicates as long as they are next to each other. <...
K.H.'s user avatar
  • 2,668
2 votes
1 answer
145 views

Function to capture all stdout to String

I wanted to have a simple way to capture all sysout for a block of code. Ended up with this: ...
K.H.'s user avatar
  • 2,668
4 votes
1 answer
894 views

Android + Kotlin advanced color picker (HSV and RGB)

For almost the past year, I have been working on a pixel art editor for Android. My pixel art editor was relying on an external library for its color picker. For 0.2.0, I wanted to change this by ...
thebluepandabear's user avatar
2 votes
2 answers
362 views

Temperature Scale Converter in Kotlin

Problem statement: Write a program that converts all given temperatures from a given input temperature scale to a given output temperature scale. The temperature scales to be supported are Kelvin, ...
Christian Hujer's user avatar
0 votes
3 answers
217 views

Android - A way to show/hide loader without writting false/true in every viewmodelScope.launch

I have been writting a lot of code that looks like this ...
George Shalvashvili's user avatar
2 votes
1 answer
76 views

Processing charge current error messages with HashMap<>

I have certain error states that I am displaying in my Android TextView but only one message is displayed at a time and if all values are set to 0, no message is displayed. So, I check all the values ...
Dylon Jaynes's user avatar
2 votes
1 answer
48 views

Observe LiveData to indicate whether or not to display TextViews in MVVM

In the context of MVVM, is this an efficient way to communicate to the view that I should display some TextViews? Any advice on how I can improve it? ViewModel code: ...
Dylon Jaynes's user avatar
2 votes
2 answers
69 views

Load data from database, change it asynchronously and return the new data

I have written this function to load data from the database, change it asynchronously and return the new data. It appears to work fine, but since I am new to Kotlin, I wanted to ask if this code is ok ...
Newbee's user avatar
  • 43
3 votes
0 answers
1k views

Jetpack compose login screen + ViewModel

Im working on the login screen for my application. It has fields for users email and password. Also users can click on forgot password button to send an email with new passsword. It can validate these ...
Destroyer's user avatar
  • 477
2 votes
1 answer
65 views

parsing source code to generate documentation of an open source program (StreetComplete, an OpenStreetMap editor) - 1180 lines of Kotlin script

All help welcomed! I posted a big chunk of code here - but feel free to review only a small section. I will use answers to improve this deployed open source software. About the code This code works. ...
reducing activity's user avatar
2 votes
0 answers
178 views

Android architecture and dependency injection of domain layer usecases

I am implementing some of the architectural designs from Google I/O's app to my own app, but I have come across something in their app that has created some confusion for me. They have a domain layer ...
CJR's user avatar
  • 151
2 votes
1 answer
111 views

Adapter pattern apply with JsonObject

The purpose of the code is to apply adapter pattern to put an extra feature for searching through json object. I hate deep nested json object because it makes my code look messy when access through ...
Patrick's user avatar
  • 331
8 votes
3 answers
251 views

Produce an arithmetic progression

I have made a function which takes in an end point and a step, then produces a list of integers with the step in mind. For example, if the end point is 10 and the step is 2, the function should return ...
SpawnTheTronix's user avatar
-3 votes
1 answer
122 views

Kotlin, calculate fingerprint from public key

I created function for calculating fingerprint from a public key ...
Big boi.'s user avatar
6 votes
3 answers
222 views

Performing complex operation before calling the primary constructor in Kotlin

Semester is a simple enum class. ...
Hyeonseo Yang's user avatar
3 votes
1 answer
1k views

Getting a single result from multiple LiveData objects

I have an Android viewmodel for a Fragment that requires the user to perform multiple tasks. In addition to a LiveData object to track the status of each task, I ...
Moshe Katz's user avatar
3 votes
1 answer
109 views

Iterative Fibonacci number generator in Kotlin

I have very limited experience in Java and slightly more in C# (just doing Advent of Code problems last month), so I'm not familiar with how to write idiomatic Kotlin. This class implements an ...
William Bradley's user avatar
5 votes
1 answer
3k views

Calculator App with Kotlin and Android Studio

Hello I am an absolute beginner with Kotlin and Android Studio. I want to hear what I could do better for the next time or any flaws my code has. The code implements a four-function calculator (+ - ✕ ÷...
cp54lory's user avatar
2 votes
0 answers
295 views

Kotlin AsyncPriorityQueue

Unbounded threadsafe suspending priority queue Items are ordered by an integer priority value passed into the enqueue() method dequeue() retrieves and removes the head of the queue or suspends until ...
Caleb Moore's user avatar
2 votes
2 answers
238 views

commandline Password-Generator in Kotlin

So I (a newbie to programming) wrote this password-generator as one of my very first programs in Kotlin. I started with Java a few weeks ago. I soon realized that Java was too hard for me, so I ...
RobertVanGaalen's user avatar

1
2 3 4 5 6