Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiruili committed Jul 15, 2017
1 parent 22affea commit 9fbc61f
Show file tree
Hide file tree
Showing 16 changed files with 372 additions and 102 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.google.android:flexbox:0.3.0'
compile 'com.android.support:recyclerview-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:windowSoftInputMode="stateHidden"
android:screenOrientation="portrait">
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
79 changes: 25 additions & 54 deletions app/src/main/java/com/example/zhiruili/videoconf/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -13,12 +12,10 @@
import android.view.MenuItem;
import android.view.ViewGroup;

import com.example.zhiruili.utils.ViewUtils;
import com.example.zhiruili.videoconf.call.account.ILiveHelper;
import com.example.zhiruili.videoconf.call.constants.CallResultCode;
import com.tencent.callsdk.ILVCallConfig;
import com.tencent.callsdk.ILVCallConstants;
import com.tencent.callsdk.ILVCallListener;
import com.tencent.callsdk.ILVCallManager;
import com.tencent.callsdk.ILVCallNotification;
import com.tencent.callsdk.ILVCallNotificationListener;
Expand All @@ -38,38 +35,21 @@ public final class MainActivity
extends AppCompatActivity
implements
ToCallBufferFragment.OnFragmentInteractionListener,
ILVCallNotificationListener, ILVIncomingListener, ILVCallListener {
RecentCallsFragment.OnFragmentInteractionListener,
ILVCallNotificationListener, ILVIncomingListener {

private static final String TAG = MainActivity.class.getSimpleName();

private ViewGroup mMainContainer;
private ToCallBufferFragment mToCallBuffer;
private RecentCallsFragment mRecentCallsList;

private static final class RequestCode {
public static final int REQ_CALL = 0;
}

// 是否登录
private boolean mHasLogin = false;
// 当前导航 tab id
private int mCurrNavItemId = -1;
// 导航 tab 点击事件监听器
private BottomNavigationView.OnNavigationItemSelectedListener
mOnNavigationItemSelectedListener = item -> {

Log.d(TAG, "Select item " + item.getItemId());
int itemId = item.getItemId();
if (itemId == mCurrNavItemId) {
return false;
}
if (itemId == R.id.navigation_recent_calls) {

} else if (itemId == R.id.navigation_contacts) {

} else {
return false;
}
return true;
};

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -86,7 +66,6 @@ protected void onCreate(Bundle savedInstanceState) {
mHasLogin = intent.getBooleanExtra(getString(R.string.intent_extra_has_login), false);
if (mHasLogin) {
Log.v(TAG, "User has login");
initViews();
initCallSdk();
return;
}
Expand All @@ -105,7 +84,6 @@ protected void onCreate(Bundle savedInstanceState) {
_ignore -> {
Log.v(TAG, "login success");
mHasLogin = true;
initViews();
initCallSdk();
},
err -> {
Expand All @@ -115,13 +93,8 @@ protected void onCreate(Bundle savedInstanceState) {
gotoLogin();
});
}
ViewUtils.hideKeyboard(this);
}

private void initViews() {
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
navigation.setSelectedItemId(R.id.navigation_recent_calls);
mToCallBuffer = (ToCallBufferFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_to_call_buffer);
mRecentCallsList = (RecentCallsFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_recent_calls_list);
}

@Override
Expand All @@ -146,11 +119,9 @@ private void initCallSdk() {

private void registerCallSdkListeners() {
ILVCallManager.getInstance().addIncomingListener(this);
ILVCallManager.getInstance().addCallListener(this);
}

private void unregisterCallSdkListeners() {
ILVCallManager.getInstance().removeCallListener(this);
ILVCallManager.getInstance().removeIncomingListener(this);
}

Expand Down Expand Up @@ -274,6 +245,11 @@ public void onStartCalling(ArrayList<String> calledIds) {
gotoCall(ILiveLoginManager.getInstance().getMyUserId(), 0, ILVCallConstants.CALL_TYPE_VIDEO, calledIds);
}

@Override
public void onListItemClick(String callId) {
mToCallBuffer.addIdToBuffer(callId);
}

@Override
public void onRecvNotification(int callId, ILVCallNotification notification) {
Log.d(TAG, "onRecvNotification, callId: " + callId);
Expand All @@ -282,17 +258,20 @@ public void onRecvNotification(int callId, ILVCallNotification notification) {
@Override
public void onNewIncomingCall(int callId, int callType, ILVIncomingNotification notification) {
Log.d(TAG, "onNewIncomingCall, callId: " + callId + ", callType: " + callType);
Log.d(TAG, "onNewIncomingCall, sponsorId: " + notification.getSponsorId() + ", sender: " + notification.getSender() + ", members: " + notification.getMembersString());
Log.d(TAG, "onNewIncomingCall, sponsorId: " + notification.getSponsorId() +
", sender: " + notification.getSender() +
", members: " + notification.getMembersString());
final String membersMsg;
if (notification.getMembersString() == null) {
membersMsg = "";
} else {
membersMsg = "\n其他参与者:" + notification.getMembersString();
membersMsg = "\n参与者:" + notification.getMembersString();
}
new AlertDialog.Builder(this)
.setTitle("新会议请求")
.setMessage("会议发起人:" + notification.getSponsorId() + membersMsg)
.setNegativeButton("拒绝", null)
.setNegativeButton("拒绝",
(dialog, which) -> ILVCallManager.getInstance().rejectCall(callId))
.setPositiveButton("接受", (dialog, which) -> {
final ArrayList<String> members = new ArrayList<>();
if (notification.getMembers() != null) {
Expand All @@ -304,21 +283,13 @@ public void onNewIncomingCall(int callId, int callType, ILVIncomingNotification
}

private void gotoCall(String sponsor, int callId, int callType, ArrayList<String> members) {
startActivityForResult(CallActivity.createIntent(this, callId, callType, sponsor, members), RequestCode.REQ_CALL);
}

@Override
public void onCallEstablish(int callId) {
Log.d(TAG, "onCallEstablish, callId: " + callId);
}

@Override
public void onCallEnd(int callId, int endResult, String endInfo) {
Log.d(TAG, "onCallEnd, callId: " + callId + ", endResult: " + endResult);
}

@Override
public void onException(int iExceptionId, int errCode, String errMsg) {
Log.d(TAG, "onException, exceptionId: " + iExceptionId + ", errorCode: " + errCode + ", errMsg: " + errMsg);
// mRecentCallsList
// .updateCalls(members, callId != 0)
// .subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(success -> {
// Log.d(TAG, "gotoCall success = " + success);
startActivityForResult(CallActivity.createIntent(this, callId, callType, sponsor, members), RequestCode.REQ_CALL);
// });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.example.zhiruili.videoconf;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v4.app.Fragment;
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 com.example.zhiruili.videoconf.data.RecentCallsDbHelper;
import com.example.zhiruili.videoconf.data.RecentCallsListContract.*;
import com.example.zhiruili.videoconf.data.TestHelper;

import java.util.List;

import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class RecentCallsFragment extends Fragment {

private OnFragmentInteractionListener mInteractionListener;
private RecentCallsListAdapter mListAdapter = null;
private SQLiteDatabase mDb;

public RecentCallsFragment() { }

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_recent_calls, container, false);
final RecyclerView callsListView = (RecyclerView) rootView.findViewById(R.id.rv_recent_calls_list);
callsListView.setLayoutManager(new LinearLayoutManager(rootView.getContext()));

Single
.fromCallable(() -> new RecentCallsDbHelper(getActivity()).getWritableDatabase())
.doOnSuccess(db -> mDb = db)
// .doOnSuccess(TestHelper::insertFakeData)
.map(_ignore -> getAllRecentCalls())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(cursor -> new RecentCallsListAdapter(rootView.getContext(), cursor, mInteractionListener::onListItemClick))
.doOnSuccess(adapter -> mListAdapter = adapter)
.doOnSuccess(callsListView::setAdapter)
.doOnError(Throwable::printStackTrace)
.subscribe();

return rootView;
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mInteractionListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}

@Override
public void onDetach() {
super.onDetach();
mInteractionListener = null;
}

@Override
public void onDestroyView() {
super.onDestroyView();
}

public interface OnFragmentInteractionListener {
void onListItemClick(String callId);
}

public Single<Boolean> updateCalls(List<String> callIds, boolean isCallIn) {
return Single
.fromCallable(() -> {
mDb.beginTransaction();
for (String id : callIds) {
mDb.delete(RecentCallsListEntry.TABLE_NAME, RecentCallsListEntry.COLUMN_PERSON_ID + "=?", new String[] { id });
}
for (String id : callIds) {
ContentValues cv = new ContentValues();
cv.put(RecentCallsListEntry.COLUMN_PERSON_ID, id);
cv.put(RecentCallsListEntry.COLUMN_IS_CALL_IN, isCallIn);
mDb.insert(RecentCallsListEntry.TABLE_NAME, null, cv);
}
mDb.setTransactionSuccessful();
return true;
})
.doFinally(() -> mDb.endTransaction())
.map(_ignore -> getAllRecentCalls())
.doOnError(Throwable::printStackTrace)
.subscribeOn(Schedulers.io())
.doOnSuccess(mListAdapter::swapCursor)
.subscribeOn(AndroidSchedulers.mainThread())
.map(_ignore -> true)
.onErrorReturn(err -> {
err.printStackTrace();
return false;
});
}

public Cursor getAllRecentCalls() {
return mDb.query(
RecentCallsListEntry.TABLE_NAME,
null, null, null, null, null,
RecentCallsListEntry.COLUMN_CALL_TIME + " DESC");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.example.zhiruili.videoconf;

import android.content.Context;
import android.database.Cursor;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.zhiruili.videoconf.data.RecentCallsListContract.*;

public class RecentCallsListAdapter extends RecyclerView.Adapter<RecentCallsListAdapter.RecentCallViewHolder> {

private Context mContext;
private Cursor mCursor;
private OnItemClickListener mClickListener;

public RecentCallsListAdapter(Context context, Cursor cursor, OnItemClickListener listener) {
mContext = context;
mCursor = cursor;
mClickListener = listener;
}

@Override
public RecentCallViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.recent_calls_list_item, parent, false);
return new RecentCallViewHolder(view);
}

@Override
public void onBindViewHolder(RecentCallViewHolder holder, int position) {
if (!mCursor.moveToPosition(position)) {
return;
}
int idxCallId = mCursor.getColumnIndex(RecentCallsListEntry.COLUMN_PERSON_ID);
String callId = mCursor.getString(idxCallId);
int idxIsCallIn = mCursor.getColumnIndex(RecentCallsListEntry.COLUMN_IS_CALL_IN);
boolean isCallIn = mCursor.getInt(idxIsCallIn) != 0;
int idxCallTime = mCursor.getColumnIndex(RecentCallsListEntry.COLUMN_CALL_TIME);
String callTimeString = mCursor.getString(idxCallTime);
holder.callId.setText(callId);
holder.callTime.setText(callTimeString);
holder.callInOrOut.setText(isCallIn ? mContext.getString(R.string.label_call_in) : mContext.getString(R.string.label_call_out));
}

void swapCursor(Cursor newCursor) {
mCursor = newCursor;
notifyDataSetChanged();
}

@Override
public int getItemCount() {
return mCursor.getCount();
}

class RecentCallViewHolder extends RecyclerView.ViewHolder {

TextView callId;
TextView callTime;
TextView callInOrOut;

public RecentCallViewHolder(View itemView) {
super(itemView);
callId = (TextView) itemView.findViewById(R.id.tv_call_id);
callTime = (TextView) itemView.findViewById(R.id.tv_call_time);
callInOrOut = (TextView) itemView.findViewById(R.id.tv_call_in_or_out);
itemView.setOnClickListener(v -> mClickListener.onClick(callId.getText().toString()));
}
}

public interface OnItemClickListener {
void onClick(String callId);
}
}
Loading

0 comments on commit 9fbc61f

Please sign in to comment.