diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-07-14 08:33:23 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-07-14 08:33:23 +0000 |
commit | 8320a7509c2bed9897be6caa0cad1efb23152b38 (patch) | |
tree | b635a103cc63de218d270f824e86c30b8630e870 /app/src/main/java/ml | |
parent | faa15f8d09b157eeb03bb76d6fa2e61f08f2136b (diff) | |
download | infinity-for-reddit-8320a7509c2bed9897be6caa0cad1efb23152b38.tar infinity-for-reddit-8320a7509c2bed9897be6caa0cad1efb23152b38.tar.gz infinity-for-reddit-8320a7509c2bed9897be6caa0cad1efb23152b38.tar.bz2 infinity-for-reddit-8320a7509c2bed9897be6caa0cad1efb23152b38.tar.lz infinity-for-reddit-8320a7509c2bed9897be6caa0cad1efb23152b38.tar.xz infinity-for-reddit-8320a7509c2bed9897be6caa0cad1efb23152b38.tar.zst infinity-for-reddit-8320a7509c2bed9897be6caa0cad1efb23152b38.zip |
Add double tap to zoom in ViewImageOrGifActivity. Delete MultiRedditListingActivity.
Diffstat (limited to 'app/src/main/java/ml')
4 files changed, 48 insertions, 306 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index 4b488bfa..bc15b896 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -479,7 +479,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class); break; case R.string.multi_reddit: - intent = new Intent(MainActivity.this, MultiRedditListingActivity.class); + intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class); + intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true); break; case R.string.inbox: intent = new Intent(MainActivity.this, InboxActivity.class); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java deleted file mode 100644 index 83b34001..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java +++ /dev/null @@ -1,302 +0,0 @@ -package ml.docilealligator.infinityforreddit.Activity; - -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Build; -import android.os.Bundle; -import android.view.MenuItem; -import android.view.View; -import android.view.Window; -import android.view.WindowManager; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.appcompat.widget.Toolbar; -import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.lifecycle.ViewModelProvider; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.RequestManager; -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.dialog.MaterialAlertDialogBuilder; -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import com.r0adkll.slidr.Slidr; - -import java.util.ArrayList; - -import javax.inject.Inject; -import javax.inject.Named; - -import butterknife.BindView; -import butterknife.ButterKnife; -import me.zhanghai.android.fastscroll.FastScrollerBuilder; -import ml.docilealligator.infinityforreddit.Adapter.MultiRedditListingRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; -import ml.docilealligator.infinityforreddit.AsyncTask.InsertMultiRedditAsyncTask; -import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.MultiReddit.DeleteMultiReddit; -import ml.docilealligator.infinityforreddit.MultiReddit.FetchMyMultiReddits; -import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit; -import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditViewModel; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; -import retrofit2.Retrofit; - -public class MultiRedditListingActivity extends BaseActivity { - - private static final String INSERT_MULTI_REDDIT_STATE = "ISSS"; - private static final String NULL_ACCESS_TOKEN_STATE = "NATS"; - private static final String ACCESS_TOKEN_STATE = "ATS"; - private static final String ACCOUNT_NAME_STATE = "ANS"; - - @BindView(R.id.coordinator_layout_multi_reddit_listing_activity) - CoordinatorLayout mCoordinatorLayout; - @BindView(R.id.appbar_layout_multi_reddit_listing_activity) - AppBarLayout mAppBarLayout; - @BindView(R.id.toolbar_multi_reddit_listing_activity) - Toolbar mToolbar; - @BindView(R.id.swipe_refresh_layout_multi_reddit_listing_activity) - SwipeRefreshLayout mSwipeRefreshLayout; - @BindView(R.id.recycler_view_multi_reddit_listing_activity) - RecyclerView mRecyclerView; - @BindView(R.id.fetch_multi_reddit_listing_info_linear_layout_multi_reddit_listing_activity) - LinearLayout mErrorLinearLayout; - @BindView(R.id.fetch_multi_reddit_listing_info_image_view_multi_reddit_listing_activity) - ImageView mErrorImageView; - @BindView(R.id.fetch_multi_reddit_listing_info_text_view_multi_reddit_listing_activity) - TextView mErrorTextView; - @BindView(R.id.fab_multi_reddit_listing_activity) - FloatingActionButton fab; - @Inject - RedditDataRoomDatabase mRedditDataRoomDatabase; - @Inject - @Named("default") - SharedPreferences mSharedPreferences; - @Inject - @Named("oauth") - Retrofit mOauthRetrofit; - @Inject - CustomThemeWrapper mCustomThemeWrapper; - - MultiRedditViewModel mMultiRedditViewModel; - private RequestManager mGlide; - - private boolean mNullAccessToken = false; - private String mAccessToken; - private String mAccountName; - private boolean mInsertSuccess = false; - - @Override - protected void onCreate(Bundle savedInstanceState) { - ((Infinity) getApplication()).getAppComponent().inject(this); - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_multi_reddit_listing); - - ButterKnife.bind(this); - - applyCustomTheme(); - - if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) { - Slidr.attach(this); - } - - if (Build.VERSION.SDK_INT >= 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<MultiReddit> 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); |