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
4 votes
1 answer
2k views

Correct flow between Kotlin, Realm and ViewModels using Coroutines

I'm stepping back into Android after being away from it for about a year. Trying to get an out of date app of mine back on its feet, and continuing work on it. The app was written using Java, MVP, ...
BHogan's user avatar
  • 41
2 votes
0 answers
55 views

Linked tree built from (n) leaves

Firstly, here is the relevant code. It is written in kotlin. ...
Emery Tanghanwaye's user avatar
4 votes
1 answer
139 views

Finding the type of number entered by the user

I am making a fractions calculator that can calculate fractions, whole numbers and mixed fractions. So there is a String fraction, which is the input. Also, the user will enter the fraction in a ...
DeathVenom's user avatar
2 votes
1 answer
207 views

Double LinkedList Deep Copy in Kotlin

Goal Return a deep copy of a double LinkedList. Each node also contains an additional random pointer, potentially to any node or null. Code to start ...
AdamHurwitz's user avatar
4 votes
1 answer
306 views

Code for sorting items in recyclerView

I'm have recyclerView which is needed for displayed for show list of my audio records. I added the ability to sort my audio records. Please take a look at the code that I use for sorting and tell me ...
Destroyer's user avatar
  • 427
1 vote
2 answers
756 views

Adapter for RecyclerView with supported onClick handling and select color text on last clicked item

I have written an adapter for RecyclerView. It can handle onClicks for RecyclerView items and select the color name and edit <...
Destroyer's user avatar
  • 427
1 vote
1 answer
161 views

Cycle through an array of available colors repeatedly

I have an array of colors for my app to choose from. My goal was to have the app cycle through the array of colors, apply it to my object, and reset to the beginning once each color has been used. ...
primelf's user avatar
  • 113
1 vote
1 answer
40 views

Would my implementation of this enum pass?

I have a feature with feature flagging enabled, basis the condition I want to load different pages in my screen, to achieve this I have the following enum: ...
User3's user avatar
  • 261
2 votes
2 answers
114 views

List Filtering Code

I am developing applications for android. In my application, the user can add information about his weight and watch the progress of weight change. I decided to add filtering of the elements according ...
Destroyer's user avatar
  • 427
3 votes
1 answer
97 views

Springer book downloader in Kotlin

I'm starting with Kotlin recently and am hoping to improve. I wrote a small app to parse the list of free Springer books and download the books into your chosen local folder. Comments around obvious ...
user224321's user avatar
1 vote
2 answers
63 views

Building a Building - Is the building clean?

I'm writing a small game and I use Kotlin for that. I want to model my buildings with the following class: ...
DBalazs's user avatar
  • 11
1 vote
1 answer
25 views

Can delegation be used to set these values at declaration time (thus reducing lines)?

This class represents a single entry in a log file of the Common Log Format. Can this be improved? I think I might be able to use delegation to pluck values from the matcher. Ideally I would be able ...
Christian Bongiorno's user avatar
2 votes
1 answer
79 views

Code for adding a user to the database

I have a code that adds a user to the database, getting the username from the dialog.My fragment implements the interface with the onInputSend method, which is called by the dialog when the user ...
Destroyer's user avatar
  • 427
1 vote
1 answer
71 views

Using a factory pattern many times [closed]

This is my first question on this website and I hope it goes well. I have created a Kotlin factory pattern and I am using it very frequently. the code I use it consists of functions inside a class. ...
Dimitrios Filippou's user avatar
2 votes
1 answer
44 views

Class for user actions

I implemented a class for relationships with the user (deletion, name change, check for existence), I created this class to remove extra logic from the activity class. Could you talk about how my code ...
Destroyer's user avatar
  • 427
4 votes
1 answer
151 views

Change layout in Gridlayout runtime

I'm trying to change the GridLayout of my application in runtime, the user can select 1, 2 or 3 columns for his display. To do that I've used a ...
Biscuit's user avatar
  • 141
6 votes
1 answer
103 views

Dangers of increasing fishing on a fish population simulation

