Office Hours — Today, December 18

Saturday, December 15

Dec 18
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:35 PM
Ahmad M.
has entered the room
Mark M.
hello, Ahmad!
how can I help you today?
Ahmad M.
hello Mr.Mark
yes please
i did what you tell me about making Repeat as foreignKey for TodoModel , this is the Repeat Entity :
View paste (25 more lines)

@Entity(tableName = "repeats" ,
        foreignKeys = @ForeignKey(entity = ListOfTodo.class,
        parentColumns = "uniqueTodoId",
        childColumns = "uniqueRepeatId",
        onDelete = ForeignKey.CASCADE),
        indices = @Index(value = "uniqueRepeatId" ,unique = true))
public class Repeat {

    @NotNull
    @PrimaryKey
    public String uniqueRepeatId;

    @Embedded
    public RepeatType repeatType;
...
the Repeat has RepeatType which is enum
7:40 PM
Ahmad M.
View paste (15 more lines)
public enum RepeatType {

    ONE_TIME(0), DAILY(1), WEEKLY(2), MONTHLY(3), YEARLY(4);

    private int value;

    @TypeConverter
    public static RepeatType fromLevel(Integer level) {
        for (RepeatType p : values()) {
            if (p.value==level) {
                return(p);
            }
        }

        return(null);
...
and the Repeat Time which is semple class
View paste
public class RepeatTime {

    public RepeatTime(int hourReminderTime, int minuteReminderTime) {
        this.hourReminderTime = hourReminderTime;
        this.minuteReminderTime = minuteReminderTime;
    }

    public int hourReminderTime;
    public int minuteReminderTime;
}
represent time
Mark M.
@Embedded public RepeatType repeatType; -- you should not need @Embedded here
RepeatType will go into a single column in your table, by way of your @TypeConverter methods
you should be able to skip the @Embedded annotation
Ahmad M.
yes u right
this cope i make to u
this is the Weekly Repeat Class
View paste
public class WeeklyRepeat {

    @TypeConverters({Converters.class})
    public ArrayList<Integer> daysInTheWeek;
    public int weeklyRepeatType;

    public WeeklyRepeat(ArrayList<Integer> daysInTheWeek, int weeklyRepeatType) {
        this.daysInTheWeek = daysInTheWeek;
        this.weeklyRepeatType = weeklyRepeatType;
    }
}
and this is the Monthly Repeat Class
View paste (3 more lines)
public class MonthlyRepeat{

    public int monthlyRepeatType;
    public int monthlyIntervalRepeatType;

    @TypeConverters({Converters.class})
    public ArrayList<Integer> months;

    @TypeConverters({Converters.class})
    public ArrayList<Integer> days;

    public MonthlyRepeat(int monthlyRepeatType, int monthlyIntervalRepeatType, ArrayList<Integer> months, ArrayList<Integer> days) {
        this.monthlyRepeatType = monthlyRepeatType;
        this.monthlyIntervalRepeatType = monthlyIntervalRepeatType;
        this.months = months;
...
7:45 PM
Aaron
has entered the room
Mark M.
(hello, Aaron -- I will be with you after Ahmad has had a chance to ask a question!)
Aaron
thanks
Ahmad M.
and i notes that every field in the Entity should not have the same name as in the "days" field in the Weekly repeat class and Monthly repeat class
is this structure for my Database is right?
Mark M.
well, other than the unnecessary @Embedded on the RepeatType field, there is nothing I see that is wrong
7:50 PM
Mark M.
personally, I would try to model it differently, but that is a question of my preferences versus yours
7:50 PM
Ahmad M.
all this because the user going to chose one of the Repeating types
maybe Weekly or Monthly ext
is there any way better
Mark M.
I do not know what "better" would be for you
Ahmad M.
if the user chose weekly Type the other Types well all be null
can i chose the one Entity from many at run Time
Mark M.
one approach for that is inheritance, where you would have a RepeatBase class that has the common things, and subclasses for different varieties (weekly, monthly, yearly)
it makes the relations more complex, but it keeps the individual classes simpler
see the "Polymorphic Room Relations" chapter in "Android's Architecture Components" for more about that
7:55 PM
Mark M.
another possibility is that you do not try to have individual columns/fields for each discrete piece of data
instead, you use some other encoding system
for example, the iCalendar specification has a whole language for repeat rules (RRULE, if I remember the name correctly)
those just get represented as text that you would parse
so, you could say that your ToDo items have a List<String>, where each String represents a single iCalendar repeat rule
you would have to write the code to parse and generate the rule strings, but it would simplify your database structure a lot
my guess is that you are not going to be querying the database for the individual fields much
for example, you are unlikely to be executing a SQL SELECT statement where you are querying on daysInTheWeek
Ahmad M.
what are u mean about "it makes the relations more complex"
Mark M.
each subclass of RepeatBase gets its own table
as each subclass would be its own @Entity
so ToDo would have relations to three separate entity classes
rather than just the one that you have right now
let me take a question from Aaron, and I will return to you shortly
Aaron: your turn, do you have a question?
Ahmad M.
ok
Mark M.
(and since I know you usually come with a list... could you post just one?)
Aaron
sure
um, this is 2 parts so I'll just post the first
View paste
I have a couple problems with my day and night colors.xml files.

https://github.com/ajh3/NoSurfForReddit/blob/master/app/src/main/res/values/colors.xml
https://github.com/ajh3/NoSurfForReddit/blob/master/app/src/main/res/values-night/colors.xml

a) I am hardcoding colorRecyclerViewText and colorRecyclerViewTextClicked, to tweak some colors in my RecyclerView in Day vs. Night mode. I picked these colors by logging them myself from existing colors on widgets in the DayNight theme that looked like nice colors to use. I had to do this because there is no DOM-inspector equivalent in the Layout Inspector, and therefore I have no idea what are the correct style names to reference with ?android:attr/ to avoid hardcoding the values like this. Is there any way to find the style names esides trial and error? I feel like I asked a similar question a few months back and there was no trick to help, but just in case...
8:00 PM
Mark M.
I have no idea how to do what you are seeking, sorry
since that was pretty quick, what's the second part of the question?
Aaron
b) For colorNightBg and colorAmoledNightBg, as per their names, these colors are only used in night mode and I don't want/need to use them in the default colors.xml at all. However the app crashes (and Lint complains, I believe) when they are not also included in the default colors.xml, so I am unnecessarily repeating them there. Is there anything to do about that?
Mark M.
your problem would then lie in where you are using these, presumably
the point behind resource sets is that you should not have dedicated resources along the same axis as the set
so, for example, you would not have app_name and app_name_french as string resources
you would just have app_name, with values in res/values and res/values-en/
so, colorNightBg is a code smell
it should just be colorBg
where you use that color all the time
Aaron
yes, understood, and the only reason I have this is because of the AMOLED night mode, where I have two possible values for the background color when the app is in night mode
8:05 PM
Aaron
after the user puts it into night mode, they can additionally select AMOLED night mode in which case the background is set to pure black, so there is no day mode analogue
Mark M.
I guess I don't understand the significance of AMOLED night mode with respect to what you're doing, but OK
then there's something else afoot
res/values/ is the default; res/values-night/ overrides them
there is never a need to duplicate a value in an override
so your app crash is inexplicable, and I'd need a lot more to go on to help with that (code, stack trace, etc.)
in terms of Lint warnings, that could just be an over-aggressive Lint check
though it's possible that whatever is causing the crash might have a trickle-down effect on Lint
oh, wait
I had your problem inverted
you avoid the duplication by putting the colorNightBg in res/values/ and leave it out of res/values-night/
Aaron
ah, yes
Mark M.
the fact that *you* happen to only be using it in night mode is a red herring from the standpoint of Android's resource system
for all Android knows, you only use colorNightBg on the user's birthday
Aaron
OK that's what I was looking for
makes sense
Mark M.
sorry it took me so long to wrap my head around that
Aaron
and I see why it is crashing now, too, thanks, please feel free to switch back to Ahmad
no worries
8:10 PM
Mark M.
Ahmad: your turn! do you have another question?
Ahmad M.
yes
are u mean like this :
View paste (6 more lines)

@Entity(tableName = "repeats" ,
        foreignKeys = @ForeignKey(entity = Repeat.class,
                parentColumns = "uniqueRepeatId",
                childColumns = "uniqueWeeklyRepeatId",
                onDelete = ForeignKey.CASCADE),
        indices = @Index(value = "uniqueWeeklyRepeatId" ,unique = true))
public class WeeklyRepeat extends RepeatBase{

    public String uniqueWeeklyRepeatId;

    @TypeConverters({Converters.class})
    public ArrayList<Integer> daysInTheWeek;
    public int weeklyRepeatType;

...
View paste

public class RepeatBase  {

    // this is enum
    public RepeatType repeatType;

    @Embedded
    public RepeatUntil repeatUntil;

}
Mark M.
yes, something like that
WeeklyRepeat is simpler than your original Repeat class and has fewer unnecessary fields
the same will be true for the other subclasses of RepeatBase
Ahmad M.
ok
Mark M.
when you load your ToDo instances, you will need to retrieve the repeat rules from these other entities, rather than just from the one Repeat entity
Ahmad M.
when i query for single Todo i'll query for it in at least 3 Entity right
??
Mark M.
well, there is still just one ToDo entity and table
remember that Room does not automatically retrieve related entities when you do a query
8:15 PM
Ahmad M.
uha
Mark M.
View paste
so your Dao will have some method like:

@Query("SELECT * FROM ToDo WHERE ...")
List<ToDo> loadToDos()
Ahmad M.
that is rghit
Mark M.
you will then need to also have DAO methods for retrieving the weekly, monthly, and yearly repeat rules
in that chapter that I mentioned on polymorphic Room relations, I have some suggestions on how to set up that sort of thing
Ahmad M.
yes that is esey
Mark M.
along with sample code
Ahmad M.
give your suggestions pleas
Mark M.
ummm... suggestions for what?
Ahmad M.
uha i think u have more suggestions for me
thank u Mr.Mark
Mark M.
you are welcome!
Aaron: your turn! do you have another question?
Aaron
yes, and this is actually my only other question today
Is it accurate to say that in plain Java a Future is analogous to an Rx Disposable, with the main difference being that Futures also get you the result value, whereas Disposables do not? Also, it seems that Futures play no role in Rx. Is there a reason why Rx didn't include/build on Futures in some way?
Mark M.
I have not used Future in Java
Aaron
ok, no worries
Mark M.
so I can't really comment on it -- sorry
for whatever reason, it hasn't seemed that popular in Android circles, even though we've had it since the beginning
8:20 PM
Aaron
as a final comment, I think it is wild that there is no stylesheet-inspector-like tool for layouts, with regard to my first question
this problem keeps coming up for me, but I can barely find anyone talking about it online
Mark M.
well, that's not that easy to create
Aaron
yes, true, I am just surprised that more people aren't asking for it
Mark M.
for example, you mentioned that the Layout Inspector doesn't show you where the value came from
that's because all the Layout Inspector knows is what the final value is
the Layout Inspector doesn't even really know the state of the Configuration, let alone have all of the details of how the resource sets got applied
that would take something a bit more like the layout editor, which basically starts with your code and generates a preview
Ahmad M.
has left the room
Mark M.
it also really runs the code for the widgets, which is why the preview looks as accurate as it does
Aaron
yes, that makes sense why it has not been developed, I just would have expected more complaining
I've found like one stackoverflow post asking for such a thing
Mark M.
oh, there are probably people complaining
Aaron
/shrug
Mark M.
it's just that we have a *lot* of complaints
Aaron
not as many as I would have expected
ha
OK, well thanks for the info
Mark M.
that one probably doesn't rise above the level of complaint background noise
Aaron
I will suffer in silence
have a nice night!
Mark M.
you too!
Aaron
has left the room
8:30 PM
Mark M.
turned off guest access

Saturday, December 15

 

Office Hours

People in this transcript

  • Aaron
  • Ahmad Mustafa
  • Mark Murphy