Merge branch 'master' of https://gitlab.com/Cloud_Solution/doctor_app_flutter into hussam
commit
ba72d40deb
@ -0,0 +1,115 @@
|
||||
package com.example.doctor_app_flutter.Model;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class GetSessionStatusModel implements Parcelable {
|
||||
|
||||
@SerializedName("VC_ID")
|
||||
@Expose
|
||||
private Integer vCID;
|
||||
@SerializedName("TokenID")
|
||||
@Expose
|
||||
private String tokenID;
|
||||
@SerializedName("generalid")
|
||||
@Expose
|
||||
private String generalid;
|
||||
@SerializedName("DoctorId")
|
||||
@Expose
|
||||
private Integer doctorId;
|
||||
|
||||
public GetSessionStatusModel() {
|
||||
}
|
||||
|
||||
public GetSessionStatusModel(Integer vCID, String tokenID, String generalid, Integer doctorId) {
|
||||
this.vCID = vCID;
|
||||
this.tokenID = tokenID;
|
||||
this.generalid = generalid;
|
||||
this.doctorId = doctorId;
|
||||
}
|
||||
|
||||
protected GetSessionStatusModel(Parcel in) {
|
||||
if (in.readByte() == 0) {
|
||||
vCID = null;
|
||||
} else {
|
||||
vCID = in.readInt();
|
||||
}
|
||||
tokenID = in.readString();
|
||||
generalid = in.readString();
|
||||
if (in.readByte() == 0) {
|
||||
doctorId = null;
|
||||
} else {
|
||||
doctorId = in.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static final Creator<GetSessionStatusModel> CREATOR = new Creator<GetSessionStatusModel>() {
|
||||
@Override
|
||||
public GetSessionStatusModel createFromParcel(Parcel in) {
|
||||
return new GetSessionStatusModel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetSessionStatusModel[] newArray(int size) {
|
||||
return new GetSessionStatusModel[size];
|
||||
}
|
||||
};
|
||||
|
||||
public Integer getVCID() {
|
||||
return vCID;
|
||||
}
|
||||
|
||||
public void setVCID(Integer vCID) {
|
||||
this.vCID = vCID;
|
||||
}
|
||||
|
||||
public String getTokenID() {
|
||||
return tokenID;
|
||||
}
|
||||
|
||||
public void setTokenID(String tokenID) {
|
||||
this.tokenID = tokenID;
|
||||
}
|
||||
|
||||
public String getGeneralid() {
|
||||
return generalid;
|
||||
}
|
||||
|
||||
public void setGeneralid(String generalid) {
|
||||
this.generalid = generalid;
|
||||
}
|
||||
|
||||
public Integer getDoctorId() {
|
||||
return doctorId;
|
||||
}
|
||||
|
||||
public void setDoctorId(Integer doctorId) {
|
||||
this.doctorId = doctorId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
if (vCID == null) {
|
||||
dest.writeByte((byte) 0);
|
||||
} else {
|
||||
dest.writeByte((byte) 1);
|
||||
dest.writeInt(vCID);
|
||||
}
|
||||
dest.writeString(tokenID);
|
||||
dest.writeString(generalid);
|
||||
if (doctorId == null) {
|
||||
dest.writeByte((byte) 0);
|
||||
} else {
|
||||
dest.writeByte((byte) 1);
|
||||
dest.writeInt(doctorId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,106 @@
|
||||
package com.example.doctor_app_flutter.Model;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class SessionStatusModel implements Parcelable {
|
||||
|
||||
@SerializedName("Result")
|
||||
@Expose
|
||||
private String result;
|
||||
@SerializedName("SessionStatus")
|
||||
@Expose
|
||||
private Integer sessionStatus;
|
||||
@SerializedName("IsAuthenticated")
|
||||
@Expose
|
||||
private Boolean isAuthenticated;
|
||||
@SerializedName("MessageStatus")
|
||||
@Expose
|
||||
private Integer messageStatus;
|
||||
|
||||
protected SessionStatusModel(Parcel in) {
|
||||
result = in.readString();
|
||||
if (in.readByte() == 0) {
|
||||
sessionStatus = null;
|
||||
} else {
|
||||
sessionStatus = in.readInt();
|
||||
}
|
||||
byte tmpIsAuthenticated = in.readByte();
|
||||
isAuthenticated = tmpIsAuthenticated == 0 ? null : tmpIsAuthenticated == 1;
|
||||
if (in.readByte() == 0) {
|
||||
messageStatus = null;
|
||||
} else {
|
||||
messageStatus = in.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static final Creator<SessionStatusModel> CREATOR = new Creator<SessionStatusModel>() {
|
||||
@Override
|
||||
public SessionStatusModel createFromParcel(Parcel in) {
|
||||
return new SessionStatusModel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionStatusModel[] newArray(int size) {
|
||||
return new SessionStatusModel[size];
|
||||
}
|
||||
};
|
||||
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(String result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public Integer getSessionStatus() {
|
||||
return sessionStatus;
|
||||
}
|
||||
|
||||
public void setSessionStatus(Integer sessionStatus) {
|
||||
this.sessionStatus = sessionStatus;
|
||||
}
|
||||
|
||||
public Boolean getIsAuthenticated() {
|
||||
return isAuthenticated;
|
||||
}
|
||||
|
||||
public void setIsAuthenticated(Boolean isAuthenticated) {
|
||||
this.isAuthenticated = isAuthenticated;
|
||||
}
|
||||
|
||||
public Integer getMessageStatus() {
|
||||
return messageStatus;
|
||||
}
|
||||
|
||||
public void setMessageStatus(Integer messageStatus) {
|
||||
this.messageStatus = messageStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(result);
|
||||
if (sessionStatus == null) {
|
||||
dest.writeByte((byte) 0);
|
||||
} else {
|
||||
dest.writeByte((byte) 1);
|
||||
dest.writeInt(sessionStatus);
|
||||
}
|
||||
dest.writeByte((byte) (isAuthenticated == null ? 0 : isAuthenticated ? 1 : 2));
|
||||
if (messageStatus == null) {
|
||||
dest.writeByte((byte) 0);
|
||||
} else {
|
||||
dest.writeByte((byte) 1);
|
||||
dest.writeInt(messageStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
package com.example.doctor_app_flutter.Service;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.flutter.view.FlutterMain;
|
||||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class AppRetrofit extends Application {
|
||||
private static final int MY_SOCKET_TIMEOUT_MS = 20000;
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
FlutterMain.startInitialization(this);
|
||||
}
|
||||
|
||||
private Activity mCurrentActivity = null;
|
||||
|
||||
public Activity getCurrentActivity() {
|
||||
return mCurrentActivity;
|
||||
}
|
||||
|
||||
public void setCurrentActivity(Activity mCurrentActivity) {
|
||||
this.mCurrentActivity = mCurrentActivity;
|
||||
}
|
||||
|
||||
public static Retrofit getRetrofit( String baseUrl) {
|
||||
|
||||
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
|
||||
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
Gson gson = new GsonBuilder().serializeNulls().create();
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(chain -> {
|
||||
okhttp3.Request originalRequest = chain.request();
|
||||
okhttp3.Request newRequest = originalRequest.newBuilder()
|
||||
.addHeader("Content-Type","application/json")
|
||||
.addHeader("Accept","application/json")
|
||||
.build();
|
||||
|
||||
return chain.proceed(newRequest);
|
||||
})
|
||||
.addInterceptor(interceptor)
|
||||
.callTimeout(MY_SOCKET_TIMEOUT_MS, TimeUnit.SECONDS)
|
||||
.connectTimeout(MY_SOCKET_TIMEOUT_MS, TimeUnit.SECONDS)
|
||||
.readTimeout(MY_SOCKET_TIMEOUT_MS, TimeUnit.SECONDS)
|
||||
.connectionPool(new ConnectionPool(0, 5 * 60 * 1000, TimeUnit.SECONDS))
|
||||
.retryOnConnectionFailure(false)
|
||||
.build();
|
||||
|
||||
|
||||
return new Retrofit.Builder()
|
||||
.baseUrl(baseUrl)
|
||||
.addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.client(okHttpClient)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.example.doctor_app_flutter.Service;
|
||||
|
||||
import com.example.doctor_app_flutter.Model.GetSessionStatusModel;
|
||||
import com.example.doctor_app_flutter.Model.SessionStatusModel;
|
||||
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface SessionStatusAPI {
|
||||
|
||||
@POST("LiveCareApi/DoctorApp/GetSessionStatus")
|
||||
Call<SessionStatusModel> getSessionStatusModelData(@Body GetSessionStatusModel getSessionStatusModel);
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.example.doctor_app_flutter.ui;
|
||||
|
||||
import com.example.doctor_app_flutter.Model.GetSessionStatusModel;
|
||||
import com.example.doctor_app_flutter.Model.SessionStatusModel;
|
||||
|
||||
public interface VideoCallContract {
|
||||
|
||||
interface VideoCallView{
|
||||
|
||||
void onCallSuccessful(SessionStatusModel sessionStatusModel);
|
||||
void onFailure();
|
||||
}
|
||||
|
||||
interface VideoCallPresenter {
|
||||
|
||||
void callClintConnected(GetSessionStatusModel statusModel);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package com.example.doctor_app_flutter.ui;
|
||||
|
||||
import com.example.doctor_app_flutter.Model.GetSessionStatusModel;
|
||||
import com.example.doctor_app_flutter.Model.SessionStatusModel;
|
||||
import com.example.doctor_app_flutter.Service.AppRetrofit;
|
||||
import com.example.doctor_app_flutter.Service.SessionStatusAPI;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class VideoCallPresenterImpl implements VideoCallContract.VideoCallPresenter {
|
||||
|
||||
private VideoCallContract.VideoCallView view;
|
||||
private SessionStatusAPI sessionStatusAPI;
|
||||
private String baseUrl;
|
||||
|
||||
public VideoCallPresenterImpl(VideoCallContract.VideoCallView view, String baseUrl) {
|
||||
this.view = view;
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callClintConnected(GetSessionStatusModel statusModel) {
|
||||
|
||||
|
||||
sessionStatusAPI = AppRetrofit.getRetrofit(baseUrl).create(SessionStatusAPI.class);
|
||||
|
||||
Call<SessionStatusModel> call = sessionStatusAPI.getSessionStatusModelData(statusModel);
|
||||
|
||||
call.enqueue(new Callback<SessionStatusModel>() {
|
||||
@Override
|
||||
public void onResponse(@NotNull Call<SessionStatusModel> call, @NotNull Response<SessionStatusModel> response) {
|
||||
if (response.isSuccessful()) {
|
||||
view.onCallSuccessful(response.body());
|
||||
} else
|
||||
view.onFailure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call<SessionStatusModel> call, @NotNull Throwable t) {
|
||||
view.onFailure();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,45 +1,101 @@
|
||||
package com.example.doctor_app_flutter
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import androidx.annotation.NonNull;
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugins.GeneratedPluginRegistrant
|
||||
import androidx.annotation.NonNull
|
||||
import com.example.doctor_app_flutter.Model.GetSessionStatusModel
|
||||
import com.example.doctor_app_flutter.Model.SessionStatusModel
|
||||
import com.example.doctor_app_flutter.ui.VideoCallActivity
|
||||
import com.google.gson.GsonBuilder
|
||||
import io.flutter.embedding.android.FlutterFragmentActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import io.flutter.plugins.GeneratedPluginRegistrant
|
||||
|
||||
class MainActivity: FlutterFragmentActivity() {
|
||||
class MainActivity : FlutterFragmentActivity(), MethodChannel.MethodCallHandler {
|
||||
|
||||
private val CHANNEL = "Dr.cloudSolution/videoCall"
|
||||
private var result: MethodChannel.Result? = null
|
||||
private var call: MethodCall? = null
|
||||
private val LAUNCH_VIDEO: Int = 1
|
||||
|
||||
|
||||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
||||
GeneratedPluginRegistrant.registerWith(flutterEngine)
|
||||
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
|
||||
call, result ->
|
||||
if (call.method == "openVideoCall") {
|
||||
val apiKey = call.argument<String>("kApiKey")
|
||||
val sessionId = call.argument<String>("kSessionId")
|
||||
val token = call.argument<String>("kToken")
|
||||
// val callDuration = call.argument<String>("callDuration")
|
||||
// val warningDuration = call.argument<String>("warningDuration")
|
||||
val appLang = call.argument<String>("appLang")
|
||||
openVideoCall(apiKey,sessionId,token/*,callDuration,warningDuration*/,appLang)
|
||||
} else {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler(this)
|
||||
}
|
||||
|
||||
private fun openVideoCall(apiKey: String?, sessionId: String?, token: String?/*, callDuration: String?, warningDuration: String?*/, appLang: String?) {
|
||||
|
||||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
|
||||
|
||||
this.result = result
|
||||
this.call = call
|
||||
|
||||
if (call.method == "openVideoCall") {
|
||||
val apiKey = call.argument<String>("kApiKey")
|
||||
val sessionId = call.argument<String>("kSessionId")
|
||||
val token = call.argument<String>("kToken")
|
||||
val appLang = call.argument<String>("appLang")
|
||||
val baseUrl = call.argument<String>("baseUrl")
|
||||
|
||||
// Session Status model
|
||||
val VC_ID = call.argument<Int>("VC_ID")
|
||||
val tokenID = call.argument<String>("TokenID")
|
||||
val generalId = call.argument<String>("generalId")
|
||||
val doctorId = call.argument<Int>("DoctorId")
|
||||
|
||||
val sessionStatusModel = GetSessionStatusModel(VC_ID, tokenID, generalId, doctorId)
|
||||
|
||||
|
||||
openVideoCall(apiKey, sessionId, token, appLang, baseUrl, sessionStatusModel)
|
||||
|
||||
} else {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
|
||||
private fun openVideoCall(apiKey: String?, sessionId: String?, token: String?, appLang: String?, baseUrl: String?, sessionStatusModel: GetSessionStatusModel) {
|
||||
// val videoCallActivity = VideoCallActivity()
|
||||
|
||||
val intent = Intent(this, VideoCallActivity::class.java)
|
||||
intent.putExtra("apiKey", apiKey)
|
||||
intent.putExtra("sessionId", sessionId)
|
||||
intent.putExtra("token", token)
|
||||
// intent.putExtra("callDuration", callDuration)
|
||||
//intent.putExtra("warningDuration", warningDuration)
|
||||
intent.putExtra("appLang", appLang)
|
||||
startActivity(intent)
|
||||
intent.putExtra("baseUrl", baseUrl)
|
||||
intent.putExtra("sessionStatusModel", sessionStatusModel)
|
||||
startActivityForResult(intent, LAUNCH_VIDEO)
|
||||
|
||||
}
|
||||
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
var asd = "";
|
||||
if (requestCode == LAUNCH_VIDEO) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
val result : SessionStatusModel? = data?.getParcelableExtra("sessionStatusNotRespond")
|
||||
val callResponse : HashMap<String, String> = HashMap()
|
||||
|
||||
val sessionStatus : HashMap<String, String> = HashMap()
|
||||
val gson = GsonBuilder().serializeNulls().create()
|
||||
|
||||
callResponse["callResponse"] = "CallNotRespond"
|
||||
val jsonRes = gson.toJson(result)
|
||||
callResponse["sessionStatus"] = jsonRes
|
||||
|
||||
this.result?.success(callResponse)
|
||||
}
|
||||
if (resultCode == Activity.RESULT_CANCELED) {
|
||||
val callResponse : HashMap<String, String> = HashMap()
|
||||
callResponse["callResponse"] = "CallEnd"
|
||||
|
||||
result?.success(callResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
//
|
||||
// ICallProtocol.swift
|
||||
// Runner
|
||||
//
|
||||
// Created by Elham Rababah && Mohammad Aljammal on 7/2/20.
|
||||
// Copyright © 2020 The Chromium Authors. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol ICallProtocol {
|
||||
|
||||
func sessionDone(res:Any)
|
||||
func sessionNotResponded(res: Any)
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
class SessionStatusModel {
|
||||
bool isAuthenticated;
|
||||
int messageStatus;
|
||||
String result;
|
||||
int sessionStatus;
|
||||
|
||||
SessionStatusModel(
|
||||
{this.isAuthenticated,
|
||||
this.messageStatus,
|
||||
this.result,
|
||||
this.sessionStatus});
|
||||
|
||||
SessionStatusModel.fromJson(Map<dynamic, dynamic> json) {
|
||||
isAuthenticated = json['IsAuthenticated'];
|
||||
messageStatus = json['MessageStatus'];
|
||||
result = json['Result'];
|
||||
sessionStatus = json['SessionStatus'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['IsAuthenticated'] = this.isAuthenticated;
|
||||
data['MessageStatus'] = this.messageStatus;
|
||||
data['Result'] = this.result;
|
||||
data['SessionStatus'] = this.sessionStatus;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -1,28 +1,44 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
import 'package:doctor_app_flutter/config/config.dart';
|
||||
import 'package:doctor_app_flutter/models/livecare/session_status_model.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class VideoChannel{
|
||||
/// channel name
|
||||
static const _channel = const MethodChannel("Dr.cloudSolution/videoCall");
|
||||
static Future<dynamic> openVideoCallScreen(
|
||||
{kApiKey, kSessionId, kToken, callDuration, warningDuration}) {
|
||||
static openVideoCallScreen(
|
||||
{kApiKey, kSessionId, kToken, callDuration, warningDuration,int vcId,String tokenID,String generalId,int doctorId, Function() onCallEnd , Function(SessionStatusModel sessionStatusModel) onCallNotRespond ,Function(String error) onFailure}) async {
|
||||
var result;
|
||||
try {
|
||||
result = _channel.invokeMethod(
|
||||
result = await _channel.invokeMethod(
|
||||
'openVideoCall',
|
||||
{
|
||||
"kApiKey": kApiKey,
|
||||
"kSessionId": kSessionId,
|
||||
"kToken": kToken,
|
||||
/* "callDuration": callDuration,
|
||||
"warningDuration": warningDuration,*/
|
||||
"appLang": "en",
|
||||
"baseUrl": BASE_URL,
|
||||
"VC_ID": vcId,
|
||||
"TokenID": tokenID,
|
||||
"generalId": generalId,
|
||||
"DoctorId": doctorId ,
|
||||
},
|
||||
);
|
||||
} on PlatformException catch (e) {
|
||||
result = e.toString();
|
||||
if(result['callResponse'] == 'CallEnd') {
|
||||
onCallEnd();
|
||||
}
|
||||
else {
|
||||
SessionStatusModel sessionStatusModel = SessionStatusModel.fromJson(Platform.isIOS ?result['sessionStatus'] :json.decode(result['sessionStatus']));
|
||||
onCallNotRespond(sessionStatusModel);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
onFailure(e.toString());
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue