diff options
author | Samuel Holland <samuel@sholland.org> | 2017-08-16 01:43:15 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2017-08-16 01:43:15 -0500 |
commit | 6b774ebafba211d0650aef42cdc9f358b52bd47f (patch) | |
tree | 94d6741d6224234539775ae94a7df38f0f722b3b /app/src/main/java | |
parent | 1db9d53c6398868ed99a38ef80db27cfd0a50b27 (diff) |
ConfigActivity: Inline PlaceholderFragment into the layout
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/com/wireguard/android/ConfigActivity.java | 53 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/PlaceholderFragment.java | 19 |
2 files changed, 26 insertions, 46 deletions
diff --git a/app/src/main/java/com/wireguard/android/ConfigActivity.java b/app/src/main/java/com/wireguard/android/ConfigActivity.java index 4833d876..fb565e96 100644 --- a/app/src/main/java/com/wireguard/android/ConfigActivity.java +++ b/app/src/main/java/com/wireguard/android/ConfigActivity.java @@ -25,7 +25,6 @@ public class ConfigActivity extends BaseConfigActivity { private boolean isStateSaved; private ConfigListFragment listFragment; private int mainContainer; - private final PlaceholderFragment placeholderFragment = new PlaceholderFragment(); private boolean wasUpdateSkipped; @Override @@ -153,34 +152,34 @@ public class ConfigActivity extends BaseConfigActivity { } private void switchToFragment(final int container, final String tag, final boolean push) { - final Fragment fragment; if (tag.equals(TAG_PLACEHOLDER)) { - fragment = placeholderFragment; - } else { - final BaseConfigFragment configFragment; - switch (tag) { - case TAG_DETAIL: - if (detailFragment == null) - detailFragment = new ConfigDetailFragment(); - configFragment = detailFragment; - break; - case TAG_EDIT: - if (editFragment == null) - editFragment = new ConfigEditFragment(); - configFragment = editFragment; - break; - case TAG_LIST: - if (listFragment == null) - listFragment = new ConfigListFragment(); - configFragment = listFragment; - break; - default: - throw new IllegalArgumentException(); - } - if (configFragment.getCurrentConfig() != getCurrentConfig()) - configFragment.setCurrentConfig(getCurrentConfig()); - fragment = configFragment; + final Fragment oldFragment = fm.findFragmentById(container); + if (oldFragment != null) + fm.beginTransaction().remove(oldFragment).commit(); + return; + } + final BaseConfigFragment fragment; + switch (tag) { + case TAG_DETAIL: + if (detailFragment == null) + detailFragment = new ConfigDetailFragment(); + fragment = detailFragment; + break; + case TAG_EDIT: + if (editFragment == null) + editFragment = new ConfigEditFragment(); + fragment = editFragment; + break; + case TAG_LIST: + if (listFragment == null) + listFragment = new ConfigListFragment(); + fragment = listFragment; + break; + default: + throw new IllegalArgumentException(); } + if (fragment.getCurrentConfig() != getCurrentConfig()) + fragment.setCurrentConfig(getCurrentConfig()); if (fm.findFragmentById(container) != fragment) { final FragmentTransaction transaction = fm.beginTransaction(); if (push) { diff --git a/app/src/main/java/com/wireguard/android/PlaceholderFragment.java b/app/src/main/java/com/wireguard/android/PlaceholderFragment.java deleted file mode 100644 index db5d7b33..00000000 --- a/app/src/main/java/com/wireguard/android/PlaceholderFragment.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.wireguard.android; - -import android.app.Fragment; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -/** - * Fragment that shows a placeholder message. - */ - -public class PlaceholderFragment extends Fragment { - @Override - public View onCreateView(final LayoutInflater inflater, final ViewGroup parent, - final Bundle savedInstanceState) { - return inflater.inflate(R.layout.placeholder_fragment, parent, false); - } -} |