Commit ab5d82b8 authored by Adrien Béraud's avatar Adrien Béraud Committed by Sébastien Blin
Browse files

settings: cleanup

Change-Id: I59104880e7c6dc0657ed2629a81835bbf75be339
parent fdf5ded0
......@@ -31,14 +31,6 @@ import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.TextUtils;
......@@ -51,16 +43,27 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import net.jami.account.JamiAccountSummaryPresenter;
import net.jami.account.JamiAccountSummaryView;
import net.jami.model.Account;
import net.jami.utils.StringUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import cx.ring.R;
import cx.ring.application.JamiApplication;
import cx.ring.client.HomeActivity;
......@@ -71,17 +74,12 @@ import cx.ring.fragments.GeneralAccountFragment;
import cx.ring.fragments.LinkDeviceFragment;
import cx.ring.fragments.MediaPreferenceFragment;
import cx.ring.fragments.QRCodeFragment;
import net.jami.account.JamiAccountSummaryPresenter;
import net.jami.account.JamiAccountSummaryView;
import net.jami.model.Account;
import cx.ring.mvp.BaseSupportFragment;
import cx.ring.settings.AccountFragment;
import cx.ring.settings.SettingsFragment;
import cx.ring.utils.AndroidFileUtils;
import cx.ring.utils.BitmapUtils;
import cx.ring.utils.ContentUriHandler;
import net.jami.utils.StringUtils;
import cx.ring.views.AvatarDrawable;
import cx.ring.views.SwitchButton;
import io.reactivex.Single;
......@@ -106,10 +104,6 @@ public class JamiAccountSummaryFragment extends BaseSupportFragment<JamiAccountS
private static final String FRAGMENT_DIALOG_BACKUP = TAG + ".dialog.backup";
private static final int WRITE_REQUEST_CODE = 43;
private static final int SCROLL_DIRECTION_UP = -1;
private static final int SETTINGS_ACCOUNT = 0;
private static final int SETTINGS_MEDIA = 1;
private static final int SETTINGS_SYSTEM = 2;
private static final int SETTINGS_ADVANCED = 3;
private final OnBackPressedCallback mOnBackPressedCallback = new OnBackPressedCallback(false) {
@Override
......@@ -180,35 +174,15 @@ public class JamiAccountSummaryFragment extends BaseSupportFragment<JamiAccountS
mBinding.linkedDevices.setRightDrawableOnClickListener(v -> onDeviceRename());
mBinding.registerName.setOnClickListener(v -> showUsernameRegistrationPopup());
List<SettingItem> items = new ArrayList<>();
SettingItem accountItem = new SettingItem(R.string.account, R.drawable.baseline_account_card_details);
SettingItem mediaItem = new SettingItem(R.string.account_preferences_media_tab, R.drawable.outline_file_copy_24);
SettingItem systemItem = new SettingItem(R.string.notif_channel_messages, R.drawable.baseline_chat_24);
SettingItem advancedItem = new SettingItem(R.string.account_preferences_advanced_tab, R.drawable.round_check_circle_24);
items.add(accountItem);
items.add(mediaItem);
items.add(systemItem);
items.add(advancedItem);
List<SettingItem> items = new ArrayList<>(4);
items.add(new SettingItem(R.string.account, R.drawable.baseline_account_card_details, () -> presenter.goToAccount()));
items.add(new SettingItem(R.string.account_preferences_media_tab, R.drawable.outline_file_copy_24, () -> presenter.goToMedia()));
items.add(new SettingItem(R.string.notif_channel_messages, R.drawable.baseline_chat_24, () -> presenter.goToSystem()));
items.add(new SettingItem(R.string.account_preferences_advanced_tab, R.drawable.round_check_circle_24, () -> presenter.goToAdvanced()));
SettingsAdapter adapter = new SettingsAdapter(view.getContext(), R.layout.item_setting, items);
mBinding.settingsList.setOnItemClickListener((adapterView, v, i, l) -> adapter.getItem(i).onClick());
mBinding.settingsList.setAdapter(adapter);
mBinding.settingsList.setOnItemClickListener((adapterView, v, i, l) -> {
switch (i) {
case SETTINGS_ACCOUNT:
presenter.goToAccount();
break;
case SETTINGS_MEDIA:
presenter.goToMedia();
break;
case SETTINGS_SYSTEM:
presenter.goToSystem();
break;
case SETTINGS_ADVANCED:
presenter.goToAdvanced();
break;
}
});
int totalHeight = 0;
for (int i = 0; i < adapter.getCount(); i++) {
......
package cx.ring.account;
public class SettingItem {
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
private int mTitleRes;
private int mImageId;
public class SettingItem {
private final int mTitleRes;
private final int mImageId;
private final Runnable mOnClick;
public SettingItem(int titleRes, int imageId) {
public SettingItem(@StringRes int titleRes, @DrawableRes int imageId, @NonNull Runnable onClick) {
mTitleRes = titleRes;
mImageId = imageId;
mOnClick = onClick;
}
public int getTitleRes() {
public @StringRes int getTitleRes() {
return mTitleRes;
}
public void setTitleRes(int titleRes) {
mTitleRes = titleRes;
}
public int getImageId() {
public @DrawableRes int getImageId() {
return mImageId;
}
public void setImageId(int imageId) {
mImageId = imageId;
public void onClick() {
mOnClick.run();
}
}
/*
* Copyright (C) 2004-2021 Savoir-faire Linux Inc.
*
* 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 cx.ring.account;
import android.app.Activity;
......@@ -6,53 +22,31 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.annotation.Nullable;
import java.util.List;
import cx.ring.R;
import cx.ring.databinding.ItemSettingBinding;
public class SettingsAdapter extends ArrayAdapter<SettingItem> {
private Context mContext;
public SettingsAdapter(@NonNull Context context, int resource, @NonNull List<SettingItem> objects) {
super(context, resource, objects);
mContext = context;
}
private class ViewHolder {
TextView title;
ImageView icon;
FloatingActionButton fab;
}
public View getView(int position, View view, ViewGroup parent) {
ViewHolder holder = null;
SettingItem item = getItem(position);
LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
public View getView(int position, @Nullable View view, ViewGroup parent) {
ItemSettingBinding binding;
if (view == null) {
view = mInflater.inflate(R.layout.item_setting, null);
holder = new ViewHolder();
holder.title = view.findViewById(R.id.title);
holder.icon = view.findViewById(R.id.icon);
view.setTag(holder);
binding = ItemSettingBinding.inflate((LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE));
view = binding.getRoot();
view.setTag(binding);
} else
holder = (ViewHolder) view.getTag();
holder.title.setText(mContext.getString(item.getTitleRes()));
holder.icon.setImageResource(item.getImageId());
holder.icon.setColorFilter(ContextCompat.getColor(mContext, R.color.white),
android.graphics.PorterDuff.Mode.SRC_IN);
binding = (ItemSettingBinding) view.getTag();
SettingItem item = getItem(position);
binding.title.setText(getContext().getString(item.getTitleRes()));
binding.icon.setImageResource(item.getImageId());
return view;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="12dp">
......@@ -13,7 +15,9 @@
android:background="@drawable/item_settings_icon_background"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:padding="5dp"/>
android:padding="5dp"
app:tint="@color/white"
tools:src="@drawable/round_check_circle_24"/>
<TextView
android:id="@+id/title"
......@@ -22,6 +26,7 @@
android:textColor="@color/text_color"
android:textStyle="bold"
android:textSize="18sp"
android:layout_marginStart="4dp"/>
android:layout_marginStart="4dp"
tools:text="@string/account_preferences_advanced_tab"/>
</LinearLayout>
\ No newline at end of file
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