ask for display over other apps permission in settings

This commit is contained in:
Harshal Lele 2020-01-25 22:30:49 +05:30
parent 5bc0d2c31b
commit e1145f16f2
2 changed files with 57 additions and 0 deletions

View File

@ -1,12 +1,68 @@
package org.schabi.newpipe.settings; package org.schabi.newpipe.settings;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import androidx.annotation.Nullable;
import com.google.android.material.snackbar.Snackbar;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.util.PermissionHelper;
public class VideoAudioSettingsFragment extends BasePreferenceFragment { public class VideoAudioSettingsFragment extends BasePreferenceFragment {
private SharedPreferences.OnSharedPreferenceChangeListener listener;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
if(s.equals(getString(R.string.minimize_on_exit_key))){
String newSetting = sharedPreferences.getString(s,null);
if(newSetting != null){
if(newSetting.equals(getString(R.string.minimize_on_exit_popup_key))){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getContext())){
Snackbar.make(getListView(),R.string.permission_display_over_apps,Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.settings, new View.OnClickListener() {
@Override
public void onClick(View view) {
PermissionHelper.checkSystemAlertWindowPermission(getContext());
}
})
.show();
}
}
}
}
}
};
}
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.video_audio_settings); addPreferencesFromResource(R.xml.video_audio_settings);
} }
@Override
public void onResume() {
super.onResume();
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(listener);
}
@Override
public void onPause() {
super.onPause();
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(listener);
}
} }

View File

@ -227,6 +227,7 @@
<string name="saved_tabs_invalid_json">Using default tabs, error while reading saved tabs</string> <string name="saved_tabs_invalid_json">Using default tabs, error while reading saved tabs</string>
<string name="restore_defaults">Restore defaults</string> <string name="restore_defaults">Restore defaults</string>
<string name="restore_defaults_confirmation">Do you want to restore the defaults?</string> <string name="restore_defaults_confirmation">Do you want to restore the defaults?</string>
<string name="permission_display_over_apps">Give permission to display over other apps</string>
<!-- error activity --> <!-- error activity -->
<string name="sorry_string">Sorry, that should not have happened.</string> <string name="sorry_string">Sorry, that should not have happened.</string>
<string name="guru_meditation" translatable="false">Guru Meditation.</string> <string name="guru_meditation" translatable="false">Guru Meditation.</string>