Merge pull request #2255 from hadi-norouzi/feature/share_sub
Feature/share sub
This commit is contained in:
9 files changed
+95
-7
No files matched your search
@@ -2,20 +2,34 @@ package com.v2ray.ang.ui
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
import android.text.TextUtils
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.tencent.mmkv.MMKV
|
import com.tencent.mmkv.MMKV
|
||||||
import com.v2ray.ang.R
|
import com.v2ray.ang.R
|
||||||
|
import com.v2ray.ang.databinding.ItemQrcodeBinding
|
||||||
import com.v2ray.ang.databinding.ItemRecyclerSubSettingBinding
|
import com.v2ray.ang.databinding.ItemRecyclerSubSettingBinding
|
||||||
|
import com.v2ray.ang.dto.EConfigType
|
||||||
|
import com.v2ray.ang.extension.toast
|
||||||
|
import com.v2ray.ang.util.AngConfigManager
|
||||||
import com.v2ray.ang.util.MmkvManager
|
import com.v2ray.ang.util.MmkvManager
|
||||||
|
import com.v2ray.ang.util.QRCodeDecoder
|
||||||
|
import com.v2ray.ang.util.Utils
|
||||||
|
|
||||||
class SubSettingRecyclerAdapter(val activity: SubSettingActivity) : RecyclerView.Adapter<SubSettingRecyclerAdapter.MainViewHolder>() {
|
class SubSettingRecyclerAdapter(val activity: SubSettingActivity) :
|
||||||
|
RecyclerView.Adapter<SubSettingRecyclerAdapter.MainViewHolder>() {
|
||||||
|
|
||||||
private var mActivity: SubSettingActivity = activity
|
private var mActivity: SubSettingActivity = activity
|
||||||
private val subStorage by lazy { MMKV.mmkvWithID(MmkvManager.ID_SUB, MMKV.MULTI_PROCESS_MODE) }
|
private val subStorage by lazy { MMKV.mmkvWithID(MmkvManager.ID_SUB, MMKV.MULTI_PROCESS_MODE) }
|
||||||
|
|
||||||
|
private val share_method: Array<out String> by lazy {
|
||||||
|
mActivity.resources.getStringArray(R.array.share_sub_method)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getItemCount() = mActivity.subscriptions.size
|
override fun getItemCount() = mActivity.subscriptions.size
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: MainViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: MainViewHolder, position: Int) {
|
||||||
@@ -31,7 +45,8 @@ class SubSettingRecyclerAdapter(val activity: SubSettingActivity) : RecyclerView
|
|||||||
holder.itemView.setBackgroundColor(Color.TRANSPARENT)
|
holder.itemView.setBackgroundColor(Color.TRANSPARENT)
|
||||||
|
|
||||||
holder.itemSubSettingBinding.layoutEdit.setOnClickListener {
|
holder.itemSubSettingBinding.layoutEdit.setOnClickListener {
|
||||||
mActivity.startActivity(Intent(mActivity, SubEditActivity::class.java)
|
mActivity.startActivity(
|
||||||
|
Intent(mActivity, SubEditActivity::class.java)
|
||||||
.putExtra("subId", subId)
|
.putExtra("subId", subId)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -40,11 +55,51 @@ class SubSettingRecyclerAdapter(val activity: SubSettingActivity) : RecyclerView
|
|||||||
subStorage?.encode(subId, Gson().toJson(subItem))
|
subStorage?.encode(subId, Gson().toJson(subItem))
|
||||||
notifyItemChanged(position)
|
notifyItemChanged(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(subItem.url)) {
|
||||||
|
holder.itemSubSettingBinding.layoutShare.visibility = View.INVISIBLE
|
||||||
|
} else {
|
||||||
|
holder.itemSubSettingBinding.layoutShare.setOnClickListener {
|
||||||
|
AlertDialog.Builder(mActivity)
|
||||||
|
.setItems(share_method.asList().toTypedArray()) { _, i ->
|
||||||
|
try {
|
||||||
|
when (i) {
|
||||||
|
0 -> {
|
||||||
|
val ivBinding =
|
||||||
|
ItemQrcodeBinding.inflate(LayoutInflater.from(mActivity))
|
||||||
|
ivBinding.ivQcode.setImageBitmap(
|
||||||
|
QRCodeDecoder.createQRCode(
|
||||||
|
subItem.url
|
||||||
|
|
||||||
|
)
|
||||||
|
)
|
||||||
|
AlertDialog.Builder(mActivity).setView(ivBinding.root).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
1 -> {
|
||||||
|
Utils.setClipboard(mActivity, subItem.url)
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> mActivity.toast("else")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MainViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MainViewHolder {
|
||||||
return MainViewHolder(ItemRecyclerSubSettingBinding.inflate(LayoutInflater.from(parent.context), parent, false))
|
return MainViewHolder(
|
||||||
|
ItemRecyclerSubSettingBinding.inflate(
|
||||||
|
LayoutInflater.from(parent.context),
|
||||||
|
parent,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class MainViewHolder(val itemSubSettingBinding: ItemRecyclerSubSettingBinding) : RecyclerView.ViewHolder(itemSubSettingBinding.root)
|
class MainViewHolder(val itemSubSettingBinding: ItemRecyclerSubSettingBinding) :
|
||||||
|
RecyclerView.ViewHolder(itemSubSettingBinding.root)
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,8 @@
|
|||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/recycler_view"
|
android:id="@+id/recycler_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent"
|
||||||
|
tools:listitem="@layout/item_recycler_sub_setting"/>
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
@@ -73,12 +73,13 @@
|
|||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="@dimen/layout_margin_spacing"
|
android:padding="@dimen/layout_margin_spacing"
|
||||||
android:visibility="invisible">
|
>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="@dimen/png_height"
|
android:layout_width="@dimen/png_height"
|
||||||
android:layout_height="@dimen/png_height"
|
android:layout_height="@dimen/png_height"
|
||||||
android:src="@drawable/ic_share_black_24dp" />
|
android:src="@drawable/ic_share_black_24dp"
|
||||||
|
app:tint="?attr/colorMainText"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -211,6 +211,11 @@
|
|||||||
<item>خروجی گرفتن پیکربندی کامل در کلیپبورد</item>
|
<item>خروجی گرفتن پیکربندی کامل در کلیپبورد</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="share_sub_method">
|
||||||
|
<item>QRcode</item>
|
||||||
|
<item>خروجی گرفتن در کلیپبورد</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="routing_tag">
|
<string-array name="routing_tag">
|
||||||
<item>نشانی اینترنتی یا آیپی پروکسی</item>
|
<item>نشانی اینترنتی یا آیپی پروکسی</item>
|
||||||
<item>نشانی اینترنتی یا آیپی مستقیم</item>
|
<item>نشانی اینترنتی یا آیپی مستقیم</item>
|
||||||
|
|||||||
@@ -216,6 +216,11 @@
|
|||||||
<item>Экспорт всего профиля в буфер обмена</item>
|
<item>Экспорт всего профиля в буфер обмена</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="share_sub_method">
|
||||||
|
<item>QR-код</item>
|
||||||
|
<item>Экспорт в буфер обмена</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="routing_tag">
|
<string-array name="routing_tag">
|
||||||
<item>Проксируемые</item>
|
<item>Проксируемые</item>
|
||||||
<item>Прямые</item>
|
<item>Прямые</item>
|
||||||
|
|||||||
@@ -210,6 +210,11 @@
|
|||||||
<item>Sao chép thành cấu hình tùy chỉnh</item>
|
<item>Sao chép thành cấu hình tùy chỉnh</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="share_sub_method">
|
||||||
|
<item>Xuất ra mã QR (Chụp màn hình để lưu)</item>
|
||||||
|
<item>Sao chép cấu hình này</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="routing_tag">
|
<string-array name="routing_tag">
|
||||||
<item>Proxy URL hoặc IP</item>
|
<item>Proxy URL hoặc IP</item>
|
||||||
<item>Direct URL hoặc IP</item>
|
<item>Direct URL hoặc IP</item>
|
||||||
|
|||||||
@@ -209,6 +209,12 @@
|
|||||||
<item>导出至剪贴板</item>
|
<item>导出至剪贴板</item>
|
||||||
<item>导出完整配置至剪贴板</item>
|
<item>导出完整配置至剪贴板</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="share_sub_method">
|
||||||
|
<item>二维码</item>
|
||||||
|
<item>导出至剪贴板</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
share_method
|
share_method
|
||||||
<string-array name="routing_tag">
|
<string-array name="routing_tag">
|
||||||
<item>代理的网址或IP</item>
|
<item>代理的网址或IP</item>
|
||||||
|
|||||||
@@ -210,6 +210,11 @@
|
|||||||
<item>匯出完整組態至剪貼簿</item>
|
<item>匯出完整組態至剪貼簿</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="share_sub_method">
|
||||||
|
<item>QR Code</item>
|
||||||
|
<item>匯出至剪貼簿</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="routing_tag">
|
<string-array name="routing_tag">
|
||||||
<item>Proxy URL 或 IP</item>
|
<item>Proxy URL 或 IP</item>
|
||||||
<item>直接連線 URL 或 IP</item>
|
<item>直接連線 URL 或 IP</item>
|
||||||
|
|||||||
@@ -218,6 +218,11 @@
|
|||||||
<item>Export full configuration to clipboard</item>
|
<item>Export full configuration to clipboard</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="share_sub_method">
|
||||||
|
<item>QRcode</item>
|
||||||
|
<item>Export to clipboard</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="routing_tag">
|
<string-array name="routing_tag">
|
||||||
<item>proxy URL or IP</item>
|
<item>proxy URL or IP</item>
|
||||||
<item>direct URL or IP</item>
|
<item>direct URL or IP</item>
|
||||||
|
|||||||
Reference in new issue
Block a user