Bläddra i källkod

Start working on call

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 år sedan
förälder
incheckning
5b3e2f55e3

+ 6 - 1
app/src/main/AndroidManifest.xml

@@ -11,7 +11,7 @@
     <uses-permission android:name="android.permission.RECORD_AUDIO"/>
     <uses-permission android:name="android.permission.INTERNET"/>
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
-    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
     <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 
@@ -37,6 +37,11 @@
             </intent-filter>
         </activity>
 
+        <activity
+            android:name=".activities.CallActivity"
+            android:launchMode="singleTask"
+            />
+
 
         <service
             android:name=".services.firebase.MagicFirebaseMessagingService">

+ 98 - 0
app/src/main/java/com/nextcloud/talk/activities/CallActivity.java

@@ -0,0 +1,98 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
+ *
+ * This program 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.
+ *
+ * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.talk.activities;
+
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.view.WindowManager;
+
+import com.bluelinelabs.conductor.Conductor;
+import com.bluelinelabs.conductor.Router;
+import com.bluelinelabs.conductor.RouterTransaction;
+import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler;
+import com.nextcloud.talk.R;
+import com.nextcloud.talk.application.NextcloudTalkApplication;
+import com.nextcloud.talk.controllers.CallController;
+import com.nextcloud.talk.utils.bundle.BundleBuilder;
+
+import autodagger.AutoInjector;
+import butterknife.BindView;
+import butterknife.ButterKnife;
+
+@AutoInjector(NextcloudTalkApplication.class)
+public class CallActivity extends AppCompatActivity {
+    private static final String TAG = "CallActivity";
+
+    @BindView(R.id.controller_container)
+    ViewGroup container;
+
+    private Router router;
+
+    private String roomToken;
+    private String userDisplayName;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        requestWindowFeature(Window.FEATURE_NO_TITLE);
+        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
+                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
+                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
+                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
+        getWindow().getDecorView().setSystemUiVisibility(getSystemUiVisibility());
+
+        setContentView(R.layout.activity_call);
+        NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
+        ButterKnife.bind(this);
+
+        roomToken = getIntent().getExtras().getString("roomToken", "");
+        userDisplayName = getIntent().getExtras().getString("userDisplayName", "");
+
+        router = Conductor.attachRouter(this, container, savedInstanceState);
+
+        if (!router.hasRootController()) {
+            BundleBuilder bundleBuilder = new BundleBuilder(new Bundle());
+            bundleBuilder.putString("roomToken", roomToken);
+            bundleBuilder.putString("userDisplayName", userDisplayName);
+
+            router.setRoot(RouterTransaction.with(new CallController(bundleBuilder.build()))
+            .popChangeHandler(new SimpleSwapChangeHandler())
+            .pushChangeHandler((new SimpleSwapChangeHandler())));
+        }
+    }
+
+    @Override
+    public void onBackPressed() {
+        if (!router.handleBack()) {
+            super.onBackPressed();
+        }
+    }
+
+    private static int getSystemUiVisibility() {
+        int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
+        flags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
+        return flags;
+    }
+}

+ 0 - 2
app/src/main/java/com/nextcloud/talk/adapters/items/RoomItem.java

@@ -28,7 +28,6 @@ import android.widget.TextView;
 import com.bumptech.glide.load.engine.DiskCacheStrategy;
 import com.bumptech.glide.load.model.GlideUrl;
 import com.bumptech.glide.load.model.LazyHeaders;
-import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions;
 import com.nextcloud.talk.R;
 import com.nextcloud.talk.api.helpers.api.ApiHelper;
 import com.nextcloud.talk.api.models.json.rooms.Room;
@@ -122,7 +121,6 @@ public class RoomItem extends AbstractFlexibleItem<RoomItem.RoomItemViewHolder>
 
                     GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
                             .asBitmap()
-                            .transition(BitmapTransitionOptions.withCrossFade())
                             .skipMemoryCache(true)
                             .diskCacheStrategy(DiskCacheStrategy.NONE)
                             .load(glideUrl)

+ 6 - 0
app/src/main/java/com/nextcloud/talk/api/models/json/call/CallOCS.java

@@ -24,6 +24,12 @@ import com.bluelinelabs.logansquare.annotation.JsonField;
 import com.bluelinelabs.logansquare.annotation.JsonObject;
 import com.nextcloud.talk.api.models.json.generic.GenericOCS;
 
