mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-04-19 22:37:09 -04:00
Merge branch 'target-sdk-30' into 'master'
🌭 swap: external storage support for sdk 30+ See merge request fdroid/fdroidclient!1277
This commit is contained in:
@@ -6,4 +6,6 @@ class NearbyViewBinder {
|
||||
static void updateUsbOtg(Context context) {
|
||||
throw new IllegalStateException("unimplemented");
|
||||
}
|
||||
static void updateExternalStorageViews(Context context) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import android.os.Environment;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.os.storage.StorageVolume;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@@ -73,8 +74,6 @@ public class NearbyViewBinder {
|
||||
subtext.setText(activity.getString(R.string.nearby_splash__both_parties_need_fdroid,
|
||||
activity.getString(R.string.app_name)));
|
||||
|
||||
ImageView nearbySplash = swapView.findViewById(R.id.image);
|
||||
|
||||
Button startButton = swapView.findViewById(R.id.find_people_button);
|
||||
startButton.setOnClickListener(v -> {
|
||||
final String coarseLocation = Manifest.permission.ACCESS_COARSE_LOCATION;
|
||||
@@ -86,6 +85,23 @@ public class NearbyViewBinder {
|
||||
}
|
||||
});
|
||||
|
||||
updateExternalStorageViews(activity);
|
||||
updateUsbOtg(activity);
|
||||
}
|
||||
|
||||
public static void updateExternalStorageViews(final AppCompatActivity activity) {
|
||||
if (swapView == null || activity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ImageView nearbySplash = swapView.findViewById(R.id.image);
|
||||
TextView explainer = swapView.findViewById(R.id.read_external_storage_text);
|
||||
Button button = swapView.findViewById(R.id.request_read_external_storage_button);
|
||||
|
||||
if (nearbySplash == null || explainer == null || button == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
File[] dirs = activity.getExternalFilesDirs("");
|
||||
if (dirs != null) {
|
||||
for (File dir : dirs) {
|
||||
@@ -102,28 +118,48 @@ public class NearbyViewBinder {
|
||||
}
|
||||
|
||||
final String readExternalStorage = Manifest.permission.READ_EXTERNAL_STORAGE;
|
||||
|
||||
if (externalStorage != null) {
|
||||
nearbySplash.setVisibility(View.GONE);
|
||||
TextView readExternalStorageText = swapView.findViewById(R.id.read_external_storage_text);
|
||||
readExternalStorageText.setVisibility(View.VISIBLE);
|
||||
Button requestReadExternalStorage = swapView.findViewById(R.id.request_read_external_storage_button);
|
||||
requestReadExternalStorage.setVisibility(View.VISIBLE);
|
||||
requestReadExternalStorage.setOnClickListener(v -> {
|
||||
if ((externalStorage == null || !externalStorage.canRead())
|
||||
&& PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activity,
|
||||
readExternalStorage)) {
|
||||
ActivityCompat.requestPermissions(activity, new String[]{readExternalStorage},
|
||||
MainActivity.REQUEST_STORAGE_PERMISSIONS);
|
||||
explainer.setVisibility(View.VISIBLE);
|
||||
button.setVisibility(View.VISIBLE);
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
if (!Environment.isExternalStorageManager()) {
|
||||
// we don't have permission to access files yet, so ask for it
|
||||
explainer.setText(R.string.nearby_splach__external_storage_permission_explainer);
|
||||
button.setText(R.string.nearby_splace__external_storage_permission_button);
|
||||
button.setOnClickListener(view -> activity.startActivity(
|
||||
new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
|
||||
Uri.parse(String.format("package:%s",
|
||||
activity.getPackageName())))));
|
||||
} else {
|
||||
Toast.makeText(activity,
|
||||
activity.getString(R.string.scan_removable_storage_toast, externalStorage),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
SDCardScannerService.scan(activity);
|
||||
explainer.setText(R.string.nearby_splash__read_external_storage);
|
||||
button.setText(R.string.nearby_splash__request_permission);
|
||||
button.setOnClickListener(view -> scanExternalStorageNow(activity));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if ((externalStorage == null || !externalStorage.canRead())
|
||||
&& PackageManager.PERMISSION_GRANTED
|
||||
!= ContextCompat.checkSelfPermission(activity, readExternalStorage)) {
|
||||
explainer.setText(R.string.nearby_splach__external_storage_permission_explainer);
|
||||
button.setText(R.string.nearby_splace__external_storage_permission_button);
|
||||
button.setOnClickListener(v -> {
|
||||
ActivityCompat.requestPermissions(activity, new String[]{readExternalStorage},
|
||||
MainActivity.REQUEST_STORAGE_PERMISSIONS);
|
||||
});
|
||||
} else {
|
||||
explainer.setText(R.string.nearby_splash__read_external_storage);
|
||||
button.setText(R.string.nearby_splash__request_permission);
|
||||
button.setOnClickListener(view -> scanExternalStorageNow(activity));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateUsbOtg(activity);
|
||||
private static void scanExternalStorageNow(final AppCompatActivity activity) {
|
||||
Toast.makeText(activity, activity.getString(R.string.scan_removable_storage_toast, externalStorage),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
SDCardScannerService.scan(activity);
|
||||
}
|
||||
|
||||
public static void updateUsbOtg(final Context context) {
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
<uses-permission
|
||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="28" />
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.NFC" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission
|
||||
@@ -71,6 +72,7 @@
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="${applicationLabel}"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.App">
|
||||
|
||||
|
||||
@@ -173,6 +173,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
// AppDetailsActivity and RepoDetailsActivity set different NFC actions, so reset here
|
||||
NfcHelper.setAndroidBeam(this, getApplication().getPackageName());
|
||||
checkForAddRepoIntent(getIntent());
|
||||
|
||||
NearbyViewBinder.updateExternalStorageViews(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -518,7 +518,9 @@ This often occurs with apps installed via Google Play or other sources, if they
|
||||
<string name="nearby_splash__read_external_storage">Search SD Card for repos and mirrors.</string>
|
||||
<string name="nearby_splash__document_tree">Search USB OTG for repos and mirrors.</string>
|
||||
<!-- This is a button label for a small button, the text needs to be under 10 characters, the shorter the better. Also, a literal translation probably will miss the point. "Try it" is more a saying than two words. Google has been pushing these short buttons, like "Got it" and "Try now" so this button is trying to match those buttons in Android. -->
|
||||
<string name="nearby_splash__request_permission">Try it</string>
|
||||
<string name="nearby_splash__request_permission">Search now</string>
|
||||
<string name="nearby_splach__external_storage_permission_explainer">F-Droid can search for repos and mirrors on your SD Card, but needs your permission to do so.</string>
|
||||
<string name="nearby_splace__external_storage_permission_button">Try it</string>
|
||||
|
||||
<!-- This is a screen title, it should be maximum 25 characters -->
|
||||
<string name="swap_nfc_title">Touch to swap</string>
|
||||
|
||||
Reference in New Issue
Block a user