@@ -222,23 +222,15 @@ public void sa(int n) {
222222 //insert text
223223 public void i (int n , String parameter ) {
224224 for (int i =0 ;i <n ;i ++) {
225- if (buffer != null ) {
226- commitText (parameter .replaceAll ("\\ $0" , buffer ));
227- } else {
228- commitText (parameter );
229- }
225+ commitText (replaceDollarWords (parameter ));
230226 }
231227
232228 }
233229
234230 //insert text raw (without autospace etc)
235231 public void iraw (int n , String parameter ) {
236232 for (int i =0 ;i <n ;i ++) {
237- if (buffer != null ) {
238- inputConnection .commitText (parameter .replaceAll ("\\ $0" , buffer ), 1 );
239- } else {
240233 inputConnection .commitText (parameter , 1 );
241- }
242234 }
243235 }
244236
@@ -292,24 +284,16 @@ public void pc(int n) {
292284 //make uppercase
293285 public void upper (int n , String parameter ) {
294286 for (int i =0 ;i <n ;i ++) {
295- String lastBufferWord = buffer ;
296- if (lastBufferWord != null ) {
297- inputConnection .commitText (parameter .replaceAll ("\\ $0" , lastBufferWord ).toUpperCase (), 1 );
298- } else {
299287 inputConnection .commitText (parameter .toUpperCase (), 1 );
300- }
301288 }
302289 }
303290
304291 //make lowercase
305292 public void lower (int n , String parameter ) {
306293 for (int i =0 ;i <n ;i ++) {
307- String lastBufferWord = buffer ;
308- if (lastBufferWord != null ) {
309- inputConnection .commitText (parameter .replaceAll ("\\ $0" , lastBufferWord ).toLowerCase (), 1 );
310- } else {
294+
311295 inputConnection .commitText (parameter .toLowerCase (), 1 );
312- }
296+
313297 }
314298 }
315299
@@ -457,7 +441,7 @@ public Map<String, String> getHeaders(){
457441 }
458442 }
459443
460- public Uri getImageUri (Bitmap inImage ) {
444+ private Uri getImageUri (Bitmap inImage ) {
461445 ByteArrayOutputStream bytes = new ByteArrayOutputStream ();
462446 inImage .compress (Bitmap .CompressFormat .JPEG , 100 , bytes );
463447 String path = MediaStore .Images .Media .insertImage (mIme .getContentResolver (), inImage , "Title" , null );
@@ -514,7 +498,7 @@ public void run() {
514498 commands = new String [1 ];
515499 commands [0 ] = cmd ;
516500 int numberOfTimes = cmd .indexOf ("e" ) > 0 ? Integer .parseInt (cmd .substring (0 , cmd .indexOf ("e" ))) : 1 ;
517- String parameter = cmd .substring (cmd .indexOf ("(" ) + 1 , cmd .lastIndexOf (")" ));
501+ String parameter = replaceDollarWords ( cmd .substring (cmd .indexOf ("(" ) + 1 , cmd .lastIndexOf (")" ) ));
518502 e (numberOfTimes , parameter );
519503 } else {
520504 commands = cmd .split ("," );
@@ -525,7 +509,8 @@ public void run() {
525509 String [] commandMethodParts = command .split ("(\\ ((?!\\ ))|,|(?<!\\ ()\\ ))" ); //split out parameter in brackets
526510 if (commandMethodParts .length > 1 ) { //has parameter
527511 commandMethod = commandMethodParts [0 ];
528- parameter = commandMethodParts [1 ].replaceAll ("\\ $0" , buffer );
512+ parameter = replaceDollarWords (commandMethodParts [1 ]);
513+
529514 } else {
530515 commandMethod = commandMethodParts [0 ];
531516 }
@@ -551,6 +536,27 @@ public void run() {
551536
552537 }
553538
539+ private String replaceDollarWords (String initial ) {
540+ String newWord = initial ;
541+ if (buffer != null ) {
542+ newWord = newWord .replace ("$0" , buffer );
543+ }
544+ if (KboardAccessibilityService .getCurrentWhatsappName () != null ) {
545+ String fullName = KboardAccessibilityService .getCurrentWhatsappName ();
546+ String [] names = fullName .split (" " );
547+
548+ if (names .length > 1 ) {
549+ newWord = newWord .replace ("$fname" , names [0 ]);
550+ newWord = newWord .replace ("$lname" , names [1 ]);
551+ } else {
552+ newWord = newWord .replace ("$fname" , fullName );
553+ }
554+
555+ newWord = newWord .replace ("$name" , KboardAccessibilityService .getCurrentWhatsappName ());
556+ }
557+ return newWord ;
558+ }
559+
554560 private void execute (String cmd , int n , String parameter ) {
555561 inputConnection .beginBatchEdit ();
556562
0 commit comments