Skip to content

Commit

Permalink
Included feature no internet connection handler
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelf03kai committed Jan 6, 2024
1 parent f340587 commit c0a4028
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .idea/vcs.xml

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

1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!--<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />-->

<application
android:allowBackup="true"
Expand Down
Binary file added app/src/main/ic_no_connection-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
247 changes: 153 additions & 94 deletions app/src/main/java/com/miguelf03kai/weatherapp/MainActivity.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.miguelf03kai.weatherapp.utils;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Connection {

// Check if the device have internet connection
public static boolean checkConnection(ConnectivityManager connectivityManager){
boolean connected = (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
.getState() == NetworkInfo.State.CONNECTED || connectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED);

return connected;
}
}
36 changes: 36 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,40 @@

</RelativeLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/noConnectionRelativeLayout"
android:visibility="gone">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:background="@mipmap/ic_no_connection"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:minHeight="80dp"
android:minWidth="80dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Please check your connection!"
android:id="@+id/textView2"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"
android:textColor="#ffffff" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Try Again"
android:id="@+id/button"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="48dp" />
</RelativeLayout>

</RelativeLayout>
Binary file added app/src/main/res/mipmap-hdpi/ic_no_connection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-mdpi/ic_no_connection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c0a4028

Please sign in to comment.