fix: 修复一些 Bug

This commit is contained in:
HuanCheng65 2022-08-01 15:47:25 +08:00
parent e32d325495
commit 27de542385
No known key found for this signature in database
GPG Key ID: E9031EF91A805148
12 changed files with 40 additions and 15 deletions

View File

@ -27,6 +27,8 @@ import androidx.appcompat.app.AppCompatDelegate
import com.github.gzuliyujiang.oaid.DeviceID
import com.github.gzuliyujiang.oaid.DeviceIdentifier
import com.github.gzuliyujiang.oaid.IGetter
import com.github.piasy.biv.BigImageViewer
import com.github.piasy.biv.loader.glide.GlideImageLoader
import com.huanchengfly.tieba.post.activities.BaseActivity
import com.huanchengfly.tieba.post.api.interfaces.CommonCallback
import com.huanchengfly.tieba.post.components.dialogs.LoadingDialog
@ -76,6 +78,7 @@ class BaseApplication : Application(), IApp {
override fun onCreate() {
instance = this
super.onCreate()
BigImageViewer.initialize(GlideImageLoader.with(this))
DeviceIdentifier.register(this)
DeviceID.getOAID(this, object : IGetter {
override fun onOAIDGetComplete(result: String) {

View File

@ -178,6 +178,7 @@ class TranslucentThemeActivity : BaseActivity(), View.OnClickListener, OnSeekBar
})
}
@Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_CODE_CHOOSE && resultCode == Activity.RESULT_OK) {

View File

@ -80,7 +80,11 @@ public class WebViewActivity extends BaseActivity implements OnReceivedTitleList
mUrl :
mWebViewFragment.getWebView().getUrl());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
try {
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
break;
case R.id.menu_copy_link:
TiebaUtil.copyText(this, mWebViewFragment.getWebView().getUrl());

View File

@ -2,12 +2,11 @@ package com.huanchengfly.tieba.post.adapters;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import java.util.ArrayList;
import java.util.List;
public class FragmentTabViewPagerAdapter extends FragmentPagerAdapter {
public class FragmentTabViewPagerAdapter extends SmartFragmentStatePagerAdapter {
public Fragment currentFragment;
public int currentFragmentPosition;
private List<Fragment> fragments;

View File

@ -45,9 +45,7 @@ abstract class BaseAdapter<Item>(
fun setOnItemLongClickListener(listener: ((viewHolder: MyViewHolder, item: Item, position: Int) -> Boolean)?) {
onItemLongClickListener = object : OnItemLongClickListener<Item> {
override fun onLongClick(viewHolder: MyViewHolder, item: Item, position: Int): Boolean {
if (listener != null) {
return listener(viewHolder, item, position)
}
listener?.invoke(viewHolder, item, position)
return false
}
}
@ -63,9 +61,7 @@ abstract class BaseAdapter<Item>(
) {
onItemChildClickListeners[viewId] = object : OnItemChildClickListener<Item> {
override fun onItemChildClick(viewHolder: MyViewHolder, item: Item, position: Int) {
if (listener != null) {
listener(viewHolder, item, position)
}
listener?.invoke(viewHolder, item, position)
}
}
}

View File

@ -18,7 +18,6 @@ import com.huanchengfly.tieba.post.utils.ThemeUtil
import com.huanchengfly.tieba.post.utils.appPreferences
import com.jrummyapps.android.colorpicker.ColorPickerDialog
import com.jrummyapps.android.colorpicker.ColorPickerDialogListener
import java.util.*
class CustomThemeDialog(context: Context) : AlertDialog(context),
View.OnClickListener, DialogInterface.OnClickListener, CompoundButton.OnCheckedChangeListener,
@ -69,7 +68,7 @@ class CustomThemeDialog(context: Context) : AlertDialog(context),
.create()
primaryColorPicker.setColorPickerDialogListener(this)
primaryColorPicker.show(
Objects.requireNonNull(ThemeUtils.getWrapperActivity(context)).fragmentManager,
ThemeUtils.getWrapperActivity(context)!!.fragmentManager,
"ColorPicker_PrimaryColor"
)
}

View File

@ -12,15 +12,18 @@ import androidx.annotation.CallSuper
import androidx.fragment.app.Fragment
import butterknife.ButterKnife
import butterknife.Unbinder
import com.huanchengfly.tieba.post.BaseApplication
import com.huanchengfly.tieba.post.interfaces.BackHandledInterface
import com.huanchengfly.tieba.post.interfaces.Refreshable
import com.huanchengfly.tieba.post.isLandscape
import com.huanchengfly.tieba.post.isPortrait
import com.huanchengfly.tieba.post.isTablet
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils
import com.huanchengfly.tieba.post.utils.AppPreferencesUtils
import com.huanchengfly.tieba.post.utils.HandleBackUtil
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO
import java.lang.ref.WeakReference
import kotlin.coroutines.CoroutineContext
/**
@ -48,7 +51,19 @@ abstract class BaseFragment : Fragment(), BackHandledInterface, CoroutineScope {
var isFirstVisible = false
private set
private var rootView: View? = null
lateinit var attachContext: Context
var attachContextWeakReference: WeakReference<Context>? = null
val attachContext: Context
get() {
var mContext: Context? = context
if (mContext == null && attachContextWeakReference != null) {
mContext = attachContextWeakReference!!.get()
ThemeUtils.getWrapperActivity(mContext)?.let { mContext = it }
}
if (mContext == null) {
mContext = BaseApplication.instance
}
return mContext!!
}
protected val appPreferences: AppPreferencesUtils
get() = AppPreferencesUtils(attachContext)
@ -58,6 +73,7 @@ abstract class BaseFragment : Fragment(), BackHandledInterface, CoroutineScope {
onAttachToContext(context)
}
@Deprecated("Deprecated in Java")
override fun onAttach(activity: Activity) {
super.onAttach(activity)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
@ -67,7 +83,7 @@ abstract class BaseFragment : Fragment(), BackHandledInterface, CoroutineScope {
@CallSuper
private fun onAttachToContext(context: Context) {
attachContext = context
attachContextWeakReference = WeakReference(context)
}
override fun onBackPressed(): Boolean {
@ -79,6 +95,7 @@ abstract class BaseFragment : Fragment(), BackHandledInterface, CoroutineScope {
//如果Fragment从可见->不可见那么setUserVisibleHint()也会被调用传入isVisibleToUser = false
//总结setUserVisibleHint()除了Fragment的可见状态发生变化时会被回调外在new时也会被回调
//如果我们需要在Fragment可见与不可见时干点事用这个的话就会有多余的回调了那么就需要重新封装一个
@Deprecated("Deprecated in Java")
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
super.setUserVisibleHint(isVisibleToUser)
//setUserVisibleHint()有可能在fragment的生命周期外被调用

View File

@ -80,6 +80,7 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
super.onSaveInstanceState(outState)
}
@Deprecated("Deprecated in Java")
override fun onActivityCreated(savedInstanceState: Bundle?) {
if (savedInstanceState != null) {
forumName = savedInstanceState.getString(PARAM_FORUM_NAME)

View File

@ -98,6 +98,7 @@ class ForumInfoFragment : BaseFragment(), Refreshable, ScrollTopable {
super.onSaveInstanceState(outState)
}
@Deprecated("Deprecated in Java")
override fun onActivityCreated(savedInstanceState: Bundle?) {
if (savedInstanceState != null) {
forumName = savedInstanceState.getString(ForumFragment.PARAM_FORUM_NAME)

View File

@ -14,14 +14,14 @@ public class BaseFragment extends Fragment {
@TargetApi(23)
@Override
public void onAttach(Context context) {
public void onAttach(@NonNull Context context) {
super.onAttach(context);
onAttachToContext(context);
}
@SuppressWarnings("deprecation")
@Override
public void onAttach(Activity activity) {
public void onAttach(@NonNull Activity activity) {
super.onAttach(activity);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
onAttachToContext(activity);

View File

@ -17,6 +17,7 @@ import android.widget.WrapperListAdapter;
import androidx.annotation.AttrRes;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.Nullable;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.recyclerview.widget.RecyclerView;
@ -75,6 +76,7 @@ public class ThemeUtils {
refreshUI(context, null);
}
@Nullable
public static Activity getWrapperActivity(Context context) {
if (context instanceof Activity) {
return (Activity) context;

View File

@ -89,6 +89,7 @@ public class ImageUtil {
public static final String TAG = "ImageUtil";
private static boolean isGifFile(File file) {
if (file == null) return false;
try {
return isGifFile(new FileInputStream(file));
} catch (FileNotFoundException e) {
@ -99,6 +100,7 @@ public class ImageUtil {
//判断是否为GIF文件
private static boolean isGifFile(InputStream inputStream) {
if (inputStream == null) return false;
byte[] bytes = new byte[4];
try {
inputStream.read(bytes);