1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 22:57:29 +00:00

Move downloads to Environment downloads folder

This commit is contained in:
Ammar Githam 2021-04-02 01:42:21 +09:00
parent 24b5b4801f
commit 91c70b778a
18 changed files with 426 additions and 294 deletions

View File

@ -12,13 +12,13 @@ def getGitHash = { ->
} }
android { android {
compileSdkVersion 29 compileSdkVersion 30
defaultConfig { defaultConfig {
applicationId 'me.austinhuang.instagrabber' applicationId 'me.austinhuang.instagrabber'
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 30
versionCode 60 versionCode 60
versionName '19.1.0' versionName '19.1.0'

View File

@ -33,7 +33,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import awais.instagrabber.databinding.ActivityCameraBinding; import awais.instagrabber.databinding.ActivityCameraBinding;
import awais.instagrabber.utils.DirectoryUtils; import awais.instagrabber.utils.DownloadUtils;
import awais.instagrabber.utils.PermissionUtils; import awais.instagrabber.utils.PermissionUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
@ -74,7 +74,7 @@ public class CameraActivity extends BaseLanguageActivity {
setContentView(binding.getRoot()); setContentView(binding.getRoot());
Utils.transparentStatusBar(this, true, false); Utils.transparentStatusBar(this, true, false);
displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE); displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
outputDirectory = DirectoryUtils.getOutputMediaDirectory(this, "Camera"); outputDirectory = DownloadUtils.getCameraDir();
cameraExecutor = Executors.newSingleThreadExecutor(); cameraExecutor = Executors.newSingleThreadExecutor();
displayManager.registerDisplayListener(displayListener, null); displayManager.registerDisplayListener(displayListener, null);
binding.viewFinder.post(() -> { binding.viewFinder.post(() -> {

View File

@ -2,8 +2,11 @@ package awais.instagrabber.dialogs;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.DocumentsContract;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -14,27 +17,25 @@ import android.view.inputmethod.InputMethodManager;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentTransaction;
import java.io.File;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import awais.instagrabber.databinding.DialogCreateBackupBinding; import awais.instagrabber.databinding.DialogCreateBackupBinding;
import awais.instagrabber.utils.DirectoryChooser; import awais.instagrabber.utils.DownloadUtils;
import awais.instagrabber.utils.ExportImportUtils; import awais.instagrabber.utils.ExportImportUtils;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import static awais.instagrabber.utils.Constants.FOLDER_PATH; import static android.app.Activity.RESULT_OK;
import static awais.instagrabber.utils.DownloadUtils.PERMS;
public class CreateBackupDialogFragment extends DialogFragment { public class CreateBackupDialogFragment extends DialogFragment {
private static final String TAG = CreateBackupDialogFragment.class.getSimpleName();
private static final int STORAGE_PERM_REQUEST_CODE = 8020; private static final int STORAGE_PERM_REQUEST_CODE = 8020;
private static final SimpleDateFormat BACKUP_FILE_DATE_TIME_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US); private static final SimpleDateFormat BACKUP_FILE_DATE_TIME_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
private static final int CREATE_FILE_REQUEST_CODE = 1;
private final OnResultListener onResultListener; private final OnResultListener onResultListener;
private DialogCreateBackupBinding binding; private DialogCreateBackupBinding binding;
@ -113,60 +114,113 @@ public class CreateBackupDialogFragment extends DialogFragment {
imm.hideSoftInputFromWindow(binding.etPassword.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN); imm.hideSoftInputFromWindow(binding.etPassword.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);
}); });
binding.btnSaveTo.setOnClickListener(v -> { binding.btnSaveTo.setOnClickListener(v -> {
if (ContextCompat.checkSelfPermission(context, PERMS[0]) == PackageManager.PERMISSION_GRANTED) { createFile();
showChooser(context); // if (ContextCompat.checkSelfPermission(context, PERMS[0]) == PackageManager.PERMISSION_GRANTED) {
} else { // showChooser(context);
requestPermissions(PERMS, STORAGE_PERM_REQUEST_CODE); // } else {
} // requestPermissions(PERMS, STORAGE_PERM_REQUEST_CODE);
// }
}); });
} }
@Override @Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) { public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == STORAGE_PERM_REQUEST_CODE && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // if (requestCode == STORAGE_PERM_REQUEST_CODE && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
final Context context = getContext(); // final Context context = getContext();
if (context == null) return; // if (context == null) return;
showChooser(context); // showChooser(context);
} // }
} }
private void showChooser(@NonNull final Context context) { @Override
final String folderPath = Utils.settingsHelper.getString(FOLDER_PATH); public void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent data) {
if (data == null || data.getData() == null) return;
if (resultCode != RESULT_OK || requestCode != CREATE_FILE_REQUEST_CODE) return;
final Context context = getContext();
if (context == null) return;
final Editable passwordText = binding.etPassword.getText(); final Editable passwordText = binding.etPassword.getText();
final String password = binding.cbPassword.isChecked() final String password = binding.cbPassword.isChecked()
&& passwordText != null && passwordText != null
&& !TextUtils.isEmpty(passwordText.toString()) && !TextUtils.isEmpty(passwordText.toString())
? passwordText.toString().trim() ? passwordText.toString().trim()
: null; : null;
final DirectoryChooser directoryChooser = new DirectoryChooser() int flags = 0;
.setInitialDirectory(folderPath) if (binding.cbExportFavorites.isChecked()) {
.setInteractionListener(path -> { flags |= ExportImportUtils.FLAG_FAVORITES;
final Date now = new Date(); }
final File file = new File(path, String.format("barinsta_%s.backup", BACKUP_FILE_DATE_TIME_FORMAT.format(now))); if (binding.cbExportSettings.isChecked()) {
int flags = 0; flags |= ExportImportUtils.FLAG_SETTINGS;
if (binding.cbExportFavorites.isChecked()) { }
flags |= ExportImportUtils.FLAG_FAVORITES; if (binding.cbExportLogins.isChecked()) {
} flags |= ExportImportUtils.FLAG_COOKIES;
if (binding.cbExportSettings.isChecked()) { }
flags |= ExportImportUtils.FLAG_SETTINGS; ExportImportUtils.exportData(context, flags, data.getData(), password, result -> {
} if (onResultListener != null) {
if (binding.cbExportLogins.isChecked()) { onResultListener.onResult(result);
flags |= ExportImportUtils.FLAG_COOKIES; }
} dismiss();
ExportImportUtils.exportData(context, flags, file, password, result -> { });
if (onResultListener != null) { // try (final OutputStream stream = context.getContentResolver().openOutputStream(data.getData())) {
onResultListener.onResult(result); // } catch (Exception e) {
} // Log.e(TAG, "onActivityResult: ", e);
dismiss(); // }
});
});
directoryChooser.setEnterTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
directoryChooser.setExitTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
directoryChooser.show(getChildFragmentManager(), "directory_chooser");
} }
// private void showChooser(@NonNull final Context context) {
// final String folderPath = Utils.settingsHelper.getString(FOLDER_PATH);
// final Editable passwordText = binding.etPassword.getText();
// final String password = binding.cbPassword.isChecked()
// && passwordText != null
// && !TextUtils.isEmpty(passwordText.toString())
// ? passwordText.toString().trim()
// : null;
// final DirectoryChooser directoryChooser = new DirectoryChooser()
// .setInitialDirectory(folderPath)
// .setInteractionListener(path -> {
// final Date now = new Date();
// final File file = new File(path, String.format("barinsta_%s.backup", BACKUP_FILE_DATE_TIME_FORMAT.format(now)));
// int flags = 0;
// if (binding.cbExportFavorites.isChecked()) {
// flags |= ExportImportUtils.FLAG_FAVORITES;
// }
// if (binding.cbExportSettings.isChecked()) {
// flags |= ExportImportUtils.FLAG_SETTINGS;
// }
// if (binding.cbExportLogins.isChecked()) {
// flags |= ExportImportUtils.FLAG_COOKIES;
// }
// ExportImportUtils.exportData(context, flags, file, password, result -> {
// if (onResultListener != null) {
// onResultListener.onResult(result);
// }
// dismiss();
// });
//
// });
// directoryChooser.setEnterTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
// directoryChooser.setExitTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
// directoryChooser.show(getChildFragmentManager(), "directory_chooser");
// }
private void createFile() {
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/octet-stream");
final Date now = new Date();
final String fileName = String.format("barinsta_%s.backup", BACKUP_FILE_DATE_TIME_FORMAT.format(now));
intent.putExtra(Intent.EXTRA_TITLE, fileName);
// Optionally, specify a URI for the directory that should be opened in
// the system file picker when your app creates the document.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Uri.fromFile(DownloadUtils.getDownloadDir()));
}
startActivityForResult(intent, CREATE_FILE_REQUEST_CODE);
}
public interface OnResultListener { public interface OnResultListener {
void onResult(boolean result); void onResult(boolean result);
} }

