Permalink
Browse files

Audio now muted by default (#647)

  • Loading branch information...
QuantumBadger committed Feb 2, 2019
1 parent a84877f commit 5b41540934ac9a2e80881bab708a4542352104fe
@@ -1,4 +1,5 @@
87/1.9.10
Audio now muted by default
Added preference to move toolbar to bottom of screen (thanks to Cameron Merkel)
Added aspect ratio indicator while loading images (off by default) (thanks to Cameron Merkel)
Avoid line-breaks in gilding badge (thanks to Marco Costa)
@@ -18,8 +18,8 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.quantumbadger.redreader"
android:versionCode="86"
android:versionName="1.9.9.1"
android:versionCode="87"
android:versionName="1.9.10"
android:installLocation="auto">

<uses-feature android:glEsVersion="0x00020000" android:required="true" />
@@ -25,6 +25,7 @@
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.util.TypedValue;
@@ -295,21 +296,7 @@ public void onNotAnImage() {
mFloatingToolbar = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.floating_toolbar, outerFrame, false);
outerFrame.addView(mFloatingToolbar);

final ImageButton ib = (ImageButton) LayoutInflater.from(this).inflate(R.layout.flat_image_button, mFloatingToolbar, false);
final int buttonPadding = General.dpToPixels(this, 10);
ib.setPadding(buttonPadding, buttonPadding, buttonPadding, buttonPadding);
ib.setImageResource(R.drawable.ic_action_info_dark);

if (mFloatingToolbar != null) {
mFloatingToolbar.addView(ib);
}

ib.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
ImageInfoDialog.newInstance(mImageInfo).show(ImageViewActivity.this.getSupportFragmentManager(), null);
}
});
mFloatingToolbar.setVisibility(View.GONE);
}

if(post != null) {
@@ -387,26 +374,25 @@ private void onImageLoaded(
return;
}

final boolean floatingToolbarShown;

if(mImageInfo != null
&& ((mImageInfo.title != null && mImageInfo.title.length() > 0)
|| (mImageInfo.caption != null && mImageInfo.caption.length() > 0))) {

floatingToolbarShown = true;

// TODO preference
AndroidCommon.UI_THREAD_HANDLER.post(new Runnable() {
@Override
public void run() {
if(mFloatingToolbar != null) {
mFloatingToolbar.setVisibility(View.VISIBLE);
}

addFloatingToolbarButton(
R.drawable.ic_action_info_dark,
new View.OnClickListener() {

@Override
public void onClick(final View view) {
ImageInfoDialog.newInstance(mImageInfo).show(ImageViewActivity.this.getSupportFragmentManager(), null);
}
});
}
});

} else {
floatingToolbarShown = false;
}

if(Constants.Mime.isVideo(mimetype)) {
@@ -430,29 +416,24 @@ public void run() {

} else if(videoViewMode == PrefsUtility.VideoViewMode.EXTERNAL_APP_VLC) {

AndroidCommon.UI_THREAD_HANDLER.post(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(
"org.videolan.vlc",
"org.videolan.vlc.gui.video.VideoPlayerActivity");
try {
intent.setDataAndType(cacheFile.getUri(), mimetype);
} catch(IOException e) {
revertToWeb();
return;
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(
"org.videolan.vlc",
"org.videolan.vlc.gui.video.VideoPlayerActivity");
try {
intent.setDataAndType(cacheFile.getUri(), mimetype);
} catch(IOException e) {
revertToWeb();
return;
}

try {
startActivity(intent);
} catch(final Throwable t) {
General.quickToast(ImageViewActivity.this, R.string.videoview_mode_app_vlc_launch_failed);
Log.e(TAG, "VLC failed to launch", t);
}
finish();
}
});
try {
startActivity(intent);
} catch(final Throwable t) {
General.quickToast(ImageViewActivity.this, R.string.videoview_mode_app_vlc_launch_failed);
Log.e(TAG, "VLC failed to launch", t);
}
finish();

} else {

@@ -493,7 +474,7 @@ public void onError() {
revertToWeb();
}
},
floatingToolbarShown ? 84 : 0);
128);

