This commit is contained in:
ocean 2024-07-15 18:56:41 +08:00
parent 2ce6d61bae
commit 2c7a8e3169
5 changed files with 126 additions and 76 deletions

View File

@ -36,29 +36,27 @@ open class BaseActivity : AppCompatActivity(), LifecycleOwner {
appStore.shouldEnterMusicPage = true
}
LogTag.LogD(TAG, "BaseActivity withPermission shouldEnterMusicPage->${appStore.shouldEnterMusicPage}")
if (!appStore.shouldEnterMusicPage) {
return false
}
// 不允许的国家代码
val restrictedCountries = setOf(
// "CN",
"HK",
"TW",
"JP",
"KR",
// "GB",
// "CH",
// "BE",
// "MO",
// "SG"
)
// 检查是否包含当前的国家代码
LogTag.LogD(TAG, "BaseActivity withPermission ipCountryCode->${appStore.ipCountryCode}")
if (appStore.ipCountryCode in restrictedCountries) {
return false
}
// 如果不在受限国家代码中,则继续其他检查
return withIso()
return appStore.shouldEnterMusicPage
// // 不允许的国家代码
// val restrictedCountries = setOf(
//// "CN",
// "HK",
// "TW",
// "JP",
// "KR",
//// "GB",
//// "CH",
//// "BE",
//// "MO",
//// "SG"
// )
// // 检查是否包含当前的国家代码
// LogTag.LogD(TAG, "BaseActivity withPermission ipCountryCode->${appStore.ipCountryCode}")
// if (appStore.ipCountryCode in restrictedCountries) {
// return false
// }
// // 如果不在受限国家代码中,则继续其他检查
// return withIso()
}
private fun withIso(): Boolean {

View File

@ -358,29 +358,27 @@ abstract class MoBaseActivity : AppCompatActivity(), MusicPlayerView.PlaySkipFor
appStore.shouldEnterMusicPage = true
}
LogTag.LogD(TAG, "withPermission shouldEnterMusicPage->${appStore.shouldEnterMusicPage}")
if (!appStore.shouldEnterMusicPage) {
return false
}
// 不允许的国家代码
val restrictedCountries = setOf(
// "CN",
"HK",
"TW",
"JP",
"KR",
// "GB",
// "CH",
// "BE",
// "MO",
// "SG"
)
// 检查是否包含当前的国家代码
LogTag.LogD(TAG, "withPermission ipCountryCode->${appStore.ipCountryCode}")
if (appStore.ipCountryCode in restrictedCountries) {
return false
}
// 如果不在受限国家代码中,则继续其他检查
return withIso()
return appStore.shouldEnterMusicPage
// // 不允许的国家代码
// val restrictedCountries = setOf(
//// "CN",
// "HK",
// "TW",
// "JP",
// "KR",
//// "GB",
//// "CH",
//// "BE",
//// "MO",
//// "SG"
// )
// // 检查是否包含当前的国家代码
// LogTag.LogD(TAG, "withPermission ipCountryCode->${appStore.ipCountryCode}")
// if (appStore.ipCountryCode in restrictedCountries) {
// return false
// }
// // 如果不在受限国家代码中,则继续其他检查
// return withIso()
}
private fun withIso(): Boolean {

View File

@ -90,6 +90,8 @@ class SearchFragment : MoBaseFragment<FragmentSearchBinding>(), TextWatcher,
R.layout.ad_layout_admob_banner,
R.layout.ad_layout_max_banner
)
LogTag.LogD(TAG, "search onResume")
}
private fun initView() {
@ -162,9 +164,14 @@ class SearchFragment : MoBaseFragment<FragmentSearchBinding>(), TextWatcher,
when (it) {
is Request.SearchSuggestions -> {
val input = binding.searchEdit.text.toString().trim()
if (input.isNotEmpty()) {
Innertube.searchSuggestions(SearchSuggestionsBody(input = input))
?.onSuccess { suggestionsList ->
LogTag.LogD(TAG, "suggestionsList->${suggestionsList?.size}")
LogTag.LogD(
TAG,
"suggestionsList->${suggestionsList?.size}"
)
if(binding.searchEdit.text.toString().trim().isNotEmpty()){
if (suggestionsList != null) {
AnalysisUtil.logEvent(AnalysisUtil.SEARCH_SUG_SHOW)
showSearchSuggestions()
@ -174,13 +181,21 @@ class SearchFragment : MoBaseFragment<FragmentSearchBinding>(), TextWatcher,
} else {
binding.searchSuggestionsLayout.visibility = View.GONE
}
}else{
searchSuggestionsList.clear()
searchSuggestionsAdapterAdapter?.notifyDataSetChanged()
binding.searchSuggestionsLayout.visibility = View.GONE
}
}?.onFailure { error ->
LogTag.LogD(TAG, "searchSuggestions onFailure->${error}")
binding.searchSuggestionsLayout.visibility = View.GONE
}
}
}
is Request.SearchData -> {
val input = it.input
if (input.isNotEmpty()) {
AnalysisUtil.logEvent(AnalysisUtil.SEARCH_TRIGGER)
LolAdWrapper.shared.showAdTiming(
requireActivity(), AdPlacement.INST_SEARCH
@ -188,8 +203,7 @@ class SearchFragment : MoBaseFragment<FragmentSearchBinding>(), TextWatcher,
showLoadingLayout()
binding.contentLayout.removeAllViews()
binding.searchEdit.clearFocus()
val input = it.input
if (input.isNotEmpty()) {
searchHistorySet.clear()
searchHistorySet.addAll(appStore.searchHistoryStore)
if (!appStore.searchHistoryStore.contains(input)) {//把不存在的记录保存到集合中
@ -223,7 +237,7 @@ class SearchFragment : MoBaseFragment<FragmentSearchBinding>(), TextWatcher,
}?.onFailure {
showNoContentLayout()
}
}
LolAdWrapper.shared.loadAdIfNotCached(
requireActivity(), AdPlacement.INST_SEARCH
)
@ -231,13 +245,25 @@ class SearchFragment : MoBaseFragment<FragmentSearchBinding>(), TextWatcher,
}
}
}
events.onReceive {
when (it) {
Event.FragmentOnResume -> {
LogTag.LogD(TAG, "search FragmentOnResume")
updateHistoryUi()
}
}
}
}
}
}
override fun onHiddenChanged(hidden: Boolean) {
super.onHiddenChanged(hidden)
LogTag.LogD(TAG, "search onHiddenChanged->$hidden")
if (!hidden) {
binding.searchEdit.requestFocus()
showSearchHistory()
updateHistoryUi()
} else {
binding.searchEdit.clearFocus()
binding.searchEdit.text.clear()
@ -273,6 +299,12 @@ class SearchFragment : MoBaseFragment<FragmentSearchBinding>(), TextWatcher,
@SuppressLint("NotifyDataSetChanged")
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}
override fun afterTextChanged(s: Editable?) {
requests.trySend(Request.SearchSuggestions)
if (s.isNullOrEmpty()) {//没有输入内容,隐藏删除按钮,展示历史记录,重新获取焦点弹出键盘。
binding.deleteInputBtn.visibility = View.GONE
showSearchHistory()
@ -283,11 +315,8 @@ class SearchFragment : MoBaseFragment<FragmentSearchBinding>(), TextWatcher,
}
}
override fun afterTextChanged(s: Editable?) {
requests.trySend(Request.SearchSuggestions)
}
override fun onFocusChange(v: View?, hasFocus: Boolean) {
LogTag.LogD(TAG,"onFocusChange hasFocus->$hasFocus")
handler.postDelayed({
if (hasFocus) {
showImm()

View File

@ -5,6 +5,7 @@ import okhttp3.Call
import okhttp3.Response
import org.json.JSONObject
import melody.offline.music.sp.AppStore
import melody.offline.music.util.AnalysisUtil
import melody.offline.music.util.LogTag
import java.io.IOException
@ -29,13 +30,17 @@ class UploadEventName {
BaseApiUtil.shared.postJson(context, "first_open"),
object : okhttp3.Callback {
override fun onFailure(call: Call, e: IOException) {
val jsonObject = JSONObject()
jsonObject.put("fail", e.toString())
val map = mutableMapOf(Pair(AnalysisUtil.PARAM_VALUE, jsonObject.toString()))
AnalysisUtil.logEvent(AnalysisUtil.APP_FIRST_OPEN_FAIL, map)
}
override fun onResponse(call: Call, response: Response) {
try {
LogTag.LogD(TAG, "first_open response->${response}")
if (response.code == 200) {
AnalysisUtil.logEvent(AnalysisUtil.APP_FIRST_OPEN_SUCCESS)
val responseData = response.body?.string()
if (responseData != null) {
val jsonObject = JSONObject(responseData)
@ -46,7 +51,13 @@ class UploadEventName {
AppStore(context).firstOpenIsSucceed = true
}
}
}else{
val jsonObject = JSONObject()
jsonObject.put("fail", response)
val map = mutableMapOf(Pair(AnalysisUtil.PARAM_VALUE, jsonObject.toString()))
AnalysisUtil.logEvent(AnalysisUtil.APP_FIRST_OPEN_FAIL, map)
}
} catch (e: Exception) {
e.printStackTrace()
}
@ -64,13 +75,17 @@ class UploadEventName {
BaseApiUtil.shared.postJson(context, "app_open"),
object : okhttp3.Callback {
override fun onFailure(call: Call, e: IOException) {
val jsonObject = JSONObject()
jsonObject.put("fail", e.toString())
val map = mutableMapOf(Pair(AnalysisUtil.PARAM_VALUE, jsonObject.toString()))
AnalysisUtil.logEvent(AnalysisUtil.APP_OPEN_FAIL, map)
}
override fun onResponse(call: Call, response: Response) {
try {
LogTag.LogD(TAG, "start_program response->${response}")
if (response.code == 200) {
AnalysisUtil.logEvent(AnalysisUtil.APP_OPEN_SUCCESS)
val responseData = response.body?.string()
if (responseData != null) {
val jsonObject = JSONObject(responseData)
@ -78,7 +93,13 @@ class UploadEventName {
LogTag.LogD(TAG, "start_program jsonObject->${jsonObject}")
LogTag.LogD(TAG, "start_program status->${status}")
}
}else{
val jsonObject = JSONObject()
jsonObject.put("fail", response)
val map = mutableMapOf(Pair(AnalysisUtil.PARAM_VALUE, jsonObject.toString()))
AnalysisUtil.logEvent(AnalysisUtil.APP_OPEN_FAIL, map)
}
} catch (e: Exception) {
e.printStackTrace()
}

View File

@ -38,6 +38,10 @@ object AnalysisUtil {
const val RATING_DIALOG_OK_CLICK = "rating_dialog_ok_click"
const val RATING_DIALOG_CANCEL_CLICK = "rating_dialog_cancel_click"
const val HOME_A_TO_B = "home_a_to_b"
const val APP_FIRST_OPEN_SUCCESS = "app_first_open_success"
const val APP_FIRST_OPEN_FAIL = "app_first_open_fail"
const val APP_OPEN_SUCCESS = "app_open_success"
const val APP_OPEN_FAIL = "app_open_fail"
private const val AD_INST_SPLASH_SUCCESS = "ad_user_open_success"//首页开屏广告展示成功