Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyPavlenko committed Jun 2, 2020
1 parent b1bafff commit 95e33f0
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 32 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ext {
VERSION_CODE = 62
VERSION_CODE = 63
VERSION_NAME = "1.7.0"
SDK_MIN_VERSION = 23
SDK_TARGET_VERSION = 29
Expand All @@ -24,7 +24,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.0.0-rc01'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.google.gms:google-services:4.3.3'
}
}
Expand Down
35 changes: 30 additions & 5 deletions fermata/src/main/java/me/aap/fermata/addon/AddonManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.aap.fermata.addon;

import android.app.Activity;

import androidx.annotation.IdRes;
import androidx.annotation.Nullable;

Expand All @@ -10,6 +12,7 @@

import me.aap.fermata.BuildConfig;
import me.aap.fermata.FermataApplication;
import me.aap.fermata.R;
import me.aap.fermata.ui.activity.MainActivity;
import me.aap.utils.app.App;
import me.aap.utils.event.BasicEventBroadcaster;
Expand All @@ -19,6 +22,8 @@
import me.aap.utils.ui.activity.ActivityBase;
import me.aap.utils.ui.fragment.ActivityFragment;

import static java.util.Collections.singletonList;

/**
* @author Andrey Pavlenko
*/
Expand Down Expand Up @@ -50,6 +55,7 @@ public FermataAddon getAddon(String className) {
return addons.get(className);
}

