Skip to content

Upgrade to actual libs and AndroidX #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ local.properties
.Trashes
ehthumbs.db
Thumbs.db
/.idea
12 changes: 9 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 14 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
compileSdkVersion 30
defaultConfig {
applicationId "at.xtools.pwawrapper"
minSdkVersion 20
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
minSdkVersion 23
targetSdkVersion 30
versionCode 2
versionName "2.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

debug {
minifyEnabled false
debuggable true
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
androidTestImplementation('androidx.test.espresso:espresso-core:3.4.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
implementation 'androidx.appcompat:appcompat:1.3.1'
testImplementation 'junit:junit:4.13.2'
}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="at.xtools.pwawrapper">
<!-- Necessary permissions -->
<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -16,7 +17,8 @@
android:icon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true">
android:supportsRtl="true"
tools:targetApi="n">
<activity android:name="at.xtools.pwawrapper.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/AppTheme.Launch">
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/at/xtools/pwawrapper/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
public class Constants {
public Constants(){}
// Root page
public static String WEBAPP_URL = "https://www.leasingrechnen.at/";
public static String WEBAPP_HOST = "leasingrechnen.at"; // used for checking Intent-URLs
public static final String WEBAPP_URL = "https://www.leasingrechnen.at/";
public static final String WEBAPP_HOST = "leasingrechnen.at"; // used for checking Intent-URLs

// User Agent tweaks
public static boolean POSTFIX_USER_AGENT = true; // set to true to append USER_AGENT_POSTFIX to user agent
public static boolean OVERRIDE_USER_AGENT = false; // set to true to use USER_AGENT instead of default one
public static String USER_AGENT_POSTFIX = "AndroidApp"; // useful for identifying traffic, e.g. in Google Analytics
public static String USER_AGENT = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36";
public static final boolean POSTFIX_USER_AGENT = true; // set to true to append USER_AGENT_POSTFIX to user agent
public static final boolean OVERRIDE_USER_AGENT = false; // set to true to use USER_AGENT instead of default one
public static final String USER_AGENT_POSTFIX = "AndroidApp"; // useful for identifying traffic, e.g. in Google Analytics
public static final String USER_AGENT = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36";

// Constants
// window transition duration in ms
public static int SLIDE_EFFECT = 2200;
public static final int SLIDE_EFFECT = 2200;
// show your app when the page is loaded XX %.
// lower it, if you've got server-side rendering (e.g. to 35),
// bump it up to ~98 if you don't have SSR or a loading screen in your web app
public static int PROGRESS_THRESHOLD = 65;
public static final int PROGRESS_THRESHOLD = 65;
// turn on/off mixed content (both https+http within one page) for API >= 21
public static boolean ENABLE_MIXED_CONTENT = true;
public static final boolean ENABLE_MIXED_CONTENT = true;
}
7 changes: 3 additions & 4 deletions app/src/main/java/at/xtools/pwawrapper/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

import at.xtools.pwawrapper.ui.UIManager;
import at.xtools.pwawrapper.webview.WebViewHelper;

public class MainActivity extends AppCompatActivity {
// Globals
private UIManager uiManager;
private WebViewHelper webViewHelper;
private boolean intentHandled = false;

Expand All @@ -22,7 +20,8 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

// Setup Helpers
uiManager = new UIManager(this);
// Globals
UIManager uiManager = new UIManager(this);
webViewHelper = new WebViewHelper(this, uiManager);

// Setup App
Expand Down
53 changes: 24 additions & 29 deletions app/src/main/java/at/xtools/pwawrapper/ui/UIManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,24 @@

public class UIManager {
// Instance variables
private Activity activity;
private WebView webView;
private ProgressBar progressSpinner;
private ProgressBar progressBar;
private LinearLayout offlineContainer;
private final Activity activity;
private final WebView webView;
private final ProgressBar progressSpinner;
private final ProgressBar progressBar;
private final LinearLayout offlineContainer;
private boolean pageLoaded = false;

public UIManager(Activity activity) {
this.activity = activity;
this.progressBar = (ProgressBar) activity.findViewById(R.id.progressBarBottom);
this.progressSpinner = (ProgressBar) activity.findViewById(R.id.progressSpinner);
this.offlineContainer = (LinearLayout) activity.findViewById(R.id.offlineContainer);
this.webView = (WebView) activity.findViewById(R.id.webView);
this.progressBar = activity.findViewById(R.id.progressBarBottom);
this.progressSpinner = activity.findViewById(R.id.progressSpinner);
this.offlineContainer = activity.findViewById(R.id.offlineContainer);
this.webView = activity.findViewById(R.id.webView);

// set click listener for offline-screen
offlineContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
webView.loadUrl(Constants.WEBAPP_URL);
setOffline(false);
}
offlineContainer.setOnClickListener(v -> {
webView.loadUrl(Constants.WEBAPP_URL);
setOffline(false);
});
}

Expand Down Expand Up @@ -92,21 +89,19 @@ public void setOffline(boolean offline) {

// set icon in recent activity view to a white one to be visible in the app bar
public void changeRecentAppsIcon() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Bitmap iconWhite = BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_appbar);
Bitmap iconWhite = BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_appbar);

TypedValue typedValue = new TypedValue();
Resources.Theme theme = activity.getTheme();
theme.resolveAttribute(R.attr.colorPrimary, typedValue, true);
int color = typedValue.data;
TypedValue typedValue = new TypedValue();
Resources.Theme theme = activity.getTheme();
theme.resolveAttribute(R.attr.colorPrimary, typedValue, true);
int color = typedValue.data;

ActivityManager.TaskDescription description = new ActivityManager.TaskDescription(
activity.getResources().getString(R.string.app_name),
iconWhite,
color
);
activity.setTaskDescription(description);
iconWhite.recycle();
}
ActivityManager.TaskDescription description = new ActivityManager.TaskDescription(
activity.getResources().getString(R.string.app_name),
iconWhite,
color
);
activity.setTaskDescription(description);
iconWhite.recycle();
}
}
48 changes: 16 additions & 32 deletions app/src/main/java/at/xtools/pwawrapper/webview/WebViewHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.xtools.pwawrapper.webview;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
Expand All @@ -26,15 +27,15 @@

