Skip to content

Commit

Permalink
misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliskov committed Oct 25, 2020
1 parent 2019c54 commit 3725237
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void createAndShowDialog(List<Account> accounts) {

createSelectAccountSection(accounts, settingsPresenter);
createRemoveAccountSection(accounts, settingsPresenter);
createAddAccountSection(settingsPresenter);
createAddAccountButton(settingsPresenter);

settingsPresenter.showDialog(mContext.getString(R.string.settings_accounts), () -> {
for (Account account : mPendingRemove) {
Expand All @@ -86,7 +86,7 @@ private void createSelectAccountSection(List<Account> accounts, AppSettingsPrese
}

optionItems.add(UiOptionItem.from(
account.getName(), option -> mSelectedAccount = account, account.isSelected()
formatAccount(account), option -> mSelectedAccount = account, account.isSelected()
));
}

Expand All @@ -98,7 +98,7 @@ private void createRemoveAccountSection(List<Account> accounts, AppSettingsPrese

for (Account account : accounts) {
optionItems.add(UiOptionItem.from(
account.getName(), option -> {
formatAccount(account), option -> {
if (option.isSelected()) {
mPendingRemove.add(account);
} else {
Expand All @@ -111,8 +111,20 @@ private void createRemoveAccountSection(List<Account> accounts, AppSettingsPrese
settingsPresenter.appendCheckedCategory(mContext.getString(R.string.dialog_remove_account), optionItems);
}

private void createAddAccountSection(AppSettingsPresenter settingsPresenter) {
private void createAddAccountButton(AppSettingsPresenter settingsPresenter) {
settingsPresenter.appendSingleButton(UiOptionItem.from(
mContext.getString(R.string.dialog_add_account), option -> SignInPresenter.instance(mContext).start()));
}

private String formatAccount(Account account) {
String format;

if (account.getEmail() != null) {
format = String.format("%s (%s)", account.getName(), account.getEmail());
} else {
format = account.getName();
}

return format;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,27 +314,22 @@ private void updateVideoRows(Category category, Observable<List<MediaGroup>> gro
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
mediaGroups -> updateVideoRows(category, mediaGroups)
mediaGroups -> {
updateView(category, mediaGroups);
updateRefreshTime();

// Hide loading as long as first group received
if (!mediaGroups.isEmpty()) {
mView.showProgressBar(false);
}
}
, error -> Log.e(TAG, "updateRowsHeader error: " + error)
, () -> {
mView.showProgressBar(false);
mView.updateErrorIfEmpty(new CategoryEmptyError(mContext));
});
}

private void updateVideoRows(Category category, List<MediaGroup> mediaGroups) {
for (MediaGroup mediaGroup : mediaGroups) {
if (mediaGroup.getMediaItems() == null) {
Log.e(TAG, "loadRowsHeader: MediaGroup is empty. Group Name: " + mediaGroup.getTitle());
continue;
}

mView.updateCategory(VideoGroup.from(mediaGroup, category));

updateRefreshTime();
}
}

private void updateVideoGrid(Category category, Observable<MediaGroup> group) {
Log.d(TAG, "updateGridHeader: Start loading category: " + category.getTitle());

Expand All @@ -345,11 +340,27 @@ private void updateVideoGrid(Category category, Observable<MediaGroup> group) {
mediaGroup -> {
mView.updateCategory(VideoGroup.from(mediaGroup, category));
updateRefreshTime();

// Hide loading as long as first group received
if (mediaGroup.getMediaItems() != null) {
mView.showProgressBar(false);
}
}
, error -> Log.e(TAG, "updateGridHeader error: " + error)
, () -> {
mView.showProgressBar(false);
mView.updateErrorIfEmpty(new CategoryEmptyError(mContext));
});
}

private void updateView(Category category, List<MediaGroup> mediaGroups) {
for (MediaGroup mediaGroup : mediaGroups) {
if (mediaGroup.getMediaItems() == null) {
Log.e(TAG, "loadRowsHeader: MediaGroup is empty. Group Name: " + mediaGroup.getTitle());
continue;
}

mView.updateCategory(VideoGroup.from(mediaGroup, category));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ public void setPosition(int position) {
mPosition = position;
}

public static void setup(androidx.leanback.app.ProgressBarManager manager) {
ViewGroup rootView = (ViewGroup) Helpers.getField(manager, "rootView");

public static void setup(androidx.leanback.app.ProgressBarManager manager, ViewGroup rootView) {
if (rootView != null) {
manager.setProgressBarView(createProgressBar(rootView, Gravity.CENTER));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
View view = super.onCreateView(inflater, container, savedInstanceState);

// ProgressBar.setRootView is called in this moment
ProgressBarManager.setup(getProgressBarManager());
ProgressBarManager.setup(getProgressBarManager(), (ViewGroup) view);

return view;
}
Expand Down

0 comments on commit 3725237

Please sign in to comment.