From 5505c78fdcfd96dd04e0f95c55f489e2ac561663 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sat, 18 Nov 2017 00:53:17 -0800 Subject: [PATCH] Refine 'Replace CardView with normal list view' --- mobile/src/main/res/layout/layout_profile.xml | 148 +++++++++--------- .../github/shadowsocks/ProfilesFragment.scala | 9 +- .../shadowsocks/widget/BoundedCardView.scala | 32 ---- 3 files changed, 78 insertions(+), 111 deletions(-) delete mode 100644 mobile/src/main/scala/com/github/shadowsocks/widget/BoundedCardView.scala diff --git a/mobile/src/main/res/layout/layout_profile.xml b/mobile/src/main/res/layout/layout_profile.xml index c22c26f4..24408578 100644 --- a/mobile/src/main/res/layout/layout_profile.xml +++ b/mobile/src/main/res/layout/layout_profile.xml @@ -1,84 +1,88 @@ - - - + - + - - - - - + - - - + 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"/> + - + + + + + diff --git a/mobile/src/main/scala/com/github/shadowsocks/ProfilesFragment.scala b/mobile/src/main/scala/com/github/shadowsocks/ProfilesFragment.scala index efcdd708..9108817b 100644 --- a/mobile/src/main/scala/com/github/shadowsocks/ProfilesFragment.scala +++ b/mobile/src/main/scala/com/github/shadowsocks/ProfilesFragment.scala @@ -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)) diff --git a/mobile/src/main/scala/com/github/shadowsocks/widget/BoundedCardView.scala b/mobile/src/main/scala/com/github/shadowsocks/widget/BoundedCardView.scala deleted file mode 100644 index b8e97a7b..00000000 --- a/mobile/src/main/scala/com/github/shadowsocks/widget/BoundedCardView.scala +++ /dev/null @@ -1,32 +0,0 @@ -/*******************************************************************************/ -/* */ -/* Copyright (C) 2017 by Max Lv */ -/* Copyright (C) 2017 by Mygod Studio */ -/* */ -/* 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 . */ -/* */ -/*******************************************************************************/ - -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) -}