Some improvements with instance health + allow to disable live notification for accounts in a same modal

This commit is contained in:
tom79 2019-10-03 19:42:04 +02:00
parent bd7107042e
commit 37871f39ca
11 changed files with 321 additions and 37 deletions

View File

@ -443,6 +443,12 @@
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.LiveNotificationSettingsAccountsActivity"
android:theme="@style/Base.V7.Theme.AppCompat.Dialog"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" />
<activity
android:name="app.fedilab.android.activities.MutedInstanceActivity"
android:windowSoftInputMode="stateAlwaysHidden"

View File

@ -34,11 +34,13 @@ import androidx.core.content.ContextCompat;
import android.text.SpannableString;
import android.text.style.UnderlineSpan;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
@ -48,6 +50,7 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
import java.util.HashMap;
@ -69,7 +72,9 @@ public class InstanceHealthActivity extends BaseActivity {
private InstanceSocial instanceSocial;
private TextView name, values, checked_at, up, uptime;
private String instance;
private LinearLayout container, instance_container;
private RelativeLayout container;
private LinearLayout instance_container;
private ImageView back_ground_image;
private RelativeLayout loader;
@Override
@ -80,19 +85,23 @@ public class InstanceHealthActivity extends BaseActivity {
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme);
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(InstanceHealthActivity.this, R.color.mastodonC3__));
break;
case Helper.THEME_DARK:
setTheme(R.style.AppThemeDark);
setTheme(R.style.AppThemeDark_NoActionBar);
getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(InstanceHealthActivity.this, R.color.mastodonC1));
break;
case Helper.THEME_BLACK:
setTheme(R.style.AppThemeBlack);
setTheme(R.style.AppThemeBlack_NoActionBar);
getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(InstanceHealthActivity.this, R.color.black_3));
break;
default:
setTheme(R.style.AppThemeDark);
setTheme(R.style.AppThemeDark_NoActionBar);
getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(InstanceHealthActivity.this, R.color.mastodonC1));
}
setContentView(R.layout.activity_instance_social);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
Bundle b = getIntent().getExtras();
if (getSupportActionBar() != null)
getSupportActionBar().hide();
@ -109,7 +118,7 @@ public class InstanceHealthActivity extends BaseActivity {
container = findViewById(R.id.container);
instance_container = findViewById(R.id.instance_container);
loader = findViewById(R.id.loader);
back_ground_image = findViewById(R.id.back_ground_image);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -155,6 +164,7 @@ public class InstanceHealthActivity extends BaseActivity {
HashMap<String, String> parameters = new HashMap<>();
parameters.put("name", instance.trim());
final String response = new HttpsConnection(InstanceHealthActivity.this, instance).get("https://instances.social/api/1.0/instances/show", 30, parameters, Helper.THEKINRAR_SECRET_TOKEN);
Log.v(Helper.TAG,"response: " + response);
if (response != null)
instanceSocial = API.parseInstanceSocialResponse(getApplicationContext(), new JSONObject(response));
runOnUiThread(new Runnable() {
@ -164,24 +174,7 @@ public class InstanceHealthActivity extends BaseActivity {
Glide.with(getApplicationContext())
.asBitmap()
.load(instanceSocial.getThumbnail())
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
Bitmap workingBitmap = Bitmap.createBitmap(resource);
Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(mutableBitmap);
Paint p = new Paint(Color.BLACK);
ColorFilter filter = new LightingColorFilter(0xFF7F7F7F, 0x00000000);
p.setColorFilter(filter);
canvas.drawBitmap(mutableBitmap, new Matrix(), p);
BitmapDrawable background = new BitmapDrawable(getResources(), mutableBitmap);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
container.setBackground(background);
} else {
container.setBackgroundDrawable(background);
}
}
});
.into(back_ground_image);
name.setText(instanceSocial.getName());
if (instanceSocial.isUp()) {
up.setText("Is up!");

View File

@ -0,0 +1,103 @@
/* 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>. */
package app.fedilab.android.activities;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.view.Window;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import app.fedilab.android.R;
import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.drawers.AccountLiveAdapter;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.sqlite.AccountDAO;
import app.fedilab.android.sqlite.Sqlite;
/**
* Created by Thomas on 03/10/2019.
* Manage live notifications for accounts
*/
public class LiveNotificationSettingsAccountsActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_NoActionBar_Fedilab);
getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(LiveNotificationSettingsAccountsActivity.this, R.color.mastodonC3__));
break;
case Helper.THEME_DARK:
setTheme(R.style.AppThemeDark_NoActionBar);
getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(LiveNotificationSettingsAccountsActivity.this, R.color.mastodonC1));
break;
case Helper.THEME_BLACK:
setTheme(R.style.AppThemeBlack_NoActionBar);
getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(LiveNotificationSettingsAccountsActivity.this, R.color.black_3));
break;
default:
setTheme(R.style.AppThemeDark_NoActionBar);
getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(LiveNotificationSettingsAccountsActivity.this, R.color.mastodonC1));
}
setContentView(R.layout.activity_livenotifications_all_accounts);
getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
if (getSupportActionBar() != null)
getSupportActionBar().hide();
RecyclerView list_of_accounts = findViewById(R.id.list_of_accounts);
ArrayList<Account> accounts = new ArrayList<>();
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<Account> accountStreams = new AccountDAO(getApplicationContext(), db).getAllAccountCrossAction();
for (Account account : accountStreams) {
if (account.getSocial() == null || account.getSocial().equals("MASTODON") || account.getSocial().equals("PLEROMA") || account.getSocial().equals("PIXELFED")) {
accounts.add(account);
}
}
AccountLiveAdapter accountLiveAdapter = new AccountLiveAdapter(accounts);
list_of_accounts.setAdapter(accountLiveAdapter);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
list_of_accounts.setLayoutManager(mLayoutManager);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -4486,7 +4486,9 @@ public class API {
instanceSocial.setHttps_rank(resobj.get("https_rank").toString());
instanceSocial.setHttps_score(Integer.parseInt(resobj.get("https_score").toString()));
instanceSocial.setAdded_at(Helper.mstStringToDate(context, resobj.get("added_at").toString()));
if( !resobj.isNull("added_at")) {
instanceSocial.setAdded_at(Helper.mstStringToDate(context, resobj.get("added_at").toString()));
}
instanceSocial.setChecked_at(Helper.mstStringToDate(context, resobj.get("checked_at").toString()));
instanceSocial.setUpdated_at(Helper.mstStringToDate(context, resobj.get("updated_at").toString()));

View File

@ -0,0 +1,104 @@
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;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.SwitchCompat;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import app.fedilab.android.R;
import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.services.LiveNotificationDelayedService;
import static android.content.Context.MODE_PRIVATE;
/**
* Created by Thomas on 03/10/2019
* Adapter for accounts and live notifications
*/
public class AccountLiveAdapter extends RecyclerView.Adapter {
private Context context;
private List<Account> accounts;
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;
holder.account_acct.setText(accounts.get(i).getUsername() + "@" + accounts.get(i).getInstance());
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);
holder.account_acct_live_notifications.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View 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();
if (holder.account_acct_live_notifications.isChecked()) {
LiveNotificationDelayedService.totalAccount++;
} else {
LiveNotificationDelayedService.totalAccount--;
}
}
});
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return accounts.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
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);
}
}
}

