// Path: force-update/src/main/java/net/skoumal/forceupdate/util/GooglePlay.java
// public class GooglePlay {
// 
//     public static void openAppDetail(Activity gContext) {
//         String appPackage = gContext.getPackageName();
//         Uri googlePlayUri = Uri.parse("market://details?id=" + appPackage);
//         Intent googlePlayIntent = new Intent(Intent.ACTION_VIEW, googlePlayUri);
//         boolean googlePlayAvailable = false;
// 
//         // try to find official Google Play app
//         final List<ResolveInfo> availableApps = gContext.getPackageManager().queryIntentActivities(googlePlayIntent, 0);
//         for (ResolveInfo app: availableApps) {
//             if (app.activityInfo.applicationInfo.packageName.equals("com.android.vending")) {
// 
//                 ActivityInfo appActivity = app.activityInfo;
//                 ComponentName component = new ComponentName(
//                         appActivity.applicationInfo.packageName,
//                         appActivity.name
//                 );
//                 googlePlayIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
//                 googlePlayIntent.setComponent(component);
//                 gContext.startActivity(googlePlayIntent);
//                 googlePlayAvailable = true;
//                 break;
// 
//             }
//         }
// 
//         if (!googlePlayAvailable) {
//             if (availableApps.size() > 0) {
//                 // fallback to universal Google Play Intent
//                 gContext.startActivity(googlePlayIntent);
//             } else {
//                 // if there is no app bind to market:// open Google Play in browser
//                 Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackage));
//                 gContext.startActivity(webIntent);
//             }
//         }
//     }
// }


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import net.skoumal.forceupdate.R;
import net.skoumal.forceupdate.util.GooglePlay;

package net.skoumal.forceupdate.view.dialog;



/**
 * Created by gingo on 1.10.2016.
 */
public class ForceUpdateActivity extends Activity {

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

        setTheme(R.style.NoActionBarTheme);

        setContentView(R.layout.force_update_activity);

        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openGooglePlay();
            }
        });

    }

    public void openGooglePlay() {

// Path: force-update/src/main/java/net/skoumal/forceupdate/util/GooglePlay.java
// public class GooglePlay {
// 
//     public static void openAppDetail(Activity gContext) {
//         String appPackage = gContext.getPackageName();
//         Uri googlePlayUri = Uri.parse("market://details?id=" + appPackage);
//         Intent googlePlayIntent = new Intent(Intent.ACTION_VIEW, googlePlayUri);
//         boolean googlePlayAvailable = false;
// 
//         // try to find official Google Play app
//         final List<ResolveInfo> availableApps = gContext.getPackageManager().queryIntentActivities(googlePlayIntent, 0);
//         for (ResolveInfo app: availableApps) {
//             if (app.activityInfo.applicationInfo.packageName.equals("com.android.vending")) {
// 
//                 ActivityInfo appActivity = app.activityInfo;
//                 ComponentName component = new ComponentName(
//                         appActivity.applicationInfo.packageName,
//                         appActivity.name
//                 );
//                 googlePlayIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
//                 googlePlayIntent.setComponent(component);
//                 gContext.startActivity(googlePlayIntent);
//                 googlePlayAvailable = true;
//                 break;
// 
//             }
//         }
// 
//         if (!googlePlayAvailable) {
//             if (availableApps.size() > 0) {
//                 // fallback to universal Google Play Intent
//                 gContext.startActivity(googlePlayIntent);
//             } else {
//                 // if there is no app bind to market:// open Google Play in browser
//                 Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackage));
//                 gContext.startActivity(webIntent);
//             }
//         }
//     }
// }


// Path: force-update/src/main/java/net/skoumal/forceupdate/view/dialog/ForceUpdateActivity.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import net.skoumal.forceupdate.R;
import net.skoumal.forceupdate.util.GooglePlay;

package net.skoumal.forceupdate.view.dialog;



/**
 * Created by gingo on 1.10.2016.
 */
public class ForceUpdateActivity extends Activity {

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

        setTheme(R.style.NoActionBarTheme);

        setContentView(R.layout.force_update_activity);

        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openGooglePlay();
            }
        });

    }

    public void openGooglePlay() {

        GooglePlay.openAppDetail(this);
