Allows to hide tabs.

This commit is contained in:
tom79 2017-09-01 17:17:22 +02:00
parent 7ec14069fd
commit 7d3772a922
9 changed files with 164 additions and 78 deletions

View File

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

View File

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

View File

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

View File

@ -65,6 +65,17 @@
android:text="@string/set_preview_reply"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_display_local"
android:layout_width="wrap_content"
android:text="@string/set_display_local"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_display_global"
android:layout_width="wrap_content"
android:text="@string/set_display_global"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/set_preview_reply_pp_container"

View File

@ -65,6 +65,18 @@
android:text="@string/set_preview_reply"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_display_local"
android:layout_width="wrap_content"
android:text="@string/set_display_local"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_display_global"
android:layout_width="wrap_content"
android:text="@string/set_display_global"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/set_preview_reply_pp_container"
android:layout_width="match_parent"

View File

@ -281,6 +281,8 @@
<string name="load_attachment_spoiler">Mehr anzeigen…</string>
<string name="load_sensitive_attachment">Sensibler Inhalt</string>
<string name="set_display_reply">Zeige vorherige Nachricht beim Antworten</string>
<string name="set_display_local">Lokale Zeitleiste anzeigen</string>
<string name="set_display_global">Öffentliche Zeitlinie anzeigen</string>
<string name="set_folder_title">Pfad: </string>
<string name="set_auto_store_toot">Speichere Entwürfe automatisch</string>
<string name="settings_title_notifications">Benachrichtigen wenn …</string>

View File

@ -283,6 +283,8 @@
<string name="load_attachment_spoiler">Afficher le contenu ?</string>
<string name="load_sensitive_attachment">Charger les images sensibles</string>
<string name="set_display_reply">Afficher le message précédent lors d\'une réponse</string>
<string name="set_display_local">Afficher le fil local</string>
<string name="set_display_global">Afficher le fil public</string>
<string name="set_folder_title">Destination : </string>
<string name="set_auto_store_toot">Enregistrer les brouillons automatiquement</string>
<string name="set_bubble_counter">Afficher les compteurs</string>

View File

@ -288,6 +288,8 @@
<string name="load_attachment_spoiler">Show more…</string>
<string name="load_sensitive_attachment">Sensitive content</string>
<string name="set_display_reply">Display previous message in responses</string>
<string name="set_display_local">Display local timeline</string>
<string name="set_display_global">Display federated timeline</string>
<string name="set_folder_title">Path: </string>
<string name="set_auto_store_toot">Save drafts automatically</string>
<string name="set_bubble_counter">Display counters</string>

View File

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