From 8320a7509c2bed9897be6caa0cad1efb23152b38 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 14 Jul 2020 16:33:23 +0800 Subject: Add double tap to zoom in ViewImageOrGifActivity. Delete MultiRedditListingActivity. --- app/src/main/AndroidManifest.xml | 5 - .../infinityforreddit/Activity/MainActivity.java | 3 +- .../Activity/MultiRedditListingActivity.java | 302 --------------------- .../Activity/ViewImageOrGifActivity.java | 46 ++++ .../infinityforreddit/AppComponent.java | 3 - .../res/layout/activity_multi_reddit_listing.xml | 84 ------ .../main/res/layout/activity_view_image_or_gif.xml | 3 +- 7 files changed, 50 insertions(+), 396 deletions(-) delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java delete mode 100644 app/src/main/res/layout/activity_multi_reddit_listing.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ca502970..a1e0577c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -89,11 +89,6 @@ android:name=".Activity.ViewMultiRedditDetailActivity" android:parentActivityName=".Activity.MainActivity" android:theme="@style/AppTheme.Slidable" /> - = Build.VERSION_CODES.M) { - Window window = getWindow(); - - if (isChangeStatusBarIconColor()) { - addOnOffsetChangedListener(mAppBarLayout); - } - - if (isImmersiveInterface()) { - window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); - adjustToolbar(mToolbar); - - int navBarHeight = getNavBarHeight(); - if (navBarHeight > 0) { - mRecyclerView.setPadding(0, 0, 0, navBarHeight); - } - } - } - - setSupportActionBar(mToolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - mSwipeRefreshLayout.setOnRefreshListener(this::loadMultiReddits); - - if (savedInstanceState != null) { - mInsertSuccess = savedInstanceState.getBoolean(INSERT_MULTI_REDDIT_STATE); - mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); - mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE); - mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE); - if (!mNullAccessToken && mAccessToken == null) { - getCurrentAccountAndBindView(); - } else { - bindView(); - } - } else { - getCurrentAccountAndBindView(); - } - } - - private void getCurrentAccountAndBindView() { - new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { - if (account == null) { - mNullAccessToken = true; - } else { - mAccessToken = account.getAccessToken(); - mAccountName = account.getUsername(); - } - bindView(); - }).execute(); - } - - private void bindView() { - loadMultiReddits(); - - mGlide = Glide.with(this); - - fab.setOnClickListener(view -> { - Intent intent = new Intent(MultiRedditListingActivity.this, CreateMultiRedditActivity.class); - startActivity(intent); - }); - - mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); - MultiRedditListingRecyclerViewAdapter adapter = new MultiRedditListingRecyclerViewAdapter(this, - mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, mAccessToken, mAccountName); - mRecyclerView.setAdapter(adapter); - mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { - super.onScrolled(recyclerView, dx, dy); - if (dy > 0) { - fab.hide(); - } else { - fab.show(); - } - } - }); - new FastScrollerBuilder(mRecyclerView).build(); - - mMultiRedditViewModel = new ViewModelProvider(this, - new MultiRedditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName)) - .get(MultiRedditViewModel.class); - - mMultiRedditViewModel.getAllMultiReddits().observe(this, subscribedUserData -> { - if (subscribedUserData == null || subscribedUserData.size() == 0) { - mRecyclerView.setVisibility(View.GONE); - mErrorLinearLayout.setVisibility(View.VISIBLE); - mGlide.load(R.drawable.error_image).into(mErrorImageView); - } else { - mErrorLinearLayout.setVisibility(View.GONE); - mRecyclerView.setVisibility(View.VISIBLE); - mGlide.clear(mErrorImageView); - } - adapter.setMultiReddits(subscribedUserData); - }); - - mMultiRedditViewModel.getAllFavoriteMultiReddits().observe(this, favoriteSubscribedUserData -> { - if (favoriteSubscribedUserData != null && favoriteSubscribedUserData.size() > 0) { - mErrorLinearLayout.setVisibility(View.GONE); - mRecyclerView.setVisibility(View.VISIBLE); - mGlide.clear(mErrorImageView); - } - adapter.setFavoriteMultiReddits(favoriteSubscribedUserData); - }); - } - - private void loadMultiReddits() { - mSwipeRefreshLayout.setRefreshing(true); - FetchMyMultiReddits.fetchMyMultiReddits(mOauthRetrofit, mAccessToken, new FetchMyMultiReddits.FetchMyMultiRedditsListener() { - @Override - public void success(ArrayList multiReddits) { - new InsertMultiRedditAsyncTask(mRedditDataRoomDatabase, multiReddits, mAccountName, () -> { - mInsertSuccess = true; - mSwipeRefreshLayout.setRefreshing(false); - }).execute(); - } - - @Override - public void failed() { - mInsertSuccess = false; - mSwipeRefreshLayout.setRefreshing(false); - Toast.makeText(MultiRedditListingActivity.this, R.string.error_loading_multi_reddit_list, Toast.LENGTH_SHORT).show(); - } - }); - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - if (item.getItemId() == android.R.id.home) { - finish(); - return true; - } - - return false; - } - - @Override - protected void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - outState.putBoolean(INSERT_MULTI_REDDIT_STATE, mInsertSuccess); - outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken); - outState.putString(ACCESS_TOKEN_STATE, mAccessToken); - outState.putString(ACCOUNT_NAME_STATE, mAccountName); - } - - @Override - public SharedPreferences getDefaultSharedPreferences() { - return mSharedPreferences; - } - - @Override - protected CustomThemeWrapper getCustomThemeWrapper() { - return mCustomThemeWrapper; - } - - @Override - protected void applyCustomTheme() { - mCoordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); - mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); - mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); - applyFABTheme(fab); - } - - public void deleteMultiReddit(MultiReddit multiReddit) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.delete) - .setMessage(R.string.delete_multi_reddit_dialog_message) - .setPositiveButton(R.string.delete, (dialogInterface, i) - -> DeleteMultiReddit.deleteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, - mAccessToken, mAccountName, multiReddit.getPath(), new DeleteMultiReddit.DeleteMultiRedditListener() { - @Override - public void success() { - Toast.makeText(MultiRedditListingActivity.this, - R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show(); - loadMultiReddits(); - } - - @Override - public void failed() { - Toast.makeText(MultiRedditListingActivity.this, - R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show(); - } - })) - .setNegativeButton(R.string.cancel, null) - .show(); - } - - /*@Subscribe - public void onRefreshMultiRedditsEvent(RefreshMultiRedditsEvent event) { - loadMultiReddits(); - }*/ -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java index 29c123bc..2aa00850 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java @@ -11,6 +11,7 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.text.Html; +import android.util.DisplayMetrics; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -35,6 +36,7 @@ import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.transition.Transition; +import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; import com.github.piasy.biv.BigImageViewer; import com.github.piasy.biv.loader.ImageLoader; import com.github.piasy.biv.loader.glide.GlideImageLoader; @@ -152,6 +154,10 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa setTitle(""); } + DisplayMetrics displayMetrics = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); + int windowHeight = displayMetrics.heightPixels; + mHaulerView.setOnDragDismissedListener(dragDirection -> { int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down; finish(); @@ -214,6 +220,46 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa @Override public void onSuccess(File image) { mProgressBar.setVisibility(View.GONE); + + final SubsamplingScaleImageView view = mImageView.getSSIV(); + + if (view != null) { + view.setMinimumDpi(80); + + view.setOnImageEventListener(new SubsamplingScaleImageView.OnImageEventListener() { + @Override + public void onReady() { + + } + + @Override + public void onImageLoaded() { + view.setDoubleTapZoomDpi(70); + view.setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_FIXED); + view.setQuickScaleEnabled(false); + } + + @Override + public void onPreviewLoadError(Exception e) { + + } + + @Override + public void onImageLoadError(Exception e) { + + } + + @Override + public void onTileLoadError(Exception e) { + + } + + @Override + public void onPreviewReleased() { + + } + }); + } } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index d3c471cf..cd75c469 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -16,7 +16,6 @@ import ml.docilealligator.infinityforreddit.Activity.FilteredThingActivity; import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity; import ml.docilealligator.infinityforreddit.Activity.LoginActivity; import ml.docilealligator.infinityforreddit.Activity.MainActivity; -import ml.docilealligator.infinityforreddit.Activity.MultiRedditListingActivity; import ml.docilealligator.infinityforreddit.Activity.PostImageActivity; import ml.docilealligator.infinityforreddit.Activity.PostLinkActivity; import ml.docilealligator.infinityforreddit.Activity.PostTextActivity; @@ -138,8 +137,6 @@ public interface AppComponent { void inject(ViewImageOrGifActivity viewGIFActivity); - void inject(MultiRedditListingActivity multiRedditListingActivity); - void inject(ViewMultiRedditDetailActivity viewMultiRedditDetailActivity); void inject(ViewVideoActivity viewVideoActivity); diff --git a/app/src/main/res/layout/activity_multi_reddit_listing.xml b/app/src/main/res/layout/activity_multi_reddit_listing.xml deleted file mode 100644 index a7c69f72..00000000 --- a/app/src/main/res/layout/activity_multi_reddit_listing.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_view_image_or_gif.xml b/app/src/main/res/layout/activity_view_image_or_gif.xml index 35cdb0b6..250c5077 100644 --- a/app/src/main/res/layout/activity_view_image_or_gif.xml +++ b/app/src/main/res/layout/activity_view_image_or_gif.xml @@ -28,7 +28,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" app:optimizeDisplay="true" - app:tapToRetry="false" /> + app:tapToRetry="false" + app:initScaleType="centerInside" />