saf cleanup, close #1439

This commit is contained in:
Austin Huang 2021-06-20 14:30:08 -04:00
parent 96fd8de879
commit ad69f7d382
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
37 changed files with 15 additions and 323 deletions

View File

@ -66,8 +66,6 @@ import awais.instagrabber.webservices.ServiceCallback;
public class CollectionPostsFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = "CollectionPostsFragment";
private static final int STORAGE_PERM_REQUEST_CODE = 8020;
private static final int STORAGE_PERM_REQUEST_CODE_FOR_SELECTION = 8030;
private MainActivity fragmentActivity;
private FragmentCollectionPostsBinding binding;
@ -76,8 +74,6 @@ public class CollectionPostsFragment extends Fragment implements SwipeRefreshLay
private SavedCollection savedCollection;
private ActionMode actionMode;
private Set<Media> selectedFeedModels;
private Media downloadFeedModel;
private int downloadChildPosition = -1;
private CollectionService collectionService;
private PostsLayoutPreferences layoutPreferences = Utils.getPostsLayoutPreferences(Constants.PREF_SAVED_POSTS_LAYOUT);
private MenuItem deleteMenu, editMenu;
@ -102,12 +98,8 @@ public class CollectionPostsFragment extends Fragment implements SwipeRefreshLay
if (CollectionPostsFragment.this.selectedFeedModels == null) return false;
final Context context = getContext();
if (context == null) return false;
// if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
DownloadUtils.download(context, ImmutableList.copyOf(CollectionPostsFragment.this.selectedFeedModels));
binding.posts.endSelection();
// return true;
// }
// requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE_FOR_SELECTION);
}
return false;
}
@ -137,13 +129,7 @@ public class CollectionPostsFragment extends Fragment implements SwipeRefreshLay
public void onDownloadClick(final Media feedModel, final int childPosition) {
final Context context = getContext();
if (context == null) return;
// if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
// return;
// }
// downloadFeedModel = feedModel;
// downloadChildPosition = -1;
// requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
}
@Override
@ -375,25 +361,6 @@ public class CollectionPostsFragment extends Fragment implements SwipeRefreshLay
resetToolbar();
}
@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
final Context context = getContext();
if (context == null) return;
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
if (downloadFeedModel == null) return;
DownloadUtils.showDownloadDialog(context, downloadFeedModel, downloadChildPosition);
downloadFeedModel = null;
downloadChildPosition = -1;
return;
}
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
binding.posts.endSelection();
}
}
private void resetToolbar() {
fragmentActivity.resetToolbar();
}

View File

