Skip to content

Commit

Permalink
Tweaked NestedScrollViews
Browse files Browse the repository at this point in the history
  • Loading branch information
evilbunny2008 committed Jan 18, 2023
1 parent 4a2e7eb commit 83b7123
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 192 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.odiousapps.weewxweather"
minSdkVersion 23
targetSdkVersion 33
versionCode 1000008
versionName "1.0.8"
versionCode 1000010
versionName "1.0.10"
}
buildTypes {
release {
Expand All @@ -26,7 +26,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.github.smart-fun:XmlToJson:1.5.2'
Expand Down
22 changes: 10 additions & 12 deletions app/src/main/java/com/odiousapps/weewxweather/Custom.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.odiousapps.weewxweather;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -39,29 +37,28 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
wv = rootView.findViewById(R.id.custom);
wv.getSettings().setUserAgentString(Common.UA);
wv.getSettings().setJavaScriptEnabled(true);
wv.setOnLongClickListener(v ->
{
Vibrator vibrator = (Vibrator)common.context.getSystemService(Context.VIBRATOR_SERVICE);
if(vibrator != null)
vibrator.vibrate(250);
Common.LogMessage("long press");
reloadWebView();
return true;
});

WebSettings settings = wv.getSettings();
settings.setDomStorageEnabled(true);

swipeLayout = rootView.findViewById(R.id.swipeToRefresh);
swipeLayout.setOnRefreshListener(() ->
{
Common.LogMessage("wv.getScrollY() == " + wv.getScrollY());
swipeLayout.setRefreshing(true);
Common.LogMessage("onRefresh();");
reloadWebView();
swipeLayout.setRefreshing(false);
});

wv.getViewTreeObserver().addOnScrollChangedListener(() -> swipeLayout.setEnabled(wv.getScrollY() == 0));
wv.getViewTreeObserver().addOnScrollChangedListener(() ->
{
Common.LogMessage("wv.getScrollY() == " + wv.getScrollY());
if(wv.getScrollY() == 0)
swipeLayout.setEnabled(true);
else
swipeLayout.setEnabled(false);
});

wv.setWebViewClient(new WebViewClient()
{
Expand Down Expand Up @@ -119,6 +116,7 @@ private void reloadWebView()
if(custom_url != null && !custom_url.equals(""))
custom = custom_url;

wv.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
wv.loadUrl(custom);
}

Expand Down
37 changes: 0 additions & 37 deletions app/src/main/java/com/odiousapps/weewxweather/Forecast.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Vibrator;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -56,18 +55,6 @@ public class Forecast extends Fragment
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
rootView = inflater.inflate(R.layout.fragment_forecast, container, false);
rootView.setOnLongClickListener(v ->
{
Vibrator vibrator = (Vibrator) common.context.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator != null)
vibrator.vibrate(250);
swipeLayout.setRefreshing(true);
Common.LogMessage("rootview long press");
reloadWebView(true);
getForecast(true);
return true;
});

swipeLayout = rootView.findViewById(R.id.swipeToRefresh);
swipeLayout.setOnRefreshListener(() ->
{
Expand Down Expand Up @@ -95,18 +82,6 @@ public boolean onConsoleMessage(ConsoleMessage cm)
}
});

wv1.setOnLongClickListener(v ->
{
Vibrator vibrator = (Vibrator) common.context.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator != null)
vibrator.vibrate(250);
swipeLayout.setRefreshing(true);
Common.LogMessage("webview long press");
reloadWebView(true);
getForecast(true);
return true;
});

wv1.setWebViewClient(new WebViewClient()
{
@Override
Expand All @@ -132,18 +107,6 @@ public boolean onConsoleMessage(ConsoleMessage cm)
}
});

wv2.setOnLongClickListener(v ->
{
Vibrator vibrator = (Vibrator) common.context.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator != null)
vibrator.vibrate(250);
swipeLayout.setRefreshing(true);
Common.LogMessage("webview long press");
reloadWebView(true);
getForecast(true);
return true;
});

wv2.setWebViewClient(new WebViewClient()
{
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Objects;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
Expand Down Expand Up @@ -94,17 +93,15 @@ protected void onCreate(Bundle savedInstanceState)
mSectionsPagerAdapter.addFragment(new Custom(common));

ViewPager2 mViewPager = findViewById(R.id.container);
//mViewPager.setUserInputEnabled(false);
mViewPager.setAdapter(mSectionsPagerAdapter);
String[] tabTitles;
if(common.GetBoolPref("radarforecast", true))
tabTitles = new String[]{getString(R.string.weather2), getString(R.string.stats2), getString(R.string.radar), getString(R.string.webcam2), getString(R.string.custom2)};
else
tabTitles = new String[]{getString(R.string.weather2), getString(R.string.stats2), getString(R.string.forecast2), getString(R.string.webcam2), getString(R.string.custom2)};
else
tabTitles = new String[]{getString(R.string.weather2), getString(R.string.stats2), getString(R.string.radar), getString(R.string.webcam2), getString(R.string.custom2)};
new TabLayoutMediator(tabLayout, mViewPager, ((tab, position) -> tab.setText(tabTitles[position]))).attach();

if(!common.GetBoolPref("radarforecast", true))
Objects.requireNonNull(tabLayout.getTabAt(2)).setText(R.string.radar);

try
{
if(common.GetStringPref("BASE_URL", "").equals(""))
Expand Down
21 changes: 0 additions & 21 deletions app/src/main/java/com/odiousapps/weewxweather/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Vibrator;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -51,16 +50,6 @@ public class Stats extends Fragment
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
rootView = inflater.inflate(R.layout.fragment_stats, container, false);
rootView.setOnLongClickListener(v ->
{
Vibrator vibrator = (Vibrator)common.context.getSystemService(Context.VIBRATOR_SERVICE);
if(vibrator != null)
vibrator.vibrate(250);
Common.LogMessage("rootview long press");
forceRefresh();
return true;
});

swipeLayout = rootView.findViewById(R.id.swipeToRefresh);
swipeLayout.setOnRefreshListener(() ->
{
Expand All @@ -72,16 +61,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

wv = rootView.findViewById(R.id.webView1);
wv.getSettings().setUserAgentString(Common.UA);
wv.setOnLongClickListener(v ->
{
Vibrator vibrator = (Vibrator)common.context.getSystemService(Context.VIBRATOR_SERVICE);
if(vibrator != null)
vibrator.vibrate(250);
Common.LogMessage("webview long press");
forceRefresh();
return true;
});

wv.getViewTreeObserver().addOnScrollChangedListener(() -> swipeLayout.setEnabled(wv.getScrollY() == 0));

ll1 = rootView.findViewById(R.id.ll1);
Expand Down
Loading

0 comments on commit 83b7123

Please sign in to comment.