优化 explorer view记住文件夹位置
修复 explorer view不能设置root和current的问题
This commit is contained in:
@@ -43,7 +43,7 @@ public class ScriptWidgetSettingsActivity extends BaseActivity {
|
|||||||
|
|
||||||
private void initScriptListRecyclerView() {
|
private void initScriptListRecyclerView() {
|
||||||
mExplorer = new Explorer(new ExplorerFileProvider(Scripts.FILE_FILTER), 0);
|
mExplorer = new Explorer(new ExplorerFileProvider(Scripts.FILE_FILTER), 0);
|
||||||
ExplorerView explorerView = (ExplorerView) findViewById(R.id.script_list);
|
ExplorerView explorerView = findViewById(R.id.script_list);
|
||||||
explorerView.setExplorer(mExplorer, ExplorerDirPage.createRoot(Environment.getExternalStorageDirectory()));
|
explorerView.setExplorer(mExplorer, ExplorerDirPage.createRoot(Environment.getExternalStorageDirectory()));
|
||||||
explorerView.setOnItemClickListener((view, file) -> {
|
explorerView.setOnItemClickListener((view, file) -> {
|
||||||
mSelectedScriptFilePath = file.getPath();
|
mSelectedScriptFilePath = file.getPath();
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import com.stardust.pio.PFiles;
|
|||||||
import org.autojs.autojs.R;
|
import org.autojs.autojs.R;
|
||||||
import org.autojs.autojs.model.explorer.Explorer;
|
import org.autojs.autojs.model.explorer.Explorer;
|
||||||
import org.autojs.autojs.model.explorer.ExplorerChangeEvent;
|
import org.autojs.autojs.model.explorer.ExplorerChangeEvent;
|
||||||
|
import org.autojs.autojs.model.explorer.ExplorerDirPage;
|
||||||
import org.autojs.autojs.model.explorer.ExplorerFileItem;
|
import org.autojs.autojs.model.explorer.ExplorerFileItem;
|
||||||
import org.autojs.autojs.model.explorer.ExplorerItem;
|
import org.autojs.autojs.model.explorer.ExplorerItem;
|
||||||
import org.autojs.autojs.model.explorer.ExplorerPage;
|
import org.autojs.autojs.model.explorer.ExplorerPage;
|
||||||
@@ -123,13 +124,15 @@ public class ExplorerView extends ThemeColorSwipeRefreshLayout implements SwipeR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enterChildPage(ExplorerPage childItemGroup) {
|
protected void enterDirectChildPage(ExplorerPage childItemGroup) {
|
||||||
mCurrentPageState.position = ((LinearLayoutManager) mExplorerItemListView.getLayoutManager()).findFirstVisibleItemPosition();
|
mCurrentPageState.scrollY = ((LinearLayoutManager) mExplorerItemListView.getLayoutManager()).findLastCompletelyVisibleItemPosition();
|
||||||
mPageStateHistory.push(mCurrentPageState);
|
mPageStateHistory.push(mCurrentPageState);
|
||||||
setCurrentPageState(new ExplorerPageState(childItemGroup));
|
setCurrentPageState(new ExplorerPageState(childItemGroup));
|
||||||
loadItemList();
|
loadItemList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
|
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
|
||||||
mOnItemClickListener = onItemClickListener;
|
mOnItemClickListener = onItemClickListener;
|
||||||
}
|
}
|
||||||
@@ -160,6 +163,25 @@ public class ExplorerView extends ThemeColorSwipeRefreshLayout implements SwipeR
|
|||||||
enterChildPage(currentPage);
|
enterChildPage(currentPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void enterChildPage(ExplorerPage childPage) {
|
||||||
|
ScriptFile root = mCurrentPageState.page.toScriptFile();
|
||||||
|
ScriptFile dir = childPage.toScriptFile();
|
||||||
|
Stack<ScriptFile> dirs = new Stack<>();
|
||||||
|
while (!dir.equals(root)) {
|
||||||
|
dir = dir.getParentFile();
|
||||||
|
dirs.push(dir);
|
||||||
|
}
|
||||||
|
ExplorerDirPage parent = null;
|
||||||
|
while (!dirs.empty()) {
|
||||||
|
dir = dirs.pop();
|
||||||
|
ExplorerDirPage dirPage = new ExplorerDirPage(dir, parent);
|
||||||
|
mPageStateHistory.push(new ExplorerPageState(dirPage));
|
||||||
|
parent = dirPage;
|
||||||
|
}
|
||||||
|
setCurrentPageState(new ExplorerPageState(childPage));
|
||||||
|
loadItemList();
|
||||||
|
}
|
||||||
|
|
||||||
public void setOnItemOperatedListener(OnItemOperatedListener onItemOperatedListener) {
|
public void setOnItemOperatedListener(OnItemOperatedListener onItemOperatedListener) {
|
||||||
mOnItemOperatedListener = onItemOperatedListener;
|
mOnItemOperatedListener = onItemOperatedListener;
|
||||||
}
|
}
|
||||||
@@ -237,7 +259,7 @@ public class ExplorerView extends ThemeColorSwipeRefreshLayout implements SwipeR
|
|||||||
mExplorerAdapter.notifyDataSetChanged();
|
mExplorerAdapter.notifyDataSetChanged();
|
||||||
setRefreshing(false);
|
setRefreshing(false);
|
||||||
post(() ->
|
post(() ->
|
||||||
mExplorerItemListView.scrollToPosition(mCurrentPageState.position)
|
mExplorerItemListView.scrollToPosition(mCurrentPageState.scrollY)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -589,7 +611,7 @@ public class ExplorerView extends ThemeColorSwipeRefreshLayout implements SwipeR
|
|||||||
|
|
||||||
@OnClick(R.id.item)
|
@OnClick(R.id.item)
|
||||||
void onItemClick() {
|
void onItemClick() {
|
||||||
enterChildPage(mExplorerPage);
|
enterDirectChildPage(mExplorerPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.more)
|
@OnClick(R.id.more)
|
||||||
@@ -697,7 +719,7 @@ public class ExplorerView extends ThemeColorSwipeRefreshLayout implements SwipeR
|
|||||||
|
|
||||||
boolean filesCollapsed;
|
boolean filesCollapsed;
|
||||||
|
|
||||||
int position;
|
int scrollY;
|
||||||
|
|
||||||
ExplorerPageState() {
|
ExplorerPageState() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ public class FileChooseListView extends ExplorerView {
|
|||||||
|
|
||||||
@OnClick(R.id.item)
|
@OnClick(R.id.item)
|
||||||
void onItemClick() {
|
void onItemClick() {
|
||||||
enterChildPage(mExplorerPage);
|
enterDirectChildPage(mExplorerPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnCheckedChanged(R.id.checkbox)
|
@OnCheckedChanged(R.id.checkbox)
|
||||||
|
|||||||
@@ -119,6 +119,13 @@ public class Dialogs {
|
|||||||
.showAndGet();
|
.showAndGet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ScriptInterface
|
||||||
|
public Object selectFile(String title, String prefill, Object callback) {
|
||||||
|
return ((BlockedMaterialDialog.Builder) dialogBuilder(callback)
|
||||||
|
.input(null, prefill, true)
|
||||||
|
.title(title))
|
||||||
|
.showAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
private BlockedMaterialDialog.Builder dialogBuilder(Object callback) {
|
private BlockedMaterialDialog.Builder dialogBuilder(Object callback) {
|
||||||
Context context = mRuntime.app.getCurrentActivity();
|
Context context = mRuntime.app.getCurrentActivity();
|
||||||
|
|||||||
Reference in New Issue
Block a user