Skip to content

Commit

Permalink
enable debug fragment from hibernation screen and extend debug fragme…
Browse files Browse the repository at this point in the history
…nt with access to HistoryFragment
  • Loading branch information
simonroesch committed Mar 19, 2022
1 parent d384ac3 commit 6288432
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 19 deletions.
10 changes: 10 additions & 0 deletions app/src/abnahme/java/ch/admin/bag/dp3t/debug/DebugFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.dpppt.android.sdk.internal.nearby.ExposureWindowMatchingWorker;

import ch.admin.bag.dp3t.R;
import ch.admin.bag.dp3t.contacts.HistoryFragment;
import ch.admin.bag.dp3t.networking.CertificatePinning;

public class DebugFragment extends Fragment {
Expand Down Expand Up @@ -62,6 +63,15 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

view.findViewById(R.id.debug_trigger_exposure_check)
.setOnClickListener(v -> ExposureWindowMatchingWorker.startMatchingWorker(v.getContext()));

View historyButton = view.findViewById(R.id.debug_history);
historyButton.setOnClickListener(v -> {
getParentFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.slide_enter, R.anim.slide_exit, R.anim.slide_pop_enter, R.anim.slide_pop_exit)
.replace(R.id.main_fragment_container, HistoryFragment.newInstance())
.addToBackStack(HistoryFragment.class.getCanonicalName())
.commit();
});
}

}
20 changes: 15 additions & 5 deletions app/src/dev/java/ch/admin/bag/dp3t/debug/DebugFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import ch.admin.bag.dp3t.R;
import ch.admin.bag.dp3t.checkin.CrowdNotifierViewModel;
import ch.admin.bag.dp3t.checkin.models.SwissCovidAssociatedData;
import ch.admin.bag.dp3t.contacts.HistoryFragment;
import ch.admin.bag.dp3t.debug.model.DebugAppState;
import ch.admin.bag.dp3t.networking.CertificatePinning;
import ch.admin.bag.dp3t.storage.SecureStorage;
Expand Down Expand Up @@ -87,11 +88,11 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
private void setupSdkViews(View view) {
TextView statusText = view.findViewById(R.id.debug_sdk_state_text);
tracingViewModel.getTracingStatusLiveData().observe(getViewLifecycleOwner(), status -> {
statusText.setText(DebugUtils.formatStatusString(status, view.getContext()));
boolean isTracing = (status.isTracingEnabled()) && status.getErrors().size() == 0;
statusText.setBackgroundTintList(ColorStateList.valueOf(
isTracing ? getResources().getColor(R.color.status_green_bg, null)
: getResources().getColor(R.color.status_purple_bg, null)));
statusText.setText(DebugUtils.formatStatusString(status, view.getContext()));
boolean isTracing = (status.isTracingEnabled()) && status.getErrors().size() == 0;
statusText.setBackgroundTintList(ColorStateList.valueOf(
isTracing ? getResources().getColor(R.color.status_green_bg, null)
: getResources().getColor(R.color.status_purple_bg, null)));
});

view.findViewById(R.id.debug_button_reset).setOnClickListener(v -> {
Expand Down Expand Up @@ -132,6 +133,15 @@ private void setupSdkViews(View view) {

view.findViewById(R.id.debug_trigger_exposure_check)
.setOnClickListener(v -> ExposureWindowMatchingWorker.startMatchingWorker(v.getContext()));

View historyButton = view.findViewById(R.id.debug_history);
historyButton.setOnClickListener(v -> {
getParentFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.slide_enter, R.anim.slide_exit, R.anim.slide_pop_enter, R.anim.slide_pop_exit)
.replace(R.id.main_fragment_container, HistoryFragment.newInstance())
.addToBackStack(HistoryFragment.class.getCanonicalName())
.commit();
});
}

private void setupStateOptions(View view) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/log/java/ch/admin/bag/dp3t/debug/DebugFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.dpppt.android.sdk.internal.nearby.ExposureWindowMatchingWorker;

import ch.admin.bag.dp3t.R;
import ch.admin.bag.dp3t.contacts.HistoryFragment;
import ch.admin.bag.dp3t.networking.CertificatePinning;

public class DebugFragment extends Fragment {
Expand Down Expand Up @@ -62,6 +63,15 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

view.findViewById(R.id.debug_trigger_exposure_check)
.setOnClickListener(v -> ExposureWindowMatchingWorker.startMatchingWorker(v.getContext()));

View historyButton = view.findViewById(R.id.debug_history);
historyButton.setOnClickListener(v -> {
getParentFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.slide_enter, R.anim.slide_exit, R.anim.slide_pop_enter, R.anim.slide_pop_exit)
.replace(R.id.main_fragment_container, HistoryFragment.newInstance())
.addToBackStack(HistoryFragment.class.getCanonicalName())
.commit();
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
setupBottomNavigationView();
}

private static void setupDebugButton(View schwiizerchruez, FragmentManager fragmentManager) {
public static void setupDebugButton(View schwiizerchruez, FragmentManager fragmentManager) {
if (!DebugFragment.EXISTS) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ch.admin.bag.dp3t.R
import ch.admin.bag.dp3t.TabbarHostFragment
import ch.admin.bag.dp3t.databinding.FragmentHibernatingInfoBinding
import ch.admin.bag.dp3t.html.HtmlFragment
import ch.admin.bag.dp3t.networking.models.InfoBoxModel
import ch.admin.bag.dp3t.util.AssetUtil
import ch.admin.bag.dp3t.util.UrlUtil

Expand All @@ -32,6 +31,9 @@ class HibernatingInfoFragment : Fragment() {
true
}

val schwiizerchruez = toolbar.findViewById<View>(R.id.schwiizerchruez)
TabbarHostFragment.setupDebugButton(schwiizerchruez, requireActivity().supportFragmentManager)

viewModel.isHibernatingModeEnabled.observe(viewLifecycleOwner) { isHibernatingModeEnabled ->
if (!isHibernatingModeEnabled) {
showHomeFragment()
Expand Down
27 changes: 15 additions & 12 deletions app/src/main/java/ch/admin/bag/dp3t/viewmodel/TracingViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.dpppt.android.sdk.DP3T;
import org.dpppt.android.sdk.InfectionStatus;
import org.dpppt.android.sdk.TracingStatus;
import org.dpppt.android.sdk.internal.BroadcastHelper;
import org.dpppt.android.sdk.internal.history.HistoryEntry;
Expand All @@ -41,22 +43,12 @@
public class TracingViewModel extends AndroidViewModel {

private final MutableLiveData<TracingStatus> tracingStatusLiveData = new MutableLiveData<>();
private BroadcastReceiver tracingStatusBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
invalidateTracingStatus();
loadHistoryEntries();
}
};

private final MutableLiveData<Boolean> tracingEnabledLiveData = new MutableLiveData<>();
private final MutableLiveData<Pair<Boolean, Boolean>> exposedLiveData = new MutableLiveData<>();
private final MutableLiveData<Collection<TracingStatus.ErrorState>> errorsLiveData =
new MutableLiveData<>(Collections.emptyList());
private final MutableLiveData<TracingStatusInterface> appStatusLiveData = new MutableLiveData<>();

private TracingStatusInterface tracingStatusInterface = new TracingStatusWrapper();

private final MutableLiveData<Boolean> bluetoothEnabledLiveData = new MutableLiveData<>();
private BroadcastReceiver bluetoothReceiver = new BroadcastReceiver() {
@Override
Expand All @@ -67,8 +59,14 @@ public void onReceive(Context context, Intent intent) {
}
}
};

private final MutableLiveData<List<HistoryEntry>> historyMutableLiveData = new MutableLiveData<>();
private BroadcastReceiver tracingStatusBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
invalidateTracingStatus();
loadHistoryEntries();
}
};

public TracingViewModel(@NonNull Application application) {
super(application);
Expand Down Expand Up @@ -101,7 +99,12 @@ public void resetSdk() {
}

public void invalidateTracingStatus() {
TracingStatus status = DP3T.getStatus(getApplication());
TracingStatus status;
if (DP3T.isInitialized()) {
status = DP3T.getStatus(getApplication());
} else {
status = new TracingStatus(false, 0, InfectionStatus.HEALTHY, new ArrayList<>(), new ArrayList<>());
}
tracingStatusLiveData.setValue(status);
}

Expand Down
32 changes: 32 additions & 0 deletions app/src/main/res/layout/fragment_debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,38 @@

</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
style="@style/NextStep.Card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_medium_large">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_medium_large"
android:layout_marginRight="@dimen/spacing_large"
android:layout_marginBottom="@dimen/spacing_large"
android:orientation="vertical">

<TextView
style="@style/NextStep.Text.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="History" />

<Button
android:id="@+id/debug_history"
style="@style/NextStep.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Worker History" />

</LinearLayout>

</androidx.cardview.widget.CardView>

</LinearLayout>

</ScrollView>
Expand Down

0 comments on commit 6288432

Please sign in to comment.