make monocles chat working without any permissions

This commit is contained in:
Arne 2022-07-20 19:30:45 +02:00
parent 0b64151ec3
commit e6e48c45d1
2 changed files with 10 additions and 61 deletions

View file

@ -18,8 +18,7 @@ import eu.siacs.conversations.ui.ConversationsActivity;
import eu.siacs.conversations.ui.util.IntroHelper;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
public class StartUI extends AppCompatActivity
implements EasyPermissions.PermissionCallbacks {
public class StartUI extends AppCompatActivity {
private static final int NeededPermissions = 1000;
String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
@ -29,66 +28,17 @@ public class StartUI extends AppCompatActivity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start_ui);
IntroHelper.showIntro(this, false);
requestNeededPermissions();
}
@AfterPermissionGranted(NeededPermissions)
private void requestNeededPermissions() {
String PREF_FIRST_START = "FirstStart";
SharedPreferences FirstStart = getApplicationContext().getSharedPreferences(PREF_FIRST_START, Context.MODE_PRIVATE);
long FirstStartTime = FirstStart.getLong(PREF_FIRST_START, 0);
if (EasyPermissions.hasPermissions(this, perms)) {
// Already have permission, start ConversationsActivity
Log.d(Config.LOGTAG, "All permissions granted, starting " + getString(R.string.app_name) + "(" + FirstStartTime + ")");
Intent intent = new Intent(this, ConversationsActivity.class);
intent.putExtra(PREF_FIRST_START, FirstStartTime);
startActivity(intent);
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
finish();
} else {
// set first start to 0 if there are permissions to request
Log.d(Config.LOGTAG, "Requesting required permissions");
SharedPreferences.Editor editor = FirstStart.edit();
editor.putLong(PREF_FIRST_START, 0);
editor.commit();
// Do not have permissions, request them now
EasyPermissions.requestPermissions(this, getString(R.string.request_permissions_message),
NeededPermissions, perms);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// Forward results to EasyPermissions
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}
@Override
public void onPermissionsGranted(int requestCode, List<String> list) {
Log.d(Config.LOGTAG, "Permissions granted:" + requestCode);
}
@Override
public void onPermissionsDenied(int requestCode, List<String> list) {
Log.d(Config.LOGTAG, "Permissions denied:" + requestCode);
final AlertDialog dialog = new AlertDialog.Builder(this)
.setMessage(getString(R.string.request_permissions_message_again))
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
}
})
.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.create();
dialog.show();
}
Log.d(Config.LOGTAG, "All permissions granted, starting " + getString(R.string.app_name) + "(" + FirstStartTime + ")");
Intent intent = new Intent(this, ConversationsActivity.class);
intent.putExtra(PREF_FIRST_START, FirstStartTime);
startActivity(intent);
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
finish(); }
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

View file

@ -77,8 +77,7 @@
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="@string/import_database"
android:textColor="?attr/colorAccent"
android:visibility="gone" />
android:textColor="?attr/colorAccent" />
<Button
android:id="@+id/create_account"