From 41a2e7effcd7f0eb8efad96a950dd65670b566a6 Mon Sep 17 00:00:00 2001 From: Kr328 <39107975+Kr328@users.noreply.github.com> Date: Mon, 9 Dec 2019 00:41:13 +0800 Subject: [PATCH] fix proxy name display & profile not fully display --- app/build.gradle | 6 +-- .../github/kr328/clash/ProfilesActivity.kt | 8 ++-- .../kr328/clash/adapter/ProfileAdapter.kt | 43 ++++++++++++++++--- app/src/main/res/layout/activity_profiles.xml | 24 ++--------- .../main/res/layout/adapter_proxy_item.xml | 2 +- 5 files changed, 48 insertions(+), 35 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 051f8d7..421f536 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { applicationId "com.github.kr328.clash" minSdkVersion 24 targetSdkVersion 29 - versionCode 10008 - versionName "1.0.8-alpha" + versionCode 10009 + versionName "1.0.9-alpha" } buildTypes { release { @@ -41,7 +41,7 @@ dependencies { implementation 'androidx.preference:preference:1.1.0' implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.core:core-ktx:1.2.0-rc01' - implementation 'androidx.fragment:fragment-ktx:1.2.0-rc02' + implementation 'androidx.fragment:fragment-ktx:1.2.0-rc03' implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3' implementation "androidx.room:room-runtime:$room_version" diff --git a/app/src/main/java/com/github/kr328/clash/ProfilesActivity.kt b/app/src/main/java/com/github/kr328/clash/ProfilesActivity.kt index 1803960..550dbdb 100644 --- a/app/src/main/java/com/github/kr328/clash/ProfilesActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/ProfilesActivity.kt @@ -33,10 +33,6 @@ class ProfilesActivity : BaseActivity() { setSupportActionBar(activity_profiles_toolbar) - activity_profiles_new_profile.setOnClickListener { - startActivity(Intent(this, CreateProfileActivity::class.java)) - } - activity_profiles_main_list.layoutManager = object : LinearLayoutManager(this) { override fun canScrollHorizontally(): Boolean = false override fun canScrollVertically(): Boolean = false @@ -44,7 +40,9 @@ class ProfilesActivity : BaseActivity() { activity_profiles_main_list.adapter = ProfileAdapter(this, this::onProfileClick, this::onOperateClick, - this::onProfileLongClick) + this::onProfileLongClick) { + startActivity(Intent(this, CreateProfileActivity::class.java)) + } } override fun onStart() { diff --git a/app/src/main/java/com/github/kr328/clash/adapter/ProfileAdapter.kt b/app/src/main/java/com/github/kr328/clash/adapter/ProfileAdapter.kt index 962620d..62b7426 100644 --- a/app/src/main/java/com/github/kr328/clash/adapter/ProfileAdapter.kt +++ b/app/src/main/java/com/github/kr328/clash/adapter/ProfileAdapter.kt @@ -6,6 +6,7 @@ import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.github.kr328.clash.R import com.github.kr328.clash.service.data.ClashProfileEntity +import com.github.kr328.clash.view.FatItem import com.github.kr328.clash.view.RadioFatItem import java.text.SimpleDateFormat import java.util.* @@ -13,13 +14,24 @@ import java.util.* class ProfileAdapter(private val context: Context, private val onClick: (ClashProfileEntity) -> Unit, private val onOperateClick: (ClashProfileEntity) -> Unit, - private val onLongClicked: (View,ClashProfileEntity) -> Unit) : - RecyclerView.Adapter() { + private val onLongClicked: (View,ClashProfileEntity) -> Unit, + private val onNewProfile: () -> Unit) : + RecyclerView.Adapter() { var profiles: Array = emptyArray() class ProfileViewHolder(val view: RadioFatItem) : RecyclerView.ViewHolder(view) + class NewProfileHolder(val view: FatItem) : RecyclerView.ViewHolder(view) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + if ( viewType == 0 ) { + return NewProfileHolder(FatItem(context).apply { + layoutParams = ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) + }) + } - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProfileViewHolder { return ProfileViewHolder( RadioFatItem(context).apply { layoutParams = ViewGroup.LayoutParams( @@ -31,11 +43,25 @@ class ProfileAdapter(private val context: Context, } override fun getItemCount(): Int { - return profiles.size + return profiles.size + 1 } - override fun onBindViewHolder(holder: ProfileViewHolder, position: Int) { + override fun onBindViewHolder(raw: RecyclerView.ViewHolder, position: Int) { + if ( position == profiles.size ) { + val holder = raw as NewProfileHolder + + holder.view.icon = context.getDrawable(R.drawable.ic_new_profile) + holder.view.title = context.getString(R.string.clash_new_profile) + + holder.view.setOnClickListener { + onNewProfile() + } + + return + } + val current = profiles[position] + val holder = raw as ProfileViewHolder holder.view.title = current.name holder.view.isChecked = current.active @@ -74,4 +100,11 @@ class ProfileAdapter(private val context: Context, } } } + + override fun getItemViewType(position: Int): Int { + return if ( position == profiles.size ) + 0 + else + 1 + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_profiles.xml b/app/src/main/res/layout/activity_profiles.xml index 91ff361..77c47d4 100644 --- a/app/src/main/res/layout/activity_profiles.xml +++ b/app/src/main/res/layout/activity_profiles.xml @@ -17,26 +17,8 @@ android:layout_height="60dp" /> - - - - - - - - - + android:layout_height="match_parent" /> \ No newline at end of file diff --git a/app/src/main/res/layout/adapter_proxy_item.xml b/app/src/main/res/layout/adapter_proxy_item.xml index 3d40c92..6d390ac 100644 --- a/app/src/main/res/layout/adapter_proxy_item.xml +++ b/app/src/main/res/layout/adapter_proxy_item.xml @@ -20,7 +20,7 @@