save works

This commit is contained in:
hyb1996
2018-09-17 15:58:10 +08:00
parent 04bffdc425
commit 36e9c9481a
5 changed files with 44 additions and 37 deletions

View File

@@ -100,7 +100,7 @@ public class Pref {
}
public static boolean shouldShowAd() {
if (isFirstDay() && !BuildConfig.DEBUG) {
if (isFirstDay()) {
return false;
}
String adShowingMode = def().getString(getString(R.string.key_ad_showing_mode), "Default");

View File

@@ -30,49 +30,60 @@ public class Explorer {
this(explorerProvider, cacheSize, EventBus.getDefault());
}
public void notifyChildrenChanged(ExplorerPage itemGroup) {
clearCache(itemGroup);
mEventBus.post(new ExplorerChangeEvent(itemGroup));
public void notifyChildrenChanged(ExplorerPage page) {
clearCache(page);
mEventBus.post(new ExplorerChangeEvent(page, CHILDREN_CHANGE, null));
}
public void notifyItemChanged(ExplorerItem oldItem, ExplorerItem newItem) {
ExplorerPage itemGroup = getParentFromCache(oldItem);
if (itemGroup != null) {
itemGroup.updateChild(oldItem, newItem);
ExplorerPage parent = getParent(oldItem);
ExplorerPage cachedParent = getFromCache(parent);
if (cachedParent != null) {
cachedParent.updateChild(oldItem, newItem);
}
mEventBus.post(new ExplorerChangeEvent(oldItem.getParent(), CHANGE, oldItem, newItem));
mEventBus.post(new ExplorerChangeEvent(parent, CHANGE, oldItem, newItem));
}
private ExplorerPage getParentFromCache(ExplorerItem item) {
if (mExplorerPageLruCache == null) {
return null;
}
ExplorerPage parent = item.getParent();
if (parent == null) {
if (item instanceof ExplorerFileItem) {
PFile parentFile = ((ExplorerFileItem) item).getFile().getParentFile();
return parentFile == null ? null : mExplorerPageLruCache.get(parentFile.getPath());
}
private ExplorerPage getFromCache(ExplorerPage parent) {
if(mExplorerPageLruCache == null || parent == null){
return null;
}
return mExplorerPageLruCache.get(parent.getPath());
}
private ExplorerPage getParentFromCache(ExplorerItem item) {
return getFromCache(getParent(item));
}
public void notifyItemRemoved(ExplorerItem item) {
ExplorerPage itemGroup = getParentFromCache(item);
if (itemGroup != null) {
itemGroup.removeChild(item);
ExplorerPage parent = getParent(item);
ExplorerPage cachedParent = getFromCache(parent);
if (cachedParent != null) {
cachedParent.removeChild(item);
}
mEventBus.post(new ExplorerChangeEvent(item.getParent(), REMOVE, item));
mEventBus.post(new ExplorerChangeEvent(parent, REMOVE, item));
}
private ExplorerPage getParent(ExplorerItem item) {
ExplorerPage parent = item.getParent();
if (parent == null) {
if (item instanceof ExplorerFileItem) {
PFile parentFile = ((ExplorerFileItem) item).getFile().getParentFile();
return new ExplorerDirPage(parentFile, null);
}
return null;
}
return parent;
}
public void notifyItemCreated(ExplorerItem item) {
ExplorerPage itemGroup = getParentFromCache(item);
if (itemGroup != null) {
itemGroup.addChild(item);
ExplorerPage parent = getParent(item);
ExplorerPage cachedParent = getFromCache(parent);
if (cachedParent != null) {
cachedParent.addChild(item);
}
mEventBus.post(new ExplorerChangeEvent(item.getParent(), CREATE, item));
mEventBus.post(new ExplorerChangeEvent(parent, CREATE, item));
}
@SuppressWarnings("unchecked")

View File

@@ -6,16 +6,13 @@ public class ExplorerChangeEvent {
public static final int CREATE = 1;
public static final int CHANGE = 2;
public static final int ALL = 3;
public static final int CHILDREN_CHANGE = 4;
private final int mAction;
private final ExplorerItem mItem;
private final ExplorerItem mNewItem;
private final ExplorerPage mPage;
public ExplorerChangeEvent(ExplorerPage page) {
this(page, CHANGE, null, null);
}
public ExplorerChangeEvent(ExplorerPage parent, int action, ExplorerItem oldItem, ExplorerItem newItem) {
mAction = action;
mPage = parent;

View File

@@ -220,10 +220,8 @@ public class ExplorerView extends ThemeColorSwipeRefreshLayout implements SwipeR
@Subscribe
public void onExplorerChange(ExplorerChangeEvent event) {
if (event.getAction() == ExplorerChangeEvent.ALL
|| (event.getAction() == ExplorerChangeEvent.CHANGE &&
mCurrentPageState.page.getPath().equals(event.getPage().getPath()))
|| (event.getAction() == Explorer)) {
if ((event.getAction() == ExplorerChangeEvent.ALL)
|| mCurrentPageState.page.getPath().equals(event.getPage().getPath())) {
loadItemList();
}
}
@@ -462,14 +460,14 @@ public class ExplorerView extends ThemeColorSwipeRefreshLayout implements SwipeR
PopupMenu popupMenu = new PopupMenu(getContext(), mOptions);
popupMenu.inflate(R.menu.menu_script_options);
Menu menu = popupMenu.getMenu();
if(!mExplorerItem.isExecutable()){
if (!mExplorerItem.isExecutable()) {
menu.removeItem(R.id.run_repeatedly);
menu.removeItem(R.id.more);
}
if(!mExplorerItem.canDelete()){
if (!mExplorerItem.canDelete()) {
menu.removeItem(R.id.delete);
}
if(!mExplorerItem.canRename()){
if (!mExplorerItem.canRename()) {
menu.removeItem(R.id.rename);
}
popupMenu.setOnMenuItemClickListener(ExplorerView.this);

View File

@@ -179,6 +179,7 @@ public class MyScriptListFragment extends ViewPagerFragment implements BackPress
case 2:
new ScriptOperations(getContext(), mExplorerView, mExplorerView.getCurrentPage())
.importFile();
break;
case 3:
ProjectConfigActivity_.intent(getContext())
.extra(ProjectConfigActivity.EXTRA_PARENT_DIRECTORY, mExplorerView.getCurrentPage().getPath())