From 7d3772a92292ab0e5b3350d9a9ad6cf48260b9c7 Mon Sep 17 00:00:00 2001 From: tom79 Date: Fri, 1 Sep 2017 17:17:22 +0200 Subject: [PATCH] Allows to hide tabs. --- .../activities/MainActivity.java | 88 +++++++++++-------- .../mastodon/fragments/SettingsFragment.java | 36 ++++++++ .../gouv/etalab/mastodon/helper/Helper.java | 2 + .../res/layout-sw600dp/fragment_settings.xml | 11 +++ app/src/main/res/layout/fragment_settings.xml | 12 +++ app/src/main/res/values-de/strings.xml | 2 + app/src/main/res/values-fr/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + .../activities/MainActivity.java | 87 ++++++++++-------- 9 files changed, 164 insertions(+), 78 deletions(-) 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 e49d88a4e..3c62d5eea 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 @@ -123,6 +123,8 @@ public class MainActivity extends AppCompatActivity private DisplayNotificationsFragment notificationsFragment; private BroadcastReceiver receive_data; private int newNotif, newHome; + private boolean display_local, display_global; + public MainActivity() { } @@ -190,6 +192,9 @@ public class MainActivity extends AppCompatActivity } setContentView(R.layout.activity_main); + display_local = sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true); + display_global = sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true); + //Test if user is still log in if( ! Helper.isLoggedIn(getApplicationContext())) { //It is not, the user is redirected to the login page @@ -247,8 +252,10 @@ public class MainActivity extends AppCompatActivity tabLayout.addTab(tabHome); tabLayout.addTab(tabNotif); - tabLayout.addTab(tabLocal); - tabLayout.addTab(tabPublic); + if( display_local) + tabLayout.addTab(tabLocal); + if( display_global) + tabLayout.addTab(tabPublic); viewPager = (ViewPager) findViewById(R.id.viewpager); main_app_container = (RelativeLayout) findViewById(R.id.main_app_container); @@ -274,33 +281,33 @@ public class MainActivity extends AppCompatActivity main_app_container.setVisibility(View.GONE); viewPager.setVisibility(View.VISIBLE); Helper.switchLayout(MainActivity.this); - switch (tab.getPosition()){ - case 0: - item = navigationView.getMenu().findItem(R.id.nav_home); - fragmentTag = "HOME_TIMELINE"; - if( homeFragment != null && newHome > 0) { - homeFragment.refresh(null); - } - newHome = 0; - updateHomeCounter(); - break; - case 1: - fragmentTag = "NOTIFICATIONS"; - item = navigationView.getMenu().findItem(R.id.nav_notification); - if( notificationsFragment != null && newNotif > 0) { - notificationsFragment.refresh(null); - } - newNotif = 0; - updateNotifCounter(); - break; - case 2: - fragmentTag = "LOCAL_TIMELINE"; - item = navigationView.getMenu().findItem(R.id.nav_local); - break; - case 3: + if( tab.getPosition() == 0) { + item = navigationView.getMenu().findItem(R.id.nav_home); + fragmentTag = "HOME_TIMELINE"; + if (homeFragment != null && newHome > 0) { + homeFragment.refresh(null); + } + newHome = 0; + updateHomeCounter(); + }else if( tab.getPosition() == 1) { + + fragmentTag = "NOTIFICATIONS"; + item = navigationView.getMenu().findItem(R.id.nav_notification); + if (notificationsFragment != null && newNotif > 0) { + notificationsFragment.refresh(null); + } + newNotif = 0; + updateNotifCounter(); + }else if( tab.getPosition() == 2 && display_local) { + + fragmentTag = "LOCAL_TIMELINE"; + item = navigationView.getMenu().findItem(R.id.nav_local); + }else if( tab.getPosition() == 2 && !display_local) { item = navigationView.getMenu().findItem(R.id.nav_global); fragmentTag = "PUBLIC_TIMELINE"; - break; + }else if( tab.getPosition() == 3){ + item = navigationView.getMenu().findItem(R.id.nav_global); + fragmentTag = "PUBLIC_TIMELINE"; } if( item != null){ toolbarTitle.setText(item.getTitle()); @@ -1035,26 +1042,29 @@ public class MainActivity extends AppCompatActivity //Selection comes from another menu, no action to do DisplayStatusFragment statusFragment; Bundle bundle = new Bundle(); - switch (position) { - case 0: - homeFragment = new DisplayStatusFragment(); - bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.HOME); - homeFragment.setArguments(bundle); - return homeFragment; - case 1: - notificationsFragment = new DisplayNotificationsFragment(); - return notificationsFragment; - case 2: + if (position == 0) { + homeFragment = new DisplayStatusFragment(); + bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.HOME); + homeFragment.setArguments(bundle); + return homeFragment; + }else if( position == 1) { + notificationsFragment = new DisplayNotificationsFragment(); + return notificationsFragment; + }else if( position == 2 && display_local) { statusFragment = new DisplayStatusFragment(); bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.LOCAL); statusFragment.setArguments(bundle); return statusFragment; - case 3: + }else if( position == 2 && !display_local){ statusFragment = new DisplayStatusFragment(); bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PUBLIC); statusFragment.setArguments(bundle); return statusFragment; - + }else if (position == 3){ + statusFragment = new DisplayStatusFragment(); + bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PUBLIC); + statusFragment.setArguments(bundle); + return statusFragment; } return null; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java index 5907cb623..5509e8bda 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java @@ -139,6 +139,7 @@ public class SettingsFragment extends Fragment { } } }); + if( !preview_reply){ set_preview_reply_pp_container.setVisibility(View.GONE); }else{ @@ -169,6 +170,41 @@ public class SettingsFragment extends Fragment { }); + boolean display_local = sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true); + final CheckBox set_display_local = (CheckBox) rootView.findViewById(R.id.set_display_local); + set_display_local.setChecked(display_local); + + set_display_local.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putBoolean(Helper.SET_DISPLAY_LOCAL, set_display_local.isChecked()); + editor.apply(); + getActivity().recreate(); + Intent intent = new Intent(context, MainActivity.class); + intent.putExtra(INTENT_ACTION, CHANGE_THEME_INTENT); + startActivity(intent); + } + }); + + + boolean display_global = sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true); + final CheckBox set_display_global = (CheckBox) rootView.findViewById(R.id.set_display_global); + set_display_global.setChecked(display_global); + + set_display_global.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putBoolean(Helper.SET_DISPLAY_GLOBAL, set_display_global.isChecked()); + editor.apply(); + getActivity().recreate(); + Intent intent = new Intent(context, MainActivity.class); + intent.putExtra(INTENT_ACTION, CHANGE_THEME_INTENT); + startActivity(intent); + } + }); + final CheckBox set_embedded_browser = (CheckBox) rootView.findViewById(R.id.set_embedded_browser); final LinearLayout set_javascript_container = (LinearLayout) rootView.findViewById(R.id.set_javascript_container); final SwitchCompat set_javascript = (SwitchCompat) rootView.findViewById(R.id.set_javascript); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 6d9af2a19..b70886fc8 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -234,6 +234,8 @@ public class Helper { public static final String SET_COOKIES = "set_cookies"; public static final String SET_FOLDER_RECORD = "set_folder_record"; public static final String SET_TOOT_VISIBILITY = "set_toot_visibility"; + public static final String SET_DISPLAY_LOCAL = "set_display_local"; + public static final String SET_DISPLAY_GLOBAL = "set_display_global"; //End points public static final String EP_AUTHORIZE = "/oauth/authorize"; diff --git a/app/src/main/res/layout-sw600dp/fragment_settings.xml b/app/src/main/res/layout-sw600dp/fragment_settings.xml index 9e104537d..9fd2b931e 100644 --- a/app/src/main/res/layout-sw600dp/fragment_settings.xml +++ b/app/src/main/res/layout-sw600dp/fragment_settings.xml @@ -65,6 +65,17 @@ android:text="@string/set_preview_reply" android:layout_height="wrap_content" /> + + + + + + + Mehr anzeigen… Sensibler Inhalt Zeige vorherige Nachricht beim Antworten + Lokale Zeitleiste anzeigen + Öffentliche Zeitlinie anzeigen Pfad: Speichere Entwürfe automatisch Benachrichtigen wenn … diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 045b148af..4d729a944 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -283,6 +283,8 @@ Afficher le contenu ? Charger les images sensibles Afficher le message précédent lors d\'une réponse + Afficher le fil local + Afficher le fil public Destination : Enregistrer les brouillons automatiquement Afficher les compteurs diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bdcebd66d..c48b7ee4c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -288,6 +288,8 @@ Show more… Sensitive content Display previous message in responses + Display local timeline + Display federated timeline Path: Save drafts automatically Display counters 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 101120f3f..34258d8e9 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 @@ -127,6 +127,7 @@ public class MainActivity extends AppCompatActivity private static final int ERROR_DIALOG_REQUEST_CODE = 97; private BroadcastReceiver receive_data; private int newNotif, newHome; + private boolean display_local, display_global; public MainActivity() { } @@ -196,6 +197,9 @@ public class MainActivity extends AppCompatActivity } setContentView(R.layout.activity_main); + display_local = sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true); + display_global = sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true); + //Test if user is still log in if( ! Helper.isLoggedIn(getApplicationContext())) { //It is not, the user is redirected to the login page @@ -254,8 +258,10 @@ public class MainActivity extends AppCompatActivity tabLayout.addTab(tabHome); tabLayout.addTab(tabNotif); - tabLayout.addTab(tabLocal); - tabLayout.addTab(tabPublic); + if( display_local) + tabLayout.addTab(tabLocal); + if( display_global) + tabLayout.addTab(tabPublic); viewPager = (ViewPager) findViewById(R.id.viewpager); main_app_container = (RelativeLayout) findViewById(R.id.main_app_container); @@ -281,33 +287,33 @@ public class MainActivity extends AppCompatActivity main_app_container.setVisibility(View.GONE); viewPager.setVisibility(View.VISIBLE); Helper.switchLayout(MainActivity.this); - switch (tab.getPosition()){ - case 0: - item = navigationView.getMenu().findItem(R.id.nav_home); - fragmentTag = "HOME_TIMELINE"; - if( homeFragment != null && newHome > 0) { - homeFragment.refresh(null); - } - newHome = 0; - updateHomeCounter(); - break; - case 1: - fragmentTag = "NOTIFICATIONS"; - item = navigationView.getMenu().findItem(R.id.nav_notification); - if( notificationsFragment != null && newNotif > 0) { - notificationsFragment.refresh(null); - } - newNotif = 0; - updateNotifCounter(); - break; - case 2: - fragmentTag = "LOCAL_TIMELINE"; - item = navigationView.getMenu().findItem(R.id.nav_local); - break; - case 3: + if( tab.getPosition() == 0) { + item = navigationView.getMenu().findItem(R.id.nav_home); + fragmentTag = "HOME_TIMELINE"; + if (homeFragment != null && newHome > 0) { + homeFragment.refresh(null); + } + newHome = 0; + updateHomeCounter(); + }else if( tab.getPosition() == 1) { + + fragmentTag = "NOTIFICATIONS"; + item = navigationView.getMenu().findItem(R.id.nav_notification); + if (notificationsFragment != null && newNotif > 0) { + notificationsFragment.refresh(null); + } + newNotif = 0; + updateNotifCounter(); + }else if( tab.getPosition() == 2 && display_local) { + + fragmentTag = "LOCAL_TIMELINE"; + item = navigationView.getMenu().findItem(R.id.nav_local); + }else if( tab.getPosition() == 2 && !display_local) { item = navigationView.getMenu().findItem(R.id.nav_global); fragmentTag = "PUBLIC_TIMELINE"; - break; + }else if( tab.getPosition() == 3){ + item = navigationView.getMenu().findItem(R.id.nav_global); + fragmentTag = "PUBLIC_TIMELINE"; } if( item != null){ toolbarTitle.setText(item.getTitle()); @@ -1090,26 +1096,29 @@ public class MainActivity extends AppCompatActivity //Selection comes from another menu, no action to do DisplayStatusFragment statusFragment; Bundle bundle = new Bundle(); - switch (position) { - case 0: - homeFragment = new DisplayStatusFragment(); - bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.HOME); - homeFragment.setArguments(bundle); - return homeFragment; - case 1: - notificationsFragment = new DisplayNotificationsFragment(); - return notificationsFragment; - case 2: + if (position == 0) { + homeFragment = new DisplayStatusFragment(); + bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.HOME); + homeFragment.setArguments(bundle); + return homeFragment; + }else if( position == 1) { + notificationsFragment = new DisplayNotificationsFragment(); + return notificationsFragment; + }else if( position == 2 && display_local) { statusFragment = new DisplayStatusFragment(); bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.LOCAL); statusFragment.setArguments(bundle); return statusFragment; - case 3: + }else if( position == 2 && !display_local){ statusFragment = new DisplayStatusFragment(); bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PUBLIC); statusFragment.setArguments(bundle); return statusFragment; - + }else if (position == 3){ + statusFragment = new DisplayStatusFragment(); + bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PUBLIC); + statusFragment.setArguments(bundle); + return statusFragment; } return null; }