Skip to content
This repository was archived by the owner on Jun 5, 2022. It is now read-only.

Commit 477b710

Browse files
committed
Add settings panels on Android 10
- When the user is using Android 10 and some API calls fail, link to the new connctivity settings panel - The button to go to the settings when loading a watcher fails will also be visible on older Android versions and link to the regular network/internet settings
1 parent bfc7c03 commit 477b710

File tree

7 files changed

+61
-28
lines changed

7 files changed

+61
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ An Android front end application for interacting with a [Movie Notifier](https:/
66

77
## Building
88

9-
- *Requires* Android Studio 3.6 RC 1 or newer.
9+
- *Requires* Android Studio 3.6 RC 2 or newer.
1010
- Add the `google-services.json` file from your Firebase project to the `app` module.
1111
- Make sure to add a `gradle.properties` file in the root of the project. An example of the file is [included](https://github.com/jpelgrom/Movie-Notifier-Android/blob/master/gradle.properties.example).

app/src/main/java/nl/jpelgrm/movienotifier/ui/MainActivity.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
144144

145145
@Override
146146
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
147-
switch(requestCode) {
148-
case WatchersFragment.PERMISSION_LOCATION_AUTOMAGIC:
149-
if(getSupportFragmentManager().findFragmentByTag("watchersFragment") != null) {
150-
getSupportFragmentManager().findFragmentByTag("watchersFragment").onRequestPermissionsResult(requestCode, permissions, grantResults);
151-
}
152-
break;
153-
default:
154-
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
155-
break;
147+
if (requestCode == WatchersFragment.PERMISSION_LOCATION_AUTOMAGIC) {
148+
if (getSupportFragmentManager().findFragmentByTag("watchersFragment") != null) {
149+
getSupportFragmentManager().findFragmentByTag("watchersFragment").onRequestPermissionsResult(requestCode, permissions, grantResults);
150+
}
151+
} else {
152+
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
156153
}
157154
}
158155
}

app/src/main/java/nl/jpelgrm/movienotifier/ui/WatcherActivity.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.os.Build;
1515
import android.os.Bundle;
1616
import android.os.Handler;
17+
import android.provider.Settings;
1718
import android.text.Editable;
1819
import android.text.TextWatcher;
1920
import android.util.Patterns;
@@ -264,6 +265,13 @@ public void afterTextChanged(Editable editable) {
264265
});
265266

