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 #535 from a93h/master
Browse files Browse the repository at this point in the history
Permissions and Warnings, + RU update
  • Loading branch information
Austin H authored Sep 19, 2019
2 parents 1c933bc + f4f6e9e commit 8cd802a
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 97 deletions.
3 changes: 3 additions & 0 deletions app/src/main/assets/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ For privacy concerns.

- 1.6.8 (2019-9-15) codename: kingus
* Correction Rules database problem fixed
* Back button in permissions fixed
* Privacy information in permissions
* Russian thanks to alexesprit

- 1.6.7 (2019-9-15) codename: jingus
* Fixed non-foreground service crash Bug
Expand Down
114 changes: 56 additions & 58 deletions app/src/main/java/com/adam/aslfms/PermissionsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,37 @@
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.adam.aslfms.util.AppSettings;
import com.adam.aslfms.util.MyContextWrapper;
import com.adam.aslfms.util.Util;

/**
* @author a93h
* @since 1.5.8
*/
public class PermissionsActivity extends AppCompatActivity {

private enum ButtonChoice { SKIP, CONTINUE, BACK }

private static final String TAG = "PermissionsActivity";
private static final int disabledColor = Color.argb(25, 0,0,0);
private static final int enabledColor = Color.argb(75, 0,255,0);
private static final int warningColor = Color.argb(80,255,0,0);

private int WRITE_EXTERNAL_STORAGE;

int WRITE_EXTERNAL_STORAGE;
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 skipBtn = null;
Button continueBtn = null;
Button externalPermBtn = null;
Button notifiPermBtn = null;
Button batteryPermBtn = null;
private boolean skipPermissions = false;

private AppSettings settings = null;
private Button skipBtn = null;
private Button continueBtn = null;
private Button externalPermBtn = null;
private Button notifiPermBtn = null;
private Button batteryPermBtn = null;
private ImageButton privacyLinkBtn = null;
Context ctx = this;

@Override
Expand Down Expand Up @@ -95,7 +102,14 @@ protected void onCreate(Bundle savedInstanceState) {
checkCurrrentPermissions();
}

@Override
public void onBackPressed() {
leavePermissionsDialogue(this, ButtonChoice.BACK);
}

public void checkCurrrentPermissions(){
privacyLinkBtn = findViewById(R.id.privacy_link_button);

skipBtn = findViewById(R.id.button_skip);
skipBtn.setBackgroundColor(enabledColor);
continueBtn = findViewById(R.id.button_continue);
Expand Down Expand Up @@ -159,50 +173,9 @@ public void checkCurrrentPermissions(){
}
});

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); // user has bypassed permissions is True
int v = Util.getAppVersionCode(ctx , getPackageName());
if (settings.getWhatsNewViewedVersion() < v) {
resetVersionCode(v);
}
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.warning) + "! " + 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);
}
builder.setMessage(message).setPositiveButton(R.string.yes, dialogClickListener)
.setNegativeButton(R.string.no, dialogClickListener).show();
}
});
continueBtn.setOnClickListener((View view) -> {
if(allPermsCheck()){
settings.setKeyBypassNewPermissions(0); // user has bypassed permissions is false
int v = Util.getAppVersionCode(this, getPackageName());
if (settings.getWhatsNewViewedVersion() < v) {
resetVersionCode(v);
}
Intent intent = new Intent(ctx, SettingsActivity.class);
ctx.startActivity(intent);
Util.runServices(ctx);
}
});

skipBtn.setOnClickListener((View view) -> leavePermissionsDialogue(view.getContext(), ButtonChoice.SKIP));
continueBtn.setOnClickListener((View view) -> leavePermissionsDialogue(view.getContext() , ButtonChoice.CONTINUE));
privacyLinkBtn.setOnClickListener((View view) -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/simple-last-fm-scrobbler/sls/wiki/Privacy-Concerns"))));
}

public void colorPermission(boolean enabled, Button button){
Expand All @@ -227,8 +200,33 @@ private boolean allPermsCheck() {
&& Util.checkBatteryOptimizationsPermission(this);
}

private void resetVersionCode(int v){
new WhatsNewDialog(this).show();
settings.setWhatsNewViewedVersion(v);
private void resolveChoice(int bypass){
settings.setWhatsNewViewedVersion(Util.getAppVersionCode(ctx,getPackageName()));
settings.setKeyBypassNewPermissions(bypass);
finish();
}

private void leavePermissionsDialogue(Context context, ButtonChoice buttonChoice){
if (allPermsCheck() && buttonChoice != ButtonChoice.SKIP){
resolveChoice(0); // user has bypassed permissions is False
} else if (!allPermsCheck() && buttonChoice != ButtonChoice.CONTINUE) {
DialogInterface.OnClickListener dialogClickListener = (DialogInterface dialog, int which) -> {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
resolveChoice(1); // user has bypassed permissions is True
break;
case DialogInterface.BUTTON_NEGATIVE:
break;
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(context);
String message = context.getResources().getString(R.string.warning) + "! " + context.getResources().getString(R.string.are_you_sure);
if (Build.VERSION_CODES.O <= Build.VERSION.SDK_INT && !Util.checkNotificationListenerPermission(context)) {
message += " - " + context.getResources().getString(R.string.warning_will_not_scrobble);
message += " - " + context.getResources().getString(R.string.permission_notification_listener);
}
builder.setMessage(message).setPositiveButton(R.string.yes, dialogClickListener)
.setNegativeButton(R.string.no, dialogClickListener).show();
}
}
}
37 changes: 18 additions & 19 deletions app/src/main/java/com/adam/aslfms/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,10 @@ protected void onCreate(Bundle savedInstanceState) {
mDb = null;
}

checkNetwork();

mHeartCurrentTrack = findPreference(KEY_HEART_CURRENT_TRACK);
mScrobbleAllNow = findPreference(KEY_SCROBBLE_ALL_NOW);
mViewScrobbleCache = findPreference(KEY_VIEW_SCROBBLE_CACHE);
mCopyCurrentTrack = findPreference(KEY_COPY_CURRENT_TRACK);

// TODO: VERIFY EVERYTHING BELOW IS SAFE
int v = Util.getAppVersionCode(this, getPackageName());
if (settings.getWhatsNewViewedVersion() < v){
settings.setKeyBypassNewPermissions(2);
mDb.rebuildScrobblesDatabaseOnce(); // keep as not all users have the newest database.
// TODO: verify only needed databases are destroyed
}
if (settings.getKeyBypassNewPermissions() == 2){
startActivity(new Intent(this, PermissionsActivity.class));
}
Util.runServices(this);
}

@Override
Expand All @@ -150,11 +136,7 @@ protected void onResume() {
ifs.addAction(ScrobblingService.BROADCAST_ONSTATUSCHANGED);
registerReceiver(onStatusChange, ifs);
update();
Util.runServices(this);
if(settings.getKeyBypassNewPermissions() == 2){
Intent i = new Intent(this, PermissionsActivity.class);
startActivity(i);
}
runChecks();
}

@Override
Expand Down Expand Up @@ -222,6 +204,23 @@ public void onReceive(Context context, Intent intent) {
}
};

private void runChecks(){
settings = new AppSettings(this);
// TODO: VERIFY EVERYTHING BELOW IS SAFE
int v = Util.getAppVersionCode(this, getPackageName());
if (settings.getWhatsNewViewedVersion() < v){
settings.setKeyBypassNewPermissions(2);
mDb.rebuildScrobblesDatabaseOnce(); // keep as not all users have the newest database.
// TODO: verify only needed databases are destroyed
}
if (settings.getKeyBypassNewPermissions() == 2){
startActivity(new Intent(this, PermissionsActivity.class));
} else if (settings.getWhatsNewViewedVersion() < v) {
new WhatsNewDialog(this).show();
}
Util.runServices(this);
}

private void checkNetwork() {
this.sendBroadcast(new Intent(AppSettings.ACTION_NETWORK_OPTIONS_CHANGED));
if (Util.checkForOkNetwork(this) != Util.NetworkStatus.OK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void parseTrack(Context ctx, Track.Builder b, Bundle bundle) {
long audioid = getAudioId(bundle);

if (shouldFetchFromMediaStore(ctx, audioid)) { // read from MediaStore
if(Build.VERSION_CODES.KITKAT >= Build.VERSION.SDK_INT && !Util.checkExternalPermission(ctx)){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && !Util.checkExternalPermission(ctx)){
Util.myNotify(ctx, ctx.getResources().getString(R.string.warning), ctx.getResources().getString(R.string.permission_external_storage), 81234, PermissionsActivity.class);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;

import com.adam.aslfms.PermissionsActivity;
import com.adam.aslfms.R;
import com.adam.aslfms.util.Track;
import com.adam.aslfms.util.Util;

Expand Down Expand Up @@ -116,6 +119,10 @@ else if (id instanceof Integer)
b.setWhen(Util.currentTimeSecsUTC());

if (msid != -1) { // read from MediaStore
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && !Util.checkExternalPermission(ctx)){
Util.myNotify(ctx, ctx.getResources().getString(R.string.warning), ctx.getResources().getString(R.string.permission_external_storage), 81234, PermissionsActivity.class);
return;
}
final String[] columns = new String[]{
MediaStore.Audio.AudioColumns.ARTIST,
MediaStore.Audio.AudioColumns.TITLE,
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/res/layout/activity_permissions.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -25,17 +26,28 @@

<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="match_parent"
android:gravity="center_horizontal|center_vertical" >

<TextView
android:id="@+id/text_permisions_title"
android:layout_width="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="4sp"
android:ellipsize="end"
android:gravity="center_horizontal"
android:maxLines="2"
android:text="@string/permissions_title"
android:textSize="24sp" />

<ImageButton
android:id="@+id/privacy_link_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@android:drawable/ic_menu_help"
android:textSize="12sp"
android:background="@android:color/holo_blue_bright" />

</TableRow>

<Space
Expand Down
Loading

0 comments on commit 8cd802a

Please sign in to comment.