Skip to content

Commit 9448138

Browse files
feat: add offline screen
1 parent 737421c commit 9448138

File tree

8 files changed

+92
-4
lines changed

8 files changed

+92
-4
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.undershows.app"
1111
minSdk 26
1212
targetSdk 35
13-
versionCode 1
14-
versionName "1.0"
13+
versionCode 2
14+
versionName "1.0.0"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
}

app/release/app-release.aab

4.07 MB
Binary file not shown.

app/release/undershows_1_0_0.aab

4.07 MB
Binary file not shown.

app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:tools="http://schemas.android.com/tools">
44

55
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
67

78
<application
89
android:allowBackup="true"
@@ -14,16 +15,21 @@
1415
android:supportsRtl="true"
1516
android:theme="@style/Theme.Undershows"
1617
tools:targetApi="31">
18+
1719
<activity
1820
android:name=".MainActivity"
1921
android:exported="true"
2022
android:screenOrientation="portrait">
2123
<intent-filter>
2224
<action android:name="android.intent.action.MAIN" />
23-
2425
<category android:name="android.intent.category.LAUNCHER" />
2526
</intent-filter>
2627
</activity>
28+
29+
<activity
30+
android:name=".NoInternetActivity"
31+
android:exported="true"
32+
android:screenOrientation="portrait" />
2733
</application>
2834

2935
</manifest>

app/src/main/java/com/undershows/app/MainActivity.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package com.undershows.app;
22

3+
import com.undershows.app.NoInternetActivity;
34
import android.os.Bundle;
45
import android.webkit.WebView;
56
import android.webkit.WebViewClient;
67
import android.content.Intent;
78
import android.net.Uri;
9+
import android.net.ConnectivityManager;
10+
import android.net.NetworkInfo;
11+
import android.content.Context;
12+
import android.widget.Toast;
813
import androidx.appcompat.app.AppCompatActivity;
914

1015
public class MainActivity extends AppCompatActivity {
@@ -18,6 +23,7 @@ protected void onCreate(Bundle savedInstanceState) {
1823
webView = findViewById(R.id.webview);
1924
webView.getSettings().setJavaScriptEnabled(true);
2025
webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 10; Mobile) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Mobile Safari/537.36");
26+
2127
webView.setWebViewClient(new WebViewClient() {
2228
@Override
2329
public boolean shouldOverrideUrlLoading(WebView view, String url) {
@@ -29,7 +35,20 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
2935
return false;
3036
}
3137
});
32-
webView.loadUrl("https://shows.undershows.com.br");
38+
39+
if (isConnected()) {
40+
webView.loadUrl("https://shows.undershows.com.br");
41+
} else {
42+
Intent intent = new Intent(this, NoInternetActivity.class);
43+
startActivity(intent);
44+
finish();
45+
}
46+
}
47+
48+
private boolean isConnected() {
49+
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
50+
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
51+
return (networkInfo != null && networkInfo.isConnected());
3352
}
3453

3554
@Override
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.undershows.app;
2+
3+
import android.os.Bundle;
4+
import androidx.appcompat.app.AppCompatActivity;
5+
6+
public class NoInternetActivity extends AppCompatActivity {
7+
@Override
8+
protected void onCreate(Bundle savedInstanceState) {
9+
super.onCreate(savedInstanceState);
10+
setContentView(R.layout.activity_no_internet);
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
<WebView
7+
android:id="@+id/webview"
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent" />
10+
</RelativeLayout>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:background="#000000"
6+
android:orientation="vertical"
7+
android:gravity="center"
8+
android:padding="24dp">
9+
10+
<LinearLayout
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:orientation="vertical"
14+
android:background="#121212"
15+
android:padding="24dp"
16+
android:gravity="center"
17+
android:layout_margin="16dp"
18+
android:elevation="6dp"
19+
android:layout_gravity="center"
20+
android:backgroundTint="#1E1E1E"
21+
android:clipToOutline="true">
22+
23+
<ImageView
24+
android:id="@+id/logo_offline"
25+
android:layout_width="150dp"
26+
android:layout_height="150dp"
27+
android:layout_marginBottom="16dp"
28+
android:src="@mipmap/ic_launcher" />
29+
30+
<TextView
31+
android:id="@+id/text_offline"
32+
android:layout_width="wrap_content"
33+
android:layout_height="wrap_content"
34+
android:text="Sem internet!\nConecte seu Wi-Fi ou 3G/4G/5G para usar o app.\nDepois, feche e reabra o app."
35+
android:textColor="#FFFFFF"
36+
android:textSize="16sp"
37+
android:textAlignment="center" />
38+
</LinearLayout>
39+
40+
</LinearLayout>
41+

0 commit comments

Comments
 (0)