View File

@ -77,6 +77,7 @@ import java.util.Set;
import app.fedilab.android.R;
import app.fedilab.android.activities.BaseMainActivity;
import app.fedilab.android.activities.LiveNotificationSettingsAccountsActivity;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.activities.SettingsActivity;
import app.fedilab.android.asynctasks.DownloadTrackingDomainsAsyncTask;
@ -1724,6 +1725,12 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
}
});
final ImageButton set_allow_live_notifications_others = rootView.findViewById(R.id.set_allow_live_notifications_others);
set_allow_live_notifications_others.setOnClickListener(view -> {
Intent intent = new Intent(context, LiveNotificationSettingsAccountsActivity.class);
startActivity(intent);
});
boolean trans_forced = sharedpreferences.getBoolean(Helper.SET_TRANS_FORCED, false);
final CheckBox set_trans_forced = rootView.findViewById(R.id.set_trans_forced);
set_trans_forced.setChecked(trans_forced);
@ -1920,6 +1927,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
final Button sound_backup = rootView.findViewById(R.id.sound_backup);
final Button sound_media = rootView.findViewById(R.id.sound_media);
final ImageButton set_hide_status_bar = rootView.findViewById(R.id.set_hide_status_bar);
Button set_notif_sound = rootView.findViewById(R.id.set_notif_sound);
settings_time_from.setText(time_from);
settings_time_to.setText(time_to);

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,5c1.66,0 3,1.34 3,3s-1.34,3 -3,3 -3,-1.34 -3,-3 1.34,-3 3,-3zM12,19.2c-2.5,0 -4.71,-1.28 -6,-3.22 0.03,-1.99 4,-3.08 6,-3.08 1.99,0 5.97,1.09 6,3.08 -1.29,1.94 -3.5,3.22 -6,3.22z"/>
</vector>

View File

@ -1,17 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:fitsSystemWindows="true"
tools:context="app.fedilab.android.activities.InstanceHealthActivity"
android:layout_margin="@dimen/fab_margin"
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="300dp">
<LinearLayout
android:id="@+id/instance_container"
android:visibility="gone"
android:layout_margin="@dimen/fab_margin"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -19,7 +18,7 @@
<TextView
android:id="@+id/name"
android:textSize="20sp"
android:textColor="@color/titleb"
android:textColor="@color/mastodonC3"
android:layout_gravity="center"
android:gravity="center"
android:layout_width="wrap_content"
@ -80,7 +79,7 @@
android:layout_gravity="center"
android:textAllCaps="false"
android:text="@string/close"
android:textColor="@color/buttonb"
android:textColor="@color/mastodonC4"
style="?attr/borderlessColored"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
@ -90,6 +89,7 @@
android:id="@+id/loader"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center">
<ProgressBar
@ -97,4 +97,16 @@
android:layout_height="wrap_content"
android:indeterminate="true" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.2"
>
<ImageView
android:id="@+id/back_ground_image"
android:scaleType="centerCrop"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
</RelativeLayout>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:fitsSystemWindows="true"
tools:context="app.fedilab.android.activities.InstanceHealthActivity"
android:layout_margin="@dimen/fab_margin"
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list_of_accounts"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

View File

@ -0,0 +1,19 @@
<?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="wrap_content"
android:layout_margin="@dimen/activity_vertical_margin"
android:orientation="horizontal">
<TextView
android:id="@+id/account_acct"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:textSize="16sp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/account_acct_live_notifications"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -794,11 +794,26 @@
android:textColor="@color/mastodonC2"
android:textSize="12sp" />
</LinearLayout>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/set_allow_live_notifications"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/set_allow_live_notifications"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageButton
android:id="@+id/set_allow_live_notifications_others"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end"
android:contentDescription="@string/bookmark_add"
android:padding="5dp"
android:src="@drawable/ic_account_circle_acct" />
</LinearLayout>
</LinearLayout>