// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/APIService.java
// public interface APIService {
// 
//     @GET("session")
//     Call<GetSessionResponse> getSession();
// 
//     @POST("archive/start")
//     @Headers("Content-Type: application/json")
//     Call<Void> startArchive(@Body StartArchiveRequest startArchiveRequest);
// 
//     @POST("archive/{archiveId}/stop")
//     Call<Void> stopArchive(@Path("archiveId") String archiveId);
// }
// 
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/EmptyCallback.java
// public class EmptyCallback<T> implements Callback<T> {
//     @Override
//     public void onResponse(Call<T> call, Response<T> response) {
// 
//     }
// 
//     @Override
//     public void onFailure(Call<T> call, Throwable t) {
// 
//     }
// }
// 
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/GetSessionResponse.java
// public class GetSessionResponse {
//     @Json(name = "apiKey") public String apiKey;
//     @Json(name = "sessionId") public String sessionId;
//     @Json(name = "token") public String token;
// }
// 
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/StartArchiveRequest.java
// public class StartArchiveRequest {
//     @Json(name = "sessionId") public String sessionId;
// }


import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.tokbox.sample.archiving.network.APIService;
import com.tokbox.sample.archiving.network.EmptyCallback;
import com.tokbox.sample.archiving.network.GetSessionResponse;
import com.tokbox.sample.archiving.network.StartArchiveRequest;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;
import java.util.List;
    public void onPermissionsDenied(int requestCode, List<String> perms) {
        finishWithMessage("onPermissionsDenied: " + requestCode + ": " + perms);
    }

    @AfterPermissionGranted(PERMISSIONS_REQUEST_CODE)
    private void requestPermissions() {
        String[] perms = {Manifest.permission.INTERNET, Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO};
        
        if (EasyPermissions.hasPermissions(this, perms)) {
            initRetrofit();
            getSession();
        } else {
            EasyPermissions.requestPermissions(this, getString(R.string.rationale_video_app), PERMISSIONS_REQUEST_CODE, perms);
        }
    }

    /* Make a request for session data */
    private void getSession() {
        Log.i(TAG, "getSession");

        Call<GetSessionResponse> call = apiService.getSession();

        call.enqueue(new Callback<GetSessionResponse>() {
            @Override
            public void onResponse(Call<GetSessionResponse> call, Response<GetSessionResponse> response) {
                GetSessionResponse body = response.body();
                initializeSession(body.apiKey, body.sessionId, body.token);
            }

            @Override
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/APIService.java
// public interface APIService {
// 
//     @GET("session")
//     Call<GetSessionResponse> getSession();
// 
//     @POST("archive/start")
//     @Headers("Content-Type: application/json")
//     Call<Void> startArchive(@Body StartArchiveRequest startArchiveRequest);
// 
//     @POST("archive/{archiveId}/stop")
//     Call<Void> stopArchive(@Path("archiveId") String archiveId);
// }
// 
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/EmptyCallback.java
// public class EmptyCallback<T> implements Callback<T> {
//     @Override
//     public void onResponse(Call<T> call, Response<T> response) {
// 
//     }
// 
//     @Override
//     public void onFailure(Call<T> call, Throwable t) {
// 
//     }
// }
// 
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/GetSessionResponse.java
// public class GetSessionResponse {
//     @Json(name = "apiKey") public String apiKey;
//     @Json(name = "sessionId") public String sessionId;
//     @Json(name = "token") public String token;
// }
// 
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/StartArchiveRequest.java
// public class StartArchiveRequest {
//     @Json(name = "sessionId") public String sessionId;
// }


// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/MainActivity.java
import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.tokbox.sample.archiving.network.APIService;
import com.tokbox.sample.archiving.network.EmptyCallback;
import com.tokbox.sample.archiving.network.GetSessionResponse;
import com.tokbox.sample.archiving.network.StartArchiveRequest;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;
import java.util.List;

    public void onPermissionsDenied(int requestCode, List<String> perms) {
        finishWithMessage("onPermissionsDenied: " + requestCode + ": " + perms);
    }

    @AfterPermissionGranted(PERMISSIONS_REQUEST_CODE)
    private void requestPermissions() {
        String[] perms = {Manifest.permission.INTERNET, Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO};
        
        if (EasyPermissions.hasPermissions(this, perms)) {
            initRetrofit();
            getSession();
        } else {
            EasyPermissions.requestPermissions(this, getString(R.string.rationale_video_app), PERMISSIONS_REQUEST_CODE, perms);
        }
    }

    /* Make a request for session data */
    private void getSession() {
        Log.i(TAG, "getSession");

        Call<GetSessionResponse> call = apiService.getSession();

        call.enqueue(new Callback<GetSessionResponse>() {
            @Override
            public void onResponse(Call<GetSessionResponse> call, Response<GetSessionResponse> response) {
                GetSessionResponse body = response.body();
                initializeSession(body.apiKey, body.sessionId, body.token);
            }

            @Override
            public void onFailure(Call<GetSessionResponse> call, Throwable t) {