Removed unnecessary base activity

This commit is contained in:
ByteHamster 2020-01-27 10:52:21 +01:00
parent bb8a7a2ac0
commit 20d6838e5b
5 changed files with 48 additions and 86 deletions

View File

@ -141,7 +141,7 @@
<activity android:name=".activity.StorageErrorActivity">
</activity>
<activity
android:name=".activity.OpmlImportFromIntentActivity"
android:name=".activity.OpmlImportActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/opml_import_label">
<intent-filter>

View File

@ -4,35 +4,53 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import androidx.core.app.ActivityCompat;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.asynctask.OpmlFeedQueuer;
import de.danoeh.antennapod.asynctask.OpmlImportWorker;
import de.danoeh.antennapod.core.export.opml.OpmlElement;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.util.LangUtils;
import org.apache.commons.lang3.ArrayUtils;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.asynctask.OpmlFeedQueuer;
import de.danoeh.antennapod.asynctask.OpmlImportWorker;
import de.danoeh.antennapod.core.export.opml.OpmlElement;
import de.danoeh.antennapod.core.util.LangUtils;
/**
* Base activity for Opml Import - e.g. with code what to do afterwards
* Activity for Opml Import.
* */
public class OpmlImportBaseActivity extends AppCompatActivity {
public class OpmlImportActivity extends AppCompatActivity {
private static final String TAG = "OpmlImportBaseActivity";
private static final int PERMISSION_REQUEST_READ_EXTERNAL_STORAGE = 5;
private OpmlImportWorker importWorker;
@Nullable private Uri uri;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme());
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Uri uri = getIntent().getData();
if (uri != null && uri.toString().startsWith("/")) {
uri = Uri.parse("file://" + uri.toString());
} else {
String extraText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
if (extraText != null) {
uri = Uri.parse(extraText);
}
}
importUri(uri);
}
/**
* Handles the choices made by the user in the OpmlFeedChooserActivity and
* starts the OpmlFeedQueuer if necessary.
@ -42,9 +60,7 @@ public class OpmlImportBaseActivity extends AppCompatActivity {
Log.d(TAG, "Received result");
if (resultCode == RESULT_CANCELED) {
Log.d(TAG, "Activity was cancelled");
if (finishWhenCanceled()) {
finish();
}
finish();
} else {
int[] selected = data.getIntArrayExtra(OpmlFeedChooserActivity.EXTRA_SELECTED_ITEMS);
if (selected != null && selected.length > 0) {
@ -53,7 +69,7 @@ public class OpmlImportBaseActivity extends AppCompatActivity {
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
Intent intent = new Intent(OpmlImportBaseActivity.this, MainActivity.class);
Intent intent = new Intent(OpmlImportActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
@ -68,7 +84,7 @@ public class OpmlImportBaseActivity extends AppCompatActivity {
}
void importUri(@Nullable Uri uri) {
if(uri == null) {
if (uri == null) {
new AlertDialog.Builder(this)
.setMessage(R.string.opml_import_error_no_file)
.setPositiveButton(android.R.string.ok, null)
@ -76,9 +92,10 @@ public class OpmlImportBaseActivity extends AppCompatActivity {
return;
}
this.uri = uri;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
uri.toString().contains(Environment.getExternalStorageDirectory().toString())) {
int permission = ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& uri.toString().contains(Environment.getExternalStorageDirectory().toString())) {
int permission = ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.READ_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
requestPermission();
return;
@ -93,9 +110,8 @@ public class OpmlImportBaseActivity extends AppCompatActivity {
}
@Override
public void onRequestPermissionsResult(int requestCode,
String[] permissions,
int[] grantResults) {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
if (requestCode != PERMISSION_REQUEST_READ_EXTERNAL_STORAGE) {
return;
}
@ -113,8 +129,8 @@ public class OpmlImportBaseActivity extends AppCompatActivity {
/** Starts the import process. */
private void startImport() {
try {
Reader mReader = new InputStreamReader(getContentResolver().openInputStream(uri), LangUtils.UTF_8);
importWorker = new OpmlImportWorker(this, mReader) {
Reader reader = new InputStreamReader(getContentResolver().openInputStream(uri), LangUtils.UTF_8);
OpmlImportWorker importWorker = new OpmlImportWorker(this, reader) {
@Override
protected void onPostExecute(ArrayList<OpmlElement> result) {
@ -123,7 +139,7 @@ public class OpmlImportBaseActivity extends AppCompatActivity {
Log.d(TAG, "Parsing was successful");
OpmlImportHolder.setReadElements(result);
startActivityForResult(new Intent(
OpmlImportBaseActivity.this,
OpmlImportActivity.this,
OpmlFeedChooserActivity.class), 0);
} else {
Log.d(TAG, "Parser error occurred");
@ -140,10 +156,4 @@ public class OpmlImportBaseActivity extends AppCompatActivity {
.show();
}
}
boolean finishWhenCanceled() {
return false;
}
}

View File

@ -1,40 +0,0 @@
package de.danoeh.antennapod.activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import de.danoeh.antennapod.core.preferences.UserPreferences;
/**
* Lets the user start the OPML-import process.
*/
public class OpmlImportFromIntentActivity extends OpmlImportBaseActivity {
private static final String TAG = "OpmlImportFromIntentAct";
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme());
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Uri uri = getIntent().getData();
if (uri != null && uri.toString().startsWith("/")) {
uri = Uri.parse("file://" + uri.toString());
} else {
String extraText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
if(extraText != null) {
uri = Uri.parse(extraText);
}
}
importUri(uri);
}
@Override
protected boolean finishWhenCanceled() {
return true;
}
}

View File

@ -15,18 +15,11 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import com.google.android.material.snackbar.Snackbar;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.activity.OnlineFeedViewActivity;
import de.danoeh.antennapod.activity.OpmlImportFromIntentActivity;
import de.danoeh.antennapod.core.export.html.HtmlWriter;
import de.danoeh.antennapod.core.export.opml.OpmlWriter;
import de.danoeh.antennapod.core.storage.DatabaseExporter;
import de.danoeh.antennapod.activity.OpmlImportActivity;
import de.danoeh.antennapod.fragment.gpodnet.GpodnetMainFragment;
import io.reactivex.Completable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
/**
* Provides actions for adding new podcast subscriptions
@ -159,7 +152,7 @@ public class AddFeedFragment extends Fragment {
Uri uri = data.getData();
if (requestCode == REQUEST_CODE_CHOOSE_OPML_IMPORT_PATH) {
Intent intent = new Intent(getContext(), OpmlImportFromIntentActivity.class);
Intent intent = new Intent(getContext(), OpmlImportActivity.class);
intent.setData(uri);
startActivity(intent);
}

View File

@ -18,7 +18,7 @@ import androidx.core.content.FileProvider;
import androidx.preference.PreferenceFragmentCompat;
import com.google.android.material.snackbar.Snackbar;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.OpmlImportFromIntentActivity;
import de.danoeh.antennapod.activity.OpmlImportActivity;
import de.danoeh.antennapod.activity.PreferenceActivity;
import de.danoeh.antennapod.activity.SplashActivity;
import de.danoeh.antennapod.asynctask.DocumentFileExportWorker;
@ -81,7 +81,6 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat {
}
private void setupStorageScreen() {
final Activity activity = getActivity();
findPreference(PREF_OPML_EXPORT).setOnPreferenceClickListener(
preference -> {
openExportPathPicker(CONTENT_TYPE_OPML, DEFAULT_OPML_OUTPUT_NAME,
@ -254,7 +253,7 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat {
progressDialog.dismiss();
}, this::showExportErrorDialog);
} else if (requestCode == REQUEST_CODE_CHOOSE_OPML_IMPORT_PATH) {
Intent intent = new Intent(getContext(), OpmlImportFromIntentActivity.class);
Intent intent = new Intent(getContext(), OpmlImportActivity.class);
intent.setData(uri);
startActivity(intent);
}