-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix export profile on pre-19 API levels #320
base: master
Are you sure you want to change the base?
Changes from all commits
98db421
744526e
95b7259
597618a
214b77d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.aprsdroid.app; | ||
|
||
import static androidx.test.espresso.Espresso.onView; | ||
import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu; | ||
import static androidx.test.espresso.action.ViewActions.click; | ||
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasAction; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withText; | ||
import static org.hamcrest.Matchers.allOf; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
import android.Manifest; | ||
import android.app.Instrumentation; | ||
import android.content.Intent; | ||
import android.os.Environment; | ||
|
||
import androidx.test.core.app.ActivityScenario; | ||
import androidx.test.espresso.intent.Intents; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.rule.GrantPermissionRule; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class ProfileTests { | ||
@Rule | ||
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE); | ||
|
||
@Before | ||
public void setUp() { | ||
Intents.init(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
Intents.release(); | ||
} | ||
|
||
@Test | ||
public void testThatExportProfileOpensTheChooser() { | ||
assumeTrue(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())); | ||
ActivityScenario scenario = ActivityScenario.launch(PrefsAct.class); | ||
Intents.intending(hasAction(Intent.ACTION_CHOOSER)).respondWith(new Instrumentation.ActivityResult(0, null)); | ||
openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getInstrumentation().getTargetContext()); | ||
onView(withText(R.string.profile_export)) | ||
.perform(click()); | ||
Intents.intended(hasAction(Intent.ACTION_MAIN)); // Validate the activity launch | ||
Intents.intended(allOf(hasAction(Intent.ACTION_CHOOSER))); | ||
Intents.assertNoUnverifiedIntents(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<paths xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<external-path name="APRSdroid" path="Documents/APRSdroid" /> | ||
<external-path name="APRSdroid-top" path="APRSdroid" /> | ||
</paths> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,17 @@ import _root_.android.preference.PreferenceActivity | |
import _root_.android.preference.PreferenceManager | ||
import _root_.android.view.{Menu, MenuItem} | ||
import _root_.android.widget.Toast | ||
import android.util.Log | ||
|
||
import java.text.SimpleDateFormat | ||
import java.io.{File, PrintWriter} | ||
import java.util.Date | ||
|
||
import org.json.JSONObject | ||
|
||
class PrefsAct extends PreferenceActivity { | ||
val TAG = "APRSdroid.PrefsAct" | ||
|
||
lazy val db = StorageDatabase.open(this) | ||
lazy val prefs = new PrefsWrapper(this) | ||
|
||
|
@@ -33,7 +37,10 @@ class PrefsAct extends PreferenceActivity { | |
|
||
UIHelper.shareFile(this, file, filename) | ||
} catch { | ||
case e : Exception => Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show() | ||
case e : Exception => { | ||
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show() | ||
Log.i(TAG, "Caught exception sharing file: " + e, e) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this shouldn't be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! Probably any errors that warrant generating an on-screen toast message should probably be warn or higher. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After further thought, if we ever hit that catch, it basically means that a piece of user functionality was not able to do its job so it should probably be an error-level log. I can push an update this evening if preferred or, I think this could even be edited from the web though without the GitHub CI branch in place to automatically compile and test, I don't know if I'd trust that. |
||
} | ||
} | ||
} | ||
|
||
|
@@ -62,7 +69,7 @@ class PrefsAct extends PreferenceActivity { | |
|
||
def resolveContentUri(uri : Uri) = { | ||
val Array(storage, path) = uri.getPath().replace("/document/", "").split(":", 2) | ||
android.util.Log.d("PrefsAct", "resolveContentUri s=" + storage + " p=" + path) | ||
android.util.Log.d(TAG, "resolveContentUri s=" + storage + " p=" + path) | ||
if (storage == "primary") | ||
Environment.getExternalStorageDirectory() + "/" + path | ||
else | ||
|
@@ -108,7 +115,7 @@ class PrefsAct extends PreferenceActivity { | |
} | ||
|
||
override def onActivityResult(reqCode : Int, resultCode : Int, data : Intent) { | ||
android.util.Log.d("PrefsAct", "onActResult: request=" + reqCode + " result=" + resultCode + " " + data) | ||
android.util.Log.d(TAG, "onActResult: request=" + reqCode + " result=" + resultCode + " " + data) | ||
if (resultCode == android.app.Activity.RESULT_OK && reqCode == 123456) { | ||
parseFilePickerResult(data, "mapfile", R.string.mapfile_error) | ||
} else | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit-pick, this would normally be a Java
private final static
and I believe it's currently an instance variable. I'd have to look up what the Scala version of that is. I believe I copied this from the style used elsewhere, however.