Skip to content

Commit

Permalink
Update build info displayed for sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoud-elmorabea committed Oct 27, 2024
1 parent b92a8c1 commit 90321af
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

import io.customer.android.sample.java_layout.BuildConfig;
import io.customer.android.sample.java_layout.R;
import io.customer.sdk.core.di.AndroidSDKComponent;
import io.customer.sdk.core.di.SDKComponent;

public class ViewUtils {
public static void prepareForAutomatedTests(@NonNull View view, @StringRes int contentDescResId) {
Expand Down Expand Up @@ -55,16 +55,40 @@ public static void setError(@NonNull TextInputLayout textInputLayout, @Nullable
}

public static void setBuildInfo(@NonNull TextView textView) {
AndroidSDKComponent androidSDKComponent = SDKComponent.INSTANCE.android();
String sdkVersion = androidSDKComponent.getClient().getSdkVersion();
String buildInfo = String.format(Locale.ENGLISH,
"Customer.io Android SDK %s Java Layout %s (%s)",
sdkVersion,
BuildConfig.VERSION_NAME,
BuildConfig.VERSION_CODE);
String buildInfo = String.format(
Locale.ENGLISH,
"SDK version: %s\n" +
"Build date: %s\n" +
"Branch: %s\n" +
"Default workspace: Native iOS & Android\n" +
"App version: %s",
getSdkVersion(),
getBuildTime(),
getBranchName(),
BuildConfig.VERSION_CODE
);
textView.setText(buildInfo);
}

private static String getBuildTime() {
return DateFormat.getDateTimeInstance().format(new Date(BuildConfig.BUILD_TIMESTAMP));
}

private static String getSdkVersion() {
if (isEmptyOrUnset(BuildConfig.SDK_VERSION)) return "as source code(" + getBranchName() + ")";
return BuildConfig.SDK_VERSION;
}

private static String getBranchName() {
if (isEmptyOrUnset(BuildConfig.BRANCH)) return "local development";
return BuildConfig.BRANCH;
}

private static boolean isEmptyOrUnset(String text) {
// When local properties are not set, they have a string value of "null"
return TextUtils.isEmpty(text) || "null".equalsIgnoreCase(text);
}

@NonNull
public static MaterialAlertDialogBuilder createAlertDialog(@NonNull Activity activity) {
return new MaterialAlertDialogBuilder(activity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_default"
android:gravity="center"
android:textAppearance="@style/TextAppearance.Material3.BodySmall"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
1 change: 0 additions & 1 deletion samples/java_layout/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_default"
android:gravity="center"
android:textAppearance="@style/TextAppearance.Material3.BodySmall"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down

0 comments on commit 90321af

Please sign in to comment.