Skip to content

Commit

Permalink
Main: opening sessions from the list
Browse files Browse the repository at this point in the history
  • Loading branch information
klauswuestefeld committed Sep 24, 2015
1 parent 9bcf198 commit 36d0dba
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import rx.functions.Action1;
import sneer.android.utils.AndroidUtils;
import sneer.convos.Convo;
import sneer.convos.SessionHandle;
import sneer.convos.Sessions;

Expand All @@ -17,26 +16,26 @@

public class PluginActivities {

public static void start(final Context context, Plugin plugin, Convo convo) {
start(context, plugin, convo, null);
public static void start(final Context context, Plugin plugin, long convoId) {
start(context, plugin, convoId, null);
}

public static void open(Context context, SessionHandle session, Convo convo) {
public static void open(Context context, SessionHandle session, long convoId) {
Plugin plugin = Plugins.forSessionType(context, session.type);
if (plugin == null)
Toast.makeText(context, "Please install an app for " + session.type, Toast.LENGTH_LONG).show();
else
start(context, plugin, convo, session);
start(context, plugin, convoId, session);
}

private static void start(final Context context, final Plugin plugin, Convo convo, SessionHandle session) {
private static void start(final Context context, final Plugin plugin, long convoId, SessionHandle session) {
final Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(plugin.packageName, plugin.activityName);
intent.putExtra(SEND_MESSAGE, SendMessage.intentFor(convo));
intent.putExtra(SEND_MESSAGE, SendMessage.intentFor(convoId));

if (plugin.partnerSessionType != null && session == null)
request(Sessions.Actions.startSession(convo.id, plugin.partnerSessionType)).subscribe(new Action1<Long>() {
request(Sessions.Actions.startSession(convoId, plugin.partnerSessionType)).subscribe(new Action1<Long>() {
@Override
public void call(Long sessionId) {
startActivity(context, intent, new SessionHandle(sessionId, plugin.partnerSessionType, true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
import android.content.Intent;
import android.util.Log;

import rx.functions.Action1;
import sneer.convos.Convo;
import sneer.convos.Convos;

import static sneer.android.SneerAndroidContainer.component;
import static sneer.android.SneerAndroidFlux.dispatch;

public class SendMessage extends IntentService {
Expand All @@ -20,10 +17,10 @@ public SendMessage() {
}


static Intent intentFor(Convo convo) {
static Intent intentFor(long convoId) {
return new Intent()
.setClassName("sneer.main", SendMessage.class.getName())
.putExtra(TOKEN, convo.id);
.putExtra(TOKEN, convoId);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.*;

import java.util.ArrayList;
import java.util.List;

import rx.Observable;
import rx.Subscription;
import rx.functions.Action1;
import sneer.android.ipc.PluginActivities;
import sneer.convos.ChatMessage;
import sneer.convos.Convo;
import sneer.convos.Convos;
import sneer.convos.SessionSummary;
import sneer.main.R;

import static android.text.TextUtils.isEmpty;
Expand Down Expand Up @@ -252,7 +251,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

private void setupSessionsList() {
sessionsAdapter = new SessionListAdapter(this);
((ListView) sessionsView.findViewById(R.id.sessionList)).setAdapter(sessionsAdapter);
ListView sessions = (ListView) sessionsView.findViewById(R.id.sessionList);
sessions.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
SessionSummary summary = sessionsAdapter.getItem(position);
System.out.println("=============== " + summary);
PluginActivities.open(ConvoActivityWithTabs.this, summary, convoId);
}
});
sessions.setAdapter(sessionsAdapter);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public View getView(int position, View convertView, ViewGroup parent) {

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
dialog.dismiss();
PluginActivities.start(activity, plugins.get(position), convoProvider.getConvo());
PluginActivities.start(activity, plugins.get(position), convoProvider.getConvo().id);
}});

dialog.setView(listView, 0, 0, 0, 0);
Expand Down

0 comments on commit 36d0dba

Please sign in to comment.