Commit 4ea76188 authored by Albert Vaca's avatar Albert Vaca

Use a library to get the human-friendly device name

We had a list of names before, but it was outdated. Using a library gives
us an up-to-date list plus a fallback that fetches the name from the
internet if not in the list.
parent 56598124
......@@ -75,6 +75,7 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.jakewharton:disklrucache:2.0.2' //For caching album art bitmaps
implementation 'com.jaredrummler:android-device-names:1.1.9' //To get a human-friendly device name
implementation 'org.apache.sshd:sshd-core:0.14.0'
implementation 'org.apache.mina:mina-core:2.0.19' //For some reason, makes sshd-core:0.14.0 work without NIO, which isn't available until Android 8+
......
......@@ -100,11 +100,13 @@ public class MainActivity extends AppCompatActivity implements SharedPreferences
mDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerToggle.syncState();
String deviceName = DeviceHelper.getDeviceName(this);
mNavViewDeviceName.setText(deviceName);
preferences = getSharedPreferences("stored_menu_selection", Context.MODE_PRIVATE);
// Note: The preference changed listener should be registered before getting the name, because getting
// it can trigger a background fetch from the internet that will eventually update the preference
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
String deviceName = DeviceHelper.getDeviceName(this);
mNavViewDeviceName.setText(deviceName);
mNavigationView.setNavigationItemSelectedListener(menuItem -> {
mCurrentMenuEntry = menuItem.getItemId();
......@@ -379,7 +381,7 @@ public class MainActivity extends AppCompatActivity implements SharedPreferences
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (DeviceHelper.KEY_DEVICE_NAME_PREFERENCE.equals(key)) {
mNavViewDeviceName.setText(DeviceHelper.getDeviceName(this));
BackgroundService.RunCommand(this, BackgroundService::onNetworkChange);
BackgroundService.RunCommand(this, BackgroundService::onNetworkChange); //Re-send our identity packet
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment