广告调整与悬浮layout添加下一曲。

This commit is contained in:
ocean 2024-06-17 15:11:32 +08:00
parent 948355b16c
commit 7e4ba3c73f
14 changed files with 239 additions and 155 deletions

View File

@ -16,8 +16,8 @@ android {
applicationId = "com.hi.melody.music.noise"
minSdk = 24
targetSdk = 34
versionCode = 2
versionName = "1.0.2"
versionCode = 3
versionName = "1.0.3"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

View File

@ -60,7 +60,7 @@ class LaunchActivity : MoBaseActivity() {
removeMessages(MSG_LOAD_AD_LOADED)
return
}
progress += 2
progress += 3
progressBar.setProgress(progress)
sendEmptyMessageDelayed(MSG_LOAD_AD_LOADED, delayMillis)
}

View File

@ -43,10 +43,9 @@ class MainActivity : BaseActivity() {
override fun onResume() {
super.onResume()
LolAdWrapper.shared.loadAdIfNotCached(this, AdPlacement.INST_CUTTING_SONG)
LolAdWrapper.shared.loadAdIfNotCached(this, AdPlacement.INST_DOWNLOAD)
LolAdWrapper.shared.loadAdIfNotCached(this, AdPlacement.INST_SEARCH)
LolAdWrapper.shared.loadAdIfNotCached(this, AdPlacement.INST_ME_PAGE_LIST)
val currentPlayer = LocalMediaControllerManager.getController()
if (melody.offline.music.App.currentPlayingAudio == null) {

View File

@ -131,9 +131,20 @@ class LolAdWrapper {
}
fun showAdTiming(act: Activity, placement: String, listener: LolShowListener? = null) {
//当前时间减去旧时间,才展示广告
//当前时间减去旧时间,才展示广告满足间隔时间才show广告
if (System.currentTimeMillis() - App.app.lastAdDisplayTime.get() >= AppStore(App.app).showAdIntervalTime) {
showAdIfCached(act, placement, listener)
//判断当前广告位是否可以show不能show则判断补位广告是否可以show。
if (act.isFinishing || !hasCache(placement)) {
if (hasCache(AdPlacement.INST_BACKUP_ADS)) {
showAd(act, AdPlacement.INST_BACKUP_ADS, listener)
} else {
val map = mutableMapOf(Pair(AnalysisUtil.PARAM_VALUE, "No cache for ads"))
AnalysisUtil.placeToLogEvent(placement, AnalysisAdState.AD_SHOW_FAILED, map)
listener?.showFailed(LolShowError("No cache for ads"))
}
} else {
showAd(act, placement, listener)
}
}
}

View File

@ -5,7 +5,7 @@ object Constants {
const val KEY_SHOULD_ENTER_MUSIC_JSON = "key_should_enter_music_json"
const val DEFAULT_SHOULD_ENTER_MUSIC_JSON = """
{
"versionCode": 2,
"versionCode": 3,
"enter": false
}
"""

View File

@ -30,6 +30,7 @@ class MoMeFragment : MoBaseFragment<FragmentMoMeBinding>() {
get() = FragmentMoMeBinding::inflate
override suspend fun onViewCreated() {
LolAdWrapper.shared.loadAdIfNotCached(requireActivity(), AdPlacement.INST_ME_PAGE_LIST)
initView()
onReceive()
}

View File

@ -71,6 +71,7 @@ class SearchFragment : MoBaseFragment<FragmentSearchBinding>(), TextWatcher,
get() = FragmentSearchBinding::inflate
override suspend fun onViewCreated() {
LolAdWrapper.shared.loadAdIfNotCached(requireActivity(), AdPlacement.INST_SEARCH)
initView()
initSearchSuggestionsAdapter()
initSearchHistoryAdapter()

View File

@ -18,6 +18,8 @@ import com.bumptech.glide.Glide
import melody.offline.music.R
import melody.offline.music.activity.MoPlayDetailsActivity
import melody.offline.music.activity.PrimaryActivity
import melody.offline.music.ads.AdPlacement
import melody.offline.music.ads.LolAdWrapper
import melody.offline.music.fragment.MoHomeFragment
import melody.offline.music.fragment.MoMeFragment
import melody.offline.music.fragment.SearchFragment
@ -39,6 +41,7 @@ class MusicPlayerView(
private var name: TextView
private var desc: TextView
private var playBlackBtn: LinearLayout
private var playSkipForwardBtn:LinearLayout
init {
LayoutInflater.from(context).inflate(R.layout.music_player_layout, this, true)
@ -49,6 +52,7 @@ class MusicPlayerView(
name = findViewById(R.id.name)
desc = findViewById(R.id.desc)
playBlackBtn = findViewById(R.id.play_black_btn)
playSkipForwardBtn = findViewById(R.id.play_skip_forward_btn)
initOnClickListener()
}
@ -65,6 +69,17 @@ class MusicPlayerView(
updateProgressState(meController)
}
}
playSkipForwardBtn.setOnClickListener {
if (meController != null) {
meController.seekToNextMediaItem()
updateInfoUi(meController.currentMediaItem)
updateProgressState(meController)
if (!meController.isPlaying) {
meController.prepare()
meController.play()
}
}
}
goDetailsBtn.setOnClickListener {
when (context) {
is PrimaryActivity -> {

View File

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="34dp"
android:height="34dp"
android:viewportWidth="34"
android:viewportHeight="34">
<path
android:pathData="M9,9h17v16h-17z"
android:fillColor="#ffffff"/>
<path
android:pathData="M16.99,2.129C25.197,2.129 31.85,8.782 31.85,16.989C31.85,25.196 25.197,31.849 16.99,31.849C8.783,31.849 2.13,25.196 2.13,16.989C2.13,8.782 8.783,2.129 16.99,2.129ZM11.285,20.143C11.272,22.285 12.188,22.816 14.032,21.733C15.876,20.652 17.726,19.58 19.582,18.52C20.081,18.234 20.445,17.949 20.676,17.664V21.447C20.676,22.005 21.128,22.458 21.686,22.458C22.244,22.458 22.697,22.005 22.697,21.447V12.531C22.697,11.973 22.244,11.521 21.686,11.521C21.128,11.521 20.676,11.973 20.676,12.531V16.194C20.445,15.908 20.081,15.623 19.582,15.338C17.726,14.277 15.876,13.206 14.032,12.124C12.188,11.042 11.272,11.572 11.285,13.715C11.297,15.858 11.297,18 11.285,20.143Z"
android:fillColor="#333333"/>
</vector>

View File

@ -7,7 +7,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="96dp"
android:layout_height="122dp"
android:background="@drawable/drw_admob_bg"
android:gravity="center_horizontal"
android:orientation="horizontal">
@ -44,7 +44,7 @@
android:layout_marginBottom="4dp"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingHorizontal="12dp">
android:paddingHorizontal="8dp">
<LinearLayout
android:layout_width="wrap_content"

View File

@ -35,6 +35,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingBottom="4dp">
<TextView

View File

@ -7,7 +7,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_card_white_ad_round4dp"
android:background="@drawable/drw_admob_bg"
android:orientation="vertical"
tools:ignore="MissingConstraints">
@ -27,32 +27,51 @@
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="12dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/tv_event_title"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="4dp"
android:ellipsize="end"
android:drawableLeft="@mipmap/ad_tag"
android:fontFamily="@string/Roboto_Medium"
android:lineSpacingExtra="0dp"
android:paddingBottom="4dp"
android:singleLine="true"
android:textColor="@color/theme_black"
android:textSize="16dp"
android:textStyle="bold"
tools:text="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingBottom="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/drw_ad_tag_bg"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:text="AD"
android:textColor="@color/white"
android:textSize="12dp" />
<TextView
android:id="@+id/tv_event_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="@string/Roboto_Medium"
android:lineSpacingExtra="0dp"
android:paddingStart="4dp"
android:paddingBottom="4dp"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="16dp"
android:textStyle="bold"
tools:text="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
</LinearLayout>
<TextView
android:id="@+id/tv_advertiser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:fontFamily="@string/Roboto_Regular"
android:textColor="@color/color_7f000000"
android:textColor="@color/white_60"
android:textSize="12dp"
android:visibility="visible"
tools:text="xxxxxxxxxxxxxxxxxxxxx" />
@ -62,10 +81,10 @@
android:id="@+id/ll_ad_options_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentEnd="true"
android:layout_marginTop="-10dp"
android:visibility="visible"
android:layout_alignParentEnd="true">
android:orientation="vertical"
android:visibility="visible">
</LinearLayout>
</LinearLayout>
@ -74,13 +93,13 @@
android:id="@+id/tv_event_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="12dp"
android:layout_marginBottom="12dp"
android:ellipsize="end"
android:fontFamily="@string/Roboto_Regular"
android:lineSpacingExtra="0dp"
android:maxLines="2"
android:layout_marginBottom="12dp"
android:layout_marginHorizontal="12dp"
android:textColor="@color/text_gray"
android:textColor="@color/white_60"
android:textSize="12dp"
tools:text="xxxxxxxxxxxxxxxxxxxxx" />
@ -88,10 +107,9 @@
<FrameLayout
android:id="@+id/mv_event_con"
android:layout_width="match_parent"
android:layout_height="152dp"
android:layout_marginHorizontal="12dp"
tools:background="@color/color_FFF7F9FB"
android:layout_height="152dp" >
</FrameLayout>
tools:background="@color/black_60"></FrameLayout>
<Button
android:id="@+id/tv_event_bt"
@ -99,10 +117,10 @@
android:layout_height="48dp"
android:layout_marginHorizontal="14dp"
android:layout_marginTop="10dp"
android:background="@drawable/bg_btn_ad"
android:layout_marginBottom="12dp"
android:background="@drawable/drw_btn_bg"
android:textColor="@color/white"
android:textSize="15dp"
android:layout_marginBottom="12dp"
android:textStyle="bold"
tools:text="action now " />
</LinearLayout>

View File

@ -51,148 +51,159 @@
</LinearLayout>
</LinearLayout>
<LinearLayout
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="14dp"
android:orientation="horizontal">
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/likedSongsBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
app:cardBackgroundColor="@color/green_60"
app:cardCornerRadius="10dp"
app:cardElevation="0dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="24dp"
android:src="@drawable/library_liked_icon" />
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="@font/medium_font"
android:text="@string/liked_songs"
android:textColor="@color/white"
android:textSize="14dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_margin="14dp"
android:orientation="horizontal">
<TextView
android:id="@+id/likedSongsTv"
android:layout_width="wrap_content"
<LinearLayout
android:id="@+id/likedSongsBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="@font/regular_font"
android:text="0"
android:textColor="@color/white_60"
android:textSize="12dp" />
android:layout_margin="4dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
app:cardBackgroundColor="@color/green_60"
app:cardCornerRadius="10dp"
app:cardElevation="0dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="24dp"
android:src="@drawable/library_liked_icon" />
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="@font/medium_font"
android:text="@string/liked_songs"
android:textColor="@color/white"
android:textSize="14dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/likedSongsTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/regular_font"
android:text="0"
android:textColor="@color/white_60"
android:textSize="12dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:fontFamily="@font/regular_font"
android:text="@string/songs"
android:textColor="@color/white_60"
android:textSize="12dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/offlineSongsBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:fontFamily="@font/regular_font"
android:text="@string/songs"
android:textColor="@color/white_60"
android:textSize="12dp" />
android:layout_margin="4dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
app:cardBackgroundColor="@color/offline_bg_color_60"
app:cardCornerRadius="10dp"
app:cardElevation="0dp">
<LinearLayout
android:id="@+id/offlineSongsBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="24dp"
android:src="@drawable/library_offline_icon" />
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
app:cardBackgroundColor="@color/offline_bg_color_60"
app:cardCornerRadius="10dp"
app:cardElevation="0dp">
</androidx.cardview.widget.CardView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="24dp"
android:src="@drawable/library_offline_icon" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="@font/medium_font"
android:text="@string/offline_songs"
android:textColor="@color/white"
android:textSize="14dp" />
</androidx.cardview.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="@font/medium_font"
android:text="@string/offline_songs"
android:textColor="@color/white"
android:textSize="14dp" />
<TextView
android:id="@+id/offlineSongsTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/regular_font"
android:text="0"
android:textColor="@color/white_60"
android:textSize="12dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:fontFamily="@font/regular_font"
android:text="@string/songs"
android:textColor="@color/white_60"
android:textSize="12dp" />
<TextView
android:id="@+id/offlineSongsTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/regular_font"
android:text="0"
android:textColor="@color/white_60"
android:textSize="12dp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:fontFamily="@font/regular_font"
android:text="@string/songs"
android:textColor="@color/white_60"
android:textSize="12dp" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/frame_ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="14dp"
android:layout_marginEnd="14dp" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/frame_ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="14dp"
android:layout_marginEnd="14dp" />
</androidx.core.widget.NestedScrollView>
</LinearLayout>

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_height="wrap_content">
<com.lihang.ShadowLayout
android:id="@+id/playing_status_layout"
@ -48,8 +48,8 @@
<ImageView
android:id="@+id/audio_img"
android:layout_width="48dp"
android:scaleType="centerCrop"
android:layout_height="48dp"
android:scaleType="centerCrop"
android:src="@mipmap/app_logo" />
</androidx.cardview.widget.CardView>
@ -106,6 +106,21 @@
android:src="@drawable/play_black_icon" />
</LinearLayout>
<LinearLayout
android:id="@+id/play_skip_forward_btn"
android:layout_width="42dp"
android:layout_height="42dp"
android:gravity="center">
<ImageView
android:id="@+id/play_skip_forward_img"
android:layout_width="34dp"
android:layout_height="34dp"
android:src="@drawable/play_skip_forward_black_icon" />
</LinearLayout>
</LinearLayout>
</com.lihang.ShadowLayout>