// Path: RetroShareAndroidIntegration/src/org/retroshare/android/RsConversationService.java
// public static class RsConversationServiceListenerUniqueHandleFactory
// {
// 	public static Long getNewUniqueHandle()
// 	{
// 		Long ret = new Long(System.currentTimeMillis());
// 		while(repository.contains(ret)) ret = new Long(System.currentTimeMillis() + (long)ret.hashCode());
// 		repository.add(ret);
// 		return ret;
// 	}
// 	private static final Set<Long> repository = new WeakHashSet<Long>();
// }


import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.database.DataSetObserver;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.SystemClock;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.retroshare.android.RsConversationService.RsConversationServiceListenerUniqueHandleFactory;
import rsctrl.chat.Chat;
		return fv;
	}
	@Override public void onAttach(Activity a)
	{
		super.onAttach(a);
		mInflater = a.getLayoutInflater();
	}
	@Override public void onServiceConnected(ComponentName className, IBinder service)
	{
		super.onServiceConnected(className, service);
		if(mHandler == null) mHandler = new Handler();
		mHandler.post(new RequestLobbiesListUpdateRunnable());
	}
	@Override public void registerRsServicesListeners() { getConnectedServer().mRsConversationService.registerRsConversationServiceListener(lobbiesListAdapter); }
	@Override public void unregisterRsServicesListeners() { getConnectedServer().mRsConversationService.unregisterRsConversationServiceListener(lobbiesListAdapter); }
	@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)
	{
		super.onCreateContextMenu(menu, v, menuInfo);
		getActivity().getMenuInflater().inflate(R.menu.lobbies_list_context_menu, menu);
		int position = ((AdapterView.AdapterContextMenuInfo)menuInfo).position;
		Chat.ChatLobbyInfo info = lobbiesList.get(position);
		boolean joined = info.getLobbyState().equals(Chat.ChatLobbyInfo.LobbyState.LOBBYSTATE_JOINED);
		menu.findItem(R.id.join_lobby_menu_item).setVisible(!joined).setOnMenuItemClickListener(new JoinLobbyMenuItemClickListener(position));
		menu.findItem(R.id.leave_lobby_menu_item).setVisible(joined).setOnMenuItemClickListener(new LeaveLobbyMenuItemClickListener(position));
		menu.findItem(R.id.lobby_show_details_menu_item).setOnMenuItemClickListener(new ShowLobbyInfoMenuItemClickListener(position));
	}

	private class LobbiesListAdapter implements ListAdapter, RsConversationService.RsConversationServiceListener, AdapterView.OnItemClickListener
	{
		/** Implements RsConversationServiceListener */
// Path: RetroShareAndroidIntegration/src/org/retroshare/android/RsConversationService.java
// public static class RsConversationServiceListenerUniqueHandleFactory
// {
// 	public static Long getNewUniqueHandle()
// 	{
// 		Long ret = new Long(System.currentTimeMillis());
// 		while(repository.contains(ret)) ret = new Long(System.currentTimeMillis() + (long)ret.hashCode());
// 		repository.add(ret);
// 		return ret;
// 	}
// 	private static final Set<Long> repository = new WeakHashSet<Long>();
// }


// Path: RetroShareAndroidIntegration/src/org/retroshare/android/LobbiesListFragment.java
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.database.DataSetObserver;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.SystemClock;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.retroshare.android.RsConversationService.RsConversationServiceListenerUniqueHandleFactory;
import rsctrl.chat.Chat;

		return fv;
	}
	@Override public void onAttach(Activity a)
	{
		super.onAttach(a);
		mInflater = a.getLayoutInflater();
	}
	@Override public void onServiceConnected(ComponentName className, IBinder service)
	{
		super.onServiceConnected(className, service);
		if(mHandler == null) mHandler = new Handler();
		mHandler.post(new RequestLobbiesListUpdateRunnable());
	}
	@Override public void registerRsServicesListeners() { getConnectedServer().mRsConversationService.registerRsConversationServiceListener(lobbiesListAdapter); }
	@Override public void unregisterRsServicesListeners() { getConnectedServer().mRsConversationService.unregisterRsConversationServiceListener(lobbiesListAdapter); }
	@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)
	{
		super.onCreateContextMenu(menu, v, menuInfo);
		getActivity().getMenuInflater().inflate(R.menu.lobbies_list_context_menu, menu);
		int position = ((AdapterView.AdapterContextMenuInfo)menuInfo).position;
		Chat.ChatLobbyInfo info = lobbiesList.get(position);
		boolean joined = info.getLobbyState().equals(Chat.ChatLobbyInfo.LobbyState.LOBBYSTATE_JOINED);
		menu.findItem(R.id.join_lobby_menu_item).setVisible(!joined).setOnMenuItemClickListener(new JoinLobbyMenuItemClickListener(position));
		menu.findItem(R.id.leave_lobby_menu_item).setVisible(joined).setOnMenuItemClickListener(new LeaveLobbyMenuItemClickListener(position));
		menu.findItem(R.id.lobby_show_details_menu_item).setOnMenuItemClickListener(new ShowLobbyInfoMenuItemClickListener(position));
	}

	private class LobbiesListAdapter implements ListAdapter, RsConversationService.RsConversationServiceListener, AdapterView.OnItemClickListener
	{
		/** Implements RsConversationServiceListener */
		private final Long handle = RsConversationServiceListenerUniqueHandleFactory.getNewUniqueHandle();