1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 13:26:50 +01:00

Update device settings action bar title depending on current screen

This commit is contained in:
José Rebelo 2023-07-23 22:27:11 +01:00
parent b1ceb96100
commit a02a6cba14
2 changed files with 29 additions and 0 deletions

View File

@ -19,6 +19,7 @@ package nodomain.freeyourgadget.gadgetbridge.activities.devicesettings;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
import androidx.appcompat.app.ActionBar;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@ -77,9 +78,17 @@ public class DeviceSettingsActivity extends AbstractGBActivity implements
.replace(R.id.settings_container, fragment, preferenceScreen.getKey()) .replace(R.id.settings_container, fragment, preferenceScreen.getKey())
.addToBackStack(preferenceScreen.getKey()) .addToBackStack(preferenceScreen.getKey())
.commit(); .commit();
return true; return true;
} }
public void setActionBarTitle(final CharSequence title) {
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(title);
}
}
@Override @Override
public boolean onOptionsItemSelected(final MenuItem item) { public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {

View File

@ -39,6 +39,7 @@ import com.mobeta.android.dslv.DragSortListPreference;
import com.mobeta.android.dslv.DragSortListPreferenceFragment; import com.mobeta.android.dslv.DragSortListPreferenceFragment;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -199,6 +200,25 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
super.onStop(); super.onStop();
} }
@Override
public void onResume() {
super.onResume();
updateActionBarTitle();
}
private void updateActionBarTitle() {
try {
CharSequence title = getPreferenceScreen().getTitle();
if (StringUtils.isBlank(title)) {
title = getString(R.string.title_activity_device_specific_settings);
}
((DeviceSettingsActivity) requireActivity()).setActionBarTitle(title);
} catch (final Exception e) {
LOG.error("Failed to update action bar title", e);
}
}
/* /*
* delayed execution so that the preferences are applied first * delayed execution so that the preferences are applied first
*/ */