From 0a857ef76ff4aea7b2ef9040643127d44a62a233 Mon Sep 17 00:00:00 2001 From: Piotro Date: Mon, 10 Jul 2023 17:19:44 +0200 Subject: [PATCH] Add GPLAY flavour Badge + theme --- .idea/misc.xml | 2 +- app/build.gradle | 15 +++++++++++ .../eu/piotro/sondechaser/MainActivity.java | 18 +++++++++++-- app/src/main/res/drawable/badge_bg.xml | 7 +++++ app/src/main/res/layout/nav_header_main.xml | 27 ++++++++++++++++++- app/src/main/res/values-night/themes.xml | 16 +++++++++++ app/src/main/res/values/dimens.xml | 2 +- app/src/main/res/values/themes.xml | 16 +++++++++++ 8 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/drawable/badge_bg.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 8f6d6c1..d00665c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -10,7 +10,7 @@ diff --git a/app/build.gradle b/app/build.gradle index 4c1535b..aad9636 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,8 +28,23 @@ android { debuggable true applicationIdSuffix ".debug" buildConfigField("String", "VERSION_SUFF", "\"[beta-DEBUG]\"") + } } + + flavorDimensions "channel" + productFlavors { + dist { + dimension "channel" + buildConfigField("boolean", "GPLAY", "false") + } + gplay { + dimension "channel" + buildConfigField("boolean", "GPLAY", "true") + applicationIdSuffix ".paid" + } + } + compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 diff --git a/app/src/main/java/eu/piotro/sondechaser/MainActivity.java b/app/src/main/java/eu/piotro/sondechaser/MainActivity.java index 98ba686..2b289e3 100644 --- a/app/src/main/java/eu/piotro/sondechaser/MainActivity.java +++ b/app/src/main/java/eu/piotro/sondechaser/MainActivity.java @@ -3,9 +3,11 @@ package eu.piotro.sondechaser; import android.Manifest; import android.app.AlertDialog; import android.content.pm.PackageManager; +import android.content.res.Resources; import android.os.Bundle; import android.view.View; import android.view.Menu; +import android.widget.FrameLayout; import android.widget.TextView; import com.google.android.material.snackbar.Snackbar; @@ -38,7 +40,6 @@ public class MainActivity extends AppCompatActivity { // TODO: Main activity get destroyed on task-switch. // It probably should be there (but where?), we need further separation of tasks and UI (could help loading times also) // It should be created in app constructor (notification about running in backgroud?) and non re-crated on UI crate!!!! - // main activy is destroyed and then recreated - kill all other threads on destroy dataCollector = new DataCollector(this); @@ -61,8 +62,13 @@ public class MainActivity extends AppCompatActivity { NavigationUI.setupWithNavController(navigationView, navController); View headerView = navigationView.getHeaderView(0); - TextView navUsername = (TextView) headerView.findViewById(R.id.nav_version); + TextView navUsername = headerView.findViewById(R.id.nav_version); + FrameLayout nav_badge = headerView.findViewById(R.id.nav_badge); navUsername.setText("v"+BuildConfig.VERSION_NAME + BuildConfig.VERSION_SUFF + " " + getString(R.string.nav_header_subtitle)); + if(BuildConfig.GPLAY) { + nav_badge.setVisibility(View.VISIBLE); + setTheme(R.style.Theme_SondeChaser_GPLAY); + } // Map configurations Configuration.getInstance().setUserAgentValue(getApplicationContext().getPackageName()); @@ -80,6 +86,14 @@ public class MainActivity extends AppCompatActivity { dataCollectorThread.start(); } + @Override + public Resources.Theme getTheme() { + Resources.Theme theme = super.getTheme(); + if(BuildConfig.GPLAY) + theme.applyStyle(R.style.Theme_SondeChaser_GPLAY, true); + return theme; + } + @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. diff --git a/app/src/main/res/drawable/badge_bg.xml b/app/src/main/res/drawable/badge_bg.xml new file mode 100644 index 0000000..3d09f1e --- /dev/null +++ b/app/src/main/res/drawable/badge_bg.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/app/src/main/res/layout/nav_header_main.xml b/app/src/main/res/layout/nav_header_main.xml index 9ccf8be..f7b6944 100644 --- a/app/src/main/res/layout/nav_header_main.xml +++ b/app/src/main/res/layout/nav_header_main.xml @@ -31,5 +31,30 @@ android:id="@+id/nav_version" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/nav_header_subtitle" /> + android:text="@string/nav_header_subtitle" + android:textSize="12dp" /> + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 87c501b..7001cc5 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -13,4 +13,20 @@ ?attr/colorPrimaryVariant + + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 4ab4520..0ee05a5 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -3,6 +3,6 @@ 16dp 16dp 8dp - 176dp + 200dp 16dp \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 1bdb7c6..e6df6b9 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -14,6 +14,22 @@ + +