[android] Fix review notes

This commit is contained in:
Dmitry Donskoy 2018-06-01 20:29:18 +03:00 committed by Arsentiy Milchakov
parent 699ce5f655
commit c85a387f01
5 changed files with 29 additions and 20 deletions

View file

@ -4,4 +4,4 @@
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
</WebView>

View file

@ -6,10 +6,9 @@ import android.webkit.WebView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmFragment;
import com.mapswithme.maps.base.OnBackPressListener;
import com.mapswithme.util.Utils;
public class BaseWebViewMwmFragment extends BaseMwmFragment implements OnBackPressListener
public class BaseWebViewMwmFragment extends BaseMwmFragment
{
@Override
public boolean onBackPressed()
@ -19,9 +18,8 @@ public class BaseWebViewMwmFragment extends BaseMwmFragment implements OnBackPre
boolean goBackAllowed = (root = getView()) != null
&& (webView = Utils.castTo(root.findViewById(getWebViewResId()))) != null
&& webView.canGoBack();
if (goBackAllowed){
if (goBackAllowed)
webView.goBack();
}
return goBackAllowed;
}

View file

@ -7,7 +7,6 @@ import com.mapswithme.util.Utils;
public class BaseMwmFragment extends Fragment implements OnBackPressListener
{
@Override
public void onAttach(Context context)
{

View file

@ -225,12 +225,12 @@ public abstract class BaseMwmFragmentActivity extends AppCompatActivity
@Override
public void onBackPressed()
{
FragmentManager manager = getSupportFragmentManager();
if (getFragmentClass() == null)
{
super.onBackPressed();
return;
}
FragmentManager manager = getSupportFragmentManager();
String name = getFragmentClass().getName();
Fragment fragment = manager.findFragmentByTag(name);
@ -240,15 +240,14 @@ public abstract class BaseMwmFragmentActivity extends AppCompatActivity
return;
}
boolean processed = onBackPressedInternal(fragment);
if (processed)
if (onBackPressedInternal(fragment))
{
return;
}
super.onBackPressed();
}
protected boolean onBackPressedInternal(@NonNull @SuppressWarnings("unused") Fragment currentFragment)
protected boolean onBackPressedInternal(@NonNull Fragment currentFragment)
{
return false;
}

View file

@ -1,5 +1,6 @@
package com.mapswithme.maps.bookmarks;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -18,6 +19,8 @@ import java.io.IOException;
public class BookmarksCatalogFragment extends BaseWebViewMwmFragment
{
public static final String EXTRA_BOOKMARKS_CATALOG_URL = "bookmarks_catalog_url";
@SuppressWarnings("NullableProblems")
@NonNull
private String mCatalogUrl;
@ -25,19 +28,12 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment
public void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Bundle args = getArguments();
if ((args == null || (mCatalogUrl = args.getString(EXTRA_BOOKMARKS_CATALOG_URL)) == null)
&& (mCatalogUrl = getActivity().getIntent()
.getStringExtra(EXTRA_BOOKMARKS_CATALOG_URL)) == null)
{
throw new IllegalArgumentException("Catalog url not found in bundle");
}
mCatalogUrl = getCatalogUrlOrThrow();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState)
{
View root = inflater.inflate(R.layout.bookmarks_catalog_frag, container, false);
@ -47,13 +43,30 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment
return root;
}
private void initWebView(WebView webView)
@SuppressLint("SetJavaScriptEnabled")
private void initWebView(@NonNull WebView webView)
{
webView.setWebViewClient(new WebViewBookmarksCatalogClient());
final WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
@NonNull
public String getCatalogUrlOrThrow()
{
Bundle args = getArguments();
String result = args != null ? args.getString(EXTRA_BOOKMARKS_CATALOG_URL) : null;
if (result == null)
{
result = getActivity().getIntent().getStringExtra(EXTRA_BOOKMARKS_CATALOG_URL);
}
if (result == null)
throw new IllegalArgumentException("Catalog url not found in bundle");
return result;
}
private static class WebViewBookmarksCatalogClient extends WebViewClient
{
@Override