mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-20 06:11:22 +02:00
Update device settings action bar title depending on current screen
This commit is contained in:
parent
b1ceb96100
commit
a02a6cba14
@ -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()) {
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user