Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a link to Add-ons in the Settings #1656

Merged
merged 3 commits into from
Jan 8, 2025
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 @@ -4,8 +4,10 @@

import androidx.annotation.NonNull;

import com.igalia.wolvic.ui.widgets.Windows;

public interface LibraryNavigationDelegate {
default void onButtonClick(@NonNull View view) {}
default void onButtonClick(Windows.ContentType contentType) {}
default void onClose(@NonNull View view) {}
default void onBack(@NonNull View view) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.content.res.Configuration;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
Expand Down Expand Up @@ -38,6 +39,11 @@ public class LibraryPanel extends FrameLayout {
private SystemNotificationsView mSystemNotificationsView;
private LibraryView mCurrentView;
private Windows.ContentType mCurrentPanel;
private Controller mController;

public interface Controller {
void setPanelContent(Windows.ContentType contentType);
}

public LibraryPanel(@NonNull Context context) {
super(context);
Expand Down Expand Up @@ -113,9 +119,11 @@ public void onBack(@NonNull View view) {
}

@Override
public void onButtonClick(@NonNull View view) {
public void onButtonClick(Windows.ContentType contentType) {
requestFocus();
selectTab(view);
if (mController != null) {
mController.setPanelContent(contentType);
}
}
});
mBinding.executePendingBindings();
Expand Down Expand Up @@ -177,6 +185,10 @@ public void onDestroy() {
mSystemNotificationsView.onDestroy();
}

public void setController(Controller controller) {
mController = controller;
}

public Windows.ContentType getSelectedPanelType() {
if (mCurrentView == mBookmarksView) {
return Windows.ContentType.BOOKMARKS;
Expand All @@ -201,7 +213,13 @@ public Windows.ContentType getSelectedPanelType() {
}
}

private void selectTab(@NonNull View view) {
public void selectPanel(Windows.ContentType panelType) {
mCurrentPanel = panelType;

if (panelType == Windows.ContentType.WEB_CONTENT) {
panelType = getSelectedPanelType();
}

mBinding.tabcontent.removeAllViews();

if (BuildConfig.FLAVOR_backend.equals("chromium")) {
Expand All @@ -214,60 +232,36 @@ private void selectTab(@NonNull View view) {
mBinding.downloads.setActiveMode(false);
mBinding.addons.setActiveMode(false);
mBinding.notifications.setActiveMode(false);
if(view.getId() == R.id.bookmarks){
selectBookmarks();

} else if(view.getId() == R.id.history){
selectHistory();

} else if(view.getId() == R.id.downloads){
selectDownloads();

} else if(view.getId() == R.id.addons){
selectAddons();

} else if (view.getId() == R.id.notifications) {
selectNotifications();

} else if (view.getId() == R.id.web_apps) {
selectWebApps();
}

mBinding.setCanGoBack(mCurrentView.canGoBack());
mCurrentView.onShow();

mBinding.searchBar.setQuery("", false);
mBinding.searchBar.clearFocus();
mBinding.searchBar.setVisibility(mCurrentView.supportsSearch() ? View.VISIBLE : View.INVISIBLE);
}

public void selectPanel(Windows.ContentType panelType) {
mCurrentPanel = panelType;

if (panelType == Windows.ContentType.WEB_CONTENT) {
panelType = getSelectedPanelType();
}
switch (panelType) {
case WEB_CONTENT:
break;
case BOOKMARKS:
selectTab(mBinding.bookmarks);
selectBookmarks();
break;
case WEB_APPS:
selectTab(mBinding.webApps);
selectWebApps();
break;
case HISTORY:
selectTab(mBinding.history);
selectHistory();
break;
case DOWNLOADS:
selectTab(mBinding.downloads);
selectDownloads();
break;
case ADDONS:
selectTab(mBinding.addons);
selectAddons();
break;
case NOTIFICATIONS:
selectTab(mBinding.notifications);
selectNotifications();
break;
}

mBinding.setCanGoBack(mCurrentView.canGoBack());
mCurrentView.onShow();

mBinding.searchBar.setQuery("", false);
mBinding.searchBar.clearFocus();
mBinding.searchBar.setVisibility(mCurrentView.supportsSearch() ? View.VISIBLE : View.INVISIBLE);
}

private void selectBookmarks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ private void animateButtonPadding(UIButton button, int paddingEnd, int duration)
return;
}

if (button.getAnimation() != null) {
button.getAnimation().cancel();
}

int paddingStart = button.getPaddingLeft();
button.animate()
.setDuration(duration)
Expand Down Expand Up @@ -605,6 +609,10 @@ public void attachToWindow(@NonNull WindowWidget aWindow) {
}

private Observer<Windows.ContentType> mCurrentContentTypeObserver = contentType -> {
// Prevent a race condition in case the animation runs faster than the data binding.
mBinding.bookmarksButton.setActiveMode(contentType != Windows.ContentType.WEB_CONTENT && contentType != Windows.ContentType.DOWNLOADS);
mBinding.downloadsButton.setActiveMode(contentType == Windows.ContentType.DOWNLOADS);

if (contentType == Windows.ContentType.WEB_CONTENT) {
animateButtonPadding(mBinding.bookmarksButton, mMaxPadding, ICON_ANIMATION_DURATION);
animateButtonPadding(mBinding.downloadsButton, mMaxPadding, ICON_ANIMATION_DURATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ private void initialize(Context aContext) {
setupListeners(mSession);

mLibrary = new LibraryPanel(aContext);
mLibrary.setController(this::showPanel);

SessionStore.get().getBookmarkStore().addListener(mBookmarksListener);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
import android.text.Html;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
Expand All @@ -42,6 +41,7 @@
import com.igalia.wolvic.ui.widgets.UIWidget;
import com.igalia.wolvic.ui.widgets.WidgetPlacement;
import com.igalia.wolvic.ui.widgets.WindowWidget;
import com.igalia.wolvic.ui.widgets.Windows;
import com.igalia.wolvic.ui.widgets.dialogs.ClearUserDataDialogWidget;
import com.igalia.wolvic.ui.widgets.dialogs.RestartDialogWidget;
import com.igalia.wolvic.ui.widgets.dialogs.UIDialog;
Expand Down Expand Up @@ -74,22 +74,11 @@ public class SettingsWidget extends UIDialog implements SettingsView.Delegate {
private SettingsView.SettingViewType mOpenDialog;
private SettingsViewModel mSettingsViewModel;
private boolean mAreMozillaAccountsDisabled;
private final Pair<String, String> mVersionDetail = new Pair<>(
"versionCode " + BuildConfig.VERSION_CODE,
BuildConfig.GIT_HASH + " (AC " + Build.version + ")");
private boolean mIsFirstVersionDetail;

class VersionGestureListener extends GestureDetector.SimpleOnGestureListener {

private boolean mIsHash;

@Override
public boolean onDown (MotionEvent e) {
mBinding.buildText.setText(mIsHash ?
"versionCode " + BuildConfig.VERSION_CODE :
BuildConfig.GIT_HASH + " (AC " + Build.version + ")");

mIsHash = !mIsHash;

return true;
}
}

public SettingsWidget(Context aContext) {
super(aContext);
Expand Down Expand Up @@ -193,18 +182,19 @@ public void updateUI() {
Html.FROM_HTML_MODE_LEGACY));

} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
Log.e(LOGTAG, "Error when getting package info:" + e.getMessage());
mBinding.versionText.setText(R.string.app_name);
}

mBinding.buildText.setText("versionCode " + BuildConfig.VERSION_CODE);
mIsFirstVersionDetail = false;
mBinding.buildText.setText(mVersionDetail.first);

final GestureDetector gd = new GestureDetector(getContext(), new VersionGestureListener());
mBinding.settingsMasthead.setOnTouchListener((view, motionEvent) -> {
if (gd.onTouchEvent(motionEvent)) {
return true;
}
return view.performClick();
});
OnClickListener updateVersionDetail = v -> {
mIsFirstVersionDetail = !mIsFirstVersionDetail;
mBinding.buildText.setText(mIsFirstVersionDetail ? mVersionDetail.first : mVersionDetail.second);
};
mBinding.ffLogoSettings.setOnClickListener(updateVersionDetail);
mBinding.versionText.setOnClickListener(updateVersionDetail);

if (DeviceType.getStoreType() == DeviceType.StoreType.MAINLAND_CHINA) {
mBinding.chinaLicenseNumber.setOnClickListener(v -> {
Expand All @@ -225,6 +215,14 @@ public void updateUI() {
});
}

mBinding.addonsButton.setOnClickListener(view -> {
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}
mWidgetManager.getFocusedWindow().showPanel(Windows.ContentType.ADDONS);
onDismiss();
});

mBinding.helpButton.setOnClickListener(view -> {
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
Expand Down Expand Up @@ -264,9 +262,13 @@ public void updateUI() {

SettingsStore.getInstance(getContext()).setRemotePropsVersionName(BuildConfig.VERSION_NAME);
RemoteProperties props = mSettingsViewModel.getProps().getValue().get(BuildConfig.VERSION_NAME);
String whatsNewUrl;
if (props != null) {
mWidgetManager.openNewTabForeground(props.getWhatsNewUrl());
whatsNewUrl = props.getWhatsNewUrl();
} else {
whatsNewUrl = getContext().getString(R.string.home_page_url);
}
mWidgetManager.openNewTabForeground(whatsNewUrl);
onDismiss();
});

Expand Down
13 changes: 7 additions & 6 deletions app/src/main/res/layout/library.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="com.igalia.wolvic.ui.widgets.Windows.ContentType"/>
<variable
name="delegate"
type="com.igalia.wolvic.ui.delegates.LibraryNavigationDelegate" />
Expand Down Expand Up @@ -31,32 +32,32 @@
style="@style/libraryButtonStartTheme"
android:src="@drawable/ic_icon_bookmark"
android:id="@+id/bookmarks"
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(view) : void}"/>
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.BOOKMARKS) : void}"/>
<com.igalia.wolvic.ui.views.UIButton
style="@style/libraryButtonMiddleTheme"
android:src="@drawable/ic_icon_webapps"
android:id="@+id/web_apps"
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(view) : void}"/>
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.WEB_APPS) : void}"/>
<com.igalia.wolvic.ui.views.UIButton
style="@style/libraryButtonMiddleTheme"
android:src="@drawable/ic_icon_history"
android:id="@+id/history"
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(view) : void}"/>
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.HISTORY) : void}"/>
<com.igalia.wolvic.ui.views.UIButton
style="@style/libraryButtonMiddleTheme"
android:src="@drawable/ic_icon_downloads"
android:id="@+id/downloads"
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(view) : void}"/>
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.DOWNLOADS) : void}"/>
<com.igalia.wolvic.ui.views.UIButton
style="@style/libraryButtonMiddleTheme"
android:src="@drawable/ic_icon_addons"
android:id="@+id/addons"
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(view) : void}"/>
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.ADDONS) : void}"/>
<com.igalia.wolvic.ui.views.UIButton
style="@style/libraryButtonMiddleTheme"
android:src="@drawable/ic_icon_dialog_notification"
android:id="@+id/notifications"
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(view) : void}"
android:onClick="@{(view) -> delegate != null ? delegate.onButtonClick(ContentType.NOTIFICATIONS) : void}"
visibleGone="@{supportsSystemNotifications}"/>
</LinearLayout>
</FrameLayout>
Expand Down
Loading
Loading