mirror of
https://github.com/badaix/snapcast.git
synced 2025-08-06 10:09:33 +02:00
fixed "hide offline"
This commit is contained in:
parent
3a02bc3dde
commit
fe8a1cdb6f
3 changed files with 102 additions and 15 deletions
|
@ -5,7 +5,6 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
import android.net.nsd.NsdServiceInfo;
|
||||
|
@ -40,6 +39,7 @@ import de.badaix.snapcast.control.RemoteControl;
|
|||
import de.badaix.snapcast.control.ServerInfo;
|
||||
import de.badaix.snapcast.control.Stream;
|
||||
import de.badaix.snapcast.utils.NsdHelper;
|
||||
import de.badaix.snapcast.utils.Settings;
|
||||
import de.badaix.snapcast.utils.Setup;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements ClientListFragment.OnFragmentInteractionListener, ClientInfoItem.ClientInfoItemListener, RemoteControl.RemoteControlListener, SnapclientService.SnapclientListener, NsdHelper.NsdHelperListener {
|
||||
|
@ -146,6 +146,8 @@ public class MainActivity extends AppCompatActivity implements ClientListFragmen
|
|||
// ATTENTION: This was auto-generated to implement the App Indexing API.
|
||||
// See https://g.co/AppIndexing/AndroidStudio for more information.
|
||||
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
|
||||
|
||||
sectionsPagerAdapter.setHideOffline(Settings.getInstance(this).getBoolean("hide_offline", false));
|
||||
}
|
||||
|
||||
public void checkFirstRun() {
|
||||
|
@ -167,8 +169,7 @@ public class MainActivity extends AppCompatActivity implements ClientListFragmen
|
|||
getMenuInflater().inflate(R.menu.menu_snapcast, menu);
|
||||
miStartStop = menu.findItem(R.id.action_play_stop);
|
||||
updateStartStopMenuItem();
|
||||
SharedPreferences settings = getSharedPreferences("settings", MODE_PRIVATE);
|
||||
boolean isChecked = settings.getBoolean("hide_offline", false);
|
||||
boolean isChecked = Settings.getInstance(this).getBoolean("hide_offline", false);
|
||||
MenuItem menuItem = menu.findItem(R.id.action_hide_offline);
|
||||
menuItem.setChecked(isChecked);
|
||||
sectionsPagerAdapter.setHideOffline(isChecked);
|
||||
|
@ -197,10 +198,7 @@ public class MainActivity extends AppCompatActivity implements ClientListFragmen
|
|||
return true;
|
||||
} else if (id == R.id.action_hide_offline) {
|
||||
item.setChecked(!item.isChecked());
|
||||
SharedPreferences settings = getSharedPreferences("settings", MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putBoolean("hide_offline", item.isChecked());
|
||||
editor.apply();
|
||||
Settings.getInstance(this).put("hide_offline", item.isChecked());
|
||||
sectionsPagerAdapter.setHideOffline(item.isChecked());
|
||||
return true;
|
||||
} else if (id == R.id.action_refresh) {
|
||||
|
@ -368,8 +366,7 @@ public class MainActivity extends AppCompatActivity implements ClientListFragmen
|
|||
});
|
||||
*/
|
||||
wrongSamplerateSnackbar.show();
|
||||
}
|
||||
else if (nativeSampleRate == 0) {
|
||||
} else if (nativeSampleRate == 0) {
|
||||
wrongSamplerateSnackbar = Snackbar.make(findViewById(R.id.myCoordinatorLayout),
|
||||
getString(R.string.unknown_sample_rate), Snackbar.LENGTH_LONG);
|
||||
wrongSamplerateSnackbar.show();
|
||||
|
@ -532,8 +529,8 @@ public class MainActivity extends AppCompatActivity implements ClientListFragmen
|
|||
public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
private Vector<ClientListFragment> fragments = new Vector<>();
|
||||
private ServerInfo serverInfo = new ServerInfo();
|
||||
private int streamCount = 0;
|
||||
private boolean hideOffline = false;
|
||||
|
||||
public SectionsPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
|
@ -543,11 +540,6 @@ public class MainActivity extends AppCompatActivity implements ClientListFragmen
|
|||
MainActivity.this.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (serverInfo == null)
|
||||
SectionsPagerAdapter.this.serverInfo = new ServerInfo();
|
||||
else ;
|
||||
SectionsPagerAdapter.this.serverInfo = serverInfo;
|
||||
|
||||
boolean changed = (serverInfo.getStreams().size() != streamCount);
|
||||
|
||||
while (serverInfo.getStreams().size() > fragments.size())
|
||||
|
@ -563,6 +555,8 @@ public class MainActivity extends AppCompatActivity implements ClientListFragmen
|
|||
notifyDataSetChanged();
|
||||
tabLayout.setTabsFromPagerAdapter(SectionsPagerAdapter.this);
|
||||
}
|
||||
|
||||
setHideOffline(hideOffline);
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -570,6 +564,7 @@ public class MainActivity extends AppCompatActivity implements ClientListFragmen
|
|||
}
|
||||
|
||||
public void setHideOffline(boolean hide) {
|
||||
this.hideOffline = hide;
|
||||
for (ClientListFragment clientListFragment : fragments)
|
||||
clientListFragment.setHideOffline(hide);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ public class NsdHelper {
|
|||
private android.net.nsd.NsdManager.ResolveListener mResolveListener = null;
|
||||
private Context mContext;
|
||||
private NsdHelperListener listener = null;
|
||||
|
||||
private NsdHelper(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
package de.badaix.snapcast.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
/**
|
||||
* Created by johannes on 21.02.16.
|
||||
*/
|
||||
public class Settings {
|
||||
private static Settings instance = null;
|
||||
private Context ctx = null;
|
||||
|
||||
public static Settings getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
instance = new Settings();
|
||||
}
|
||||
if (context != null)
|
||||
instance.ctx = context.getApplicationContext();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public Resources getResources() {
|
||||
return ctx.getResources();
|
||||
}
|
||||
|
||||
public SharedPreferences getPrefs() {
|
||||
return PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
}
|
||||
|
||||
public Settings put(String key, String value) {
|
||||
SharedPreferences.Editor editor = getPrefs().edit();
|
||||
editor.putString(key, value);
|
||||
editor.commit();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings put(String key, boolean value) {
|
||||
SharedPreferences.Editor editor = getPrefs().edit();
|
||||
editor.putBoolean(key, value);
|
||||
editor.commit();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings put(String key, float value) {
|
||||
SharedPreferences.Editor editor = getPrefs().edit();
|
||||
editor.putFloat(key, value);
|
||||
editor.commit();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings put(String key, int value) {
|
||||
SharedPreferences.Editor editor = getPrefs().edit();
|
||||
editor.putInt(key, value);
|
||||
editor.commit();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings put(String key, long value) {
|
||||
SharedPreferences.Editor editor = getPrefs().edit();
|
||||
editor.putLong(key, value);
|
||||
editor.commit();
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getString(String key, String defaultValue) {
|
||||
return getPrefs().getString(key, defaultValue);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String key, boolean defaultValue) {
|
||||
return getPrefs().getBoolean(key, defaultValue);
|
||||
}
|
||||
|
||||
public float getFloat(String key, float defaultValue) {
|
||||
return getPrefs().getFloat(key, defaultValue);
|
||||
}
|
||||
|
||||
public int getInt(String key, int defaultValue) {
|
||||
return getPrefs().getInt(key, defaultValue);
|
||||
}
|
||||
|
||||
public long getLong(String key, long defaultValue) {
|
||||
return getPrefs().getLong(key, defaultValue);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue