Skip to content

Commit

Permalink
Added ability to specify Squeezelite options.
Browse files Browse the repository at this point in the history
Closes #7
  • Loading branch information
CDrummond committed Feb 28, 2023
1 parent 7219d4a commit 609ba0a
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 13 deletions.
4 changes: 4 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/401.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Improved

• Added ability to specify Squeezelite options.

Fixed

• Catch exceptions when launching PDF viewer.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@

import org.json.JSONObject;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;

import io.github.muddz.styleabletoast.StyleableToast;
Expand Down Expand Up @@ -92,14 +94,36 @@ public void startTermuxSqueezeLite() {
ServerDiscovery.Server current = new ServerDiscovery.Server(sharedPreferences.getString(SettingsActivity.SERVER_PREF_KEY, null));
state = State.INITIAL;
if (current!=null) {
if (runTermuxCommand("/data/data/com.termux/files/usr/bin/squeezelite",
new String[]{
"-M", "SqueezeLiteAndroid",
"-C", "5",
"-s", current.ip,
"-m", getTermuxMac(),
"-n", Settings.Global.getString(context.getContentResolver(), "device_name")
}, false)) {
String opts = sharedPreferences.getString(SettingsActivity.SQUEEZELITE_OPTIONS_KEY,"");
Map<String, String> params = new HashMap<>();
params.put("-M", "SqueezeLiteAndroid");
params.put("-C", "5");
params.put("-s", current.ip);
params.put("-m", getTermuxMac());
params.put("-n", Settings.Global.getString(context.getContentResolver(), "device_name"));
if (null!=opts) {
String[] parts = opts.split(" ");
if (parts.length>1 && parts.length%2 == 0) {
for (int i=0; i<parts.length; i+=2) {
if (parts[i].startsWith("-")) {
if (parts[i].equals("-n")) {
params.put(parts[i], parts[i + 1].replace("_", " "));
} else {
params.put(parts[i], parts[i + 1]);
}
}
}
}
}
String[] args = new String[params.size()*2];
int i=0;
for (Map.Entry<String, String> entry: params.entrySet()) {
args[i]=entry.getKey();
i++;
args[i]=entry.getValue();
i++;
}
if (runTermuxCommand("/data/data/com.termux/files/usr/bin/squeezelite", args, false)) {
state = State.STARTED;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.ActionBar;
Expand Down Expand Up @@ -56,6 +58,7 @@ public class SettingsActivity extends AppCompatActivity {
public static final String PLAYER_START_MENU_ITEM_PREF_KEY = "menu_start_player";
public static final String STOP_APP_ON_QUIT_PREF_KEY = "stop_app_on_quit";
public static final String IS_DARK_PREF_KEY = "is_dark";
public static final String SQUEEZELITE_OPTIONS_KEY = "squeezelite_options";

public static final String TERMUX_PERMISSION = "com.termux.permission.RUN_COMMAND";
public static final int PERMISSION_READ_PHONE_STATE = 1;
Expand Down Expand Up @@ -211,14 +214,17 @@ public boolean onPreferenceClick(Preference arg0) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(R.string.server_address);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
Discovery.Server server = new Discovery.Server(sharedPreferences.getString(SettingsActivity.SERVER_PREF_KEY,null));
Discovery.Server server = new Discovery.Server(sharedPreferences.getString(SERVER_PREF_KEY,null));

int padding = getResources().getDimensionPixelOffset(R.dimen.dlg_padding);
final EditText input = new EditText(getContext());
input.setInputType(InputType.TYPE_CLASS_TEXT);
input.setText(server.address());
input.setPadding(padding, input.getPaddingTop(), padding, input.getPaddingBottom());
builder.setView(input);
LinearLayout layout = new LinearLayout(getContext());
layout.setOrientation(LinearLayout.VERTICAL);
layout.setPadding(padding, padding, padding, padding/2);
layout.addView(input);
builder.setView(layout);

builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
Expand Down Expand Up @@ -264,7 +270,7 @@ public boolean onPreferenceClick(Preference arg0) {

final Preference defaultPlayerButton = getPreferenceManager().findPreference("default_player");
if (defaultPlayerButton != null) {
String defaultPlayer = sharedPreferences.getString(SettingsActivity.DEFAULT_PLAYER_PREF_KEY, null);
String defaultPlayer = sharedPreferences.getString(DEFAULT_PLAYER_PREF_KEY, null);
if (defaultPlayer!=null && !defaultPlayer.isEmpty()) {
defaultPlayerButton.setSummary(defaultPlayer);
}
Expand All @@ -275,7 +281,7 @@ public boolean onPreferenceClick(Preference arg0) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(R.string.default_player);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
String value = sharedPreferences.getString(SettingsActivity.DEFAULT_PLAYER_PREF_KEY,null);
String value = sharedPreferences.getString(DEFAULT_PLAYER_PREF_KEY,null);

int padding = getResources().getDimensionPixelOffset(R.dimen.dlg_padding);
final EditText input = new EditText(getContext());
Expand Down Expand Up @@ -344,6 +350,53 @@ public boolean onPreferenceClick(Preference arg0) {
});
}

final Preference squeezeliteOptionsButton = getPreferenceManager().findPreference(SQUEEZELITE_OPTIONS_KEY);
if (squeezeliteOptionsButton != null) {
squeezeliteOptionsButton.setSummary(sharedPreferences.getString(SQUEEZELITE_OPTIONS_KEY,""));
squeezeliteOptionsButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(R.string.squeezelite_options);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());

int padding = getResources().getDimensionPixelOffset(R.dimen.dlg_padding);
TextView text = new TextView(getContext());
final EditText input = new EditText(getContext());
input.setInputType(InputType.TYPE_CLASS_TEXT);
input.setText(sharedPreferences.getString(SQUEEZELITE_OPTIONS_KEY,null));
text.setText(R.string.squeezelite_options_summary);
LinearLayout layout = new LinearLayout(getContext());
layout.setOrientation(LinearLayout.VERTICAL);
layout.setPadding(padding, padding, padding, padding/2);
layout.addView(text);
layout.addView(input);
builder.setView(layout);

builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String str = input.getText().toString();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(SQUEEZELITE_OPTIONS_KEY, str);
editor.apply();
squeezeliteOptionsButton.setSummary(str);
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});

builder.show();
return true;
}
});
}

updateListSummary(STATUSBAR_PREF_KEY);
updateListSummary(NAVBAR_PREF_KEY);
updateListSummary(ORIENTATION_PREF_KEY);
Expand Down
2 changes: 2 additions & 0 deletions lms-material/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@
<string name="stopping_player">Stopping local player</string>
<string name="no_termux_run_perms">Do not have permission to run Termux commands</string>
<string name="failed_start_activity">Failed to start activity</string>
<string name="squeezelite_options_summary">Extra options to pass to Squeezelite</string>
<string name="squeezelite_options">Squeezelite (via Termux) options</string>
</resources>
5 changes: 5 additions & 0 deletions lms-material/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
android:key="player_app"
android:title="@string/player_app"
app:iconSpaceReserved="false" />
<Preference
app:iconSpaceReserved="false"
app:key="squeezelite_options"
app:summary="@string/squeezelite_options_summary"
app:title="@string/squeezelite_options" />
<SwitchPreference
app:iconSpaceReserved="false"
app:key="auto_start_player"
Expand Down

0 comments on commit 609ba0a

Please sign in to comment.