diff --git a/app/build.gradle b/app/build.gradle index d72feae38..8a5a95cac 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.3" + compileSdkVersion 26 + buildToolsVersion "26.0.2" defaultConfig { applicationId "fr.gouv.etalab.mastodon" minSdkVersion 15 - targetSdkVersion 25 + targetSdkVersion 26 versionCode 55 versionName "1.4.9-beta-7" } @@ -31,10 +31,10 @@ allprojects { } } dependencies { - compile 'com.android.support:appcompat-v7:25.4.0' - compile 'com.android.support:design:25.4.0' - compile 'com.android.support:support-v4:25.4.0' - compile 'com.android.support:cardview-v7:25.4.0' + compile 'com.android.support:appcompat-v7:26.0.2' + compile 'com.android.support:design:26.0.2' + compile 'com.android.support:support-v4:26.0.2' + compile 'com.android.support:cardview-v7:26.0.2' compile 'com.loopj.android:android-async-http:1.4.9' compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' compile 'com.evernote:android-job:1.1.11' diff --git a/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java b/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java index 232db4ac2..b70bddef0 100644 --- a/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java +++ b/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java @@ -42,6 +42,7 @@ import android.support.v7.widget.SwitchCompat; import android.util.Patterns; import android.view.Gravity; import android.view.LayoutInflater; +import android.view.Menu; import android.view.View; import android.support.design.widget.NavigationView; import android.support.v4.view.GravityCompat; @@ -139,6 +140,7 @@ public class MainActivity extends AppCompatActivity private String userIdService; private Intent streamingIntent; public static String lastHomeId = null, lastNotificationId = null; + boolean notif_follow, notif_add, notif_mention, notif_share; public MainActivity() { } @@ -224,6 +226,89 @@ public class MainActivity extends AppCompatActivity tabLayout.addTab(tabLocal); if( display_global) tabLayout.addTab(tabPublic); + //Display filter for notification when long pressing the tab + final LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0); + tabStrip.getChildAt(1).setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + //Only shown if the tab has focus + if( notificationsFragment != null && notificationsFragment.getUserVisibleHint()){ + PopupMenu popup = new PopupMenu(MainActivity.this, tabStrip.getChildAt(1)); + popup.getMenuInflater() + .inflate(R.menu.option_filter_notifications, popup.getMenu()); + Menu menu = popup.getMenu(); + final MenuItem itemFavourite = menu.findItem(R.id.action_favorite); + final MenuItem itemFollow = menu.findItem(R.id.action_follow); + final MenuItem itemMention = menu.findItem(R.id.action_mention); + final MenuItem itemBoost = menu.findItem(R.id.action_boost); + notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true); + notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true); + notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true); + notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true); + itemFavourite.setChecked(notif_add); + itemFollow.setChecked(notif_follow); + itemMention.setChecked(notif_mention); + itemBoost.setChecked(notif_share); + popup.setOnDismissListener(new PopupMenu.OnDismissListener() { + @Override + public void onDismiss(PopupMenu menu) { + if( notificationsFragment != null) + notificationsFragment.refreshAll(); + } + }); + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + public boolean onMenuItemClick(MenuItem item) { + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); + item.setActionView(new View(getApplicationContext())); + item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { + @Override + public boolean onMenuItemActionExpand(MenuItem item) { + return false; + } + + @Override + public boolean onMenuItemActionCollapse(MenuItem item) { + return false; + } + }); + switch (item.getItemId()) { + case R.id.action_favorite: + SharedPreferences.Editor editor = sharedpreferences.edit(); + notif_add = !notif_add; + editor.putBoolean(Helper.SET_NOTIF_ADD, notif_add); + itemFavourite.setChecked(notif_add); + editor.apply(); + break; + case R.id.action_follow: + editor = sharedpreferences.edit(); + notif_follow = !notif_follow; + editor.putBoolean(Helper.SET_NOTIF_FOLLOW, notif_follow); + itemFollow.setChecked(notif_follow); + editor.apply(); + break; + case R.id.action_mention: + editor = sharedpreferences.edit(); + notif_mention = !notif_mention; + editor.putBoolean(Helper.SET_NOTIF_MENTION, notif_mention); + itemMention.setChecked(notif_mention); + editor.apply(); + break; + case R.id.action_boost: + editor = sharedpreferences.edit(); + notif_share = !notif_share; + editor.putBoolean(Helper.SET_NOTIF_SHARE, notif_share); + itemBoost.setChecked(notif_share); + editor.apply(); + break; + } + return false; + } + }); + popup.show(); + } + return true; + } + }); viewPager = (ViewPager) findViewById(R.id.viewpager); int countPage = 2; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java index 3245b1d53..407ceb596 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java @@ -247,6 +247,18 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve } } + public void refreshAll(){ + if( context == null) + return; + max_id = null; + notifications = new ArrayList<>(); + firstLoad = true; + flag_loading = true; + swiped = true; + MainActivity.countNewNotifications = 0; + asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + public void refresh(Notification notification){ if( context == null) diff --git a/app/src/main/res/menu/option_filter_notifications.xml b/app/src/main/res/menu/option_filter_notifications.xml new file mode 100644 index 000000000..9d91657fd --- /dev/null +++ b/app/src/main/res/menu/option_filter_notifications.xml @@ -0,0 +1,30 @@ + + + + + + + diff --git a/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java b/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java index 6fde91392..f978b0167 100644 --- a/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java +++ b/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java @@ -42,6 +42,7 @@ import android.support.v7.widget.SwitchCompat; import android.util.Patterns; import android.view.Gravity; import android.view.LayoutInflater; +import android.view.Menu; import android.view.View; import android.support.design.widget.NavigationView; import android.support.v4.view.GravityCompat; @@ -142,6 +143,7 @@ public class MainActivity extends AppCompatActivity private String userIdService; private Intent streamingIntent; public static String lastHomeId = null, lastNotificationId = null; + boolean notif_follow, notif_add, notif_mention, notif_share; public MainActivity() { } @@ -227,6 +229,89 @@ public class MainActivity extends AppCompatActivity tabLayout.addTab(tabLocal); if( display_global) tabLayout.addTab(tabPublic); + //Display filter for notification when long pressing the tab + final LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0); + tabStrip.getChildAt(1).setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + //Only shown if the tab has focus + if( notificationsFragment != null && notificationsFragment.getUserVisibleHint()){ + PopupMenu popup = new PopupMenu(MainActivity.this, tabStrip.getChildAt(1)); + popup.getMenuInflater() + .inflate(R.menu.option_filter_notifications, popup.getMenu()); + Menu menu = popup.getMenu(); + final MenuItem itemFavourite = menu.findItem(R.id.action_favorite); + final MenuItem itemFollow = menu.findItem(R.id.action_follow); + final MenuItem itemMention = menu.findItem(R.id.action_mention); + final MenuItem itemBoost = menu.findItem(R.id.action_boost); + notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true); + notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true); + notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true); + notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true); + itemFavourite.setChecked(notif_add); + itemFollow.setChecked(notif_follow); + itemMention.setChecked(notif_mention); + itemBoost.setChecked(notif_share); + popup.setOnDismissListener(new PopupMenu.OnDismissListener() { + @Override + public void onDismiss(PopupMenu menu) { + if( notificationsFragment != null) + notificationsFragment.refreshAll(); + } + }); + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + public boolean onMenuItemClick(MenuItem item) { + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); + item.setActionView(new View(getApplicationContext())); + item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { + @Override + public boolean onMenuItemActionExpand(MenuItem item) { + return false; + } + + @Override + public boolean onMenuItemActionCollapse(MenuItem item) { + return false; + } + }); + switch (item.getItemId()) { + case R.id.action_favorite: + SharedPreferences.Editor editor = sharedpreferences.edit(); + notif_add = !notif_add; + editor.putBoolean(Helper.SET_NOTIF_ADD, notif_add); + itemFavourite.setChecked(notif_add); + editor.apply(); + break; + case R.id.action_follow: + editor = sharedpreferences.edit(); + notif_follow = !notif_follow; + editor.putBoolean(Helper.SET_NOTIF_FOLLOW, notif_follow); + itemFollow.setChecked(notif_follow); + editor.apply(); + break; + case R.id.action_mention: + editor = sharedpreferences.edit(); + notif_mention = !notif_mention; + editor.putBoolean(Helper.SET_NOTIF_MENTION, notif_mention); + itemMention.setChecked(notif_mention); + editor.apply(); + break; + case R.id.action_boost: + editor = sharedpreferences.edit(); + notif_share = !notif_share; + editor.putBoolean(Helper.SET_NOTIF_SHARE, notif_share); + itemBoost.setChecked(notif_share); + editor.apply(); + break; + } + return false; + } + }); + popup.show(); + } + return true; + } + }); viewPager = (ViewPager) findViewById(R.id.viewpager); int countPage = 2;