浏览代码

1.添加查看大图

石慧云 4 年之前
父节点
当前提交
fa56e01b3c

+ 2 - 0
app/build.gradle

@@ -119,6 +119,8 @@ dependencies {
     addComponent 'umeng'
     addComponent 'jpush'
     addComponent 'gaode'
+    addComponent 'lookimg'
+
 
     //微信sdk
     implementation 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:+'

+ 2 - 0
app/src/main/AndroidManifest.xml

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
     package="com.quansu.heifengwuliu" >
 
     <!-- 如果有视频相关的广告且使用textureView播放,请务必添加,否则黑屏 -->
@@ -33,6 +34,7 @@
         android:roundIcon="@mipmap/ic_launcher"
         android:supportsRtl="true"
         android:theme="@style/AppTheme.NoActionBar"
+        tools:replace="android:name"
         android:usesCleartextTraffic="true" >
 
         <meta-data

+ 13 - 0
app/src/main/java/com/quansu/heifengwuliu/vmodel/OrderListVModel.kt

@@ -5,9 +5,12 @@ import com.quansu.heifengwuliu.activity.SourceDetailsActivity
 import com.quansu.heifengwuliu.utils.net.NetEngine
 import com.ysnows.base.base.BRRepository
 import com.ysnows.base.base.BRViewModel
+import com.ysnows.base.ccretrofit.CCRetrofit
 import com.ysnows.base.net.IResponse
+import com.ysnows.base.route.ILookimg
 import com.ysnows.base.utils.UiSwitch
 import io.reactivex.Observable
+import java.util.ArrayList
 
 class OrderListVModel : BRViewModel<BRRepository>() {
 
@@ -41,4 +44,14 @@ class OrderListVModel : BRViewModel<BRRepository>() {
     }
 
 
+    fun toLookImg(qrcode:String){
+        var list= ArrayList<String>()
+        list.add(qrcode)
+        CCRetrofit.instance()
+                .with(repository().context)
+                .create(ILookimg::class.java)
+                .previewImageArr(list,0)
+                .subscribe()
+    }
+
 }

+ 1 - 0
app/src/main/res/layout/item_order.xml

@@ -153,6 +153,7 @@
                 android:src="@drawable/ic_qr"
                 app:layout_constraintBottom_toBottomOf="@id/img_goods"
                 app:layout_constraintEnd_toEndOf="parent"
+                android:onClick="@{v->vm.toLookImg(item.qrcode)}"
                 app:layout_constraintTop_toTopOf="@id/img_vehicle" />
 
         </androidx.constraintlayout.widget.ConstraintLayout >

+ 0 - 20
base/src/main/java/com/ysnows/base/route/IImagePreview.java

@@ -1,20 +0,0 @@
-package com.ysnows.base.route;
-
-import com.billy.cc.core.component.CCResult;
-import com.ysnows.base.ccretrofit.annotation.Param;
-
-import java.util.ArrayList;
-
-import io.reactivex.Observable;
-
-/**
- * Created by shihuiyun
- * on 2020/5/29
- */
-public interface IImagePreview {
-
-
-    Observable<CCResult> previewImageArr(@Param("urls") ArrayList<String> urls, @Param("position") int position);
-
-
-}

+ 16 - 0
base/src/main/java/com/ysnows/base/route/ILookimg.kt

@@ -0,0 +1,16 @@
+package com.ysnows.base.route
+
+import com.billy.cc.core.component.CCResult
+import com.ysnows.base.ccretrofit.IRoute
+import com.ysnows.base.ccretrofit.annotation.Param
+import io.reactivex.Observable
+import java.util.ArrayList
+
+/**
+ *Created by shihuiyun
+ *on 2020/9/18
+ */
+interface ILookimg : IRoute {
+
+    fun previewImageArr(@Param("urls") urls: ArrayList<String>,@Param("position") position:Int): Observable<CCResult>
+}

+ 6 - 0
base/src/main/java/com/ysnows/base/utils/B.java

@@ -3,6 +3,8 @@ package com.ysnows.base.utils;
 import android.os.Bundle;
 import android.os.Parcelable;
 
+import androidx.annotation.Nullable;
+
 import java.io.Serializable;
 import java.util.ArrayList;
 
@@ -33,6 +35,10 @@ public class B {
         this.bundle.putStringArray(name, value);
         return this;
     }
+    public B putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value) {
+        this.bundle.putStringArrayList(key, value);
+        return this;
+    }
 
     public B putInt(String name, int value) {
         this.bundle.putInt(name, value);

+ 1 - 0
lookimg/.gitignore

@@ -0,0 +1 @@
+/build

+ 51 - 0
lookimg/build.gradle

@@ -0,0 +1,51 @@
+apply from: rootProject.file('cc-settings.gradle')
+apply from: rootProject.file('common-build.gradle')
+
+android {
+    compileSdkVersion rootProject.target_sdk_version
+    defaultConfig {
+        minSdkVersion rootProject.min_sdk_version
+        targetSdkVersion rootProject.target_sdk_version
+        versionCode rootProject.application_version_code
+        versionName rootProject.application_version_name
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+        }
+    }
+    kotlinOptions {
+        jvmTarget = '1.8'
+    }
+    android.buildFeatures {
+        dataBinding = true
+        viewBinding = false
+    }
+
+
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_8
+        targetCompatibility JavaVersion.VERSION_1_8
+    }
+
+
+}
+
+dependencies {
+    implementation fileTree(dir: 'libs', include: ['*.jar'])
+    implementation project(':base')
+    implementation 'com.github.chrisbanes:PhotoView:2.0.0'
+    //图片/视频选择、预览、编辑与拍照
+    implementation 'com.github.guoxiaoxing:phoenix:1.0.15'
+//选填 - 图片压缩,开启功能:Phoenix.with().enableCompress(true),获取结果:MediaEntity.getCompressPath()
+    implementation 'com.github.guoxiaoxing:phoenix-compress-picture:1.0.15'
+
+//选填 - 视频压缩,开启功能:Phoenix.with().enableCompress(true),获取结果:MediaEntity.getCompressPath()
+    implementation 'com.github.guoxiaoxing:phoenix-compress-video:1.0.15'
+
+
+
+}
+

