1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2025-02-16 15:00:14 -05:00

New user action view and new actions: reply, query

This commit is contained in:
Sebastian Kaspari 2011-02-05 16:04:22 +01:00
parent 984fbd7efa
commit 669113610a
15 changed files with 331 additions and 137 deletions

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Yaaic - Yet Another Android IRC Client
Copyright 2009-2011 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="4px">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/action_reply"
android:layout_gravity="center_vertical" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3px"
android:textSize="12px"
android:text="Reply">
</TextView>
</LinearLayout>

View File

@ -28,59 +28,12 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:id="@+id/nickname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10px"
android:autoLink="all"
android:linksClickable="true"
android:textSize="20px" />
<LinearLayout
android:orientation="horizontal"
android:padding="5px"
android:drawableLeft="@drawable/user_title"
android:drawablePadding="3px"
android:textSize="16px" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/op"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_op" />
<Button
android:id="@+id/deop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_deop" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/voice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_voice" />
<Button
android:id="@+id/devoice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_devoice" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/kick"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_kick" />
<Button
android:id="@+id/ban"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button_ban" />
</LinearLayout>
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -20,9 +20,10 @@ 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:id="@+id/host"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="7px"
android:text=""
android:textSize="12px" />
android:padding="5px"
android:textSize="12px"
android:drawableLeft="@drawable/user"
android:drawablePadding="3px">
</TextView>

View File

@ -145,12 +145,14 @@
<string name="message_remove_moderated">%1$s removes moderated</string>
<string name="message_disconnected">Disconnected</string>
<string name="button_op">Op</string>
<string name="button_deop">DeOp</string>
<string name="button_voice">Voice</string>
<string name="button_devoice">DeVoice</string>
<string name="button_kick">Kick</string>
<string name="button_ban">Ban</string>
<string name="user_action_reply">Reply</string>
<string name="user_action_query">Query</string>
<string name="user_action_op">Op</string>
<string name="user_action_deop">DeOp</string>
<string name="user_action_voice">Voice</string>
<string name="user_action_devoice">DeVoice</string>
<string name="user_action_kick">Kick</string>
<string name="user_action_ban">Ban</string>
<string name="settings_connection">Verbindung</string>
<string name="settings_reconnect_title">Neuverbinden</string>

View File

@ -151,12 +151,12 @@
<string name="message_not_connected">No conectado</string>
<string name="message_users_on_chan">Usuarios en %1$s:</string>
<string name="button_op">Op</string>
<string name="button_deop">DeOp</string>
<string name="button_voice">Voice</string>
<string name="button_devoice">DeVoice</string>
<string name="button_kick">Kick</string>
<string name="button_ban">Ban</string>
<string name="user_action_op">Op</string>
<string name="user_action_deop">DeOp</string>
<string name="user_action_voice">Voice</string>
<string name="user_action_devoice">DeVoice</string>
<string name="user_action_kick">Kick</string>
<string name="user_action_ban">Ban</string>
<string name="settings_connection">Conexión</string>
<string name="settings_reconnect_title">Reconectar</string>

View File

@ -151,12 +151,12 @@
<string name="message_not_connected">Non connecté</string>
<string name="message_users_on_chan">Utilisateurs sur %1$s :</string>
<string name="button_op">Op</string>
<string name="button_deop">DeOp</string>
<string name="button_voice">Voice</string>
<string name="button_devoice">DeVoice</string>
<string name="button_kick">Expulser</string>
<string name="button_ban">Bannir</string>
<string name="user_action_op">Op</string>
<string name="user_action_deop">DeOp</string>
<string name="user_action_voice">Voice</string>
<string name="user_action_devoice">DeVoice</string>
<string name="user_action_kick">Expulser</string>
<string name="user_action_ban">Bannir</string>
<string name="settings_connection">Connexion</string>
<string name="settings_reconnect_title">Reconnexion</string>

View File

@ -152,12 +152,12 @@
<string name="message_not_connected">Non connesso</string>
<string name="message_users_on_chan">Utenti in %1$s:</string>
<string name="button_op">Op</string>
<string name="button_deop">DeOp</string>
<string name="button_voice">Voice</string>
<string name="button_devoice">DeVoice</string>
<string name="button_kick">Kick</string>
<string name="button_ban">Ban</string>
<string name="user_action_op">Op</string>
<string name="user_action_deop">DeOp</string>
<string name="user_action_voice">Voice</string>
<string name="user_action_devoice">DeVoice</string>
<string name="user_action_kick">Kick</string>
<string name="user_action_ban">Ban</string>
<string name="settings_connection">Connessione</string>
<string name="settings_reconnect_title">Riconnetti</string>

View File

@ -145,12 +145,12 @@
<string name="message_remove_moderated">%1$s removes moderated</string>
<string name="message_disconnected">Disconnected</string>
<string name="button_op">Op</string>
<string name="button_deop">DeOp</string>
<string name="button_voice">Voice</string>
<string name="button_devoice">DeVoice</string>
<string name="button_kick">Kick</string>
<string name="button_ban">Ban</string>
<string name="user_action_op">Op</string>
<string name="user_action_deop">DeOp</string>
<string name="user_action_voice">Voice</string>
<string name="user_action_devoice">DeVoice</string>
<string name="user_action_kick">Kick</string>
<string name="user_action_ban">Ban</string>
<string name="settings_connection">Connection</string>
<string name="settings_reconnect_title">Reconnect</string>

View File

@ -164,13 +164,12 @@
<string name="message_remove_moderated">%1$s 移除审核</string>
<string name="message_disconnected">已断开</string>
<string name="button_op">设为管理员</string>
<string name="button_deop">取消管理员</string>
<string name="button_voice">发言权</string>
<string name="button_devoice">取消发言权</string>
<string name="button_kick">踢出</string>
<string name="button_ban">禁止</string>
<string name="user_action_op">设为管理员</string>
<string name="user_action_deop">取消管理员</string>
<string name="user_action_voice">发言权</string>
<string name="user_action_devoice">取消发言权</string>
<string name="user_action_kick">踢出</string>
<string name="user_action_ban">禁止</string>
<string name="settings_connection">连接</string>
<string name="settings_reconnect_title">重新连接</string>

View File

@ -151,12 +151,14 @@
<string name="message_not_connected">Not connected</string>
<string name="message_users_on_chan">Users on %1$s:</string>
<string name="button_op">Op</string>
<string name="button_deop">DeOp</string>
<string name="button_voice">Voice</string>
<string name="button_devoice">DeVoice</string>
<string name="button_kick">Kick</string>
<string name="button_ban">Ban</string>
<string name="user_action_reply">Reply</string>
<string name="user_action_query">Query</string>
<string name="user_action_op">Op</string>
<string name="user_action_deop">DeOp</string>
<string name="user_action_voice">Voice</string>
<string name="user_action_devoice">DeVoice</string>
<string name="user_action_kick">Kick</string>
<string name="user_action_ban">Ban</string>
<string name="settings_connection">Connection</string>
<string name="settings_reconnect_title">Reconnect</string>

View File

@ -42,11 +42,13 @@ import org.yaaic.model.Broadcast;
import org.yaaic.model.Conversation;
import org.yaaic.model.Extra;
import org.yaaic.model.Message;
import org.yaaic.model.Query;
import org.yaaic.model.Scrollback;
import org.yaaic.model.Server;
import org.yaaic.model.ServerInfo;
import org.yaaic.model.Settings;
import org.yaaic.model.Status;
import org.yaaic.model.User;
import org.yaaic.receiver.ConversationReceiver;
import org.yaaic.receiver.ServerReceiver;
import org.yaaic.view.ConversationSwitcher;
@ -62,6 +64,7 @@ import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.speech.RecognizerIntent;
import android.view.KeyEvent;
@ -722,6 +725,7 @@ public class ConversationActivity extends Activity implements ServiceConnection,
final String nickname = data.getExtras().getString(Extra.USER);
final IRCConnection connection = binder.getService().getConnection(server.getId());
final String conversation = server.getSelectedConversation();
final Handler handler = new Handler();
// XXX: Implement me - The action should be handled after onResume()
// to catch the broadcasts... now we just wait a second
@ -736,24 +740,62 @@ public class ConversationActivity extends Activity implements ServiceConnection,
// Do nothing
}
String nicknameWithoutPrefix = nickname;
while (
nicknameWithoutPrefix.startsWith("@") ||
nicknameWithoutPrefix.startsWith("+") ||
nicknameWithoutPrefix.startsWith(".") ||
nicknameWithoutPrefix.startsWith("%")
) {
// Strip prefix(es) now
nicknameWithoutPrefix = nicknameWithoutPrefix.substring(1);
}
switch (actionId) {
case R.id.op:
connection.op(conversation, nickname);
case User.ACTION_REPLY:
final String replyText = nicknameWithoutPrefix + ": ";
handler.post(new Runnable() {
@Override
public void run() {
EditText input = (EditText) findViewById(R.id.input);
input.setText(replyText);
input.setSelection(replyText.length());
}
});
break;
case R.id.deop:
connection.deOp(conversation, nickname);
case User.ACTION_QUERY:
Conversation query = server.getConversation(nicknameWithoutPrefix);
if (query == null) {
// Open a query if there's none yet
query = new Query(nicknameWithoutPrefix);
server.addConversationl(query);
Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_NEW,
server.getId(),
nicknameWithoutPrefix
);
binder.getService().sendBroadcast(intent);
}
break;
case R.id.voice:
connection.voice(conversation, nickname);
case User.ACTION_OP:
connection.op(conversation, nicknameWithoutPrefix);
break;
case R.id.devoice:
connection.deVoice(conversation, nickname);
case User.ACTION_DEOP:
connection.deOp(conversation, nicknameWithoutPrefix);
break;
case R.id.kick:
connection.kick(conversation, nickname);
case User.ACTION_VOICE:
connection.voice(conversation, nicknameWithoutPrefix);
break;
case R.id.ban:
connection.ban(conversation, nickname + "!*@*");
case User.ACTION_DEVOICE:
connection.deVoice(conversation, nicknameWithoutPrefix);
break;
case User.ACTION_KICK:
connection.kick(conversation, nicknameWithoutPrefix);
break;
case User.ACTION_BAN:
connection.ban(conversation, nicknameWithoutPrefix + "!*@*");
break;
}
}

