Commit 5505c78f authored by Mygod's avatar Mygod

Refine 'Replace CardView with normal list view'

parent f59f7137
<?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 -->
<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"
android:id="@+id/ads"
android:id="@+id/indicator"
android:orientation="vertical"
android:focusable="false"
android:background="@drawable/background_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="@+id/indicator">
<LinearLayout android:layout_width="match_parent"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="16dp"
......@@ -22,11 +20,13 @@
android:nextFocusRight="@+id/edit"
android:id="@+id/content"
android:background="?android:attr/selectableItemBackground">
<LinearLayout android:layout_width="match_parent"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:id="@+id/container">
<TextView android:id="@android:id/text1"
<TextView
android:id="@android:id/text1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
......@@ -37,7 +37,8 @@
android:gravity="center_vertical"
android:maxLines="2"
android:ellipsize="end"/>
<android.support.v7.widget.AppCompatImageView android:id="@+id/share"
<android.support.v7.widget.AppCompatImageView
android:id="@+id/share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
......@@ -47,7 +48,8 @@
android:contentDescription="@string/share"
android:focusable="true"
android:nextFocusLeft="@+id/container"/>
<android.support.v7.widget.AppCompatImageView android:id="@+id/edit"
<android.support.v7.widget.AppCompatImageView
android:id="@+id/edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
......@@ -57,10 +59,12 @@
android:contentDescription="@string/edit"
android:focusable="true"/>
</LinearLayout>
<RelativeLayout android:layout_width="match_parent"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp">
<TextView android:id="@android:id/text2"
<TextView
android:id="@android:id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
......@@ -70,7 +74,8 @@
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"/>
<TextView android:id="@+id/traffic"
<TextView
android:id="@+id/traffic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
......@@ -80,5 +85,4 @@
android:textColor="?android:attr/textColorSecondary"/>
</RelativeLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
......@@ -78,8 +78,6 @@ final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClic
edit.setOnClickListener(_ => startConfig(item.id))
edit.setOnLongClickListener(cardButtonLongClickListener)
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 = _
......@@ -135,12 +133,11 @@ final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClic
val params =
new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
params.gravity = Gravity.CENTER_HORIZONTAL
params.setMargins(0, 0, 0, 0)
adView = new AdView(getActivity)
adView.setLayoutParams(params)
adView.setAdUnitId("ca-app-pub-9097031975646651/7760346322")
adView.setAdSize(AdSize.SMART_BANNER)
itemView.findViewById[LinearLayout](R.id.ads).addView(adView)
itemView.findViewById[LinearLayout](R.id.indicator).addView(adView)
// Load Ad
val adBuilder = new AdRequest.Builder()
......@@ -267,10 +264,8 @@ final class ProfilesFragment extends ToolbarFragment with Toolbar.OnMenuItemClic
if (app.profileManager.getFirstProfile.isEmpty) app.dataStore.profileId = app.profileManager.createProfile().id
val profilesList = view.findViewById[RecyclerView](R.id.list)
val layoutManager = new LinearLayoutManager(getActivity, LinearLayoutManager.VERTICAL, false)
val dividerItemDecoration = new DividerItemDecoration(profilesList.getContext(),
layoutManager.getOrientation())
profilesList.setLayoutManager(layoutManager)
profilesList.addItemDecoration(dividerItemDecoration)
profilesList.addItemDecoration(new DividerItemDecoration(getActivity, layoutManager.getOrientation))
layoutManager.scrollToPosition(profilesAdapter.profiles.zipWithIndex.collectFirst {
case (profile, i) if profile.id == app.dataStore.profileId => i
}.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