@ -26,7 +26,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.constraintlayout.motion.widget.MotionLayout;
import androidx.constraintlayout.motion.widget.MotionScene;
import androidx.core.content.PermissionChecker;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.NavDirections;
@ -72,14 +71,10 @@ import awais.instagrabber.webservices.StoriesRepository;
import awais.instagrabber.webservices.TagsService;
import kotlinx.coroutines.Dispatchers;
import static androidx.core.content.PermissionChecker.checkSelfPermission;
import static awais.instagrabber.utils.DownloadUtils.WRITE_PERMISSION;
import static awais.instagrabber.utils.Utils.settingsHelper;
public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = "HashTagFragment";
private static final int STORAGE_PERM_REQUEST_CODE = 8020;
private static final int STORAGE_PERM_REQUEST_CODE_FOR_SELECTION = 8030;
public static final String ARG_HASHTAG = "hashtag";
@ -98,8 +93,6 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
private GraphQLRepository graphQLRepository;
private boolean storiesFetching;
private Set<Media> selectedFeedModels;
private Media downloadFeedModel;
private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = Utils.getPostsLayoutPreferences(Constants.PREF_HASHTAG_POSTS_LAYOUT);
private LayoutHashtagDetailsBinding hashtagDetailsBinding;
@ -123,12 +116,8 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (HashTagFragment.this.selectedFeedModels == null) return false;
final Context context = getContext();
if (context == null) return false;
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
DownloadUtils.download(context, ImmutableList.copyOf(HashTagFragment.this.selectedFeedModels));
binding.posts.endSelection();
return true;
}
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE_FOR_SELECTION);
DownloadUtils.download(context, ImmutableList.copyOf(HashTagFragment.this.selectedFeedModels));
binding.posts.endSelection();
return true;
}
return false;
@ -159,13 +148,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
public void onDownloadClick(final Media feedModel, final int childPosition) {
final Context context = getContext();
if (context == null) return;
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
return;
}
downloadFeedModel = feedModel;
downloadChildPosition = childPosition;
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
}
@Override
@ -349,25 +332,6 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
return super.onOptionsItemSelected(item);
}
@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
final Context context = getContext();
if (context == null) return;
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
if (downloadFeedModel == null) return;
DownloadUtils.showDownloadDialog(context, downloadFeedModel, downloadChildPosition);
downloadFeedModel = null;
downloadChildPosition = -1;
return;
}
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
binding.posts.endSelection();
}
}
private void init() {
if (getArguments() == null) return;
final HashTagFragmentArgs fragmentArgs = HashTagFragmentArgs.fromBundle(getArguments());

View File

@ -24,7 +24,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.constraintlayout.motion.widget.MotionLayout;
import androidx.constraintlayout.motion.widget.MotionScene;
import androidx.core.content.PermissionChecker;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.NavDirections;
@ -68,14 +67,10 @@ import awais.instagrabber.webservices.ServiceCallback;
import awais.instagrabber.webservices.StoriesRepository;
import kotlinx.coroutines.Dispatchers;
import static androidx.core.content.PermissionChecker.checkSelfPermission;
import static awais.instagrabber.utils.DownloadUtils.WRITE_PERMISSION;
import static awais.instagrabber.utils.Utils.settingsHelper;
public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = "LocationFragment";
private static final int STORAGE_PERM_REQUEST_CODE = 8020;
private static final int STORAGE_PERM_REQUEST_CODE_FOR_SELECTION = 8030;
private MainActivity fragmentActivity;
private FragmentLocationBinding binding;
@ -92,8 +87,6 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
private boolean isLoggedIn;
private boolean storiesFetching;
private Set<Media> selectedFeedModels;
private Media downloadFeedModel;
private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = Utils.getPostsLayoutPreferences(Constants.PREF_LOCATION_POSTS_LAYOUT);
private LayoutLocationDetailsBinding locationDetailsBinding;
@ -117,12 +110,9 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
if (LocationFragment.this.selectedFeedModels == null) return false;
final Context context = getContext();
if (context == null) return false;
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
DownloadUtils.download(context, ImmutableList.copyOf(LocationFragment.this.selectedFeedModels));
binding.posts.endSelection();
return true;
}
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE_FOR_SELECTION);
DownloadUtils.download(context, ImmutableList.copyOf(LocationFragment.this.selectedFeedModels));
binding.posts.endSelection();
return true;
}
return false;
}
@ -152,13 +142,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
public void onDownloadClick(final Media feedModel, final int childPosition) {
final Context context = getContext();
if (context == null) return;
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
return;
}
downloadFeedModel = feedModel;
downloadChildPosition = childPosition;
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
}
@Override
@ -344,25 +328,6 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
return super.onOptionsItemSelected(item);
}
@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
final Context context = getContext();
if (context == null) return;
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
if (downloadFeedModel == null) return;
DownloadUtils.showDownloadDialog(context, downloadFeedModel, downloadChildPosition);
downloadFeedModel = null;
downloadChildPosition = -1;
return;
}
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
binding.posts.endSelection();
}
}
private void init() {
if (getArguments() == null) return;
final LocationFragmentArgs fragmentArgs = LocationFragmentArgs.fromBundle(getArguments());

View File

@ -30,7 +30,6 @@ import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.widget.TooltipCompat;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.PermissionChecker;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.WindowInsetsControllerCompat;
@ -105,10 +104,8 @@ import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.viewmodels.PostViewV2ViewModel;
//import static androidx.core.content.PermissionChecker.checkSelfPermission;
import static awais.instagrabber.fragments.HashTagFragment.ARG_HASHTAG;
import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_SHOWN_COUNT_TOOLTIP;
import static awais.instagrabber.utils.DownloadUtils.WRITE_PERMISSION;
import static awais.instagrabber.utils.Utils.settingsHelper;
public class PostViewV2Fragment extends Fragment implements EditTextDialogFragment.EditTextDialogFragmentCallback {
@ -116,7 +113,6 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
// private static final int DETAILS_HIDE_DELAY_MILLIS = 2000;
public static final String ARG_MEDIA = "media";
public static final String ARG_SLIDER_POSITION = "position";
private static final int STORAGE_PERM_REQUEST_CODE = 8020;
private DialogPostViewBinding binding;
private Context context;
@ -281,16 +277,6 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme
}
}
@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == STORAGE_PERM_REQUEST_CODE && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
final Context context = getContext();
if (context == null) return;
DownloadUtils.showDownloadDialog(context, viewModel.getMedia(), sliderPosition);
}
}
private void init() {
final Bundle arguments = getArguments();
if (arguments == null) {

View File

@ -49,8 +49,6 @@ import static awais.instagrabber.utils.Utils.settingsHelper;
public final class SavedViewerFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = SavedViewerFragment.class.getSimpleName();
private static final int STORAGE_PERM_REQUEST_CODE = 8020;
private static final int STORAGE_PERM_REQUEST_CODE_FOR_SELECTION = 8030;
private FragmentSavedBinding binding;
private String username;
@ -61,8 +59,6 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
private boolean isLoggedIn, shouldRefresh = true;
private PostItemType type;
private Set<Media> selectedFeedModels;
private Media downloadFeedModel;
private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences;
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
@ -85,12 +81,8 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
if (SavedViewerFragment.this.selectedFeedModels == null) return false;
final Context context = getContext();
if (context == null) return false;
// if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
DownloadUtils.download(context, ImmutableList.copyOf(SavedViewerFragment.this.selectedFeedModels));
binding.posts.endSelection();
// return true;
// }
// requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE_FOR_SELECTION);
}
return false;
}
@ -120,13 +112,7 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
public void onDownloadClick(final Media feedModel, final int childPosition) {
final Context context = getContext();
if (context == null) return;
// if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
// return;
// }
// downloadFeedModel = feedModel;
// downloadChildPosition = childPosition;
// requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
}
@Override
@ -306,25 +292,6 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
}
}
@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
final Context context = getContext();
if (context == null) return;
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
if (downloadFeedModel == null) return;
DownloadUtils.showDownloadDialog(context, downloadFeedModel, downloadChildPosition);
downloadFeedModel = null;
downloadChildPosition = -1;
return;
}
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
binding.posts.endSelection();
}
}
private void setTitle() {
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
if (actionBar == null) return;

View File

@ -209,10 +209,7 @@ public class StoryViewerFragment extends Fragment {
if (context == null) return false;
int itemId = item.getItemId();
if (itemId == R.id.action_download) {
if (ContextCompat.checkSelfPermission(context, DownloadUtils.PERMS[0]) == PackageManager.PERMISSION_GRANTED)
downloadStory();
else
ActivityCompat.requestPermissions(requireActivity(), DownloadUtils.PERMS, 8020);
downloadStory();
return true;
}
if (itemId == R.id.action_dms) {
@ -263,13 +260,6 @@ public class StoryViewerFragment extends Fragment {
return false;
}
@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 8020 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
downloadStory();
}
@Override
public void onPause() {
super.onPause();

View File

@ -61,8 +61,6 @@ import awais.instagrabber.webservices.DiscoverService;
public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = TopicPostsFragment.class.getSimpleName();
private static final int STORAGE_PERM_REQUEST_CODE = 8020;
private static final int STORAGE_PERM_REQUEST_CODE_FOR_SELECTION = 8030;
private MainActivity fragmentActivity;
private FragmentTopicPostsBinding binding;
@ -71,8 +69,6 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
private TopicCluster topicCluster;
private ActionMode actionMode;
private Set<Media> selectedFeedModels;
private Media downloadFeedModel;
private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = Utils.getPostsLayoutPreferences(Constants.PREF_TOPIC_POSTS_LAYOUT);
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
@ -95,12 +91,9 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
if (TopicPostsFragment.this.selectedFeedModels == null) return false;
final Context context = getContext();
if (context == null) return false;
// if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
DownloadUtils.download(context, ImmutableList.copyOf(TopicPostsFragment.this.selectedFeedModels));
binding.posts.endSelection();
return true;
// }
// requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE_FOR_SELECTION);
}
return false;
}
@ -130,13 +123,7 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
public void onDownloadClick(final Media feedModel, final int childPosition) {
final Context context = getContext();
if (context == null) return;
// if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
// return;
// }
// downloadFeedModel = feedModel;
// downloadChildPosition = -1;
// requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
}
@Override
@ -299,25 +286,6 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
resetToolbar();
}
@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
final Context context = getContext();
if (context == null) return;
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
if (downloadFeedModel == null) return;
DownloadUtils.showDownloadDialog(context, downloadFeedModel, downloadChildPosition);
downloadFeedModel = null;
downloadChildPosition = -1;
return;
}
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
binding.posts.endSelection();
}
}
private void resetToolbar() {
fragmentActivity.resetToolbar();
}

View File

@ -128,7 +128,6 @@ import awais.instagrabber.viewmodels.factories.DirectThreadViewModelFactory;
public class DirectMessageThreadFragment extends Fragment implements DirectReactionsAdapter.OnReactionClickListener,
EmojiPicker.OnEmojiClickListener {
private static final String TAG = DirectMessageThreadFragment.class.getSimpleName();
private static final int STORAGE_PERM_REQUEST_CODE = 8020;
private static final int AUDIO_RECORD_PERM_REQUEST_CODE = 1000;
private static final int CAMERA_REQUEST_CODE = 200;
private static final String TRANSLATION_Y = "translationY";
@ -490,17 +489,12 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
final Context context = getContext();
if (context == null) return;
if (requestCode == STORAGE_PERM_REQUEST_CODE && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (tempMedia == null) return;
downloadItem(context, tempMedia);
return;
}
if (requestCode == AUDIO_RECORD_PERM_REQUEST_CODE) {
if (PermissionUtils.hasAudioRecordPerms(context)) {
Toast.makeText(context, "You can send voice messages now!", Toast.LENGTH_LONG).show();
return;
}
Toast.makeText(context, "Require RECORD_AUDIO and WRITE_EXTERNAL_STORAGE permissions", Toast.LENGTH_LONG).show();
Toast.makeText(context, "Require RECORD_AUDIO permission", Toast.LENGTH_LONG).show();
}
}
@ -1408,13 +1402,8 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
return;
}
// if (ContextCompat.checkSelfPermission(context, DownloadUtils.PERMS[0]) == PackageManager.PERMISSION_GRANTED) {
DownloadUtils.download(context, media);
Toast.makeText(context, R.string.downloader_downloading_media, Toast.LENGTH_SHORT).show();
// return;
// }
// tempMedia = media;
// requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
}
@Nullable