Setup The following code implements the algorithm described in this and this paper. The first paper describes how the evolution of a fish population can be simulated, while the second paper introdues ...
Sito's user avatar
  • 384
1 vote
0 answers
61 views

Design to separate client API from internal API in Kotlin for a chess engine

This is a follow-up from my previous review on this site. To be clear, the code is stand-alone, and does not depend on the previous review. As before my goal is to come up with a design for a chess ...
Klaas van Aarsen's user avatar
5 votes
1 answer
122 views

Design that avoids undesired dependencies in Kotlin for a chess engine

I'm trying to come up with a design for a chess engine in Kotlin that hides implementation details, and that ensures that such an implementation cannot accidentally become spaghetti. Client side ...
Klaas van Aarsen's user avatar
2 votes
1 answer
110 views

Make querySelector in kotlin-js more convenient and type-safe

I'd like you to take a look at those extension functions I made in kotlinjs (version 1.3.61): ...
K.H.'s user avatar
  • 2,568
7 votes
3 answers
4k views

Count the number of duplicated chars in a string

It's an exercise, which I found on Codewars. Instructions: Write a function which returns the count of distinct case-insensitive alphabetic characters and numeric digits which occur more then once ...
michael.zech's user avatar
  • 4,232
1 vote
1 answer
71 views

Make extensions for kotlin arrays

I wanted to make a library thing which provides specific extensions for collections/collection-like containers in kotlin: ...
Adam's user avatar
  • 121
1 vote
0 answers
87 views

Generate random letters containing a word

There is a popular game called 4 Pics 1 Word that presents to the user 4 pictures representing a common word. The word has to be typed by selecting some of the 9 random letters appearing below the ...
Roland Illig's user avatar
  • 21.2k
3 votes
0 answers
98 views

ANDROID - Receive and manage markers in Google Maps

Recently, I've received negative feedback of interview's test. They say that they need somebody with higher technical level, the quality of the task was not good enough. I upload it here, to request ...
Dani Nuñez's user avatar
2 votes
1 answer
104 views

Mapping a complex JSON response to two different JPA Entities

I am mapping a complex JSON response to two JPA Entity model classes using Jackson. The classes are CxExport and Mention, Mention has a Many to one relationship with CxExport I.e. Many mentions belong ...
user2094257's user avatar
3 votes
2 answers
307 views

WebService to calculate transaction statistics

Recently got rejected in a code challenge that was a very simple WebService with 3 endpoins: POST /transactions to add transactions with an ammount and timestamp....
pragmatic_programmer's user avatar
2 votes
1 answer
91 views

An app displaying items fetched from JSON, but I think maybe I'm not using best Android development praxis

I have been programming in various languages for a very long time, and this was one of my first attempts to build an Android app. Apparently this was not good enough for the challengee, could somebody ...
Simson's user avatar
  • 297
3 votes
1 answer
300 views

Longest Substring without Repeating Characters Problem - Kotlin Recursion

I am practicing coding questions on leetcode. I have been an OOP my whole career, and I am trying to wade into the dark abyss that is functional programming. So I am trying to do things purely ...
GoldFlsh's user avatar
  • 133
2 votes
0 answers
335 views

Canvas Drawing / Bucket Filing Kotlin

I have completed a solution for the below problem and uploaded it in Git Repo. I would be grateful if somebody can review in term of code quality, design and Kotlin language usage. Repo You're ...
Ramanathan Ganesan's user avatar
1 vote
0 answers
49 views

Android Studio Autocomplete that creates a new entry if no entry selected

I want to use the android component autocomplete: https://developer.android.com/reference/android/widget/AutoCompleteTextView There are some possible values the user can select, but I also want that,...
Manuelarte's user avatar
3 votes
1 answer
54 views

ZooRater mobile app. This code is responsible for displaying and handling zoo dashboard. Need general advice

Context: gitlab link I know, it's a lot of code but I need your help ladies and gentleman. I'm not sure if I can ask for code review for the whole project so I just ask to review this activity. I ...
GalaktycznyRychu14's user avatar
1 vote
1 answer
664 views

