fix: 修复一些 Bug
This commit is contained in:
parent
e32d325495
commit
27de542385
|
|
@ -27,6 +27,8 @@ import androidx.appcompat.app.AppCompatDelegate
|
||||||
import com.github.gzuliyujiang.oaid.DeviceID
|
import com.github.gzuliyujiang.oaid.DeviceID
|
||||||
import com.github.gzuliyujiang.oaid.DeviceIdentifier
|
import com.github.gzuliyujiang.oaid.DeviceIdentifier
|
||||||
import com.github.gzuliyujiang.oaid.IGetter
|
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.activities.BaseActivity
|
||||||
import com.huanchengfly.tieba.post.api.interfaces.CommonCallback
|
import com.huanchengfly.tieba.post.api.interfaces.CommonCallback
|
||||||
import com.huanchengfly.tieba.post.components.dialogs.LoadingDialog
|
import com.huanchengfly.tieba.post.components.dialogs.LoadingDialog
|
||||||
|
|
@ -76,6 +78,7 @@ class BaseApplication : Application(), IApp {
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
instance = this
|
instance = this
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
BigImageViewer.initialize(GlideImageLoader.with(this))
|
||||||
DeviceIdentifier.register(this)
|
DeviceIdentifier.register(this)
|
||||||
DeviceID.getOAID(this, object : IGetter {
|
DeviceID.getOAID(this, object : IGetter {
|
||||||
override fun onOAIDGetComplete(result: String) {
|
override fun onOAIDGetComplete(result: String) {
|
||||||
|
|
|
||||||
|
|
@ -178,6 +178,7 @@ class TranslucentThemeActivity : BaseActivity(), View.OnClickListener, OnSeekBar
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Deprecated in Java")
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
super.onActivityResult(requestCode, resultCode, data)
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
if (requestCode == REQUEST_CODE_CHOOSE && resultCode == Activity.RESULT_OK) {
|
if (requestCode == REQUEST_CODE_CHOOSE && resultCode == Activity.RESULT_OK) {
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,11 @@ public class WebViewActivity extends BaseActivity implements OnReceivedTitleList
|
||||||
mUrl :
|
mUrl :
|
||||||
mWebViewFragment.getWebView().getUrl());
|
mWebViewFragment.getWebView().getUrl());
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
|
try {
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case R.id.menu_copy_link:
|
case R.id.menu_copy_link:
|
||||||
TiebaUtil.copyText(this, mWebViewFragment.getWebView().getUrl());
|
TiebaUtil.copyText(this, mWebViewFragment.getWebView().getUrl());
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,11 @@ package com.huanchengfly.tieba.post.adapters;
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentPagerAdapter;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class FragmentTabViewPagerAdapter extends FragmentPagerAdapter {
|
public class FragmentTabViewPagerAdapter extends SmartFragmentStatePagerAdapter {
|
||||||
public Fragment currentFragment;
|
public Fragment currentFragment;
|
||||||
public int currentFragmentPosition;
|
public int currentFragmentPosition;
|
||||||
private List<Fragment> fragments;
|
private List<Fragment> fragments;
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,7 @@ abstract class BaseAdapter<Item>(
|
||||||
fun setOnItemLongClickListener(listener: ((viewHolder: MyViewHolder, item: Item, position: Int) -> Boolean)?) {
|
fun setOnItemLongClickListener(listener: ((viewHolder: MyViewHolder, item: Item, position: Int) -> Boolean)?) {
|
||||||
onItemLongClickListener = object : OnItemLongClickListener<Item> {
|
onItemLongClickListener = object : OnItemLongClickListener<Item> {
|
||||||
override fun onLongClick(viewHolder: MyViewHolder, item: Item, position: Int): Boolean {
|
override fun onLongClick(viewHolder: MyViewHolder, item: Item, position: Int): Boolean {
|
||||||
if (listener != null) {
|
listener?.invoke(viewHolder, item, position)
|
||||||
return listener(viewHolder, item, position)
|
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -63,9 +61,7 @@ abstract class BaseAdapter<Item>(
|
||||||
) {
|
) {
|
||||||
onItemChildClickListeners[viewId] = object : OnItemChildClickListener<Item> {
|
onItemChildClickListeners[viewId] = object : OnItemChildClickListener<Item> {
|
||||||
override fun onItemChildClick(viewHolder: MyViewHolder, item: Item, position: Int) {
|
override fun onItemChildClick(viewHolder: MyViewHolder, item: Item, position: Int) {
|
||||||
if (listener != null) {
|
listener?.invoke(viewHolder, item, position)
|
||||||
listener(viewHolder, item, position)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ import com.huanchengfly.tieba.post.utils.ThemeUtil
|
||||||
import com.huanchengfly.tieba.post.utils.appPreferences
|
import com.huanchengfly.tieba.post.utils.appPreferences
|
||||||
import com.jrummyapps.android.colorpicker.ColorPickerDialog
|
import com.jrummyapps.android.colorpicker.ColorPickerDialog
|
||||||
import com.jrummyapps.android.colorpicker.ColorPickerDialogListener
|
import com.jrummyapps.android.colorpicker.ColorPickerDialogListener
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class CustomThemeDialog(context: Context) : AlertDialog(context),
|
class CustomThemeDialog(context: Context) : AlertDialog(context),
|
||||||
View.OnClickListener, DialogInterface.OnClickListener, CompoundButton.OnCheckedChangeListener,
|
View.OnClickListener, DialogInterface.OnClickListener, CompoundButton.OnCheckedChangeListener,
|
||||||
|
|
@ -69,7 +68,7 @@ class CustomThemeDialog(context: Context) : AlertDialog(context),
|
||||||
.create()
|
.create()
|
||||||
primaryColorPicker.setColorPickerDialogListener(this)
|
primaryColorPicker.setColorPickerDialogListener(this)
|
||||||
primaryColorPicker.show(
|
primaryColorPicker.show(
|
||||||
Objects.requireNonNull(ThemeUtils.getWrapperActivity(context)).fragmentManager,
|
ThemeUtils.getWrapperActivity(context)!!.fragmentManager,
|
||||||
"ColorPicker_PrimaryColor"
|
"ColorPicker_PrimaryColor"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,18 @@ import androidx.annotation.CallSuper
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import butterknife.ButterKnife
|
import butterknife.ButterKnife
|
||||||
import butterknife.Unbinder
|
import butterknife.Unbinder
|
||||||
|
import com.huanchengfly.tieba.post.BaseApplication
|
||||||
import com.huanchengfly.tieba.post.interfaces.BackHandledInterface
|
import com.huanchengfly.tieba.post.interfaces.BackHandledInterface
|
||||||
import com.huanchengfly.tieba.post.interfaces.Refreshable
|
import com.huanchengfly.tieba.post.interfaces.Refreshable
|
||||||
import com.huanchengfly.tieba.post.isLandscape
|
import com.huanchengfly.tieba.post.isLandscape
|
||||||
import com.huanchengfly.tieba.post.isPortrait
|
import com.huanchengfly.tieba.post.isPortrait
|
||||||
import com.huanchengfly.tieba.post.isTablet
|
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.AppPreferencesUtils
|
||||||
import com.huanchengfly.tieba.post.utils.HandleBackUtil
|
import com.huanchengfly.tieba.post.utils.HandleBackUtil
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
|
import java.lang.ref.WeakReference
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -48,7 +51,19 @@ abstract class BaseFragment : Fragment(), BackHandledInterface, CoroutineScope {
|
||||||
var isFirstVisible = false
|
var isFirstVisible = false
|
||||||
private set
|
private set
|
||||||
private var rootView: View? = null
|
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
|
protected val appPreferences: AppPreferencesUtils
|
||||||
get() = AppPreferencesUtils(attachContext)
|
get() = AppPreferencesUtils(attachContext)
|
||||||
|
|
||||||
|
|
@ -58,6 +73,7 @@ abstract class BaseFragment : Fragment(), BackHandledInterface, CoroutineScope {
|
||||||
onAttachToContext(context)
|
onAttachToContext(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Deprecated in Java")
|
||||||
override fun onAttach(activity: Activity) {
|
override fun onAttach(activity: Activity) {
|
||||||
super.onAttach(activity)
|
super.onAttach(activity)
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||||
|
|
@ -67,7 +83,7 @@ abstract class BaseFragment : Fragment(), BackHandledInterface, CoroutineScope {
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
private fun onAttachToContext(context: Context) {
|
private fun onAttachToContext(context: Context) {
|
||||||
attachContext = context
|
attachContextWeakReference = WeakReference(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed(): Boolean {
|
override fun onBackPressed(): Boolean {
|
||||||
|
|
@ -79,6 +95,7 @@ abstract class BaseFragment : Fragment(), BackHandledInterface, CoroutineScope {
|
||||||
//如果Fragment从可见->不可见,那么setUserVisibleHint()也会被调用,传入isVisibleToUser = false
|
//如果Fragment从可见->不可见,那么setUserVisibleHint()也会被调用,传入isVisibleToUser = false
|
||||||
//总结:setUserVisibleHint()除了Fragment的可见状态发生变化时会被回调外,在new时也会被回调
|
//总结:setUserVisibleHint()除了Fragment的可见状态发生变化时会被回调外,在new时也会被回调
|
||||||
//如果我们需要在Fragment可见与不可见时干点事,用这个的话就会有多余的回调了,那么就需要重新封装一个
|
//如果我们需要在Fragment可见与不可见时干点事,用这个的话就会有多余的回调了,那么就需要重新封装一个
|
||||||
|
@Deprecated("Deprecated in Java")
|
||||||
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
|
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
|
||||||
super.setUserVisibleHint(isVisibleToUser)
|
super.setUserVisibleHint(isVisibleToUser)
|
||||||
//setUserVisibleHint()有可能在fragment的生命周期外被调用
|
//setUserVisibleHint()有可能在fragment的生命周期外被调用
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Deprecated in Java")
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
forumName = savedInstanceState.getString(PARAM_FORUM_NAME)
|
forumName = savedInstanceState.getString(PARAM_FORUM_NAME)
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ class ForumInfoFragment : BaseFragment(), Refreshable, ScrollTopable {
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Deprecated in Java")
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
forumName = savedInstanceState.getString(ForumFragment.PARAM_FORUM_NAME)
|
forumName = savedInstanceState.getString(ForumFragment.PARAM_FORUM_NAME)
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,14 @@ public class BaseFragment extends Fragment {
|
||||||
|
|
||||||
@TargetApi(23)
|
@TargetApi(23)
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(@NonNull Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
onAttachToContext(context);
|
onAttachToContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(@NonNull Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||||
onAttachToContext(activity);
|
onAttachToContext(activity);
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import android.widget.WrapperListAdapter;
|
||||||
import androidx.annotation.AttrRes;
|
import androidx.annotation.AttrRes;
|
||||||
import androidx.annotation.ColorInt;
|
import androidx.annotation.ColorInt;
|
||||||
import androidx.annotation.ColorRes;
|
import androidx.annotation.ColorRes;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.graphics.drawable.DrawableCompat;
|
import androidx.core.graphics.drawable.DrawableCompat;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
|
@ -75,6 +76,7 @@ public class ThemeUtils {
|
||||||
refreshUI(context, null);
|
refreshUI(context, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static Activity getWrapperActivity(Context context) {
|
public static Activity getWrapperActivity(Context context) {
|
||||||
if (context instanceof Activity) {
|
if (context instanceof Activity) {
|
||||||
return (Activity) context;
|
return (Activity) context;
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ public class ImageUtil {
|
||||||
public static final String TAG = "ImageUtil";
|
public static final String TAG = "ImageUtil";
|
||||||
|
|
||||||
private static boolean isGifFile(File file) {
|
private static boolean isGifFile(File file) {
|
||||||
|
if (file == null) return false;
|
||||||
try {
|
try {
|
||||||
return isGifFile(new FileInputStream(file));
|
return isGifFile(new FileInputStream(file));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
|
|
@ -99,6 +100,7 @@ public class ImageUtil {
|
||||||
|
|
||||||
//判断是否为GIF文件
|
//判断是否为GIF文件
|
||||||
private static boolean isGifFile(InputStream inputStream) {
|
private static boolean isGifFile(InputStream inputStream) {
|
||||||
|
if (inputStream == null) return false;
|
||||||
byte[] bytes = new byte[4];
|
byte[] bytes = new byte[4];
|
||||||
try {
|
try {
|
||||||
inputStream.read(bytes);
|
inputStream.read(bytes);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue