Skip to content

Commit

Permalink
Refine 'Replace CardView with normal list view'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod committed Nov 18, 2017
1 parent f59f713 commit 5505c78
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 111 deletions.
148 changes: 76 additions & 72 deletions mobile/src/main/res/layout/layout_profile.xml
Original file line number Diff line number Diff line change
@@ -1,84 +1,88 @@
<?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"
<LinearLayout
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"
android:orientation="vertical"
android:paddingLeft="16dp"
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:orientation="vertical"
android:paddingLeft="16dp"
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_marginStart="8dp"
android:id="@+id/container">
<TextView
android:id="@android:id/text1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:id="@+id/container">
<TextView android:id="@android:id/text1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold"
android:gravity="center_vertical"
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_gravity="center_vertical"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold"
android:gravity="center_vertical"
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: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>
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>
</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>
Original file line number Diff line number Diff line change
Expand Up @@ -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 = _

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
Expand Down

This file was deleted.

0 comments on commit 5505c78

Please sign in to comment.