package com.thebluealliance.androidclient.listeners;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.view.View;
import android.widget.Toast;

import com.thebluealliance.androidclient.helpers.AnalyticsHelper;

import java.util.List;

import javax.inject.Inject;

public class SocialClickListener implements View.OnClickListener {

    private Context mContext;
    private String mModelKey;

    @Inject
    public SocialClickListener(Context context) {
        mContext = context;
    }

    public void setModelKey(String modelKey) {
        mModelKey = modelKey;
    }

    @Override
    public void onClick(View view) {
        PackageManager manager = mContext.getPackageManager();
        if (view.getTag() != null) {

            String uri = view.getTag().toString();

            //social button was clicked. Track the call
            AnalyticsHelper.sendSocialUpdate(mContext, uri, mModelKey);

            Intent i = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
            List<ResolveInfo> handlers = manager.queryIntentActivities(i, 0);
            if (!handlers.isEmpty()) {
                // There is an application to handle this intent intent
                mContext.startActivity(i);
            } else {
                // No application can handle this intent
                Toast.makeText(mContext, "No app can handle that request", Toast.LENGTH_SHORT)
                  .show();
            }
        }
    }
}

@@ -74,46 +74,33 @@
 ent.
-Context;%0Aimport android.content.Intent
+ActivityNotFoundException
 ;%0Aim
@@ -124,25 +124,15 @@
 ent.
-pm.PackageManager
+Context
 ;%0Aim
@@ -156,22 +156,14 @@
 ent.
-pm.ResolveInfo
+Intent
 ;%0Aim
@@ -311,32 +311,8 @@
 r;%0A%0A
-import java.util.List;%0A%0A
 impo
@@ -701,71 +701,8 @@
 ) %7B%0A
-        PackageManager manager = mContext.getPackageManager();%0A
     
@@ -734,17 +734,16 @@
 null) %7B%0A
-%0A
         
@@ -1018,305 +1018,108 @@
     
-List%3CResolveInfo%3E handlers = manager.queryIntentActivities(i, 0);%0A            if (!handlers.isEmpty()) %7B%0A                // There is an application to handle this intent intent%0A                mContext.startActivity(i);%0A            %7D else %7B%0A                // No application can handle this intent
+try %7B%0A                mContext.startActivity(i);%0A            %7D catch (ActivityNotFoundException e) %7B
 %0A   
@@ -1210,16 +1210,22 @@
 _SHORT)%0A
+      
         

Fix geo: intents on Android 11+ (#963)