@@ -60,8 +60,6 @@ class MediaBrowseTreeSnapshot(private val mBrowser : MediaBrowserCompat, private
60
60
}
61
61
62
62
private fun takeBrowserSnapshotImpl (mItems : MutableList <MediaBrowserCompat .MediaItem >, executorService : ExecutorService ){
63
- // Create output file
64
-
65
63
// Create output file
66
64
val root = Environment .getExternalStorageDirectory()
67
65
val dirsPath = root.absolutePath + " /Temp/"
@@ -84,7 +82,7 @@ class MediaBrowseTreeSnapshot(private val mBrowser : MediaBrowserCompat, private
84
82
} catch (e: InterruptedException ) {
85
83
e.printStackTrace()
86
84
}
87
- writeMediaItemToFile (item, pw, 1 ,
85
+ visitMediaItemNode (item, pw, 1 ,
88
86
executorService)
89
87
writeCompleted.release()
90
88
}
@@ -103,24 +101,13 @@ class MediaBrowseTreeSnapshot(private val mBrowser : MediaBrowserCompat, private
103
101
}
104
102
}
105
103
106
- private fun writeMediaItemToFile (mediaItem : MediaBrowserCompat .MediaItem ? , printWriter : PrintWriter , depth : Int ,
107
- executorService : ExecutorService ) {
108
- if (mediaItem != null ) {
109
- val descriptionCompat = mediaItem.description
110
104
111
- // Tab the media item to the respective depth
112
- val tabStr = String (CharArray (depth)).replace(" \u0000 " ,
113
- " \t " )
114
- val titleStr = if (descriptionCompat.title != null ) descriptionCompat.title.toString() else " NAN"
115
- val subTitleStr = if (descriptionCompat.subtitle != null ) descriptionCompat.subtitle.toString() else " NAN"
116
- val mIDStr = if (descriptionCompat.mediaId != null ) descriptionCompat.mediaId else " NAN"
117
- val uriStr = if (descriptionCompat.mediaUri != null ) descriptionCompat.mediaUri.toString() else " NAN"
118
- val desStr = if (descriptionCompat.description != null ) descriptionCompat.description.toString() else " NAN"
119
- val infoStr = String .format(
120
- " %sTitle:%s,Subtitle:%s,MediaId:%s,URI:%s,Description:%s" ,
121
- tabStr, titleStr, subTitleStr, mIDStr, uriStr, desStr)
122
- printWriter.println (infoStr)
105
+ private fun visitMediaItemNode (mediaItem : MediaBrowserCompat .MediaItem ? , printWriter : PrintWriter , depth : Int ,
106
+ executorService : ExecutorService ) {
107
+ if (mediaItem != null ) {
108
+ printMediaItemDescription(printWriter, mediaItem, depth)
123
109
val mid = if (mediaItem.mediaId != null ) mediaItem.mediaId!! else " "
110
+
124
111
// If a media item is not a leaf continue DFS on it
125
112
if (mediaItem.isBrowsable && mid != " " ) {
126
113
val loaded = Semaphore (1 )
@@ -152,13 +139,29 @@ class MediaBrowseTreeSnapshot(private val mBrowser : MediaBrowserCompat, private
152
139
153
140
// Run DFS on all of the nodes children
154
141
for (mediaItemChild in mChildren) {
155
- writeMediaItemToFile (mediaItemChild, printWriter, depth + 1 ,
142
+ visitMediaItemNode (mediaItemChild, printWriter, depth + 1 ,
156
143
executorService)
157
144
}
158
145
}
159
146
}
160
147
}
161
148
149
+ private fun printMediaItemDescription (printWriter : PrintWriter , mediaItem : MediaBrowserCompat .MediaItem , depth : Int ){
150
+ val descriptionCompat = mediaItem.description
151
+ // Tab the media item to the respective depth
152
+ val tabStr = String (CharArray (depth)).replace(" \u0000 " ,
153
+ " \t " )
154
+ val titleStr = if (descriptionCompat.title != null ) descriptionCompat.title.toString() else " NAN"
155
+ val subTitleStr = if (descriptionCompat.subtitle != null ) descriptionCompat.subtitle.toString() else " NAN"
156
+ val mIDStr = if (descriptionCompat.mediaId != null ) descriptionCompat.mediaId else " NAN"
157
+ val uriStr = if (descriptionCompat.mediaUri != null ) descriptionCompat.mediaUri.toString() else " NAN"
158
+ val desStr = if (descriptionCompat.description != null ) descriptionCompat.description.toString() else " NAN"
159
+ val infoStr = String .format(
160
+ " %sTitle:%s,Subtitle:%s,MediaId:%s,URI:%s,Description:%s" ,
161
+ tabStr, titleStr, subTitleStr, mIDStr, uriStr, desStr)
162
+ printWriter.println (infoStr)
163
+ }
164
+
162
165
private fun notifyUser (textToNotify : String ) {
163
166
Handler (Looper .getMainLooper()).post {
164
167
val toast = Toast .makeText(
0 commit comments