Questions tagged [kotlin]
Kotlin is a statically typed programming language that compiles to JVM bytecode, JavaScript, or native binaries.
258
questions
0
votes
1
answer
150
views
Two dimensional arrays with nulls [closed]
I'm new with Kotlin, and this is my first attempt of a two dimensional array.
...
3
votes
1
answer
97
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 -> ...
2
votes
1
answer
182
views
Kotlin Android request client
As part of an android app, I've written a simple wrapper that makes requests to an api and fetches stuff.
...
3
votes
3
answers
290
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
1
answer
301
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 ...
1
vote
0
answers
24
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
2
answers
195
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
0
answers
900
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
0
answers
2k
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
0
answers
296
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 squares ...
1
vote
0
answers
290
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 ...
2
votes
1
answer
62
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-
...
3
votes
1
answer
69
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
1
answer
352
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 :...
5
votes
1
answer
137
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
...
3
votes
1
answer
2k
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 ...
6
votes
0
answers
189
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
1
answer
77
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
0
answers
92
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
2
answers
2k
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
1
answer
3k
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 ...
3
votes
2
answers
269
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 ...
3
votes
0
answers
70
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.
...
1
vote
1
answer
2k
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
...
7
votes
2
answers
442
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
1
answer
41
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
1
answer
907
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
0
answers
47
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).
...
4
votes
0
answers
902
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
1
answer
3k
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 ...
3
votes
0
answers
443
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 ...
2
votes
0
answers
1k
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
1
answer
56
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
1
answer
49
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
0
answers
2k
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
1
answer
144
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 ...
2
votes
1
answer
367
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.
...
1
vote
0
answers
377
views
Extending kotlinx.html dsl to create functions that include bootstrap classes
I'm looking to create a library that extends kotlinx.html and will include functions that have default css classes.
The goal is to be able to use a function row{} ...
0
votes
1
answer
175
views
3
votes
0
answers
767
views
Endless scroll in kotlin (android)
This is the code of my function to endless scrolling. It's a good practice to bind new disposable in onscroll listener? What do you think about my code?
...
2
votes
2
answers
168
views
Kotlin program to summarize git commits by regex match
I am trying to learn Kotlin. I am coming from some background in Java. As a learning exercise, I wrote this simple program to summarize occurrences of a string by author email in a list of git ...
0
votes
1
answer
461
views
JDBC wrapper in a functional manner
I implemented a simple Java JDBC wrapper in Kotlin with Arrow functional library.
...
4
votes
2
answers
106
views
Parsing CAN frames from a ByteArray
Here's my method used for parsing a ByteArray into multiple frames of CAN interface. It works now correctly but it's somewhat ugly in my opinion.
It's written in ...
3
votes
2
answers
444
views
Find the sum of all digits that match the following digit in a circular list
The challenge
The captcha requires you to review a sequence of digits (your puzzle input) and find the sum of all digits that match the next digit in the list. The list is circular, so the digit ...
5
votes
1
answer
448
views
Compute PI in Kotlin on a T-shirt
I have written code in Kotlin with the objective of computing Pi in few enough lines so that it looks good on a t-shirt.
Can be cut and paste into http://try.kotlinlang.org under "My Programs" and ...
3
votes
2
answers
1k
views
Kotlin extension functions with null checks
Kotlin defines extension functions like also but they are not null checked. That's fine because you might not need the check. In case you do though, do you see any ...
3
votes
0
answers
570
views
Reverse string in Kotlin
In the question of how to reverse a string in Java, a comment mentioned that combining Unicode code points need to be taken into account.
The below code works as intended for all test cases I tried. ...
1
vote
0
answers
2k
views
Parsing a JSON array from a JSON object
So its my first time using Kotlin, and for now I am converting old Java code to Kotlin. I took a simple function to parse a JSONArray from a ...
4
votes
0
answers
64
views
Time travelling through state history with persistent consequences
I am working on a game written in Kotlin that has a state management system similar to Redux. The state of the game is kept in a single place and is represented as immutable data classes (no logic). ...
1
vote
1
answer
132
views
Kotlin API - endpoint for users
I am writing API in Kotlin - this is my first code in this language. I implemented a very primitive 'player' endpoint. I was wondering if I am doing everything ok (please don't mind the static ...