Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Add second activity to example app #37

Merged
merged 5 commits into from
Oct 25, 2016
Merged

Add second activity to example app #37

merged 5 commits into from
Oct 25, 2016

Conversation

miguelandres
Copy link
Contributor

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

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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;


Copy link
Contributor

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) {
Copy link
Contributor

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:

  1. 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.
  2. 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?

Copy link
Contributor Author

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.

Copy link
Contributor

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) {
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoopss

Copy link
Contributor

@pingpongboss pingpongboss left a 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);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank spaces - taylor swift

Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this javadoc right?

Copy link
Contributor Author

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;
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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. :/

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #40 to investigate

@miguelandres miguelandres merged commit 267802b into develop Oct 25, 2016
@miguelandres miguelandres deleted the demo_app branch October 25, 2016 20:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants