diff --git a/app/build.gradle b/app/build.gradle
index 27021fc..478dfa2 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -22,6 +22,8 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:22.0.0'
+ compile 'com.android.support:cardview-v7:22.0.0'
+ compile "com.android.support:recyclerview-v7:22.0.0"
compile 'com.viewpagerindicator:library:2.4.1@aar'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 4087fca..95cb7ed 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -27,12 +27,11 @@ along with Yaaic. If not, see .
-
diff --git a/app/src/main/java/org/yaaic/activity/MainActivity.java b/app/src/main/java/org/yaaic/activity/MainActivity.java
new file mode 100644
index 0000000..7e9ff91
--- /dev/null
+++ b/app/src/main/java/org/yaaic/activity/MainActivity.java
@@ -0,0 +1,101 @@
+/*
+Yaaic - Yet Another Android IRC Client
+
+Copyright 2009-2015 Sebastian Kaspari
+
+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 .
+ */
+package org.yaaic.activity;
+
+import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.Bundle;
+import android.os.IBinder;
+
+import org.yaaic.R;
+import org.yaaic.fragment.OverviewFragment;
+import org.yaaic.irc.IRCBinder;
+import org.yaaic.irc.IRCService;
+import org.yaaic.model.Extra;
+import org.yaaic.model.Server;
+import org.yaaic.model.Status;
+
+/**
+ * The main activity of Yaaic. We'll add, remove and replace fragments here.
+ */
+public class MainActivity extends Activity implements OverviewFragment.Callback, ServiceConnection {
+ private IRCBinder binder;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.activity_main);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ Intent intent = new Intent(this, IRCService.class);
+ intent.setAction(IRCService.ACTION_BACKGROUND);
+ startService(intent);
+
+ bindService(intent, this, 0);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+
+ if (binder != null && binder.getService() != null) {
+ binder.getService().checkServiceStatus();
+ }
+
+ unbindService(this);
+ }
+
+ @Override
+ public void onServerSelected(Server server) {
+ Intent intent = new Intent(this, ConversationActivity.class);
+
+ if (server.getStatus() == Status.DISCONNECTED && !server.mayReconnect()) {
+ server.setStatus(Status.PRE_CONNECTING);
+ intent.putExtra(Extra.CONNECT, true);
+ }
+
+ intent.putExtra(Extra.SERVER_ID, server.getId());
+ startActivity(intent);
+
+ }
+
+ @Override
+ public IRCBinder getBinder() {
+ return binder;
+ }
+
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ binder = (IRCBinder) service;
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ binder = null;
+ }
+}
diff --git a/app/src/main/java/org/yaaic/activity/ServersActivity.java b/app/src/main/java/org/yaaic/activity/ServersActivity.java
deleted file mode 100644
index 434d9b7..0000000
--- a/app/src/main/java/org/yaaic/activity/ServersActivity.java
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
-Yaaic - Yet Another Android IRC Client
-
-Copyright 2009-2013 Sebastian Kaspari
-
-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 .
- */
-package org.yaaic.activity;
-
-import java.util.ArrayList;
-
-import org.yaaic.R;
-import org.yaaic.Yaaic;
-import org.yaaic.adapter.ServerListAdapter;
-import org.yaaic.db.Database;
-import org.yaaic.irc.IRCBinder;
-import org.yaaic.irc.IRCService;
-import org.yaaic.listener.ServerListener;
-import org.yaaic.model.Broadcast;
-import org.yaaic.model.Extra;
-import org.yaaic.model.Server;
-import org.yaaic.model.Status;
-import org.yaaic.receiver.ServerReceiver;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.ComponentName;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.ServiceConnection;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.AdapterView.OnItemLongClickListener;
-import android.widget.ListView;
-import android.widget.Toast;
-
-/**
- * List of servers
- *
- * @author Sebastian Kaspari
- */
-public class ServersActivity extends Activity implements ServiceConnection, ServerListener, OnItemClickListener, OnItemLongClickListener {
- private IRCBinder binder;
- private ServerReceiver receiver;
- private ServerListAdapter adapter;
- private ListView list;
- private static int instanceCount = 0;
-
- /**
- * On create
- */
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- /*
- * With activity:launchMode = standard, we get duplicated activities
- * depending on the task the app was started in. In order to avoid
- * stacking up of this duplicated activities we keep a count of this
- * root activity and let it finish if it already exists
- *
- * Launching the app via the notification icon creates a new task,
- * and there doesn't seem to be a way around this so this is needed
- */
- if (instanceCount > 0) {
- finish();
- }
- instanceCount++;
- setContentView(R.layout.servers);
-
- adapter = new ServerListAdapter();
-
- list = (ListView) findViewById(android.R.id.list);
- list.setAdapter(adapter);
- list.setOnItemClickListener(this);
- list.setOnItemLongClickListener(this);
- }
-
- /**
- * On Destroy
- */
- @Override
- public void onDestroy()
- {
- super.onDestroy();
- instanceCount--;
- }
-
- /**
- * On resume
- */
- @Override
- public void onResume()
- {
- super.onResume();
-
- // Start and connect to service
- Intent intent = new Intent(this, IRCService.class);
- intent.setAction(IRCService.ACTION_BACKGROUND);
- startService(intent);
- bindService(intent, this, 0);
-
- receiver = new ServerReceiver(this);
- registerReceiver(receiver, new IntentFilter(Broadcast.SERVER_UPDATE));
-
- adapter.loadServers();
- }
-
- /**
- * On pause
- */
- @Override
- public void onPause()
- {
- super.onPause();
-
- if (binder != null && binder.getService() != null) {
- binder.getService().checkServiceStatus();
- }
-
- unbindService(this);
- unregisterReceiver(receiver);
- }
-
- /**
- * Service connected to Activity
- */
- @Override
- public void onServiceConnected(ComponentName name, IBinder service)
- {
- binder = (IRCBinder) service;
- }
-
- /**
- * Service disconnected from Activity
- */
- @Override
- public void onServiceDisconnected(ComponentName name)
- {
- binder = null;
- }
-
- /**
- * On server selected
- */
- @Override
- public void onItemClick(AdapterView> parent, View view, int position, long id) {
- Server server = adapter.getItem(position);
-
- if (server == null) {
- // "Add server" was selected
- startActivityForResult(new Intent(this, AddServerActivity.class), 0);
- return;
- }
-
- Intent intent = new Intent(this, ConversationActivity.class);
-
- if (server.getStatus() == Status.DISCONNECTED && !server.mayReconnect()) {
- server.setStatus(Status.PRE_CONNECTING);
- intent.putExtra("connect", true);
- }
-
- intent.putExtra("serverId", server.getId());
- startActivity(intent);
- }
-
- /**
- * On long click
- */
- @Override
- public boolean onItemLongClick(AdapterView> l, View v, int position, long id)
- {
- final Server server = adapter.getItem(position);
-
- if (server == null) {
- // "Add server" view selected
- return true;
- }
-
- final CharSequence[] items = {
- getString(R.string.connect),
- getString(R.string.disconnect),
- getString(R.string.edit),
- getString(R.string.delete)
- };
-
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(server.getTitle());
- builder.setItems(items, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int item) {
- switch (item) {
- case 0: // Connect
- if (server.getStatus() == Status.DISCONNECTED) {
- binder.connect(server);
- server.setStatus(Status.CONNECTING);
- adapter.notifyDataSetChanged();
- }
- break;
- case 1: // Disconnect
- server.clearConversations();
- server.setStatus(Status.DISCONNECTED);
- server.setMayReconnect(false);
- binder.getService().getConnection(server.getId()).quitServer();
- break;
- case 2: // Edit
- editServer(server.getId());
- break;
- case 3: // Delete
- binder.getService().getConnection(server.getId()).quitServer();
- deleteServer(server.getId());
- break;
- }
- }
- });
- AlertDialog alert = builder.create();
- alert.show();
- return true;
- }
-
- /**
- * Start activity to edit server with given id
- *
- * @param serverId The id of the server
- */
- private void editServer(int serverId)
- {
- Server server = Yaaic.getInstance().getServerById(serverId);
-
- if (server.getStatus() != Status.DISCONNECTED) {
- Toast.makeText(this, getResources().getString(R.string.disconnect_before_editing), Toast.LENGTH_SHORT).show();
- }
- else {
- Intent intent = new Intent(this, AddServerActivity.class);
- intent.putExtra(Extra.SERVER, serverId);
- startActivityForResult(intent, 0);
- }
- }
-
- /**
- * Options Menu (Menu Button pressed)
- */
- @Override
- public boolean onCreateOptionsMenu(Menu menu)
- {
- super.onCreateOptionsMenu(menu);
-
- // inflate from xml
- MenuInflater inflater = new MenuInflater(this);
- inflater.inflate(R.menu.servers, menu);
-
- return true;
- }
-
- /**
- * On menu item selected
- */
- @Override
- public boolean onMenuItemSelected(int featureId, MenuItem item)
- {
- switch (item.getItemId()) {
- case R.id.add:
- startActivityForResult(new Intent(this, AddServerActivity.class), 0);
- break;
- case R.id.about:
- startActivity(new Intent(this, AboutActivity.class));
- break;
- case R.id.settings:
- startActivity(new Intent(this, SettingsActivity.class));
- break;
- case R.id.disconnect_all:
- ArrayList mServers = Yaaic.getInstance().getServersAsArrayList();
- for (Server server : mServers) {
- if (binder.getService().hasConnection(server.getId())) {
- server.setStatus(Status.DISCONNECTED);
- server.setMayReconnect(false);
- binder.getService().getConnection(server.getId()).quitServer();
- }
- }
- // ugly
- binder.getService().stopForegroundCompat(R.string.app_name);
- }
-
- return true;
- }
-
- /**
- * On activity result
- */
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data)
- {
- if (resultCode == RESULT_OK) {
- // Refresh list from database
- adapter.loadServers();
- }
- }
-
- /**
- * Delete server
- *
- * @param serverId
- */
- public void deleteServer(int serverId)
- {
- Database db = new Database(this);
- db.removeServerById(serverId);
- db.close();
-
- Yaaic.getInstance().removeServerById(serverId);
- adapter.loadServers();
- }
-
- /**
- * On server status update
- */
- @Override
- public void onStatusUpdate()
- {
- adapter.loadServers();
-
- if (adapter.getCount() > 2) {
- // Hide background if there are servers in the list
- list.setBackgroundDrawable(null);
- }
- }
-}
diff --git a/app/src/main/java/org/yaaic/adapter/ServerListAdapter.java b/app/src/main/java/org/yaaic/adapter/ServerListAdapter.java
deleted file mode 100644
index e1e492a..0000000
--- a/app/src/main/java/org/yaaic/adapter/ServerListAdapter.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
-Yaaic - Yet Another Android IRC Client
-
-Copyright 2009-2013 Sebastian Kaspari
-
-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 .
- */
-package org.yaaic.adapter;
-
-import java.util.ArrayList;
-
-import org.yaaic.R;
-import org.yaaic.Yaaic;
-import org.yaaic.model.Server;
-
-import android.content.Context;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.BaseAdapter;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-/**
- * Adapter for server lists
- *
- * @author Sebastian Kaspari
- */
-public class ServerListAdapter extends BaseAdapter
-{
- private static final int COLOR_CONNECTED = 0xFFbcbcbc;
- private static final int COLOR_DISCONNECTED = 0xFF585858;
-
- private ArrayList servers;
-
- /**
- * Create a new adapter for server lists
- */
- public ServerListAdapter()
- {
- loadServers();
- }
-
- /**
- * Load servers from database
- *
- * Delegate call to yaaic instance
- */
- public void loadServers()
- {
- servers = Yaaic.getInstance().getServersAsArrayList();
- notifyDataSetChanged();
- }
-
- /**
- * Get number of items
- */
- @Override
- public int getCount()
- {
- int size = servers.size();
-
- // Display "Add server" item
- if (size == 0) {
- return 1;
- }
-
- return size;
- }
-
- /**
- * Get item at position
- *
- * @param position
- */
- @Override
- public Server getItem(int position)
- {
- if (servers.size() == 0) {
- return null; // No server object for the "add server" view
- }
-
- return servers.get(position);
- }
-
- /**
- * Get id of item at position
- *
- * @param position
- */
- @Override
- public long getItemId(int position)
- {
- if (servers.size() == 0) {
- return 0;
- }
-
- return getItem(position).getId();
- }
-
- /**
- * Get view for item at given position
- *
- * @param position
- * @param convertView
- * @param parent
- */
- @Override
- public View getView(int position, View convertView, ViewGroup parent)
- {
- Server server = getItem(position);
-
- LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-
- if (server == null) {
- // Return "Add server" view
- return inflater.inflate(R.layout.addserveritem, null);
- }
-
- View v = inflater.inflate(R.layout.serveritem, null);
-
- TextView titleView = (TextView) v.findViewById(R.id.title);
- titleView.setText(server.getTitle());
-
- TextView hostView = (TextView) v.findViewById(R.id.host);
- hostView.setText(server.getIdentity().getNickname() + " @ " + server.getHost() + " : " + server.getPort());
-
- if (server.isConnected()) {
- titleView.setTextColor(COLOR_CONNECTED);
- hostView.setTextColor(COLOR_CONNECTED);
- } else {
- titleView.setTextColor(COLOR_DISCONNECTED);
- hostView.setTextColor(COLOR_DISCONNECTED);
- }
-
- ((ImageView) v.findViewById(R.id.status)).setImageResource(server.getStatusIcon());
-
- return v;
- }
-}
diff --git a/app/src/main/java/org/yaaic/adapter/ServersAdapter.java b/app/src/main/java/org/yaaic/adapter/ServersAdapter.java
new file mode 100644
index 0000000..e775ef7
--- /dev/null
+++ b/app/src/main/java/org/yaaic/adapter/ServersAdapter.java
@@ -0,0 +1,128 @@
+/*
+Yaaic - Yet Another Android IRC Client
+
+Copyright 2009-2013 Sebastian Kaspari
+
+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 .
+ */
+package org.yaaic.adapter;
+
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import org.yaaic.R;
+import org.yaaic.Yaaic;
+import org.yaaic.menu.ServerPopupMenu;
+import org.yaaic.model.Server;
+
+import java.util.List;
+
+/**
+ * RecyclerView adapter for server cards.
+ */
+public class ServersAdapter extends RecyclerView.Adapter {
+ public interface ClickListener {
+ void onServerSelected(Server server);
+ void onConnectToServer(Server server);
+ void onDisconnectFromServer(Server server);
+ void onEditServer(Server server);
+ void onDeleteServer(Server server);
+ }
+
+ public static class ViewHolder extends RecyclerView.ViewHolder {
+ public final TextView titleView;
+ public final TextView hostView;
+ public final View connectionView;
+ public final View menuView;
+ public final ServerPopupMenu popupMenu;
+
+ public ViewHolder(View view, ClickListener listener) {
+ super(view);
+
+ titleView = (TextView) view.findViewById(R.id.title);
+ hostView = (TextView) view.findViewById(R.id.host);
+ connectionView = view.findViewById(R.id.connection);
+ menuView = view.findViewById(R.id.menu);
+
+ popupMenu = new ServerPopupMenu(
+ view.getContext(), view.findViewById(R.id.menu),
+ listener
+ );
+ }
+ }
+
+ private List servers;
+ private ClickListener listener;
+
+ public ServersAdapter(ClickListener listener) {
+ this.listener = listener;
+
+ loadServers();
+ }
+
+ @Override
+ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ View view = LayoutInflater.
+ from(parent.getContext()).
+ inflate(R.layout.item_server, parent, false);
+
+ return new ViewHolder(view, listener);
+ }
+
+ @Override
+ public void onBindViewHolder(final ViewHolder holder, int position) {
+ final Server server = servers.get(position);
+
+ int colorResource = server.isConnected() ? R.color.connected : R.color.disconnected;
+ int color = holder.itemView.getContext().getResources().getColor(colorResource);
+
+ holder.titleView.setText(server.getTitle());
+ holder.titleView.setTextColor(color);
+ holder.connectionView.setBackgroundColor(color);
+ holder.hostView.setText(String.format("%s @ %s : %d",
+ server.getIdentity().getNickname(),
+ server.getHost(),
+ server.getPort()
+ ));
+
+ holder.itemView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ listener.onServerSelected(server);
+ }
+ });
+
+ holder.popupMenu.updateServer(server);
+ }
+
+ /**
+ * Load servers from database
+ *
+ * Delegate call to yaaic instance
+ */
+ public void loadServers() {
+ servers = Yaaic.getInstance().getServersAsArrayList();
+ notifyDataSetChanged();
+ }
+
+ @Override
+ public int getItemCount() {
+ return servers.size();
+ }
+}
diff --git a/app/src/main/java/org/yaaic/fragment/OverviewFragment.java b/app/src/main/java/org/yaaic/fragment/OverviewFragment.java
new file mode 100644
index 0000000..a9e4e57
--- /dev/null
+++ b/app/src/main/java/org/yaaic/fragment/OverviewFragment.java
@@ -0,0 +1,183 @@
+/*
+Yaaic - Yet Another Android IRC Client
+
+Copyright 2009-2015 Sebastian Kaspari
+
+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 .
+ */
+package org.yaaic.fragment;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ImageButton;
+import android.widget.Toast;
+
+import org.yaaic.R;
+import org.yaaic.Yaaic;
+import org.yaaic.activity.AddServerActivity;
+import org.yaaic.adapter.ServersAdapter;
+import org.yaaic.db.Database;
+import org.yaaic.irc.IRCBinder;
+import org.yaaic.irc.IRCService;
+import org.yaaic.listener.ServerListener;
+import org.yaaic.model.Broadcast;
+import org.yaaic.model.Extra;
+import org.yaaic.model.Server;
+import org.yaaic.model.Status;
+import org.yaaic.receiver.ServerReceiver;
+
+/**
+ * Fragment showing a list of configured servers.
+ */
+public class OverviewFragment extends Fragment implements ServerListener, ServersAdapter.ClickListener, View.OnClickListener {
+ /**
+ * Callback interface to be implemented by Activities using this fragment.
+ */
+ public interface Callback {
+ void onServerSelected(Server server);
+ IRCBinder getBinder();
+ }
+
+ private ServersAdapter adapter;
+ private Callback callback;
+ private BroadcastReceiver receiver;
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+
+ if (!(activity instanceof Callback)) {
+ throw new IllegalArgumentException("Activity has to implement Callback interface");
+ }
+
+ this.callback = (Callback) activity;
+ }
+
+ @Nullable
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.fragment_servers, container, false);
+
+ adapter = new ServersAdapter(this);
+
+ RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
+ recyclerView.setAdapter(adapter);
+ recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
+
+ ImageButton button = (ImageButton) view.findViewById(R.id.fab);
+ button.setOnClickListener(this);
+
+ return view;
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ receiver = new ServerReceiver(this);
+ getActivity().registerReceiver(receiver, new IntentFilter(Broadcast.SERVER_UPDATE));
+
+ adapter.loadServers();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+
+ getActivity().unregisterReceiver(receiver);
+ }
+
+ @Override
+ public void onClick(View view) {
+ final Context context = view.getContext();
+
+ Intent intent = new Intent(context, AddServerActivity.class);
+ context.startActivity(intent);
+ }
+
+ @Override
+ public void onServerSelected(Server server) {
+ callback.onServerSelected(server);
+ }
+
+ @Override
+ public void onConnectToServer(Server server) {
+ IRCBinder binder = callback.getBinder();
+
+ if (binder != null && server.getStatus() == Status.DISCONNECTED) {
+ binder.connect(server);
+ server.setStatus(Status.CONNECTING);
+ adapter.notifyDataSetChanged();
+ }
+ }
+
+ @Override
+ public void onDisconnectFromServer(Server server) {
+ IRCBinder binder = callback.getBinder();
+
+ if (binder != null) {
+ server.clearConversations();
+ server.setStatus(Status.DISCONNECTED);
+ server.setMayReconnect(false);
+ binder.getService().getConnection(server.getId()).quitServer();
+ }
+ }
+
+ @Override
+ public void onEditServer(Server server) {
+ if (server.getStatus() != Status.DISCONNECTED) {
+ Toast.makeText(getActivity(), getResources().getString(R.string.disconnect_before_editing), Toast.LENGTH_SHORT).show();
+ } else {
+ Intent intent = new Intent(getActivity(), AddServerActivity.class);
+ intent.putExtra(Extra.SERVER, server.getId());
+ startActivityForResult(intent, 0);
+ }
+
+ }
+
+ @Override
+ public void onDeleteServer(Server server) {
+ IRCBinder binder = callback.getBinder();
+
+ if (binder != null) {
+ binder.getService().getConnection(server.getId()).quitServer();
+
+ Database db = new Database(getActivity());
+ db.removeServerById(server.getId());
+ db.close();
+
+ Yaaic.getInstance().removeServerById(server.getId());
+ adapter.loadServers();
+ }
+ }
+
+ @Override
+ public void onStatusUpdate() {
+ adapter.loadServers();
+ }
+}
diff --git a/app/src/main/java/org/yaaic/menu/ServerPopupMenu.java b/app/src/main/java/org/yaaic/menu/ServerPopupMenu.java
new file mode 100644
index 0000000..4f72819
--- /dev/null
+++ b/app/src/main/java/org/yaaic/menu/ServerPopupMenu.java
@@ -0,0 +1,79 @@
+/*
+Yaaic - Yet Another Android IRC Client
+
+Copyright 2009-2013 Sebastian Kaspari
+
+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 .
+ */
+package org.yaaic.menu;
+
+import android.content.Context;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.PopupMenu;
+
+import org.yaaic.R;
+import org.yaaic.adapter.ServersAdapter;
+import org.yaaic.model.Server;
+
+/**
+ * Popup menu for the server cards.
+ */
+public class ServerPopupMenu extends PopupMenu implements PopupMenu.OnMenuItemClickListener, View.OnClickListener {
+ private Server server;
+ private ServersAdapter.ClickListener listener;
+
+ public ServerPopupMenu(Context context, View anchor, ServersAdapter.ClickListener listener) {
+ super(context, anchor);
+
+ this.listener = listener;
+
+ getMenuInflater().inflate(R.menu.context_server, getMenu());
+ setOnMenuItemClickListener(this);
+
+ anchor.setOnClickListener(this);
+ }
+
+ public void updateServer(Server server) {
+ this.server = server;
+ }
+
+ @Override
+ public boolean onMenuItemClick(MenuItem item) {
+ int id = item.getItemId();
+
+ switch (id) {
+ case R.id.edit:
+ listener.onEditServer(server);
+ break;
+ case R.id.delete:
+ listener.onDeleteServer(server);
+ break;
+ case R.id.connect:
+ listener.onConnectToServer(server);
+ break;
+ case R.id.disconnect:
+ listener.onDisconnectFromServer(server);
+ break;
+ }
+
+ return true;
+ }
+
+ public void onClick(View v) {
+ show();
+ }
+}
diff --git a/app/src/main/java/org/yaaic/model/Extra.java b/app/src/main/java/org/yaaic/model/Extra.java
index 101c5cb..6cb62a5 100644
--- a/app/src/main/java/org/yaaic/model/Extra.java
+++ b/app/src/main/java/org/yaaic/model/Extra.java
@@ -41,4 +41,7 @@ public class Extra
public static final String NICKSERV_PASSWORD = "nickserv_password";
public static final String SASL_USER = "sasl_user";
public static final String SASL_PASSWORD = "sasl_password";
+
+ public static final String CONNECT = "connect";
+ public static final String SERVER_ID = "serverId";
}
diff --git a/app/src/main/java/org/yaaic/model/Server.java b/app/src/main/java/org/yaaic/model/Server.java
index 368893a..a149444 100644
--- a/app/src/main/java/org/yaaic/model/Server.java
+++ b/app/src/main/java/org/yaaic/model/Server.java
@@ -409,26 +409,6 @@ public class Server
return channels;
}
- /**
- * Get icon for current server status
- *
- * @return int Status icon ressource
- */
- public int getStatusIcon()
- {
- switch (status) {
- case Status.CONNECTED:
- return R.drawable.connected;
- case Status.DISCONNECTED:
- return R.drawable.disconnected;
- case Status.PRE_CONNECTING:
- case Status.CONNECTING:
- return R.drawable.connecting;
- }
-
- return R.drawable.connecting;
- }
-
/**
* Get whether a ConversationActivity for this server is currently in the foreground.
*/
diff --git a/app/src/main/res/drawable-hdpi/ic_action_menu.png b/app/src/main/res/drawable-hdpi/ic_action_menu.png
new file mode 100755
index 0000000..88d538f
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_menu.png differ
diff --git a/app/src/main/res/drawable-mdpi/connected.png b/app/src/main/res/drawable-mdpi/connected.png
deleted file mode 100644
index e83d112..0000000
Binary files a/app/src/main/res/drawable-mdpi/connected.png and /dev/null differ
diff --git a/app/src/main/res/drawable-mdpi/connecting.png b/app/src/main/res/drawable-mdpi/connecting.png
deleted file mode 100644
index f93a006..0000000
Binary files a/app/src/main/res/drawable-mdpi/connecting.png and /dev/null differ
diff --git a/app/src/main/res/drawable-mdpi/disconnected.png b/app/src/main/res/drawable-mdpi/disconnected.png
deleted file mode 100644
index a77059b..0000000
Binary files a/app/src/main/res/drawable-mdpi/disconnected.png and /dev/null differ
diff --git a/app/src/main/res/drawable-mdpi/ic_action_menu.png b/app/src/main/res/drawable-mdpi/ic_action_menu.png
new file mode 100755
index 0000000..9f51be4
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_menu.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_action_menu.png b/app/src/main/res/drawable-xhdpi/ic_action_menu.png
new file mode 100755
index 0000000..7d69251
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_menu.png differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_menu.png b/app/src/main/res/drawable-xxhdpi/ic_action_menu.png
new file mode 100755
index 0000000..f61f9cb
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_menu.png differ
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..624ecd0
--- /dev/null
+++ b/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/addserveritem.xml b/app/src/main/res/layout/addserveritem.xml
deleted file mode 100644
index 136fa56..0000000
--- a/app/src/main/res/layout/addserveritem.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
diff --git a/app/src/main/res/layout/fragment_servers.xml b/app/src/main/res/layout/fragment_servers.xml
new file mode 100644
index 0000000..ed5041f
--- /dev/null
+++ b/app/src/main/res/layout/fragment_servers.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/item_server.xml b/app/src/main/res/layout/item_server.xml
new file mode 100644
index 0000000..df062e7
--- /dev/null
+++ b/app/src/main/res/layout/item_server.xml
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/serveritem.xml b/app/src/main/res/layout/serveritem.xml
deleted file mode 100644
index 649fc20..0000000
--- a/app/src/main/res/layout/serveritem.xml
+++ /dev/null
@@ -1,51 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/servers.xml b/app/src/main/res/layout/servers.xml
index f06b401..2f28257 100644
--- a/app/src/main/res/layout/servers.xml
+++ b/app/src/main/res/layout/servers.xml
@@ -19,7 +19,7 @@ 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 .
-->
-
@@ -27,4 +27,4 @@ along with Yaaic. If not, see .
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
-
+
diff --git a/app/src/main/res/menu/context_server.xml b/app/src/main/res/menu/context_server.xml
new file mode 100644
index 0000000..21ed7d4
--- /dev/null
+++ b/app/src/main/res/menu/context_server.xml
@@ -0,0 +1,15 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/servers.xml b/app/src/main/res/menu/servers.xml
deleted file mode 100644
index 71d158e..0000000
--- a/app/src/main/res/menu/servers.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
-
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 03dc99b..5de8ce0 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -9,4 +9,8 @@
#B6B6B6
#FFC107
#EEEEEE
+
+ #FFFFFF
+ #4CAF50
+ #F44336
\ No newline at end of file