@SuppressWarnings("unchecked")
@Nullable
public <A extends FermataAddon> A getAddon(Class<A> c) {
return (A) addons.get(c.getName());
Expand Down Expand Up @@ -85,8 +91,10 @@ private void install(AddonInfo i, boolean installModule) {
if (!addons.containsKey(i.className)) {
try {
FermataAddon a = (FermataAddon) Class.forName(i.className).newInstance();
PreferenceStore prefs = FermataApplication.get().getPreferenceStore();
addons.put(i.className, a);
fireBroadcastEvent(c -> c.addonChanged(this, i, true));
prefs.fireBroadcastEvent(l -> l.onPreferenceChanged(prefs, singletonList(i.enabledPref)));
return;
} catch (Exception ignore) {
}
Expand All @@ -95,31 +103,48 @@ private void install(AddonInfo i, boolean installModule) {

ActivityBase.create(App.get(), CHANNEL_ID, i.moduleName, i.icon,
i.moduleName, null, MainActivity.class).onSuccess(a -> {
DynamicModuleInstaller inst = new DynamicModuleInstaller(a);
inst.install(i.moduleName).onSuccess(v -> fireBroadcastEvent(c -> {
DynamicModuleInstaller inst = createInstaller(a, i);
inst.install(i.moduleName).onSuccess(v -> {
Log.i("Module installed: ", i.moduleName);
install(i, false);
}));

for (AddonInfo ai : BuildConfig.ADDONS) {
if (i.moduleName.equals(ai.moduleName)) install(ai, false);
}
});
});
}
}

private void uninstall(AddonInfo i) {
if (addons.remove(i.className) != null) {
PreferenceStore prefs = FermataApplication.get().getPreferenceStore();
fireBroadcastEvent(c -> c.addonChanged(this, i, false));
prefs.fireBroadcastEvent(l -> l.onPreferenceChanged(prefs, singletonList(i.enabledPref)));

for (AddonInfo ai : BuildConfig.ADDONS) {
if (ai.moduleName.equals(i.moduleName)) return;
}

ActivityBase.create(App.get(), CHANNEL_ID, i.moduleName, i.icon,
i.moduleName, null, MainActivity.class).onSuccess(a -> {
DynamicModuleInstaller inst = new DynamicModuleInstaller(a);
DynamicModuleInstaller inst = createInstaller(a, i);
inst.uninstall(i.moduleName).onSuccess(v -> Log.i("Module uninstalled: ", i.moduleName));
});
}
}

private static DynamicModuleInstaller createInstaller(Activity a, AddonInfo ai) {
DynamicModuleInstaller i = new DynamicModuleInstaller(a);
String name = a.getString(ai.addonName);
i.setSmallIcon(R.drawable.ic_notification);
i.setTitle(a.getString(R.string.module_installation, name));
i.setNotificationChannel(CHANNEL_ID, a.getString(R.string.installing, name));
i.setPendingMessage(a.getString(R.string.install_pending, name));
i.setDownloadingMessage(a.getString(R.string.downloading, name));
i.setInstallingMessage(a.getString(R.string.installing, name));
return i;
}

public interface Listener {
void addonChanged(AddonManager mgr, AddonInfo info, boolean installed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public boolean isActive() {
@Override
public void setVisibility(int visibility) {
if (visibility == VISIBLE) {
if ((mask & MASK_VIDEO_MODE) != 0) return;
mask |= MASK_VISIBLE;
if ((mask & MASK_VIDEO_MODE) != 0) return;

MainActivityDelegate a = getActivity();
super.setVisibility(VISIBLE);
Expand All @@ -146,8 +146,8 @@ public void setVisibility(int visibility) {
setShowHideBarsIcon(a);
}
} else {
mask &= ~MASK_VISIBLE;
MainActivityDelegate a = getActivity();
mask = 0;
super.setVisibility(GONE);
a.getFloatingButton().setVisibility(VISIBLE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.view.ViewGroup;
import android.webkit.GeolocationPermissions;
import android.webkit.WebChromeClient;
import android.widget.FrameLayout;

import me.aap.fermata.ui.activity.MainActivityDelegate;
import me.aap.utils.app.App;
Expand All @@ -17,7 +18,6 @@

import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_UP;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
Expand Down Expand Up @@ -136,7 +136,12 @@ public FutureSupplier<Void> enterFullScreen() {
}

fullScreenReq = req = new Promise<>();
web.requestFullScreen();

if (!web.requestFullScreen()) {
onShowCustomView(new FrameLayout(web.getContext()), () -> {
});
}

return req;
}

Expand All @@ -156,25 +161,18 @@ public FutureSupplier<Void> exitFullScreen() {
}

protected boolean onTouchEvent(View v, MotionEvent event) {
if (!isFullScreen()) return false;

int action = event.getAction();
if ((action != ACTION_UP) && (action != ACTION_DOWN)) return false;
if (!isFullScreen() || (event.getAction() != ACTION_DOWN)) return false;

MainActivityDelegate a = MainActivityDelegate.get(v.getContext());
FloatingButton fb = a.getFloatingButton();
long st = touchStamp = System.currentTimeMillis();

if (action == ACTION_DOWN) {
fb.setVisibility(GONE);
} else {
fb.setVisibility(VISIBLE);
App.get().getHandler().postDelayed(() -> {
if (st == touchStamp) fb.setVisibility(GONE);
}, 3000);
}
fb.setVisibility(VISIBLE);
App.get().getHandler().postDelayed(() -> {
if (st == touchStamp) fb.setVisibility(GONE);
}, 3000);

return false;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import static androidx.webkit.WebViewFeature.FORCE_DARK;
import static me.aap.fermata.addon.web.FermataJsInterface.JS_EDIT;
import static me.aap.fermata.addon.web.FermataJsInterface.JS_ERR;
import static me.aap.fermata.addon.web.FermataJsInterface.JS_EVENT;

/**
Expand Down Expand Up @@ -102,11 +101,8 @@ protected void pageLoaded(String uri) {
if (m instanceof WebToolBarMediator) ((WebToolBarMediator) m).setAddress(a.getToolBar(), uri);
}

protected void requestFullScreen() {
loadUrl("javascript: var v = document.body;\n" +
"if ('webkitRequestFullscreen' in v) v.webkitRequestFullscreen();\n" +
"else if ('requestFullscreen' in v) v.requestFullscreen();\n" +
"else " + JS_EVENT + "(" + JS_ERR + ", 'Method requestFullscreen() not found in ' + v);");
protected boolean requestFullScreen() {
return false;
}

@SuppressLint("ClickableViewAccessibility")
Expand Down Expand Up @@ -203,4 +199,11 @@ public boolean onEditorAction(TextView v, int actionId, @Nullable KeyEvent event

return false;
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
FermataChromeClient chrome = getWebChromeClient();
if ((chrome != null) && chrome.isFullScreen()) chrome.onTouchEvent(this, ev);
return super.onInterceptTouchEvent(ev);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected void handleEvent(int event, String data) {
break;
case JS_VIDEO_PAUSED:
Log.d("Video paused");
engine.paused();
break;
case JS_VIDEO_ENDED:
Log.d("Video ended");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class YoutubeMediaEngine implements MediaEngine, OverlayMenu.SelectionHandler {
private final YoutubeItem prev;
private final YoutubeItem end;
private YoutubeItem current;
private boolean ignorePause;

public YoutubeMediaEngine(YoutubeWebView web, MainActivityDelegate a) {
this.web = web;
Expand Down Expand Up @@ -72,6 +73,12 @@ void ended() {
cb.onEngineEnded(this);
}

void paused() {
ignorePause = true;
cb.onPause();
ignorePause = false;
}

@Override
public int getId() {
return MEDIA_ENG_YT;
Expand Down Expand Up @@ -102,7 +109,7 @@ public void stop() {

@Override
public void pause() {
web.pause();
if (!ignorePause) web.pause();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ void attachListeners() {
"findVideo();");
}

protected void requestFullScreen() {
protected boolean requestFullScreen() {
loadUrl("javascript: var v = document.querySelector('video');\n" +
"if ('webkitRequestFullscreen' in v) v.webkitRequestFullscreen();\n" +
"else if ('requestFullscreen' in v) v.requestFullscreen();\n" +
"else " + JS_EVENT + "(" + JS_ERR + ", 'Method requestFullscreen not found in ' + v);");
return true;
}

void play() {
Expand Down

0 comments on commit 95e33f0

Please sign in to comment.