diff options
author | Samuel Holland <samuel@sholland.org> | 2017-08-09 06:19:37 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2017-08-09 06:19:37 -0500 |
commit | 39ed03f758fdcb22dd01ca576e31b19057ca387a (patch) | |
tree | 829c04cbd18b943e95ea5ee7714001f8d65dba21 /app/src/main/java/com | |
parent | 52cdf3e7e5fb4292d1dfa99ba123701ca7959092 (diff) |
ProfileList: Add the list fragment in code so it knows the layout
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com')
-rw-r--r-- | app/src/main/java/com/wireguard/android/ProfileListActivity.java | 19 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/ProfileListFragment.java | 7 |
2 files changed, 20 insertions, 6 deletions
diff --git a/app/src/main/java/com/wireguard/android/ProfileListActivity.java b/app/src/main/java/com/wireguard/android/ProfileListActivity.java index 60c35462..feb25511 100644 --- a/app/src/main/java/com/wireguard/android/ProfileListActivity.java +++ b/app/src/main/java/com/wireguard/android/ProfileListActivity.java @@ -17,15 +17,22 @@ public class ProfileListActivity extends ProfileActivity { super.onCreate(savedInstanceState); setContentView(R.layout.profile_list_activity); isSplitLayout = findViewById(R.id.fragment_container) != null; + final FragmentTransaction transaction = getFragmentManager().beginTransaction(); + final Fragment listFragment = getFragmentManager().findFragmentByTag(TAG_LIST); + if (listFragment instanceof ProfileListFragment) { + ((ProfileListFragment) listFragment).setIsSplitLayout(isSplitLayout); + } else { + final ProfileListFragment newListFragment = new ProfileListFragment(); + newListFragment.setIsSplitLayout(isSplitLayout); + transaction.add(R.id.list_container, newListFragment, TAG_LIST); + } if (!isSplitLayout) { // Avoid ProfileDetailFragment adding its menu when it is not in the view hierarchy. - final Fragment fragment = getFragmentManager().findFragmentByTag(TAG_DETAIL); - if (fragment != null) { - final FragmentTransaction transaction = getFragmentManager().beginTransaction(); - transaction.remove(fragment); - transaction.commit(); - } + final Fragment detailFragment = getFragmentManager().findFragmentByTag(TAG_DETAIL); + if (detailFragment != null) + transaction.remove(detailFragment); } + transaction.commit(); onProfileSelected(getCurrentProfile()); } diff --git a/app/src/main/java/com/wireguard/android/ProfileListFragment.java b/app/src/main/java/com/wireguard/android/ProfileListFragment.java index 7c9ecd4d..be1358a4 100644 --- a/app/src/main/java/com/wireguard/android/ProfileListFragment.java +++ b/app/src/main/java/com/wireguard/android/ProfileListFragment.java @@ -16,11 +16,14 @@ import com.wireguard.config.Profile; public class ProfileListFragment extends ServiceClientFragment<ProfileServiceInterface> { private ProfileListFragmentBinding binding; + private boolean isSplitLayout; @Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { binding = ProfileListFragmentBinding.inflate(inflater, parent, false); final ListView listView = (ListView) binding.getRoot(); + listView.setChoiceMode(isSplitLayout + ? ListView.CHOICE_MODE_SINGLE : ListView.CHOICE_MODE_NONE); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { @@ -51,4 +54,8 @@ public class ProfileListFragment extends ServiceClientFragment<ProfileServiceInt super.onServiceConnected(service); binding.setProfiles(service.getProfiles()); } + + public void setIsSplitLayout(boolean isSplitLayout) { + this.isSplitLayout = isSplitLayout; + } } |