summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorYuutaW <17158086+trumeet@users.noreply.github.com>2019-04-13 14:27:50 -0700
committerYuutaW <17158086+Trumeet@users.noreply.github.com>2019-04-13 14:27:50 -0700
commitaee4c4f0f4c644dd024cef2c5fa084af0684c1ac (patch)
tree71357320f902df739ed4c4d87271db92f3a099f1 /app
parent64d97258a1b8c293f5cd0adcc179e60c01c9ca85 (diff)
downloadFlow-aee4c4f0f4c644dd024cef2c5fa084af0684c1ac.tar
Flow-aee4c4f0f4c644dd024cef2c5fa084af0684c1ac.tar.gz
Flow-aee4c4f0f4c644dd024cef2c5fa084af0684c1ac.tar.bz2
Flow-aee4c4f0f4c644dd024cef2c5fa084af0684c1ac.zip
fix(app/library): add instance state handling
Signed-off-by: YuutaW <17158086+Trumeet@users.noreply.github.com>
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/moe/yuuta/flow/MainActivity.java33
1 files changed, 31 insertions, 2 deletions
diff --git a/app/src/main/java/moe/yuuta/flow/MainActivity.java b/app/src/main/java/moe/yuuta/flow/MainActivity.java
index cba4bbd..d827aa6 100644
--- a/app/src/main/java/moe/yuuta/flow/MainActivity.java
+++ b/app/src/main/java/moe/yuuta/flow/MainActivity.java
@@ -6,6 +6,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
@@ -26,9 +27,9 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
Log.i(TAG, "onCreate()");
- if (mFragment == null) {
+ if (mFragment == null && savedInstanceState == null) {
mFragment = new FlowFragment();
- mFragment.setPages(Arrays.asList(new Page1(), new Page2(), new Page3()));
+ mFragment.setPages(Arrays.asList(new Page1(), new Page2(), new Page3(), new Page4()));
getSupportFragmentManager()
.beginTransaction()
.replace(android.R.id.content, mFragment)
@@ -95,6 +96,34 @@ public class MainActivity extends AppCompatActivity {
}
}
+ public static class Page4 extends PageFragment {
+ public Page4() {
+ mInfo = new FlowInfo(new HeaderConfig("Page 4", "just a counter", false), null);
+ }
+
+ // TODO: The FlowFragment keeps the instance, maybe we don't want that happened to child fragments.
+ private int mCount;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ Button button = new Button(requireContext());
+ button.setMinHeight(20);
+ button.setText("+1s");
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mCount++;
+ HeaderConfig config = mInfo.getHeaderConfig();
+ config.setSubtitleText(Integer.toString(mCount));
+ mInfo.setHeaderConfig(config);
+ getHostFragment().notifyCurrentFlowInfoUpdated();
+ }
+ });
+ return button;
+ }
+ }
+
@Override
public void onBackPressed() {
if (mFragment != null && mFragment.onBackPressed()) return;