Skip to content
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

Feature/flavoringapp #24

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ jobs:
java-version: 1.8

- name: Build with Gradle
run: ./gradlew assembleProdRelease
run: ./gradlew assembleProdNoiAppRelease

- name: Upload APK
uses: actions/[email protected]
with:
name: app
path: app/build/outputs/apk/prod/release/app-prod-release.apk
path: app/build/outputs/apk/prodNoiApp/release/app-prodNoiApp-release.apk

- name: Build Debug with Gradle
run: ./gradlew assembleDevDebug
run: ./gradlew assembleDevNoiAppDebug

- name: Upload debug APK
uses: actions/[email protected]
with:
name: app
path: app/build/outputs/apk/dev/debug/app-dev-debug.apk
path: app/build/outputs/apk/devNoiApp/debug/app-devNoiApp-debug.apk
16 changes: 15 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,23 @@ android {
productFlavors {
dev {
buildConfigField 'boolean', 'IS_DEV', 'true'
buildConfigField 'String', "CUSTOM_BACKEND_URL", '\"\"'
buildConfigField 'String', "APPNAME", '\"org.dpppt.demo\"'
}
prod {
prod{
buildConfigField 'boolean', 'IS_DEV', 'false'
buildConfigField 'String', "CUSTOM_BACKEND_URL", '\"\"'
buildConfigField 'String', "APPNAME", '\"org.dpppt.demo\"'
}
devNoiApp {
buildConfigField 'boolean', 'IS_DEV', 'true'
buildConfigField 'String', "CUSTOM_BACKEND_URL", '\"https://protetti.app/\"'
buildConfigField 'String', "APPNAME", '\"it.noiapp.demo\"'
}
prodNoiApp {
buildConfigField 'boolean', 'IS_DEV', 'false'
buildConfigField 'String', "CUSTOM_BACKEND_URL", '\"https://protetti.app/\"'
buildConfigField 'String', "APPNAME", '\"it.noiapp.demo\"'
}
}

Expand Down
Binary file added app/src/dev/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/dev/res/mipmap-hdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/dev/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/dev/res/mipmap-mdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/dev/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/dev/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/dev/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
168 changes: 168 additions & 0 deletions app/src/devNoiApp/java/org/dpppt/android/app/debug/DebugFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package org.dpppt.android.app.debug;

import android.app.AlertDialog;
import android.content.res.ColorStateList;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import org.dpppt.android.app.R;
import org.dpppt.android.app.debug.model.DebugAppState;
import org.dpppt.android.app.main.TracingViewModel;
import org.dpppt.android.app.util.InfoDialog;
import org.dpppt.android.sdk.TracingStatus;

public class DebugFragment extends Fragment {

private static final DateFormat DATE_FORMAT_SYNC = SimpleDateFormat.getDateTimeInstance();
private TracingViewModel tracingViewModel;

public static void startDebugFragment(FragmentManager parentFragmentManager) {
parentFragmentManager.beginTransaction()
.replace(R.id.main_fragment_container, DebugFragment.newInstance())
.addToBackStack(DebugFragment.class.getCanonicalName())
.commit();
}

private static DebugFragment newInstance() {
return new DebugFragment();
}

public DebugFragment() {
super(R.layout.fragment_debug);
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tracingViewModel = new ViewModelProvider(requireActivity()).get(TracingViewModel.class);
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
Toolbar toolbar = view.findViewById(R.id.contacts_toolbar);
toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack());

setupSdkViews(view);
setupStateOptions(view);
}

private void setupSdkViews(View view) {
TextView statusText = view.findViewById(R.id.debug_sdk_state_text);
tracingViewModel.getTracingStatusLiveData().observe(getViewLifecycleOwner(), status -> {
statusText.setText(formatStatusString(status));
boolean isTracing = (status.isAdvertising() || status.isReceiving()) && status.getErrors().size() == 0;
statusText.setBackgroundTintList(ColorStateList.valueOf(
isTracing ? getResources().getColor(R.color.status_green_bg, null)
: getResources().getColor(R.color.status_red_bg, null)));
});

view.findViewById(R.id.debug_button_reset).setOnClickListener(v -> {
AlertDialog progressDialog = new AlertDialog.Builder(getContext())
.setView(R.layout.dialog_loading)
.show();
tracingViewModel.resetSdk(() -> {
progressDialog.dismiss();
InfoDialog.newInstance(R.string.debug_sdk_reset_text)
.show(getChildFragmentManager(), InfoDialog.class.getCanonicalName());
updateRadioGroup(getView().findViewById(R.id.debug_state_options_group));
});
});
}

private void setupStateOptions(View view) {
RadioGroup optionsGroup = view.findViewById(R.id.debug_state_options_group);
optionsGroup.setOnCheckedChangeListener((group, checkedId) -> {
switch (checkedId) {
case R.id.debug_state_option_none:
tracingViewModel.setDebugAppState(DebugAppState.NONE);
break;
case R.id.debug_state_option_healthy:
tracingViewModel.setDebugAppState(DebugAppState.HEALTHY);
break;
case R.id.debug_state_option_exposed:
tracingViewModel.setDebugAppState(DebugAppState.CONTACT_EXPOSED);
break;
case R.id.debug_state_option_infected:
tracingViewModel.setDebugAppState(DebugAppState.REPORTED_EXPOSED);
break;
}
});

updateRadioGroup(optionsGroup);
}

private void updateRadioGroup(RadioGroup optionsGroup) {
int preSetId = -1;
switch (tracingViewModel.getDebugAppState()) {
case NONE:
preSetId = R.id.debug_state_option_none;
break;
case HEALTHY:
preSetId = R.id.debug_state_option_healthy;
break;
case CONTACT_EXPOSED:
preSetId = R.id.debug_state_option_exposed;
break;
case REPORTED_EXPOSED:
preSetId = R.id.debug_state_option_infected;
break;
}
optionsGroup.check(preSetId);
}

private SpannableString formatStatusString(TracingStatus status) {
SpannableStringBuilder builder = new SpannableStringBuilder();
boolean isTracing = (status.isAdvertising() || status.isReceiving()) && status.getErrors().size() == 0;
builder.append(getString(isTracing ? R.string.tracing_active_title : R.string.tracing_error_title)).append("\n")
.setSpan(new StyleSpan(Typeface.BOLD), 0, builder.length() - 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

long lastSyncDateUTC = status.getLastSyncDate();
String lastSyncDateString =
lastSyncDateUTC > 0 ? DATE_FORMAT_SYNC.format(new Date(lastSyncDateUTC)) : "n/a";
builder.append(getString(R.string.debug_sdk_state_last_synced))
.append(lastSyncDateString).append("\n")
.append(getString(R.string.debug_sdk_state_self_exposed))
.append(getBooleanDebugString(status.isReportedAsExposed())).append("\n")
.append(getString(R.string.debug_sdk_state_contact_exposed))
.append(getBooleanDebugString(status.wasContactExposed())).append("\n")
.append(getString(R.string.debug_sdk_state_number_handshakes))
.append(String.valueOf(status.getNumberOfHandshakes()));

ArrayList<TracingStatus.ErrorState> errors = status.getErrors();
if (errors != null && errors.size() > 0) {
int start = builder.length();
builder.append("\n");
for (TracingStatus.ErrorState error : errors) {
builder.append("\n").append(error.toString());
}
builder.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.red_main, null)),
start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}

return new SpannableString(builder);
}

private String getBooleanDebugString(boolean value) {
return getString(value ? R.string.debug_sdk_state_boolean_true : R.string.debug_sdk_state_boolean_false);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.dpppt.android.app.debug;

import org.dpppt.android.app.debug.model.DebugAppState;
import org.dpppt.android.app.main.model.AppState;
import org.dpppt.android.app.main.model.TracingStatusInterface;
import org.dpppt.android.sdk.TracingStatus;

public class TracingStatusWrapper implements TracingStatusInterface {

private DebugAppState debugAppState = DebugAppState.NONE;
private TracingStatus status;

public TracingStatusWrapper(DebugAppState debugAppState) {
this.debugAppState = debugAppState;
}

public void setStatus(TracingStatus status) {
this.status = status;
}

@Override
public boolean isReportedAsExposed() {
return status.isReportedAsExposed() || debugAppState == DebugAppState.REPORTED_EXPOSED;
}

@Override
public boolean wasContactExposed() {
return status.wasContactExposed() || debugAppState == DebugAppState.CONTACT_EXPOSED;
}

@Override
public void setDebugAppState(DebugAppState debugAppState) {
this.debugAppState = debugAppState;
}

@Override
public DebugAppState getDebugAppState() {
return debugAppState;
}

@Override
public AppState getAppState() {
boolean hasError = status.getErrors().size() > 0 || !(status.isAdvertising() || status.isReceiving());
switch (debugAppState) {
case NONE:
if (status.isReportedAsExposed() || status.wasContactExposed()) {
return hasError ? AppState.EXPOSED_ERROR : AppState.EXPOSED;
} else if (hasError) {
return AppState.ERROR;
} else {
return AppState.TRACING;
}
case HEALTHY:
return hasError ? AppState.ERROR : AppState.TRACING;
case REPORTED_EXPOSED:
case CONTACT_EXPOSED:
return hasError ? AppState.EXPOSED_ERROR : AppState.EXPOSED;
}
throw new IllegalStateException("Unkown debug AppState: " + debugAppState.toString());
}

}
11 changes: 11 additions & 0 deletions app/src/devNoiApp/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Created by Ubique Innovation AG
~ https://www.ubique.ch
~ Copyright (c) 2020. All rights reserved.
-->

<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
11 changes: 11 additions & 0 deletions app/src/devNoiApp/res/mipmap-anydpi-v26/ic_launcher_round.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Created by Ubique Innovation AG
~ https://www.ubique.ch
~ Copyright (c) 2020. All rights reserved.
-->

<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
9 changes: 7 additions & 2 deletions app/src/main/java/org/dpppt/android/app/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ public void onCreate() {
super.onCreate();
if (ProcessUtil.isMainProcess(this)) {
registerReceiver(broadcastReceiver, DP3T.getUpdateIntentFilter());
DP3T.init(this, new ApplicationInfo("it.noiapp.demo", "https://protetti.app/"));
}

if(BuildConfig.CUSTOM_BACKEND_URL.length() > 0) {
DP3T.init(this, new ApplicationInfo(BuildConfig.APPNAME, BuildConfig.CUSTOM_BACKEND_URL));
}else{
DP3T.init(this, BuildConfig.APPNAME, BuildConfig.FLAVOR.equals("dev"));
}
}
}

@Override
Expand Down
11 changes: 11 additions & 0 deletions app/src/prod/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Created by Ubique Innovation AG
~ https://www.ubique.ch
~ Copyright (c) 2020. All rights reserved.
-->

<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
11 changes: 11 additions & 0 deletions app/src/prod/res/mipmap-anydpi-v26/ic_launcher_round.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Created by Ubique Innovation AG
~ https://www.ubique.ch
~ Copyright (c) 2020. All rights reserved.
-->

<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Binary file added app/src/prod/res/mipmap-hdpi/ic_launcher.png
Binary file added app/src/prod/res/mipmap-mdpi/ic_launcher.png
Binary file added app/src/prod/res/mipmap-xhdpi/ic_launcher.png
Binary file added app/src/prod/res/mipmap-xxhdpi/ic_launcher.png
Binary file added app/src/prod/res/mipmap-xxxhdpi/ic_launcher.png
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.dpppt.android.app.debug;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

public class DebugFragment extends Fragment {

public static void startDebugFragment(FragmentManager parentFragmentManager) {
/*
*
* NOT IMPLEMENTED ON PROD. ONLY MODIFY THIS FRAGMENT IN THE DEV FOLDER
*
* */
}

}
Loading