2019-10-03 19:42:04 +02:00
|
|
|
package app.fedilab.android.drawers;
|
|
|
|
/* Copyright 2019 Thomas Schneider
|
|
|
|
*
|
|
|
|
* This file is a part of Fedilab
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Fedilab 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 Fedilab; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.TextView;
|
2019-11-15 16:32:25 +01:00
|
|
|
|
2019-10-03 19:42:04 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.widget.SwitchCompat;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2019-11-15 16:32:25 +01:00
|
|
|
|
2019-10-03 19:42:04 +02:00
|
|
|
import java.util.List;
|
2019-11-15 16:32:25 +01:00
|
|
|
|
2019-10-03 19:42:04 +02:00
|
|
|
import app.fedilab.android.R;
|
|
|
|
import app.fedilab.android.client.Entities.Account;
|
|
|
|
import app.fedilab.android.helper.Helper;
|
2019-10-13 18:41:47 +02:00
|
|
|
|
2019-10-03 19:42:04 +02:00
|
|
|
import static android.content.Context.MODE_PRIVATE;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 03/10/2019
|
|
|
|
* Adapter for accounts and live notifications
|
|
|
|
*/
|
2020-06-16 18:23:13 +02:00
|
|
|
public class AccountLiveAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
2019-10-03 19:42:04 +02:00
|
|
|
|
|
|
|
private Context context;
|
2021-01-19 17:43:51 +01:00
|
|
|
private final List<Account> accounts;
|
2019-10-03 19:42:04 +02:00
|
|
|
|
|
|
|
public AccountLiveAdapter(List<Account> accounts) {
|
|
|
|
this.accounts = accounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
|
|
|
|
context = parent.getContext();
|
|
|
|
LayoutInflater layoutInflater = LayoutInflater.from(context);
|
|
|
|
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_account_notification_settings, parent, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
|
|
|
|
|
|
|
|
ViewHolder holder = (ViewHolder) viewHolder;
|
2020-03-07 14:16:28 +01:00
|
|
|
String name = accounts.get(i).getUsername() + "@" + accounts.get(i).getInstance();
|
|
|
|
holder.account_acct.setText(name);
|
2019-10-03 19:42:04 +02:00
|
|
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
|
|
|
boolean allowStream = sharedpreferences.getBoolean(Helper.SET_ALLOW_STREAM + accounts.get(i).getId() + accounts.get(i).getInstance(), true);
|
|
|
|
|
|
|
|
holder.account_acct_live_notifications.setChecked(allowStream);
|
2020-03-07 14:16:28 +01:00
|
|
|
holder.account_acct_live_notifications.setOnClickListener(v -> {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(Helper.SET_ALLOW_STREAM + accounts.get(i).getId() + accounts.get(i).getInstance(), holder.account_acct_live_notifications.isChecked());
|
|
|
|
editor.apply();
|
2019-10-03 19:42:04 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return accounts.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-07 14:16:28 +01:00
|
|
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
2019-10-03 19:42:04 +02:00
|
|
|
TextView account_acct;
|
|
|
|
SwitchCompat account_acct_live_notifications;
|
|
|
|
|
|
|
|
public ViewHolder(@NonNull View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
account_acct = itemView.findViewById(R.id.account_acct);
|
|
|
|
account_acct_live_notifications = itemView.findViewById(R.id.account_acct_live_notifications);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|