Browse Source

Added more version info in About for debug builds

pull/61/merge
Ezerous 6 years ago
parent
commit
ebff5cee34
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 25
      app/build.gradle
  2. 29
      app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java
  3. 1
      build.gradle

25
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'

29
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,9 +100,9 @@ public class AboutActivity extends BaseActivity {
mVersionLastPressedTime = System.currentTimeMillis();
mVersionPressedCounter = 0;
}
}
});
}
}
TextView privacyPolicy = findViewById(R.id.privacy_policy_header);
privacyPolicy.setMovementMethod(new LinkMovementMethod());

1
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'
}
}

Loading…
Cancel
Save