Jun 18 | 7:25 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Marek D. | has entered the room |
Mark M. |
hello, Marek
|
Mark M. |
how can I help you today?
|
Marek D. |
hello Mark, thank you for the offer :)
|
Marek D. |
I have an app that is used to buy things i.e. lunch-es
|
Marek D. |
our designer wishes to have onscreen keyboard
|
Jun 18 | 7:30 PM |
Marek D. |
so 12 buttons 0-9 , backspace
|
Marek D. |
I tried Constraint layout to build the things
|
Marek D. |
1st solution is chains
|
Marek D. |
(the keyboard needs dividers as well)
|
Marek D. |
dividers is View with background
|
Marek D. |
looks pretty ok imo :)
|
Marek D. |
2nd solution is Constraint with guidelines
|
Marek D. |
3rd solution is linear layout and backgrounds that build the grid/dividers
|
Marek D. |
so 1 has East South 9-patch
|
Marek D. |
2 has ESW
|
Marek D. |
building those layouts was bit of a challenge
|
Marek D. |
but what I have is quite a lot of buttons
|
Marek D. |
so I have button0.setOnClickListener, button1.setOnClickListener ...
|
Marek D. |
so reviewers are not fond of it and they suggest a recycler view
|
Marek D. |
with GridLayout manager
|
Marek D. |
the challange here is that there is nothing recycled
|
Mark M. |
unless the keyboard is going to have thousands of keys, with scrolling, do not use a RecyclerView
|
Jun 18 | 7:35 PM |
Mark M. |
you add overhead and complexity for no value
|
Marek D. |
agree here
|
Marek D. |
the other challenge is the size of the recycler
|
Marek D. |
to build the cells I need to know the height of it
|
Marek D. |
before I add the buttons to the recycler
|
Mark M. |
if it helps, you can point the reviewers to this chat's transcript and show that I said: don't use a RecyclerViwe
|
Mark M. |
(er, RecyclerView)
|
Marek D. |
yes it will be useful I hope :D
|
Mark M. |
it is really the wrong solution here
|
Mark M. |
of your four approaches, you presented them in about the order I would recommend, with the best one first
|
Marek D. |
ok, next question
|
Marek D. |
I am expecting a question why I choose the 1st approach :)
|
Marek D. |
again the transcript could be a winning argument
|
Mark M. |
the first two are fairly close, and the choice might depend a bit on what the designer wants, particularly for different screen sizes
|
Marek D. |
but if I could somehow measure performance ?
|
Marek D. |
dunno, inflate it 100 times ?
|
Mark M. |
why?
|
Jun 18 | 7:40 PM |
Marek D. |
well I could say this layout performs the best
|
Mark M. |
if you had hundreds of these keyboards in a scrolling container, then perhaps rendering performance would be a metric to worry about
|
Mark M. |
AFAIK, you have just one
|
Marek D. |
agree
|
Mark M. |
if so, I wouldn't worry about that much
|
Mark M. |
the two ConstraintLayout approaches might perform a bit better than the LinearLayout one
|
Marek D. |
ok but this question is more general
|
Mark M. |
but all should have rendering speeds measured in microseconds
|
Marek D. |
if I have two layouts to choose
|
Marek D. |
which to prefer
|
Mark M. |
unless you have lots of them in a scrolling container, performance is unlikely to be a problem
|
Marek D. |
I was developing from 2.1 and I have a tendency to use Linears everywhere
|
Marek D. |
but younger devs say Google says use Constraint :)
|
Mark M. |
LinearLayout got a bad reputation, but again, it was mostly when they were used for complex rows in a ListView
|
Mark M. |
and they had to get rendered and re-rendered and re-re-re-rendered a lot
|
Marek D. |
ok makes sense
|
Mark M. |
ConstraintLayout is also more flexible, so I would lean towards it for new development
|
Marek D. |
if we can return to the keyboard question
|
Marek D. |
keyboard matter
|
Marek D. |
the keyboard is for the price
|
Marek D. |
to enter the price
|
Jun 18 | 7:45 PM |
Marek D. |
the design gave me no hints (I just saw a full price) how to format the price when is being entered
|
Marek D. |
so if I want to put 123.45
|
Marek D. | |
Marek D. |
I display it in a textview
|
Marek D. |
did I broke the chat ?
|
Mark M. |
no
|
Marek D. |
ok nvmd
|
Marek D. |
but the designer wants a blinking cursos
|
Marek D. |
cursor (single)
|
Marek D. |
do you have any hints how to create this cursor effect
|
Marek D. |
/ indicated a bold span previously, forgot to mention that
|
Marek D. |
and of course I forgot the cents
|
Marek D. | |
Mark M. |
well, to be completely honest, your designer and I are not really going to get along
|
Mark M. |
from an accessibility standpoint, the right answer is to just use an EditText
|
Marek D. |
then I cannot use this chat transcript :D
|
Jun 18 | 7:50 PM |
Mark M. |
sorry, but I get fairly grumpy when designers value aesthetics over accessibility
|
Mark M. |
since you are more likely to get sued or fined by a government for accessibility violations than for having boring aesthetics
|
Marek D. |
was not aware
|
Mark M. |
I do not know what the market your app is in, and what the regulations are where you live and distribute the app
|
Mark M. |
but, this is the sort of thing that probably should get reviewed by legal counsel
|
Mark M. |
but, let's pretend that the attorney says the plan is fine, or management does not want to research the point
|
Marek D. |
well I could use edittext
|
Marek D. |
but I think there is a reason they prefer onscreenkeyboard
|
Mark M. |
for abled people, it is possible that an on-screen keyboard is a more efficient solution
|
Marek D. |
1. looks nicer
|
Marek D. |
2. I happen to find screens where keyboard does not open
|
Marek D. |
I don't have particular example at the moment
|
Marek D. |
but I had <EditText><requestFocus/>
|
Marek D. |
and for some reason, for some device the keyboard was not being displayed
|
Mark M. |
yes, sometimes you have to use InputMethodManager to convince the keyboard to appear
|
Marek D. |
and the ET was focused
|
Mark M. |
it's annoying
|
Jun 18 | 7:55 PM |
Marek D. |
so you need to unfocus and focus by hand
|
Marek D. |
never knew how to use it properly (IMM)
|
Marek D. |
if I use edit text for displaying the price
|
Marek D. |
I need to make it disabled
|
Marek D. |
then I do not have blinking cursor, right?
|
Mark M. |
I forget, but I suspect that you are correct
|
Marek D. |
and if I use the edittext enabled then I might have two keyboards
|
Mark M. |
yes
|
Mark M. |
so, you have a few options that I can think of
|
Marek D. |
I am not sure If I have enough mana to convince everyone to use ET
|
Marek D. |
or enough charisma
|
Mark M. |
yes, I'm focusing now on how to implement your blinking cursor
|
Marek D. |
I am all ears
|
Mark M. |
option 1: find a character that looks like a Cursor, put it in your Spanned wrapped in a ForegroundColorSpan, and try calling updateDrawState() periodically to achieve the blinking effect
|
Jun 18 | 8:00 PM |
Marek D. |
123|.00
|
Mark M. |
effectively, yes
|
Mark M. |
option 2: use an image in your Spanned via an ImageSpan, and see if you can animate it via changing color filters or tints or something to make it appear to come and go
|
Mark M. |
option 3: have two TextView widgets wrapped around an ImageView, where the ImageView is your cursor and you animate it using normal animation stuff
|
Marek D. |
thank you very useful
|
Marek D. |
View paste
|
Mark M. |
that might work
|
Marek D. |
allright will try them all
|
Mark M. |
a variation on that theme would be to have an EditText that is behind something transparent, so the user cannot tap on it to bring up the system keyboard
|
Marek D. |
yes
|
Mark M. |
then, so long as you suppress the system keyboard at the outset, it probably will not appear
|
Jun 18 | 8:05 PM |
Marek D. |
allright moving to last question
|
Marek D. |
Keyboard is a separate component in reality
|
Marek D. |
i want to keep it dumb
|
Marek D. |
the PriceTag as I call it has the logic
|
Marek D. |
of formatting the price
|
Marek D. |
+ interpreting the keyboard
|
Marek D. |
like not allowing more digits after cents
|
Marek D. |
double commas etc
|
Marek D. |
so keyboard is a custom view
|
Marek D. |
it has listeners for the keyboard presses
|
Marek D. |
the Fragment that holds the view
|
Marek D. |
passes the messages to something
|
Marek D. |
at the moment this something is a viewmodel
|
Marek D. |
let's call it PriceTagViewModel
|
Marek D. |
and it sends formatted string as live data
|
Marek D. |
I am wondering if LiveData makes sense here
|
Marek D. |
this is not async thing
|
Marek D. |
and formatting is pretty fast
|
Mark M. |
no, but LiveData primarily is a reactive thing
|
Mark M. |
we happen to use it for async work, but that does not mean that all LiveData uses should be for async work
|
Mark M. |
for example, in shared viewmodels (such as between two fragments), you might use LiveData as a means of getting values from one fragment to another
|
Jun 18 | 8:10 PM |
Mark M. |
I cannot really say whether you need LiveData here -- that would depend on who is using the formatted string and whether it needs to react to changes in real time
|
Mark M. |
if it does, then LiveData is a reasonable choice, particularly if the project is in Java
|
Marek D. |
is kotlin
|
Mark M. |
you could use coroutines stuff like StateFlow then, if you wanted, or stick with LiveData
|
Marek D. |
I was just wondering it this pseudo code would make more sense. priceTagTextView.text = priceTag.append(1)
|
Marek D. |
where priceTag is a viewmodel (but could be just any object)
|
Marek D. |
so all methods of this object would return immediately the result of manipulation of the price
|
Mark M. |
¯\_(ツ)_/¯
|
Marek D. |
:)
|
Marek D. |
ok many thanks for the chat
|
Mark M. |
it is difficult for me to provide that level of advice, as I do not know your code
|
Marek D. |
I understand
|
Marek D. |
I just don't like that people put LD everywhere
|
Jun 18 | 8:15 PM |
Marek D. |
because Google says LD is the king
|
Mark M. |
LiveData is fine for cases where the supplier of data cannot have a reference to the consumer of that data, such as a viewmodel not having a reference to a fragment
|
Mark M. |
so, you would not use LiveData (usually) to have a fragment get data *to* a viewmodel, because it is perfectly fine for a fragment to have a reference to its viewmodel
|
Mark M. |
LiveData, in the end, is a lifecycle-aware value holder with a set of observers
|
Mark M. |
in other words, it is a callback system with a great marketing budget
|
ansh s. | has entered the room |
Marek D. |
for me LD is a kind of event bus
|
Mark M. |
it happens to solve the viewmodel -> fragment problem fairly nicely
|
ansh s. |
Hi mark
|
Marek D. |
+ redelivery of the last value
|
Mark M. |
Marek: let me try to take a question from Ansh, before the chat is over -- if there is time, I will swing back to you
|
Marek D. |
sure
|
Mark M. |
Ansh: hi! how can I help you today?
|
Jun 18 | 8:20 PM |
ansh s. |
Nothing much, you can go on talking to marek (Hi btw) . I saw your time and came to say a hi. hope you are doing fine and safe, its been long since i came here. Also I was able to figure out the issue with my DB Problem(From the community ) . turns out we don't have to set the foriegn key constraint on the relation table
|
Mark M. |
ah, OK -- I haven't played with M:N relations in Room recently, and I forgot
|
ansh s. |
View paste
(3 more lines)
|
Mark M. |
my apologies for not thinking of that in the forum thread!
|
ansh s. |
No worries.But i think this has been in your book too. you might want to update that
|
Marek D. | |
Mark M. |
ah, but you have foreign keys from the other tables to the ItemCategoryRelation, right?
|
Mark M. |
Marek: you're welcome!
|
ansh s. |
Although my guess was just randomly commenting out the code, and you are the boss of things , can you explain what is happenning ?
|
ansh s. |
no i don't have any other relations, room is figuring out on its own
|
ansh s. |
just the entities i poste before https://community.commonsware.com/t/trying-the-...
|
Mark M. |
yeah, I was just looking at those and cross-checking with my book samples
|
Mark M. |
give me one minute for some research
|
Jun 18 | 8:25 PM |
Mark M. |
hmmm...
|
ansh s. |
sure. does my initial query about keeping the same column names still holds true?
|
Mark M. |
well, I thought my comment there was correct
|
Mark M. |
now I am going to need to spend some time and try to see what is going on
|
ansh s. |
oh ok :)
|
ansh s. |
Also i am not sure about this, but i think room's debug libs have a bug
|
Mark M. |
it wouldn't be the first time :-)
|
Mark M. |
but, let me poke at this a bit and I'll try to respond back to your forum post this weekend
|
ansh s. |
hehe. as you said , when i tested my code with activity, it ran fine, but this code is still not producing any outputs in the instrumentation test
|
ansh s. |
sure
|
ansh s. |
BtW , How are things in the US ? are you safe and healthy?
|
Mark M. |
AFAIK, yes :-)
|
Mark M. |
I hope things are OK with you as well!
|
ansh s. |
yeah. I would have graduated this year if covid didn't happenned
|
Jun 18 | 8:30 PM |
Mark M. |
sorry to hear that!
|
ansh s. |
Hey i wanted to know how can i check about the expiry of my subscribtion
|
ansh s. |
i mean when do i have to renew it? i wanted to know that
|
Mark M. |
log in, click the Renew option in the nav bar
|
Mark M. |
under the "Renew!" headline will be your expiration date
|
ansh s. |
oh ok, found that, thanks
|
ansh s. |
Well i will be going now. nice talking to you
|
Mark M. |
likewise!
|
Mark M. |
the next chat is Thursday at 4pm US Eastern
|
ansh s. | has left the room |
Mark M. |
the transcript for this chat will appear at https://commonsware.com/office-hours/ shortly
|
Marek D. | has left the room |
Mark M. | turned off guest access |