All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xworker.gluon.attach.ShareActions Maven / Gradle / Ivy

The newest version!
package xworker.gluon.attach;

import com.gluonhq.attach.share.ShareService;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.lang.executor.Executor;

import java.io.File;

public class ShareActions {
    private static final String TAG = ShareActions.class.getName();
    public static void share(ActionContext actionContext){
        Thing self = actionContext.getObject("self");
        String subject = self.doAction("getSubject", actionContext);
        String type = self.doAction("getType", actionContext);
        File file = self.doAction("getFile", actionContext);
        String contentText = self.doAction("getContentText", actionContext);

        ShareService service = ShareService.create().orElse(null);
        if(service != null){
            if(file == null && (subject == null || subject.isEmpty())){
                service.share(contentText);
            }else if(file == null){
                service.share(subject, contentText);
            }else {
                service.share(subject, contentText, type, file);
            }
        }else{
            Executor.warn(TAG, "Can not share, ShareService.create() return null.");
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy