Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom icon preference for sustainers #1645

Merged
merged 7 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion Simplenote/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</activity>

<activity
android:name="com.automattic.simplenote.NotesActivity"
android:name=".NotesActivity"
android:configChanges="screenSize|smallestScreenSize|orientation|screenLayout"
android:label="@string/app_launcher_name"
android:resizeableActivity="true"
Expand Down Expand Up @@ -93,6 +93,40 @@

</activity>

<activity-alias android:label="@string/app_name"
android:enabled="false"
android:exported="true"
android:icon="@mipmap/ic_launcher_green"
android:name=".NotesActivitySustainerAlias"
android:targetActivity=".NotesActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="com.google.android.gm.action.AUTO_SEND" />
<action android:name="com.google.android.voicesearch.action.AUTO_SEND" />
<action android:name="com.automattic.simplenote.NEW_NOTE" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.google.android.voicesearch.SELF_NOTE" />
<data android:mimeType="text/*" />
</intent-filter>

<intent-filter
android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="app.simplenote.com"
android:pathPattern="/account/.*/reset?redirect=simplenote://launch"
android:scheme="https">
</data>
</intent-filter>
</activity-alias>

<activity
android:name="com.automattic.simplenote.NoteEditorActivity"
android:configChanges="screenSize|smallestScreenSize|orientation|screenLayout"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.automattic.simplenote.databinding.ActivityCollaboratorsBinding
import com.automattic.simplenote.utils.CollaboratorsAdapter
import com.automattic.simplenote.utils.CollaboratorsAdapter.*
import com.automattic.simplenote.utils.CollaboratorsAdapter.CollaboratorDataItem.*
import com.automattic.simplenote.utils.IntentUtils
import com.automattic.simplenote.utils.toast
import com.automattic.simplenote.viewmodels.CollaboratorsViewModel
import com.automattic.simplenote.viewmodels.CollaboratorsViewModel.Event
Expand Down Expand Up @@ -157,7 +158,7 @@ class CollaboratorsActivity : ThemedAppCompatActivity() {
}

