diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java index 40890a42..7d83c39c 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java @@ -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�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�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(); diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/ShareActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/ShareActivity.java index 666f061b..92f98797 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/ShareActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/ShareActivity.java @@ -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); diff --git a/app/src/main/res/layout/main__activity.xml b/app/src/main/res/layout/main__activity.xml index 3d1475f5..d964f809 100644 --- a/app/src/main/res/layout/main__activity.xml +++ b/app/src/main/res/layout/main__activity.xml @@ -14,7 +14,7 @@ android:layout_height="match_parent" /> - + android:layout_height="wrap_content" + android:theme="@style/AppTheme.AppBarOverlay"> - + - - - - - + \ No newline at end of file diff --git a/app/src/main/res/menu/main__menu_bottom.xml b/app/src/main/res/menu/main__menu_bottom.xml new file mode 100644 index 00000000..e5fe5a27 --- /dev/null +++ b/app/src/main/res/menu/main__menu_bottom.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/main__menu.xml b/app/src/main/res/menu/main__menu_top.xml similarity index 57% rename from app/src/main/res/menu/main__menu.xml rename to app/src/main/res/menu/main__menu_top.xml index ec8ad3ca..f1b0d37b 100644 --- a/app/src/main/res/menu/main__menu.xml +++ b/app/src/main/res/menu/main__menu_top.xml @@ -1,7 +1,7 @@ + tools:context=".activity.MainActivity"> - - - - diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 17407c3f..de488afd 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -48,9 +48,9 @@ // Floating Action Buttons - Titles - Nach oben scrollen - Suche nach Tags oder Personen … - Neuer Beitrag + Nach oben scrollen + Suche nach Tags oder Personen … + Neuer Beitrag Suche nach Tags @@ -147,8 +147,8 @@ along with this program. If not, see http://www.gnu.org/licenses.<br> <br <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.</i> - Suche nach Personen … - Suche nach Tags … + Suche nach Personen … + Suche nach Tags … Startbildschirm Ungelesene Unterhaltung. Öffnen? Ungelesene Benachrichtigung. Lesen? diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bd2af4f4..3eca4b72 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -81,11 +81,11 @@ // Floating Action Buttons - Titles - Go to top - Search by tags or persons - Search for tag … - Search for person … - New message + Go to top + Search by tags or persons + Search for tag … + Search for person … + New message Search