diff options
author | cyBerta <cyberta@riseup.net> | 2021-11-25 15:10:19 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2021-11-25 15:10:19 +0100 |
commit | 57ce0635f310d1a4cd4e81b01455d8a70978003b (patch) | |
tree | 7a6aeed942bbccaa6cf041b0764ea13e44093ed3 /app/src/main/java/se | |
parent | ffefc40b06b41b6612a95eb4d604674ce9e70742 (diff) |
ensure that action bar subtitle remains after orientation changes for all fragments
Diffstat (limited to 'app/src/main/java/se')
7 files changed, 32 insertions, 36 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/AboutFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/AboutFragment.java index dbdd008a..646637b9 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/AboutFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/AboutFragment.java @@ -17,6 +17,8 @@ import se.leap.bitmaskclient.BuildConfig; import se.leap.bitmaskclient.R; import static android.view.View.VISIBLE; +import static se.leap.bitmaskclient.R.string.about_fragment_title; +import static se.leap.bitmaskclient.base.utils.ViewHelper.setActionBarTitle; public class AboutFragment extends Fragment { @@ -34,6 +36,7 @@ public class AboutFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.f_about, container, false); unbinder = ButterKnife.bind(this, view); + setActionBarTitle(this, about_fragment_title); return view; } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/ExcludeAppsFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/ExcludeAppsFragment.java index f5d7f286..1574dbb0 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/ExcludeAppsFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/ExcludeAppsFragment.java @@ -26,9 +26,6 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.SearchView; -import androidx.annotation.StringRes; -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.AppCompatTextView; import androidx.fragment.app.Fragment; @@ -41,6 +38,7 @@ import java.util.Vector; import de.blinkt.openvpn.VpnProfile; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.utils.PreferenceHelper; +import se.leap.bitmaskclient.base.utils.ViewHelper; import se.leap.bitmaskclient.base.views.SimpleCheckBox; import static se.leap.bitmaskclient.R.string.exclude_apps_fragment_title; @@ -314,18 +312,11 @@ public class ExcludeAppsFragment extends Fragment implements AdapterView.OnItemC mListView.setOnItemClickListener(this); mListView.setEmptyView(v.findViewById(R.id.loading_container)); - setActionBarTitle(exclude_apps_fragment_title); + ViewHelper.setActionBarTitle(this, exclude_apps_fragment_title); new Thread(() -> mListAdapter.populateList(getActivity())).start(); return v; } - private void setActionBarTitle(@StringRes int stringId) { - ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); - if (actionBar != null) { - actionBar.setSubtitle(stringId); - } - } - } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index e3845164..72cca644 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -58,6 +58,7 @@ import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; import static se.leap.bitmaskclient.base.models.Constants.LOCATION; import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; import static se.leap.bitmaskclient.base.models.Constants.USE_BRIDGES; +import static se.leap.bitmaskclient.base.utils.ViewHelper.setActionBarTitle; interface LocationListSelectionListener { void onLocationManuallySelected(Location location); @@ -103,6 +104,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca super.onViewCreated(view, savedInstanceState); initRecyclerView(); initRecommendedLocationEntry(); + setActionBarTitle(this, R.string.gateway_selection_title); } @Override diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/LogFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/LogFragment.java index a5a5e555..6f0f29ef 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/LogFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/LogFragment.java @@ -60,6 +60,8 @@ import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.models.Constants; import static de.blinkt.openvpn.core.OpenVPNService.humanReadableByteCount; +import static se.leap.bitmaskclient.R.string.log_fragment_title; +import static se.leap.bitmaskclient.base.utils.ViewHelper.setActionBarTitle; public class LogFragment extends ListFragment implements StateListener, SeekBar.OnSeekBarChangeListener, RadioGroup.OnCheckedChangeListener, VpnStatus.ByteCountListener { public static final String TAG = LogFragment.class.getSimpleName(); @@ -530,6 +532,8 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. mConnectStatus = v.findViewById(R.id.speedStatus); if (mShowOptionsLayout) mOptionsLayout.setVisibility(View.VISIBLE); + + setActionBarTitle(this, log_fragment_title); return v; } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java index cc3ecca6..9f210bd5 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java @@ -54,16 +54,12 @@ import se.leap.bitmaskclient.base.models.ProviderObservable; import se.leap.bitmaskclient.base.views.IconSwitchEntry; import se.leap.bitmaskclient.base.views.IconTextEntry; import se.leap.bitmaskclient.eip.EipStatus; -import se.leap.bitmaskclient.firewall.FirewallManager; import se.leap.bitmaskclient.providersetup.ProviderListActivity; import se.leap.bitmaskclient.tethering.TetheringObservable; import static android.content.Context.MODE_PRIVATE; import static android.view.View.GONE; import static android.view.View.VISIBLE; -import static se.leap.bitmaskclient.R.string.about_fragment_title; -import static se.leap.bitmaskclient.R.string.advanced_settings; -import static se.leap.bitmaskclient.R.string.log_fragment_title; import static se.leap.bitmaskclient.base.BitmaskApp.getRefWatcher; import static se.leap.bitmaskclient.base.models.Constants.DONATION_URL; import static se.leap.bitmaskclient.base.models.Constants.ENABLE_DONATION; @@ -320,7 +316,6 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen FragmentManagerEnhanced fragmentManager = new FragmentManagerEnhanced(getActivity().getSupportFragmentManager()); closeDrawer(); Fragment fragment = new GatewaySelectionFragment(); - setActionBarTitle(R.string.gateway_selection_title); fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG); }); } @@ -344,7 +339,6 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen log.setOnClickListener((buttonView) -> { closeDrawer(); Fragment fragment = new LogFragment(); - setActionBarTitle(log_fragment_title); fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG); }); } @@ -355,7 +349,6 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen about.setOnClickListener((buttonView) -> { closeDrawer(); Fragment fragment = new AboutFragment(); - setActionBarTitle(about_fragment_title); fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG); }); } @@ -481,13 +474,6 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen return ((AppCompatActivity) getActivity()).getSupportActionBar(); } - private void setActionBarTitle(@StringRes int resId) { - ActionBar actionBar = getActionBar(); - if (actionBar != null) { - actionBar.setSubtitle(resId); - } - } - private void hideActionBarSubTitle() { ActionBar actionBar = getActionBar(); if (actionBar != null) { diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java index ae2a1052..a38314d1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java @@ -10,9 +10,6 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; @@ -46,6 +43,7 @@ import static se.leap.bitmaskclient.base.utils.PreferenceHelper.hasSnowflakePref import static se.leap.bitmaskclient.base.utils.PreferenceHelper.preferUDP; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useBridges; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useSnowflake; +import static se.leap.bitmaskclient.base.utils.ViewHelper.setActionBarTitle; public class SettingsFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -74,7 +72,7 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh initUseSnowflakeEntry(view); initFirewallEntry(view); initTetheringEntry(view); - setActionBarTitle(advanced_settings); + setActionBarTitle(this, advanced_settings); return view; } @@ -248,11 +246,4 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh } } - private void setActionBarTitle(@StringRes int stringId) { - ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); - if (actionBar != null) { - actionBar.setSubtitle(stringId); - } - } - } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java index 23ca40e5..7410172f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/ViewHelper.java @@ -3,6 +3,10 @@ package se.leap.bitmaskclient.base.utils; import android.content.Context; import androidx.annotation.DimenRes; +import androidx.annotation.StringRes; +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment; /** * Created by cyberta on 29.06.18. @@ -14,4 +18,19 @@ public class ViewHelper { return context.getResources().getDimensionPixelSize(dimension); } + /** + * Sets the subtitle of an activities action bar. The activity needs to be an AppCompatActivity. + * @param fragment + * @param stringId + */ + public static void setActionBarTitle(Fragment fragment, @StringRes int stringId) { + AppCompatActivity appCompatActivity = (AppCompatActivity) fragment.getActivity(); + if (appCompatActivity != null) { + ActionBar actionBar = appCompatActivity.getSupportActionBar(); + if (actionBar != null) { + actionBar.setSubtitle(stringId); + } + } + } + } |