From 8098343fa10d3788623a11ab325b3b7251155217 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 18 Mar 2019 11:15:23 +0000 Subject: [PATCH] Save parent/child folders --- .../eu/faircode/email/FragmentFolders.java | 28 +++++++++++++++++-- .../java/eu/faircode/email/TupleFolderEx.java | 3 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentFolders.java b/app/src/main/java/eu/faircode/email/FragmentFolders.java index fef4c75e5b..fcbe93c95e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentFolders.java +++ b/app/src/main/java/eu/faircode/email/FragmentFolders.java @@ -24,7 +24,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; import android.os.Bundle; -import android.util.LongSparseArray; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -37,7 +36,9 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -67,7 +68,7 @@ public class FragmentFolders extends FragmentBase { private boolean searching = false; private AdapterFolder adapter; - private static LongSparseArray> parentChilds = new LongSparseArray<>(); + private Map> parentChilds = new HashMap<>(); @Override public void onCreate(Bundle savedInstanceState) { @@ -78,11 +79,34 @@ public class FragmentFolders extends FragmentBase { account = args.getLong("account", -1); } + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + outState.putLongArray("fair:parents", Helper.toLongArray(parentChilds.keySet())); + for (Long parent : parentChilds.keySet()) { + List childs = parentChilds.get(parent); + outState.putInt("fair:childs:" + parent + ":count", childs.size()); + for (int i = 0; i < childs.size(); i++) + outState.putSerializable("fair:childs:" + parent + ":" + i, childs.get(i)); + } + } + @Override @Nullable public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { setHasOptionsMenu(true); + if (savedInstanceState != null) { + for (long parent : savedInstanceState.getLongArray("fair:parents")) { + int count = savedInstanceState.getInt("fair:childs:" + parent + ":count"); + List childs = new ArrayList<>(count); + for (int i = 0; i < count; i++) + childs.add((TupleFolderEx) savedInstanceState.getSerializable("fair:childs:" + parent + ":" + i)); + parentChilds.put(parent, childs); + } + } + view = (ViewGroup) inflater.inflate(R.layout.fragment_folders, container, false); // Get controls diff --git a/app/src/main/java/eu/faircode/email/TupleFolderEx.java b/app/src/main/java/eu/faircode/email/TupleFolderEx.java index 9165387a02..7027a6f604 100644 --- a/app/src/main/java/eu/faircode/email/TupleFolderEx.java +++ b/app/src/main/java/eu/faircode/email/TupleFolderEx.java @@ -19,9 +19,10 @@ package eu.faircode.email; Copyright 2018-2019 by Marcel Bokhorst (M66B) */ +import java.io.Serializable; import java.util.Objects; -public class TupleFolderEx extends EntityFolder { +public class TupleFolderEx extends EntityFolder implements Serializable { public String accountName; public Integer accountColor; public String accountState;