Skip to content

Commit

Permalink
Fix merge conflicts, fix intent flags to support opening multiple tas…
Browse files Browse the repository at this point in the history
…ks for backward compatibility
  • Loading branch information
VishalNehra committed Sep 6, 2017
2 parents 291adf2 + cf088e2 commit d94a58a
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
package com.amaze.filemanager.activities;

import android.app.ActivityManager;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
Expand All @@ -41,6 +43,7 @@
import com.amaze.filemanager.R;
import com.amaze.filemanager.exceptions.RootNotPermittedException;
import com.amaze.filemanager.fragments.DbViewerFragment;
import com.amaze.filemanager.fragments.preference_fragments.Preffrag;
import com.amaze.filemanager.utils.PreferenceUtils;
import com.amaze.filemanager.utils.RootUtils;
import com.amaze.filemanager.utils.Utils;
Expand Down Expand Up @@ -75,6 +78,7 @@ public void onCreate(Bundle savedInstanceState) {
this.checkStorage = false;
super.onCreate(savedInstanceState);

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);

if (getAppTheme().equals(AppTheme.DARK)) {
setTheme(R.style.appCompatDark);
Expand All @@ -93,7 +97,11 @@ public void onCreate(Bundle savedInstanceState) {
}
getSupportActionBar()
.setBackgroundDrawable(getColorPreference().getDrawable(ColorUsage.getPrimary(MainActivity.currentTab)));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

boolean useNewStack = sharedPref.getBoolean(Preffrag.PREFERENCE_TEXTEDITOR_NEWSTACK, false);

getSupportActionBar().setDisplayHomeAsUpEnabled(!useNewStack);

if (SDK_INT == 20 || SDK_INT == 19) {
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
Expand Down
21 changes: 10 additions & 11 deletions app/src/main/java/com/amaze/filemanager/activities/TextReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import com.amaze.filemanager.exceptions.StreamNotFoundException;
import com.amaze.filemanager.filesystem.BaseFile;
import com.amaze.filemanager.filesystem.FileUtil;
import com.amaze.filemanager.fragments.preference_fragments.Preffrag;
import com.amaze.filemanager.services.asynctasks.SearchTextTask;
import com.amaze.filemanager.ui.dialogs.GeneralDialogCreation;
import com.amaze.filemanager.utils.files.GenericCopyUtil;
Expand Down Expand Up @@ -171,10 +172,12 @@ public void onCreate(Bundle savedInstanceState) {
closeButton.setOnClickListener(this);

getSupportActionBar().setBackgroundDrawable(getColorPreference().getDrawable(ColorUsage.getPrimary(MainActivity.currentTab)));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
int sdk = Build.VERSION.SDK_INT;

if (sdk == Build.VERSION_CODES.KITKAT_WATCH || sdk == Build.VERSION_CODES.KITKAT) {
boolean useNewStack = sharedPref.getBoolean(Preffrag.PREFERENCE_TEXTEDITOR_NEWSTACK, false);

getSupportActionBar().setDisplayHomeAsUpEnabled(!useNewStack);

if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT_WATCH || Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintColor(getColorPreference().getColor(ColorUsage.getPrimary(MainActivity.currentTab)));
Expand Down Expand Up @@ -244,13 +247,8 @@ public void onCreate(Bundle savedInstanceState) {
getSupportActionBar().setTitle(fileName);

mInput.addTextChangedListener(this);
try {
if (getAppTheme().equals(AppTheme.DARK))
mInput.setBackgroundColor(Utils.getColor(this, R.color.holo_dark_background));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} catch (Exception e) {

}
if (getAppTheme().equals(AppTheme.DARK))
mInput.setBackgroundColor(Utils.getColor(this, R.color.holo_dark_background));

mInputTypefaceDefault = mInput.getTypeface();
mInputTypefaceMono = Typeface.MONOSPACE;
Expand Down Expand Up @@ -551,7 +549,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
case R.id.openwith:
if (mFile.exists()) {
getFutils().openunknown(new File(mFile.getPath()), this, false);
boolean useNewStack = sharedPref.getBoolean(Preffrag.PREFERENCE_TEXTEDITOR_NEWSTACK, false);
getFutils().openunknown(new File(mFile.getPath()), this, false, useNewStack);
} else Toast.makeText(this, R.string.not_allowed, Toast.LENGTH_SHORT).show();
break;
case R.id.find:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.LayoutRes;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -32,6 +33,7 @@
public class HiddenAdapter extends RecyclerArrayAdapter<HFile, HiddenAdapter.ViewHolder> {

private Futils utils;
private SharedPreferences sharedPrefs;

private MainFragment context;
private Context c;
Expand All @@ -41,12 +43,14 @@ public class HiddenAdapter extends RecyclerArrayAdapter<HFile, HiddenAdapter.Vie
private DataUtils dataUtils = DataUtils.getInstance();
/// public HashMap<Integer, Boolean> myChecked = new HashMap<Integer, Boolean>();

public HiddenAdapter(Context context, MainFragment mainFrag, Futils utils, @LayoutRes int layoutId,
ArrayList<HFile> items, MaterialDialog materialDialog, boolean hide) {
public HiddenAdapter(Context context, MainFragment mainFrag, Futils utils, SharedPreferences sharedPreferences,
@LayoutRes int layoutId, ArrayList<HFile> items, MaterialDialog materialDialog,
boolean hide) {
addAll(items);
this.utils = utils;
this.c = context;
this.context = mainFrag;
sharedPrefs = sharedPreferences;
this.items = items;
this.hide = hide;
this.materialDialog = materialDialog;
Expand Down Expand Up @@ -124,7 +128,7 @@ public void run() {
context.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
utils.openFile(new File(file.getPath()), (MainActivity) context.getActivity());
utils.openFile(new File(file.getPath()), (MainActivity) context.getActivity(), sharedPrefs);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
Expand Down Expand Up @@ -60,6 +61,7 @@ public class RecyclerAdapter extends RecyclerArrayAdapter<String, RecyclerView.V

private UtilitiesProviderInterface utilsProvider;
private MainFragment mainFrag;
private SharedPreferences sharedPrefs;
private boolean showHeaders;
private ArrayList<ListItem> itemsDigested = new ArrayList<>();
private Context context;
Expand All @@ -70,11 +72,12 @@ public class RecyclerAdapter extends RecyclerArrayAdapter<String, RecyclerView.V
private int offset = 0;


public RecyclerAdapter(MainFragment m, UtilitiesProviderInterface utilsProvider,
public RecyclerAdapter(MainFragment m, UtilitiesProviderInterface utilsProvider, SharedPreferences sharedPrefs,
ArrayList<LayoutElement> itemsRaw, Context context, boolean showHeaders) {
this.mainFrag = m;
this.utilsProvider = utilsProvider;
this.context = context;
this.sharedPrefs = sharedPrefs;
this.showHeaders = showHeaders;

mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
Expand Down Expand Up @@ -742,7 +745,7 @@ private void showPopup(View v, final LayoutElement rowItem, final int position)
@Override
public void onClick(View view) {
PopupMenu popupMenu = new ItemPopupMenu(context, mainFrag.getMainActivity(),
utilsProvider, mainFrag, rowItem, view);
utilsProvider, mainFrag, rowItem, view, sharedPrefs);
popupMenu.inflate(R.menu.item_extras);
String description = rowItem.getDesc().toLowerCase();

Expand Down
101 changes: 43 additions & 58 deletions app/src/main/java/com/amaze/filemanager/fragments/MainFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import com.amaze.filemanager.filesystem.BaseFile;
import com.amaze.filemanager.filesystem.HFile;
import com.amaze.filemanager.filesystem.MediaStoreHack;
import com.amaze.filemanager.fragments.preference_fragments.Preffrag;
import com.amaze.filemanager.services.DeleteTask;
import com.amaze.filemanager.services.asynctasks.LoadList;
import com.amaze.filemanager.ui.LayoutElement;
Expand Down Expand Up @@ -757,7 +758,8 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
mode.finish();
return true;
case R.id.openwith:
Futils.openunknown(new File(checkedItems.get(0).getDesc()), getActivity(), true);
boolean useNewStack = sharedPref.getBoolean(Preffrag.PREFERENCE_TEXTEDITOR_NEWSTACK, false);
Futils.openunknown(new File(checkedItems.get(0).getDesc()), getActivity(), true, useNewStack);
return true;
case R.id.addshortcut:
addShortcut(checkedItems.get(0));
Expand Down Expand Up @@ -814,7 +816,7 @@ public void onReceive(Context context, Intent intent) {
public void onReceive(Context context, Intent intent) {

if (isEncryptOpen && encryptBaseFile != null) {
getMainActivity().getFutils().openFile(new File(encryptBaseFile.getPath()), getMainActivity());
getMainActivity().getFutils().openFile(new File(encryptBaseFile.getPath()), getMainActivity(), sharedPref);
isEncryptOpen = false;
}
}
Expand All @@ -840,9 +842,7 @@ public void onListItemClicked(boolean isBackButton, int position, LayoutElement
SearchWorkerFragment fragment = (SearchWorkerFragment) fragmentManager
.findFragmentByTag(MainActivity.TAG_ASYNC_HELPER);
if (fragment != null) {

if (fragment.mSearchAsyncTask.getStatus() == AsyncTask.Status.RUNNING) {

fragment.mSearchAsyncTask.cancel(true);
}
getActivity().getSupportFragmentManager().beginTransaction().remove(fragment).commit();
Expand All @@ -856,34 +856,30 @@ public void onListItemClicked(boolean isBackButton, int position, LayoutElement
}

if (selection) {
if (!isBackButton) {
// the first {goback} item if back navigation is enabled
adapter.toggleChecked(position, imageView);
} else {
if (isBackButton) {
selection = false;
if (mActionMode != null)
mActionMode.finish();
mActionMode = null;
} else {
// the first {goback} item if back navigation is enabled
adapter.toggleChecked(position, imageView);
}
} else {
if (!isBackButton) {
if(isBackButton) {
goBackItemClick();
} else {
// hiding search view if visible
if (getMainActivity().getAppbar().getSearchView().isEnabled()) {
getMainActivity().getAppbar().getSearchView().hideSearchView();
}

String path;
if (!e.hasSymlink()) {
String path = !e.hasSymlink()? e.getDesc():e.getSymlink();

path = e.getDesc();
} else {

path = e.getSymlink();
}

// check if we're trying to click on encrypted file
if (!e.isDirectory() &&
e.getDesc().endsWith(CryptUtil.CRYPT_EXTENSION)) {
if (e.isDirectory()) {
computeScroll();
loadlist(path, false, openMode);
} else if (e.getDesc().endsWith(CryptUtil.CRYPT_EXTENSION)) {
// decrypt the file
isEncryptOpen = true;

Expand All @@ -894,50 +890,39 @@ public void onListItemClicked(boolean isBackButton, int position, LayoutElement
EncryptDecryptUtils.decryptFile(getContext(), getMainActivity(), ma, openMode,
e.generateBaseFile(), getActivity().getExternalCacheDir().getPath(),
utilsProvider, true);
return;
}

if (e.isDirectory()) {

computeScroll();
loadlist(path, false, openMode);
} else {

if (getMainActivity().mReturnIntent) {
// are we here to return an intent to another app
returnIntentResults(e.generateBaseFile());
return;
}
} else {
switch (e.getMode()) {
case SMB:
try {
SmbFile smbFile = new SmbFile(e.getDesc());
launchSMB(smbFile, e.getlongSize(), getMainActivity());
} catch (MalformedURLException ex) {
ex.printStackTrace();
}
break;
case OTG:
utils.openFile(OTGUtil.getDocumentFile(e.getDesc(), getContext(), false),
(MainActivity) getActivity(), sharedPref);
break;
case DROPBOX:
case BOX:
case GDRIVE:
case ONEDRIVE:
Toast.makeText(getContext(), getResources().getString(R.string.please_wait), Toast.LENGTH_LONG).show();
CloudUtil.launchCloud(e.generateBaseFile(), openMode, getMainActivity());
break;
default:
utils.openFile(new File(e.getDesc()), (MainActivity) getActivity(), sharedPref);
break;
}

switch (e.getMode()) {
case SMB:
try {
SmbFile smbFile = new SmbFile(e.getDesc());
launchSMB(smbFile, e.getlongSize(), getMainActivity());
} catch (MalformedURLException ex) {
ex.printStackTrace();
}
break;
case OTG:
utils.openFile(OTGUtil.getDocumentFile(e.getDesc(), getContext(), false),
(MainActivity) getActivity());
break;
case DROPBOX:
case BOX:
case GDRIVE:
case ONEDRIVE:
Toast.makeText(getContext(), getResources().getString(R.string.please_wait), Toast.LENGTH_LONG).show();
CloudUtil.launchCloud(e.generateBaseFile(), openMode, getMainActivity());
break;
default:
utils.openFile(new File(e.getDesc()), (MainActivity) getActivity());
break;
dataUtils.addHistoryFile(e.getDesc());
}

dataUtils.addHistoryFile(e.getDesc());
}
} else {
goBackItemClick();
}
}
}
Expand Down Expand Up @@ -1153,7 +1138,7 @@ public void createViews(ArrayList<LayoutElement> bitmap, boolean back, String pa
switchToGrid();
else if (!grid && !IS_LIST) switchToList();
if (adapter == null) {
adapter = new RecyclerAdapter(ma, utilsProvider, bitmap, ma.getActivity(), SHOW_HEADERS);
adapter = new RecyclerAdapter(ma, utilsProvider, sharedPref, bitmap, ma.getActivity(), SHOW_HEADERS);
} else {
adapter.setItems(getLayoutElements());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public void onServiceDisconnected(ComponentName name) {
// open most recent entry added to files to be deleted from cache
File cacheFile = new File(files.get(files.size() - 1).getPath());
if (cacheFile != null && cacheFile.exists())
utilsProvider.getFutils().openFile(cacheFile, mainActivity);
utilsProvider.getFutils().openFile(cacheFile, mainActivity, mainActivity.sharedPref);

// reset the flag and cache file, as it's root is already in the list for deletion
isOpen = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ public class Preffrag extends PreferenceFragment implements Preference.OnPrefere
private static final String[] PREFERENCE_KEYS =
{"columns", "theme", "sidebar_folders_enable", "sidebar_quickaccess_enable",
"rootmode", "showHidden", "feedback", PREFERENCE_KEY_ABOUT, "plus_pic", "colors",
"sidebar_folders", "sidebar_quickaccess", "advancedsearch", "typeablepaths"};
"sidebar_folders", "sidebar_quickaccess", "texteditor_newstack", "advancedsearch", "typeablepaths"};


public static final String PREFERENCE_SHOW_SIDEBAR_FOLDERS = "show_sidebar_folders";
public static final String PREFERENCE_SHOW_SIDEBAR_QUICKACCESSES = "show_sidebar_quickaccesses";

public static final String PREFERENCE_TEXTEDITOR_NEWSTACK = "texteditor_newstack";

public static final String PREFERENCE_SHOW_HIDDENFILES = "showHidden";

public static final String PREFERENCE_ROOTMODE = "rootmode";
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/com/amaze/filemanager/ui/ItemPopupMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@ public class ItemPopupMenu extends PopupMenu implements PopupMenu.OnMenuItemClic
private MainActivity mainActivity;
private UtilitiesProviderInterface utilitiesProvider;
private MainFragment mainFragment;
private SharedPreferences sharedPrefs;
private LayoutElement rowItem;
private int accentColor;

public ItemPopupMenu(Context c, MainActivity ma, UtilitiesProviderInterface up, MainFragment mainFragment,
LayoutElement ri, View anchor) {
LayoutElement ri, View anchor, SharedPreferences sharedPreferences) {
super(c, anchor);

context = c;
mainActivity = ma;
utilitiesProvider = up;
this.mainFragment = mainFragment;
sharedPrefs = sharedPreferences;
rowItem = ri;
accentColor = mainActivity.getColorPreference().getColor(ColorUsage.ACCENT);

Expand Down Expand Up @@ -126,7 +128,8 @@ public boolean onMenuItemClick(MenuItem item) {
positions, utilitiesProvider.getAppTheme());
return true;
case R.id.open_with:
Futils.openWith(new File(rowItem.getDesc()), mainFragment.getActivity());
boolean useNewStack = sharedPrefs.getBoolean(Preffrag.PREFERENCE_TEXTEDITOR_NEWSTACK, false);
Futils.openWith(new File(rowItem.getDesc()), mainFragment.getActivity(), useNewStack);
return true;
case R.id.encrypt:
final Intent encryptIntent = new Intent(context, EncryptService.class);
Expand Down
Loading

0 comments on commit d94a58a

Please sign in to comment.