diff options
-rw-r--r-- | res/drawable/grey.xml | 5 | ||||
-rw-r--r-- | res/drawable/greybackground.xml | 6 | ||||
-rw-r--r-- | res/layout/share_with.xml | 50 | ||||
-rw-r--r-- | res/values/strings.xml | 1 | ||||
-rw-r--r-- | src/eu/siacs/conversations/services/XmppConnectionService.java | 12 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/ConversationActivity.java | 5 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/ConversationFragment.java | 14 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/ManageAccountActivity.java | 16 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/MucDetailsActivity.java | 20 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/NewConversationActivity.java | 43 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/ShareWithActivity.java | 128 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/XmppActivity.java | 16 | ||||
-rw-r--r-- | src/eu/siacs/conversations/xmpp/XmppConnection.java | 2 |
13 files changed, 251 insertions, 67 deletions
diff --git a/res/drawable/grey.xml b/res/drawable/grey.xml new file mode 100644 index 000000000..bdb9383fc --- /dev/null +++ b/res/drawable/grey.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle"> + <solid android:color="#ffdddddd" /> +</shape>
\ No newline at end of file diff --git a/res/drawable/greybackground.xml b/res/drawable/greybackground.xml new file mode 100644 index 000000000..529af5e8a --- /dev/null +++ b/res/drawable/greybackground.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<selector xmlns:android="http://schemas.android.com/apk/res/android" > + <item + android:state_pressed="true" + android:drawable="@drawable/grey" /> +</selector> diff --git a/res/layout/share_with.xml b/res/layout/share_with.xml new file mode 100644 index 000000000..ae73a688f --- /dev/null +++ b/res/layout/share_with.xml @@ -0,0 +1,50 @@ +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent"> + +<LinearLayout + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:orientation="vertical" > + + <TextView + android:id="@+id/conversations_header" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Active Conversations" + style="@style/sectionHeader" + android:paddingLeft="8dp" + android:paddingTop="8dp" + android:paddingRight="8dp"/> + + + <LinearLayout + android:id="@+id/conversations" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:divider="?android:dividerHorizontal" + android:showDividers="middle" > + + </LinearLayout> + <TextView + android:id="@+id/contacts_header" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Contacts" + style="@style/sectionHeader" + android:paddingLeft="8dp" + android:paddingTop="8dp" + android:paddingRight="8dp"/> + <LinearLayout + android:id="@+id/contacts" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:divider="?android:dividerHorizontal" + android:showDividers="middle" > + + </LinearLayout> +</LinearLayout> +</ScrollView>
\ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 646ec4c5e..937f55706 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -25,4 +25,5 @@ <string name="untrusted_cert_hint">The server %s presented you with an unstrusted, possible self signed, certificate.</string> <string name="account_info">Server Info</string> <string name="register_account">Register new account on server</string> + <string name="share_with">Share with</string> </resources> diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 57cb60b9c..9a5cbc0cc 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -398,7 +398,7 @@ public class XmppConnectionService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { - Log.d(LOGTAG,"calling start service. caller was:"+intent.getAction()); + //Log.d(LOGTAG,"calling start service. caller was:"+intent.getAction()); ConnectivityManager cm = (ConnectivityManager) getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); @@ -670,7 +670,7 @@ public class XmppConnectionService extends Service { return packet; } - public void getRoster(Account account, + private void getRoster(Account account, final OnRosterFetchedListener listener) { List<Contact> contacts = databaseBackend.getContactsByAccount(account); for (int i = 0; i < contacts.size(); ++i) { @@ -680,6 +680,14 @@ public class XmppConnectionService extends Service { listener.onRosterFetched(contacts); } } + + public List<Contact> getRoster(Account account) { + List<Contact> contacts = databaseBackend.getContactsByAccount(account); + for (int i = 0; i < contacts.size(); ++i) { + contacts.get(i).setAccount(account); + } + return contacts; + } public void updateRoster(final Account account, final OnRosterFetchedListener listener) { diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index e471d46dc..1577fdc53 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -11,7 +11,6 @@ import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.utils.UIHelper; -import android.net.Uri; import android.os.Bundle; import android.app.AlertDialog; import android.app.FragmentTransaction; @@ -42,6 +41,7 @@ public class ConversationActivity extends XmppActivity { public static final String VIEW_CONVERSATION = "viewConversation"; public static final String CONVERSATION = "conversationUuid"; + public static final String TEXT = "text"; public static final int REQUEST_SEND_MESSAGE = 0x75441; public static final int REQUEST_DECRYPT_PGP = 0x76783; @@ -437,7 +437,8 @@ public class ConversationActivity extends XmppActivity { } } paneShouldBeOpen = false; - swapConversationFragment(); + String text = getIntent().getExtras().getString(TEXT, null); + swapConversationFragment().setText(text); } } else { if (xmppConnectionService.getAccounts().size() == 0) { diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index 2aabec873..23b17077e 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -1,6 +1,5 @@ package eu.siacs.conversations.ui; -import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; @@ -19,7 +18,6 @@ import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.MucOptions.OnRenameListener; import eu.siacs.conversations.services.XmppConnectionService; -import eu.siacs.conversations.utils.PhoneHelper; import eu.siacs.conversations.utils.UIHelper; import android.app.AlertDialog; import android.app.Fragment; @@ -30,9 +28,7 @@ import android.content.IntentSender; import android.content.SharedPreferences; import android.content.IntentSender.SendIntentException; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.Typeface; -import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; @@ -63,6 +59,7 @@ public class ConversationFragment extends Fragment { protected String queuedPqpMessage = null; private EditText chatMsg; + private String pastedText = null; protected Bitmap selfBitmap; @@ -153,6 +150,11 @@ public class ConversationFragment extends Fragment { final View view = inflater.inflate(R.layout.fragment_conversation, container, false); chatMsg = (EditText) view.findViewById(R.id.textinput); + + if (pastedText!=null) { + chatMsg.setText(pastedText); + } + ImageButton sendButton = (ImageButton) view .findViewById(R.id.textSendButton); sendButton.setOnClickListener(this.sendMsgListener); @@ -640,4 +642,8 @@ public class ConversationFragment extends Fragment { } } + + public void setText(String text) { + this.pastedText = text; + } } diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java index 0d3adc857..22f7c78fb 100644 --- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -289,6 +289,8 @@ public class ManageAccountActivity extends XmppActivity { XmppConnection xmpp = selectedAccountForActionMode.getXmppConnection(); long connectionAge = (SystemClock.elapsedRealtime() - xmpp.lastConnect) / 60000; long sessionAge = (SystemClock.elapsedRealtime() - xmpp.lastSessionStarted) / 60000; + long connectionAgeHours = connectionAge / 60; + long sessionAgeHours = sessionAge / 60; View view = (View) getLayoutInflater().inflate(R.layout.server_info, null); TextView connection = (TextView) view.findViewById(R.id.connection); TextView session = (TextView) view.findViewById(R.id.session); @@ -299,13 +301,21 @@ public class ManageAccountActivity extends XmppActivity { TextView roster = (TextView) view.findViewById(R.id.roster); pcks_received.setText(""+xmpp.getReceivedStanzas()); pcks_sent.setText(""+xmpp.getSentStanzas()); - connection.setText(connectionAge+" mins"); + if (connectionAgeHours >= 2) { + connection.setText(connectionAgeHours+" hours"); + } else { + connection.setText(connectionAge+" mins"); + } if (xmpp.hasFeatureStreamManagment()) { - session.setText(sessionAge+" mins"); + if (sessionAgeHours >= 2) { + session.setText(sessionAgeHours+" hours"); + } else { + session.setText(sessionAge+" mins"); + } stream.setText("Yes"); } else { stream.setText("No"); - session.setText(connectionAge+" mins"); + session.setText(connection.getText()); } if (xmpp.hasFeaturesCarbon()) { carbon.setText("Yes"); diff --git a/src/eu/siacs/conversations/ui/MucDetailsActivity.java b/src/eu/siacs/conversations/ui/MucDetailsActivity.java index 5bd3556cd..478397e7a 100644 --- a/src/eu/siacs/conversations/ui/MucDetailsActivity.java +++ b/src/eu/siacs/conversations/ui/MucDetailsActivity.java @@ -64,26 +64,6 @@ public class MucDetailsActivity extends XmppActivity { membersView = (LinearLayout) findViewById(R.id.muc_members); mMoreDetails = (LinearLayout) findViewById(R.id.muc_more_details); mMoreDetails.setVisibility(View.GONE); - /*contactsAdapter = new ArrayAdapter<MucOptions.User>(this, - R.layout.contact, users) { - @Override - public View getView(int position, View view, ViewGroup parent) { - LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); - User contact = getItem(position); - if (view == null) { - view = (View) inflater.inflate(R.layout.contact, null); - } - - ((TextView) view.findViewById(R.id.contact_display_name)) - .setText(getItem(position).getName()); - TextView role = (TextView) view.findViewById(R.id.contact_jid); - role.setText(getReadableRole(contact.getRole())); - ImageView imageView = (ImageView) view - .findViewById(R.id.contact_photo); - imageView.setImageBitmap(UIHelper.getContactPictureByName(contact.getName(), 90)); - return view; - } - };*/ getActionBar().setHomeButtonEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/src/eu/siacs/conversations/ui/NewConversationActivity.java b/src/eu/siacs/conversations/ui/NewConversationActivity.java index e275cea76..537e6c51f 100644 --- a/src/eu/siacs/conversations/ui/NewConversationActivity.java +++ b/src/eu/siacs/conversations/ui/NewConversationActivity.java @@ -6,7 +6,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.Locale; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; @@ -14,11 +13,9 @@ import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.Validator; -import android.net.Uri; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; -import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -230,19 +227,7 @@ public class NewConversationActivity extends XmppActivity { Conversation conversation = xmppConnectionService .findOrCreateConversation(account, contact.getJid(), muc); - switchToConversation(conversation); - } - - public void switchToConversation(Conversation conversation) { - Intent viewConversationIntent = new Intent(this, - ConversationActivity.class); - viewConversationIntent.setAction(Intent.ACTION_VIEW); - viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, - conversation.getUuid()); - viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION); - viewConversationIntent.setFlags(viewConversationIntent.getFlags() - | Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(viewConversationIntent); + switchToConversation(conversation,null); } @Override @@ -265,12 +250,14 @@ public class NewConversationActivity extends XmppActivity { @Override public void onClick(DialogInterface dialog, int which) { Conversation conversation = xmppConnectionService.findOrCreateConversation(accounts.get(which), finalJid, false); - switchToConversation(conversation); + switchToConversation(conversation,null); + finish(); } }).show(); } else { Conversation conversation = xmppConnectionService.findOrCreateConversation(this.accounts.get(0), jid, false); - switchToConversation(conversation); + switchToConversation(conversation,null); + finish(); } } } @@ -282,24 +269,10 @@ public class NewConversationActivity extends XmppActivity { } this.rosterContacts.clear(); for (int i = 0; i < accounts.size(); ++i) { - xmppConnectionService.getRoster(accounts.get(i), - new OnRosterFetchedListener() { - - @Override - public void onRosterFetched(List<Contact> roster) { - rosterContacts.addAll(roster); - runOnUiThread(new Runnable() { - - @Override - public void run() { - updateAggregatedContacts(); - } - }); - - } - }); - } + rosterContacts.addAll(xmppConnectionService.getRoster(accounts.get(i))); } + updateAggregatedContacts(); + } @Override public boolean onCreateOptionsMenu(Menu menu) { diff --git a/src/eu/siacs/conversations/ui/ShareWithActivity.java b/src/eu/siacs/conversations/ui/ShareWithActivity.java new file mode 100644 index 000000000..81616212a --- /dev/null +++ b/src/eu/siacs/conversations/ui/ShareWithActivity.java @@ -0,0 +1,128 @@ +package eu.siacs.conversations.ui; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Contact; +import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.utils.UIHelper; +import android.content.Intent; +import android.graphics.Bitmap; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +public class ShareWithActivity extends XmppActivity { + + private LinearLayout conversations; + private LinearLayout contacts; + + private OnClickListener click = new OnClickListener() { + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + + setContentView(R.layout.share_with); + setTitle("Share with Conversation"); + + contacts = (LinearLayout) findViewById(R.id.contacts); + conversations = (LinearLayout) findViewById(R.id.conversations); + + } + + + public View createContactView(String name, String msgTxt, Bitmap bm) { + View view = (View) getLayoutInflater().inflate(R.layout.contact, null); + view.setBackgroundResource(R.drawable.greybackground); + TextView contactName =(TextView) view.findViewById(R.id.contact_display_name); + contactName.setText(name); + TextView msg = (TextView) view.findViewById(R.id.contact_jid); + msg.setText(msgTxt); + ImageView imageView = (ImageView) view.findViewById(R.id.contact_photo); + imageView.setImageBitmap(bm); + return view; + } + + + + @Override + void onBackendConnected() { + Set<String> displayedContacts = new HashSet<String>(); + conversations.removeAllViews(); + List<Conversation> convList = xmppConnectionService.getConversations(); + Collections.sort(convList, new Comparator<Conversation>() { + @Override + public int compare(Conversation lhs, Conversation rhs) { + return (int) (rhs.getLatestMessage().getTimeSent() - lhs.getLatestMessage().getTimeSent()); + } + }); + for(final Conversation conversation : convList) { + View view = createContactView(conversation.getName(), conversation.getLatestMessage().getBody().trim(), UIHelper.getContactPicture(conversation.getContact(),conversation.getName(), 90,this.getApplicationContext())); + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + String sharedText = getIntent().getStringExtra(Intent.EXTRA_TEXT); + switchToConversation(conversation, sharedText); + finish(); + } + }); + conversations.addView(view); + if (conversation.getContact() != null) { + displayedContacts.add(conversation.getContact().getUuid()); + } + } + contacts.removeAllViews(); + final List<Contact> contactsList = new ArrayList<Contact>(); + for(Account account : xmppConnectionService.getAccounts()) { + for(final Contact contact : xmppConnectionService.getRoster(account)) { + if (!displayedContacts.contains(contact.getUuid())) { + contactsList.add(contact); + } + } + } + + Collections.sort(contactsList, new Comparator<Contact>() { + @Override + public int compare(Contact lhs, Contact rhs) { + return lhs.getDisplayName().compareToIgnoreCase(rhs.getDisplayName()); + } + }); + + for(int i = 0; i < contactsList.size(); ++i) { + final Contact con = contactsList.get(i); + View view = createContactView(con.getDisplayName(), con.getJid(), UIHelper.getContactPicture(con,null, 90,this.getApplicationContext())); + view.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + String sharedText = getIntent().getStringExtra(Intent.EXTRA_TEXT); + Conversation conversation = xmppConnectionService.findOrCreateConversation(con.getAccount(), con.getJid(), false); + switchToConversation(conversation, sharedText); + finish(); + } + }); + contacts.addView(view); + } + } + +} diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java index 1596a53a6..dc8c3d5d9 100644 --- a/src/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/eu/siacs/conversations/ui/XmppActivity.java @@ -1,6 +1,7 @@ package eu.siacs.conversations.ui; import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder; import eu.siacs.conversations.utils.ExceptionHelper; @@ -103,4 +104,19 @@ public abstract class XmppActivity extends Activity { super.onCreate(savedInstanceState); ExceptionHelper.init(getApplicationContext()); } + + public void switchToConversation(Conversation conversation, String text) { + Intent viewConversationIntent = new Intent(this, + ConversationActivity.class); + viewConversationIntent.setAction(Intent.ACTION_VIEW); + viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, + conversation.getUuid()); + if (text!=null) { + viewConversationIntent.putExtra(ConversationActivity.TEXT, text); + } + viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION); + viewConversationIntent.setFlags(viewConversationIntent.getFlags() + | Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(viewConversationIntent); + } } diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 5a29ad622..677c0ba66 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -720,7 +720,7 @@ public class XmppConnection implements Runnable { if (this.streamFeatures==null) { return false; } else { - return this.streamFeatures.hasChild("has"); + return this.streamFeatures.hasChild("sm"); } } |