-
Notifications
You must be signed in to change notification settings - Fork 70
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 #269 from wealthfront/non-activity-context
Support non-activity context in DialogComponent
- Loading branch information
Showing
3 changed files
with
27 additions
and
15 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
21 changes: 21 additions & 0 deletions
21
magellan-library/src/main/java/com/wealthfront/magellan/ContextUtil.kt
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,21 @@ | ||
package com.wealthfront.magellan | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.content.ContextWrapper | ||
|
||
public object ContextUtil { | ||
public fun findActivity(context: Context): Activity { | ||
return when (context) { | ||
is Activity -> { | ||
context | ||
} | ||
is ContextWrapper -> { | ||
findActivity(context.baseContext) | ||
} | ||
else -> { | ||
throw IllegalStateException("Context must be Activity or wrap Activity") | ||
} | ||
} | ||
} | ||
} |
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