diff --git a/.gradle/7.3.3/executionHistory/executionHistory.bin b/.gradle/7.3.3/executionHistory/executionHistory.bin index 3f94c23..fa9a3e6 100644 Binary files a/.gradle/7.3.3/executionHistory/executionHistory.bin and b/.gradle/7.3.3/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.3.3/executionHistory/executionHistory.lock b/.gradle/7.3.3/executionHistory/executionHistory.lock index 04d14e2..35e11bd 100644 Binary files a/.gradle/7.3.3/executionHistory/executionHistory.lock and b/.gradle/7.3.3/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.3.3/fileHashes/fileHashes.bin b/.gradle/7.3.3/fileHashes/fileHashes.bin index 9fce00f..1706402 100644 Binary files a/.gradle/7.3.3/fileHashes/fileHashes.bin and b/.gradle/7.3.3/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.3.3/fileHashes/fileHashes.lock b/.gradle/7.3.3/fileHashes/fileHashes.lock index 7845182..661534d 100644 Binary files a/.gradle/7.3.3/fileHashes/fileHashes.lock and b/.gradle/7.3.3/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.3.3/fileHashes/resourceHashesCache.bin b/.gradle/7.3.3/fileHashes/resourceHashesCache.bin index 3d46778..63f4063 100644 Binary files a/.gradle/7.3.3/fileHashes/resourceHashesCache.bin and b/.gradle/7.3.3/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 308d0cb..2c42843 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index be54974..5abb8ea 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index cc5b7fc..b7d277c 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index aed6cf9..285cdd1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,6 +11,7 @@ android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" /> + + + + android:exported="false" + android:screenOrientation="portrait" /> + android:exported="false" + android:screenOrientation="portrait" /> + android:label="@string/built_in_browser" + android:screenOrientation="portrait" /> - - () { /** * 初始化搜索项目事件 */ - private fun initSearchItem(newSearchView: SearchView) { - val navigationIcon = viewBinding.toolbar.navigationIcon - var oldTile: CharSequence = viewBinding.toolbar.title - val hideView: (collapsed: Boolean) -> Unit = { - if (it) { - newSearchView.onActionViewCollapsed() - } - viewBinding.toolbar.navigationIcon = navigationIcon - viewBinding.toolbar.title = oldTile - } - newSearchView.queryHint = getString(R.string.search_hint) - newSearchView.setOnCloseListener { - hideView.invoke(false) - return@setOnCloseListener false - } - newSearchView.setOnSearchClickListener { - oldTile = viewBinding.toolbar.title - viewBinding.toolbar.navigationIcon = null - viewBinding.toolbar.title = getString(R.string.search) - } - - newSearchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { - override fun onQueryTextSubmit(query: String?): Boolean { - hideView.invoke(true) - val key = query - if (key != null) { - val goIntent = Intent(this@MainActivity, SearchActivity::class.java) - goIntent.putExtra("key", key) - startActivity(goIntent) - } - return false - } - - override fun onQueryTextChange(newText: String?): Boolean { - return false - } - - }) - searchView = newSearchView - } +// private fun initSearchItem(newSearchView: SearchView) { +// val navigationIcon = viewBinding.toolbar.navigationIcon +// var oldTile: CharSequence = viewBinding.toolbar.title +// val hideView: (collapsed: Boolean) -> Unit = { +// if (it) { +// newSearchView.onActionViewCollapsed() +// } +// viewBinding.toolbar.navigationIcon = navigationIcon +// viewBinding.toolbar.title = oldTile +// } +// newSearchView.queryHint = getString(R.string.search_hint) +// newSearchView.setOnCloseListener { +// hideView.invoke(false) +// return@setOnCloseListener false +// } +// newSearchView.setOnSearchClickListener { +// oldTile = viewBinding.toolbar.title +// viewBinding.toolbar.navigationIcon = null +// viewBinding.toolbar.title = getString(R.string.search) +// } +// +// newSearchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { +// override fun onQueryTextSubmit(query: String?): Boolean { +// hideView.invoke(true) +// val key = query +// if (key != null) { +// val goIntent = Intent(this@MainActivity, SearchResultActivity::class.java) +// goIntent.putExtra("key", key) +// startActivity(goIntent) +// } +// return false +// } +// +// override fun onQueryTextChange(newText: String?): Boolean { +// return false +// } +// +// }) +// searchView = newSearchView +// } /** * 导入模板 @@ -643,8 +642,8 @@ class MainActivity : BaseActivity() { override fun onCreateOptionsMenu(menu: Menu): Boolean { val inflater = menuInflater inflater.inflate(R.menu.menu_main, menu) - val searchView = menu.findItem(R.id.app_bar_search).actionView as SearchView - initSearchItem(searchView) +// val searchView = menu.findItem(R.id.app_bar_search).actionView as SearchView +// initSearchItem(searchView) return true } @@ -655,6 +654,9 @@ class MainActivity : BaseActivity() { } override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (item.itemId == R.id.search) { + startActivity(Intent(this, SearchActivity::class.java)) + } return false } @@ -693,8 +695,8 @@ class MainActivity : BaseActivity() { ) ) }.setNegativeButton(R.string.dialog_close) { - finish() - }.setCancelable(false).show() + finish() + }.setCancelable(false).show() } else { showGameConfiguredDialog() } diff --git a/app/src/main/java/com/coldmint/rust/pro/ReleaseModActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ReleaseModActivity.kt index 329f4dd..5801335 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ReleaseModActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ReleaseModActivity.kt @@ -866,7 +866,7 @@ class ReleaseModActivity : BaseActivity() { .positiveButton(R.string.dialog_ok).cancelable(false) } WebMod.instance.releaseMod(appSettings.getValue(AppSettings.Setting.AppID, ""), modId, - account, + appSettings.getValue(AppSettings.Setting.Token, ""), modName, modDescribe, tagsBuilder.toString(), diff --git a/app/src/main/java/com/coldmint/rust/pro/ReviewModActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ReviewModActivity.kt index 11b8d78..e327115 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ReviewModActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ReviewModActivity.kt @@ -22,15 +22,15 @@ import com.google.android.material.snackbar.Snackbar * @date 2022/1/9 16:50 */ class ReviewModActivity : BaseActivity() { - val account: String by lazy { - appSettings.getValue(AppSettings.Setting.Account, "") + val token by lazy { + AppSettings.getInstance(this).getValue(AppSettings.Setting.Token, "") } override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { if (canUseView) { viewBinding.toolbar.title = getText(R.string.review_mod) setReturnButton() - if (account.isBlank()) { + if (token.isBlank()) { showInfoToView(resId = R.string.please_login_first) return } @@ -65,7 +65,7 @@ class ReviewModActivity : BaseActivity() { } itemAuditModBinding.consentView.setOnClickListener { WebMod.instance.auditMod( - account, + token, data.id, true, object : ApiCallBack { @@ -93,8 +93,9 @@ class ReviewModActivity : BaseActivity() { }) } itemAuditModBinding.refusedView.setOnClickListener { + WebMod.instance.auditMod( - account, + token, data.id, false, object : ApiCallBack { diff --git a/app/src/main/java/com/coldmint/rust/pro/SearchActivity.kt b/app/src/main/java/com/coldmint/rust/pro/SearchActivity.kt index 515d994..e67eb2b 100644 --- a/app/src/main/java/com/coldmint/rust/pro/SearchActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/SearchActivity.kt @@ -1,85 +1,84 @@ package com.coldmint.rust.pro +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import androidx.appcompat.widget.SearchView import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager -import com.coldmint.rust.core.dataBean.SearchResultDataBean +import com.coldmint.rust.core.dataBean.SearchSuggestionsData import com.coldmint.rust.core.interfaces.ApiCallBack import com.coldmint.rust.core.web.Search -import com.coldmint.rust.core.web.ServerConfiguration -import com.coldmint.rust.pro.adapters.SearchResultAdapter +import com.coldmint.rust.pro.adapters.SearchSuggestionsAdapter import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.databinding.ActivitySearchBinding /** - * 搜索activity + * 搜索界面 */ class SearchActivity : BaseActivity() { - lateinit var keyWord: String override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { - if (canUseView) { - setReturnButton() - loadData(keyWord) - title = String.format(getString(R.string.search_mod_key), keyWord) - viewBinding.recyclerView.layoutManager = LinearLayoutManager(this) - } else { - val thisIntent = intent - val key = thisIntent.getStringExtra("key") - if (key == null) { - showError("key为null") - return - } - keyWord = key - } - } + title = getString(R.string.search) + setReturnButton() + viewBinding.recyclerView.layoutManager = LinearLayoutManager(this) - /** - * 加载数据 - * @param keyWord String - */ - fun loadData(keyWord: String) { - Search.instance.searchAll(keyWord, object : ApiCallBack { - override fun onResponse(t: SearchResultDataBean) { - if (t.code == ServerConfiguration.Success_Code) { - val list = t.data - if (list != null && list.isNotEmpty()) { - val adapter = SearchResultAdapter(this@SearchActivity, keyWord, list) - viewBinding.progressBar.isVisible = false - viewBinding.tipView.isVisible = false - viewBinding.recyclerView.isVisible = true - viewBinding.recyclerView.adapter = adapter - title = String.format( - getString(R.string.search_mod_key), - keyWord - ) + "(" + list.size + ")" - } else { - showInfoToView(t.message) - } - } else { - showInfoToView(t.message) + viewBinding.searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener, + android.widget.SearchView.OnQueryTextListener { + override fun onQueryTextSubmit(query: String?): Boolean { + if (query != null && query.isNotBlank()) { + val intent = Intent(this@SearchActivity, SearchResultActivity::class.java) + intent.putExtra("key", query) + startActivity(intent) } + return true } - override fun onFailure(e: Exception) { - showInfoToView(this@SearchActivity.getString(R.string.network_error)) + override fun onQueryTextChange(newText: String?): Boolean { + if (newText != null && newText.isNotBlank()) { + Search.instance.suggestions(newText, + object : ApiCallBack { + override fun onResponse(t: SearchSuggestionsData) { + val dataList = t.data + if (dataList.isNullOrEmpty()) { + viewBinding.recyclerView.isVisible = false + } else { + val adapter = + SearchSuggestionsAdapter( + this@SearchActivity, + newText, + dataList + ) + adapter.setItemEvent { i, itemSearchSuggestionsBinding, viewHolder, s -> + itemSearchSuggestionsBinding.root.setOnClickListener { + val intent = Intent( + this@SearchActivity, + SearchResultActivity::class.java + ) + intent.putExtra("key", s) + startActivity(intent) + } + } + viewBinding.recyclerView.adapter = adapter + viewBinding.recyclerView.isVisible = true + } + } + + override fun onFailure(e: Exception) { + viewBinding.recyclerView.isVisible = false + } + + }) + } else { + viewBinding.recyclerView.isVisible = false + } + return true } }) } - /** - * 显示信息到视图 - * @param text String - */ - fun showInfoToView(text: String) { - viewBinding.tipView.isVisible = true - viewBinding.tipView.text = text - viewBinding.progressBar.isVisible = false - viewBinding.recyclerView.isVisible = false - } - - override fun getViewBindingObject(): ActivitySearchBinding { return ActivitySearchBinding.inflate(layoutInflater) } + } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/SearchResultActivity.kt b/app/src/main/java/com/coldmint/rust/pro/SearchResultActivity.kt new file mode 100644 index 0000000..d30dc44 --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/SearchResultActivity.kt @@ -0,0 +1,109 @@ +package com.coldmint.rust.pro + +import android.os.Bundle +import androidx.core.view.isVisible +import com.coldmint.rust.core.dataBean.user.SearchResultDataBean +import com.coldmint.rust.core.interfaces.ApiCallBack +import com.coldmint.rust.core.web.Search +import com.coldmint.rust.core.web.ServerConfiguration +import com.coldmint.rust.pro.adapters.SearchPageAdapter +import com.coldmint.rust.pro.base.BaseActivity +import com.coldmint.rust.pro.databinding.ActivitySearchResultBinding +import com.google.android.material.tabs.TabLayoutMediator + +/** + * 搜索activity + */ +class SearchResultActivity : BaseActivity() { + lateinit var keyWord: String + val typeMap by lazy { + val map = HashMap() + map["mod"] = R.string.search_type_mod + map["user"] = R.string.search_type_user + map["dynamic"] = R.string.search_type_dynamic + map["mod_comments"] = R.string.search_type_mod_comments + map["mod_versions"] = R.string.search_type_mod_versions + map["purchase_plan"] = R.string.search_type_purchase_plan + map + } + + override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { + if (canUseView) { + setReturnButton() + loadData(keyWord) + title = String.format(getString(R.string.search_mod_key), keyWord) + } else { + val thisIntent = intent + val key = thisIntent.getStringExtra("key") + if (key == null) { + showError("key为null") + return + } + keyWord = key + } + } + + /** + * 加载数据 + * @param keyWord String + */ + fun loadData(keyWord: String) { + Search.instance.searchAll(keyWord, object : ApiCallBack { + override fun onResponse(t: SearchResultDataBean) { + if (t.code == ServerConfiguration.Success_Code) { + val list = t.data.total + if (list.isNotEmpty()) { + val adapter = SearchPageAdapter(this@SearchResultActivity, keyWord, t.data) + viewBinding.viewPager2.adapter = adapter + TabLayoutMediator(viewBinding.tabLayout, viewBinding.viewPager2) { tab, i -> + tab.text = if (i == 0) { + getString(R.string.search_type_mod_all) + "(" + t.data.total.size + ")" + } else { + val typeData = t.data.type[i - 1] + val id = typeMap[typeData.typeName] ?: -1 + val name = if (id == -1) { + typeData.typeName + } else { + getString(id) + } + name + "(" + typeData.num + ")" + } + }.attach() + viewBinding.progressBar.isVisible = false + viewBinding.tipView.isVisible = false + viewBinding.contentLayout.isVisible = true + title = String.format( + getString(R.string.search_mod_key), + keyWord + ) + } else { + showInfoToView(t.message) + } + } else { + showInfoToView(t.message) + } + } + + override fun onFailure(e: Exception) { + showInfoToView(this@SearchResultActivity.getString(R.string.network_error)) + } + + }) + } + + /** + * 显示信息到视图 + * @param text String + */ + fun showInfoToView(text: String) { + viewBinding.tipView.isVisible = true + viewBinding.tipView.text = text + viewBinding.progressBar.isVisible = false + viewBinding.contentLayout.isVisible = false + } + + + override fun getViewBindingObject(): ActivitySearchResultBinding { + return ActivitySearchResultBinding.inflate(layoutInflater) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt b/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt index 4d99340..175d88d 100644 --- a/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt @@ -68,8 +68,8 @@ class WebModInfoActivity : BaseActivity() { val modFilePath = "$modFolderPath$modId.rwmod" File(modFilePath) } - val account by lazy { - appSettings.getValue(AppSettings.Setting.Account, "") + val token by lazy { + appSettings.getValue(AppSettings.Setting.Token, "") } var developer: String? = null @@ -105,7 +105,7 @@ class WebModInfoActivity : BaseActivity() { private fun initData() { - if (account.isBlank()) { + if (token.isBlank()) { viewBinding.progressBar.isVisible = false viewBinding.tipView.isVisible = true viewBinding.tipView.setText(R.string.please_login_first) @@ -115,7 +115,7 @@ class WebModInfoActivity : BaseActivity() { loadModCommentList(modId) - WebMod.instance.getInfo(account, modId, object : ApiCallBack { + WebMod.instance.getInfo(token, modId, object : ApiCallBack { override fun onResponse(t: WebModInfoData) { if (t.code == ServerConfiguration.Success_Code) { developer = t.data.developer @@ -287,26 +287,13 @@ class WebModInfoActivity : BaseActivity() { when (item.itemId) { R.id.report_item -> { if (isOpen) { - //不能举报自己的模组 - if (developer != null && developer == account) { - Snackbar.make( - viewBinding.button, - R.string.unable_to_report2, - Snackbar.LENGTH_SHORT - ).setAction(R.string.open) { - val gotoIntent = - Intent(this, WorkManagementActivity::class.java) - startActivity(gotoIntent) - }.show() - } else { - val thisIntent = Intent(this, ReportActivity::class.java) - val bundle = Bundle() - bundle.putString("target", modId) - bundle.putString("type", "mod") - bundle.putString("name", viewBinding.titleView.text.toString()) - thisIntent.putExtra("data", bundle) - startActivity(thisIntent) - } + val thisIntent = Intent(this, ReportActivity::class.java) + val bundle = Bundle() + bundle.putString("target", modId) + bundle.putString("type", "mod") + bundle.putString("name", viewBinding.titleView.text.toString()) + thisIntent.putExtra("data", bundle) + startActivity(thisIntent) } else { //不能举报未公开的模组 Snackbar.make( @@ -492,8 +479,7 @@ class WebModInfoActivity : BaseActivity() { val text = inputField.text.toString() if (!text.isBlank()) { WebMod.instance.sendComment( - account, - appSettings.getValue(AppSettings.Setting.AppID, ""), + appSettings.getValue(AppSettings.Setting.Token, ""), modId, text, object : ApiCallBack { diff --git a/app/src/main/java/com/coldmint/rust/pro/WorkManagementActivity.kt b/app/src/main/java/com/coldmint/rust/pro/WorkManagementActivity.kt index fd21b0a..eae6a4f 100644 --- a/app/src/main/java/com/coldmint/rust/pro/WorkManagementActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/WorkManagementActivity.kt @@ -175,7 +175,11 @@ class WorkManagementActivity : BaseActivity() { .positiveButton(R.string.dialog_ok) .positiveButton { WebMod.instance.afreshAuditMod( - data.developer, + AppSettings.getInstance(this@WorkManagementActivity) + .getValue( + AppSettings.Setting.Token, + "" + ), data.id, object : ApiCallBack { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/SearchPageAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/SearchPageAdapter.kt new file mode 100644 index 0000000..7a78521 --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/SearchPageAdapter.kt @@ -0,0 +1,29 @@ +package com.coldmint.rust.pro.adapters + +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentActivity +import androidx.viewpager2.adapter.FragmentStateAdapter +import com.coldmint.rust.core.dataBean.user.SearchResultDataBean +import com.coldmint.rust.pro.fragments.SearchResultFragment + +class SearchPageAdapter( + fragmentActivity: FragmentActivity, val keyword: String, + val data: SearchResultDataBean.Data +) : FragmentStateAdapter(fragmentActivity) { + + + override fun getItemCount(): Int { + return data.type.size + 1 + } + + override fun createFragment(position: Int): Fragment { + val typeName = if (position == 0) { + "all" + } else { + data.type[position - 1].typeName + } + return SearchResultFragment(keyword, data, typeName) + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/SearchResultAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/SearchResultAdapter.kt index 49d2b54..30520e7 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/SearchResultAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/SearchResultAdapter.kt @@ -2,26 +2,17 @@ package com.coldmint.rust.pro.adapters import android.content.Context import android.content.Intent -import android.graphics.Color -import android.graphics.Typeface import android.os.Bundle -import android.text.SpannableStringBuilder -import android.text.Spanned -import android.text.style.ForegroundColorSpan -import android.text.style.StyleSpan import android.view.LayoutInflater import android.view.ViewGroup -import android.widget.Toast import androidx.core.view.isVisible import com.bumptech.glide.Glide -import com.bumptech.glide.request.RequestOptions -import com.coldmint.rust.core.dataBean.SearchResultDataBean +import com.coldmint.rust.core.dataBean.user.SearchResultDataBean import com.coldmint.rust.core.web.ServerConfiguration import com.coldmint.rust.pro.UserHomePageActivity import com.coldmint.rust.pro.WebModInfoActivity import com.coldmint.rust.pro.base.BaseAdapter import com.coldmint.rust.pro.databinding.ItemSearchResultBinding -import com.coldmint.rust.pro.edit.RustAutoComplete2 import com.coldmint.rust.pro.tool.GlobalMethod import com.coldmint.rust.pro.tool.TextStyleMaker import java.util.* @@ -35,9 +26,9 @@ import java.util.* class SearchResultAdapter( val context: Context, val keyWord: String, - dataList: MutableList + dataList: MutableList ) : - BaseAdapter(context, dataList) { + BaseAdapter(context, dataList) { override fun getViewBindingObject( @@ -49,7 +40,7 @@ class SearchResultAdapter( } override fun onBingView( - data: SearchResultDataBean.Data, + data: SearchResultDataBean.Data.Total, viewBinding: ItemSearchResultBinding, viewHolder: ViewHolder, position: Int diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/SearchSuggestionsAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/SearchSuggestionsAdapter.kt new file mode 100644 index 0000000..77c7e5b --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/SearchSuggestionsAdapter.kt @@ -0,0 +1,35 @@ +package com.coldmint.rust.pro.adapters + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import com.coldmint.rust.pro.base.BaseAdapter +import com.coldmint.rust.pro.databinding.ItemSearchSuggestionsBinding + +/** + * 搜索建议适配器 + * @constructor + */ +class SearchSuggestionsAdapter( + context: Context, + val keyword: String, + dataList: MutableList +) : + BaseAdapter(context, dataList) { + override fun getViewBindingObject( + layoutInflater: LayoutInflater, + parent: ViewGroup, + viewType: Int + ): ItemSearchSuggestionsBinding { + return ItemSearchSuggestionsBinding.inflate(layoutInflater, parent, false) + } + + override fun onBingView( + data: String, + viewBinding: ItemSearchSuggestionsBinding, + viewHolder: ViewHolder, + position: Int + ) { + viewBinding.titleView.text = createSpannableString(data,keyword) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/base/BaseAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/base/BaseAdapter.kt index a1b5203..cb4f147 100644 --- a/app/src/main/java/com/coldmint/rust/pro/base/BaseAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/base/BaseAdapter.kt @@ -37,7 +37,7 @@ abstract class BaseAdapter( Handler(Looper.getMainLooper()) } private val spannableStringBuilder: SpannableStringBuilder = SpannableStringBuilder() - private val colorSpan: ForegroundColorSpan = ForegroundColorSpan(Color.parseColor("#2196F3")) + private val colorSpan: ForegroundColorSpan = ForegroundColorSpan(Color.parseColor("#e91e63")) private val bold = StyleSpan(Typeface.BOLD) diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/SearchResultFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/SearchResultFragment.kt new file mode 100644 index 0000000..7f018d8 --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/SearchResultFragment.kt @@ -0,0 +1,50 @@ +package com.coldmint.rust.pro.fragments + +import android.os.Bundle +import android.view.LayoutInflater +import androidx.recyclerview.widget.LinearLayoutManager +import com.coldmint.rust.core.dataBean.user.SearchResultDataBean +import com.coldmint.rust.pro.adapters.SearchResultAdapter +import com.coldmint.rust.pro.base.BaseFragment +import com.coldmint.rust.pro.databinding.FragmentSearchResultBinding + +/** + * 搜索结果碎片 + * @property keyword String + * @property dataList MutableList + * @constructor + */ +class SearchResultFragment( + val keyword: String, + val data: SearchResultDataBean.Data, + val typeName: String +) : + BaseFragment() { + override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { + + val adapter = SearchResultAdapter(requireContext(), keyword, filterList()) + viewBinding.recyclerView.adapter = adapter + viewBinding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) + } + + /** + * 过滤列表(为all返回所有) + * @return MutableList + */ + fun filterList(): MutableList { + if (typeName == "all") { + return data.total + } + val list = ArrayList() + data.total.forEach { + if (it.type == typeName) { + list.add(it) + } + } + return list + } + + override fun getViewBindingObject(): FragmentSearchResultBinding { + return FragmentSearchResultBinding.inflate(layoutInflater) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt index c0e31b3..689b759 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt @@ -21,6 +21,7 @@ import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.GlobalMethod class UserInfoFragment : BaseFragment() { + lateinit var token: String lateinit var account: String /** @@ -103,8 +104,8 @@ class UserInfoFragment : BaseFragment() { override fun onResume() { super.onResume() - if (account.isNotBlank()) { - User.getUserActivationInfo(account, object : ApiCallBack { + if (token.isNotBlank()) { + User.getUserActivationInfo(token, object : ApiCallBack { override fun onFailure(e: Exception) { @@ -127,9 +128,8 @@ class UserInfoFragment : BaseFragment() { } loadRecyclerView(t.data.permission) } else { - viewBinding.nameView.text = account + viewBinding.nameView.text = t.data.userName loadRecyclerView(3) -// viewBinding.expirationTimeView.text = t.message } } @@ -138,6 +138,7 @@ class UserInfoFragment : BaseFragment() { } override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { + token = appSettings.getValue(AppSettings.Setting.Token, "") account = appSettings.getValue(AppSettings.Setting.Account, "") viewBinding.myHomeView.setOnClickListener { val intent = Intent( diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml index 49eca38..7c47b21 100644 --- a/app/src/main/res/layout/activity_search.xml +++ b/app/src/main/res/layout/activity_search.xml @@ -6,7 +6,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" - tools:context=".OrderListActivity"> + tools:context=".ActivateActivity"> - - - - - - - + android:layout_height="wrap_content" + android:layout_margin="8dp"> + + + + + + - - \ No newline at end of file + + + + + + + + diff --git a/app/src/main/res/layout/activity_search_result.xml b/app/src/main/res/layout/activity_search_result.xml new file mode 100644 index 0000000..ff90397 --- /dev/null +++ b/app/src/main/res/layout/activity_search_result.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_search_result.xml b/app/src/main/res/layout/fragment_search_result.xml new file mode 100644 index 0000000..678b206 --- /dev/null +++ b/app/src/main/res/layout/fragment_search_result.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_search_result.xml b/app/src/main/res/layout/item_search_result.xml index 4ce65de..e9086c9 100644 --- a/app/src/main/res/layout/item_search_result.xml +++ b/app/src/main/res/layout/item_search_result.xml @@ -1,18 +1,17 @@ - + android:layout_margin="8dp"> + android:padding="16dp"> + android:layout_marginStart="8dp" + android:layout_toEndOf="@id/imageView" + android:text="@string/mod_title" /> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/item_search_suggestions.xml b/app/src/main/res/layout/item_search_suggestions.xml new file mode 100644 index 0000000..0daa04f --- /dev/null +++ b/app/src/main/res/layout/item_search_suggestions.xml @@ -0,0 +1,27 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index 5844687..e8f963e 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -4,8 +4,7 @@ + android:title="@string/search" /> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4935b39..79f9d06 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -846,4 +846,12 @@ 跟随设备壁纸更换主题色。 此设备不支持动态颜色。 标题 + 模组 + 用户 + 动态 + 模组评论 + 模组更新日志 + 套餐 + 全部 + \ No newline at end of file diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/SearchResultDataBean.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/SearchResultDataBean.kt deleted file mode 100644 index 5bf4e65..0000000 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/SearchResultDataBean.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.coldmint.rust.core.dataBean - - -import com.google.gson.annotations.SerializedName - -/** - * 搜索记录 - * @property code Int - * @property `data` List - * @property message String - * @constructor - */ -data class SearchResultDataBean( - @SerializedName("code") - val code: Int, - @SerializedName("data") - val `data`: MutableList?, - @SerializedName("message") - val message: String -) { - data class Data( - @SerializedName("content") - val content: String, - @SerializedName("icon") - val icon: String?, - @SerializedName("id") - val id: String, - @SerializedName("title") - val title: String, - @SerializedName("type") - val type: String - ) -} \ No newline at end of file diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/SearchSuggestionsData.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/SearchSuggestionsData.kt new file mode 100644 index 0000000..185b15f --- /dev/null +++ b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/SearchSuggestionsData.kt @@ -0,0 +1,20 @@ +package com.coldmint.rust.core.dataBean + + +import com.google.gson.annotations.SerializedName + +/** + * 搜索建议 + * @property code Int + * @property `data` List + * @property message String + * @constructor + */ +data class SearchSuggestionsData( + @SerializedName("code") + val code: Int, + @SerializedName("data") + val `data`: MutableList, + @SerializedName("message") + val message: String +) \ No newline at end of file diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/user/SearchResultDataBean.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/user/SearchResultDataBean.kt new file mode 100644 index 0000000..b8dc71c --- /dev/null +++ b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/dataBean/user/SearchResultDataBean.kt @@ -0,0 +1,40 @@ +package com.coldmint.rust.core.dataBean.user + + +import com.google.gson.annotations.SerializedName + +data class SearchResultDataBean( + @SerializedName("code") + val code: Int, + @SerializedName("data") + val `data`: Data, + @SerializedName("message") + val message: String +) { + data class Data( + @SerializedName("total") + val total: MutableList, + @SerializedName("type") + val type: List + ) { + data class Total( + @SerializedName("content") + val content: String, + @SerializedName("icon") + val icon: String?, + @SerializedName("id") + val id: String, + @SerializedName("title") + val title: String, + @SerializedName("type") + val type: String + ) + + data class Type( + @SerializedName("num") + val num: Int, + @SerializedName("typeName") + val typeName: String + ) + } +} \ No newline at end of file diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/Search.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/Search.kt index 6e35dd6..86aa2bc 100644 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/Search.kt +++ b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/Search.kt @@ -2,8 +2,8 @@ package com.coldmint.rust.core.web import android.os.Handler import android.os.Looper -import com.coldmint.rust.core.dataBean.SearchResultDataBean -import com.coldmint.rust.core.dataBean.mod.WebModListData +import com.coldmint.rust.core.dataBean.SearchSuggestionsData +import com.coldmint.rust.core.dataBean.user.SearchResultDataBean import com.coldmint.rust.core.interfaces.ApiCallBack import com.google.gson.Gson import okhttp3.* @@ -59,4 +59,46 @@ class Search private constructor() { }) } + /** + * 搜索建议 + * @param key String 关键字 + * @param apiCallBack ApiCallBack + */ + fun suggestions(key: String, apiCallBack: ApiCallBack) { + val okHttpClient = ServerConfiguration.initOkHttpClient() + val requestBodyBuilder: FormBody.Builder = + FormBody.Builder().add("key", key) + val requestBody = requestBodyBuilder.build() + val request = + Request.Builder() + .url(ServerConfiguration.website + "php/search.php?action=suggestions") + .post(requestBody).build() + val call = okHttpClient.newCall(request) + val handler = Handler(Looper.getMainLooper()) + val gson = Gson() + call.enqueue(object : Callback { + override fun onFailure(call: Call, e: IOException) { + e.printStackTrace() + handler.post { apiCallBack.onFailure(e) } + } + + override fun onResponse(call: Call, response: Response) { + try { + val data = response.body!!.string() + val finalSearchSuggestionsData = + gson.fromJson(data, SearchSuggestionsData::class.java) + handler.post { + apiCallBack.onResponse(finalSearchSuggestionsData) + } + } catch (e: Exception) { + e.printStackTrace() + handler.post { + apiCallBack.onFailure(e) + } + } + } + + }) + } + } \ No newline at end of file diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/WebMod.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/WebMod.kt index 03e59d0..61bc020 100644 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/WebMod.kt +++ b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/WebMod.kt @@ -190,20 +190,20 @@ class WebMod private constructor() { //audit /** * 审核模组 - * @param account String 账号(管理员) + * @param token String 令牌(管理员) * @param modId String 模组id * @param state Boolean 通过状态 * @param apiCallBack ApiCallBack 回调接口 */ fun auditMod( - account: String, + token: String, modId: String, state: Boolean, apiCallBack: ApiCallBack ) { val okHttpClient = ServerConfiguration.initOkHttpClient() val requestBodyBuilder: FormBody.Builder = - FormBody.Builder().add("account", account).add("modId", modId) + FormBody.Builder().add("token", token).add("modId", modId) .add("state", state.toString()) val requestBody = requestBodyBuilder.build() val request = @@ -239,14 +239,14 @@ class WebMod private constructor() { /** * 重新审核模组 - * @param account String 账号 + * @param token String 令牌 * @param modId String 模组id * @param apiCallBack ApiCallBack 回调接口 */ - fun afreshAuditMod(account: String, modId: String, apiCallBack: ApiCallBack) { + fun afreshAuditMod(token: String, modId: String, apiCallBack: ApiCallBack) { val okHttpClient = ServerConfiguration.initOkHttpClient() val requestBodyBuilder: FormBody.Builder = - FormBody.Builder().add("account", account).add("modId", modId) + FormBody.Builder().add("token", token).add("modId", modId) val requestBody = requestBodyBuilder.build() val request = Request.Builder() @@ -515,22 +515,20 @@ class WebMod private constructor() { /** * 发布评论 - * @param account String 账号 - * @param appId String appid + * @param token String token * @param modId String 模组id * @param content String 评论内容 * @param apiCallBack ApiCallBack 结果 */ fun sendComment( - account: String, - appId: String, + token: String, modId: String, content: String, apiCallBack: ApiCallBack ) { val okHttpClient = ServerConfiguration.initOkHttpClient() val requestBody: FormBody = - FormBody.Builder().add("account", account).add("appId", appId).add("modId", modId) + FormBody.Builder().add("token", token).add("modId", modId) .add("content", content).build() val request = Request.Builder().url(ServerConfiguration.website + "php/mod.php?action=comments") @@ -565,13 +563,13 @@ class WebMod private constructor() { /** * 查看模组信息 - * @param account String 账号 + * @param token String 令牌 * @param modId String 模组Id */ - fun getInfo(account: String, modId: String, apiCallBack: ApiCallBack) { + fun getInfo(token: String, modId: String, apiCallBack: ApiCallBack) { val okHttpClient = ServerConfiguration.initOkHttpClient() val requestBody: FormBody = - FormBody.Builder().add("account", account).add("modId", modId).build() + FormBody.Builder().add("token", token).add("modId", modId).build() val request = Request.Builder().url(ServerConfiguration.website + "php/mod.php?action=getInfo") .post(requestBody).build() @@ -587,6 +585,7 @@ class WebMod private constructor() { override fun onResponse(call: Call, response: Response) { try { val data = response.body!!.string() + Log.d("模组信息",data) val finalWebModInfoData = gson.fromJson(data, WebModInfoData::class.java) handler.post { @@ -871,7 +870,7 @@ class WebMod private constructor() { /** * 发布模组 - * @param account String 账号 + * @param token String 账号 * @param modName String 模组名称 * @param describe String 描述 * @param tags String 标签 @@ -881,7 +880,7 @@ class WebMod private constructor() { fun releaseMod( appId: String, modId: String, - account: String, + token: String, modName: String, describe: String, tags: String, @@ -896,7 +895,7 @@ class WebMod private constructor() { val builder = MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("appID", appId) .addFormDataPart("modId", modId) - .addFormDataPart("account", account).addFormDataPart("modName", modName) + .addFormDataPart("token", token).addFormDataPart("modName", modName) .addFormDataPart("describe", describe).addFormDataPart("tags", tags) .addFormDataPart("versionName", versionName) .addFormDataPart("unitNumber", unitNum.toString()) @@ -958,6 +957,7 @@ class WebMod private constructor() { val body = response.body if (body != null) { val data = body.string() + Log.d("发布模组响应",data) val finalApiResponse = gson.fromJson(data, ApiResponse::class.java) handler.post { apiCallBack.onResponse(finalApiResponse)