Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Addons UI fixes #3843

Merged
merged 5 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;

import org.mozilla.vrbrowser.R;
Expand All @@ -24,38 +23,8 @@ public AddonsOptionsPermissionsViewAdapter() {
}

public void setPermissionsList(final List<String> permissionsList) {
if (mPermissionsList == null) {
mPermissionsList = permissionsList;
notifyItemRangeInserted(0, permissionsList.size());

} else {
DiffUtil.DiffResult result = DiffUtil.calculateDiff(new DiffUtil.Callback() {
@Override
public int getOldListSize() {
return mPermissionsList.size();
}

@Override
public int getNewListSize() {
return permissionsList.size();
}

@Override
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
return mPermissionsList.get(oldItemPosition).equals(permissionsList.get(newItemPosition));
}

@Override
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
String newPermissionItem = permissionsList.get(newItemPosition);
String oldHPermissionItem = mPermissionsList.get(oldItemPosition);
return newPermissionItem.equals(oldHPermissionItem);
}
});

mPermissionsList = permissionsList;
result.dispatchUpdatesTo(this);
}
mPermissionsList = permissionsList;
notifyDataSetChanged();
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ public void bind(Addon addon) {
return null;
}));


mBinding.addonSettings.setEnabled(
addon.getInstalledState() != null &&
addon.getInstalledState().getOptionsPageUrl() != null);
setAddonEnabled(addon, addon.isEnabled());
}

mBinding.executePendingBindings();
Expand All @@ -74,7 +71,8 @@ private void setAddonEnabled(@NonNull Addon addon, boolean isEnabled) {
mBinding.setAddon(addon1);
mBinding.addonPrivateMode.setVisibility(View.VISIBLE);
mBinding.addonSettings.setVisibility(View.VISIBLE);
mBinding.addonSettings.setEnabled(true);
mBinding.addonSettings.setEnabled(addon1.getInstalledState() != null &&
addon1.getInstalledState().getOptionsPageUrl() != null);
return null;

}, throwable -> {
Expand Down Expand Up @@ -111,6 +109,7 @@ public void onRemoveAddonButtonClicked(@NonNull View view, @NonNull Addon addon)
}

