feat:show information of script
This commit is contained in:
parent
a568a704fe
commit
eb689e8a48
@ -28,7 +28,11 @@ import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
import pub.doric.Doric;
|
||||
import pub.doric.DoricContext;
|
||||
@ -228,6 +232,27 @@ public class DoricDevActivity extends AppCompatActivity implements DoricDev.Stat
|
||||
}
|
||||
}
|
||||
|
||||
private static String toHex(byte[] bytes) {
|
||||
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
char[] resultCharArray = new char[bytes.length * 2];
|
||||
int index = 0;
|
||||
for (byte b : bytes) {
|
||||
resultCharArray[index++] = hexDigits[b >>> 4 & 0xf];
|
||||
resultCharArray[index++] = hexDigits[b & 0xf];
|
||||
}
|
||||
return new String(resultCharArray);
|
||||
}
|
||||
|
||||
private static String md5(String s) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] bytes = md.digest(s.getBytes(Charset.forName("UTF-8")));
|
||||
return toHex(bytes);
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static class ContextCellAdapter extends RecyclerView.Adapter<ContextCellHolder> {
|
||||
private final ArrayList<DoricContext> contexts = new ArrayList<>();
|
||||
private Bitmap icon_off;
|
||||
@ -285,9 +310,16 @@ public class DoricDevActivity extends AppCompatActivity implements DoricDev.Stat
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == 0) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(holder.itemView.getContext(), R.style.Theme_Doric_Modal_Alert);
|
||||
builder.setTitle("View source: " + context.getSource());
|
||||
builder.setTitle(String.format(Locale.getDefault(),
|
||||
"View source: %s",
|
||||
context.getSource()));
|
||||
String btnTitle = holder.itemView.getContext().getString(android.R.string.ok);
|
||||
builder.setMessage(context.getScript())
|
||||
builder.setMessage(
|
||||
String.format(Locale.getDefault(),
|
||||
"Size:%d\nMD5:%s\nScript:\n%s",
|
||||
context.getScript().length(),
|
||||
md5(context.getScript()),
|
||||
context.getScript()))
|
||||
.setPositiveButton(btnTitle, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
@ -21,6 +21,7 @@
|
||||
//
|
||||
#import <DoricCore/Doric.h>
|
||||
#import <DoricCore/DoricContextManager.h>
|
||||
#import<CommonCrypto/CommonDigest.h>
|
||||
|
||||
#import "DoricDev.h"
|
||||
#import "DoricDevViewController.h"
|
||||
@ -72,13 +73,30 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSStr
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *)md5:(NSString *)input {
|
||||
const char *cStr = [input UTF8String];
|
||||
unsigned char digest[CC_MD5_DIGEST_LENGTH];
|
||||
CC_MD5(cStr, (CC_LONG) strlen(cStr), digest);
|
||||
|
||||
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
|
||||
for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
|
||||
[output appendFormat:@"%02x", digest[i]];
|
||||
}
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
- (void)onClick {
|
||||
UIAlertController *alertController = [[UIAlertController alloc] init];
|
||||
UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil];
|
||||
UIAlertAction *viewSource = [UIAlertAction actionWithTitle:@"View source" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_) {
|
||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"View source: %@", self.doricContext.source]
|
||||
message:self.doricContext.script
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
message:[NSString stringWithFormat:@"Size:%@\nMD5:%@\nScript:\n%@",
|
||||
@(self.doricContext.script.length),
|
||||
[self md5:self.doricContext.script],
|
||||
self.doricContext.script]
|
||||
preferredStyle:
|
||||
UIAlertControllerStyleAlert];
|
||||
UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:nil];
|
||||
|
Reference in New Issue
Block a user