@@ -0,0 +1,3900 @@
+package com.alwaysallthetime.adnlibutils;%0A%0Aimport com.alwaysallthetime.adnlib.AppDotNetClient;%0Aimport com.alwaysallthetime.adnlib.QueryParameters;%0Aimport com.alwaysallthetime.adnlib.data.Channel;%0Aimport com.alwaysallthetime.adnlib.data.ChannelList;%0Aimport com.alwaysallthetime.adnlib.data.User;%0Aimport com.alwaysallthetime.adnlib.response.ChannelListResponseHandler;%0Aimport com.alwaysallthetime.adnlib.response.ChannelResponseHandler;%0A%0Aimport java.util.HashMap;%0A%0A/**%0A * A utility for creating and retrieving channels that are intended to be used%0A * privately, by a single user - based on how Ohai does it.%0A *%0A * See: https://github.com/appdotnet/object-metadata/blob/master/channel-types/net.app.ohai.journal.md%0A */%0Apublic class PrivateChannelUtility %7B%0A    private static HashMap%3CString, Channel%3E sChannels = new HashMap%3CString, Channel%3E();%0A%0A    public interface PrivateChannelHandler %7B%0A        public void onResponse(Channel channel);%0A        public void onError(Exception error);%0A    %7D%0A%0A    public static Channel getChannel(String channelType) %7B%0A        return sChannels.get(channelType);%0A    %7D%0A%0A    public static void retrieveChannel(AppDotNetClient client, final String channelType, final PrivateChannelHandler handler) %7B%0A        QueryParameters params = new QueryParameters();%0A        params.put(%22channel_types%22, channelType);%0A        client.retrieveCurrentUserSubscribedChannels(params, new ChannelListResponseHandler() %7B%0A            @Override%0A            public void onSuccess(ChannelList responseData) %7B%0A                Channel theChannel = null;%0A%0A                if(responseData.size() == 1) %7B%0A                    theChannel = responseData.get(0);%0A                %7D else if(responseData.size() %3E 1) %7B%0A                    User currentUser = ADNSharedPreferences.getToken().getUser();%0A                    for(Channel channel : responseData) %7B%0A                        Channel.Acl writers = channel.getWriters();%0A%0A                        if(channel.getOwner().getId().equals(currentUser.getId()) &&%0A                                writers.isImmutable() && writers.isCurrentUserAuthorized() && !writers.isAnyUser() && !channel.getReaders().isImmutable()) %7B%0A                            if(theChannel == null %7C%7C Integer.valueOf(channel.getId()) %3C Integer.valueOf(theChannel.getId())) %7B%0A                                theChannel = channel;%0A                            %7D%0A                        %7D%0A                    %7D%0A                %7D%0A%0A                sChannels.put(channelType, theChannel);%0A                handler.onResponse(theChannel);%0A            %7D%0A%0A            @Override%0A            public void onError(Exception error) %7B%0A                handler.onError(error);%0A            %7D%0A        %7D);%0A    %7D%0A%0A    public static void createChannel(final AppDotNetClient client, final String channelType, final PrivateChannelHandler handler) %7B%0A        User currentUser = ADNSharedPreferences.getToken().getUser();%0A%0A        Channel c = new Channel();%0A        c.setType(channelType);%0A%0A        Channel.Acl writer = new Channel.Acl(true);%0A        writer.setUserIds(new String%5B%5D %7B currentUser.getId() %7D);%0A        writer.setAnyUser(false);%0A%0A        Channel.Acl reader = new Channel.Acl(false);%0A%0A        c.setWriters(writer);%0A        c.setReaders(reader);%0A%0A        client.createChannel(c, new ChannelResponseHandler() %7B%0A            @Override%0A            public void onSuccess(final Channel responseData) %7B%0A                client.subscribeChannel(responseData, new ChannelResponseHandler() %7B%0A                    @Override%0A                    public void onSuccess(Channel responseData) %7B%0A                        sChannels.put(channelType, responseData);%0A                        handler.onResponse(responseData);%0A                    %7D%0A                %7D);%0A            %7D%0A%0A            @Override%0A            public void onError(Exception error) %7B%0A                handler.onError(error);%0A            %7D%0A        %7D);%0A    %7D%0A%7D%0A

add PrivateChannelUtility for creating channels like Ohai does, but of any channel type