View File

@ -1,12 +1,18 @@
package awais.instagrabber.dialogs; package awais.instagrabber.dialogs;
import android.app.Dialog; import android.app.Dialog;
import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.provider.MediaStore;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -15,30 +21,28 @@ import android.view.inputmethod.InputMethodManager;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentTransaction;
import java.io.File;
import awais.instagrabber.databinding.DialogRestoreBackupBinding; import awais.instagrabber.databinding.DialogRestoreBackupBinding;
import awais.instagrabber.utils.DirectoryChooser; import awais.instagrabber.utils.AppExecutors;
import awais.instagrabber.utils.ExportImportUtils; import awais.instagrabber.utils.ExportImportUtils;
import awais.instagrabber.utils.PasswordUtils.IncorrectPasswordException; import awais.instagrabber.utils.PasswordUtils.IncorrectPasswordException;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import static awais.instagrabber.utils.Constants.FOLDER_PATH; import static android.app.Activity.RESULT_OK;
import static awais.instagrabber.utils.DownloadUtils.PERMS;
public class RestoreBackupDialogFragment extends DialogFragment { public class RestoreBackupDialogFragment extends DialogFragment {
private static final String TAG = RestoreBackupDialogFragment.class.getSimpleName();
private static final int STORAGE_PERM_REQUEST_CODE = 8020; private static final int STORAGE_PERM_REQUEST_CODE = 8020;
private static final int OPEN_FILE_REQUEST_CODE = 1;
private OnResultListener onResultListener; private OnResultListener onResultListener;
private DialogRestoreBackupBinding binding; private DialogRestoreBackupBinding binding;
private File file; // private File file;
private boolean isEncrypted; private boolean isEncrypted;
private Uri uri;
public RestoreBackupDialogFragment() {} public RestoreBackupDialogFragment() {}
@ -83,18 +87,62 @@ public class RestoreBackupDialogFragment extends DialogFragment {
@Override @Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) { public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == STORAGE_PERM_REQUEST_CODE && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // if (requestCode == STORAGE_PERM_REQUEST_CODE && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
showChooser(); // showChooser();
// }
}
@Override
public void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent data) {
if (data == null || data.getData() == null) return;
if (resultCode != RESULT_OK || requestCode != OPEN_FILE_REQUEST_CODE) return;
final Context context = getContext();
if (context == null) return;
isEncrypted = ExportImportUtils.isEncrypted(context, data.getData());
if (isEncrypted) {
binding.passwordGroup.setVisibility(View.VISIBLE);
binding.passwordGroup.post(() -> {
binding.etPassword.requestFocus();
binding.etPassword.post(() -> {
final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm == null) return;
imm.showSoftInput(binding.etPassword, InputMethodManager.SHOW_IMPLICIT);
});
binding.btnRestore.setEnabled(!TextUtils.isEmpty(binding.etPassword.getText()));
});
} else {
binding.passwordGroup.setVisibility(View.GONE);
binding.btnRestore.setEnabled(true);
} }
uri = data.getData();
AppExecutors.getInstance().mainThread().execute(() -> {
Cursor c = null;
try {
String[] projection = {MediaStore.Files.FileColumns.DISPLAY_NAME};
final ContentResolver contentResolver = context.getContentResolver();
c = contentResolver.query(uri, projection, null, null, null);
if (c != null) {
while (c.moveToNext()) {
final String displayName = c.getString(0);
binding.filePath.setText(displayName);
}
}
} catch (Exception e) {
Log.e(TAG, "onActivityResult: ", e);
} finally {
if (c != null) {
c.close();
}
}
});
} }
private void init() { private void init() {
final Context context = getContext(); final Context context = getContext();
if (context == null) { if (context == null) return;
return;
}
binding.btnRestore.setEnabled(false); binding.btnRestore.setEnabled(false);
binding.btnRestore.setOnClickListener(v -> new Handler().post(() -> { binding.btnRestore.setOnClickListener(v -> new Handler(Looper.getMainLooper()).post(() -> {
if (uri == null) return;
int flags = 0; int flags = 0;
if (binding.cbFavorites.isChecked()) { if (binding.cbFavorites.isChecked()) {
flags |= ExportImportUtils.FLAG_FAVORITES; flags |= ExportImportUtils.FLAG_FAVORITES;
@ -111,7 +159,7 @@ public class RestoreBackupDialogFragment extends DialogFragment {
ExportImportUtils.importData( ExportImportUtils.importData(
context, context,
flags, flags,
file, uri,
!isEncrypted ? null : text.toString(), !isEncrypted ? null : text.toString(),
result -> { result -> {
if (onResultListener != null) { if (onResultListener != null) {
@ -137,45 +185,55 @@ public class RestoreBackupDialogFragment extends DialogFragment {
@Override @Override
public void afterTextChanged(final Editable s) {} public void afterTextChanged(final Editable s) {}
}); });
if (ContextCompat.checkSelfPermission(context, PERMS[0]) == PackageManager.PERMISSION_GRANTED) { // if (ContextCompat.checkSelfPermission(context, PERMS[0]) == PackageManager.PERMISSION_GRANTED) {
showChooser(); // showChooser();
return; // return;
} // }
requestPermissions(PERMS, STORAGE_PERM_REQUEST_CODE); // requestPermissions(PERMS, STORAGE_PERM_REQUEST_CODE);
final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
// intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
// intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{
// "application/pdf", // .pdf
// "application/vnd.oasis.opendocument.text", // .odt
// "text/plain" // .txt
// });
startActivityForResult(intent, OPEN_FILE_REQUEST_CODE);
} }
private void showChooser() { // private void showChooser() {
final String folderPath = Utils.settingsHelper.getString(FOLDER_PATH); // final String folderPath = Utils.settingsHelper.getString(FOLDER_PATH);
final Context context = getContext(); // final Context context = getContext();
if (context == null) return; // if (context == null) return;
final DirectoryChooser directoryChooser = new DirectoryChooser() // final DirectoryChooser directoryChooser = new DirectoryChooser()
.setInitialDirectory(folderPath) // .setInitialDirectory(folderPath)
.setShowBackupFiles(true) // .setShowBackupFiles(true)
.setInteractionListener(file -> { // .setInteractionListener(file -> {
isEncrypted = ExportImportUtils.isEncrypted(file); // isEncrypted = ExportImportUtils.isEncrypted(file);
if (isEncrypted) { // if (isEncrypted) {
binding.passwordGroup.setVisibility(View.VISIBLE); // binding.passwordGroup.setVisibility(View.VISIBLE);
binding.passwordGroup.post(() -> { // binding.passwordGroup.post(() -> {
binding.etPassword.requestFocus(); // binding.etPassword.requestFocus();
binding.etPassword.post(() -> { // binding.etPassword.post(() -> {
final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); // final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm == null) return; // if (imm == null) return;
imm.showSoftInput(binding.etPassword, InputMethodManager.SHOW_IMPLICIT); // imm.showSoftInput(binding.etPassword, InputMethodManager.SHOW_IMPLICIT);
}); // });
binding.btnRestore.setEnabled(!TextUtils.isEmpty(binding.etPassword.getText())); // binding.btnRestore.setEnabled(!TextUtils.isEmpty(binding.etPassword.getText()));
}); // });
} else { // } else {
binding.passwordGroup.setVisibility(View.GONE); // binding.passwordGroup.setVisibility(View.GONE);
binding.btnRestore.setEnabled(true); // binding.btnRestore.setEnabled(true);
} // }
this.file = file; // this.file = file;
binding.filePath.setText(file.getAbsolutePath()); // binding.filePath.setText(file.getAbsolutePath());
}); // });
directoryChooser.setEnterTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); // directoryChooser.setEnterTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
directoryChooser.setExitTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); // directoryChooser.setExitTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
directoryChooser.setOnCancelListener(this::dismiss); // directoryChooser.setOnCancelListener(this::dismiss);
directoryChooser.show(getChildFragmentManager(), "directory_chooser"); // directoryChooser.show(getChildFragmentManager(), "directory_chooser");
} // }
public interface OnResultListener { public interface OnResultListener {
void onResult(boolean result); void onResult(boolean result);

View File

@ -74,9 +74,6 @@ import static androidx.core.content.PermissionChecker.checkSelfPermission;
import static awais.instagrabber.utils.DownloadUtils.WRITE_PERMISSION; import static awais.instagrabber.utils.DownloadUtils.WRITE_PERMISSION;
import static awais.instagrabber.utils.Utils.settingsHelper; import static awais.instagrabber.utils.Utils.settingsHelper;
//import awaisomereport.LogCollector;
//import static awais.instagrabber.utils.Utils.logCollector;
public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener { public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = "HashTagFragment"; private static final String TAG = "HashTagFragment";
private static final int STORAGE_PERM_REQUEST_CODE = 8020; private static final int STORAGE_PERM_REQUEST_CODE = 8020;

View File

@ -1,26 +1,14 @@
package awais.instagrabber.fragments.settings; package awais.instagrabber.fragments.settings;
import android.content.Context; import android.content.Context;
import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder;
import androidx.preference.SwitchPreferenceCompat; import androidx.preference.SwitchPreferenceCompat;
import com.google.android.material.switchmaterial.SwitchMaterial;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.DirectoryChooser;
import awais.instagrabber.utils.TextUtils;
import static awais.instagrabber.utils.Constants.FOLDER_PATH;
import static awais.instagrabber.utils.Constants.FOLDER_SAVE_TO;
import static awais.instagrabber.utils.Utils.settingsHelper;
public class DownloadsPreferencesFragment extends BasePreferencesFragment { public class DownloadsPreferencesFragment extends BasePreferencesFragment {
@Override @Override
@ -28,7 +16,7 @@ public class DownloadsPreferencesFragment extends BasePreferencesFragment {
final Context context = getContext(); final Context context = getContext();
if (context == null) return; if (context == null) return;
screen.addPreference(getDownloadUserFolderPreference(context)); screen.addPreference(getDownloadUserFolderPreference(context));
screen.addPreference(getSaveToCustomFolderPreference(context)); // screen.addPreference(getSaveToCustomFolderPreference(context));
} }
private Preference getDownloadUserFolderPreference(@NonNull final Context context) { private Preference getDownloadUserFolderPreference(@NonNull final Context context) {
@ -39,63 +27,63 @@ public class DownloadsPreferencesFragment extends BasePreferencesFragment {
return preference; return preference;
} }
private Preference getSaveToCustomFolderPreference(@NonNull final Context context) { // private Preference getSaveToCustomFolderPreference(@NonNull final Context context) {
return new SaveToCustomFolderPreference(context, (resultCallback) -> new DirectoryChooser() // return new SaveToCustomFolderPreference(context, (resultCallback) -> new DirectoryChooser()
.setInitialDirectory(settingsHelper.getString(FOLDER_PATH)) // .setInitialDirectory(settingsHelper.getString(FOLDER_PATH))
.setInteractionListener(file -> { // .setInteractionListener(file -> {
settingsHelper.putString(FOLDER_PATH, file.getAbsolutePath()); // settingsHelper.putString(FOLDER_PATH, file.getAbsolutePath());
resultCallback.onResult(file.getAbsolutePath()); // resultCallback.onResult(file.getAbsolutePath());
}) // })
.show(getParentFragmentManager(), null)); // .show(getParentFragmentManager(), null));
} // }
public static class SaveToCustomFolderPreference extends Preference { // public static class SaveToCustomFolderPreference extends Preference {
private AppCompatTextView customPathTextView; // private AppCompatTextView customPathTextView;
private final OnSelectFolderButtonClickListener onSelectFolderButtonClickListener; // private final OnSelectFolderButtonClickListener onSelectFolderButtonClickListener;
private final String key; // private final String key;
//
public SaveToCustomFolderPreference(final Context context, final OnSelectFolderButtonClickListener onSelectFolderButtonClickListener) { // public SaveToCustomFolderPreference(final Context context, final OnSelectFolderButtonClickListener onSelectFolderButtonClickListener) {
super(context); // super(context);
this.onSelectFolderButtonClickListener = onSelectFolderButtonClickListener; // this.onSelectFolderButtonClickListener = onSelectFolderButtonClickListener;
key = Constants.FOLDER_SAVE_TO; // key = Constants.FOLDER_SAVE_TO;
setLayoutResource(R.layout.pref_custom_folder); // setLayoutResource(R.layout.pref_custom_folder);
setKey(key); // setKey(key);
setTitle(R.string.save_to_folder); // setTitle(R.string.save_to_folder);
setIconSpaceReserved(false); // setIconSpaceReserved(false);
} // }
//
@Override // @Override
public void onBindViewHolder(final PreferenceViewHolder holder) { // public void onBindViewHolder(final PreferenceViewHolder holder) {
super.onBindViewHolder(holder); // super.onBindViewHolder(holder);
final SwitchMaterial cbSaveTo = (SwitchMaterial) holder.findViewById(R.id.cbSaveTo); // final SwitchMaterial cbSaveTo = (SwitchMaterial) holder.findViewById(R.id.cbSaveTo);
final View buttonContainer = holder.findViewById(R.id.button_container); // final View buttonContainer = holder.findViewById(R.id.button_container);
customPathTextView = (AppCompatTextView) holder.findViewById(R.id.custom_path); // customPathTextView = (AppCompatTextView) holder.findViewById(R.id.custom_path);
cbSaveTo.setOnCheckedChangeListener((buttonView, isChecked) -> { // cbSaveTo.setOnCheckedChangeListener((buttonView, isChecked) -> {
settingsHelper.putBoolean(FOLDER_SAVE_TO, isChecked); // settingsHelper.putBoolean(FOLDER_SAVE_TO, isChecked);
buttonContainer.setVisibility(isChecked ? View.VISIBLE : View.GONE); // buttonContainer.setVisibility(isChecked ? View.VISIBLE : View.GONE);
final String customPath = settingsHelper.getString(FOLDER_PATH); // final String customPath = settingsHelper.getString(FOLDER_PATH);
customPathTextView.setText(customPath); // customPathTextView.setText(customPath);
}); // });
final boolean savedToEnabled = settingsHelper.getBoolean(key); // final boolean savedToEnabled = settingsHelper.getBoolean(key);
holder.itemView.setOnClickListener(v -> cbSaveTo.toggle()); // holder.itemView.setOnClickListener(v -> cbSaveTo.toggle());
cbSaveTo.setChecked(savedToEnabled); // cbSaveTo.setChecked(savedToEnabled);
buttonContainer.setVisibility(savedToEnabled ? View.VISIBLE : View.GONE); // buttonContainer.setVisibility(savedToEnabled ? View.VISIBLE : View.GONE);
final AppCompatButton btnSaveTo = (AppCompatButton) holder.findViewById(R.id.btnSaveTo); // final AppCompatButton btnSaveTo = (AppCompatButton) holder.findViewById(R.id.btnSaveTo);
btnSaveTo.setOnClickListener(v -> { // btnSaveTo.setOnClickListener(v -> {
if (onSelectFolderButtonClickListener == null) return; // if (onSelectFolderButtonClickListener == null) return;
onSelectFolderButtonClickListener.onClick(result -> { // onSelectFolderButtonClickListener.onClick(result -> {
if (TextUtils.isEmpty(result)) return; // if (TextUtils.isEmpty(result)) return;
customPathTextView.setText(result); // customPathTextView.setText(result);
}); // });
}); // });
} // }
//
public interface ResultCallback { // public interface ResultCallback {
void onResult(String result); // void onResult(String result);
} // }
//
public interface OnSelectFolderButtonClickListener { // public interface OnSelectFolderButtonClickListener {
void onClick(ResultCallback resultCallback); // void onClick(ResultCallback resultCallback);
} // }
} // }
} }

View File

@ -991,7 +991,7 @@ public final class ThreadManager {
@NonNull final Uri uri) { @NonNull final Uri uri) {
try { try {
final Pair<Integer, Integer> dimensions = BitmapUtils.decodeDimensions(contentResolver, uri); final Pair<Integer, Integer> dimensions = BitmapUtils.decodeDimensions(contentResolver, uri);
if (dimensions == null) { if (dimensions == null || dimensions.first == null || dimensions.second == null) {
data.postValue(Resource.error("Decoding dimensions failed", null)); data.postValue(Resource.error("Decoding dimensions failed", null));
return; return;
} }

View File

@ -236,10 +236,15 @@ public final class BitmapUtils {
@NonNull final Uri uri) throws FileNotFoundException { @NonNull final Uri uri) throws FileNotFoundException {
BitmapFactory.Options options = new BitmapFactory.Options(); BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(contentResolver.openInputStream(uri), null, options); try (final InputStream inputStream = contentResolver.openInputStream(uri)) {
return (options.outWidth == -1 || options.outHeight == -1) BitmapFactory.decodeStream(inputStream, null, options);
? null return (options.outWidth == -1 || options.outHeight == -1)
: new Pair<>(options.outWidth, options.outHeight); ? null
: new Pair<>(options.outWidth, options.outHeight);
} catch (IOException e) {
Log.e(TAG, "decodeDimensions: ", e);
}
return null;
} }
public static File convertToJpegAndSaveToFile(@NonNull final Bitmap bitmap, @Nullable final File file) throws IOException { public static File convertToJpegAndSaveToFile(@NonNull final Bitmap bitmap, @Nullable final File file) throws IOException {

View File

@ -1,7 +1,5 @@
package awais.instagrabber.utils; package awais.instagrabber.utils;
import android.content.Context;
import android.os.Build;
import android.os.Environment; import android.os.Environment;
import java.io.File; import java.io.File;
@ -10,8 +8,6 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import awais.instagrabber.R;
public class DirectoryUtils { public class DirectoryUtils {
private static final Pattern DIR_SEPORATOR = Pattern.compile("/"); private static final Pattern DIR_SEPORATOR = Pattern.compile("/");
@ -73,22 +69,22 @@ public class DirectoryUtils {
return rv; return rv;
} }
public static File getOutputMediaDirectory(final Context context, final String... dirs) { // public static File getOutputMediaDirectory(final Context context, final String... dirs) {
if (context == null) return null; // if (context == null) return null;
final File[] externalMediaDirs = context.getExternalMediaDirs(); // final File[] externalMediaDirs = context.getExternalMediaDirs();
if (externalMediaDirs == null || externalMediaDirs.length == 0) return context.getFilesDir(); // if (externalMediaDirs == null || externalMediaDirs.length == 0) return context.getFilesDir();
final File externalMediaDir = externalMediaDirs[0]; // final File externalMediaDir = externalMediaDirs[0];
File subDir = new File(externalMediaDir, context.getString(R.string.app_name)); // File subDir = new File(externalMediaDir, context.getString(R.string.app_name));
if (dirs != null) { // if (dirs != null) {
for (final String dir : dirs) { // for (final String dir : dirs) {
subDir = new File(subDir, dir); // subDir = new File(subDir, dir);
//noinspection ResultOfMethodCallIgnored // //noinspection ResultOfMethodCallIgnored
subDir.mkdirs(); // subDir.mkdirs();
} // }
} // }
if (!subDir.exists()) { // if (!subDir.exists()) {
return context.getFilesDir(); // return context.getFilesDir();
} // }
return subDir; // return subDir;
} // }
} }

View File

@ -41,26 +41,54 @@ import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.VideoVersion; import awais.instagrabber.repositories.responses.VideoVersion;
import awais.instagrabber.workers.DownloadWorker; import awais.instagrabber.workers.DownloadWorker;
import static awais.instagrabber.utils.Constants.FOLDER_PATH;
import static awais.instagrabber.utils.Constants.FOLDER_SAVE_TO;
public final class DownloadUtils { public final class DownloadUtils {
private static final String TAG = "DownloadUtils"; private static final String TAG = DownloadUtils.class.getSimpleName();
public static final String WRITE_PERMISSION = Manifest.permission.WRITE_EXTERNAL_STORAGE; public static final String WRITE_PERMISSION = Manifest.permission.WRITE_EXTERNAL_STORAGE;
public static final String[] PERMS = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}; public static final String[] PERMS = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
public static final String DIR_BARINSTA = "Barinsta";
public static final String DIR_DOWNLOADS = "Downloads";
public static final String DIR_CAMERA = "Camera";
public static final String DIR_EDIT = "Edit";
@NonNull public static File getDownloadDir(final String... dirs) {
private static File getDownloadDir() { final File parent = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DOWNLOADS);
File dir = new File(Environment.getExternalStorageDirectory(), "Download"); File subDir = new File(parent, DIR_BARINSTA);
if (dirs != null) {
if (Utils.settingsHelper.getBoolean(FOLDER_SAVE_TO)) { for (final String dir : dirs) {
final String customPath = Utils.settingsHelper.getString(FOLDER_PATH); subDir = new File(subDir, dir);
if (!TextUtils.isEmpty(customPath)) { //noinspection ResultOfMethodCallIgnored
dir = new File(customPath); subDir.mkdirs();
} }
} }
return dir; return subDir;
}
@NonNull
public static File getDownloadDir() {
// final File parent = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DOWNLOADS);
// final File dir = new File(new File(parent, "barinsta"), "downloads");
// if (!dir.exists()) {
// final boolean mkdirs = dir.mkdirs();
// if (!mkdirs) {
// Log.e(TAG, "getDownloadDir: failed to create dir");
// }
// }
// if (Utils.settingsHelper.getBoolean(FOLDER_SAVE_TO)) {
// final String customPath = Utils.settingsHelper.getString(FOLDER_PATH);
// if (!TextUtils.isEmpty(customPath)) {
// dir = new File(customPath);
// }
// }
return getDownloadDir(DIR_DOWNLOADS);
}
public static File getCameraDir() {
return getDownloadDir(DIR_CAMERA);
}
public static File getImageEditDir(final String sessionId) {
return getDownloadDir(DIR_EDIT, sessionId);
} }
@Nullable @Nullable

View File

@ -2,6 +2,7 @@ package awais.instagrabber.utils;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri;
import android.util.Base64; import android.util.Base64;
import android.util.Log; import android.util.Log;
import android.util.Pair; import android.util.Pair;
@ -20,9 +21,8 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.File; import java.io.InputStream;
import java.io.FileInputStream; import java.io.OutputStream;
import java.io.FileOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
@ -55,14 +55,15 @@ public final class ExportImportUtils {
public static void importData(@NonNull final Context context, public static void importData(@NonNull final Context context,
@ExportImportFlags final int flags, @ExportImportFlags final int flags,
@NonNull final File file, @NonNull final Uri uri,
final String password, final String password,
final FetchListener<Boolean> fetchListener) throws IncorrectPasswordException { final FetchListener<Boolean> fetchListener) throws IncorrectPasswordException {
try (final FileInputStream fis = new FileInputStream(file)) { try (final InputStream stream = context.getContentResolver().openInputStream(uri)) {
final int configType = fis.read(); if (stream == null) return;
final int configType = stream.read();
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
int c; int c;
while ((c = fis.read()) != -1) { while ((c = stream.read()) != -1) {
builder.append((char) c); builder.append((char) c);
} }
if (configType == 'A') { if (configType == 'A') {
@ -80,8 +81,8 @@ public final class ExportImportUtils {
throw e; throw e;
} catch (final Exception e) { } catch (final Exception e) {
if (fetchListener != null) fetchListener.onResult(false); if (fetchListener != null) fetchListener.onResult(false);
// if (logCollector != null) // if (logCollector != null)
// logCollector.appendException(e, LogFile.UTILS_IMPORT, "Import::pass"); // logCollector.appendException(e, LogFile.UTILS_IMPORT, "Import::pass");
if (BuildConfig.DEBUG) Log.e(TAG, "Error importing backup", e); if (BuildConfig.DEBUG) Log.e(TAG, "Error importing backup", e);
} }
} else if (configType == 'Z') { } else if (configType == 'Z') {
@ -99,7 +100,7 @@ public final class ExportImportUtils {
throw e; throw e;
} catch (final Exception e) { } catch (final Exception e) {
if (fetchListener != null) fetchListener.onResult(false); if (fetchListener != null) fetchListener.onResult(false);
// if (logCollector != null) logCollector.appendException(e, LogFile.UTILS_IMPORT, "Import"); // if (logCollector != null) logCollector.appendException(e, LogFile.UTILS_IMPORT, "Import");
if (BuildConfig.DEBUG) Log.e(TAG, "", e); if (BuildConfig.DEBUG) Log.e(TAG, "", e);
} }
} }
@ -122,7 +123,7 @@ public final class ExportImportUtils {
if (fetchListener != null) fetchListener.onResult(true); if (fetchListener != null) fetchListener.onResult(true);
} catch (final Exception e) { } catch (final Exception e) {
if (fetchListener != null) fetchListener.onResult(false); if (fetchListener != null) fetchListener.onResult(false);
// if (logCollector != null) logCollector.appendException(e, LogFile.UTILS_IMPORT, "importJson"); // if (logCollector != null) logCollector.appendException(e, LogFile.UTILS_IMPORT, "importJson");
if (BuildConfig.DEBUG) Log.e(TAG, "", e); if (BuildConfig.DEBUG) Log.e(TAG, "", e);
} }
} }
@ -212,9 +213,11 @@ public final class ExportImportUtils {
} }
} }
public static boolean isEncrypted(final File file) { public static boolean isEncrypted(@NonNull final Context context,
try (final FileInputStream fis = new FileInputStream(file)) { @NonNull final Uri uri) {
final int configType = fis.read(); try (final InputStream stream = context.getContentResolver().openInputStream(uri)) {
if (stream == null) return false;
final int configType = stream.read();
if (configType == 'A') { if (configType == 'A') {
return true; return true;
} }
@ -226,7 +229,7 @@ public final class ExportImportUtils {
public static void exportData(@NonNull final Context context, public static void exportData(@NonNull final Context context,
@ExportImportFlags final int flags, @ExportImportFlags final int flags,
@NonNull final File filePath, @NonNull final Uri uri,
final String password, final String password,
final FetchListener<Boolean> fetchListener) { final FetchListener<Boolean> fetchListener) {
getExportString(flags, context, exportString -> { getExportString(flags, context, exportString -> {
@ -241,25 +244,30 @@ public final class ExportImportUtils {
exportBytes = PasswordUtils.enc(exportString, bytes); exportBytes = PasswordUtils.enc(exportString, bytes);
} catch (final Exception e) { } catch (final Exception e) {
if (fetchListener != null) fetchListener.onResult(false); if (fetchListener != null) fetchListener.onResult(false);
// if (logCollector != null) // if (logCollector != null)
// logCollector.appendException(e, LogFile.UTILS_EXPORT, "Export::isPass"); // logCollector.appendException(e, LogFile.UTILS_EXPORT, "Export::isPass");
if (BuildConfig.DEBUG) Log.e(TAG, "", e); if (BuildConfig.DEBUG) Log.e(TAG, "", e);
} }
} else { } else {
exportBytes = Base64.encode(exportString.getBytes(), Base64.DEFAULT | Base64.NO_WRAP | Base64.NO_PADDING); exportBytes = Base64.encode(exportString.getBytes(), Base64.DEFAULT | Base64.NO_WRAP | Base64.NO_PADDING);
} }
if (exportBytes != null && exportBytes.length > 1) { if (exportBytes != null && exportBytes.length > 1) {
try (final FileOutputStream fos = new FileOutputStream(filePath)) { try (final OutputStream stream = context.getContentResolver().openOutputStream(uri)) {
fos.write(isPass ? 'A' : 'Z'); if (stream == null) return;
fos.write(exportBytes); stream.write(isPass ? 'A' : 'Z');
stream.write(exportBytes);
if (fetchListener != null) fetchListener.onResult(true); if (fetchListener != null) fetchListener.onResult(true);
} catch (final Exception e) { } catch (Exception e) {
if (fetchListener != null) fetchListener.onResult(false); if (fetchListener != null) fetchListener.onResult(false);
// if (logCollector != null) // if (logCollector != null)
// logCollector.appendException(e, LogFile.UTILS_EXPORT, "Export::notPass"); // logCollector.appendException(e, LogFile.UTILS_EXPORT, "Export::notPass");
if (BuildConfig.DEBUG) Log.e(TAG, "", e); Log.e(TAG, "exportData", e);
} }
} else if (fetchListener != null) fetchListener.onResult(false); return;
}
if (fetchListener != null) {
fetchListener.onResult(false);
}
}); });
} }
@ -324,7 +332,7 @@ public final class ExportImportUtils {
}, AppExecutors.getInstance().tasksThread()); }, AppExecutors.getInstance().tasksThread());
return; return;
} catch (final Exception e) { } catch (final Exception e) {
// if (logCollector != null) logCollector.appendException(e, LogFile.UTILS_EXPORT, "getExportString"); // if (logCollector != null) logCollector.appendException(e, LogFile.UTILS_EXPORT, "getExportString");
if (BuildConfig.DEBUG) Log.e(TAG, "", e); if (BuildConfig.DEBUG) Log.e(TAG, "", e);
} }
callback.onCreated(null); callback.onCreated(null);
@ -373,9 +381,9 @@ public final class ExportImportUtils {
jsonArray.put(jsonObject); jsonArray.put(jsonObject);
} }
} catch (Exception e) { } catch (Exception e) {
// if (logCollector != null) { // if (logCollector != null) {
// logCollector.appendException(e, LogFile.UTILS_EXPORT, "getFavorites"); // logCollector.appendException(e, LogFile.UTILS_EXPORT, "getFavorites");
// } // }
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
Log.e(TAG, "Error exporting favorites", e); Log.e(TAG, "Error exporting favorites", e);
} }
@ -409,9 +417,9 @@ public final class ExportImportUtils {
jsonArray.put(jsonObject); jsonArray.put(jsonObject);
} }
} catch (Exception e) { } catch (Exception e) {
// if (logCollector != null) { // if (logCollector != null) {
// logCollector.appendException(e, LogFile.UTILS_EXPORT, "getCookies"); // logCollector.appendException(e, LogFile.UTILS_EXPORT, "getCookies");
// } // }
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
Log.e(TAG, "Error exporting accounts", e); Log.e(TAG, "Error exporting accounts", e);
} }

View File

@ -2,7 +2,6 @@ package awais.instagrabber.utils;
import android.net.Uri; import android.net.Uri;
import android.util.Log; import android.util.Log;
import android.util.Pair;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -76,10 +75,10 @@ public final class ResponseBodyUtils {
if (lastIndexMain >= 0) return sources[lastIndexMain]; if (lastIndexMain >= 0) return sources[lastIndexMain];
else if (lastIndexBase >= 0) return sources[lastIndexBase]; else if (lastIndexBase >= 0) return sources[lastIndexBase];
} catch (final Exception e) { } catch (final Exception e) {
// if (Utils.logCollector != null) // if (Utils.logCollector != null)
// Utils.logCollector.appendException(e, LogCollector.LogFile.UTILS, "getHighQualityPost", // Utils.logCollector.appendException(e, LogCollector.LogFile.UTILS, "getHighQualityPost",
// new Pair<>("resourcesNull", resources == null), // new Pair<>("resourcesNull", resources == null),
// new Pair<>("isVideo", isVideo)); // new Pair<>("isVideo", isVideo));
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e); if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
} }
return null; return null;
@ -94,9 +93,9 @@ public final class ResponseBodyUtils {
src = getHighQualityPost(resources.getJSONObject("image_versions2").getJSONArray("candidates"), false, true, false); src = getHighQualityPost(resources.getJSONObject("image_versions2").getJSONArray("candidates"), false, true, false);
if (src == null) return resources.getString("display_url"); if (src == null) return resources.getString("display_url");
} catch (final Exception e) { } catch (final Exception e) {
// if (Utils.logCollector != null) // if (Utils.logCollector != null)
// Utils.logCollector.appendException(e, LogCollector.LogFile.UTILS, "getHighQualityImage", // Utils.logCollector.appendException(e, LogCollector.LogFile.UTILS, "getHighQualityImage",
// new Pair<>("resourcesNull", resources == null)); // new Pair<>("resourcesNull", resources == null));
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e); if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
} }
return src; return src;
@ -732,8 +731,8 @@ public final class ResponseBodyUtils {
final List<MediaCandidate> candidates = new ArrayList<MediaCandidate>(); final List<MediaCandidate> candidates = new ArrayList<MediaCandidate>();
if (feedItem.has("display_resources") || feedItem.has("thumbnail_resources")) { if (feedItem.has("display_resources") || feedItem.has("thumbnail_resources")) {
final JSONArray displayResources = feedItem.has("display_resources") final JSONArray displayResources = feedItem.has("display_resources")
? feedItem.getJSONArray("display_resources") ? feedItem.getJSONArray("display_resources")
: feedItem.getJSONArray("thumbnail_resources"); : feedItem.getJSONArray("thumbnail_resources");
for (int i = 0; i < displayResources.length(); i++) { for (int i = 0; i < displayResources.length(); i++) {
final JSONObject displayResource = displayResources.getJSONObject(i); final JSONObject displayResource = displayResources.getJSONObject(i);
candidates.add(new MediaCandidate( candidates.add(new MediaCandidate(
@ -1090,9 +1089,10 @@ public final class ResponseBodyUtils {
if (imageVersions2 == null) return null; if (imageVersions2 == null) return null;
final List<MediaCandidate> candidates = imageVersions2.getCandidates(); final List<MediaCandidate> candidates = imageVersions2.getCandidates();
if (candidates == null || candidates.isEmpty()) return null; if (candidates == null || candidates.isEmpty()) return null;
final List<MediaCandidate> sortedCandidates = candidates.stream() final List<MediaCandidate> sortedCandidates = candidates
.stream()
.sorted((c1, c2) -> Integer.compare(c2.getWidth(), c1.getWidth())) .sorted((c1, c2) -> Integer.compare(c2.getWidth(), c1.getWidth()))
.filter(c -> c.getWidth() < type.getValue()) // .filter(c -> c.getWidth() < type.getValue())
.collect(Collectors.toList()); .collect(Collectors.toList());
final MediaCandidate candidate = sortedCandidates.get(0); final MediaCandidate candidate = sortedCandidates.get(0);
if (candidate == null) return null; if (candidate == null) return null;

View File

@ -50,19 +50,15 @@ import java.text.SimpleDateFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
//import javax.crypto.Mac;
//import javax.crypto.spec.SecretKeySpec;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.models.PostsLayoutPreferences; import awais.instagrabber.models.PostsLayoutPreferences;
import awais.instagrabber.models.enums.FavoriteType; import awais.instagrabber.models.enums.FavoriteType;
//import awaisomereport.LogCollector;
public final class Utils { public final class Utils {
private static final String TAG = "Utils"; private static final String TAG = "Utils";
private static final int VIDEO_CACHE_MAX_BYTES = 10 * 1024 * 1024; private static final int VIDEO_CACHE_MAX_BYTES = 10 * 1024 * 1024;
// public static LogCollector logCollector; // public static LogCollector logCollector;
public static SettingsHelper settingsHelper; public static SettingsHelper settingsHelper;
public static boolean sessionVolumeFull = false; public static boolean sessionVolumeFull = false;
public static final MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); public static final MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
@ -93,34 +89,34 @@ public final class Utils {
} }
public static Map<String, String> sign(final Map<String, Object> form) { public static Map<String, String> sign(final Map<String, Object> form) {
// final String signed = sign(Constants.SIGNATURE_KEY, new JSONObject(form).toString()); // final String signed = sign(Constants.SIGNATURE_KEY, new JSONObject(form).toString());
// if (signed == null) { // if (signed == null) {
// return null; // return null;
// } // }
final Map<String, String> map = new HashMap<>(); final Map<String, String> map = new HashMap<>();
// map.put("ig_sig_key_version", Constants.SIGNATURE_VERSION); // map.put("ig_sig_key_version", Constants.SIGNATURE_VERSION);
// map.put("signed_body", signed); // map.put("signed_body", signed);
map.put("signed_body", "SIGNATURE." + new JSONObject(form).toString()); map.put("signed_body", "SIGNATURE." + new JSONObject(form).toString());
return map; return map;
} }
// public static String sign(final String key, final String message) { // public static String sign(final String key, final String message) {
// try { // try {
// final Mac hasher = Mac.getInstance("HmacSHA256"); // final Mac hasher = Mac.getInstance("HmacSHA256");
// hasher.init(new SecretKeySpec(key.getBytes(), "HmacSHA256")); // hasher.init(new SecretKeySpec(key.getBytes(), "HmacSHA256"));
// byte[] hash = hasher.doFinal(message.getBytes()); // byte[] hash = hasher.doFinal(message.getBytes());
// final StringBuilder hexString = new StringBuilder(); // final StringBuilder hexString = new StringBuilder();
// for (byte b : hash) { // for (byte b : hash) {
// final String hex = Integer.toHexString(0xff & b); // final String hex = Integer.toHexString(0xff & b);
// if (hex.length() == 1) hexString.append('0'); // if (hex.length() == 1) hexString.append('0');
// hexString.append(hex); // hexString.append(hex);
// } // }
// return hexString.toString() + "." + message; // return hexString.toString() + "." + message;
// } catch (Exception e) { // } catch (Exception e) {
// Log.e(TAG, "Error signing", e); // Log.e(TAG, "Error signing", e);
// return null; // return null;
// } // }
// } // }
public static String getMimeType(@NonNull final Uri uri, final ContentResolver contentResolver) { public static String getMimeType(@NonNull final Uri uri, final ContentResolver contentResolver) {
String mimeType; String mimeType;

View File

@ -34,7 +34,7 @@ import awais.instagrabber.repositories.responses.directmessages.RankedRecipient;
import awais.instagrabber.repositories.responses.giphy.GiphyGif; import awais.instagrabber.repositories.responses.giphy.GiphyGif;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.DirectoryUtils; import awais.instagrabber.utils.DownloadUtils;
import awais.instagrabber.utils.MediaController; import awais.instagrabber.utils.MediaController;
import awais.instagrabber.utils.MediaUtils; import awais.instagrabber.utils.MediaUtils;
import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.TextUtils;
@ -72,7 +72,7 @@ public class DirectThreadViewModel extends AndroidViewModel {
throw new IllegalArgumentException("User is not logged in!"); throw new IllegalArgumentException("User is not logged in!");
} }
contentResolver = application.getContentResolver(); contentResolver = application.getContentResolver();
recordingsDir = DirectoryUtils.getOutputMediaDirectory(application, "Recordings"); recordingsDir = DownloadUtils.getDownloadDir("Recordings");
final DirectMessagesManager messagesManager = DirectMessagesManager.getInstance(); final DirectMessagesManager messagesManager = DirectMessagesManager.getInstance();
threadManager = messagesManager.getThreadManager(threadId, pending, currentUser, contentResolver); threadManager = messagesManager.getThreadManager(threadId, pending, currentUser, contentResolver);
threadManager.fetchPendingRequests(); threadManager.fetchPendingRequests();

View File

@ -24,7 +24,7 @@ import awais.instagrabber.fragments.imageedit.filters.filters.Filter;
import awais.instagrabber.fragments.imageedit.filters.properties.Property; import awais.instagrabber.fragments.imageedit.filters.properties.Property;
import awais.instagrabber.models.SavedImageEditState; import awais.instagrabber.models.SavedImageEditState;
import awais.instagrabber.utils.AppExecutors; import awais.instagrabber.utils.AppExecutors;
import awais.instagrabber.utils.DirectoryUtils; import awais.instagrabber.utils.DownloadUtils;
import awais.instagrabber.utils.SerializablePair; import awais.instagrabber.utils.SerializablePair;
import jp.co.cyberagent.android.gpuimage.GPUImage; import jp.co.cyberagent.android.gpuimage.GPUImage;
import jp.co.cyberagent.android.gpuimage.filter.GPUImageFilter; import jp.co.cyberagent.android.gpuimage.filter.GPUImageFilter;
@ -56,7 +56,7 @@ public class ImageEditViewModel extends AndroidViewModel {
public ImageEditViewModel(final Application application) { public ImageEditViewModel(final Application application) {
super(application); super(application);
sessionId = SIMPLE_DATE_FORMAT.format(new Date()); sessionId = SIMPLE_DATE_FORMAT.format(new Date());
outputDir = DirectoryUtils.getOutputMediaDirectory(application, "Edit", sessionId); outputDir = DownloadUtils.getImageEditDir(sessionId);
destinationFile = new File(outputDir, RESULT + ".jpg"); destinationFile = new File(outputDir, RESULT + ".jpg");
destinationUri = Uri.fromFile(destinationFile); destinationUri = Uri.fromFile(destinationFile);
cropDestinationUri = Uri.fromFile(new File(outputDir, CROP + ".jpg")); cropDestinationUri = Uri.fromFile(new File(outputDir, CROP + ".jpg"));

View File

@ -69,5 +69,5 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="end"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:text="@string/create_backup" /> android:text="@string/backup" />
</LinearLayout> </LinearLayout>

View File

@ -127,7 +127,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="end"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:text="@string/restore_backup" android:text="@string/restore"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/bottom_password_divider" /> app:layout_constraintTop_toBottomOf="@id/bottom_password_divider" />

View File

@ -477,4 +477,6 @@
<string name="crash_report_title">Select an email app to send crash logs</string> <string name="crash_report_title">Select an email app to send crash logs</string>
<string name="copy_caption">Copy caption</string> <string name="copy_caption">Copy caption</string>
<string name="copy_reply">Copy reply</string> <string name="copy_reply">Copy reply</string>
<string name="restore">Restore</string>
<string name="backup">Backup</string>
</resources> </resources>