feat:add debug option stop debugging

This commit is contained in:
pengfei.zhou 2021-03-02 11:52:03 +08:00 committed by osborn
parent 4e5b1c94bf
commit de4188b74e
2 changed files with 28 additions and 8 deletions

View File

@ -299,16 +299,19 @@ public class DoricDevActivity extends AppCompatActivity implements DoricDev.Stat
holder.layoutBtn.setOnClickListener(new View.OnClickListener() { holder.layoutBtn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final String[] items = DoricDev.getInstance().isInDevMode() ArrayList<String> list = new ArrayList<>();
? new String[]{"View source",} list.add("View source");
: new String[]{"View source",}; if (context.getDriver() instanceof DoricDebugDriver) {
list.add("Stop debugging");
}
final String[] items = list.toArray(new String[0]);
AlertDialog.Builder builder = new AlertDialog.Builder(holder.itemView.getContext(), R.style.Theme_Doric_Modal); AlertDialog.Builder builder = new AlertDialog.Builder(holder.itemView.getContext(), R.style.Theme_Doric_Modal);
builder.setTitle(String.format("%s %s", context.getContextId(), context.getSource())); builder.setTitle(String.format("%s %s", context.getContextId(), context.getSource()));
builder.setIcon(new BitmapDrawable(holder.itemView.getContext().getResources(), icon_on)); builder.setIcon(new BitmapDrawable(holder.itemView.getContext().getResources(), icon_on));
builder.setItems(items, new DialogInterface.OnClickListener() { builder.setItems(items, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (which == 0) { if ("View source".equals(items[which])) {
AlertDialog.Builder builder = new AlertDialog.Builder(holder.itemView.getContext(), R.style.Theme_Doric_Modal_Alert); AlertDialog.Builder builder = new AlertDialog.Builder(holder.itemView.getContext(), R.style.Theme_Doric_Modal_Alert);
builder.setTitle(String.format(Locale.getDefault(), builder.setTitle(String.format(Locale.getDefault(),
"View source: %s", "View source: %s",
@ -328,6 +331,8 @@ public class DoricDevActivity extends AppCompatActivity implements DoricDev.Stat
}); });
builder.setCancelable(false); builder.setCancelable(false);
builder.show(); builder.show();
} else if ("Stop debugging".equals(items[which])) {
DoricDev.getInstance().stopDebugging(true);
} }
dialog.dismiss(); dialog.dismiss();
} }

View File

@ -105,6 +105,13 @@ - (void)onClick {
}]; }];
[alertController addAction:cancel]; [alertController addAction:cancel];
[alertController addAction:viewSource]; [alertController addAction:viewSource];
if ([self.doricContext.driver isKindOfClass:DoricDebugDriver.class]) {
UIAlertAction *stopDebugging = [UIAlertAction actionWithTitle:@"Stop debugging" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_) {
[DoricDev.instance stopDebugging:YES];
}];
[alertController addAction:stopDebugging];
}
[self.vc presentViewController:alertController animated:true completion:nil]; [self.vc presentViewController:alertController animated:true completion:nil];
} }
@end @end
@ -311,11 +318,15 @@ - (UIImage *)decodeImage:(BOOL)on {
return [UIImage imageWithData:imageData]; return [UIImage imageWithData:imageData];
} }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:
(NSInteger)section {
return [DoricContextManager.instance aliveContexts].count; return [DoricContextManager.instance aliveContexts].count;
} }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
DoricContextCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; DoricContextCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) { if (cell == nil) {
cell = [[DoricContextCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; cell = [[DoricContextCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
@ -351,7 +362,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell; return cell;
} }
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - (CGFloat) tableView:(UITableView *)tableView
heightForRowAtIndexPath:
(NSIndexPath *)indexPath {
return 60.f; return 60.f;
} }
@ -375,7 +388,9 @@ - (void)onFailure:(NSError *)error {
[self.listView reloadData]; [self.listView reloadData];
} }
- (void)onReload:(DoricContext *)context script:(NSString *)script { - (void)onReload:(DoricContext *)context
script:
(NSString *)script {
[self.listView reloadData]; [self.listView reloadData];
} }