1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-11 03:35:07 -05:00
Yaaic/app/src/main/java/org/yaaic/Yaaic.java

148 lines
3.2 KiB
Java
Raw Normal View History

2009-12-17 15:27:57 -05:00
/*
2010-03-12 14:35:25 -05:00
Yaaic - Yet Another Android IRC Client
2009-12-17 15:27:57 -05:00
2013-01-21 15:32:43 -05:00
Copyright 2009-2013 Sebastian Kaspari
2009-12-17 15:27:57 -05:00
This file is part of Yaaic.
Yaaic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Yaaic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
2011-01-25 15:02:27 -05:00
*/
2009-12-17 15:27:57 -05:00
package org.yaaic;
import java.util.ArrayList;
import java.util.HashMap;
2010-03-21 11:36:16 -04:00
import java.util.Set;
2009-12-17 15:27:57 -05:00
import org.yaaic.db.Database;
2009-12-17 15:27:57 -05:00
import org.yaaic.model.Server;
import android.content.Context;
2009-12-17 15:27:57 -05:00
/**
* Global Master Class :)
*
* @author Sebastian Kaspari <sebastian@yaaic.org>
*/
public class Yaaic
{
2011-01-25 15:02:27 -05:00
public static Yaaic instance;
2010-11-18 12:52:19 -05:00
private HashMap<Integer, Server> servers;
2011-01-25 15:02:27 -05:00
private boolean serversLoaded = false;
2010-11-18 12:52:19 -05:00
/**
* Private constructor, you may want to use static getInstance()
*/
private Yaaic()
{
servers = new HashMap<Integer, Server>();
}
2011-01-25 15:02:27 -05:00
2010-11-18 12:52:19 -05:00
/**
* Load servers from database
*
* @param context
*/
public void loadServers(Context context)
{
if (!serversLoaded) {
Database db = new Database(context);
servers = db.getServers();
db.close();
2011-01-25 15:02:27 -05:00
// context.sendBroadcast(new Intent(Broadcast.SERVER_UPDATE));
2010-11-18 12:52:19 -05:00
serversLoaded = true;
}
}
2011-01-25 15:02:27 -05:00
2010-11-18 12:52:19 -05:00
/**
* Get global Yaaic instance
*
* @return the global Yaaic instance
*/
public static Yaaic getInstance()
{
if (instance == null) {
2011-01-25 15:02:27 -05:00
instance = new Yaaic();
2010-11-18 12:52:19 -05:00
}
2011-01-25 15:02:27 -05:00
2010-11-18 12:52:19 -05:00
return instance;
}
2011-01-25 15:02:27 -05:00
2010-11-18 12:52:19 -05:00
/**
* Get server by id
*
* @return Server object with given unique id
*/
public Server getServerById(int serverId)
{
return servers.get(serverId);
}
2011-01-25 15:02:27 -05:00
2010-11-18 12:52:19 -05:00
/**
* Remove server with given unique id from list
*
* @param serverId
*/
public void removeServerById(int serverId)
{
servers.remove(serverId);
}
2011-01-25 15:02:27 -05:00
2010-11-18 12:52:19 -05:00
/**
* Set servers
*
* @param servers
*/
public void setServers(HashMap<Integer, Server> servers)
{
this.servers = servers;
}
2011-01-25 15:02:27 -05:00
2010-11-18 12:52:19 -05:00
/**
* Add server to list
*/
public void addServer(Server server)
{
if (!servers.containsKey(server.getId())) {
servers.put(server.getId(), server);
}
}
2011-01-25 15:02:27 -05:00
2010-11-18 12:52:19 -05:00
/**
* Update a server in list
*/
public void updateServer(Server server)
{
servers.put(server.getId(), server);
}
2011-01-25 15:02:27 -05:00
2010-11-18 12:52:19 -05:00
/**
* Get list of servers
*
* @return list of servers
*/
public ArrayList<Server> getServersAsArrayList()
{
ArrayList<Server> serverList = new ArrayList<Server>();
2011-01-25 15:02:27 -05:00
2010-11-18 12:52:19 -05:00
Set<Integer> mKeys = servers.keySet();
for (int key : mKeys) {
serverList.add(servers.get(key));
}
2011-01-25 15:02:27 -05:00
2010-11-18 12:52:19 -05:00
return serverList;
}
2009-12-17 15:27:57 -05:00
}