layout.addView(mVideoPlayerWrapper);
setMainView(layout);
@@ -508,6 +489,38 @@ public void onError() {
mVideoPlayerWrapper.setOnTouchListener(gestureHandler);
layout.setOnTouchListener(gestureHandler);

final boolean muteByDefault = PrefsUtility.pref_behaviour_video_mute_default(
ImageViewActivity.this,
PreferenceManager.getDefaultSharedPreferences(ImageViewActivity.this));

mVideoPlayerWrapper.setMuted(muteByDefault);

final int iconMuted = R.drawable.ic_volume_off_white_24dp;
final int iconUnmuted = R.drawable.ic_volume_up_white_24dp;

if(mImageInfo != null
&& mImageInfo.hasAudio != ImageInfo.HasAudio.NO_AUDIO) {

final AtomicReference<ImageButton> muteButton = new AtomicReference<>();
muteButton.set(addFloatingToolbarButton(
muteByDefault ? iconMuted : iconUnmuted,
new View.OnClickListener() {

@Override
public void onClick(final View view) {
final ImageButton button = muteButton.get();

if(mVideoPlayerWrapper.isMuted()) {
mVideoPlayerWrapper.setMuted(false);
button.setImageResource(iconUnmuted);
} else {
mVideoPlayerWrapper.setMuted(true);
button.setImageResource(iconMuted);
}
}
}));
}

} catch(OutOfMemoryError e) {
General.quickToast(ImageViewActivity.this, R.string.imageview_oom);
revertToWeb();
@@ -1126,6 +1139,33 @@ protected void onSuccess(
});
}
}

@Nullable
private ImageButton addFloatingToolbarButton(
final int drawable,
@NonNull final View.OnClickListener listener) {

if(mFloatingToolbar == null) {
return null;
}

mFloatingToolbar.setVisibility(View.VISIBLE);

final ImageButton ib = (ImageButton) LayoutInflater.from(this).inflate(
R.layout.flat_image_button,
mFloatingToolbar,
false);

final int buttonPadding = General.dpToPixels(this, 10);
ib.setPadding(buttonPadding, buttonPadding, buttonPadding, buttonPadding);
ib.setImageResource(drawable);

ib.setOnClickListener(listener);

mFloatingToolbar.addView(ib);

return ib;
}
}


@@ -587,7 +587,7 @@ public void onFailure(final @CacheRequest.RequestFailureType int type, final Thr
Log.i("getImgurImageInfo", "All API requests failed!");

if(returnUrlOnFailure) {
listener.onSuccess(new ImageInfo("https://i.imgur.com/" + imgId + ".jpg", null));
listener.onSuccess(new ImageInfo("https://i.imgur.com/" + imgId + ".jpg", null, ImageInfo.HasAudio.MAYBE_AUDIO));

} else {
listener.onFailure(type, t, status, readableMessage);
@@ -738,7 +738,7 @@ private static ImageInfo getImageUrlPatternMatch(final String url) {
if(matchRedditUploads.find()) {
final String imgId = matchRedditUploads.group(1);
if(imgId.length() > 10) {
return new ImageInfo(url, ImageInfo.MediaType.IMAGE);
return new ImageInfo(url, ImageInfo.MediaType.IMAGE, ImageInfo.HasAudio.NO_AUDIO);
}
}
}
@@ -750,7 +750,7 @@ private static ImageInfo getImageUrlPatternMatch(final String url) {
final String imgId = matchImgflip.group(1);
if(imgId.length() > 3) {
final String imageUrl = "https://i.imgflip.com/" + imgId + ".jpg";
return new ImageInfo(imageUrl, ImageInfo.MediaType.IMAGE);
return new ImageInfo(imageUrl, ImageInfo.MediaType.IMAGE, ImageInfo.HasAudio.NO_AUDIO);
}
}
}
@@ -762,7 +762,7 @@ private static ImageInfo getImageUrlPatternMatch(final String url) {
final String imgId = matchMakeameme.group(1);
if(imgId.length() > 3) {
final String imageUrl = "https://media.makeameme.org/created/" + imgId + ".jpg";
return new ImageInfo(imageUrl, ImageInfo.MediaType.IMAGE);
return new ImageInfo(imageUrl, ImageInfo.MediaType.IMAGE, ImageInfo.HasAudio.NO_AUDIO);
}
}
}
@@ -774,18 +774,18 @@ private static ImageInfo getImageUrlPatternMatch(final String url) {

for(final String ext: imageExtensions) {
if(urlLower.endsWith(ext)) {
return new ImageInfo(url, ImageInfo.MediaType.IMAGE);
return new ImageInfo(url, ImageInfo.MediaType.IMAGE, ImageInfo.HasAudio.MAYBE_AUDIO);
}
}

for(final String ext: videoExtensions) {
if(urlLower.endsWith(ext)) {
return new ImageInfo(url, ImageInfo.MediaType.VIDEO);
return new ImageInfo(url, ImageInfo.MediaType.VIDEO, ImageInfo.HasAudio.MAYBE_AUDIO);
}
}

if(urlLower.endsWith(".gif")) {
return new ImageInfo(url, ImageInfo.MediaType.GIF);
return new ImageInfo(url, ImageInfo.MediaType.GIF, ImageInfo.HasAudio.MAYBE_AUDIO);
}


@@ -795,18 +795,18 @@ private static ImageInfo getImageUrlPatternMatch(final String url) {

for(final String ext: imageExtensions) {
if(urlBeforeQ.endsWith(ext)) {
return new ImageInfo(url, ImageInfo.MediaType.IMAGE);
return new ImageInfo(url, ImageInfo.MediaType.IMAGE, ImageInfo.HasAudio.MAYBE_AUDIO);
}
}

for(final String ext: videoExtensions) {
if(urlBeforeQ.endsWith(ext)) {
return new ImageInfo(url, ImageInfo.MediaType.VIDEO);
return new ImageInfo(url, ImageInfo.MediaType.VIDEO, ImageInfo.HasAudio.MAYBE_AUDIO);
}
}

if(urlBeforeQ.endsWith(".gif")) {
return new ImageInfo(url, ImageInfo.MediaType.GIF);
return new ImageInfo(url, ImageInfo.MediaType.GIF, ImageInfo.HasAudio.MAYBE_AUDIO);
}
}

@@ -815,7 +815,7 @@ private static ImageInfo getImageUrlPatternMatch(final String url) {
if(matchQkme1.find()) {
final String imgId = matchQkme1.group(1);
if(imgId.length() > 2) {
return new ImageInfo(String.format(Locale.US, "http://i.qkme.me/%s.jpg", imgId), ImageInfo.MediaType.IMAGE);
return new ImageInfo(String.format(Locale.US, "http://i.qkme.me/%s.jpg", imgId), ImageInfo.MediaType.IMAGE, ImageInfo.HasAudio.NO_AUDIO);
}
}

@@ -824,7 +824,7 @@ private static ImageInfo getImageUrlPatternMatch(final String url) {
if(matchQkme2.find()) {
final String imgId = matchQkme2.group(1);
if (imgId.length() > 2) {
return new ImageInfo(String.format(Locale.US, "http://i.qkme.me/%s.jpg", imgId), ImageInfo.MediaType.IMAGE);
return new ImageInfo(String.format(Locale.US, "http://i.qkme.me/%s.jpg", imgId), ImageInfo.MediaType.IMAGE, ImageInfo.HasAudio.NO_AUDIO);
}
}

@@ -833,7 +833,7 @@ private static ImageInfo getImageUrlPatternMatch(final String url) {
if(matchLvme.find()) {
final String imgId = matchLvme.group(1);
if (imgId.length() > 2) {
return new ImageInfo(String.format(Locale.US, "http://www.livememe.com/%s.jpg", imgId), ImageInfo.MediaType.IMAGE);
return new ImageInfo(String.format(Locale.US, "http://www.livememe.com/%s.jpg", imgId), ImageInfo.MediaType.IMAGE, ImageInfo.HasAudio.NO_AUDIO);
}
}

@@ -18,6 +18,8 @@
package org.quantumbadger.redreader.common;

import android.os.Parcel;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.quantumbadger.redreader.image.ImageInfo;

public class ParcelHelper {
@@ -34,15 +36,20 @@ public static String readNullableString(final Parcel in) {
return in.readString();
}

public static ImageInfo.MediaType readNullableEnum(final Parcel in) {
@Nullable
public static ImageInfo.MediaType readNullableImageInfoMediaType(final Parcel in) {

final boolean isNull = readBoolean(in);
if(isNull) return null;

return ImageInfo.MediaType.valueOf(in.readString());
}

public static void writeNullableEnum(final Parcel parcel, final ImageInfo.MediaType value) {
public static ImageInfo.HasAudio readImageInfoHasAudio(final Parcel in) {
return ImageInfo.HasAudio.valueOf(in.readString());
}

public static void writeNullableEnum(final Parcel parcel, @Nullable final Enum value) {

if(value == null) {
writeBoolean(parcel, false);
@@ -52,6 +59,10 @@ public static void writeNullableEnum(final Parcel parcel, final ImageInfo.MediaT
}
}

public static void writeNonNullEnum(final Parcel parcel, @NonNull final Enum value) {
parcel.writeString(value.name());
}

public static Integer readNullableInt(final Parcel in) {

final boolean isNull = readBoolean(in);
@@ -367,6 +367,10 @@ public static boolean pref_behaviour_video_playback_controls(final Context conte
return getBoolean(R.string.pref_behaviour_video_playback_controls_key, false, context, sharedPreferences);
}

public static boolean pref_behaviour_video_mute_default(final Context context, final SharedPreferences sharedPreferences) {
return getBoolean(R.string.pref_behaviour_video_mute_default_key, true, context, sharedPreferences);
}

public static int pref_behaviour_bezel_toolbar_swipezone_dp(final Context context, final SharedPreferences sharedPreferences) {
try {
return Integer.parseInt(getString(R.string.pref_behaviour_bezel_toolbar_swipezone_key, "10", context, sharedPreferences));
Oops, something went wrong.

0 comments on commit 5b41540

Please sign in to comment.