private fun navigateToNotesList() {
val intent = Intent(applicationContext, NotesActivity::class.java)
val intent = IntentUtils.maybeAliasedIntent(applicationContext)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
startActivity(intent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import androidx.appcompat.app.AppCompatActivity;

import com.automattic.simplenote.utils.AuthUtils;
import com.automattic.simplenote.utils.IntentUtils;
import com.automattic.simplenote.utils.WidgetUtils;

import net.openid.appauth.RedirectUriReceiverActivity;

Expand All @@ -26,7 +28,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
intent.setData(uri);
startActivity(intent);
} else if (uri.getHost().equals(LOGIN_SCHEME)) {
Intent intent = new Intent(this, NotesActivity.class);
Intent intent = IntentUtils.maybeAliasedIntent(getApplicationContext());
Simplenote app = (Simplenote) getApplication();
String email = AuthUtils.extractEmailFromMagicLink(uri);
if (app.isLoggedIn() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import com.automattic.simplenote.utils.AppLog;
import com.automattic.simplenote.utils.AppLog.Type;
import com.automattic.simplenote.utils.DisplayUtils;
import com.automattic.simplenote.utils.IntentUtils;
import com.automattic.simplenote.utils.NetworkUtils;
import com.automattic.simplenote.utils.WidgetUtils;
import com.automattic.simplenote.widgets.NoteEditorViewPager;
import com.automattic.simplenote.widgets.RobotoMediumTextView;
import com.google.android.material.tabs.TabLayout;
Expand Down Expand Up @@ -241,7 +243,7 @@ private void handleBackPressed() {
// The editor can be the task root when it comes from an action on a widget
// In these cases, instead of going to the home screen, the notes activity
// is started
Intent intent = new Intent(getApplicationContext(), NotesActivity.class);
Intent intent = IntentUtils.maybeAliasedIntent(getApplicationContext());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.automattic.simplenote.analytics.AnalyticsTracker;
import com.automattic.simplenote.models.Note;
import com.automattic.simplenote.utils.IntentUtils;
import com.automattic.simplenote.utils.PrefUtils;
import com.simperium.Simperium;
import com.simperium.client.Bucket;
Expand Down Expand Up @@ -112,14 +113,14 @@ private void updateWidget(Context context, AppWidgetManager appWidgetManager, in

if (user.getStatus().equals(User.Status.NOT_AUTHORIZED)) {
// Create intent to navigate to notes activity which redirects to login on widget click
Intent intent = new Intent(context, NotesActivity.class);
Intent intent = IntentUtils.maybeAliasedIntent(context);
intent.putExtra(KEY_LIST_WIDGET_CLICK, NOTE_LIST_WIDGET_SIGN_IN_TAPPED);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_IMMUTABLE);
views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent);

// Reset intent to navigate to note editor on note list add button click to navigate to notes activity, which redirects to login/signup
Intent intentButton = new Intent(context, NotesActivity.class);
Intent intentButton = IntentUtils.maybeAliasedIntent(context);
views.setOnClickPendingIntent(R.id.widget_button, PendingIntent.getActivity(context, appWidgetId, intentButton, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE));

views.setTextViewText(R.id.widget_text, context.getResources().getString(R.string.log_in_use_widget));
Expand All @@ -136,7 +137,7 @@ private void updateWidget(Context context, AppWidgetManager appWidgetManager, in

if (cursor.getCount() > 0) {
// Create intent to navigate to notes activity on widget click while loading
Intent intentLoading = new Intent(context, NotesActivity.class);
Intent intentLoading = IntentUtils.maybeAliasedIntent(context);
intentLoading.putExtra(KEY_LIST_WIDGET_CLICK, NOTE_LIST_WIDGET_TAPPED);
intentLoading.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntentLoading = PendingIntent.getActivity(context, appWidgetId, intentLoading, PendingIntent.FLAG_IMMUTABLE);
Expand All @@ -159,7 +160,7 @@ private void updateWidget(Context context, AppWidgetManager appWidgetManager, in
views.setPendingIntentTemplate(R.id.widget_list, pendingIntentItem);

// Create intent to navigate to note editor on note list add button click
Intent intentButton = new Intent(context, NotesActivity.class);
Intent intentButton = IntentUtils.maybeAliasedIntent(context);
intentButton.putExtra(KEY_LIST_WIDGET_CLICK, NOTE_LIST_WIDGET_BUTTON_TAPPED);
intentButton.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntentButton = PendingIntent.getActivity(context, appWidgetId, intentButton, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
Expand All @@ -172,14 +173,14 @@ private void updateWidget(Context context, AppWidgetManager appWidgetManager, in
views.setViewVisibility(R.id.widget_list, View.VISIBLE);
} else {
// Create intent to navigate to notes activity on widget click
Intent intent = new Intent(context, NotesActivity.class);
Intent intent = IntentUtils.maybeAliasedIntent(context);
intent.putExtra(KEY_LIST_WIDGET_CLICK, NOTE_LIST_WIDGET_TAPPED);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_IMMUTABLE);
views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent);

// Create intent to navigate to note editor on note list add button click
Intent intentButton = new Intent(context, NotesActivity.class);
Intent intentButton = IntentUtils.maybeAliasedIntent(context);
intentButton.putExtra(KEY_LIST_WIDGET_CLICK, NOTE_LIST_WIDGET_BUTTON_TAPPED);
intentButton.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntentButton = PendingIntent.getActivity(context, appWidgetId, intentButton, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.automattic.simplenote.analytics.AnalyticsTracker;
import com.automattic.simplenote.models.Note;
import com.automattic.simplenote.utils.IntentUtils;
import com.automattic.simplenote.utils.PrefUtils;
import com.simperium.Simperium;
import com.simperium.client.Bucket;
Expand Down Expand Up @@ -112,14 +113,14 @@ private void updateWidget(Context context, AppWidgetManager appWidgetManager, in

if (user.getStatus().equals(User.Status.NOT_AUTHORIZED)) {
// Create intent to navigate to notes activity which redirects to login on widget click
Intent intent = new Intent(context, NotesActivity.class);
Intent intent = IntentUtils.maybeAliasedIntent(context);
intent.putExtra(KEY_LIST_WIDGET_CLICK, NOTE_LIST_WIDGET_SIGN_IN_TAPPED);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_IMMUTABLE);
views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent);

// Reset intent to navigate to note editor on note list add button click to navigate to notes activity, which redirects to login/signup
Intent intentButton = new Intent(context, NotesActivity.class);
Intent intentButton = IntentUtils.maybeAliasedIntent(context);
views.setOnClickPendingIntent(R.id.widget_button, PendingIntent.getActivity(context, appWidgetId, intentButton, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE));

views.setTextViewText(R.id.widget_text, context.getResources().getString(R.string.log_in_use_widget));
Expand All @@ -136,7 +137,7 @@ private void updateWidget(Context context, AppWidgetManager appWidgetManager, in

if (cursor.getCount() > 0) {
// Create intent to navigate to notes activity on widget click while loading
Intent intentLoading = new Intent(context, NotesActivity.class);
Intent intentLoading = IntentUtils.maybeAliasedIntent(context);
intentLoading.putExtra(KEY_LIST_WIDGET_CLICK, NOTE_LIST_WIDGET_TAPPED);
intentLoading.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntentLoading = PendingIntent.getActivity(context, appWidgetId, intentLoading, PendingIntent.FLAG_IMMUTABLE);
Expand All @@ -159,7 +160,7 @@ private void updateWidget(Context context, AppWidgetManager appWidgetManager, in
views.setPendingIntentTemplate(R.id.widget_list, pendingIntentItem);

// Create intent to navigate to note editor on note list add button click
Intent intentButton = new Intent(context, NotesActivity.class);
Intent intentButton = IntentUtils.maybeAliasedIntent(context);
intentButton.putExtra(KEY_LIST_WIDGET_CLICK, NOTE_LIST_WIDGET_BUTTON_TAPPED);
intentButton.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntentButton = PendingIntent.getActivity(context, appWidgetId, intentButton, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
Expand All @@ -172,14 +173,14 @@ private void updateWidget(Context context, AppWidgetManager appWidgetManager, in
views.setViewVisibility(R.id.widget_list, View.VISIBLE);
} else {
// Create intent to navigate to notes activity on widget click
Intent intent = new Intent(context, NotesActivity.class);
Intent intent = IntentUtils.maybeAliasedIntent(context);
intent.putExtra(KEY_LIST_WIDGET_CLICK, NOTE_LIST_WIDGET_TAPPED);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_IMMUTABLE);
views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent);

// Create intent to navigate to note editor on note list add button click
Intent intentButton = new Intent(context, NotesActivity.class);
Intent intentButton = IntentUtils.maybeAliasedIntent(context);
intentButton.putExtra(KEY_LIST_WIDGET_CLICK, NOTE_LIST_WIDGET_BUTTON_TAPPED);
intentButton.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntentButton = PendingIntent.getActivity(context, appWidgetId, intentButton, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.automattic.simplenote.analytics.AnalyticsTracker;
import com.automattic.simplenote.models.Note;
import com.automattic.simplenote.utils.ChecklistUtils;
import com.automattic.simplenote.utils.IntentUtils;
import com.automattic.simplenote.utils.PrefUtils;
import com.simperium.Simperium;
import com.simperium.client.Bucket;
Expand Down Expand Up @@ -108,7 +109,7 @@ private void updateWidget(Context context, AppWidgetManager appWidgetManager, in

if (user.getStatus().equals(User.Status.NOT_AUTHORIZED)) {
// Create intent to navigate to notes activity which redirects to login on widget click
Intent intent = new Intent(context, NotesActivity.class);
Intent intent = IntentUtils.maybeAliasedIntent(context);
intent.putExtra(KEY_WIDGET_CLICK, NOTE_WIDGET_SIGN_IN_TAPPED);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_IMMUTABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.automattic.simplenote.analytics.AnalyticsTracker;
import com.automattic.simplenote.models.Note;
import com.automattic.simplenote.utils.ChecklistUtils;
import com.automattic.simplenote.utils.IntentUtils;
import com.automattic.simplenote.utils.PrefUtils;
import com.simperium.Simperium;
import com.simperium.client.Bucket;
Expand Down Expand Up @@ -108,7 +109,7 @@ private void updateWidget(Context context, AppWidgetManager appWidgetManager, in

if (user.getStatus().equals(User.Status.NOT_AUTHORIZED)) {
// Create intent to navigate to notes activity which redirects to login on widget click
Intent intent = new Intent(context, NotesActivity.class);
Intent intent = IntentUtils.maybeAliasedIntent(context);
intent.putExtra(KEY_WIDGET_CLICK, NOTE_WIDGET_SIGN_IN_TAPPED);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_IMMUTABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@

import android.app.Activity;
import android.app.Fragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.widget.Switch;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
Expand Down Expand Up @@ -237,6 +241,23 @@ public boolean onPreferenceClick(Preference preference) {
}
});

final SwitchPreferenceCompat sustainerIconPreference = findPreference("pref_key_sustainer_icon");
try {
if (
mPreferencesBucket.get(PREFERENCES_OBJECT_KEY).getCurrentSubscriptionPlatform() != null &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
) {
sustainerIconPreference.setVisible(true);
sustainerIconPreference.setOnPreferenceChangeListener((preference, newValue) -> {
toggleSustainerAppIcon((boolean) newValue);

return true;
});
}
} catch (BucketObjectMissingException e) {
sustainerIconPreference.setVisible(false);
}

final Preference membershipPreference = findPreference("pref_key_membership");
membershipPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
Expand Down Expand Up @@ -347,6 +368,30 @@ public boolean onPreferenceClick(Preference preference) {
});
}

private void toggleSustainerAppIcon(boolean enabled) {
Context context = getContext();
if (context == null) {
return;
}

PackageManager packageManager = context.getPackageManager();
String componentPackage = BuildConfig.DEBUG ? "com.automattic.simplenote.debug" : "com.automattic.simplenote";

ComponentName mainComponent = new ComponentName(componentPackage, "com.automattic.simplenote.NotesActivity");
packageManager.setComponentEnabledSetting(
mainComponent,
enabled ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED : PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP
);

ComponentName sustainerComponent = new ComponentName(componentPackage, "com.automattic.simplenote.NotesActivitySustainerAlias");
packageManager.setComponentEnabledSetting(
sustainerComponent,
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP
);
}

private void showProgressDialogDeleteAccount() {
FragmentActivity activity = getActivity();
if (activity == null) {
Expand Down
Loading
Loading