Office Hours — Today, May 22

Saturday, May 18

Mark M.
has entered the room
Mark M.
turned on guest access
May 22
9:00 AM
Benny
has entered the room
Mark M.
hello, Benny!
how can I help you today?
Benny
Hi Mark, how are you?
Mark M.
OK, and you?
9:05 AM
Benny
I am fine thank you
I am working FCM on a project now
what would you use to put changes to the activity form the FirebaseMessagingService, is a localBroadcast a good way?
Mark M.
that can work
what do the FCM messages contain?
Benny
only 2 key value pairs like userName and userId
Mark M.
why are you sending those in an FCM message? is this to trigger your app to make a Web service request to get more data?
Benny
this is actually only a little example app, I just want to update the UI via FCM
9:10 AM
Benny
but in the future it should also make a request to a Web service, yes
Mark M.
then, if you wanted to use LocalBroadcastManager now, that is OK
eventually, you will want to use WorkManager or JobIntentService to arrange for your Web service request
Benny
okay, this sounds good
I will do this
I have one more question about the app architecture
I will start with a new App soon, what do you think is the best design pattern for now, MVVM?
Mark M.
I cannot really answer that
I prefer MVI, but that is definitely a personal preference
Benny
I thought so :-)
Mark M.
I cannot claim any particular UI pattern is "best"
9:15 AM
Benny
ok, so I just should compare them in deep and find out what would works good for me
9:15 AM
Benny
I only used MVP before
Mark M.
if you are the only developer on the project, yes, for whatever level of "in deep" you want
basically, if you are the only developer, so long as you are happy with your choice, you are fine
Benny
I also have a main iOS developer in my team which will also work on this app for time to time
Mark M.
just make sure that this other developer understands how you are setting up the architecture
Benny
ok, thank you :-)
Mark M.
in other words, worry less about what the architecture is and worry more about explaining that architecture to those who need to understand it
Benny
I think I will start with the android Arch eBook
yes, this is a good point
Mark M.
note that my "Android's Architecture Components" book talks a bit about GUI architectures, but not a lot, as I do not claim to be an expert in that subject
and it is also a first-generation book (Java and Support Library instead of Kotlin and AndroidX)
Benny
ah, okay I understand
9:20 AM
Benny
do you have plans for an update?
Mark M.
some of the material from it will be updated and included in *Elements of Android Jetpack*
some of that is there now, more will be added in the next 4-6 weeks
other topics from it may get updated in other books, such as a short book focused on Room
Benny
okay, thank you
do you cover MVI or MVVM in a book?
Mark M.
the app that is being built in *Exploring Android* uses MVI
or, at least, it uses my particular flavor of MVI
Benny
okay, great, I will check that as a example for me
Mark M.
MVI, like MVVM, are "blurry" UI patterns, with lots of variation
9:25 AM
Benny
Well I think this is it for me today :) thank you for your help
Mark M.
you're welcome!
Benny
see you soon, good bye
Benny
has left the room
trocchietto_Ivano
has entered the room
Mark M.
hello, Ivano!
how can I help you today?
9:30 AM
trocchietto_Ivano
Hallo Mark
I just come by, that yesterday I have been a bit in commons ware forum, so I remembered the chat, no specific questions
Mark M.
OK, if you have a question, ask away!
trocchietto_Ivano
mmh apart a really subtle meta-question
I noticed you use a backend Kotlin tool httpsomething
Mark M.
http4k
trocchietto_Ivano
yes and I am moderately curious to know if you do not believe in Ktor
is what the cool guys like now with Kotlin backend
Mark M.
when I made my evaluation, I looked at Ktor and liked http4k a bit better
9:35 AM
Mark M.
I forget the reasoning, as this was a year or so ago
trocchietto_Ivano
I see, Ktor was not so popular like today
thank you, I wait for somebody to come in the chat
Mark M.
Benny was here earlier but left shortly before you joined
trocchietto_Ivano
OK, 26 minutes of hope then
9:40 AM
trocchietto_Ivano
hey Mark I have a small question actually
Mark M.
go ahead!
trocchietto_Ivano
well I have this
9:45 AM
trocchietto_Ivano
View paste
  val invoiceDetailSectionsList: List<InvoiceSections> =
        listOf(
            FinancialInvoiceDetailSection(invoiceLine),
            EncodingInvoiceDetailSection(invoiceLine),
            AssessorEmployeeDetailSection(invoiceLine))

            .onEach { invoiceSections ->
                invoiceSections.listSection
                    .filter { invoiceItem ->
                        invoiceItem.itemDescription != "null"

                    }.filter { invoiceItem ->
                        invoiceItem.itemDescription != "null - null"
                    }
            }
