-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Android): Add progress bar to notification (#41)
- Loading branch information
Showing
5 changed files
with
155 additions
and
92 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
104 changes: 104 additions & 0 deletions
104
android/src/main/java/com/asterinet/react/bgactions/BackgroundTaskOptions.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,104 @@ | ||
package com.asterinet.react.bgactions; | ||
|
||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
|
||
import androidx.annotation.ColorInt; | ||
import androidx.annotation.IdRes; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.facebook.react.bridge.Arguments; | ||
import com.facebook.react.bridge.ReactContext; | ||
import com.facebook.react.bridge.ReadableMap; | ||
|
||
public final class BackgroundTaskOptions { | ||
private final Bundle extras; | ||
|
||
public BackgroundTaskOptions(@NonNull final Bundle extras) { | ||
this.extras = extras; | ||
} | ||
|
||
public BackgroundTaskOptions(@NonNull final ReactContext reactContext, @NonNull final ReadableMap options) { | ||
// Create extras | ||
extras = Arguments.toBundle(options); | ||
if (extras == null) | ||
throw new IllegalArgumentException("Could not convert arguments to bundle"); | ||
// Get taskTitle | ||
try { | ||
if (options.getString("taskTitle") == null) | ||
throw new IllegalArgumentException(); | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException("Task title cannot be null"); | ||
} | ||
// Get taskDesc | ||
try { | ||
if (options.getString("taskDesc") == null) | ||
throw new IllegalArgumentException(); | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException("Task description cannot be null"); | ||
} | ||
// Get iconInt | ||
try { | ||
final ReadableMap iconMap = options.getMap("taskIcon"); | ||
if (iconMap == null) | ||
throw new IllegalArgumentException(); | ||
final String iconName = iconMap.getString("name"); | ||
final String iconType = iconMap.getString("type"); | ||
String iconPackage; | ||
try { | ||
iconPackage = iconMap.getString("package"); | ||
if (iconPackage == null) | ||
throw new IllegalArgumentException(); | ||
} catch (Exception e) { | ||
// Get the current package as default | ||
iconPackage = reactContext.getPackageName(); | ||
} | ||
final int iconInt = reactContext.getResources().getIdentifier(iconName, iconType, iconPackage); | ||
extras.putInt("iconInt", iconInt); | ||
if (iconInt == 0) | ||
throw new IllegalArgumentException(); | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException("Task icon not found"); | ||
} | ||
// Get color | ||
try { | ||
final String color = options.getString("color"); | ||
extras.putInt("color", Color.parseColor(color)); | ||
} catch (Exception e) { | ||
extras.putInt("color", Color.parseColor("#ffffff")); | ||
} | ||
} | ||
|
||
public Bundle getExtras() { | ||
return extras; | ||
} | ||
|
||
public String getTaskTitle() { | ||
return extras.getString("taskTitle", ""); | ||
} | ||
|
||
public String getTaskDesc() { | ||
return extras.getString("taskDesc", ""); | ||
} | ||
|
||
@IdRes | ||
public int getIconInt() { | ||
return extras.getInt("iconInt"); | ||
} | ||
|
||
@ColorInt | ||
public int getColor() { | ||
return extras.getInt("color"); | ||
} | ||
|
||
@Nullable | ||
public String getLinkingURI() { | ||
return extras.getString("linkingURI"); | ||
} | ||
|
||
@Nullable | ||
public Bundle getProgressBar() { | ||
return extras.getBundle("progressBar"); | ||
} | ||
} |
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