Commit f990cdfb authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 95119d20
......@@ -214,6 +214,8 @@ dependencies {
// 三方接入
// leakcanary
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'
// shareSdk
implementation project(':shareSdkLib')
// umeng
......
......@@ -21,6 +21,7 @@ object TopOnNativeAd {
private val TAG = TopOnNativeAd::class.java.simpleName
var context: Context? = null
var atNatives: ATNative? = null
var mNativeAd: NativeAd? = null
var anyThinkNativeAdView: ATNativeAdView? = null
......@@ -32,6 +33,7 @@ object TopOnNativeAd {
* 应用初始化
*/
fun init(context: Context) {
this.context = context
atNatives = ATNative(context, TopOnManager.INFORMATION_ID, object : ATNativeNetworkListener {
override fun onNativeAdLoaded() {
LogUtil.e(TAG, "onNativeAdLoaded")
......@@ -61,16 +63,16 @@ object TopOnNativeAd {
/**
* 预加载
*/
fun loadNativeAd(context: Context, frameLayout: FrameLayout?) {
fun loadNativeAd(frameLayout: FrameLayout?) {
atNatives?.makeAdRequest()
showNativeAd(context,frameLayout)
showNativeAd(frameLayout)
}
/**
* 显示
*/
fun showNativeAd(context: Context, frameLayout: FrameLayout?) {
private fun showNativeAd(frameLayout: FrameLayout?) {
val nativeAd = atNatives?.nativeAd
nativeAd?.let {
if (mNativeAd != null) {
......@@ -118,7 +120,7 @@ object TopOnNativeAd {
it.prepare(anyThinkNativeAdView, anyThinkRender.getClickView(), null)
if (anyThinkNativeAdView != null && anyThinkNativeAdView!!.parent == null) {
frameLayout?.addView(anyThinkNativeAdView, FrameLayout.LayoutParams(context.getResources().getDisplayMetrics().widthPixels, containerHeight))
frameLayout?.addView(anyThinkNativeAdView, FrameLayout.LayoutParams(context?.getResources()!!.getDisplayMetrics().widthPixels, containerHeight))
}
}
}
......@@ -138,6 +140,8 @@ object TopOnNativeAd {
}
fun onDestroy() {
anyThinkNativeAdView?.destory()
mNativeAd?.destory()
context = null
}
}
\ No newline at end of file
......@@ -30,11 +30,7 @@ public class AppConfig {
public static volatile double curLatitude = 0;//纬度 39.977181
public static volatile String curAddress = "授权定位权限后获取位置";//位置
public static volatile String poiName = "";//位置
public static volatile String aoiName = "";//建筑
public static volatile double preChangeLongitude = 1;//位置变化改变 上一次经度 116.307511
public static volatile double preChangeLatitude = 1;//位置变化改变 上一次纬度 39.977181
// public static volatile int canSaveMinimumM = 50;//范围 米
public static volatile int canSaveMinimumM = 1;//范围 米
......
......@@ -35,7 +35,7 @@ class VipPayManager private constructor(activity: Activity) {
private fun init(activity: Activity) {
this.activity = activity
spUtil = SPUtil.getInstance(activity)
spUtil = SPUtil.getInstance()
}
/**
......@@ -56,19 +56,19 @@ class VipPayManager private constructor(activity: Activity) {
/**
* 跳转支付界面 type-3 五折, type-4 全款
*/
fun gotoPayPage(type: Int) {
if (activity == null) return
if (TextUtils.equals("onePrice", spUtil?.getString(Constant.PAY_PAGE_TYPE))) {
//固定套餐
readyGo(Vip2Activity::class.java)
} else {
//多价格套餐
val bundle = Bundle()
bundle.putInt(Constant.PRICE_TYPE, type)
readyGo(Vip3Activity::class.java, bundle)
}
}
// fun gotoPayPage(type: Int) {
// if (activity == null) return
//
// if (TextUtils.equals("onePrice", spUtil?.getString(Constant.PAY_PAGE_TYPE))) {
// //固定套餐
// readyGo(Vip2Activity::class.java)
// } else {
// //多价格套餐
// val bundle = Bundle()
// bundle.putInt(Constant.PRICE_TYPE, type)
// readyGo(Vip3Activity::class.java, bundle)
// }
// }
private fun readyGo(clazz: Class<*>?) {
activity.let {
......
......@@ -26,6 +26,9 @@ import java.util.*
class MainFragmentPresenter : BasePresenter<MainFragmentView>() {
/**
* 获取关心的人
*/
fun getAllReqMy() {
AppHttpManager.getInstance(loanApplication)
.call(loanService.getCares(),
......
......@@ -30,7 +30,7 @@ class CallMeActivity : BaseActivity(), View.OnClickListener {
if (UserManager.getInstance().vipFlag) {
rlCallmeQQ.visibility = View.VISIBLE
val phone = SPUtil.getInstance(context).getString(Constant.USER_TELEPHONE)
val phone = SPUtil.getInstance().getString(Constant.USER_TELEPHONE)
tvCallPhone.text = phone
} else {
rlCallmeQQ.visibility = View.GONE
......
......@@ -15,6 +15,7 @@ import androidx.fragment.app.FragmentTransaction;
import com.mints.xunmi.MintsApplication;
import com.mints.xunmi.R;
import com.mints.xunmi.ad.TopOnNativeAd;
import com.mints.xunmi.common.AppConfig;
import com.mints.xunmi.common.Constant;
import com.mints.xunmi.manager.MainAmapLocationManager;
......@@ -93,6 +94,8 @@ public class MainActivity extends BaseActivity implements MainView {
@Override
public void onDestroy() {
super.onDestroy();
TopOnNativeAd.INSTANCE.onDestroy();
}
@Override
......
......@@ -2,6 +2,7 @@ package com.mints.xunmi.ui.activitys;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
......@@ -163,5 +164,11 @@ public class SplashAdShowActivity extends BaseActivity implements ATSplashAdList
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyDown(keyCode, event);
}
}
......@@ -2,6 +2,7 @@ package com.mints.xunmi.ui.activitys;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
......@@ -128,5 +129,11 @@ public class SplashBackActivity extends BaseActivity implements ATSplashAdListen
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyDown(keyCode, event);
}
}
......@@ -3,14 +3,13 @@ package com.mints.xunmi.ui.fragment
import android.Manifest
import android.os.Build
import android.os.Bundle
import android.os.Message
import android.text.TextUtils
import android.view.View
import android.widget.FrameLayout
import androidx.recyclerview.widget.LinearLayoutManager
import com.mints.library.recyclerview.HeaderAndFooterRecyclerViewAdapter
import com.mints.library.recyclerview.RecyclerViewUtils
import com.mints.library.utils.nodoubleclick.AntiShake
import com.mints.xunmi.BuildConfig
import com.mints.xunmi.R
import com.mints.xunmi.ad.TopOnNativeAd
import com.mints.xunmi.common.AppConfig
......@@ -26,7 +25,10 @@ import com.mints.xunmi.ui.adapter.MyConcernedPeopleAdapter
import com.mints.xunmi.ui.adapter.MyMainConcernedPeopleAdapterFooter
import com.mints.xunmi.ui.fragment.base.BaseFragment
import com.mints.xunmi.ui.widgets.*
import com.mints.xunmi.utils.LogUtil
import com.mints.xunmi.utils.SPUtil
import com.mints.xunmi.utils.WeakHandler
import com.mints.xunmi.utils.WeakHandler.IHandler
import com.tbruyelle.rxpermissions.RxPermissions
import kotlinx.android.synthetic.main.fragment_main_first.*
......@@ -36,10 +38,17 @@ import kotlinx.android.synthetic.main.fragment_main_first.*
* 时间:2020/6/4 17:30
*/
class MainFragment : BaseFragment()
, MainFragmentView, MyConcernedPeopleAdapter.OnItemClickListener, View.OnClickListener {
, MainFragmentView, MyConcernedPeopleAdapter.OnItemClickListener
, View.OnClickListener, IHandler {
private val TAG = MainFragment::class.java.simpleName
/*首页位置刷新相关*/
private var refreshLocationFlag = true
private val LOCATION_TIME: Long = 3000
private val LOCATION_MSG: Int = 102
private var mHandler: WeakHandler? = null
private var friendsSetBottomDialog: FriendsSetBottomDialog? = null
private var powerDialog: PowerDialog? = null
private var messageDialog: MessageDialog? = null
......@@ -69,7 +78,7 @@ class MainFragment : BaseFragment()
context?.let {
TopOnNativeAd.init(it)
TopOnNativeAd.loadNativeAd(it, null)
TopOnNativeAd.loadNativeAd(null)
}
linearLayoutManager = LinearLayoutManager(activity)
......@@ -85,6 +94,8 @@ class MainFragment : BaseFragment()
// discountDialog()
// }
// }
mHandler = WeakHandler(this)
}
override fun onHiddenChanged(hidden: Boolean) {
......@@ -129,27 +140,34 @@ class MainFragment : BaseFragment()
getCares(null)
mainFragmentPresenter?.userLogin(context!!)
}
// refreshLocationFlag = true
mHandler?.sendEmptyMessageDelayed(LOCATION_MSG, LOCATION_TIME)
}
}
override fun onPause() {
super.onPause()
refreshLocationFlag = false
}
override fun onDestroy() {
super.onDestroy()
mHandler?.removeCallbacksAndMessages(null)
mHandler = null
mainFragmentPresenter.detachView()
}
override fun getCares(data: MyCareBean?) {
if (activity != null && !activity!!.isFinishing()) {
myConcernedPeopleBeanArrayList = arrayListOf<MyCareBean.ListBean>()
val people = MyCareBean.ListBean()
people.cmobile = "我自己"
people.update = System.currentTimeMillis() / 1000
people.gpsMsg = AppConfig.curAddress
people.cuid = Constant.MY_USER_UID
(myConcernedPeopleBeanArrayList as ArrayList<MyCareBean.ListBean>).addAll(listOf(people))
myConcernedPeopleBeanArrayList?.addAll(listOf(getMyLocationInfo()))
if (data != null && data.list != null && data.list.size > 0) {
(myConcernedPeopleBeanArrayList as ArrayList<MyCareBean.ListBean>).addAll(data.list)
myConcernedPeopleBeanArrayList?.addAll(data.list)
}
initRvView()
......@@ -298,7 +316,7 @@ class MainFragment : BaseFragment()
}
private fun initManager() {
spUtil = SPUtil.getInstance(context)
spUtil = SPUtil.getInstance()
userManager = UserManager.getInstance()
// 首次安装APP时,只弹一次权限声明
......@@ -410,22 +428,46 @@ class MainFragment : BaseFragment()
* 五折弹窗
*/
private fun discountDialog() {
discountDialog = DiscountDialog(context, object : DialogListener() {
override fun onClick(v: View) {
if (activity != null && !activity!!.isFinishing() &&
discountDialog != null && discountDialog!!.isShowing()) {
discountDialog!!.onDestory()
discountDialog!!.dismiss()
}
when (v.id) {
R.id.tv_dialog_discount -> {
if (!userManager?.vipFlag!!) {
activity?.let { VipPayManager.getInstance(it)!!.gotoPayPage(3) }
}
}
}
// discountDialog = DiscountDialog(context, object : DialogListener() {
// override fun onClick(v: View) {
// if (activity != null && !activity!!.isFinishing() &&
// discountDialog != null && discountDialog!!.isShowing()) {
// discountDialog!!.onDestory()
// discountDialog!!.dismiss()
// }
// when (v.id) {
// R.id.tv_dialog_discount -> {
// if (!userManager?.vipFlag!!) {
// activity?.let { VipPayManager.getInstance(it)!!.gotoPayPage(3) }
// }
// }
// }
// }
// })
// discountDialog!!.show()
}
override fun handleMsg(msg: Message?) {
if (msg?.what == LOCATION_MSG) {
if (activity != null && !activity!!.isFinishing() && refreshLocationFlag) {
LogUtil.d(TAG, "mainfragment handleMsg")
mHandler?.sendEmptyMessageDelayed(LOCATION_MSG, LOCATION_TIME)
myConcernedPeopleBeanArrayList?.set(0, getMyLocationInfo())
myConcernedPeopleAdapter.notifyItemChanged(0)
}
})
discountDialog!!.show()
}
}
fun getMyLocationInfo(): MyCareBean.ListBean {
val people = MyCareBean.ListBean()
people.cmobile = "我自己"
people.update = System.currentTimeMillis() / 1000
people.gpsMsg = AppConfig.curAddress
people.cuid = Constant.MY_USER_UID
return people
}
}
\ No newline at end of file
......@@ -68,7 +68,7 @@ class MyFragment : BaseFragment()
}
myPresenter.attachView(this)
spUtil = SPUtil.getInstance(context)
spUtil = SPUtil.getInstance()
userManager = UserManager.getInstance()
drawable = activity?.let { ContextCompat.getDrawable(it, R.mipmap.ic_launcher) }
initListener()
......@@ -92,7 +92,7 @@ class MyFragment : BaseFragment()
myPresenter?.userLogin(context!!)
}
// context?.let { TopOnNativeAd.loadNativeAd(it, flMyAdContainer) }
TopOnNativeAd.loadNativeAd(flMyAdContainer)
}
}
......@@ -168,7 +168,6 @@ class MyFragment : BaseFragment()
override fun onDestroy() {
super.onDestroy()
TopOnNativeAd.onDestroy()
myPresenter.detachView()
}
......@@ -187,12 +186,6 @@ class MyFragment : BaseFragment()
override fun getSysBaseMsg(msgNum: Int, notifyNum: Int, phone: String) {
if (activity != null && !activity!!.isFinishing()) {
// if (msgNum >= 1) {
// ivMyFragmentNofity.setImageResource(R.mipmap.ic_main_msg_enable)
// } else {
// ivMyFragmentNofity.setImageResource(R.mipmap.ic_main_msg)
// }
if (notifyNum >= 1) {
messageDialog()
}
......@@ -271,21 +264,6 @@ class MyFragment : BaseFragment()
readyGo(WebActivity::class.java, bundle)
}
R.id.rlMyShare -> {
// sendSMS(BuildConfig.MainIp + "instructions.html")
// val wechat_sp = ShareParams()
// wechat_sp.shareType = Platform.SHARE_WEBPAGE
// wechat_sp.title = Constant.SHARE_TITLE
// wechat_sp.text = Constant.SHARE_CONTENT
// wechat_sp.imageData = ImageUtil.drawableToBitmap(drawable)
// wechat_sp.url = Constant.SHARE_URL
// val wechat = ShareSDK.getPlatform(Wechat.NAME)
// if (wechat.isClientValid) {
// // 执行图文分享
// wechat.share(wechat_sp)
// } else {
// showToast("请先安装微信")
// }
bottomDialog = BottomDialog.create(supportFragmentManager)
.setViewListener { v ->
v.findViewById<LinearLayout>(R.id.llDialogShareWx).setOnClickListener(this)
......@@ -326,22 +304,6 @@ class MyFragment : BaseFragment()
}
AppPackageUsageUtils.gotoMessage(context, "")
// val sp = ShareParams()
// sp.title = Constant.SHARE_TITLE
// sp.titleUrl = Constant.SHARE_URL
// sp.text = Constant.SHARE_CONTENT
// sp.site = getString(R.string.app_name)
// sp.siteUrl = Constant.SHARE_URL
// val qq = ShareSDK.getPlatform(QQ.NAME)
// if (qq.isClientValid) {
// // 执行图文分享
// qq.share(sp)
// } else {
// showToast("请先安装QQ")
// }
}
R.id.tvDialogShareNext -> {
if (activity != null && !activity!!.isFinishing()) {
......
......@@ -6,6 +6,7 @@ import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Message
import android.provider.Settings
import android.text.TextUtils
import android.view.LayoutInflater
......@@ -29,6 +30,7 @@ import com.mints.xunmi.ui.activitys.CarePeopleActivity
import com.mints.xunmi.ui.activitys.MyLocusActivity
import com.mints.xunmi.utils.LogUtil
import com.mints.xunmi.utils.TimeRender
import com.mints.xunmi.utils.WeakHandler
import com.tbruyelle.rxpermissions.RxPermissions
import kotlinx.android.synthetic.main.fragment_main_position.*
import java.util.*
......@@ -39,10 +41,16 @@ import java.util.*
* 时间:2020/6/4 17:30
*/
class PositionFragment : Fragment()
, PositionView, View.OnClickListener {
, PositionView, View.OnClickListener, WeakHandler.IHandler {
private val TAG = PositionFragment::class.java.simpleName
/*首页位置刷新相关*/
private var refreshLocationFlag = true
private val LOCATION_TIME: Long = 3000
private val LOCATION_MSG: Int = 103
private var mHandler: WeakHandler? = null
private lateinit var positionPresenter: PositionPresenter
private var mapLayout: View? = null
......@@ -82,6 +90,7 @@ class PositionFragment : Fragment()
positionPresenter?.userLogin(context!!)
}
mHandler = WeakHandler(this)
initMapStyle()
initListener()
......@@ -120,19 +129,21 @@ class PositionFragment : Fragment()
override fun onResume() {
super.onResume()
if (AppConfig.fragmentClickFlag === Constant.FRAGMENT_CLICK_POSITION) {
tvFragmentPositionPosition.text = AppConfig.curAddress
tvFragmentPositionDate.text = TimeRender.formatDate(Date(), TimeRender.ALL_FORMAT_LINE2)
if (mapPosition != null) {
mapPosition.onResume()
}
LogUtil.d(TAG, " PositionFragment onResume")
mHandler?.sendEmptyMessageDelayed(LOCATION_MSG, LOCATION_TIME)
}
}
override fun onPause() {
super.onPause()
refreshLocationFlag = false
if (mapPosition != null) {
mapPosition.onPause()
}
......@@ -148,6 +159,9 @@ class PositionFragment : Fragment()
override fun onDestroy() {
super.onDestroy()
mHandler?.removeCallbacksAndMessages(null)
mHandler = null
mMap?.let {
mMap!!.setOnMyLocationChangeListener(null)
mMap = null
......@@ -191,20 +205,20 @@ class PositionFragment : Fragment()
// 实现定位蓝点
myLocationStyle = MyLocationStyle() //初始化定位蓝点样式类myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE)//连续定位、且将视角移动到地图中心点,定位点依照设备方向旋转,并且会跟随设备移动。(1秒1次定位)如果不设置myLocationType,默认也会执行此种模式。
myLocationStyle?.let {
myLocationStyle!!.showMyLocation(true)//设置是否显示定位小蓝点,用于满足只想使用定位,不想使用定位小蓝点的场景,设置false以后图面上不再有定位蓝点的概念,但是会持续回调位置信息。
myLocationStyle!!.interval(5000) //设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。
it.showMyLocation(true)//设置是否显示定位小蓝点,用于满足只想使用定位,不想使用定位小蓝点的场景,设置false以后图面上不再有定位蓝点的概念,但是会持续回调位置信息。
it.interval(5000) //设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。
}
mMap?.let {
uiSettings = mMap!!.getUiSettings()
mMap!!.moveCamera(CameraUpdateFactory.zoomTo(16F))//设置希望展示的地图缩放级别
mMap!!.setMyLocationStyle(myLocationStyle!!.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE))//连续定位、且将视角移动到地图中心点,定位蓝点跟随设备移动
mMap!!.setMyLocationEnabled(true) // 设置为true表示启动显示定位蓝点,false表示隐藏定位蓝点并不进行定位,默认是false。
uiSettings = it.getUiSettings()
it.moveCamera(CameraUpdateFactory.zoomTo(16F))//设置希望展示的地图缩放级别
it.setMyLocationStyle(myLocationStyle!!.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE))//连续定位、且将视角移动到地图中心点,定位蓝点跟随设备移动
it.setMyLocationEnabled(true) // 设置为true表示启动显示定位蓝点,false表示隐藏定位蓝点并不进行定位,默认是false。
}
uiSettings?.let {
uiSettings!!.setMyLocationButtonEnabled(false)//设置默认定位按钮是否显示
uiSettings!!.setScaleControlsEnabled(false)//设置地图默认的比例尺是否显示
uiSettings!!.setZoomControlsEnabled(false)//设置缩放按钮
it.setMyLocationButtonEnabled(false)//设置默认定位按钮是否显示
it.setScaleControlsEnabled(false)//设置地图默认的比例尺是否显示
it.setZoomControlsEnabled(false)//设置缩放按钮
}
}
......@@ -215,15 +229,12 @@ class PositionFragment : Fragment()
}
override fun showLoading(msg: String?) {
TODO("Not yet implemented")
}
override fun showToast(msg: String?) {
TODO("Not yet implemented")
}
override fun hideLoading() {
TODO("Not yet implemented")
}
override fun getBaseApplication(): MintsApplication = activity?.application as MintsApplication
......@@ -263,4 +274,18 @@ class PositionFragment : Fragment()
builder.setCancelable(false)
builder.show()
}
override fun handleMsg(msg: Message?) {
if (msg?.what == LOCATION_MSG) {
if (activity != null && !activity!!.isFinishing() && refreshLocationFlag) {
LogUtil.d(TAG, "PositionFragment handleMsg")
tvFragmentPositionPosition?.text = AppConfig.curAddress
tvFragmentPositionDate?.text = TimeRender.formatDate(Date(), TimeRender.ALL_FORMAT_LINE2)
mHandler?.sendEmptyMessageDelayed(LOCATION_MSG, LOCATION_TIME)
}
}
}
}
\ No newline at end of file
......@@ -3,6 +3,8 @@ package com.mints.xunmi.utils;
import android.content.Context;
import android.content.SharedPreferences;
import com.mints.xunmi.MintsApplication;
import java.util.Map;
import java.util.Set;
......@@ -22,9 +24,9 @@ public class SPUtil {
private static SPUtil spUtil;
public static SPUtil getInstance(Context context) {
public static SPUtil getInstance() {
if (spUtil == null) {
mContext = context;
mContext = MintsApplication.getContext();
spUtil = new SPUtil();
mPreferences = mContext.getSharedPreferences(mShareName, Context.MODE_PRIVATE);
}
......
......@@ -399,6 +399,7 @@
android:scaleType="fitXY"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20pt"
android:layout_marginBottom="20pt"
android:src="@mipmap/bg_banner" />
</LinearLayout>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment