-
-
Notifications
You must be signed in to change notification settings - Fork 28
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 #2755 from dimagi/dv/nav_fixes
Navigation fixes for Connect workflows
- Loading branch information
Showing
20 changed files
with
308 additions
and
127 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
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,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<androidx.fragment.app.FragmentContainerView | ||
android:id="@+id/connect_job_info_container" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintBottom_toBottomOf="parent"/> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
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
140 changes: 140 additions & 0 deletions
140
app/src/org/commcare/activities/connect/ConnectJobInfoActivity.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,140 @@ | ||
package org.commcare.activities.connect; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
|
||
import androidx.activity.result.ActivityResultLauncher; | ||
import androidx.activity.result.contract.ActivityResultContracts; | ||
import androidx.appcompat.app.ActionBar; | ||
import androidx.fragment.app.Fragment; | ||
import androidx.navigation.NavController; | ||
import androidx.navigation.fragment.NavHostFragment; | ||
|
||
import org.commcare.activities.CommCareActivity; | ||
import org.commcare.activities.CommCareVerificationActivity; | ||
import org.commcare.android.database.connect.models.ConnectJobRecord; | ||
import org.commcare.dalvik.R; | ||
import org.commcare.fragments.connect.ConnectDeliveryProgressFragment; | ||
import org.commcare.fragments.connect.ConnectDownloadingFragment; | ||
import org.commcare.fragments.connect.ConnectJobIntroFragment; | ||
import org.commcare.fragments.connect.ConnectLearningProgressFragment; | ||
import org.commcare.tasks.ResourceEngineListener; | ||
import org.commcare.views.dialogs.CustomProgressDialog; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class ConnectJobInfoActivity extends CommCareActivity<ResourceEngineListener> { | ||
private boolean backButtonEnabled = true; | ||
private boolean waitDialogEnabled = true; | ||
|
||
ActivityResultLauncher<Intent> verificationLauncher = registerForActivityResult( | ||
new ActivityResultContracts.StartActivityForResult(), | ||
result -> { | ||
if (result.getResultCode() == Activity.RESULT_OK) { | ||
ConnectDownloadingFragment connectDownloadFragment = getConnectDownloadFragment(); | ||
if (connectDownloadFragment != null) { | ||
connectDownloadFragment.onSuccessfulVerification(); | ||
} | ||
} | ||
}); | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.screen_connect_job_info); | ||
setTitle(getString(R.string.connect_title)); | ||
updateBackButton(); | ||
|
||
Fragment fragment = null; | ||
ConnectJobRecord job = ConnectManager.getActiveJob(); | ||
if(job != null) { | ||
switch(job.getStatus()) { | ||
case ConnectJobRecord.STATUS_LEARNING -> { | ||
fragment = ConnectLearningProgressFragment.newInstance(false); | ||
} | ||
case ConnectJobRecord.STATUS_DELIVERING -> { | ||
fragment = ConnectDeliveryProgressFragment.newInstance(false, false); | ||
} | ||
} | ||
} | ||
|
||
if(fragment == null) { | ||
fragment = ConnectJobIntroFragment.newInstance(false); | ||
} | ||
|
||
getSupportFragmentManager().beginTransaction() | ||
.add(R.id.connect_job_info_container, fragment).commit(); | ||
} | ||
|
||
@Override | ||
public void onBackPressed() { | ||
if(backButtonEnabled) { | ||
super.onBackPressed(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent intent) { | ||
ConnectManager.handleFinishedActivity(requestCode, resultCode, intent); | ||
super.onActivityResult(requestCode, resultCode, intent); | ||
} | ||
|
||
@Override | ||
public CustomProgressDialog generateProgressDialog(int taskId) { | ||
if(waitDialogEnabled) { | ||
return CustomProgressDialog.newInstance(null, getString(R.string.please_wait), taskId); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public void setBackButtonEnabled(boolean enabled) { backButtonEnabled = enabled; } | ||
public void setWaitDialogEnabled(boolean enabled) { waitDialogEnabled = enabled; } | ||
|
||
private void updateBackButton() { | ||
ActionBar actionBar = getSupportActionBar(); | ||
if (actionBar != null) { | ||
actionBar.setDisplayShowHomeEnabled(isBackEnabled()); | ||
actionBar.setDisplayHomeAsUpEnabled(isBackEnabled()); | ||
} | ||
} | ||
|
||
@Override | ||
protected boolean shouldShowBreadcrumbBar() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public ResourceEngineListener getReceiver() { | ||
return getConnectDownloadFragment(); | ||
} | ||
|
||
@Nullable | ||
private ConnectDownloadingFragment getConnectDownloadFragment() { | ||
NavHostFragment navHostFragment = | ||
(NavHostFragment)getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment_connect); | ||
Fragment currentFragment = | ||
navHostFragment.getChildFragmentManager().getPrimaryNavigationFragment(); | ||
if (currentFragment instanceof ConnectDownloadingFragment) { | ||
return (ConnectDownloadingFragment)currentFragment; | ||
} | ||
return null; | ||
} | ||
|
||
public void startAppValidation() { | ||
Intent i = new Intent(this, CommCareVerificationActivity.class); | ||
i.putExtra(CommCareVerificationActivity.KEY_LAUNCH_FROM_SETTINGS, true); | ||
verificationLauncher.launch(i); | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
app/src/org/commcare/activities/connect/IConnectAppLauncher.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,5 @@ | ||
package org.commcare.activities.connect; | ||
|
||
public interface IConnectAppLauncher { | ||
void launchApp(String appId, boolean isLearning); | ||
} |
Oops, something went wrong.