sample: 自定义控件; fix: ActivityNotFoundException

This commit is contained in:
hyb1996
2018-10-14 10:33:23 +08:00
parent db3571851c
commit 14b7a7e85e
39 changed files with 615 additions and 220 deletions

View File

@@ -48,7 +48,7 @@ public class TaskerScriptEditActivity extends BaseActivity {
.putExtra(EXTRA_RUN_ENABLED, false)
.putExtra(EXTRA_SAVE_ENABLED, false))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Observers.consumer(),
.subscribe(Observers.emptyConsumer(),
ex -> {
Toast.makeText(TaskerScriptEditActivity.this, ex.getMessage(), Toast.LENGTH_LONG).show();
finish();

View File

@@ -101,7 +101,7 @@ public class AndroidClassIndices {
.doOnNext(this::load)
.subscribeOn(Schedulers.from(mSingleThreadExecutor))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Observers.consumer(), t -> {
.subscribe(Observers.emptyConsumer(), t -> {
mLoadThrowable = t;
t.printStackTrace();
});

View File

@@ -58,11 +58,11 @@ public class TimedTaskManager {
return;
if (task.isDisposable()) {
mTimedTaskDatabase.delete(task)
.subscribe(Observers.consumer(), Throwable::printStackTrace);
.subscribe(Observers.emptyConsumer(), Throwable::printStackTrace);
} else {
task.setScheduled(false);
mTimedTaskDatabase.update(task)
.subscribe(Observers.consumer(), Throwable::printStackTrace);
.subscribe(Observers.emptyConsumer(), Throwable::printStackTrace);
}
}
@@ -70,13 +70,13 @@ public class TimedTaskManager {
public void removeTask(TimedTask timedTask) {
TimedTaskScheduler.cancel(mContext, timedTask);
mTimedTaskDatabase.delete(timedTask)
.subscribe(Observers.consumer(), Throwable::printStackTrace);
.subscribe(Observers.emptyConsumer(), Throwable::printStackTrace);
}
@SuppressLint("CheckResult")
public void addTask(TimedTask timedTask) {
mTimedTaskDatabase.insert(timedTask)
.subscribe(Observers.consumer(), Throwable::printStackTrace);;
.subscribe(Observers.emptyConsumer(), Throwable::printStackTrace);;
TimedTaskScheduler.scheduleTaskIfNeeded(mContext, timedTask);
}
@@ -119,7 +119,7 @@ public class TimedTaskManager {
public void notifyTaskScheduled(TimedTask timedTask) {
timedTask.setScheduled(true);
mTimedTaskDatabase.update(timedTask)
.subscribe(Observers.consumer(), Throwable::printStackTrace);
.subscribe(Observers.emptyConsumer(), Throwable::printStackTrace);
}
@@ -134,7 +134,7 @@ public class TimedTaskManager {
@SuppressLint("CheckResult")
public void updateTask(TimedTask task) {
mTimedTaskDatabase.update(task)
.subscribe(Observers.consumer(), Throwable::printStackTrace);
.subscribe(Observers.emptyConsumer(), Throwable::printStackTrace);
TimedTaskScheduler.cancel(mContext, task);
TimedTaskScheduler.scheduleTaskIfNeeded(mContext, task);
}

View File

@@ -2,6 +2,10 @@ package org.autojs.autojs.tool;
import com.stardust.app.GlobalAppContext;
import org.autojs.autojs.model.explorer.ExplorerFileItem;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
public class Observers {
@@ -17,11 +21,36 @@ public class Observers {
@SuppressWarnings("unchecked")
public static <T> Consumer<T> consumer() {
public static <T> Consumer<T> emptyConsumer() {
return CONSUMER;
}
public static Consumer<Throwable> toastMessage() {
return TOAST_MESSAGE;
}
public static <T> Observer<T> emptyObserver() {
return new Observer<T>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(T t) {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
};
}
}

View File

@@ -51,6 +51,7 @@ import java.io.InputStream;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.internal.functions.ObjectHelper;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.PublishSubject;
@@ -267,17 +268,19 @@ public class ScriptOperations {
}
}
public Observable<Boolean> rename(final ExplorerFileItem item) {
public Observable<ExplorerFileItem> rename(final ExplorerFileItem item) {
final ScriptFile oldFile = new ScriptFile(item.getPath());
String originalName = item.getName();
return showNameInputDialog(originalName, new InputCallback(oldFile.isDirectory() ? null : PFiles.getExtension(item.getName()),
originalName))
.map(newName -> {
ExplorerFileItem newItem = item.rename(newName);
if (newItem != null) {
notifyFileChanged(mCurrentDirectory, item, newItem);
if (ObjectHelper.equals(newItem.toScriptFile(), item.toScriptFile())) {
showMessage(R.string.error_cannot_rename);
throw new IOException();
}
return newItem != null;
notifyFileChanged(mCurrentDirectory, item, newItem);
return newItem;
});
}

View File

@@ -81,7 +81,7 @@ EditActivity extends BaseActivity implements OnActivityResultDelegate.DelegateHo
void setUpViews() {
mEditorView.handleIntent(getIntent())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Observers.consumer(),
.subscribe(Observers.emptyConsumer(),
ex -> onLoadFileError(ex.getMessage()));
mEditorMenu = new EditorMenu(mEditorView);
setUpToolbar();

View File

@@ -440,7 +440,7 @@ public class EditorView extends FrameLayout implements CodeCompletionBar.OnHintC
public void saveFile() {
save()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Observers.consumer(), e -> {
.subscribe(Observers.emptyConsumer(), e -> {
e.printStackTrace();
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
});

View File

@@ -119,7 +119,6 @@ public class CodeEditText extends AppCompatEditText {
@Override
protected void onDraw(Canvas canvas) {
Log.v(LOG_TAG, "onDraw");
mLogger.reset();
if (mParentScrollView == null) {
mParentScrollView = (HVScrollView) getParent();

View File

@@ -31,8 +31,6 @@ import org.autojs.autojs.model.explorer.ExplorerProjectPage;
import org.autojs.autojs.model.explorer.ExplorerSampleItem;
import org.autojs.autojs.model.explorer.ExplorerSamplePage;
import org.autojs.autojs.model.explorer.Explorers;
import org.autojs.autojs.model.explorer.WorkspaceFileProvider;
import org.autojs.autojs.model.sample.SampleFile;
import org.autojs.autojs.model.script.ScriptFile;
import org.autojs.autojs.model.script.Scripts;
import org.autojs.autojs.tool.Observers;
@@ -268,7 +266,7 @@ public class ExplorerView extends ThemeColorSwipeRefreshLayout implements SwipeR
case R.id.rename:
new ScriptOperations(getContext(), this, getCurrentPage())
.rename((ExplorerFileItem) mSelectedItem)
.subscribe();
.subscribe(Observers.emptyObserver());
break;
case R.id.delete:
new ScriptOperations(getContext(), this, getCurrentPage())

View File

@@ -279,7 +279,7 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
.input("", host, (dialog, input) -> {
Pref.saveServerAddress(input.toString());
DevPluginService.getInstance().connectToServer(input.toString())
.subscribe(Observers.consumer(), this::onConnectException);
.subscribe(Observers.emptyConsumer(), this::onConnectException);
})
.neutralText(R.string.text_help)
.onNeutral((dialog, which) -> {

View File

@@ -317,7 +317,7 @@ public class BuildActivity extends BaseActivity implements AutoJsApkBuilder.Prog
.positiveText(R.string.text_install)
.negativeText(R.string.cancel)
.onPositive((dialog, which) ->
IntentUtil.installApk(BuildActivity.this, outApk.getPath(), AppFileProvider.AUTHORITY)
IntentUtil.installApkOrToast(BuildActivity.this, outApk.getPath(), AppFileProvider.AUTHORITY)
)
.show();

View File

@@ -119,7 +119,7 @@ public class UpdateInfoDialogBuilder extends MaterialDialog.Builder {
final String path = new File(Pref.getScriptDirPath(), "AutoJs.apk").getPath();
DownloadManager.getInstance().downloadWithProgress(getContext(), downloadUrl, path)
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe(file -> IntentUtil.installApk(getContext(), file.getPath(), AppFileProvider.AUTHORITY),
.subscribe(file -> IntentUtil.installApkOrToast(getContext(), file.getPath(), AppFileProvider.AUTHORITY),
error -> {
error.printStackTrace();
Toast.makeText(getContext(), R.string.text_download_failed, Toast.LENGTH_SHORT).show();