Support for video compress

This commit is contained in:
tom79 2019-09-21 10:45:17 +02:00
parent 5f70268902
commit 099a43e29e
5 changed files with 86 additions and 13 deletions

View File

@ -114,7 +114,7 @@ dependencies {
implementation 'com.github.adrielcafe:AndroidAudioRecorder:0.3.0' implementation 'com.github.adrielcafe:AndroidAudioRecorder:0.3.0'
implementation 'yogesh.firzen:MukkiyaSevaigal:1.0.6' implementation 'yogesh.firzen:MukkiyaSevaigal:1.0.6'
implementation 'id.zelory:compressor:2.1.0' implementation 'com.iceteck.silicompressorr:silicompressor:2.2.2'
implementation "ch.acra:acra-mail:$acraVersion" implementation "ch.acra:acra-mail:$acraVersion"
implementation "ch.acra:acra-limiter:$acraVersion" implementation "ch.acra:acra-limiter:$acraVersion"
implementation "ch.acra:acra-notification:$acraVersion" implementation "ch.acra:acra-notification:$acraVersion"

View File

@ -1822,6 +1822,19 @@ public class ContentSettingsFragment extends Fragment implements ScreenShotable
}); });
//Resize
final CheckBox set_resize_video = rootView.findViewById(R.id.set_resize_video);
boolean compressVideo = sharedpreferences.getBoolean(Helper.SET_VIDEO_COMPRESSED, true);
set_resize_video.setChecked(compressVideo);
set_resize_video.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_VIDEO_COMPRESSED, set_resize_video.isChecked());
editor.apply();
}
});
boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true); boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true);

View File

@ -123,6 +123,7 @@ import com.bumptech.glide.request.transition.Transition;
import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayout;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.iceteck.silicompressorr.SiliCompressor;
import com.jaredrummler.materialspinner.MaterialSpinner; import com.jaredrummler.materialspinner.MaterialSpinner;
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton; import com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton;
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu; import com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu;
@ -158,6 +159,7 @@ import java.io.OutputStream;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URISyntaxException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.Security; import java.security.Security;
@ -221,7 +223,6 @@ import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask; import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
import app.fedilab.android.sqlite.AccountDAO; import app.fedilab.android.sqlite.AccountDAO;
import app.fedilab.android.sqlite.Sqlite; import app.fedilab.android.sqlite.Sqlite;
import id.zelory.compressor.Compressor;
import info.guardianproject.netcipher.client.StrongBuilder; import info.guardianproject.netcipher.client.StrongBuilder;
import info.guardianproject.netcipher.client.StrongOkHttpClientBuilder; import info.guardianproject.netcipher.client.StrongOkHttpClientBuilder;
import okhttp3.ConnectionSpec; import okhttp3.ConnectionSpec;
@ -351,6 +352,7 @@ public class Helper {
public static final String SET_CAPITALIZE = "set_capitalize"; public static final String SET_CAPITALIZE = "set_capitalize";
public static final String SET_WYSIWYG = "set_wysiwyg"; public static final String SET_WYSIWYG = "set_wysiwyg";
public static final String SET_PICTURE_COMPRESSED = "set_picture_compressed"; public static final String SET_PICTURE_COMPRESSED = "set_picture_compressed";
public static final String SET_VIDEO_COMPRESSED = "set_picture_compressed";
public static final String SET_FORWARD_TAGS_IN_REPLY = "set_forward_tags_in_reply"; public static final String SET_FORWARD_TAGS_IN_REPLY = "set_forward_tags_in_reply";
public static final String SET_FULL_PREVIEW = "set_full_preview"; public static final String SET_FULL_PREVIEW = "set_full_preview";
public static final String SET_COMPACT_MODE = "set_compact_mode"; public static final String SET_COMPACT_MODE = "set_compact_mode";
@ -3420,8 +3422,13 @@ public class Helper {
String mime = cr.getType(uriFile); String mime = cr.getType(uriFile);
File file = new File(uriFile.getPath()); File file = new File(uriFile.getPath());
ByteArrayInputStream bs = null; ByteArrayInputStream bs = null;
if (mime != null && mime.toLowerCase().contains("image")) {
File dir = new File(context.getCacheDir().getAbsolutePath()+"/compress");
if (!dir.exists()) dir.mkdirs();
String destinationDirectory = context.getCacheDir().getAbsolutePath()+"/compress/"+ file.getName();
InputStream resizedIS = null;
if (mime != null && mime.toLowerCase().contains("image")) {
ExifInterface exif = null; ExifInterface exif = null;
try (InputStream inputStream = context.getContentResolver().openInputStream(uriFile)) { try (InputStream inputStream = context.getContentResolver().openInputStream(uriFile)) {
assert inputStream != null; assert inputStream != null;
@ -3429,7 +3436,6 @@ public class Helper {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
Matrix matrix; Matrix matrix;
if (exif != null) { if (exif != null) {
int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
@ -3446,15 +3452,12 @@ public class Helper {
matrix.preRotate(rotationDegree); matrix.preRotate(rotationDegree);
} }
} }
InputStream resizedIS = null;
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean compressed = sharedpreferences.getBoolean(Helper.SET_PICTURE_COMPRESSED, true); boolean compressed = sharedpreferences.getBoolean(Helper.SET_PICTURE_COMPRESSED, true);
if( compressed) { if( compressed) {
try { try {
File compressedFile= new Compressor(context).compressToFile(file); String filePath = SiliCompressor.with(context).compress(file.getAbsolutePath(), new File(destinationDirectory));
resizedIS = new FileInputStream(compressedFile.getAbsolutePath()); resizedIS = new FileInputStream(filePath);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -3481,13 +3484,34 @@ public class Helper {
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
boolean compressed = sharedpreferences.getBoolean(Helper.SET_VIDEO_COMPRESSED, true);
if( compressed) {
String filePath = null;
try {
filePath = SiliCompressor.with(context).compressVideo(file.getAbsolutePath(), destinationDirectory);
} catch (URISyntaxException e) {
e.printStackTrace();
}
try {
assert filePath != null;
resizedIS = new FileInputStream(filePath);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}else{
try {
resizedIS = context.getContentResolver().openInputStream(uriFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
try { try {
InputStream inputStream = context.getContentResolver().openInputStream(uriFile);
byte[] buff = new byte[8 * 1024]; byte[] buff = new byte[8 * 1024];
int bytesRead; int bytesRead;
ByteArrayOutputStream bao = new ByteArrayOutputStream(); ByteArrayOutputStream bao = new ByteArrayOutputStream();
assert inputStream != null; assert resizedIS != null;
while ((bytesRead = inputStream.read(buff)) != -1) { while ((bytesRead = resizedIS.read(buff)) != -1) {
bao.write(buff, 0, bytesRead); bao.write(buff, 0, bytesRead);
} }
byte[] data = bao.toByteArray(); byte[] data = bao.toByteArray();
@ -3498,7 +3522,6 @@ public class Helper {
e.printStackTrace(); e.printStackTrace();
} }
} }
return bs; return bs;
} }

View File

@ -1860,6 +1860,41 @@
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/settings_checkbox_margin"
android:layout_marginBottom="@dimen/settings_checkbox_margin"
android:orientation="horizontal">
<CheckBox
android:id="@+id/set_resize_video"
android:layout_width="wrap_content"
android:textSize="16sp"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/set_resize_video_text"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:textSize="16sp"
android:text="@string/set_resize_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:textColor="@color/mastodonC2"
android:text="@string/set_resize_video_indication"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<!-- WYSIWYG --> <!-- WYSIWYG -->
<LinearLayout <LinearLayout
android:id="@+id/set_wysiwyg_container" android:id="@+id/set_wysiwyg_container"

View File

@ -413,6 +413,7 @@
<string name="action_search">Search</string> <string name="action_search">Search</string>
<string name="set_capitalize">First letter in capital for replies</string> <string name="set_capitalize">First letter in capital for replies</string>
<string name="set_resize_picture">Resize pictures</string> <string name="set_resize_picture">Resize pictures</string>
<string name="set_resize_video">Resize videos</string>
<!-- Quick settings for notifications --> <!-- Quick settings for notifications -->
<string name="settings_popup_title">Push notifications</string> <string name="settings_popup_title">Push notifications</string>
@ -1221,4 +1222,5 @@
<string name="action_add_notes">Add notes</string> <string name="action_add_notes">Add notes</string>
<string name="note_for_account">Notes for the account</string> <string name="note_for_account">Notes for the account</string>
<string name="set_resize_picture_indication">Allow to compress large photos into smaller sized photos with very less or negligible loss in quality of the image.</string> <string name="set_resize_picture_indication">Allow to compress large photos into smaller sized photos with very less or negligible loss in quality of the image.</string>
<string name="set_resize_video_indication">Allow to compress videos while maintaining their quality.</string>
</resources> </resources>