Skip to content
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

Switch to No Nonsense FilePicker #76

Merged
merged 4 commits into from
May 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {
compile 'com.crystal:crystalrangeseekbar:1.1.3'
compile 'commons-io:commons-io:2.5'
compile group: 'com.google.guava', name: 'guava', version: '20.0'
compile 'com.github.codekidX:storage-chooser:2.0.3'
compile 'com.nononsenseapps:filepicker:4.2.1'
implementation group: 'org.javatuples', name: 'javatuples', version: '1.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.8.11.1'

Expand Down
20 changes: 19 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,33 @@
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name="com.nononsenseapps.filepicker.FilePickerActivity"
android:label="@string/app_name"
android:theme="@style/FilePickerTheme">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:name=".provider.ExportFileProvider"
android:grantUriPermissions="true"
android:exported="false"
android:authorities="${applicationId}">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths"/>
</provider>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/nnf_provider_paths" />
</provider>
<service
android:name=".service.FFmpegProcessService"
android:permission="android.permission.BIND_JOB_SERVICE"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package protect.videotranscoder.activity;

import android.Manifest;
import android.app.Activity;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
Expand Down Expand Up @@ -37,11 +38,13 @@
import android.widget.Toast;
import android.widget.VideoView;

import com.codekidlabs.storagechooser.StorageChooser;
import com.crystal.crystalrangeseekbar.interfaces.OnRangeSeekbarChangeListener;
import com.google.common.collect.ImmutableMap;

import com.crystal.crystalrangeseekbar.widgets.CrystalRangeSeekbar;
import com.nononsenseapps.filepicker.FilePickerActivity;
import com.nononsenseapps.filepicker.Utils;

import org.javatuples.Triplet;

import java.io.File;
Expand Down Expand Up @@ -81,6 +84,8 @@ public class MainActivity extends AppCompatActivity

private static final int READ_WRITE_PERMISSION_REQUEST = 1;

private static final int SELECT_FILE_REQUEST = 2;

final List<Integer> BASIC_SETTINGS_IDS = Collections.unmodifiableList(Arrays.asList(
R.id.basicSettingsText,
R.id.basicSettingsTopDivider,
Expand Down Expand Up @@ -483,30 +488,37 @@ public void onClick(DialogInterface dialog, int which)
}

/**
* Opening gallery for uploading video
* Opening gallery for selecting video file
*/
private void selectVideo()
{
final StorageChooser fileChooser = new StorageChooser.Builder()
.withActivity(MainActivity.this)
.withFragmentManager(getFragmentManager())
.allowCustomPath(true)
.setType(StorageChooser.FILE_PICKER)
.disableMultiSelect()
.build();
Intent i = new Intent(this, FilePickerActivity.class);

i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false);
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE);

i.putExtra(FilePickerActivity.EXTRA_START_PATH, Environment.getExternalStorageDirectory().getPath());

// get path that the user has chosen
fileChooser.setOnSelectListener(new StorageChooser.OnSelectListener()
startActivityForResult(i, SELECT_FILE_REQUEST);
}

protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
if (requestCode == SELECT_FILE_REQUEST && resultCode == Activity.RESULT_OK)
{
@Override
public void onSelect(String filePath)
// Use the provided utility method to parse the result
List<Uri> files = Utils.getSelectedFilesFromResult(intent);

// There should be at most once result
if(files.size() > 0)
{
Log.i(TAG, "Selected file: " + filePath);
setSelectMediaFile(filePath);
}
});
File file = Utils.getFileForUri(files.get(0));

fileChooser.show();
Log.i(TAG, "Selected file: " + file.getAbsolutePath());
setSelectMediaFile(file.getAbsolutePath());
}
}
}

private List<String> getFfmpegEncodingArgs(String inputFilePath, Integer startTimeSec, Integer endTimeSec,
Expand Down Expand Up @@ -1394,7 +1406,7 @@ private void displayAboutDialog()
.put("FFmpeg Android", "https://github.com/bravobit/FFmpeg-Android")
.put("Guava", "https://github.com/google/guava")
.put("Crystal Range Seekbar", "https://github.com/syedowaisali/crystal-range-seekbar")
.put("Storage Chooser", "https://github.com/codekidX/storage-chooser")
.put("NoNonsense-FilePicker", "https://github.com/spacecowboy/NoNonsense-FilePicker")
.put("javatuples", "https://www.javatuples.org/")
.put("jackson-databind", "https://github.com/FasterXML/jackson-databind")
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package protect.videotranscoder.provider;

import android.support.v4.content.FileProvider;

/**
* This file picker exists only to avoid a name conflict with
* a used package that uses the FileProvider directly.
*/
public class ExportFileProvider extends FileProvider
{
}
23 changes: 23 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,27 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<!-- You can also inherit from NNF_BaseTheme.Light -->
<style name="FilePickerTheme" parent="NNF_BaseTheme.Light">
<!-- Set these to match your theme -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

<!-- Setting a divider is entirely optional -->
<item name="nnf_list_item_divider">?android:attr/listDivider</item>

<!-- Need to set this also to style create folder dialog -->
<item name="alertDialogTheme">@style/FilePickerAlertDialogTheme</item>

<!-- If you want to set a specific toolbar theme, do it here -->
<item name="nnf_toolbarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>

<style name="FilePickerAlertDialogTheme" parent="Theme.AppCompat.Dialog.Alert">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
2 changes: 1 addition & 1 deletion app/src/test/shell/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def ffprobe(filename):
stdout, stderr = p.communicate()
rc = p.wait()
if rc != 0:
raise Exception("ffprobe failed with " + str(rc) + " on " + filename + ":\n" + stderr)
raise Exception("ffprobe failed with " + str(rc) + " on " + filename + ":\n" + stdout + "\n" + stderr)
data = json.loads(stdout)
return data

Expand Down