Skip to content

Commit

Permalink
Push: Fix permission dialog
Browse files Browse the repository at this point in the history
Fixes #2270
  • Loading branch information
mar-v-in committed Aug 14, 2024
1 parent 21189cc commit f76f371
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 93 deletions.
2 changes: 1 addition & 1 deletion play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@
android:name="org.microg.gms.ui.AskPushPermission"
android:excludeFromRecents="true"
android:process=":ui"
android:theme="@style/Theme.App.DayNight.Dialog.Alert.NoActionBar" />
android:theme="@style/Theme.App.Translucent" />

<activity
android:name="org.microg.gms.ui.GoogleMoreFragment$AsActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.microg.gms.ui;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
Expand All @@ -17,6 +18,7 @@
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;

import com.google.android.gms.R;
Expand Down Expand Up @@ -60,41 +62,38 @@ public void onCreate(Bundle savedInstanceState) {
return;
}

setContentView(R.layout.ask_gcm);

try {
View view = getLayoutInflater().inflate(R.layout.ask_gcm, null);
PackageManager pm = getPackageManager();
final ApplicationInfo info = pm.getApplicationInfo(packageName, 0);
String label = pm.getApplicationLabel(info).toString();
String raw = getString(R.string.gcm_allow_app_popup, label);
SpannableString s = new SpannableString(raw);
s.setSpan(new StyleSpan(Typeface.BOLD), raw.indexOf(label), raw.indexOf(label) + label.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);

((TextView) findViewById(R.id.permission_message)).setText(s);
findViewById(R.id.permission_allow_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (answered) return;
database.noteAppKnown(packageName, true);
answered = true;
Bundle bundle = new Bundle();
bundle.putBoolean(EXTRA_EXPLICIT, true);
resultReceiver.send(Activity.RESULT_OK, bundle);
finish();
}
});
findViewById(R.id.permission_deny_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (answered) return;
database.noteAppKnown(packageName, false);
answered = true;
Bundle bundle = new Bundle();
bundle.putBoolean(EXTRA_EXPLICIT, true);
resultReceiver.send(Activity.RESULT_CANCELED, bundle);
finish();
}
});
((TextView) view.findViewById(R.id.permission_message)).setText(s);
UtilsKt.buildAlertDialog(this)
.setView(view)
.setPositiveButton(R.string.allow, (dialog, which) -> {
if (answered) return;
database.noteAppKnown(packageName, true);
answered = true;
Bundle bundle = new Bundle();
bundle.putBoolean(EXTRA_EXPLICIT, true);
resultReceiver.send(Activity.RESULT_OK, bundle);
finish();
})
.setNegativeButton(R.string.deny, (dialog, which) -> {
if (answered) return;
database.noteAppKnown(packageName, false);
answered = true;
Bundle bundle = new Bundle();
bundle.putBoolean(EXTRA_EXPLICIT, true);
resultReceiver.send(Activity.RESULT_CANCELED, bundle);
finish();
})
.create()
.show();
} catch (PackageManager.NameNotFoundException e) {
finish();
}
Expand Down
86 changes: 21 additions & 65 deletions play-services-core/src/main/res/layout/ask_gcm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 The Android Open Source Project
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,80 +13,37 @@
limitations under the License.
-->

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/dialog_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"
android:divider="?attr/dividerHorizontal"
android:gravity="center"
android:orientation="vertical"
android:showDividers="middle">

<LinearLayout
android:paddingLeft="24dp"
android:paddingTop="18dp"
android:paddingRight="24dp"
android:paddingBottom="24dp">

<ImageView
android:id="@+id/permission_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginBottom="12dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_cloud_bell"
app:tint="?attr/colorAccent"></ImageView>

<TextView
android:id="@+id/permission_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingTop="18dp"
android:paddingRight="24dp"
android:paddingBottom="24dp">

<ImageView
android:id="@+id/permission_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginBottom="12dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_cloud_bell"
app:tint="?attr/colorAccent">
</ImageView>

<TextView
android:id="@+id/permission_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/gcm_allow_app_popup"
android:textSize="18sp">
</TextView>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="?attr/dividerHorizontal"
android:orientation="vertical"
android:showDividers="middle">

<Button
android:id="@+id/permission_allow_button"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?android:attr/selectableItemBackground"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="@string/allow">
</Button>

<Button
android:id="@+id/permission_deny_button"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?android:attr/selectableItemBackground"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="@string/deny">
</Button>

</LinearLayout>
android:text="@string/gcm_allow_app_popup"
android:textSize="18sp"></TextView>

</LinearLayout>

Expand Down

0 comments on commit f76f371

Please sign in to comment.