1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-10 14:36:01 +01:00

toolbar/actions/menu changes, replaced fab

This commit is contained in:
Gregor Santner 2016-06-04 17:10:24 +02:00
parent 234335e696
commit f7ce310703
8 changed files with 177 additions and 179 deletions

View file

@ -20,8 +20,8 @@
package com.github.dfa.diaspora_android.activity;
import android.Manifest;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
@ -46,6 +46,7 @@ import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.SpannableString;
@ -68,12 +69,10 @@ import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.getbase.floatingactionbutton.FloatingActionsMenu;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.data.PodUserProfile;
import com.github.dfa.diaspora_android.listener.SoftKeyboardStateWatcher;
import com.github.dfa.diaspora_android.listener.WebUserProfileChangedListener;
import com.github.dfa.diaspora_android.ui.ContextMenuWebView;
import com.github.dfa.diaspora_android.ui.CustomWebViewClient;
@ -92,6 +91,7 @@ import java.util.Locale;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, WebUserProfileChangedListener {
@ -115,6 +115,9 @@ public class MainActivity extends AppCompatActivity
private final Handler uiHandler = new Handler();
private CustomWebViewClient webViewClient;
/**
* UI Bindings
*/
@BindView(R.id.swipe)
SwipeRefreshLayout swipeRefreshLayout;
@ -122,13 +125,19 @@ public class MainActivity extends AppCompatActivity
ProgressBar progressBar;
@BindView(R.id.toolbar)
Toolbar toolbar;
Toolbar toolbarTop;
@BindView(R.id.toolbar2)
ActionMenuView toolbarBottom;
@BindView(R.id.webView)
ContextMenuWebView webView;
@BindView(R.id.fab_menubutton)
FloatingActionsMenu fab;
@BindView(R.id.main__navigaion_view)
NavigationView navigationView;
@BindView(R.id.drawer_layout)
DrawerLayout drawer;
// NavHeader cannot be bound by Butterknife
private TextView navheaderTitle;
@ -136,6 +145,10 @@ public class MainActivity extends AppCompatActivity
private ImageView navheaderImage;
/**
* END UI Bindings
*/
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -156,33 +169,11 @@ public class MainActivity extends AppCompatActivity
webView.setParentActivity(this);
// Setup toolbar
setSupportActionBar(toolbar);
toolbar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Helpers.isOnline(MainActivity.this)) {
webView.loadUrl("https://" + podDomain + "/stream");
setTitle(R.string.jb_stream);
} else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
}
}
});
// Keyboard State Watcher
final SoftKeyboardStateWatcher softKeyboardStateWatcher
= new SoftKeyboardStateWatcher(findViewById(R.id.swipe));
softKeyboardStateWatcher.addSoftKeyboardStateListener(new SoftKeyboardStateWatcher.SoftKeyboardStateListener() {
@Override
public void onSoftKeyboardOpened(int keyboardHeightInPx) {
fab.setVisibility(View.GONE);
}
@Override
public void onSoftKeyboardClosed() {
fab.setVisibility(View.VISIBLE);
setSupportActionBar(toolbarTop);
getMenuInflater().inflate(R.menu.main__menu_bottom, toolbarBottom.getMenu());
toolbarBottom.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
return MainActivity.this.onOptionsItemSelected(item);
}
});
@ -245,11 +236,9 @@ public class MainActivity extends AppCompatActivity
if (progress > 60) {
Helpers.hideTopBar(wv);
fab.setVisibility(View.VISIBLE);
}
if (progress == 100) {
fab.collapse();
progressBar.setVisibility(View.GONE);
} else {
progressBar.setVisibility(View.VISIBLE);
@ -316,17 +305,15 @@ public class MainActivity extends AppCompatActivity
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
}
}
}
private void setupNavigationSlider() {
DrawerLayout drawer = ButterKnife.findById(this, R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
this, drawer, toolbarTop, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = ButterKnife.findById(this, R.id.nav_view);
//NavigationView navigationView = ButterKnife.findById(this, R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
View navHeader = navigationView.getHeaderView(0);
@ -349,66 +336,9 @@ public class MainActivity extends AppCompatActivity
}
}
/*
* Fab button events
*/
public void fab1_click(View v) {
fab.collapse();
if (Helpers.isOnline(MainActivity.this)) {
webView.loadUrl("https://" + podDomain + "/status_messages/new");
setTitle(R.string.fab1_title);
} else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
}
}
public void fab2_click(View v) {
fab.collapse();
if (Helpers.isOnline(MainActivity.this)) {
final EditText input = new EditText(this);
final AlertDialog.Builder dialog = new AlertDialog.Builder(this)
.setView(input)
.setIcon(R.drawable.ic_launcher)
.setTitle(R.string.search_alert_title)
.setPositiveButton(R.string.search_alert_people, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String inputTag = input.getText().toString().trim();
String cleanTag = inputTag.replaceAll("\\*", "");
// this validate the input data for tagfind
if (cleanTag == null || cleanTag.equals("")) {
dialog.cancel(); // if user don<EFBFBD>t have added a tag
Snackbar.make(swipeRefreshLayout, R.string.search_alert_bypeople_validate_needsomedata, Snackbar.LENGTH_LONG).show();
} else { // User have added a search tag
webView.loadUrl("https://" + podDomain + "/people.mobile?q=" + cleanTag);
setTitle(R.string.fab2_title_person);
}
}
})
.setNegativeButton(R.string.search_alert_tag,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String inputTag = input.getText().toString().trim();
String cleanTag = inputTag.replaceAll("\\#", "");
// this validate the input data for tagfind
if (cleanTag == null || cleanTag.equals("")) {
dialog.cancel(); // if user hasn't added a tag
Snackbar.make(swipeRefreshLayout, R.string.search_alert_bytags_validate_needsomedata, Snackbar.LENGTH_LONG).show();
} else { // User have added a search tag
webView.loadUrl("https://" + podDomain + "/tags/" + cleanTag);
setTitle(R.string.fab2_title_tag);
}
}
});
dialog.show();
} else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
}
}
public void fab3_click(View v) {
fab.collapse();
webView.scrollTo(0, 0);
@OnClick(R.id.toolbar)
public void onToolBarClicked(View view) {
onNavigationItemSelected(navigationView.getMenu().findItem(R.id.nav_stream));
}
private File createImageFile() throws IOException {
@ -469,7 +399,11 @@ public class MainActivity extends AppCompatActivity
@Override
public void onBackPressed() {
fab.collapse();
if (drawer.isDrawerOpen(navigationView)) {
drawer.closeDrawer(navigationView);
return;
}
if (webView.canGoBack()) {
webView.goBack();
setTitle(R.string.app_name);
@ -504,7 +438,7 @@ public class MainActivity extends AppCompatActivity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main__menu, menu);
getMenuInflater().inflate(R.menu.main__menu_top, menu);
return true;
}
@ -556,8 +490,26 @@ public class MainActivity extends AppCompatActivity
case R.id.action_exit: {
moveTaskToBack(true);
return true;
}
case R.id.action_compose: {
if (Helpers.isOnline(MainActivity.this)) {
webView.loadUrl("https://" + podDomain + "/status_messages/new");
setTitle(R.string.compose);
} else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
}
return true;
}
case R.id.action_go_to_top: {
// Scroll to top (animated)
ObjectAnimator anim = ObjectAnimator.ofInt(webView, "scrollY", webView.getScrollY(), 0);
anim.setDuration(400);
anim.start();
return true;
}
return true;
case R.id.action_share: {
final CharSequence[] options = {getString(R.string.share_link), getString(R.string.share_screenshot), getString(R.string.take_screenshot)};
@ -730,8 +682,51 @@ public class MainActivity extends AppCompatActivity
}
}
}).show();
return true;
}
case R.id.action_search: {
if (Helpers.isOnline(MainActivity.this)) {
final EditText input = new EditText(this);
final AlertDialog.Builder dialog = new AlertDialog.Builder(this)
.setView(input)
.setIcon(R.drawable.ic_launcher)
.setTitle(R.string.search_alert_title)
.setPositiveButton(R.string.search_alert_people, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String inputTag = input.getText().toString().trim();
String cleanTag = inputTag.replaceAll("\\*", "");
// this validate the input data for tagfind
if (cleanTag == null || cleanTag.equals("")) {
dialog.cancel(); // if user don<EFBFBD>t have added a tag
Snackbar.make(swipeRefreshLayout, R.string.search_alert_bypeople_validate_needsomedata, Snackbar.LENGTH_LONG).show();
} else { // User have added a search tag
webView.loadUrl("https://" + podDomain + "/people.mobile?q=" + cleanTag);
setTitle(R.string.search_by_person);
}
}
})
.setNegativeButton(R.string.search_alert_tag,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String inputTag = input.getText().toString().trim();
String cleanTag = inputTag.replaceAll("\\#", "");
// this validate the input data for tagfind
if (cleanTag == null || cleanTag.equals("")) {
dialog.cancel(); // if user hasn't added a tag
Snackbar.make(swipeRefreshLayout, R.string.search_alert_bytags_validate_needsomedata, Snackbar.LENGTH_LONG).show();
} else { // User have added a search tag
webView.loadUrl("https://" + podDomain + "/tags/" + cleanTag);
setTitle(R.string.search_by_tag);
}
}
});
dialog.show();
} else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
}
return true;
}
return true;
}
return super.onOptionsItemSelected(item);
}
@ -809,7 +804,7 @@ public class MainActivity extends AppCompatActivity
uiHandler.post(new Runnable() {
@Override
public void run() {
if(menu == null){
if (menu == null) {
return;
}
notificationCount = Integer.valueOf(webMessage);
@ -855,7 +850,7 @@ public class MainActivity extends AppCompatActivity
uiHandler.post(new Runnable() {
@Override
public void run() {
if(menu == null){
if (menu == null) {
return;
}
conversationCount = Integer.valueOf(webMessage);
@ -1082,7 +1077,7 @@ public class MainActivity extends AppCompatActivity
new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.help_help)
.setMessage(Html.fromHtml(getString(R.string.markdown_text)))
.setPositiveButton(android.R.string.yes,null).show();
.setPositiveButton(android.R.string.yes, null).show();
}
}
}).show();

View file

@ -351,7 +351,6 @@ public class ShareActivity extends MainActivity {
@Override
public void onBackPressed() {
fab.collapse();
if (webView.canGoBack()) {
webView.goBack();
setTitle(R.string.app_name);

View file

@ -14,7 +14,7 @@
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:id="@+id/main__navigaion_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"

View file

@ -24,56 +24,19 @@
<include layout="@layout/main__content" />
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/fab_menubutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_gravity="bottom|end"
android:layout_marginBottom="4dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:visibility="gone"
app:layout_behavior=".ui.FloatingActionsMenuBehavior"
fab:fab_addButtonColorNormal="@color/fab_big"
fab:fab_addButtonColorPressed="@color/fab_big_pressed"
fab:fab_addButtonPlusIconColor="@color/white"
fab:fab_labelStyle="@style/menu_labels_style">
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="fab3_click"
fab:fab_colorNormal="@color/fab_small"
fab:fab_colorPressed="@color/fab_small_pressed"
fab:fab_icon="@drawable/fab_top"
fab:fab_labelStyle="@style/menu_labels_style"
fab:fab_size="mini"
fab:fab_title="@string/fab3_title" />
<android.support.v7.widget.ActionMenuView
android:id="@+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="fab2_click"
fab:fab_colorNormal="@color/fab_small"
fab:fab_colorPressed="@color/fab_small_pressed"
fab:fab_icon="@drawable/fab_search"
fab:fab_labelStyle="@style/menu_labels_style"
fab:fab_size="mini"
fab:fab_title="@string/fab2_title" />
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_compose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="fab1_click"
fab:fab_colorNormal="@color/fab_small"
fab:fab_colorPressed="@color/fab_small_pressed"
fab:fab_icon="@drawable/fab_compose"
fab:fab_size="mini"
fab:fab_title="@string/fab1_title" />
</com.getbase.floatingactionbutton.FloatingActionsMenu>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

View file

@ -0,0 +1,53 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".activity.MainActivity">
<item
android:id="@+id/action_search"
android:icon="@drawable/fab_search"
app:showAsAction="always"
android:title="@string/search_by_tags_or_persons" />
<item
android:id="@+id/action_compose"
android:icon="@drawable/fab_compose"
app:showAsAction="always"
android:title="@string/compose" />
<item
android:id="@+id/action_share"
android:icon="@drawable/ic_share_white_24dp"
android:title="@string/jb_share"
app:showAsAction="always" />
<!--
<item
android:id="@+id/action_share2"
android:icon="@drawable/ic_share_white_24dp"
android:title="@string/jb_share"
app:showAsAction="always" >
<menu>
<item android:id="@+id/item1" android:title="@string/search_alert_people"></item>
<item android:id="@+id/item2" android:title="@string/search_alert_tag"></item>
</menu>
</item> -->
<!-- Keep right most -->
<item
android:id="@+id/action_go_to_top"
android:icon="@drawable/fab_top"
android:title="@string/go_to_top"
app:showAsAction="always"/>
<!-- overflow menu -->
<item
android:id="@+id/action_exit"
android:icon="@drawable/ic_sync_white_24dp"
android:title="@string/exit_app"
app:showAsAction="never" />
</menu>

View file

@ -1,7 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.github.dfa.diaspora_android.activity.MainActivity">
tools:context=".activity.MainActivity">
<item
android:id="@+id/action_notifications"
@ -15,16 +15,4 @@
android:title="@string/messages"
app:showAsAction="always" />
<item
android:id="@+id/action_share"
android:icon="@drawable/ic_share_white_24dp"
android:title="@string/jb_share"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_exit"
android:icon="@drawable/ic_sync_white_24dp"
android:title="@string/exit_app"
app:showAsAction="never" />
</menu>

View file

@ -48,9 +48,9 @@
// Floating Action Buttons - Titles
<string name="fab3_title">Nach oben scrollen</string>
<string name="fab2_title">Suche nach Tags oder Personen …</string>
<string name="fab1_title">Neuer Beitrag</string>
<string name="go_to_top">Nach oben scrollen</string>
<string name="search_by_tags_or_persons">Suche nach Tags oder Personen …</string>
<string name="compose">Neuer Beitrag</string>
<string name="search_alert_title">Suche</string>
<string name="search_alert_tag">nach Tags</string>
@ -147,8 +147,8 @@ along with this program. If not, see http://www.gnu.org/licenses.&lt;br> &lt;br
&lt;i>Die Bilder des Startbildschirms können auf Flickr gefunden werden:
https://www.flickr.com/photos/129581906@N06/sets/72157651933980136/with/16594947123.
Sie wurden von \"Lydia\" veröffentlicht und stehen unter der cc by-nc-sa Lizenz.&lt;/i></string>
<string name="fab2_title_person">Suche nach Personen …</string>
<string name="fab2_title_tag">Suche nach Tags …</string>
<string name="search_by_person">Suche nach Personen …</string>
<string name="search_by_tag">Suche nach Tags …</string>
<string name="splash_screen_description">Startbildschirm</string>
<string name="new_conversations">Ungelesene Unterhaltung. Öffnen?</string>
<string name="new_notifications">Ungelesene Benachrichtigung. Lesen?</string>

View file

@ -81,11 +81,11 @@
// Floating Action Buttons - Titles
<string name="fab3_title">Go to top</string>
<string name="fab2_title">Search by tags or persons</string>
<string name="fab2_title_tag">Search for tag …</string>
<string name="fab2_title_person">Search for person …</string>
<string name="fab1_title">New message</string>
<string name="go_to_top">Go to top</string>
<string name="search_by_tags_or_persons">Search by tags or persons</string>
<string name="search_by_tag">Search for tag …</string>
<string name="search_by_person">Search for person …</string>
<string name="compose">New message</string>
<string name="search_alert_title">Search</string>