From 37871f39cacbd7a40f84756fa88fbc08d5986080 Mon Sep 17 00:00:00 2001 From: tom79 Date: Thu, 3 Oct 2019 19:42:04 +0200 Subject: [PATCH] Some improvements with instance health + allow to disable live notification for accounts in a same modal --- app/src/main/AndroidManifest.xml | 6 + .../activities/InstanceHealthActivity.java | 43 +++----- ...eNotificationSettingsAccountsActivity.java | 103 +++++++++++++++++ .../java/app/fedilab/android/client/API.java | 4 +- .../android/drawers/AccountLiveAdapter.java | 104 ++++++++++++++++++ .../fragments/ContentSettingsFragment.java | 8 ++ .../res/drawable/ic_account_circle_acct.xml | 5 + .../res/layout/activity_instance_social.xml | 26 +++-- ...ctivity_livenotifications_all_accounts.xml | 17 +++ .../drawer_account_notification_settings.xml | 19 ++++ .../res/layout/fragment_settings_reveal.xml | 23 +++- 11 files changed, 321 insertions(+), 37 deletions(-) create mode 100644 app/src/main/java/app/fedilab/android/activities/LiveNotificationSettingsAccountsActivity.java create mode 100644 app/src/main/java/app/fedilab/android/drawers/AccountLiveAdapter.java create mode 100644 app/src/main/res/drawable/ic_account_circle_acct.xml create mode 100644 app/src/main/res/layout/activity_livenotifications_all_accounts.xml create mode 100644 app/src/main/res/layout/drawer_account_notification_settings.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 47c853ed6..bbdddaec9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -443,6 +443,12 @@ android:windowSoftInputMode="stateAlwaysHidden" android:configChanges="orientation|screenSize" android:label="@string/app_name" /> + 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() { - @Override - public void onResourceReady(Bitmap resource, Transition 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!"); diff --git a/app/src/main/java/app/fedilab/android/activities/LiveNotificationSettingsAccountsActivity.java b/app/src/main/java/app/fedilab/android/activities/LiveNotificationSettingsAccountsActivity.java new file mode 100644 index 000000000..83ec57863 --- /dev/null +++ b/app/src/main/java/app/fedilab/android/activities/LiveNotificationSettingsAccountsActivity.java @@ -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 . */ +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 accounts = new ArrayList<>(); + SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + List 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); + } + + +} diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java index a049be7e2..068313261 100644 --- a/app/src/main/java/app/fedilab/android/client/API.java +++ b/app/src/main/java/app/fedilab/android/client/API.java @@ -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())); diff --git a/app/src/main/java/app/fedilab/android/drawers/AccountLiveAdapter.java b/app/src/main/java/app/fedilab/android/drawers/AccountLiveAdapter.java new file mode 100644 index 000000000..8ff6e9bd0 --- /dev/null +++ b/app/src/main/java/app/fedilab/android/drawers/AccountLiveAdapter.java @@ -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 . */ + + +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 accounts; + + public AccountLiveAdapter(List 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); + } + } + + +} \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java b/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java index a6ce979cb..e7c3dde05 100644 --- a/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java +++ b/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java @@ -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); diff --git a/app/src/main/res/drawable/ic_account_circle_acct.xml b/app/src/main/res/drawable/ic_account_circle_acct.xml new file mode 100644 index 000000000..38d58a889 --- /dev/null +++ b/app/src/main/res/drawable/ic_account_circle_acct.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_instance_social.xml b/app/src/main/res/layout/activity_instance_social.xml index a835d9477..2bbf74f81 100644 --- a/app/src/main/res/layout/activity_instance_social.xml +++ b/app/src/main/res/layout/activity_instance_social.xml @@ -1,17 +1,16 @@ - @@ -19,7 +18,7 @@ @@ -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"> - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_livenotifications_all_accounts.xml b/app/src/main/res/layout/activity_livenotifications_all_accounts.xml new file mode 100644 index 000000000..230463d44 --- /dev/null +++ b/app/src/main/res/layout/activity_livenotifications_all_accounts.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/drawer_account_notification_settings.xml b/app/src/main/res/layout/drawer_account_notification_settings.xml new file mode 100644 index 000000000..42b09ba13 --- /dev/null +++ b/app/src/main/res/layout/drawer_account_notification_settings.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_settings_reveal.xml b/app/src/main/res/layout/fragment_settings_reveal.xml index 637be5fd4..7be3dae98 100644 --- a/app/src/main/res/layout/fragment_settings_reveal.xml +++ b/app/src/main/res/layout/fragment_settings_reveal.xml @@ -794,11 +794,26 @@ android:textColor="@color/mastodonC2" android:textSize="12sp" /> - - + android:layout_height="wrap_content" + android:orientation="vertical"> + + + + +