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

View File

@ -358,29 +358,27 @@ abstract class MoBaseActivity : AppCompatActivity(), MusicPlayerView.PlaySkipFor
appStore.shouldEnterMusicPage = true appStore.shouldEnterMusicPage = true
} }
LogTag.LogD(TAG, "withPermission shouldEnterMusicPage->${appStore.shouldEnterMusicPage}") LogTag.LogD(TAG, "withPermission shouldEnterMusicPage->${appStore.shouldEnterMusicPage}")
if (!appStore.shouldEnterMusicPage) { return appStore.shouldEnterMusicPage
return false // // 不允许的国家代码
} // val restrictedCountries = setOf(
// 不允许的国家代码 //// "CN",
val restrictedCountries = setOf( // "HK",
// "CN", // "TW",
"HK", // "JP",
"TW", // "KR",
"JP", //// "GB",
"KR", //// "CH",
// "GB", //// "BE",
// "CH", //// "MO",
// "BE", //// "SG"
// "MO", // )
// "SG" // // 检查是否包含当前的国家代码
) // LogTag.LogD(TAG, "withPermission ipCountryCode->${appStore.ipCountryCode}")
// 检查是否包含当前的国家代码 // if (appStore.ipCountryCode in restrictedCountries) {
LogTag.LogD(TAG, "withPermission ipCountryCode->${appStore.ipCountryCode}") // return false
if (appStore.ipCountryCode in restrictedCountries) { // }
return false // // 如果不在受限国家代码中,则继续其他检查
} // return withIso()
// 如果不在受限国家代码中,则继续其他检查
return withIso()
} }
private fun withIso(): Boolean { 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_admob_banner,
R.layout.ad_layout_max_banner R.layout.ad_layout_max_banner
) )
LogTag.LogD(TAG, "search onResume")
} }
private fun initView() { private fun initView() {
@ -162,9 +164,14 @@ class SearchFragment : MoBaseFragment<FragmentSearchBinding>(), TextWatcher,
when (it) { when (it) {
is Request.SearchSuggestions -> { is Request.SearchSuggestions -> {
val input = binding.searchEdit.text.toString().trim() val input = binding.searchEdit.text.toString().trim()
if (input.isNotEmpty()) {
Innertube.searchSuggestions(SearchSuggestionsBody(input = input)) Innertube.searchSuggestions(SearchSuggestionsBody(input = input))
?.onSuccess { suggestionsList -> ?.onSuccess { suggestionsList ->
LogTag.LogD(TAG, "suggestionsList->${suggestionsList?.size}") LogTag.LogD(
TAG,
"suggestionsList->${suggestionsList?.size}"
)
if(binding.searchEdit.text.toString().trim().isNotEmpty()){
if (suggestionsList != null) { if (suggestionsList != null) {
AnalysisUtil.logEvent(AnalysisUtil.SEARCH_SUG_SHOW) AnalysisUtil.logEvent(AnalysisUtil.SEARCH_SUG_SHOW)
showSearchSuggestions() showSearchSuggestions()
@ -174,13 +181,21 @@ class SearchFragment : MoBaseFragment<FragmentSearchBinding>(), TextWatcher,
} else { } else {
binding.searchSuggestionsLayout.visibility = View.GONE binding.searchSuggestionsLayout.visibility = View.GONE
} }
}else{
searchSuggestionsList.clear()
searchSuggestionsAdapterAdapter?.notifyDataSetChanged()
binding.searchSuggestionsLayout.visibility = View.GONE
}
}?.onFailure { error -> }?.onFailure { error ->
LogTag.LogD(TAG, "searchSuggestions onFailure->${error}") LogTag.LogD(TAG, "searchSuggestions onFailure->${error}")
binding.searchSuggestionsLayout.visibility = View.GONE binding.searchSuggestionsLayout.visibility = View.GONE
} }
} }
}
is Request.SearchData -> { is Request.SearchData -> {
val input = it.input
if (input.isNotEmpty()) {
AnalysisUtil.logEvent(AnalysisUtil.SEARCH_TRIGGER) AnalysisUtil.logEvent(AnalysisUtil.SEARCH_TRIGGER)
LolAdWrapper.shared.showAdTiming( LolAdWrapper.shared.showAdTiming(
requireActivity(), AdPlacement.INST_SEARCH requireActivity(), AdPlacement.INST_SEARCH
@ -188,8 +203,7 @@ class SearchFragment : MoBaseFragment<FragmentSearchBinding>(), TextWatcher,
showLoadingLayout() showLoadingLayout()
binding.contentLayout.removeAllViews() binding.contentLayout.removeAllViews()
binding.searchEdit.clearFocus() binding.searchEdit.clearFocus()
val input = it.input
if (input.isNotEmpty()) {
searchHistorySet.clear() searchHistorySet.clear()
searchHistorySet.addAll(appStore.searchHistoryStore) searchHistorySet.addAll(appStore.searchHistoryStore)
if (!appStore.searchHistoryStore.contains(input)) {//把不存在的记录保存到集合中 if (!appStore.searchHistoryStore.contains(input)) {//把不存在的记录保存到集合中
@ -223,7 +237,7 @@ class SearchFragment : MoBaseFragment<FragmentSearchBinding>(), TextWatcher,
}?.onFailure { }?.onFailure {
showNoContentLayout() showNoContentLayout()
} }
}
LolAdWrapper.shared.loadAdIfNotCached( LolAdWrapper.shared.loadAdIfNotCached(
requireActivity(), AdPlacement.INST_SEARCH 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) { override fun onHiddenChanged(hidden: Boolean) {
super.onHiddenChanged(hidden) super.onHiddenChanged(hidden)
LogTag.LogD(TAG, "search onHiddenChanged->$hidden")
if (!hidden) { if (!hidden) {
binding.searchEdit.requestFocus() binding.searchEdit.requestFocus()
showSearchHistory()
updateHistoryUi()
} else { } else {
binding.searchEdit.clearFocus() binding.searchEdit.clearFocus()
binding.searchEdit.text.clear() binding.searchEdit.text.clear()
@ -273,6 +299,12 @@ class SearchFragment : MoBaseFragment<FragmentSearchBinding>(), TextWatcher,
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}
override fun afterTextChanged(s: Editable?) {
requests.trySend(Request.SearchSuggestions)
if (s.isNullOrEmpty()) {//没有输入内容,隐藏删除按钮,展示历史记录,重新获取焦点弹出键盘。 if (s.isNullOrEmpty()) {//没有输入内容,隐藏删除按钮,展示历史记录,重新获取焦点弹出键盘。
binding.deleteInputBtn.visibility = View.GONE binding.deleteInputBtn.visibility = View.GONE
showSearchHistory() 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) { override fun onFocusChange(v: View?, hasFocus: Boolean) {
LogTag.LogD(TAG,"onFocusChange hasFocus->$hasFocus")
handler.postDelayed({ handler.postDelayed({
if (hasFocus) { if (hasFocus) {
showImm() showImm()

View File

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

View File

@ -38,6 +38,10 @@ object AnalysisUtil {
const val RATING_DIALOG_OK_CLICK = "rating_dialog_ok_click" const val RATING_DIALOG_OK_CLICK = "rating_dialog_ok_click"
const val RATING_DIALOG_CANCEL_CLICK = "rating_dialog_cancel_click" const val RATING_DIALOG_CANCEL_CLICK = "rating_dialog_cancel_click"
const val HOME_A_TO_B = "home_a_to_b" 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"//首页开屏广告展示成功 private const val AD_INST_SPLASH_SUCCESS = "ad_user_open_success"//首页开屏广告展示成功