+import org.parceler.Parcel;
+
+import lombok.Data;
+
+@Data
+@Parcel
 @JsonObject
 public class CallOCS extends GenericOCS {
     @JsonField(name = "data")

+ 6 - 0
app/src/main/java/com/nextcloud/talk/api/models/json/call/CallOverall.java

@@ -23,6 +23,12 @@ package com.nextcloud.talk.api.models.json.call;
 import com.bluelinelabs.logansquare.annotation.JsonField;
 import com.bluelinelabs.logansquare.annotation.JsonObject;
 
+import org.parceler.Parcel;
+
+import lombok.Data;
+
+@Data
+@Parcel
 @JsonObject
 public class CallOverall {
     @JsonField(name = "ocs")

+ 69 - 0
app/src/main/java/com/nextcloud/talk/controllers/CallController.java

@@ -0,0 +1,69 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
+ *
+ * This program 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.
+ *
+ * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.talk.controllers;
+
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.nextcloud.talk.R;
+import com.nextcloud.talk.application.NextcloudTalkApplication;
+import com.nextcloud.talk.controllers.base.RefWatchingController;
+
+import org.webrtc.SurfaceViewRenderer;
+
+import autodagger.AutoInjector;
+import butterknife.BindView;
+
+@AutoInjector(NextcloudTalkApplication.class)
+public class CallController extends RefWatchingController {
+    private static final String TAG = "CallController";
+
+    @BindView(R.id.fullscreen_video_view)
+    SurfaceViewRenderer fullScreenVideo;
+
+    @BindView(R.id.pip_video_view)
+    SurfaceViewRenderer pipVideoView;
+
+    private String roomToken;
+    private String userDisplayName;
+
+    public CallController(Bundle args) {
+        super(args);
+        this.roomToken = args.getString("roomToken", "");
+        this.userDisplayName = args.getString("userDisplayName");
+
+    }
+
+    @Override
+    protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
+        return inflater.inflate(R.layout.controller_call, container, false);
+    }
+
+    @Override
+    protected void onViewBound(@NonNull View view) {
+        super.onViewBound(view);
+        NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
+    }
+
+}

+ 39 - 0
app/src/main/java/com/nextcloud/talk/controllers/CallsListController.java

@@ -22,6 +22,7 @@ package com.nextcloud.talk.controllers;
 
 import android.app.SearchManager;
 import android.content.Context;
+import android.content.Intent;
 import android.os.Bundle;
 import android.os.Handler;
 import android.support.annotation.NonNull;
@@ -46,15 +47,19 @@ import android.view.inputmethod.EditorInfo;
 
 import com.bluelinelabs.conductor.RouterTransaction;
 import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
+import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler;
 import com.bluelinelabs.logansquare.LoganSquare;
 import com.nextcloud.talk.R;
+import com.nextcloud.talk.activities.CallActivity;
 import com.nextcloud.talk.adapters.items.RoomItem;
 import com.nextcloud.talk.api.NcApi;
 import com.nextcloud.talk.api.helpers.api.ApiHelper;
+import com.nextcloud.talk.api.models.json.call.CallOverall;
 import com.nextcloud.talk.api.models.json.rooms.Room;
 import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.controllers.base.BaseController;
 import com.nextcloud.talk.persistence.entities.UserEntity;
+import com.nextcloud.talk.utils.bundle.BundleBuilder;
 import com.nextcloud.talk.utils.database.cache.CacheUtils;
 import com.nextcloud.talk.utils.database.user.UserUtils;
 
@@ -69,7 +74,9 @@ import eu.davidea.flexibleadapter.FlexibleAdapter;
 import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
 import io.reactivex.android.schedulers.AndroidSchedulers;
 import io.reactivex.disposables.Disposable;
+import io.reactivex.functions.Consumer;
 import io.reactivex.schedulers.Schedulers;
+import okhttp3.Credentials;
 import retrofit2.HttpException;
 
 @AutoInjector(NextcloudTalkApplication.class)
@@ -108,6 +115,35 @@ public class CallsListController extends BaseController implements SearchView.On
     private SearchView searchView;
     private String searchQuery;
 
+    private FlexibleAdapter.OnItemClickListener onItemClickListener =
+            new FlexibleAdapter.OnItemClickListener() {
+                @Override
+                public boolean onItemClick(int position) {
+                    RoomItem roomItem = roomItems.get(position);
+                    ncApi.joinCall(Credentials.basic(userEntity.getUsername(), userEntity.getToken()),
+                            ApiHelper.getUrlForCall(userEntity.getBaseUrl(), roomItem.getModel().getToken()))
+                            .subscribeOn(Schedulers.newThread())
+                            .observeOn(AndroidSchedulers.mainThread())
+                            .subscribe(new Consumer<CallOverall>() {
+                                @Override
+                                public void accept(CallOverall callOverall) throws Exception {
+
+                                    overridePushHandler(new SimpleSwapChangeHandler());
+                                    overridePopHandler(new SimpleSwapChangeHandler());
+
+                                    Intent callIntent = new Intent(getActivity(), CallActivity.class);
+                                    BundleBuilder bundleBuilder = new BundleBuilder(new Bundle());
+                                    bundleBuilder.putString("roomToken", roomItem.getModel().getToken());
+                                    bundleBuilder.putString("userDisplayName", userEntity.getDisplayName());
+                                    callIntent.putExtras(bundleBuilder.build());
+                                    startActivity(callIntent);
+                                }
+                            });
+
+                    return true;
+                }
+            };
+
     public CallsListController() {
         super();
         setHasOptionsMenu(true);
@@ -132,6 +168,8 @@ public class CallsListController extends BaseController implements SearchView.On
             adapter = new FlexibleAdapter<>(roomItems, getActivity(), false);
         }
 
+        adapter.addListener(onItemClickListener);
+
         prepareViews();
 
         if ((userEntity = userUtils.getCurrentUser()) != null) {
@@ -391,4 +429,5 @@ public class CallsListController extends BaseController implements SearchView.On
     public boolean onQueryTextSubmit(String query) {
         return onQueryTextChange(query);
     }
+
 }

+ 8 - 1
app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java

@@ -21,6 +21,7 @@ package com.nextcloud.talk.controllers.base;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.v7.app.ActionBar;
+import android.util.Log;
 import android.view.View;
 
 import com.bluelinelabs.conductor.Controller;
@@ -28,6 +29,7 @@ import com.nextcloud.talk.controllers.base.providers.ActionBarProvider;
 
 public abstract class BaseController extends RefWatchingController {
 
+    private static final String TAG = "BaseController";
     protected BaseController() {
     }
 
@@ -38,7 +40,12 @@ public abstract class BaseController extends RefWatchingController {
     // Note: This is just a quick demo of how an ActionBar *can* be accessed, not necessarily how it *should*
     // be accessed. In a production app, this would use Dagger instead.
     protected ActionBar getActionBar() {
-        ActionBarProvider actionBarProvider = ((ActionBarProvider) getActivity());
+        ActionBarProvider actionBarProvider = null;
+        try {
+            actionBarProvider = ((ActionBarProvider) getActivity());
+        } catch (Exception exception) {
+            Log.d(TAG, "Failed to fetch the action bar provider");
+        }
         return actionBarProvider != null ? actionBarProvider.getSupportActionBar() : null;
     }
 

+ 35 - 0
app/src/main/res/layout/activity_call.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Nextcloud Talk application
+  ~
+  ~ @author Mario Danic
+  ~ Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
+  ~
+  ~ This program 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.
+  ~
+  ~ This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+  -->
+
+<RelativeLayout 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"
+                                                 android:fitsSystemWindows="true"
+                                                 tools:context=".activities.CallActivity">
+
+    <com.bluelinelabs.conductor.ChangeHandlerFrameLayout
+        android:id="@+id/controller_container"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        />
+
+</RelativeLayout>

+ 39 - 0
app/src/main/res/layout/controller_call.xml

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Nextcloud Talk application
+  ~
+  ~ @author Mario Danic
+  ~ Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
+  ~
+  ~ This program 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.
+  ~
+  ~ This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+  -->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:orientation="vertical">
+
+    <org.webrtc.SurfaceViewRenderer
+        android:id="@+id/fullscreen_video_view"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"/>
+
+    <org.webrtc.SurfaceViewRenderer
+        android:id="@+id/pip_video_view"
+        android:layout_width="wrap_content"
+        android:layout_height="144dp"
+        android:layout_gravity="bottom|end"
+        android:layout_margin="16dp"/>
+
+</RelativeLayout>