+ 34 - 0
lookimg/src/main/AndroidManifest.xml

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.quansu.lookimg" >
+
+    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
+
+    <application
+        android:name=".LookImgApp"
+        android:allowBackup="true"
+        android:label="@string/app_name"
+        android:supportsRtl="true" >
+
+        <!--        <meta-data-->
+        <!--            android:name="design_width"-->
+        <!--            android:value="768" >-->
+        <!--        </meta-data >-->
+        <!--        <meta-data-->
+        <!--            android:name="design_height"-->
+        <!--            android:value="1280" >-->
+        <!--        </meta-data >-->
+
+        <activity android:name=".ImagePagerActivity"/>
+
+
+    </application >
+
+</manifest >
+
+

+ 102 - 0
lookimg/src/main/java/com/quansu/lookimg/ImagePagerActivity.kt

@@ -0,0 +1,102 @@
+package com.quansu.lookimg
+
+import android.os.Bundle
+import android.view.KeyEvent
+import android.view.View
+import androidx.viewpager.widget.ViewPager
+import com.quansu.lookimg.adapter.ImagePagerAdapter
+import com.quansu.lookimg.databinding.ActivityImagepagerBinding
+import com.quansu.lookimg.vmodel.ImagePagerVModel
+import com.ysnows.base.base.BActivity
+import java.util.*
+
+/**
+ *Created by shihuiyun
+ *on 2020/9/18
+ */
+class ImagePagerActivity : BActivity<ImagePagerVModel, ActivityImagepagerBinding>() {
+
+
+    var adapter: ImagePagerAdapter? = null
+    var urls: ArrayList<String>? = null
+    private var position = 0
+
+
+    override fun __before() {
+        super.__before()
+
+        urls = intent.extras.getStringArrayList("urls")
+        position = intent.extras.getInt("position")
+
+
+    }
+
+
+    override fun initCreate(savedInstanceState: Bundle?) {
+        super.initCreate(savedInstanceState)
+        initViewPager()
+    }
+
+
+    private fun initViewPager() {
+        adapter = ImagePagerAdapter(supportFragmentManager, urls!!)
+        binding.pager.adapter = adapter
+
+        val text: CharSequence = getString(R.string.viewpager_indicator, 1, binding.pager.adapter!!.count)
+        if (urls!!.size == 1) binding.indicator.visibility = View.GONE else binding.indicator.visibility = View.VISIBLE
+
+
+        vm.text.value = text.toString()
+
+
+        binding.pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
+            override fun onPageScrollStateChanged(state: Int) {
+
+            }
+
+            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
+
+            }
+
+            override fun onPageSelected(position: Int) {
+
+                val text: CharSequence = getString(R.string.viewpager_indicator, position + 1, binding.pager.adapter!!.count)
+                vm.text.value = text.toString()
+
+
+            }
+
+        })
+
+        binding.pager.currentItem = position
+
+
+    }
+
+    override fun vmClass(): Class<ImagePagerVModel> {
+        return ImagePagerVModel::class.java
+    }
+
+
+    override fun binding(): ActivityImagepagerBinding {
+        return ActivityImagepagerBinding.inflate(layoutInflater)
+    }
+
+
+    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
+        if (keyCode == KeyEvent.KEYCODE_BACK && event!!.action == KeyEvent.ACTION_UP) {
+            finish()
+            //不执行父类点击事件
+            return true
+        }
+
+
+        return super.onKeyDown(keyCode, event)
+    }
+
+
+    override fun title(): String? {
+        return null
+    }
+
+}