public class WebViewHelper {
// Instance variables
private Activity activity;
private UIManager uiManager;
private WebView webView;
private WebSettings webSettings;
private final Activity activity;
private final UIManager uiManager;
private final WebView webView;
private final WebSettings webSettings;

public WebViewHelper(Activity activity, UIManager uiManager) {
this.activity = activity;
this.uiManager = uiManager;
this.webView = (WebView) activity.findViewById(R.id.webView);
this.webView = activity.findViewById(R.id.webView);
this.webSettings = webView.getSettings();
}

Expand Down Expand Up @@ -73,6 +74,7 @@ public void forceCacheIfOffline() {
}

// handles initial setup of webview
@SuppressLint("SetJavaScriptEnabled")
public void setupWebView() {
// accept cookies
CookieManager.getInstance().setAcceptCookie(true);
Expand All @@ -82,20 +84,13 @@ public void setupWebView() {
webSettings.setSupportMultipleWindows(true);

// PWA settings
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
webSettings.setDatabasePath(activity.getApplicationContext().getFilesDir().getAbsolutePath());
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
webSettings.setAppCacheMaxSize(Long.MAX_VALUE);
}
webSettings.setDomStorageEnabled(true);
webSettings.setAppCachePath(activity.getApplicationContext().getCacheDir().getAbsolutePath());
webSettings.setAppCacheEnabled(true);
webSettings.setDatabaseEnabled(true);

// enable mixed content mode conditionally
if (Constants.ENABLE_MIXED_CONTENT
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (Constants.ENABLE_MIXED_CONTENT) {
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
}

Expand Down Expand Up @@ -150,21 +145,16 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
@Deprecated
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
handleLoadError(errorCode);
}
}

@TargetApi(Build.VERSION_CODES.M)
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// new API method calls this on every error for each resource.
// we only want to interfere if the page itself got problems.
String url = request.getUrl().toString();
if (view.getUrl().equals(url)) {
handleLoadError(error.getErrorCode());
}
// new API method calls this on every error for each resource.
// we only want to interfere if the page itself got problems.
String url = request.getUrl().toString();
if (view.getUrl().equals(url)) {
handleLoadError(error.getErrorCode());
}
}
});
Expand Down Expand Up @@ -192,17 +182,13 @@ private void handleLoadError(int errorCode) {
uiManager.setOffline(true);
} else {
// Unsupported Scheme, recover
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
goBack();
}
}, 100);
new Handler().postDelayed(() -> goBack(), 100);
}
}

// handle external urls
private boolean handleUrlLoad(WebView view, String url) {
@SuppressLint("QueryPermissionsNeeded")
private void handleUrlLoad(WebView view, String url) {
// prevent loading content that isn't ours
if (!url.startsWith(Constants.WEBAPP_URL)) {
// stop loading
Expand All @@ -222,13 +208,11 @@ private boolean handleUrlLoad(WebView view, String url) {
showNoAppDialog(activity);
}
// return value for shouldOverrideUrlLoading
return true;
} else {
// let WebView load the page!
// activate loading animation screen
uiManager.setLoading(true);
// return value for shouldOverrideUrlLoading
return false;
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tint="@color/colorPrimary"
app:srcCompat="@drawable/ic_cloud_off_black_48dp" />
app:srcCompat="@drawable/ic_cloud_off_black_48dp"
app:tint="@color/colorPrimary" />

<TextView
android:id="@+id/offlineHeading"
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.android.tools.build:gradle:7.0.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,10 +15,11 @@ buildscript {

allprojects {
repositories {
jcenter()
mavenCentral()
maven {
url "https://maven.google.com"
}
google()
}
}

Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
Expand Down
Loading