Ensuring file handle is closed in case of an exception [closed]

...
slaiyer's user avatar
  • 119
1 vote
1 answer
940 views

Am I wrapping synchronous code in ktor/Kotlin coroutine correctly?

I'm playing with ktor right now. If I understand this correctly, code in ktor's handlers need to be as asynchronous as possible. So I was trying to figure out how do you write synchronous (potentially ...
art-solopov's user avatar
6 votes
2 answers
913 views

Detect charset from raw bytes in Kotlin

I needed in my project to import .txt files without knowing their encoding, but knowing, they will most likely be in Czech or Slovak language. Sadly there is bunch of possible encodings so I decided ...
K.H.'s user avatar
  • 2,568
1 vote
0 answers
61 views

Strong components in kotlin

I have written a function to calculate all strong components in a graph. How do I make this cleaner and nicer? ...
nz_21's user avatar
  • 1,041
0 votes
2 answers
1k views

Merge objects in Kotlin if they are updated

I am very new to Kotlin and I am trying to achieve this: I get a batch of PersonDetails to save or update In the batch, the same ...
NewUser's user avatar
  • 127
3 votes
1 answer
197 views

Parsing opening hours, discarding insane ones (part of the OpenStreetMap editor)

This code is used to check opening hours data from OpenStreetMap can be handled by an editor app. In case where opening hours is not too complex data is also turned into an usable form. It is a part ...
reducing activity's user avatar
2 votes
2 answers
76 views

Decrypt multiple 10Mb files with defined password

One operation of my Android project is to decrypt one file (chosen in a set of ~30 files for pagination1) of ~10 Mb each and I do this with the following: ...
Cliff Burton's user avatar
2 votes
1 answer
384 views

Notify observers when object attributes update

I have a Singleton manager class for managing request model and its attributes. My main aim is update object observers when some of the object attributes changes. ...
ysfcyln's user avatar
  • 131
2 votes
1 answer
556 views

Getting a value with timeout using Kotlin coroutines

So, here's a task. A background thread may or may not call all of it's listeners some time after sendRequest() was called (in other words ...
sibwaf's user avatar
  • 21
4 votes
1 answer
249 views

More convenient way to use comparators in Kotlin

In Kotlin comparison operators can be used instead of compareTo method: ...
IlyaMuravjov's user avatar
2 votes
2 answers
129 views

Concise way of creating a IntRange out of an Int

I want to create a collection (in this case a map due to the extended function 'groupBy') that maps an IntRange to a list of a data class, which members are determined whether an int inside the data ...
Hooni's user avatar
  • 165
12 votes
4 answers
307 views

The Best™ class

Have you ever wanted to get just not one "best" element from a list, but all of them, or a random element of the best ones? That's what the Best class is here for. Opinion-based? Definitely not! ...
Simon Forsberg's user avatar
1 vote
0 answers
42 views

Thread await and execute different methods based on some event or value

Use case: I am writing a proactive session updater; The use case is for parallel API calls or sequential API calls intercept the API call and check whether token is valid. If token is valid ...
User3's user avatar
  • 261
1 vote
0 answers
53 views

Multiple Stopwatch App

I was fed up with the default alarm clock when doing laundry. The washing machine is in the basement and takes different time depending on the choosen program. The stopwatch has to be configured for ...
user1882585's user avatar
1 vote
1 answer
69 views

Simple function to Http GET some data

This is within a base class of a library, where several other classes inherit this one. This seems like the simplest way of just getting some data, for now without timeout/errorhandling. This is ...
Metallkiller's user avatar
3 votes
0 answers
63 views

Node Based Code Flow Builder

Background In my development of a game engine, I realized the need to be able to construct processing units in a serializable way (code below does not show serialization, just the wiring). I broke ...
Zymus's user avatar
  • 187
4 votes
1 answer
91 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 "[email protected]" ...
Druckles's user avatar
  • 176
2 votes
1 answer
139 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, ...
Hooni's user avatar
  • 165
3 votes
1 answer
745 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: ...
Ian Newson's user avatar