// Path: app/src/main/java/io/github/marktony/espresso/mvp/packagedetails/PackageDetailsActivity.java
// public class PackageDetailsActivity extends AppCompatActivity{
// 
//     private PackageDetailsFragment fragment;
// 
//     public static final String PACKAGE_ID = "PACKAGE_ID";
// 
//     @Override
//     protected void onCreate(@Nullable Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         setContentView(R.layout.container);
// 
//         // Set the navigation bar color
//         if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("navigation_bar_tint", true)) {
//             getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
//         }
// 
//         // Restore the status.
//         if (savedInstanceState != null) {
//             fragment = (PackageDetailsFragment) getSupportFragmentManager().getFragment(savedInstanceState, "PackageDetailsFragment");
//         } else {
//             fragment = PackageDetailsFragment.newInstance();
//         }
// 
//         getSupportFragmentManager().beginTransaction()
//                 .replace(R.id.view_pager, fragment)
//                 .commit();
// 
//         // Create the presenter.
//         new PackageDetailsPresenter(
//                 getIntent().getStringExtra(PACKAGE_ID),
//                 PackagesRepository.getInstance(
//                         PackagesRemoteDataSource.getInstance(),
//                         PackagesLocalDataSource.getInstance()),
//                 fragment);
// 
//     }
// 
//     // Save the fragment state to bundle.
//     @Override
//     protected void onSaveInstanceState(Bundle outState) {
//         super.onSaveInstanceState(outState);
//         getSupportFragmentManager().putFragment(outState, "PackageDetailsFragment", fragment);
//     }
// 
// }


import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.RemoteViews;
import io.github.marktony.espresso.R;
import io.github.marktony.espresso.mvp.packagedetails.PackageDetailsActivity;
/*
 *  Copyright(c) 2017 lizhaotailang
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.github.marktony.espresso.appwidget;



/**
 * Created by lizhaotailang on 2017/3/8.
 */

public class AppWidgetProvider extends android.appwidget.AppWidgetProvider {

    private static final String REFRESH_ACTION = "io.github.marktony.espresso.appwidget.action.REFRESH";

    public static Intent getRefreshBroadcastIntent(Context context) {
        return new Intent(REFRESH_ACTION)
                .setComponent(new ComponentName(context, AppWidgetProvider.class));
    }

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        for (int appWidgetId : appWidgetIds) {
            RemoteViews remoteViews = updateWidgetListView(context, appWidgetId);
            appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
        }
        super.onUpdate(context, appWidgetManager, appWidgetIds);
    }

    private RemoteViews updateWidgetListView(Context context, int id) {
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.launcher_list_widget);

        Intent intent = new Intent(context, AppWidgetService.class);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));

        remoteViews.setRemoteAdapter(R.id.listViewWidget, intent);
        remoteViews.setEmptyView(R.id.listViewWidget, R.id.emptyView);

// Path: app/src/main/java/io/github/marktony/espresso/mvp/packagedetails/PackageDetailsActivity.java
// public class PackageDetailsActivity extends AppCompatActivity{
// 
//     private PackageDetailsFragment fragment;
// 
//     public static final String PACKAGE_ID = "PACKAGE_ID";
// 
//     @Override
//     protected void onCreate(@Nullable Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         setContentView(R.layout.container);
// 
//         // Set the navigation bar color
//         if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("navigation_bar_tint", true)) {
//             getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
//         }
// 
//         // Restore the status.
//         if (savedInstanceState != null) {
//             fragment = (PackageDetailsFragment) getSupportFragmentManager().getFragment(savedInstanceState, "PackageDetailsFragment");
//         } else {
//             fragment = PackageDetailsFragment.newInstance();
//         }
// 
//         getSupportFragmentManager().beginTransaction()
//                 .replace(R.id.view_pager, fragment)
//                 .commit();
// 
//         // Create the presenter.
//         new PackageDetailsPresenter(
//                 getIntent().getStringExtra(PACKAGE_ID),
//                 PackagesRepository.getInstance(
//                         PackagesRemoteDataSource.getInstance(),
//                         PackagesLocalDataSource.getInstance()),
//                 fragment);
// 
//     }
// 
//     // Save the fragment state to bundle.
//     @Override
//     protected void onSaveInstanceState(Bundle outState) {
//         super.onSaveInstanceState(outState);
//         getSupportFragmentManager().putFragment(outState, "PackageDetailsFragment", fragment);
//     }
// 
// }


// Path: app/src/main/java/io/github/marktony/espresso/appwidget/AppWidgetProvider.java
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.RemoteViews;
import io.github.marktony.espresso.R;
import io.github.marktony.espresso.mvp.packagedetails.PackageDetailsActivity;

/*
 *  Copyright(c) 2017 lizhaotailang
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.github.marktony.espresso.appwidget;



/**
 * Created by lizhaotailang on 2017/3/8.
 */

public class AppWidgetProvider extends android.appwidget.AppWidgetProvider {

    private static final String REFRESH_ACTION = "io.github.marktony.espresso.appwidget.action.REFRESH";

    public static Intent getRefreshBroadcastIntent(Context context) {
        return new Intent(REFRESH_ACTION)
                .setComponent(new ComponentName(context, AppWidgetProvider.class));
    }

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        for (int appWidgetId : appWidgetIds) {
            RemoteViews remoteViews = updateWidgetListView(context, appWidgetId);
            appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
        }
        super.onUpdate(context, appWidgetManager, appWidgetIds);
    }

    private RemoteViews updateWidgetListView(Context context, int id) {
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.launcher_list_widget);

        Intent intent = new Intent(context, AppWidgetService.class);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));

        remoteViews.setRemoteAdapter(R.id.listViewWidget, intent);
        remoteViews.setEmptyView(R.id.listViewWidget, R.id.emptyView);

        Intent tempIntent = new Intent(context, PackageDetailsActivity.class);