Skip to content

Commit 3026757

Browse files
authored
Minor Fixes (#38)
1 parent 87fccb5 commit 3026757

File tree

10 files changed

+226
-161
lines changed

10 files changed

+226
-161
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,25 @@ Additionally, the URL is copied to the clipboard and the preview show in the app
8686
8787
## Features
8888

89-
- Share or Open any file and automatically copy the URL to the clipboard.
90-
- Ability to add multiple servers and switch on the fly from the Server List menu.
89+
- Share or Open any files and automatically copy the URL to the clipboard.
90+
- Upload Previews for Media with File Selector when uploading multiple files.
91+
- Native File List with Options, Infinite Scroll, and Live Previews for Media.
9192
- Supports Native Local Login, GitHub OAuth, Google OAuth, and Discord OAuth.
92-
- Native Upload feature from Navigation Drawer and Upload Shortcut on Icon long press.
93-
- Basic Native File List with Open, Share, Preview, Infinite Scroll, Custom Options.
94-
- File Previews for Images, Video, Audio and Text via Glide, ExoPlayer and Highlight.js.
93+
- Ability to add multiple servers and switch on the fly from the Server List menu.
9594

9695
### Planned
9796

9897
- Add Default Upload Options.
99-
- Add File Options to Preview page.
100-
- Option to Disable Preview Page on Open, Share, and/or for Links.
101-
- Ability to Authenticate if/when your session (cookie) is expired.
98+
- Option to Disable Preview Page.
99+
- Ability to Auto Authenticate when your session expires.
100+
- Upload Preview
101+
- Upload Options
102102
- File List
103103
- Multi-Select with File Options
104104
- Response Caching for Infinite Scroll
105105
- File Preview
106-
- PDF Previews
107106
- File Options
107+
- PDF Previews
108108

109109
### Known Issues
110110

TODO.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TODO
22

3-
- [Authentication](#Authentication)
3+
- [TODO](#TODO)
44
- [Status](#Status)
55

66
## Authentication
@@ -13,8 +13,7 @@ Options for persistent authentication are:
1313
## Upload
1414

1515
- Add Upload Options to Previews
16-
- Enable Multi for Upload Shortcut
17-
- Enable Multi for Upload Menu Option
16+
- Add Support for Plain Text Sharing
1817

1918
## File List
2019

@@ -41,14 +40,34 @@ Options for persistent authentication are:
4140
- Move Room to Directory
4241
- Implement Room Active Server
4342

43+
---
44+
4445
# Status
4546

4647
## Authentication
4748

4849
- Returns a Cookie
4950
- Uses Cookie to get Token
5051

51-
## File List
52+
## Uploads
53+
54+
### File
55+
56+
- File Previews
57+
58+
### Multiple Files
59+
60+
- Image Previews w/ Multi-Select
61+
62+
### URLs
63+
64+
- Preview w/ Vanity Option
65+
66+
### Text
67+
68+
- WIP
69+
70+
## File List/Preview
5271

5372
Total Cache Size: `700` MB
5473

app/src/main/java/com/djangofiles/djangofiles/MainActivity.kt

Lines changed: 81 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)