Skip to content
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

Fix #963 #965

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public class PreferencesActivity extends PreferenceActivity
/**
* Initialize the activity, loading the preference specifications.
*/
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState)
{
Expand Down Expand Up @@ -101,6 +100,16 @@ public void onSharedPreferenceChanged (SharedPreferences sharedPreferences, Stri
}
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix for the back button, right?

Why do we need the onStart overrides?

Copy link
Contributor Author

@wchen342 wchen342 Jun 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is related to the old problem with the back behavior #935. I found the previous fixes only work for O, but not below N it will display a blank page instead of going back immediately.

switch (item.getItemId()) {
case android.R.id.home:
this.onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}

public static class AudioFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState)
Expand Down Expand Up @@ -167,9 +176,15 @@ public void onCreate(Bundle savedInstanceState)
} catch (Exception e) {
// ignored. Whee!
}
}

@Override
public void onStart() {
super.onStart();
FragmentManager fragmentManager = getFragmentManager();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || !fragmentManager.isStateSaved()) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
getActivity().onBackPressed();
} else {
fragmentManager.popBackStack();
}
}
Expand Down Expand Up @@ -244,12 +259,19 @@ public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

Activity activity = getActivity();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/vanilla-music/vanilla-music.github.io/wiki"));
if (intent != null) {
startActivity(intent);
}
activity.finish();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
getActivity().onBackPressed();
}

@Override
public void onStart() {
super.onStart();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
getActivity().onBackPressed();
}
}

Expand All @@ -275,15 +297,11 @@ public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

Activity activity = getActivity();
final Activity activity = getActivity();
Intent intent = activity.getPackageManager().getLaunchIntentForPackage(VPLUG_PACKAGE_NAME);

if (intent != null) {
startActivity(intent);
FragmentManager fragmentManager = getFragmentManager();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || !fragmentManager.isStateSaved()) {
fragmentManager.popBackStack();
}
} else {
// package is not installed, ask user to install it
new AlertDialog.Builder(activity)
Expand All @@ -294,17 +312,31 @@ public void onClick(DialogInterface dialog, int id) {
Intent marketIntent = new Intent(Intent.ACTION_VIEW);
marketIntent.setData(Uri.parse("market://details?id="+VPLUG_PACKAGE_NAME));
startActivity(marketIntent);
getActivity().onBackPressed();
activity.onBackPressed();
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
getActivity().onBackPressed();
activity.onBackPressed();
}
})
.show();
}
}

@Override
public void onStart() {
super.onStart();
Activity activity = getActivity();
Intent intent = activity.getPackageManager().getLaunchIntentForPackage(VPLUG_PACKAGE_NAME);
FragmentManager fragmentManager = getFragmentManager();
if (intent != null)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
activity.onBackPressed();
} else {
fragmentManager.popBackStack();
}
}
}

@Override
Expand Down