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
3
votes
0answers
31 views

Constructing constrained/validated objects

I'm trying to do some rudimentary DDD in validating my objects to ensure they are of a particular type. I.e. an Email object would always look like "my@example.com" ...
-1
votes
0answers
64 views

Night out with friends. Calculating the costs per person with Kotlin and Android

The following app basically sums up the costs for an evening and calculates the costs per person. The user can input the description of the costs [String] (for example, round one = Spare Ribs Place, ...
2
votes
1answer
51 views

Kotlin shared preferences

So I've written a class for storing user/device specific settings, but I've written the Kotlin pretty much like I would in Java: ...
0
votes
0answers
17 views

Kotlin HTML timetable visualisation generator

A Kotlin class that I wrote fairly early on while learning Kotlin which is used by another program to build and generate HTML visualisations of timetables. I'd be grateful for any feedback, especially ...
1
vote
0answers
9 views

Fetching data from realm database and searching and viewed in recyclerView [closed]

Attached my data class, datas is not fetched from realm database while performing filtering in performFiltering method: ...
0
votes
1answer
84 views

Two dimensional arrays with nulls [closed]

I'm new with Kotlin, and this is my first attempt of a two dimensional array. ...
1
vote
0answers
53 views

ViewModels for image transformations

In my project I have a chain of Fragments where each one gets a bitmap, manipulates it, then sends it to another fragment for more processing. My fragment chain looks like this: CaptureFragment -> ...
1
vote
0answers
31 views

Kotlin Android Request Client: want to make code more idiomatic

As part of an android app, I've written a simple wrapper that makes requests to an api and fetches stuff. ...
0
votes
0answers
43 views

Kotlin Goal Oriented Action Planning

I've implemented Goal Oriented Action Planning (GOAP) in Kotlin. Goal Oriented Action Planning is an algorithm originally devised by J Orkin for the game F.E.A.R. and performs a state space search ...
4
votes
1answer
38 views

Optimizing voxel merge algorithm

I have a bunch of voxel having an int value inside a 16^3 grid. I want to merge individual voxels with the same int value together in order to create the least possible amount of boxes the fastest way ...
0
votes
0answers
190 views

Digit Sum find number of ways and max people

I applied for a job, and the prospective employer sent me the following HackerRank problem, which cannot be found in the public area. There is a lottery with n ...
1
vote
0answers
24 views

Building treetableview using directory as a datasource [closed]

Trying to build a TreeTableView following this guide https://edvin.gitbooks.io/tornadofx-guide/content/part1/5.%20Data%20Controls.html. While I managed to use File class as a data source, I still ...
1
vote
0answers
22 views

Match favorite data from db with data coming from api [closed]

I have a mutableListOf a sealed class. I am trying to compare the result coming from the api with the ones saved in the db so I can update my UI base on ...
4
votes
2answers
86 views

Music Theory: The Basics - a Ring

I've recently started building an API that allows a consumer to create and manipulate musical entities such as notes, intervals, scales and chords. The first step is to create a a foundation of base ...
3
votes
0answers
57 views

Object Oriented Chess Design In Kotlin

I know there's a similar question to this: See here. And I have taken the points mentioned there into consideration. However, I wanted to learn Kotlin and thought of writing OOP based Chess myself. ...
2
votes
0answers
42 views

Program to draw ASCII art based on commands

I want to know how to improve the design of Canvas drawing implementation. Canvas Drawing This solution is to implement a console-based canvas drawing application. Problem Statement Description ...
1
vote
0answers
49 views

Graph-coloring solution using depth-first search

I'm trying to solve this question: Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them. The park consists of n ...
1
vote
0answers
88 views

Max-Heap Implementation in Kotlin

I am concerned about a few things about my heap implementation. This is in Kotlin. For starters- When and when not to use expressions? The use of also to swap ...
1
vote
1answer
42 views

Data class where i need to set values for different fields at different times

I am creating a request for an api using below class- ...
2
votes
0answers
33 views

Range validator for multiple types

I have an existing overloaded set of functions that I cannot change and need to be tested: ...
1
vote
1answer
33 views

Android RecyclerView Popop Activity - 5 second popup time

So I've been working on a RecyclerView recently that's in a popup, and it takes a few seconds to popup with around 100 items. I want to make this faster, so any improvements on my code is appreciated :...
0
votes
0answers
31 views

Adapter for Spinner

I need to my spinner supported endless scrolling. As rule the user will have only 1 - 5 items but in very rare cases some users can have 100+ items that will be loaded from server by pages (15 per ...
4
votes
1answer
33 views

Finding the number of pairs in an integer Array

This function returns the number of pairs of the same elements in the array It takes, array length and the array as the parameter n: Length of array ar: Array of integers for example ...
0
votes
0answers
13 views

CLI to make HTTP Head requests and check for response code

I needed to create a simple CLI utility to check if a specific endpoint is available and (optionally) responds with some expected HTTP code to help troubleshoot users environments (proxy, network ...
1
vote
1answer
38 views

Android LiveData Shared between activities by Application Session

I'm developing an app that use socket to receive messages from a chat. I'm using an MVP approach and I store the data in a Singleton class named DataBridge like ...
5
votes
0answers
151 views

Converting between cooking measurements

I've made an Android app that converts between cooking measurements, taking into account the type of product you use (that way it can convert between mass and volume by using the density). What are ...
2
votes
1answer
38 views

Determine if a String can be parsed to LocalDateTime or Int

I have the following kotlin function that takes in a string "value", then attempts to parse "value" as both a LocalDateTime and an Int. It returns a Pair of the parsed value of "value" and an enum ...
1
vote
0answers
33 views

Temporarily block API calls when server sends a 503 response

I have a scenario in which I call many APIs throughout my application lifecycle. In case the server sends me a 503 response code, it will also send a lockdown object which has a timestamp associated ...
4
votes
2answers
807 views

Compiling and throwing simple dynamic exceptions at runtime for JVM

I've been using my Dynamic Exception with C# for quite some time already and it saved me a lot of time. This means, I don't have to create a new exception ...
1
vote
1answer
337 views

RSA wrapper written in Kotlin

I've written up a small wrapper for RSA and AES encryption in Kotlin, and I want to make sure I'm not making any glaring mistakes before use it. This is going on a small project with basically no ...
0
votes
0answers
26 views

CPU Barycentric rendering in JavaFX/Kotlin

I am writing a software renderer for the Kotlin port of Dear ImGui. In order to be feature complete, I needed to add barycentric coloring to some triangles for things such as color pickers. I have ...
3
votes
2answers
78 views

Constructing a cumulative distribution function from a histogram

During some running process, a histogram of values shall be build up. When done, the CDF shall be derived from it and used to get the quantiles for some values. My current implementation looks as ...
2
votes
0answers
52 views

Listing YouTube videos using API with RxJava

I am new to RxJava and have the following code which I use to search YouTube videos via the API and ultimately display them in a list. ...
0
votes
1answer
134 views

Destroy Singleton pattern in kotlin

I am practicing Singleton pattern in kotlin. It is a quiz app which has question tile with four options and one correctIndex. McqOldActivity.classs ...
0
votes
0answers
13 views

Mapping one object to a data object for the UI

I'm mapping our Lead object (which is very messy) to a data object for the UI. It takes a couple seconds to map 1000 objects, how can I improve the performance? <...
3
votes
0answers
62 views

Quiz for random boolean expressions

Inspired by the various quiz programs on this site, as well as Simon Tatham's puzzle collection, I thought I'd write a quiz that constructs its questions automatically and randomly. A typical session ...
-3
votes
1answer
31 views

Change Kotlin optional-like style [closed]

I have next method in client fun authUser(loginRequest: LoginRequest): String? I need to implement next logic: check if user already exists - nothing to do, if ...
2
votes
1answer
116 views

Sorting algorithms in Kotlin - Bubble, Insertion, Selection, Merge and Quick sort

Introduction I decided to try Kotlin because of its forgiving nature to long-time Java users. I implemented a few introductory sorting algorithms and would like to have them reviewed, not just to ...
2
votes
0answers
35 views

Convert flat object hierarchy to json

I do work for a project currently, where the data is send to the server as application/x-www-form-urlencoded (which is bad, and it should be JSON, but unfortunately I am not able to change this one). ...
1
vote
0answers
296 views

Wrap location API in coroutines

In my app I need to query location and scan wifi periodically. To conserve power I need to change the rate dynamically, depending on the distance to the target. Also I want to wait for both ...
3
votes
1answer
566 views

Mastermind game in Kotlin

I am trying to create an evaluator in Kotlin for the Mastermind game which compares two strings and tells how many letters and letters on the right position they share. I was hoping to get some ...
0
votes
0answers
31 views

Running a JavaFX 11 interface update at regular intervals (in Kotlin)

I want to update a field on a JavaFX 11 UI in response to a thread which retries a process every second and updates statusString with the result. Since the ...
2
votes
0answers
196 views

Timer application in MVP

I create simple Android timer application and I try to use MVP design pattern. I read some tutorials and after that I started writing code. My code is working correctly and as intended. There is ...
1
vote
0answers
312 views

Kotlin DAO with Exposed: How to reduce redundancy in classes?

I'm writing a Kotlin app that uses Exposed (https://github.com/JetBrains/Exposed) as a SQL wrapper to write and read objects from databases. The problem I'm facing is that I end up with 3 classes ...
0
votes
1answer
43 views

Simple Registration Form. I would like to get rid of code duplications

I don't like my current code, because of duplications. What's the best way to leverage Kotlin to make it more concise. I have simple registration form ...
1
vote
0answers
79 views

Lexer for my “Obganism” language

After having rewritten this lexer for the Nth time, I finally feel confident enough to show it publicly. I'm looking for advices to improve my code. The lexer you are going to see is the first step ...
1
vote
1answer
41 views

Proper naming for objects which have a position and bounds on a plane

I have an interface which is for an object which has bounds in a 2D plane. ...
1
vote
0answers
926 views

LiveData, MVVM and Repository Pattern

Is this a good approach or I've just found a nasty workaround? I'm using MediatorLiveData class because seems useful to update the source of a ...
3
votes
1answer
50 views

Ungrouping of values into multiple lists

Given is a list with (possibly) non-unique elements. My goal is to split this list into multiple lists, in sum containing the same elements, but separated in a way that no sublist contains each ...
0
votes
1answer
177 views

Kotlin reflection to generate one class from class similar with similar properties

This code is intended to generate a class (domain) from a class with class with similar/identical properties (api). Motivation is to speed development time when using clean architecture. ...