Skip to content

Widget cleanup#298

Merged
korelstar merged 3 commits into
nextcloud:masterfrom
dan0xii:widget_cleanup
Nov 27, 2017
Merged

Widget cleanup#298
korelstar merged 3 commits into
nextcloud:masterfrom
dan0xii:widget_cleanup

Conversation

@dan0xii

@dan0xii dan0xii commented Nov 13, 2017

Copy link
Copy Markdown
Collaborator

General improvements to widget code

  • Removed unused imports
  • Improvements to accessibility and internationalisation
  • Removed hard coded dimensions in layouts
  • Set the note list widget's empty view to be displayed in the scenario when the user adds the widget to their home screen then proceeds to delete all notes from within the app.

This includes the changes from #297 so it will be worth waiting until that's agreed before reviewing this PR.

The widget will now check to see if the note exists before trying to display it. Fixes nextcloud#293.
Moved opening of db from getViewAt.
Fixed the widget's empty view.

@korelstar korelstar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you done with your optimizations? There are some comments which indicate that this is not the case (see NotesListWidgetFactory regarding mAppWidgetId and SingleNoteWidgetFactory regarding "TODO Set loading view").

Log.e(TAG, "Error: note not found");
note = null;
} else {
note = db.getNote(noteID);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the note exists (which is the default scenario) db.getNote(noteID) is executed twice. Since database queries are expensive, this should be optimized.

@Override
public void onDestroy() {

db.close();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since NoteSQLiteOpenHelper is currently a singleton, it's dangerous to close the database from here. Theoretically, it's possible that another objects still wants to use the database. Hence, I suggest to remove this.

android:layout_width="match_parent"
android:orientation="horizontal"
android:padding="4dp">
android:padding="@dimen/widget_note_list_entry_layout_padding">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the advantage of moving these dimensions to dimens.xml? As far as I can see, you are not re-using any of them! From my point of view, this makes everything much more complex ...

android:layout_height="match_parent"
android:paddingLeft="6dp"
android:paddingStart="@dimen/widget_note_list_entry_padding_start"
android:paddingEnd="@dimen/widget_note_list_entry_padding_end"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do use different dimensions for padding left and start (respective right and end)? These values should be the same and therefore the dimension keys, too (if used at all, see other comment). I don't think, that the file values-v17/dimens.xml is needed.

@dan0xii

dan0xii commented Nov 15, 2017

Copy link
Copy Markdown
Collaborator Author

Hello Korelstar,

I was intending on using mAppWidgetId in NotesListWidgetFactory but have removed it for now because it will be a while before I get around to it.

The TODO for the loading view is a reminder but I will remove it if you prefer. I noticed that the "Loading" text isn't formatted great but it only appears on my phone for a split second every so often.

I'll work on the getNote() operation in SingleNoteWidgetFactory. I was trying to avoid using try-catch. I'll remove the call to db.close() also, that hadn't occured to me.

I moved the dimensions to a separate file as I was under the impression it's best practice to allow for different layout sizes on different devices (with varying display sizes).

I agree I could have used the same key name for the left/right and start/end dimensions but I thought it might be confusing to have paddingStart="@dimen/padding_left". The file values-v17/dimens.xml is needed to provide proper layout support for right-to-left devices. Once we are only supporting API 17 and upwards paddingLeft and paddingRight will be ignored when paddingStart and paddingEnd exist.

@korelstar

Copy link
Copy Markdown
Member

The TODO for the loading view is a reminder but I will remove it if you prefer.

No, that's fine.

I'll work on the getNote() operation in SingleNoteWidgetFactory. I was trying to avoid using try-catch.

Just save the result as local variable.

I moved the dimensions to a separate file as I was under the impression it's best practice to allow for different layout sizes on different devices (with varying display sizes).

Okay, but I still think, that maintainability would be increased if you use one single dimension-key for all usages that belong to each other. E.g., introduce a dimension widget_note_list_outer_padding with value 6dp an use this one instead of widget_note_list_header_icon_padding_left, widget_note_list_header_icon_padding_start, widget_note_list_create_icon_padding_right, widget_note_list_create_icon_padding_end, widget_note_list_title_padding_left, widget_note_list_title_padding_start, widget_note_list_entry_padding_left, widget_note_list_entry_padding_start, widget_note_list_fav_icon_padding_right and widget_note_list_fav_icon_padding_end. Motivation: If you change one of them, all of them have to be changed to the same value. Otherwise, the widget will look strange.

I agree I could have used the same key name for the left/right and start/end dimensions but I thought it might be confusing to have paddingStart="@dimen/padding_left".

If you name it padding_start it looks better. Even for paddingLeft="@dimen/padding_start", since paddingLeft is deprecated.

The file values-v17/dimens.xml is needed to provide proper layout support for right-to-left devices.

I don't understand this. If you use padding_start (or something like widget_note_list_outer_padding, see above) for both paddingLeft and paddingStart, then the definition must be in values/dimens.xml and you don't need values-v17/dimens.xml anymore. Nevertheless, right-to-left is fully supported this way.

Once we are only supporting API 17 and upwards paddingLeft and paddingRight will be ignored when paddingStart and paddingEnd exist.

Isn't this already the case when the app is executed on a device supporting the respective API?

Daniel Bailey added 2 commits November 19, 2017 14:44
* Removed unused imports
* Improvements to accessibility and internationalisation
* Removed hard coded dimensions in layouts
  *  Condensed dimensions definitions. Alignment problem.
@dan0xii

dan0xii commented Nov 19, 2017

Copy link
Copy Markdown
Collaborator Author

Take a look at the latest revision. I think I have ironed out all of the issues.

@korelstar korelstar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perfect! Thank you very much, @dan0xii

@stefan-niedermann I would merge this if you don't raise any objections.

@stefan-niedermann

Copy link
Copy Markdown
Member

Nope i'm fine with the changes, merge :)

@korelstar korelstar merged commit 11c2614 into nextcloud:master Nov 27, 2017
@dan0xii dan0xii deleted the widget_cleanup branch December 4, 2017 15:33
@korelstar korelstar added this to the 0.13.0 milestone Feb 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants