Add collapsing toolbar fab action in menu after total layout collapse
This commit is contained in:
parent
d2a6617311
commit
f668f88a60
@ -45,6 +45,7 @@ public class ItemActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private ItemWithFeed itemWithFeed;
|
private ItemWithFeed itemWithFeed;
|
||||||
|
|
||||||
|
private boolean appBarCollapsed;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -93,12 +94,21 @@ public class ItemActivity extends AppCompatActivity {
|
|||||||
.into(imageView);
|
.into(imageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
appBarLayout.addOnOffsetChangedListener(((appBarLayout1, i) -> {
|
||||||
|
if (Math.abs(i) >= (appBarLayout.getTotalScrollRange() - ((5 * appBarLayout.getTotalScrollRange()) / 100))) {
|
||||||
|
appBarCollapsed = true;
|
||||||
|
invalidateOptionsMenu();
|
||||||
|
} else {
|
||||||
|
appBarCollapsed = false;
|
||||||
|
invalidateOptionsMenu();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
viewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication()).create(ItemViewModel.class);
|
viewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication()).create(ItemViewModel.class);
|
||||||
viewModel.getItemById(itemId).observe(this, this::bindUI);
|
viewModel.getItemById(itemId).observe(this, this::bindUI);
|
||||||
|
|
||||||
actionButton.setOnClickListener(v -> {
|
actionButton.setOnClickListener(v -> {
|
||||||
Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(itemWithFeed.getItem().getLink()));
|
openLink();
|
||||||
startActivity(urlIntent);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,19 +165,40 @@ public class ItemActivity extends AppCompatActivity {
|
|||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.item_menu, menu);
|
getMenuInflater().inflate(R.menu.item_menu, menu);
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
|
MenuItem item = menu.findItem(R.id.item_open);
|
||||||
|
|
||||||
|
if (appBarCollapsed)
|
||||||
|
item.setVisible(true);
|
||||||
|
else
|
||||||
|
item.setVisible(false);
|
||||||
|
|
||||||
|
return super.onPrepareOptionsMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.item_share:
|
case R.id.item_share:
|
||||||
shareArticle();
|
shareArticle();
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.item_open:
|
||||||
|
openLink();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void openLink() {
|
||||||
|
Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(itemWithFeed.getItem().getLink()));
|
||||||
|
startActivity(urlIntent);
|
||||||
|
}
|
||||||
|
|
||||||
private void shareArticle() {
|
private void shareArticle() {
|
||||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||||
shareIntent.setType("text/plain");
|
shareIntent.setType("text/plain");
|
||||||
|
@ -2,6 +2,12 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/item_open"
|
||||||
|
android:title="@string/open_url"
|
||||||
|
android:icon="@drawable/ic_open_in_browser_white"
|
||||||
|
app:showAsAction="ifRoom"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/item_share"
|
android:id="@+id/item_share"
|
||||||
android:title="@string/share"
|
android:title="@string/share"
|
||||||
@ -9,4 +15,6 @@
|
|||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</menu>
|
</menu>
|
@ -21,5 +21,6 @@
|
|||||||
<string name="read_time_lower_than_1">Moins d\'une minute</string>
|
<string name="read_time_lower_than_1">Moins d\'une minute</string>
|
||||||
<string name="read_time_one_minute">1 min</string>
|
<string name="read_time_one_minute">1 min</string>
|
||||||
<string name="share">Partager l\'article</string>
|
<string name="share">Partager l\'article</string>
|
||||||
|
<string name="open_url">Ouvrir le lien</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -23,4 +23,5 @@
|
|||||||
<string name="read_time_one_minute">1 min</string>
|
<string name="read_time_one_minute">1 min</string>
|
||||||
<string name="interpoint" translatable="false">·</string>
|
<string name="interpoint" translatable="false">·</string>
|
||||||
<string name="share">Share Article</string>
|
<string name="share">Share Article</string>
|
||||||
|
<string name="open_url">Open url</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user