is inside a viewModel
I need to filter a list before is threw inside an Adpter parameter
thrown*
Mark M.
I do not understand what that onEach() is doing, as it does not look like it is doing anything
trocchietto_Ivano
but this snippet does not work, does not filter at all the list
yes, is what my senior said
I want that takes the list inside listof
and check the two "null". and "null - null" conditions
so instead to receive back 10 items, I am expecting 7 of them
how can I filter this List<InvoiceSections> ?
where the interrogation mark is not made to make a joke
Mark M.
is listSection a property of an InvoiceSection?
9:50 AM
trocchietto_Ivano
View paste
  val invoiceDetailSectionsList: List<InvoiceSections> =
        listOf(
            FinancialInvoiceDetailSection(invoiceLine),
            EncodingInvoiceDetailSection(invoiceLine),
            AssessorEmployeeDetailSection(invoiceLine))

            .onEach { invoiceSections ->
                invoiceSections.listSection
                    .filter { invoiceItem ->
                        invoiceItem.itemDescription != "null"

                    }.filter { invoiceItem ->
                        invoiceItem.itemDescription != "null - null"
                    }
            }
sorry
View paste
   interface InvoiceSections {
        val sectionTitle: Int
        val listSection: List<InvoiceItem>
    }
list Section is a member of the interface indeed
Mark M.
"so instead to receive back 10 items, I am expecting 7 of them" -- you have only 3, though
invoiceDetailSectionsList is a List<InvoiceSections>, not a List<InvoiceItem>
trocchietto_Ivano
ah
Mark M.
where are the 7 or 10 items? are those sizes of the possible List<InvoiceItem> in an InvoiceSection?
trocchietto_Ivano
yes they are
I have an adapter nested inside another adapter
so I used this modelization
Mark M.
are you looking to change the actual contents of the InvoiceSection's list, or are you looking to filter just for the adapter?
trocchietto_Ivano
just filter them
Mark M.
just filter them for the adapter?
trocchietto_Ivano
yes, absolutely that
it was working inside the adapter, but my senior asked me to extract outside the adapter
Mark M.
OK, then perhaps InvoiceSection has a val filteredItems by lazy { listSection.filter { it.itemDescription != null } } or something
9:55 AM
Mark M.
and you reference filteredItems in the adapter
trocchietto_Ivano
yes
every single implementation
originally was working in the adapter
like that was
View paste (5 more lines)
 fun bind(invoiceSections: InvoiceSections) {

            sectionTitle.text = itemView.context.getString(invoiceSections.sectionTitle)


            var invoiceSectionsFiltered = invoiceSections
                .listSection
                .filter { invoiceItem ->
                    invoiceItem.itemDescription != "null"
                }
                .filter { invoiceItem ->
                    invoiceItem.itemDescription != "null - null"

                }

...
Mark M.
so, you could move that into the InvoiceSection as a lazy-evaluated property (which basically works like a memoization pattern, so we calculate it at most once but skip it if we never need it)
trocchietto_Ivano
I see thanks I am going to examine this opportunity
Mark M.
alternatively, if InvoiceSection and InvoiceItem are model objects, you might create a separate representation (more like a viewmodel/viewstate), and do the filtering as part of the conversion, with the adapter using this separate representation
trocchietto_Ivano
this second case is what was expected by me
10:00 AM
Mark M.
that is a wrap for today's chat
the next chat is tomorrow at 4pm US Eastern
trocchietto_Ivano
OK
Mark M.
as usual, this chat's transcript will be posted to https://commonsware.com/office-hours/ shortly
trocchietto_Ivano
have a nice day
Mark M.
you too!
trocchietto_Ivano
has left the room
Mark M.
turned off guest access

Saturday, May 18

 

Office Hours

People in this transcript

  • Benny
  • Mark Murphy
  • trocchietto_Ivano