private void showRemoveAddonSuccessDialog(@NonNull Addon addon) {
mDelegate.showAddonsList();
PromptData data = new PromptData.Builder()
.withIconRes(R.drawable.ic_icon_addons)
.withTitle(mContext.getString(
Expand All @@ -119,12 +118,12 @@ private void showRemoveAddonSuccessDialog(@NonNull Addon addon) {
.withBtnMsg(new String[]{
mContext.getString(R.string.addons_remove_success_dialog_ok)
})
.withCallback((index, isChecked) -> mDelegate.showAddonsList())
.build();
mWidgetManager.getFocusedWindow().showConfirmPrompt(data);
}

private void showRemoveAddonErrorDialog(@NonNull Addon addon) {
mDelegate.showAddonsList();
PromptData data = new PromptData.Builder()
.withIconRes(R.drawable.ic_icon_addons)
.withTitle(mContext.getString(
Expand All @@ -133,7 +132,6 @@ private void showRemoveAddonErrorDialog(@NonNull Addon addon) {
.withBtnMsg(new String[]{
mContext.getString(R.string.addons_remove_error_dialog_ok)
})
.withCallback((index, isChecked) -> mDelegate.showAddonsList())
.build();
mWidgetManager.getFocusedWindow().showConfirmPrompt(data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public void onDestroy() {
@Override
public void onShow() {
updateLayout();

if (mBinding.pager.getCurrentItem() == AddonsViewAdapter.ADDONS_LEVEL_0) {
if (mRootPanel != null) {
mRootPanel.onViewUpdated(getContext().getString(R.string.addons_title));
}
} else {
if (mRootPanel != null) {
mRootPanel.onViewUpdated(ExtensionsKt.getTranslatedName(mAdapter.getCurrentAddon()));
}
}
}

public boolean onBack() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.mozilla.vrbrowser.ui.callbacks.LibraryContextMenuCallback;
import org.mozilla.vrbrowser.ui.viewmodel.BookmarksViewModel;
import org.mozilla.vrbrowser.ui.widgets.WindowWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.MenuWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.library.BookmarksContextMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.library.LibraryContextMenuWidget;
import org.mozilla.vrbrowser.utils.SystemUtils;
Expand Down Expand Up @@ -143,6 +142,9 @@ public void updateUI() {
public void onShow() {
updateLayout();
mBinding.bookmarksList.smoothScrollToPosition(0);
if (mRootPanel != null) {
mRootPanel.onViewUpdated(getContext().getString(R.string.bookmarks_title));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
import org.mozilla.vrbrowser.ui.widgets.WindowWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.PromptDialogWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.MenuWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.library.DownloadsContextMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.library.LibraryContextMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.library.SortingContextMenuWidget;
Expand Down Expand Up @@ -121,6 +120,9 @@ public void onShow() {
mDownloadsManager.addListener(this);
onDownloadsUpdate(mDownloadsManager.getDownloads());
updateLayout();
if (mRootPanel != null) {
mRootPanel.onViewUpdated(getContext().getString(R.string.downloads_title));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.mozilla.vrbrowser.ui.widgets.UIWidget;
import org.mozilla.vrbrowser.ui.widgets.WindowWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.ClearHistoryDialogWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.MenuWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.library.HistoryContextMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.library.LibraryContextMenuWidget;
import org.mozilla.vrbrowser.utils.SystemUtils;
Expand Down Expand Up @@ -160,6 +159,9 @@ public void onDestroy() {
public void onShow() {
updateLayout();
mBinding.historyList.smoothScrollToPosition(0);
if (mRootPanel != null) {
mRootPanel.onViewUpdated(getContext().getString(R.string.history_title));
}
}

private final HistoryItemCallback mHistoryItemCallback = new HistoryItemCallback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,31 +214,24 @@ private void selectBookmarks() {
mCurrentView = mBookmarksView;
mBinding.bookmarks.setActiveMode(true);
mBinding.tabcontent.addView(mBookmarksView);
mBinding.title.setText(R.string.bookmarks_title);
}

private void selectHistory() {
mCurrentView = mHistoryView;
mBinding.history.setActiveMode(true);
mBinding.tabcontent.addView(mHistoryView);
mBinding.title.setText(R.string.history_title);
}

private void selectDownloads() {
mCurrentView = mDownloadsView;
mBinding.downloads.setActiveMode(true);
mBinding.tabcontent.addView(mDownloadsView);
mBinding.title.setText(R.string.downloads_title);
}

private void selectAddons() {
boolean alreadySelected = mCurrentView == mAddonsView;
mCurrentView = mAddonsView;
mBinding.addons.setActiveMode(true);
mBinding.tabcontent.addView(mAddonsView);
if (!alreadySelected) {
mBinding.title.setText(R.string.addons_title);
}
}

public void onViewUpdated(@NonNull String title) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/addon_options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
android:id="@+id/addon_enabled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:description="@string/addons_details_enabled" />
app:description="@{addon.enabled ? @string/addons_details_enabled : @string/addons_details_disabled}" />
<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
android:id="@+id/addon_private_mode"
android:layout_width="match_parent"
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1137,9 +1137,12 @@
'Close' refers to closing the Addons panel and showing the latest active tab. -->
<string name="addons_close_tooltip">Close Add-Ons</string>

<!-- This string is displayed in the Addon Details enable/disable switch text that determines the global status of the Addon. -->
<!-- This string is displayed in the Addon Details enable/disable switch text that determines the global status of the Addon when the addon is enabled. -->
<string name="addons_details_enabled">Enabled</string>

<!-- This string is displayed in the Addon Details enable/disable switch text that determines the global status of the Addon when the addon is disabled. -->
<string name="addons_details_disabled">Disabled</string>

<!-- This string is displayed in the Addon Details "Run in private browsing" switch text that determines if the Addon will run in private browsing mode. -->
<string name="addons_details_private_mode">Run in private browsing</string>

Expand Down