@@ -58,14 +58,41 @@ class MainActivity : AppCompatActivity() {
5858 binding = ActivityMainBinding .inflate(layoutInflater)
5959 setContentView(binding.root)
6060
61- // NOTE : This is used over findNavController to use androidx.fragment.app.FragmentContainerView
61+ // Note : This is used over findNavController to use androidx.fragment.app.FragmentContainerView
6262 navController =
6363 (supportFragmentManager.findFragmentById(R .id.nav_host_fragment) as NavHostFragment ).navController
6464 NavigationUI .setupWithNavController(binding.navigationView, navController)
6565
66+ // Note: This does not work as expected and has many bugs
67+ // val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
68+ // navController = navHostFragment.navController
69+ // val inflater = navController.navInflater
70+ // val originalGraph = inflater.inflate(R.navigation.nav_graph)
71+ // Log.d("Main[onCreate]", "intent?.action: ${intent?.action}")
72+ // val startDest = when (intent?.action) {
73+ // Intent.ACTION_VIEW -> R.id.nav_item_upload
74+ // Intent.ACTION_SEND -> R.id.nav_item_upload
75+ // Intent.ACTION_SEND_MULTIPLE -> R.id.nav_item_upload_multi
76+ // else -> R.id.nav_item_home
77+ // }
78+ // Log.d("Main[onCreate]", "startDest: $startDest")
79+ // val navState = NavGraphNavigator(navController.navigatorProvider)
80+ // val newGraph = NavGraph(navState).apply {
81+ // id = originalGraph.id
82+ // addAll(originalGraph)
83+ // setStartDestination(startDest)
84+ // }
85+ // val args = if (startDest != R.id.nav_item_home) {
86+ // Bundle().apply {
87+ // putParcelable("EXTRA_INTENT", intent)
88+ // }
89+ // } else null
90+ // Log.d("Main[onCreate]", "args: $args")
91+ // navController.setGraph(newGraph, args)
92+ // Log.d("Main[onCreate]", "DONE - navController")
93+
6694 val packageInfo = packageManager.getPackageInfo(this .packageName, 0 )
6795 val versionName = packageInfo.versionName
68- // Log.d("Main[onCreate]", "versionName: $versionName")
6996
7097 val headerView = binding.navigationView.getHeaderView(0 )
7198 val versionTextView = headerView.findViewById<TextView >(R .id.header_version)
@@ -135,19 +162,21 @@ class MainActivity : AppCompatActivity() {
135162 }
136163
137164 filePickerLauncher =
138- registerForActivityResult(ActivityResultContracts .OpenDocument ()) { uri ->
139- Log .d(" filePickerLauncher" , " uri: $uri " )
140- if (uri != null ) {
141- val mimeType = contentResolver.getType(uri)
142- Log .d(" filePickerLauncher" , " mimeType: $mimeType " )
143- showPreview(uri, mimeType)
165+ registerForActivityResult(ActivityResultContracts .OpenMultipleDocuments ()) { uris ->
166+ Log .d(" filePickerLauncher" , " uris: $uris " )
167+ if (uris.size > 1 ) {
168+ Log .i(" filePickerLauncher" , " MULTI!" )
169+ showMultiPreview(uris as ArrayList <Uri >)
170+ } else if (uris.size == 1 ) {
171+ Log .i(" filePickerLauncher" , " SINGLE!" )
172+ showPreview(uris[0 ])
144173 } else {
145- Log .w(" filePickerLauncher" , " No File Selected!" )
146- Toast .makeText(this , " No File Selected!" , Toast .LENGTH_SHORT ).show()
174+ Log .w(" filePickerLauncher" , " No Files Selected!" )
175+ Toast .makeText(this , " No Files Selected!" , Toast .LENGTH_SHORT ).show()
147176 }
148177 }
149178
150- // Only Handel Intent Once on Startup
179+ // Only Handel Intent Once Here after App Start
151180 if (savedInstanceState?.getBoolean(" intentHandled" ) != true ) {
152181 handleIntent(intent)
153182 }
@@ -158,8 +187,8 @@ class MainActivity : AppCompatActivity() {
158187 outState.putBoolean(" intentHandled" , true )
159188 }
160189
161- // TODO: Update with a ViewModel...
162190 fun setDrawerLockMode (enabled : Boolean ) {
191+ // TODO: Update with a ViewModel...
163192 Log .d(" setDrawerLockMode" , " enabled: $enabled " )
164193 val lockMode =
165194 if (enabled) DrawerLayout .LOCK_MODE_UNLOCKED else DrawerLayout .LOCK_MODE_LOCKED_CLOSED
@@ -209,12 +238,10 @@ class MainActivity : AppCompatActivity() {
209238 binding.drawerLayout.closeDrawers()
210239
211240 // TODO: Cleanup the logic for handling MAIN intent...
212-
213241 // val currentDestinationId = navController.currentDestination?.id
214242 // Log.d("handleIntent", "currentDestinationId: $currentDestinationId")
215243 // val launcherAction = sharedPreferences.getString("launcher_action", null)
216244 // Log.d("handleIntent", "launcherAction: $launcherAction")
217-
218245 // Log.d("handleIntent", "nav_item_preview: ${R.id.nav_item_preview}")
219246 // Log.d("handleIntent", "nav_item_short: ${R.id.nav_item_short}")
220247 // if (currentDestinationId == R.id.nav_item_preview || currentDestinationId == R.id.nav_item_short) {
@@ -231,7 +258,6 @@ class MainActivity : AppCompatActivity() {
231258 // navController.navigate(R.id.nav_item_home)
232259 // }
233260
234- // TODO: Determine if this needs to be in the above if/else
235261 val fromShortcut = intent.getStringExtra(" fromShortcut" )
236262 Log .d(" handleIntent" , " fromShortcut: $fromShortcut " )
237263 if (fromShortcut == " upload" ) {
@@ -262,7 +288,6 @@ class MainActivity : AppCompatActivity() {
262288 }
263289 // TODO: Determine how to properly navigate on new intent...
264290 // navController.navigate(R.id.nav_item_short, bundle)
265-
266291 navController.popBackStack(R .id.nav_graph, true )
267292 navController.navigate(
268293 R .id.nav_item_short, bundle, NavOptions .Builder ()
@@ -275,7 +300,7 @@ class MainActivity : AppCompatActivity() {
275300 Log .w(" handleIntent" , " NOT IMPLEMENTED" )
276301 }
277302 } else {
278- showPreview(fileUri, type )
303+ showPreview(fileUri)
279304 }
280305
281306 } else if (Intent .ACTION_SEND_MULTIPLE == action) {
@@ -293,18 +318,7 @@ class MainActivity : AppCompatActivity() {
293318 Log .w(" handleIntent" , " fileUris is null" )
294319 return
295320 }
296- // fileUris.sort()
297- // Log.d("handleIntent", "fileUris: $fileUris")
298- val bundle = Bundle ()
299- bundle.putParcelableArrayList(" fileUris" , fileUris)
300-
301- navController.popBackStack(R .id.nav_graph, true )
302- navController.navigate(
303- R .id.nav_item_upload_multi, bundle, NavOptions .Builder ()
304- .setPopUpTo(R .id.nav_item_home, true )
305- .setLaunchSingleTop(true )
306- .build()
307- )
321+ showMultiPreview(fileUris)
308322
309323 } else if (Intent .ACTION_VIEW == action) {
310324 Log .d(" handleIntent" , " ACTION_VIEW" )
@@ -330,58 +344,72 @@ class MainActivity : AppCompatActivity() {
330344 }
331345 } else {
332346 Log .d(" handleIntent" , " File URI: $data " )
333- showPreview(data, type )
347+ showPreview(data)
334348 }
335349 } else {
336350 Toast .makeText(this , " That's a Bug!" , Toast .LENGTH_LONG ).show()
337351 Log .e(" handleIntent" , " BUG: UNKNOWN action: $action " )
338352 }
339353 }
340354
341- private fun showPreview (uri : Uri ? , type : String? ) {
342- Log .d(" Main[showPreview]" , " $type - $uri " )
355+ // private fun navigateIntent(destination: Int){
356+ // val args = Bundle().apply { putParcelable("intent", intent) }
357+ // Log.d("Main[onCreate]", "args: $args")
358+ // navController.popBackStack(R.id.nav_graph, true)
359+ // navController.navigate(
360+ // destination, args, NavOptions.Builder()
361+ // .setPopUpTo(R.id.nav_item_home, true)
362+ // .setLaunchSingleTop(true)
363+ // .build()
364+ // )
365+ // }
366+
367+ private fun showMultiPreview (fileUris : ArrayList <Uri >) {
368+ Log .d(" Main[showMultiPreview]" , " fileUris: $fileUris " )
369+ // fileUris.sort()
343370 binding.drawerLayout.closeDrawers()
344- val bundle = Bundle ().apply {
345- putString(" uri" , uri.toString())
346- putString(" type" , type)
347- }
348- // TODO: Determine how to properly navigate on new intent...
349- // navController.navigate(R.id.nav_item_preview, bundle)
371+ val bundle = Bundle ().apply { putParcelableArrayList(" fileUris" , fileUris) }
372+ navController.popBackStack(R .id.nav_graph, true )
373+ navController.navigate(
374+ R .id.nav_item_upload_multi, bundle, NavOptions .Builder ()
375+ .setPopUpTo(R .id.nav_item_home, true )
376+ .setLaunchSingleTop(true )
377+ .build()
378+ )
379+ }
350380
381+ private fun showPreview (uri : Uri ? ) {
382+ Log .d(" Main[showPreview]" , " uri: $uri " )
383+ binding.drawerLayout.closeDrawers()
384+ val bundle = Bundle ().apply { putString(" uri" , uri.toString()) }
351385 navController.popBackStack(R .id.nav_graph, true )
352386 navController.navigate(
353387 R .id.nav_item_upload, bundle, NavOptions .Builder ()
354388 .setPopUpTo(R .id.nav_item_home, true )
355389 .setLaunchSingleTop(true )
356390 .build()
357391 )
358-
359- // val navOptions = NavOptions.Builder()
360- // .setPopUpTo(R.id.nav_item_home, false)
361- // .setLaunchSingleTop(true)
362- // .build()
363- // navController.navigate(R.id.nav_item_preview, bundle, navOptions)
364392 }
365393
366394 private fun processOauth (data : Uri ) {
367395 // TODO: Can do this in a fragment to show loading screen/errors eventually...
368- Log .d(" handleIntent " , " processOauth: data: $data " )
396+ Log .d(" processOauth " , " processOauth: data: $data " )
369397 val token = data.getQueryParameter(" token" )
370398 val sessionKey = data.getQueryParameter(" session_key" )
371399 val error = data.getQueryParameter(" error" )
372400
373401 // TODO: Handle null data and errors
374- Log .d(" handleIntent " , " token: $token " )
375- Log .d(" handleIntent " , " session_key: $sessionKey " )
376- Log .d(" handleIntent " , " error: $error " )
402+ Log .d(" processOauth " , " token: $token " )
403+ Log .d(" processOauth " , " session_key: $sessionKey " )
404+ Log .d(" processOauth " , " error: $error " )
377405
378406 // TODO: Determine how to better get oauthUrl
379407 val sharedPreferences = this .getSharedPreferences(" AppPreferences" , MODE_PRIVATE )
380408 val oauthUrl = sharedPreferences.getString(" oauth_host" , null )
381- Log .d(" handleIntent " , " oauthUrl: $oauthUrl " )
409+ Log .d(" processOauth " , " oauthUrl: $oauthUrl " )
382410 if (oauthUrl == null ) {
383411 // TODO: Handle this error...
384- Log .e(" handleIntent " , " oauthUrl is null" )
412+ Log .e(" processOauth " , " oauthUrl is null" )
385413 return
386414 }
387415
@@ -400,14 +428,14 @@ class MainActivity : AppCompatActivity() {
400428 val cookieManager = CookieManager .getInstance()
401429 // cookieManager.setAcceptThirdPartyCookies(webView, true)
402430 val cookie = " sessionid=$sessionKey ; Path=/; HttpOnly; Secure"
403- Log .d(" handleIntent " , " cookie: $cookie " )
431+ Log .d(" processOauth " , " cookie: $cookie " )
404432
405433 val uri = oauthUrl.toUri()
406434 val origin = " ${uri.scheme} ://${uri.authority} "
407- Log .d(" handleIntent " , " origin: $origin " )
435+ Log .d(" processOauth " , " origin: $origin " )
408436 cookieManager.setCookie(origin, cookie) { cookieManager.flush() }
409437
410- Log .d(" handleIntent " , " navigate: nav_item_home - setPopUpTo: nav_item_login" )
438+ Log .d(" processOauth " , " navigate: nav_item_home - setPopUpTo: nav_item_login" )
411439 setDrawerLockMode(true )
412440 navController.navigate(
413441 R .id.nav_item_home, null , NavOptions .Builder ()
@@ -438,7 +466,6 @@ class MainActivity : AppCompatActivity() {
438466 Log .d(" processLogout" , " NO MORE SERVERS - LOCK TO LOGIN" )
439467 // (requireActivity() as MainActivity).setDrawerLockMode(false)
440468 setDrawerLockMode(false )
441- // TODO: Confirm this removes history and locks user to login
442469 navController.navigate(
443470 R .id.nav_item_login, null , NavOptions .Builder ()
444471 .setPopUpTo(R .id.nav_item_home, true )
0 commit comments