Commit 5505c78f authored by Mygod's avatar Mygod

Refine 'Replace CardView with normal list view'

parent f59f7137
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Based on: https://github.com/android/platform_frameworks_base/blob/505e3ab/core/res/res/layout/simple_list_item_2.xml --> <!-- Based on: https://github.com/android/platform_frameworks_base/blob/505e3ab/core/res/res/layout/simple_list_item_2.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ads" android:id="@+id/indicator"
android:orientation="vertical" android:orientation="vertical"
android:focusable="false" android:background="@drawable/background_profile"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<FrameLayout android:layout_width="match_parent" <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:orientation="vertical"
android:id="@+id/indicator"> android:paddingLeft="16dp"
<LinearLayout android:layout_width="match_parent" android:paddingRight="4dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:focusable="true"
android:nextFocusRight="@+id/edit"
android:id="@+id/content"
android:background="?android:attr/selectableItemBackground">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:layout_marginStart="8dp"
android:paddingLeft="16dp" android:id="@+id/container">
android:paddingRight="4dp" <TextView
android:paddingTop="8dp" android:id="@android:id/text1"
android:paddingBottom="8dp" android:layout_width="0dp"
android:focusable="true"
android:nextFocusRight="@+id/edit"
android:id="@+id/content"
android:background="?android:attr/selectableItemBackground">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_gravity="center_vertical"
android:id="@+id/container"> android:layout_weight="1"
<TextView android:id="@android:id/text1" android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="0dp" android:textColor="?android:attr/textColorPrimary"
android:layout_height="wrap_content" android:textStyle="bold"
android:layout_gravity="center_vertical" android:gravity="center_vertical"
android:layout_weight="1" android:maxLines="2"
android:textAppearance="?android:attr/textAppearanceMedium" android:ellipsize="end"/>
android:textColor="?android:attr/textColorPrimary" <android.support.v7.widget.AppCompatImageView
android:textStyle="bold" android:id="@+id/share"
android:gravity="center_vertical" android:layout_width="wrap_content"
android:maxLines="2"
android:ellipsize="end"/>
<android.support.v7.widget.AppCompatImageView android:id="@+id/share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:layout_gravity="top"
app:srcCompat="@drawable/ic_social_share"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/share"
android:focusable="true"
android:nextFocusLeft="@+id/container"/>
<android.support.v7.widget.AppCompatImageView android:id="@+id/edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:layout_gravity="top"
app:srcCompat="@drawable/ic_image_edit"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/edit"
android:focusable="true"/>
</LinearLayout>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp"> android:padding="8dp"
<TextView android:id="@android:id/text2" android:layout_gravity="top"
android:layout_width="wrap_content" app:srcCompat="@drawable/ic_social_share"
android:layout_height="wrap_content" android:background="?attr/selectableItemBackgroundBorderless"
android:layout_alignParentStart="true" android:contentDescription="@string/share"
android:layout_toStartOf="@+id/traffic" android:focusable="true"
android:layout_marginEnd="8dp" android:nextFocusLeft="@+id/container"/>
android:maxLines="2" <android.support.v7.widget.AppCompatImageView
android:ellipsize="end" android:id="@+id/edit"
android:textAppearance="?android:attr/textAppearanceSmall" android:layout_width="wrap_content"
android:textColor="?android:attr/textColorSecondary"/> android:layout_height="wrap_content"
<TextView android:id="@+id/traffic" android:padding="8dp"
android:layout_width="wrap_content" android:layout_gravity="top"
android:layout_height="wrap_content" app:srcCompat="@drawable/ic_image_edit"
android:layout_gravity="bottom" android:background="?attr/selectableItemBackgroundBorderless"
android:layout_alignParentEnd="true" android:contentDescription="@string/edit"
android:ellipsize="end" android:focusable="true"/>
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"/>
</RelativeLayout>
</LinearLayout> </LinearLayout>
</FrameLayout> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp">
<TextView
android:id="@android:id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/traffic"
android:layout_marginEnd="8dp"
android:maxLines="2"
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"/>
<TextView
android:id="@+id/traffic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_alignParentEnd="true"
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>
...@@ -78,8 +78,6 @@ final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClic ...@@ -78,8 +78,6 @@ final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClic
edit.setOnClickListener(_ => startConfig(item.id)) edit.setOnClickListener(_ => startConfig(item.id))
edit.setOnLongClickListener(cardButtonLongClickListener) edit.setOnLongClickListener(cardButtonLongClickListener)
itemView.setOnClickListener(this) itemView.setOnClickListener(this)
// it will not take effect unless set in code
itemView.findViewById[View](R.id.indicator).setBackgroundResource(R.drawable.background_profile)
private var adView: AdView = _ private var adView: AdView = _
...@@ -135,12 +133,11 @@ final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClic ...@@ -135,12 +133,11 @@ final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClic
val params = val params =
new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
params.gravity = Gravity.CENTER_HORIZONTAL params.gravity = Gravity.CENTER_HORIZONTAL
params.setMargins(0, 0, 0, 0)
adView = new AdView(getActivity) adView = new AdView(getActivity)
adView.setLayoutParams(params) adView.setLayoutParams(params)
adView.setAdUnitId("ca-app-pub-9097031975646651/7760346322") adView.setAdUnitId("ca-app-pub-9097031975646651/7760346322")
adView.setAdSize(AdSize.SMART_BANNER) adView.setAdSize(AdSize.SMART_BANNER)
itemView.findViewById[LinearLayout](R.id.ads).addView(adView) itemView.findViewById[LinearLayout](R.id.indicator).addView(adView)
// Load Ad // Load Ad
val adBuilder = new AdRequest.Builder() val adBuilder = new AdRequest.Builder()
...@@ -267,10 +264,8 @@ final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClic ...@@ -267,10 +264,8 @@ final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClic
if (app.profileManager.getFirstProfile.isEmpty) app.dataStore.profileId = app.profileManager.createProfile().id if (app.profileManager.getFirstProfile.isEmpty) app.dataStore.profileId = app.profileManager.createProfile().id
val profilesList = view.findViewById[RecyclerView](R.id.list) val profilesList = view.findViewById[RecyclerView](R.id.list)
val layoutManager = new LinearLayoutManager(getActivity, LinearLayoutManager.VERTICAL, false) val layoutManager = new LinearLayoutManager(getActivity, LinearLayoutManager.VERTICAL, false)
val dividerItemDecoration = new DividerItemDecoration(profilesList.getContext(),
layoutManager.getOrientation())
profilesList.setLayoutManager(layoutManager) profilesList.setLayoutManager(layoutManager)
profilesList.addItemDecoration(dividerItemDecoration) profilesList.addItemDecoration(new DividerItemDecoration(getActivity, layoutManager.getOrientation))
layoutManager.scrollToPosition(profilesAdapter.profiles.zipWithIndex.collectFirst { layoutManager.scrollToPosition(profilesAdapter.profiles.zipWithIndex.collectFirst {
case (profile, i) if profile.id == app.dataStore.profileId => i case (profile, i) if profile.id == app.dataStore.profileId => i
}.getOrElse(-1)) }.getOrElse(-1))
......
/*******************************************************************************/
/* */
/* Copyright (C) 2017 by Max Lv <max.c.lv@gmail.com> */
/* Copyright (C) 2017 by Mygod Studio <contact-shadowsocks-android@mygod.be> */
/* */
/* This program is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*******************************************************************************/
package com.github.shadowsocks.widget
import android.content.Context
import android.support.v7.widget.CardView
import android.util.AttributeSet
/**
* @author Mygod
*/
class BoundedCardView(context: Context, attrs: AttributeSet) extends CardView(context, attrs) with BoundedView {
initAttrs(context, attrs)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment