Office Hours — Today, January 20

Thursday, January 18

Jan 20
8:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
9:00 AM
Gerrit
has entered the room
Gerrit
Hi Mark!
Mark M.
hello, Gerrit!
how can I help you today?
Gerrit
I've got two somewhat similar problems that can be catagorized as "lost in refactoration" (pun intended).
View paste
It's about how to change from an activity based approach to a fragment based one : 
(1) for RecyclerView action mode (p.1622) 
and (2) a custom DialogPreference preferences dialog (p.1991) for an often used filter.
View paste
(1) Why : it's a cascaded detail view (of 1|-> many) on database tables, simple example : LastName |-> cities |-> street |-> full adresses.
So I want to be able on tablets to see two fragment parts (ex. cities with all streets for the selected city (single selection action mode) 
 
(1) Works mostly, my approach was to move everything that needed it (receive/pass intent; RecyclerView; FragmentAdapter based on abstract FragmentBaseAdapter; ViewHolder) 
to the fragment and reference "fragment.getActivity()" to keep the references to the activity where necessary. 
But I can't get the action mode code to work. (The code is not traversed when I put a breakpoint in debug mode).
If I move the code to an OptionsMenu it works fine, but then the actionbar clearly is an optionsmenu and not an actionmenu, 
so I think I've missed "taking a Trick", as we say when playing Whist.
Mark M.
well, RecyclerView itself is not tied to activity or fragment
make sure that whatever trigger you are using for initiating the action mode works (e.g., OnLongClickListener)
the MVI sample from the latest "Android's Architecture Components" offers an action mode, though that sample is a bit involved
9:05 AM
Mark M.
but that action mode is for a RecyclerView shown in a fragment
and so perhaps it can give you some clues
I do not recall having to do anything out of the ordinary to get the action mode to work in a fragment
Gerrit
Ok, I'll have a look at that MVI one as well then, and you're probably right that I'll have to recheck the listener.
Mark M.
in that sample, I am using data binding, and I have an android:onLongClick attribute that calls into my ViewHolder, and that eventually triggers the action mode
DialogPreference is not tied to an activity or fragment either, so I am not completely clear on what the issue is
(with regards to your second area of concern)
Gerrit
View paste
(2) Why : I want to launch a single filter dialog that's often used from a menu; and for the CWAC Colormixer example lint says xml based preferences approach is deprecated.
BTW: Is deprecation the team sport at android dev ;-) ?
The filter is a seekbar + gradual text explanation (so some values have the same text) 
i.e. "everything vaguely similar / loose ressemblance /stricter ressemblance / exact match only"

(2) I have it working now by passing through the preference activity with the intent, which launches the layout (with the XML) that contains the fragment. 
Can a DialogPreference fragment be launched from a normal activity, or should I use a normal dialog that's accessing shared preferences for this ?
Mark M.
"xml based preferences approach is deprecated" -- I am not certain what you are referring to
"Is deprecation the team sport at android dev" -- no, but it feels like that there is a per-major-release quota
"Can a DialogPreference fragment be launched from a normal activity" -- I wouldn't do that
9:10 AM
Mark M.
"should I use a normal dialog that's accessing shared preferences for this ?" -- whether it should be a dialog or not is difficult to answer (my tendency is to avoid dialogs where possible), but if the host is not a PreferenceFragment, it should be a normal dialog, not a DialogPreference
*Preference classes are for the preference system only
Gerrit
View paste
In android studio, the Lint popup says "addPreferencesFromResource(R.xml.preferences)" is deprecated,and if you follow the link to the preferenceactivity class : 
     * @deprecated This function is not relevant for a modern fragment-based
     * PreferenceActivity.