View File

@ -21,17 +21,15 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
package org.yaaic.activity;
import org.yaaic.R;
import org.yaaic.adapter.UserActionListAdapter;
import org.yaaic.model.Extra;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
/**
@ -39,7 +37,7 @@ import android.widget.TextView;
*
* @author Sebastian Kaspari <sebastian@yaaic.org>
*/
public class UserActivity extends Activity implements OnClickListener
public class UserActivity extends ListActivity
{
private String nickname;
@ -52,32 +50,21 @@ public class UserActivity extends Activity implements OnClickListener
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
nickname = getIntent().getStringExtra(Extra.USER);
setContentView(R.layout.user);
setListAdapter(new UserActionListAdapter());
// Use full width
LayoutParams params = getWindow().getAttributes();
params.width = WindowManager.LayoutParams.FILL_PARENT;
getWindow().setAttributes(params);
((Button) findViewById(R.id.op)).setOnClickListener(this);
((Button) findViewById(R.id.deop)).setOnClickListener(this);
((Button) findViewById(R.id.voice)).setOnClickListener(this);
((Button) findViewById(R.id.devoice)).setOnClickListener(this);
((Button) findViewById(R.id.kick)).setOnClickListener(this);
((Button) findViewById(R.id.ban)).setOnClickListener(this);
nickname = getIntent().getStringExtra(Extra.USER);
((TextView) findViewById(R.id.nickname)).setText(nickname);
}
/**
* On button click
* On action selected
*/
@Override
public void onClick(View v)
protected void onListItemClick(ListView list, View view, int position, long id)
{
Intent intent = new Intent();
intent.putExtra(Extra.ACTION, v.getId());
intent.putExtra(Extra.ACTION, (int) id);
intent.putExtra(Extra.USER, nickname);
setResult(RESULT_OK, intent);
finish();

View File

@ -0,0 +1,130 @@
/*
Yaaic - Yet Another Android IRC Client
Copyright 2009-2011 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 org.yaaic.R;
import org.yaaic.model.User;
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 user action lists
*
* @author Sebastian Kaspari <sebastian@yaaic.org>
*/
public class UserActionListAdapter extends BaseAdapter
{
/**
* Action IDs
*/
private final int[] actions = {
User.ACTION_REPLY,
User.ACTION_QUERY,
User.ACTION_OP,
User.ACTION_DEOP,
User.ACTION_VOICE,
User.ACTION_DEVOICE,
User.ACTION_KICK,
User.ACTION_BAN
};
/**
* Labels for actions
*/
private final int[] labels = {
R.string.user_action_reply,
R.string.user_action_query,
R.string.user_action_op,
R.string.user_action_deop,
R.string.user_action_voice,
R.string.user_action_devoice,
R.string.user_action_kick,
R.string.user_action_ban
};
/**
* Icons for actions
*/
private final int[] icons = {
R.drawable.action_reply,
R.drawable.action_query,
R.drawable.action_op,
R.drawable.action_deop,
R.drawable.action_voice,
R.drawable.action_devoice,
R.drawable.action_kick,
R.drawable.action_ban,
};
/**
* Get number of actions
*/
@Override
public int getCount()
{
return actions.length;
}
/**
* Get object for given position
*/
@Override
public Object getItem(int position)
{
return null;
}
/**
* Get item id for given position
*/
@Override
public long getItemId(int position)
{
return actions[position];
}
/**
* Get view for given position
*/
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.actionitem, null);
}
TextView textView = (TextView) convertView.findViewById(R.id.label);
ImageView iconView = (ImageView) convertView.findViewById(R.id.icon);
textView.setText(labels[position]);
iconView.setImageResource(icons[position]);
return convertView;
}
}

View File

@ -1090,8 +1090,7 @@ public class IRCConnection extends PircBot
String[] users = new String[mLength];
for (int i = 0; i < mLength; i++) {
// Prefix disabled
users[i] = /*userArray[i].getPrefix() + */ userArray[i].getNick();
users[i] = userArray[i].getPrefix() + userArray[i].getNick();
}
return users;

View File

@ -0,0 +1,38 @@
/*
Yaaic - Yet Another Android IRC Client
Copyright 2009-2011 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.model;
/**
* Helper class for anything regarding users
*
* @author Sebastian Kaspari <sebastian@yaaic.org>
*/
public class User
{
public static final int ACTION_REPLY = 1;
public static final int ACTION_QUERY = 2;
public static final int ACTION_OP = 3;
public static final int ACTION_DEOP = 4;
public static final int ACTION_VOICE = 5;
public static final int ACTION_DEVOICE = 6;
public static final int ACTION_KICK = 7;
public static final int ACTION_BAN = 8;
}