Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
noahweasley committed Jul 25, 2021
1 parent 85c5cd1 commit 87fb59c
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 66 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'org.jetbrains:annotations:15.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.appcompat:appcompat-resources:1.3.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.appcompat:appcompat-resources:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.fragment:fragment:1.3.5'
implementation 'androidx.fragment:fragment:1.3.6'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.kevalpatel2106:ringtonepicker:1.2'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0-beta02'
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@

<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />

<!-- Android 11 and above-->
<queries>
<package android:name="com.whatsapp" />
<package android:name="com.gbwhatsapp" />
</queries>

<application
android:allowBackup="true"
android:fullBackupContent="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ public void onCreate(Bundle savedState) {

submitButton.setOnClickListener(v -> saveOrUpdateAssignment());
btn_gallery.setOnClickListener(
v -> startActivity(new Intent(this, ImageDirectory.class)
.putExtra(ImageDirectory.STORAGE_ACCESS_ROOT, ImageDirectory.EXTERNAL)
.setAction(ADD_NEW)));
v -> {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R)
startActivity(new Intent(this, ImageDirectory.class)
.putExtra(ImageDirectory.STORAGE_ACCESS_ROOT, ImageDirectory.EXTERNAL)
.setAction(ADD_NEW));
else Toast.makeText(this, "Not supported yet", Toast.LENGTH_LONG).show();
});

ArrayAdapter<String> courseAdapter = new ArrayAdapter<>(this,
R.layout.simple_spinner_item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -56,7 +58,12 @@ protected void onCreate(Bundle savedInstanceState) {
tv_description.setText(assignment.getDescription());

// Start image viewer
btn_viewImages.setOnClickListener(v -> ImageViewerActivity.start(getContext(), position, title));
btn_viewImages.setOnClickListener(v -> {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R)
ImageViewerActivity.start(getContext(), position, title);
else Toast.makeText(getContext(), "Not supported yet", Toast.LENGTH_LONG).show();

});
}
}
}
65 changes: 8 additions & 57 deletions app/src/main/java/com/noah/timely/gallery/ImageDirectory.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package com.noah.timely.gallery;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ContentUris;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.provider.Settings;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.Toast;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
Expand All @@ -33,10 +28,6 @@
import java.util.ArrayList;
import java.util.List;

import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static android.os.Build.VERSION.SDK_INT;

public class ImageDirectory extends AppCompatActivity implements Runnable {
public static final int requestCode = 112;
public static final String STORAGE_ACCESS_ROOT = "Storage access";
Expand All @@ -49,21 +40,6 @@ public class ImageDirectory extends AppCompatActivity implements Runnable {
private ViewGroup v_noMedia;
private String accessedStorage;

private final ActivityResultLauncher<Intent> resultLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(), result -> {
if (result.getResultCode() == Activity.RESULT_OK) {
Intent data = result.getData();
if (SDK_INT >= Build.VERSION_CODES.R) {
if (Environment.isExternalStorageManager()) {
// perform action when allow permission success
new Thread(this).start();
} else {
Toast.makeText(this, "Allow permission for storage access", Toast.LENGTH_SHORT).show();
}
}
}
});

protected void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.image_gallery);
Expand All @@ -72,51 +48,26 @@ protected void onCreate(Bundle state) {
indeterminateProgress = findViewById(R.id.indeterminateProgress);
v_noMedia = findViewById(R.id.no_media);
setSupportActionBar(toolbar);

getSupportActionBar().setTitle("Select Images");

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

imageList.setHasFixedSize(true);
imageList.setAdapter(imageAdapter);
imageList.setLayoutManager(new GridLayoutManager(this, 2));
imageList.setClickable(true);

if (checkPermission()) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
ThreadUtils.runBackgroundTask(this);
} else {
requestPermission();
}
}

private void requestPermission() {
if (SDK_INT >= Build.VERSION_CODES.R) {
try {
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse(String.format("package:%s", getPackageName())));
resultLauncher.launch(intent);
} catch (Exception e) {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
resultLauncher.launch(intent);
}
} else {
// below android 11
ActivityCompat.requestPermissions(this,
new String[]{READ_EXTERNAL_STORAGE},
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
requestCode);
}
}

private boolean checkPermission() {
if (SDK_INT >= Build.VERSION_CODES.R) {
return Environment.isExternalStorageManager();
} else {
int result = ContextCompat.checkSelfPermission(this, READ_EXTERNAL_STORAGE);
int result1 = ContextCompat.checkSelfPermission(this, WRITE_EXTERNAL_STORAGE);
return result == PackageManager.PERMISSION_GRANTED && result1 == PackageManager.PERMISSION_GRANTED;
}
}

@Override
public boolean onSupportNavigateUp() {
onBackPressed();
Expand All @@ -136,7 +87,7 @@ public void onRequestPermissionsResult(int _requestCode,
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
new Thread(this).start();
} else {
Toast.makeText(this, "Allow permission for storage access", Toast.LENGTH_LONG).show();
Toast.makeText(this, "Image selector requires permission", Toast.LENGTH_LONG).show();
finish();
}
}
Expand All @@ -145,7 +96,7 @@ public void onRequestPermissionsResult(int _requestCode,
@SuppressLint("InlinedApi")
public void run() {
Uri storageUri;
if (SDK_INT >= Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
storageUri = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
} else {
storageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/dialog_update_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:gravity="start"
android:layout_marginBottom="@dimen/layout_gap"
android:text="@string/fix_message_2"
android:textColor="@android:color/black"
external:drawableLeftCompat="@drawable/ic_circle_fill" />
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@
<string name="app_name_multi_colored">Time<font color="#FF2424">LY</font></string>
<string name="never">NEVER</string>
<string name="later">LATER</string>
<string name="fix_message_1">Fixed image access issues on Android 11 devices</string>
<string name="fix_message_1">Fixed report action bug on Android 11 devices</string>
<string name="fix_message_2">Fixed no-scroll behaviour in Info dialog</string>
</resources>

0 comments on commit 87fb59c

Please sign in to comment.