Show example

pull/178/head
M66B 6 years ago
parent 1e654d7765
commit b1d516f61b

@ -28,7 +28,6 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.view.View;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -38,7 +37,6 @@ public class WidgetUnified extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean pro = ActivityBilling.isPro(context);
for (int appWidgetId : appWidgetIds) { for (int appWidgetId : appWidgetIds) {
long account = prefs.getLong("widget." + appWidgetId + ".account", -1L); long account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
long folder = prefs.getLong("widget." + appWidgetId + ".folder", -1L); long folder = prefs.getLong("widget." + appWidgetId + ".folder", -1L);
@ -58,32 +56,28 @@ public class WidgetUnified extends AppWidgetProvider {
if (!semi) if (!semi)
views.setInt(R.id.widget, "setBackgroundColor", Color.TRANSPARENT); views.setInt(R.id.widget, "setBackgroundColor", Color.TRANSPARENT);
views.setViewVisibility(R.id.pro, pro ? View.GONE : View.VISIBLE); String name = prefs.getString("widget." + appWidgetId + ".name", null);
if (pro) { if (name == null)
String name = prefs.getString("widget." + appWidgetId + ".name", null); views.setTextViewText(R.id.title, context.getString(R.string.title_folder_unified));
if (name == null) else
views.setTextViewText(R.id.title, context.getString(R.string.title_folder_unified)); views.setTextViewText(R.id.title, name);
else
views.setTextViewText(R.id.title, name);
views.setOnClickPendingIntent(R.id.title, pi); views.setOnClickPendingIntent(R.id.title, pi);
Intent service = new Intent(context, WidgetUnifiedService.class); Intent service = new Intent(context, WidgetUnifiedService.class);
service.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); service.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
service.setData(Uri.parse(service.toUri(Intent.URI_INTENT_SCHEME))); service.setData(Uri.parse(service.toUri(Intent.URI_INTENT_SCHEME)));
views.setRemoteAdapter(R.id.lv, service); views.setRemoteAdapter(R.id.lv, service);
Intent thread = new Intent(context, ActivityView.class); Intent thread = new Intent(context, ActivityView.class);
thread.setAction("widget"); thread.setAction("widget");
thread.putExtra("filter_archive", !EntityFolder.ARCHIVE.equals(type)); thread.putExtra("filter_archive", !EntityFolder.ARCHIVE.equals(type));
thread.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); thread.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent piItem = PendingIntent.getActivity( PendingIntent piItem = PendingIntent.getActivity(
context, ActivityView.REQUEST_WIDGET, thread, PendingIntent.FLAG_UPDATE_CURRENT); context, ActivityView.REQUEST_WIDGET, thread, PendingIntent.FLAG_UPDATE_CURRENT);
views.setPendingIntentTemplate(R.id.lv, piItem); views.setPendingIntentTemplate(R.id.lv, piItem);
} else
views.setTextViewText(R.id.pro, context.getText(R.string.title_pro_feature));
appWidgetManager.updateAppWidget(appWidgetId, views); appWidgetManager.updateAppWidget(appWidgetId, views);
} }

@ -51,6 +51,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
private boolean flagged; private boolean flagged;
private int colorWidgetForeground; private int colorWidgetForeground;
private int colorWidgetRead; private int colorWidgetRead;
private boolean pro;
private List<TupleMessageWidget> messages = new ArrayList<>(); private List<TupleMessageWidget> messages = new ArrayList<>();
WidgetUnifiedRemoteViewsFactory(final Context context, Intent intent) { WidgetUnifiedRemoteViewsFactory(final Context context, Intent intent) {
@ -80,6 +81,8 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
colorWidgetForeground = ContextCompat.getColor(context, R.color.colorWidgetForeground); colorWidgetForeground = ContextCompat.getColor(context, R.color.colorWidgetForeground);
colorWidgetRead = ContextCompat.getColor(context, R.color.colorWidgetRead); colorWidgetRead = ContextCompat.getColor(context, R.color.colorWidgetRead);
pro = ActivityBilling.isPro(context);
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
try { try {
db.beginTransaction(); db.beginTransaction();
@ -127,7 +130,9 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
SpannableString ssFrom = new SpannableString(MessageHelper.formatAddressesShort(message.from)); SpannableString ssFrom = new SpannableString(MessageHelper.formatAddressesShort(message.from));
SpannableString ssTime = new SpannableString(Helper.getRelativeTimeSpanString(context, message.received)); SpannableString ssTime = new SpannableString(Helper.getRelativeTimeSpanString(context, message.received));
SpannableString ssSubject = new SpannableString(TextUtils.isEmpty(message.subject) ? "" : message.subject); SpannableString ssSubject = new SpannableString(pro
? TextUtils.isEmpty(message.subject) ? "" : message.subject
: context.getString(R.string.title_pro_feature));
SpannableString ssAccount = new SpannableString(TextUtils.isEmpty(message.accountName) ? "" : message.accountName); SpannableString ssAccount = new SpannableString(TextUtils.isEmpty(message.accountName) ? "" : message.accountName);
if (message.ui_seen) { if (message.ui_seen) {

@ -25,16 +25,6 @@
android:layout_height="1dp" android:layout_height="1dp"
android:background="@color/colorWidgetForeground" /> android:background="@color/colorWidgetForeground" />
<TextView
android:id="@+id/pro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="12dp"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@color/colorWidgetForeground"
android:visibility="gone" />
<ListView <ListView
android:id="@+id/lv" android:id="@+id/lv"
android:layout_width="match_parent" android:layout_width="match_parent"

Loading…
Cancel
Save