Questions tagged [kotlin]
Kotlin is a statically typed programming language that compiles to JVM bytecode, JavaScript, or native binaries.
258
questions
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, ...
2
votes
0
answers
55
views
Linked tree built from (n) leaves
Firstly, here is the relevant code. It is written in kotlin.
...
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 ...
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
...
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 ...
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 <...
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. ...
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:
...
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 ...
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 ...
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:
...
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 ...
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 ...
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. ...
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 ...
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 ...
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 ...
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 ...
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 ...
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):
...
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 ...
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:
...
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 ...
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 ...
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 ...
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....
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 ...
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 ...
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 ...
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,...
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 ...
1
vote
1
answer
664
views
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 ...
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 ...
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?
...
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 ...
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 ...
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:
...
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.
...
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 ...
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:
...
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 ...
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!
...
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 ...
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 ...
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 ...
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 ...
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]" ...
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, ...
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:
...