diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 451dad0e..d89beb83 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -37,8 +37,7 @@ 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 3026ceda..b7f9884b 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 @@ -138,10 +138,11 @@ public class MainActivity extends AppCompatActivity ContextMenuWebView webView; @BindView(R.id.main__navigaion_view) - NavigationView navigationView; + NavigationView navView; + + @BindView(R.id.main__layout) + DrawerLayout navDrawer; - @BindView(R.id.drawer_layout) - DrawerLayout drawer; // NavHeader cannot be bound by Butterknife private TextView navheaderTitle; @@ -171,6 +172,7 @@ public class MainActivity extends AppCompatActivity this.registerForContextMenu(webView); webView.setParentActivity(this); + webView.setOverScrollMode(WebView.OVER_SCROLL_ALWAYS); // Setup toolbar setSupportActionBar(toolbarTop); @@ -181,7 +183,6 @@ public class MainActivity extends AppCompatActivity } }); - // Load app settings setupNavigationSlider(); @@ -191,6 +192,7 @@ public class MainActivity extends AppCompatActivity swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary, R.color.fab_big); + // Setup WebView webView.addJavascriptInterface(new JavaScriptInterface(), "AndroidBridge"); if (savedInstanceState != null) { webView.restoreState(savedInstanceState); @@ -313,14 +315,14 @@ public class MainActivity extends AppCompatActivity private void setupNavigationSlider() { ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( - this, drawer, toolbarTop, R.string.navigation_drawer_open, R.string.navigation_drawer_close); - drawer.addDrawerListener(toggle); + this, navDrawer, toolbarTop, R.string.navigation_drawer_open, R.string.navigation_drawer_close); + navDrawer.addDrawerListener(toggle); toggle.syncState(); - //NavigationView navigationView = ButterKnife.findById(this, R.id.nav_view); - navigationView.setNavigationItemSelectedListener(this); + //NavigationView navView = ButterKnife.findById(this, R.id.nav_view); + navView.setNavigationItemSelectedListener(this); - View navHeader = navigationView.getHeaderView(0); + View navHeader = navView.getHeaderView(0); navheaderTitle = ButterKnife.findById(navHeader, R.id.navheader_title); navheaderDescription = ButterKnife.findById(navHeader, R.id.podselection__podupti_notice); navheaderImage = ButterKnife.findById(navHeader, R.id.navheader_user_image); @@ -342,7 +344,7 @@ public class MainActivity extends AppCompatActivity @OnClick(R.id.toolbar) public void onToolBarClicked(View view) { - onNavigationItemSelected(navigationView.getMenu().findItem(R.id.nav_stream)); + onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream)); } private File createImageFile() throws IOException { @@ -403,8 +405,8 @@ public class MainActivity extends AppCompatActivity @Override public void onBackPressed() { - if (drawer.isDrawerOpen(navigationView)) { - drawer.closeDrawer(navigationView); + if (navDrawer.isDrawerOpen(navView)) { + navDrawer.closeDrawer(navView); return; } @@ -1035,7 +1037,7 @@ public class MainActivity extends AppCompatActivity break; } - DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); + DrawerLayout drawer = (DrawerLayout) findViewById(R.id.main__layout); drawer.closeDrawer(GravityCompat.START); return true; } 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 92f98797..8fcafdee 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 @@ -20,9 +20,6 @@ package com.github.dfa.diaspora_android.activity; import android.annotation.SuppressLint; -import android.annotation.TargetApi; -import android.app.AlertDialog; -import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Build; @@ -33,8 +30,6 @@ import android.support.design.widget.Snackbar; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.Toolbar; import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; import android.view.View; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; @@ -50,7 +45,6 @@ import com.github.dfa.diaspora_android.util.Helpers; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Date; public class ShareActivity extends MainActivity { @@ -163,7 +157,7 @@ public class ShareActivity extends MainActivity { takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { // Error occurred while creating the File - Snackbar.make(getWindow().findViewById(R.id.drawer_layout), "Unable to get image", Snackbar.LENGTH_LONG).show(); + Snackbar.make(getWindow().findViewById(R.id.main__layout), "Unable to get image", Snackbar.LENGTH_LONG).show(); } // Continue only if the File was successfully created @@ -202,7 +196,7 @@ public class ShareActivity extends MainActivity { if (Helpers.isOnline(ShareActivity.this)) { webView.loadUrl("https://" + podDomain + "/status_messages/new"); } else { - Snackbar.make(getWindow().findViewById(R.id.drawer_layout), R.string.no_internet, Snackbar.LENGTH_LONG).show(); + Snackbar.make(getWindow().findViewById(R.id.main__layout), R.string.no_internet, Snackbar.LENGTH_LONG).show(); } } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/listener/SoftKeyboardStateWatcher.java b/app/src/main/java/com/github/dfa/diaspora_android/listener/SoftKeyboardStateWatcher.java deleted file mode 100644 index 0e44d277..00000000 --- a/app/src/main/java/com/github/dfa/diaspora_android/listener/SoftKeyboardStateWatcher.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.github.dfa.diaspora_android.listener; - -/** - * Created by juergen on 25.03.16. Part of Diaspora for Android. - * solution found on: http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android - */ - -import android.graphics.Rect; -import android.view.View; -import android.view.ViewTreeObserver; - -import java.util.LinkedList; -import java.util.List; - -public class SoftKeyboardStateWatcher implements ViewTreeObserver.OnGlobalLayoutListener { - - private final List listeners = new LinkedList<>(); - private final View activityRootView; - private int lastSoftKeyboardHeightInPx; - private boolean isSoftKeyboardOpened; - public SoftKeyboardStateWatcher(View activityRootView) { - this(activityRootView, false); - } - - public SoftKeyboardStateWatcher(View activityRootView, boolean isSoftKeyboardOpened) { - this.activityRootView = activityRootView; - this.isSoftKeyboardOpened = isSoftKeyboardOpened; - activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(this); - } - - @Override - public void onGlobalLayout() { - final Rect r = new Rect(); - //r will be populated with the coordinates of your view that area still visible. - activityRootView.getWindowVisibleDisplayFrame(r); - - final int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top); - if (!isSoftKeyboardOpened && heightDiff > 100) { // if more than 100 pixels, its probably a keyboard... - isSoftKeyboardOpened = true; - notifyOnSoftKeyboardOpened(heightDiff); - } else if (isSoftKeyboardOpened && heightDiff < 100) { - isSoftKeyboardOpened = false; - notifyOnSoftKeyboardClosed(); - } - } - - public void setIsSoftKeyboardOpened(boolean isSoftKeyboardOpened) { - this.isSoftKeyboardOpened = isSoftKeyboardOpened; - } - - public boolean isSoftKeyboardOpened() { - return isSoftKeyboardOpened; - } - - /** - * Default value is zero {@code 0}. - * - * @return last saved keyboard height in px - */ - public int getLastSoftKeyboardHeightInPx() { - return lastSoftKeyboardHeightInPx; - } - - public void addSoftKeyboardStateListener(SoftKeyboardStateListener listener) { - listeners.add(listener); - } - - public void removeSoftKeyboardStateListener(SoftKeyboardStateListener listener) { - listeners.remove(listener); - } - - private void notifyOnSoftKeyboardOpened(int keyboardHeightInPx) { - this.lastSoftKeyboardHeightInPx = keyboardHeightInPx; - - for (SoftKeyboardStateListener listener : listeners) { - if (listener != null) { - listener.onSoftKeyboardOpened(keyboardHeightInPx); - } - } - } - - private void notifyOnSoftKeyboardClosed() { - for (SoftKeyboardStateListener listener : listeners) { - if (listener != null) { - listener.onSoftKeyboardClosed(); - } - } - } - - public interface SoftKeyboardStateListener { - void onSoftKeyboardOpened(int keyboardHeightInPx); - - void onSoftKeyboardClosed(); - } -} diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java b/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java index b80250c2..d71adccf 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java @@ -51,6 +51,8 @@ public class Helpers { public static void hideTopBar(final WebView wv) { wv.loadUrl("javascript: ( function() {" + + " document.documentElement.style.paddingBottom = '260px';" + + " document.getElementById('main').style.paddingTop = '5px';" + " if(document.getElementById('main_nav')) {" + " document.getElementById('main_nav').parentNode.removeChild(" + " document.getElementById('main_nav'));" + diff --git a/app/src/main/res/layout/main__activity.xml b/app/src/main/res/layout/main__activity.xml index d964f809..ca41fb0a 100644 --- a/app/src/main/res/layout/main__activity.xml +++ b/app/src/main/res/layout/main__activity.xml @@ -2,7 +2,7 @@