Fix moreee bugs

This commit is contained in:
blank X 2022-04-29 23:13:06 +07:00
parent 13e469f269
commit 59fde090ad
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 10 additions and 13 deletions

View File

@ -1,6 +1,7 @@
package com.blankie.fileify;
import android.app.Activity;
import android.widget.Toast;
import android.content.Intent;
import android.content.ActivityNotFoundException;
import android.util.Log;
@ -10,12 +11,6 @@ import com.blankie.fileify.R;
public class PickActivity extends Activity {
public static final String TAG = "fileify";
private void logAndToast(int priority, String msg) {
Log.println(priority, TAG, msg);
Toast.makeText(getApplicationContext(), msg, Toast.LENGH_SHORT)
.show();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -41,8 +36,10 @@ public class PickActivity extends Activity {
try {
startActivityForResult(newIntent, 0);
} catch (ActivityNotFoundException e) {
logAndToast(Log.ERROR, R.string.no_activity);
setResult(RESULT_CANCELLED);
Log.e(TAG, getString(R.string.no_activity));
Toast.makeText(getApplicationContext(), msg, Toast.LENGH_SHORT)
.show();
setResult(Activity.RESULT_CANCELLED);
finish();
}
}
@ -55,13 +52,13 @@ public class PickActivity extends Activity {
if (resultCode != RESULT_OK) {
Log.d(TAG, "Received resultCode = " + resultCode);
setResult(RESULT_CANCELLED);
setResult(Activity.RESULT_CANCELLED);
finish();
// probably not necessary but just in case or something
return;
} else if (data == null) {
Log.d(TAG, "Received data = null");
setResult(RESULT_CANCELLED);
setResult(Activity.RESULT_CANCELLED);
finish();
return;
}
@ -70,14 +67,14 @@ public class PickActivity extends Activity {
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (data.getData() != null) {
intent.setData(data.getData());
setResult(RESULT_OK, intent);
setResult(Activity.RESULT_OK, intent);
} else if (data.getClipData() != null) {
// unsafe?
intent.setClipData(data.getClipData());
setResult(RESULT_OK, intent);
setResult(Activity.RESULT_OK, intent);
} else {
Log.d(TAG, "Received data.getData() = null and data.getClipData() = null");
setResult(RESULT_CANCELLED);
setResult(Activity.RESULT_CANCELLED);
}
finish();
}