feat:DevKit add disconnect action

This commit is contained in:
pengfei.zhou 2020-03-20 15:53:09 +08:00 committed by osborn
parent 4d6884098c
commit e9d8018a09
7 changed files with 37 additions and 5 deletions

View File

@ -36,7 +36,7 @@ public class DoricDev {
} }
public void closeDevMode() { public void closeDevMode() {
EventBus.getDefault().post(new EOFExceptionEvent()); DevKit.getInstance().disconnectDevKit();
} }
public boolean isInDevMode() { public boolean isInDevMode() {

View File

@ -53,7 +53,7 @@ public class WSClient extends WebSocketListener {
} }
public void close() { public void close() {
webSocket.close(-1, "Close"); webSocket.close(1024, "Close");
} }
@Override @Override

View File

@ -5,6 +5,8 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@ -63,6 +65,23 @@ public class DoricDevActivity extends AppCompatActivity {
} }
} }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.doric_devkit_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.doric_action_disconnect) {
DoricDev.getInstance().closeDevMode();
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);

View File

@ -0,0 +1,8 @@
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/doric_action_disconnect"
android:icon="@android:drawable/ic_menu_close_clear_cancel"
android:title="Disconnect"
app:showAsAction="ifRoom" />
</menu>

View File

@ -44,6 +44,8 @@ - (void)viewDidLoad {
it.dataSource = self; it.dataSource = self;
it.delegate = self; it.delegate = self;
}]]; }]];
UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:@"Disconnect" style:UIBarButtonItemStylePlain target:self action:@selector(onClose)];
self.navigationItem.rightBarButtonItem = rightBarItem;
if ([[DoricDev instance] isInDevMode]) { if ([[DoricDev instance] isInDevMode]) {
return; return;
} }
@ -56,7 +58,10 @@ - (void)viewDidLoad {
[self.navigationController pushViewController:[QRScanViewController new] animated:NO]; [self.navigationController pushViewController:[QRScanViewController new] animated:NO];
} }
} }
- (void)onClose {
[[DoricDev instance] closeDevMode];
[self.navigationController popViewControllerAnimated:YES];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [DoricContextManager.instance aliveContexts].count; return [DoricContextManager.instance aliveContexts].count;
} }

View File

@ -4005,7 +4005,7 @@ return __module.exports;
var doric_web = (function (exports, axios, sandbox) { var doric_web = (function (exports, axios, sandbox) {
'use strict'; 'use strict';
axios = axios && Object.prototype.hasOwnProperty.call(axios, 'default') ? axios['default'] : axios; axios = axios && axios.hasOwnProperty('default') ? axios['default'] : axios;
class DoricPlugin { class DoricPlugin {
constructor(context) { constructor(context) {

File diff suppressed because one or more lines are too long