fix: 修复部分导致闪退的问题
This commit is contained in:
parent
7e653906e4
commit
b02f17d419
|
|
@ -170,7 +170,7 @@ class FloorActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResponse(call: Call<SubFloorListBean>, response: Response<SubFloorListBean>) {
|
override fun onResponse(call: Call<SubFloorListBean>, response: Response<SubFloorListBean>) {
|
||||||
val subFloorListBean = response.body()!!
|
val subFloorListBean = response.body() ?: return
|
||||||
pid = subFloorListBean.post!!.id
|
pid = subFloorListBean.post!!.id
|
||||||
spid = null
|
spid = null
|
||||||
if (Integer.valueOf(subFloorListBean.page!!.currentPage) >= Integer.valueOf(subFloorListBean.page.totalPage)) {
|
if (Integer.valueOf(subFloorListBean.page!!.currentPage) >= Integer.valueOf(subFloorListBean.page.totalPage)) {
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,10 @@ class ForumActivity : BaseActivity(), View.OnClickListener, OnRefreshedListener
|
||||||
forumName = intent.getStringExtra(EXTRA_FORUM_NAME)
|
forumName = intent.getStringExtra(EXTRA_FORUM_NAME)
|
||||||
title = getString(R.string.title_forum, forumName)
|
title = getString(R.string.title_forum, forumName)
|
||||||
}
|
}
|
||||||
|
if (forumName == null) {
|
||||||
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
initView()
|
initView()
|
||||||
setTitle(title)
|
setTitle(title)
|
||||||
initData()
|
initData()
|
||||||
|
|
|
||||||
|
|
@ -668,7 +668,7 @@ class ThreadActivity : BaseActivity(), View.OnClickListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun finish() {
|
override fun finish() {
|
||||||
if (dataBean != null) {
|
if (dataBean != null && dataBean!!.thread != null) {
|
||||||
val postListItemBean = lastVisibleItem
|
val postListItemBean = lastVisibleItem
|
||||||
var extras = ""
|
var extras = ""
|
||||||
if (postListItemBean != null) {
|
if (postListItemBean != null) {
|
||||||
|
|
@ -682,8 +682,9 @@ class ThreadActivity : BaseActivity(), View.OnClickListener {
|
||||||
.setExtras(extras)
|
.setExtras(extras)
|
||||||
.setTitle(dataBean!!.thread.title)
|
.setTitle(dataBean!!.thread.title)
|
||||||
.setType(HistoryHelper.TYPE_THREAD)
|
.setType(HistoryHelper.TYPE_THREAD)
|
||||||
if (dataBean!!.thread != null && dataBean!!.thread.author != null) {
|
if (dataBean!!.thread.author != null) {
|
||||||
history.setAvatar(dataBean!!.thread.author.portrait).username = dataBean!!.thread.author.nameShow
|
history.avatar = dataBean!!.thread.author.portrait
|
||||||
|
history.username = dataBean!!.thread.author.nameShow
|
||||||
}
|
}
|
||||||
historyHelper!!.writeHistory(history)
|
historyHelper!!.writeHistory(history)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,365 +0,0 @@
|
||||||
package com.huanchengfly.tieba.post.activities;
|
|
||||||
|
|
||||||
import android.animation.Animator;
|
|
||||||
import android.animation.AnimatorListenerAdapter;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.ProgressBar;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.appcompat.widget.Toolbar;
|
|
||||||
import androidx.viewpager2.widget.ViewPager2;
|
|
||||||
|
|
||||||
import com.google.android.material.bottomappbar.BottomAppBar;
|
|
||||||
import com.huanchengfly.theme.utils.ThemeUtils;
|
|
||||||
import com.huanchengfly.tieba.api.TiebaApi;
|
|
||||||
import com.huanchengfly.tieba.api.models.PicPageBean;
|
|
||||||
import com.huanchengfly.tieba.post.R;
|
|
||||||
import com.huanchengfly.tieba.post.activities.base.BaseActivity;
|
|
||||||
import com.huanchengfly.tieba.post.adapters.PhotoViewAdapter;
|
|
||||||
import com.huanchengfly.tieba.post.base.Config;
|
|
||||||
import com.huanchengfly.tieba.post.fragments.PhotoViewFragment;
|
|
||||||
import com.huanchengfly.tieba.post.models.PhotoViewBean;
|
|
||||||
import com.huanchengfly.tieba.post.utils.AnimUtil;
|
|
||||||
import com.huanchengfly.tieba.post.utils.ImageUtil;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import retrofit2.Call;
|
|
||||||
import retrofit2.Callback;
|
|
||||||
import retrofit2.Response;
|
|
||||||
|
|
||||||
public class PhotoViewActivity extends BaseActivity implements PhotoViewFragment.OnChangeBottomBarVisibilityListener, Toolbar.OnMenuItemClickListener {
|
|
||||||
public static final String TAG = PhotoViewActivity.class.getSimpleName();
|
|
||||||
public static final String EXTRA_BEANS = "beans";
|
|
||||||
public static final String EXTRA_POSITION = "position";
|
|
||||||
public static final String EXTRA_FORUM_ID = "forum_id";
|
|
||||||
public static final String EXTRA_FORUM_NAME = "forum_name";
|
|
||||||
public static final String EXTRA_THREAD_ID = "thread_id";
|
|
||||||
public static final String EXTRA_SEE_LZ = "see_lz";
|
|
||||||
public static final String EXTRA_IS_FRS = "is_frs";
|
|
||||||
public static final String EXTRA_OBJ_TYPE = "obj_type";
|
|
||||||
public static final int DEFAULT_HIDE_DELAY = 3000;
|
|
||||||
public static final String OBJ_TYPE_THREAD_PAGE = "pb";
|
|
||||||
public static final String OBJ_TYPE_FORUM_PAGE = "frs";
|
|
||||||
private static Handler handler = new Handler();
|
|
||||||
private List<PhotoViewBean> photoViewBeans;
|
|
||||||
private int startPosition;
|
|
||||||
private ProgressBar progressBar;
|
|
||||||
private TextView mCounter;
|
|
||||||
private BottomAppBar mAppBar;
|
|
||||||
private int lastIndex;
|
|
||||||
private boolean loadFinished = false;
|
|
||||||
private String amount;
|
|
||||||
private PhotoViewAdapter mAdapter;
|
|
||||||
private String forumName;
|
|
||||||
private String forumId;
|
|
||||||
private String threadId;
|
|
||||||
private boolean seeLz;
|
|
||||||
private boolean isFrs;
|
|
||||||
private String objType;
|
|
||||||
private ViewPager2 mViewPager;
|
|
||||||
private Runnable autoHideRunnable = this::onHide;
|
|
||||||
private boolean mLoading;
|
|
||||||
|
|
||||||
public static void launch(@NonNull Context context, PhotoViewBean photoViewBean) {
|
|
||||||
launch(context, new PhotoViewBean[]{photoViewBean});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void launch(@NonNull Context context, List<PhotoViewBean> photoViewBeanList) {
|
|
||||||
launch(context, photoViewBeanList.toArray(new PhotoViewBean[0]), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void launch(@NonNull Context context, List<PhotoViewBean> photoViewBeanList, int position) {
|
|
||||||
launch(context, photoViewBeanList.toArray(new PhotoViewBean[0]), position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void launch(@NonNull Context context, PhotoViewBean[] photoViewBeans) {
|
|
||||||
launch(context, photoViewBeans, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void launch(@NonNull Context context, PhotoViewBean[] photoViewBeans, int position) {
|
|
||||||
context.startActivity(new Intent(context, PhotoViewActivity.class)
|
|
||||||
.putExtra(EXTRA_BEANS, photoViewBeans)
|
|
||||||
.putExtra(EXTRA_POSITION, position)
|
|
||||||
.putExtra(EXTRA_IS_FRS, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void launch(@NonNull Context context,
|
|
||||||
PhotoViewBean[] photoViewBeans,
|
|
||||||
int position,
|
|
||||||
String forumName,
|
|
||||||
String forumId,
|
|
||||||
String threadId,
|
|
||||||
boolean seeLz,
|
|
||||||
String objType) {
|
|
||||||
context.startActivity(new Intent(context, PhotoViewActivity.class)
|
|
||||||
.putExtra(EXTRA_BEANS, photoViewBeans)
|
|
||||||
.putExtra(EXTRA_POSITION, position)
|
|
||||||
.putExtra(EXTRA_IS_FRS, true)
|
|
||||||
.putExtra(EXTRA_FORUM_NAME, forumName)
|
|
||||||
.putExtra(EXTRA_FORUM_ID, forumId)
|
|
||||||
.putExtra(EXTRA_THREAD_ID, threadId)
|
|
||||||
.putExtra(EXTRA_SEE_LZ, seeLz)
|
|
||||||
.putExtra(EXTRA_OBJ_TYPE, objType));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadMore() {
|
|
||||||
if (loadFinished) {
|
|
||||||
progressBar.setVisibility(View.GONE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (mLoading) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mLoading = true;
|
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
|
||||||
PhotoViewBean lastBean = photoViewBeans.get(photoViewBeans.size() - 1);
|
|
||||||
TiebaApi.getInstance().picPage(
|
|
||||||
forumId,
|
|
||||||
forumName,
|
|
||||||
threadId,
|
|
||||||
seeLz,
|
|
||||||
ImageUtil.getPicId(lastBean.getOriginUrl()),
|
|
||||||
String.valueOf(photoViewBeans.size()),
|
|
||||||
objType,
|
|
||||||
false
|
|
||||||
).enqueue(new Callback<PicPageBean>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NotNull Call<PicPageBean> call, @NotNull Response<PicPageBean> response) {
|
|
||||||
PicPageBean data = response.body();
|
|
||||||
mLoading = false;
|
|
||||||
progressBar.setVisibility(View.GONE);
|
|
||||||
amount = data.getPicAmount();
|
|
||||||
updateCounter(mViewPager.getCurrentItem());
|
|
||||||
List<PicPageBean.PicBean> picBeans = new ArrayList<>();
|
|
||||||
List<PicPageBean.ImgInfoBean> imgInfoBeans = new ArrayList<>();
|
|
||||||
if (data.getPicList().size() > 0) {
|
|
||||||
int index = Integer.valueOf(data.getPicList().get(data.getPicList().size() - 1).getOverAllIndex());
|
|
||||||
loadFinished = index >= Integer.valueOf(amount);
|
|
||||||
for (PicPageBean.PicBean picBean : data.getPicList()) {
|
|
||||||
picBeans.add(picBean);
|
|
||||||
imgInfoBeans.add(picBean.getImg().getOriginal());
|
|
||||||
}
|
|
||||||
lastIndex = Integer.parseInt(picBeans.get(0).getOverAllIndex());
|
|
||||||
for (PhotoViewBean photoViewBean : photoViewBeans) {
|
|
||||||
int ind = lastIndex - (photoViewBeans.size() - 1 - photoViewBeans.indexOf(photoViewBean));
|
|
||||||
photoViewBean.setIndex(String.valueOf(ind));
|
|
||||||
}
|
|
||||||
picBeans.remove(0);
|
|
||||||
imgInfoBeans.remove(0);
|
|
||||||
List<PhotoViewBean> beans = new ArrayList<>();
|
|
||||||
for (PicPageBean.ImgInfoBean imgInfoBean : imgInfoBeans) {
|
|
||||||
PhotoViewBean photoViewBean = new PhotoViewBean(imgInfoBean.getBigCdnSrc(),
|
|
||||||
imgInfoBean.getOriginalSrc(),
|
|
||||||
Integer.parseInt(imgInfoBean.getHeight()) > Config.EXACT_SCREEN_HEIGHT,
|
|
||||||
picBeans.get(imgInfoBeans.indexOf(imgInfoBean)).getOverAllIndex(),
|
|
||||||
TextUtils.equals(imgInfoBean.getFormat(), "2"));
|
|
||||||
beans.add(photoViewBean);
|
|
||||||
}
|
|
||||||
mAdapter.insert(beans);
|
|
||||||
photoViewBeans = mAdapter.getData();
|
|
||||||
mAdapter.notifyDataSetChanged();
|
|
||||||
updateCounter(mViewPager.getCurrentItem());
|
|
||||||
} else {
|
|
||||||
loadFinished = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NotNull Call<PicPageBean> call, @NotNull Throwable t) {
|
|
||||||
mLoading = false;
|
|
||||||
progressBar.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadFrs() {
|
|
||||||
forumName = getIntent().getStringExtra(EXTRA_FORUM_NAME);
|
|
||||||
forumId = getIntent().getStringExtra(EXTRA_FORUM_ID);
|
|
||||||
threadId = getIntent().getStringExtra(EXTRA_THREAD_ID);
|
|
||||||
seeLz = getIntent().getBooleanExtra(EXTRA_SEE_LZ, false);
|
|
||||||
objType = getIntent().getStringExtra(EXTRA_OBJ_TYPE);
|
|
||||||
loadMore();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_photo_view);
|
|
||||||
View decorView = getWindow().getDecorView();
|
|
||||||
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
||||||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
|
||||||
decorView.setSystemUiVisibility(uiOptions);
|
|
||||||
mViewPager = (ViewPager2) findViewById(R.id.view_pager);
|
|
||||||
mCounter = (TextView) findViewById(R.id.counter);
|
|
||||||
mAppBar = (BottomAppBar) findViewById(R.id.bottom_app_bar);
|
|
||||||
mAppBar.setOnMenuItemClickListener(this);
|
|
||||||
Drawable overflowIcon = mAppBar.getOverflowIcon();
|
|
||||||
if (overflowIcon != null) {
|
|
||||||
mAppBar.setOverflowIcon(ThemeUtils.tintDrawable(overflowIcon, Color.WHITE));
|
|
||||||
}
|
|
||||||
progressBar = (ProgressBar) findViewById(R.id.progressBar);
|
|
||||||
isFrs = getIntent().getBooleanExtra(EXTRA_IS_FRS, false);
|
|
||||||
photoViewBeans = new ArrayList<>();
|
|
||||||
startPosition = getIntent().getIntExtra(EXTRA_POSITION, 0);
|
|
||||||
Parcelable[] parcelables = getIntent().getParcelableArrayExtra(EXTRA_BEANS);
|
|
||||||
for (Parcelable parcelable : parcelables) {
|
|
||||||
photoViewBeans.add((PhotoViewBean) parcelable);
|
|
||||||
}
|
|
||||||
amount = String.valueOf(photoViewBeans.size());
|
|
||||||
mAdapter = new PhotoViewAdapter(this, photoViewBeans);
|
|
||||||
mViewPager.setAdapter(mAdapter);
|
|
||||||
mViewPager.setCurrentItem(startPosition, false);
|
|
||||||
updateCounter();
|
|
||||||
mViewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
|
||||||
@Override
|
|
||||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
||||||
onShow(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPageSelected(int position) {
|
|
||||||
updateCounter(position);
|
|
||||||
onShow(true);
|
|
||||||
if (!mLoading && isFrs && position >= photoViewBeans.size() - 1) {
|
|
||||||
loadMore();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (isFrs) {
|
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
|
||||||
loadFrs();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNeedImmersionBar() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void finish() {
|
|
||||||
super.finish();
|
|
||||||
overridePendingTransition(R.anim.anim_fade_in, R.anim.anim_fade_out);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBackPressed() {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateCounter() {
|
|
||||||
updateCounter(startPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateCounter(int position) {
|
|
||||||
onShow(true);
|
|
||||||
if (photoViewBeans.size() <= 1) {
|
|
||||||
Log.i(TAG, "updateCounter: null");
|
|
||||||
mCounter.setText(null);
|
|
||||||
} else if (isFrs && lastIndex > 0) {
|
|
||||||
String index = photoViewBeans.get(position).getIndex();
|
|
||||||
mCounter.setText(getString(R.string.tip_position, index == null ? position + 1 + "" : index, amount));
|
|
||||||
} else {
|
|
||||||
mCounter.setText(getString(R.string.tip_position, position + 1 + "", amount));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onShow(boolean autoHide) {
|
|
||||||
handler.removeCallbacks(autoHideRunnable);
|
|
||||||
if (mAppBar.getVisibility() == View.VISIBLE) {
|
|
||||||
if (autoHide) {
|
|
||||||
handler.postDelayed(autoHideRunnable, DEFAULT_HIDE_DELAY);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
AnimUtil.alphaIn(mAppBar)
|
|
||||||
.setListener(new AnimatorListenerAdapter() {
|
|
||||||
@Override
|
|
||||||
public void onAnimationEnd(Animator animation) {
|
|
||||||
mAppBar.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAnimationEnd(Animator animation, boolean isReverse) {
|
|
||||||
if (autoHide) {
|
|
||||||
handler.postDelayed(autoHideRunnable, DEFAULT_HIDE_DELAY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onHide() {
|
|
||||||
if (mAppBar.getVisibility() == View.GONE || mViewPager.getOrientation() != ViewPager2.ORIENTATION_HORIZONTAL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
AnimUtil.alphaOut(mAppBar)
|
|
||||||
.setListener(new AnimatorListenerAdapter() {
|
|
||||||
@Override
|
|
||||||
public void onAnimationEnd(Animator animation) {
|
|
||||||
mAppBar.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case R.id.menu_toggle_orientation:
|
|
||||||
item.setIcon(mViewPager.getOrientation() == ViewPager2.ORIENTATION_HORIZONTAL ?
|
|
||||||
R.drawable.ic_round_view_day_white :
|
|
||||||
R.drawable.ic_round_view_carousel_white);
|
|
||||||
item.setTitle(mViewPager.getOrientation() == ViewPager2.ORIENTATION_HORIZONTAL ?
|
|
||||||
R.string.title_comic_mode_on :
|
|
||||||
R.string.title_comic_mode);
|
|
||||||
Toast.makeText(this, mViewPager.getOrientation() == ViewPager2.ORIENTATION_HORIZONTAL ?
|
|
||||||
R.string.toast_comic_mode_on :
|
|
||||||
R.string.toast_comic_mode_off, Toast.LENGTH_SHORT).show();
|
|
||||||
mViewPager.setOrientation(mViewPager.getOrientation() == ViewPager2.ORIENTATION_HORIZONTAL ?
|
|
||||||
ViewPager2.ORIENTATION_VERTICAL :
|
|
||||||
ViewPager2.ORIENTATION_HORIZONTAL);
|
|
||||||
return true;
|
|
||||||
case R.id.menu_save_image:
|
|
||||||
ImageUtil.download(this, mAdapter.getBean(mViewPager.getCurrentItem()).getOriginUrl(), mAdapter.getBean(mViewPager.getCurrentItem()).isGif());
|
|
||||||
return true;
|
|
||||||
case R.id.menu_share:
|
|
||||||
Toast.makeText(this, R.string.toast_preparing_share_pic, Toast.LENGTH_SHORT).show();
|
|
||||||
ImageUtil.download(this, mAdapter.getBean(mViewPager.getCurrentItem()).getOriginUrl(), mAdapter.getBean(mViewPager.getCurrentItem()).isGif(), true, uri -> {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
||||||
intent.putExtra(Intent.EXTRA_STREAM, uri);
|
|
||||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
||||||
} else {
|
|
||||||
intent.putExtra(Intent.EXTRA_STREAM, uri);
|
|
||||||
}
|
|
||||||
intent.setType(Intent.normalizeMimeType("image/jpeg"));
|
|
||||||
Intent chooser = Intent.createChooser(intent, getString(R.string.title_share_pic));
|
|
||||||
if (intent.resolveActivity(getPackageManager()) != null) {
|
|
||||||
startActivity(chooser);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,331 @@
|
||||||
|
package com.huanchengfly.tieba.post.activities
|
||||||
|
|
||||||
|
import android.animation.Animator
|
||||||
|
import android.animation.AnimatorListenerAdapter
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.os.Handler
|
||||||
|
import android.view.MenuItem
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.ProgressBar
|
||||||
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.appcompat.widget.Toolbar
|
||||||
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
|
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
||||||
|
import butterknife.BindView
|
||||||
|
import com.google.android.material.bottomappbar.BottomAppBar
|
||||||
|
import com.huanchengfly.theme.utils.ThemeUtils
|
||||||
|
import com.huanchengfly.tieba.api.TiebaApi.getInstance
|
||||||
|
import com.huanchengfly.tieba.api.models.PicPageBean
|
||||||
|
import com.huanchengfly.tieba.api.models.PicPageBean.ImgInfoBean
|
||||||
|
import com.huanchengfly.tieba.post.R
|
||||||
|
import com.huanchengfly.tieba.post.activities.base.BaseActivity
|
||||||
|
import com.huanchengfly.tieba.post.adapters.PhotoViewAdapter
|
||||||
|
import com.huanchengfly.tieba.post.base.Config
|
||||||
|
import com.huanchengfly.tieba.post.fragments.PhotoViewFragment.OnChangeBottomBarVisibilityListener
|
||||||
|
import com.huanchengfly.tieba.post.models.PhotoViewBean
|
||||||
|
import com.huanchengfly.tieba.post.utils.AnimUtil
|
||||||
|
import com.huanchengfly.tieba.post.utils.ImageUtil
|
||||||
|
import retrofit2.Call
|
||||||
|
import retrofit2.Callback
|
||||||
|
import retrofit2.Response
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class PhotoViewActivity : BaseActivity(), OnChangeBottomBarVisibilityListener, Toolbar.OnMenuItemClickListener {
|
||||||
|
@BindView(R.id.progressBar)
|
||||||
|
lateinit var progressBar: ProgressBar
|
||||||
|
@BindView(R.id.counter)
|
||||||
|
lateinit var mCounter: TextView
|
||||||
|
@BindView(R.id.bottom_app_bar)
|
||||||
|
lateinit var mAppBar: BottomAppBar
|
||||||
|
@BindView(R.id.view_pager)
|
||||||
|
lateinit var mViewPager: ViewPager2
|
||||||
|
|
||||||
|
private lateinit var photoViewBeans: MutableList<PhotoViewBean>
|
||||||
|
private lateinit var mAdapter: PhotoViewAdapter
|
||||||
|
private var startPosition = 0
|
||||||
|
private var lastIndex = 0
|
||||||
|
private var seeLz = false
|
||||||
|
private var isFrs = false
|
||||||
|
private var mLoading = false
|
||||||
|
private var loadFinished = false
|
||||||
|
private val autoHideRunnable = Runnable { onHide() }
|
||||||
|
private var amount: String? = null
|
||||||
|
private var forumName: String? = null
|
||||||
|
private var forumId: String? = null
|
||||||
|
private var threadId: String? = null
|
||||||
|
private var objType: String? = null
|
||||||
|
|
||||||
|
private fun loadMore() {
|
||||||
|
if (loadFinished) {
|
||||||
|
progressBar.visibility = View.GONE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (mLoading) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mLoading = true
|
||||||
|
progressBar.visibility = View.VISIBLE
|
||||||
|
val lastBean = photoViewBeans[photoViewBeans.size - 1]
|
||||||
|
getInstance().picPage(
|
||||||
|
forumId!!,
|
||||||
|
forumName!!,
|
||||||
|
threadId!!,
|
||||||
|
seeLz,
|
||||||
|
ImageUtil.getPicId(lastBean.originUrl), photoViewBeans.size.toString(),
|
||||||
|
objType!!,
|
||||||
|
false
|
||||||
|
).enqueue(object : Callback<PicPageBean?> {
|
||||||
|
override fun onResponse(call: Call<PicPageBean?>, response: Response<PicPageBean?>) {
|
||||||
|
val data = response.body()!!
|
||||||
|
mLoading = false
|
||||||
|
progressBar.visibility = View.GONE
|
||||||
|
amount = data.picAmount ?: "${photoViewBeans.size}"
|
||||||
|
updateCounter(mViewPager.currentItem)
|
||||||
|
val picBeans: MutableList<PicPageBean.PicBean> = ArrayList()
|
||||||
|
val imgInfoBeans: MutableList<ImgInfoBean> = ArrayList()
|
||||||
|
if (data.picList.isNotEmpty()) {
|
||||||
|
val index = data.picList.last().overAllIndex.toInt()
|
||||||
|
loadFinished = index >= amount!!.toInt()
|
||||||
|
picBeans.addAll(data.picList)
|
||||||
|
picBeans.forEach {
|
||||||
|
imgInfoBeans.add(it.img.original)
|
||||||
|
}
|
||||||
|
lastIndex = picBeans.first().overAllIndex.toInt()
|
||||||
|
for (photoViewBean in photoViewBeans) {
|
||||||
|
val ind = lastIndex - (photoViewBeans.size - 1 - photoViewBeans.indexOf(photoViewBean))
|
||||||
|
photoViewBean.index = ind.toString()
|
||||||
|
}
|
||||||
|
picBeans.removeAt(0)
|
||||||
|
imgInfoBeans.removeAt(0)
|
||||||
|
val beans = imgInfoBeans.mapIndexed { i, it ->
|
||||||
|
PhotoViewBean(it.bigCdnSrc,
|
||||||
|
it.originalSrc,
|
||||||
|
(it.height ?: "0").toInt() > Config.EXACT_SCREEN_HEIGHT,
|
||||||
|
picBeans[i].overAllIndex,
|
||||||
|
"2" == it.format)
|
||||||
|
}.toMutableList()
|
||||||
|
mAdapter.insert(beans)
|
||||||
|
photoViewBeans = mAdapter.data
|
||||||
|
mAdapter.notifyDataSetChanged()
|
||||||
|
updateCounter(mViewPager.currentItem)
|
||||||
|
} else {
|
||||||
|
loadFinished = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(call: Call<PicPageBean?>, t: Throwable) {
|
||||||
|
mLoading = false
|
||||||
|
progressBar.visibility = View.GONE
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadFrs() {
|
||||||
|
forumName = intent.getStringExtra(EXTRA_FORUM_NAME)
|
||||||
|
forumId = intent.getStringExtra(EXTRA_FORUM_ID)
|
||||||
|
threadId = intent.getStringExtra(EXTRA_THREAD_ID)
|
||||||
|
seeLz = intent.getBooleanExtra(EXTRA_SEE_LZ, false)
|
||||||
|
objType = intent.getStringExtra(EXTRA_OBJ_TYPE)
|
||||||
|
loadMore()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getLayoutId(): Int {
|
||||||
|
return R.layout.activity_photo_view
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||||
|
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
|
||||||
|
mAppBar.setOnMenuItemClickListener(this)
|
||||||
|
val overflowIcon = mAppBar.overflowIcon
|
||||||
|
if (overflowIcon != null) {
|
||||||
|
mAppBar.overflowIcon = ThemeUtils.tintDrawable(overflowIcon, Color.WHITE)
|
||||||
|
}
|
||||||
|
isFrs = intent.getBooleanExtra(EXTRA_IS_FRS, false)
|
||||||
|
photoViewBeans = mutableListOf()
|
||||||
|
startPosition = intent.getIntExtra(EXTRA_POSITION, 0)
|
||||||
|
val parcelables = intent.getParcelableArrayExtra(EXTRA_BEANS)
|
||||||
|
photoViewBeans.addAll(parcelables.map { it as PhotoViewBean })
|
||||||
|
amount = photoViewBeans.size.toString()
|
||||||
|
mAdapter = PhotoViewAdapter(this, photoViewBeans)
|
||||||
|
mViewPager.adapter = mAdapter
|
||||||
|
mViewPager.setCurrentItem(startPosition, false)
|
||||||
|
updateCounter()
|
||||||
|
mViewPager.registerOnPageChangeCallback(object : OnPageChangeCallback() {
|
||||||
|
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
||||||
|
onShow(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageSelected(position: Int) {
|
||||||
|
updateCounter(position)
|
||||||
|
onShow(true)
|
||||||
|
if (!mLoading && isFrs && position >= photoViewBeans.size - 1) {
|
||||||
|
loadMore()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (isFrs) {
|
||||||
|
progressBar.visibility = View.VISIBLE
|
||||||
|
loadFrs()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isNeedImmersionBar(): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun finish() {
|
||||||
|
super.finish()
|
||||||
|
overridePendingTransition(R.anim.anim_fade_in, R.anim.anim_fade_out)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBackPressed() {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateCounter(position: Int = startPosition) {
|
||||||
|
onShow(true)
|
||||||
|
if (photoViewBeans.size <= 1) {
|
||||||
|
mCounter.text = null
|
||||||
|
} else if (isFrs && lastIndex > 0) {
|
||||||
|
val index = photoViewBeans[position].index
|
||||||
|
mCounter.text = getString(R.string.tip_position, (index ?: position
|
||||||
|
+ 1).toString(), amount)
|
||||||
|
} else {
|
||||||
|
mCounter.text = getString(R.string.tip_position, (position + 1).toString(), amount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onShow(autoHide: Boolean) {
|
||||||
|
handler.removeCallbacks(autoHideRunnable)
|
||||||
|
if (mAppBar.visibility == View.VISIBLE) {
|
||||||
|
if (autoHide) {
|
||||||
|
handler.postDelayed(autoHideRunnable, DEFAULT_HIDE_DELAY.toLong())
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
AnimUtil.alphaIn(mAppBar)
|
||||||
|
.setListener(object : AnimatorListenerAdapter() {
|
||||||
|
override fun onAnimationEnd(animation: Animator) {
|
||||||
|
mAppBar.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAnimationEnd(animation: Animator, isReverse: Boolean) {
|
||||||
|
if (autoHide) {
|
||||||
|
handler.postDelayed(autoHideRunnable, DEFAULT_HIDE_DELAY.toLong())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onHide() {
|
||||||
|
if (mAppBar.visibility == View.GONE || mViewPager.orientation != ViewPager2.ORIENTATION_HORIZONTAL) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
AnimUtil.alphaOut(mAppBar)
|
||||||
|
.setListener(object : AnimatorListenerAdapter() {
|
||||||
|
override fun onAnimationEnd(animation: Animator) {
|
||||||
|
mAppBar.visibility = View.GONE
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||||
|
when (item.itemId) {
|
||||||
|
R.id.menu_toggle_orientation -> {
|
||||||
|
item.setIcon(if (mViewPager.orientation == ViewPager2.ORIENTATION_HORIZONTAL) R.drawable.ic_round_view_day_white else R.drawable.ic_round_view_carousel_white)
|
||||||
|
item.setTitle(if (mViewPager.orientation == ViewPager2.ORIENTATION_HORIZONTAL) R.string.title_comic_mode_on else R.string.title_comic_mode)
|
||||||
|
Toast.makeText(this, if (mViewPager.orientation == ViewPager2.ORIENTATION_HORIZONTAL) R.string.toast_comic_mode_on else R.string.toast_comic_mode_off, Toast.LENGTH_SHORT).show()
|
||||||
|
mViewPager.orientation = if (mViewPager.orientation == ViewPager2.ORIENTATION_HORIZONTAL) ViewPager2.ORIENTATION_VERTICAL else ViewPager2.ORIENTATION_HORIZONTAL
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
R.id.menu_save_image -> {
|
||||||
|
ImageUtil.download(this, mAdapter.getBean(mViewPager.currentItem).originUrl, mAdapter.getBean(mViewPager.currentItem).isGif)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
R.id.menu_share -> {
|
||||||
|
Toast.makeText(this, R.string.toast_preparing_share_pic, Toast.LENGTH_SHORT).show()
|
||||||
|
ImageUtil.download(this, mAdapter.getBean(mViewPager.currentItem).originUrl, mAdapter.getBean(mViewPager.currentItem).isGif, true) { uri: Uri? ->
|
||||||
|
val intent = Intent(Intent.ACTION_SEND)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
intent.putExtra(Intent.EXTRA_STREAM, uri)
|
||||||
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
} else {
|
||||||
|
intent.putExtra(Intent.EXTRA_STREAM, uri)
|
||||||
|
}
|
||||||
|
intent.type = Intent.normalizeMimeType("image/jpeg")
|
||||||
|
val chooser = Intent.createChooser(intent, getString(R.string.title_share_pic))
|
||||||
|
if (intent.resolveActivity(packageManager) != null) {
|
||||||
|
startActivity(chooser)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val TAG = PhotoViewActivity::class.java.simpleName
|
||||||
|
const val EXTRA_BEANS = "beans"
|
||||||
|
const val EXTRA_POSITION = "position"
|
||||||
|
const val EXTRA_FORUM_ID = "forum_id"
|
||||||
|
const val EXTRA_FORUM_NAME = "forum_name"
|
||||||
|
const val EXTRA_THREAD_ID = "thread_id"
|
||||||
|
const val EXTRA_SEE_LZ = "see_lz"
|
||||||
|
const val EXTRA_IS_FRS = "is_frs"
|
||||||
|
const val EXTRA_OBJ_TYPE = "obj_type"
|
||||||
|
const val DEFAULT_HIDE_DELAY = 3000
|
||||||
|
const val OBJ_TYPE_THREAD_PAGE = "pb"
|
||||||
|
const val OBJ_TYPE_FORUM_PAGE = "frs"
|
||||||
|
private val handler = Handler()
|
||||||
|
fun launch(context: Context, photoViewBean: PhotoViewBean) {
|
||||||
|
launch(context, arrayOf(photoViewBean))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun launch(context: Context, photoViewBeanList: List<PhotoViewBean>) {
|
||||||
|
launch(context, photoViewBeanList.toTypedArray(), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun launch(context: Context, photoViewBeanList: List<PhotoViewBean>, position: Int) {
|
||||||
|
launch(context, photoViewBeanList.toTypedArray(), position)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmOverloads
|
||||||
|
fun launch(context: Context, photoViewBeans: Array<PhotoViewBean>?, position: Int = 0) {
|
||||||
|
context.startActivity(Intent(context, PhotoViewActivity::class.java)
|
||||||
|
.putExtra(EXTRA_BEANS, photoViewBeans)
|
||||||
|
.putExtra(EXTRA_POSITION, position)
|
||||||
|
.putExtra(EXTRA_IS_FRS, false))
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun launch(context: Context,
|
||||||
|
photoViewBeans: Array<PhotoViewBean?>?,
|
||||||
|
position: Int,
|
||||||
|
forumName: String?,
|
||||||
|
forumId: String?,
|
||||||
|
threadId: String?,
|
||||||
|
seeLz: Boolean,
|
||||||
|
objType: String?) {
|
||||||
|
context.startActivity(Intent(context, PhotoViewActivity::class.java)
|
||||||
|
.putExtra(EXTRA_BEANS, photoViewBeans)
|
||||||
|
.putExtra(EXTRA_POSITION, position)
|
||||||
|
.putExtra(EXTRA_IS_FRS, true)
|
||||||
|
.putExtra(EXTRA_FORUM_NAME, forumName)
|
||||||
|
.putExtra(EXTRA_FORUM_ID, forumId)
|
||||||
|
.putExtra(EXTRA_THREAD_ID, threadId)
|
||||||
|
.putExtra(EXTRA_SEE_LZ, seeLz)
|
||||||
|
.putExtra(EXTRA_OBJ_TYPE, objType))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -96,7 +96,7 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
||||||
val bundle = arguments
|
val bundle = arguments
|
||||||
if (savedInstanceState == null && bundle != null) {
|
if (savedInstanceState == null && bundle != null) {
|
||||||
forumName = bundle.getString(PARAM_FORUM_NAME)
|
forumName = bundle.getString(PARAM_FORUM_NAME)
|
||||||
isGood = bundle.getBoolean(PARAM_IS_GOOD)
|
isGood = bundle.getBoolean(PARAM_IS_GOOD, false)
|
||||||
sortType = valueOf(bundle.getInt(PARAM_SORT_TYPE))
|
sortType = valueOf(bundle.getInt(PARAM_SORT_TYPE))
|
||||||
preload = bundle.getBoolean(PARAM_PRELOAD)
|
preload = bundle.getBoolean(PARAM_PRELOAD)
|
||||||
preloadId = bundle.getInt(PARAM_PRELOAD_ID)
|
preloadId = bundle.getInt(PARAM_PRELOAD_ID)
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ import com.huanchengfly.tieba.post.activities.UserActivity;
|
||||||
import com.huanchengfly.tieba.post.activities.UserCollectActivity;
|
import com.huanchengfly.tieba.post.activities.UserCollectActivity;
|
||||||
import com.huanchengfly.tieba.post.interfaces.Refreshable;
|
import com.huanchengfly.tieba.post.interfaces.Refreshable;
|
||||||
import com.huanchengfly.tieba.post.models.MyInfoBean;
|
import com.huanchengfly.tieba.post.models.MyInfoBean;
|
||||||
|
import com.huanchengfly.tieba.post.models.database.Account;
|
||||||
import com.huanchengfly.tieba.post.utils.AccountUtil;
|
import com.huanchengfly.tieba.post.utils.AccountUtil;
|
||||||
import com.huanchengfly.tieba.post.utils.ImageUtil;
|
import com.huanchengfly.tieba.post.utils.ImageUtil;
|
||||||
import com.huanchengfly.tieba.post.utils.NavigationHelper;
|
import com.huanchengfly.tieba.post.utils.NavigationHelper;
|
||||||
|
|
@ -50,6 +51,8 @@ import com.scwang.wave.MultiWaveHeader;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static com.huanchengfly.tieba.post.utils.ThemeUtil.SP_CUSTOM_TOOLBAR_PRIMARY_COLOR;
|
import static com.huanchengfly.tieba.post.utils.ThemeUtil.SP_CUSTOM_TOOLBAR_PRIMARY_COLOR;
|
||||||
import static com.huanchengfly.tieba.post.utils.ThemeUtil.THEME_TRANSLUCENT;
|
import static com.huanchengfly.tieba.post.utils.ThemeUtil.THEME_TRANSLUCENT;
|
||||||
|
|
||||||
|
|
@ -190,8 +193,13 @@ public class MyInfoFragment extends BaseFragment implements NavigationView.OnNav
|
||||||
multiWaveHeader = contentView.findViewById(R.id.wave_header);
|
multiWaveHeader = contentView.findViewById(R.id.wave_header);
|
||||||
RelativeLayout cardView = contentView.findViewById(R.id.my_info);
|
RelativeLayout cardView = contentView.findViewById(R.id.my_info);
|
||||||
cardView.setOnClickListener((View view) -> {
|
cardView.setOnClickListener((View view) -> {
|
||||||
if (AccountUtil.isLoggedIn(getAttachContext()) && data != null) {
|
if (AccountUtil.isLoggedIn(getAttachContext())) {
|
||||||
NavigationHelper.toUserSpaceWithAnim(getAttachContext(), String.valueOf(data.getData().getUid()), data.getData().getAvatarUrl(), avatarImageView);
|
if (data != null) {
|
||||||
|
NavigationHelper.toUserSpaceWithAnim(getAttachContext(), String.valueOf(data.getData().getUid()), data.getData().getAvatarUrl(), avatarImageView);
|
||||||
|
} else {
|
||||||
|
Account loginInfo = Objects.requireNonNull(AccountUtil.getLoginInfo(getAttachContext()));
|
||||||
|
NavigationHelper.toUserSpaceWithAnim(getAttachContext(), String.valueOf(loginInfo.getUid()), loginInfo.getPortrait(), avatarImageView);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
getAttachContext().startActivity(new Intent(getAttachContext(), LoginActivity.class));
|
getAttachContext().startActivity(new Intent(getAttachContext(), LoginActivity.class));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -381,7 +381,7 @@ public class WebViewFragment extends BaseFragment implements DownloadListener {
|
||||||
.setOnGrantedCallback(isForever -> {
|
.setOnGrantedCallback(isForever -> {
|
||||||
AndPermission.with(getAttachContext())
|
AndPermission.with(getAttachContext())
|
||||||
.runtime()
|
.runtime()
|
||||||
.permission(Permission.Group.LOCATION)
|
.permission(Permission.ACCESS_COARSE_LOCATION, Permission.ACCESS_FINE_LOCATION)
|
||||||
.onGranted((List<String> permissions) -> {
|
.onGranted((List<String> permissions) -> {
|
||||||
if (isEnabledLocationFunction()) {
|
if (isEnabledLocationFunction()) {
|
||||||
callback.invoke(origin, true, isForever);
|
callback.invoke(origin, true, isForever);
|
||||||
|
|
|
||||||
|
|
@ -94,17 +94,26 @@ public final class NavigationHelper {
|
||||||
public void navigationByData(int action) {
|
public void navigationByData(int action) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ACTION_LOGIN:
|
case ACTION_LOGIN:
|
||||||
mContext.startActivity(new Intent(mContext, LoginActivity.class));
|
startActivity(new Intent(mContext, LoginActivity.class));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startActivity(Intent intent) {
|
||||||
|
try {
|
||||||
|
mContext.startActivity(intent);
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Toast.makeText(mContext, R.string.toast_nav_failed, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void navigationByData(int action, String data) {
|
public void navigationByData(int action, String data) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ACTION_FORUM:
|
case ACTION_FORUM:
|
||||||
Intent intent = new Intent(mContext, ForumActivity.class);
|
Intent intent = new Intent(mContext, ForumActivity.class);
|
||||||
intent.putExtra(EXTRA_FORUM_NAME, data);
|
intent.putExtra(EXTRA_FORUM_NAME, data);
|
||||||
mContext.startActivity(intent);
|
startActivity(intent);
|
||||||
break;
|
break;
|
||||||
case ACTION_URL:
|
case ACTION_URL:
|
||||||
navigationByUrl(data);
|
navigationByUrl(data);
|
||||||
|
|
@ -116,7 +125,7 @@ public final class NavigationHelper {
|
||||||
navigationByUrl(mContext.getString(R.string.url_user_home, data, 0));
|
navigationByUrl(mContext.getString(R.string.url_user_home, data, 0));
|
||||||
break;
|
break;
|
||||||
case ACTION_USER_BY_UID:
|
case ACTION_USER_BY_UID:
|
||||||
mContext.startActivity(new Intent(mContext, UserActivity.class).putExtra(UserActivity.EXTRA_UID, data));
|
startActivity(new Intent(mContext, UserActivity.class).putExtra(UserActivity.EXTRA_UID, data));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +143,7 @@ public final class NavigationHelper {
|
||||||
from = from == null ? "" : from;
|
from = from == null ? "" : from;
|
||||||
maxPid = maxPid == null ? "" : maxPid;
|
maxPid = maxPid == null ? "" : maxPid;
|
||||||
boolean seeLz = (seeLzStr != null && seeLzStr.equalsIgnoreCase("1"));
|
boolean seeLz = (seeLzStr != null && seeLzStr.equalsIgnoreCase("1"));
|
||||||
mContext.startActivity(new Intent(mContext, ThreadActivity.class)
|
startActivity(new Intent(mContext, ThreadActivity.class)
|
||||||
.putExtra("tid", tid)
|
.putExtra("tid", tid)
|
||||||
.putExtra("pid", pid)
|
.putExtra("pid", pid)
|
||||||
.putExtra("from", from)
|
.putExtra("from", from)
|
||||||
|
|
@ -149,7 +158,7 @@ public final class NavigationHelper {
|
||||||
if (floorTid != null) {
|
if (floorTid != null) {
|
||||||
pid = floorPid == null ? "" : floorPid;
|
pid = floorPid == null ? "" : floorPid;
|
||||||
String spid = floorSPid == null ? "" : floorSPid;
|
String spid = floorSPid == null ? "" : floorSPid;
|
||||||
mContext.startActivity(new Intent(mContext, FloorActivity.class)
|
startActivity(new Intent(mContext, FloorActivity.class)
|
||||||
.putExtra("tid", floorTid)
|
.putExtra("tid", floorTid)
|
||||||
.putExtra("pid", pid)
|
.putExtra("pid", pid)
|
||||||
.putExtra("spid", spid));
|
.putExtra("spid", spid));
|
||||||
|
|
@ -205,7 +214,7 @@ public final class NavigationHelper {
|
||||||
} else if (kz != null) {
|
} else if (kz != null) {
|
||||||
Intent intent = new Intent(mContext, ThreadActivity.class);
|
Intent intent = new Intent(mContext, ThreadActivity.class);
|
||||||
intent.putExtra("url", url);
|
intent.putExtra("url", url);
|
||||||
mContext.startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (path.startsWith("/index/tbwise") || path.equalsIgnoreCase("/")) {
|
} else if (path.startsWith("/index/tbwise") || path.equalsIgnoreCase("/")) {
|
||||||
|
|
@ -219,7 +228,7 @@ public final class NavigationHelper {
|
||||||
} else if (path.startsWith("/p/")) {
|
} else if (path.startsWith("/p/")) {
|
||||||
Intent intent = new Intent(mContext, ThreadActivity.class);
|
Intent intent = new Intent(mContext, ThreadActivity.class);
|
||||||
intent.putExtra("url", url);
|
intent.putExtra("url", url);
|
||||||
mContext.startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -227,7 +236,7 @@ public final class NavigationHelper {
|
||||||
if (!(activityName.startsWith("WebViewActivity") || activityName.startsWith("LoginActivity"))) {
|
if (!(activityName.startsWith("WebViewActivity") || activityName.startsWith("LoginActivity"))) {
|
||||||
boolean isTiebaLink = host.contains("tieba.baidu.com") || host.contains("wappass.baidu.com") || host.contains("ufosdk.baidu.com") || host.contains("m.help.baidu.com");
|
boolean isTiebaLink = host.contains("tieba.baidu.com") || host.contains("wappass.baidu.com") || host.contains("ufosdk.baidu.com") || host.contains("m.help.baidu.com");
|
||||||
if (isTiebaLink || SharedPreferencesUtil.get(mContext, SharedPreferencesUtil.SP_SETTINGS).getBoolean("use_webview", true)) {
|
if (isTiebaLink || SharedPreferencesUtil.get(mContext, SharedPreferencesUtil.SP_SETTINGS).getBoolean("use_webview", true)) {
|
||||||
mContext.startActivity(new Intent(mContext, WebViewActivity.class).putExtra("url", url));
|
startActivity(new Intent(mContext, WebViewActivity.class).putExtra("url", url));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (SharedPreferencesUtil.get(mContext, SharedPreferencesUtil.SP_SETTINGS).getBoolean("use_custom_tabs", true)) {
|
if (SharedPreferencesUtil.get(mContext, SharedPreferencesUtil.SP_SETTINGS).getBoolean("use_custom_tabs", true)) {
|
||||||
|
|
@ -237,10 +246,10 @@ public final class NavigationHelper {
|
||||||
try {
|
try {
|
||||||
intentBuilder.build().launchUrl(mContext, uri);
|
intentBuilder.build().launchUrl(mContext, uri);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
mContext.startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mContext.startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -268,7 +277,7 @@ public final class NavigationHelper {
|
||||||
oldHost + scheme,
|
oldHost + scheme,
|
||||||
mContext.getString(R.string.title_start_app_permission, oldHost, appName),
|
mContext.getString(R.string.title_start_app_permission, oldHost, appName),
|
||||||
R.drawable.ic_round_exit_to_app))
|
R.drawable.ic_round_exit_to_app))
|
||||||
.setOnGrantedCallback(isForever -> mContext.startActivity(intent))
|
.setOnGrantedCallback(isForever -> startActivity(intent))
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -296,7 +305,7 @@ public final class NavigationHelper {
|
||||||
oldHost + scheme,
|
oldHost + scheme,
|
||||||
mContext.getString(R.string.title_start_app_permission, oldHost, appName),
|
mContext.getString(R.string.title_start_app_permission, oldHost, appName),
|
||||||
R.drawable.ic_round_exit_to_app))
|
R.drawable.ic_round_exit_to_app))
|
||||||
.setOnGrantedCallback(isForever -> mContext.startActivity(intent))
|
.setOnGrantedCallback(isForever -> startActivity(intent))
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -383,4 +383,5 @@
|
||||||
<string name="toast_sign_failed">签到失败 %s</string>
|
<string name="toast_sign_failed">签到失败 %s</string>
|
||||||
<string name="toast_like_failed">关注失败 %s</string>
|
<string name="toast_like_failed">关注失败 %s</string>
|
||||||
<string name="toast_please_login">请先登录</string>
|
<string name="toast_please_login">请先登录</string>
|
||||||
|
<string name="toast_nav_failed">跳转失败</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue