Fixed dispose calls. 75/264675/4
authorshivamv <shivam.v2@samsung.com>
Tue, 28 Sep 2021 05:58:34 +0000 (11:28 +0530)
committershivamv <shivam.v2@samsung.com>
Tue, 28 Sep 2021 08:16:38 +0000 (13:46 +0530)
Change-Id: Ic8c88af826cda6ad00404df1a935e2d3fb6cfba5
Signed-off-by: shivamv <shivam.v2@samsung.com>
music-player/Views/PlaylistSelectorView.cs
music-player/Views/SearchView.cs
music-player/Views/ViewManager.cs
packaging/org.tizen.MusicPlayer-1.0.0.tpk

index 973f93c4f95561cfc817764dac988b2cc6a9d431..9b3c64fff397e8048b89d0d8c63a8e251bc67fa0 100755 (executable)
@@ -15,7 +15,7 @@ namespace MusicPlayer.Views
     {
         private View selectPlaylistContentArea;
         private View createPlaylistContentArea;
-        private View searchBox;
+        private View inputArea;
         private Button createNewPlaylistButton;
         private TextLabel noListText;
         private TextLabel underText;
@@ -39,7 +39,7 @@ namespace MusicPlayer.Views
                 Size2D = new Size2D(1184, 660),
                 Title = "Add to playlist",
                 Content = selectPlaylistContentArea,
-                Actions = new List<View> { selectPlaylistCancelButton},
+                Actions = new List<View> { selectPlaylistCancelButton },
                 Padding = new Extents(0, 0, 0, 0),
                 Margin = new Extents(0, 0, 0, 0),
             };
@@ -118,7 +118,7 @@ namespace MusicPlayer.Views
                 Size2D = new Size2D(1184, 465),
                 Title = "Create playlist",
                 Content = createPlaylistContentArea,
-                Actions = new List<View> { createPlaylistCancelButton , createPlaylistCreateButton },
+                Actions = new List<View> { createPlaylistCancelButton, createPlaylistCreateButton },
                 Padding = new Extents(0, 0, 0, 0),
                 Margin = new Extents(0, 0, 0, 0),
             };
@@ -213,7 +213,7 @@ namespace MusicPlayer.Views
                 Margin = new Extents(0, 0, 0, 24),
             };
             createPlaylistContentArea.Add(textLabel);
-            AddSearchBox();
+            AddInputArea();
             View itemSeperator = new View()
             {
                 WidthSpecification = LayoutParamPolicies.MatchParent,
@@ -236,9 +236,9 @@ namespace MusicPlayer.Views
             createPlaylistContentArea.Add(underText);
         }
 
-        private void AddSearchBox()
+        private void AddInputArea()
         {
-            searchBox = new View()
+            inputArea = new View()
             {
                 Size2D = new Size2D(1024, 48),
                 Layout = new FlexLayout()
@@ -268,9 +268,9 @@ namespace MusicPlayer.Views
             };
             crossButton.Clicked += CrossButtonClicked;
 
-            searchBox.Add(textField);
-            searchBox.Add(crossButton);
-            createPlaylistContentArea.Add(searchBox);
+            inputArea.Add(textField);
+            inputArea.Add(crossButton);
+            createPlaylistContentArea.Add(inputArea);
         }
 
         private void TextFieldTextChanged(object sender, TextField.TextChangedEventArgs e)
@@ -290,7 +290,7 @@ namespace MusicPlayer.Views
                 createPlaylistCreateButton.IsSelectable = true;
                 createPlaylistCreateButton.IsEnabled = true;
             }
-            if(searchText.Length > 64)
+            if (searchText.Length > 64)
             {
                 Notification.MakeToast("Maximum number of characters reached.", Notification.ToastCenter).Post(Notification.ToastShort);
                 underText.Text = "Can't enter more than 64 characters.";
@@ -334,7 +334,7 @@ namespace MusicPlayer.Views
                 RemoveTheCreatePopup();
                 Window.Instance.Add(selectPlaylistDialog);
                 Playlist playlist = PlaylistManager.Instance.AddPlaylist(textField.Text);
-                PlaylistModel playlistModel = new PlaylistModel(new PlaylistData(playlist.Id,playlist.Name, viewModel.GetTrackCountForPlaylist(playlist.Id), playlist.ThumbnailPath));
+                PlaylistModel playlistModel = new PlaylistModel(new PlaylistData(playlist.Id, playlist.Name, viewModel.GetTrackCountForPlaylist(playlist.Id), playlist.ThumbnailPath));
                 collectionView.SelectedItem = playlistModel;
             }
             else
@@ -352,56 +352,54 @@ namespace MusicPlayer.Views
             }
             if (type == DisposeTypes.Explicit)
             {
-                selectPlaylistDialog?.Dispose();
-                selectPlaylistDialog = null;
-                createPlaylistDialog?.Dispose();
-                createPlaylistDialog = null;
-
-                searchBox?.Remove(textField);
+                inputArea?.Remove(textField);
                 textField?.Dispose();
                 textField = null;
-                searchBox?.Remove(crossButton);
+                inputArea?.Remove(crossButton);
                 crossButton?.Dispose();
                 crossButton = null;
 
-                if(selectPlaylistContentArea != null)
+                if (selectPlaylistContentArea != null)
                 {
                     List<View> children = selectPlaylistContentArea.Children;
-                    foreach(View child in children)
+                    while (children.Count > 0)
                     {
+                        View child = children[0];
                         selectPlaylistContentArea.Remove(child);
                         child?.Dispose();
                     }
-                    selectPlaylistContentArea.Dispose();
                 }
                 if (createPlaylistContentArea != null)
                 {
                     List<View> children = createPlaylistContentArea.Children;
-                    foreach (View child in children)
+                    while (children.Count > 0)
                     {
+                        View child = children[0];
                         createPlaylistContentArea.Remove(child);
                         child?.Dispose();
                     }
-                    createPlaylistContentArea.Dispose();
-                    createPlaylistContentArea = null;
                 }
-
                 createNewPlaylistButton = null;
-                collectionView?.Dispose();
                 collectionView = null;
-                noListText?.Dispose();
                 noListText = null;
-                searchBox = null;
+                inputArea = null;
                 underText = null;
 
+                selectPlaylistDialog?.Dispose();
+                selectPlaylistDialog = null;
+                createPlaylistDialog?.Dispose();
+                createPlaylistDialog = null;
+                selectPlaylistContentArea = null;
+                createPlaylistContentArea = null;
+
                 selectPlaylistCancelButton?.Dispose();
                 selectPlaylistCancelButton = null;
                 createPlaylistCancelButton?.Dispose();
                 createPlaylistCancelButton = null;
                 createPlaylistCreateButton?.Dispose();
                 createPlaylistCreateButton = null;
-
             }
+
             base.Dispose(type);
         }
 
index 2ac62ae40611d4d9e2f6556da841551e0f8cca46..463c488b6b437f9ef4431d3a968c3382757bf7b6 100755 (executable)
@@ -180,8 +180,7 @@ namespace MusicPlayer.Views
 
         private void BackButtonClicked(object sender, ClickedEventArgs e)
         {
-            Window.Instance.Remove(this);
-            //DeleteSearchView();
+            DeleteSearchView();
         }
 
         private void AddCollectionView()
@@ -230,7 +229,6 @@ namespace MusicPlayer.Views
             object selectedObject = collectionView.SelectedItem;
             if (selectedObject is SearchModel)
             {
-                Window.Instance.Remove(this);
                 SearchModel searchModel = (SearchModel)selectedObject;
                 if (searchModel.ItemType == 0)
                 {
@@ -248,8 +246,8 @@ namespace MusicPlayer.Views
                 {
                     Track currentTrack = searchModel.TrackDetail;
                     viewModel.PlayTrack(currentTrack);
-                    //DeleteSearchView();
                 }
+                DeleteSearchView();
             }
         }
 
