Skip to content

Commit

Permalink
Aligned Theming
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Geniola committed Jun 27, 2021
1 parent f5b9b07 commit 9c670a9
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="@string/title_activity_main"
android:theme="@style/Theme.MaterialComponents.NoActionBar"
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar"
/>
<activity
android:name=".PairActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,16 @@ public void onDestroy() {
if (mBroadcastReceiverRegistered) {
unRegisterWifiBroadcastReceiver();
}

// Unregister network callbacks
if (mNetworkCallbackRegistered && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
}


@Override
public void onPause() {
super.onPause();

// Whenever the application is paused, we want to deregister all listeners,
// as the UI might not be available any longer
if (mNetworkCallbackRegistered && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
if (mBroadcastReceiverRegistered) {
unRegisterWifiBroadcastReceiver();
}
}

private void restoreState(Bundle savedState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class ConfigureWifiFragment extends AbstractWifiFragment {
private static final String MQTT_RESOLVE = "Resolving service...";
private static final String COMPLETED = "Completed";

private boolean mPaused = false;


@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -139,6 +141,18 @@ public void onNothingSelected(AdapterView<?> parent) {
});
}

@Override
public void onPause() {
super.onPause();
mPaused = true;
}

@Override
public void onResume() {
super.onResume();
mPaused = false;
}

@Override
public void onDestroy() {
super.onDestroy();
Expand Down Expand Up @@ -204,7 +218,7 @@ protected void onMissingWifiPermissions(String ssid) {
@SneakyThrows(PermissionNotGrantedException.class)
@Override
protected void onWifiPermissionsGranted(String ssid) {
startWifiConnection(ssid, mSelectedWifi.getClearWifiPassword(), null, 20000);
startWifiConnection(ssid, mSelectedWifi.getClearWifiPassword(), null, 60000);
}

@UiThread
Expand Down Expand Up @@ -276,6 +290,11 @@ public void onClick(View v) {

private void notifyResolveCompleted(@Nullable final String hostname,
@Nullable final Integer port) {
// FIXME: Workaround, as it appears there is no way to stop the mNSDManager from
// notifying resolved services ater a network/reconnection (stopping the discovery does
// not help)
if (mPaused)
return;

configureUi(false, COMPLETED, null);

Expand All @@ -287,6 +306,10 @@ private void notifyResolveCompleted(@Nullable final String hostname,
Toast.makeText(requireContext(), "Found a Meross MQTT broker in this LAN", Toast.LENGTH_SHORT).show();
}

// Cancel the timeout task
if (mTimer!=null)
mTimer.cancel();

Runnable r = new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void connectToLocalWifi() {
// Check if we are already connected to such wifi
// TODO: Check comparison happens with double quotes
try {
startWifiConnection(ssid, passphrase, null, 15000);
startWifiConnection(ssid, passphrase, null, 60000);
// Flow starts again from onWifiConnected() / onWifiUnavailable()
} catch (PermissionNotGrantedException e) {
Log.e(TAG, "Missing wifi permissions");
Expand All @@ -158,7 +158,7 @@ private void connectToLocalWifi() {
private void pollDeviceList() {
state = State.VERIFYING_PAIRING_SUCCEEDED;

final long timeout = GregorianCalendar.getInstance().getTimeInMillis() + 30000; // 30 seconds timeout
final long timeout = GregorianCalendar.getInstance().getTimeInMillis() + 60000; // 30 seconds timeout
ScheduledFuture<?> future = worker.schedule(new Runnable() {
private @Nullable DeviceInfo findDevice(Collection<DeviceInfo> devices, String deviceUuid) {
for (DeviceInfo d : devices) {
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/res/layout/activity_pair.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
android:layout_height="wrap_content">

<androidx.appcompat.widget.Toolbar
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
style="@style/Widget.MaterialComponents.Toolbar.Primary" />

</com.google.android.material.appbar.AppBarLayout>

Expand Down
8 changes: 3 additions & 5 deletions app/src/main/res/layout/app_bar_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
android:layout_height="wrap_content">

<androidx.appcompat.widget.Toolbar
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
style="@style/Widget.MaterialComponents.Toolbar.Primary" />

</com.google.android.material.appbar.AppBarLayout>

Expand Down
8 changes: 0 additions & 8 deletions app/src/main/res/values-v21/styles.xml

This file was deleted.

5 changes: 4 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<!-- Customize your theme here. -->
<!--
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
-->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<!--
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
-->

<style name="AppTheme.Launcher">
<item name="android:windowBackground">@drawable/splash</item>
Expand Down

0 comments on commit 9c670a9

Please sign in to comment.