Skip to content

Commit

Permalink
[WIP] Add context menu "Open in Terminal" option
Browse files Browse the repository at this point in the history
  • Loading branch information
TranceLove committed Jul 1, 2024
1 parent bdc86af commit 5b50f6e
Show file tree
Hide file tree
Showing 14 changed files with 555 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="com.termux.permission.RUN_COMMAND" />
<uses-permission android:name="com.termoneplus.permission.RUN_SCRIPT" />

<uses-permission android:name="jackpal.androidterm.permission.RUN_SCRIPT" />
<uses-permission android:name="com.termoneplus.permission.RUN_SCRIPT" />
<uses-permission android:name="yarolegovich.materialterminal.permission.RUN_SCRIPT" />

<uses-feature
android:name="android.hardware.touchscreen"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class AppsRecyclerAdapter(
MaterialDialog.Builder(fragment.requireContext())
builder1
.theme(
themedActivity.appTheme.getMaterialDialogTheme(),
themedActivity.appTheme.materialDialogTheme,
)
.content(fragment.getString(R.string.unin_system_apk))
.title(fragment.getString(R.string.warning))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1435,13 +1435,15 @@ private void showPopup(@NonNull View view, @NonNull final LayoutElementParcelabl
if (rowItem.isDirectory) {
popupMenu.getMenu().findItem(R.id.open_with).setVisible(false);
popupMenu.getMenu().findItem(R.id.share).setVisible(false);
popupMenu.getMenu().findItem(R.id.open_in_terminal).setVisible(true);

if (mainFragment.getMainActivity().mReturnIntent) {
popupMenu.getMenu().findItem(R.id.return_select).setVisible(true);
}
} else {
popupMenu.getMenu().findItem(R.id.book).setVisible(false);
popupMenu.getMenu().findItem(R.id.compress).setVisible(true);
popupMenu.getMenu().findItem(R.id.open_in_terminal).setVisible(false);

if (description.endsWith(fileExtensionZip)
|| description.endsWith(fileExtensionJar)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/amaze/filemanager/ui/ItemPopupMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
import com.amaze.filemanager.ui.dialogs.EncryptAuthenticateDialog;
import com.amaze.filemanager.ui.dialogs.EncryptWithPresetPasswordSaveAsDialog;
import com.amaze.filemanager.ui.dialogs.GeneralDialogCreation;
import com.amaze.filemanager.ui.dialogs.OpenFolderInTerminalFragment;
import com.amaze.filemanager.ui.fragments.MainFragment;
import com.amaze.filemanager.ui.fragments.preferencefragments.PreferencesConstants;
import com.amaze.filemanager.ui.provider.UtilitiesProvider;
import com.amaze.filemanager.utils.DataUtils;
import com.amaze.filemanager.utils.OpenTerminalUtilsExtKt;

import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -256,6 +258,9 @@ public void onButtonPressed(Intent intent, String password)
case R.id.return_select:
mainFragment.returnIntentResults(new HybridFileParcelable[] {rowItem.generateBaseFile()});
return true;
case R.id.open_in_terminal:
OpenFolderInTerminalFragment.Companion.openTerminalOrShow(rowItem.desc, mainActivity);
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.hiddenitems).setVisible(true);
menu.findItem(R.id.view).setVisible(true);
menu.findItem(R.id.extract).setVisible(false);
menu.findItem(R.id.open_in_terminal).setVisible(true);
invalidatePasteSnackbar(true);
findViewById(R.id.buttonbarframe).setVisibility(View.VISIBLE);
} else if (fragment instanceof AppsListFragment
Expand All @@ -1133,6 +1134,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.home).setVisible(false);
menu.findItem(R.id.history).setVisible(false);
menu.findItem(R.id.extract).setVisible(false);
menu.findItem(R.id.open_in_terminal).setVisible(false);
if (fragment instanceof ProcessViewerFragment) {
menu.findItem(R.id.sort).setVisible(false);
} else if (fragment instanceof FtpServerFragment) {
Expand All @@ -1156,6 +1158,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.hiddenitems).setVisible(false);
menu.findItem(R.id.view).setVisible(false);
menu.findItem(R.id.extract).setVisible(true);
menu.findItem(R.id.open_in_terminal).setVisible(false);
invalidatePasteSnackbar(false);
}
return super.onPrepareOptionsMenu(menu);
Expand Down Expand Up @@ -1292,6 +1295,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.search:
getAppbar().getSearchView().revealSearchView();
break;
case R.id.open_in_terminal:
if (getFragmentAtFrame() instanceof MainFragment) {

}
break;
}
return null;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ public void requestInstallApkPermission(
isInitialStart);
}

public void requestTerminalPermission() {

}

/**
* Requests permission, overrides {@param rationale}'s POSITIVE button dialog action.
*
Expand Down
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
}
}
Loading

0 comments on commit 5b50f6e

Please sign in to comment.