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 5, 2024
1 parent bdc86af commit 7214c84
Show file tree
Hide file tree
Showing 30 changed files with 1,672 additions and 461 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<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-feature
android:name="android.hardware.touchscreen"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class AppsRecyclerAdapter(
private val isBottomSheet: Boolean,
private val adjustListViewCallback: AdjustListViewForTv<AppHolder>,
private val appDataParcelableList: MutableList<AppDataParcelable>,
private val onClickRowAction: ((AppDataParcelable) -> Unit)? = null,
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private val myChecked = SparseBooleanArray()
private var appDataListItem: MutableList<ListItem> = mutableListOf()
Expand Down Expand Up @@ -209,7 +210,11 @@ class AppsRecyclerAdapter(
holder.rl.isClickable = true
holder.rl.nextFocusRightId = holder.about.id
holder.rl.setOnClickListener {
startActivityForRowItem(rowItem)
if (onClickRowAction != null) {
onClickRowAction.invoke(rowItem)
} else {
startActivityForRowItem(rowItem)
}
}
}
if (myChecked[position]) {
Expand Down Expand Up @@ -508,7 +513,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
11 changes: 11 additions & 0 deletions app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
import io.reactivex.schedulers.Schedulers;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import kotlin.Deprecated;
import kotlin.ReplaceWith;
import kotlin.collections.ArraysKt;
import kotlin.io.ByteStreamsKt;
import kotlin.text.Charsets;
Expand Down Expand Up @@ -607,6 +609,9 @@ public String getParent(Context context) {
*
* @deprecated use {@link #isDirectory(Context)} to handle content resolvers
*/
@Deprecated(
replaceWith = @ReplaceWith(expression = "isDirectory(Context)", imports = ""),
message = "")
public boolean isDirectory() {
boolean isDirectory;
switch (mode) {
Expand Down Expand Up @@ -701,6 +706,9 @@ public Boolean execute(@NonNull SFTPClient client) {
/**
* @deprecated use {@link #folderSize(Context)}
*/
@Deprecated(
replaceWith = @ReplaceWith(expression = "folderSize(Context)", imports = ""),
message = "")
public long folderSize() {
long size = 0L;

Expand Down Expand Up @@ -1060,6 +1068,9 @@ public FTPFile[] executeWithFtpClient(@NonNull FTPClient ftpClient)
*
* @deprecated use forEachChildrenFile()
*/
@Deprecated(
replaceWith = @ReplaceWith(expression = "forEachChildrenFile", imports = ""),
message = "")
public ArrayList<HybridFileParcelable> listFiles(Context context, boolean isRoot) {
ArrayList<HybridFileParcelable> arrayList = new ArrayList<>();
forEachChildrenFile(context, isRoot, arrayList::add);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
import androidx.annotation.Nullable;
import androidx.documentfile.provider.DocumentFile;

import kotlin.Deprecated;
import kotlin.ReplaceWith;

/**
* Created by vishal on 19/4/17.
*
Expand All @@ -73,6 +76,7 @@ public class CloudUtil {
/**
* @deprecated use getCloudFiles()
*/
@Deprecated(replaceWith = @ReplaceWith(expression = "getCloudFiles", imports = ""), message = "")
public static ArrayList<HybridFileParcelable> listFiles(
String path, CloudStorage cloudStorage, OpenMode openMode) throws CloudPluginException {
final ArrayList<HybridFileParcelable> baseFiles = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,11 @@ public static void installApk(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& !permissionsActivity.getPackageManager().canRequestPackageInstalls()) {
permissionsActivity.requestInstallApkPermission(
() -> installApk(f, permissionsActivity), true);
() -> {
installApk(f, permissionsActivity);
return null;
},
true);
}

Intent intent = new Intent(Intent.ACTION_VIEW);
Expand Down
4 changes: 4 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,6 +37,7 @@
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;
Expand Down Expand Up @@ -256,6 +257,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 @@ -210,7 +210,9 @@
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import kotlin.Unit;
import kotlin.collections.ArraysKt;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.text.Charsets;

Expand All @@ -220,7 +222,7 @@ public class MainActivity extends PermissionsActivity
CloudConnectionCallbacks,
LoaderManager.LoaderCallbacks<Cursor>,
FolderChooserDialog.FolderCallback,
PermissionsActivity.OnPermissionGranted {
Function0<Unit> {

private static final Logger LOG = LoggerFactory.getLogger(MainActivity.class);

Expand Down Expand Up @@ -530,9 +532,8 @@ public void invalidateFragmentAndBundle(Bundle savedInstanceState, boolean isClo
}
}

@Override
@SuppressLint("CheckResult")
public void onPermissionGranted() {
public Unit invoke() {
drawer.refreshDrawer();
TabFragment tabFragment = getTabFragment();
boolean b = getBoolean(PREFERENCE_NEED_TO_SET_HOME);
Expand Down Expand Up @@ -561,6 +562,7 @@ public void onPermissionGranted() {
if (main1 != null) ((MainFragment) main1).updateList(false);
}
}
return null;
}

private void checkForExternalPermission() {
Expand Down Expand Up @@ -1120,6 +1122,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 +1136,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 +1160,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 @@ -1291,6 +1296,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
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 @@ -17,32 +17,25 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.amaze.filemanager.ui.activities.superclasses

package com.amaze.filemanager.ui.activities.superclasses;
import androidx.appcompat.app.AppCompatActivity
import com.amaze.filemanager.application.AppConfig
import com.amaze.filemanager.ui.colors.ColorPreferenceHelper
import com.amaze.filemanager.ui.provider.UtilitiesProvider
import com.amaze.filemanager.ui.theme.AppTheme

import com.amaze.filemanager.application.AppConfig;
import com.amaze.filemanager.ui.colors.ColorPreferenceHelper;
import com.amaze.filemanager.ui.provider.UtilitiesProvider;
import com.amaze.filemanager.ui.theme.AppTheme;
/** Created by rpiotaix on 17/10/16. */
open class BasicActivity : AppCompatActivity() {
private val appConfig: AppConfig
get() = application as AppConfig

import androidx.appcompat.app.AppCompatActivity;
val colorPreference: ColorPreferenceHelper
get() = appConfig.utilsProvider.colorPreference

/** Created by rpiotaix on 17/10/16. */
public class BasicActivity extends AppCompatActivity {
val appTheme: AppTheme
get() = appConfig.utilsProvider.appTheme

protected AppConfig getAppConfig() {
return (AppConfig) getApplication();
}

public ColorPreferenceHelper getColorPreference() {
return getAppConfig().getUtilsProvider().getColorPreference();
}

public AppTheme getAppTheme() {
return getAppConfig().getUtilsProvider().getAppTheme();
}

public UtilitiesProvider getUtilsProvider() {
return getAppConfig().getUtilsProvider();
}
val utilsProvider: UtilitiesProvider
get() = appConfig.utilsProvider
}
Loading

0 comments on commit 7214c84

Please sign in to comment.