Add double tap to zoom in ViewImageOrGifActivity. Delete MultiRedditListingActivity.

This commit is contained in:
Alex Ning 2020-07-14 16:33:23 +08:00
parent faa15f8d09
commit 8320a7509c
7 changed files with 50 additions and 396 deletions

View File

@ -89,11 +89,6 @@
android:name=".Activity.ViewMultiRedditDetailActivity" android:name=".Activity.ViewMultiRedditDetailActivity"
android:parentActivityName=".Activity.MainActivity" android:parentActivityName=".Activity.MainActivity"
android:theme="@style/AppTheme.Slidable" /> android:theme="@style/AppTheme.Slidable" />
<activity
android:name=".Activity.MultiRedditListingActivity"
android:label="@string/multi_reddit_listing_activity_label"
android:parentActivityName=".Activity.MainActivity"
android:theme="@style/AppTheme.Slidable" />
<activity <activity
android:name=".Activity.AccountSavedThingActivity" android:name=".Activity.AccountSavedThingActivity"
android:label="@string/account_saved_thing_activity_label" android:label="@string/account_saved_thing_activity_label"

View File

@ -479,7 +479,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class); intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
break; break;
case R.string.multi_reddit: 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; break;
case R.string.inbox: case R.string.inbox:
intent = new Intent(MainActivity.this, InboxActivity.class); intent = new Intent(MainActivity.this, InboxActivity.class);

View File

@ -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();
}*/
}

View File

@ -11,6 +11,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html; import android.text.Html;
import android.util.DisplayMetrics;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; 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.CustomTarget;
import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition; import com.bumptech.glide.request.transition.Transition;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.github.piasy.biv.BigImageViewer; import com.github.piasy.biv.BigImageViewer;
import com.github.piasy.biv.loader.ImageLoader; import com.github.piasy.biv.loader.ImageLoader;
import com.github.piasy.biv.loader.glide.GlideImageLoader; import com.github.piasy.biv.loader.glide.GlideImageLoader;
@ -152,6 +154,10 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
setTitle(""); setTitle("");
} }
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int windowHeight = displayMetrics.heightPixels;
mHaulerView.setOnDragDismissedListener(dragDirection -> { mHaulerView.setOnDragDismissedListener(dragDirection -> {
int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down; int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down;
finish(); finish();
@ -214,6 +220,46 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
@Override @Override
public void onSuccess(File image) { public void onSuccess(File image) {
mProgressBar.setVisibility(View.GONE); 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 @Override

View File

@ -16,7 +16,6 @@ import ml.docilealligator.infinityforreddit.Activity.FilteredThingActivity;
import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity; import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.Activity.LoginActivity; import ml.docilealligator.infinityforreddit.Activity.LoginActivity;
import ml.docilealligator.infinityforreddit.Activity.MainActivity; import ml.docilealligator.infinityforreddit.Activity.MainActivity;
import ml.docilealligator.infinityforreddit.Activity.MultiRedditListingActivity;
import ml.docilealligator.infinityforreddit.Activity.PostImageActivity; import ml.docilealligator.infinityforreddit.Activity.PostImageActivity;
import ml.docilealligator.infinityforreddit.Activity.PostLinkActivity; import ml.docilealligator.infinityforreddit.Activity.PostLinkActivity;
import ml.docilealligator.infinityforreddit.Activity.PostTextActivity; import ml.docilealligator.infinityforreddit.Activity.PostTextActivity;
@ -138,8 +137,6 @@ public interface AppComponent {
void inject(ViewImageOrGifActivity viewGIFActivity); void inject(ViewImageOrGifActivity viewGIFActivity);
void inject(MultiRedditListingActivity multiRedditListingActivity);
void inject(ViewMultiRedditDetailActivity viewMultiRedditDetailActivity); void inject(ViewMultiRedditDetailActivity viewMultiRedditDetailActivity);
void inject(ViewVideoActivity viewVideoActivity); void inject(ViewVideoActivity viewVideoActivity);

View File

@ -1,84 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinator_layout_multi_reddit_listing_activity"
tools:context=".Activity.MultiRedditListingActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_layout_multi_reddit_listing_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
app:titleEnabled="false"
app:toolbarId="@+id/toolbar_multi_reddit_listing_activity">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_multi_reddit_listing_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:navigationIcon="?attr/homeAsUpIndicator" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout_multi_reddit_listing_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_multi_reddit_listing_activity"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/fetch_multi_reddit_listing_info_linear_layout_multi_reddit_listing_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="48dp"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ImageView
android:id="@+id/fetch_multi_reddit_listing_info_image_view_multi_reddit_listing_activity"
android:layout_width="150dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/fetch_multi_reddit_listing_info_text_view_multi_reddit_listing_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="@string/no_multi_reddits"
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family" />
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_multi_reddit_listing_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:layout_gravity="bottom|end"
app:srcCompat="@drawable/ic_add_day_night_24dp"
app:tint="@android:color/white" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -28,7 +28,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:optimizeDisplay="true" app:optimizeDisplay="true"
app:tapToRetry="false" /> app:tapToRetry="false"
app:initScaleType="centerInside" />
<LinearLayout <LinearLayout
android:id="@+id/load_image_error_linear_layout_view_image_or_gif_activity" android:id="@+id/load_image_error_linear_layout_view_image_or_gif_activity"