+ 26 - 0
lookimg/src/main/java/com/quansu/lookimg/LookImgApp.java

@@ -0,0 +1,26 @@
+package com.quansu.lookimg;
+
+import com.ysnows.base.base.BApp;
+import com.ysnows.base.config.IConfig;
+
+import org.jetbrains.annotations.Nullable;
+
+
+/**
+ * Created by shihuiyun
+ * on 2020/9/18
+ */
+public class LookImgApp extends BApp {
+
+    @Override
+    protected void init() {
+
+    }
+
+
+    @Nullable
+    @Override
+    public IConfig config() {
+        return null;
+    }
+}

+ 30 - 0
lookimg/src/main/java/com/quansu/lookimg/adapter/ImagePagerAdapter.kt

@@ -0,0 +1,30 @@
+package com.quansu.lookimg.adapter
+
+import androidx.fragment.app.Fragment
+import androidx.fragment.app.FragmentManager
+import androidx.fragment.app.FragmentStatePagerAdapter
+import com.quansu.lookimg.fragment.ImageDetailFragment
+import com.ysnows.base.utils.B
+import java.util.*
+
+
+/**
+ *Created by shihuiyun
+ *on 2020/9/18
+ */
+class ImagePagerAdapter(val fm: FragmentManager,val urls: ArrayList<String>) : FragmentStatePagerAdapter(fm){
+
+    override fun getItem(position: Int): Fragment {
+        val url = urls[position]
+
+        val fragment = ImageDetailFragment()
+         fragment.arguments = B.with()
+                .putString("url", url)
+                .ok()
+        return fragment
+    }
+
+    override fun getCount(): Int {
+        return urls.size
+    }
+}

+ 28 - 0
lookimg/src/main/java/com/quansu/lookimg/component/CpLookimg.kt

@@ -0,0 +1,28 @@
+package com.quansu.lookimg.component
+
+import com.billy.cc.core.component.CC
+import com.billy.cc.core.component.CCResult
+import com.billy.cc.core.component.IComponent
+import com.quansu.lookimg.ImagePagerActivity
+import com.ysnows.base.ccextension.BIComponent
+import com.ysnows.base.utils.B
+import com.ysnows.base.utils.UiSwitch
+import java.util.*
+
+/**
+ *Created by shihuiyun
+ *on 2020/9/18
+ */
+class CpLookimg: BIComponent() , IComponent {
+
+    fun previewImageArr(cc: CC,urls: ArrayList<String>,position:Int): Boolean {
+
+        UiSwitch.bundle(cc.context, ImagePagerActivity::class.java,
+                B.with().putStringArrayList("urls", urls)
+                        .putInt("position", position)
+                        .ok())
+        CC.sendCCResult(cc.getCallId(), CCResult.success())
+        return false
+    }
+
+}

+ 60 - 0
lookimg/src/main/java/com/quansu/lookimg/fragment/ImageDetailFragment.kt

@@ -0,0 +1,60 @@
+package com.quansu.lookimg.fragment
+
+import android.app.Activity
+import android.os.Bundle
+import android.util.Log
+import android.view.LayoutInflater
+import android.view.ViewGroup
+import com.github.chrisbanes.photoview.PhotoViewAttacher
+import com.quansu.lookimg.databinding.FragmentImagedetailBinding
+import com.quansu.lookimg.vmodel.ImageDetailVModel
+import com.ysnows.base.base.BFragment
+import com.ysnows.base.inter.IUser
+
+/**
+ *Created by shihuiyun
+ *on 2020/9/18
+ */
+class ImageDetailFragment : BFragment<ImageDetailVModel, FragmentImagedetailBinding>(){
+
+    var url=""
+    override fun __before(savedInstanceState: Bundle?) {
+        super.__before(savedInstanceState)
+        url = arguments?.getString("url")!!
+    }
+
+
+    override fun init(savedInstanceState: Bundle?) {
+        super.init(savedInstanceState)
+        Log.e("-shy-", "url=: "+url )
+        vm.url.value=url
+        initImg()
+    }
+
+
+    private fun initImg(){
+
+        var mAttacher= PhotoViewAttacher(binding.image)
+        mAttacher.isZoomEnabled
+        mAttacher.setOnPhotoTapListener{
+            view, x, y ->
+            (context as Activity).onBackPressed()
+        }
+
+    }
+
+
+
+    override fun binding(inflater: LayoutInflater, container: ViewGroup?): FragmentImagedetailBinding {
+       return FragmentImagedetailBinding.inflate(inflater)
+    }
+
+    override fun vmClass(): Class<ImageDetailVModel> {
+        return ImageDetailVModel::class.java
+    }
+
+
+    override fun user(): IUser? {
+        TODO("Not yet implemented")
+    }
+}

