Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Add the ability to open a file in a external application #442

Merged
merged 10 commits into from Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.blankj.utilcode.util.ClipboardUtils
import com.blankj.utilcode.util.FileIOUtils
import com.blankj.utilcode.util.FileUtils
import com.blankj.utilcode.util.IntentUtils
import com.itsaky.androidide.utils.IntentUtils.shareFile
import com.itsaky.androidide.EditorActivity
import com.itsaky.androidide.R
import com.itsaky.androidide.R.string
Expand Down Expand Up @@ -84,6 +85,7 @@ class FileTreeActionHandler : BaseEventHandler() {
const val ID_DELETE_FILE = 2
const val ID_NEW_FILE = 3
const val ID_NEW_FOLDER = 4
const val ID_OPEN_WITH = 5
}

@Subscribe(threadMode = MAIN)
Expand Down Expand Up @@ -137,6 +139,7 @@ class FileTreeActionHandler : BaseEventHandler() {
ID_DELETE_FILE -> delete(context, file)
ID_NEW_FILE -> createNewFile(context, file)
ID_NEW_FOLDER -> createNewFolder(context, file)
ID_OPEN_WITH -> openWith(context, file)
}
}

Expand All @@ -157,9 +160,17 @@ class FileTreeActionHandler : BaseEventHandler() {
)
}

if (file.isFile) {
fragment.addOption(SheetOption(ID_OPEN_WITH, R.drawable.ic_open_with, string.open_with, file))
}

return fragment
}

private fun openWith(context: Context, file: File) {
shareFile(context, file, "*/*")
}

private fun createNewFile(context: Context, file: File) {
createNewFile(context, file, false)
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_open_with.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:fillColor="#ffffff"
android:pathData="M24,44 L15.85,35.85 18.05,33.65 22.5,38.1V28.65H25.5V38.1L29.95,33.65L32.15,35.85ZM11.9,31.9 L4,24 11.95,16.05 14.15,18.25 9.9,22.5H19.35V25.5H9.9L14.1,29.7ZM36.1,31.9 L33.9,29.7 38.1,25.5H28.7V22.5H38.1L33.9,18.3L36.1,16.1L44,24ZM22.5,19.3V9.9L18.3,14.1L16.1,11.9L24,4L31.9,11.9L29.7,14.1L25.5,9.9V19.3Z"/>
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
<string name="msg_checking_storage_permissions">Проверка разрешений на взаимодействие с памятью</string>
<string name="msg_storage_denied">Невозможно без разрешения на взаимодействие с памятью</string>
<string name="msg_storage_granted">Разрешение на взаимодействие с памятью получено!</string>
<string name="open_with">Открыть с помощью...</string>

<!-- Code Editor -->
<string name="undo">Отмена действия</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
<string name="msg_failed_list_files">Failed to list project files!</string>
<string name="msg_storage_denied">Can\'t proceed without storage permissions</string>
<string name="msg_storage_granted">Storage permissions granted!</string>
<string name="open_with">Open with...</string>

<!-- Code Editor -->
<string name="undo">Undo</string>
Expand Down