|
@@ -55,8 +55,8 @@ public class CPDFViewCtrlFlutter implements PlatformView, MethodChannel.MethodCa
|
|
|
Log.e(LOG_TAG, "CPDFViewCtrlFlutter:Create CPDFDocumentFragment");
|
|
|
initCPDFViewCtrl(context, creationParams);
|
|
|
|
|
|
- String channelName = "com.compdfkit.flutter.ui.pdfviewer."+ viewId;
|
|
|
- Log.e(LOG_TAG, "CPDFViewCtrlFlutter: create MethodChannel:"+ channelName);
|
|
|
+ String channelName = "com.compdfkit.flutter.ui.pdfviewer." + viewId;
|
|
|
+ Log.e(LOG_TAG, "CPDFViewCtrlFlutter: create MethodChannel:" + channelName);
|
|
|
methodChannel = new MethodChannel(binaryMessenger, channelName);
|
|
|
methodChannel.setMethodCallHandler(this);
|
|
|
}
|
|
@@ -75,6 +75,7 @@ public class CPDFViewCtrlFlutter implements PlatformView, MethodChannel.MethodCa
|
|
|
fragmentContainerView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
|
|
|
@Override
|
|
|
public void onViewAttachedToWindow(@NonNull View v) {
|
|
|
+ Log.e(LOG_TAG, "CPDFViewCtrlFlutter: Attached CPDFDocumentFragment to window");
|
|
|
FragmentActivity fragmentActivity = getFragmentActivity(context);
|
|
|
if (fragmentActivity != null) {
|
|
|
fragmentActivity.getSupportFragmentManager()
|
|
@@ -87,18 +88,31 @@ public class CPDFViewCtrlFlutter implements PlatformView, MethodChannel.MethodCa
|
|
|
|
|
|
@Override
|
|
|
public void onViewDetachedFromWindow(@NonNull View v) {
|
|
|
- FragmentActivity fragmentActivity = getFragmentActivity(context);
|
|
|
- if (fragmentActivity != null) {
|
|
|
- fragmentActivity.getSupportFragmentManager()
|
|
|
- .beginTransaction()
|
|
|
- .remove(documentFragment)
|
|
|
- .setReorderingAllowed(true)
|
|
|
- .commit();
|
|
|
- }
|
|
|
+ documentFragment.pdfView.savePDF((s, uri) -> {
|
|
|
+ Log.e(LOG_TAG, "CPDFViewCtrlFlutter: pdfView.savePDF Success");
|
|
|
+ detachedFragment(context);
|
|
|
+ }, e -> {
|
|
|
+ Log.e(LOG_TAG, "CPDFViewCtrlFlutter: pdfView.savePDF Fail");
|
|
|
+ e.printStackTrace();
|
|
|
+ detachedFragment(context);
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private void detachedFragment(Context context){
|
|
|
+ Log.e(LOG_TAG, "CPDFViewCtrlFlutter: Detached CPDFDocumentFragment from window");
|
|
|
+ FragmentActivity fragmentActivity = getFragmentActivity(context);
|
|
|
+ if (fragmentActivity != null) {
|
|
|
+ fragmentActivity.getSupportFragmentManager()
|
|
|
+ .beginTransaction()
|
|
|
+ .remove(documentFragment)
|
|
|
+ .setReorderingAllowed(true)
|
|
|
+ .commit();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Nullable
|
|
|
@Override
|
|
|
public View getView() {
|
|
@@ -117,7 +131,8 @@ public class CPDFViewCtrlFlutter implements PlatformView, MethodChannel.MethodCa
|
|
|
|
|
|
@Override
|
|
|
public void dispose() {
|
|
|
- fragmentContainerView = null;
|
|
|
+ Log.e(LOG_TAG, "CPDFViewCtrlFlutter: dispose()");
|
|
|
+ fragmentContainerView = null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -131,7 +146,7 @@ public class CPDFViewCtrlFlutter implements PlatformView, MethodChannel.MethodCa
|
|
|
}
|
|
|
|
|
|
private FragmentActivity getFragmentActivity(Context context) {
|
|
|
- if (context instanceof FragmentActivity){
|
|
|
+ if (context instanceof FragmentActivity) {
|
|
|
return (FragmentActivity) context;
|
|
|
} else if (context instanceof MutableContextWrapper) {
|
|
|
return getFragmentActivity(((MutableContextWrapper) context).getBaseContext());
|