Merge pull request #5989 from ByteHamster/remove-storage-error

Remove storage error activity
This commit is contained in:
ByteHamster 2022-07-31 10:51:51 +02:00 committed by GitHub
commit d3b689127f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 3 additions and 188 deletions

View File

@ -158,8 +158,6 @@
android:resource="@xml/player_widget_info"/>
</receiver>
<activity android:name=".activity.StorageErrorActivity">
</activity>
<activity
android:name=".activity.OpmlImportActivity"
android:configChanges="keyboardHidden|orientation|screenSize"

View File

@ -50,7 +50,6 @@ import de.danoeh.antennapod.event.MessageEvent;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.receiver.MediaButtonReceiver;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.util.StorageUtils;
import de.danoeh.antennapod.core.util.download.AutoUpdateManager;
import de.danoeh.antennapod.dialog.RatingDialog;
import de.danoeh.antennapod.fragment.AddFeedFragment;
@ -112,7 +111,6 @@ public class MainActivity extends CastEnabledActivity {
ensureGeneratedViewIdGreaterThan(savedInstanceState.getInt(KEY_GENERATED_VIEW_ID, 0));
}
super.onCreate(savedInstanceState);
StorageUtils.checkStorageAvailability(this);
setContentView(R.layout.main);
recycledViewPool.setMaxRecycledViews(R.id.view_type_episode_item, 25);
@ -414,7 +412,6 @@ public class MainActivity extends CastEnabledActivity {
@Override
protected void onResume() {
super.onResume();
StorageUtils.checkStorageAvailability(this);
handleNavIntent();
RatingDialog.check();

View File

@ -56,7 +56,6 @@ import de.danoeh.antennapod.parser.feed.FeedHandler;
import de.danoeh.antennapod.parser.feed.FeedHandlerResult;
import de.danoeh.antennapod.model.download.DownloadError;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.StorageUtils;
import de.danoeh.antennapod.core.util.URLChecker;
import de.danoeh.antennapod.core.util.syndication.FeedDiscoverer;
import de.danoeh.antennapod.core.util.syndication.HtmlToPlainText;
@ -122,7 +121,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTranslucentTheme());
super.onCreate(savedInstanceState);
StorageUtils.checkStorageAvailability(this);
viewBinding = OnlinefeedviewActivityBinding.inflate(getLayoutInflater());
setContentView(viewBinding.getRoot());

View File

@ -1,79 +0,0 @@
package de.danoeh.antennapod.activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.util.StorageUtils;
import de.danoeh.antennapod.dialog.ChooseDataFolderDialog;
/**
* Is show if there is now external storage available.
*/
public class StorageErrorActivity extends AppCompatActivity {
private static final String TAG = "StorageErrorActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme());
super.onCreate(savedInstanceState);
setContentView(R.layout.storage_error);
Button btnChooseDataFolder = findViewById(R.id.btnChooseDataFolder);
btnChooseDataFolder.setOnClickListener(v ->
ChooseDataFolderDialog.showDialog(this, path -> {
UserPreferences.setDataFolder(path);
leaveErrorState();
}));
}
@Override
protected void onResume() {
super.onResume();
if (StorageUtils.storageAvailable()) {
leaveErrorState();
} else {
registerReceiver(mediaUpdate, new IntentFilter(Intent.ACTION_MEDIA_MOUNTED));
}
}
@Override
protected void onPause() {
super.onPause();
try {
unregisterReceiver(mediaUpdate);
} catch (IllegalArgumentException e) {
Log.e(TAG, Log.getStackTraceString(e));
}
}
private void leaveErrorState() {
finish();
startActivity(new Intent(this, MainActivity.class));
}
private final BroadcastReceiver mediaUpdate = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (TextUtils.equals(intent.getAction(), Intent.ACTION_MEDIA_MOUNTED)) {
if (intent.getBooleanExtra("read-only", true)) {
Log.d(TAG, "Media was mounted; Finishing activity");
leaveErrorState();
} else {
Log.d(TAG, "Media seemed to have been mounted read only");
}
}
}
};
}

View File

