-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47626 from software-mansion-labs/conversation-sty…
…le-notifications Add conversation styling and shortcuts for Android 🤖
- Loading branch information
Showing
11 changed files
with
185 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...oid/app/src/main/java/com/expensify/chat/shortcutManagerModule/ShortcutManagerModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.expensify.chat.shortcutManagerModule; | ||
|
||
import static androidx.core.app.NotificationCompat.CATEGORY_MESSAGE; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
import android.net.Uri; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.core.app.Person; | ||
import androidx.core.content.pm.ShortcutInfoCompat; | ||
import androidx.core.content.pm.ShortcutManagerCompat; | ||
import androidx.core.graphics.drawable.IconCompat; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
|
||
import java.util.Collections; | ||
|
||
import com.expensify.chat.customairshipextender.CustomNotificationProvider; | ||
|
||
public class ShortcutManagerModule extends ReactContextBaseJavaModule { | ||
private ReactApplicationContext context; | ||
|
||
public ShortcutManagerModule(ReactApplicationContext context) { | ||
super(context); | ||
this.context = context; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String getName() { | ||
return "ShortcutManager"; | ||
} | ||
|
||
@ReactMethod | ||
public void removeAllDynamicShortcuts() { | ||
ShortcutManagerUtils.removeAllDynamicShortcuts(context); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...id/app/src/main/java/com/expensify/chat/shortcutManagerModule/ShortcutManagerPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.expensify.chat.shortcutManagerModule; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class ShortcutManagerPackage implements ReactPackage { | ||
|
||
@NonNull | ||
@Override | ||
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) { | ||
List<NativeModule> modules = new ArrayList<>(); | ||
modules.add(new ShortcutManagerModule(reactContext)); | ||
return modules; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
android/app/src/main/java/com/expensify/chat/shortcutManagerModule/ShortcutManagerUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.expensify.chat.shortcutManagerModule; | ||
|
||
import static androidx.core.app.NotificationCompat.CATEGORY_MESSAGE; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
import android.net.Uri; | ||
|
||
import androidx.core.app.Person; | ||
import androidx.core.content.pm.ShortcutInfoCompat; | ||
import androidx.core.content.pm.ShortcutManagerCompat; | ||
import androidx.core.graphics.drawable.IconCompat; | ||
|
||
import java.util.Collections; | ||
|
||
public class ShortcutManagerUtils { | ||
public static void removeAllDynamicShortcuts(Context context) { | ||
ShortcutManagerCompat.removeAllDynamicShortcuts(context); | ||
} | ||
|
||
public static void addDynamicShortcut(Context context, long reportID, String name, String accountID, Bitmap personIcon, Person person) { | ||
Intent intent = new Intent(Intent.ACTION_VIEW, | ||
Uri.parse("new-expensify://r/" + reportID)); | ||
|
||
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(context, accountID) | ||
.setShortLabel(name) | ||
.setLongLabel(name) | ||
.setCategories(Collections.singleton(CATEGORY_MESSAGE)) | ||
.setIntent(intent) | ||
.setLongLived(true) | ||
.setPerson(person) | ||
.setIcon(IconCompat.createWithBitmap(personIcon)) | ||
.build(); | ||
ShortcutManagerCompat.pushDynamicShortcut(context, shortcutInfo); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// RCTShortcutManagerModule.h | ||
#import <React/RCTBridgeModule.h> | ||
@interface RCTShortcutManagerModule : NSObject <RCTBridgeModule> | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// RCTCalendarModule.m | ||
// iOS doesn't have dynamic shortcuts like Android, so this module contains noop functions to prevent iOS from crashing | ||
#import "RCTShortcutManagerModule.h" | ||
|
||
@implementation RCTShortcutManagerModule | ||
|
||
RCT_EXPORT_METHOD(removeAllDynamicShortcuts){} | ||
|
||
RCT_EXPORT_MODULE(ShortcutManager); | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {NativeModules} from 'react-native'; | ||
|
||
type ShortcutManagerModule = { | ||
removeAllDynamicShortcuts: () => void; | ||
}; | ||
|
||
const {ShortcutManager} = NativeModules; | ||
|
||
export type {ShortcutManagerModule}; | ||
|
||
export default ShortcutManager || | ||
({ | ||
removeAllDynamicShortcuts: () => {}, | ||
} as ShortcutManagerModule); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters