Made unified inbox widget a pro feature

pull/160/head
M66B 5 years ago
parent 9f1f446210
commit c55cafa5d0

@ -67,6 +67,7 @@ All pro features are convenience or advanced features.
* Keyword management
* Biometric authentication ([instructions](https://github.com/M66B/FairEmail/blob/master/FAQ.md#user-content-faq113))
* Encryption/decryption ([OpenPGP](https://www.openpgp.org/)) ([instructions](https://github.com/M66B/FairEmail/blob/master/FAQ.md#user-content-faq12))
* Unified inbox widget
* Export settings
## Simple

@ -26,6 +26,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.RemoteViews;
public class WidgetUnified extends AppWidgetProvider {
@ -36,24 +37,29 @@ public class WidgetUnified extends AppWidgetProvider {
view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi = PendingIntent.getActivity(context, ActivityView.REQUEST_UNIFIED, view, PendingIntent.FLAG_UPDATE_CURRENT);
boolean pro = Helper.isPro(context);
for (int id : appWidgetIds) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_unified);
views.setOnClickPendingIntent(R.id.title, pi);
views.setViewVisibility(R.id.pro, pro ? View.GONE : View.VISIBLE);
if (pro) {
views.setOnClickPendingIntent(R.id.title, pi);
Intent service = new Intent(context, WidgetUnifiedService.class);
service.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
service.setData(Uri.parse(service.toUri(Intent.URI_INTENT_SCHEME)));
Intent service = new Intent(context, WidgetUnifiedService.class);
service.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
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);
thread.setAction("widget");
thread.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent piItem = PendingIntent.getActivity(
context, ActivityView.REQUEST_WIDGET, thread, PendingIntent.FLAG_UPDATE_CURRENT);
Intent thread = new Intent(context, ActivityView.class);
thread.setAction("widget");
thread.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent piItem = PendingIntent.getActivity(
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(id, views);
}
@ -61,8 +67,10 @@ public class WidgetUnified extends AppWidgetProvider {
static void update(Context context) {
Log.i("Widget unified update");
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetUnified.class));
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.lv);
if (Helper.isPro(context)) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetUnified.class));
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.lv);
}
}
}

@ -24,6 +24,16 @@
android:layout_height="1dp"
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
android:id="@+id/lv"
android:layout_width="match_parent"

Loading…
Cancel
Save