forked from TeamAmaze/AmazeFileManager
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Add context menu "Open in Terminal" option
Fixes TeamAmaze#2666
- Loading branch information
1 parent
bdc86af
commit 006b4c9
Showing
14 changed files
with
476 additions
and
1 deletion.
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
105 changes: 105 additions & 0 deletions
105
app/src/main/java/com/amaze/filemanager/ui/dialogs/AbstractChooseAppToOpenFragment.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,105 @@ | ||
package com.amaze.filemanager.ui.dialogs | ||
|
||
import android.content.SharedPreferences | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.preference.PreferenceManager | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.amaze.filemanager.R | ||
import com.amaze.filemanager.adapters.AppsRecyclerAdapter | ||
import com.amaze.filemanager.adapters.data.AppDataParcelable | ||
import com.amaze.filemanager.adapters.glide.AppsAdapterPreloadModel | ||
import com.amaze.filemanager.adapters.holders.AppHolder | ||
import com.amaze.filemanager.databinding.FragmentOpenFileDialogBinding | ||
import com.amaze.filemanager.ui.activities.MainActivity | ||
import com.amaze.filemanager.ui.base.BaseBottomSheetFragment | ||
import com.amaze.filemanager.ui.fragments.AdjustListViewForTv | ||
import com.amaze.filemanager.utils.GlideConstants | ||
import com.bumptech.glide.Glide | ||
import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader | ||
import com.bumptech.glide.util.ViewPreloadSizeProvider | ||
|
||
abstract class AbstractChooseAppToOpenFragment : | ||
BaseBottomSheetFragment(), | ||
AdjustListViewForTv<AppHolder> { | ||
|
||
protected var fragmentOpenFileDialogBinding: FragmentOpenFileDialogBinding? = null | ||
protected val viewBinding get() = fragmentOpenFileDialogBinding!! | ||
|
||
private lateinit var adapter: AppsRecyclerAdapter | ||
private lateinit var sharedPreferences: SharedPreferences | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setStyle(STYLE_NORMAL, R.style.appBottomSheetDialogTheme) | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle?, | ||
): View? { | ||
fragmentOpenFileDialogBinding = FragmentOpenFileDialogBinding.inflate(inflater) | ||
initDialogResources(viewBinding.parent) | ||
return viewBinding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
val modelProvider = AppsAdapterPreloadModel(this, true) | ||
val sizeProvider = ViewPreloadSizeProvider<String>() | ||
val preloader = RecyclerViewPreloader( | ||
Glide.with(this), | ||
modelProvider, | ||
sizeProvider, | ||
GlideConstants.MAX_PRELOAD_FILES, | ||
) | ||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) | ||
|
||
val appDataParcelableList = loadAppList() | ||
|
||
adapter = AppsRecyclerAdapter( | ||
this, | ||
modelProvider, | ||
true, | ||
this, | ||
appDataParcelableList, | ||
) | ||
loadViews() | ||
viewBinding.appsRecyclerView.addOnScrollListener(preloader) | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
fragmentOpenFileDialogBinding = null | ||
} | ||
|
||
override fun onPause() { | ||
super.onPause() | ||
dismiss() | ||
} | ||
|
||
private fun loadViews() { | ||
viewBinding.run { | ||
appsRecyclerView.layoutManager = LinearLayoutManager(requireContext()) | ||
appsRecyclerView.adapter = adapter | ||
doLoadViewsWith(this) | ||
} | ||
} | ||
|
||
protected open fun doLoadViewsWith(viewBinding: FragmentOpenFileDialogBinding) = Unit | ||
|
||
protected abstract fun loadAppList(): MutableList<AppDataParcelable> | ||
|
||
protected abstract fun initLastAppData( | ||
lastClassAndPackage: List<String>?, | ||
appDataParcelableList: MutableList<AppDataParcelable>, | ||
): AppDataParcelable? | ||
|
||
override fun adjustListViewForTv(viewHolder: AppHolder, mainActivity: MainActivity) { | ||
// do nothing | ||
} | ||
} |
Oops, something went wrong.