-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Add document manager shortcut and use it for Android/{data,…
…obb}. Fixes: #845
- Loading branch information
Showing
22 changed files
with
443 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
app/src/main/java/me/zhanghai/android/files/storage/AddDocumentManagerShortcutActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2023 Hai Zhang <dreaming.in.code.zh@gmail.com> | ||
* All Rights Reserved. | ||
*/ | ||
|
||
package me.zhanghai.android.files.storage | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.fragment.app.commit | ||
import me.zhanghai.android.files.app.AppActivity | ||
import me.zhanghai.android.files.util.args | ||
import me.zhanghai.android.files.util.putArgs | ||
|
||
class AddDocumentManagerShortcutActivity : AppActivity() { | ||
private val args by args<AddDocumentManagerShortcutFragment.Args>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
// Calls ensureSubDecor(). | ||
findViewById<View>(android.R.id.content) | ||
if (savedInstanceState == null) { | ||
val fragment = AddDocumentManagerShortcutFragment().putArgs(args) | ||
supportFragmentManager.commit { | ||
add(fragment, AddDocumentManagerShortcutFragment::class.java.name) | ||
} | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
app/src/main/java/me/zhanghai/android/files/storage/AddDocumentManagerShortcutFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2023 Hai Zhang <dreaming.in.code.zh@gmail.com> | ||
* All Rights Reserved. | ||
*/ | ||
|
||
package me.zhanghai.android.files.storage | ||
|
||
import android.os.Bundle | ||
import androidx.annotation.StringRes | ||
import androidx.fragment.app.Fragment | ||
import kotlinx.parcelize.Parcelize | ||
import me.zhanghai.android.files.R | ||
import me.zhanghai.android.files.app.packageManager | ||
import me.zhanghai.android.files.file.DocumentUri | ||
import me.zhanghai.android.files.util.ParcelableArgs | ||
import me.zhanghai.android.files.util.args | ||
import me.zhanghai.android.files.util.createDocumentManagerViewDirectoryIntent | ||
import me.zhanghai.android.files.util.finish | ||
import me.zhanghai.android.files.util.showToast | ||
|
||
class AddDocumentManagerShortcutFragment : Fragment() { | ||
private val args by args<Args>() | ||
|
||
override fun onActivityCreated(savedInstanceState: Bundle?) { | ||
super.onActivityCreated(savedInstanceState) | ||
|
||
val uri = args.uri | ||
val hasDocumentManager = uri.value.createDocumentManagerViewDirectoryIntent() | ||
.resolveActivity(packageManager) != null | ||
if (hasDocumentManager) { | ||
val documentManagerShortcut = DocumentManagerShortcut( | ||
null, args.customNameRes?.let { getString(it) }, uri | ||
) | ||
Storages.addOrReplace(documentManagerShortcut) | ||
} else { | ||
showToast(R.string.activity_not_found) | ||
} | ||
finish() | ||
} | ||
|
||
@Parcelize | ||
class Args( | ||
@StringRes val customNameRes: Int?, | ||
val uri: DocumentUri | ||
) : ParcelableArgs | ||
} |
Oops, something went wrong.