Adds clickable tab for notifications

This commit is contained in:
tom79 2017-10-01 10:32:51 +02:00
parent e9f813222a
commit e036c600e5
5 changed files with 219 additions and 7 deletions

View File

@ -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'

View File

@ -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;

View File

@ -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)

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_favorite"
android:checkable="true"
android:title="@string/favourite"
app:actionViewClass="android.widget.CheckBox"
app:showAsAction="always"
tools:ignore="AlwaysShowAction" />
<item
android:id="@+id/action_follow"
android:checkable="true"
android:title="@string/follow"
app:actionViewClass="android.widget.CheckBox"
app:showAsAction="always" />
<item
android:id="@+id/action_mention"
android:checkable="true"
android:title="@string/mention"
app:actionViewClass="android.widget.CheckBox"
app:showAsAction="always" />
<item
android:id="@+id/action_boost"
android:checkable="true"
android:title="@string/reblog"
app:actionViewClass="android.widget.CheckBox"
app:showAsAction="always" />
</menu>

View File

@ -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;