From cef22b3a54def3c86d52c0457364a1590696cef6 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Wed, 26 Dec 2018 13:28:47 +0200 Subject: [PATCH] Main fab fixes, Init AddRestaurantActivity, RestaurantActivity --- .../flavoursWithoutBorders/app/build.gradle | 1 - .../app/src/main/AndroidManifest.xml | 2 + .../flavours/activities/LoginActivity.java | 4 +- .../flavours/activities/SignUpActivity.java | 2 +- .../activities/main/MainActivity.java | 21 ++++-- .../restaurant/AddRestaurantActivity.java | 49 ++++++++++++++ .../restaurant/RestaurantActivity.java | 15 +++++ .../utils/ScrollAwareFABBehavior.java | 63 ++++++++++++++++++ .../res/drawable-hdpi/ic_add_white_24dp.png | Bin 0 -> 156 bytes .../res/drawable-mdpi/ic_add_white_24dp.png | Bin 0 -> 103 bytes .../res/drawable-xhdpi/ic_add_white_24dp.png | Bin 0 -> 135 bytes .../res/drawable-xxhdpi/ic_add_white_24dp.png | Bin 0 -> 180 bytes .../drawable-xxxhdpi/ic_add_white_24dp.png | Bin 0 -> 243 bytes .../res/layout/activity_add_restaurant.xml | 23 +++++++ .../app/src/main/res/layout/activity_main.xml | 8 ++- .../main/res/layout/activity_restaurant.xml | 37 ++++++++++ .../main/res/layout/fragment_main_list.xml | 4 +- 17 files changed, 218 insertions(+), 11 deletions(-) create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/AddRestaurantActivity.java create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/ScrollAwareFABBehavior.java create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-hdpi/ic_add_white_24dp.png create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-mdpi/ic_add_white_24dp.png create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xhdpi/ic_add_white_24dp.png create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxhdpi/ic_add_white_24dp.png create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxxhdpi/ic_add_white_24dp.png create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_add_restaurant.xml create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_restaurant.xml diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/build.gradle b/UI/AndroidApp/flavoursWithoutBorders/app/build.gradle index 7f76950..b597ccf 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/build.gradle +++ b/UI/AndroidApp/flavoursWithoutBorders/app/build.gradle @@ -34,7 +34,6 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' implementation 'com.mikepenz:fontawesome-typeface:4.7.0.0@aar' implementation 'com.mikepenz:google-material-typeface:3.0.1.2.original@aar' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.material:material:1.0.0' implementation 'com.google.android.gms:play-services-maps:16.0.0' } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml index 4745b2a..a36e51b 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml @@ -45,6 +45,8 @@ + + \ No newline at end of file diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/LoginActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/LoginActivity.java index b487f60..a8d08c0 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/LoginActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/LoginActivity.java @@ -18,7 +18,7 @@ public class LoginActivity extends BaseActivity { findViewById(R.id.login_btn_sign_up).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Intent intent = new Intent(getBaseContext(), SignUpActivity.class); + Intent intent = new Intent(view.getContext(), SignUpActivity.class); startActivity(intent); finish(); } @@ -27,7 +27,7 @@ public class LoginActivity extends BaseActivity { findViewById(R.id.login_btn_login).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Intent intent = new Intent(getBaseContext(), MainActivity.class); + Intent intent = new Intent(view.getContext(), MainActivity.class); startActivity(intent); finish(); } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/SignUpActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/SignUpActivity.java index 775fdcf..7145b75 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/SignUpActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/SignUpActivity.java @@ -29,7 +29,7 @@ public class SignUpActivity extends BaseActivity { findViewById(R.id.sign_up_btn_login).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Intent intent = new Intent(getBaseContext(), LoginActivity.class); + Intent intent = new Intent(view.getContext(), LoginActivity.class); startActivity(intent); finish(); } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java index de09f4f..51317d3 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java @@ -1,8 +1,10 @@ package gr.auth.databases.flavours.activities.main; +import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; +import android.view.View; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; @@ -13,12 +15,14 @@ import androidx.fragment.app.FragmentStatePagerAdapter; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; import gr.auth.databases.flavours.R; +import gr.auth.databases.flavours.activities.restaurant.AddRestaurantActivity; import gr.auth.databases.flavours.activities.main.fragments.MainListFragment; import gr.auth.databases.flavours.activities.main.fragments.MainMapFragment; import gr.auth.databases.flavours.base.BaseActivity; public class MainActivity extends BaseActivity { private static final int NUM_PAGES = 2; + private ViewPager viewPager; private MenuItem menuMapItem; @@ -34,7 +38,6 @@ public class MainActivity extends BaseActivity { actionbar.setDisplayHomeAsUpEnabled(true); actionbar.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp); - createDrawer(); viewPager = findViewById(R.id.main_pager); @@ -58,16 +61,26 @@ public class MainActivity extends BaseActivity { } }); + findViewById(R.id.main_fab).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(view.getContext(), AddRestaurantActivity.class); + startActivity(intent); + } + }); + PagerAdapter pagerAdapter = new MainPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(pagerAdapter); } @Override public void onBackPressed() { - if (viewPager.getCurrentItem() == 0) { - super.onBackPressed(); - } else { + if (drawer.isDrawerOpen()) { + drawer.closeDrawer(); + } else if (viewPager.getCurrentItem() == 1) { viewPager.setCurrentItem(0); + } else { + super.onBackPressed(); } } diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/AddRestaurantActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/AddRestaurantActivity.java new file mode 100644 index 0000000..f032154 --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/AddRestaurantActivity.java @@ -0,0 +1,49 @@ +package gr.auth.databases.flavours.activities.restaurant; + +import android.os.Bundle; +import android.view.MenuItem; + +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.widget.Toolbar; +import gr.auth.databases.flavours.R; +import gr.auth.databases.flavours.base.BaseActivity; + +public class AddRestaurantActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + Toolbar toolbar = findViewById(R.id.main_toolbar); + toolbar.setTitle("Add Restaurant"); + setSupportActionBar(toolbar); + ActionBar actionbar = getSupportActionBar(); + actionbar.setDisplayHomeAsUpEnabled(true); + actionbar.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp); + + createDrawer(); + } + + @Override + public void onBackPressed() { + if (drawer.isDrawerOpen()) { + drawer.closeDrawer(); + } else { + super.onBackPressed(); + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + + if (id == android.R.id.home) { + drawer.openDrawer(); + return true; + } + + return super.onOptionsItemSelected(item); + } + +} diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java new file mode 100644 index 0000000..929ff5a --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java @@ -0,0 +1,15 @@ +package gr.auth.databases.flavours.activities.restaurant; + +import gr.auth.databases.flavours.R; +import gr.auth.databases.flavours.base.BaseActivity; + +import android.os.Bundle; + +public class RestaurantActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_restaurant); + } +} diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/ScrollAwareFABBehavior.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/ScrollAwareFABBehavior.java new file mode 100644 index 0000000..559db83 --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/ScrollAwareFABBehavior.java @@ -0,0 +1,63 @@ +package gr.auth.databases.flavours.utils; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; + +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.snackbar.Snackbar; + +import androidx.annotation.NonNull; +import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.core.view.ViewCompat; + +@SuppressWarnings("unused") +public class ScrollAwareFABBehavior extends CoordinatorLayout.Behavior { + + public ScrollAwareFABBehavior(Context context, AttributeSet attrs) { + super(); + } + + @Override + public boolean onStartNestedScroll(@NonNull final CoordinatorLayout coordinatorLayout, + @NonNull final FloatingActionButton child, + @NonNull final View directTargetChild, @NonNull final View target, + final int nestedScrollAxes, int type) { + return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL; + } + + @Override + public void onNestedScroll(@NonNull final CoordinatorLayout coordinatorLayout, + @NonNull final FloatingActionButton child, + @NonNull final View target, final int dxConsumed, final int dyConsumed, + final int dxUnconsumed, final int dyUnconsumed, int type) { + super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, + dyUnconsumed, type); + if (dyConsumed > 0 || (!target.canScrollVertically(-1) && dyConsumed == 0 && dyUnconsumed > 50)) { + child.hide(new FloatingActionButton.OnVisibilityChangedListener() { + @Override + public void onHidden(FloatingActionButton fab) { + super.onHidden(fab); + fab.setVisibility(View.INVISIBLE); + } + }); + } else if (dyConsumed < 0 || !target.canScrollVertically(-1) && dyUnconsumed < -50) { + child.show(); + child.setVisibility(View.VISIBLE); + } + } + + @Override + public boolean layoutDependsOn(@NonNull CoordinatorLayout parent, + @NonNull FloatingActionButton child, @NonNull View dependency) { + return dependency instanceof Snackbar.SnackbarLayout; + } + + @Override + public boolean onDependentViewChanged(@NonNull CoordinatorLayout parent, + @NonNull FloatingActionButton child, @NonNull View dependency) { + float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight()); + child.setTranslationY(translationY); + return true; + } +} \ No newline at end of file diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-hdpi/ic_add_white_24dp.png b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-hdpi/ic_add_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..9999b98900511b85ad4e96c1165db5b250729b88 GIT binary patch literal 156 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k1|%Oc%$NbBl097~)z3#~6pvd7GIQ`kB zm?-Pd;vyEDc2^u8bLC%q(4nIGPH(1C0|TQL!zH=d7kL&iMy3LJOeK;c)9>l&Hr(p} zT*cIN_r6v&*Oa`JJ4Ox-45185tDk(li#;{an^LB{Ts5 D5N9(o literal 0 HcmV?d00001 diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-mdpi/ic_add_white_24dp.png b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-mdpi/ic_add_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..9d8a94e330b3c942dd6dd2abf323e4bdb9692296 GIT binary patch literal 103 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjdY&$hAr-fhfBgS%&#Y^Bcm=ET zIVK5-tqE6{4v9_RX6t8NJkciWU`DM$7NZaw!(o%R>5JumQ~-4{c)I$ztaD0e0svz& B9*_V4 literal 0 HcmV?d00001 diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xhdpi/ic_add_white_24dp.png b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xhdpi/ic_add_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..6d8e55d3dea22abcb334daf3345416d063717487 GIT binary patch literal 135 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCKTj9OkcwMxZ*1gbFyLW!e7k?k zrS>U`M+%zcA4rM&-S*J~DguG$-xwhb1|POPatsIZ8NxZB0td>az^n&x+^n~@9uu{n Q>Ivd|y85}Sb4q9e0FUD#jQ{`u literal 0 HcmV?d00001 diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxhdpi/ic_add_white_24dp.png b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxhdpi/ic_add_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..3a15191ccd086f909161c6d1b0c979536569044b GIT binary patch literal 180 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@ZgvM!)t)YnAr-gYUNz)pVBlbO{4-mR zE8>R2^(VY{E_nsbYG&XNP;h8qU}RDOlPnq6O&|=II17YP%e2b~B5~p@GZR#h5sBde gG6XCR6_mUB%0H6-lIo@JKxZ&`y85}Sb4q9e0Gq5Su>b%7 literal 0 HcmV?d00001 diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxxhdpi/ic_add_white_24dp.png b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxxhdpi/ic_add_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..078af52b5aa7c50b4925d5868d12eeebba8e7a6a GIT binary patch literal 243 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7OGoyF6VSLn>~)y}pr?!GVLt@pt~O z9{XQDf^Ik1@|3haGxe1j7!(*7SQr`@7z7v?m>3)w7&sUh7=eQR` + + + + + + + + \ No newline at end of file diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_main.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_main.xml index 419ab8b..4e6e36e 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_main.xml +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_main.xml @@ -29,8 +29,12 @@ app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + android:layout_gravity="bottom|end" + android:layout_margin="16dp" + android:src="@drawable/ic_add_white_24dp" + app:fabSize="mini" + app:layout_behavior="gr.auth.databases.flavours.utils.ScrollAwareFABBehavior" /> \ No newline at end of file diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_restaurant.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_restaurant.xml new file mode 100644 index 0000000..29e5499 --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_restaurant.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/fragment_main_list.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/fragment_main_list.xml index 2b9e532..a880c57 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/fragment_main_list.xml +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/fragment_main_list.xml @@ -1,8 +1,10 @@ \ No newline at end of file + android:orientation="vertical" + app:layout_behavior="@string/appbar_scrolling_view_behavior" /> \ No newline at end of file