diff --git a/app/build.gradle b/app/build.gradle index a737dec01..81307ef57 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,7 +44,10 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + + implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30' -// implementation project(path: ':nsfw') - implementation 'com.github.devzwy:open_nsfw_android:1.2.4' + implementation 'com.github.LuckSiege.PictureSelector:picture_library:v2.2.3' + implementation project(path: ':nsfw') +// implementation 'com.github.devzwy:open_nsfw_android:1.2.4' } diff --git a/app/debug/output.json b/app/debug/output.json deleted file mode 100644 index 92a078474..000000000 --- a/app/debug/output.json +++ /dev/null @@ -1 +0,0 @@ -[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"app-debug.apk","properties":{}}] \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ab5c79484..7df9728b5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ - + diff --git a/app/src/main/java/com/example/open_nsfw_android/MainActivity.kt b/app/src/main/java/com/example/open_nsfw_android/MainActivity.kt index c2fbe8e5a..15b62a3e4 100644 --- a/app/src/main/java/com/example/open_nsfw_android/MainActivity.kt +++ b/app/src/main/java/com/example/open_nsfw_android/MainActivity.kt @@ -1,45 +1,120 @@ package com.example.open_nsfw_android -import android.annotation.SuppressLint +import android.content.Intent import android.graphics.BitmapFactory import android.os.Bundle import android.support.v7.app.AppCompatActivity import android.support.v7.widget.LinearLayoutManager +import android.view.View +import com.luck.picture.lib.PictureSelector +import com.luck.picture.lib.config.PictureConfig +import com.luck.picture.lib.config.PictureMimeType +import com.luck.picture.lib.entity.LocalMedia import com.zwy.nsfw.api.NsfwHelper import kotlinx.android.synthetic.main.activity_main.* -class MainActivity : AppCompatActivity() { +class MainActivity : AppCompatActivity(), View.OnClickListener { + var nsfwHelper: NsfwHelper? = null var mainAdapter: MainAdapter? = null var index = 0 - val listData: ArrayList = ArrayList() - @SuppressLint("SetTextI18n") + var listData: ArrayList = ArrayList() + var selectList: List? = null + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - //assets 目录下的timg-10.jpeg为正常静态图片 ccc.gif 为动态正常图片 可用作测试 -// val b = BitmapFactory.decodeStream(resources.assets.open("img/06 (1).jpg")) -// iv.setImageBitmap(b) - nsfwHelper = NsfwHelper.getInstance(this, true, 1) + initNsfwHelper() + initAdapter() + initClickListener() + } + + override fun onClick(v: View) { + when (v.id) { + R.id.bt_sc_assets -> { + reScAssetsImgs() + } + R.id.bt_sc_from_other -> { + PictureSelector.create(this) + .openGallery(PictureMimeType.ofImage())//全部.ofAll()、图片.、视频.ofVideo()、音频.ofAudio() + .maxSelectNum(20)// 最大图片选择数量 int + .minSelectNum(1)// 最小选择数量 int + .imageSpanCount(3)// 每行显示个数 int + .selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选 or PictureConfig.SINGLE + .previewImage(true)// 是否可预览图片 true or false + .isCamera(false)// 是否显示拍照按钮 true or false + .isZoomAnim(true)// 图片列表点击 缩放效果 默认true + .selectionMedia(selectList) + .sizeMultiplier(0.5f)// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效 + .previewEggs(true)// 预览图片时 是否增强左右滑动图片体验(图片滑动一半即可看到上一张是否选中) true or false + .forResult(0x01);//结果回调onActivityResult code + } + } + } + + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (requestCode == 0x01 && resultCode == RESULT_OK) { + selectList = PictureSelector.obtainMultipleResult(data) + if (selectList != null && selectList?.size ?: 0 > 0) + reScFromImgs(selectList!!) + } + } + + + private fun initClickListener() { + bt_sc_assets.setOnClickListener(this) + bt_sc_from_other.setOnClickListener(this) + } + + private fun initAdapter() { mainAdapter = MainAdapter(null) rv.layoutManager = LinearLayoutManager(this) rv.adapter = mainAdapter - tv_start.setOnClickListener { - for (a in resources.assets.list("img")) { - val path = "img/${a}" - val b = BitmapFactory.decodeStream(resources.assets.open(path)) - listData.add(MyNsfwBean(0f, 0f, path, b)) - nsfwHelper?.scanBitmap(b) { sfw, nsfw -> + } + + private fun initNsfwHelper() { + nsfwHelper = NsfwHelper.getInstance(this, false, 1) + } + + private fun reScFromImgs(list: List) { + index = 0 + mainAdapter?.setNewData(null) + listData = ArrayList() + Thread(Runnable { + for (lm in list) { + val bitmap = BitmapFactory.decodeFile(lm.path) + listData.add(MyNsfwBean(0.0f, 0.0f, lm.path, bitmap)) + nsfwHelper?.scanBitmap(bitmap) { sfw, nsfw -> listData[index].sfw = sfw listData[index].nsfw = nsfw mainAdapter?.addData(listData[index]) mainAdapter?.notifyItemInserted(index) + rv.scrollToPosition(index) index++ } } + }).start() + } + private fun reScAssetsImgs() { + index = 0 + mainAdapter?.setNewData(null) + listData = ArrayList() + for (a in resources.assets.list("img")) { + val path = "img/${a}" + val b = BitmapFactory.decodeStream(resources.assets.open(path)) + listData.add(MyNsfwBean(0f, 0f, path, b)) + nsfwHelper?.scanBitmap(b) { sfw, nsfw -> + listData[index].sfw = sfw + listData[index].nsfw = nsfw + mainAdapter?.addData(listData[index]) + mainAdapter?.notifyItemInserted(index) + rv.scrollToPosition(index) + index++ + } } - } } diff --git a/app/src/main/java/com/example/open_nsfw_android/MainAdapter.kt b/app/src/main/java/com/example/open_nsfw_android/MainAdapter.kt index 3e40d90b1..cbedcdb4f 100644 --- a/app/src/main/java/com/example/open_nsfw_android/MainAdapter.kt +++ b/app/src/main/java/com/example/open_nsfw_android/MainAdapter.kt @@ -8,7 +8,7 @@ import android.widget.TextView import com.chad.library.adapter.base.BaseQuickAdapter import com.chad.library.adapter.base.BaseViewHolder -class MainAdapter(val nsfwList: List?) : +class MainAdapter(nsfwList: List?) : BaseQuickAdapter(R.layout.main_item, nsfwList) { @SuppressLint("SetTextI18n") @@ -17,15 +17,15 @@ class MainAdapter(val nsfwList: List?) : val imageView = helper.getView(R.id.iv) val view = helper.getView(R.id.view) var nsfwStr = "色情图片" - var color = ContextCompat.getColor(mContext,R.color.nsfw1) + var color = ContextCompat.getColor(mContext, R.color.nsfw1) when (item.nsfw) { in 0.0..0.3 -> { nsfwStr = "正常图片" - color = ContextCompat.getColor(mContext,R.color.nsfw3) + color = ContextCompat.getColor(mContext, R.color.nsfw3) } - in 0.3..0.7 -> { + in 0.3..0.6 -> { nsfwStr = "👙比基尼" - color = ContextCompat.getColor(mContext,R.color.nsfw2) + color = ContextCompat.getColor(mContext, R.color.nsfw2) } } textView.text = diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 67a45de1b..90b0513ad 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,13 +4,26 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> - + +