-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Intent for launching a specific App In CommCare #2710
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
afbc774
Take app id as an intent extra and log out from current app if required
shubham1g5 84fdf72
If preset app id is present, set single app layout and seat preset re…
shubham1g5 28bc7a0
Set resource status after test installs ready as we don't verify mult…
shubham1g5 6b8f974
test for CC launches with app Id
shubham1g5 b57bc5f
Adds support lib method to launch CC with an App
shubham1g5 a412181
Update support lib readme with new method
shubham1g5 ab555bf
contentEquals -> equals
shubham1g5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -2,14 +2,10 @@ | |
|
||
import android.content.SharedPreferences; | ||
import android.content.res.Resources; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.graphics.drawable.Drawable; | ||
import android.graphics.drawable.StateListDrawable; | ||
import android.os.Build; | ||
import android.text.Editable; | ||
import android.text.InputType; | ||
import android.text.TextWatcher; | ||
import android.util.StateSet; | ||
import android.view.View; | ||
import android.view.inputmethod.EditorInfo; | ||
import android.widget.ArrayAdapter; | ||
|
@@ -21,6 +17,8 @@ | |
import android.widget.Spinner; | ||
import android.widget.TextView; | ||
|
||
import androidx.preference.PreferenceManager; | ||
|
||
import org.commcare.CommCareApplication; | ||
import org.commcare.CommCareNoficationManager; | ||
import org.commcare.android.database.app.models.UserKeyRecord; | ||
|
@@ -43,7 +41,7 @@ | |
import java.util.ArrayList; | ||
import java.util.Vector; | ||
|
||
import androidx.preference.PreferenceManager; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Handles login activity UI | ||
|
@@ -196,15 +194,15 @@ public void refreshView() { | |
|
||
// Decide whether or not to show the app selection spinner based upon # of usable apps | ||
ArrayList<ApplicationRecord> readyApps = MultipleAppsUtil.getUsableAppRecords(); | ||
|
||
if (readyApps.size() == 1) { | ||
ApplicationRecord presetAppRecord = getPresetAppRecord(readyApps); | ||
if (readyApps.size() == 1 || presetAppRecord != null) { | ||
// Set this app as the last selected app, for use in choosing what app to initialize | ||
// on first startup | ||
ApplicationRecord r = readyApps.get(0); | ||
ApplicationRecord r = presetAppRecord != null ? presetAppRecord : readyApps.get(0); | ||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); | ||
prefs.edit().putString(LoginActivity.KEY_LAST_APP, r.getUniqueId()).apply(); | ||
|
||
setSingleAppUIState(); | ||
activity.seatAppIfNeeded(r.getUniqueId()); | ||
} else { | ||
activity.populateAppSpinner(readyApps); | ||
} | ||
|
@@ -230,6 +228,23 @@ public void refreshView() { | |
} | ||
} | ||
|
||
@Nullable | ||
private ApplicationRecord getPresetAppRecord(ArrayList<ApplicationRecord> readyApps) { | ||
String presetAppId = activity.getPresetAppID(); | ||
if (presetAppId != null) { | ||
for (ApplicationRecord readyApp : readyApps) { | ||
if (readyApp.getUniqueId().contentEquals(presetAppId)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. contentEquals() again, see above comment. |
||
return readyApp; | ||
} | ||
} | ||
|
||
// if preset App id is supplied but not found show an error | ||
String appNotFoundError = activity.getString(R.string.app_with_id_not_found); | ||
setErrorMessageUI(appNotFoundError, false); | ||
} | ||
return null; | ||
} | ||
|
||
protected void refreshForNewApp() { | ||
// Remove any error content from trying to log into a different app | ||
setStyleDefault(); | ||
|
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
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
23 changes: 23 additions & 0 deletions
23
...e-support-library/src/main/java/org/commcare/commcaresupportlibrary/CommCareLauncher.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,23 @@ | ||
package org.commcare.commcaresupportlibrary; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
|
||
/** | ||
* Utility class with methods to launch CommCare | ||
*/ | ||
public class CommCareLauncher { | ||
public static final String SESSION_ENDPOINT_APP_ID = "ccodk_session_endpoint_app_id"; | ||
private static final String CC_LAUNCH_ACTION = "org.commcare.dalvik.action.CommCareSession"; | ||
|
||
/** | ||
* | ||
* @param context Android context to launch the CommCare with | ||
* @param appId Unique Id for CommCare App that CommCare should launch with | ||
*/ | ||
public static void launchCommCareForAppId(Context context, String appId) { | ||
Intent intent = new Intent(CC_LAUNCH_ACTION); | ||
intent.putExtra(SESSION_ENDPOINT_APP_ID, appId); | ||
context.startActivity(intent); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious about the use of contentEquals() here instead of just equals(). From what I understand contentEquals() just calls equals() under the hood when the passed input is a String, so functionally there should be no difference. So this may just be a consistency nit.
But in LoginActivity line 561 I see we're only calling equals(). When I search for "getUniqueId." I see 4 times that we use equals() and one that we use contentEquals(). Okay to ignore this if you don't think it's worth changing.