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

Commit

Permalink
chore: update SoundManagerModule (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly authored Feb 24, 2023
1 parent 6330731 commit 475e2fb
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 83 deletions.
188 changes: 106 additions & 82 deletions app/src/main/java/com/discord/sounds/SoundManagerModule.java
Original file line number Diff line number Diff line change
@@ -1,130 +1,154 @@
package com.discord.sounds;

import com.discord.BuildConfig;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import android.content.Context;
import android.webkit.URLUtil;
import com.discord.BuildConfig;
import com.discord.logging.Log;
import com.discord.sounds.utils.SoundExtensionsKt;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import java.io.File;
import kotlin.Metadata;
import kotlin.jvm.internal.q;

public final class SoundManagerModule extends ReactContextBaseJavaModule {
private final SoundManager soundManager;

public SoundManagerModule(ReactApplicationContext reactApplicationContext0) {
super(reactApplicationContext0);
if(reactApplicationContext0 == null)
throw new NullPointerException("reactApplicationContext must not be null");
this.soundManager = new SoundManager(reactApplicationContext0);
public SoundManagerModule(ReactApplicationContext reactContext) {
super(reactContext);
q.g(reactContext, "reactContext");
this.soundManager = new SoundManager(reactContext);
}

@Override // com.facebook.react.bridge.NativeModule
private final int resolveRawResId(Context context, String str, String str2) {
// ALIUCORD CHANGED: dynamic package name lookup -> BuildConfig.APPLICATION_ID
int identifier = context.getResources().getIdentifier(str, str2, BuildConfig.APPLICATION_ID);
if (identifier > 0) {
return identifier;
}
throw new IllegalArgumentException("Trying to resolve unknown sound " + str);
}

static /* synthetic */ int resolveRawResId$default(SoundManagerModule soundManagerModule, Context context, String str, String str2, int i10, Object obj) {
if ((i10 & 2) != 0) {
str2 = "raw";
}
return soundManagerModule.resolveRawResId(context, str, str2);
}

@Override // com.facebook.react.bridge.NativeModule
public String getName() {
return "DCDSoundManager";
}

@ReactMethod
public final void pause(int v) {
Log.i$default(Log.INSTANCE, "SoundManager", "Pause " + v, null, 4, null);
this.soundManager.pause(v);
public final void pause(int i10) {
Log log = Log.INSTANCE;
String logTag = SoundManager.Companion.getLogTag();
Log.i$default(log, logTag, "Pause " + i10, (Throwable) null, 4, (Object) null);
this.soundManager.pause(i10);
}

@ReactMethod
public final void play(int v) {
Log.i$default(Log.INSTANCE, "SoundManager", "Play " + v, null, 4, null);
this.soundManager.play(v);
public final void play(int i10) {
Log log = Log.INSTANCE;
String logTag = SoundManager.Companion.getLogTag();
Log.i$default(log, logTag, "Play " + i10, (Throwable) null, 4, (Object) null);
this.soundManager.play(i10);
}

@ReactMethod
public final void prepare(String s, String s1, int v, Callback callback0) {
if(s == null)
throw new NullPointerException("s must not be null");
if(callback0 == null)
throw new NullPointerException("callback0 must not be null");

Log.i$default(Log.INSTANCE, "SoundManager", "Prepare " + s + " with " + v + ".", null, 4, null);
int v1 = 5;
if(s1 != null) {
int hashCode = s1.hashCode();
if(hashCode != 0x6B2E132) {
switch(hashCode) {
case 0x11F69621: {
if(s1.equals("ring_tone")) {
v1 = 6;
}

break;
}
case 595233003: {
s1.equals("notification");
public final void prepare(String fileName, String str, int i10, Callback callback) {
Integer valueOf;
String str2;
q.g(fileName, "fileName");
q.g(callback, "callback");
Log.i$default(Log.INSTANCE, SoundManager.Companion.getLogTag(), "Prepare " + fileName + " with " + i10 + ".", (Throwable) null, 4, (Object) null);
int i11 = 5;
if (str != null) {
int hashCode = str.hashCode();
if (hashCode != 112386354) {
if (hashCode != 301372961) {
if (hashCode == 595233003) {
str.equals("notification");
}
} else if (str.equals("ring_tone")) {
i11 = 6;
}
} else if (str.equals("voice")) {
i11 = 2;
}
else if(s1.equals("voice")) {
v1 = 2;
}
if (URLUtil.isValidUrl(fileName)) {
String remoteSoundFilename = SoundExtensionsKt.getRemoteSoundFilename(fileName);
ReactApplicationContext reactApplicationContext = getReactApplicationContext();
q.f(reactApplicationContext, "reactApplicationContext");
File file = new File(SoundExtensionsKt.getSoundsCacheDirectory(reactApplicationContext), remoteSoundFilename);
if (!file.exists()) {
ReactApplicationContext reactApplicationContext2 = getReactApplicationContext();
q.f(reactApplicationContext2, "reactApplicationContext");
SoundExtensionsKt.fetchSound(reactApplicationContext2, fileName, this.soundManager, i10, i11, new SoundManagerModule$prepare$1(callback));
return;
}
file.setLastModified(System.currentTimeMillis());
str2 = file.getAbsolutePath();
valueOf = null;
} else {
ReactApplicationContext reactApplicationContext3 = getReactApplicationContext();
q.f(reactApplicationContext3, "reactApplicationContext");
valueOf = Integer.valueOf(resolveRawResId$default(this, reactApplicationContext3, fileName, null, 2, null));
str2 = null;
}

ReactApplicationContext reactApplicationContext0 = this.getReactApplicationContext();
if(reactApplicationContext0 == null)
throw new NullPointerException("reactApplicationContext must not be null");

int v3 = SoundManagerModule.resolveRawResId$default(this, reactApplicationContext0, s, null, 2, null);
com.discord.sounds.SoundManagerModule$prepare$1 soundManagerModule$prepare$10 = new com.discord.sounds.SoundManagerModule$prepare$1(callback0);
this.soundManager.prepare(v, v1, v3, soundManagerModule$prepare$10);
this.soundManager.prepare(i10, i11, valueOf, str2, new SoundManagerModule$prepare$2(callback));
}

@ReactMethod
public final void release(int v) {
Log.i$default(Log.INSTANCE, "SoundManager", "Release " + v, null, 4, null);
this.soundManager.release(v);
}

private final int resolveRawResId(Context context0, String s, String s1) {
// ALIUCORD CHANGED: dynamic package name lookup -> BuildConfig.APPLICATION_ID
int v = context0.getResources().getIdentifier(s, s1, BuildConfig.APPLICATION_ID);
if(v > 0) {
return v;
}

throw new IllegalArgumentException("Trying to resolve unknown sound " + s);
}

static int resolveRawResId$default(SoundManagerModule soundManagerModule0, Context context0, String s, String s1, int v, Object object0) {
if((v & 2) != 0) {
s1 = "raw";
}

return soundManagerModule0.resolveRawResId(context0, s, s1);
public final void release(int i10) {
Log log = Log.INSTANCE;
String logTag = SoundManager.Companion.getLogTag();
Log.i$default(log, logTag, "Release " + i10, (Throwable) null, 4, (Object) null);
this.soundManager.release(i10);
}

@ReactMethod
public final void setCurrentTime(int v, int v1) {
Log.i$default(Log.INSTANCE, "SoundManager", "Set current time for " + v + " with value " + v1, null, 4, null);
this.soundManager.setCurrentTime(v, v1);
public final void setCurrentTime(int i10, int i11) {
Log log = Log.INSTANCE;
String logTag = SoundManager.Companion.getLogTag();
Log.i$default(log, logTag, "Set current time for " + i10 + " with value " + i11, (Throwable) null, 4, (Object) null);
this.soundManager.setCurrentTime(i10, i11);
}

@ReactMethod
public final void setNumberOfLoops(int v, int v1) {
Log.i$default(Log.INSTANCE, "SoundManager", "Set number of loops for " + v + " with value " + v1, null, 4, null);
this.soundManager.setNumberOfLoops(v, v1);
public final void setNumberOfLoops(int i10, int i11) {
Log log = Log.INSTANCE;
String logTag = SoundManager.Companion.getLogTag();
Log.i$default(log, logTag, "Set number of loops for " + i10 + " with value " + i11, (Throwable) null, 4, (Object) null);
this.soundManager.setNumberOfLoops(i10, i11);
}

@ReactMethod
public final void setPan(int v, int v1) {
Log.i$default(Log.INSTANCE, "SoundManager", "Set pan for " + v + " with value " + v1, null, 4, null);
this.soundManager.setPan(v, ((float)v1));
public final void setPan(int i10, int i11) {
Log log = Log.INSTANCE;
String logTag = SoundManager.Companion.getLogTag();
Log.i$default(log, logTag, "Set pan for " + i10 + " with value " + i11, (Throwable) null, 4, (Object) null);
this.soundManager.setPan(i10, (float) i11);
}

@ReactMethod
public final void setVolume(int v, float f) {
Log.i$default(Log.INSTANCE, "SoundManager", "Set volume for " + v + " with value " + f, null, 4, null);
this.soundManager.setVolume(v, f);
public final void setVolume(int i10, float f10) {
Log log = Log.INSTANCE;
String logTag = SoundManager.Companion.getLogTag();
Log.i$default(log, logTag, "Set volume for " + i10 + " with value " + f10, (Throwable) null, 4, (Object) null);
this.soundManager.setVolume(i10, f10);
}

@ReactMethod
public final void stop(int v) {
Log.i$default(Log.INSTANCE, "SoundManager", "Stop " + v, null, 4, null);
this.soundManager.stop(v);
public final void stop(int i10) {
Log log = Log.INSTANCE;
String logTag = SoundManager.Companion.getLogTag();
Log.i$default(log, logTag, "Stop " + i10, (Throwable) null, 4, (Object) null);
this.soundManager.stop(i10);
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

discord_version=164203
discord_version=168206

0 comments on commit 475e2fb

Please sign in to comment.