Skip to content

Commit dfdef4f

Browse files
committed
fixed #3
1 parent ab37a75 commit dfdef4f

File tree

5 files changed

+36
-27
lines changed

5 files changed

+36
-27
lines changed

android/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/src/main/java/com/divyanshushekhar/flutter_process_text/EventCallHandlerImplementation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class EventCallHandlerImplementation implements StreamHandler {
1818
private static EventSink mEventSink = null;
1919
@SuppressLint("StaticFieldLeak")
2020
private static Activity activity = null;
21+
@SuppressLint("StaticFieldLeak")
2122
private static Context context = null;
2223

2324
EventCallHandlerImplementation(Context context,Activity activity) {
@@ -46,7 +47,6 @@ public static void onProcessTextChanged() {
4647
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
4748
textIntent = activity.getIntent().getStringExtra(Intent.EXTRA_PROCESS_TEXT);
4849
} else {
49-
textIntent = null;
5050
Log.e(TAG,"Compatibility Issue:");
5151
Log.i(TAG,"Make sure device android version >= M (Marshmallow)");
5252
}

android/src/main/java/com/divyanshushekhar/flutter_process_text/FlutterProcessTextPlugin.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,20 @@ public static String getPluginTag() {
5252

5353

5454
/* ------------- User Initialization -------------- */
55-
private static boolean showToast = true;
55+
private static boolean showConfirmationToast = true;
56+
private static boolean showRefreshToast = true;
57+
private static boolean showErrorToast = true;
5658
private static String confirmationMessage = null;
5759
private static String refreshMessage = null;
5860
private static String errorMessage = null;
5961

60-
public static void setUserInitialization(boolean showToast, String confirmationMessage, String refreshMessage, String errorMessage) {
61-
FlutterProcessTextPlugin.showToast = showToast;
62+
public static void setUserInitialization(boolean showConfirmationToast, boolean showRefreshToast,
63+
boolean showErrorToast, String confirmationMessage,
64+
String refreshMessage, String errorMessage) {
65+
66+
FlutterProcessTextPlugin.showConfirmationToast = showConfirmationToast;
67+
FlutterProcessTextPlugin.showRefreshToast = showRefreshToast;
68+
FlutterProcessTextPlugin.showErrorToast = showErrorToast;
6269
FlutterProcessTextPlugin.confirmationMessage = confirmationMessage;
6370
FlutterProcessTextPlugin.refreshMessage = refreshMessage;
6471
FlutterProcessTextPlugin.errorMessage = errorMessage;
@@ -67,19 +74,19 @@ public static void setUserInitialization(boolean showToast, String confirmationM
6774

6875
/* ------------- Toast Messages -------------- */
6976
public static void showConfirmationToast() {
70-
if(showToast) {
77+
if(showConfirmationToast) {
7178
Toast.makeText(context, confirmationMessage, Toast.LENGTH_LONG).show();
7279
}
7380
}
7481

7582
public static void showRefreshToast() {
76-
if(showToast) {
83+
if(showRefreshToast) {
7784
Toast.makeText(context, refreshMessage, Toast.LENGTH_LONG).show();
7885
}
7986
}
8087

8188
public static void showErrorToast() {
82-
if(showToast) {
89+
if(showErrorToast) {
8390
Toast.makeText(context, errorMessage, Toast.LENGTH_LONG).show();
8491
}
8592
}
@@ -120,7 +127,7 @@ private void setupChannel(BinaryMessenger messenger, Context context, Activity a
120127
methodChannel = new MethodChannel(binaryMessenger, CHANNEL_ID);
121128
eventChannel = new EventChannel(binaryMessenger,STREAM_ID);
122129

123-
methodHandler = new MethodCallHandlerImplementation(context, activity);
130+
methodHandler = new MethodCallHandlerImplementation();
124131
eventHandler = new EventCallHandlerImplementation(context, activity);
125132

126133
methodChannel.setMethodCallHandler(methodHandler);
@@ -161,7 +168,6 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
161168
@Override
162169
public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) {
163170
activity = binding.getActivity();
164-
methodHandler.setActivity(activity);
165171
EventCallHandlerImplementation.setActivity(activity);
166172
}
167173

@@ -177,7 +183,6 @@ public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBindin
177183

178184
@Override
179185
public void onDetachedFromActivity() {
180-
methodHandler.setActivity(null);
181186
EventCallHandlerImplementation.setActivity(null);
182187
}
183188

android/src/main/java/com/divyanshushekhar/flutter_process_text/MethodCallHandlerImplementation.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,19 @@ public class MethodCallHandlerImplementation implements MethodChannel.MethodCall
1515

1616
private static final String TAG = FlutterProcessTextPlugin.getPluginTag();
1717

18-
private final Context context;
19-
private Activity activity;
20-
21-
MethodCallHandlerImplementation(Context context, Activity activity) {
22-
this.context = context;
23-
this.activity = activity;
24-
}
25-
26-
void setActivity(Activity activity) {
27-
this.activity = activity;
28-
}
18+
public MethodCallHandlerImplementation() {}
2919

3020
@Override
3121
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
3222
if (call.method.equals("initialize")) {
3323
Map<String, String> arguments = call.arguments();
3424
// Setting User Initialization coming from flutter side
35-
FlutterProcessTextPlugin.setUserInitialization(Boolean.parseBoolean(arguments.get("showToast")),
36-
arguments.get("confirmationMessage"), arguments.get("refreshMessage"),
25+
FlutterProcessTextPlugin.setUserInitialization(
26+
Boolean.parseBoolean(arguments.get("showConfirmationToast")),
27+
Boolean.parseBoolean(arguments.get("showRefreshToast")),
28+
Boolean.parseBoolean(arguments.get("showErrorToast")),
29+
arguments.get("confirmationMessage"),
30+
arguments.get("refreshMessage"),
3731
arguments.get("errorMessage"));
3832
} else if (call.method.equals("getRefreshProcessText")) {
3933
try {

lib/flutter_process_text.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,30 @@ class FlutterProcessText {
1212
static Stream<String>? _processTextStream;
1313

1414
/// Initialize FlutterProcessText Plugins.
15-
/// showToast<bool> - if true, will show a toast message, else not.
15+
/// bool Confirmation, Refresh and Error Toast.
1616
/// set ConfirmationMessage to show a confirmation message in the Toast.
1717
/// set refreshMessage to show a refresh message in the Toast.
1818
/// set errorMessage to show a error message in the Toast.
1919
static Future<void> initialize({
20-
bool showToast = true,
20+
bool showConfirmationToast = true,
21+
bool showRefreshToast = true,
22+
bool showErrorToast = true,
2123
String confirmationMessage = "Text Fetched",
2224
String refreshMessage = "Refreshed",
2325
String errorMessage = "Unable to fetch text!",
2426
}) async {
2527
return await _channel.invokeMethod('initialize', {
26-
'showToast': showToast.toString(),
28+
'showConfirmationToast': showConfirmationToast.toString(),
29+
'showRefreshToast': showRefreshToast.toString(),
30+
'showErrorToast': showErrorToast.toString(),
2731
'confirmationMessage': confirmationMessage,
2832
'refreshMessage': refreshMessage,
2933
'errorMessage': errorMessage,
3034
});
3135
}
3236

3337
/// Get the pending data by refreshing the process text
34-
static Future<String> get refreshProcessText async {
38+
static Future<String?> get refreshProcessText async {
3539
return await _channel.invokeMethod('getRefreshProcessText');
3640
}
3741

0 commit comments

Comments
 (0)