Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_xunmi
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
android
android_xunmi
Commits
6023ade7
Commit
6023ade7
authored
Nov 05, 2020
by
mengcuiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
预加载优化
parent
5fdbd924
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
36 deletions
+47
-36
TopOnNativeAd.kt
...ion/app/src/main/java/com/mints/xunmi/ad/TopOnNativeAd.kt
+25
-20
MainFragment.kt
...src/main/java/com/mints/xunmi/ui/fragment/MainFragment.kt
+21
-15
MyFragment.kt
...p/src/main/java/com/mints/xunmi/ui/fragment/MyFragment.kt
+1
-1
No files found.
position/app/src/main/java/com/mints/xunmi/ad/TopOnNativeAd.kt
View file @
6023ade7
...
@@ -8,6 +8,7 @@ import com.anythink.core.api.ATAdConst
...
@@ -8,6 +8,7 @@ import com.anythink.core.api.ATAdConst
import
com.anythink.core.api.ATAdInfo
import
com.anythink.core.api.ATAdInfo
import
com.anythink.core.api.AdError
import
com.anythink.core.api.AdError
import
com.anythink.nativead.api.*
import
com.anythink.nativead.api.*
import
com.mints.xunmi.MintsApplication
import
com.mints.xunmi.manager.TopOnManager
import
com.mints.xunmi.manager.TopOnManager
import
com.mints.xunmi.ui.widgets.NativeDemoRender
import
com.mints.xunmi.ui.widgets.NativeDemoRender
import
com.mints.xunmi.utils.LogUtil
import
com.mints.xunmi.utils.LogUtil
...
@@ -21,19 +22,20 @@ object TopOnNativeAd {
...
@@ -21,19 +22,20 @@ object TopOnNativeAd {
private
val
TAG
=
TopOnNativeAd
::
class
.
java
.
simpleName
private
val
TAG
=
TopOnNativeAd
::
class
.
java
.
simpleName
var
context
:
Context
?
=
null
private
lateinit
var
context
:
Context
var
atNatives
:
ATNative
?
=
null
private
var
atNatives
:
ATNative
?
=
null
var
mNativeAd
:
NativeAd
?
=
null
private
var
mNativeAd
:
NativeAd
?
=
null
var
anyThinkNativeAdView
:
ATNativeAdView
?
=
null
private
var
anyThinkNativeAdView
:
ATNativeAdView
?
=
null
var
padding
:
Int
=
0
private
var
padding
:
Int
=
0
var
containerHeight
:
Int
=
0
private
var
containerHeight
:
Int
=
0
/**
/**
* 应用初始化
* 应用初始化
*/
*/
fun
init
(
context
:
Context
)
{
fun
init
()
{
this
.
context
=
context
val
contextMints
=
MintsApplication
.
getContext
()
this
.
context
=
contextMints
atNatives
=
ATNative
(
context
,
TopOnManager
.
INFORMATION_ID
,
object
:
ATNativeNetworkListener
{
atNatives
=
ATNative
(
context
,
TopOnManager
.
INFORMATION_ID
,
object
:
ATNativeNetworkListener
{
override
fun
onNativeAdLoaded
()
{
override
fun
onNativeAdLoaded
()
{
LogUtil
.
e
(
TAG
,
"onNativeAdLoaded"
)
LogUtil
.
e
(
TAG
,
"onNativeAdLoaded"
)
...
@@ -43,9 +45,9 @@ object TopOnNativeAd {
...
@@ -43,9 +45,9 @@ object TopOnNativeAd {
LogUtil
.
e
(
TAG
,
"onNativeAdLoadFail"
+
adError
.
desc
)
LogUtil
.
e
(
TAG
,
"onNativeAdLoadFail"
+
adError
.
desc
)
}
}
})
})
padding
=
dip2px
(
context
,
10f
)
padding
=
dip2px
(
context
Mints
,
10f
)
containerHeight
=
dip2px
(
context
,
290f
)
containerHeight
=
dip2px
(
context
Mints
,
290f
)
val
adViewWidth
:
Int
=
context
.
getResources
().
getDisplayMetrics
().
widthPixels
-
2
*
padding
val
adViewWidth
:
Int
=
context
Mints
.
getResources
().
getDisplayMetrics
().
widthPixels
-
2
*
padding
val
adViewHeight
=
containerHeight
-
2
*
padding
val
adViewHeight
=
containerHeight
-
2
*
padding
val
localMap
:
MutableMap
<
String
,
Any
>
=
HashMap
()
val
localMap
:
MutableMap
<
String
,
Any
>
=
HashMap
()
// since v5.6.4
// since v5.6.4
...
@@ -61,18 +63,19 @@ object TopOnNativeAd {
...
@@ -61,18 +63,19 @@ object TopOnNativeAd {
}
}
/**
/**
* 预加载
* 预加载
广告
*/
*/
fun
loadNativeAd
(
frameLayout
:
FrameLayout
?)
{
fun
loadNativeAd
()
{
atNatives
?.
makeAdRequest
()
try
{
atNatives
?.
makeAdRequest
()
showNativeAd
(
frameLayout
)
}
catch
(
e
:
Exception
)
{
}
}
}
/**
/**
* 显示
* 显示
广告
*/
*/
private
fun
showNativeAd
(
frameLayout
:
FrameLayout
?)
{
fun
showNativeAd
(
frameLayout
:
FrameLayout
?)
{
val
nativeAd
=
atNatives
?.
nativeAd
val
nativeAd
=
atNatives
?.
nativeAd
nativeAd
?.
let
{
nativeAd
?.
let
{
if
(
mNativeAd
!=
null
)
{
if
(
mNativeAd
!=
null
)
{
...
@@ -120,10 +123,13 @@ object TopOnNativeAd {
...
@@ -120,10 +123,13 @@ object TopOnNativeAd {
it
.
prepare
(
anyThinkNativeAdView
,
anyThinkRender
.
getClickView
(),
null
)
it
.
prepare
(
anyThinkNativeAdView
,
anyThinkRender
.
getClickView
(),
null
)
if
(
anyThinkNativeAdView
!=
null
&&
anyThinkNativeAdView
!!
.
parent
==
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
))
}
}
}
}
}
}
// 预加载
loadNativeAd
()
}
}
fun
dip2px
(
context
:
Context
,
dipValue
:
Float
):
Int
{
fun
dip2px
(
context
:
Context
,
dipValue
:
Float
):
Int
{
...
@@ -142,6 +148,5 @@ object TopOnNativeAd {
...
@@ -142,6 +148,5 @@ object TopOnNativeAd {
fun
onDestroy
()
{
fun
onDestroy
()
{
anyThinkNativeAdView
?.
destory
()
anyThinkNativeAdView
?.
destory
()
mNativeAd
?.
destory
()
mNativeAd
?.
destory
()
context
=
null
}
}
}
}
\ No newline at end of file
position/app/src/main/java/com/mints/xunmi/ui/fragment/MainFragment.kt
View file @
6023ade7
...
@@ -10,6 +10,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
...
@@ -10,6 +10,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import
com.mints.library.recyclerview.HeaderAndFooterRecyclerViewAdapter
import
com.mints.library.recyclerview.HeaderAndFooterRecyclerViewAdapter
import
com.mints.library.recyclerview.RecyclerViewUtils
import
com.mints.library.recyclerview.RecyclerViewUtils
import
com.mints.library.utils.nodoubleclick.AntiShake
import
com.mints.library.utils.nodoubleclick.AntiShake
import
com.mints.xunmi.MintsApplication
import
com.mints.xunmi.R
import
com.mints.xunmi.R
import
com.mints.xunmi.ad.TopOnNativeAd
import
com.mints.xunmi.ad.TopOnNativeAd
import
com.mints.xunmi.common.AppConfig
import
com.mints.xunmi.common.AppConfig
...
@@ -69,21 +70,8 @@ class MainFragment : BaseFragment()
...
@@ -69,21 +70,8 @@ class MainFragment : BaseFragment()
override
fun
getContentViewLayoutID
()
=
R
.
layout
.
fragment_main_first
override
fun
getContentViewLayoutID
()
=
R
.
layout
.
fragment_main_first
override
fun
initViewsAndEvents
()
{
override
fun
initViewsAndEvents
()
{
if
(!
::
mainFragmentPresenter
.
isInitialized
)
{
mainFragmentPresenter
=
MainFragmentPresenter
()
}
mainFragmentPresenter
.
attachView
(
this
)
initManager
()
initManager
()
initTopOnNativeAd
()
context
?.
let
{
TopOnNativeAd
.
init
(
it
)
TopOnNativeAd
.
loadNativeAd
(
null
)
}
linearLayoutManager
=
LinearLayoutManager
(
activity
)
rvMain
.
layoutManager
=
linearLayoutManager
initLinstener
()
initLinstener
()
...
@@ -95,7 +83,15 @@ class MainFragment : BaseFragment()
...
@@ -95,7 +83,15 @@ class MainFragment : BaseFragment()
// }
// }
// }
// }
mHandler
=
WeakHandler
(
this
)
}
/**
* 初始化 预加载 topon信息流
*/
private
fun
initTopOnNativeAd
()
{
TopOnNativeAd
.
init
()
TopOnNativeAd
.
loadNativeAd
()
}
}
override
fun
onHiddenChanged
(
hidden
:
Boolean
)
{
override
fun
onHiddenChanged
(
hidden
:
Boolean
)
{
...
@@ -316,6 +312,11 @@ class MainFragment : BaseFragment()
...
@@ -316,6 +312,11 @@ class MainFragment : BaseFragment()
}
}
private
fun
initManager
()
{
private
fun
initManager
()
{
if
(!
::
mainFragmentPresenter
.
isInitialized
)
{
mainFragmentPresenter
=
MainFragmentPresenter
()
}
mainFragmentPresenter
.
attachView
(
this
)
spUtil
=
SPUtil
.
getInstance
()
spUtil
=
SPUtil
.
getInstance
()
userManager
=
UserManager
.
getInstance
()
userManager
=
UserManager
.
getInstance
()
...
@@ -323,6 +324,11 @@ class MainFragment : BaseFragment()
...
@@ -323,6 +324,11 @@ class MainFragment : BaseFragment()
if
(
spUtil
?.
getBoolean
(
Constant
.
LOAN_PERMISSION_FLAG
,
true
)
!!
)
{
if
(
spUtil
?.
getBoolean
(
Constant
.
LOAN_PERMISSION_FLAG
,
true
)
!!
)
{
powerDialog
()
powerDialog
()
}
}
linearLayoutManager
=
LinearLayoutManager
(
activity
)
rvMain
.
layoutManager
=
linearLayoutManager
mHandler
=
WeakHandler
(
this
)
}
}
private
fun
initLinstener
()
{
private
fun
initLinstener
()
{
...
...
position/app/src/main/java/com/mints/xunmi/ui/fragment/MyFragment.kt
View file @
6023ade7
...
@@ -92,7 +92,7 @@ class MyFragment : BaseFragment()
...
@@ -92,7 +92,7 @@ class MyFragment : BaseFragment()
myPresenter
?.
userLogin
(
context
!!
)
myPresenter
?.
userLogin
(
context
!!
)
}
}
TopOnNativeAd
.
load
NativeAd
(
flMyAdContainer
)
TopOnNativeAd
.
show
NativeAd
(
flMyAdContainer
)
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment