Help with implementing MVVM in school project

Hi, I’m learning to code at school for about a year, and until now, all the code that I developed was in console with languages like C or Java. I also learned the basics of web development.

Right now I’m being introduced to Kotlin and my teacher gave us a simple app to make some data be sharable between activity’s.

I made it as best as I could and the goals were achieved, but the teacher also asked us to implement MVVM architecture to the project and it’s here that I’m having troubles. I can understand the concept of having the code divided but I can’t figure how to apply that to my project.

I would greatly appreciate if someone could take a look at it and give me some enlightenment on how to do or even change the code to fit the assignment objectives.

The code is here:

submitted by /u/Queasy_Ad9473
[link] [comments]

Continue ReadingHelp with implementing MVVM in school project

It appears that JetBrains is abandoning compatibility with Java annotation processors

I’m a Kotlin user who primarily uses it as a Java replacement in server-side projects. There are many excellent Java tools such as MapStruct, QueryDSL, and more that rely on annotation processors and code generation in order to work. However, using these tools with IntelliJ is complicated, especially when using Maven.

Currently, the kapt tool works well if invoked directly by Maven CLI commands (or the IntelliJ GUI that allows for invoking said CLI commands). However, IntelliJ itself will not properly run kapt as part of its own Kotlin build system. This makes it deeply frustrating to work on a project in Kotlin with annotation processors, as there is no “one click” build step within IntelliJ.

It appears that JetBrains has been ignoring this issue for several years already. What concerns me more is the fact that kapt is in maintenance mode, deprecated in favor of the new KSP tool. While I’m totally fine with the idea of moving to newer and better tools, from what I’ve read about KSP so far it is not compatible with traditional annotation processors (I might be wrong about that, it’s just the impression I have so far). This makes it less likely that JetBrains will resolve the current limitations of kapt, and more likely that they will be moving further away from proper support for Java annotation processors.

As someone who loves using Kotlin instead of Java alongside the broader Java ecosystem, this is very concerning to me. I especially feel it will hinder Kotlin’s adoption in the enterprise space, where Java is still king but a lot of developers (including myself) are slowly increasing Kotlin’s adoption.

I hope I’m misinterpreting what is happening, but I’m deeply upset by this change. I hope that better solutions come forward in the future.

submitted by /u/Droid2Win
[link] [comments]

Continue ReadingIt appears that JetBrains is abandoning compatibility with Java annotation processors

Door: Room Database for Kotlin Multiplatform [r/Android crosspost]

Hi everyone,

I have been working on making Room Database work for Kotlin multiplatform. The objectives are similar to SQLDelight. Door is a Kotlin Symbol Processor and generates Kotlin Multiplatform expect/actual implementations, so the actual Android implementation is Room itself (supports LiveData, Paging, Flow, etc). JVM supports Postgres and SQLite via JDBC. Javascript supports SQLite in the browser via SQL.js. Hopefully will support iOS/native in the near future (pull requests from anyone more familiar with iOS/Native would be very welcome).

Any feedback, bug reports, contributions, etc. would be welcome. A sync/replication engine is in process. This is all open source under an Apache license.


submitted by /u/mikesdawson
[link] [comments]

Continue ReadingDoor: Room Database for Kotlin Multiplatform [r/Android crosspost]

Building double-linked tree structures


Would like some advice for what is the most Kotlin idiomatic way to build a double-linked tree structure. Each node in the tree can have zero or more children, and every node other than the root has exactly one parent. After it has been constructed the tree is immutable. I need to be able to traverse the tree from bottom up as well as top down.

At present I’m building the tree bottom up, then doing a post build pass through the tree filling in each node’s parent. So each node contains properties:-

private val children : List<Node>
private var parent : Node?

Which works fine, but I don’t much like the way I have parent exposed as var when it is immutable after the post-build stage, as this blocks kotlin’s null smart casts. I can’t make parent lateinit as I need the null value for the tree root.

I could alternatively build the tree top down, passing the parent as an argument to child constructor, and having the child call back to add itself.

private val children : MutableList<Node>
private val parent : Node?

This avoids the second pass, makes everything val and allows null smart casts. But to me that feels worse as it implies the number of children at a node is mutable.

What do people consider is the more idiomatic?

submitted by /u/Falcon731
[link] [comments]

Continue ReadingBuilding double-linked tree structures

Background location

Hey guys. Was working on a project where I needed continuous access to background location. I leverage location access inside a background job and then send the fetched lat/lng to a server via API calls. These API calls are present inside a service. But I’ve noticed Android kills the service when it runs in background on a few devices. Any idea what a better approach could be ?

submitted by /u/hmmmmaks
[link] [comments]

Continue ReadingBackground location

Stable Diffusion with kotlin to phyton?

I am long time android/kotlin developer, my python skills are lacking.

i want to make a kotlin/python hybrid but cant understand python environments, till today i been using it “normal” in windows environment.

i am able to execute command line code (with default windows env) from kotlin, but cant make it work with conda.

can someone point me in the right direction?

submitted by /u/Clicker7
[link] [comments]

Continue ReadingStable Diffusion with kotlin to phyton?

Koin – SharedStateViewModel unexpected behavior

Hey, so I am working on a simple note app in which I am using Koin to learn it. In the app, there’s a NotesFragment that shows notes and InsertNotesFragment, that shows details of a clicked note or in which you can insert a new note.

In the InsertNotesFragment, there’s a button that also shows up a BottomSheetDialogFragment, in which one can select a color for a new/existing note.

InsertNotesFragment can be opened by clicking an existing note (note editing mode) or by clicking an add button in the NotesFragment (note inserting mode).

Now, InsertNotesFragment and BottomSheetDialogFragment are supposed to share a ViewModel with a StateFlow object that represents Note’s state.

Note class:

data class Note( val id: Int? = 0, val title: String? = "", val content: String? = "", val date: String? = "", val color: Int? = Color.parseColor("#ffffff") ) 

Note’s StateFlow in the shared view model:

private val _noteState = MutableStateFlow(Note()) val noteState: StateFlow<Note> = _noteState.asStateFlow() 

It should work in a way that for example changing title or content text in InsertNotesFragment should update the note’s StateFlow “title” and “content” values and changing the color in BottomSheetDialogFragment should change the note’s StateFlow “color” value.

To share the viewModel instance, I am using Koin’s sharedStateViewModel, as I am injecting SavedStateHandle into the shared view model (so I can retrieve navigation arguments – I am passing id of the clicked note to load note’s details).

When I for example click the add button, the shared view model gets initialized. However, when I then press the back button and click the add button again, the screen (InsertNotesFragment) shows but the shared view model does not initialize again as I would expect – the view model instance stays alive for some reason. Not only that, the value passed in navigation arguments is never retrieved in the savedstatehandle. This is the way I am trying to get those arguments in viewmodel

val id = InsertNotesFragmentArgs.fromSavedStateHandle(savedStateHandle).noteId 

I don’t really know what I am doing wrong here. I’ve used saved state handle with Compose Navigation in the past this way and it worked great. I thought it would be the same with XML Navigation. I am also not sure why viewmodel persists when I close the InsertNotesFragment with a back press.

I am probably missing some knowledge that I am unaware of and I am not sure on how to fix this. If there’s someone who uses Koin regularly and could help me, it would be really appreciated.

submitted by /u/Gowreen
[link] [comments]

Continue ReadingKoin – SharedStateViewModel unexpected behavior

End of content

No more pages to load