Skip to content

Commit ffa691e

Browse files
committed
fix #129, allow creating folder shortcuts
1 parent d08165e commit ffa691e

File tree

9 files changed

+74
-2
lines changed

9 files changed

+74
-2
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ android {
5151
}
5252

5353
dependencies {
54-
implementation 'com.simplemobiletools:commons:5.12.10'
54+
implementation 'com.simplemobiletools:commons:5.12.11'
5555
implementation 'com.github.Stericson:RootTools:df729dcb13'
5656
implementation 'com.github.Stericson:RootShell:1.6'
5757
implementation 'com.alexvasilkov:gesture-views:2.5.2'

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/SplashActivity.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ class SplashActivity : BaseSplashActivity() {
77
override fun getAppPackageName() = packageName
88

99
override fun initActivity() {
10-
startActivity(Intent(this, MainActivity::class.java))
10+
if (intent.action == Intent.ACTION_VIEW && intent.data != null) {
11+
Intent(this, MainActivity::class.java).apply {
12+
action = Intent.ACTION_VIEW
13+
data = intent.data
14+
startActivity(this)
15+
}
16+
} else {
17+
startActivity(Intent(this, MainActivity::class.java))
18+
}
1119
finish()
1220
}
1321
}

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
package com.simplemobiletools.filemanager.pro.adapters
22

3+
import android.annotation.SuppressLint
4+
import android.app.PendingIntent
35
import android.content.ClipData
46
import android.content.ClipboardManager
57
import android.content.Context
8+
import android.content.Intent
69
import android.content.pm.PackageManager
10+
import android.content.pm.ShortcutInfo
11+
import android.content.pm.ShortcutManager
712
import android.graphics.drawable.Drawable
13+
import android.graphics.drawable.Icon
14+
import android.graphics.drawable.LayerDrawable
15+
import android.net.Uri
816
import android.view.Menu
917
import android.view.View
1018
import android.view.ViewGroup
@@ -17,12 +25,14 @@ import com.simplemobiletools.commons.dialogs.*
1725
import com.simplemobiletools.commons.extensions.*
1826
import com.simplemobiletools.commons.helpers.CONFLICT_OVERWRITE
1927
import com.simplemobiletools.commons.helpers.CONFLICT_SKIP
28+
import com.simplemobiletools.commons.helpers.isNougatMR1Plus
2029
import com.simplemobiletools.commons.models.FileDirItem
2130
import com.simplemobiletools.commons.models.RadioItem
2231
import com.simplemobiletools.commons.views.FastScroller
2332
import com.simplemobiletools.commons.views.MyRecyclerView
2433
import com.simplemobiletools.filemanager.pro.R
2534
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
35+
import com.simplemobiletools.filemanager.pro.activities.SplashActivity
2636
import com.simplemobiletools.filemanager.pro.dialogs.CompressAsDialog
2737
import com.simplemobiletools.filemanager.pro.extensions.*
2838
import com.simplemobiletools.filemanager.pro.helpers.*
@@ -67,6 +77,7 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
6777
findItem(R.id.cab_open_with).isVisible = isOneFileSelected()
6878
findItem(R.id.cab_open_as).isVisible = isOneFileSelected()
6979
findItem(R.id.cab_set_as).isVisible = isOneFileSelected()
80+
findItem(R.id.cab_create_shortcut).isVisible = isNougatMR1Plus() && isOneItemSelected() && File(getFirstSelectedItemPath()).isDirectory
7081

7182
checkHideBtnVisibility(this)
7283
}
@@ -84,6 +95,7 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
8495
R.id.cab_share -> shareFiles()
8596
R.id.cab_hide -> toggleFileVisibility(true)
8697
R.id.cab_unhide -> toggleFileVisibility(false)
98+
R.id.cab_create_shortcut -> createShortcut()
8799
R.id.cab_copy_path -> copyPath()
88100
R.id.cab_set_as -> setAs()
89101
R.id.cab_open_with -> openWith()
@@ -216,6 +228,37 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
216228
}.start()
217229
}
218230

231+
@SuppressLint("NewApi")
232+
private fun createShortcut() {
233+
val manager = activity.getSystemService(ShortcutManager::class.java)
234+
if (manager.isRequestPinShortcutSupported) {
235+
val path = getFirstSelectedItemPath()
236+
237+
val appIconColor = baseConfig.appIconColor
238+
val drawable = resources.getDrawable(R.drawable.shortcut_folder)
239+
(drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_folder_background).applyColorFilter(appIconColor)
240+
val bmp = drawable.convertToBitmap()
241+
242+
val intent = Intent(activity, SplashActivity::class.java)
243+
intent.action = Intent.ACTION_VIEW
244+
intent.data = Uri.fromFile(File(path))
245+
246+
val shortcut = ShortcutInfo.Builder(activity, path)
247+
.setShortLabel(path.getFilenameFromPath())
248+
.setIcon(Icon.createWithBitmap(bmp))
249+
.setIntent(intent)
250+
.build()
251+
252+
manager.dynamicShortcuts = Arrays.asList(shortcut)
253+
254+
val pinShortcutInfo = ShortcutInfo.Builder(activity, path).build()
255+
val pinnedShortcutCallbackIntent = manager.createShortcutResultIntent(pinShortcutInfo)
256+
257+
val successCallback = PendingIntent.getBroadcast(activity, 0, pinnedShortcutCallbackIntent, 0)
258+
manager.requestPinShortcut(pinShortcutInfo, successCallback.intentSender)
259+
}
260+
}
261+
219262
private fun addFileUris(path: String, paths: ArrayList<String>) {
220263
if (File(path).isDirectory) {
221264
val shouldShowHidden = activity.config.shouldShowHidden
179 Bytes
Loading
243 Bytes
Loading
267 Bytes
Loading
457 Bytes
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:id="@+id/shortcut_folder_background">
4+
<shape android:shape="oval">
5+
<solid android:color="@color/color_primary"/>
6+
</shape>
7+
</item>
8+
9+
<item
10+
android:id="@+id/shortcut_folder_image"
11+
android:bottom="@dimen/medium_margin"
12+
android:drawable="@drawable/ic_folder_big"
13+
android:left="@dimen/medium_margin"
14+
android:right="@dimen/medium_margin"
15+
android:top="@dimen/medium_margin"/>
16+
17+
</layer-list>

app/src/main/res/menu/cab.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
android:icon="@drawable/ic_unhide"
3232
android:title="@string/unhide"
3333
app:showAsAction="ifRoom"/>
34+
<item
35+
android:id="@+id/cab_create_shortcut"
36+
android:title="@string/create_shortcut"
37+
app:showAsAction="never"/>
3438
<item
3539
android:id="@+id/cab_copy_path"
3640
android:title="@string/copy_path"

0 commit comments

Comments
 (0)