1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-21 16:35:09 -05:00

Refactoring ServersActivity to new (more "Material") OverviewFragment.

The new launch activity is MainActivity. The other activities will mostly become fragments.
This commit is contained in:
Sebastian Kaspari 2015-03-21 12:08:37 +01:00
parent 9ed0b8c001
commit 2c78483c64
26 changed files with 639 additions and 641 deletions

View File

@ -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'
}

View File

@ -27,12 +27,11 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:icon="@drawable/icon"
android:icon="@mipmap/ic_launcher"
android:label="Yaaic"
android:theme="@style/Theme.Yaaic"
android:allowBackup="true">
<activity
android:name=".activity.ServersActivity"
<activity android:name=".activity.MainActivity"
android:label="@string/app_name"
android:launchMode="standard" >
<intent-filter>

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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 <sebastian@yaaic.org>
*/
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<Server> 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);
}
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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 <sebastian@yaaic.org>
*/
public class ServerListAdapter extends BaseAdapter
{
private static final int COLOR_CONNECTED = 0xFFbcbcbc;
private static final int COLOR_DISCONNECTED = 0xFF585858;
private ArrayList<Server> 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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<ServersAdapter.ViewHolder> {
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<Server> 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();
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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();
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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();
}
}

View File

@ -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";
}

View File

@ -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.
*/

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 454 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 498 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 440 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="org.yaaic.fragment.OverviewFragment" />
</FrameLayout>

View File

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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 <http://www.gnu.org/licenses/>.
-->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="10dip"
android:gravity="center_vertical"
android:text="@string/add_server_list"
android:textSize="18sp" />

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?><!--
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 <http://www.gnu.org/licenses/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="4dp" />
<ImageButton
android:id="@+id/fab"
style="@style/FloatingActionButton"
android:src="@drawable/plus"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:contentDescription="@string/add_server_label" />
</RelativeLayout>

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?><!--
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 <http://www.gnu.org/licenses/>.
-->
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_margin="4dp"
card_view:cardBackgroundColor="@color/cardview_background">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<View
android:id="@+id/connection"
android:layout_width="16dp"
android:layout_height="match_parent"
android:layout_marginRight="4dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:paddingLeft="4dp">
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Server"
android:textAppearance="@android:style/TextAppearance.Material.Title" />
<TextView
android:id="@+id/host"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="irc.example.com"
android:textAppearance="@android:style/TextAppearance.Material.Body1" />
</LinearLayout>
<ImageView
android:id="@+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_menu" />
</LinearLayout>
</android.support.v7.widget.CardView>

View File

@ -1,51 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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 <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<ImageView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/disconnected"
android:layout_gravity="center_vertical" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dp">
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Server"
android:textSize="18sp" />
<TextView
android:id="@+id/host"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="irc.example.com"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>

View File

@ -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 <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
@ -27,4 +27,4 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</FrameLayout>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/connect"
android:title="@string/connect" />
<item
android:id="@+id/disconnect"
android:title="@string/disconnect" />
<item
android:id="@+id/edit"
android:title="@string/edit" />
<item
android:id="@+id/delete"
android:title="@string/delete" />
</menu>

View File

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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 <http://www.gnu.org/licenses/>.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/add"
android:title="@string/add_server_menu" />
<item
android:id="@+id/settings"
android:title="@string/settings_menu" />
<item
android:id="@+id/disconnect_all"
android:title="@string/disconnect_menu" />
<item
android:id="@+id/about"
android:title="@string/about_menu" />
</menu>

View File

@ -9,4 +9,8 @@
<color name="divider">#B6B6B6</color>
<color name="highlight">#FFC107</color>
<color name="window_background">#EEEEEE</color>
<color name="cardview_background">#FFFFFF</color>
<color name="connected">#4CAF50</color>
<color name="disconnected">#F44336</color>
</resources>