11package cc .rome753 .activitytask .view ;
22
33import android .content .Context ;
4- import android .text .TextUtils ;
54import android .util .Log ;
65import android .view .MotionEvent ;
76import android .view .View ;
109import android .widget .LinearLayout ;
1110
1211import java .util .ArrayList ;
12+ import java .util .HashSet ;
1313import java .util .Map ;
14- import java .util .Set ;
1514
1615import cc .rome753 .activitytask .AUtils ;
1716import cc .rome753 .activitytask .R ;
@@ -27,11 +26,11 @@ public class ActivityTaskView extends LinearLayout {
2726
2827 public static final String TAG = ActivityTaskView .class .getSimpleName ();
2928 private ViewGroup mLinearLayout ;
30- private ViewGroup mContainer ;
3129 private View mTinyView ;
3230 private View mTaskView ;
3331 private View mEmptyView ;
3432
33+ private HashSet <String > mPendingRemove ; // Wait for fragments destroy
3534
3635 private int mStatusHeight ;
3736 private int mScreenWidth ;
@@ -41,21 +40,11 @@ public ActivityTaskView(Context context) {
4140 inflate (context , R .layout .view_activity_task , this );
4241 mStatusHeight = AUtils .getStatusBarHeight (context );
4342 mScreenWidth = AUtils .getScreenWidth (context );
44- mLinearLayout = findViewById (R .id .ll );
45- mContainer = findViewById (R .id .fl );
43+ mLinearLayout = findViewById (R .id .container );
4644 mTinyView = findViewById (R .id .tiny_view );
47- mTaskView = findViewById (R .id .task_view );
45+ mTaskView = findViewById (R .id .main_view );
4846 mEmptyView = findViewById (R .id .view_empty );
49- }
50-
51- public FragmentTaskView findFragmentTaskView (String activity ) {
52- for (int i = 0 ; i < mContainer .getChildCount (); i ++) {
53- View view = mContainer .getChildAt (i );
54- if (TextUtils .equals ((CharSequence ) view .getTag (), activity )) {
55- return (FragmentTaskView ) view ;
56- }
57- }
58- return null ;
47+ mPendingRemove = new HashSet <>();
5948 }
6049
6150 float mInnerX ;
@@ -119,50 +108,77 @@ private void moveToBorder() {
119108 private ATree aTree = new ATree ();
120109
121110 public void add (LifecycleInfo info ) {
122- FragmentTaskView view = new FragmentTaskView (getContext ());
123- view .setTitle (info .activity );
124- view .setTag (info .activity );
125- mContainer .addView (view , 0 );
126-
127111 aTree .add (info .task , info .activity , info .lifecycle );
128112 notifyData ();
129113 }
130114
131115 public void remove (LifecycleInfo info ) {
132- FragmentTaskView view = findFragmentTaskView (info .activity );
133- ViewPool .get ().recycle (view );
134- mContainer .removeView (view );
135-
136- aTree .remove (info .task , info .activity );
137- notifyData ();
116+ if (ViewPool .get ().getF (info .activity ) != null ) {
117+ mPendingRemove .add (info .activity );
118+ update (info );
119+ } else {
120+ aTree .remove (info .task , info .activity );
121+ notifyData ();
122+ }
138123 }
139124
140125 public void update (LifecycleInfo info ) {
141126 aTree .updateLifecycle (info .activity , info .lifecycle );
142127 ViewPool .get ().notifyLifecycleChange (info );
143128 }
144129
130+ public void addF (LifecycleInfo info ) {
131+ FragmentTaskView view = ViewPool .get ().getF (info .activity );
132+ if (view == null ) {
133+ view = ViewPool .get ().addF (getContext (), info .activity );
134+ notifyData ();
135+ }
136+ view .add (info );
137+ }
138+
139+ public void removeF (LifecycleInfo info ) {
140+ FragmentTaskView view = ViewPool .get ().getF (info .activity );
141+ if (view != null ) {
142+ view .remove (info );
143+ if (view .getChildCount () == 0 && mPendingRemove .contains (info .activity )) {
144+ mPendingRemove .remove (info .activity );
145+ remove (info );
146+ }
147+ }
148+ }
149+
150+ public void updateF (LifecycleInfo info ) {
151+ FragmentTaskView view = ViewPool .get ().getF (info .activity );
152+ if (view != null ) {
153+ view .update (info );
154+ }
155+ }
156+
145157 private void notifyData () {
146158 ViewPool .get ().recycle (mLinearLayout );
147159 mLinearLayout .removeAllViews ();
148- Set <Map .Entry <String , ArrayList <String >>> set = aTree .entrySet ();
149- for (Map .Entry <String , ArrayList <String >> entry : set ) {
150- TaskLayout layout = new TaskLayout (getContext ());
151- layout .setTitle (entry .getKey ());
152- for (String value : entry .getValue ()) {
160+ for (Map .Entry <String , ArrayList <String >> entry : aTree .entrySet ()) {
161+ TaskLayout taskLayout = new TaskLayout (getContext ());
162+ taskLayout .setTitle (entry .getKey ());
163+ for (String activity : entry .getValue ()) {
153164 ATextView textView = ViewPool .get ().getOne (getContext ());
154- textView .setInfoText (value , aTree .getLifecycle (value ));
155- layout .addFirst (textView );
165+ textView .setInfoText (activity , aTree .getLifecycle (activity ));
166+ taskLayout .addFirst (textView );
167+
168+ FragmentTaskView view = ViewPool .get ().getF (activity );
169+ if (view != null ) {
170+ taskLayout .addSecond (view );
171+ }
156172 }
157- mLinearLayout .addView (layout , 0 );
173+ mLinearLayout .addView (taskLayout , 0 );
158174 }
159175 mEmptyView .setVisibility (mLinearLayout .getChildCount () == 0 ? VISIBLE : GONE );
160176
161177 }
162178
163179 public void clear () {
180+ ViewPool .get ().clearF ();
164181 aTree = new ATree ();
165- mContainer .removeAllViews ();
166182 notifyData ();
167183 }
168184
0 commit comments