266267
binding.loaderErrorAccount.setOnClickListener(view -> startActivity(new Intent(WatcherActivity.this, AccountActivity.class)));
268+
binding.loaderErrorSettings.setOnClickListener(view -> {
269+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
270+
startActivity(new Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY));
271+
} else {
272+
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
273+
}
274+
});
267275
binding.loaderErrorButton.setOnClickListener(view -> {
268276
binding.loaderErrorButton.setEnabled(false);
269277
binding.progress.setVisibility(View.VISIBLE);
@@ -397,8 +405,10 @@ public void onResponse(@NonNull Call<Watcher> call, @NonNull Response<Watcher> r
397405
}
398406
} else {
399407
binding.progress.setVisibility(View.GONE);
408+
binding.loaderErrorSettings.setVisibility(View.GONE);
400409

401410
if(response.code() == 400) {
411+
binding.loaderErrorAccount.setVisibility(View.GONE);
402412
binding.loaderErrorText.setText(R.string.error_watcher_400);
403413
binding.loaderErrorButton.setVisibility(View.GONE);
404414
} else {
@@ -426,6 +436,7 @@ public void onFailure(@NonNull Call<Watcher> call, @NonNull Throwable t) {
426436

427437
binding.loaderErrorText.setText(R.string.error_general_exception);
428438
binding.loaderErrorAccount.setVisibility(View.GONE);
439+
binding.loaderErrorSettings.setVisibility(View.VISIBLE);
429440
binding.loaderErrorButton.setEnabled(true);
430441
binding.loaderErrorButton.setVisibility(View.VISIBLE);
431442
binding.loaderError.setVisibility(View.VISIBLE);

app/src/main/java/nl/jpelgrm/movienotifier/ui/WatchersFragment.java

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package nl.jpelgrm.movienotifier.ui;
22

33
import android.Manifest;
4+
import android.app.Activity;
45
import android.content.Context;
56
import android.content.DialogInterface;
67
import android.content.Intent;
78
import android.content.SharedPreferences;
89
import android.content.pm.PackageManager;
910
import android.location.Location;
11+
import android.os.Build;
1012
import android.os.Bundle;
13+
import android.provider.Settings;
1114
import android.view.LayoutInflater;
1215
import android.view.View;
1316
import android.view.ViewGroup;
@@ -46,6 +49,7 @@
4649

4750
public class WatchersFragment extends Fragment {
4851
public static final int PERMISSION_LOCATION_AUTOMAGIC = 153;
52+
public static final int INTENT_CONNECTIVITYPANEL_LIST = 170;
4953

5054
private FragmentWatchersBinding binding;
5155

@@ -176,6 +180,10 @@ public void onFailure(@NonNull Call<List<Watcher>> call, @NonNull Throwable t) {
176180
if(showError) {
177181
snackbar = Snackbar.make(binding.coordinator, R.string.error_general_exception_short, Snackbar.LENGTH_INDEFINITE);
178182
snackbar.setAnchorView(binding.fab);
183+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
184+
snackbar.setAction(R.string.error_general_exception_settings,
185+
view -> startActivityForResult(new Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY), INTENT_CONNECTIVITYPANEL_LIST));
186+
}
179187
snackbar.show();
180188
}
181189
}
@@ -430,21 +438,30 @@ public Context getContext() {
430438
}
431439
}
432440

441+
@Override
442+
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
443+
if (requestCode == INTENT_CONNECTIVITYPANEL_LIST) {
444+
if (resultCode == Activity.RESULT_OK) {
445+
refreshList(false, true);
446+
}
447+
} else {
448+
super.onActivityResult(requestCode, resultCode, data);
449+
}
450+
}
451+
433452
@Override
434453
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
435-
switch(requestCode) {
436-
case PERMISSION_LOCATION_AUTOMAGIC:
437-
if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
438-
settings.edit().putInt("prefAutomagicLocation", 1).apply();
439-
startLocation();
440-
} else {
441-
snackbar = Snackbar.make(binding.coordinator, R.string.settings_general_location_permission_denied, Snackbar.LENGTH_LONG);
442-
snackbar.setAnchorView(binding.fab);
443-
snackbar.show();
444-
settings.edit().putInt("prefAutomagicLocation", 0).apply();
445-
}
446-
binding.automagicSuggestion.setVisibility(View.GONE);
447-
break;
454+
if (requestCode == PERMISSION_LOCATION_AUTOMAGIC) {
455+
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
456+
settings.edit().putInt("prefAutomagicLocation", 1).apply();
457+
startLocation();
458+
} else {
459+
snackbar = Snackbar.make(binding.coordinator, R.string.settings_general_location_permission_denied, Snackbar.LENGTH_LONG);
460+
snackbar.setAnchorView(binding.fab);
461+
snackbar.show();
462+
settings.edit().putInt("prefAutomagicLocation", 0).apply();
463+
}
464+
binding.automagicSuggestion.setVisibility(View.GONE);
448465
}
449466
}
450467
}

app/src/main/res/layout/activity_watcher.xml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,15 +438,22 @@
438438
android:layout_width="wrap_content"
439439
android:layout_height="wrap_content"
440440
android:text="@string/user_add_title"
441-
android:visibility="gone"
442-
style="@style/Widget.AppCompat.Button.Borderless.Colored"/>
441+
android:layout_marginBottom="8dp"
442+
android:visibility="gone"/>
443+
444+
<Button
445+
android:id="@+id/loaderErrorSettings"
446+
android:layout_width="wrap_content"
447+
android:layout_height="wrap_content"
448+
android:text="@string/error_general_exception_settings"
449+
android:layout_marginBottom="8dp"
450+
style="@style/Widget.MaterialComponents.Button.OutlinedButton"/>
443451

444452
<Button
445453
android:id="@+id/loaderErrorButton"
446454
android:layout_width="wrap_content"
447455
android:layout_height="wrap_content"
448-
android:text="@string/retry"
449-
style="@style/Widget.AppCompat.Button.Borderless.Colored"/>
456+
android:text="@string/retry"/>
450457

451458
</LinearLayout>
452459

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
<string name="error_general_401">Please log in to an account or register.</string>
180180
<string name="error_general_exception">Oops! We encountered an error. Please make sure you have a working network connection and try again.</string>
181181
<string name="error_general_exception_short">Oops! Check your connection and try again.</string>
182+
<string name="error_general_exception_settings">Settings</string>
182183
<string name="error_general_message">Oops! We encountered an issue. Please try again. You may find this information useful:\n%1$s</string>
183184
<string name="error_general_server">Oops! The server encountered an error. Please try again. You may find this information useful:\n%1$s</string>
184185
<string name="error_general_server_short">Oops! Please try again (%1$s).</string>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.6.0-rc01'
10+
classpath 'com.android.tools.build:gradle:3.6.0-rc02'
1111

1212
// NOTE: Do not place your application dependencies here; they belong
1313
// in the individual module build.gradle files

0 commit comments

Comments
 (0)