Mark M.
ah, OK
PreferenceActivity in general is deprecated
the current direction is a regular activity hosting a PreferenceFragment
but that is for collecting preferences "in bulk"
in your case, this is just a regular portion of your UI that *happens* to persist its data in SharedPreferences
as it turns out, that same MVI sample has a "filter mode" drop-down menu that is backed by SharedPreferences
in my case, I am demonstrating Model-View-Intent, including the repository pattern, so I have a FilterModeRepository that is backed by SharedPreferences
the change in the filter mode simply triggers actions which flows through the MVI setup to both affect the UI change and update the repositoyr
er, repository
9:15 AM
Gerrit
View paste
Ok, guess it's worth to dive into that book more profoundly as well then 
(Only skimmed it for now, as I'm not using Room for my app
Mark M.
it happens that your two areas of concern are illustrated there
just reading the GUI architecture chapter, and the subsequent chapter on MVI, may help
note that while I spend a lot of pages on the MVI sample app, it is mostly for the MVI
er, MVI functionality
I am re-re-re-re-writing the tutorials to build that MVI app from scratch, and so I am not covering the full details of every bit of code in "Android's Architecture Components"
9:25 AM
Gerrit
Can I bug you with 2 gradle questions as well?
Mark M.
sure
if you're lucky, I can even answer them!
Gerrit
Yeah, my stack overflow searches have the same result ;-)
Can you get the Buildconfig.debug variable read in gradle somehow, so that I can adjust the version for debug builds (like say +1) ?
Mark M.
that's not how it works
Gradle isn't a script for building an app
Gradle is a script for building an object model of how to build an app
hence, your script is always both debuggable and not-debuggable
instead, you would need to arrange to change the version in debug tasks
9:30 AM
Mark M.
that's a fairly standard block of Gradle code in my CWAC libraries
it is setting up the publishing stuff for Maven
but in this block, I am iterating over all the build variants and adding a custom task for the non-debug variants: https://github.com/commonsguy/cwac-saferoom/blo...
I presume that there is a similar approach that you could iterate over the build variants and adjust your version for the debug variants
Gerrit
View paste
Maybe my wording was wrong, but I indeed meant how to script for debug builds, so this 
if (name.equals(com.android.builder.core.BuilderConstants.DEBUG)) {
            return; // Skip debug builds.
} 
part, is what I was looking for.
Mark M.
ok
9:35 AM
Mark M.
I am not certain then if I answered your question, but it's about the best that I have on that particular point
Gerrit
View paste
Yes, that's a good hint.
9:40 AM
Gerrit
View paste
Second problem is gradle and the jacoco plugin issues with a specific library dependency: 
to be clear, on Github even the Gradle and Jacoco people refer to each-other for how to fix, 
so I know it's not a solution, but more of a possible problem-approach I'm looking for.
So normally, you can script gradle to exclude classes from the jacoco coverage, 
but it still touches the code excluded(adds jacoco related variables in intermediate class files)
 even if it shouldn't and that messes up the library's checks and balances and fails the compile.
So my question is: is there a way to "debug" gradle scripts, to check what it does / doesn't skip ?
Mark M.
that is far outside my area of expertise, sorry
Gerrit
OK, no problem
9:45 AM
Gerrit
View paste
Ok, maybe to round up a question that probably has such a simple answer that the answer is right in front of my nose, but I can't seem to find it: I'm using style windowFullscreen/ windowNoTitle, but I'm still getting my app name in every action/menubar, what have I overlooked?
Mark M.
if your question is "why do I have an action bar?", I do not know, as it sounds like your theme should be requesting to not have one
if your question is "why do I have my app name in the action bar?", well, that's the default action bar title, and AFAIK the theme doesn't affect that
9:50 AM
Gerrit
Yes, it should be the first question, so I presume that though I changed (added) this style, I forgot to change it in manifest as well.
Mark M.
that's a possibility
9:55 AM
Gerrit
Ok, that's all for me, thank you for your time, and have a nice weekend.
Mark M.
you too!
Gerrit
Thanks, see you later.
10:00 AM
Gerrit
has left the room
Mark M.
turned off guest access

Thursday, January 18

 

Office Hours

People in this transcript

  • Gerrit
  • Mark Murphy