-
Notifications
You must be signed in to change notification settings - Fork 54
Conversation
MainActivity contains a two textviews, title and freeform text, whose text is controlled by a String list Variable and a String Variable, respectively. Box activity contains a title text and a box. The box has a color controlled by a Color list Variable and it is hidden or shown based on a Boolean variable. Both activities’ title text share a Range Variable that dictates their size, this is meant to showcase Remixer keeping values across different contexts, but this depends on #36
* explicit (not-annotation-based) API for Remixer. | ||
* | ||
* <p>While this is supported we think most people would prefer to use the clearer, less verbose | ||
* annotation-based API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'm not convinced that you need to create showcase a non-annotation-based example. In fact, I would argue that since you want to encourage clients to use the annotation-based version, you should just showcase that.
Plus, you can still ensure support for the explicit API via tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix that
// The remixer instance | ||
private Remixer remixer; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting and blank lines for these fields
remixer.addItem(booleanVariable.buildAndInit()); | ||
@RangeVariableMethod( | ||
minValue = 16, maxValue = 72, increment = 4, title = "(Shared) Title font size") | ||
void setTitleTextSize(Integer size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if I'm reading this right, then the key of an annotated method is the simple method name? And this is how you ensure this Variable is shared across 2 activities?
This is really clever, but it's a really difficult to discover API. This is also prone to errors: imagine if a client has two different Activities, each with an annotated setTextSize()
(maybe they're lazy) but meant to target completely different widgets. All of a sudden, these 2 variables are linked due to having the same key/name, and it's probably a huge pain trying to debug why it's happening (without your help).
I would suggest changing it, perhaps to something more explicit. I have some ideas, but can you first enumerate the reasons why we have keys? I'll start us off:
- Two RemixerItems can have the same key in order to share the current value. The constraint is that they must both share the same Type and their parent Activity must differ.
- A RemixerItem's key is used to connect it to the corresponding remixer Widget so updates in the widget are correctly routed to the right callback. (is this true?) The constraint is that all RemixerItems under the same parent Activity must have different keys.
Anything else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key can be set explicitly, remember a while ago we were trying to minimize the amount of boilerplate a user needed to write, key was one of them, so it takes a sensible default.
I can still change it to something more explicit, and maybe remove auto key generation if you think it's that problematic.
Also you're correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should definitely keep an eye out for whether this trips anyone up. And/or think about when an unintended key collision happens, how you can help the client debug. All of this can be done after this PR.
adapter.add(getResources().getString(R.string.boxDemoName)); | ||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | ||
@Override | ||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rename i and l. position
and id
|
||
public class MenuActivity extends AppCompatActivity { | ||
|
||
private ListView listView; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest being a good example (get it?) and using RecyclerView. Since this is in the example
project, clients won't unnecessarily inherit the RV dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
Intent intent = new Intent(); | ||
switch (i) { | ||
case 0: | ||
intent.setClass(getApplicationContext(), MainActivity.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noooo don't use the application context unnecessarily. Or did you do it on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoopss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woohoo
void setBoxColor(Integer color) { | ||
box.setBackgroundColor(color); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank spaces - taylor swift
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HAHAHAHAHAHA
import com.google.android.libraries.remixer.ui.gesture.Direction; | ||
import com.google.android.libraries.remixer.ui.view.RemixerFragment; | ||
|
||
/** | ||
* Main activity with explicit instantiation of Remixer Objects. | ||
* Annotated version of the BoxActivity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this javadoc right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
private TextView freeformText; | ||
// The remixer instance | ||
private Remixer remixer; | ||
TextView titleText; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these package-private for a reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
.setLayoutId(R.layout.color_list_variable_widget); | ||
remixer.addItem(colorVariable.buildAndInit()); | ||
remixerButton = (Button) findViewById(R.id.button); | ||
RemixerBinder.bind(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not for this PR, but: could this call be replaced with an @annotation on the Activity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It generally can't, this is because of the way Annotation processing works, all such frameworks use a similar method to tie things together :(
@RangeVariableMethod( | ||
key = "titleTextSize", | ||
minValue = 16, maxValue = 72, increment = 4, title = "(Shared) Title font size") | ||
void setTitleTextSize(Integer size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious if this param can be replaced with int
? It may be better as an example for this to be int
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it can't :/ Java is very dumb about unboxing templated stuff. :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or rather, I'm checking that the parameter is of a specific class, and since templates don't work with primitives and primitives aren't classes, it's mandatory to use the boxed version, I will investigate whether there is a way to compare to the unboxed type, but I don't think that's likely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whaaat really? I think this deserves another look (later). There must be a way to support this.
I think this is pretty important, or devs who add @RemixerAnnotations to existing code will find it to be a major PITA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #40 to investigate
MainActivity contains a two textviews, title and freeform text, whose
text is controlled by a String list Variable and a String Variable,
respectively.
Box activity contains a title text and a box. The box has a color
controlled by a Color list Variable and it is hidden or shown based on
a Boolean variable.
Both activities’ title text share a Range Variable that dictates their
size, this is meant to showcase Remixer keeping values across different
contexts, but this depends on #36