From 36e9c9481a26f24f73497f73876af5baeb6bd2c0 Mon Sep 17 00:00:00 2001 From: hyb1996 <946994919@qq.com> Date: Mon, 17 Sep 2018 15:58:10 +0800 Subject: [PATCH] save works --- app/src/main/java/org/autojs/autojs/Pref.java | 2 +- .../autojs/model/explorer/Explorer.java | 61 +++++++++++-------- .../model/explorer/ExplorerChangeEvent.java | 5 +- .../autojs/ui/main/scripts/ExplorerView.java | 12 ++-- .../ui/main/scripts/MyScriptListFragment.java | 1 + 5 files changed, 44 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/org/autojs/autojs/Pref.java b/app/src/main/java/org/autojs/autojs/Pref.java index 19121fde..e63bc533 100644 --- a/app/src/main/java/org/autojs/autojs/Pref.java +++ b/app/src/main/java/org/autojs/autojs/Pref.java @@ -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"); diff --git a/app/src/main/java/org/autojs/autojs/model/explorer/Explorer.java b/app/src/main/java/org/autojs/autojs/model/explorer/Explorer.java index 0e922610..ade9ea3f 100644 --- a/app/src/main/java/org/autojs/autojs/model/explorer/Explorer.java +++ b/app/src/main/java/org/autojs/autojs/model/explorer/Explorer.java @@ -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") diff --git a/app/src/main/java/org/autojs/autojs/model/explorer/ExplorerChangeEvent.java b/app/src/main/java/org/autojs/autojs/model/explorer/ExplorerChangeEvent.java index f2a20b36..825f9854 100644 --- a/app/src/main/java/org/autojs/autojs/model/explorer/ExplorerChangeEvent.java +++ b/app/src/main/java/org/autojs/autojs/model/explorer/ExplorerChangeEvent.java @@ -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; diff --git a/app/src/main/java/org/autojs/autojs/ui/main/scripts/ExplorerView.java b/app/src/main/java/org/autojs/autojs/ui/main/scripts/ExplorerView.java index 86d17104..88530d9a 100644 --- a/app/src/main/java/org/autojs/autojs/ui/main/scripts/ExplorerView.java +++ b/app/src/main/java/org/autojs/autojs/ui/main/scripts/ExplorerView.java @@ -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); diff --git a/app/src/main/java/org/autojs/autojs/ui/main/scripts/MyScriptListFragment.java b/app/src/main/java/org/autojs/autojs/ui/main/scripts/MyScriptListFragment.java index 813a3431..8f4c8042 100644 --- a/app/src/main/java/org/autojs/autojs/ui/main/scripts/MyScriptListFragment.java +++ b/app/src/main/java/org/autojs/autojs/ui/main/scripts/MyScriptListFragment.java @@ -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())