+ 14 - 0
lookimg/src/main/java/com/quansu/lookimg/vmodel/ImageDetailVModel.kt

@@ -0,0 +1,14 @@
+package com.quansu.lookimg.vmodel
+
+import androidx.lifecycle.MutableLiveData
+import com.ysnows.base.base.BRepository
+import com.ysnows.base.base.BViewModel
+
+/**
+ *Created by shihuiyun
+ *on 2020/9/18
+ */
+class ImageDetailVModel : BViewModel<BRepository>() {
+   var url= MutableLiveData<String>("")
+
+}

+ 17 - 0
lookimg/src/main/java/com/quansu/lookimg/vmodel/ImagePagerVModel.kt

@@ -0,0 +1,17 @@
+package com.quansu.lookimg.vmodel
+
+import androidx.lifecycle.MutableLiveData
+import com.ysnows.base.base.BRepository
+import com.ysnows.base.base.BViewModel
+
+/**
+ *Created by shihuiyun
+ *on 2020/9/18
+ */
+class ImagePagerVModel : BViewModel<BRepository>() {
+
+    var text= MutableLiveData<String>("")
+
+
+
+}

二进制
lookimg/src/main/res/drawable-xxhdpi/ic_download.webp


+ 51 - 0
lookimg/src/main/res/layout/activity_imagepager.xml

@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layout xmlns:android="http://schemas.android.com/apk/res/android" >
+
+    <data >
+
+        <import type="android.view.View" />
+
+        <variable
+            name="vm"
+            type="com.quansu.lookimg.vmodel.ImagePagerVModel" />
+
+    </data >
+
+    <FrameLayout
+        android:layout_width="match_parent"
+        xmlns:tools="http://schemas.android.com/tools"
+        android:background="@android:color/black"
+        android:layout_height="match_parent" >
+
+          <androidx.viewpager.widget.ViewPager
+              android:id="@+id/pager"
+              android:layout_width="match_parent"
+              android:background="@android:color/black"
+              android:layout_height="match_parent"/>
+
+
+
+        <TextView
+            android:id="@+id/indicator"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_gravity="bottom"
+            android:background="@android:color/transparent"
+            android:gravity="center"
+            android:text="@{vm.text}"
+            android:textColor="@android:color/white"
+            android:textSize="18sp" />
+
+        <ImageView
+            android:id="@+id/img_down"
+            android:layout_width="48dp"
+            android:layout_height="48dp"
+            android:layout_gravity="bottom|right"
+            android:padding="12dp"
+            android:visibility="gone"
+            tools:visibility="visible"
+            android:src="@drawable/ic_download"
+            />
+
+    </FrameLayout >
+</layout >

+ 36 - 0
lookimg/src/main/res/layout/fragment_imagedetail.xml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layout xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <data>
+
+        <variable
+            name="vm"
+            type="com.quansu.lookimg.vmodel.ImageDetailVModel" />
+
+    </data>
+
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:background="@color/black"
+        xmlns:app="http://schemas.android.com/apk/res-auto"
+        android:orientation="vertical">
+
+
+        <com.github.chrisbanes.photoview.PhotoView
+            android:id="@+id/image"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            app:url="@{vm.url}"
+            android:background="#000000" />
+
+        <ProgressBar
+            android:id="@+id/loading"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:visibility="gone" />
+
+    </FrameLayout>
+
+</layout>

+ 5 - 0
lookimg/src/main/res/values/strings.xml

@@ -0,0 +1,5 @@
+<resources >
+    <string name="app_name" >lookimg</string >
+    <string name="viewpager_indicator" >%1$d/%2$d</string >
+
+</resources >

+ 5 - 0
lookimg/src/main/res/values/styles.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources >
+
+
+</resources>

+ 2 - 0
settings.gradle

@@ -2,4 +2,6 @@ include ':jpush'
 include ':umeng'
 include ':update'
 include ':gaode'
+include ':lookimg'
+
 include ':app',':base'