mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-23 06:31:17 +00:00
Made unified inbox widget a pro feature
This commit is contained in:
parent
9f1f446210
commit
c55cafa5d0
3 changed files with 33 additions and 14 deletions
|
@ -67,6 +67,7 @@ All pro features are convenience or advanced features.
|
||||||
* Keyword management
|
* Keyword management
|
||||||
* Biometric authentication ([instructions](https://github.com/M66B/FairEmail/blob/master/FAQ.md#user-content-faq113))
|
* 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))
|
* 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
|
* Export settings
|
||||||
|
|
||||||
## Simple
|
## Simple
|
||||||
|
|
|
@ -26,6 +26,7 @@ import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
public class WidgetUnified extends AppWidgetProvider {
|
public class WidgetUnified extends AppWidgetProvider {
|
||||||
|
@ -36,24 +37,29 @@ public class WidgetUnified extends AppWidgetProvider {
|
||||||
view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
PendingIntent pi = PendingIntent.getActivity(context, ActivityView.REQUEST_UNIFIED, view, PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent pi = PendingIntent.getActivity(context, ActivityView.REQUEST_UNIFIED, view, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
boolean pro = Helper.isPro(context);
|
||||||
for (int id : appWidgetIds) {
|
for (int id : appWidgetIds) {
|
||||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_unified);
|
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);
|
Intent service = new Intent(context, WidgetUnifiedService.class);
|
||||||
service.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
|
service.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
|
||||||
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.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(id, views);
|
appWidgetManager.updateAppWidget(id, views);
|
||||||
}
|
}
|
||||||
|
@ -61,8 +67,10 @@ public class WidgetUnified extends AppWidgetProvider {
|
||||||
|
|
||||||
static void update(Context context) {
|
static void update(Context context) {
|
||||||
Log.i("Widget unified update");
|
Log.i("Widget unified update");
|
||||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
if (Helper.isPro(context)) {
|
||||||
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetUnified.class));
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||||
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.lv);
|
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetUnified.class));
|
||||||
|
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.lv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,16 @@
|
||||||
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…
Reference in a new issue