|
|
@@ -3,7 +3,6 @@ package kr.co.zumo.app.lifeplus.view.screen.widget;
|
|
|
import android.app.PendingIntent;
|
|
|
import android.appwidget.AppWidgetManager;
|
|
|
import android.appwidget.AppWidgetProvider;
|
|
|
-import android.content.ComponentName;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.util.Log;
|
|
|
@@ -36,34 +35,6 @@ public class LifeplusWidget extends AppWidgetProvider {
|
|
|
|
|
|
private static Disposable disposable;
|
|
|
|
|
|
-
|
|
|
- static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
|
|
|
- Log.e("APP# LifeplusWidget | updateAppWidget", "|" + "updateAppwidget==>");
|
|
|
-
|
|
|
- if (null != disposable) {
|
|
|
- disposable.dispose();
|
|
|
- }
|
|
|
-
|
|
|
- INetworkConfig networkConfig;
|
|
|
- if (AppUtil.isDebug()) {
|
|
|
- networkConfig = new NetworkConfigDevelop();
|
|
|
- }
|
|
|
- else {
|
|
|
- networkConfig = new NetworkConfigProduct();
|
|
|
- }
|
|
|
-
|
|
|
- String API_URL = networkConfig.getHostUrl() + ":" + networkConfig.getHostPort() + "/";
|
|
|
- disposable = new LifeplusAPIService(API_URL).getWidgetData(new RequestBean())
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribe(resultBean -> {
|
|
|
- disposable = null;
|
|
|
- render(context, appWidgetManager, appWidgetId, resultBean.getData());
|
|
|
- }, e -> {
|
|
|
- disposable = null;
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
private static void render(Context context, AppWidgetManager appWidgetManager, int appWidgetId, LifeplusContentsBean contentsBean) {
|
|
|
// Construct the RemoteViews object
|
|
|
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.lifeplus_widget);
|
|
|
@@ -91,7 +62,11 @@ public class LifeplusWidget extends AppWidgetProvider {
|
|
|
|
|
|
Intent refreshIntent = new Intent(context, LifeplusWidget.class);
|
|
|
refreshIntent.setAction(REFRESH_CLICK);
|
|
|
- views.setOnClickPendingIntent(R.id.image_view_refresh, PendingIntent.getBroadcast(context, 0, refreshIntent, 0));
|
|
|
+ views.setOnClickPendingIntent(R.id.image_view_refresh, PendingIntent.getBroadcast(context, 0, refreshIntent, appWidgetId));
|
|
|
+
|
|
|
+ appWidgetManager.updateAppWidget(appWidgetId, views);
|
|
|
+
|
|
|
+ Log.w("APP# LifeplusWidget | render", "|" + "-----------------------------------");
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -102,24 +77,47 @@ public class LifeplusWidget extends AppWidgetProvider {
|
|
|
for (int appWidgetId : appWidgetIds) {
|
|
|
updateAppWidget(context, appWidgetManager, appWidgetId);
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
|
|
|
+ Log.e("APP# LifeplusWidget | updateAppWidget", "|" + "updateAppwidget==>");
|
|
|
+
|
|
|
+ if (null != disposable) {
|
|
|
+ disposable.dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ INetworkConfig networkConfig;
|
|
|
+ if (AppUtil.isDebug()) {
|
|
|
+ networkConfig = new NetworkConfigDevelop();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ networkConfig = new NetworkConfigProduct();
|
|
|
+ }
|
|
|
|
|
|
+ String API_URL = networkConfig.getHostUrl() + ":" + networkConfig.getHostPort() + "/";
|
|
|
+ disposable = new LifeplusAPIService(API_URL).getWidgetData(new RequestBean())
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(resultBean -> {
|
|
|
+ disposable = null;
|
|
|
+ render(context, appWidgetManager, appWidgetId, resultBean.getData());
|
|
|
+ }, e -> {
|
|
|
+ disposable = null;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
|
|
- ComponentName widget = new ComponentName(context, LifeplusWidget.class);
|
|
|
- RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.lifeplus_widget);
|
|
|
|
|
|
super.onReceive(context, intent);
|
|
|
|
|
|
+ int appWidgetId = intent.getFlags();
|
|
|
switch (intent.getAction()) {
|
|
|
case REFRESH_CLICK:
|
|
|
Log.e("APP# LifeplusWidget | onReceive", "|" + "refresh click after ===>");
|
|
|
- views.setTextViewText(R.id.text_view_title, "refresh 클릭함" + (int) (Math.random() * 10));
|
|
|
- views.setImageViewResource(R.id.image_view_background, R.drawable.banner_bg_1);
|
|
|
- appWidgetManager.updateAppWidget(widget, views);
|
|
|
+ updateAppWidget(context, appWidgetManager, appWidgetId);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|