diff --git a/app/build.gradle b/app/build.gradle index 71169d70..a5e0cbee 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,5 @@ import groovy.json.JsonSlurper +import org.ajoberstar.grgit.Grgit apply plugin: 'com.android.application' apply plugin: 'io.fabric' @@ -14,6 +15,8 @@ android { versionCode 14 versionName "1.5.0" archivesBaseName = "mTHMMY-v$versionName" + buildConfigField "String", "CURRENT_BRANCH", "\"" + getCurrentBranch() + "\"" + buildConfigField "String", "COMMIT_HASH", "\"" + getCommitHash() + "\"" } buildTypes { @@ -47,6 +50,28 @@ tasks.whenTaskAdded { task -> } } +static def getCurrentBranch() { + try { + def grgit = Grgit.open() + def curBranch = grgit.branch.getCurrent().name + grgit.close() + return curBranch + } catch (Exception ignored) { + return "" + } +} + +static def getCommitHash() { + try { + def grgit = Grgit.open() + def commitHash = grgit.head().id + grgit.close() + return commitHash + } catch (Exception ignored) { + return "" + } +} + dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.0' diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java index 0fac281f..741e11f3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java @@ -1,6 +1,8 @@ package gr.thmmy.mthmmy.activities; +import android.content.Intent; import android.content.pm.ActivityInfo; +import android.net.Uri; import android.os.Bundle; import com.google.android.material.appbar.AppBarLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout; @@ -38,6 +40,18 @@ public class AboutActivity extends BaseActivity { setContentView(R.layout.activity_about); String versionName = BuildConfig.VERSION_NAME; + boolean gitExists = true; + + String commitHash = BuildConfig.COMMIT_HASH; + if (commitHash.length() > 8) + commitHash = commitHash.substring(0, 8); + else + gitExists = false; + + String versionInfo = ""; + if(gitExists) + versionInfo = "-" + BuildConfig.CURRENT_BRANCH + "-" + commitHash; + //Initialize appbar appBar = findViewById(R.id.appbar); coordinatorLayout = findViewById(R.id.main_content); @@ -59,14 +73,19 @@ public class AboutActivity extends BaseActivity { TextView tv = findViewById(R.id.version); if (tv != null) { if (BuildConfig.DEBUG) - tv.setText(getString(R.string.version, versionName + "-debug")); + tv.setText(getString(R.string.version, versionName + versionInfo)); else tv.setText(getString(R.string.version, versionName)); - tv.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { + if(BuildConfig.DEBUG && gitExists){ + tv.setOnClickListener(view -> { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/ThmmyNoLife/mTHMMY/commit/" + BuildConfig.COMMIT_HASH)); + startActivity(intent); + }); + } + else{ // Easter Egg + tv.setOnClickListener(view -> { if (mVersionLastPressedTime + TIME_INTERVAL > System.currentTimeMillis()) { if (mVersionPressedCounter == TIMES_TO_PRESS) { appBar.setVisibility(View.INVISIBLE); @@ -81,8 +100,8 @@ public class AboutActivity extends BaseActivity { mVersionLastPressedTime = System.currentTimeMillis(); mVersionPressedCounter = 0; } - } - }); + }); + } } TextView privacyPolicy = findViewById(R.id.privacy_policy_header); diff --git a/build.gradle b/build.gradle index 11cbc2e0..74c7bcf9 100644 --- a/build.gradle +++ b/build.gradle @@ -11,6 +11,7 @@ buildscript { classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.google.gms:google-services:4.1.0' classpath 'io.fabric.tools:gradle:1.26.1' + classpath 'org.ajoberstar.grgit:grgit-core:3.0.0-rc.2' } }