ProfileList: Add the list fragment in code so it knows the layout
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
52cdf3e7e5
commit
39ed03f758
@ -17,15 +17,22 @@ public class ProfileListActivity extends ProfileActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.profile_list_activity);
|
setContentView(R.layout.profile_list_activity);
|
||||||
isSplitLayout = findViewById(R.id.fragment_container) != null;
|
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) {
|
if (!isSplitLayout) {
|
||||||
// Avoid ProfileDetailFragment adding its menu when it is not in the view hierarchy.
|
// Avoid ProfileDetailFragment adding its menu when it is not in the view hierarchy.
|
||||||
final Fragment fragment = getFragmentManager().findFragmentByTag(TAG_DETAIL);
|
final Fragment detailFragment = getFragmentManager().findFragmentByTag(TAG_DETAIL);
|
||||||
if (fragment != null) {
|
if (detailFragment != null)
|
||||||
final FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
transaction.remove(detailFragment);
|
||||||
transaction.remove(fragment);
|
|
||||||
transaction.commit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
transaction.commit();
|
||||||
onProfileSelected(getCurrentProfile());
|
onProfileSelected(getCurrentProfile());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,11 +16,14 @@ import com.wireguard.config.Profile;
|
|||||||
|
|
||||||
public class ProfileListFragment extends ServiceClientFragment<ProfileServiceInterface> {
|
public class ProfileListFragment extends ServiceClientFragment<ProfileServiceInterface> {
|
||||||
private ProfileListFragmentBinding binding;
|
private ProfileListFragmentBinding binding;
|
||||||
|
private boolean isSplitLayout;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
||||||
binding = ProfileListFragmentBinding.inflate(inflater, parent, false);
|
binding = ProfileListFragmentBinding.inflate(inflater, parent, false);
|
||||||
final ListView listView = (ListView) binding.getRoot();
|
final ListView listView = (ListView) binding.getRoot();
|
||||||
|
listView.setChoiceMode(isSplitLayout
|
||||||
|
? ListView.CHOICE_MODE_SINGLE : ListView.CHOICE_MODE_NONE);
|
||||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
@ -51,4 +54,8 @@ public class ProfileListFragment extends ServiceClientFragment<ProfileServiceInt
|
|||||||
super.onServiceConnected(service);
|
super.onServiceConnected(service);
|
||||||
binding.setProfiles(service.getProfiles());
|
binding.setProfiles(service.getProfiles());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIsSplitLayout(boolean isSplitLayout) {
|
||||||
|
this.isSplitLayout = isSplitLayout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,11 @@
|
|||||||
android:baselineAligned="false"
|
android:baselineAligned="false"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<fragment
|
<FrameLayout
|
||||||
android:name="com.wireguard.android.ProfileListFragment"
|
android:id="@+id/list_container"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1" />
|
||||||
android:tag="list" />
|
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/fragment_container"
|
android:id="@+id/fragment_container"
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:name="com.wireguard.android.ProfileListFragment"
|
android:id="@+id/list_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent" />
|
||||||
android:tag="list" />
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?android:attr/activatedBackgroundIndicator"
|
||||||
android:padding="16dp">
|
android:padding="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
Loading…
Reference in New Issue
Block a user