From ef7d88d84bc1c3efec4e391ff1384c26fd911eeb Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 1 Jul 2019 14:47:59 +0300 Subject: [PATCH] AboutActivity improvements, up version --- app/build.gradle | 4 +- .../mthmmy/activities/AboutActivity.java | 85 +++++++++++++------ .../gr/thmmy/mthmmy/base/BaseApplication.java | 10 ++- 3 files changed, 67 insertions(+), 32 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c3aa2e1e..b47ae972 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,8 +13,8 @@ android { applicationId "gr.thmmy.mthmmy" minSdkVersion 19 targetSdkVersion 28 - versionCode 20 - versionName "1.7.2" + versionCode 21 + versionName "1.7.3" archivesBaseName = "mTHMMY-v$versionName" buildConfigField "String", "CURRENT_BRANCH", "\"" + getCurrentBranch() + "\"" buildConfigField "String", "COMMIT_HASH", "\"" + getCommitHash() + "\"" 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 0963be99..49e9dc8c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java @@ -11,8 +11,10 @@ import android.view.LayoutInflater; import android.view.View; import android.webkit.WebView; import android.widget.FrameLayout; +import android.widget.ImageView; import android.widget.ScrollView; import android.widget.TextView; +import android.widget.Toast; import androidx.appcompat.app.AlertDialog; import androidx.coordinatorlayout.widget.CoordinatorLayout; @@ -23,6 +25,7 @@ import com.google.android.material.appbar.AppBarLayout; import gr.thmmy.mthmmy.BuildConfig; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseActivity; +import gr.thmmy.mthmmy.base.BaseApplication; public class AboutActivity extends BaseActivity { private static final int TIME_INTERVAL = 1000; @@ -32,8 +35,9 @@ public class AboutActivity extends BaseActivity { private AppBarLayout appBar; private CoordinatorLayout coordinatorLayout; + private ScrollView mainContent; private AlertDialog alertDialog; - private FrameLayout trollGif; + private FrameLayout easterEggImage; @Override protected void onCreate(Bundle savedInstanceState) { @@ -70,41 +74,41 @@ public class AboutActivity extends BaseActivity { createDrawer(); drawer.setSelection(ABOUT_ID); - final ScrollView mainContent = findViewById(R.id.scrollview); - trollGif = findViewById(R.id.trollPicFrame); + mainContent = findViewById(R.id.scrollview); + easterEggImage = findViewById(R.id.trollPicFrame); + + // Set Easter egg on logo image + ImageView logoImageView = findViewById(R.id.logoView); + logoImageView.setOnClickListener(view -> { + if (mVersionLastPressedTime + TIME_INTERVAL > System.currentTimeMillis()) { + if (mVersionPressedCounter == TIMES_TO_PRESS) + showEasterEgg(); + mVersionLastPressedTime = System.currentTimeMillis(); + ++mVersionPressedCounter; + } else { + mVersionLastPressedTime = System.currentTimeMillis(); + mVersionPressedCounter = 0; + } + }); - TextView tv = findViewById(R.id.version); - if (tv != null) { + TextView versionTextView = findViewById(R.id.version); + if (versionTextView != null) { if (BuildConfig.DEBUG) - tv.setText(getString(R.string.version, versionName + versionInfo)); + versionTextView.setText(getString(R.string.version, versionName + versionInfo)); else - tv.setText(getString(R.string.version, versionName)); - + versionTextView.setText(getString(R.string.version, versionName)); - if(BuildConfig.DEBUG && gitExists){ - tv.setOnClickListener(view -> { + if(gitExists){ + versionTextView.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); - mainContent.setVisibility(View.INVISIBLE); - trollGif.setVisibility(View.VISIBLE); - drawer.getDrawerLayout().setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); - } - mVersionLastPressedTime = System.currentTimeMillis(); - ++mVersionPressedCounter; - } else { - mVersionLastPressedTime = System.currentTimeMillis(); - mVersionPressedCounter = 0; - } - }); - } + + versionTextView.setOnLongClickListener(view -> { + Toast.makeText(getApplicationContext(), BaseApplication.getFirebaseProjectId(), Toast.LENGTH_SHORT).show(); + return true; + }); } TextView privacyPolicy = findViewById(R.id.privacy_policy_header); @@ -122,6 +126,14 @@ public class AboutActivity extends BaseActivity { super.onResume(); } + @Override + public void onBackPressed() { + if(easterEggImage.getVisibility()==View.INVISIBLE) + super.onBackPressed(); + else + hideEasterEgg(); + } + public void displayApacheLibraries(View v) { LayoutInflater inflater = LayoutInflater.from(this); WebView webView = (WebView) inflater.inflate(R.layout.dialog_licenses, coordinatorLayout, false); @@ -152,4 +164,21 @@ public class AboutActivity extends BaseActivity { alertDialog.getWindow().setLayout(width, height); } + private void showEasterEgg(){ + if(getResources().getConfiguration().orientation==ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){ + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + appBar.setVisibility(View.INVISIBLE); + mainContent.setVisibility(View.INVISIBLE); + easterEggImage.setVisibility(View.VISIBLE); + drawer.getDrawerLayout().setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); + } + } + + private void hideEasterEgg(){ + appBar.setVisibility(View.VISIBLE); + mainContent.setVisibility(View.VISIBLE); + easterEggImage.setVisibility(View.INVISIBLE); + drawer.getDrawerLayout().setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED); + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); + } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java index 6ba7d3cc..ba0e6a0f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java @@ -18,6 +18,7 @@ import com.crashlytics.android.core.CrashlyticsCore; import com.franmontiel.persistentcookiejar.PersistentCookieJar; import com.franmontiel.persistentcookiejar.cache.SetCookieCache; import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; +import com.google.firebase.FirebaseApp; import com.google.firebase.analytics.FirebaseAnalytics; import com.itkacher.okhttpprofiler.OkHttpProfilerInterceptor; import com.jakewharton.picasso.OkHttp3Downloader; @@ -51,7 +52,8 @@ import timber.log.Timber; public class BaseApplication extends Application { private static BaseApplication baseApplication; //BaseApplication singleton - //Firebase Analytics + //Firebase + private static String firebaseProjectId; private FirebaseAnalytics firebaseAnalytics; //Client & SessionManager @@ -63,7 +65,6 @@ public class BaseApplication extends Application { //Display Metrics private static float dpWidth; - public static BaseApplication getInstance() { return baseApplication; } @@ -87,6 +88,7 @@ public class BaseApplication extends Application { else Timber.i("Starting app with Crashlytics disabled."); + firebaseProjectId = FirebaseApp.getInstance().getOptions().getProjectId(); firebaseAnalytics = FirebaseAnalytics.getInstance(this); boolean enableAnalytics = settingsSharedPrefs.getBoolean(getString(R.string.pref_privacy_analytics_enable_key), false); firebaseAnalytics.setAnalyticsCollectionEnabled(enableAnalytics); @@ -216,4 +218,8 @@ public class BaseApplication extends Application { } else Timber.i("Crashlytics were already initialized for this app session."); } + + public static String getFirebaseProjectId(){ + return firebaseProjectId; + } }