Skip to content

Context instead of Activity in SiteSettingsInterface - #6823

Merged
nbradbury merged 1 commit into
developfrom
feature/sitesettingsinterface-context
Nov 6, 2017
Merged

Context instead of Activity in SiteSettingsInterface#6823
nbradbury merged 1 commit into
developfrom
feature/sitesettingsinterface-context

Conversation

@hypest

@hypest hypest commented Nov 3, 2017

Copy link
Copy Markdown
Contributor

This way, SiteSettingsInterface can be used by Services as well.

No new functionality added.

To test:

  • Try to change the site settings via the app. It should work and the remote site be updated as well.

This way, SiteSettingsInterface can be used by Services as well.
@hypest hypest mentioned this pull request Nov 3, 2017
@nbradbury nbradbury self-assigned this Nov 4, 2017
siteSettingsPreferences(mActivity).edit().putString(LANGUAGE_PREF_KEY, mSettings.language).apply();
siteSettingsPreferences(mActivity).edit().putInt(DEF_CATEGORY_PREF_KEY, mSettings.defaultCategory).apply();
siteSettingsPreferences(mActivity).edit().putString(DEF_FORMAT_PREF_KEY, mSettings.defaultPostFormat).apply();
siteSettingsPreferences(mContext).edit().putString(LANGUAGE_PREF_KEY, mSettings.language).apply();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know this is pre-existing code, but how about using the builder pattern here?

siteSettingsPreferences(mContext).edit()
        .putString(LANGUAGE_PREF_KEY, mSettings.language)
        .putInt(DEF_CATEGORY_PREF_KEY, mSettings.defaultCategory)
        .putString(DEF_FORMAT_PREF_KEY, mSettings.defaultPostFormat)
        .apply();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, done in c97620d.

protected void notifyFetchErrorOnUiThread(final Exception error) {
if (mActivity == null || mActivity.isFinishing() || mListener == null) {
if (mContext == null
|| (mContext instanceof Activity && ((Activity) mContext).isFinishing())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really need to check isFinishing() here? That seems like something the caller should deal with.

@hypest hypest Nov 6, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was only adapting the existing code without changing the logic and yeah, that check is awkward. I removed it with 0247fd6, letting the listener decide whether the Activity (if any) needs to be checked for finishing. It seems that almost all listeners are already checking for isAdded so, no new checks are needed.

Is that what you had in mind @nbradbury ?

@hypest

hypest commented Nov 6, 2017

Copy link
Copy Markdown
Contributor Author

I addressed your comments @nbradbury , ready for another pass, thanks!

@nbradbury

Copy link
Copy Markdown
Contributor

Looks good! :shipit:

@nbradbury
nbradbury merged commit 61d9257 into develop Nov 6, 2017
@nbradbury
nbradbury deleted the feature/sitesettingsinterface-context branch November 6, 2017 12:13
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.

2 participants