Search in sources :

Example 1 with ScriptFile

use of com.stardust.scriptdroid.model.script.ScriptFile in project Auto.js by hyb1996.

the class ScriptOperations method importFile.

public Observable<String> importFile(String prefix, final InputStream inputStream, final String ext) {
    return showFileNameInputDialog(PFiles.getNameWithoutExtension(prefix), ext).observeOn(Schedulers.io()).map(input -> {
        final String pathTo = getCurrentDirectoryPath() + input + "." + ext;
        if (PFiles.copyStream(inputStream, pathTo)) {
            showMessage(R.string.text_import_succeed);
        } else {
            showMessage(R.string.text_import_fail);
        }
        mStorageFileProvider.notifyFileCreated(mCurrentDirectory, new ScriptFile(pathTo));
        return pathTo;
    });
}
Also used : ScriptFile(com.stardust.scriptdroid.model.script.ScriptFile)

Example 2 with ScriptFile

use of com.stardust.scriptdroid.model.script.ScriptFile in project Auto.js by hyb1996.

the class ScriptOperations method rename.

public Observable<Boolean> rename(final ScriptFile file) {
    final ScriptFile oldFile = new ScriptFile(file.getPath());
    String originalName = file.getSimplifiedName();
    return showNameInputDialog(originalName, new InputCallback(file.isDirectory() ? null : PFiles.getExtension(file.getName()), originalName)).map(newName -> {
        PFile newFile = file.renameAndReturnNewFile(newName);
        if (newFile != null) {
            mStorageFileProvider.notifyFileChanged(mCurrentDirectory, oldFile, newFile);
        }
        return newFile != null;
    });
}
Also used : PFile(com.stardust.pio.PFile) ScriptFile(com.stardust.scriptdroid.model.script.ScriptFile)

Example 3 with ScriptFile

use of com.stardust.scriptdroid.model.script.ScriptFile in project Auto.js by hyb1996.

the class ScriptListView method loadScriptList.

private void loadScriptList() {
    setRefreshing(true);
    mStorageFileProvider.getDirectoryFiles(mCurrentDirectory).subscribeOn(Schedulers.io()).filter(f -> mFilter == null ? true : mFilter.apply(f)).collectInto(mScriptList.cloneConfig(), (list, file) -> {
        if (file instanceof ScriptFile) {
            list.add((ScriptFile) file);
        } else {
            list.add(new ScriptFile(file));
        }
    }).observeOn(Schedulers.computation()).doOnSuccess(ScriptList::sort).observeOn(AndroidSchedulers.mainThread()).subscribe(list -> {
        mScriptList = list;
        mScriptListAdapter.notifyDataSetChanged();
        setRefreshing(false);
    });
}
Also used : Context(android.content.Context) GridLayoutManager(android.support.v7.widget.GridLayoutManager) PFiles(com.stardust.pio.PFiles) BindableViewHolder(com.stardust.scriptdroid.ui.widget.BindableViewHolder) ButterKnife(butterknife.ButterKnife) BuildActivity(com.stardust.scriptdroid.ui.build.BuildActivity) ImageView(android.widget.ImageView) ScriptList(com.stardust.scriptdroid.ui.viewmodel.ScriptList) R(com.stardust.scriptdroid.R) ScriptOperations(com.stardust.scriptdroid.ui.common.ScriptOperations) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) Scripts(com.stardust.scriptdroid.model.script.Scripts) OnClick(butterknife.OnClick) MenuItem(android.view.MenuItem) BindView(butterknife.BindView) AttributeSet(android.util.AttributeSet) GradientDrawable(android.graphics.drawable.GradientDrawable) PopupMenu(android.widget.PopupMenu) View(android.view.View) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ScriptFile(com.stardust.scriptdroid.model.script.ScriptFile) PFile(com.stardust.pio.PFile) ResourcesCompat(android.support.v4.content.res.ResourcesCompat) StorageFileProvider(com.stardust.scriptdroid.storage.file.StorageFileProvider) LayoutInflater(android.view.LayoutInflater) ThemeColorSwipeRefreshLayout(com.stardust.theme.widget.ThemeColorSwipeRefreshLayout) ViewGroup(android.view.ViewGroup) ScriptLoopDialog(com.stardust.scriptdroid.ui.common.ScriptLoopDialog) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Subscribe(org.greenrobot.eventbus.Subscribe) BuildActivity_(com.stardust.scriptdroid.ui.build.BuildActivity_) Function(io.reactivex.functions.Function) Nullable(android.support.annotation.Nullable) ScriptList(com.stardust.scriptdroid.ui.viewmodel.ScriptList) ScriptFile(com.stardust.scriptdroid.model.script.ScriptFile)

Example 4 with ScriptFile

use of com.stardust.scriptdroid.model.script.ScriptFile in project Auto.js by hyb1996.

the class TimedTaskSettingActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    int taskId = getIntent().getIntExtra(TaskReceiver.EXTRA_TASK_ID, -1);
    if (taskId != -1) {
        mTimedTask = TimedTaskManager.getInstance().getTimedTask(taskId);
        if (mTimedTask != null) {
            mScriptFile = new ScriptFile(mTimedTask.getScriptPath());
        }
    } else {
        String path = getIntent().getStringExtra(ScriptIntents.EXTRA_KEY_PATH);
        if (TextUtils.isEmpty(path)) {
            finish();
        }
        mScriptFile = new ScriptFile(path);
    }
}
Also used : ScriptFile(com.stardust.scriptdroid.model.script.ScriptFile)

Example 5 with ScriptFile

use of com.stardust.scriptdroid.model.script.ScriptFile in project Auto.js by hyb1996.

the class ScriptOperations method newDirectory.

public void newDirectory() {
    showNameInputDialog("", new InputCallback()).subscribe(path -> {
        ScriptFile newDir = new ScriptFile(getCurrentDirectory(), path);
        if (newDir.mkdirs()) {
            showMessage(R.string.text_already_create);
            mStorageFileProvider.notifyFileCreated(mCurrentDirectory, new ScriptFile(newDir));
        } else {
            showMessage(R.string.text_create_fail);
        }
    });
}
Also used : ScriptFile(com.stardust.scriptdroid.model.script.ScriptFile)

Aggregations

ScriptFile (com.stardust.scriptdroid.model.script.ScriptFile)8 PFile (com.stardust.pio.PFile)2 ScriptListView (com.stardust.scriptdroid.ui.main.scripts.ScriptListView)2 Context (android.content.Context)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 Nullable (android.support.annotation.Nullable)1 ResourcesCompat (android.support.v4.content.res.ResourcesCompat)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 AttributeSet (android.util.AttributeSet)1 LayoutInflater (android.view.LayoutInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ImageView (android.widget.ImageView)1 PopupMenu (android.widget.PopupMenu)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 ButterKnife (butterknife.ButterKnife)1