Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #524 from a93h/master
Browse files Browse the repository at this point in the history
Resolves #520 to #523
  • Loading branch information
Austin H authored Sep 14, 2019
2 parents b315f78 + 19f0fcb commit b820930
Show file tree
Hide file tree
Showing 18 changed files with 193 additions and 375 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.adam.aslfms"
minSdkVersion 14
targetSdkVersion 26
versionCode = 55
versionName = "1.6.4"
versionCode = 56
versionName = "1.6.5"

testApplicationId "com.adam.aslfms.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,6 @@
<action android:name="com.adam.aslfms.service.copy" />
</intent-filter>
</service>
<service
android:name=".service.NotificationBarService"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.adam.aslfms.service.notificationbarupdate" />
</intent-filter>
</service>
<service
android:name=".service.ControllerReceiverService"
android:enabled="true"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/assets/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ Visit,
https://github.com/simple-last-fm-scrobbler/sls
For more details.

- 1.6.5 (2019-9-13) codename: hingus
* Better Service Management
* Update Permissions UI
* Fixed Notification Priority

- 1.6.4 (2019-9-10) codename: gingus
* UI ListenBrainz Login Bug
* Changelog 2019
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/adam/aslfms/ChangeThemeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Resources.Theme getTheme() {
settings = new AppSettings(this);
Resources.Theme theme = super.getTheme();
theme.applyStyle(settings.getAppTheme(), true);
Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
//Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
// you could also use a switch if you have many themes that could apply
return theme;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/adam/aslfms/MusicAppsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Resources.Theme getTheme() {
settings = new AppSettings(this);
Resources.Theme theme = super.getTheme();
theme.applyStyle(settings.getAppTheme(), true);
Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
//Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
// you could also use a switch if you have many themes that could apply
return theme;
}
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/com/adam/aslfms/OptionsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Resources.Theme getTheme() {
settings = new AppSettings(this);
Resources.Theme theme = super.getTheme();
theme.applyStyle(settings.getAppTheme(), true);
Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
//Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
// you could also use a switch if you have many themes that could apply
return theme;
}
Expand Down Expand Up @@ -210,7 +210,10 @@ public void create() {
notification_priority.setDefaultValue(Util.notificationStringToInt(getApplicationContext()));
languages_list = (ListPreference) findPreference(KEY_LANGUAGES_LIST);
notification_priority.setOnPreferenceChangeListener((Preference preference, Object object) -> {
settings.setKeyNotificationPriority(notification_priority.getValue());
String[] strings = getResources().getStringArray(R.array.notification_priority_list);
String string = (String) object;
int position = Arrays.asList(strings).indexOf(string);
settings.setKeyNotificationPriority(position);
return false;
}
);
Expand Down Expand Up @@ -242,7 +245,7 @@ public void create() {
public boolean onClick(Preference pref) {
if (pref == active_app) {
settings.setActiveAppEnabled(power, active_app.isChecked());
Util.runServices(pref.getContext()); // Scrobbler, Controller, Notification
Util.runServices(pref.getContext());
} else if (pref == scrobble) {
settings.setScrobblingEnabled(power, scrobble.isChecked());
return true;
Expand Down
181 changes: 81 additions & 100 deletions app/src/main/java/com/adam/aslfms/PermissionsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
Expand All @@ -39,6 +40,7 @@
import android.widget.TextView;

import com.adam.aslfms.util.AppSettings;
import com.adam.aslfms.util.InternalTrackTransmitter;
import com.adam.aslfms.util.MyContextWrapper;
import com.adam.aslfms.util.Util;
/**
Expand All @@ -50,13 +52,16 @@ public class PermissionsActivity extends AppCompatActivity {
private static final String TAG = "PermissionsActivity";

int WRITE_EXTERNAL_STORAGE;
int REQUEST_IGNORE_BATTERY_OPTIMIZATIONS;
int disabledColor = Color.argb(25, 0,0,0);
int enabledColor = Color.argb(75, 0,255,0);
int warningColor = Color.argb(80,255,0,0);

AppSettings settings = null;
Button btnSkip = null;
Button skipBtn = null;
Button continueBtn = null;
Button externalPermBtn = null;
Button notifiPermBtn = null;
Button batteryPermBtn = null;
Context ctx = this;

@Override
Expand All @@ -69,16 +74,15 @@ public Resources.Theme getTheme() {
settings = new AppSettings(this);
Resources.Theme theme = super.getTheme();
theme.applyStyle(settings.getAppTheme(), true);
Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
//Log.d(TAG, getResources().getResourceName(settings.getAppTheme()));
// you could also use a switch if you have many themes that could apply
return theme;
}

@Override
protected void onResume() {
super.onResume();
checkCurrrentPermissions();
permsCheck();
checkAndSetColors();
}

@Override
Expand All @@ -89,120 +93,109 @@ protected void onCreate(Bundle savedInstanceState) {
settings = new AppSettings(this);
setTheme(settings.getAppTheme());

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
checkCurrrentPermissions();
permsCheck();
}

public void checkCurrrentPermissions(){
boolean enabled;
btnSkip = findViewById(R.id.button_skip);
btnSkip.setBackgroundColor(enabledColor);
Button externalPermBtn = findViewById(R.id.button_permission_external_storage);
Button notifiPermBtn = findViewById(R.id.button_permission_notification_listener);
Button batteryPermBtn = findViewById(R.id.button_permission_battery_optimizations);
Button batteryBasicPermBtn = findViewById(R.id.button_permission_battery_basic);
skipBtn = findViewById(R.id.button_skip);
skipBtn.setBackgroundColor(enabledColor);
continueBtn = findViewById(R.id.button_continue);
externalPermBtn = findViewById(R.id.button_permission_external_storage);
notifiPermBtn = findViewById(R.id.button_permission_notification_listener);
batteryPermBtn = findViewById(R.id.button_permission_battery_optimizations);

TextView findBattery = findViewById(R.id.text_find_battery_optimization_setting);
TextView findNotify = findViewById(R.id.text_find_notification_setting);

enabled = Util.checkExternalPermission(this);
colorPermission(enabled, externalPermBtn);

enabled = Util.checkNotificationListenerPermission(this);
colorPermission(enabled, notifiPermBtn);

enabled = Util.checkBatteryOptimizationsPermission(this);
colorPermission(enabled, batteryPermBtn);

enabled = Util.checkBatteryOptimizationBasicPermission(this);
colorPermission(enabled, batteryBasicPermBtn);
checkAndSetColors();

externalPermBtn.setOnClickListener((View view) -> {
if (!Util.checkExternalPermission(this)) {
try {
try {
if (Util.checkExternalPermission(this)){
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);
} else {
ActivityCompat.requestPermissions(PermissionsActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_STORAGE);
} catch (Exception e) {
Log.e(TAG,e.toString());
}
} else {
colorPermission(true, externalPermBtn);
} catch (Exception e) {
Log.e(TAG,e.toString());
}
});

notifiPermBtn.setOnClickListener((View view) -> {
if (!Util.checkNotificationListenerPermission(this)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
Intent intent = new Intent();
intent.setAction(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
startActivity(intent);
} catch (Exception e) {
findNotify.setTextColor(warningColor);
findNotify.setText(R.string.find_notifications_settings);
Log.e(TAG,e.toString());
Log.e(TAG, e.toString());
}
} else {
colorPermission(true, notifiPermBtn);
}
});

batteryPermBtn.setOnClickListener((View view) -> {
if (!Util.checkBatteryOptimizationsPermission(this)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
try {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + this.getPackageName()));
startActivity(intent);
String packageName = this.getPackageName();
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
if (pm.isIgnoringBatteryOptimizations(packageName))
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
else {
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
}
this.startActivity(intent);
} catch (Exception e) {
findBattery.setTextColor(warningColor);
findBattery.setText(R.string.find_battery_settings);
Log.e(TAG,e.toString());
}
} else {
colorPermission(true, batteryPermBtn);
}
});

batteryBasicPermBtn.setOnClickListener((View view) -> {
if (!Util.checkBatteryOptimizationBasicPermission(this)) {
try {
ActivityCompat.requestPermissions(PermissionsActivity.this, new String[]{Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS}, REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
} catch (Exception e) {
Log.e(TAG,e.toString());
skipBtn.setOnClickListener((View view) -> {
if(!allPermsCheck()) {
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
settings.setKeyBypassNewPermissions(1);
Intent intent = new Intent(ctx, SettingsActivity.class);
ctx.startActivity(intent);
Util.runServices(ctx);
break;
case DialogInterface.BUTTON_NEGATIVE:
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
String message = ctx.getResources().getString(R.string.are_you_sure);
if (Build.VERSION_CODES.O <= Build.VERSION.SDK_INT && !Util.checkNotificationListenerPermission(ctx)){
message += " " + ctx.getResources().getString(R.string.warning_will_not_scrobble);
message += "/" + ctx.getResources().getString(R.string.permission_notification_listener);
}
} else {
colorPermission(true, batteryBasicPermBtn);
builder.setMessage(message).setPositiveButton(R.string.yes, dialogClickListener)
.setNegativeButton(R.string.no, dialogClickListener).show();
}
});

btnSkip.setOnClickListener((View view) -> {
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
settings.setKeyBypassNewPermissions(1);
Intent intent = new Intent(ctx, SettingsActivity.class);
ctx.startActivity(intent);
Util.runServices(ctx);
break;

case DialogInterface.BUTTON_NEGATIVE:
break;
}
}
};

AlertDialog.Builder builder = new AlertDialog.Builder(this);
String message = ctx.getResources().getString(R.string.are_you_sure);
if (Build.VERSION_CODES.O <= Build.VERSION.SDK_INT && !Util.checkNotificationListenerPermission(ctx)){
message += " " + ctx.getResources().getString(R.string.warning_will_not_scrobble);
message += "/" + ctx.getResources().getString(R.string.permission_notification_listener);
continueBtn.setOnClickListener((View v) -> {
if(allPermsCheck()){
settings.setKeyBypassNewPermissions(0);
Intent intent = new Intent(ctx, SettingsActivity.class);
ctx.startActivity(intent);
Util.runServices(ctx);
}
builder.setMessage(message).setPositiveButton(R.string.yes, dialogClickListener)
.setNegativeButton(R.string.no, dialogClickListener).show();
});

}

public void colorPermission(boolean enabled, Button button){
Expand All @@ -213,29 +206,17 @@ public void colorPermission(boolean enabled, Button button){
button.setBackgroundColor(disabledColor);
}

private void permsCheck() {
//PERMISSION CHECK

boolean allPermissionsGo = true;
allPermissionsGo = allPermissionsGo && Util.checkNotificationListenerPermission(this);
allPermissionsGo = allPermissionsGo && Util.checkExternalPermission(this);
allPermissionsGo = allPermissionsGo && Util.checkBatteryOptimizationsPermission(this);
allPermissionsGo = allPermissionsGo && Util.checkBatteryOptimizationBasicPermission(this);
Log.d(TAG,"All Permissions Go: " + allPermissionsGo);
if (allPermissionsGo) {
Intent intent = new Intent(this, SettingsActivity.class);
this.startActivity(intent);
settings.setKeyBypassNewPermissions(0);
Util.runServices(ctx);
}
private void checkAndSetColors(){
colorPermission(Util.checkExternalPermission(this), externalPermBtn);
colorPermission(Util.checkNotificationListenerPermission(this), notifiPermBtn);
colorPermission(Util.checkBatteryOptimizationsPermission(this), batteryPermBtn);
colorPermission(allPermsCheck(), continueBtn);
colorPermission(!allPermsCheck(), skipBtn);
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
try {
permsCheck();
} catch (Exception e) {
Log.e(TAG, "READ_EXTERNAL_STORAGE. " + e);
}
private boolean allPermsCheck() {
return Util.checkNotificationListenerPermission(this)
&& Util.checkExternalPermission(this)
&& Util.checkBatteryOptimizationsPermission(this);
}
}
Loading

0 comments on commit b820930

Please sign in to comment.