fix proxy name display & profile not fully display

This commit is contained in:
Kr328 committed 2019-12-09 00:41:13 +08:00
1 parent 6947118d2e
commit 41a2e7effc
5 files changed
+48 -35

No files matched your search

+3 -3
View File
@@ -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"
@@ -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() {
@@ -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<ProfileAdapter.ProfileViewHolder>() {
private val onLongClicked: (View,ClashProfileEntity) -> Unit,
private val onNewProfile: () -> Unit) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
var profiles: Array<ClashProfileEntity> = 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
}
}
+3 -21
View File
@@ -17,26 +17,8 @@
android:layout_height="60dp" />
</com.google.android.material.appbar.AppBarLayout>
<ScrollView
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/activity_profiles_main_list"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/activity_profiles_main_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.github.kr328.clash.view.FatItem
android:id="@+id/activity_profiles_new_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_new_profile"
app:title="@string/clash_new_profile" />
</LinearLayout>
</ScrollView>
android:layout_height="match_parent" />
</LinearLayout>
@@ -20,7 +20,7 @@
<TextView
android:id="@+id/adapter_proxy_item_name"
android:ellipsize="marquee"
android:ellipsize="middle"
android:textColor="@android:color/black"
android:singleLine="true"
android:layout_width="wrap_content"