View File

@ -20,7 +20,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.motion.widget.MotionLayout;
import androidx.constraintlayout.motion.widget.MotionScene;
import androidx.core.content.PermissionChecker;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
@ -57,13 +56,8 @@ import awais.instagrabber.viewmodels.FeedStoriesViewModel;
import awais.instagrabber.webservices.StoriesRepository;
import kotlinx.coroutines.Dispatchers;
import static androidx.core.content.PermissionChecker.checkSelfPermission;
import static awais.instagrabber.utils.DownloadUtils.WRITE_PERMISSION;
public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = "FeedFragment";
private static final int STORAGE_PERM_REQUEST_CODE = 8020;
private static final int STORAGE_PERM_REQUEST_CODE_FOR_SELECTION = 8030;
private MainActivity fragmentActivity;
private MotionLayout root;
@ -75,8 +69,6 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
private boolean storiesFetching;
private ActionMode actionMode;
private Set<Media> selectedFeedModels;
private Media downloadFeedModel;
private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = Utils.getPostsLayoutPreferences(Constants.PREF_POSTS_LAYOUT);
private RecyclerView storiesRecyclerView;
private MenuItem storyListMenu;
@ -129,13 +121,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
public void onDownloadClick(final Media feedModel, final int childPosition) {
final Context context = getContext();
if (context == null) return;
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
return;
}
downloadFeedModel = feedModel;
downloadChildPosition = childPosition;
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
}
@Override
@ -218,12 +204,8 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
if (FeedFragment.this.selectedFeedModels == null) return false;
final Context context = getContext();
if (context == null) return false;
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
DownloadUtils.download(context, ImmutableList.copyOf(FeedFragment.this.selectedFeedModels));
binding.feedRecyclerView.endSelection();
return true;
}
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE_FOR_SELECTION);
DownloadUtils.download(context, ImmutableList.copyOf(FeedFragment.this.selectedFeedModels));
binding.feedRecyclerView.endSelection();
return true;
}
return false;
@ -359,29 +341,6 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
}
}
@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
final boolean granted = grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
final Context context = getContext();
if (context == null) return;
if (!granted) {
Toast.makeText(context, R.string.download_permission, Toast.LENGTH_SHORT).show();
return;
}
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
if (downloadFeedModel == null) return;
DownloadUtils.showDownloadDialog(context, downloadFeedModel, downloadChildPosition);
downloadFeedModel = null;
downloadChildPosition = -1;
return;
}
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
binding.feedRecyclerView.endSelection();
}
}
private void setupFeed() {
binding.feedRecyclerView.setViewModelStoreOwner(this)
.setLifeCycleOwner(this)

View File

@ -30,7 +30,6 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.constraintlayout.motion.widget.MotionLayout;
import androidx.constraintlayout.motion.widget.MotionScene;
import androidx.core.content.PermissionChecker;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
@ -105,14 +104,10 @@ import awais.instagrabber.webservices.StoriesRepository;
import awais.instagrabber.webservices.UserRepository;
import kotlinx.coroutines.Dispatchers;
import static androidx.core.content.PermissionChecker.checkSelfPermission;
import static awais.instagrabber.fragments.HashTagFragment.ARG_HASHTAG;
import static awais.instagrabber.utils.DownloadUtils.WRITE_PERMISSION;
public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private static final String TAG = "ProfileFragment";
private static final int STORAGE_PERM_REQUEST_CODE = 8020;
private static final int STORAGE_PERM_REQUEST_CODE_FOR_SELECTION = 8030;
private MainActivity fragmentActivity;
private MotionLayout root;
@ -139,8 +134,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private boolean accountIsUpdated = false;
private boolean postsSetupDone = false;
private Set<Media> selectedFeedModels;
private Media downloadFeedModel;
private int downloadChildPosition = -1;
private long myId;
private PostsLayoutPreferences layoutPreferences = Utils.getPostsLayoutPreferences(Constants.PREF_PROFILE_POSTS_LAYOUT);
private LayoutProfileDetailsBinding profileDetailsBinding;
@ -199,12 +192,8 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (ProfileFragment.this.selectedFeedModels == null) return false;
final Context context = getContext();
if (context == null) return false;
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
DownloadUtils.download(context, ImmutableList.copyOf(ProfileFragment.this.selectedFeedModels));
binding.postsRecyclerView.endSelection();
return true;
}
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE_FOR_SELECTION);
DownloadUtils.download(context, ImmutableList.copyOf(ProfileFragment.this.selectedFeedModels));
binding.postsRecyclerView.endSelection();
return true;
}
return false;
@ -235,13 +224,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
public void onDownloadClick(final Media feedModel, final int childPosition) {
final Context context = getContext();
if (context == null) return;
if (checkSelfPermission(context, WRITE_PERMISSION) == PermissionChecker.PERMISSION_GRANTED) {
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
return;
}
downloadFeedModel = feedModel;
downloadChildPosition = childPosition;
requestPermissions(DownloadUtils.PERMS, STORAGE_PERM_REQUEST_CODE);
DownloadUtils.showDownloadDialog(context, feedModel, childPosition);
}
@Override
@ -638,25 +621,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
}
}
@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
final boolean granted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
final Context context = getContext();
if (context == null) return;
if (requestCode == STORAGE_PERM_REQUEST_CODE && granted) {
if (downloadFeedModel == null) return;
DownloadUtils.showDownloadDialog(context, downloadFeedModel, downloadChildPosition);
downloadFeedModel = null;
downloadChildPosition = -1;
return;
}
if (requestCode == STORAGE_PERM_REQUEST_CODE_FOR_SELECTION && granted) {
DownloadUtils.download(context, ImmutableList.copyOf(selectedFeedModels));
binding.postsRecyclerView.endSelection();
}
}
private void init() {
disableDm = !Utils.isNavRootInCurrentTabs("direct_messages_nav_graph");
if (getArguments() != null) {

View File

@ -427,7 +427,6 @@
<item quantity="many">%s stories</item>
<item quantity="other">%s stories</item>
</plurals>
<string name="download_permission">لا يوجد إذن للوصول إلى ذاكرة التخزين!</string>
<string name="details">التفاصيل</string>
<string name="title">العنوان</string>
<string name="members">الأعضاء</string>

View File

@ -391,7 +391,6 @@
<item quantity="one">%s història</item>
<item quantity="other">%s històries</item>
</plurals>
<string name="download_permission">No s\'ha concedit el permís d\'emmagatzematge!</string>
<string name="details">Detalls</string>
<string name="title">Títol</string>
<string name="members">Membres</string>

View File

@ -409,7 +409,6 @@
<item quantity="many">%s příběhů</item>
<item quantity="other">%s příběhů</item>
</plurals>
<string name="download_permission">Přístup k úložišti nebyl udělen!</string>
<string name="details">Podrobnosti</string>
<string name="title">Název</string>
<string name="members">Členové</string>

View File

@ -391,7 +391,6 @@
<item quantity="one">%s Story</item>
<item quantity="other">%s Stories</item>
</plurals>
<string name="download_permission">Speicher-Zugriff nicht erteilt!</string>
<string name="details">Details</string>
<string name="title">Titel</string>
<string name="members">Mitglieder</string>

View File

@ -391,7 +391,6 @@
<item quantity="one">%s ιστορία</item>
<item quantity="other">%s ιστορίες</item>
</plurals>
<string name="download_permission">Δεν παραχωρήθηκε άδεια για πρόσβαση στον χώρο αποθήκευσης!</string>
<string name="details">Λεπτομέρειες</string>
<string name="title">Τίτλος</string>
<string name="members">Μέλη</string>

View File

@ -391,7 +391,6 @@
<item quantity="one">%s historia</item>
<item quantity="other">%s historias</item>
</plurals>
<string name="download_permission">¡Permiso de almacenamiento no concecido!</string>
<string name="details">Detalles</string>
<string name="title">Título</string>
<string name="members">Miembros</string>

View File

@ -391,7 +391,6 @@
<item quantity="one">Istorio %s</item>
<item quantity="other">%s istorio</item>
</plurals>
<string name="download_permission">Biltegiratze-baimenik ez da eman!</string>
<string name="details">Xehetasunak</string>
<string name="title">Izenburua</string>
<string name="members">Kideak</string>

View File

@ -392,7 +392,6 @@
<item quantity="one">%s story</item>
<item quantity="other">%s stories</item>
</plurals>
<string name="download_permission">Storage permission not granted!</string>
<string name="details">Details</string>
<string name="title">Title</string>
<string name="members">Members</string>

View File

@ -391,7 +391,6 @@
<item quantity="one">%s story</item>
<item quantity="other">%s stories</item>
</plurals>
<string name="download_permission">L\'autorisation d\'accès au stockage a été refusée !</string>
<string name="details">Détails</string>
<string name="title">Titre</string>
<string name="members">Membres</string>

View File

@ -392,7 +392,6 @@
<item quantity="one">%s story</item>
<item quantity="other">%s stories</item>
</plurals>
<string name="download_permission">स्टोरेज की अनुमति नहीं दी गई</string>
<string name="details">Details</string>
<string name="title">Title</string>
<string name="members">Members</string>

View File

@ -382,7 +382,6 @@
<plurals name="stories_count">
<item quantity="other">%s cerita</item>
</plurals>
<string name="download_permission">Izin penyimpanan ditolak!</string>
<string name="details">Detail</string>
<string name="title">Judul</string>
<string name="members">Anggota</string>

View File

@ -391,7 +391,6 @@
<item quantity="one">%s storia</item>
<item quantity="other">%s storie</item>
</plurals>
<string name="download_permission">Permesso di archiviazione non garantito!</string>
<string name="details">Dettagli</string>
<string name="title">Titolo</string>
<string name="members">Membri</string>

View File

@ -382,7 +382,6 @@
<plurals name="stories_count">
<item quantity="other">%s ストーリー</item>
</plurals>
<string name="download_permission">ストレージへのアクセス権限がありません</string>
<string name="details">詳細</string>
<string name="title">タイトル</string>
<string name="members">メンバー</string>

View File

@ -382,7 +382,6 @@
<plurals name="stories_count">
<item quantity="other">%s개 스토리</item>
</plurals>
<string name="download_permission">Storage permission not granted!</string>
<string name="details">상세내용</string>
<string name="title">제목</string>
<string name="members">멤버</string>

View File

@ -391,7 +391,6 @@
<item quantity="one">%s приказна</item>
<item quantity="other">%s приказни</item>
</plurals>
<string name="download_permission">Нема дозвола за пристап до меморија!</string>
<string name="details">Детали</string>
<string name="title">Наслов</string>
<string name="members">Членови</string>

View File

@ -391,7 +391,6 @@
<item quantity="one">%s verhaal</item>
<item quantity="other">%s verhalen</item>
</plurals>
<string name="download_permission">Opslag toestemming niet verleend!</string>
<string name="details">Details</string>
<string name="title">Titel</string>
<string name="members">Members</string>

View File

@ -391,7 +391,6 @@
<item quantity="one">%s story</item>
<item quantity="other">%s stories</item>
</plurals>
<string name="download_permission">Storage permission not granted!</string>
<string name="details">Details</string>
<string name="title">Title</string>
<string name="members">Members</string>

View File

@ -409,7 +409,6 @@
<item quantity="many">%s relacji</item>
<item quantity="other">%s relacji</item>
</plurals>
<string name="download_permission">Nie przyznano uprawnień do pamięci!</string>
<string name="details">Szczegóły</string>
<string name="title">Tytuł</string>
<string name="members">Członkowie</string>

View File

@ -391,7 +391,6 @@
<item quantity="one">%s story</item>
<item quantity="other">%s stories</item>
</plurals>
<string name="download_permission">Permissão de armazenamento não concedida!</string>
<string name="details">Detalhes</string>
<string name="title">Título</string>
<string name="members">Membros</string>

View File

@ -409,7 +409,6 @@
<item quantity="many">%s историй</item>
<item quantity="other">%s истории</item>
</plurals>
<string name="download_permission">Разрешение на доступ к хранилищу не предоставлено!</string>
<string name="details">Подробнее</string>
<string name="title">Заголовок</string>
<string name="members">Участники</string>

View File

@ -409,7 +409,6 @@
<item quantity="many">%s príbehu</item>
<item quantity="other">%s príbehov</item>
</plurals>
<string name="download_permission">Povolenia na ukladanie neboli udelené!</string>
<string name="details">Detaily</string>
<string name="title">Nadpis</string>
<string name="members">Členovia</string>

View File

@ -391,7 +391,6 @@
<item quantity="one">%s story</item>
<item quantity="other">%s stories</item>
</plurals>
<string name="download_permission">Storage permission not granted!</string>
<string name="details">Detaljer</string>
<string name="title">Titel</string>
<string name="members">Medlemmar</string>

View File

@ -391,7 +391,6 @@
<item quantity="one">%s hikaye</item>
<item quantity="other">%s hikaye</item>
</plurals>
<string name="download_permission">Depolama izni verilmedi!</string>
<string name="details">Detaylar</string>
<string name="title">Başlık</string>
<string name="members">Üyeler</string>

View File

@ -382,7 +382,6 @@
<plurals name="stories_count">
<item quantity="other">%s story</item>
</plurals>
<string name="download_permission">Chưa cấp quyền bộ nhớ!</string>
<string name="details">Chi tiết</string>
<string name="title">Tiêu đề</string>
<string name="members">Thành viên</string>

View File

@ -382,7 +382,6 @@
<plurals name="stories_count">
<item quantity="other">%s 个故事</item>
</plurals>
<string name="download_permission">未授予存储权限!</string>
<string name="details">详情</string>
<string name="title">标题</string>
<string name="members">成员</string>

View File

@ -382,7 +382,6 @@
<plurals name="stories_count">
<item quantity="other">%s 個動態</item>
</plurals>
<string name="download_permission">儲存空間存取權限被拒</string>
<string name="details">詳情</string>
<string name="title">標題</string>
<string name="members">成員</string>

View File

@ -405,7 +405,6 @@
<item quantity="one">%s story</item>
<item quantity="other">%s stories</item>
</plurals>
<string name="download_permission">Storage permission not granted!</string>
<string name="details">Details</string>
<string name="title">Title</string>
<string name="members">Members</string>