@@ -311,6 +309,7 @@ namespace MusicPlayer.Views
 
         public void DeleteSearchView()
         {
+            Window.Instance.Remove(this);
             Dispose(DisposeTypes.Explicit);
         }
 
@@ -325,8 +324,9 @@ namespace MusicPlayer.Views
                 if (searchBox != null)
                 {
                     List<View> children = searchBox.Children;
-                    foreach (View child in children)
+                    while (children.Count > 0)
                     {
+                        View child = children[0];
                         searchBox.Remove(child);
                         child?.Dispose();
                     }
@@ -337,8 +337,9 @@ namespace MusicPlayer.Views
                 if (topView != null)
                 {
                     List<View> children = topView.Children;
-                    foreach (View child in children)
+                    while (children.Count > 0)
                     {
+                        View child = children[0];
                         topView.Remove(child);
                         child?.Dispose();
                     }
@@ -349,13 +350,13 @@ namespace MusicPlayer.Views
                     topView = null;
                 }
 
-                if (!noItemFound && collectionView != null)
+                if (noItemFound)
                 {
-                    base.Remove(collectionView);
+                    base.Remove(noItemView);
                 }
-                else if(noItemFound && noItemView != null)
+                else
                 {
-                    base.Remove(noItemView);
+                    base.Remove(collectionView);
                 }
 
                 if (collectionView != null)
@@ -367,10 +368,11 @@ namespace MusicPlayer.Views
                 if (noItemView != null)
                 {
                     List<View> children = noItemView.Children;
-                    foreach (View child in children)
+                    while (children.Count > 0)
                     {
+                        View child = children[0];
                         noItemView.Remove(child);
-                        child.Dispose();
+                        child?.Dispose();
                     }
                     noItemView.Dispose();
                     noItemView = null;
index a673ac55d0f623c977f9247fe31dc11b8998e4b1..530708e96507b3f1fb4ee85acd84257b922de310 100755 (executable)
@@ -17,7 +17,6 @@ namespace MusicPlayer.Views
         private ViewLibrary viewLibrary;
         private View rootView;
         private  BaseView baseView;
-        private SearchView searchView;
         private static string[] TabNames = new string[]
         {
             "Playlists",
@@ -121,20 +120,13 @@ namespace MusicPlayer.Views
 
         private void OnSearchIconClicked(object sender, ClickedEventArgs e)
         {
-            searchView = viewLibrary.CreateSearchView();
+            SearchView searchView = viewLibrary.CreateSearchView();
             if (searchView != null)
             {
-                searchView.LaunchDetailView += OnSubViewAddedFromSearch;
+                searchView.LaunchDetailView += OnSubViewAdded;
             }
         }
 
-        private void OnSubViewAddedFromSearch(object sender, SubContentViewAddEventArgs subViewAddEventArgs)
-        {
-            BaseSubContentView baseSubContentView = viewLibrary.GetSubContentView(subViewAddEventArgs.SubViewType, subViewAddEventArgs.ViewModelData);
-            baseView.AddSubViewContent(subViewAddEventArgs.TitleText, baseSubContentView);
-            //searchView.DeleteSearchView();
-        }
-
         private void OnSubViewAdded(object sender, SubContentViewAddEventArgs subViewAddEventArgs)
         {
             BaseSubContentView baseSubContentView = viewLibrary.GetSubContentView(subViewAddEventArgs.SubViewType, subViewAddEventArgs.ViewModelData);
index ceb41d649e315eefe69e8c1375401399e791187a..8783c742cabfe49159fbe59f019bc0c0a87e6b8b 100755 (executable)
Binary files a/packaging/org.tizen.MusicPlayer-1.0.0.tpk and b/packaging/org.tizen.MusicPlayer-1.0.0.tpk differ