mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-25 15:23:52 +00:00
[android] Migrate bookmarks layouts to Material Components
Signed-off-by: Jean-Baptiste Charron <jeanbaptiste.charron@outlook.fr>
This commit is contained in:
committed by
Konstantin Pastbin
parent
b31819fcfb
commit
8db9289b56
@@ -11,7 +11,6 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -172,7 +171,7 @@ public class BookmarkCategorySettingsFragment extends BaseMwmToolbarFragment
|
||||
return !TextUtils.equals(mCategory.getDescription(), categoryDesc);
|
||||
}
|
||||
|
||||
private void clearAndFocus(TextView textView)
|
||||
private void clearAndFocus(TextInputEditText textView)
|
||||
{
|
||||
textView.getEditableText().clear();
|
||||
textView.requestFocus();
|
||||
|
||||
@@ -4,12 +4,13 @@ import android.content.res.Resources;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.textview.MaterialTextView;
|
||||
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.bookmarks.data.BookmarkCategory;
|
||||
import app.organicmaps.bookmarks.data.BookmarkInfo;
|
||||
@@ -439,14 +440,14 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
||||
holder = bookmarkHolder;
|
||||
break;
|
||||
case TYPE_SECTION:
|
||||
TextView tv = (TextView) inflater.inflate(R.layout.item_category_title, parent, false);
|
||||
MaterialTextView tv = (MaterialTextView) inflater.inflate(R.layout.item_category_title, parent, false);
|
||||
holder = new Holders.SectionViewHolder(tv);
|
||||
break;
|
||||
case TYPE_DESC:
|
||||
View desc = inflater.inflate(R.layout.item_category_description, parent, false);
|
||||
TextView moreBtn = desc.findViewById(R.id.more_btn);
|
||||
TextView text = desc.findViewById(R.id.text);
|
||||
TextView title = desc.findViewById(R.id.title);
|
||||
MaterialTextView moreBtn = desc.findViewById(R.id.more_btn);
|
||||
MaterialTextView text = desc.findViewById(R.id.text);
|
||||
MaterialTextView title = desc.findViewById(R.id.title);
|
||||
setMoreButtonVisibility(text, moreBtn);
|
||||
holder = new Holders.DescriptionViewHolder(desc, mSectionsDataSource.getCategory());
|
||||
text.setOnClickListener(v -> onMoreButtonClicked(text, moreBtn));
|
||||
@@ -537,12 +538,12 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
||||
}
|
||||
}
|
||||
|
||||
private void setMoreButtonVisibility(TextView text, TextView moreBtn)
|
||||
private void setMoreButtonVisibility(MaterialTextView text, MaterialTextView moreBtn)
|
||||
{
|
||||
text.post(() -> setShortModeDescription(text, moreBtn));
|
||||
}
|
||||
|
||||
private void onMoreButtonClicked(TextView textView, TextView moreBtn)
|
||||
private void onMoreButtonClicked(MaterialTextView textView, MaterialTextView moreBtn)
|
||||
{
|
||||
if (isShortModeDescription(textView))
|
||||
{
|
||||
@@ -554,18 +555,18 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isShortModeDescription(TextView text)
|
||||
private boolean isShortModeDescription(MaterialTextView text)
|
||||
{
|
||||
return text.getMaxLines() == MAX_VISIBLE_LINES;
|
||||
}
|
||||
|
||||
private void setExpandedModeDescription(TextView textView, TextView moreBtn)
|
||||
private void setExpandedModeDescription(MaterialTextView textView, MaterialTextView moreBtn)
|
||||
{
|
||||
textView.setMaxLines(Integer.MAX_VALUE);
|
||||
moreBtn.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void setShortModeDescription(TextView textView, TextView moreBtn)
|
||||
private void setShortModeDescription(MaterialTextView textView, MaterialTextView moreBtn)
|
||||
{
|
||||
textView.setMaxLines(MAX_VISIBLE_LINES);
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
@@ -53,6 +52,7 @@ import app.organicmaps.widget.placepage.BookmarkColorDialogFragment;
|
||||
import app.organicmaps.widget.placepage.EditBookmarkFragment;
|
||||
import app.organicmaps.widget.recycler.DividerItemDecorationWithPadding;
|
||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
|
||||
import com.google.android.material.imageview.ShapeableImageView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -599,7 +599,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<ConcatAdapter
|
||||
i.putExtra(MwmActivity.EXTRA_BOOKMARK_ID, bookmark.getBookmarkId());
|
||||
}
|
||||
|
||||
private void showColorDialog(ImageView v, int position)
|
||||
private void showColorDialog(ShapeableImageView v, int position)
|
||||
{
|
||||
BookmarkListAdapter adapter = getBookmarkListAdapter();
|
||||
|
||||
|
||||
@@ -4,12 +4,13 @@ import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.radiobutton.MaterialRadioButton;
|
||||
import com.google.android.material.textview.MaterialTextView;
|
||||
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.bookmarks.data.BookmarkCategory;
|
||||
|
||||
@@ -101,8 +102,8 @@ public class ChooseBookmarkCategoryAdapter extends BaseBookmarkCategoryAdapter<C
|
||||
|
||||
static class SingleChoiceHolder extends RecyclerView.ViewHolder
|
||||
{
|
||||
TextView name;
|
||||
RadioButton checked;
|
||||
MaterialTextView name;
|
||||
MaterialRadioButton checked;
|
||||
|
||||
public SingleChoiceHolder(View convertView)
|
||||
{
|
||||
|
||||
@@ -6,15 +6,16 @@ import android.location.Location;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.PluralsRes;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.imageview.ShapeableImageView;
|
||||
import com.google.android.material.textview.MaterialTextView;
|
||||
import com.google.android.material.checkbox.MaterialCheckBox;
|
||||
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.adapter.OnItemClickListener;
|
||||
import app.organicmaps.bookmarks.data.BookmarkCategory;
|
||||
@@ -34,9 +35,9 @@ public class Holders
|
||||
public static class GeneralViewHolder extends RecyclerView.ViewHolder
|
||||
{
|
||||
@NonNull
|
||||
private final TextView mText;
|
||||
private final MaterialTextView mText;
|
||||
@NonNull
|
||||
private final ImageView mImage;
|
||||
private final ShapeableImageView mImage;
|
||||
|
||||
GeneralViewHolder(@NonNull View itemView)
|
||||
{
|
||||
@@ -46,13 +47,13 @@ public class Holders
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public TextView getText()
|
||||
public MaterialTextView getText()
|
||||
{
|
||||
return mText;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ImageView getImage()
|
||||
public ShapeableImageView getImage()
|
||||
{
|
||||
return mImage;
|
||||
}
|
||||
@@ -61,9 +62,9 @@ public class Holders
|
||||
public static class HeaderViewHolder extends RecyclerView.ViewHolder
|
||||
{
|
||||
@NonNull
|
||||
private final TextView mButton;
|
||||
private final MaterialTextView mButton;
|
||||
@NonNull
|
||||
private final TextView mText;
|
||||
private final MaterialTextView mText;
|
||||
|
||||
|
||||
HeaderViewHolder(@NonNull View itemView)
|
||||
@@ -74,13 +75,13 @@ public class Holders
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public TextView getText()
|
||||
public MaterialTextView getText()
|
||||
{
|
||||
return mText;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public TextView getButton()
|
||||
public MaterialTextView getButton()
|
||||
{
|
||||
return mButton;
|
||||
}
|
||||
@@ -168,7 +169,7 @@ public class Holders
|
||||
protected BookmarkCategory mEntity;
|
||||
|
||||
@NonNull
|
||||
protected final TextView mSize;
|
||||
protected final MaterialTextView mSize;
|
||||
|
||||
public CategoryViewHolderBase(@NonNull View root)
|
||||
{
|
||||
@@ -229,9 +230,9 @@ public class Holders
|
||||
@NonNull
|
||||
private final View mView;
|
||||
@NonNull
|
||||
private final TextView mName;
|
||||
private final MaterialTextView mName;
|
||||
@NonNull
|
||||
private final CheckBox mVisibilityMarker;
|
||||
private final MaterialCheckBox mVisibilityMarker;
|
||||
|
||||
CollectionViewHolder(@NonNull View root)
|
||||
{
|
||||
@@ -268,11 +269,11 @@ public class Holders
|
||||
static class CategoryViewHolder extends CategoryViewHolderBase
|
||||
{
|
||||
@NonNull
|
||||
private final TextView mName;
|
||||
private final MaterialTextView mName;
|
||||
@NonNull
|
||||
CheckBox mVisibilityMarker;
|
||||
MaterialCheckBox mVisibilityMarker;
|
||||
@NonNull
|
||||
ImageView mMoreButton;
|
||||
ShapeableImageView mMoreButton;
|
||||
|
||||
CategoryViewHolder(@NonNull View root)
|
||||
{
|
||||
@@ -338,11 +339,11 @@ public class Holders
|
||||
static class BookmarkViewHolder extends BaseBookmarkHolder
|
||||
{
|
||||
@NonNull
|
||||
private final ImageView mIcon;
|
||||
private final ShapeableImageView mIcon;
|
||||
@NonNull
|
||||
private final TextView mName;
|
||||
private final MaterialTextView mName;
|
||||
@NonNull
|
||||
private final TextView mDistance;
|
||||
private final MaterialTextView mDistance;
|
||||
|
||||
BookmarkViewHolder(@NonNull View itemView)
|
||||
{
|
||||
@@ -384,12 +385,12 @@ public class Holders
|
||||
static class TrackViewHolder extends BaseBookmarkHolder
|
||||
{
|
||||
@NonNull
|
||||
private final ImageView mIcon;
|
||||
private final ShapeableImageView mIcon;
|
||||
@NonNull
|
||||
private final TextView mName;
|
||||
private final MaterialTextView mName;
|
||||
@NonNull
|
||||
private final TextView mDistance;
|
||||
private final ImageView mMoreButton;
|
||||
private final MaterialTextView mDistance;
|
||||
private final ShapeableImageView mMoreButton;
|
||||
|
||||
TrackViewHolder(@NonNull View itemView)
|
||||
{
|
||||
@@ -424,16 +425,16 @@ public class Holders
|
||||
|
||||
public void setTrackIconClickListener(IconClickListener listener)
|
||||
{
|
||||
mIcon.setOnClickListener(v -> listener.onItemClick((ImageView) v, getBindingAdapterPosition()));
|
||||
mIcon.setOnClickListener(v -> listener.onItemClick((ShapeableImageView) v, getBindingAdapterPosition()));
|
||||
}
|
||||
}
|
||||
|
||||
public static class SectionViewHolder extends BaseBookmarkHolder
|
||||
{
|
||||
@NonNull
|
||||
private final TextView mView;
|
||||
private final MaterialTextView mView;
|
||||
|
||||
SectionViewHolder(@NonNull TextView itemView)
|
||||
SectionViewHolder(@NonNull MaterialTextView itemView)
|
||||
{
|
||||
super(itemView);
|
||||
mView = itemView;
|
||||
@@ -452,9 +453,9 @@ public class Holders
|
||||
static final float SPACING_MULTIPLE = 1.0f;
|
||||
static final float SPACING_ADD = 0.0f;
|
||||
@NonNull
|
||||
private final TextView mTitle;
|
||||
private final MaterialTextView mTitle;
|
||||
@NonNull
|
||||
private final TextView mDescText;
|
||||
private final MaterialTextView mDescText;
|
||||
|
||||
DescriptionViewHolder(@NonNull View itemView, @NonNull BookmarkCategory category)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,8 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.google.android.material.imageview.ShapeableImageView;
|
||||
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.bookmarks.data.Icon;
|
||||
@@ -61,7 +62,7 @@ public class IconsAdapter extends ArrayAdapter<Icon>
|
||||
|
||||
private static class SpinnerViewHolder
|
||||
{
|
||||
final ImageView icon;
|
||||
final ShapeableImageView icon;
|
||||
|
||||
SpinnerViewHolder(View convertView)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package app.organicmaps.bookmarks.data;
|
||||
|
||||
import android.widget.ImageView;
|
||||
import com.google.android.material.imageview.ShapeableImageView;
|
||||
|
||||
public interface IconClickListener
|
||||
{
|
||||
void onItemClick(ImageView v, int position);
|
||||
void onItemClick(ShapeableImageView v, int position);
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -34,8 +32,10 @@ import app.organicmaps.util.UiUtils;
|
||||
import app.organicmaps.util.WindowInsetUtils.PaddingInsetsListener;
|
||||
|
||||
import com.google.android.material.appbar.MaterialToolbar;
|
||||
import com.google.android.material.imageview.ShapeableImageView;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import com.google.android.material.textview.MaterialTextView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -54,8 +54,8 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
||||
private TextInputEditText mEtName;
|
||||
@NonNull
|
||||
private TextInputLayout clearNameBtn;
|
||||
private TextView mTvBookmarkGroup;
|
||||
private ImageView mIvColor;
|
||||
private MaterialTextView mTvBookmarkGroup;
|
||||
private ShapeableImageView mIvColor;
|
||||
private BookmarkCategory mBookmarkCategory;
|
||||
@Nullable
|
||||
private Icon mIcon;
|
||||
@@ -208,7 +208,7 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(toolbar, PaddingInsetsListener.excludeBottom());
|
||||
|
||||
final ImageView imageView = toolbar.findViewById(R.id.save);
|
||||
final ShapeableImageView imageView = toolbar.findViewById(R.id.save);
|
||||
switch (mType)
|
||||
{
|
||||
case TYPE_BOOKMARK ->
|
||||
@@ -412,7 +412,7 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
private void clearAndFocus(TextView textView)
|
||||
private void clearAndFocus(TextInputEditText textView)
|
||||
{
|
||||
textView.getEditableText().clear();
|
||||
textView.requestFocus();
|
||||
|
||||
Reference in New Issue
Block a user