@ -50,7 +50,6 @@ import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.ShareUtils;
import de.danoeh.antennapod.core.util.StorageUtils;
import de.danoeh.antennapod.core.util.TimeSpeedConverter;
import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil;
import de.danoeh.antennapod.core.util.playback.PlaybackController;
@ -107,7 +106,6 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate()");
StorageUtils.checkStorageAvailability(this);
getWindow().setFormat(PixelFormat.TRANSPARENT);
viewBinding = VideoplayerActivityBinding.inflate(LayoutInflater.from(this));
@ -120,7 +118,6 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
@Override
protected void onResume() {
super.onResume();
StorageUtils.checkStorageAvailability(this);
switchToAudioOnly = false;
if (PlaybackService.isCasting()) {
Intent intent = PlaybackService.getPlayerActivityIntent(this);

View File

@ -2,11 +2,8 @@ package de.danoeh.antennapod.config;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.activity.StorageErrorActivity;
import de.danoeh.antennapod.core.ApplicationCallbacks;
public class ApplicationCallbacksImpl implements ApplicationCallbacks {
@ -15,10 +12,4 @@ public class ApplicationCallbacksImpl implements ApplicationCallbacks {
public Application getApplicationInstance() {
return PodcastApp.getInstance();
}
@Override
public Intent getStorageErrorActivity(Context context) {
return new Intent(context, StorageErrorActivity.class);
}
}

View File

@ -29,15 +29,8 @@ public class ChooseDataFolderDialog {
});
((RecyclerView) content.findViewById(R.id.recyclerView)).setAdapter(adapter);
if (adapter.getItemCount() > 0) {
if (adapter.getItemCount() != 0) {
dialog.show();
} else {
new AlertDialog.Builder(context)
.setTitle(R.string.error_label)
.setMessage(R.string.external_storage_error_msg)
.setPositiveButton(android.R.string.ok, null)
.show();
}
}
}
}

View File

@ -1,33 +0,0 @@
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp">
<ImageView
android:id="@+id/imageView1"
android:contentDescription="@string/external_storage_error_msg"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_margin="8dp"
app:srcCompat="@drawable/ic_storage" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="@string/external_storage_error_msg" />
<Button
android:id="@+id/btnChooseDataFolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="@string/choose_data_directory"/>
</LinearLayout>

View File

@ -1,8 +1,6 @@
package de.danoeh.antennapod.core;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
/**
* Callbacks related to the application in general
@ -13,11 +11,4 @@ public interface ApplicationCallbacks {
* Returns a non-null instance of the application class
*/
Application getApplicationInstance();
/**
* Returns a non-null intent that starts the storage error
* activity.
*/
Intent getStorageErrorActivity(Context context);
}

View File

@ -113,9 +113,6 @@ public class HttpDownloader extends Downloader {
} else if (!response.isSuccessful() || response.body() == null) {
callOnFailByResponseCode(response);
return;
} else if (!StorageUtils.storageAvailable()) {
onFail(DownloadError.ERROR_DEVICE_NOT_FOUND, null);
return;
} else if (request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA
&& isContentTypeTextAndSmallerThan100kb(response)) {
onFail(DownloadError.ERROR_FILE_TYPE, null);

View File

@ -1,50 +1,16 @@
package de.danoeh.antennapod.core.util;
import android.app.Activity;
import android.os.StatFs;
import android.util.Log;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import java.io.File;
import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.preferences.UserPreferences;
/**
* Utility functions for handling storage errors
*/
public class StorageUtils {
private StorageUtils(){}
private static final String TAG = "StorageUtils";
public static boolean storageAvailable() {
File dir = UserPreferences.getDataFolder(null);
if (dir != null) {
return dir.exists() && dir.canRead() && dir.canWrite();
} else {
Log.d(TAG, "Storage not available: data folder is null");
return false;
}
}
/**
* Checks if external storage is available. If external storage isn't
* available, the current activity is finsished an an error activity is
* launched.
*
* @param activity the activity which would be finished if no storage is
* available
* @return true if external storage is available
*/
public static boolean checkStorageAvailability(Activity activity) {
boolean storageAvailable = storageAvailable();
if (!storageAvailable) {
activity.finish();
activity.startActivity(ClientConfig.applicationCallbacks.getStorageErrorActivity(activity));
}
return storageAvailable;
}
/**
* Get the number of free bytes that are available on the external storage.
*/

View File

@ -95,7 +95,6 @@
<string name="error_label">Error</string>
<string name="error_msg_prefix">An error occurred:</string>
<string name="refresh_label">Refresh</string>
<string name="external_storage_error_msg">No external storage is available. Please make sure that external storage is mounted so that the app can work properly.</string>
<string name="chapters_label">Chapters</string>
<string name="chapter_duration">Duration: %1$s</string>
<string name="description_label">Description</string>