From 98ab900b3d4672f176d20fde19ec1f45065e04bb Mon Sep 17 00:00:00 2001 From: akaessens <24660231+akaessens@users.noreply.github.com> Date: Wed, 26 Aug 2020 15:51:10 +0200 Subject: [PATCH] set banner as default toolbar image --- app/build.gradle | 2 +- .../akdev/nofbeventscraper/MainActivity.java | 27 ++++++++- app/src/main/res/drawable/ic_icon.xml | 58 ------------------- 3 files changed, 25 insertions(+), 62 deletions(-) delete mode 100644 app/src/main/res/drawable/ic_icon.xml diff --git a/app/build.gradle b/app/build.gradle index dae7d72..6a4ae91 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,7 +30,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.constraintlayout:constraintlayout:2.0.1' implementation 'androidx.navigation:navigation-fragment:2.3.0' implementation 'androidx.navigation:navigation-ui:2.3.0' diff --git a/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java b/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java index c28b439..b540ac1 100644 --- a/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java +++ b/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.textfield.TextInputEditText; import androidx.appcompat.app.AppCompatActivity; @@ -66,6 +67,28 @@ public class MainActivity extends AppCompatActivity { ok_button.setEnabled(false); + toolbar_image_view.setImageResource(R.drawable.ic_banner_foreground); + + AppBarLayout app_bar_layout = (AppBarLayout) findViewById(R.id.app_bar); + app_bar_layout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { + boolean isShow = true; + int scrollRange = -1; + + @Override + public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { + if (scrollRange == -1) { + scrollRange = appBarLayout.getTotalScrollRange(); + } + if (scrollRange + verticalOffset == 0) { + toolbar_layout.setTitle(getString(R.string.app_name)); + isShow = true; + } else if(isShow) { + toolbar_layout.setTitle(" "); + isShow = false; + } + } + }); + paste_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -259,14 +282,13 @@ public class MainActivity extends AppCompatActivity { field_event_description.setError(null); toolbar_image_view.setImageDrawable(null); - toolbar_layout.setTitle(getString(R.string.app_name)); - if (scraper!=null) { scraper.cancel(true); scraper = null; } ok_button.setEnabled(false); + toolbar_image_view.setImageResource(R.drawable.ic_banner_foreground); } public void update(FbEvent event) { @@ -306,7 +328,6 @@ public class MainActivity extends AppCompatActivity { try { Picasso.get().load(event.image_url).into(toolbar_image_view); - toolbar_layout.setTitle(" "); } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/res/drawable/ic_icon.xml b/app/src/main/res/drawable/ic_icon.xml deleted file mode 100644 index 4834787..0000000 --- a/app/src/main/res/drawable/ic_icon.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - -